blob: 235ae1f745b639b06e2904042f3f74abb7412280 [file] [log] [blame]
Naresh Tannirue3b18452014-03-04 14:44:27 +05301/*
Aniket Kumar Lata544846d2019-12-09 12:56:29 -08002 * Copyright (c) 2013-2020, The Linux Foundation. All rights reserved.
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303 * Not a Contribution.
4 *
Naresh Tannirue3b18452014-03-04 14:44:27 +05305 * Copyright (C) 2013 The Android Open Source Project
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19
Naresh Tannirudb72d1e2014-03-05 17:33:47 +053020#define LOG_TAG "msm8916_platform"
Naresh Tannirue3b18452014-03-04 14:44:27 +053021/*#define LOG_NDEBUG 0*/
22#define LOG_NDDEBUG 0
23
24#include <stdlib.h>
25#include <dlfcn.h>
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +053026#include <fcntl.h>
Vidyakumar Athota21b3bb92014-04-25 11:08:08 -070027#include <sys/ioctl.h>
Weiyin Jiang2995f662019-04-17 14:25:12 +080028#include <log/log.h>
Naresh Tannirue3b18452014-03-04 14:44:27 +053029#include <cutils/properties.h>
Naresh Tannirudb72d1e2014-03-05 17:33:47 +053030#include <cutils/str_parms.h>
Naresh Tannirue3b18452014-03-04 14:44:27 +053031#include <audio_hw.h>
32#include <platform_api.h>
Ramjee Singh82f63242018-06-06 15:22:02 +053033#include <unistd.h>
Naresh Tannirue3b18452014-03-04 14:44:27 +053034#include "platform.h"
Naresh Tannirudb72d1e2014-03-05 17:33:47 +053035#include "audio_extn.h"
Vignesh Kulothungan55396882017-04-20 14:37:02 -070036#include "acdb.h"
Naresh Tannirudb72d1e2014-03-05 17:33:47 +053037#include "voice_extn.h"
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +053038#include "edid.h"
39#include "sound/compress_params.h"
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +053040#include "sound/msmcal-hwdep.h"
Preetam Singh Ranawatc7f7f5c2015-04-02 12:19:58 +053041#include <dirent.h>
Sharad Sangleaca972a2017-01-25 12:38:22 +053042#include <linux/msm_audio.h>
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +053043
Haynes Mathew Georgeef514882017-05-01 17:46:23 -070044#if defined(PLATFORM_MSMFALCON)
45#include <sound/devdep_params.h>
46#endif
47
Revathi Uddaraju1eac8b02017-05-18 17:13:33 +053048#ifdef DYNAMIC_LOG_ENABLED
49#include <log_xml_parser.h>
50#define LOG_MASK HAL_MOD_FILE_PLATFORM
51#include <log_utils.h>
52#endif
53
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +053054#define SOUND_TRIGGER_DEVICE_HANDSET_MONO_LOW_POWER_ACDB_ID (100)
Preetam Singh Ranawat9519e9c2015-11-18 16:05:55 +053055#define MAX_MIXER_XML_PATH 100
Naresh Tanniru10758b62017-06-05 21:05:53 +053056#define MIXER_XML_PATH_QRD_SKUH "/vendor/etc/mixer_paths_qrd_skuh.xml"
57#define MIXER_XML_PATH_QRD_SKUI "/vendor/etc/mixer_paths_qrd_skui.xml"
58#define MIXER_XML_PATH_QRD_SKUHF "/vendor/etc/mixer_paths_qrd_skuhf.xml"
59#define MIXER_XML_PATH_SKUK "/vendor/etc/mixer_paths_skuk.xml"
60#define MIXER_XML_PATH_SKUA "/vendor/etc/mixer_paths_skua.xml"
61#define MIXER_XML_PATH_SKUC "/vendor/etc/mixer_paths_skuc.xml"
62#define MIXER_XML_PATH_SKUE "/vendor/etc/mixer_paths_skue.xml"
63#define MIXER_XML_PATH_SKUL "/vendor/etc/mixer_paths_skul.xml"
64#define MIXER_XML_PATH_SKUS "/vendor/etc/mixer_paths_skus.xml"
65#define MIXER_XML_PATH_SKUSH "/vendor/etc/mixer_paths_skush.xml"
66#define MIXER_XML_PATH_QRD_SKUT "/vendor/etc/mixer_paths_qrd_skut.xml"
67#define MIXER_XML_PATH_SKUM "/vendor/etc/mixer_paths_qrd_skum.xml"
68#define MIXER_XML_PATH_SKU1 "/vendor/etc/mixer_paths_qrd_sku1.xml"
69#define MIXER_XML_PATH_SKUN_CAJON "/vendor/etc/mixer_paths_qrd_skun_cajon.xml"
70#define MIXER_XML_PATH_SKU3 "/vendor/etc/mixer_paths_qrd_sku3.xml"
71#define MIXER_XML_PATH_AUXPCM "/vendor/etc/mixer_paths_auxpcm.xml"
72#define MIXER_XML_PATH_AUXPCM "/vendor/etc/mixer_paths_auxpcm.xml"
73#define MIXER_XML_PATH_I2S "/vendor/etc/mixer_paths_i2s.xml"
74#define MIXER_XML_PATH_WCD9306 "/vendor/etc/mixer_paths_wcd9306.xml"
75#define MIXER_XML_PATH_WCD9330 "/vendor/etc/mixer_paths_wcd9330.xml"
76#define MIXER_XML_PATH_WCD9340 "/vendor/etc/mixer_paths_wcd9340.xml"
Yamit Mehtaa0d653a2016-11-25 20:33:25 +053077#ifdef LINUX_ENABLED
Rohit Kumarb7d4dff2016-12-26 13:20:39 +053078/* For LE platforms */
Yamit Mehtaa0d653a2016-11-25 20:33:25 +053079#define MIXER_XML_PATH "/etc/mixer_paths.xml"
80#define MIXER_XML_PATH_MSM8909_PM8916 "/etc/mixer_paths_msm8909_pm8916.xml"
81#define MIXER_XML_PATH_MTP "/etc/mixer_paths_mtp.xml"
Vaishnavi Kommaraju9ddcfc62018-03-23 17:26:44 +053082#define MIXER_XML_PATH_SDM439_PM8953 "/etc/mixer_paths_sdm439_pm8953.xml"
Yamit Mehtaa0d653a2016-11-25 20:33:25 +053083#define MIXER_XML_PATH_SKU2 "/etc/mixer_paths_qrd_sku2.xml"
84#define MIXER_XML_PATH_WCD9326 "/etc/mixer_paths_wcd9326.xml"
Rohit Kumarb7d4dff2016-12-26 13:20:39 +053085#define MIXER_XML_PATH_WCD9335 "/etc/mixer_paths_wcd9335.xml"
Yamit Mehtaa0d653a2016-11-25 20:33:25 +053086#define PLATFORM_INFO_XML_PATH_EXTCODEC "/etc/audio_platform_info_extcodec.xml"
Walter Yangb3540112017-03-01 14:05:03 +080087#define PLATFORM_INFO_XML_PATH_SKUSH "/etc/audio_platform_info_skush.xml"
Yamit Mehtaa0d653a2016-11-25 20:33:25 +053088#define PLATFORM_INFO_XML_PATH "/etc/audio_platform_info.xml"
89#define MIXER_XML_PATH_WCD9326_I2S "/etc/mixer_paths_wcd9326_i2s.xml"
Surendar karka87fc59f2017-12-18 19:15:23 +053090#define MIXER_XML_PATH_WCD9326_I2S_TDM "/etc/mixer_paths_wcd9326_i2s_tdm.xml"
Yamit Mehtaa0d653a2016-11-25 20:33:25 +053091#define MIXER_XML_PATH_WCD9330_I2S "/etc/mixer_paths_wcd9330_i2s.xml"
Siena Richard264ed052017-03-17 10:35:01 -070092#define MIXER_XML_PATH_WCD9335_I2S "/etc/mixer_paths_wcd9335_i2s.xml"
Yamit Mehtaa0d653a2016-11-25 20:33:25 +053093#define MIXER_XML_PATH_SBC "/etc/mixer_paths_sbc.xml"
94#else
Naresh Tanniru10758b62017-06-05 21:05:53 +053095#define MIXER_XML_PATH "/vendor/etc/mixer_paths.xml"
96#define MIXER_XML_PATH_MSM8909_PM8916 "/vendor/etc/mixer_paths_msm8909_pm8916.xml"
97#define MIXER_XML_PATH_MTP "/vendor/etc/mixer_paths_mtp.xml"
Vaishnavi Kommaraju9ddcfc62018-03-23 17:26:44 +053098#define MIXER_XML_PATH_SDM439_PM8953 "/vendor/etc/mixer_paths_sdm439_pm8953.xml"
Naresh Tanniru10758b62017-06-05 21:05:53 +053099#define MIXER_XML_PATH_SKU2 "/vendor/etc/mixer_paths_qrd_sku2.xml"
100#define PLATFORM_INFO_XML_PATH_EXTCODEC "/vendor/etc/audio_platform_info_extcodec.xml"
101#define PLATFORM_INFO_XML_PATH_SKUSH "/vendor/etc/audio_platform_info_skush.xml"
102#define MIXER_XML_PATH_WCD9326 "/vendor/etc/mixer_paths_wcd9326.xml"
103#define MIXER_XML_PATH_WCD9335 "/vendor/etc/mixer_paths_wcd9335.xml"
104#define MIXER_XML_PATH_SKUN "/vendor/etc/mixer_paths_qrd_skun.xml"
105#define PLATFORM_INFO_XML_PATH "/vendor/etc/audio_platform_info.xml"
106#define MIXER_XML_PATH_WCD9326_I2S "/vendor/etc/mixer_paths_wcd9326_i2s.xml"
Surendar karka87fc59f2017-12-18 19:15:23 +0530107#define MIXER_XML_PATH_WCD9326_I2S_TDM "/vendor/etc/mixer_paths_wcd9326_i2s_tdm.xml"
Naresh Tanniru10758b62017-06-05 21:05:53 +0530108#define MIXER_XML_PATH_WCD9330_I2S "/vendor/etc/mixer_paths_wcd9330_i2s.xml"
109#define MIXER_XML_PATH_WCD9335_I2S "/vendor/etc/mixer_paths_wcd9335_i2s.xml"
110#define MIXER_XML_PATH_SBC "/vendor/etc/mixer_paths_sbc.xml"
Yamit Mehtaa0d653a2016-11-25 20:33:25 +0530111#endif
Naresh Tanniru10758b62017-06-05 21:05:53 +0530112#define MIXER_XML_PATH_SKUN "/vendor/etc/mixer_paths_qrd_skun.xml"
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530113
Naresh Tannirue3b18452014-03-04 14:44:27 +0530114#define LIB_ACDB_LOADER "libacdbloader.so"
Avinash Vaish71c066d2014-08-27 12:32:35 +0530115#define CVD_VERSION_MIXER_CTL "CVD Version"
Naresh Tannirue3b18452014-03-04 14:44:27 +0530116
Preetam Singh Ranawat3e5b9e72016-11-10 16:12:25 +0530117#define FLAC_COMPRESS_OFFLOAD_FRAGMENT_SIZE (256 * 1024)
118#define MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE (2 * 1024 * 1024)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530119#define MIN_COMPRESS_OFFLOAD_FRAGMENT_SIZE (2 * 1024)
120#define COMPRESS_OFFLOAD_FRAGMENT_SIZE_FOR_AV_STREAMING (2 * 1024)
121#define COMPRESS_OFFLOAD_FRAGMENT_SIZE (32 * 1024)
Vikram Panduranga7e784962016-10-27 12:32:30 -0700122#define DEFAULT_RX_BACKEND "SLIMBUS_0_RX"
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530123
124/*
Naresh Tannirue3b18452014-03-04 14:44:27 +0530125 * This file will have a maximum of 38 bytes:
126 *
127 * 4 bytes: number of audio blocks
128 * 4 bytes: total length of Short Audio Descriptor (SAD) blocks
129 * Maximum 10 * 3 bytes: SAD blocks
130 */
131#define MAX_SAD_BLOCKS 10
132#define SAD_BLOCK_SIZE 3
Avinash Vaish71c066d2014-08-27 12:32:35 +0530133#define MAX_CVD_VERSION_STRING_SIZE 100
Karthik Reddy Katta8513f432016-04-12 14:29:27 +0530134#define MAX_SND_CARD_STRING_SIZE 100
Naresh Tannirue3b18452014-03-04 14:44:27 +0530135
136/* EDID format ID for LPCM audio */
137#define EDID_FORMAT_LPCM 1
138
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -0700139/* fallback app type if the default app type from acdb loader fails */
140#define DEFAULT_APP_TYPE 0x11130
Naresh Tanniru2727f822015-05-11 15:27:08 +0530141#define DEFAULT_APP_TYPE_RX_PATH 0x11130
142#define DEFAULT_APP_TYPE_TX_PATH 0x11132
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -0700143
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530144#define SAMPLE_RATE_8KHZ 8000
145#define SAMPLE_RATE_16KHZ 16000
146
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530147#define MAX_SET_CAL_BYTE_SIZE 65536
148
Vikram Panduranga6e761cd2016-10-12 16:50:52 -0700149/* Mixer path names */
150#define AFE_SIDETONE_MIXER_PATH "afe-sidetone"
151
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530152#define AUDIO_PARAMETER_KEY_FLUENCE_TYPE "fluence"
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530153#define AUDIO_PARAMETER_KEY_SLOWTALK "st_enable"
Avinash Vaishd5fa4572014-09-15 14:41:14 +0530154#define AUDIO_PARAMETER_KEY_HD_VOICE "hd_voice"
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530155#define AUDIO_PARAMETER_KEY_VOLUME_BOOST "volume_boost"
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530156#define AUDIO_PARAMETER_KEY_AUD_CALDATA "cal_data"
157#define AUDIO_PARAMETER_KEY_AUD_CALRESULT "cal_result"
158
Rohit kumarf4120402016-08-05 19:19:48 +0530159#define AUDIO_PARAMETER_KEY_MONO_SPEAKER "mono_speaker"
160
Karthik Reddy Katta8513f432016-04-12 14:29:27 +0530161/* Reload ACDB files from specified path */
162#define AUDIO_PARAMETER_KEY_RELOAD_ACDB "reload_acdb"
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530163
164/* Query external audio device connection status */
165#define AUDIO_PARAMETER_KEY_EXT_AUDIO_DEVICE "ext_audio_device"
166
Surendar Karka45850ae2018-07-02 17:45:27 +0530167#define AUDIO_PARAMETER_KEY_SPKR_DEVICE_CHMAP "spkr_device_chmap"
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530168#define EVENT_EXTERNAL_SPK_1 "qc_ext_spk_1"
169#define EVENT_EXTERNAL_SPK_2 "qc_ext_spk_2"
170#define EVENT_EXTERNAL_MIC "qc_ext_mic"
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +0530171#define MAX_CAL_NAME 20
Naresh Tanniru34a303c2016-01-27 17:26:41 +0530172#define MAX_MIME_TYPE_LENGTH 30
Aditya Bavanari4875a262019-01-17 19:39:59 +0530173#define MAX_SND_CARD_NAME_LENGTH 100
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +0530174
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700175#define GET_IN_DEVICE_INDEX(SND_DEVICE) ((SND_DEVICE) - (SND_DEVICE_IN_BEGIN))
176
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +0530177char cal_name_info[WCD9XXX_MAX_CAL][MAX_CAL_NAME] = {
178 [WCD9XXX_ANC_CAL] = "anc_cal",
179 [WCD9XXX_MBHC_CAL] = "mbhc_cal",
Banajit Goswami20cdd212015-09-11 01:11:30 -0700180 [WCD9XXX_VBAT_CAL] = "vbat_cal",
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +0530181};
182
Naresh Tanniruc0517bc2014-10-26 15:30:55 +0530183#define AUDIO_PARAMETER_KEY_REC_PLAY_CONC "rec_play_conc_on"
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530184
Sidipotu Ashokf490be52015-10-20 10:41:34 +0530185#define AUDIO_PARAMETER_IS_HW_DECODER_SESSION_AVAILABLE "is_hw_dec_session_available"
Sidipotu Ashok42483b62015-09-08 10:21:44 +0530186
Naresh Tanniru25873b82016-11-01 14:15:28 +0530187static char *default_rx_backend = NULL;
188
Revathi Uddaraju1eac8b02017-05-18 17:13:33 +0530189#ifdef DYNAMIC_LOG_ENABLED
190extern void log_utils_init(void);
191extern void log_utils_deinit(void);
192#endif
193
Naresh Tanniru34a303c2016-01-27 17:26:41 +0530194char dsp_only_decoders_mime[][MAX_MIME_TYPE_LENGTH] = {
Sidipotu Ashok42483b62015-09-08 10:21:44 +0530195 "audio/x-ms-wma" /* wma*/ ,
196 "audio/x-ms-wma-lossless" /* wma lossless */ ,
197 "audio/x-ms-wma-pro" /* wma prop */ ,
198 "audio/amr-wb-plus" /* amr wb plus */ ,
199 "audio/alac" /*alac */ ,
200 "audio/x-ape" /*ape */,
201};
202
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530203enum {
204 VOICE_FEATURE_SET_DEFAULT,
205 VOICE_FEATURE_SET_VOLUME_BOOST
206};
207
Naresh Tannirue3b18452014-03-04 14:44:27 +0530208struct audio_block_header
209{
210 int reserved;
211 int length;
212};
213
Sharad Sangleaca972a2017-01-25 12:38:22 +0530214enum {
215 CAL_MODE_SEND = 0x1,
216 CAL_MODE_PERSIST = 0x2,
217 CAL_MODE_RTAC = 0x4
218};
219
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +0530220acdb_loader_get_calibration_t acdb_loader_get_calibration;
Naresh Tannirue3b18452014-03-04 14:44:27 +0530221
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +0530222typedef struct codec_backend_cfg {
223 uint32_t sample_rate;
224 uint32_t bit_width;
Ashish Jaind84fd6a2016-07-27 12:33:25 +0530225 uint32_t channels;
Siddartha Shaik44dd7702017-06-14 12:13:25 +0530226 uint32_t format;
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +0530227 char *bitwidth_mixer_ctl;
228 char *samplerate_mixer_ctl;
Ashish Jaind84fd6a2016-07-27 12:33:25 +0530229 char *channels_mixer_ctl;
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +0530230} codec_backend_cfg_t;
231
Ashish Jain4826f6c2017-02-06 13:33:20 +0530232static native_audio_prop na_props = {0, 0, NATIVE_AUDIO_MODE_INVALID};
Ashish Jainf1eaa582016-05-23 20:54:24 +0530233static bool supports_true_32_bit = false;
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +0530234
Siena Richard7c2db772016-12-21 11:32:34 -0800235static int max_be_dai_names = 0;
236static const struct be_dai_name_struct *be_dai_name_table;
237
Ramjee Singh33412cb2018-07-02 18:21:30 +0530238struct snd_device_to_mic_map {
239 struct mic_info microphones[AUDIO_MICROPHONE_MAX_COUNT];
240 size_t mic_count;
241};
242
Naresh Tannirue3b18452014-03-04 14:44:27 +0530243struct platform_data {
244 struct audio_device *adev;
245 bool fluence_in_spkr_mode;
246 bool fluence_in_voice_call;
247 bool fluence_in_voice_rec;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530248 bool fluence_in_audio_rec;
Dhanalakshmi Siddani3dbfc382017-03-21 15:15:03 +0530249 bool fluence_in_hfp_call;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530250 bool external_spk_1;
251 bool external_spk_2;
252 bool external_mic;
Vignesh Kulothungan3b5fae52017-09-25 12:16:30 -0700253 bool speaker_lr_swap;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530254 int fluence_type;
Venkata Narendra Kumar Gutta88fd0bc2014-03-27 19:47:56 +0530255 char fluence_cap[PROPERTY_VALUE_MAX];
Karthik Reddy Kattad9fff862014-07-21 21:07:21 +0530256 int fluence_mode;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530257 bool slowtalk;
Avinash Vaishd5fa4572014-09-15 14:41:14 +0530258 bool hd_voice;
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +0530259 bool ec_ref_enabled;
Preetam Singh Ranawatc7f7f5c2015-04-02 12:19:58 +0530260 bool is_wsa_speaker;
Ramjee Singh203473b2015-06-09 15:18:42 +0530261 bool is_acdb_initialized;
Venkata Narendra Kumar Gutta4bd09d02016-01-29 15:31:04 +0530262 bool hifi_audio;
Banajit Goswami20cdd212015-09-11 01:11:30 -0700263 /* Vbat monitor related flags */
264 bool is_vbat_speaker;
265 bool gsm_mode_enabled;
Rohit kumarf4120402016-08-05 19:19:48 +0530266 int mono_speaker;
Vikram Panduranga8c68e862018-04-27 12:59:42 -0700267 bool voice_speaker_stereo;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530268 /* Audio calibration related functions */
269 void *acdb_handle;
270 int voice_feature_set;
271 acdb_init_t acdb_init;
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +0530272 acdb_init_v3_t acdb_init_v3;
Aditya Bavanari29bcea22017-10-03 20:10:35 +0530273 acdb_init_v4_t acdb_init_v4;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530274 acdb_deallocate_t acdb_deallocate;
275 acdb_send_audio_cal_t acdb_send_audio_cal;
Siena Richard7c2db772016-12-21 11:32:34 -0800276 acdb_send_audio_cal_v3_t acdb_send_audio_cal_v3;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530277 acdb_set_audio_cal_t acdb_set_audio_cal;
278 acdb_get_audio_cal_t acdb_get_audio_cal;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530279 acdb_send_voice_cal_t acdb_send_voice_cal;
280 acdb_reload_vocvoltable_t acdb_reload_vocvoltable;
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -0700281 acdb_get_default_app_type_t acdb_get_default_app_type;
Ben Rombergerfeca4b82015-07-07 20:40:44 -0700282 acdb_send_common_top_t acdb_send_common_top;
Banajit Goswami20cdd212015-09-11 01:11:30 -0700283 acdb_set_codec_data_t acdb_set_codec_data;
Karthik Reddy Katta8513f432016-04-12 14:29:27 +0530284 acdb_reload_t acdb_reload;
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +0530285 acdb_reload_v2_t acdb_reload_v2;
Arun Mirpurie008ed22019-03-21 11:21:04 -0700286
Naresh Tanniruc0517bc2014-10-26 15:30:55 +0530287 bool rec_play_conc_set;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530288 void *hw_info;
Sharad Sangleaca972a2017-01-25 12:38:22 +0530289 acdb_send_gain_dep_cal_t acdb_send_gain_dep_cal;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530290 struct csd_data *csd;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530291 void *edid_info;
292 bool edid_valid;
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -0700293 int ext_disp_type;
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +0530294 codec_backend_cfg_t current_backend_cfg[MAX_CODEC_BACKENDS];
Apoorv Raghuvanshi924b3022015-07-06 15:07:14 -0700295 char ec_ref_mixer_path[64];
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +0530296 char codec_version[CODEC_VERSION_MAX_LENGTH];
Venkata Narendra Kumar Guttae071e5a2016-01-11 18:08:26 +0530297 int hw_dep_fd;
Karthik Reddy Katta8513f432016-04-12 14:29:27 +0530298 char cvd_version[MAX_CVD_VERSION_STRING_SIZE];
299 char snd_card_name[MAX_SND_CARD_STRING_SIZE];
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +0530300 int source_mic_type;
301 int max_mic_count;
Preetam Singh Ranawat3e5b9e72016-11-10 16:12:25 +0530302 bool is_dsd_supported;
303 bool is_asrc_supported;
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +0530304 struct listnode acdb_meta_key_list;
Dhananjay Kumar704ce6f2017-09-28 22:08:00 +0530305 bool use_generic_handset;
Aditya Bavanari29bcea22017-10-03 20:10:35 +0530306 struct acdb_init_data_v4 acdb_init_data;
Ramjee Singh33412cb2018-07-02 18:21:30 +0530307 uint32_t declared_mic_count;
308 struct audio_microphone_characteristic_t microphones[AUDIO_MICROPHONE_MAX_COUNT];
309 struct snd_device_to_mic_map mic_map[SND_DEVICE_MAX];
Surendar Karka45850ae2018-07-02 17:45:27 +0530310 struct spkr_device_chmap *spkr_ch_map;
Dieter Luecking5d57def2018-09-07 14:23:37 +0200311 bool use_sprk_default_sample_rate;
Dhananjay Kumar429eb452018-12-10 22:26:53 +0530312 struct listnode custom_mtmx_params_list;
Surendar Karka45850ae2018-07-02 17:45:27 +0530313};
314
315struct spkr_device_chmap {
316 int num_ch;
317 char chmap[AUDIO_CHANNEL_COUNT_MAX];
Naresh Tannirue3b18452014-03-04 14:44:27 +0530318};
319
Venkata Narendra Kumar Guttaed408a12015-03-31 20:24:04 +0530320static bool is_external_codec = false;
Sachin Mohan Gadag1ec7fab2016-12-12 17:41:26 +0530321static bool is_slimbus_interface = false;
Venkata Narendra Kumar Guttaed408a12015-03-31 20:24:04 +0530322
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530323int pcm_device_table[AUDIO_USECASE_MAX][2] = {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530324 [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = {DEEP_BUFFER_PCM_DEVICE,
325 DEEP_BUFFER_PCM_DEVICE},
326 [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
327 LOWLATENCY_PCM_DEVICE},
328 [USECASE_AUDIO_PLAYBACK_MULTI_CH] = {MULTIMEDIA2_PCM_DEVICE,
329 MULTIMEDIA2_PCM_DEVICE},
Haynes Mathew George484e8d22017-07-31 18:55:17 -0700330 [USECASE_AUDIO_PLAYBACK_HIFI] = {MULTIMEDIA2_PCM_DEVICE,
331 MULTIMEDIA2_PCM_DEVICE},
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530332 [USECASE_AUDIO_PLAYBACK_OFFLOAD] =
333 {PLAYBACK_OFFLOAD_DEVICE, PLAYBACK_OFFLOAD_DEVICE},
Dhananjay Kumara68d7af2015-05-25 19:11:30 +0530334 /* Below entries are initialized with invalid values
335 * Valid values should be updated from fnc platform_info_init()
336 * based on pcm ids defined in audio_platform_info.xml.
337 */
338 [USECASE_AUDIO_PLAYBACK_OFFLOAD2] = {-1, -1},
339 [USECASE_AUDIO_PLAYBACK_OFFLOAD3] = {-1, -1},
340 [USECASE_AUDIO_PLAYBACK_OFFLOAD4] = {-1, -1},
341 [USECASE_AUDIO_PLAYBACK_OFFLOAD5] = {-1, -1},
342 [USECASE_AUDIO_PLAYBACK_OFFLOAD6] = {-1, -1},
343 [USECASE_AUDIO_PLAYBACK_OFFLOAD7] = {-1, -1},
344 [USECASE_AUDIO_PLAYBACK_OFFLOAD8] = {-1, -1},
345 [USECASE_AUDIO_PLAYBACK_OFFLOAD9] = {-1, -1},
Naresh Tanniru3a7dbe72015-06-25 20:08:01 -0700346 [USECASE_AUDIO_PLAYBACK_ULL] = {MULTIMEDIA3_PCM_DEVICE, MULTIMEDIA3_PCM_DEVICE},
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530347 [USECASE_AUDIO_RECORD] = {AUDIO_RECORD_PCM_DEVICE, AUDIO_RECORD_PCM_DEVICE},
348 [USECASE_AUDIO_RECORD_COMPRESS] = {COMPRESS_CAPTURE_DEVICE, COMPRESS_CAPTURE_DEVICE},
Dhananjay Kumaree4d2002016-10-25 18:02:58 +0530349 [USECASE_AUDIO_RECORD_COMPRESS2] = {-1, -1},
350 [USECASE_AUDIO_RECORD_COMPRESS3] = {-1, -1},
351 [USECASE_AUDIO_RECORD_COMPRESS4] = {-1, -1},
Dhananjay Kumar376e38b2017-09-28 22:26:23 +0530352 [USECASE_AUDIO_RECORD_COMPRESS5] = {-1, -1},
353 [USECASE_AUDIO_RECORD_COMPRESS6] = {-1, -1},
354
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530355 [USECASE_AUDIO_RECORD_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
356 LOWLATENCY_PCM_DEVICE},
357 [USECASE_AUDIO_RECORD_FM_VIRTUAL] = {MULTIMEDIA2_PCM_DEVICE,
358 MULTIMEDIA2_PCM_DEVICE},
Haynes Mathew George484e8d22017-07-31 18:55:17 -0700359 [USECASE_AUDIO_RECORD_HIFI] = {MULTIMEDIA2_PCM_DEVICE,
360 MULTIMEDIA2_PCM_DEVICE},
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530361 [USECASE_AUDIO_PLAYBACK_FM] = {FM_PLAYBACK_PCM_DEVICE, FM_CAPTURE_PCM_DEVICE},
362 [USECASE_AUDIO_HFP_SCO] = {HFP_PCM_RX, HFP_SCO_RX},
363 [USECASE_AUDIO_HFP_SCO_WB] = {HFP_PCM_RX, HFP_SCO_RX},
364 [USECASE_VOICE_CALL] = {VOICE_CALL_PCM_DEVICE, VOICE_CALL_PCM_DEVICE},
365 [USECASE_VOICE2_CALL] = {VOICE2_CALL_PCM_DEVICE, VOICE2_CALL_PCM_DEVICE},
Haynes Mathew George16081042017-05-31 17:16:49 -0700366 [USECASE_AUDIO_PLAYBACK_MMAP] = {MMAP_PLAYBACK_PCM_DEVICE,
367 MMAP_PLAYBACK_PCM_DEVICE},
368 [USECASE_AUDIO_RECORD_MMAP] = {MMAP_RECORD_PCM_DEVICE,
369 MMAP_RECORD_PCM_DEVICE},
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530370 [USECASE_VOLTE_CALL] = {VOLTE_CALL_PCM_DEVICE, VOLTE_CALL_PCM_DEVICE},
371 [USECASE_QCHAT_CALL] = {QCHAT_CALL_PCM_DEVICE, QCHAT_CALL_PCM_DEVICE},
Karthik Reddy Katta3b0a60c2014-04-06 14:52:37 +0530372 [USECASE_VOWLAN_CALL] = {VOWLAN_CALL_PCM_DEVICE, VOWLAN_CALL_PCM_DEVICE},
Venkata Narendra Kumar Gutta0d293362015-12-18 15:52:27 +0530373 [USECASE_VOICEMMODE1_CALL] = {-1, -1}, /* pcm ids updated from platform info file */
374 [USECASE_VOICEMMODE2_CALL] = {-1, -1}, /* pcm ids updated from platform info file */
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530375 [USECASE_COMPRESS_VOIP_CALL] = {COMPRESS_VOIP_CALL_PCM_DEVICE, COMPRESS_VOIP_CALL_PCM_DEVICE},
376 [USECASE_INCALL_REC_UPLINK] = {AUDIO_RECORD_PCM_DEVICE,
377 AUDIO_RECORD_PCM_DEVICE},
378 [USECASE_INCALL_REC_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
379 AUDIO_RECORD_PCM_DEVICE},
380 [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
381 AUDIO_RECORD_PCM_DEVICE},
382 [USECASE_INCALL_REC_UPLINK_COMPRESS] = {COMPRESS_CAPTURE_DEVICE,
383 COMPRESS_CAPTURE_DEVICE},
384 [USECASE_INCALL_REC_DOWNLINK_COMPRESS] = {COMPRESS_CAPTURE_DEVICE,
385 COMPRESS_CAPTURE_DEVICE},
386 [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK_COMPRESS] = {COMPRESS_CAPTURE_DEVICE,
387 COMPRESS_CAPTURE_DEVICE},
388 [USECASE_INCALL_MUSIC_UPLINK] = {INCALL_MUSIC_UPLINK_PCM_DEVICE,
389 INCALL_MUSIC_UPLINK_PCM_DEVICE},
390 [USECASE_INCALL_MUSIC_UPLINK2] = {INCALL_MUSIC_UPLINK2_PCM_DEVICE,
391 INCALL_MUSIC_UPLINK2_PCM_DEVICE},
392 [USECASE_AUDIO_SPKR_CALIB_RX] = {SPKR_PROT_CALIB_RX_PCM_DEVICE, -1},
393 [USECASE_AUDIO_SPKR_CALIB_TX] = {-1, SPKR_PROT_CALIB_TX_PCM_DEVICE},
Preetam Singh Ranawat7112f3b2015-02-26 16:51:58 +0530394 [USECASE_AUDIO_PLAYBACK_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
395 AFE_PROXY_RECORD_PCM_DEVICE},
396 [USECASE_AUDIO_RECORD_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
397 AFE_PROXY_RECORD_PCM_DEVICE},
Md Mansoor Ahmeddb1b4f92018-01-25 18:56:31 +0530398 [USECASE_AUDIO_PLAYBACK_SILENCE] = {MULTIMEDIA9_PCM_DEVICE, -1},
Surendar Karka93cd25a2018-08-28 14:21:37 +0530399 [USECASE_AUDIO_TRANSCODE_LOOPBACK_RX] = {TRANSCODE_LOOPBACK_RX_DEV_ID, -1},
400 [USECASE_AUDIO_TRANSCODE_LOOPBACK_TX] = {-1, TRANSCODE_LOOPBACK_TX_DEV_ID},
Vikram Panduranga93f080e2017-06-07 18:16:14 -0700401 [USECASE_AUDIO_PLAYBACK_VOIP] = {AUDIO_PLAYBACK_VOIP_PCM_DEVICE, AUDIO_PLAYBACK_VOIP_PCM_DEVICE},
402 [USECASE_AUDIO_RECORD_VOIP] = {AUDIO_RECORD_VOIP_PCM_DEVICE, AUDIO_RECORD_VOIP_PCM_DEVICE},
Siddartha Shaik31b530e2017-05-19 15:26:33 +0530403
Varun Balaraje49253e2017-07-06 19:48:56 +0530404 [USECASE_AUDIO_PLAYBACK_INTERACTIVE_STREAM1] =
405 {PLAYBACK_INTERACTIVE_STRM_DEVICE1, PLAYBACK_INTERACTIVE_STRM_DEVICE1},
406 [USECASE_AUDIO_PLAYBACK_INTERACTIVE_STREAM2] =
407 {PLAYBACK_INTERACTIVE_STRM_DEVICE2, PLAYBACK_INTERACTIVE_STRM_DEVICE2},
408 [USECASE_AUDIO_PLAYBACK_INTERACTIVE_STREAM3] =
409 {PLAYBACK_INTERACTIVE_STRM_DEVICE3, PLAYBACK_INTERACTIVE_STRM_DEVICE3},
410 [USECASE_AUDIO_PLAYBACK_INTERACTIVE_STREAM4] =
411 {PLAYBACK_INTERACTIVE_STRM_DEVICE4, PLAYBACK_INTERACTIVE_STRM_DEVICE4},
412 [USECASE_AUDIO_PLAYBACK_INTERACTIVE_STREAM5] =
413 {PLAYBACK_INTERACTIVE_STRM_DEVICE5, PLAYBACK_INTERACTIVE_STRM_DEVICE5},
414 [USECASE_AUDIO_PLAYBACK_INTERACTIVE_STREAM6] =
415 {PLAYBACK_INTERACTIVE_STRM_DEVICE6, PLAYBACK_INTERACTIVE_STRM_DEVICE6},
416 [USECASE_AUDIO_PLAYBACK_INTERACTIVE_STREAM7] =
417 {PLAYBACK_INTERACTIVE_STRM_DEVICE7, PLAYBACK_INTERACTIVE_STRM_DEVICE7},
418 [USECASE_AUDIO_PLAYBACK_INTERACTIVE_STREAM8] =
419 {PLAYBACK_INTERACTIVE_STRM_DEVICE8, PLAYBACK_INTERACTIVE_STRM_DEVICE8},
Garmond Leunge2433c32017-09-28 21:51:22 -0700420 [USECASE_AUDIO_EC_REF_LOOPBACK] = {-1, -1}, /* pcm id updated from platform info file */
Naresh Tannirue3b18452014-03-04 14:44:27 +0530421};
422
423/* Array to store sound devices */
424static const char * const device_table[SND_DEVICE_MAX] = {
425 [SND_DEVICE_NONE] = "none",
426 /* Playback sound devices */
427 [SND_DEVICE_OUT_HANDSET] = "handset",
428 [SND_DEVICE_OUT_SPEAKER] = "speaker",
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530429 [SND_DEVICE_OUT_SPEAKER_EXTERNAL_1] = "speaker-ext-1",
430 [SND_DEVICE_OUT_SPEAKER_EXTERNAL_2] = "speaker-ext-2",
Preetam Singh Ranawatc7f7f5c2015-04-02 12:19:58 +0530431 [SND_DEVICE_OUT_SPEAKER_WSA] = "wsa-speaker",
Venkata Narendra Kumar Gutta55def542015-06-16 13:59:08 +0530432 [SND_DEVICE_OUT_SPEAKER_VBAT] = "vbat-speaker",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530433 [SND_DEVICE_OUT_SPEAKER_REVERSE] = "speaker-reverse",
434 [SND_DEVICE_OUT_HEADPHONES] = "headphones",
Preetam Singh Ranawat3e5b9e72016-11-10 16:12:25 +0530435 [SND_DEVICE_OUT_HEADPHONES_DSD] = "headphones-dsd",
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +0530436 [SND_DEVICE_OUT_HEADPHONES_44_1] = "headphones-44.1",
Naresh Tanniru9c4ba542015-11-06 18:01:09 +0530437 [SND_DEVICE_OUT_LINE] = "line",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530438 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones",
Naresh Tanniru9c4ba542015-11-06 18:01:09 +0530439 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = "speaker-and-line",
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530440 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_1] = "speaker-and-headphones-ext-1",
441 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_2] = "speaker-and-headphones-ext-2",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530442 [SND_DEVICE_OUT_VOICE_HANDSET] = "voice-handset",
443 [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker",
Vikram Panduranga8c68e862018-04-27 12:59:42 -0700444 [SND_DEVICE_OUT_VOICE_SPEAKER_STEREO] = "voice-speaker-stereo",
Preetam Singh Ranawatc7f7f5c2015-04-02 12:19:58 +0530445 [SND_DEVICE_OUT_VOICE_SPEAKER_WSA] = "wsa-voice-speaker",
Venkata Narendra Kumar Gutta55def542015-06-16 13:59:08 +0530446 [SND_DEVICE_OUT_VOICE_SPEAKER_VBAT] = "vbat-voice-speaker",
Rohit kumarf4120402016-08-05 19:19:48 +0530447 [SND_DEVICE_OUT_VOICE_SPEAKER_2] = "voice-speaker-2",
448 [SND_DEVICE_OUT_VOICE_SPEAKER_2_WSA] = "wsa-voice-speaker-2",
449 [SND_DEVICE_OUT_VOICE_SPEAKER_2_VBAT] = "vbat-voice-speaker-2",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530450 [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones",
Naresh Tanniru9c4ba542015-11-06 18:01:09 +0530451 [SND_DEVICE_OUT_VOICE_LINE] = "voice-line",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530452 [SND_DEVICE_OUT_HDMI] = "hdmi",
453 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi",
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -0700454 [SND_DEVICE_OUT_DISPLAY_PORT] = "display-port",
455 [SND_DEVICE_OUT_SPEAKER_AND_DISPLAY_PORT] = "speaker-and-display-port",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530456 [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530457 [SND_DEVICE_OUT_BT_SCO_WB] = "bt-sco-headset-wb",
Naresh Tanniru9d027a62015-03-13 01:32:10 +0530458 [SND_DEVICE_OUT_BT_A2DP] = "bt-a2dp",
459 [SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] = "speaker-and-bt-a2dp",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530460 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones",
461 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones",
462 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset",
Preetam Singh Ranawat7112f3b2015-02-26 16:51:58 +0530463 [SND_DEVICE_OUT_VOICE_TX] = "voice-tx",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530464 [SND_DEVICE_OUT_AFE_PROXY] = "afe-proxy",
Ashish Jain3e37a702016-11-25 12:27:15 +0530465 [SND_DEVICE_OUT_USB_HEADSET] = "usb-headset",
Aniket Kumar Lata3e2e1232017-06-16 17:25:07 -0700466 [SND_DEVICE_OUT_VOICE_USB_HEADSET] = "usb-headset",
Ashish Jain3e37a702016-11-25 12:27:15 +0530467 [SND_DEVICE_OUT_USB_HEADPHONES] = "usb-headphones",
Aniket Kumar Lata3e2e1232017-06-16 17:25:07 -0700468 [SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = "usb-headphones",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530469 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = "speaker-and-usb-headphones",
470 [SND_DEVICE_OUT_TRANSMISSION_FM] = "transmission-fm",
471 [SND_DEVICE_OUT_ANC_HEADSET] = "anc-headphones",
472 [SND_DEVICE_OUT_ANC_FB_HEADSET] = "anc-fb-headphones",
473 [SND_DEVICE_OUT_VOICE_ANC_HEADSET] = "voice-anc-headphones",
474 [SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET] = "voice-anc-fb-headphones",
Preetam Singh Ranawat91132162017-03-13 20:32:03 +0530475 [SND_DEVICE_OUT_VOICE_SPEAKER_AND_VOICE_HEADPHONES] = "voice-speaker-and-voice-headphones",
476 [SND_DEVICE_OUT_VOICE_SPEAKER_AND_VOICE_ANC_HEADSET] = "voice-speaker-and-voice-anc-headphones",
Vikram Panduranga8c68e862018-04-27 12:59:42 -0700477 [SND_DEVICE_OUT_VOICE_SPEAKER_STEREO_AND_VOICE_HEADPHONES] = "voice-speaker-stereo-and-voice-headphones",
478 [SND_DEVICE_OUT_VOICE_SPEAKER_STEREO_AND_VOICE_ANC_HEADSET] = "voice-speaker-stereo-and-voice-anc-headphones",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530479 [SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET] = "speaker-and-anc-headphones",
480 [SND_DEVICE_OUT_ANC_HANDSET] = "anc-handset",
481 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = "speaker-protected",
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530482 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = "voice-speaker-protected",
Vikram Panduranga8c68e862018-04-27 12:59:42 -0700483 [SND_DEVICE_OUT_VOICE_SPEAKER_STEREO_PROTECTED] = "voice-speaker-stereo-protected",
Rohit kumarf4120402016-08-05 19:19:48 +0530484 [SND_DEVICE_OUT_VOICE_SPEAKER_2_PROTECTED] = "voice-speaker-2-protected",
Banajit Goswami20cdd212015-09-11 01:11:30 -0700485 [SND_DEVICE_OUT_SPEAKER_PROTECTED_VBAT] = "speaker-protected-vbat",
486 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED_VBAT] = "voice-speaker-protected-vbat",
Rohit kumarf4120402016-08-05 19:19:48 +0530487 [SND_DEVICE_OUT_VOICE_SPEAKER_2_PROTECTED_VBAT] = "voice-speaker-2-protected-vbat",
Rohit Kumarbe6935f2017-01-20 14:58:34 +0530488 [SND_DEVICE_OUT_SPEAKER_PROTECTED_RAS] = "speaker-protected",
489 [SND_DEVICE_OUT_SPEAKER_PROTECTED_VBAT_RAS] = "speaker-protected-vbat",
kunleizbe6a8442017-08-08 17:11:35 +0800490 [SND_DEVICE_OUT_SPEAKER_AND_BT_SCO] = "speaker-and-bt-sco",
491 [SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB] = "speaker-and-bt-sco-wb",
kunleize114ec72018-05-18 11:24:23 +0800492 [SND_DEVICE_OUT_SPEAKER_WSA_AND_BT_SCO] = "wsa-speaker-and-bt-sco",
493 [SND_DEVICE_OUT_SPEAKER_WSA_AND_BT_SCO_WB] = "wsa-speaker-and-bt-sco-wb",
Naresh Tanniruc0517bc2014-10-26 15:30:55 +0530494 [SND_DEVICE_OUT_VOIP_HANDSET] = "voip-handset",
495 [SND_DEVICE_OUT_VOIP_SPEAKER] = "voip-speaker",
496 [SND_DEVICE_OUT_VOIP_HEADPHONES] = "voip-headphones",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530497
498 /* Capture sound devices */
499 [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530500 [SND_DEVICE_IN_HANDSET_MIC_EXTERNAL] = "handset-mic-ext",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530501 [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530502 [SND_DEVICE_IN_HANDSET_MIC_NS] = "handset-mic",
503 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = "handset-mic",
504 [SND_DEVICE_IN_HANDSET_DMIC] = "dmic-endfire",
505 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = "dmic-endfire",
506 [SND_DEVICE_IN_HANDSET_DMIC_NS] = "dmic-endfire",
507 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = "dmic-endfire",
508 [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
509 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "speaker-mic",
510 [SND_DEVICE_IN_SPEAKER_MIC_NS] = "speaker-mic",
511 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = "speaker-mic",
512 [SND_DEVICE_IN_SPEAKER_DMIC] = "speaker-dmic-endfire",
513 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = "speaker-dmic-endfire",
514 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = "speaker-dmic-endfire",
515 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = "speaker-dmic-endfire",
516 [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
517 [SND_DEVICE_IN_HEADSET_MIC_FLUENCE] = "headset-mic",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530518 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
519 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
520 [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic",
521 [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
Vicky Sehrawate240e5d2014-08-12 17:17:04 -0700522 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = "bt-sco-mic",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530523 [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb",
Vicky Sehrawate240e5d2014-08-12 17:17:04 -0700524 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = "bt-sco-mic-wb",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530525 [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530526 [SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef",
527 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = "voice-speaker-dmic-ef",
Vikram Pandurangaf0ca0b12018-05-04 16:00:07 -0700528 [SND_DEVICE_IN_VOICE_SPEAKER_TMIC] = "voice-speaker-tmic",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530529 [SND_DEVICE_IN_VOICE_SPEAKER_QMIC] = "voice-speaker-qmic",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530530 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
531 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
532 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
533 [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530534 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = "voice-rec-mic",
535 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = "voice-rec-dmic-ef",
536 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence",
Preetam Singh Ranawat7112f3b2015-02-26 16:51:58 +0530537 [SND_DEVICE_IN_VOICE_RX] = "voice-rx",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530538 [SND_DEVICE_IN_USB_HEADSET_MIC] = "usb-headset-mic",
Aniket Kumar Lata3e2e1232017-06-16 17:25:07 -0700539 [SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] ="usb-headset-mic",
540 [SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = "usb-headset-mic",
541 [SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = "usb-headset-mic",
542 [SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = "usb-headset-mic",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530543 [SND_DEVICE_IN_CAPTURE_FM] = "capture-fm",
544 [SND_DEVICE_IN_AANC_HANDSET_MIC] = "aanc-handset-mic",
545 [SND_DEVICE_IN_QUAD_MIC] = "quad-mic",
546 [SND_DEVICE_IN_HANDSET_STEREO_DMIC] = "handset-stereo-dmic-ef",
547 [SND_DEVICE_IN_SPEAKER_STEREO_DMIC] = "speaker-stereo-dmic-ef",
548 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = "vi-feedback",
Rohit kumarf4120402016-08-05 19:19:48 +0530549 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK_MONO_1] = "vi-feedback-mono-1",
550 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK_MONO_2] = "vi-feedback-mono-2",
Karthik Reddy Kattad9fff862014-07-21 21:07:21 +0530551 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BROADSIDE] = "voice-speaker-dmic-broadside",
552 [SND_DEVICE_IN_SPEAKER_DMIC_BROADSIDE] = "speaker-dmic-broadside",
553 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_BROADSIDE] = "speaker-dmic-broadside",
554 [SND_DEVICE_IN_SPEAKER_DMIC_NS_BROADSIDE] = "speaker-dmic-broadside",
555 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_BROADSIDE] = "speaker-dmic-broadside",
Sidipotu Ashok3bcca232014-11-07 14:41:58 +0530556 [SND_DEVICE_IN_VOICE_FLUENCE_DMIC_AANC] = "aanc-fluence-dmic-handset",
Karthik Reddy Kattad71b94b2015-01-19 14:06:53 +0530557 [SND_DEVICE_IN_HANDSET_QMIC] = "quad-mic",
558 [SND_DEVICE_IN_SPEAKER_QMIC_AEC] = "quad-mic",
559 [SND_DEVICE_IN_SPEAKER_QMIC_NS] = "quad-mic",
560 [SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS] = "quad-mic",
Shiv Maliyappanahalli5a10aea2015-07-02 10:36:23 -0700561 [SND_DEVICE_IN_THREE_MIC] = "three-mic",
Vikram Pandurangab1e26aa2018-06-21 17:28:20 -0700562 [SND_DEVICE_IN_HANDSET_TMIC_FLUENCE_PRO] = "three-mic",
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +0530563 [SND_DEVICE_IN_HANDSET_TMIC] = "three-mic",
Vikram Pandurangaf0ca0b12018-05-04 16:00:07 -0700564 [SND_DEVICE_IN_SPEAKER_TMIC_AEC] = "speaker-tmic",
565 [SND_DEVICE_IN_SPEAKER_TMIC_NS] = "speaker-tmic",
566 [SND_DEVICE_IN_SPEAKER_TMIC_AEC_NS] = "speaker-tmic",
Ben Rombergera4d76db2016-10-13 15:26:02 -0700567 [SND_DEVICE_IN_VOICE_REC_TMIC] = "three-mic",
Chaithanya Krishna Bacharaju24f86f32016-05-26 16:34:53 +0530568 [SND_DEVICE_IN_UNPROCESSED_MIC] = "unprocessed-mic",
569 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = "voice-rec-dmic-ef",
570 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = "three-mic",
571 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = "quad-mic",
572 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = "headset-mic",
Garmond Leunge2433c32017-09-28 21:51:22 -0700573 [SND_DEVICE_IN_HANDSET_6MIC] = "handset-6mic",
574 [SND_DEVICE_IN_HANDSET_8MIC] = "handset-8mic",
575 [SND_DEVICE_IN_EC_REF_LOOPBACK_MONO] = "ec-ref-loopback-mono",
576 [SND_DEVICE_IN_EC_REF_LOOPBACK_STEREO] = "ec-ref-loopback-stereo",
Dhananjay Kumar704ce6f2017-09-28 22:08:00 +0530577 [SND_DEVICE_IN_HANDSET_GENERIC_QMIC] = "quad-mic",
Divya Narayanan Poojary85d0a592018-02-06 14:25:16 +0530578 [SND_DEVICE_IN_INCALL_REC_RX] = "incall-rec-rx",
579 [SND_DEVICE_IN_INCALL_REC_TX] = "incall-rec-tx",
580 [SND_DEVICE_IN_INCALL_REC_RX_TX] = "incall-rec-rx-tx",
Ramu Gottipati813ae982018-07-25 14:14:48 +0530581 [SND_DEVICE_IN_LINE] = "line-in",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530582};
583
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530584// Platform specific backend bit width table
585static int backend_bit_width_table[SND_DEVICE_MAX] = {0};
586
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700587static struct audio_effect_config effect_config_table[GET_IN_DEVICE_INDEX(SND_DEVICE_MAX)][EFFECT_MAX] = {
588 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS)][EFFECT_AEC] = {TX_VOICE_FLUENCE_PROV2, 0x0, 0x10EAF, 0x01},
589 [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 -0700590 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_SPEAKER_TMIC_AEC_NS)][EFFECT_AEC] = {TX_VOICE_TM_FLUENCE_PRO_VC, 0x0, 0x10EAF, 0x01},
591 [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 -0700592 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_BROADSIDE)][EFFECT_AEC] = {TX_VOICE_DM_FV5_BROADSIDE, 0x0,
593 0x10EAF, 0x01},
594 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_BROADSIDE)][EFFECT_NS] = {TX_VOICE_DM_FV5_BROADSIDE, 0x0,
595 0x10EAF, 0x02},
596 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)][EFFECT_AEC] = {TX_VOICE_FV5ECNS_DM, 0x0, 0x10EAF, 0x01},
597 [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 -0700598 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_SPEAKER_MIC)][EFFECT_AEC] = {TX_VOICE_SMECNS_V2, 0x0, 0x10EAF, 0x01},
599 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_SPEAKER_MIC)][EFFECT_NS] = {TX_VOICE_SMECNS_V2, 0x0, 0x10EAF, 0x02},
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700600 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)][EFFECT_AEC] = {TX_VOICE_FV5ECNS_DM, 0x0, 0x10EAF, 0x01},
601 [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 -0700602 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_HANDSET_MIC)][EFFECT_AEC] = {TX_VOICE_SMECNS_V2, 0x0, 0x10EAF, 0x01},
603 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_HANDSET_MIC)][EFFECT_NS] = {TX_VOICE_SMECNS_V2, 0x0, 0x10EAF, 0x02},
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700604};
605
Naresh Tannirue3b18452014-03-04 14:44:27 +0530606/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530607static int acdb_device_table[SND_DEVICE_MAX] = {
Naresh Tannirue3b18452014-03-04 14:44:27 +0530608 [SND_DEVICE_NONE] = -1,
609 [SND_DEVICE_OUT_HANDSET] = 7,
Srikanth Uyyalaa675cd12014-10-15 14:48:11 +0530610 [SND_DEVICE_OUT_SPEAKER] = 14,
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530611 [SND_DEVICE_OUT_SPEAKER_EXTERNAL_1] = 14,
612 [SND_DEVICE_OUT_SPEAKER_EXTERNAL_2] = 14,
Preetam Singh Ranawatc7f7f5c2015-04-02 12:19:58 +0530613 [SND_DEVICE_OUT_SPEAKER_WSA] = 135,
Banajit Goswami20cdd212015-09-11 01:11:30 -0700614 [SND_DEVICE_OUT_SPEAKER_VBAT] = 135,
Srikanth Uyyalaa675cd12014-10-15 14:48:11 +0530615 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 14,
Naresh Tanniru9c4ba542015-11-06 18:01:09 +0530616 [SND_DEVICE_OUT_LINE] = 10,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530617 [SND_DEVICE_OUT_HEADPHONES] = 10,
Preetam Singh Ranawat3e5b9e72016-11-10 16:12:25 +0530618 [SND_DEVICE_OUT_HEADPHONES_DSD] = 10,
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +0530619 [SND_DEVICE_OUT_HEADPHONES_44_1] = 10,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530620 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
Naresh Tanniru9c4ba542015-11-06 18:01:09 +0530621 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = 10,
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530622 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_1] = 10,
623 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_2] = 10,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530624 [SND_DEVICE_OUT_VOICE_HANDSET] = 7,
Naresh Tanniru9c4ba542015-11-06 18:01:09 +0530625 [SND_DEVICE_OUT_VOICE_LINE] = 10,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530626 [SND_DEVICE_OUT_VOICE_SPEAKER] = 14,
Vikram Panduranga8c68e862018-04-27 12:59:42 -0700627 [SND_DEVICE_OUT_VOICE_SPEAKER_STEREO] = 15,
Rohit kumarf4120402016-08-05 19:19:48 +0530628 [SND_DEVICE_OUT_VOICE_SPEAKER_2] = 14,
Preetam Singh Ranawatc7f7f5c2015-04-02 12:19:58 +0530629 [SND_DEVICE_OUT_VOICE_SPEAKER_WSA] = 135,
Rohit kumarf4120402016-08-05 19:19:48 +0530630 [SND_DEVICE_OUT_VOICE_SPEAKER_2_WSA] = 135,
Banajit Goswami20cdd212015-09-11 01:11:30 -0700631 [SND_DEVICE_OUT_VOICE_SPEAKER_VBAT] = 135,
Rohit kumarf4120402016-08-05 19:19:48 +0530632 [SND_DEVICE_OUT_VOICE_SPEAKER_2_VBAT] = 135,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530633 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
Preetam Singh Ranawat91132162017-03-13 20:32:03 +0530634 [SND_DEVICE_OUT_VOICE_SPEAKER_AND_VOICE_HEADPHONES] = 10,
635 [SND_DEVICE_OUT_VOICE_SPEAKER_AND_VOICE_ANC_HEADSET] = 10,
Vikram Panduranga8c68e862018-04-27 12:59:42 -0700636 [SND_DEVICE_OUT_VOICE_SPEAKER_STEREO_AND_VOICE_HEADPHONES] = 10,
637 [SND_DEVICE_OUT_VOICE_SPEAKER_STEREO_AND_VOICE_ANC_HEADSET] = 10,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530638 [SND_DEVICE_OUT_HDMI] = 18,
Srikanth Uyyalaa675cd12014-10-15 14:48:11 +0530639 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 14,
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -0700640 [SND_DEVICE_OUT_DISPLAY_PORT] = 18,
641 [SND_DEVICE_OUT_SPEAKER_AND_DISPLAY_PORT] = 14,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530642 [SND_DEVICE_OUT_BT_SCO] = 22,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530643 [SND_DEVICE_OUT_BT_SCO_WB] = 39,
Naresh Tanniru9d027a62015-03-13 01:32:10 +0530644 [SND_DEVICE_OUT_BT_A2DP] = 20,
645 [SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] = 14,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530646 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
647 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
648 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
Preetam Singh Ranawat7112f3b2015-02-26 16:51:58 +0530649 [SND_DEVICE_OUT_VOICE_TX] = 45,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530650 [SND_DEVICE_OUT_AFE_PROXY] = 0,
651 [SND_DEVICE_OUT_USB_HEADSET] = 45,
Aniket Kumar Lata3e2e1232017-06-16 17:25:07 -0700652 [SND_DEVICE_OUT_VOICE_USB_HEADSET] = 45,
Ashish Jain3e37a702016-11-25 12:27:15 +0530653 [SND_DEVICE_OUT_USB_HEADPHONES] = 45,
Aniket Kumar Lata3e2e1232017-06-16 17:25:07 -0700654 [SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = 45,
Satya Krishna Pindiprolif5eddfd2016-12-28 11:29:08 +0530655 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = 45,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530656 [SND_DEVICE_OUT_TRANSMISSION_FM] = 0,
657 [SND_DEVICE_OUT_ANC_HEADSET] = 26,
658 [SND_DEVICE_OUT_ANC_FB_HEADSET] = 27,
659 [SND_DEVICE_OUT_VOICE_ANC_HEADSET] = 26,
660 [SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET] = 27,
661 [SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET] = 26,
662 [SND_DEVICE_OUT_ANC_HANDSET] = 103,
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530663 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = 124,
664 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = 101,
Rohit kumarf4120402016-08-05 19:19:48 +0530665 [SND_DEVICE_OUT_VOICE_SPEAKER_2_PROTECTED] = 101,
Banajit Goswami20cdd212015-09-11 01:11:30 -0700666 [SND_DEVICE_OUT_SPEAKER_PROTECTED_VBAT] = 124,
667 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED_VBAT] = 101,
Rohit kumarf4120402016-08-05 19:19:48 +0530668 [SND_DEVICE_OUT_VOICE_SPEAKER_2_PROTECTED_VBAT] = 101,
Vikram Panduranga8c68e862018-04-27 12:59:42 -0700669 [SND_DEVICE_OUT_VOICE_SPEAKER_STEREO_PROTECTED] = 124,
Rohit Kumarbe6935f2017-01-20 14:58:34 +0530670 [SND_DEVICE_OUT_SPEAKER_PROTECTED_RAS] = 134,
671 [SND_DEVICE_OUT_SPEAKER_PROTECTED_VBAT_RAS] = 134,
Naresh Tanniruc0517bc2014-10-26 15:30:55 +0530672 [SND_DEVICE_OUT_VOIP_HANDSET] = 133,
673 [SND_DEVICE_OUT_VOIP_SPEAKER] = 132,
674 [SND_DEVICE_OUT_VOIP_HEADPHONES] = 134,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530675
676 [SND_DEVICE_IN_HANDSET_MIC] = 4,
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530677 [SND_DEVICE_IN_HANDSET_MIC_EXTERNAL] = 4,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530678 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 106,
679 [SND_DEVICE_IN_HANDSET_MIC_NS] = 107,
680 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = 108,
681 [SND_DEVICE_IN_HANDSET_DMIC] = 41,
682 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = 109,
683 [SND_DEVICE_IN_HANDSET_DMIC_NS] = 110,
684 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = 111,
685 [SND_DEVICE_IN_SPEAKER_MIC] = 11,
686 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 112,
687 [SND_DEVICE_IN_SPEAKER_MIC_NS] = 113,
688 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = 114,
689 [SND_DEVICE_IN_SPEAKER_DMIC] = 43,
690 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = 115,
691 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = 116,
692 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = 117,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530693 [SND_DEVICE_IN_HEADSET_MIC] = 8,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530694 [SND_DEVICE_IN_HEADSET_MIC_FLUENCE] = 47,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530695 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
696 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = 8,
697 [SND_DEVICE_IN_HDMI_MIC] = 4,
698 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
Vicky Sehrawate240e5d2014-08-12 17:17:04 -0700699 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = 122,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530700 [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38,
Vicky Sehrawate240e5d2014-08-12 17:17:04 -0700701 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = 123,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530702 [SND_DEVICE_IN_CAMCORDER_MIC] = 4,
703 [SND_DEVICE_IN_VOICE_DMIC] = 41,
704 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 43,
Vikram Pandurangaf0ca0b12018-05-04 16:00:07 -0700705 [SND_DEVICE_IN_VOICE_SPEAKER_TMIC] = 161,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530706 [SND_DEVICE_IN_VOICE_SPEAKER_QMIC] = 19,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530707 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
708 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
709 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530710 [SND_DEVICE_IN_VOICE_REC_MIC] = 4,
711 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = 107,
712 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = 34,
713 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 41,
Preetam Singh Ranawat7112f3b2015-02-26 16:51:58 +0530714 [SND_DEVICE_IN_VOICE_RX] = 44,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530715 [SND_DEVICE_IN_USB_HEADSET_MIC] = 44,
Aniket Kumar Lata3e2e1232017-06-16 17:25:07 -0700716 [SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = 44,
717 [SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = 44,
718 [SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = 44,
719 [SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = 44,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530720 [SND_DEVICE_IN_CAPTURE_FM] = 0,
721 [SND_DEVICE_IN_AANC_HANDSET_MIC] = 104,
722 [SND_DEVICE_IN_QUAD_MIC] = 46,
723 [SND_DEVICE_IN_HANDSET_STEREO_DMIC] = 34,
724 [SND_DEVICE_IN_SPEAKER_STEREO_DMIC] = 35,
725 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = 102,
Rohit kumarf4120402016-08-05 19:19:48 +0530726 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK_MONO_1] = 102,
727 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK_MONO_2] = 102,
Karthik Reddy Kattad9fff862014-07-21 21:07:21 +0530728 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BROADSIDE] = 12,
729 [SND_DEVICE_IN_SPEAKER_DMIC_BROADSIDE] = 12,
730 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_BROADSIDE] = 119,
731 [SND_DEVICE_IN_SPEAKER_DMIC_NS_BROADSIDE] = 121,
732 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_BROADSIDE] = 120,
Venkata Narendra Kumar Gutta9bb5af62015-06-05 11:53:06 +0530733 [SND_DEVICE_IN_VOICE_FLUENCE_DMIC_AANC] = 105,
Karthik Reddy Kattad71b94b2015-01-19 14:06:53 +0530734 [SND_DEVICE_IN_HANDSET_QMIC] = 125,
735 [SND_DEVICE_IN_SPEAKER_QMIC_AEC] = 126,
736 [SND_DEVICE_IN_SPEAKER_QMIC_NS] = 127,
737 [SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS] = 129,
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +0530738 [SND_DEVICE_IN_THREE_MIC] = 46, /* for APSS Surround Sound Recording */
Vikram Pandurangab1e26aa2018-06-21 17:28:20 -0700739 [SND_DEVICE_IN_HANDSET_TMIC_FLUENCE_PRO] = 125,
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +0530740 [SND_DEVICE_IN_HANDSET_TMIC] = 125, /* for 3mic recording with fluence */
Vikram Pandurangaf0ca0b12018-05-04 16:00:07 -0700741 [SND_DEVICE_IN_SPEAKER_TMIC_AEC] = 158,
742 [SND_DEVICE_IN_SPEAKER_TMIC_NS] = 159,
743 [SND_DEVICE_IN_SPEAKER_TMIC_AEC_NS] = 160,
Ben Rombergera4d76db2016-10-13 15:26:02 -0700744 [SND_DEVICE_IN_VOICE_REC_TMIC] = 125,
Chaithanya Krishna Bacharaju24f86f32016-05-26 16:34:53 +0530745 [SND_DEVICE_IN_UNPROCESSED_MIC] = 143,
746 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = 144,
747 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = 145,
748 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = 146,
749 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = 147,
Garmond Leunge2433c32017-09-28 21:51:22 -0700750 [SND_DEVICE_IN_HANDSET_6MIC] = 4,
751 [SND_DEVICE_IN_HANDSET_8MIC] = 4,
752 [SND_DEVICE_IN_EC_REF_LOOPBACK_MONO] = 4,
Dhananjay Kumar704ce6f2017-09-28 22:08:00 +0530753 [SND_DEVICE_IN_EC_REF_LOOPBACK_STEREO] = 4,
Ramu Gottipati813ae982018-07-25 14:14:48 +0530754 [SND_DEVICE_IN_HANDSET_GENERIC_QMIC] = 150,
755 [SND_DEVICE_IN_LINE] = 4,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530756};
757
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530758struct name_to_index {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530759 char name[100];
760 unsigned int index;
761};
Naresh Tannirue3b18452014-03-04 14:44:27 +0530762
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530763#define TO_NAME_INDEX(X) #X, X
Naresh Tannirue3b18452014-03-04 14:44:27 +0530764
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530765/* Used to get index from parsed sting */
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530766static struct name_to_index snd_device_name_index[SND_DEVICE_MAX] = {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530767 {TO_NAME_INDEX(SND_DEVICE_OUT_HANDSET)},
768 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER)},
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530769 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_EXTERNAL_1)},
770 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_EXTERNAL_2)},
Preetam Singh Ranawatc7f7f5c2015-04-02 12:19:58 +0530771 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_WSA)},
Banajit Goswami20cdd212015-09-11 01:11:30 -0700772 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_VBAT)},
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530773 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_REVERSE)},
774 {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES)},
Preetam Singh Ranawat3e5b9e72016-11-10 16:12:25 +0530775 {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES_DSD)},
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +0530776 {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES_44_1)},
Naresh Tanniru9c4ba542015-11-06 18:01:09 +0530777 {TO_NAME_INDEX(SND_DEVICE_OUT_LINE)},
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530778 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES)},
Naresh Tanniru9c4ba542015-11-06 18:01:09 +0530779 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_LINE)},
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530780 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_1)},
781 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_2)},
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530782 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET)},
783 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER)},
Preetam Singh Ranawatc7f7f5c2015-04-02 12:19:58 +0530784 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_WSA)},
Banajit Goswami20cdd212015-09-11 01:11:30 -0700785 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_VBAT)},
Rohit kumarf4120402016-08-05 19:19:48 +0530786 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_2)},
787 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_2_WSA)},
788 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_2_VBAT)},
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530789 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADPHONES)},
Naresh Tanniru9c4ba542015-11-06 18:01:09 +0530790 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_LINE)},
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530791 {TO_NAME_INDEX(SND_DEVICE_OUT_HDMI)},
792 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HDMI)},
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -0700793 {TO_NAME_INDEX(SND_DEVICE_OUT_DISPLAY_PORT)},
794 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_DISPLAY_PORT)},
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530795 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO)},
796 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO_WB)},
Naresh Tanniru9d027a62015-03-13 01:32:10 +0530797 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_A2DP)},
798 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP)},
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530799 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES)},
800 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES)},
801 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET)},
kunleizbe6a8442017-08-08 17:11:35 +0800802 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_SCO)},
803 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB)},
kunleize114ec72018-05-18 11:24:23 +0800804 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_WSA_AND_BT_SCO)},
805 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_WSA_AND_BT_SCO_WB)},
Preetam Singh Ranawat7112f3b2015-02-26 16:51:58 +0530806 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TX)},
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530807 {TO_NAME_INDEX(SND_DEVICE_OUT_AFE_PROXY)},
808 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADSET)},
Aniket Kumar Lata3e2e1232017-06-16 17:25:07 -0700809 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_USB_HEADSET)},
Ashish Jain3e37a702016-11-25 12:27:15 +0530810 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADPHONES)},
Aniket Kumar Lata3e2e1232017-06-16 17:25:07 -0700811 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_USB_HEADPHONES)},
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530812 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET)},
813 {TO_NAME_INDEX(SND_DEVICE_OUT_TRANSMISSION_FM)},
814 {TO_NAME_INDEX(SND_DEVICE_OUT_ANC_HEADSET)},
815 {TO_NAME_INDEX(SND_DEVICE_OUT_ANC_FB_HEADSET)},
816 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_ANC_HEADSET)},
817 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET)},
818 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET)},
819 {TO_NAME_INDEX(SND_DEVICE_OUT_ANC_HANDSET)},
820 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED)},
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530821 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED)},
Rohit kumarf4120402016-08-05 19:19:48 +0530822 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_2_PROTECTED)},
Vikram Panduranga8c68e862018-04-27 12:59:42 -0700823 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_STEREO_PROTECTED)},
Banajit Goswami20cdd212015-09-11 01:11:30 -0700824 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED_VBAT)},
825 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED_VBAT)},
Rohit kumarf4120402016-08-05 19:19:48 +0530826 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_2_PROTECTED_VBAT)},
Rohit Kumarbe6935f2017-01-20 14:58:34 +0530827 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED_RAS)},
828 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED_VBAT_RAS)},
Soumya Managolib23c7b52018-04-11 11:47:47 +0530829 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_AND_VOICE_HEADPHONES)},
Naresh Tanniruc0517bc2014-10-26 15:30:55 +0530830 {TO_NAME_INDEX(SND_DEVICE_OUT_VOIP_HANDSET)},
831 {TO_NAME_INDEX(SND_DEVICE_OUT_VOIP_SPEAKER)},
832 {TO_NAME_INDEX(SND_DEVICE_OUT_VOIP_HEADPHONES)},
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530833 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC)},
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530834 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_EXTERNAL)},
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530835 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC)},
836 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_NS)},
837 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)},
838 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC)},
839 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC)},
840 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_NS)},
841 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)},
842 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC)},
843 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC)},
844 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_NS)},
845 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)},
846 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC)},
847 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC)},
848 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS)},
849 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)},
850 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC)},
851 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC_FLUENCE)},
852 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC)},
853 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEADSET_MIC)},
854 {TO_NAME_INDEX(SND_DEVICE_IN_HDMI_MIC)},
855 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC)},
Vicky Sehrawate240e5d2014-08-12 17:17:04 -0700856 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_NREC)},
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530857 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB)},
Vicky Sehrawate240e5d2014-08-12 17:17:04 -0700858 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB_NREC)},
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530859 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_MIC)},
860 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC)},
861 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC)},
Vikram Pandurangaf0ca0b12018-05-04 16:00:07 -0700862 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_TMIC)},
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530863 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_QMIC)},
864 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC)},
865 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC)},
866 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC)},
867 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC)},
868 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_NS)},
869 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_STEREO)},
870 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE)},
Preetam Singh Ranawat7112f3b2015-02-26 16:51:58 +0530871 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_RX)},
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530872 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC)},
Aniket Kumar Lata3e2e1232017-06-16 17:25:07 -0700873 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_USB_HEADSET_MIC)},
874 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC)},
875 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC)},
876 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC_AEC)},
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530877 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_FM)},
878 {TO_NAME_INDEX(SND_DEVICE_IN_AANC_HANDSET_MIC)},
879 {TO_NAME_INDEX(SND_DEVICE_IN_QUAD_MIC)},
880 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_STEREO_DMIC)},
881 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_STEREO_DMIC)},
882 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_VI_FEEDBACK)},
Rohit kumarf4120402016-08-05 19:19:48 +0530883 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_VI_FEEDBACK_MONO_1)},
884 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_VI_FEEDBACK_MONO_2)},
Sidipotu Ashok3bcca232014-11-07 14:41:58 +0530885 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_FLUENCE_DMIC_AANC)},
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530886 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BROADSIDE)},
887 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_BROADSIDE)},
888 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_BROADSIDE)},
889 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS_BROADSIDE)},
890 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_BROADSIDE)},
Karthik Reddy Kattad71b94b2015-01-19 14:06:53 +0530891 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC)},
892 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_QMIC_AEC)},
893 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_QMIC_NS)},
894 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS)},
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +0530895 {TO_NAME_INDEX(SND_DEVICE_IN_THREE_MIC)},
Vikram Pandurangab1e26aa2018-06-21 17:28:20 -0700896 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC_FLUENCE_PRO)},
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +0530897 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC)},
Vikram Pandurangaf0ca0b12018-05-04 16:00:07 -0700898 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_TMIC_AEC)},
899 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_TMIC_NS)},
900 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_TMIC_AEC_NS)},
Ben Rombergera4d76db2016-10-13 15:26:02 -0700901 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_TMIC)},
Chaithanya Krishna Bacharaju24f86f32016-05-26 16:34:53 +0530902 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_MIC)},
903 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_STEREO_MIC)},
904 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_THREE_MIC)},
905 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_QUAD_MIC)},
906 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC)},
Garmond Leunge2433c32017-09-28 21:51:22 -0700907 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_6MIC)},
908 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_8MIC)},
909 {TO_NAME_INDEX(SND_DEVICE_IN_EC_REF_LOOPBACK_MONO)},
910 {TO_NAME_INDEX(SND_DEVICE_IN_EC_REF_LOOPBACK_STEREO)},
Dhananjay Kumar704ce6f2017-09-28 22:08:00 +0530911 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_GENERIC_QMIC)},
Divya Narayanan Poojary85d0a592018-02-06 14:25:16 +0530912 {TO_NAME_INDEX(SND_DEVICE_IN_INCALL_REC_RX)},
913 {TO_NAME_INDEX(SND_DEVICE_IN_INCALL_REC_TX)},
914 {TO_NAME_INDEX(SND_DEVICE_IN_INCALL_REC_RX_TX)},
Ramu Gottipati813ae982018-07-25 14:14:48 +0530915 {TO_NAME_INDEX(SND_DEVICE_IN_LINE)},
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530916};
917
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +0530918static char * backend_tag_table[SND_DEVICE_MAX] = {0};
919static char * hw_interface_table[SND_DEVICE_MAX] = {0};
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530920
921static struct name_to_index usecase_name_index[AUDIO_USECASE_MAX] = {
922 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_DEEP_BUFFER)},
923 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_LOW_LATENCY)},
924 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_MULTI_CH)},
925 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD)},
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530926 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD2)},
927 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD3)},
928 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD4)},
929 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD5)},
930 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD6)},
931 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD7)},
932 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD8)},
933 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD9)},
Haynes Mathew George16081042017-05-31 17:16:49 -0700934 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_MMAP)},
Naresh Tanniru3a7dbe72015-06-25 20:08:01 -0700935 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_ULL)},
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530936 {TO_NAME_INDEX(USECASE_AUDIO_RECORD)},
Dhananjay Kumaree4d2002016-10-25 18:02:58 +0530937 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_COMPRESS)},
938 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_COMPRESS2)},
939 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_COMPRESS3)},
940 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_COMPRESS4)},
Dhananjay Kumar376e38b2017-09-28 22:26:23 +0530941 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_COMPRESS5)},
942 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_COMPRESS6)},
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530943 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_LOW_LATENCY)},
Haynes Mathew George16081042017-05-31 17:16:49 -0700944 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_MMAP)},
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530945 {TO_NAME_INDEX(USECASE_VOICE_CALL)},
946 {TO_NAME_INDEX(USECASE_VOICE2_CALL)},
947 {TO_NAME_INDEX(USECASE_VOLTE_CALL)},
948 {TO_NAME_INDEX(USECASE_QCHAT_CALL)},
949 {TO_NAME_INDEX(USECASE_VOWLAN_CALL)},
Avinash Vaish306e6072015-05-13 16:58:18 +0530950 {TO_NAME_INDEX(USECASE_VOICEMMODE1_CALL)},
951 {TO_NAME_INDEX(USECASE_VOICEMMODE2_CALL)},
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530952 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK)},
953 {TO_NAME_INDEX(USECASE_INCALL_REC_DOWNLINK)},
954 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK_AND_DOWNLINK)},
955 {TO_NAME_INDEX(USECASE_AUDIO_HFP_SCO)},
Satya Krishna Pindiprolic6b0a742017-02-03 14:37:18 +0530956 {TO_NAME_INDEX(USECASE_AUDIO_HFP_SCO_WB)},
Xiaojun Sangb112f882015-08-03 19:38:28 +0800957 {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_TX)},
Md Mansoor Ahmeddb1b4f92018-01-25 18:56:31 +0530958 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_SILENCE)},
Naresh Tannirue8081152016-12-07 16:08:42 +0530959 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_FM)},
960 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_FM_VIRTUAL)},
961 {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_RX)},
962 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_AFE_PROXY)},
963 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_AFE_PROXY)},
Garmond Leunge2433c32017-09-28 21:51:22 -0700964 {TO_NAME_INDEX(USECASE_AUDIO_EC_REF_LOOPBACK)},
Arun Mirpurie5c697c2018-07-17 17:58:17 -0700965 {TO_NAME_INDEX(USECASE_INCALL_MUSIC_UPLINK)},
Aniket Kumar Lata7fd86e12018-02-20 19:26:10 -0800966 {TO_NAME_INDEX(USECASE_AUDIO_A2DP_ABR_FEEDBACK)},
kunleiz6f796ac2018-07-16 17:03:59 +0800967 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_VOIP)},
968 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_VOIP)},
Surendar Karka93cd25a2018-08-28 14:21:37 +0530969 {TO_NAME_INDEX(USECASE_AUDIO_TRANSCODE_LOOPBACK_RX)},
970 {TO_NAME_INDEX(USECASE_AUDIO_TRANSCODE_LOOPBACK_TX)},
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530971};
972
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -0700973#define NO_COLS 2
974static int msm_be_id_array_len;
975static int (*msm_device_to_be_id)[];
976
977/* Below table lists output device to BE_ID mapping*/
978/* Update the table based on the board configuration*/
979
980static int msm_device_to_be_id_internal_codec [][NO_COLS] = {
981 {AUDIO_DEVICE_OUT_EARPIECE , 34},
982 {AUDIO_DEVICE_OUT_SPEAKER , 34},
983 {AUDIO_DEVICE_OUT_WIRED_HEADSET , 34},
984 {AUDIO_DEVICE_OUT_WIRED_HEADPHONE , 34},
985 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO , 11},
986 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET , 11},
987 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT , 11},
988 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP , -1},
989 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES , -1},
990 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER , -1},
991 {AUDIO_DEVICE_OUT_AUX_DIGITAL , 4},
992 {AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET , 9},
993 {AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET , 9},
994 {AUDIO_DEVICE_OUT_USB_ACCESSORY , -1},
995 {AUDIO_DEVICE_OUT_USB_DEVICE , -1},
Satya Krishna Pindiprolice227962017-12-13 16:07:14 +0530996 {AUDIO_DEVICE_OUT_USB_HEADSET , -1},
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -0700997 {AUDIO_DEVICE_OUT_REMOTE_SUBMIX , 9},
998 {AUDIO_DEVICE_OUT_PROXY , 9},
999 {AUDIO_DEVICE_OUT_FM , 7},
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -07001000 {AUDIO_DEVICE_OUT_ALL , -1},
1001 {AUDIO_DEVICE_NONE , -1},
1002 {AUDIO_DEVICE_OUT_DEFAULT , -1},
1003};
1004
1005static int msm_device_to_be_id_external_codec [][NO_COLS] = {
1006 {AUDIO_DEVICE_OUT_EARPIECE , 2},
1007 {AUDIO_DEVICE_OUT_SPEAKER , 2},
Sharad Sangle1f705a72016-10-05 20:01:39 +05301008 {AUDIO_DEVICE_OUT_WIRED_HEADSET , 41},
1009 {AUDIO_DEVICE_OUT_WIRED_HEADPHONE , 41},
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -07001010 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO , 11},
1011 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET , 11},
1012 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT , 11},
1013 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP , -1},
1014 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES , -1},
1015 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER , -1},
1016 {AUDIO_DEVICE_OUT_AUX_DIGITAL , 4},
1017 {AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET , 9},
1018 {AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET , 9},
1019 {AUDIO_DEVICE_OUT_USB_ACCESSORY , -1},
1020 {AUDIO_DEVICE_OUT_USB_DEVICE , -1},
Satya Krishna Pindiprolice227962017-12-13 16:07:14 +05301021 {AUDIO_DEVICE_OUT_USB_HEADSET , -1},
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -07001022 {AUDIO_DEVICE_OUT_REMOTE_SUBMIX , 9},
1023 {AUDIO_DEVICE_OUT_PROXY , 9},
1024 {AUDIO_DEVICE_OUT_FM , 7},
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -07001025 {AUDIO_DEVICE_OUT_ALL , -1},
1026 {AUDIO_DEVICE_NONE , -1},
1027 {AUDIO_DEVICE_OUT_DEFAULT , -1},
1028};
1029
1030
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301031#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
Ashish Jain5106d362016-05-11 19:23:33 +05301032#define PCM_OFFLOAD_PLATFORM_DELAY (30*1000LL)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301033#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
Haynes Mathew George5beddd42016-06-27 18:33:40 -07001034#define ULL_PLATFORM_DELAY (6*1000LL)
Haynes Mathew George16081042017-05-31 17:16:49 -07001035#define MMAP_PLATFORM_DELAY (3*1000LL)
Naresh Tannirue3b18452014-03-04 14:44:27 +05301036
`Deeraj Soman676c2702017-09-18 19:25:53 +05301037static const char *platform_get_mixer_control(struct mixer_ctl *);
1038
Sachin Mohan Gadag1ec7fab2016-12-12 17:41:26 +05301039static void update_interface(const char *snd_card_name) {
1040 if (!strncmp(snd_card_name, "apq8009-tashalite-snd-card",
1041 sizeof("apq8009-tashalite-snd-card"))) {
1042 is_slimbus_interface = false;
1043 }
1044}
1045
Venkata Narendra Kumar Guttaed408a12015-03-31 20:24:04 +05301046static void update_codec_type(const char *snd_card_name) {
1047
1048 if (!strncmp(snd_card_name, "msm8939-tapan-snd-card",
1049 sizeof("msm8939-tapan-snd-card")) ||
1050 !strncmp(snd_card_name, "msm8939-tapan9302-snd-card",
Avinash Vaish306e6072015-05-13 16:58:18 +05301051 sizeof("msm8939-tapan9302-snd-card")) ||
Venkata Narendra Kumar Guttaed408a12015-03-31 20:24:04 +05301052 !strncmp(snd_card_name, "msm8939-tomtom9330-snd-card",
Karthik Reddy Katta508eca42015-05-11 13:43:18 +05301053 sizeof("msm8939-tomtom9330-snd-card")) ||
1054 !strncmp(snd_card_name, "msm8952-tomtom-snd-card",
Preetam Singh Ranawat9519e9c2015-11-18 16:05:55 +05301055 sizeof("msm8952-tomtom-snd-card")) ||
Xiaojun Sang9cd237a2015-11-20 15:30:18 +08001056 !strncmp(snd_card_name, "msm8953-sku3-tasha-snd-card",
1057 sizeof("msm8953-sku3-tasha-snd-card")) ||
Preetam Singh Ranawat9519e9c2015-11-18 16:05:55 +05301058 !strncmp(snd_card_name, "msm8952-tasha-snd-card",
1059 sizeof("msm8952-tasha-snd-card")) ||
1060 !strncmp(snd_card_name, "msm8952-tashalite-snd-card",
1061 sizeof("msm8952-tashalite-snd-card")) ||
1062 !strncmp(snd_card_name, "msm8952-tasha-skun-snd-card",
Preetam Singh Ranawat61716b12015-12-14 11:55:24 +05301063 sizeof("msm8952-tasha-skun-snd-card")) ||
Aravind Kumard7691742015-05-13 13:10:51 +05301064 !strncmp(snd_card_name, "msm8976-tasha-snd-card",
Meng Wangf1ec20c2015-06-26 10:32:32 +08001065 sizeof("msm8976-tasha-snd-card")) ||
Yeleswarapu Nagaradhesh09f30be2015-07-22 14:11:03 +05301066 !strncmp(snd_card_name, "msm8976-tashalite-snd-card",
1067 sizeof("msm8976-tashalite-snd-card")) ||
Meng Wangf1ec20c2015-06-26 10:32:32 +08001068 !strncmp(snd_card_name, "msm8976-tasha-skun-snd-card",
Naresh Tanniru4d1e1a12015-12-16 19:37:50 +05301069 sizeof("msm8976-tasha-skun-snd-card")) ||
1070 !strncmp(snd_card_name, "msm8937-tasha-snd-card",
1071 sizeof("msm8937-tasha-snd-card")) ||
1072 !strncmp(snd_card_name, "msm8937-tashalite-snd-card",
1073 sizeof("msm8937-tashalite-snd-card")) ||
1074 !strncmp(snd_card_name, "msm8953-tasha-snd-card",
1075 sizeof("msm8953-tasha-snd-card")) ||
1076 !strncmp(snd_card_name, "msm8953-tashalite-snd-card",
Dhananjay Kumard3ab9f42016-07-20 17:05:47 +05301077 sizeof("msm8953-tashalite-snd-card")) ||
Arusha Goyalfda29152016-12-26 10:53:39 +05301078 !strncmp(snd_card_name, "sdm660-tasha-snd-card",
1079 sizeof("sdm660-tasha-snd-card")) ||
Yamit Mehtaa0d653a2016-11-25 20:33:25 +05301080 !strncmp(snd_card_name, "apq8009-tashalite-snd-card",
1081 sizeof("apq8009-tashalite-snd-card")) ||
Surendar karka87fc59f2017-12-18 19:15:23 +05301082 !strncmp(snd_card_name, "apq8009-tashalite-snd-card-tdm",
1083 sizeof("apq8009-tashalite-snd-card-tdm")) ||
Yamit Mehtaa0d653a2016-11-25 20:33:25 +05301084 !strncmp(snd_card_name, "mdm9607-tomtom-i2s-snd-card",
Naresh Tanniru25873b82016-11-01 14:15:28 +05301085 sizeof("mdm9607-tomtom-i2s-snd-card")) ||
Siena Richard264ed052017-03-17 10:35:01 -07001086 !strncmp(snd_card_name, "mdm-tasha-i2s-snd-card",
1087 sizeof("mdm-tasha-i2s-snd-card")) ||
Arusha Goyalfda29152016-12-26 10:53:39 +05301088 !strncmp(snd_card_name, "sdm660-tashalite-snd-card",
1089 sizeof("sdm660-tashalite-snd-card")) ||
Walter Yangfd3f3252017-01-03 01:35:23 -08001090 !strncmp(snd_card_name, "sdm660-tasha-skus-snd-card",
1091 sizeof("sdm660-tasha-skus-snd-card")) ||
Arusha Goyalfda29152016-12-26 10:53:39 +05301092 !strncmp(snd_card_name, "sdm660-tavil-snd-card",
1093 sizeof("sdm660-tavil-snd-card")))
Preetam Singh Ranawat9519e9c2015-11-18 16:05:55 +05301094 {
Venkata Narendra Kumar Guttaed408a12015-03-31 20:24:04 +05301095 ALOGI("%s: snd_card_name: %s",__func__,snd_card_name);
1096 is_external_codec = true;
Sachin Mohan Gadag1ec7fab2016-12-12 17:41:26 +05301097 is_slimbus_interface = true;
Venkata Narendra Kumar Guttaed408a12015-03-31 20:24:04 +05301098 }
1099}
Asish Bhattacharya4ff24802014-04-24 17:46:54 +05301100static void query_platform(const char *snd_card_name,
1101 char *mixer_xml_path)
1102{
1103 if (!strncmp(snd_card_name, "msm8x16-snd-card-mtp",
1104 sizeof("msm8x16-snd-card-mtp"))) {
1105 strlcpy(mixer_xml_path, MIXER_XML_PATH_MTP,
1106 sizeof(MIXER_XML_PATH_MTP));
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -07001107
1108 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
1109 msm_be_id_array_len =
1110 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
1111
Tanya Finkeldd78e062015-05-26 04:29:56 -07001112 } else if (!strncmp(snd_card_name, "msm8x16-snd-card-sbc",
1113 sizeof("msm8x16-snd-card-sbc"))) {
1114 strlcpy(mixer_xml_path, MIXER_XML_PATH_SBC,
1115 sizeof(mixer_xml_path));
1116
1117 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
1118 msm_be_id_array_len =
1119 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
1120
Walter Yang7ca90d92014-05-06 17:48:02 +08001121 } else if (!strncmp(snd_card_name, "msm8x16-skuh-snd-card",
1122 sizeof("msm8x16-skuh-snd-card"))) {
1123 strlcpy(mixer_xml_path, MIXER_XML_PATH_QRD_SKUH,
1124 sizeof(MIXER_XML_PATH_QRD_SKUH));
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -07001125
1126 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
1127 msm_be_id_array_len =
1128 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
1129
Walter Yang7ca90d92014-05-06 17:48:02 +08001130 } else if (!strncmp(snd_card_name, "msm8x16-skui-snd-card",
1131 sizeof("msm8x16-skui-snd-card"))) {
1132 strlcpy(mixer_xml_path, MIXER_XML_PATH_QRD_SKUI,
1133 sizeof(MIXER_XML_PATH_QRD_SKUI));
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -07001134
1135 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
1136 msm_be_id_array_len =
1137 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
1138
Walter Yang19f244a2014-06-17 13:30:08 +08001139 } else if (!strncmp(snd_card_name, "msm8x16-skuhf-snd-card",
1140 sizeof("msm8x16-skuhf-snd-card"))) {
1141 strlcpy(mixer_xml_path, MIXER_XML_PATH_QRD_SKUHF,
1142 sizeof(MIXER_XML_PATH_QRD_SKUHF));
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -07001143
1144 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
1145 msm_be_id_array_len =
1146 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
1147
Walter Yangc899d572014-05-27 21:52:17 +08001148 } else if (!strncmp(snd_card_name, "msm8939-snd-card-mtp",
Yamit Mehtac6003e22014-05-19 10:26:02 +05301149 sizeof("msm8939-snd-card-mtp"))) {
Aravind Kumar71ba22b2014-06-23 15:18:50 +05301150 strlcpy(mixer_xml_path, MIXER_XML_PATH_MTP,
1151 sizeof(MIXER_XML_PATH_MTP));
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -07001152
1153 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
1154 msm_be_id_array_len =
1155 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
1156
Meng Wangf00485b2014-06-03 19:44:38 +08001157 } else if (!strncmp(snd_card_name, "msm8939-snd-card-skuk",
1158 sizeof("msm8939-snd-card-skuk"))) {
1159 strlcpy(mixer_xml_path, MIXER_XML_PATH_SKUK,
1160 sizeof(MIXER_XML_PATH_SKUK));
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -07001161 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
1162 msm_be_id_array_len =
1163 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
1164
Asish Bhattacharyacb8e6d02014-06-19 12:32:25 +05301165 } else if (!strncmp(snd_card_name, "msm8939-tapan-snd-card",
1166 sizeof("msm8939-tapan-snd-card"))) {
1167 strlcpy(mixer_xml_path, MIXER_XML_PATH_WCD9306,
1168 sizeof(MIXER_XML_PATH_WCD9306));
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -07001169 msm_device_to_be_id = msm_device_to_be_id_external_codec;
1170 msm_be_id_array_len =
1171 sizeof(msm_device_to_be_id_external_codec) / sizeof(msm_device_to_be_id_external_codec[0]);
1172
Asish Bhattacharyacb8e6d02014-06-19 12:32:25 +05301173 } else if (!strncmp(snd_card_name, "msm8939-tapan9302-snd-card",
1174 sizeof("msm8939-tapan9302-snd-card"))) {
1175 strlcpy(mixer_xml_path, MIXER_XML_PATH_WCD9306,
1176 sizeof(MIXER_XML_PATH_WCD9306));
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -07001177
1178 msm_device_to_be_id = msm_device_to_be_id_external_codec;
1179 msm_be_id_array_len =
1180 sizeof(msm_device_to_be_id_external_codec) / sizeof(msm_device_to_be_id_external_codec[0]);
1181
Aviral Gupta8ed0eec2014-08-25 10:22:11 +05301182 } else if (!strncmp(snd_card_name, "msm8939-tomtom9330-snd-card",
1183 sizeof("msm8939-tomtom9330-snd-card"))) {
1184 strlcpy(mixer_xml_path, MIXER_XML_PATH_WCD9330,
1185 sizeof(MIXER_XML_PATH_WCD9330));
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -07001186 msm_device_to_be_id = msm_device_to_be_id_external_codec;
1187 msm_be_id_array_len =
1188 sizeof(msm_device_to_be_id_external_codec) / sizeof(msm_device_to_be_id_external_codec[0]);
1189
Aravind Kumard7691742015-05-13 13:10:51 +05301190 } else if (!strncmp(snd_card_name, "msm8976-tasha-snd-card",
1191 sizeof("msm8976-tasha-snd-card"))) {
1192 strlcpy(mixer_xml_path, MIXER_XML_PATH_WCD9335,
1193 sizeof(MIXER_XML_PATH_WCD9335));
1194 msm_device_to_be_id = msm_device_to_be_id_external_codec;
1195 msm_be_id_array_len =
1196 sizeof(msm_device_to_be_id_external_codec) / sizeof(msm_device_to_be_id_external_codec[0]);
1197
Yeleswarapu Nagaradhesh09f30be2015-07-22 14:11:03 +05301198 } else if (!strncmp(snd_card_name, "msm8976-tashalite-snd-card",
1199 sizeof("msm8976-tashalite-snd-card"))) {
1200 strlcpy(mixer_xml_path, MIXER_XML_PATH_WCD9326,
1201 MAX_MIXER_XML_PATH);
1202 msm_device_to_be_id = msm_device_to_be_id_external_codec;
1203 msm_be_id_array_len =
1204 sizeof(msm_device_to_be_id_external_codec) / sizeof(msm_device_to_be_id_external_codec[0]);
1205
Meng Wangf1ec20c2015-06-26 10:32:32 +08001206 } else if (!strncmp(snd_card_name, "msm8976-tasha-skun-snd-card",
1207 sizeof("msm8976-tasha-skun-snd-card"))) {
1208 strlcpy(mixer_xml_path, MIXER_XML_PATH_SKUN,
1209 sizeof(MIXER_XML_PATH_SKUN));
1210 msm_device_to_be_id = msm_device_to_be_id_external_codec;
1211 msm_be_id_array_len =
1212 sizeof(msm_device_to_be_id_external_codec) / sizeof(msm_device_to_be_id_external_codec[0]);
1213
Walter Yang42886c52014-10-23 14:31:48 +08001214 } else if (!strncmp(snd_card_name, "msm8909-skua-snd-card",
1215 sizeof("msm8909-skua-snd-card"))) {
1216 strlcpy(mixer_xml_path, MIXER_XML_PATH_SKUA,
1217 sizeof(MIXER_XML_PATH_SKUA));
Walter Yang42886c52014-10-23 14:31:48 +08001218 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
1219 msm_be_id_array_len =
1220 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
Preetam Singh Ranawat2d0e4632015-02-02 12:40:59 +05301221
Walter Yang42886c52014-10-23 14:31:48 +08001222 } else if (!strncmp(snd_card_name, "msm8909-skuc-snd-card",
1223 sizeof("msm8909-skuc-snd-card"))) {
1224 strlcpy(mixer_xml_path, MIXER_XML_PATH_SKUC,
1225 sizeof(MIXER_XML_PATH_SKUC));
Preetam Singh Ranawat2d0e4632015-02-02 12:40:59 +05301226 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
1227 msm_be_id_array_len =
1228 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
Divya Narayanan Poojary64daf662017-04-20 17:30:20 +05301229 } else if (!strncmp(snd_card_name, "msm8909-skut-snd-card",
1230 sizeof("msm8909-skut-snd-card"))) {
1231 strlcpy(mixer_xml_path, MIXER_XML_PATH_QRD_SKUT,
1232 sizeof(MIXER_XML_PATH_QRD_SKUT));
1233 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
1234 msm_be_id_array_len =
1235 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
Preetam Singh Ranawat2d0e4632015-02-02 12:40:59 +05301236
Divya Narayanan Poojary0d2d17a2017-04-20 16:51:42 +05301237 } else if (!strncmp(snd_card_name, "msm8909-skuq-snd-card",
1238 sizeof("msm8909-skuq-snd-card"))) {
1239 strlcpy(mixer_xml_path, MIXER_XML_PATH_QRD_SKUT,
1240 sizeof(MIXER_XML_PATH_QRD_SKUT));
1241 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
1242 msm_be_id_array_len =
1243 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
Preetam Singh Ranawat2d0e4632015-02-02 12:40:59 +05301244 } else if (!strncmp(snd_card_name, "msm8909-pm8916-snd-card",
1245 sizeof("msm8909-pm8916-snd-card"))) {
1246 strlcpy(mixer_xml_path, MIXER_XML_PATH_MSM8909_PM8916,
1247 sizeof(MIXER_XML_PATH_MSM8909_PM8916));
Walter Yang42886c52014-10-23 14:31:48 +08001248
1249 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
1250 msm_be_id_array_len =
1251 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
Preetam Singh Ranawat2d0e4632015-02-02 12:40:59 +05301252
1253 } else if (!strncmp(snd_card_name, "msm8909-skue-snd-card",
1254 sizeof("msm8909-skue-snd-card"))) {
1255 strlcpy(mixer_xml_path, MIXER_XML_PATH_SKUE,
1256 sizeof(MIXER_XML_PATH_SKUE));
1257 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
1258 msm_be_id_array_len =
1259 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
1260
Meng Wangcfefb8b2014-12-05 14:35:55 +08001261 } else if (!strncmp(snd_card_name, "msm8939-snd-card-skul",
1262 sizeof("msm8939-snd-card-skul"))) {
1263 strlcpy(mixer_xml_path, MIXER_XML_PATH_SKUL,
1264 sizeof(MIXER_XML_PATH_SKUL));
1265 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
1266 msm_be_id_array_len =
1267 sizeof(msm_device_to_be_id_external_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
Naresh Tanniru0d28b4a2015-03-23 00:58:49 +05301268 } else if (!strncmp(snd_card_name, "msm8952-snd-card-mtp",
Avinash Vaish306e6072015-05-13 16:58:18 +05301269 sizeof("msm8952-snd-card-mtp"))) {
Naresh Tanniru0d28b4a2015-03-23 00:58:49 +05301270 strlcpy(mixer_xml_path, MIXER_XML_PATH_MTP,
1271 sizeof(MIXER_XML_PATH_MTP));
1272 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
1273 msm_be_id_array_len =
1274 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
Vaishnavi Kommaraju9ddcfc62018-03-23 17:26:44 +05301275 } else if (!strncmp(snd_card_name, "sdm439-snd-card-mtp",
1276 sizeof("sdm439-snd-card-mtp"))) {
1277 strlcpy(mixer_xml_path, MIXER_XML_PATH_SDM439_PM8953,
1278 sizeof(MIXER_XML_PATH_SDM439_PM8953));
1279 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
1280 msm_be_id_array_len =
1281 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
Xiaojun Sang172e0fa2018-04-02 17:27:15 +08001282 } else if (!strncmp(snd_card_name, "sdm439-sku1-snd-card",
1283 sizeof("sdm439-sku1-snd-card"))) {
1284 strlcpy(mixer_xml_path, MIXER_XML_PATH_SDM439_PM8953,
1285 sizeof(MIXER_XML_PATH_SDM439_PM8953));
1286 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
1287 msm_be_id_array_len =
1288 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
Naresh Tanniru0d28b4a2015-03-23 00:58:49 +05301289 } else if (!strncmp(snd_card_name, "msm8952-tomtom-snd-card",
1290 sizeof("msm8952-tomtom-snd-card"))) {
1291 strlcpy(mixer_xml_path, MIXER_XML_PATH_WCD9330,
1292 sizeof(MIXER_XML_PATH_WCD9330));
1293 msm_device_to_be_id = msm_device_to_be_id_external_codec;
1294 msm_be_id_array_len =
1295 sizeof(msm_device_to_be_id_external_codec) / sizeof(msm_device_to_be_id_external_codec[0]);
Xiaojun Sang68b39442015-09-23 16:29:43 +08001296 } else if (!strncmp(snd_card_name, "msm8952-sku1-snd-card",
1297 sizeof("msm8952-sku1-snd-card"))) {
1298 strlcpy(mixer_xml_path, MIXER_XML_PATH_SKU1,
1299 sizeof(MIXER_XML_PATH_SKU1));
1300 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
1301 msm_be_id_array_len =
1302 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
1303 } else if (!strncmp(snd_card_name, "msm8952-sku2-snd-card",
1304 sizeof("msm8952-sku2-snd-card"))) {
1305 strlcpy(mixer_xml_path, MIXER_XML_PATH_SKU2,
1306 sizeof(MIXER_XML_PATH_SKU2));
1307 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
1308 msm_be_id_array_len =
1309 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
Xiaojun Sang9cd237a2015-11-20 15:30:18 +08001310 } else if (!strncmp(snd_card_name, "msm8953-sku3-tasha-snd-card",
1311 sizeof("msm8953-sku3-tasha-snd-card"))) {
1312 strlcpy(mixer_xml_path, MIXER_XML_PATH_SKU3,
1313 sizeof(MIXER_XML_PATH_SKU3));
1314 msm_device_to_be_id = msm_device_to_be_id_external_codec;
1315 msm_be_id_array_len =
1316 sizeof(msm_device_to_be_id_external_codec) / sizeof(msm_device_to_be_id_external_codec[0]);
Walter Yangcd132722015-04-08 16:04:30 +08001317 } else if (!strncmp(snd_card_name, "msm8952-skum-snd-card",
1318 sizeof("msm8952-skum-snd-card"))) {
1319 strlcpy(mixer_xml_path, MIXER_XML_PATH_SKUM,
1320 sizeof(MIXER_XML_PATH_SKUM));
1321 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
1322 msm_be_id_array_len =
1323 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
Preetam Singh Ranawat9519e9c2015-11-18 16:05:55 +05301324 } else if (!strncmp(snd_card_name, "msm8952-tasha-snd-card",
1325 sizeof("msm8952-tasha-snd-card"))) {
1326 strlcpy(mixer_xml_path, MIXER_XML_PATH_WCD9335,
1327 sizeof(MIXER_XML_PATH_WCD9335));
1328 msm_device_to_be_id = msm_device_to_be_id_external_codec;
1329 msm_be_id_array_len =
1330 sizeof(msm_device_to_be_id_external_codec) / sizeof(msm_device_to_be_id_external_codec[0]);
Naresh Tanniru0d28b4a2015-03-23 00:58:49 +05301331
Preetam Singh Ranawat9519e9c2015-11-18 16:05:55 +05301332 } else if (!strncmp(snd_card_name, "msm8952-tashalite-snd-card",
1333 sizeof("msm8952-tashalite-snd-card"))) {
1334 strlcpy(mixer_xml_path, MIXER_XML_PATH_WCD9326,
1335 MAX_MIXER_XML_PATH);
1336 msm_device_to_be_id = msm_device_to_be_id_external_codec;
1337 msm_be_id_array_len =
1338 sizeof(msm_device_to_be_id_external_codec) / sizeof(msm_device_to_be_id_external_codec[0]);
Meng Wang2d747622015-08-07 10:11:41 +08001339 } else if (!strncmp(snd_card_name, "msm8976-skun-snd-card",
1340 sizeof("msm8976-skun-snd-card"))) {
1341 strlcpy(mixer_xml_path, MIXER_XML_PATH_SKUN_CAJON,
1342 sizeof(MIXER_XML_PATH_SKUN_CAJON));
1343 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
1344 msm_be_id_array_len =
1345 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
Naresh Tanniru4d1e1a12015-12-16 19:37:50 +05301346
1347 } else if (!strncmp(snd_card_name, "msm8937-snd-card-mtp",
1348 sizeof("msm8937-snd-card-mtp"))) {
1349 strlcpy(mixer_xml_path, MIXER_XML_PATH_MTP,
1350 sizeof(MIXER_XML_PATH_MTP));
1351 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
1352 msm_be_id_array_len =
1353 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
1354 } else if (!strncmp(snd_card_name, "msm8937-tasha-snd-card",
1355 sizeof("msm8937-tasha-snd-card"))) {
1356 strlcpy(mixer_xml_path, MIXER_XML_PATH_WCD9335,
1357 sizeof(MIXER_XML_PATH_WCD9335));
1358 msm_device_to_be_id = msm_device_to_be_id_external_codec;
1359 msm_be_id_array_len =
1360 sizeof(msm_device_to_be_id_external_codec) / sizeof(msm_device_to_be_id_external_codec[0]);
1361 } else if (!strncmp(snd_card_name, "msm8937-tashalite-snd-card",
1362 sizeof("msm8937-tashalite-snd-card"))) {
1363 strlcpy(mixer_xml_path, MIXER_XML_PATH_WCD9326,
1364 MAX_MIXER_XML_PATH);
1365 msm_device_to_be_id = msm_device_to_be_id_external_codec;
1366 msm_be_id_array_len =
1367 sizeof(msm_device_to_be_id_external_codec) / sizeof(msm_device_to_be_id_external_codec[0]);
1368 } else if (!strncmp(snd_card_name, "msm8953-snd-card-mtp",
1369 sizeof("msm8953-snd-card-mtp"))) {
1370 strlcpy(mixer_xml_path, MIXER_XML_PATH_MTP,
1371 sizeof(MIXER_XML_PATH_MTP));
1372 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
1373 msm_be_id_array_len =
1374 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
1375 } else if (!strncmp(snd_card_name, "msm8953-tasha-snd-card",
1376 sizeof("msm8953-tasha-snd-card"))) {
1377 strlcpy(mixer_xml_path, MIXER_XML_PATH_WCD9335,
1378 sizeof(MIXER_XML_PATH_WCD9335));
1379 msm_device_to_be_id = msm_device_to_be_id_external_codec;
1380 msm_be_id_array_len =
1381 sizeof(msm_device_to_be_id_external_codec) / sizeof(msm_device_to_be_id_external_codec[0]);
1382 } else if (!strncmp(snd_card_name, "msm8953-tashalite-snd-card",
1383 sizeof("msm8937-tashalite-snd-card"))) {
1384 strlcpy(mixer_xml_path, MIXER_XML_PATH_WCD9326,
1385 MAX_MIXER_XML_PATH);
1386 msm_device_to_be_id = msm_device_to_be_id_external_codec;
1387 msm_be_id_array_len =
1388 sizeof(msm_device_to_be_id_external_codec) / sizeof(msm_device_to_be_id_external_codec[0]);
Meng Wangc5274502016-04-12 16:20:41 +08001389 } else if (!strncmp(snd_card_name, "msm8917-tmo-snd-card",
1390 sizeof("msm8917-tmo-snd-card"))) {
1391 strlcpy(mixer_xml_path, MIXER_XML_PATH_SKU2,
1392 MAX_MIXER_XML_PATH);
1393 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
1394 msm_be_id_array_len =
1395 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
1396 } else if (!strncmp(snd_card_name, "msm8917-sku5-snd-card",
1397 sizeof("msm8917-sku5-snd-card"))) {
1398 strlcpy(mixer_xml_path, MIXER_XML_PATH_SKU2,
1399 MAX_MIXER_XML_PATH);
1400 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
1401 msm_be_id_array_len =
1402 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
1403 } else if (!strncmp(snd_card_name, "msm8940-sku6-snd-card",
1404 sizeof("msm8940-sku6-snd-card"))) {
1405 strlcpy(mixer_xml_path, MIXER_XML_PATH_SKU1,
1406 MAX_MIXER_XML_PATH);
1407 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
1408 msm_be_id_array_len =
1409 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
Xiaojun Sang6b755df2018-02-08 14:53:28 +08001410 } else if (!strncmp(snd_card_name, "msm8953-sku4-snd-card",
1411 sizeof("msm8953-sku4-snd-card"))) {
1412 strlcpy(mixer_xml_path, MIXER_XML_PATH_MTP,
1413 sizeof(MIXER_XML_PATH_MTP));
1414 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
1415 msm_be_id_array_len =
1416 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
Arusha Goyalfda29152016-12-26 10:53:39 +05301417 } else if (!strncmp(snd_card_name, "sdm660-snd-card",
1418 sizeof("sdm660-snd-card"))) {
Naresh Tanniru25873b82016-11-01 14:15:28 +05301419 strlcpy(mixer_xml_path, MIXER_XML_PATH,
1420 MAX_MIXER_XML_PATH);
1421 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
1422 msm_be_id_array_len =
1423 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
Arusha Goyalfda29152016-12-26 10:53:39 +05301424 } else if (!strncmp(snd_card_name, "sdm660-snd-card-mtp",
1425 sizeof("sdm660-snd-card-mtp"))) {
Naresh Tanniru25873b82016-11-01 14:15:28 +05301426 strlcpy(mixer_xml_path, MIXER_XML_PATH_MTP,
1427 MAX_MIXER_XML_PATH);
1428 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
1429 msm_be_id_array_len =
1430 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
Walter Yang0a488e92017-02-13 21:02:39 +08001431 } else if (!strncmp(snd_card_name, "sdm660-snd-card-skush",
1432 sizeof("sdm660-snd-card-skush"))) {
1433 strlcpy(mixer_xml_path, MIXER_XML_PATH_SKUSH,
1434 MAX_MIXER_XML_PATH);
1435 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
1436 msm_be_id_array_len =
1437 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
Arusha Goyalfda29152016-12-26 10:53:39 +05301438 } else if (!strncmp(snd_card_name, "sdm660-tasha-snd-card",
1439 sizeof("sdm660-tasha-snd-card"))) {
Dhananjay Kumard3ab9f42016-07-20 17:05:47 +05301440 strlcpy(mixer_xml_path, MIXER_XML_PATH_WCD9335,
1441 sizeof(MIXER_XML_PATH_WCD9335));
1442 msm_device_to_be_id = msm_device_to_be_id_external_codec;
1443 msm_be_id_array_len =
1444 sizeof(msm_device_to_be_id_external_codec) / sizeof(msm_device_to_be_id_external_codec[0]);
Arusha Goyalfda29152016-12-26 10:53:39 +05301445 } else if (!strncmp(snd_card_name, "sdm660-tashalite-snd-card",
1446 sizeof("sdm660-tashalite-snd-card"))) {
Naresh Tanniru25873b82016-11-01 14:15:28 +05301447 strlcpy(mixer_xml_path, MIXER_XML_PATH_WCD9326,
1448 sizeof(MIXER_XML_PATH_WCD9326));
1449 msm_device_to_be_id = msm_device_to_be_id_external_codec;
1450 msm_be_id_array_len =
1451 sizeof(msm_device_to_be_id_external_codec) / sizeof(msm_device_to_be_id_external_codec[0]);
Walter Yangfd3f3252017-01-03 01:35:23 -08001452 } else if (!strncmp(snd_card_name, "sdm660-tasha-skus-snd-card",
1453 sizeof("sdm660-tasha-skus-snd-card"))) {
1454 strlcpy(mixer_xml_path, MIXER_XML_PATH_SKUS,
1455 sizeof(MIXER_XML_PATH_SKUS));
1456 msm_device_to_be_id = msm_device_to_be_id_external_codec;
1457 msm_be_id_array_len =
1458 sizeof(msm_device_to_be_id_external_codec) / sizeof(msm_device_to_be_id_external_codec[0]);
Arusha Goyalfda29152016-12-26 10:53:39 +05301459 } else if (!strncmp(snd_card_name, "sdm660-tavil-snd-card",
1460 sizeof("sdm660-tavil-snd-card"))) {
Naresh Tanniru25873b82016-11-01 14:15:28 +05301461 strlcpy(mixer_xml_path, MIXER_XML_PATH_WCD9340,
1462 sizeof(MIXER_XML_PATH_WCD9340));
1463 msm_device_to_be_id = msm_device_to_be_id_external_codec;
1464 msm_be_id_array_len =
1465 sizeof(msm_device_to_be_id_external_codec) / sizeof(msm_device_to_be_id_external_codec[0]);
Xiaojun Sangc30f0282016-07-18 11:22:09 +08001466 } else if (!strncmp(snd_card_name, "msm8920-sku7-snd-card",
1467 sizeof("msm8920-sku7-snd-card"))) {
1468 strlcpy(mixer_xml_path, MIXER_XML_PATH_SKU1,
1469 MAX_MIXER_XML_PATH);
1470 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
1471 msm_be_id_array_len =
1472 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
Yamit Mehtaa0d653a2016-11-25 20:33:25 +05301473 } else if (!strncmp(snd_card_name, "apq8009-tashalite-snd-card",
1474 sizeof("apq8009-tashalite-snd-card"))) {
1475 strlcpy(mixer_xml_path, MIXER_XML_PATH_WCD9326_I2S,
1476 MAX_MIXER_XML_PATH);
1477 msm_device_to_be_id = msm_device_to_be_id_external_codec;
1478 msm_be_id_array_len =
1479 sizeof(msm_device_to_be_id_external_codec) / sizeof(msm_device_to_be_id_external_codec[0]);
Surendar karka87fc59f2017-12-18 19:15:23 +05301480 } else if (!strncmp(snd_card_name, "apq8009-tashalite-snd-card-tdm",
1481 sizeof("apq8009-tashalite-snd-card-tdm"))) {
1482 strlcpy(mixer_xml_path, MIXER_XML_PATH_WCD9326_I2S_TDM,
1483 MAX_MIXER_XML_PATH);
1484 msm_device_to_be_id = msm_device_to_be_id_external_codec;
1485 msm_be_id_array_len =
1486 sizeof(msm_device_to_be_id_external_codec) / sizeof(msm_device_to_be_id_external_codec[0]);
Yamit Mehtaa0d653a2016-11-25 20:33:25 +05301487 } else if (!strncmp(snd_card_name, "mdm9607-tomtom-i2s-snd-card",
1488 sizeof("mdm9607-tomtom-i2s-snd-card"))) {
1489 strlcpy(mixer_xml_path, MIXER_XML_PATH_WCD9330_I2S,
1490 sizeof(MIXER_XML_PATH_WCD9330_I2S));
1491 msm_device_to_be_id = msm_device_to_be_id_external_codec;
1492 msm_be_id_array_len =
1493 sizeof(msm_device_to_be_id_external_codec) / sizeof(msm_device_to_be_id_external_codec[0]);
Siena Richard264ed052017-03-17 10:35:01 -07001494 } else if (!strncmp(snd_card_name, "mdm-tasha-i2s-snd-card",
1495 sizeof("mdm-tasha-i2s-snd-card"))) {
1496 strlcpy(mixer_xml_path, MIXER_XML_PATH_WCD9335_I2S,
1497 sizeof(MIXER_XML_PATH_WCD9335_I2S));
1498 msm_device_to_be_id = msm_device_to_be_id_external_codec;
1499 msm_be_id_array_len =
1500 sizeof(msm_device_to_be_id_external_codec) / sizeof(msm_device_to_be_id_external_codec[0]);
Asish Bhattacharya4ff24802014-04-24 17:46:54 +05301501 } else {
1502 strlcpy(mixer_xml_path, MIXER_XML_PATH,
1503 sizeof(MIXER_XML_PATH));
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -07001504
1505 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
1506 msm_be_id_array_len =
1507 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
1508
Asish Bhattacharya4ff24802014-04-24 17:46:54 +05301509 }
1510}
1511
Apoorv Raghuvanshi95333352015-07-06 15:07:14 -07001512void platform_set_echo_reference(struct audio_device *adev, bool enable,
Satya Krishna Pindiprolif1cd92b2016-04-14 19:05:23 +05301513 audio_devices_t out_device __unused)
Apoorv Raghuvanshi95333352015-07-06 15:07:14 -07001514{
1515 struct platform_data *my_data = (struct platform_data *)adev->platform;
Apoorv Raghuvanshi95333352015-07-06 15:07:14 -07001516
1517 if (strcmp(my_data->ec_ref_mixer_path, "")) {
1518 ALOGV("%s: disabling %s", __func__, my_data->ec_ref_mixer_path);
1519 audio_route_reset_and_update_path(adev->audio_route,
1520 my_data->ec_ref_mixer_path);
1521 }
1522
1523 if (enable) {
Apoorv Raghuvanshi95333352015-07-06 15:07:14 -07001524 if (adev->snd_dev_ref_cnt[SND_DEVICE_OUT_HEADPHONES_44_1] > 0)
1525 strlcpy(my_data->ec_ref_mixer_path, "echo-reference headphones-44.1",
1526 sizeof(my_data->ec_ref_mixer_path));
Leena Winterrowdd7a04cd2016-01-07 11:50:02 -08001527 else if (adev->snd_dev_ref_cnt[SND_DEVICE_OUT_SPEAKER_VBAT] > 0)
Apoorv Raghuvanshi95333352015-07-06 15:07:14 -07001528 strlcpy(my_data->ec_ref_mixer_path, "vbat-speaker echo-reference",
1529 sizeof(my_data->ec_ref_mixer_path));
1530 else
1531 strlcpy(my_data->ec_ref_mixer_path, "echo-reference",
1532 sizeof(my_data->ec_ref_mixer_path));
1533
1534
1535 ALOGD("%s: enabling %s", __func__, my_data->ec_ref_mixer_path);
1536 audio_route_apply_and_update_path(adev->audio_route,
1537 my_data->ec_ref_mixer_path);
1538 }
1539}
Banajit Goswami20cdd212015-09-11 01:11:30 -07001540void platform_set_gsm_mode(void *platform, bool enable)
1541{
1542 struct platform_data *my_data = (struct platform_data *)platform;
1543 struct audio_device *adev = my_data->adev;
1544
1545 if (my_data->gsm_mode_enabled) {
1546 my_data->gsm_mode_enabled = false;
1547 ALOGV("%s: disabling gsm mode", __func__);
1548 audio_route_reset_and_update_path(adev->audio_route, "gsm-mode");
1549 }
1550
1551 if (enable) {
1552 my_data->gsm_mode_enabled = true;
1553 ALOGD("%s: enabling gsm mode", __func__);
1554 audio_route_apply_and_update_path(adev->audio_route, "gsm-mode");
1555 }
1556}
1557
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301558void close_csd_client(struct csd_data *csd)
1559{
1560 if (csd != NULL) {
1561 csd->deinit();
1562 dlclose(csd->csd_client);
1563 free(csd);
1564 csd = NULL;
1565 }
1566}
1567
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301568
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05301569static void set_platform_defaults(struct platform_data * my_data)
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301570{
Naresh Tanniru34a303c2016-01-27 17:26:41 +05301571 int32_t dev, count = 0;
Naresh Tanniru34a303c2016-01-27 17:26:41 +05301572 const char *MEDIA_MIMETYPE_AUDIO_ALAC = "audio/alac";
1573 const char *MEDIA_MIMETYPE_AUDIO_APE = "audio/x-ape";
1574
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301575 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05301576 backend_tag_table[dev] = NULL;
1577 hw_interface_table[dev] = NULL;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301578 }
1579 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05301580 backend_bit_width_table[dev] = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301581 }
1582
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05301583 // To overwrite these go to the audio_platform_info.xml file.
1584 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("bt-sco");
1585 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("bt-sco-wb");
1586 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("bt-sco");
1587 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("bt-sco-wb");
Siddartha Shaik44dd7702017-06-14 12:13:25 +05301588 backend_tag_table[SND_DEVICE_IN_HDMI_MIC] = strdup("hdmi-mic");
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05301589 backend_tag_table[SND_DEVICE_OUT_BT_SCO] = strdup("bt-sco");
1590 backend_tag_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("bt-sco-wb");
1591 backend_tag_table[SND_DEVICE_OUT_HDMI] = strdup("hdmi");
1592 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("speaker-and-hdmi");
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07001593 backend_tag_table[SND_DEVICE_OUT_DISPLAY_PORT] = strdup("display-port");
1594 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_DISPLAY_PORT] = strdup("speaker-and-display-port");
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05301595 backend_tag_table[SND_DEVICE_OUT_VOICE_TX] = strdup("afe-proxy");
1596 backend_tag_table[SND_DEVICE_IN_VOICE_RX] = strdup("afe-proxy");
1597 backend_tag_table[SND_DEVICE_OUT_AFE_PROXY] = strdup("afe-proxy");
Ashish Jain3e37a702016-11-25 12:27:15 +05301598 backend_tag_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("usb-headset");
Aniket Kumar Lata3e2e1232017-06-16 17:25:07 -07001599 backend_tag_table[SND_DEVICE_OUT_VOICE_USB_HEADSET] = strdup("usb-headset");
Ashish Jain3e37a702016-11-25 12:27:15 +05301600 backend_tag_table[SND_DEVICE_OUT_USB_HEADPHONES] = strdup("usb-headphones");
Aniket Kumar Lata3e2e1232017-06-16 17:25:07 -07001601 backend_tag_table[SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = strdup("usb-headphones");
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05301602 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] =
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301603 strdup("speaker-and-usb-headphones");
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05301604 backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("usb-headset-mic");
Aniket Kumar Lata3e2e1232017-06-16 17:25:07 -07001605 backend_tag_table[SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1606 backend_tag_table[SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1607 backend_tag_table[SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1608 backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = strdup("usb-headset-mic");
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05301609 backend_tag_table[SND_DEVICE_IN_CAPTURE_FM] = strdup("capture-fm");
1610 backend_tag_table[SND_DEVICE_OUT_TRANSMISSION_FM] = strdup("transmission-fm");
Preetam Singh Ranawat3e5b9e72016-11-10 16:12:25 +05301611 backend_tag_table[SND_DEVICE_OUT_HEADPHONES_DSD] = strdup("headphones-dsd");
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05301612 backend_tag_table[SND_DEVICE_OUT_HEADPHONES_44_1] = strdup("headphones-44.1");
1613 backend_tag_table[SND_DEVICE_OUT_VOICE_SPEAKER_VBAT] = strdup("vbat-voice-speaker");
Rohit kumarf4120402016-08-05 19:19:48 +05301614 backend_tag_table[SND_DEVICE_OUT_VOICE_SPEAKER_2_VBAT] = strdup("vbat-voice-speaker-2");
Naresh Tanniru9d027a62015-03-13 01:32:10 +05301615 backend_tag_table[SND_DEVICE_OUT_BT_A2DP] = strdup("bt-a2dp");
1616 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] = strdup("speaker-and-bt-a2dp");
Preetam Singh Ranawat91132162017-03-13 20:32:03 +05301617 backend_tag_table[SND_DEVICE_OUT_VOICE_SPEAKER_AND_VOICE_HEADPHONES] = strdup("speaker-and-headphones");
1618 backend_tag_table[SND_DEVICE_OUT_VOICE_SPEAKER_AND_VOICE_ANC_HEADSET] = strdup("speaker-and-headphones");
Vikram Panduranga8c68e862018-04-27 12:59:42 -07001619 backend_tag_table[SND_DEVICE_OUT_VOICE_SPEAKER_STEREO_AND_VOICE_HEADPHONES] = strdup("speaker-and-headphones");
1620 backend_tag_table[SND_DEVICE_OUT_VOICE_SPEAKER_STEREO_AND_VOICE_ANC_HEADSET] = strdup("speaker-and-headphones");
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05301621
Siena Richard7c2db772016-12-21 11:32:34 -08001622 hw_interface_table[SND_DEVICE_OUT_HANDSET] = strdup("SLIMBUS_0_RX");
1623 hw_interface_table[SND_DEVICE_OUT_SPEAKER] = strdup("SLIMBUS_0_RX");
1624 hw_interface_table[SND_DEVICE_OUT_SPEAKER_EXTERNAL_1] = strdup("SLIMBUS_0_RX");
1625 hw_interface_table[SND_DEVICE_OUT_SPEAKER_EXTERNAL_2] = strdup("SLIMBUS_0_RX");
1626 hw_interface_table[SND_DEVICE_OUT_SPEAKER_REVERSE] = strdup("SLIMBUS_0_RX");
1627 hw_interface_table[SND_DEVICE_OUT_SPEAKER_VBAT] = strdup("SLIMBUS_0_RX");
1628 hw_interface_table[SND_DEVICE_OUT_LINE] = strdup("SLIMBUS_6_RX");
1629 hw_interface_table[SND_DEVICE_OUT_HEADPHONES] = strdup("SLIMBUS_6_RX");
Preetam Singh Ranawat3e5b9e72016-11-10 16:12:25 +05301630 hw_interface_table[SND_DEVICE_OUT_HEADPHONES_DSD] = strdup("SLIMBUS_2_RX");
1631 hw_interface_table[SND_DEVICE_OUT_HEADPHONES_44_1] = strdup("SLIMBUS_5_RX");
Siena Richard7c2db772016-12-21 11:32:34 -08001632 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = strdup("SLIMBUS_0_RX-and-SLIMBUS_6_RX");
Preetam Singh Ranawat91132162017-03-13 20:32:03 +05301633 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_AND_VOICE_HEADPHONES] = strdup("SLIMBUS_0_RX-and-SLIMBUS_6_RX");
1634 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_AND_VOICE_ANC_HEADSET] = strdup("SLIMBUS_0_RX-and-SLIMBUS_6_RX");
Vikram Panduranga8c68e862018-04-27 12:59:42 -07001635 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_STEREO_AND_VOICE_HEADPHONES] = strdup("SLIMBUS_0_RX-and-SLIMBUS_6_RX");
1636 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_STEREO_AND_VOICE_ANC_HEADSET] = strdup("SLIMBUS_0_RX-and-SLIMBUS_6_RX");
Siena Richard7c2db772016-12-21 11:32:34 -08001637 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_LINE] = strdup("SLIMBUS_0_RX-and-SLIMBUS_6_RX");
1638 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_1] = strdup("SLIMBUS_0_RX-and-SLIMBUS_6_RX");
1639 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_2] = strdup("SLIMBUS_0_RX-and-SLIMBUS_6_RX");
1640 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET] = strdup("SLIMBUS_0_RX");
1641 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER] = strdup("SLIMBUS_0_RX");
1642 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_VBAT] = strdup("SLIMBUS_0_RX");
1643 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_2] = strdup("SLIMBUS_0_RX");
1644 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_2_VBAT] = strdup("SLIMBUS_0_RX");
1645 hw_interface_table[SND_DEVICE_OUT_VOICE_HEADPHONES] = strdup("SLIMBUS_6_RX");
1646 hw_interface_table[SND_DEVICE_OUT_VOICE_LINE] = strdup("SLIMBUS_6_RX");
1647 hw_interface_table[SND_DEVICE_OUT_HDMI] = strdup("HDMI");
1648 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("SLIMBUS_0_RX-and-HDMI");
1649 hw_interface_table[SND_DEVICE_OUT_DISPLAY_PORT] = strdup("DISPLAY_PORT");
1650 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_DISPLAY_PORT] = strdup("SLIMBUS_0_RX-and-DISPLAY_PORT");
1651 hw_interface_table[SND_DEVICE_OUT_BT_SCO] = strdup("SLIMBUS_7_RX");
1652 hw_interface_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("SLIMBUS_7_RX");
1653 hw_interface_table[SND_DEVICE_OUT_BT_A2DP] = strdup("SLIMBUS_7_RX");
1654 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] = strdup("SLIMBUS_0_RX-and-SLIMBUS_7_RX");
1655 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = strdup("SLIMBUS_6_RX");
1656 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = strdup("SLIMBUS_6_RX");
1657 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = strdup("SLIMBUS_0_RX");
1658 hw_interface_table[SND_DEVICE_OUT_VOICE_TX] = strdup("RT_PROXY_DAI_001_RX");
1659 hw_interface_table[SND_DEVICE_OUT_AFE_PROXY] = strdup("RT_PROXY_DAI_001_RX");
Ashish Jainb26edfb2016-08-25 00:10:11 +05301660 hw_interface_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("USB_AUDIO_RX");
Aniket Kumar Lata3e2e1232017-06-16 17:25:07 -07001661 hw_interface_table[SND_DEVICE_OUT_VOICE_USB_HEADSET] = strdup("USB_AUDIO_RX");
Ashish Jain3e37a702016-11-25 12:27:15 +05301662 hw_interface_table[SND_DEVICE_OUT_USB_HEADPHONES] = strdup("USB_AUDIO_RX");
Aniket Kumar Lata3e2e1232017-06-16 17:25:07 -07001663 hw_interface_table[SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = strdup("USB_AUDIO_RX");
Ashish Jainb26edfb2016-08-25 00:10:11 +05301664 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 -08001665 hw_interface_table[SND_DEVICE_OUT_TRANSMISSION_FM] = strdup("SLIMBUS_8_TX");
1666 hw_interface_table[SND_DEVICE_OUT_ANC_HEADSET] = strdup("SLIMBUS_6_RX");
1667 hw_interface_table[SND_DEVICE_OUT_ANC_FB_HEADSET] = strdup("SLIMBUS_6_RX");
1668 hw_interface_table[SND_DEVICE_OUT_VOICE_ANC_HEADSET] = strdup("SLIMBUS_6_RX");
1669 hw_interface_table[SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET] = strdup("SLIMBUS_6_RX");
1670 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET] = strdup("SLIMBUS_0_RX-and-SLIMBUS_6_RX");
1671 hw_interface_table[SND_DEVICE_OUT_ANC_HANDSET] = strdup("SLIMBUS_0_RX");
Aditya Bavanari701a6992017-03-30 19:17:16 +05301672 hw_interface_table[SND_DEVICE_OUT_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
1673 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
1674 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_2_PROTECTED] = strdup("SLIMBUS_0_RX");
Vikram Panduranga8c68e862018-04-27 12:59:42 -07001675 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_STEREO_PROTECTED] = strdup("SLIMBUS_0_RX");
Aditya Bavanari701a6992017-03-30 19:17:16 +05301676 hw_interface_table[SND_DEVICE_OUT_SPEAKER_PROTECTED_VBAT] = strdup("SLIMBUS_0_RX");
1677 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED_VBAT] = strdup("SLIMBUS_0_RX");
1678 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_2_PROTECTED_VBAT] = strdup("SLIMBUS_0_RX");
Siena Richard7c2db772016-12-21 11:32:34 -08001679 hw_interface_table[SND_DEVICE_OUT_SPEAKER_WSA] = strdup("SLIMBUS_0_RX");
1680 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_WSA] = strdup("SLIMBUS_0_RX");
1681 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_2_WSA] = strdup("SLIMBUS_0_RX");
Siena Richard7c2db772016-12-21 11:32:34 -08001682 hw_interface_table[SND_DEVICE_OUT_VOIP_HANDSET] = strdup("SLIMBUS_0_RX");
1683 hw_interface_table[SND_DEVICE_OUT_VOIP_SPEAKER] = strdup("SLIMBUS_0_RX");
1684 hw_interface_table[SND_DEVICE_OUT_VOIP_HEADPHONES] = strdup("SLIMBUS_6_RX");
Siena Richard7c2db772016-12-21 11:32:34 -08001685 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC] = strdup("SLIMBUS_0_TX");
1686 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_EXTERNAL] = strdup("SLIMBUS_0_TX");
1687 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_AEC] = strdup("SLIMBUS_0_TX");
1688 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_NS] = strdup("SLIMBUS_0_TX");
1689 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1690 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC] = strdup("SLIMBUS_0_TX");
1691 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_AEC] = strdup("SLIMBUS_0_TX");
1692 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_NS] = strdup("SLIMBUS_0_TX");
1693 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1694 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC] = strdup("SLIMBUS_0_TX");
1695 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_AEC] = strdup("SLIMBUS_0_TX");
1696 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_NS] = strdup("SLIMBUS_0_TX");
1697 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1698 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC] = strdup("SLIMBUS_0_TX");
1699 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_AEC] = strdup("SLIMBUS_0_TX");
1700 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_NS] = strdup("SLIMBUS_0_TX");
1701 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1702 hw_interface_table[SND_DEVICE_IN_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1703 hw_interface_table[SND_DEVICE_IN_HEADSET_MIC_FLUENCE] = strdup("SLIMBUS_0_TX");
1704 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_MIC] = strdup("SLIMBUS_0_TX");
1705 hw_interface_table[SND_DEVICE_IN_VOICE_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1706 hw_interface_table[SND_DEVICE_IN_HDMI_MIC] = strdup("HDMI");
1707 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("SLIMBUS_7_TX");
1708 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("SLIMBUS_7_TX");
1709 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("SLIMBUS_7_TX");
1710 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("SLIMBUS_7_TX");
1711 hw_interface_table[SND_DEVICE_IN_CAMCORDER_MIC] = strdup("SLIMBUS_0_TX");
1712 hw_interface_table[SND_DEVICE_IN_VOICE_DMIC] = strdup("SLIMBUS_0_TX");
1713 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = strdup("SLIMBUS_0_TX");
Vikram Pandurangaf0ca0b12018-05-04 16:00:07 -07001714 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_TMIC] = strdup("SLIMBUS_0_TX");
Siena Richard7c2db772016-12-21 11:32:34 -08001715 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_QMIC] = strdup("SLIMBUS_0_TX");
1716 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1717 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = strdup("SLIMBUS_0_TX");
1718 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1719 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC] = strdup("SLIMBUS_0_TX");
1720 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC_NS] = strdup("SLIMBUS_0_TX");
1721 hw_interface_table[SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
1722 hw_interface_table[SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = strdup("SLIMBUS_0_TX");
1723 hw_interface_table[SND_DEVICE_IN_VOICE_RX] = strdup("RT_PROXY_DAI_002_TX");
1724 hw_interface_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1725 hw_interface_table[SND_DEVICE_IN_CAPTURE_FM] = strdup("SLIMBUS_8_TX");
1726 hw_interface_table[SND_DEVICE_IN_AANC_HANDSET_MIC] = strdup("SLIMBUS_0_TX");
1727 hw_interface_table[SND_DEVICE_IN_QUAD_MIC] = strdup("SLIMBUS_0_TX");
1728 hw_interface_table[SND_DEVICE_IN_HANDSET_STEREO_DMIC] = strdup("SLIMBUS_0_TX");
1729 hw_interface_table[SND_DEVICE_IN_SPEAKER_STEREO_DMIC] = strdup("SLIMBUS_0_TX");
1730 hw_interface_table[SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = strdup("SLIMBUS_4_TX");
1731 hw_interface_table[SND_DEVICE_IN_CAPTURE_VI_FEEDBACK_MONO_1] = strdup("SLIMBUS_4_TX");
1732 hw_interface_table[SND_DEVICE_IN_CAPTURE_VI_FEEDBACK_MONO_2] = strdup("SLIMBUS_4_TX");
1733 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BROADSIDE] = strdup("SLIMBUS_0_TX");
1734 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_BROADSIDE] = strdup("SLIMBUS_0_TX");
1735 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_AEC_BROADSIDE] = strdup("SLIMBUS_0_TX");
1736 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_NS_BROADSIDE] = strdup("SLIMBUS_0_TX");
1737 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_BROADSIDE] = strdup("SLIMBUS_0_TX");
1738 hw_interface_table[SND_DEVICE_IN_VOICE_FLUENCE_DMIC_AANC] = strdup("SLIMBUS_0_TX");
1739 hw_interface_table[SND_DEVICE_IN_HANDSET_QMIC] = strdup("SLIMBUS_0_TX");
1740 hw_interface_table[SND_DEVICE_IN_SPEAKER_QMIC_AEC] = strdup("SLIMBUS_0_TX");
1741 hw_interface_table[SND_DEVICE_IN_SPEAKER_QMIC_NS] = strdup("SLIMBUS_0_TX");
1742 hw_interface_table[SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1743 hw_interface_table[SND_DEVICE_IN_THREE_MIC] = strdup("SLIMBUS_0_TX");
Vikram Pandurangab1e26aa2018-06-21 17:28:20 -07001744 hw_interface_table[SND_DEVICE_IN_HANDSET_TMIC_FLUENCE_PRO] = strdup("SLIMBUS_0_TX");
Siena Richard7c2db772016-12-21 11:32:34 -08001745 hw_interface_table[SND_DEVICE_IN_HANDSET_TMIC] = strdup("SLIMBUS_0_TX");
Vikram Pandurangaf0ca0b12018-05-04 16:00:07 -07001746 hw_interface_table[SND_DEVICE_IN_SPEAKER_TMIC_AEC] = strdup("SLIMBUS_0_TX");
1747 hw_interface_table[SND_DEVICE_IN_SPEAKER_TMIC_NS] = strdup("SLIMBUS_0_TX");
1748 hw_interface_table[SND_DEVICE_IN_SPEAKER_TMIC_AEC_NS] = strdup("SLIMBUS_0_TX");
Siena Richard7c2db772016-12-21 11:32:34 -08001749 hw_interface_table[SND_DEVICE_IN_VOICE_REC_TMIC] = strdup("SLIMBUS_0_TX");
1750 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_MIC] = strdup("SLIMBUS_0_TX");
1751 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = strdup("SLIMBUS_0_TX");
1752 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = strdup("SLIMBUS_0_TX");
1753 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = strdup("SLIMBUS_0_TX");
1754 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
Dhananjay Kumar704ce6f2017-09-28 22:08:00 +05301755 hw_interface_table[SND_DEVICE_IN_HANDSET_GENERIC_QMIC] = strdup("SLIMBUS_0_TX");
Divya Narayanan Poojary85d0a592018-02-06 14:25:16 +05301756 hw_interface_table[SND_DEVICE_IN_INCALL_REC_RX] = strdup("INCALL_RECORD_RX");
1757 hw_interface_table[SND_DEVICE_IN_INCALL_REC_TX] = strdup("INCALL_RECORD_TX");
Ramu Gottipati813ae982018-07-25 14:14:48 +05301758 hw_interface_table[SND_DEVICE_IN_LINE] = strdup("SLIMBUS_0_TX");
Naresh Tanniru34a303c2016-01-27 17:26:41 +05301759
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05301760 my_data->max_mic_count = PLATFORM_DEFAULT_MIC_COUNT;
Naresh Tanniru34a303c2016-01-27 17:26:41 +05301761 /*remove ALAC & APE from DSP decoder list based on software decoder availability*/
Alexy Josephb1379942016-01-29 15:49:38 -08001762 for (count = 0; count < (int32_t) (sizeof(dsp_only_decoders_mime)/sizeof(dsp_only_decoders_mime[0]));
Naresh Tanniru34a303c2016-01-27 17:26:41 +05301763 count++) {
1764
1765 if (!strncmp(MEDIA_MIMETYPE_AUDIO_ALAC, dsp_only_decoders_mime[count],
1766 strlen(dsp_only_decoders_mime[count]))) {
1767
Aniket Kumar Lata8fc67e62017-05-02 12:33:46 -07001768 if(property_get_bool("vendor.audio.use.sw.alac.decoder", false)) {
Naresh Tanniru34a303c2016-01-27 17:26:41 +05301769 ALOGD("Alac software decoder is available...removing alac from DSP decoder list");
Preetam Singh Ranawat53194302016-03-15 16:37:42 +05301770 strlcpy(dsp_only_decoders_mime[count],"none",5);
Naresh Tanniru34a303c2016-01-27 17:26:41 +05301771 }
1772 } else if (!strncmp(MEDIA_MIMETYPE_AUDIO_APE, dsp_only_decoders_mime[count],
1773 strlen(dsp_only_decoders_mime[count]))) {
1774
Aniket Kumar Lata8fc67e62017-05-02 12:33:46 -07001775 if(property_get_bool("vendor.audio.use.sw.ape.decoder", false)) {
Naresh Tanniru34a303c2016-01-27 17:26:41 +05301776 ALOGD("APE software decoder is available...removing ape from DSP decoder list");
Preetam Singh Ranawat53194302016-03-15 16:37:42 +05301777 strlcpy(dsp_only_decoders_mime[count],"none",5);
Naresh Tanniru34a303c2016-01-27 17:26:41 +05301778 }
1779 }
1780 }
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301781}
1782
Avinash Vaish71c066d2014-08-27 12:32:35 +05301783void get_cvd_version(char *cvd_version, struct audio_device *adev)
1784{
1785 struct mixer_ctl *ctl;
1786 int count;
1787 int ret = 0;
1788
1789 ctl = mixer_get_ctl_by_name(adev->mixer, CVD_VERSION_MIXER_CTL);
1790 if (!ctl) {
1791 ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__, CVD_VERSION_MIXER_CTL);
1792 goto done;
1793 }
1794 mixer_ctl_update(ctl);
1795
1796 count = mixer_ctl_get_num_values(ctl);
1797 if (count > MAX_CVD_VERSION_STRING_SIZE)
1798 count = MAX_CVD_VERSION_STRING_SIZE;
1799
1800 ret = mixer_ctl_get_array(ctl, cvd_version, count);
1801 if (ret != 0) {
1802 ALOGE("%s: ERROR! mixer_ctl_get_array() failed to get CVD Version", __func__);
1803 goto done;
1804 }
1805
1806done:
1807 return;
1808}
1809
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +05301810static int hw_util_open(int card_no)
1811{
1812 int fd = -1;
1813 char dev_name[256];
1814
1815 snprintf(dev_name, sizeof(dev_name), "/dev/snd/hwC%uD%u",
1816 card_no, WCD9XXX_CODEC_HWDEP_NODE);
1817 ALOGD("%s Opening device %s\n", __func__, dev_name);
1818 fd = open(dev_name, O_WRONLY);
1819 if (fd < 0) {
1820 ALOGE("%s: cannot open device '%s'\n", __func__, dev_name);
1821 return fd;
1822 }
1823 ALOGD("%s success", __func__);
1824 return fd;
1825}
1826
1827struct param_data {
1828 int use_case;
1829 int acdb_id;
1830 int get_size;
1831 int buff_size;
1832 int data_size;
1833 void *buff;
1834};
1835
Banajit Goswami20cdd212015-09-11 01:11:30 -07001836static int send_vbat_adc_data_to_acdb(struct platform_data *plat_data, char *cal_type)
1837{
1838 int ret = 0;
1839 struct mixer_ctl *ctl;
1840 uint16_t vbat_adc_data[2];
1841 struct platform_data *my_data = plat_data;
1842 struct audio_device *adev = my_data->adev;
1843
1844 const char *mixer_ctl_name = "Vbat ADC data";
1845
1846 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1847 if (!ctl) {
1848 ALOGE("%s: Could not get ctl for mixer ctl name - %s",
1849 __func__, mixer_ctl_name);
1850 ret = -EINVAL;
1851 goto done;
1852 }
1853
1854 vbat_adc_data[0] = mixer_ctl_get_value(ctl, 0);
1855 vbat_adc_data[1] = mixer_ctl_get_value(ctl, 1);
1856
1857 ALOGD("%s: Vbat ADC output values: Dcp1: %d , Dcp2: %d",
1858 __func__, vbat_adc_data[0], vbat_adc_data[1]);
1859
1860 ret = my_data->acdb_set_codec_data(&vbat_adc_data[0], cal_type);
1861
1862done:
1863 return ret;
1864}
1865
Venkata Narendra Kumar Guttae071e5a2016-01-11 18:08:26 +05301866static void send_codec_cal(acdb_loader_get_calibration_t acdb_loader_get_calibration,
Banajit Goswami20cdd212015-09-11 01:11:30 -07001867 struct platform_data *plat_data, int fd)
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +05301868{
Venkata Narendra Kumar Guttae071e5a2016-01-11 18:08:26 +05301869 int type;
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +05301870
1871 for (type = WCD9XXX_ANC_CAL; type < WCD9XXX_MAX_CAL; type++) {
1872 struct wcdcal_ioctl_buffer codec_buffer;
1873 struct param_data calib;
Venkata Narendra Kumar Guttae071e5a2016-01-11 18:08:26 +05301874 int ret;
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +05301875
Bharath Ramachandramurthy63a47ef2015-08-31 17:41:46 -07001876 /* MAD calibration is handled by sound trigger HAL, skip here */
1877 if (type == WCD9XXX_MAD_CAL)
1878 continue;
1879
Banajit Goswami20cdd212015-09-11 01:11:30 -07001880 if((plat_data->is_vbat_speaker) && (WCD9XXX_VBAT_CAL == type)) {
1881 ret = send_vbat_adc_data_to_acdb(plat_data, cal_name_info[type]);
1882 if (ret < 0)
1883 ALOGE("%s error in sending vbat adc data to acdb", __func__);
1884 }
1885
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +05301886 calib.get_size = 1;
1887 ret = acdb_loader_get_calibration(cal_name_info[type], sizeof(struct param_data),
1888 &calib);
1889 if (ret < 0) {
1890 ALOGE("%s get_calibration failed\n", __func__);
Venkata Narendra Kumar Guttae071e5a2016-01-11 18:08:26 +05301891 continue;
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +05301892 }
1893 calib.get_size = 0;
1894 calib.buff = malloc(calib.buff_size);
Sidipotu Ashok04ab3d32014-12-30 10:28:31 +05301895 if(calib.buff == NULL) {
1896 ALOGE("%s mem allocation for %d bytes for %s failed\n"
1897 , __func__, calib.buff_size, cal_name_info[type]);
Venkata Narendra Kumar Guttae071e5a2016-01-11 18:08:26 +05301898 continue;
Sidipotu Ashok04ab3d32014-12-30 10:28:31 +05301899 }
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +05301900 ret = acdb_loader_get_calibration(cal_name_info[type],
1901 sizeof(struct param_data), &calib);
1902 if (ret < 0) {
Sidipotu Ashok04ab3d32014-12-30 10:28:31 +05301903 ALOGE("%s get_calibration failed type=%s calib.size=%d\n"
Preetam Singh Ranawat53194302016-03-15 16:37:42 +05301904 , __func__, cal_name_info[type], calib.buff_size);
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +05301905 free(calib.buff);
Venkata Narendra Kumar Guttae071e5a2016-01-11 18:08:26 +05301906 continue;
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +05301907 }
1908 codec_buffer.buffer = calib.buff;
1909 codec_buffer.size = calib.data_size;
1910 codec_buffer.cal_type = type;
1911 if (ioctl(fd, SNDRV_CTL_IOCTL_HWDEP_CAL_TYPE, &codec_buffer) < 0)
Sidipotu Ashok04ab3d32014-12-30 10:28:31 +05301912 ALOGE("Failed to call ioctl for %s err=%d calib.size=%d",
1913 cal_name_info[type], errno, codec_buffer.size);
1914 ALOGD("%s cal sent for %s calib.size=%d"
1915 , __func__, cal_name_info[type], codec_buffer.size);
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +05301916 free(calib.buff);
1917 }
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +05301918}
1919
1920static void audio_hwdep_send_cal(struct platform_data *plat_data)
1921{
Venkata Narendra Kumar Guttae071e5a2016-01-11 18:08:26 +05301922 int fd = plat_data->hw_dep_fd;
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +05301923
Venkata Narendra Kumar Guttae071e5a2016-01-11 18:08:26 +05301924 if (fd < 0)
1925 fd = hw_util_open(plat_data->adev->snd_card);
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +05301926 if (fd == -1) {
1927 ALOGE("%s error open\n", __func__);
1928 return;
1929 }
1930
1931 acdb_loader_get_calibration = (acdb_loader_get_calibration_t)
1932 dlsym(plat_data->acdb_handle, "acdb_loader_get_calibration");
1933
1934 if (acdb_loader_get_calibration == NULL) {
1935 ALOGE("%s: ERROR. dlsym Error:%s acdb_loader_get_calibration", __func__,
1936 dlerror());
Venkata Narendra Kumar Guttae071e5a2016-01-11 18:08:26 +05301937 if (fd >= 0) {
1938 close(fd);
1939 plat_data->hw_dep_fd = -1;
1940 }
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +05301941 return;
1942 }
Venkata Narendra Kumar Guttae071e5a2016-01-11 18:08:26 +05301943
1944 send_codec_cal(acdb_loader_get_calibration, plat_data, fd);
1945 plat_data->hw_dep_fd = fd;
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +05301946}
1947
Aditya Bavanari4875a262019-01-17 19:39:59 +05301948const char * platform_get_snd_card_name_for_acdb_loader(const char *snd_card_name)
1949{
1950 const char *acdb_card_name = NULL;
1951 char *substring = NULL;
1952 char string[MAX_SND_CARD_NAME_LENGTH] = {0};
1953 int length = 0;
Naresh Tanniru516c2452015-08-14 12:58:24 +05301954
Aditya Bavanari4875a262019-01-17 19:39:59 +05301955 if (snd_card_name == NULL)
Naresh Tanniru516c2452015-08-14 12:58:24 +05301956 return NULL;
1957
Aditya Bavanari4875a262019-01-17 19:39:59 +05301958 /* Both tasha & tasha-lite uses tasha ACDB files
1959 simulate sound card name for tasha lite, so that
1960 ACDB module loads tasha ACDB files for tasha lite */
1961 if ((substring = strstr(snd_card_name, "tashalite")) ||
1962 (substring = strstr(snd_card_name, "tasha9326"))) {
1963 ALOGD("%s: using tasha ACDB files for tasha-lite", __func__);
1964 length = substring - snd_card_name + 1;
1965 snprintf(string, length, "%s", snd_card_name);
1966 strlcat(string, "tasha-snd-card", sizeof(string));
1967 acdb_card_name = strdup(string);
1968 return acdb_card_name;
Naresh Tanniru4d1e1a12015-12-16 19:37:50 +05301969 }
Aditya Bavanari4875a262019-01-17 19:39:59 +05301970 acdb_card_name = strdup(snd_card_name);
1971 return acdb_card_name;
Naresh Tanniru516c2452015-08-14 12:58:24 +05301972}
1973
Naresh Tanniru516c2452015-08-14 12:58:24 +05301974int platform_acdb_init(void *platform)
Ramjee Singh203473b2015-06-09 15:18:42 +05301975{
1976 struct platform_data *my_data = (struct platform_data *)platform;
1977 char *cvd_version = NULL;
Aditya Bavanari71b6d532018-01-16 17:48:08 +05301978 const char *snd_card_name;
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05301979 int result = -1;
1980 struct listnode *node;
1981 struct meta_key_list *key_info;
1982 int key = 0;
1983
Ramjee Singh203473b2015-06-09 15:18:42 +05301984 cvd_version = calloc(1, MAX_CVD_VERSION_STRING_SIZE);
Preetam Singh Ranawat6746b7a2016-07-18 16:40:24 +05301985 if (!cvd_version) {
Ramjee Singh203473b2015-06-09 15:18:42 +05301986 ALOGE("Failed to allocate cvd version");
Preetam Singh Ranawat6746b7a2016-07-18 16:40:24 +05301987 return -1;
1988 } else {
Ramjee Singh203473b2015-06-09 15:18:42 +05301989 get_cvd_version(cvd_version, my_data->adev);
Preetam Singh Ranawat6746b7a2016-07-18 16:40:24 +05301990 }
Ramjee Singh203473b2015-06-09 15:18:42 +05301991
Ramjee Singh203473b2015-06-09 15:18:42 +05301992 snd_card_name = mixer_get_name(my_data->adev->mixer);
Aditya Bavanari71b6d532018-01-16 17:48:08 +05301993 snd_card_name = platform_get_snd_card_name_for_acdb_loader(snd_card_name);
Weiyin Jiang29c08a42019-04-30 17:11:10 +08001994 if (!snd_card_name) {
1995 ALOGE("Failed to get snd_card_name");
1996 goto cleanup;
1997 }
Naresh Tanniru516c2452015-08-14 12:58:24 +05301998
Aditya Bavanari29bcea22017-10-03 20:10:35 +05301999 my_data->acdb_init_data.cvd_version = cvd_version;
2000 my_data->acdb_init_data.snd_card_name = strdup(snd_card_name);
2001 my_data->acdb_init_data.meta_key_list = &my_data->acdb_meta_key_list;
2002 if (my_data->acdb_init_v4) {
2003 result = my_data->acdb_init_v4(&my_data->acdb_init_data, ACDB_LOADER_INIT_V4);
2004 } else if (my_data->acdb_init_v3) {
Aditya Bavanari71b6d532018-01-16 17:48:08 +05302005 result = my_data->acdb_init_v3(snd_card_name, cvd_version,
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05302006 &my_data->acdb_meta_key_list);
2007 } else if (my_data->acdb_init) {
2008 node = list_head(&my_data->acdb_meta_key_list);
2009 key_info = node_to_item(node, struct meta_key_list, list);
2010 key = key_info->cal_info.nKey;
Aditya Bavanari71b6d532018-01-16 17:48:08 +05302011 result = my_data->acdb_init(snd_card_name, cvd_version, key);
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05302012 }
Karthik Reddy Katta8513f432016-04-12 14:29:27 +05302013 /* Save these variables in platform_data. These will be used
2014 while reloading ACDB files during run time. */
2015 strlcpy(my_data->cvd_version, cvd_version, MAX_CVD_VERSION_STRING_SIZE);
Aditya Bavanari71b6d532018-01-16 17:48:08 +05302016 strlcpy(my_data->snd_card_name, snd_card_name,
Karthik Reddy Katta8513f432016-04-12 14:29:27 +05302017 MAX_SND_CARD_STRING_SIZE);
Karthik Reddy Katta8513f432016-04-12 14:29:27 +05302018
Weiyin Jiang29c08a42019-04-30 17:11:10 +08002019cleanup:
Ramjee Singh203473b2015-06-09 15:18:42 +05302020 if (cvd_version)
2021 free(cvd_version);
2022 if (!result) {
2023 my_data->is_acdb_initialized = true;
2024 ALOGD("ACDB initialized");
2025 audio_hwdep_send_cal(my_data);
2026 } else {
2027 my_data->is_acdb_initialized = false;
2028 ALOGD("ACDB initialization failed");
2029 }
2030 return result;
2031}
2032
Preetam Singh Ranawat9519e9c2015-11-18 16:05:55 +05302033#define MAX_PATH (256)
2034#define THERMAL_SYSFS "/sys/class/thermal"
2035#define TZ_TYPE "/sys/class/thermal/thermal_zone%d/type"
2036#define TZ_WSA "/sys/class/thermal/thermal_zone%d/temp"
2037
Naresh Tanniru74a2eee2016-02-10 13:38:19 +05302038static bool check_and_get_wsa_info(char *snd_card_name, int *wsaCount,
2039 bool *is_wsa_combo_supported)
Preetam Singh Ranawat9519e9c2015-11-18 16:05:55 +05302040{
2041 DIR *tdir = NULL;
2042 struct dirent *tdirent = NULL;
2043 int tzn = 0;
2044 char name[MAX_PATH] = {0};
2045 char cwd[MAX_PATH] = {0};
2046 char file[10] = "wsa";
2047 bool found = false;
2048 int wsa_count = 0;
2049
Naresh Tanniru25873b82016-11-01 14:15:28 +05302050 /* SL/SH hardware always has wsa by default, no need to add wsa */
Preetam Singh Ranawat76bb8632017-01-30 19:46:03 +05302051 if(snd_card_name && !strncmp(snd_card_name, "sdm660", strlen("sdm660"))) {
Arusha Goyalfda29152016-12-26 10:53:39 +05302052 ALOGD(" Ignore WSA extension for sdm 660 varients");
Naresh Tanniru25873b82016-11-01 14:15:28 +05302053 return false;
2054 }
2055
Preetam Singh Ranawat9519e9c2015-11-18 16:05:55 +05302056 if (!getcwd(cwd, sizeof(cwd)))
2057 return false;
2058
2059 chdir(THERMAL_SYSFS); /* Change dir to read the entries. Doesnt work
2060 otherwise */
2061 tdir = opendir(THERMAL_SYSFS);
2062 if (!tdir) {
2063 ALOGE("Unable to open %s\n", THERMAL_SYSFS);
2064 return false;
2065 }
2066
2067 while ((tdirent = readdir(tdir))) {
Preetam Singh Ranawat9519e9c2015-11-18 16:05:55 +05302068 struct dirent *tzdirent;
2069 DIR *tzdir = NULL;
2070
2071 tzdir = opendir(tdirent->d_name);
2072 if (!tzdir)
2073 continue;
2074 while ((tzdirent = readdir(tzdir))) {
Soumya Managoli148ec932018-04-05 17:32:42 +05302075 char buf[50] = {0};
Preetam Singh Ranawat9519e9c2015-11-18 16:05:55 +05302076 if (strcmp(tzdirent->d_name, "type"))
2077 continue;
2078 snprintf(name, MAX_PATH, TZ_TYPE, tzn);
2079 ALOGD("Opening %s\n", name);
2080 read_line_from_file(name, buf, sizeof(buf));
2081 if (strstr(buf, file)) {
2082 wsa_count++;
Preetam Singh Ranawat9519e9c2015-11-18 16:05:55 +05302083 }
2084 tzn++;
Soumya Managoli148ec932018-04-05 17:32:42 +05302085 /*We support max only two WSA speakers*/
2086 if (wsa_count == 2)
2087 break;
Preetam Singh Ranawat9519e9c2015-11-18 16:05:55 +05302088 }
2089 closedir(tzdir);
2090 }
2091 if (wsa_count > 0){
2092 ALOGD("Found %d WSA present on the platform", wsa_count);
2093 found = true;
2094 *wsaCount = wsa_count;
Naresh Tanniru74a2eee2016-02-10 13:38:19 +05302095
2096 /* update wsa combo supported flag based on sound card name */
2097 /* wsa combo flag needs to be set to true only for hardware
2098 combinations which has support for both wsa and non-wsa speaker */
Preetam Singh Ranawat53194302016-03-15 16:37:42 +05302099 *is_wsa_combo_supported = false;
2100 if(snd_card_name) {
2101 if ((!strncmp(snd_card_name, "msm8953-snd-card-mtp",
2102 sizeof("msm8953-snd-card-mtp")) ||
Xiaojun Sang2103fbd2018-03-05 13:41:39 +08002103 (!strncmp(snd_card_name, "msm8953-sku4-snd-card",
2104 sizeof("msm8953-sku4-snd-card"))) ||
Xiaojun Sang172e0fa2018-04-02 17:27:15 +08002105 (!strncmp(snd_card_name, "sdm439-sku1-snd-card",
2106 sizeof("sdm439-sku1-snd-card"))) ||
2107 (!strncmp(snd_card_name, "sdm439-snd-card-mtp",
2108 sizeof("sdm439-snd-card-mtp"))) ||
Preetam Singh Ranawat53194302016-03-15 16:37:42 +05302109 (!strncmp(snd_card_name, "msm8952-skum-snd-card",
2110 sizeof("msm8952-skum-snd-card"))))) {
2111 *is_wsa_combo_supported = true;
2112 }
Naresh Tanniru74a2eee2016-02-10 13:38:19 +05302113 }
Preetam Singh Ranawat9519e9c2015-11-18 16:05:55 +05302114 }
2115 closedir(tdir);
2116 chdir(cwd); /* Restore current working dir */
2117 return found;
2118}
2119
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05302120static void get_source_mic_type(struct platform_data * my_data)
2121{
2122 // support max to mono, example if max count is 3, usecase supports Three, dual and mono mic
2123 switch (my_data->max_mic_count) {
Garmond Leunge2433c32017-09-28 21:51:22 -07002124 case 6:
2125 my_data->source_mic_type |= SOURCE_HEX_MIC;
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05302126 case 4:
2127 my_data->source_mic_type |= SOURCE_QUAD_MIC;
2128 case 3:
2129 my_data->source_mic_type |= SOURCE_THREE_MIC;;
2130 case 2:
2131 my_data->source_mic_type |= SOURCE_DUAL_MIC;
2132 case 1:
2133 my_data->source_mic_type |= SOURCE_MONO_MIC;
2134 break;
2135 default:
2136 ALOGE("%s: max_mic_count (%d), is not supported, setting to default",
2137 __func__, my_data->max_mic_count);
2138 my_data->source_mic_type = SOURCE_MONO_MIC | SOURCE_DUAL_MIC;
2139 break;
2140 }
2141}
2142
Siena Richard7c2db772016-12-21 11:32:34 -08002143/*
2144 * Retrieves the be_dai_name_table from kernel to enable a mapping
2145 * between sound device hw interfaces and backend IDs. This allows HAL to
2146 * specify the backend a specific calibration is needed for.
2147 */
2148static int init_be_dai_name_table(struct audio_device *adev)
2149{
2150 const char *mixer_ctl_name = "Backend DAI Name Table";
2151 struct mixer_ctl *ctl;
2152 int i, j, ret, size;
2153 bool valid_hw_interface;
2154
2155 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2156 if (!ctl) {
2157 ALOGE("%s: Could not get ctl for mixer name %s\n",
2158 __func__, mixer_ctl_name);
2159 ret = -EINVAL;
2160 goto done;
2161 }
2162
2163 mixer_ctl_update(ctl);
2164
2165 size = mixer_ctl_get_num_values(ctl);
2166 if (size <= 0){
2167 ALOGE("%s: Failed to get %s size %d\n",
2168 __func__, mixer_ctl_name, size);
2169 ret = -EFAULT;
2170 goto done;
2171 }
2172
2173 be_dai_name_table =
2174 (const struct be_dai_name_struct *)calloc(1, size);
2175 if (be_dai_name_table == NULL) {
2176 ALOGE("%s: Failed to allocate memory for %s\n",
2177 __func__, mixer_ctl_name);
2178 ret = -ENOMEM;
2179 goto freeMem;
2180 }
2181
2182 ret = mixer_ctl_get_array(ctl, (void *)be_dai_name_table, size);
2183 if (ret) {
2184 ALOGE("%s: Failed to get %s, ret %d\n",
2185 __func__, mixer_ctl_name, ret);
2186 ret = -EFAULT;
2187 goto freeMem;
2188 }
2189
2190 if (be_dai_name_table != NULL) {
2191 max_be_dai_names = size / sizeof(struct be_dai_name_struct);
2192 ALOGV("%s: Successfully got %s, number of be dais is %d\n",
2193 __func__, mixer_ctl_name, max_be_dai_names);
2194 ret = 0;
2195 } else {
2196 ALOGE("%s: Failed to get %s\n", __func__, mixer_ctl_name);
2197 ret = -EFAULT;
2198 goto freeMem;
2199 }
2200
2201 /*
2202 * Validate all sound devices have a valid backend set to catch
2203 * errors for uncommon sound devices
2204 */
2205 for (i = 0; i < SND_DEVICE_MAX; i++) {
2206 valid_hw_interface = false;
2207
2208 if (hw_interface_table[i] == NULL) {
2209 ALOGW("%s: sound device %s has no hw interface set\n",
2210 __func__, platform_get_snd_device_name(i));
2211 continue;
2212 }
2213
2214 for (j = 0; j < max_be_dai_names; j++) {
2215 if (strcmp(hw_interface_table[i], be_dai_name_table[j].be_name)
2216 == 0) {
2217 valid_hw_interface = true;
2218 break;
2219 }
2220 }
2221 if (!valid_hw_interface)
2222 ALOGD("%s: sound device %s does not have a valid hw interface set (disregard for combo devices) %s\n",
2223 __func__, platform_get_snd_device_name(i), hw_interface_table[i]);
2224 }
2225
2226 goto done;
2227
2228freeMem:
2229 if (be_dai_name_table) {
2230 free((void *)be_dai_name_table);
2231 be_dai_name_table = NULL;
2232 }
2233
2234done:
2235 return ret;
2236}
2237
Naresh Tannirue3b18452014-03-04 14:44:27 +05302238void *platform_init(struct audio_device *adev)
2239{
2240 char value[PROPERTY_VALUE_MAX];
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302241 struct platform_data *my_data = NULL;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07002242 int snd_card_num = 0;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302243 const char *snd_card_name;
Yeleswarapu Nagaradhesh09f30be2015-07-22 14:11:03 +05302244 char mixer_xml_path[MAX_MIXER_XML_PATH],ffspEnable[PROPERTY_VALUE_MAX];
Satish Babu Patakokilabbd4e9d2015-05-13 22:08:06 +05302245 const char *mixer_ctl_name = "Set HPX ActiveBe";
2246 struct mixer_ctl *ctl = NULL;
Naveen Kumar70e27352015-07-22 21:07:10 +05302247 int idx;
Preetam Singh Ranawat9519e9c2015-11-18 16:05:55 +05302248 int wsaCount =0;
Naresh Tanniru74a2eee2016-02-10 13:38:19 +05302249 bool is_wsa_combo_supported = false;
`Deeraj Soman676c2702017-09-18 19:25:53 +05302250 const char *id_string = NULL;
2251 int cfg_value = -1;
Naveen Kumar70e27352015-07-22 21:07:10 +05302252
Soumya Managoli9fee7c62018-04-06 16:21:50 +05302253 snd_card_num = audio_extn_utils_open_snd_mixer(&adev->mixer);
Vignesh Kulothungan55396882017-04-20 14:37:02 -07002254 if(snd_card_num < 0) {
2255 ALOGE("%s: Unable to find correct sound card", __func__);
2256 return NULL;
2257 }
2258
2259 adev->snd_card = snd_card_num;
2260 ALOGD("%s: Opened sound card:%d", __func__, snd_card_num);
2261
Vignesh Kulothungan55396882017-04-20 14:37:02 -07002262 snd_card_name = mixer_get_name(adev->mixer);
2263 ALOGD("%s: snd_card_name: %s", __func__, snd_card_name);
2264
Naveen Kumar70e27352015-07-22 21:07:10 +05302265 my_data = calloc(1, sizeof(struct platform_data));
2266
Chaithanya Krishna Bacharajudb6236a2015-01-30 10:08:33 +05302267 if (!my_data) {
2268 ALOGE("failed to allocate platform data");
2269 return NULL;
2270 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05302271
Vignesh Kulothungan55396882017-04-20 14:37:02 -07002272 my_data->hw_info = hw_info_init(snd_card_name);
2273 if (!my_data->hw_info) {
2274 ALOGE("%s: Failed to init hardware info", __func__);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302275 free(my_data);
2276 return NULL;
2277 }
2278
Vignesh Kulothungan55396882017-04-20 14:37:02 -07002279 query_platform(snd_card_name, mixer_xml_path);
2280 ALOGD("%s: mixer path file is %s", __func__,
2281 mixer_xml_path);
2282 if (audio_extn_read_xml(adev, snd_card_num, mixer_xml_path,
2283 MIXER_XML_PATH_AUXPCM) == -ENOSYS) {
2284 adev->audio_route = audio_route_init(snd_card_num,
2285 mixer_xml_path);
2286 }
2287 if (!adev->audio_route) {
2288 ALOGE("%s: Failed to init audio route controls, aborting.",
2289 __func__);
2290 free(my_data);
Soumya Managoli9fee7c62018-04-06 16:21:50 +05302291 audio_extn_utils_close_snd_mixer(adev->mixer);
Vignesh Kulothungan55396882017-04-20 14:37:02 -07002292 return NULL;
2293 }
2294 update_codec_type(snd_card_name);
2295 update_interface(snd_card_name);
2296
Naresh Tannirue3b18452014-03-04 14:44:27 +05302297 my_data->adev = adev;
Naresh Tannirue3b18452014-03-04 14:44:27 +05302298 my_data->fluence_in_spkr_mode = false;
2299 my_data->fluence_in_voice_call = false;
2300 my_data->fluence_in_voice_rec = false;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302301 my_data->fluence_in_audio_rec = false;
Dhanalakshmi Siddani3dbfc382017-03-21 15:15:03 +05302302 my_data->fluence_in_hfp_call = false;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302303 my_data->external_spk_1 = false;
2304 my_data->external_spk_2 = false;
2305 my_data->external_mic = false;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302306 my_data->fluence_type = FLUENCE_NONE;
Karthik Reddy Kattad9fff862014-07-21 21:07:21 +05302307 my_data->fluence_mode = FLUENCE_ENDFIRE;
Avinash Vaishd5fa4572014-09-15 14:41:14 +05302308 my_data->slowtalk = false;
2309 my_data->hd_voice = false;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302310 my_data->edid_info = NULL;
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07002311 my_data->ext_disp_type = EXT_DISPLAY_TYPE_NONE;
Preetam Singh Ranawatc7f7f5c2015-04-02 12:19:58 +05302312 my_data->is_wsa_speaker = false;
Venkata Narendra Kumar Guttae071e5a2016-01-11 18:08:26 +05302313 my_data->hw_dep_fd = -1;
Rohit kumarf4120402016-08-05 19:19:48 +05302314 my_data->mono_speaker = SPKR_1;
Vikram Panduranga8c68e862018-04-27 12:59:42 -07002315 my_data->voice_speaker_stereo = false;
Ramjee Singh33412cb2018-07-02 18:21:30 +05302316 my_data->declared_mic_count = 0;
Surendar Karka45850ae2018-07-02 17:45:27 +05302317 my_data->spkr_ch_map = NULL;
Dieter Luecking5d57def2018-09-07 14:23:37 +02002318 my_data->use_sprk_default_sample_rate = true;
Naresh Tannirue3b18452014-03-04 14:44:27 +05302319
Siena Richard7c2db772016-12-21 11:32:34 -08002320 be_dai_name_table = NULL;
2321
Aniket Kumar Lata8fc67e62017-05-02 12:33:46 -07002322 property_get("ro.vendor.audio.sdk.fluencetype", my_data->fluence_cap, "");
Garmond Leunge2433c32017-09-28 21:51:22 -07002323 if (!strncmp("fluenceffv", my_data->fluence_cap, sizeof("fluenceffv"))) {
2324 my_data->fluence_type = FLUENCE_HEX_MIC | FLUENCE_QUAD_MIC | FLUENCE_DUAL_MIC;
2325 } else if (!strncmp("fluencepro", my_data->fluence_cap, sizeof("fluencepro"))) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302326 my_data->fluence_type = FLUENCE_QUAD_MIC | FLUENCE_DUAL_MIC;
Venkata Narendra Kumar Gutta88fd0bc2014-03-27 19:47:56 +05302327 } else if (!strncmp("fluence", my_data->fluence_cap, sizeof("fluence"))) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302328 my_data->fluence_type = FLUENCE_DUAL_MIC;
2329 } else {
2330 my_data->fluence_type = FLUENCE_NONE;
Naresh Tannirue3b18452014-03-04 14:44:27 +05302331 }
2332
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302333 if (my_data->fluence_type != FLUENCE_NONE) {
Aniket Kumar Lata8fc67e62017-05-02 12:33:46 -07002334 property_get("persist.vendor.audio.fluence.voicecall",value,"");
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302335 if (!strncmp("true", value, sizeof("true"))) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05302336 my_data->fluence_in_voice_call = true;
2337 }
2338
Aniket Kumar Lata8fc67e62017-05-02 12:33:46 -07002339 property_get("persist.vendor.audio.fluence.voicerec",value,"");
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302340 if (!strncmp("true", value, sizeof("true"))) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05302341 my_data->fluence_in_voice_rec = true;
2342 }
2343
Aniket Kumar Lata8fc67e62017-05-02 12:33:46 -07002344 property_get("persist.vendor.audio.fluence.audiorec",value,"");
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302345 if (!strncmp("true", value, sizeof("true"))) {
2346 my_data->fluence_in_audio_rec = true;
2347 }
2348
Aniket Kumar Lata8fc67e62017-05-02 12:33:46 -07002349 property_get("persist.vendor.audio.fluence.speaker",value,"");
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302350 if (!strncmp("true", value, sizeof("true"))) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05302351 my_data->fluence_in_spkr_mode = true;
2352 }
Karthik Reddy Kattad9fff862014-07-21 21:07:21 +05302353
Aniket Kumar Lata8fc67e62017-05-02 12:33:46 -07002354 property_get("persist.vendor.audio.fluence.mode",value,"");
Karthik Reddy Kattad9fff862014-07-21 21:07:21 +05302355 if (!strncmp("broadside", value, sizeof("broadside"))) {
2356 my_data->fluence_mode = FLUENCE_BROADSIDE;
2357 }
Dhanalakshmi Siddani3dbfc382017-03-21 15:15:03 +05302358
Aniket Kumar Lata8fc67e62017-05-02 12:33:46 -07002359 property_get("persist.vendor.audio.fluence.hfpcall",value,"");
Dhanalakshmi Siddani3dbfc382017-03-21 15:15:03 +05302360 if (!strncmp("true", value, sizeof("true"))) {
2361 my_data->fluence_in_hfp_call = true;
2362 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05302363 }
Preetam Singh Ranawat9519e9c2015-11-18 16:05:55 +05302364
Alexy Josephb1379942016-01-29 15:49:38 -08002365 if (check_and_get_wsa_info((char *)snd_card_name, &wsaCount, &is_wsa_combo_supported)) {
Preetam Singh Ranawat9519e9c2015-11-18 16:05:55 +05302366 /*Set ACDB ID of Stereo speaker if two WSAs are present*/
2367 /*Default ACDB ID for wsa speaker is that for mono*/
2368 if (wsaCount == 2) {
2369 platform_set_snd_device_acdb_id(SND_DEVICE_OUT_SPEAKER_WSA, 15);
2370 platform_set_snd_device_acdb_id(SND_DEVICE_OUT_SPEAKER_VBAT, 15);
2371 }
Naresh Tanniru74a2eee2016-02-10 13:38:19 +05302372
Preetam Singh Ranawat9519e9c2015-11-18 16:05:55 +05302373 my_data->is_wsa_speaker = true;
Naresh Tanniru74a2eee2016-02-10 13:38:19 +05302374
2375 if (is_wsa_combo_supported)
2376 hw_info_enable_wsa_combo_usecase_support(my_data->hw_info);
2377
Preetam Singh Ranawat9519e9c2015-11-18 16:05:55 +05302378 }
Vikram Panduranga8c68e862018-04-27 12:59:42 -07002379 my_data->voice_speaker_stereo =
2380 property_get_bool("persist.vendor.audio.voicecall.speaker.stereo", false);
Preetam Singh Ranawat9519e9c2015-11-18 16:05:55 +05302381
Aniket Kumar Lata8fc67e62017-05-02 12:33:46 -07002382 property_get("persist.vendor.audio.FFSP.enable", ffspEnable, "");
Srikanth Uyyalaa675cd12014-10-15 14:48:11 +05302383 if (!strncmp("true", ffspEnable, sizeof("true"))) {
2384 acdb_device_table[SND_DEVICE_OUT_SPEAKER] = 131;
Preetam Singh Ranawatc7f7f5c2015-04-02 12:19:58 +05302385 acdb_device_table[SND_DEVICE_OUT_SPEAKER_WSA] = 131;
Srikanth Uyyalaa675cd12014-10-15 14:48:11 +05302386 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE] = 131;
2387 acdb_device_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 131;
2388 acdb_device_table[SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = 131;
2389 }
Dhananjay Kumara3565b32014-07-23 01:12:48 +05302390
Banajit Goswami20cdd212015-09-11 01:11:30 -07002391 /* Check if Vbat speaker enabled property is set, this should be done before acdb init */
2392 bool ret = false;
2393 ret = audio_extn_can_use_vbat();
2394 if (ret)
2395 my_data->is_vbat_speaker = true;
2396
Venkata Narendra Kumar Gutta4bd09d02016-01-29 15:31:04 +05302397 /*
2398 * Check if hifi audio( i.e. 96, 192 KHZ) is enabled for this platform,
2399 * enable hifi audio by default for external codec targets
2400 */
2401 ret = audio_extn_is_hifi_audio_supported();
2402 if (ret || is_external_codec)
2403 my_data->hifi_audio = true;
2404
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05302405 list_init(&my_data->acdb_meta_key_list);
Dhananjay Kumar429eb452018-12-10 22:26:53 +05302406 list_init(&my_data->custom_mtmx_params_list);
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05302407
2408 set_platform_defaults(my_data);
2409
2410 /* Initialize ACDB and PCM ID's */
2411 if (is_external_codec)
Vignesh Kulothungan55396882017-04-20 14:37:02 -07002412 platform_info_init(PLATFORM_INFO_XML_PATH_EXTCODEC, my_data, PLATFORM);
Walter Yangb3540112017-03-01 14:05:03 +08002413 else if (!strncmp(snd_card_name, "sdm660-snd-card-skush",
2414 sizeof("sdm660-snd-card-skush")))
Vignesh Kulothungan55396882017-04-20 14:37:02 -07002415 platform_info_init(PLATFORM_INFO_XML_PATH_SKUSH, my_data, PLATFORM);
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05302416 else
Vignesh Kulothungan55396882017-04-20 14:37:02 -07002417 platform_info_init(PLATFORM_INFO_XML_PATH, my_data, PLATFORM);
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05302418
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302419 my_data->voice_feature_set = VOICE_FEATURE_SET_DEFAULT;
Naresh Tannirue3b18452014-03-04 14:44:27 +05302420 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
2421 if (my_data->acdb_handle == NULL) {
2422 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
2423 } else {
2424 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
2425 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
2426 "acdb_loader_deallocate_ACDB");
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302427 if (!my_data->acdb_deallocate)
2428 ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s",
2429 __func__, LIB_ACDB_LOADER);
2430
Naresh Tannirue3b18452014-03-04 14:44:27 +05302431 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 -07002432 "acdb_loader_send_audio_cal_v2");
Naresh Tannirue3b18452014-03-04 14:44:27 +05302433 if (!my_data->acdb_send_audio_cal)
Siena Richard7c2db772016-12-21 11:32:34 -08002434 ALOGE("%s: Could not find the symbol acdb_send_audio_cal_v2 from %s",
2435 __func__, LIB_ACDB_LOADER);
2436
2437 my_data->acdb_send_audio_cal_v3 = (acdb_send_audio_cal_v3_t)dlsym(my_data->acdb_handle,
2438 "acdb_loader_send_audio_cal_v3");
2439 if (!my_data->acdb_send_audio_cal_v3)
2440 ALOGE("%s: Could not find the symbol acdb_send_audio_cal_v3 from %s",
Naresh Tannirue3b18452014-03-04 14:44:27 +05302441 __func__, LIB_ACDB_LOADER);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302442
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302443 my_data->acdb_set_audio_cal = (acdb_set_audio_cal_t)dlsym(my_data->acdb_handle,
2444 "acdb_loader_set_audio_cal_v2");
2445 if (!my_data->acdb_set_audio_cal)
2446 ALOGE("%s: Could not find the symbol acdb_set_audio_cal_v2 from %s",
2447 __func__, LIB_ACDB_LOADER);
2448
2449 my_data->acdb_get_audio_cal = (acdb_get_audio_cal_t)dlsym(my_data->acdb_handle,
2450 "acdb_loader_get_audio_cal_v2");
2451 if (!my_data->acdb_get_audio_cal)
2452 ALOGE("%s: Could not find the symbol acdb_get_audio_cal_v2 from %s",
2453 __func__, LIB_ACDB_LOADER);
2454
Naresh Tannirue3b18452014-03-04 14:44:27 +05302455 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
2456 "acdb_loader_send_voice_cal");
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302457 if (!my_data->acdb_send_voice_cal)
2458 ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s",
2459 __func__, LIB_ACDB_LOADER);
2460
2461 my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle,
2462 "acdb_loader_reload_vocvoltable");
2463 if (!my_data->acdb_reload_vocvoltable)
2464 ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s",
2465 __func__, LIB_ACDB_LOADER);
2466
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -07002467 my_data->acdb_get_default_app_type = (acdb_get_default_app_type_t)dlsym(
2468 my_data->acdb_handle,
2469 "acdb_loader_get_default_app_type");
2470 if (!my_data->acdb_get_default_app_type)
2471 ALOGE("%s: Could not find the symbol acdb_get_default_app_type from %s",
2472 __func__, LIB_ACDB_LOADER);
2473
Ben Rombergerfeca4b82015-07-07 20:40:44 -07002474 my_data->acdb_send_common_top = (acdb_send_common_top_t)dlsym(
2475 my_data->acdb_handle,
2476 "acdb_loader_send_common_custom_topology");
2477 if (!my_data->acdb_send_common_top)
2478 ALOGE("%s: Could not find the symbol acdb_get_default_app_type from %s",
2479 __func__, LIB_ACDB_LOADER);
2480
Banajit Goswami20cdd212015-09-11 01:11:30 -07002481 my_data->acdb_set_codec_data = (acdb_set_codec_data_t)dlsym(
2482 my_data->acdb_handle,
2483 "acdb_loader_set_codec_data");
2484 if (!my_data->acdb_set_codec_data)
2485 ALOGE("%s: Could not find the symbol acdb_get_default_app_type from %s",
2486 __func__, LIB_ACDB_LOADER);
2487
Sharad Sangleaca972a2017-01-25 12:38:22 +05302488 my_data->acdb_send_gain_dep_cal = (acdb_send_gain_dep_cal_t)dlsym(my_data->acdb_handle,
2489 "acdb_loader_send_gain_dep_cal");
2490 if (!my_data->acdb_send_gain_dep_cal)
2491 ALOGV("%s: Could not find the symbol acdb_loader_send_gain_dep_cal from %s",
2492 __func__, LIB_ACDB_LOADER);
Banajit Goswami20cdd212015-09-11 01:11:30 -07002493
Aditya Bavanari29bcea22017-10-03 20:10:35 +05302494 my_data->acdb_init_v4 = (acdb_init_v4_t)dlsym(my_data->acdb_handle,
2495 "acdb_loader_init_v4");
2496 if (my_data->acdb_init_v4 == NULL) {
2497 ALOGE("%s: dlsym error %s for acdb_loader_init_v4", __func__, dlerror());
2498 }
2499
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05302500 my_data->acdb_init_v3 = (acdb_init_v3_t)dlsym(my_data->acdb_handle,
2501 "acdb_loader_init_v3");
2502 if (my_data->acdb_init_v3 == NULL) {
2503 ALOGE("%s: dlsym error %s for acdb_loader_init_v3", __func__, dlerror());
2504 }
2505
Naresh Tannirue3b18452014-03-04 14:44:27 +05302506 my_data->acdb_init = (acdb_init_t)dlsym(my_data->acdb_handle,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302507 "acdb_loader_init_v2");
Avinash Vaish71c066d2014-08-27 12:32:35 +05302508 if (my_data->acdb_init == NULL) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302509 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__, dlerror());
Avinash Vaish71c066d2014-08-27 12:32:35 +05302510 goto acdb_init_fail;
2511 }
Karthik Reddy Katta8513f432016-04-12 14:29:27 +05302512
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05302513 my_data->acdb_reload_v2 = (acdb_reload_v2_t)dlsym(my_data->acdb_handle,
2514 "acdb_loader_reload_acdb_files_v2");
2515 if (my_data->acdb_reload_v2 == NULL) {
2516 ALOGE("%s: dlsym error %s for acdb_loader_reload_acdb_files_v2", __func__, dlerror());
2517 }
2518
Karthik Reddy Katta8513f432016-04-12 14:29:27 +05302519 my_data->acdb_reload = (acdb_reload_t)dlsym(my_data->acdb_handle,
2520 "acdb_loader_reload_acdb_files");
2521 if (my_data->acdb_reload == NULL) {
2522 ALOGE("%s: dlsym error %s for acdb_loader_reload_acdb_files", __func__, dlerror());
2523 goto acdb_init_fail;
2524 }
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05302525
Soumya Managoli9fee7c62018-04-06 16:21:50 +05302526 int result = acdb_init_v2(adev->mixer);
Vignesh Kulothungan55396882017-04-20 14:37:02 -07002527 if (!result) {
2528 my_data->is_acdb_initialized = true;
2529 ALOGD("ACDB initialized");
2530 audio_hwdep_send_cal(my_data);
2531 } else {
2532 my_data->is_acdb_initialized = false;
2533 ALOGD("ACDB initialization failed");
Vikram Panduranga022bbd12019-10-03 16:27:57 -07002534 if (my_data->acdb_deallocate)
2535 my_data->acdb_deallocate();
Vignesh Kulothungan55396882017-04-20 14:37:02 -07002536 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05302537 }
Preetam Singh Ranawat2d0e4632015-02-02 12:40:59 +05302538 audio_extn_pm_vote();
Revathi Uddaraju1eac8b02017-05-18 17:13:33 +05302539#ifdef DYNAMIC_LOG_ENABLED
2540 log_utils_init();
2541#endif
Satish Babu Patakokilabbd4e9d2015-05-13 22:08:06 +05302542 /* Configure active back end for HPX*/
2543 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2544 if (ctl) {
2545 ALOGE(" sending HPX Active BE information ");
2546 mixer_ctl_set_value(ctl, 0, is_external_codec);
Preetam Singh Ranawatc7f7f5c2015-04-02 12:19:58 +05302547 }
2548
Avinash Vaish71c066d2014-08-27 12:32:35 +05302549acdb_init_fail:
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302550
Rohit Kumarbe6935f2017-01-20 14:58:34 +05302551 if (audio_extn_can_use_ras()) {
Aniket Kumar Lata8fc67e62017-05-02 12:33:46 -07002552 if (property_get_bool("persist.vendor.audio.speaker.prot.enable", false)) {
Rohit Kumarbe6935f2017-01-20 14:58:34 +05302553 platform_set_snd_device_acdb_id(SND_DEVICE_OUT_SPEAKER_PROTECTED,
2554 acdb_device_table[SND_DEVICE_OUT_SPEAKER_PROTECTED_RAS]);
2555 platform_set_snd_device_acdb_id(SND_DEVICE_OUT_SPEAKER_PROTECTED_VBAT,
2556 acdb_device_table[SND_DEVICE_OUT_SPEAKER_PROTECTED_VBAT_RAS]);
2557 } else {
2558 ALOGD("%s: RAS Feature should be enabled with Speaker Protection", __func__);
2559 }
2560 }
2561
Siena Richard7c2db772016-12-21 11:32:34 -08002562 /*
2563 * Get the be_dai_name_table from kernel which provides a mapping
2564 * between a backend string name and a backend ID
2565 */
2566 init_be_dai_name_table(adev);
2567
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05302568 /* obtain source mic type from max mic count*/
2569 get_source_mic_type(my_data);
2570 ALOGD("%s: Fluence_Type(%d) max_mic_count(%d) mic_type(0x%x) fluence_in_voice_call(%d)"
Dhanalakshmi Siddani3dbfc382017-03-21 15:15:03 +05302571 " fluence_in_voice_rec(%d) fluence_in_spkr_mode(%d) fluence_in_hfp_call(%d) ",
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05302572 __func__, my_data->fluence_type, my_data->max_mic_count, my_data->source_mic_type,
2573 my_data->fluence_in_voice_call, my_data->fluence_in_voice_rec,
Dhanalakshmi Siddani3dbfc382017-03-21 15:15:03 +05302574 my_data->fluence_in_spkr_mode, my_data->fluence_in_hfp_call);
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05302575
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302576 /* init usb */
2577 audio_extn_usb_init(adev);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302578
Naresh Tanniru9d027a62015-03-13 01:32:10 +05302579 /*init a2dp*/
2580 audio_extn_a2dp_init(adev);
2581
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302582 /* Read one time ssr property */
2583 audio_extn_ssr_update_enabled();
Garmond Leunge2433c32017-09-28 21:51:22 -07002584 audio_extn_ffv_update_enabled();
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302585 audio_extn_spkr_prot_init(adev);
Dhananjay Kumar89ea3bd2014-04-29 15:45:57 +05302586
Ashish Jain8ec50472014-10-16 13:56:28 +05302587 /* init dap hal */
2588 audio_extn_dap_hal_init(adev->snd_card);
2589
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302590 /* init audio device arbitration */
2591 audio_extn_dev_arbi_init();
2592
2593 my_data->edid_info = NULL;
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05302594
Naresh Tanniru25873b82016-11-01 14:15:28 +05302595 default_rx_backend = strdup("SLIMBUS_0_RX");
2596
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05302597 /* initialize backend config */
2598 for (idx = 0; idx < MAX_CODEC_BACKENDS; idx++) {
2599 my_data->current_backend_cfg[idx].sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
2600 if (idx == HEADPHONE_44_1_BACKEND)
2601 my_data->current_backend_cfg[idx].sample_rate = OUTPUT_SAMPLING_RATE_44100;
2602 my_data->current_backend_cfg[idx].bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
Ashish Jainb26edfb2016-08-25 00:10:11 +05302603 my_data->current_backend_cfg[idx].channels = CODEC_BACKEND_DEFAULT_CHANNELS;
Kuirong Wang0b947f72016-09-29 11:03:09 -07002604 if (idx > MAX_RX_CODEC_BACKENDS)
2605 my_data->current_backend_cfg[idx].channels = CODEC_BACKEND_DEFAULT_TX_CHANNELS;
Siddartha Shaik44dd7702017-06-14 12:13:25 +05302606 my_data->current_backend_cfg[idx].format = AUDIO_FORMAT_PCM;
Ashish Jainb26edfb2016-08-25 00:10:11 +05302607 my_data->current_backend_cfg[idx].bitwidth_mixer_ctl = NULL;
2608 my_data->current_backend_cfg[idx].samplerate_mixer_ctl = NULL;
2609 my_data->current_backend_cfg[idx].channels_mixer_ctl = NULL;
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05302610 }
2611
Sachin Mohan Gadag1ec7fab2016-12-12 17:41:26 +05302612 if (is_slimbus_interface) {
Venkata Narendra Kumar Gutta4bd09d02016-01-29 15:31:04 +05302613 my_data->current_backend_cfg[DEFAULT_CODEC_BACKEND].bitwidth_mixer_ctl =
2614 strdup("SLIM_0_RX Format");
2615 my_data->current_backend_cfg[DEFAULT_CODEC_BACKEND].samplerate_mixer_ctl =
2616 strdup("SLIM_0_RX SampleRate");
Satish Babu Patakokilac3c5d432017-07-04 22:48:59 +05302617 my_data->current_backend_cfg[DEFAULT_CODEC_BACKEND].channels_mixer_ctl =
2618 strdup("SLIM_0_RX Channels");
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05302619
Naresh Tanniru25873b82016-11-01 14:15:28 +05302620 my_data->current_backend_cfg[DSD_NATIVE_BACKEND].bitwidth_mixer_ctl =
2621 strdup("SLIM_2_RX Format");
2622 my_data->current_backend_cfg[DSD_NATIVE_BACKEND].samplerate_mixer_ctl =
2623 strdup("SLIM_2_RX SampleRate");
2624
Venkata Narendra Kumar Gutta4bd09d02016-01-29 15:31:04 +05302625 my_data->current_backend_cfg[HEADPHONE_44_1_BACKEND].bitwidth_mixer_ctl =
2626 strdup("SLIM_5_RX Format");
2627 my_data->current_backend_cfg[HEADPHONE_44_1_BACKEND].samplerate_mixer_ctl =
2628 strdup("SLIM_5_RX SampleRate");
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05302629
2630 my_data->current_backend_cfg[HEADPHONE_BACKEND].bitwidth_mixer_ctl =
2631 strdup("SLIM_6_RX Format");
2632 my_data->current_backend_cfg[HEADPHONE_BACKEND].samplerate_mixer_ctl =
2633 strdup("SLIM_6_RX SampleRate");
Manish Dewanganba9fcfa2016-03-24 16:20:06 +05302634
Kuirong Wang0b947f72016-09-29 11:03:09 -07002635 my_data->current_backend_cfg[SLIMBUS_0_TX].bitwidth_mixer_ctl =
Manish Dewanganba9fcfa2016-03-24 16:20:06 +05302636 strdup("SLIM_0_TX Format");
Kuirong Wang0b947f72016-09-29 11:03:09 -07002637 my_data->current_backend_cfg[SLIMBUS_0_TX].samplerate_mixer_ctl =
Manish Dewanganba9fcfa2016-03-24 16:20:06 +05302638 strdup("SLIM_0_TX SampleRate");
Venkata Narendra Kumar Gutta4bd09d02016-01-29 15:31:04 +05302639 } else {
Arusha Goyalfda29152016-12-26 10:53:39 +05302640 if (!strncmp(snd_card_name, "sdm660", strlen("sdm660"))) {
Manish Dewanganba9fcfa2016-03-24 16:20:06 +05302641
Naresh Tanniru25873b82016-11-01 14:15:28 +05302642 my_data->current_backend_cfg[DEFAULT_CODEC_BACKEND].bitwidth_mixer_ctl =
2643 strdup("INT4_MI2S_RX Format");
2644 my_data->current_backend_cfg[DEFAULT_CODEC_BACKEND].samplerate_mixer_ctl =
2645 strdup("INT4_MI2S_RX SampleRate");
2646
2647 my_data->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].bitwidth_mixer_ctl =
2648 strdup("INT3_MI2S_TX Format");
2649 my_data->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].samplerate_mixer_ctl =
2650 strdup("INT3_MI2S_TX SampleRate");
2651
2652 if (default_rx_backend)
2653 free(default_rx_backend);
2654 default_rx_backend = strdup("INT4_MI2S_RX");
2655
2656 } else {
2657 my_data->current_backend_cfg[DEFAULT_CODEC_BACKEND].bitwidth_mixer_ctl =
2658 strdup("MI2S_RX Format");
2659 my_data->current_backend_cfg[DEFAULT_CODEC_BACKEND].samplerate_mixer_ctl =
2660 strdup("MI2S_RX SampleRate");
Sachin Mohan Gadag1ec7fab2016-12-12 17:41:26 +05302661 my_data->current_backend_cfg[DEFAULT_CODEC_BACKEND].channels_mixer_ctl =
2662 strdup("MI2S_RX Channels");
Naresh Tanniru25873b82016-11-01 14:15:28 +05302663
2664 my_data->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].bitwidth_mixer_ctl =
2665 strdup("MI2S_TX Format");
2666 my_data->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].samplerate_mixer_ctl =
2667 strdup("MI2S_TX SampleRate");
2668 }
2669 my_data->current_backend_cfg[HEADPHONE_BACKEND].bitwidth_mixer_ctl =
2670 strdup("INT0_MI2S_RX Format");
2671 my_data->current_backend_cfg[HEADPHONE_BACKEND].samplerate_mixer_ctl =
2672 strdup("INT0_MI2S_RX SampleRate");
2673
Venkata Narendra Kumar Gutta4bd09d02016-01-29 15:31:04 +05302674 }
Kuirong Wang0b947f72016-09-29 11:03:09 -07002675 my_data->current_backend_cfg[USB_AUDIO_TX_BACKEND].bitwidth_mixer_ctl =
2676 strdup("USB_AUDIO_TX Format");
2677 my_data->current_backend_cfg[USB_AUDIO_TX_BACKEND].samplerate_mixer_ctl =
2678 strdup("USB_AUDIO_TX SampleRate");
2679 my_data->current_backend_cfg[USB_AUDIO_TX_BACKEND].channels_mixer_ctl =
2680 strdup("USB_AUDIO_TX Channels");
Sidipotu Ashokcf877732015-09-22 14:58:48 +05302681
Kuirong Wanga9f7cee2016-03-07 11:21:52 -08002682 my_data->current_backend_cfg[USB_AUDIO_RX_BACKEND].bitwidth_mixer_ctl =
2683 strdup("USB_AUDIO_RX Format");
2684 my_data->current_backend_cfg[USB_AUDIO_RX_BACKEND].samplerate_mixer_ctl =
2685 strdup("USB_AUDIO_RX SampleRate");
Ashish Jainb26edfb2016-08-25 00:10:11 +05302686 my_data->current_backend_cfg[USB_AUDIO_RX_BACKEND].channels_mixer_ctl =
2687 strdup("USB_AUDIO_RX Channels");
Kuirong Wanga9f7cee2016-03-07 11:21:52 -08002688
Mingming Yinddd610b2016-01-20 17:09:32 -08002689 my_data->current_backend_cfg[HDMI_RX_BACKEND].bitwidth_mixer_ctl =
2690 strdup("HDMI_RX Bit Format");
2691 my_data->current_backend_cfg[HDMI_RX_BACKEND].samplerate_mixer_ctl =
2692 strdup("HDMI_RX SampleRate");
Ashish Jaind84fd6a2016-07-27 12:33:25 +05302693 my_data->current_backend_cfg[HDMI_RX_BACKEND].channels_mixer_ctl =
2694 strdup("HDMI_RX Channels");
Mingming Yinddd610b2016-01-20 17:09:32 -08002695
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07002696 my_data->current_backend_cfg[DISP_PORT_RX_BACKEND].bitwidth_mixer_ctl =
2697 strdup("Display Port RX Bit Format");
2698 my_data->current_backend_cfg[DISP_PORT_RX_BACKEND].samplerate_mixer_ctl =
2699 strdup("Display Port RX SampleRate");
2700 my_data->current_backend_cfg[DISP_PORT_RX_BACKEND].channels_mixer_ctl =
2701 strdup("Display Port RX Channels");
2702
Siddartha Shaik44dd7702017-06-14 12:13:25 +05302703 my_data->current_backend_cfg[HDMI_TX_BACKEND].bitwidth_mixer_ctl =
2704 strdup("QUAT_MI2S_TX Format");
2705 my_data->current_backend_cfg[HDMI_TX_BACKEND].samplerate_mixer_ctl =
2706 strdup("QUAT_MI2S_TX SampleRate");
2707 my_data->current_backend_cfg[HDMI_TX_BACKEND].channels_mixer_ctl =
2708 strdup("QUAT_MI2S_TX Channels");
2709
`Deeraj Soman676c2702017-09-18 19:25:53 +05302710 for (idx = 0; idx < MAX_CODEC_BACKENDS; idx++) {
2711 if (my_data->current_backend_cfg[idx].bitwidth_mixer_ctl) {
2712 ctl = mixer_get_ctl_by_name(adev->mixer,
2713 my_data->current_backend_cfg[idx].bitwidth_mixer_ctl);
2714 id_string = platform_get_mixer_control(ctl);
2715 if (id_string) {
2716 cfg_value = audio_extn_utils_get_bit_width_from_string(id_string);
2717 if (cfg_value > 0)
2718 my_data->current_backend_cfg[idx].bit_width = cfg_value;
2719 }
2720 }
2721
2722 if (my_data->current_backend_cfg[idx].samplerate_mixer_ctl) {
2723 ctl = mixer_get_ctl_by_name(adev->mixer,
2724 my_data->current_backend_cfg[idx].samplerate_mixer_ctl);
2725 id_string = platform_get_mixer_control(ctl);
2726 if (id_string) {
2727 cfg_value = audio_extn_utils_get_sample_rate_from_string(id_string);
2728 if (cfg_value > 0)
2729 my_data->current_backend_cfg[idx].sample_rate = cfg_value;
2730 }
2731 }
2732
2733 if (my_data->current_backend_cfg[idx].channels_mixer_ctl) {
2734 ctl = mixer_get_ctl_by_name(adev->mixer,
2735 my_data->current_backend_cfg[idx].channels_mixer_ctl);
2736 id_string = platform_get_mixer_control(ctl);
2737 if (id_string) {
2738 cfg_value = audio_extn_utils_get_channels_from_string(id_string);
2739 if (cfg_value > 0)
2740 my_data->current_backend_cfg[idx].channels = cfg_value;
2741 }
2742 }
2743 }
2744
Md Mansoor Ahmeddb1b4f92018-01-25 18:56:31 +05302745 /* Initialize keep alive for HDMI/loopback silence */
2746 audio_extn_keep_alive_init(adev);
2747
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05302748 ret = audio_extn_utils_get_codec_version(snd_card_name,
2749 my_data->adev->snd_card,
2750 my_data->codec_version);
Sidipotu Ashokcf877732015-09-22 14:58:48 +05302751
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05302752 if (NATIVE_AUDIO_MODE_INVALID != platform_get_native_support()) {
2753 /*
2754 * Native playback is enabled from the UI.
2755 */
2756 if(strstr(snd_card_name, "tasha")) {
2757 if (strstr(my_data->codec_version, "WCD9335_1_0") ||
2758 strstr(my_data->codec_version, "WCD9335_1_1")) {
2759 ALOGD("%s:napb: TASHA 1.0 or 1.1 only SRC mode is supported",
2760 __func__);
2761 platform_set_native_support(NATIVE_AUDIO_MODE_SRC);
2762 }
Ashish Jain4826f6c2017-02-06 13:33:20 +05302763 }
2764 if (strstr(snd_card_name, "tavil")) {
2765 ALOGD("%s:DSD playback is supported", __func__);
2766 my_data->is_dsd_supported = true;
2767 my_data->is_asrc_supported = true;
Preetam Singh Ranawatb1c73232019-04-22 13:59:51 +05302768 platform_set_native_support(NATIVE_AUDIO_MODE_MULTIPLE_MIX_IN_CODEC);
Sidipotu Ashokcf877732015-09-22 14:58:48 +05302769 }
2770 }
2771
Dhananjay Kumar704ce6f2017-09-28 22:08:00 +05302772 if (property_get_bool("vendor.audio.apptype.multirec.enabled", false))
2773 my_data->use_generic_handset = true;
2774
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05302775 my_data->edid_info = NULL;
Naresh Tannirue3b18452014-03-04 14:44:27 +05302776 return my_data;
2777}
2778
Dhananjay Kumar429eb452018-12-10 22:26:53 +05302779struct audio_custom_mtmx_params *
2780 platform_get_custom_mtmx_params(void *platform,
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05302781 struct audio_custom_mtmx_params_info *info,
2782 uint32_t *idx)
Dhananjay Kumar429eb452018-12-10 22:26:53 +05302783{
2784 struct platform_data *my_data = (struct platform_data *)platform;
2785 struct listnode *node = NULL;
2786 struct audio_custom_mtmx_params *params = NULL;
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05302787 int i = 0;
2788
2789 if (!info || !idx) {
2790 ALOGE("%s: Invalid params", __func__);
2791 return NULL;
2792 }
Dhananjay Kumar429eb452018-12-10 22:26:53 +05302793
2794 list_for_each(node, &my_data->custom_mtmx_params_list) {
2795 params = node_to_item(node, struct audio_custom_mtmx_params, list);
2796 if (params &&
2797 params->info.id == info->id &&
2798 params->info.ip_channels == info->ip_channels &&
2799 params->info.op_channels == info->op_channels &&
Dhananjay Kumar429eb452018-12-10 22:26:53 +05302800 params->info.snd_device == info->snd_device) {
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05302801 while (params->info.usecase_id[i] != 0) {
2802 if (params->info.usecase_id[i] == info->usecase_id[0]) {
2803 ALOGV("%s: found params with ip_ch %d op_ch %d uc_id %d snd_dev %d",
2804 __func__, info->ip_channels, info->op_channels,
2805 info->usecase_id[0], info->snd_device);
2806 *idx = i;
2807 return params;
2808 }
2809 i++;
2810 }
Dhananjay Kumar429eb452018-12-10 22:26:53 +05302811 }
2812 }
2813 ALOGI("%s: no matching param with id %d ip_ch %d op_ch %d uc_id %d snd_dev %d",
2814 __func__, info->id, info->ip_channels, info->op_channels,
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05302815 info->usecase_id[0], info->snd_device);
Dhananjay Kumar429eb452018-12-10 22:26:53 +05302816 return NULL;
2817}
2818
2819int platform_add_custom_mtmx_params(void *platform,
2820 struct audio_custom_mtmx_params_info *info)
2821{
2822 struct platform_data *my_data = (struct platform_data *)platform;
2823 struct audio_custom_mtmx_params *params = NULL;
2824 uint32_t size = sizeof(*params);
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05302825 int i = 0;
2826
2827 if (!info) {
2828 ALOGE("%s: Invalid params", __func__);
2829 return NULL;
2830 }
Dhananjay Kumar429eb452018-12-10 22:26:53 +05302831
2832 if (info->ip_channels > AUDIO_CHANNEL_COUNT_MAX ||
2833 info->op_channels > AUDIO_CHANNEL_COUNT_MAX) {
2834 ALOGE("%s: unusupported channels in %d, out %d",
2835 __func__, info->ip_channels, info->op_channels);
2836 return -EINVAL;
2837 }
2838
2839 size += sizeof(params->coeffs[0]) * info->ip_channels * info->op_channels;
2840 params = (struct audio_custom_mtmx_params *) calloc(1, size);
2841 if (!params) {
2842 ALOGE("%s: failed to add custom mtmx params", __func__);
2843 return -ENOMEM;
2844 }
2845
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05302846 ALOGI("%s: adding mtmx params with id %d ip_ch %d op_ch %d snd_dev %d",
Dhananjay Kumar429eb452018-12-10 22:26:53 +05302847 __func__, info->id, info->ip_channels, info->op_channels,
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05302848 info->snd_device);
2849 while (info->usecase_id[i] != 0) {
2850 ALOGI("%s: supported usecase ids for added mtmx params %d",
2851 __func__, info->usecase_id[i]);
2852 i++;
2853 }
Dhananjay Kumar429eb452018-12-10 22:26:53 +05302854
2855 params->info = *info;
2856 list_add_tail(&my_data->custom_mtmx_params_list, &params->list);
2857 return 0;
2858}
2859
2860static void platform_release_custom_mtmx_params(void *platform)
2861{
2862 struct platform_data *my_data = (struct platform_data *)platform;
2863 struct listnode *node = NULL, *tempnode = NULL;
2864
2865 list_for_each_safe(node, tempnode, &my_data->custom_mtmx_params_list) {
2866 list_remove(node);
2867 free(node_to_item(node, struct audio_custom_mtmx_params, list));
2868 }
2869}
2870
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05302871struct audio_custom_mtmx_in_params *platform_get_custom_mtmx_in_params(void *platform,
2872 struct audio_custom_mtmx_in_params_info *info)
2873{
2874 ALOGW("%s: not implemented!", __func__);
2875 return -ENOSYS;
2876}
2877
2878int platform_add_custom_mtmx_in_params(void *platform,
2879 struct audio_custom_mtmx_in_params_info *info)
2880{
2881 ALOGW("%s: not implemented!", __func__);
2882 return -ENOSYS;
2883}
2884
Ramu Gottipati62f6d9b2018-05-01 15:21:38 +05302885void platform_release_acdb_metainfo_key(void *platform)
2886{
2887 struct platform_data *my_data = (struct platform_data *)platform;
2888 struct listnode *node, *tempnode;
2889
2890 list_for_each_safe(node, tempnode, &my_data->acdb_meta_key_list) {
2891 list_remove(node);
2892 free(node_to_item(node, struct meta_key_list, list));
2893 }
2894}
2895
Naresh Tannirue3b18452014-03-04 14:44:27 +05302896void platform_deinit(void *platform)
2897{
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302898 struct platform_data *my_data = (struct platform_data *)platform;
2899
Md Mansoor Ahmeddb1b4f92018-01-25 18:56:31 +05302900 audio_extn_keep_alive_deinit();
2901
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302902 if (my_data->edid_info) {
2903 free(my_data->edid_info);
2904 my_data->edid_info = NULL;
2905 }
2906
Siena Richard7c2db772016-12-21 11:32:34 -08002907 if (be_dai_name_table) {
2908 free((void *)be_dai_name_table);
2909 be_dai_name_table = NULL;
2910 }
2911
Venkata Narendra Kumar Guttae071e5a2016-01-11 18:08:26 +05302912 if (my_data->hw_dep_fd >= 0) {
2913 close(my_data->hw_dep_fd);
2914 my_data->hw_dep_fd = -1;
2915 }
2916
Naresh Tanniru25873b82016-11-01 14:15:28 +05302917 if (default_rx_backend)
2918 free(default_rx_backend);
2919
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302920 hw_info_deinit(my_data->hw_info);
2921 close_csd_client(my_data->csd);
2922
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302923 int32_t dev;
2924 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05302925 if (backend_tag_table[dev]) {
2926 free(backend_tag_table[dev]);
2927 backend_tag_table[dev]= NULL;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302928 }
2929 }
2930
2931 /* deinit audio device arbitration */
2932 audio_extn_dev_arbi_deinit();
2933
2934 if (my_data->edid_info) {
2935 free(my_data->edid_info);
2936 my_data->edid_info = NULL;
2937 }
2938
Dhananjay Kumara5ba5f22016-11-30 16:01:29 +05302939 if (my_data->adev->mixer) {
Soumya Managoli9fee7c62018-04-06 16:21:50 +05302940 audio_extn_utils_close_snd_mixer(my_data->adev->mixer);
Dhananjay Kumara5ba5f22016-11-30 16:01:29 +05302941 my_data->adev->mixer = NULL;
2942 }
2943
Surendar Karka45850ae2018-07-02 17:45:27 +05302944 if (my_data->spkr_ch_map) {
2945 free(my_data->spkr_ch_map);
2946 my_data->spkr_ch_map = NULL;
2947 }
2948
Ramu Gottipati62f6d9b2018-05-01 15:21:38 +05302949 int32_t idx;
2950
2951 for (idx = 0; idx < MAX_CODEC_BACKENDS; idx++) {
2952 if (my_data->current_backend_cfg[idx].bitwidth_mixer_ctl) {
2953 free(my_data->current_backend_cfg[idx].bitwidth_mixer_ctl);
2954 my_data->current_backend_cfg[idx].bitwidth_mixer_ctl = NULL;
2955 }
2956
2957 if (my_data->current_backend_cfg[idx].samplerate_mixer_ctl) {
2958 free(my_data->current_backend_cfg[idx].samplerate_mixer_ctl);
2959 my_data->current_backend_cfg[idx].samplerate_mixer_ctl = NULL;
2960 }
2961
2962 if (my_data->current_backend_cfg[idx].channels_mixer_ctl) {
2963 free(my_data->current_backend_cfg[idx].channels_mixer_ctl);
2964 my_data->current_backend_cfg[idx].channels_mixer_ctl = NULL;
2965 }
2966 }
2967
2968 /* free acdb_meta_key_list */
2969 platform_release_acdb_metainfo_key(platform);
Dhananjay Kumar429eb452018-12-10 22:26:53 +05302970 platform_release_custom_mtmx_params(platform);
Ramu Gottipati62f6d9b2018-05-01 15:21:38 +05302971
Dhanalakshmi Siddanic98136c2018-10-11 14:42:28 +05302972 if (my_data->acdb_deallocate)
2973 my_data->acdb_deallocate();
2974
Naresh Tannirue3b18452014-03-04 14:44:27 +05302975 free(platform);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302976 /* deinit usb */
2977 audio_extn_usb_deinit();
Ashish Jain8ec50472014-10-16 13:56:28 +05302978 audio_extn_dap_hal_deinit();
Revathi Uddaraju1eac8b02017-05-18 17:13:33 +05302979#ifdef DYNAMIC_LOG_ENABLED
2980 log_utils_deinit();
2981#endif
Naresh Tannirue3b18452014-03-04 14:44:27 +05302982}
2983
Ben Rombergerfeca4b82015-07-07 20:40:44 -07002984static int platform_is_acdb_initialized(void *platform)
Ramjee Singh203473b2015-06-09 15:18:42 +05302985{
2986 struct platform_data *my_data = (struct platform_data *)platform;
2987 ALOGD("%s: acdb initialized %d\n", __func__, my_data->is_acdb_initialized);
2988 return my_data->is_acdb_initialized;
2989}
2990
Dhananjay Kumare6293dd2017-05-25 17:25:30 +05302991void platform_snd_card_update(void *platform, card_status_t card_status)
Ben Rombergerfeca4b82015-07-07 20:40:44 -07002992{
2993 struct platform_data *my_data = (struct platform_data *)platform;
2994
Dhananjay Kumare6293dd2017-05-25 17:25:30 +05302995 if (card_status == CARD_STATUS_ONLINE) {
Ben Rombergerfeca4b82015-07-07 20:40:44 -07002996 if (!platform_is_acdb_initialized(my_data)) {
2997 if(platform_acdb_init(my_data))
2998 ALOGE("%s: acdb initialization is failed", __func__);
2999 } else if (my_data->acdb_send_common_top() < 0) {
3000 ALOGD("%s: acdb did not set common topology", __func__);
3001 }
3002 }
3003}
3004
Naresh Tannirue3b18452014-03-04 14:44:27 +05303005const char *platform_get_snd_device_name(snd_device_t snd_device)
3006{
3007 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX)
3008 return device_table[snd_device];
3009 else
3010 return "";
3011}
3012
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303013int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
3014 char *device_name)
3015{
3016 struct platform_data *my_data = (struct platform_data *)platform;
3017
3018 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
3019 strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE);
3020 hw_info_append_hw_type(my_data->hw_info, snd_device, device_name);
Garmond Leunge2433c32017-09-28 21:51:22 -07003021
3022 if ((snd_device == SND_DEVICE_IN_EC_REF_LOOPBACK_MONO) ||
3023 (snd_device == SND_DEVICE_IN_EC_REF_LOOPBACK_STEREO))
3024 audio_extn_ffv_append_ec_ref_dev_name(device_name);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303025 } else {
3026 strlcpy(device_name, "", DEVICE_NAME_MAX_SIZE);
3027 return -EINVAL;
3028 }
3029
3030 return 0;
3031}
3032
Banajit Goswami20cdd212015-09-11 01:11:30 -07003033void platform_add_backend_name(char *mixer_path, snd_device_t snd_device,
3034 struct audio_usecase *usecase)
Naresh Tannirue3b18452014-03-04 14:44:27 +05303035{
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303036 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
3037 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
3038 return;
3039 }
3040
Rohit kumarf4120402016-08-05 19:19:48 +05303041 if ((snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_VBAT ||
3042 snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_2_VBAT) &&
Banajit Goswami20cdd212015-09-11 01:11:30 -07003043 !(usecase->type == VOICE_CALL || usecase->type == VOIP_CALL)) {
3044 ALOGI("%s: Not adding vbat speaker device to non voice use cases", __func__);
3045 return;
3046 }
3047
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05303048 const char * suffix = backend_tag_table[snd_device];
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303049
3050 if (suffix != NULL) {
3051 strlcat(mixer_path, " ", MIXER_PATH_MAX_LENGTH);
3052 strlcat(mixer_path, suffix, MIXER_PATH_MAX_LENGTH);
3053 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05303054}
3055
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05303056bool platform_check_backends_match(snd_device_t snd_device1, snd_device_t snd_device2)
3057{
3058 bool result = true;
3059
3060 ALOGV("%s: snd_device1 = %s, snd_device2 = %s", __func__,
3061 platform_get_snd_device_name(snd_device1),
3062 platform_get_snd_device_name(snd_device2));
3063
3064 if ((snd_device1 < SND_DEVICE_MIN) || (snd_device1 >= SND_DEVICE_OUT_END)) {
3065 ALOGE("%s: Invalid snd_device = %s", __func__,
3066 platform_get_snd_device_name(snd_device1));
3067 return false;
3068 }
3069 if ((snd_device2 < SND_DEVICE_MIN) || (snd_device2 >= SND_DEVICE_OUT_END)) {
3070 ALOGE("%s: Invalid snd_device = %s", __func__,
3071 platform_get_snd_device_name(snd_device2));
3072 return false;
3073 }
3074 const char * be_itf1 = hw_interface_table[snd_device1];
3075 const char * be_itf2 = hw_interface_table[snd_device2];
3076
3077 if (NULL != be_itf1 && NULL != be_itf2) {
Kuirong Wangb9fbb1e2016-05-03 18:36:39 -07003078 if ((NULL == strstr(be_itf2, be_itf1)) && (NULL == strstr(be_itf1, be_itf2)))
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05303079 result = false;
Naresh Tanniru25873b82016-11-01 14:15:28 +05303080 } else if (NULL == be_itf1 && NULL != be_itf2 && (NULL == strstr(be_itf2, default_rx_backend))) {
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05303081 result = false;
Naresh Tanniru25873b82016-11-01 14:15:28 +05303082 } else if (NULL != be_itf1 && NULL == be_itf2 && (NULL == strstr(be_itf1, default_rx_backend))) {
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05303083 result = false;
3084 }
3085
3086 ALOGV("%s: be_itf1 = %s, be_itf2 = %s, match %d", __func__, be_itf1, be_itf2, result);
3087 return result;
3088}
3089
Naresh Tannirue3b18452014-03-04 14:44:27 +05303090int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
3091{
Venkata Narendra Kumar Guttaed408a12015-03-31 20:24:04 +05303092 int device_id = -1;
3093
Mingshu Pang1513f972019-05-24 12:43:51 +08003094 if ((usecase >= AUDIO_USECASE_MAX) || (usecase <= USECASE_INVALID)) {
3095 ALOGE("%s: invalid usecase case idx %d", __func__, usecase);
3096 return device_id;
3097 }
Karthik Reddy Katta561d4ba2016-06-23 13:41:18 +05303098 if (device_type == PCM_PLAYBACK)
3099 device_id = pcm_device_table[usecase][0];
3100 else
3101 device_id = pcm_device_table[usecase][1];
Naresh Tannirue3b18452014-03-04 14:44:27 +05303102 return device_id;
3103}
3104
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303105static int find_index(struct name_to_index * table, int32_t len, const char * name)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303106{
3107 int ret = 0;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303108 int32_t i;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303109
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303110 if (table == NULL) {
3111 ALOGE("%s: table is NULL", __func__);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303112 ret = -ENODEV;
3113 goto done;
3114 }
3115
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303116 if (name == NULL) {
3117 ALOGE("null key");
3118 ret = -ENODEV;
3119 goto done;
3120 }
3121
3122 for (i=0; i < len; i++) {
3123 const char* tn = table[i].name;
3124 size_t len = strlen(tn);
3125 if (strncmp(tn, name, len) == 0) {
3126 if (strlen(name) != len) {
3127 continue; // substring
3128 }
3129 ret = table[i].index;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303130 goto done;
3131 }
3132 }
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303133 ALOGE("%s: Could not find index for name = %s",
3134 __func__, name);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303135 ret = -ENODEV;
3136done:
3137 return ret;
3138}
3139
Venkata Narendra Kumar Gutta88fd0bc2014-03-27 19:47:56 +05303140int platform_set_fluence_type(void *platform, char *value)
3141{
3142 int ret = 0;
3143 int fluence_type = FLUENCE_NONE;
3144 int fluence_flag = NONE_FLAG;
3145 struct platform_data *my_data = (struct platform_data *)platform;
3146 struct audio_device *adev = my_data->adev;
3147
3148 ALOGV("%s: fluence type:%d", __func__, my_data->fluence_type);
3149
3150 /* only dual mic turn on and off is supported as of now through setparameters */
3151 if (!strncmp(AUDIO_PARAMETER_VALUE_DUALMIC,value, sizeof(AUDIO_PARAMETER_VALUE_DUALMIC))) {
3152 if (!strncmp("fluencepro", my_data->fluence_cap, sizeof("fluencepro")) ||
3153 !strncmp("fluence", my_data->fluence_cap, sizeof("fluence"))) {
3154 ALOGV("fluence dualmic feature enabled \n");
3155 fluence_type = FLUENCE_DUAL_MIC;
3156 fluence_flag = DMIC_FLAG;
3157 } else {
3158 ALOGE("%s: Failed to set DUALMIC", __func__);
3159 ret = -1;
3160 goto done;
3161 }
3162 } else if (!strncmp(AUDIO_PARAMETER_KEY_NO_FLUENCE, value, sizeof(AUDIO_PARAMETER_KEY_NO_FLUENCE))) {
3163 ALOGV("fluence disabled");
3164 fluence_type = FLUENCE_NONE;
3165 } else {
3166 ALOGE("Invalid fluence value : %s",value);
3167 ret = -1;
3168 goto done;
3169 }
3170
3171 if (fluence_type != my_data->fluence_type) {
3172 ALOGV("%s: Updating fluence_type to :%d", __func__, fluence_type);
3173 my_data->fluence_type = fluence_type;
3174 adev->acdb_settings = (adev->acdb_settings & FLUENCE_MODE_CLEAR) | fluence_flag;
3175 }
3176done:
3177 return ret;
3178}
3179
3180int platform_get_fluence_type(void *platform, char *value, uint32_t len)
3181{
3182 int ret = 0;
3183 struct platform_data *my_data = (struct platform_data *)platform;
3184
Garmond Leunge2433c32017-09-28 21:51:22 -07003185 if (my_data->fluence_type == FLUENCE_HEX_MIC) {
3186 strlcpy(value, "hexmic", len);
3187 } else if (my_data->fluence_type == FLUENCE_QUAD_MIC) {
Venkata Narendra Kumar Gutta88fd0bc2014-03-27 19:47:56 +05303188 strlcpy(value, "quadmic", len);
Vikram Pandurangaf0ca0b12018-05-04 16:00:07 -07003189 } else if (my_data->fluence_type == FLUENCE_TRI_MIC) {
3190 strlcpy(value, "trimic", len);
Venkata Narendra Kumar Gutta88fd0bc2014-03-27 19:47:56 +05303191 } else if (my_data->fluence_type == FLUENCE_DUAL_MIC) {
3192 strlcpy(value, "dualmic", len);
3193 } else if (my_data->fluence_type == FLUENCE_NONE) {
3194 strlcpy(value, "none", len);
3195 } else
3196 ret = -1;
3197
3198 return ret;
3199}
3200
Carter Hsu32a62362018-10-15 15:01:42 -07003201void platform_add_external_specific_device(snd_device_t snd_device __unused,
3202 const char *name __unused,
3203 unsigned int acdb_id __unused)
3204{
3205 return;
3206}
3207
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303208int platform_get_snd_device_index(char *device_name)
3209{
3210 return find_index(snd_device_name_index, SND_DEVICE_MAX, device_name);
3211}
3212
3213int platform_get_usecase_index(const char *usecase_name)
3214{
3215 return find_index(usecase_name_index, AUDIO_USECASE_MAX, usecase_name);
3216}
3217
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07003218int platform_get_effect_config_data(snd_device_t snd_device,
3219 struct audio_effect_config *effect_config,
3220 effect_type_t effect_type)
3221{
3222 int ret = 0;
3223
3224 if ((snd_device < SND_DEVICE_IN_BEGIN) || (snd_device >= SND_DEVICE_MAX) ||
3225 (effect_type <= EFFECT_NONE) || (effect_type >= EFFECT_MAX)) {
3226 ALOGE("%s: Invalid snd_device = %d",
3227 __func__, snd_device);
3228 ret = -EINVAL;
3229 goto done;
3230 }
3231
3232 if (effect_config == NULL) {
3233 ALOGE("%s: Invalid effect_config", __func__);
3234 ret = -EINVAL;
3235 goto done;
3236 }
3237
3238 ALOGV("%s: snd_device = %d module_id = %d",
3239 __func__, snd_device, effect_config_table[GET_IN_DEVICE_INDEX(snd_device)][effect_type].module_id);
3240 memcpy(effect_config, &effect_config_table[GET_IN_DEVICE_INDEX(snd_device)][effect_type],
3241 sizeof(struct audio_effect_config));
3242
3243done:
3244 return ret;
3245}
3246
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303247int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
3248{
3249 int ret = 0;
3250
3251 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
3252 ALOGE("%s: Invalid snd_device = %d",
3253 __func__, snd_device);
3254 ret = -EINVAL;
3255 goto done;
3256 }
3257
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05303258 ALOGV("%s: acdb_device_table[%s]: old = %d new = %d", __func__,
3259 platform_get_snd_device_name(snd_device), acdb_device_table[snd_device], acdb_id);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303260 acdb_device_table[snd_device] = acdb_id;
3261done:
3262 return ret;
3263}
3264
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07003265int platform_set_effect_config_data(snd_device_t snd_device,
3266 struct audio_effect_config effect_config,
3267 effect_type_t effect_type)
3268{
3269 int ret = 0;
3270
3271 if ((snd_device < SND_DEVICE_IN_BEGIN) || (snd_device >= SND_DEVICE_MAX) ||
3272 (effect_type <= EFFECT_NONE) || (effect_type >= EFFECT_MAX)) {
3273 ALOGE("%s: Invalid snd_device = %d",
3274 __func__, snd_device);
3275 ret = -EINVAL;
3276 goto done;
3277 }
3278
3279 ALOGV("%s 0x%x 0x%x 0x%x 0x%x", __func__, effect_config.module_id,
3280 effect_config.instance_id, effect_config.param_id,
3281 effect_config.param_value);
3282 effect_config_table[GET_IN_DEVICE_INDEX(snd_device)][effect_type] = effect_config;
3283
3284done:
3285 return ret;
3286}
3287
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05303288int platform_set_acdb_metainfo_key(void *platform, char *name, int key)
3289{
3290 struct meta_key_list *key_info;
3291 struct platform_data *pdata = (struct platform_data *)platform;
3292
3293 key_info = (struct meta_key_list *)calloc(1, sizeof(struct meta_key_list));
3294 if (!key_info) {
3295 ALOGE("%s: Could not allocate memory for key %d", __func__, key);
3296 return -ENOMEM;
3297 }
3298
3299 key_info->cal_info.nKey = key;
3300 strlcpy(key_info->name, name, sizeof(key_info->name));
3301 list_add_tail(&pdata->acdb_meta_key_list, &key_info->list);
3302 ALOGD("%s: successfully added module %s and key %d to the list", __func__,
3303 key_info->name, key_info->cal_info.nKey);
3304 return 0;
3305}
3306
Surendar karka30569792018-05-08 12:02:21 +05303307int platform_get_license_by_product
3308(
3309 void *platform,
3310 const char* product_name,
3311 int* product_id,
3312 char* product_license
3313)
3314{
3315 int ret = 0;
3316 int id = 0;
3317 acdb_audio_cal_cfg_t cal;
3318 uint32_t param_len = LICENSE_STR_MAX_LEN;
3319 struct platform_data *my_data = (struct platform_data *)platform;
3320
3321 if ((NULL == platform) || (NULL == product_name) || (NULL == product_id)) {
3322 ALOGE("[%s] Invalid input parameters",__func__);
3323 ret = -EINVAL;
3324 goto on_error;
3325 }
3326
3327 id = platform_get_meta_info_key_from_list(platform, (char*)product_name);
3328 if(0 == id)
3329 {
3330 ALOGE("%s:Id not found for %s", __func__, product_name);
3331 ret = -EINVAL;
3332 goto on_error;
3333 }
3334
3335 ALOGD("%s: Found Id[%d] for %s", __func__, id, product_name);
3336 if(NULL == my_data->acdb_get_audio_cal){
3337 ALOGE("[%s] acdb_get_audio_cal is NULL.",__func__);
3338 ret = -ENOSYS;
3339 goto on_error;
3340 }
3341
3342 memset(&cal, 0, sizeof(cal));
3343 cal.persist = 1;
3344 cal.cal_type = AUDIO_CORE_METAINFO_CAL_TYPE;
3345 cal.acdb_dev_id = (uint32_t) id;
3346 ret = my_data->acdb_get_audio_cal((void*)&cal, (void*)product_license, &param_len);
3347
3348 if (0 == ret) {
3349 ALOGD("%s: Got Length[%d] License[%s]", __func__, param_len, product_license );
3350 *product_id = id;
3351 return 0;
3352 }
3353 ALOGD("%s: License not found for %s", __func__, product_name);
3354
3355on_error:
Satish Babu Patakokilaf0c46eb2018-06-01 12:34:18 +05303356 if (product_id)
3357 *product_id = 0;
Surendar karka30569792018-05-08 12:02:21 +05303358 return ret;
3359}
3360
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05303361int platform_get_meta_info_key_from_list(void *platform, char *mod_name)
3362{
3363 struct listnode *node;
3364 struct meta_key_list *key_info;
3365 struct platform_data *pdata = (struct platform_data *)platform;
3366 int key = 0;
3367
3368 ALOGV("%s: for module %s", __func__, mod_name);
3369
3370 list_for_each(node, &pdata->acdb_meta_key_list) {
3371 key_info = node_to_item(node, struct meta_key_list, list);
3372 if (strcmp(key_info->name, mod_name) == 0) {
3373 key = key_info->cal_info.nKey;
3374 ALOGD("%s: Found key %d for module %s", __func__, key, mod_name);
3375 break;
3376 }
3377 }
3378 return key;
3379}
3380
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -07003381int platform_get_default_app_type(void *platform)
3382{
3383 struct platform_data *my_data = (struct platform_data *)platform;
3384
3385 if (my_data->acdb_get_default_app_type)
3386 return my_data->acdb_get_default_app_type();
3387 else
3388 return DEFAULT_APP_TYPE;
3389}
3390
Satya Krishna Pindiprolif1cd92b2016-04-14 19:05:23 +05303391int platform_get_default_app_type_v2(void *platform __unused,
3392 usecase_type_t type __unused)
Srikanth Uyyalaa1e32352015-10-09 14:48:04 +05303393{
3394 if(type == PCM_CAPTURE)
3395 return DEFAULT_APP_TYPE_TX_PATH;
3396 else
3397 return DEFAULT_APP_TYPE_RX_PATH;
3398}
3399
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -07003400int platform_get_snd_device_acdb_id(snd_device_t snd_device)
3401{
3402 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
3403 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
3404 return -EINVAL;
3405 }
3406 return acdb_device_table[snd_device];
3407}
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303408
3409int platform_set_snd_device_bit_width(snd_device_t snd_device, unsigned int bit_width)
Amit Shekhar5a39c912014-10-14 15:39:30 -07003410{
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303411 int ret = 0;
3412
3413 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
3414 ALOGE("%s: Invalid snd_device = %d",
3415 __func__, snd_device);
3416 ret = -EINVAL;
3417 goto done;
3418 }
3419
3420 backend_bit_width_table[snd_device] = bit_width;
3421done:
3422 return ret;
Amit Shekhar5a39c912014-10-14 15:39:30 -07003423}
3424
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303425int platform_get_snd_device_bit_width(snd_device_t snd_device)
Amit Shekhar5a39c912014-10-14 15:39:30 -07003426{
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303427 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
3428 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
Ashish Jainb449be32015-07-19 05:39:23 -07003429 return CODEC_BACKEND_DEFAULT_BIT_WIDTH;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303430 }
3431 return backend_bit_width_table[snd_device];
Amit Shekhar5a39c912014-10-14 15:39:30 -07003432}
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05303433int platform_set_native_support(int na_mode)
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08003434{
Preetam Singh Ranawat3e5b9e72016-11-10 16:12:25 +05303435 if (NATIVE_AUDIO_MODE_SRC == na_mode || NATIVE_AUDIO_MODE_TRUE_44_1 == na_mode
Preetam Singh Ranawatb1c73232019-04-22 13:59:51 +05303436 || NATIVE_AUDIO_MODE_MULTIPLE_MIX_IN_CODEC == na_mode
3437 || NATIVE_AUDIO_MODE_MULTIPLE_MIX_IN_DSP == na_mode) {
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05303438 na_props.platform_na_prop_enabled = na_props.ui_na_prop_enabled = true;
3439 na_props.na_mode = na_mode;
Ashish Jain6fced6e2017-01-09 14:13:22 +05303440 ALOGD("%s:napb: native audio playback enabled in (%s) mode", __func__,
3441 ((na_mode == NATIVE_AUDIO_MODE_SRC)?"SRC":
Preetam Singh Ranawatb1c73232019-04-22 13:59:51 +05303442 (na_mode == NATIVE_AUDIO_MODE_TRUE_44_1)?"True":
3443 (na_mode == NATIVE_AUDIO_MODE_MULTIPLE_MIX_IN_CODEC)?"Multiple_Mix_Codec":"Multiple_Mix_DSP"));
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05303444 } else {
3445 na_props.platform_na_prop_enabled = false;
3446 na_props.na_mode = NATIVE_AUDIO_MODE_INVALID;
3447 ALOGD("%s:napb: native audio playback disabled", __func__);
3448 }
3449
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08003450 return 0;
3451}
Preetam Singh Ranawat3e5b9e72016-11-10 16:12:25 +05303452bool platform_check_codec_dsd_support(void *platform)
3453{
3454 struct platform_data *my_data = (struct platform_data *)platform;
3455 return my_data->is_dsd_supported;
3456}
3457bool platform_check_codec_asrc_support(void *platform)
3458{
3459 struct platform_data *my_data = (struct platform_data *)platform;
3460 return my_data->is_asrc_supported;
3461}
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08003462
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05303463int platform_get_native_support()
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08003464{
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05303465 int ret = NATIVE_AUDIO_MODE_INVALID;
3466 if (na_props.platform_na_prop_enabled &&
3467 na_props.ui_na_prop_enabled) {
3468 ret = na_props.na_mode;
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05303469 }
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05303470 ALOGV("%s:napb: ui Prop enabled(%d) version(%d)", __func__,
3471 na_props.ui_na_prop_enabled, na_props.na_mode);
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05303472 return ret;
3473}
3474
3475void native_audio_get_params(struct str_parms *query,
3476 struct str_parms *reply,
3477 char *value, int len)
3478{
3479 int ret;
3480 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_NATIVE_AUDIO,
3481 value, len);
3482 if (ret >= 0) {
3483 if (na_props.platform_na_prop_enabled) {
3484 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_NATIVE_AUDIO,
3485 na_props.ui_na_prop_enabled ? "true" : "false");
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05303486 ALOGV("%s:napb: na_props.ui_na_prop_enabled: %d", __func__,
3487 na_props.ui_na_prop_enabled);
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05303488 } else {
3489 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_NATIVE_AUDIO,
3490 "false");
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05303491 ALOGV("%s:napb: native audio not supported: %d", __func__,
3492 na_props.platform_na_prop_enabled);
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05303493 }
3494 }
3495}
3496
3497int native_audio_set_params(struct platform_data *platform,
3498 struct str_parms *parms, char *value, int len)
3499{
Preetam Singh Ranawat53194302016-03-15 16:37:42 +05303500 int ret = -1;
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05303501 struct audio_usecase *usecase;
3502 struct listnode *node;
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05303503 int mode = NATIVE_AUDIO_MODE_INVALID;
3504
Preetam Singh Ranawat6746b7a2016-07-18 16:40:24 +05303505 if (!value || !parms)
Preetam Singh Ranawat53194302016-03-15 16:37:42 +05303506 return ret;
3507
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05303508 ret = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_NATIVE_AUDIO_MODE,
3509 value, len);
3510 if (ret >= 0) {
3511 if (value && !strncmp(value, "src", sizeof("src")))
3512 mode = NATIVE_AUDIO_MODE_SRC;
3513 else if (value && !strncmp(value, "true", sizeof("true")))
3514 mode = NATIVE_AUDIO_MODE_TRUE_44_1;
Preetam Singh Ranawatb1c73232019-04-22 13:59:51 +05303515 else if (value && !strncmp(value, "multiple_mix_codec", sizeof("multiple")))
3516 mode = NATIVE_AUDIO_MODE_MULTIPLE_MIX_IN_CODEC;
3517 else if (value && !strncmp(value, "multiple_mix_dsp", sizeof("multiple")))
3518 mode = NATIVE_AUDIO_MODE_MULTIPLE_MIX_IN_DSP;
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05303519 else {
3520 mode = NATIVE_AUDIO_MODE_INVALID;
3521 ALOGE("%s:napb:native_audio_mode in platform info xml,invalid mode string",
3522 __func__);
3523 }
3524 ALOGD("%s:napb updating mode (%d) from XML",__func__, mode);
3525 platform_set_native_support(mode);
3526 }
3527
3528
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05303529
3530 ret = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_NATIVE_AUDIO,
3531 value, len);
3532 if (ret >= 0) {
3533 if (na_props.platform_na_prop_enabled) {
Sidipotu Ashok894644d2015-07-06 18:35:03 +05303534 if (!strncmp("true", value, sizeof("true"))) {
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05303535 na_props.ui_na_prop_enabled = true;
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05303536 ALOGD("%s:napb: native audio feature enabled from UI",
3537 __func__);
Sidipotu Ashok894644d2015-07-06 18:35:03 +05303538 }
3539 else {
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05303540 na_props.ui_na_prop_enabled = false;
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05303541 ALOGD("%s:napb: native audio feature disabled from UI",
3542 __func__);
Sidipotu Ashok894644d2015-07-06 18:35:03 +05303543 }
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05303544
3545 str_parms_del(parms, AUDIO_PARAMETER_KEY_NATIVE_AUDIO);
3546
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05303547 /*
3548 * Iterate through the usecase list and trigger device switch for
3549 * all the appropriate usecases
3550 */
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05303551 list_for_each(node, &(platform->adev)->usecase_list) {
3552 usecase = node_to_item(node, struct audio_usecase, list);
3553
Sujin Panicker390724d2019-04-26 10:43:36 +05303554 if (usecase->stream.out && is_offload_usecase(usecase->id) &&
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05303555 (usecase->stream.out->devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
3556 usecase->stream.out->devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) &&
3557 OUTPUT_SAMPLING_RATE_44100 == usecase->stream.out->sample_rate) {
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05303558 ALOGD("%s:napb: triggering dynamic device switch for usecase(%d: %s)"
Sidipotu Ashok894644d2015-07-06 18:35:03 +05303559 " stream(%p), device(%d)", __func__, usecase->id,
Alexy Josephb1379942016-01-29 15:49:38 -08003560 use_case_table[usecase->id], (void*) usecase->stream.out,
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05303561 usecase->stream.out->devices);
Sidipotu Ashok894644d2015-07-06 18:35:03 +05303562 select_devices(platform->adev, usecase->id);
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05303563 }
3564 }
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05303565 } else
3566 ALOGD("%s:napb: native audio cannot be enabled from UI",
3567 __func__);
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05303568 }
3569 return ret;
3570}
3571
Ashish Jainf1eaa582016-05-23 20:54:24 +05303572static void true_32_bit_set_params(struct str_parms *parms,
3573 char *value, int len)
3574{
3575 int ret = 0;
3576
3577 ret = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_TRUE_32_BIT,
3578 value,len);
3579 if (ret >= 0) {
3580 if (value && !strncmp(value, "true", sizeof("src")))
3581 supports_true_32_bit = true;
3582 else
3583 supports_true_32_bit = false;
3584 str_parms_del(parms, AUDIO_PARAMETER_KEY_TRUE_32_BIT);
3585 }
3586
3587}
3588
3589bool platform_supports_true_32bit()
3590{
3591 return supports_true_32_bit;
3592}
3593
Sidipotu Ashokad8fff82016-02-02 10:48:42 +05303594int check_hdset_combo_device(snd_device_t snd_device)
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05303595{
3596 int ret = false;
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05303597
Sidipotu Ashokad8fff82016-02-02 10:48:42 +05303598 if (SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES == snd_device ||
3599 SND_DEVICE_OUT_SPEAKER_AND_LINE == snd_device ||
3600 SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_1 == snd_device ||
3601 SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_2 == snd_device ||
3602 SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET == snd_device)
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05303603 ret = true;
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05303604
3605 return ret;
3606}
3607
Ashish Jainb26edfb2016-08-25 00:10:11 +05303608int codec_device_supports_native_playback(audio_devices_t out_device)
kunleiz207afaa2016-07-22 14:26:49 +08003609{
Ashish Jainb26edfb2016-08-25 00:10:11 +05303610 int ret = false;
kunleiz207afaa2016-07-22 14:26:49 +08003611
3612 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
3613 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
3614 out_device & AUDIO_DEVICE_OUT_LINE)
Ashish Jainb26edfb2016-08-25 00:10:11 +05303615 ret = true;
kunleiz207afaa2016-07-22 14:26:49 +08003616
3617 return ret;
3618}
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05303619
Preetam Singh Ranawatcb6212e2016-07-19 18:33:53 +05303620int platform_get_backend_index(snd_device_t snd_device)
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05303621{
3622 int32_t port = DEFAULT_CODEC_BACKEND;
3623
Kuirong Wang0b947f72016-09-29 11:03:09 -07003624 if (snd_device >= SND_DEVICE_OUT_BEGIN && snd_device < SND_DEVICE_OUT_END) {
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05303625 if (backend_tag_table[snd_device] != NULL) {
3626 if (strncmp(backend_tag_table[snd_device], "headphones-44.1",
3627 sizeof("headphones-44.1")) == 0)
3628 port = HEADPHONE_44_1_BACKEND;
Preetam Singh Ranawat3e5b9e72016-11-10 16:12:25 +05303629 else if (strncmp(backend_tag_table[snd_device], "headphones-dsd",
3630 sizeof("headphones-dsd")) == 0)
3631 port = DSD_NATIVE_BACKEND;
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05303632 else if (strncmp(backend_tag_table[snd_device], "headphones",
3633 sizeof("headphones")) == 0)
3634 port = HEADPHONE_BACKEND;
3635 else if (strcmp(backend_tag_table[snd_device], "hdmi") == 0)
3636 port = HDMI_RX_BACKEND;
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07003637 else if (strcmp(backend_tag_table[snd_device], "display-port") == 0)
3638 port = DISP_PORT_RX_BACKEND;
Satya Krishna Pindiprolif5eddfd2016-12-28 11:29:08 +05303639 else if ((strcmp(backend_tag_table[snd_device], "usb-headphones") == 0) ||
3640 (strcmp(backend_tag_table[snd_device], "usb-headset") == 0))
Kuirong Wanga9f7cee2016-03-07 11:21:52 -08003641 port = USB_AUDIO_RX_BACKEND;
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05303642 }
Kuirong Wang0b947f72016-09-29 11:03:09 -07003643 } else if (snd_device >= SND_DEVICE_IN_BEGIN && snd_device < SND_DEVICE_IN_END) {
3644 port = DEFAULT_CODEC_TX_BACKEND;
Kuirong Wange9894162016-08-26 15:16:39 -07003645 if (backend_tag_table[snd_device] != NULL) {
3646 if (strcmp(backend_tag_table[snd_device], "usb-headset-mic") == 0)
3647 port = USB_AUDIO_TX_BACKEND;
Dhanalakshmi Siddanib678a802016-12-03 11:51:41 +05303648 else if (strstr(backend_tag_table[snd_device], "bt-sco") != NULL)
3649 port = BT_SCO_TX_BACKEND;
Siddartha Shaik44dd7702017-06-14 12:13:25 +05303650 else if (strcmp(backend_tag_table[snd_device], "hdmi-mic") == 0)
3651 port = HDMI_TX_BACKEND;
Kuirong Wange9894162016-08-26 15:16:39 -07003652 }
3653 } else {
Kuirong Wang0b947f72016-09-29 11:03:09 -07003654 ALOGW("%s:napb: Invalid device - %d ", __func__, snd_device);
Kuirong Wange9894162016-08-26 15:16:39 -07003655 }
3656
Kuirong Wang0b947f72016-09-29 11:03:09 -07003657 ALOGV("%s:napb: backend port - %d device - %d ", __func__, port, snd_device);
Kuirong Wange9894162016-08-26 15:16:39 -07003658 return port;
3659}
3660
Preetam Singh Ranawat2d0e4632015-02-02 12:40:59 +05303661int platform_send_audio_calibration(void *platform, struct audio_usecase *usecase,
Zhou Song06761dd2019-04-28 18:08:17 +08003662 int app_type)
Naresh Tannirue3b18452014-03-04 14:44:27 +05303663{
3664 struct platform_data *my_data = (struct platform_data *)platform;
3665 int acdb_dev_id, acdb_dev_type;
Preetam Singh Ranawat2d0e4632015-02-02 12:40:59 +05303666 int snd_device = SND_DEVICE_OUT_SPEAKER;
Siena Richard7c2db772016-12-21 11:32:34 -08003667 int new_snd_device[SND_DEVICE_OUT_END] = {0};
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05303668 int i, num_devices = 1;
Aditya Bavanari9e957d82019-01-29 17:47:13 +05303669 bool is_incall_rec_usecase = false;
3670 snd_device_t incall_rec_device;
Zhou Song06761dd2019-04-28 18:08:17 +08003671 int sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE;
Aditya Bavanari9e957d82019-01-29 17:47:13 +05303672
3673 if (voice_is_in_call(my_data->adev))
3674 is_incall_rec_usecase = voice_is_in_call_rec_stream(usecase->stream.in);
Preetam Singh Ranawat2d0e4632015-02-02 12:40:59 +05303675
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303676 if (usecase->type == PCM_PLAYBACK)
Naresh Tannirucc7c4de2015-03-10 16:19:23 +05303677 snd_device = usecase->out_snd_device;
Aditya Bavanari9e957d82019-01-29 17:47:13 +05303678 else if ((usecase->type == PCM_CAPTURE) && is_incall_rec_usecase)
Karthik Reddy Katta81c42612015-11-13 17:49:07 +05303679 snd_device = voice_get_incall_rec_snd_device(usecase->in_snd_device);
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303680 else if ((usecase->type == PCM_HFP_CALL) || (usecase->type == PCM_CAPTURE))
Naresh Tannirucc7c4de2015-03-10 16:19:23 +05303681 snd_device = usecase->in_snd_device;
Surendar Karka93cd25a2018-08-28 14:21:37 +05303682 else if (usecase->type == TRANSCODE_LOOPBACK_RX)
Siddartha Shaik343abc62017-08-08 11:15:25 +05303683 snd_device = usecase->out_snd_device;
3684
Xiaojun Sang040cc9f2015-08-03 19:38:28 +08003685 acdb_dev_id = acdb_device_table[platform_get_spkr_prot_snd_device(snd_device)];
Naresh Tannirue3b18452014-03-04 14:44:27 +05303686
Aditya Bavanari9e957d82019-01-29 17:47:13 +05303687 if (!is_incall_rec_usecase) {
3688 if (platform_split_snd_device(my_data, snd_device,
3689 &num_devices, new_snd_device) < 0) {
3690 new_snd_device[0] = snd_device;
3691 }
3692 } else {
3693 incall_rec_device = voice_get_incall_rec_backend_device(usecase->stream.in);
3694 if (platform_split_snd_device(my_data, incall_rec_device,
3695 &num_devices, new_snd_device) < 0) {
3696 new_snd_device[0] = snd_device;
3697 }
Naresh Tanniru2727f822015-05-11 15:27:08 +05303698 }
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05303699
3700 for (i = 0; i < num_devices; i++) {
Zhou Song06761dd2019-04-28 18:08:17 +08003701 if (!is_incall_rec_usecase) {
Aditya Bavanari9e957d82019-01-29 17:47:13 +05303702 acdb_dev_id = acdb_device_table[platform_get_spkr_prot_snd_device(new_snd_device[i])];
Zhou Song06761dd2019-04-28 18:08:17 +08003703 sample_rate = audio_extn_utils_get_app_sample_rate_for_device(my_data->adev, usecase,
3704 new_snd_device[i]);
3705 } else {
Aditya Bavanari9e957d82019-01-29 17:47:13 +05303706 // Use in_call_rec snd_device to extract the ACDB device ID instead of split snd devices
3707 acdb_dev_id = acdb_device_table[platform_get_spkr_prot_snd_device(snd_device)];
Zhou Song06761dd2019-04-28 18:08:17 +08003708 sample_rate = audio_extn_utils_get_app_sample_rate_for_device(my_data->adev, usecase,
3709 snd_device);
3710 }
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05303711
3712 // Do not use Rx path default app type for TX path
3713 if ((usecase->type == PCM_CAPTURE) && (app_type == DEFAULT_APP_TYPE_RX_PATH)) {
3714 ALOGD("Resetting app type for Tx path to default");
3715 app_type = DEFAULT_APP_TYPE_TX_PATH;
3716 }
3717 if (acdb_dev_id < 0) {
3718 ALOGE("%s: Could not find acdb id for device(%d)",
3719 __func__, new_snd_device[i]);
3720 return -EINVAL;
3721 }
Weiyin Jiang27dd1452019-07-12 23:46:06 +08003722
3723 /* Notify device change info to effect clients registered */
3724 if (usecase->type == PCM_PLAYBACK) {
3725 audio_extn_gef_notify_device_config(
3726 usecase->stream.out->devices,
3727 usecase->stream.out->channel_mask,
3728 sample_rate,
3729 acdb_dev_id,
3730 usecase->stream.out->app_type_cfg.app_type);
3731 }
3732
Siena Richard7c2db772016-12-21 11:32:34 -08003733 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
3734 __func__, new_snd_device[i], acdb_dev_id);
3735 if (new_snd_device[i] >= SND_DEVICE_OUT_BEGIN &&
3736 new_snd_device[i] < SND_DEVICE_OUT_END)
3737 acdb_dev_type = ACDB_DEV_TYPE_OUT;
3738 else
3739 acdb_dev_type = ACDB_DEV_TYPE_IN;
3740
3741 if (my_data->acdb_send_audio_cal_v3) {
3742 my_data->acdb_send_audio_cal_v3(acdb_dev_id, acdb_dev_type, app_type,
3743 sample_rate, i);
3744 } else if (my_data->acdb_send_audio_cal) {
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05303745 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type, app_type,
3746 sample_rate);
3747 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05303748 }
3749 return 0;
3750}
3751
3752int platform_switch_voice_call_device_pre(void *platform)
3753{
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303754 struct platform_data *my_data = (struct platform_data *)platform;
3755 int ret = 0;
3756
3757 if (my_data->csd != NULL &&
Ravi Kumar Alamandabe149392014-10-20 17:07:43 -07003758 voice_is_in_call(my_data->adev)) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303759 /* This must be called before disabling mixer controls on APQ side */
3760 ret = my_data->csd->disable_device();
3761 if (ret < 0) {
3762 ALOGE("%s: csd_client_disable_device, failed, error %d",
3763 __func__, ret);
3764 }
3765 }
3766 return ret;
Naresh Tannirue3b18452014-03-04 14:44:27 +05303767}
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303768
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303769int platform_switch_voice_call_enable_device_config(void *platform,
3770 snd_device_t out_snd_device,
3771 snd_device_t in_snd_device)
3772{
3773 struct platform_data *my_data = (struct platform_data *)platform;
3774 int acdb_rx_id, acdb_tx_id;
3775 int ret = 0;
3776
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303777 if (my_data->csd == NULL)
3778 return ret;
3779
Banajit Goswami20cdd212015-09-11 01:11:30 -07003780 if ((out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER ||
Rohit kumarf4120402016-08-05 19:19:48 +05303781 out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_2 ||
3782 out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_VBAT ||
3783 out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_2_VBAT) &&
Banajit Goswami20cdd212015-09-11 01:11:30 -07003784 audio_extn_spkr_prot_is_enabled()) {
3785 if (my_data->is_vbat_speaker)
3786 acdb_rx_id = acdb_device_table[SND_DEVICE_OUT_SPEAKER_PROTECTED_VBAT];
3787 else
3788 acdb_rx_id = acdb_device_table[SND_DEVICE_OUT_SPEAKER_PROTECTED];
3789 } else
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303790 acdb_rx_id = acdb_device_table[out_snd_device];
3791
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303792 acdb_tx_id = acdb_device_table[in_snd_device];
3793
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303794 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
3795 ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
3796 if (ret < 0) {
3797 ALOGE("%s: csd_enable_device_config, failed, error %d",
3798 __func__, ret);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303799 }
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303800 } else {
3801 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
3802 acdb_rx_id, acdb_tx_id);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303803 }
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303804
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303805 return ret;
3806}
3807
Naresh Tannirue3b18452014-03-04 14:44:27 +05303808int platform_switch_voice_call_device_post(void *platform,
3809 snd_device_t out_snd_device,
3810 snd_device_t in_snd_device)
3811{
3812 struct platform_data *my_data = (struct platform_data *)platform;
3813 int acdb_rx_id, acdb_tx_id;
3814
3815 if (my_data->acdb_send_voice_cal == NULL) {
3816 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
3817 } else {
Rohit kumarf4120402016-08-05 19:19:48 +05303818 if (audio_extn_spkr_prot_is_enabled()) {
3819 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER ||
3820 out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_WSA)
3821 out_snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED;
Vikram Panduranga8c68e862018-04-27 12:59:42 -07003822 else if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_STEREO)
3823 out_snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_STEREO_PROTECTED;
Rohit kumarf4120402016-08-05 19:19:48 +05303824 else if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_2 ||
3825 out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_2_WSA)
3826 out_snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_2_PROTECTED;
3827 else if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_VBAT)
3828 out_snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED_VBAT;
3829 else if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_2_VBAT)
3830 out_snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_2_PROTECTED_VBAT;
3831 }
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303832
Naresh Tannirue3b18452014-03-04 14:44:27 +05303833 acdb_rx_id = acdb_device_table[out_snd_device];
3834 acdb_tx_id = acdb_device_table[in_snd_device];
3835
3836 if (acdb_rx_id > 0 && acdb_tx_id > 0)
3837 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
3838 else
3839 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
3840 acdb_rx_id, acdb_tx_id);
3841 }
3842
3843 return 0;
3844}
3845
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303846int platform_switch_voice_call_usecase_route_post(void *platform,
3847 snd_device_t out_snd_device,
3848 snd_device_t in_snd_device)
Naresh Tannirue3b18452014-03-04 14:44:27 +05303849{
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303850 struct platform_data *my_data = (struct platform_data *)platform;
3851 int acdb_rx_id, acdb_tx_id;
3852 int ret = 0;
3853
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303854 if (my_data->csd == NULL)
3855 return ret;
3856
Banajit Goswami20cdd212015-09-11 01:11:30 -07003857 if ((out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER ||
Rohit kumarf4120402016-08-05 19:19:48 +05303858 out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_2 ||
Manisha Agarwaled9c4542019-02-08 14:58:48 +05303859 out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_STEREO ||
Rohit kumarf4120402016-08-05 19:19:48 +05303860 out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_VBAT ||
3861 out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_2_VBAT) &&
Banajit Goswami20cdd212015-09-11 01:11:30 -07003862 audio_extn_spkr_prot_is_enabled()) {
3863 if (my_data->is_vbat_speaker)
3864 acdb_rx_id = acdb_device_table[SND_DEVICE_OUT_SPEAKER_PROTECTED_VBAT];
3865 else
3866 acdb_rx_id = acdb_device_table[SND_DEVICE_OUT_SPEAKER_PROTECTED];
3867 } else
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303868 acdb_rx_id = acdb_device_table[out_snd_device];
3869
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303870 acdb_tx_id = acdb_device_table[in_snd_device];
3871
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303872 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
3873 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
3874 my_data->adev->acdb_settings);
3875 if (ret < 0) {
3876 ALOGE("%s: csd_enable_device, failed, error %d", __func__, ret);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303877 }
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303878 } else {
3879 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
3880 acdb_rx_id, acdb_tx_id);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303881 }
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303882
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303883 return ret;
Naresh Tannirue3b18452014-03-04 14:44:27 +05303884}
3885
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303886int platform_start_voice_call(void *platform, uint32_t vsid)
3887{
3888 struct platform_data *my_data = (struct platform_data *)platform;
3889 int ret = 0;
3890
3891 if (my_data->csd != NULL) {
3892 ret = my_data->csd->start_voice(vsid);
3893 if (ret < 0) {
3894 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
3895 }
3896 }
3897 return ret;
3898}
3899
Vignesh Kulothungan7d374312018-02-21 17:12:00 -08003900int platform_set_mic_break_det(void *platform __unused, bool enable __unused)
3901{
3902 return 0;
3903}
3904
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303905int platform_stop_voice_call(void *platform, uint32_t vsid)
3906{
3907 struct platform_data *my_data = (struct platform_data *)platform;
3908 int ret = 0;
3909
3910 if (my_data->csd != NULL) {
3911 ret = my_data->csd->stop_voice(vsid);
3912 if (ret < 0) {
3913 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
3914 }
3915 }
3916 return ret;
3917}
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07003918
Satya Krishna Pindiprolif1cd92b2016-04-14 19:05:23 +05303919int platform_get_sample_rate(void *platform __unused,
3920 uint32_t *rate __unused)
Naresh Tannirue3b18452014-03-04 14:44:27 +05303921{
3922 return 0;
3923}
3924
3925int platform_set_voice_volume(void *platform, int volume)
3926{
3927 struct platform_data *my_data = (struct platform_data *)platform;
3928 struct audio_device *adev = my_data->adev;
3929 struct mixer_ctl *ctl;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303930 const char *mixer_ctl_name = "Voice Rx Gain";
3931 int vol_index = 0, ret = 0;
Manish Dewangan338c50a2017-09-12 15:22:03 +05303932 long set_values[ ] = {0,
3933 ALL_SESSION_VSID,
3934 DEFAULT_VOLUME_RAMP_DURATION_MS};
Naresh Tannirue3b18452014-03-04 14:44:27 +05303935
3936 // Voice volume levels are mapped to adsp volume levels as follows.
3937 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
3938 // But this values don't changed in kernel. So, below change is need.
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303939 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, MAX_VOL_INDEX);
3940 set_values[0] = vol_index;
Naresh Tannirue3b18452014-03-04 14:44:27 +05303941
3942 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3943 if (!ctl) {
3944 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3945 __func__, mixer_ctl_name);
Josh Kirsch5669ad92016-12-09 10:48:52 -08003946 ret = -EINVAL;
3947 } else {
Manish Dewangan338c50a2017-09-12 15:22:03 +05303948 ALOGV("%s Setting voice volume index: %ld",__func__, set_values[0]);
Josh Kirsch5669ad92016-12-09 10:48:52 -08003949 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
Naresh Tannirue3b18452014-03-04 14:44:27 +05303950 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05303951
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303952 if (my_data->csd != NULL) {
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303953 ret = my_data->csd->volume(ALL_SESSION_VSID, volume,
3954 DEFAULT_VOLUME_RAMP_DURATION_MS);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303955 if (ret < 0) {
3956 ALOGE("%s: csd_volume error %d", __func__, ret);
3957 }
3958 }
3959 return ret;
Naresh Tannirue3b18452014-03-04 14:44:27 +05303960}
3961
3962int platform_set_mic_mute(void *platform, bool state)
3963{
3964 struct platform_data *my_data = (struct platform_data *)platform;
3965 struct audio_device *adev = my_data->adev;
3966 struct mixer_ctl *ctl;
3967 const char *mixer_ctl_name = "Voice Tx Mute";
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303968 int ret = 0;
Manish Dewangan338c50a2017-09-12 15:22:03 +05303969 long set_values[ ] = {0,
3970 ALL_SESSION_VSID,
3971 DEFAULT_MUTE_RAMP_DURATION_MS};
Naresh Tannirue3b18452014-03-04 14:44:27 +05303972
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303973 set_values[0] = state;
3974 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3975 if (!ctl) {
3976 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3977 __func__, mixer_ctl_name);
Josh Kirsch5669ad92016-12-09 10:48:52 -08003978 ret = -EINVAL;
3979 } else {
3980 ALOGV("%s: Setting voice mute state: %d",__func__, state);
3981 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
Naresh Tannirue3b18452014-03-04 14:44:27 +05303982 }
3983
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303984 if (my_data->csd != NULL) {
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303985 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state,
3986 DEFAULT_MUTE_RAMP_DURATION_MS);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303987 if (ret < 0) {
3988 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
3989 }
3990 }
3991 return ret;
Naresh Tannirue3b18452014-03-04 14:44:27 +05303992}
3993
Shiv Maliyappanahallic6fd8ee2014-03-07 15:31:55 -08003994int platform_set_device_mute(void *platform, bool state, char *dir)
3995{
3996 struct platform_data *my_data = (struct platform_data *)platform;
3997 struct audio_device *adev = my_data->adev;
3998 struct mixer_ctl *ctl;
3999 char *mixer_ctl_name = NULL;
4000 int ret = 0;
Manish Dewangan338c50a2017-09-12 15:22:03 +05304001 long set_values[ ] = {0,
4002 ALL_SESSION_VSID,
4003 0};
Shiv Maliyappanahallic6fd8ee2014-03-07 15:31:55 -08004004 if(dir == NULL) {
4005 ALOGE("%s: Invalid direction:%s", __func__, dir);
4006 return -EINVAL;
4007 }
4008
4009 if (!strncmp("rx", dir, sizeof("rx"))) {
4010 mixer_ctl_name = "Voice Rx Device Mute";
4011 } else if (!strncmp("tx", dir, sizeof("tx"))) {
4012 mixer_ctl_name = "Voice Tx Device Mute";
4013 } else {
4014 return -EINVAL;
4015 }
4016
4017 set_values[0] = state;
4018 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
4019 if (!ctl) {
4020 ALOGE("%s: Could not get ctl for mixer cmd - %s",
4021 __func__, mixer_ctl_name);
4022 return -EINVAL;
4023 }
4024
4025 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
4026 __func__,state, mixer_ctl_name);
4027 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
4028
4029 return ret;
4030}
4031
Haynes Mathew Georgebfe8ff42016-09-22 17:38:16 -07004032int platform_split_snd_device(void *platform,
4033 snd_device_t snd_device,
4034 int *num_devices,
4035 snd_device_t *new_snd_devices)
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05304036{
Haynes Mathew Georgebfe8ff42016-09-22 17:38:16 -07004037 int ret = -EINVAL;
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05304038 struct platform_data *my_data = (struct platform_data *)platform;
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05304039 if (NULL == num_devices || NULL == new_snd_devices) {
4040 ALOGE("%s: NULL pointer ..", __func__);
Haynes Mathew Georgebfe8ff42016-09-22 17:38:16 -07004041 return -EINVAL;
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05304042 }
4043
4044 /*
4045 * If wired headset/headphones/line devices share the same backend
Haynes Mathew Georgebfe8ff42016-09-22 17:38:16 -07004046 * with speaker/earpiece this routine returns -EINVAL.
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05304047 */
4048 if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES &&
4049 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_HEADPHONES)) {
4050 *num_devices = 2;
4051
4052 if (my_data->is_vbat_speaker)
4053 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_VBAT;
4054 else if (my_data->is_wsa_speaker)
4055 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_WSA;
4056 else
4057 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
4058
4059 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew Georgebfe8ff42016-09-22 17:38:16 -07004060 ret = 0;
Preetam Singh Ranawat91132162017-03-13 20:32:03 +05304061 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET &&
4062 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_ANC_HEADSET)) {
4063 *num_devices = 2;
4064 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
4065 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
4066 ret = 0;
4067 } else if (snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_AND_VOICE_HEADPHONES &&
4068 !platform_check_backends_match(SND_DEVICE_OUT_VOICE_SPEAKER, SND_DEVICE_OUT_VOICE_HEADPHONES)) {
4069 *num_devices = 2;
4070 new_snd_devices[0] = SND_DEVICE_OUT_VOICE_SPEAKER;
4071 new_snd_devices[1] = SND_DEVICE_OUT_VOICE_HEADPHONES;
4072 ret = 0;
4073 } else if (snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_AND_VOICE_ANC_HEADSET &&
4074 !platform_check_backends_match(SND_DEVICE_OUT_VOICE_SPEAKER, SND_DEVICE_OUT_VOICE_ANC_HEADSET)) {
4075 *num_devices = 2;
4076 new_snd_devices[0] = SND_DEVICE_OUT_VOICE_SPEAKER;
4077 new_snd_devices[1] = SND_DEVICE_OUT_VOICE_ANC_HEADSET;
4078 ret = 0;
Vikram Panduranga8c68e862018-04-27 12:59:42 -07004079 } else if (snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_STEREO_AND_VOICE_HEADPHONES &&
4080 !platform_check_backends_match(SND_DEVICE_OUT_VOICE_SPEAKER_STEREO, SND_DEVICE_OUT_VOICE_HEADPHONES)) {
4081 *num_devices = 2;
4082 new_snd_devices[0] = SND_DEVICE_OUT_VOICE_SPEAKER_STEREO;
4083 new_snd_devices[1] = SND_DEVICE_OUT_VOICE_HEADPHONES;
4084 ret = 0;
4085 } else if (snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_STEREO_AND_VOICE_ANC_HEADSET &&
4086 !platform_check_backends_match(SND_DEVICE_OUT_VOICE_SPEAKER_STEREO, SND_DEVICE_OUT_VOICE_ANC_HEADSET)) {
4087 *num_devices = 2;
4088 new_snd_devices[0] = SND_DEVICE_OUT_VOICE_SPEAKER_STEREO;
4089 new_snd_devices[1] = SND_DEVICE_OUT_VOICE_ANC_HEADSET;
4090 ret = 0;
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05304091 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HDMI &&
4092 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_HDMI)) {
4093 *num_devices = 2;
4094
4095 if (my_data->is_vbat_speaker)
4096 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_VBAT;
4097 else if (my_data->is_wsa_speaker)
4098 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_WSA;
4099 else
4100 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
4101
4102 new_snd_devices[1] = SND_DEVICE_OUT_HDMI;
Haynes Mathew Georgebfe8ff42016-09-22 17:38:16 -07004103 ret = 0;
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07004104 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_DISPLAY_PORT &&
4105 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_DISPLAY_PORT)) {
4106 *num_devices = 2;
4107
4108 if (my_data->is_vbat_speaker)
4109 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_VBAT;
4110 else if (my_data->is_wsa_speaker)
4111 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_WSA;
4112 else
4113 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
4114
4115 new_snd_devices[1] = SND_DEVICE_OUT_DISPLAY_PORT;
Haynes Mathew Georgebfe8ff42016-09-22 17:38:16 -07004116 ret = 0;
Kuirong Wanga9f7cee2016-03-07 11:21:52 -08004117 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET &&
4118 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_USB_HEADSET)) {
4119 *num_devices = 2;
4120 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
4121 new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
Haynes Mathew Georgebfe8ff42016-09-22 17:38:16 -07004122 ret = 0;
kunleizbe6a8442017-08-08 17:11:35 +08004123 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO &&
4124 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_BT_SCO)) {
4125 *num_devices = 2;
4126 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
4127 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO;
4128 ret = 0;
4129 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB &&
4130 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_BT_SCO_WB)) {
4131 *num_devices = 2;
4132 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
4133 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO_WB;
4134 ret = 0;
kunleize114ec72018-05-18 11:24:23 +08004135 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_WSA_AND_BT_SCO &&
4136 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_WSA, SND_DEVICE_OUT_BT_SCO)) {
4137 *num_devices = 2;
4138 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_WSA;
4139 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO;
4140 ret = 0;
4141 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_WSA_AND_BT_SCO_WB &&
4142 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_WSA, SND_DEVICE_OUT_BT_SCO_WB)) {
4143 *num_devices = 2;
4144 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_WSA;
4145 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO_WB;
4146 ret = 0;
Naresh Tannirucd2353e2016-08-19 00:37:25 +05304147 } else if (SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP == snd_device) {
4148 *num_devices = 2;
4149 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
4150 new_snd_devices[1] = SND_DEVICE_OUT_BT_A2DP;
Haynes Mathew Georgebfe8ff42016-09-22 17:38:16 -07004151 ret = 0;
Divya Narayanan Poojary85d0a592018-02-06 14:25:16 +05304152 } else if (SND_DEVICE_IN_INCALL_REC_RX_TX == snd_device) {
4153 *num_devices = 2;
4154 new_snd_devices[0] = SND_DEVICE_IN_INCALL_REC_RX;
4155 new_snd_devices[1] = SND_DEVICE_IN_INCALL_REC_TX;
4156 ret = 0;
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05304157 }
4158
4159 ALOGD("%s: snd_device(%d) num devices(%d) new_snd_devices(%d)", __func__,
4160 snd_device, *num_devices, *new_snd_devices);
4161
Haynes Mathew Georgebfe8ff42016-09-22 17:38:16 -07004162 return ret;
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05304163}
4164
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07004165int platform_get_ext_disp_type(void *platform)
4166{
4167 int disp_type;
4168 struct platform_data *my_data = (struct platform_data *)platform;
4169
Weiyin Jiang80c8f9a2020-01-10 20:42:08 +08004170 if (my_data->ext_disp_type > EXT_DISPLAY_TYPE_NONE) {
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07004171 ALOGD("%s: Returning cached ext disp type:%s",
4172 __func__, (my_data->ext_disp_type == EXT_DISPLAY_TYPE_DP) ? "DisplayPort" : "HDMI");
4173 return my_data->ext_disp_type;
4174 }
4175
Arun Mirpurib1bec9c2019-01-29 16:42:45 -08004176 if (audio_extn_is_display_port_enabled()) {
4177 struct audio_device *adev = my_data->adev;
4178 struct mixer_ctl *ctl;
4179 char *mixer_ctl_name = "External Display Type";
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07004180
Arun Mirpurib1bec9c2019-01-29 16:42:45 -08004181 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
4182 if (!ctl) {
4183 ALOGE("%s: Could not get ctl for mixer cmd - %s",
4184 __func__, mixer_ctl_name);
4185 return -EINVAL;
4186 }
4187
4188 disp_type = mixer_ctl_get_value(ctl, 0);
Weiyin Jiang80c8f9a2020-01-10 20:42:08 +08004189 if (disp_type <= EXT_DISPLAY_TYPE_NONE) {
Arun Mirpurib1bec9c2019-01-29 16:42:45 -08004190 ALOGE("%s: Invalid external display type: %d", __func__, disp_type);
4191 return -EINVAL;
4192 }
Weiyin Jiang80c8f9a2020-01-10 20:42:08 +08004193 } else {
4194 disp_type = EXT_DISPLAY_TYPE_HDMI;
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07004195 }
4196
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07004197 my_data->ext_disp_type = disp_type;
4198 ALOGD("%s: ext disp type:%s", __func__, (disp_type == EXT_DISPLAY_TYPE_DP) ? "DisplayPort" : "HDMI");
4199 return disp_type;
4200}
4201
Jaideep Sharma477917f2020-03-13 18:13:33 +05304202snd_device_t platform_get_output_snd_device(void *platform, struct stream_out *out,
4203 usecase_type_t uc_type __unused)
Naresh Tannirue3b18452014-03-04 14:44:27 +05304204{
4205 struct platform_data *my_data = (struct platform_data *)platform;
4206 struct audio_device *adev = my_data->adev;
4207 audio_mode_t mode = adev->mode;
4208 snd_device_t snd_device = SND_DEVICE_NONE;
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08004209 audio_devices_t devices = out->devices;
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05304210 unsigned int sample_rate = out->sample_rate;
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304211 int na_mode = platform_get_native_support();
Naresh Tanniruc0517bc2014-10-26 15:30:55 +05304212 bool use_voip_out_devices = false;
4213 bool prop_rec_play_enabled = false;
4214 char recConcPropValue[PROPERTY_VALUE_MAX];
Eric Laurent637e2d42018-11-15 12:24:31 -08004215 struct stream_in *in = adev_get_active_input(adev);
Naresh Tanniruc0517bc2014-10-26 15:30:55 +05304216
Aniket Kumar Lata8fc67e62017-05-02 12:33:46 -07004217 if (property_get("vendor.audio.rec.playback.conc.disabled", recConcPropValue, NULL)) {
Naresh Tanniruc0517bc2014-10-26 15:30:55 +05304218 prop_rec_play_enabled = atoi(recConcPropValue) || !strncmp("true", recConcPropValue, 4);
4219 }
4220 use_voip_out_devices = prop_rec_play_enabled &&
4221 (my_data->rec_play_conc_set || adev->mode == AUDIO_MODE_IN_COMMUNICATION);
4222 ALOGV("platform_get_output_snd_device use_voip_out_devices : %d",use_voip_out_devices);
Naresh Tannirue3b18452014-03-04 14:44:27 +05304223
Eric Laurent637e2d42018-11-15 12:24:31 -08004224 audio_channel_mask_t channel_mask = (in == NULL) ?
4225 AUDIO_CHANNEL_IN_MONO : in->channel_mask;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05304226 int channel_count = popcount(channel_mask);
4227
Naresh Tannirue3b18452014-03-04 14:44:27 +05304228 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
4229 if (devices == AUDIO_DEVICE_NONE ||
4230 devices & AUDIO_DEVICE_BIT_IN) {
4231 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
4232 goto exit;
4233 }
4234
Shiv Maliyappanahallibd401262015-08-17 11:02:21 -07004235 if (popcount(devices) == 2) {
Preetam Singh Ranawat91132162017-03-13 20:32:03 +05304236 bool is_active_voice_call = false;
4237
4238 /*
4239 * This is special case handling for combo device use case during
4240 * voice call. APM route use case to combo device if stream type is
4241 * enforced audible (e.g. Camera shutter sound).
4242 */
4243 if ((mode == AUDIO_MODE_IN_CALL) ||
Kunlei Zhanga3b3abf2019-06-25 15:42:21 +08004244 voice_check_voicecall_usecases_active(adev) ||
Preetam Singh Ranawat91132162017-03-13 20:32:03 +05304245 voice_extn_compress_voip_is_active(adev))
4246 is_active_voice_call = true;
4247
Naresh Tannirue3b18452014-03-04 14:44:27 +05304248 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
4249 AUDIO_DEVICE_OUT_SPEAKER)) {
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304250 if (my_data->external_spk_1)
4251 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_1;
4252 else if (my_data->external_spk_2)
4253 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_2;
Preetam Singh Ranawat91132162017-03-13 20:32:03 +05304254 else if (is_active_voice_call)
4255 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_AND_VOICE_HEADPHONES;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304256 else
4257 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
Naresh Tanniru9c4ba542015-11-06 18:01:09 +05304258 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
4259 AUDIO_DEVICE_OUT_SPEAKER)) {
4260 snd_device = SND_DEVICE_OUT_SPEAKER_AND_LINE;
Naresh Tannirue3b18452014-03-04 14:44:27 +05304261 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
4262 AUDIO_DEVICE_OUT_SPEAKER)) {
Preetam Singh Ranawat91132162017-03-13 20:32:03 +05304263 if (audio_extn_get_anc_enabled()) {
4264 if (is_active_voice_call)
4265 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_AND_VOICE_ANC_HEADSET;
4266 else
4267 snd_device = SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET;
4268 } else if (my_data->external_spk_1)
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304269 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_1;
4270 else if (my_data->external_spk_2)
4271 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_2;
Preetam Singh Ranawat91132162017-03-13 20:32:03 +05304272 else {
4273 if (is_active_voice_call)
4274 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_AND_VOICE_HEADPHONES;
4275 else
4276 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
4277 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05304278 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
4279 AUDIO_DEVICE_OUT_SPEAKER)) {
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07004280 switch(my_data->ext_disp_type) {
4281 case EXT_DISPLAY_TYPE_HDMI:
4282 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
4283 break;
4284 case EXT_DISPLAY_TYPE_DP:
4285 snd_device = SND_DEVICE_OUT_SPEAKER_AND_DISPLAY_PORT;
4286 break;
4287 default:
4288 ALOGE("%s: Invalid disp_type %d", __func__, my_data->ext_disp_type);
4289 goto exit;
4290 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05304291 } else if (devices == (AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET |
4292 AUDIO_DEVICE_OUT_SPEAKER)) {
4293 snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET;
Satya Krishna Pindiprolice227962017-12-13 16:07:14 +05304294 } else if ((devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
4295 AUDIO_DEVICE_OUT_SPEAKER)) ||
4296 (devices == (AUDIO_DEVICE_OUT_USB_HEADSET |
4297 AUDIO_DEVICE_OUT_SPEAKER))){
Kuirong Wanga9f7cee2016-03-07 11:21:52 -08004298 snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET;
Naresh Tanniru9d027a62015-03-13 01:32:10 +05304299 } else if ((devices & AUDIO_DEVICE_OUT_SPEAKER) &&
4300 (devices & AUDIO_DEVICE_OUT_ALL_A2DP)) {
4301 snd_device = SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP;
kunleizbe6a8442017-08-08 17:11:35 +08004302 } else if ((devices & AUDIO_DEVICE_OUT_ALL_SCO) &&
4303 ((devices & ~AUDIO_DEVICE_OUT_ALL_SCO) == AUDIO_DEVICE_OUT_SPEAKER)) {
kunleize114ec72018-05-18 11:24:23 +08004304 if (my_data->is_wsa_speaker)
4305 snd_device = adev->bt_wb_speech_enabled ?
4306 SND_DEVICE_OUT_SPEAKER_WSA_AND_BT_SCO_WB :
4307 SND_DEVICE_OUT_SPEAKER_WSA_AND_BT_SCO;
4308 else
4309 snd_device = adev->bt_wb_speech_enabled ?
4310 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB :
4311 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO;
Naresh Tannirue3b18452014-03-04 14:44:27 +05304312 } else {
4313 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
4314 goto exit;
4315 }
4316 if (snd_device != SND_DEVICE_NONE) {
4317 goto exit;
4318 }
4319 }
4320
4321 if (popcount(devices) != 1) {
4322 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
4323 goto exit;
4324 }
4325
Venkata Narendra Kumar Guttabfdfa152015-06-22 14:25:35 +05304326 if ((mode == AUDIO_MODE_IN_CALL) ||
Kunlei Zhanga3b3abf2019-06-25 15:42:21 +08004327 voice_check_voicecall_usecases_active(adev) ||
Venkata Narendra Kumar Guttabfdfa152015-06-22 14:25:35 +05304328 voice_extn_compress_voip_is_active(adev)) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05304329 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Naresh Tanniru9c4ba542015-11-06 18:01:09 +05304330 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
4331 devices & AUDIO_DEVICE_OUT_LINE) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05304332 if ((adev->voice.tty_mode != TTY_MODE_OFF) &&
4333 !voice_extn_compress_voip_is_active(adev)) {
4334 switch (adev->voice.tty_mode) {
4335 case TTY_MODE_FULL:
4336 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
4337 break;
4338 case TTY_MODE_VCO:
4339 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
4340 break;
4341 case TTY_MODE_HCO:
4342 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
4343 break;
4344 default:
4345 ALOGE("%s: Invalid TTY mode (%#x)",
4346 __func__, adev->voice.tty_mode);
4347 }
Naresh Tanniru9c4ba542015-11-06 18:01:09 +05304348 } else if (devices & AUDIO_DEVICE_OUT_LINE) {
4349 snd_device = SND_DEVICE_OUT_VOICE_LINE;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05304350 } else if (audio_extn_get_anc_enabled()) {
4351 if (audio_extn_should_use_fb_anc())
4352 snd_device = SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET;
4353 else
4354 snd_device = SND_DEVICE_OUT_VOICE_ANC_HEADSET;
4355 } else {
4356 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
4357 }
Satya Krishna Pindiprolice227962017-12-13 16:07:14 +05304358 } else if (devices &
4359 (AUDIO_DEVICE_OUT_USB_DEVICE |
4360 AUDIO_DEVICE_OUT_USB_HEADSET)) {
Aniket Kumar Lata3e2e1232017-06-16 17:25:07 -07004361 if (snd_device == SND_DEVICE_NONE) {
4362 snd_device = audio_extn_usb_is_capture_supported() ?
4363 SND_DEVICE_OUT_VOICE_USB_HEADSET :
4364 SND_DEVICE_OUT_VOICE_USB_HEADPHONES;
4365 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05304366 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Mingming Yin514a8bc2014-07-29 15:22:21 -07004367 if (adev->bt_wb_speech_enabled)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05304368 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
4369 else
4370 snd_device = SND_DEVICE_OUT_BT_SCO;
Naresh Tanniru9d027a62015-03-13 01:32:10 +05304371 } else if (devices & AUDIO_DEVICE_OUT_ALL_A2DP) {
4372 snd_device = SND_DEVICE_OUT_BT_A2DP;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05304373 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
Rohit kumarf4120402016-08-05 19:19:48 +05304374 if (my_data->is_vbat_speaker) {
4375 if (my_data->mono_speaker == SPKR_1)
4376 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_VBAT;
4377 else
4378 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_2_VBAT;
4379 } else if (my_data->is_wsa_speaker) {
4380 if (my_data->mono_speaker == SPKR_1)
4381 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_WSA;
4382 else
4383 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_2_WSA;
4384 } else {
Vikram Panduranga8c68e862018-04-27 12:59:42 -07004385 if (my_data->voice_speaker_stereo)
4386 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_STEREO;
4387 else {
4388 if (my_data->mono_speaker == SPKR_1)
4389 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
4390 else
4391 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_2;
4392 }
Rohit kumarf4120402016-08-05 19:19:48 +05304393 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05304394 } else if (devices & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
4395 devices & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
4396 snd_device = SND_DEVICE_OUT_USB_HEADSET;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05304397 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
4398 if (audio_extn_should_use_handset_anc(channel_count))
4399 snd_device = SND_DEVICE_OUT_ANC_HANDSET;
4400 else
4401 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
Preetam Singh Ranawat7112f3b2015-02-26 16:51:58 +05304402 } else if (devices & AUDIO_DEVICE_OUT_TELEPHONY_TX)
4403 snd_device = SND_DEVICE_OUT_VOICE_TX;
4404
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05304405 if (snd_device != SND_DEVICE_NONE) {
4406 goto exit;
4407 }
4408 }
4409
Naresh Tannirue3b18452014-03-04 14:44:27 +05304410 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Preetam Singh Ranawat3e5b9e72016-11-10 16:12:25 +05304411 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
4412 devices & AUDIO_DEVICE_OUT_LINE) {
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05304413 if (OUTPUT_SAMPLING_RATE_44100 == sample_rate &&
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304414 NATIVE_AUDIO_MODE_SRC == na_mode &&
Sidipotu Ashokbffd2202015-08-20 14:06:55 +05304415 !audio_extn_get_anc_enabled()) {
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304416
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05304417 snd_device = SND_DEVICE_OUT_HEADPHONES_44_1;
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304418
4419 } else if (devices & AUDIO_DEVICE_OUT_WIRED_HEADSET
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05304420 && audio_extn_get_anc_enabled()) {
Naresh Tanniruc0517bc2014-10-26 15:30:55 +05304421 if (use_voip_out_devices) {
4422 // ANC should be disabled for voip concurrency
4423 snd_device = SND_DEVICE_OUT_VOIP_HEADPHONES;
4424 } else
Naresh Tanniruc0517bc2014-10-26 15:30:55 +05304425 {
4426 if (audio_extn_should_use_fb_anc())
4427 snd_device = SND_DEVICE_OUT_ANC_FB_HEADSET;
4428 else
4429 snd_device = SND_DEVICE_OUT_ANC_HEADSET;
4430 }
Preetam Singh Ranawat3e5b9e72016-11-10 16:12:25 +05304431 } else if (NATIVE_AUDIO_MODE_SRC == na_mode &&
4432 OUTPUT_SAMPLING_RATE_44100 == sample_rate) {
4433 snd_device = SND_DEVICE_OUT_HEADPHONES_44_1;
Preetam Singh Ranawatb1c73232019-04-22 13:59:51 +05304434 } else if (NATIVE_AUDIO_MODE_MULTIPLE_MIX_IN_CODEC == na_mode &&
Preetam Singh Ranawat3e5b9e72016-11-10 16:12:25 +05304435 (sample_rate % OUTPUT_SAMPLING_RATE_44100 == 0) &&
4436 (out->format != AUDIO_FORMAT_DSD)) {
4437 snd_device = SND_DEVICE_OUT_HEADPHONES_44_1;
4438 } else if (out->format == AUDIO_FORMAT_DSD) {
4439 snd_device = SND_DEVICE_OUT_HEADPHONES_DSD;
Surendar karkaff241fc2017-09-21 10:25:50 +05304440 } else if (devices & AUDIO_DEVICE_OUT_LINE) {
4441 snd_device = SND_DEVICE_OUT_LINE;
Preetam Singh Ranawat3e5b9e72016-11-10 16:12:25 +05304442 } else {
Naresh Tanniruc0517bc2014-10-26 15:30:55 +05304443 if (use_voip_out_devices)
4444 snd_device = SND_DEVICE_OUT_VOIP_HEADPHONES;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05304445 else
Naresh Tanniruc0517bc2014-10-26 15:30:55 +05304446 snd_device = SND_DEVICE_OUT_HEADPHONES;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05304447 }
Naresh Tanniru9c4ba542015-11-06 18:01:09 +05304448 } else if (devices & AUDIO_DEVICE_OUT_LINE) {
4449 snd_device = SND_DEVICE_OUT_LINE;
Naresh Tannirue3b18452014-03-04 14:44:27 +05304450 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
Naresh Tanniruc0517bc2014-10-26 15:30:55 +05304451 if (use_voip_out_devices) {
4452 snd_device = SND_DEVICE_OUT_VOIP_SPEAKER;
4453 } else
Naresh Tanniruc0517bc2014-10-26 15:30:55 +05304454 {
4455 if (adev->speaker_lr_swap)
4456 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
4457 else
Preetam Singh Ranawatc7f7f5c2015-04-02 12:19:58 +05304458 {
Banajit Goswami20cdd212015-09-11 01:11:30 -07004459 if (my_data->is_vbat_speaker)
4460 snd_device = SND_DEVICE_OUT_SPEAKER_VBAT;
4461 else if (my_data->is_wsa_speaker)
Preetam Singh Ranawatc7f7f5c2015-04-02 12:19:58 +05304462 snd_device = SND_DEVICE_OUT_SPEAKER_WSA;
4463 else
4464 snd_device = SND_DEVICE_OUT_SPEAKER;
4465 }
Naresh Tanniruc0517bc2014-10-26 15:30:55 +05304466 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05304467 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Mingming Yin514a8bc2014-07-29 15:22:21 -07004468 if (adev->bt_wb_speech_enabled)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05304469 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
4470 else
4471 snd_device = SND_DEVICE_OUT_BT_SCO;
Naresh Tannirue3b18452014-03-04 14:44:27 +05304472 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07004473 switch(my_data->ext_disp_type) {
4474 case EXT_DISPLAY_TYPE_HDMI:
4475 snd_device = SND_DEVICE_OUT_HDMI;
4476 break;
4477 case EXT_DISPLAY_TYPE_DP:
4478 snd_device = SND_DEVICE_OUT_DISPLAY_PORT;
4479 break;
4480 default:
4481 ALOGE("%s: Invalid disp_type %d", __func__, my_data->ext_disp_type);
4482 goto exit;
4483 }
Naresh Tanniru9d027a62015-03-13 01:32:10 +05304484 } else if (devices & AUDIO_DEVICE_OUT_ALL_A2DP) {
4485 snd_device = SND_DEVICE_OUT_BT_A2DP;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05304486 } else if (devices & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
4487 devices & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
Mingming Yin5a7c5d62014-03-05 17:45:03 -08004488 ALOGD("%s: setting USB hadset channel capability(2) for Proxy", __func__);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05304489 snd_device = SND_DEVICE_OUT_USB_HEADSET;
Sachin Mohan Gadag3e6e3fd2019-03-14 17:37:05 +05304490 audio_extn_set_afe_proxy_channel_mixer(adev, 2, snd_device);
Satya Krishna Pindiprolice227962017-12-13 16:07:14 +05304491 } else if (devices &
4492 (AUDIO_DEVICE_OUT_USB_DEVICE |
4493 AUDIO_DEVICE_OUT_USB_HEADSET)) {
Ashish Jain3e37a702016-11-25 12:27:15 +05304494 if (audio_extn_usb_is_capture_supported())
4495 snd_device = SND_DEVICE_OUT_USB_HEADSET;
4496 else
4497 snd_device = SND_DEVICE_OUT_USB_HEADPHONES;
Naresh Tannirue3b18452014-03-04 14:44:27 +05304498 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Naresh Tanniruc0517bc2014-10-26 15:30:55 +05304499 if (use_voip_out_devices)
4500 snd_device = SND_DEVICE_OUT_VOIP_HANDSET;
4501 else
Naresh Tanniruc0517bc2014-10-26 15:30:55 +05304502 snd_device = SND_DEVICE_OUT_HANDSET;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05304503 } else if (devices & AUDIO_DEVICE_OUT_PROXY) {
Mingming Yin5a7c5d62014-03-05 17:45:03 -08004504 channel_count = audio_extn_get_afe_proxy_channel_count();
4505 ALOGD("%s: setting sink capability(%d) for Proxy", __func__, channel_count);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05304506 snd_device = SND_DEVICE_OUT_AFE_PROXY;
Sachin Mohan Gadag3e6e3fd2019-03-14 17:37:05 +05304507 audio_extn_set_afe_proxy_channel_mixer(adev, channel_count, snd_device);
Naresh Tannirue3b18452014-03-04 14:44:27 +05304508 } else {
4509 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
4510 }
4511exit:
4512 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
4513 return snd_device;
4514}
4515
Arun Mirpurib1bec9c2019-01-29 16:42:45 -08004516static snd_device_t get_snd_device_for_voice_comm_ecns_enabled(struct platform_data *my_data,
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07004517 audio_devices_t out_device,
4518 audio_devices_t in_device)
4519{
4520 struct audio_device *adev = my_data->adev;
4521 snd_device_t snd_device = SND_DEVICE_NONE;
4522
Vignesh Kulothungan033c7cb2018-07-12 11:35:57 -07004523 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
4524 if (my_data->fluence_in_spkr_mode) {
4525 if ((my_data->fluence_type & FLUENCE_QUAD_MIC) &&
4526 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
4527 snd_device = SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS;
4528 } else if ((my_data->fluence_type & FLUENCE_TRI_MIC) &&
4529 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
4530 snd_device = SND_DEVICE_IN_SPEAKER_TMIC_AEC_NS;
4531 } else if ((my_data->fluence_type & FLUENCE_DUAL_MIC) &&
4532 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
4533 if (my_data->fluence_mode == FLUENCE_BROADSIDE)
4534 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_BROADSIDE;
4535 else
4536 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
4537 }
4538 adev->acdb_settings |= DMIC_FLAG;
4539 } else
4540 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
4541 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
4542 if ((my_data->fluence_type & FLUENCE_DUAL_MIC) &&
4543 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
4544 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
4545 adev->acdb_settings |= DMIC_FLAG;
4546 } else
4547 snd_device = SND_DEVICE_IN_HANDSET_MIC;
4548 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
4549 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07004550 }
Vignesh Kulothungan033c7cb2018-07-12 11:35:57 -07004551 platform_set_echo_reference(adev, true, out_device);
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07004552
4553 return snd_device;
4554}
Arun Mirpurib1bec9c2019-01-29 16:42:45 -08004555
4556static snd_device_t get_snd_device_for_voice_comm_ecns_disabled(struct platform_data *my_data,
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07004557 audio_devices_t out_device,
4558 audio_devices_t in_device)
4559{
4560 struct audio_device *adev = my_data->adev;
4561 snd_device_t snd_device = SND_DEVICE_NONE;
Eric Laurent637e2d42018-11-15 12:24:31 -08004562 struct stream_in *in = adev_get_active_input(adev);
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07004563
Eric Laurent637e2d42018-11-15 12:24:31 -08004564 if (in != NULL && in->enable_aec && in->enable_ns) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07004565 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
4566 if (my_data->fluence_in_spkr_mode) {
4567 if ((my_data->fluence_type & FLUENCE_QUAD_MIC) &&
4568 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
4569 snd_device = SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS;
Vikram Pandurangaf0ca0b12018-05-04 16:00:07 -07004570 } else if ((my_data->fluence_type & FLUENCE_TRI_MIC) &&
4571 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
4572 snd_device = SND_DEVICE_IN_SPEAKER_TMIC_AEC_NS;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07004573 } else if ((my_data->fluence_type & FLUENCE_DUAL_MIC) &&
4574 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
4575 if (my_data->fluence_mode == FLUENCE_BROADSIDE)
4576 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_BROADSIDE;
4577 else
4578 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
4579 }
4580 adev->acdb_settings |= DMIC_FLAG;
4581 } else
4582 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
4583 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
4584 if ((my_data->fluence_type & FLUENCE_DUAL_MIC) &&
4585 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
4586 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
4587 adev->acdb_settings |= DMIC_FLAG;
4588 } else
4589 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
4590 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
4591 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
kunleiz1a1d26c2018-06-14 18:48:16 +08004592 } 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 -07004593 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
4594 }
4595 platform_set_echo_reference(adev, true, out_device);
Eric Laurent637e2d42018-11-15 12:24:31 -08004596 } else if (in != NULL && in->enable_aec) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07004597 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
4598 if (my_data->fluence_in_spkr_mode) {
4599 if ((my_data->fluence_type & FLUENCE_QUAD_MIC) &&
4600 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
4601 snd_device = SND_DEVICE_IN_SPEAKER_QMIC_AEC;
Vikram Pandurangaf0ca0b12018-05-04 16:00:07 -07004602 } else if ((my_data->fluence_type & FLUENCE_TRI_MIC) &&
4603 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
4604 snd_device = SND_DEVICE_IN_SPEAKER_TMIC_AEC;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07004605 } else if ((my_data->fluence_type & FLUENCE_DUAL_MIC) &&
4606 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
4607 if (my_data->fluence_mode == FLUENCE_BROADSIDE)
4608 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_BROADSIDE;
4609 else
4610 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
4611 }
4612 adev->acdb_settings |= DMIC_FLAG;
4613 } else
4614 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
4615 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
4616 if ((my_data->fluence_type & FLUENCE_DUAL_MIC) &&
4617 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
4618 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
4619 adev->acdb_settings |= DMIC_FLAG;
4620 } else
4621 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
4622 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
4623 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
kunleiz1a1d26c2018-06-14 18:48:16 +08004624 } 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 -07004625 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
4626 }
4627 platform_set_echo_reference(adev, true, out_device);
Eric Laurent637e2d42018-11-15 12:24:31 -08004628 } else if (in != NULL && in->enable_ns) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07004629 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
4630 if (my_data->fluence_in_spkr_mode) {
4631 if ((my_data->fluence_type & FLUENCE_QUAD_MIC) &&
4632 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
4633 snd_device = SND_DEVICE_IN_SPEAKER_QMIC_NS;
Vikram Pandurangaf0ca0b12018-05-04 16:00:07 -07004634 } else if ((my_data->fluence_type & FLUENCE_TRI_MIC) &&
4635 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
4636 snd_device = SND_DEVICE_IN_SPEAKER_TMIC_NS;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07004637 } else if ((my_data->fluence_type & FLUENCE_DUAL_MIC) &&
4638 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
4639 if (my_data->fluence_mode == FLUENCE_BROADSIDE)
4640 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS_BROADSIDE;
4641 else
4642 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
4643 }
4644 adev->acdb_settings |= DMIC_FLAG;
4645 } else
4646 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
4647 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
4648 if ((my_data->fluence_type & FLUENCE_DUAL_MIC) &&
4649 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
4650 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
4651 adev->acdb_settings |= DMIC_FLAG;
4652 } else
4653 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
4654 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
4655 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
4656 }
4657 platform_set_echo_reference(adev, false, out_device);
4658 } else
4659 platform_set_echo_reference(adev, false, out_device);
4660
4661 return snd_device;
4662}
Arun Mirpurib1bec9c2019-01-29 16:42:45 -08004663
4664static snd_device_t get_snd_device_for_voice_comm(struct platform_data *my_data,
4665 audio_devices_t out_device,
4666 audio_devices_t in_device)
4667{
4668 if(voice_extn_is_dynamic_ecns_enabled())
4669 return get_snd_device_for_voice_comm_ecns_enabled(my_data, out_device, in_device);
4670 else
4671 return get_snd_device_for_voice_comm_ecns_disabled(my_data, out_device, in_device);
4672}
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07004673
Eric Laurent637e2d42018-11-15 12:24:31 -08004674snd_device_t platform_get_input_snd_device(void *platform,
4675 struct stream_in *in,
Jaideep Sharma477917f2020-03-13 18:13:33 +05304676 audio_devices_t out_device,
4677 usecase_type_t uc_type __unused)
Naresh Tannirue3b18452014-03-04 14:44:27 +05304678{
4679 struct platform_data *my_data = (struct platform_data *)platform;
4680 struct audio_device *adev = my_data->adev;
Eric Laurent637e2d42018-11-15 12:24:31 -08004681 audio_mode_t mode = adev->mode;
Naresh Tannirue3b18452014-03-04 14:44:27 +05304682 snd_device_t snd_device = SND_DEVICE_NONE;
Eric Laurent637e2d42018-11-15 12:24:31 -08004683
4684 if (in == NULL) {
4685 in = adev_get_active_input(adev);
4686 }
4687
4688 audio_source_t source = (in == NULL) ? AUDIO_SOURCE_DEFAULT : in->source;
4689 audio_devices_t in_device =
4690 ((in == NULL) ? AUDIO_DEVICE_NONE : in->device) & ~AUDIO_DEVICE_BIT_IN;
4691 audio_channel_mask_t channel_mask = (in == NULL) ? AUDIO_CHANNEL_IN_MONO : in->channel_mask;
4692 int channel_count = audio_channel_count_from_in_mask(channel_mask);
4693
4694 int str_bitwidth = (in == NULL) ?
4695 CODEC_BACKEND_DEFAULT_BIT_WIDTH : in->bit_width;
Naresh Tannirue3b18452014-03-04 14:44:27 +05304696
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05304697 ALOGV("%s: enter: out_device(%#x) in_device(%#x) channel_count (%d) channel_mask (0x%x)",
4698 __func__, out_device, in_device, channel_count, channel_mask);
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304699 if (my_data->external_mic) {
Kunlei Zhanga3b3abf2019-06-25 15:42:21 +08004700 if ((out_device != AUDIO_DEVICE_NONE) && ((mode == AUDIO_MODE_IN_CALL) ||
4701 voice_check_voicecall_usecases_active(adev) ||
4702 voice_extn_compress_voip_is_active(adev) ||
4703 audio_extn_hfp_is_active(adev))) {
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304704 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
4705 out_device & AUDIO_DEVICE_OUT_EARPIECE ||
4706 out_device & AUDIO_DEVICE_OUT_SPEAKER )
4707 snd_device = SND_DEVICE_IN_HANDSET_MIC_EXTERNAL;
4708 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
4709 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
4710 snd_device = SND_DEVICE_IN_HANDSET_MIC_EXTERNAL;
4711 }
4712 }
4713
4714 if (snd_device != AUDIO_DEVICE_NONE)
4715 goto exit;
4716
Kunlei Zhanga3b3abf2019-06-25 15:42:21 +08004717 if ((out_device != AUDIO_DEVICE_NONE) && ((mode == AUDIO_MODE_IN_CALL) ||
4718 voice_check_voicecall_usecases_active(adev) ||
4719 voice_extn_compress_voip_is_active(adev) ||
4720 audio_extn_hfp_is_active(adev))) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05304721 if ((adev->voice.tty_mode != TTY_MODE_OFF) &&
4722 !voice_extn_compress_voip_is_active(adev)) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05304723 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Naresh Tanniru9c4ba542015-11-06 18:01:09 +05304724 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
4725 out_device & AUDIO_DEVICE_OUT_LINE) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05304726 switch (adev->voice.tty_mode) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05304727 case TTY_MODE_FULL:
4728 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
4729 break;
4730 case TTY_MODE_VCO:
4731 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
4732 break;
4733 case TTY_MODE_HCO:
4734 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
4735 break;
4736 default:
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05304737 ALOGE("%s: Invalid TTY mode (%#x)",
4738 __func__, adev->voice.tty_mode);
Naresh Tannirue3b18452014-03-04 14:44:27 +05304739 }
4740 goto exit;
4741 }
4742 }
4743 if (out_device & AUDIO_DEVICE_OUT_EARPIECE ||
Naresh Tanniru9c4ba542015-11-06 18:01:09 +05304744 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
4745 out_device & AUDIO_DEVICE_OUT_LINE) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05304746 if (out_device & AUDIO_DEVICE_OUT_EARPIECE &&
Sidipotu Ashok3bcca232014-11-07 14:41:58 +05304747 audio_extn_should_use_handset_anc(channel_count) &&
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05304748 my_data->fluence_type != FLUENCE_NONE &&
4749 my_data->source_mic_type & SOURCE_DUAL_MIC) {
Sidipotu Ashok3bcca232014-11-07 14:41:58 +05304750 snd_device = SND_DEVICE_IN_VOICE_FLUENCE_DMIC_AANC;
4751 adev->acdb_settings |= DMIC_FLAG;
4752 ALOGD("Selecting AANC, Fluence combo device");
4753 } else if (out_device & AUDIO_DEVICE_OUT_EARPIECE &&
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05304754 audio_extn_should_use_handset_anc(channel_count)) {
4755 snd_device = SND_DEVICE_IN_AANC_HANDSET_MIC;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304756 adev->acdb_settings |= ANC_FLAG;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05304757 } else if (my_data->fluence_type == FLUENCE_NONE ||
Vikram Pandurangae7b21342017-06-05 15:57:23 -07004758 (my_data->fluence_in_voice_call == false &&
4759 my_data->fluence_in_hfp_call == false)) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05304760 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +05304761 if (audio_extn_hfp_is_active(adev))
Apoorv Raghuvanshi924b3022015-07-06 15:07:14 -07004762 platform_set_echo_reference(adev, true, out_device);
Naresh Tannirue3b18452014-03-04 14:44:27 +05304763 } else {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05304764 snd_device = SND_DEVICE_IN_VOICE_DMIC;
4765 adev->acdb_settings |= DMIC_FLAG;
Naresh Tannirue3b18452014-03-04 14:44:27 +05304766 }
4767 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
4768 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304769 if (audio_extn_hfp_is_active(adev))
Apoorv Raghuvanshi924b3022015-07-06 15:07:14 -07004770 platform_set_echo_reference(adev, true, out_device);
Naresh Tannirue3b18452014-03-04 14:44:27 +05304771 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Vicky Sehrawate240e5d2014-08-12 17:17:04 -07004772 if (adev->bt_wb_speech_enabled) {
4773 if (adev->bluetooth_nrec)
4774 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
4775 else
4776 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
4777 } else {
4778 if (adev->bluetooth_nrec)
4779 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
4780 else
4781 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
4782 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05304783 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05304784 if (my_data->fluence_type != FLUENCE_NONE &&
Dhanalakshmi Siddani3dbfc382017-03-21 15:15:03 +05304785 (my_data->fluence_in_voice_call ||
4786 my_data->fluence_in_hfp_call) &&
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05304787 my_data->fluence_in_spkr_mode) {
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05304788 if((my_data->fluence_type & FLUENCE_QUAD_MIC) &&
4789 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05304790 adev->acdb_settings |= QMIC_FLAG;
4791 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_QMIC;
Vikram Pandurangaf0ca0b12018-05-04 16:00:07 -07004792 } else if ((my_data->fluence_type & FLUENCE_TRI_MIC) &&
4793 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
4794 adev->acdb_settings |= TMIC_FLAG;
4795 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_TMIC;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05304796 } else {
4797 adev->acdb_settings |= DMIC_FLAG;
Karthik Reddy Kattad9fff862014-07-21 21:07:21 +05304798 if (my_data->fluence_mode == FLUENCE_BROADSIDE)
4799 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BROADSIDE;
4800 else
4801 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05304802 }
Dhanalakshmi Siddani1eb3a352017-06-05 15:18:23 +05304803 if (audio_extn_hfp_is_active(adev))
4804 platform_set_echo_reference(adev, true, out_device);
Naresh Tannirue3b18452014-03-04 14:44:27 +05304805 } else {
4806 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +05304807 if (audio_extn_hfp_is_active(adev))
Apoorv Raghuvanshi924b3022015-07-06 15:07:14 -07004808 platform_set_echo_reference(adev, true, out_device);
Naresh Tannirue3b18452014-03-04 14:44:27 +05304809 }
Aniket Kumar Lata3e2e1232017-06-16 17:25:07 -07004810 } else if (out_device & AUDIO_DEVICE_OUT_TELEPHONY_TX) {
Preetam Singh Ranawat7112f3b2015-02-26 16:51:58 +05304811 snd_device = SND_DEVICE_IN_VOICE_RX;
Satya Krishna Pindiprolice227962017-12-13 16:07:14 +05304812 } else if (out_device &
4813 (AUDIO_DEVICE_OUT_USB_DEVICE |
4814 AUDIO_DEVICE_OUT_USB_HEADSET)) {
Aniket Kumar Lata3e2e1232017-06-16 17:25:07 -07004815 if (audio_extn_usb_is_capture_supported()) {
4816 snd_device = SND_DEVICE_IN_VOICE_USB_HEADSET_MIC;
4817 }
4818 }
Dhananjay Kumar704ce6f2017-09-28 22:08:00 +05304819 } else if (my_data->use_generic_handset == true && // system prop is enabled
4820 (my_data->source_mic_type & SOURCE_QUAD_MIC) && // AND 4mic is available
4821 ((in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) || // AND device is buit-in mic or back mic
4822 (in_device & AUDIO_DEVICE_IN_BACK_MIC)) &&
4823 (my_data->fluence_in_audio_rec == true && // AND fluencepro is enabled
4824 my_data->fluence_type & FLUENCE_QUAD_MIC) &&
4825 (source == AUDIO_SOURCE_CAMCORDER || // AND source is cam/mic/unprocessed
4826 source == AUDIO_SOURCE_UNPROCESSED ||
4827 source == AUDIO_SOURCE_MIC)) {
4828 snd_device = SND_DEVICE_IN_HANDSET_GENERIC_QMIC;
4829 platform_set_echo_reference(adev, true, out_device);
Naresh Tannirue3b18452014-03-04 14:44:27 +05304830 } else if (source == AUDIO_SOURCE_CAMCORDER) {
4831 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
4832 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Arun Tom Abrahamf888ae82016-12-10 04:51:49 +05304833
4834 if (str_bitwidth == 16) {
4835 if ((my_data->fluence_type & FLUENCE_DUAL_MIC) &&
4836 (my_data->source_mic_type & SOURCE_DUAL_MIC) &&
4837 (channel_count == 2))
4838 snd_device = SND_DEVICE_IN_HANDSET_STEREO_DMIC;
4839 else
4840 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
4841 }
4842 /*
4843 * for other bit widths
4844 */
4845 else {
4846 if (((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) ||
4847 (channel_mask == AUDIO_CHANNEL_IN_STEREO)) &&
4848 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
4849 snd_device = SND_DEVICE_IN_UNPROCESSED_STEREO_MIC;
4850 }
Dhananjay Kumara5d42b32017-01-11 21:22:16 +05304851 else if (((int)channel_mask == (int)AUDIO_CHANNEL_INDEX_MASK_3) &&
Arun Tom Abrahamf888ae82016-12-10 04:51:49 +05304852 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
4853 snd_device = SND_DEVICE_IN_UNPROCESSED_THREE_MIC;
Dhananjay Kumara5d42b32017-01-11 21:22:16 +05304854 } else if (((int)channel_mask == (int)AUDIO_CHANNEL_INDEX_MASK_4) &&
Arun Tom Abrahamf888ae82016-12-10 04:51:49 +05304855 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
4856 snd_device = SND_DEVICE_IN_UNPROCESSED_QUAD_MIC;
4857 } else {
4858 snd_device = SND_DEVICE_IN_UNPROCESSED_MIC;
4859 }
4860 }
4861 }
4862 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05304863 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05304864 if (my_data->fluence_in_voice_rec && channel_count == 1) {
4865 if ((my_data->fluence_type & FLUENCE_QUAD_MIC) &&
4866 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
4867 snd_device = SND_DEVICE_IN_HANDSET_QMIC;
4868 } else if ((my_data->fluence_type & FLUENCE_QUAD_MIC) &&
4869 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
Ben Rombergera4d76db2016-10-13 15:26:02 -07004870 snd_device = SND_DEVICE_IN_VOICE_REC_TMIC;
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05304871 } else if ((my_data->fluence_type & FLUENCE_DUAL_MIC) &&
4872 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
4873 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
4874 }
4875 platform_set_echo_reference(adev, true, out_device);
4876 } else if (((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) ||
4877 (channel_mask == AUDIO_CHANNEL_IN_STEREO)) &&
4878 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05304879 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
Dhananjay Kumara5d42b32017-01-11 21:22:16 +05304880 } else if (((int)channel_mask == (int)AUDIO_CHANNEL_INDEX_MASK_3) &&
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05304881 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
4882 snd_device = SND_DEVICE_IN_THREE_MIC;
Dhananjay Kumara5d42b32017-01-11 21:22:16 +05304883 } else if (((int)channel_mask == (int)AUDIO_CHANNEL_INDEX_MASK_4) &&
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05304884 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
4885 snd_device = SND_DEVICE_IN_QUAD_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05304886 }
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05304887 if (snd_device == SND_DEVICE_NONE) {
Eric Laurent637e2d42018-11-15 12:24:31 -08004888 if (in != NULL && in->enable_ns)
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05304889 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
4890 else
4891 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
4892 }
Satya Krishna Pindiprolice227962017-12-13 16:07:14 +05304893 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Aniket Kumar Lata3e2e1232017-06-16 17:25:07 -07004894 snd_device = SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC;
4895 }
Chaithanya Krishna Bacharaju24f86f32016-05-26 16:34:53 +05304896 } else if (source == AUDIO_SOURCE_UNPROCESSED) {
4897 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
4898 if (((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) ||
4899 (channel_mask == AUDIO_CHANNEL_IN_STEREO)) &&
4900 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
4901 snd_device = SND_DEVICE_IN_UNPROCESSED_STEREO_MIC;
Dhananjay Kumara5d42b32017-01-11 21:22:16 +05304902 } else if (((int)channel_mask == (int)AUDIO_CHANNEL_INDEX_MASK_3) &&
Chaithanya Krishna Bacharaju24f86f32016-05-26 16:34:53 +05304903 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
4904 snd_device = SND_DEVICE_IN_UNPROCESSED_THREE_MIC;
Dhananjay Kumara5d42b32017-01-11 21:22:16 +05304905 } else if (((int)channel_mask == (int)AUDIO_CHANNEL_INDEX_MASK_4) &&
Chaithanya Krishna Bacharaju24f86f32016-05-26 16:34:53 +05304906 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
4907 snd_device = SND_DEVICE_IN_UNPROCESSED_QUAD_MIC;
4908 } else {
4909 snd_device = SND_DEVICE_IN_UNPROCESSED_MIC;
4910 }
4911 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
4912 snd_device = SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC;
Satya Krishna Pindiprolice227962017-12-13 16:07:14 +05304913 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Aniket Kumar Lata3e2e1232017-06-16 17:25:07 -07004914 snd_device = SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC;
Chaithanya Krishna Bacharaju24f86f32016-05-26 16:34:53 +05304915 }
Karthik Reddy Kattaf621ec72014-11-21 16:37:38 +05304916 } else if ((source == AUDIO_SOURCE_VOICE_COMMUNICATION) ||
4917 (mode == AUDIO_MODE_IN_COMMUNICATION)) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05304918 if (out_device & AUDIO_DEVICE_OUT_SPEAKER)
4919 in_device = AUDIO_DEVICE_IN_BACK_MIC;
kunleizdcf967a2018-08-07 17:09:11 +08004920 else if (out_device & AUDIO_DEVICE_OUT_EARPIECE)
4921 in_device = AUDIO_DEVICE_IN_BUILTIN_MIC;
4922 else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET)
4923 in_device = AUDIO_DEVICE_IN_WIRED_HEADSET;
4924 else if (out_device & AUDIO_DEVICE_OUT_USB_DEVICE)
4925 in_device = AUDIO_DEVICE_IN_USB_DEVICE;
4926
4927 in_device = ((out_device == AUDIO_DEVICE_NONE) ?
4928 AUDIO_DEVICE_IN_BUILTIN_MIC : in_device) & ~AUDIO_DEVICE_BIT_IN;
4929
Eric Laurent637e2d42018-11-15 12:24:31 -08004930 if (in)
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07004931 snd_device = get_snd_device_for_voice_comm(my_data, out_device, in_device);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05304932 } else if (source == AUDIO_SOURCE_MIC) {
4933 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC &&
Garmond Leunge2433c32017-09-28 21:51:22 -07004934 channel_count == 1) {
Karthik Reddy Kattad71b94b2015-01-19 14:06:53 +05304935 if(my_data->fluence_in_audio_rec) {
Garmond Leunge2433c32017-09-28 21:51:22 -07004936 if ((my_data->fluence_type & FLUENCE_HEX_MIC) &&
4937 (my_data->source_mic_type & SOURCE_HEX_MIC) &&
Eric Laurent637e2d42018-11-15 12:24:31 -08004938 (audio_extn_ffv_get_stream() == in)) {
Garmond Leunge2433c32017-09-28 21:51:22 -07004939 snd_device = audio_extn_ffv_get_capture_snd_device();
4940 } else if ((my_data->fluence_type & FLUENCE_QUAD_MIC) &&
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05304941 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
Karthik Reddy Kattad71b94b2015-01-19 14:06:53 +05304942 snd_device = SND_DEVICE_IN_HANDSET_QMIC;
Apoorv Raghuvanshi924b3022015-07-06 15:07:14 -07004943 platform_set_echo_reference(adev, true, out_device);
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05304944 } else if ((my_data->fluence_type & FLUENCE_QUAD_MIC) &&
4945 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
4946 snd_device = SND_DEVICE_IN_HANDSET_TMIC;
4947 } else if ((my_data->fluence_type & FLUENCE_DUAL_MIC) &&
4948 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Karthik Reddy Kattad71b94b2015-01-19 14:06:53 +05304949 snd_device = SND_DEVICE_IN_HANDSET_DMIC;
Apoorv Raghuvanshi924b3022015-07-06 15:07:14 -07004950 platform_set_echo_reference(adev, true, out_device);
Karthik Reddy Kattad71b94b2015-01-19 14:06:53 +05304951 }
4952 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05304953 }
Mingming Yin12125e82015-10-26 20:40:36 -07004954 } else if (source == AUDIO_SOURCE_FM_TUNER) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05304955 snd_device = SND_DEVICE_IN_CAPTURE_FM;
Naresh Tannirue3b18452014-03-04 14:44:27 +05304956 } else if (source == AUDIO_SOURCE_DEFAULT) {
4957 goto exit;
4958 }
4959
Eric Laurent637e2d42018-11-15 12:24:31 -08004960 if (in && (audio_extn_ssr_get_stream() == in))
Shiv Maliyappanahalli5a10aea2015-07-02 10:36:23 -07004961 snd_device = SND_DEVICE_IN_THREE_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05304962
4963 if (snd_device != SND_DEVICE_NONE) {
4964 goto exit;
4965 }
4966
4967 if (in_device != AUDIO_DEVICE_NONE &&
4968 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
4969 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
4970 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Eric Laurent637e2d42018-11-15 12:24:31 -08004971 if (in && (audio_extn_ssr_get_stream() == in))
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05304972 snd_device = SND_DEVICE_IN_QUAD_MIC;
Vikram Pandurangaf0ca0b12018-05-04 16:00:07 -07004973 else if ((my_data->fluence_type & (FLUENCE_DUAL_MIC | FLUENCE_TRI_MIC | FLUENCE_QUAD_MIC)) &&
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05304974 (channel_count == 2) && (my_data->source_mic_type & SOURCE_DUAL_MIC))
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05304975 snd_device = SND_DEVICE_IN_HANDSET_STEREO_DMIC;
4976 else
4977 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05304978 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
4979 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Ramu Gottipati813ae982018-07-25 14:14:48 +05304980 } else if (in_device & AUDIO_DEVICE_IN_LINE) {
4981 snd_device = SND_DEVICE_IN_LINE;
Naresh Tannirue3b18452014-03-04 14:44:27 +05304982 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
4983 snd_device = SND_DEVICE_IN_HEADSET_MIC;
4984 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Vicky Sehrawate240e5d2014-08-12 17:17:04 -07004985 if (adev->bt_wb_speech_enabled) {
4986 if (adev->bluetooth_nrec)
4987 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
4988 else
4989 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
4990 } else {
4991 if (adev->bluetooth_nrec)
4992 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
4993 else
4994 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
4995 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05304996 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
4997 snd_device = SND_DEVICE_IN_HDMI_MIC;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05304998 } else if (in_device & AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET ||
4999 in_device & AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET) {
5000 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Mingming Yin12125e82015-10-26 20:40:36 -07005001 } else if (in_device & AUDIO_DEVICE_IN_FM_TUNER) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05305002 snd_device = SND_DEVICE_IN_CAPTURE_FM;
kunleiz1a1d26c2018-06-14 18:48:16 +08005003 } else if (audio_extn_usb_connected(NULL) && audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Kuirong Wanga9f7cee2016-03-07 11:21:52 -08005004 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05305005 } else {
5006 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
5007 ALOGW("%s: Using default handset-mic", __func__);
5008 snd_device = SND_DEVICE_IN_HANDSET_MIC;
5009 }
5010 } else {
5011 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
5012 snd_device = SND_DEVICE_IN_HANDSET_MIC;
5013 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
5014 snd_device = SND_DEVICE_IN_HEADSET_MIC;
5015 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05305016 if ((channel_count > 1) && (my_data->source_mic_type & SOURCE_DUAL_MIC))
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05305017 snd_device = SND_DEVICE_IN_SPEAKER_STEREO_DMIC;
5018 else
5019 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Naresh Tanniru9c4ba542015-11-06 18:01:09 +05305020 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
5021 out_device & AUDIO_DEVICE_OUT_LINE) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05305022 snd_device = SND_DEVICE_IN_HANDSET_MIC;
5023 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Vicky Sehrawate240e5d2014-08-12 17:17:04 -07005024 if (adev->bt_wb_speech_enabled) {
5025 if (adev->bluetooth_nrec)
5026 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
5027 else
5028 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
5029 } else {
5030 if (adev->bluetooth_nrec)
5031 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
5032 else
5033 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
5034 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05305035 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
5036 snd_device = SND_DEVICE_IN_HDMI_MIC;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05305037 } else if (out_device & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
5038 out_device & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
5039 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Satya Krishna Pindiprolice227962017-12-13 16:07:14 +05305040 } else if (out_device &
5041 (AUDIO_DEVICE_OUT_USB_DEVICE |
5042 AUDIO_DEVICE_OUT_USB_HEADSET)) {
kunleiz1a1d26c2018-06-14 18:48:16 +08005043 if (audio_extn_usb_is_capture_supported() && audio_extn_usb_connected(NULL))
Ashish Jain3e37a702016-11-25 12:27:15 +05305044 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
5045 else
5046 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05305047 } else {
5048 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
5049 ALOGW("%s: Using default handset-mic", __func__);
5050 snd_device = SND_DEVICE_IN_HANDSET_MIC;
5051 }
5052 }
5053exit:
5054 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
5055 return snd_device;
5056}
5057
5058int platform_set_hdmi_channels(void *platform, int channel_count)
5059{
5060 struct platform_data *my_data = (struct platform_data *)platform;
5061 struct audio_device *adev = my_data->adev;
5062 struct mixer_ctl *ctl;
5063 const char *channel_cnt_str = NULL;
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07005064 char *mixer_ctl_name;
Naresh Tannirue3b18452014-03-04 14:44:27 +05305065 switch (channel_count) {
5066 case 8:
5067 channel_cnt_str = "Eight"; break;
5068 case 7:
5069 channel_cnt_str = "Seven"; break;
5070 case 6:
5071 channel_cnt_str = "Six"; break;
5072 case 5:
5073 channel_cnt_str = "Five"; break;
5074 case 4:
5075 channel_cnt_str = "Four"; break;
5076 case 3:
5077 channel_cnt_str = "Three"; break;
5078 default:
5079 channel_cnt_str = "Two"; break;
5080 }
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07005081
5082 switch(my_data->ext_disp_type) {
5083 case EXT_DISPLAY_TYPE_HDMI:
5084 mixer_ctl_name = "HDMI_RX Channels";
5085 break;
5086 case EXT_DISPLAY_TYPE_DP:
5087 mixer_ctl_name = "Display Port RX Channels";
5088 break;
5089 default:
5090 ALOGE("%s: Invalid disp_type %d", __func__, my_data->ext_disp_type);
5091 return -EINVAL;
5092 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05305093 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
5094 if (!ctl) {
5095 ALOGE("%s: Could not get ctl for mixer cmd - %s",
5096 __func__, mixer_ctl_name);
5097 return -EINVAL;
5098 }
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07005099 ALOGV("Ext disp channel count: %s", channel_cnt_str);
Naresh Tannirue3b18452014-03-04 14:44:27 +05305100 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
5101 return 0;
5102}
5103
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05305104int platform_edid_get_max_channels(void *platform)
Naresh Tannirue3b18452014-03-04 14:44:27 +05305105{
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05305106 int channel_count;
5107 int max_channels = 2;
5108 int i = 0, ret = 0;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05305109 struct platform_data *my_data = (struct platform_data *)platform;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05305110 edid_audio_info *info = NULL;
5111 ret = platform_get_edid_info(platform);
5112 info = (edid_audio_info *)my_data->edid_info;
Naresh Tannirue3b18452014-03-04 14:44:27 +05305113
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05305114 if(ret == 0 && info != NULL) {
5115 for (i = 0; i < info->audio_blocks && i < MAX_EDID_BLOCKS; i++) {
5116 ALOGV("%s:format %d channel %d", __func__,
5117 info->audio_blocks_array[i].format_id,
5118 info->audio_blocks_array[i].channels);
5119 if (info->audio_blocks_array[i].format_id == LPCM) {
5120 channel_count = info->audio_blocks_array[i].channels;
5121 if (channel_count > max_channels) {
5122 max_channels = channel_count;
5123 }
5124 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05305125 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05305126 }
5127
5128 return max_channels;
5129}
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05305130
5131static int platform_set_slowtalk(struct platform_data *my_data, bool state)
5132{
5133 int ret = 0;
5134 struct audio_device *adev = my_data->adev;
5135 struct mixer_ctl *ctl;
5136 const char *mixer_ctl_name = "Slowtalk Enable";
Manish Dewangan338c50a2017-09-12 15:22:03 +05305137 long set_values[ ] = {0,
5138 ALL_SESSION_VSID};
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05305139
5140 set_values[0] = state;
5141 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
5142 if (!ctl) {
5143 ALOGE("%s: Could not get ctl for mixer cmd - %s",
5144 __func__, mixer_ctl_name);
5145 ret = -EINVAL;
5146 } else {
5147 ALOGV("Setting slowtalk state: %d", state);
5148 ret = mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
5149 my_data->slowtalk = state;
5150 }
5151
5152 if (my_data->csd != NULL) {
5153 ret = my_data->csd->slow_talk(ALL_SESSION_VSID, state);
5154 if (ret < 0) {
5155 ALOGE("%s: csd_client_disable_device, failed, error %d",
5156 __func__, ret);
5157 }
5158 }
5159 return ret;
5160}
5161
Avinash Vaishd5fa4572014-09-15 14:41:14 +05305162static int set_hd_voice(struct platform_data *my_data, bool state)
5163{
5164 struct audio_device *adev = my_data->adev;
5165 struct mixer_ctl *ctl;
5166 const char *mixer_ctl_name = "HD Voice Enable";
5167 int ret = 0;
Manish Dewangan338c50a2017-09-12 15:22:03 +05305168 long set_values[ ] = {0,
5169 ALL_SESSION_VSID};
Avinash Vaishd5fa4572014-09-15 14:41:14 +05305170
5171 set_values[0] = state;
5172 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
5173 if (!ctl) {
5174 ALOGE("%s: Could not get ctl for mixer cmd - %s",
5175 __func__, mixer_ctl_name);
5176 ret = -EINVAL;
5177 } else {
5178 ALOGV("Setting HD Voice state: %d", state);
5179 ret = mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
5180 my_data->hd_voice = state;
5181 }
5182
5183 return ret;
5184}
5185
Preetam Singh Ranawatb5271e02017-03-15 17:27:55 +05305186static int parse_audiocal_cfg(struct str_parms *parms, acdb_audio_cal_cfg_t *cal)
5187{
5188 int err;
5189 char value[64];
5190 int ret = 0;
5191
5192 if(parms == NULL || cal == NULL)
5193 return ret;
5194
5195 err = str_parms_get_str(parms, "cal_persist", value, sizeof(value));
5196 if (err >= 0) {
5197 str_parms_del(parms, "cal_persist");
5198 cal->persist = (uint32_t) strtoul(value, NULL, 0);
5199 ret = ret | 0x1;
5200 }
5201 err = str_parms_get_str(parms, "cal_apptype", value, sizeof(value));
5202 if (err >= 0) {
5203 str_parms_del(parms, "cal_apptype");
5204 cal->app_type = (uint32_t) strtoul(value, NULL, 0);
5205 ret = ret | 0x2;
5206 }
5207 err = str_parms_get_str(parms, "cal_caltype", value, sizeof(value));
5208 if (err >= 0) {
5209 str_parms_del(parms, "cal_caltype");
5210 cal->cal_type = (uint32_t) strtoul(value, NULL, 0);
5211 ret = ret | 0x4;
5212 }
5213 err = str_parms_get_str(parms, "cal_samplerate", value, sizeof(value));
5214 if (err >= 0) {
5215 str_parms_del(parms, "cal_samplerate");
5216 cal->sampling_rate = (uint32_t) strtoul(value, NULL, 0);
5217 ret = ret | 0x8;
5218 }
5219 err = str_parms_get_str(parms, "cal_devid", value, sizeof(value));
5220 if (err >= 0) {
5221 str_parms_del(parms, "cal_devid");
5222 cal->dev_id = (uint32_t) strtoul(value, NULL, 0);
5223 ret = ret | 0x10;
5224 }
5225 err = str_parms_get_str(parms, "cal_snddevid", value, sizeof(value));
5226 if (err >= 0) {
5227 str_parms_del(parms, "cal_snddevid");
5228 cal->snd_dev_id = (uint32_t) strtoul(value, NULL, 0);
5229 ret = ret | 0x20;
5230 }
5231 err = str_parms_get_str(parms, "cal_topoid", value, sizeof(value));
5232 if (err >= 0) {
5233 str_parms_del(parms, "cal_topoid");
5234 cal->topo_id = (uint32_t) strtoul(value, NULL, 0);
5235 ret = ret | 0x40;
5236 }
5237 err = str_parms_get_str(parms, "cal_moduleid", value, sizeof(value));
5238 if (err >= 0) {
5239 str_parms_del(parms, "cal_moduleid");
5240 cal->module_id = (uint32_t) strtoul(value, NULL, 0);
5241 ret = ret | 0x80;
5242 }
Aditya Bavanari29bcea22017-10-03 20:10:35 +05305243#ifdef INSTANCE_ID_ENABLED
5244 err = str_parms_get_str(parms, "cal_instanceid", value, sizeof(value));
5245 if (err >= 0) {
5246 str_parms_del(parms, "cal_instanceid");
5247 cal->instance_id = (uint32_t) strtoul(value, NULL, 0);
5248 ret = ret | 0x100;
5249 }
5250#endif
Preetam Singh Ranawatb5271e02017-03-15 17:27:55 +05305251 err = str_parms_get_str(parms, "cal_paramid", value, sizeof(value));
5252 if (err >= 0) {
5253 str_parms_del(parms, "cal_paramid");
5254 cal->param_id = (uint32_t) strtoul(value, NULL, 0);
Aditya Bavanari29bcea22017-10-03 20:10:35 +05305255 ret = ret | 0x200;
Preetam Singh Ranawatb5271e02017-03-15 17:27:55 +05305256 }
5257 return ret;
5258}
5259
5260static void set_audiocal(void *platform, struct str_parms *parms, char *value, int len) {
5261 struct platform_data *my_data = (struct platform_data *)platform;
5262 struct stream_out out;
5263 acdb_audio_cal_cfg_t cal;
5264 uint8_t *dptr = NULL;
5265 int32_t dlen;
5266 int err, ret;
5267 if(value == NULL || platform == NULL || parms == NULL) {
5268 ALOGE("[%s] received null pointer, failed",__func__);
5269 goto done_key_audcal;
5270 }
5271
Aditya Bavanarie293d5b2017-11-15 12:48:36 +05305272 memset(&cal, 0, sizeof(acdb_audio_cal_cfg_t));
Preetam Singh Ranawatb5271e02017-03-15 17:27:55 +05305273 /* parse audio calibration keys */
5274 ret = parse_audiocal_cfg(parms, &cal);
5275
5276 /* handle audio calibration data now */
5277 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_AUD_CALDATA, value, len);
5278 if (err >= 0) {
5279 str_parms_del(parms, AUDIO_PARAMETER_KEY_AUD_CALDATA);
5280 dlen = strlen(value);
5281 if(dlen <= 0) {
5282 ALOGE("[%s] null data received",__func__);
5283 goto done_key_audcal;
5284 }
5285 dptr = (uint8_t*) calloc(dlen, sizeof(uint8_t));
5286 if(dptr == NULL) {
5287 ALOGE("[%s] memory allocation failed for %d",__func__, dlen);
5288 goto done_key_audcal;
5289 }
5290 dlen = b64decode(value, strlen(value), dptr);
5291 if(dlen<=0) {
5292 ALOGE("[%s] data decoding failed %d", __func__, dlen);
5293 goto done_key_audcal;
5294 }
5295
Eric Laurent637e2d42018-11-15 12:24:31 -08005296 if (cal.dev_id) {
5297 if (audio_is_input_device(cal.dev_id)) {
5298 cal.snd_dev_id = platform_get_input_snd_device(platform, NULL, cal.dev_id);
Preetam Singh Ranawatb5271e02017-03-15 17:27:55 +05305299 } else {
5300 out.devices = cal.dev_id;
5301 out.sample_rate = cal.sampling_rate;
5302 cal.snd_dev_id = platform_get_output_snd_device(platform, &out);
5303 }
5304 }
5305 cal.acdb_dev_id = platform_get_snd_device_acdb_id(cal.snd_dev_id);
5306 ALOGD("Setting audio calibration for snd_device(%d) acdb_id(%d)",
5307 cal.snd_dev_id, cal.acdb_dev_id);
5308 if(cal.acdb_dev_id == -EINVAL) {
5309 ALOGE("[%s] Invalid acdb_device id %d for snd device id %d",
5310 __func__, cal.acdb_dev_id, cal.snd_dev_id);
5311 goto done_key_audcal;
5312 }
5313 if(my_data->acdb_set_audio_cal) {
5314 ret = my_data->acdb_set_audio_cal((void *)&cal, (void*)dptr, dlen);
5315 }
5316 }
5317done_key_audcal:
5318 if(dptr != NULL)
5319 free(dptr);
5320}
Surendar Karka45850ae2018-07-02 17:45:27 +05305321static void platform_spkr_device_set_params(struct platform_data *platform,
5322 struct str_parms *parms,
5323 char *value, int len)
5324{
5325 int err = 0, i = 0, num_ch = 0;
5326 char *test_r = NULL;
5327 char *opts = NULL;
5328 char *ch_count = NULL;
5329
5330 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_SPKR_DEVICE_CHMAP,
5331 value, len);
5332 if (err >= 0) {
5333 platform->spkr_ch_map = calloc(1, sizeof(struct spkr_device_chmap));
5334 if (!platform->spkr_ch_map) {
5335 ALOGE("%s: failed to allocate mem for adm channel map\n", __func__);
5336 str_parms_del(parms, AUDIO_PARAMETER_KEY_SPKR_DEVICE_CHMAP);
5337 return ;
5338 }
5339
5340 ch_count = strtok_r(value, ", ", &test_r);
5341 if (ch_count == NULL) {
5342 ALOGE("%s: incorrect ch_map\n", __func__);
5343 free(platform->spkr_ch_map);
5344 platform->spkr_ch_map = NULL;
5345 str_parms_del(parms, AUDIO_PARAMETER_KEY_SPKR_DEVICE_CHMAP);
5346 return;
5347 }
5348
5349 num_ch = atoi(ch_count);
5350 if ((num_ch > 0) && (num_ch <= AUDIO_CHANNEL_COUNT_MAX) ) {
5351 platform->spkr_ch_map->num_ch = num_ch;
5352 for (i = 0; i < num_ch; i++) {
5353 opts = strtok_r(NULL, ", ", &test_r);
Jhansi Konathala902fc412018-09-05 13:21:44 +05305354 if (opts != NULL)
5355 platform->spkr_ch_map->chmap[i] = strtoul(opts, NULL, 16);
Surendar Karka45850ae2018-07-02 17:45:27 +05305356 }
5357 }
5358 str_parms_del(parms, AUDIO_PARAMETER_KEY_SPKR_DEVICE_CHMAP);
5359 }
5360}
5361
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05305362int platform_set_parameters(void *platform, struct str_parms *parms)
5363{
5364 struct platform_data *my_data = (struct platform_data *)platform;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05305365 char value[256] = {0};
Satya Krishna Pindiprolif1cd92b2016-04-14 19:05:23 +05305366 int len;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05305367 int ret = 0, err;
Karthik Reddy Kattabfe193d2014-08-14 17:58:18 +05305368 char *kv_pairs = NULL;
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05305369 struct listnode *node;
5370 struct meta_key_list *key_info;
5371 int key = 0;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05305372
Karthik Reddy Kattabfe193d2014-08-14 17:58:18 +05305373 kv_pairs = str_parms_to_str(parms);
Preetam Singh Ranawat7156bd82016-09-07 18:29:33 +05305374 if(!kv_pairs)
5375 return ret;
Venkata Narendra Kumar Gutta7c131ef2015-11-17 14:15:57 +05305376 len = strlen(kv_pairs);
Karthik Reddy Kattabfe193d2014-08-14 17:58:18 +05305377 ALOGV("%s: enter: - %s", __func__, kv_pairs);
5378 free(kv_pairs);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05305379
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05305380 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_SLOWTALK, value, sizeof(value));
5381 if (err >= 0) {
5382 bool state = false;
5383 if (!strncmp("true", value, sizeof("true"))) {
5384 state = true;
5385 }
5386
5387 str_parms_del(parms, AUDIO_PARAMETER_KEY_SLOWTALK);
5388 ret = platform_set_slowtalk(my_data, state);
5389 if (ret)
5390 ALOGE("%s: Failed to set slow talk err: %d", __func__, ret);
5391 }
5392
Avinash Vaishd5fa4572014-09-15 14:41:14 +05305393 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_HD_VOICE, value, sizeof(value));
5394 if (err >= 0) {
5395 bool state = false;
5396 if (!strncmp("true", value, sizeof("true"))) {
5397 state = true;
5398 }
5399
5400 str_parms_del(parms, AUDIO_PARAMETER_KEY_HD_VOICE);
5401 if (my_data->hd_voice != state) {
5402 ret = set_hd_voice(my_data, state);
5403 if (ret)
5404 ALOGE("%s: Failed to set HD voice err: %d", __func__, ret);
5405 } else {
5406 ALOGV("%s: HD Voice already set to %d", __func__, state);
5407 }
5408 }
5409
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05305410 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_VOLUME_BOOST,
5411 value, sizeof(value));
5412 if (err >= 0) {
5413 str_parms_del(parms, AUDIO_PARAMETER_KEY_VOLUME_BOOST);
5414
5415 if (my_data->acdb_reload_vocvoltable == NULL) {
5416 ALOGE("%s: acdb_reload_vocvoltable is NULL", __func__);
5417 } else if (!strcmp(value, "on")) {
5418 if (!my_data->acdb_reload_vocvoltable(VOICE_FEATURE_SET_VOLUME_BOOST)) {
5419 my_data->voice_feature_set = 1;
5420 }
5421 } else {
5422 if (!my_data->acdb_reload_vocvoltable(VOICE_FEATURE_SET_DEFAULT)) {
5423 my_data->voice_feature_set = 0;
5424 }
5425 }
5426 }
5427
Karthik Reddy Katta8513f432016-04-12 14:29:27 +05305428 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_RELOAD_ACDB,
5429 value, sizeof(value));
5430 if (err >= 0) {
5431 str_parms_del(parms, AUDIO_PARAMETER_KEY_RELOAD_ACDB);
5432
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05305433 if (my_data->acdb_reload_v2) {
5434 my_data->acdb_reload_v2(value, my_data->snd_card_name,
5435 my_data->cvd_version, &my_data->acdb_meta_key_list);
5436 } else if (my_data->acdb_reload) {
5437 node = list_head(&my_data->acdb_meta_key_list);
5438 key_info = node_to_item(node, struct meta_key_list, list);
5439 key = key_info->cal_info.nKey;
5440 my_data->acdb_reload(value, my_data->snd_card_name,
5441 my_data->cvd_version, key);
5442 }
Karthik Reddy Katta8513f432016-04-12 14:29:27 +05305443 }
5444
Rohit kumard3c3b912016-11-15 18:50:31 +05305445 if (hw_info_is_stereo_spkr(my_data->hw_info)) {
5446 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_MONO_SPEAKER, value, len);
5447 if (err >= 0) {
5448 if (!strncmp("left", value, sizeof("left")))
5449 my_data->mono_speaker = SPKR_1;
5450 else if (!strncmp("right", value, sizeof("right")))
5451 my_data->mono_speaker = SPKR_2;
Rohit kumarf4120402016-08-05 19:19:48 +05305452
Rohit kumard3c3b912016-11-15 18:50:31 +05305453 str_parms_del(parms, AUDIO_PARAMETER_KEY_MONO_SPEAKER);
5454 }
Rohit kumarf4120402016-08-05 19:19:48 +05305455 }
5456
Naresh Tanniruc0517bc2014-10-26 15:30:55 +05305457 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_REC_PLAY_CONC, value, sizeof(value));
5458 if (err >= 0) {
5459 if (!strncmp("true", value, sizeof("true"))) {
5460 ALOGD("setting record playback concurrency to true");
5461 my_data->rec_play_conc_set = true;
5462 } else {
5463 ALOGD("setting record playback concurrency to false");
5464 my_data->rec_play_conc_set = false;
5465 }
Naresh Tanniruc0517bc2014-10-26 15:30:55 +05305466 }
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05305467
5468 err = str_parms_get_str(parms, PLATFORM_MAX_MIC_COUNT,
5469 value, sizeof(value));
5470 if (err >= 0) {
5471 str_parms_del(parms, PLATFORM_MAX_MIC_COUNT);
5472 my_data->max_mic_count = atoi(value);
5473 ALOGV("%s: max_mic_count %d", __func__, my_data->max_mic_count);
5474 }
5475
Preetam Singh Ranawatb5271e02017-03-15 17:27:55 +05305476 /* handle audio calibration parameters */
5477 set_audiocal(platform, parms, value, len);
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05305478 native_audio_set_params(platform, parms, value, sizeof(value));
Venkata Narendra Kumar Gutta7c131ef2015-11-17 14:15:57 +05305479 audio_extn_spkr_prot_set_parameters(parms, value, len);
Satya Krishna Pindiprolif5eddfd2016-12-28 11:29:08 +05305480 audio_extn_usb_set_sidetone_gain(parms, value, len);
Naresh Tanniru351ffc72017-04-24 17:13:07 +05305481 audio_extn_hfp_set_parameters(my_data->adev, parms);
Ashish Jainf1eaa582016-05-23 20:54:24 +05305482 true_32_bit_set_params(parms, value, len);
Garmond Leunge2433c32017-09-28 21:51:22 -07005483 audio_extn_ffv_set_parameters(my_data->adev, parms);
Surendar Karka45850ae2018-07-02 17:45:27 +05305484 platform_spkr_device_set_params(platform, parms, value, len);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05305485 ALOGV("%s: exit with code(%d)", __func__, ret);
5486 return ret;
5487}
5488
5489int platform_set_incall_recording_session_id(void *platform,
5490 uint32_t session_id, int rec_mode)
5491{
5492 int ret = 0;
5493 struct platform_data *my_data = (struct platform_data *)platform;
5494 struct audio_device *adev = my_data->adev;
5495 struct mixer_ctl *ctl;
5496 const char *mixer_ctl_name = "Voc VSID";
5497 int num_ctl_values;
5498 int i;
5499
5500 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
5501 if (!ctl) {
5502 ALOGE("%s: Could not get ctl for mixer cmd - %s",
5503 __func__, mixer_ctl_name);
5504 ret = -EINVAL;
5505 } else {
5506 num_ctl_values = mixer_ctl_get_num_values(ctl);
5507 for (i = 0; i < num_ctl_values; i++) {
5508 if (mixer_ctl_set_value(ctl, i, session_id)) {
5509 ALOGV("Error: invalid session_id: %x", session_id);
5510 ret = -EINVAL;
5511 break;
5512 }
5513 }
5514 }
5515
5516 if (my_data->csd != NULL) {
5517 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
5518 if (ret < 0) {
5519 ALOGE("%s: csd_client_start_record failed, error %d",
5520 __func__, ret);
5521 }
5522 }
5523
5524 return ret;
5525}
5526
5527int platform_stop_incall_recording_usecase(void *platform)
5528{
5529 int ret = 0;
5530 struct platform_data *my_data = (struct platform_data *)platform;
5531
5532 if (my_data->csd != NULL) {
5533 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
5534 if (ret < 0) {
5535 ALOGE("%s: csd_client_stop_record failed, error %d",
5536 __func__, ret);
5537 }
5538 }
5539
5540 return ret;
5541}
5542
5543int platform_start_incall_music_usecase(void *platform)
5544{
5545 int ret = 0;
5546 struct platform_data *my_data = (struct platform_data *)platform;
5547
5548 if (my_data->csd != NULL) {
5549 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
5550 if (ret < 0) {
5551 ALOGE("%s: csd_client_start_playback failed, error %d",
5552 __func__, ret);
5553 }
5554 }
5555
5556 return ret;
5557}
5558
5559int platform_stop_incall_music_usecase(void *platform)
5560{
5561 int ret = 0;
5562 struct platform_data *my_data = (struct platform_data *)platform;
5563
5564 if (my_data->csd != NULL) {
5565 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
5566 if (ret < 0) {
5567 ALOGE("%s: csd_client_stop_playback failed, error %d",
5568 __func__, ret);
5569 }
5570 }
5571
5572 return ret;
5573}
5574
Vidyakumar Athota21b3bb92014-04-25 11:08:08 -07005575int platform_update_lch(void *platform, struct voice_session *session,
5576 enum voice_lch_mode lch_mode)
5577{
5578 int ret = 0;
5579 struct platform_data *my_data = (struct platform_data *)platform;
5580
5581 if ((my_data->csd != NULL) && (my_data->csd->set_lch != NULL))
5582 ret = my_data->csd->set_lch(session->vsid, lch_mode);
5583 else
5584 ret = pcm_ioctl(session->pcm_tx, SNDRV_VOICE_IOCTL_LCH, &lch_mode);
5585
5586 return ret;
5587}
5588
Preetam Singh Ranawatb5271e02017-03-15 17:27:55 +05305589static void get_audiocal(void *platform, void *keys, void *pReply) {
5590 struct platform_data *my_data = (struct platform_data *)platform;
5591 struct stream_out out;
5592 struct str_parms *query = (struct str_parms *)keys;
5593 struct str_parms *reply=(struct str_parms *)pReply;
5594 acdb_audio_cal_cfg_t cal;
5595 uint8_t *dptr = NULL;
5596 char value[512] = {0};
5597 char *rparms=NULL;
5598 int ret=0, err;
5599 uint32_t param_len;
5600
5601 if(query==NULL || platform==NULL || reply==NULL) {
5602 ALOGE("[%s] received null pointer",__func__);
5603 ret=-EINVAL;
5604 goto done;
5605 }
Aditya Bavanarie293d5b2017-11-15 12:48:36 +05305606
5607 memset(&cal, 0, sizeof(acdb_audio_cal_cfg_t));
Preetam Singh Ranawatb5271e02017-03-15 17:27:55 +05305608 /* parse audiocal configuration keys */
5609 ret = parse_audiocal_cfg(query, &cal);
5610 if(ret == 0) {
5611 /* No calibration keys found */
5612 goto done;
5613 }
5614 err = str_parms_get_str(query, AUDIO_PARAMETER_KEY_AUD_CALDATA, value, sizeof(value));
5615 if (err >= 0) {
5616 str_parms_del(query, AUDIO_PARAMETER_KEY_AUD_CALDATA);
5617 } else {
5618 goto done;
5619 }
5620
5621 if(cal.dev_id & AUDIO_DEVICE_BIT_IN) {
Eric Laurent637e2d42018-11-15 12:24:31 -08005622 cal.snd_dev_id = platform_get_input_snd_device(platform, NULL, cal.dev_id);
Preetam Singh Ranawatb5271e02017-03-15 17:27:55 +05305623 } else if(cal.dev_id) {
5624 out.devices = cal.dev_id;
5625 out.sample_rate = cal.sampling_rate;
5626 cal.snd_dev_id = platform_get_output_snd_device(platform, &out);
5627 }
5628 cal.acdb_dev_id = platform_get_snd_device_acdb_id(cal.snd_dev_id);
5629 if (cal.acdb_dev_id < 0) {
5630 ALOGE("%s: Failed. Could not find acdb id for snd device(%d)",
5631 __func__, cal.snd_dev_id);
5632 ret = -EINVAL;
5633 goto done_key_audcal;
5634 }
5635 ALOGD("[%s] Getting audio calibration for snd_device(%d) acdb_id(%d)",
5636 __func__, cal.snd_dev_id, cal.acdb_dev_id);
5637
5638 param_len = MAX_SET_CAL_BYTE_SIZE;
5639 dptr = (uint8_t*)calloc(param_len, sizeof(uint8_t));
5640 if(dptr == NULL) {
5641 ALOGE("[%s] Memory allocation failed for length %d",__func__,param_len);
5642 ret = -ENOMEM;
5643 goto done_key_audcal;
5644 }
5645 if (my_data->acdb_get_audio_cal != NULL) {
5646 ret = my_data->acdb_get_audio_cal((void*)&cal, (void*)dptr, &param_len);
5647 if (ret == 0) {
5648 if(param_len == 0 || param_len == MAX_SET_CAL_BYTE_SIZE) {
5649 ret = -EINVAL;
5650 goto done_key_audcal;
5651 }
5652 /* Allocate memory for encoding */
5653 rparms = (char*)calloc((param_len*2), sizeof(char));
5654 if(rparms == NULL) {
5655 ALOGE("[%s] Memory allocation failed for size %d",
5656 __func__, param_len*2);
5657 ret = -ENOMEM;
5658 goto done_key_audcal;
5659 }
5660 if(cal.persist==0 && cal.module_id && cal.param_id) {
5661 err = b64encode(dptr+12, param_len-12, rparms);
5662 } else {
5663 err = b64encode(dptr, param_len, rparms);
5664 }
5665 if(err < 0) {
5666 ALOGE("[%s] failed to convert data to string", __func__);
5667 ret = -EINVAL;
5668 goto done_key_audcal;
5669 }
5670 str_parms_add_int(reply, AUDIO_PARAMETER_KEY_AUD_CALRESULT, ret);
5671 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_AUD_CALDATA, rparms);
5672 }
5673 }
5674done_key_audcal:
5675 if(ret != 0) {
5676 str_parms_add_int(reply, AUDIO_PARAMETER_KEY_AUD_CALRESULT, ret);
5677 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_AUD_CALDATA, "");
5678 }
5679done:
5680 if(dptr != NULL)
5681 free(dptr);
5682 if(rparms != NULL)
5683 free(rparms);
5684}
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05305685void platform_get_parameters(void *platform,
5686 struct str_parms *query,
5687 struct str_parms *reply)
5688{
5689 struct platform_data *my_data = (struct platform_data *)platform;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05305690 char value[512] = {0};
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05305691 int ret;
Karthik Reddy Kattabfe193d2014-08-14 17:58:18 +05305692 char *kv_pairs = NULL;
Sidipotu Ashok42483b62015-09-08 10:21:44 +05305693 char propValue[PROPERTY_VALUE_MAX]={0};
5694 bool prop_playback_enabled = false;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05305695
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05305696 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_SLOWTALK,
5697 value, sizeof(value));
5698 if (ret >= 0) {
5699 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_SLOWTALK,
5700 my_data->slowtalk?"true":"false");
5701 }
5702
Avinash Vaishd5fa4572014-09-15 14:41:14 +05305703 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_HD_VOICE,
5704 value, sizeof(value));
5705 if (ret >= 0) {
5706 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_HD_VOICE,
5707 my_data->hd_voice?"true":"false");
5708 }
5709
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05305710 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_VOLUME_BOOST,
5711 value, sizeof(value));
5712 if (ret >= 0) {
5713 if (my_data->voice_feature_set == VOICE_FEATURE_SET_VOLUME_BOOST) {
5714 strlcpy(value, "on", sizeof(value));
5715 } else {
5716 strlcpy(value, "off", sizeof(value));
5717 }
5718
5719 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_VOLUME_BOOST, value);
5720 }
Preetam Singh Ranawatb5271e02017-03-15 17:27:55 +05305721 /* Handle audio calibration keys */
5722 get_audiocal(platform, query, reply);
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05305723 native_audio_get_params(query, reply, value, sizeof(value));
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05305724
Sidipotu Ashokf490be52015-10-20 10:41:34 +05305725 ret = str_parms_get_str(query, AUDIO_PARAMETER_IS_HW_DECODER_SESSION_AVAILABLE,
Sidipotu Ashok42483b62015-09-08 10:21:44 +05305726 value, sizeof(value));
5727 if (ret >= 0) {
5728 int isallowed = 1; /*true*/
5729
Aniket Kumar Lata8fc67e62017-05-02 12:33:46 -07005730 if (property_get("vendor.voice.playback.conc.disabled", propValue, NULL)) {
Sidipotu Ashok42483b62015-09-08 10:21:44 +05305731 prop_playback_enabled = atoi(propValue) ||
5732 !strncmp("true", propValue, 4);
5733 }
5734
Dhanalakshmi Siddania15c6792016-08-10 15:33:53 +05305735 if ((prop_playback_enabled && (voice_is_in_call(my_data->adev))) ||
Dhananjay Kumare6293dd2017-05-25 17:25:30 +05305736 (CARD_STATUS_OFFLINE == my_data->adev->card_status)) {
Sidipotu Ashok42483b62015-09-08 10:21:44 +05305737 char *decoder_mime_type = value;
5738
5739 //check if unsupported mime type or not
5740 if(decoder_mime_type) {
Alexy Josephb1379942016-01-29 15:49:38 -08005741 unsigned int i = 0;
Sidipotu Ashok42483b62015-09-08 10:21:44 +05305742 for (i = 0; i < sizeof(dsp_only_decoders_mime)/sizeof(dsp_only_decoders_mime[0]); i++) {
5743 if (!strncmp(decoder_mime_type, dsp_only_decoders_mime[i],
5744 strlen(dsp_only_decoders_mime[i]))) {
5745 ALOGD("Rejecting request for DSP only session from HAL during voice call/SSR state");
5746 isallowed = 0;
5747 break;
5748 }
5749 }
5750 }
5751 }
Sidipotu Ashokf490be52015-10-20 10:41:34 +05305752 str_parms_add_int(reply, AUDIO_PARAMETER_IS_HW_DECODER_SESSION_AVAILABLE, isallowed);
Sidipotu Ashok42483b62015-09-08 10:21:44 +05305753 }
5754
5755
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05305756 /* Handle audio calibration keys */
Karthik Reddy Kattabfe193d2014-08-14 17:58:18 +05305757 kv_pairs = str_parms_to_str(reply);
5758 ALOGV("%s: exit: returns - %s", __func__, kv_pairs);
5759 free(kv_pairs);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05305760}
5761
Lakshman Chaluvaraju22ba9f12016-09-12 11:42:10 +05305762unsigned char* platform_get_license(void *platform __unused, int *size __unused)
5763{
5764 ALOGE("%s: Not implemented", __func__);
5765 return NULL;
5766}
5767
5768
Ashish Jain5106d362016-05-11 19:23:33 +05305769/* Delay in Us, only to be used for PCM formats */
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05305770int64_t platform_render_latency(audio_usecase_t usecase)
5771{
5772 switch (usecase) {
5773 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
5774 return DEEP_BUFFER_PLATFORM_DELAY;
5775 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
5776 return LOW_LATENCY_PLATFORM_DELAY;
Ashish Jain5106d362016-05-11 19:23:33 +05305777 case USECASE_AUDIO_PLAYBACK_OFFLOAD:
5778 case USECASE_AUDIO_PLAYBACK_OFFLOAD2:
5779 return PCM_OFFLOAD_PLATFORM_DELAY;
Haynes Mathew George5beddd42016-06-27 18:33:40 -07005780 case USECASE_AUDIO_PLAYBACK_ULL:
5781 return ULL_PLATFORM_DELAY;
Haynes Mathew George16081042017-05-31 17:16:49 -07005782 case USECASE_AUDIO_PLAYBACK_MMAP:
5783 return MMAP_PLATFORM_DELAY;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05305784 default:
5785 return 0;
5786 }
5787}
5788
5789int platform_update_usecase_from_source(int source, int usecase)
5790{
5791 ALOGV("%s: input source :%d", __func__, source);
Mingming Yin12125e82015-10-26 20:40:36 -07005792 if (source == AUDIO_SOURCE_FM_TUNER)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05305793 usecase = USECASE_AUDIO_RECORD_FM_VIRTUAL;
5794 return usecase;
5795}
5796
Dhananjay Kumar45b71742014-05-29 21:47:27 +05305797bool platform_listen_device_needs_event(snd_device_t snd_device)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05305798{
Dhananjay Kumar45b71742014-05-29 21:47:27 +05305799 bool needs_event = false;
5800
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05305801 if ((snd_device >= SND_DEVICE_IN_BEGIN) &&
5802 (snd_device < SND_DEVICE_IN_END) &&
5803 (snd_device != SND_DEVICE_IN_CAPTURE_FM) &&
Rohit kumarf4120402016-08-05 19:19:48 +05305804 (snd_device != SND_DEVICE_IN_CAPTURE_VI_FEEDBACK) &&
5805 (snd_device != SND_DEVICE_IN_CAPTURE_VI_FEEDBACK_MONO_1) &&
5806 (snd_device != SND_DEVICE_IN_CAPTURE_VI_FEEDBACK_MONO_2))
Dhananjay Kumar45b71742014-05-29 21:47:27 +05305807 needs_event = true;
5808
5809 return needs_event;
5810}
5811
5812bool platform_listen_usecase_needs_event(audio_usecase_t uc_id)
5813{
5814 bool needs_event = false;
5815
5816 switch(uc_id){
5817 /* concurrent playback usecases needs event */
5818 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
5819 case USECASE_AUDIO_PLAYBACK_MULTI_CH:
5820 case USECASE_AUDIO_PLAYBACK_OFFLOAD:
5821 needs_event = true;
5822 break;
5823 /* concurrent playback in low latency allowed */
5824 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
5825 break;
5826 /* concurrent playback FM needs event */
5827 case USECASE_AUDIO_PLAYBACK_FM:
5828 needs_event = true;
5829 break;
5830
5831 /* concurrent capture usecases, no event, capture handled by device
5832 * USECASE_AUDIO_RECORD:
5833 * USECASE_AUDIO_RECORD_COMPRESS:
5834 * USECASE_AUDIO_RECORD_LOW_LATENCY:
5835
5836 * USECASE_VOICE_CALL:
5837 * USECASE_VOICE2_CALL:
5838 * USECASE_VOLTE_CALL:
5839 * USECASE_QCHAT_CALL:
5840 * USECASE_VOWLAN_CALL:
Avinash Vaish306e6072015-05-13 16:58:18 +05305841 * USECASE_VOICEMMODE1_CALL:
5842 * USECASE_VOICEMMODE2_CALL:
Dhananjay Kumar45b71742014-05-29 21:47:27 +05305843 * USECASE_COMPRESS_VOIP_CALL:
5844 * USECASE_AUDIO_RECORD_FM_VIRTUAL:
5845 * USECASE_INCALL_REC_UPLINK:
5846 * USECASE_INCALL_REC_DOWNLINK:
5847 * USECASE_INCALL_REC_UPLINK_AND_DOWNLINK:
5848 * USECASE_INCALL_REC_UPLINK_COMPRESS:
5849 * USECASE_INCALL_REC_DOWNLINK_COMPRESS:
5850 * USECASE_INCALL_REC_UPLINK_AND_DOWNLINK_COMPRESS:
5851 * USECASE_INCALL_MUSIC_UPLINK:
5852 * USECASE_INCALL_MUSIC_UPLINK2:
5853 * USECASE_AUDIO_SPKR_CALIB_RX:
5854 * USECASE_AUDIO_SPKR_CALIB_TX:
5855 */
5856 default:
5857 ALOGV("%s:usecase_id[%d} no need to raise event.", __func__, uc_id);
5858 }
5859 return needs_event;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05305860}
5861
Ravi Kumar Alamanda8fa6b192014-09-09 16:06:42 -07005862bool platform_sound_trigger_device_needs_event(snd_device_t snd_device)
5863{
5864 bool needs_event = false;
5865
5866 if ((snd_device >= SND_DEVICE_IN_BEGIN) &&
5867 (snd_device < SND_DEVICE_IN_END) &&
5868 (snd_device != SND_DEVICE_IN_CAPTURE_FM) &&
Rohit kumarf4120402016-08-05 19:19:48 +05305869 (snd_device != SND_DEVICE_IN_CAPTURE_VI_FEEDBACK) &&
5870 (snd_device != SND_DEVICE_IN_CAPTURE_VI_FEEDBACK_MONO_1) &&
5871 (snd_device != SND_DEVICE_IN_CAPTURE_VI_FEEDBACK_MONO_2))
Ravi Kumar Alamanda8fa6b192014-09-09 16:06:42 -07005872 needs_event = true;
5873
5874 return needs_event;
5875}
5876
5877bool platform_sound_trigger_usecase_needs_event(audio_usecase_t uc_id)
5878{
5879 bool needs_event = false;
5880
5881 switch(uc_id){
5882 /* concurrent playback usecases needs event */
5883 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
5884 case USECASE_AUDIO_PLAYBACK_MULTI_CH:
5885 case USECASE_AUDIO_PLAYBACK_OFFLOAD:
Quinn Malef15123f2017-04-27 18:58:05 -07005886 case USECASE_AUDIO_PLAYBACK_OFFLOAD2:
Ravi Kumar Alamanda8fa6b192014-09-09 16:06:42 -07005887 needs_event = true;
5888 break;
5889 /* concurrent playback in low latency allowed */
5890 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
5891 break;
5892 /* concurrent playback FM needs event */
5893 case USECASE_AUDIO_PLAYBACK_FM:
5894 needs_event = true;
5895 break;
5896
Dhanalakshmi Siddanif133cc52018-02-08 14:34:51 +05305897 /* concurrent capture usecases which needs event */
5898 case USECASE_AUDIO_RECORD:
5899 case USECASE_AUDIO_RECORD_LOW_LATENCY:
5900 case USECASE_AUDIO_RECORD_COMPRESS:
5901 case USECASE_AUDIO_RECORD_MMAP:
5902 case USECASE_AUDIO_RECORD_HIFI:
5903 case USECASE_VOICE_CALL:
5904 case USECASE_VOICE2_CALL:
5905 case USECASE_VOLTE_CALL:
5906 case USECASE_QCHAT_CALL:
5907 case USECASE_VOWLAN_CALL:
5908 case USECASE_VOICEMMODE1_CALL:
5909 case USECASE_VOICEMMODE2_CALL:
5910 case USECASE_COMPRESS_VOIP_CALL:
Dhanalakshmi Siddanif133cc52018-02-08 14:34:51 +05305911 case USECASE_INCALL_REC_UPLINK:
5912 case USECASE_INCALL_REC_DOWNLINK:
5913 case USECASE_INCALL_REC_UPLINK_AND_DOWNLINK:
5914 case USECASE_INCALL_REC_UPLINK_COMPRESS:
5915 case USECASE_INCALL_REC_DOWNLINK_COMPRESS:
5916 case USECASE_INCALL_REC_UPLINK_AND_DOWNLINK_COMPRESS:
5917 case USECASE_INCALL_MUSIC_UPLINK:
5918 case USECASE_INCALL_MUSIC_UPLINK2:
Dhanalakshmi Siddanif133cc52018-02-08 14:34:51 +05305919 case USECASE_AUDIO_RECORD_VOIP:
5920 needs_event = true;
5921 break;
Ravi Kumar Alamanda8fa6b192014-09-09 16:06:42 -07005922 default:
5923 ALOGV("%s:usecase_id[%d] no need to raise event.", __func__, uc_id);
5924 }
5925 return needs_event;
5926}
5927
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05305928/* Read offload buffer size from a property.
5929 * If value is not power of 2 round it to
5930 * power of 2.
5931 */
5932uint32_t platform_get_compress_offload_buffer_size(audio_offload_info_t* info)
5933{
5934 char value[PROPERTY_VALUE_MAX] = {0};
5935 uint32_t fragment_size = COMPRESS_OFFLOAD_FRAGMENT_SIZE;
Aniket Kumar Lata8fc67e62017-05-02 12:33:46 -07005936 if((property_get("vendor.audio.offload.buffer.size.kb", value, "")) &&
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05305937 atoi(value)) {
5938 fragment_size = atoi(value) * 1024;
5939 }
5940
vivek mehta80a44292015-08-10 12:58:10 -07005941 /* Use incoming offload buffer size if default buffer size is less */
5942 if ((info != NULL) && (fragment_size < info->offload_buffer_size)) {
5943 ALOGI("%s:: Overwriting offload buffer size default:%d new:%d", __func__,
5944 fragment_size,
5945 info->offload_buffer_size);
5946 fragment_size = info->offload_buffer_size;
5947 }
5948
Ramjee Singh21ffaa82017-07-28 17:47:01 +05305949 if (info != NULL) {
5950 if (info->is_streaming && info->has_video) {
Preetam Singh Ranawat3e5b9e72016-11-10 16:12:25 +05305951 fragment_size = COMPRESS_OFFLOAD_FRAGMENT_SIZE_FOR_AV_STREAMING;
5952 ALOGV("%s: offload fragment size reduced for AV streaming to %d",
5953 __func__, fragment_size);
5954 } else if (info->format == AUDIO_FORMAT_FLAC) {
5955 fragment_size = FLAC_COMPRESS_OFFLOAD_FRAGMENT_SIZE;
5956 ALOGV("FLAC fragment size %d", fragment_size);
5957 } else if (info->format == AUDIO_FORMAT_DSD) {
5958 fragment_size = MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE;
Aniket Kumar Lata8fc67e62017-05-02 12:33:46 -07005959 if((property_get("vendor.audio.native.dsd.buffer.size.kb", value, "")) &&
Preetam Singh Ranawat3e5b9e72016-11-10 16:12:25 +05305960 atoi(value))
5961 fragment_size = atoi(value) * 1024;
5962 ALOGV("DSD fragment size %d", fragment_size);
5963 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05305964 }
5965
5966 fragment_size = ALIGN( fragment_size, 1024);
5967
5968 if(fragment_size < MIN_COMPRESS_OFFLOAD_FRAGMENT_SIZE)
5969 fragment_size = MIN_COMPRESS_OFFLOAD_FRAGMENT_SIZE;
5970 else if(fragment_size > MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE)
5971 fragment_size = MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE;
5972 ALOGV("%s: fragment_size %d", __func__, fragment_size);
5973 return fragment_size;
5974}
5975
Ashish Jainb26edfb2016-08-25 00:10:11 +05305976/*
5977 * return backend_idx on which voice call is active
5978 */
5979static int platform_get_voice_call_backend(struct audio_device* adev)
5980{
5981 struct audio_usecase *uc = NULL;
5982 struct listnode *node;
5983 snd_device_t out_snd_device = SND_DEVICE_NONE;
5984
5985 int backend_idx = -1;
5986
5987 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
5988 list_for_each(node, &adev->usecase_list) {
5989 uc = node_to_item(node, struct audio_usecase, list);
kunleiz83c0b4f2019-02-28 16:53:25 +08005990 if (uc && uc->stream.out &&
5991 (uc->type == VOICE_CALL ||
5992 uc->type == VOIP_CALL ||
5993 uc->id == USECASE_AUDIO_PLAYBACK_VOIP)) {
Ashish Jainb26edfb2016-08-25 00:10:11 +05305994 out_snd_device = platform_get_output_snd_device(adev->platform, uc->stream.out);
5995 backend_idx = platform_get_backend_index(out_snd_device);
5996 break;
5997 }
5998 }
5999 }
6000 return backend_idx;
6001}
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05306002
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05306003/*
6004 * configures afe with bit width and Sample Rate
6005 */
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05306006static int platform_set_codec_backend_cfg(struct audio_device* adev,
Ashish Jaind84fd6a2016-07-27 12:33:25 +05306007 snd_device_t snd_device, struct audio_backend_cfg backend_cfg)
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05306008{
Satish Babu Patakokilac3c5d432017-07-04 22:48:59 +05306009 int ret = -EINVAL;
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05306010 int backend_idx = DEFAULT_CODEC_BACKEND;
6011 struct platform_data *my_data = (struct platform_data *)adev->platform;
Ashish Jaind84fd6a2016-07-27 12:33:25 +05306012 unsigned int bit_width = backend_cfg.bit_width;
6013 unsigned int sample_rate = backend_cfg.sample_rate;
6014 unsigned int channels = backend_cfg.channels;
6015 audio_format_t format = backend_cfg.format;
6016 bool passthrough_enabled = backend_cfg.passthrough_enabled;
Satish Babu Patakokilac3c5d432017-07-04 22:48:59 +05306017 struct audio_device_config_param *adev_device_cfg_ptr = adev->device_cfg_params;
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05306018
6019 backend_idx = platform_get_backend_index(snd_device);
Ashish Jaind84fd6a2016-07-27 12:33:25 +05306020
Satish Babu Patakokilac3c5d432017-07-04 22:48:59 +05306021 /* Override the config params if client has already set them */
6022 adev_device_cfg_ptr += backend_idx;
6023 if (adev_device_cfg_ptr->use_client_dev_cfg) {
6024 ALOGV("%s::: Updating with the config set by client "
6025 "bitwidth %d, samplerate %d, channels %d format %d",
6026 __func__, adev_device_cfg_ptr->dev_cfg_params.bit_width,
6027 adev_device_cfg_ptr->dev_cfg_params.sample_rate,
6028 adev_device_cfg_ptr->dev_cfg_params.channels,
6029 adev_device_cfg_ptr->dev_cfg_params.format);
6030
6031 bit_width = adev_device_cfg_ptr->dev_cfg_params.bit_width;
6032 sample_rate = adev_device_cfg_ptr->dev_cfg_params.sample_rate;
6033 channels = adev_device_cfg_ptr->dev_cfg_params.channels;
6034 format = adev_device_cfg_ptr->dev_cfg_params.format;
6035 }
6036
6037 ALOGI("%s:becf: afe: bitwidth %d, samplerate %d channels %d format %d, backend_idx %d device (%s)",
6038 __func__, bit_width, sample_rate, channels, format, backend_idx,
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05306039 platform_get_snd_device_name(snd_device));
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05306040
Dhanalakshmi Siddanib678a802016-12-03 11:51:41 +05306041 if ((my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl) &&
6042 (bit_width != my_data->current_backend_cfg[backend_idx].bit_width)) {
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05306043
Kuirong Wang0b947f72016-09-29 11:03:09 -07006044 struct mixer_ctl *ctl = NULL;
Venkata Narendra Kumar Gutta4bd09d02016-01-29 15:31:04 +05306045 ctl = mixer_get_ctl_by_name(adev->mixer,
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05306046 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05306047 if (!ctl) {
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05306048 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
6049 __func__,
6050 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05306051 return -EINVAL;
6052 }
6053
6054 if (bit_width == 24) {
Ashish Jain5106d362016-05-11 19:23:33 +05306055 if (format == AUDIO_FORMAT_PCM_24_BIT_PACKED)
6056 mixer_ctl_set_enum_by_string(ctl, "S24_3LE");
6057 else
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05306058 mixer_ctl_set_enum_by_string(ctl, "S24_LE");
Kuirong Wanga9f7cee2016-03-07 11:21:52 -08006059 } else if (bit_width == 32) {
Ashish Jain058165c2016-09-28 23:18:48 +05306060 mixer_ctl_set_enum_by_string(ctl, "S32_LE");
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05306061 } else {
6062 mixer_ctl_set_enum_by_string(ctl, "S16_LE");
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05306063 }
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05306064 my_data->current_backend_cfg[backend_idx].bit_width = bit_width;
Ashish Jain5106d362016-05-11 19:23:33 +05306065 ALOGD("%s:becf: afe: %s mixer set to %d bit for %x format", __func__,
6066 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl,
6067 bit_width, format);
Satish Babu Patakokilac3c5d432017-07-04 22:48:59 +05306068 ret = 0;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05306069 }
6070
6071 /*
6072 * Backend sample rate configuration follows:
6073 * 16 bit playback - 48khz for streams at any valid sample rate
6074 * 24 bit playback - 48khz for stream sample rate less than 48khz
6075 * 24 bit playback - 96khz for sample rate range of 48khz to 96khz
6076 * 24 bit playback - 192khz for sample rate range of 96khz to 192 khz
6077 * Upper limit is inclusive in the sample rate range.
6078 */
6079 // TODO: This has to be more dynamic based on policy file
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05306080
Satish Babu Patakokilac3c5d432017-07-04 22:48:59 +05306081 if ((my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl) &&
6082 (((sample_rate != my_data->current_backend_cfg[(int)backend_idx].sample_rate) &&
Satya Krishna Pindiprolif5eddfd2016-12-28 11:29:08 +05306083 (my_data->hifi_audio ||
6084 backend_idx == USB_AUDIO_RX_BACKEND ||
Satish Babu Patakokilac3c5d432017-07-04 22:48:59 +05306085 backend_idx == USB_AUDIO_TX_BACKEND)) || passthrough_enabled)) {
Venkata Narendra Kumar Gutta4bd09d02016-01-29 15:31:04 +05306086 /*
6087 * sample rate update is needed only for hifi audio enabled platforms
6088 */
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05306089 char *rate_str = NULL;
Satya Krishna Pindiprolif5eddfd2016-12-28 11:29:08 +05306090 struct mixer_ctl *ctl = NULL;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05306091
Preetam Singh Ranawat63c02ea2017-08-10 11:53:30 +05306092 if (backend_idx == USB_AUDIO_RX_BACKEND ||
6093 backend_idx == USB_AUDIO_TX_BACKEND) {
6094 switch (sample_rate) {
6095 case 32000:
6096 rate_str = "KHZ_32";
6097 break;
6098 case 8000:
6099 rate_str = "KHZ_8";
6100 break;
6101 case 11025:
Sharad Sangle4cd17e32018-07-16 14:37:42 +05306102 rate_str = "KHZ_11P025";
Preetam Singh Ranawat63c02ea2017-08-10 11:53:30 +05306103 break;
6104 case 16000:
6105 rate_str = "KHZ_16";
6106 break;
6107 case 22050:
6108 rate_str = "KHZ_22P05";
6109 break;
6110 }
6111 }
6112
6113 if (rate_str == NULL) {
6114 switch (sample_rate) {
6115 case 32000:
Weiyin Jiang8f1d7f02019-09-04 16:45:45 +08006116 if (passthrough_enabled || (backend_idx == HDMI_TX_BACKEND) ||
6117 (backend_idx == DISP_PORT_RX_BACKEND)) {
Preetam Singh Ranawat63c02ea2017-08-10 11:53:30 +05306118 rate_str = "KHZ_32";
6119 break;
6120 }
6121 case 48000:
6122 rate_str = "KHZ_48";
6123 break;
6124 case 44100:
6125 rate_str = "KHZ_44P1";
6126 break;
6127 case 64000:
6128 case 96000:
6129 rate_str = "KHZ_96";
6130 break;
6131 case 88200:
6132 rate_str = "KHZ_88P2";
6133 break;
6134 case 176400:
6135 rate_str = "KHZ_176P4";
6136 break;
6137 case 192000:
6138 rate_str = "KHZ_192";
6139 break;
6140 case 352800:
6141 rate_str = "KHZ_352P8";
6142 break;
6143 case 384000:
6144 rate_str = "KHZ_384";
6145 break;
6146 case 144000:
6147 if (passthrough_enabled) {
6148 rate_str = "KHZ_144";
6149 break;
6150 }
6151 default:
6152 rate_str = "KHZ_48";
Satish Babu Patakokilaa395a9e2016-11-01 12:18:49 +05306153 break;
6154 }
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05306155 }
6156
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05306157 ctl = mixer_get_ctl_by_name(adev->mixer,
6158 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05306159
6160 if (!ctl) {
6161 ALOGE("%s:becf: afe: Could not get ctl to set the Sample Rate for mixer command - %s",
6162 __func__,
6163 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05306164 return -EINVAL;
6165 }
6166
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05306167 ALOGD("%s:becf: afe: %s set to %s", __func__,
6168 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl,
6169 rate_str);
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05306170 mixer_ctl_set_enum_by_string(ctl, rate_str);
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05306171 my_data->current_backend_cfg[backend_idx].sample_rate = sample_rate;
Satish Babu Patakokilac3c5d432017-07-04 22:48:59 +05306172 ret = 0;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05306173 }
Ashish Jainb26edfb2016-08-25 00:10:11 +05306174 if ((my_data->current_backend_cfg[backend_idx].channels_mixer_ctl) &&
Ashish Jaind84fd6a2016-07-27 12:33:25 +05306175 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
Satya Krishna Pindiprolif5eddfd2016-12-28 11:29:08 +05306176 struct mixer_ctl *ctl = NULL;
Ashish Jaind84fd6a2016-07-27 12:33:25 +05306177 char *channel_cnt_str = NULL;
6178
6179 switch (channels) {
6180 case 8:
6181 channel_cnt_str = "Eight"; break;
6182 case 7:
6183 channel_cnt_str = "Seven"; break;
6184 case 6:
6185 channel_cnt_str = "Six"; break;
6186 case 5:
6187 channel_cnt_str = "Five"; break;
6188 case 4:
6189 channel_cnt_str = "Four"; break;
6190 case 3:
6191 channel_cnt_str = "Three"; break;
Kuirong Wang0b947f72016-09-29 11:03:09 -07006192 case 1:
6193 channel_cnt_str = "One"; break;
6194 case 2:
Ashish Jaind84fd6a2016-07-27 12:33:25 +05306195 default:
6196 channel_cnt_str = "Two"; break;
6197 }
6198
6199 ctl = mixer_get_ctl_by_name(adev->mixer,
6200 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
6201 if (!ctl) {
6202 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
6203 __func__,
6204 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
6205 return -EINVAL;
6206 }
6207 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
6208 my_data->current_backend_cfg[backend_idx].channels = channels;
Ashish Jainb26edfb2016-08-25 00:10:11 +05306209
6210 if (backend_idx == HDMI_RX_BACKEND)
Rohit kumar4dbd2c02019-02-04 16:26:33 +05306211 platform_set_edid_channels_configuration(adev->platform, channels, HDMI_RX_BACKEND, snd_device);
Ashish Jainb26edfb2016-08-25 00:10:11 +05306212
Ashish Jaind84fd6a2016-07-27 12:33:25 +05306213 ALOGD("%s:becf: afe: %s set to %s", __func__,
6214 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl, channel_cnt_str);
Satish Babu Patakokilac3c5d432017-07-04 22:48:59 +05306215 ret = 0;
Ashish Jaind84fd6a2016-07-27 12:33:25 +05306216 }
6217
Siddartha Shaik44dd7702017-06-14 12:13:25 +05306218 bool set_ext_disp_format = false, set_mi2s_tx_data_format = false;
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07006219 char *ext_disp_format = NULL;
Ashish Jaind84fd6a2016-07-27 12:33:25 +05306220
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07006221 if (backend_idx == HDMI_RX_BACKEND) {
6222 ext_disp_format = "HDMI RX Format";
6223 set_ext_disp_format = true;
6224 } else if (backend_idx == DISP_PORT_RX_BACKEND) {
Garmond Leungade0f6d2017-02-03 15:56:10 -08006225 ext_disp_format = "Display Port RX Format";
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07006226 set_ext_disp_format = true;
Siddartha Shaik44dd7702017-06-14 12:13:25 +05306227 } else if (backend_idx == HDMI_TX_BACKEND) {
6228 ext_disp_format = "QUAT MI2S TX Format";
6229 set_mi2s_tx_data_format = true;
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07006230 } else {
6231 ALOGV("%s: Format doesnt have to be set", __func__);
6232 }
6233
Siddartha Shaik44dd7702017-06-14 12:13:25 +05306234 /* Set data format only if there is a change from PCM to compressed
6235 and vice versa */
6236 if (set_mi2s_tx_data_format && (format ^ my_data->current_backend_cfg[backend_idx].format)) {
6237 struct mixer_ctl *ctl = mixer_get_ctl_by_name(adev->mixer, ext_disp_format);
6238 if (!ctl) {
6239 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
6240 __func__, ext_disp_format);
6241 return -EINVAL;
6242 }
Arun Mirpuri3b5fcfb2019-04-11 16:44:06 -07006243 if ((format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_PCM) {
Siddartha Shaik44dd7702017-06-14 12:13:25 +05306244 ALOGE("%s:MI2S data format LPCM", __func__);
6245 mixer_ctl_set_enum_by_string(ctl, "LPCM");
6246 } else {
6247 ALOGE("%s:MI2S data format Compr", __func__);
6248 mixer_ctl_set_enum_by_string(ctl, "Compr");
6249 }
6250 my_data->current_backend_cfg[backend_idx].format = format;
6251 }
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07006252 if (set_ext_disp_format) {
6253 struct mixer_ctl *ctl = mixer_get_ctl_by_name(adev->mixer, ext_disp_format);
Ashish Jaind84fd6a2016-07-27 12:33:25 +05306254 if (!ctl) {
6255 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07006256 __func__, ext_disp_format);
Ashish Jaind84fd6a2016-07-27 12:33:25 +05306257 return -EINVAL;
6258 }
6259
6260 if (passthrough_enabled) {
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07006261 ALOGD("%s:Ext display compress format", __func__);
Ashish Jaind84fd6a2016-07-27 12:33:25 +05306262 mixer_ctl_set_enum_by_string(ctl, "Compr");
6263 } else {
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07006264 ALOGD("%s: Ext display PCM format", __func__);
Ashish Jaind84fd6a2016-07-27 12:33:25 +05306265 mixer_ctl_set_enum_by_string(ctl, "LPCM");
6266 }
Satish Babu Patakokilac3c5d432017-07-04 22:48:59 +05306267 ret = 0;
Ashish Jaind84fd6a2016-07-27 12:33:25 +05306268 }
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05306269 return ret;
6270}
6271
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05306272/*
Satish Babu Patakokila5933e972017-08-24 12:22:08 +05306273 * Get the backend configuration for current snd device
6274 */
6275int platform_get_codec_backend_cfg(struct audio_device* adev,
6276 snd_device_t snd_device,
6277 struct audio_backend_cfg *backend_cfg)
6278{
6279 int backend_idx = platform_get_backend_index(snd_device);
6280 struct platform_data *my_data = (struct platform_data *)adev->platform;
6281
6282 backend_cfg->bit_width = my_data->current_backend_cfg[backend_idx].bit_width;
6283 backend_cfg->sample_rate =
6284 my_data->current_backend_cfg[backend_idx].sample_rate;
6285 backend_cfg->channels =
6286 my_data->current_backend_cfg[backend_idx].channels;
6287 backend_cfg->format =
6288 my_data->current_backend_cfg[backend_idx].format;
6289
6290 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d format %d"
6291 ", backend_idx %d device (%s)", __func__, backend_cfg->bit_width,
6292 backend_cfg->sample_rate, backend_cfg->channels, backend_cfg->format,
6293 backend_idx, platform_get_snd_device_name(snd_device));
6294
6295 return 0;
6296}
6297
6298
6299/*
Ashish Jaind84fd6a2016-07-27 12:33:25 +05306300 *Validate the selected bit_width, sample_rate and channels using the edid
6301 *of the connected sink device.
6302 */
6303static void platform_check_hdmi_backend_cfg(struct audio_device* adev,
6304 struct audio_usecase* usecase,
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07006305 int backend_idx,
Ashish Jaind84fd6a2016-07-27 12:33:25 +05306306 struct audio_backend_cfg *hdmi_backend_cfg)
6307{
6308 unsigned int bit_width;
6309 unsigned int sample_rate;
Manish Dewangan37864bc2017-06-09 12:28:37 +05306310 int channels, max_supported_channels = 0;
Ashish Jaind84fd6a2016-07-27 12:33:25 +05306311 struct platform_data *my_data = (struct platform_data *)adev->platform;
6312 edid_audio_info *edid_info = (edid_audio_info *)my_data->edid_info;
6313 bool passthrough_enabled = false;
6314
6315 bit_width = hdmi_backend_cfg->bit_width;
6316 sample_rate = hdmi_backend_cfg->sample_rate;
6317 channels = hdmi_backend_cfg->channels;
6318
6319
6320 ALOGI("%s:becf: HDMI: bitwidth %d, samplerate %d, channels %d"
6321 ", usecase = %d", __func__, bit_width,
6322 sample_rate, channels, usecase->id);
6323
6324 if (audio_extn_passthru_is_enabled() && audio_extn_passthru_is_active()
6325 && (usecase->stream.out->compr_config.codec->compr_passthr != 0)) {
6326 passthrough_enabled = true;
6327 ALOGI("passthrough is enabled for this stream");
6328 }
6329
6330 // For voice calls use default configuration i.e. 16b/48K, only applicable to
6331 // default backend
6332 if (!passthrough_enabled) {
6333
6334 max_supported_channels = platform_edid_get_max_channels(my_data);
6335
6336 //Check EDID info for supported samplerate
Arun Mirpurib1bec9c2019-01-29 16:42:45 -08006337 if (!audio_extn_edid_is_supported_sr(edid_info,sample_rate)) {
Garmond Leung2f78a672016-11-07 16:27:40 -08006338 //check to see if current BE sample rate is supported by EDID
6339 //else assign the highest sample rate supported by EDID
Arun Mirpurib1bec9c2019-01-29 16:42:45 -08006340 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 -08006341 sample_rate = my_data->current_backend_cfg[backend_idx].sample_rate;
6342 else
Arun Mirpurib1bec9c2019-01-29 16:42:45 -08006343 sample_rate = audio_extn_edid_get_highest_supported_sr(edid_info);
Ashish Jaind84fd6a2016-07-27 12:33:25 +05306344 }
6345
6346 //Check EDID info for supported bit width
Arun Mirpurib1bec9c2019-01-29 16:42:45 -08006347 if (!audio_extn_edid_is_supported_bps(edid_info,bit_width)) {
Ashish Jaind84fd6a2016-07-27 12:33:25 +05306348 //reset to current sample rate
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07006349 bit_width = my_data->current_backend_cfg[backend_idx].bit_width;
Ashish Jaind84fd6a2016-07-27 12:33:25 +05306350 }
6351
6352 if (channels > max_supported_channels)
6353 channels = max_supported_channels;
6354
6355 } else {
Manish Dewangan37864bc2017-06-09 12:28:37 +05306356 channels = audio_extn_passthru_get_channel_count(usecase->stream.out);
6357 if (channels <= 0) {
6358 ALOGE("%s: becf: afe: HDMI backend using defalut channel %u",
6359 __func__, DEFAULT_HDMI_OUT_CHANNELS);
Ben Romberger1aaaf862017-04-06 17:49:46 -07006360 channels = DEFAULT_HDMI_OUT_CHANNELS;
Manish Dewangan37864bc2017-06-09 12:28:37 +05306361 }
Harsh Bansal026d97f2017-08-17 17:44:49 +05306362 if (((usecase->stream.out->format == AUDIO_FORMAT_E_AC3) ||
Ben Romberger1aaaf862017-04-06 17:49:46 -07006363 (usecase->stream.out->format == AUDIO_FORMAT_E_AC3_JOC) ||
Harsh Bansal026d97f2017-08-17 17:44:49 +05306364 (usecase->stream.out->format == AUDIO_FORMAT_DOLBY_TRUEHD))
6365 && (usecase->stream.out->compr_config.codec->compr_passthr == PASSTHROUGH)) {
6366 sample_rate = sample_rate * 4;
Naresh Tanniru3a406772017-05-10 13:09:05 -07006367 if (sample_rate > HDMI_PASSTHROUGH_MAX_SAMPLE_RATE)
6368 sample_rate = HDMI_PASSTHROUGH_MAX_SAMPLE_RATE;
6369 }
Ben Romberger1aaaf862017-04-06 17:49:46 -07006370
Ashish Jaind84fd6a2016-07-27 12:33:25 +05306371 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
6372 /* We force route so that the BE format can be set to Compr */
6373 }
6374
6375 ALOGI("%s:becf: afe: HDMI backend: passthrough %d updated bit width: %d and sample rate: %d"
6376 "channels %d", __func__, passthrough_enabled , bit_width,
6377 sample_rate, channels);
6378
6379 hdmi_backend_cfg->bit_width = bit_width;
6380 hdmi_backend_cfg->sample_rate = sample_rate;
6381 hdmi_backend_cfg->channels = channels;
6382 hdmi_backend_cfg->passthrough_enabled = passthrough_enabled;
6383}
6384
6385/*
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05306386 * goes through all the current usecases and picks the highest
6387 * bitwidth & samplerate
6388 */
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05306389static bool platform_check_codec_backend_cfg(struct audio_device* adev,
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05306390 struct audio_usecase* usecase,
6391 snd_device_t snd_device,
Ashish Jaind84fd6a2016-07-27 12:33:25 +05306392 struct audio_backend_cfg *backend_cfg)
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05306393{
6394 bool backend_change = false;
6395 struct listnode *node;
6396 struct stream_out *out = NULL;
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05306397 char value[PROPERTY_VALUE_MAX] = {0};
6398 unsigned int bit_width;
6399 unsigned int sample_rate;
Ashish Jaind84fd6a2016-07-27 12:33:25 +05306400 unsigned int channels;
6401 bool passthrough_enabled = false;
Ashish Jain8c930292017-03-13 16:33:12 +05306402 bool voice_call_active = false;
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05306403 int backend_idx = DEFAULT_CODEC_BACKEND;
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05306404 struct platform_data *my_data = (struct platform_data *)adev->platform;
Preetam Singh Ranawat3e5b9e72016-11-10 16:12:25 +05306405 int na_mode = platform_get_native_support();
Ashish Jaind84fd6a2016-07-27 12:33:25 +05306406 bool channels_updated = false;
Satish Babu Patakokilac3c5d432017-07-04 22:48:59 +05306407 struct audio_device_config_param *adev_device_cfg_ptr = adev->device_cfg_params;
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05306408
Ashish Jainc597d102016-12-12 10:31:34 +05306409 /*BT devices backend is not configured from HAL hence skip*/
6410 if (snd_device == SND_DEVICE_OUT_BT_A2DP ||
6411 snd_device == SND_DEVICE_OUT_BT_SCO ||
Sachin Mohan Gadag2e4dcb12017-05-12 13:05:08 +05306412 snd_device == SND_DEVICE_OUT_BT_SCO_WB ||
6413 snd_device == SND_DEVICE_OUT_AFE_PROXY) {
Ashish Jainc597d102016-12-12 10:31:34 +05306414 backend_change = false;
6415 return backend_change;
6416 }
6417
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05306418 backend_idx = platform_get_backend_index(snd_device);
6419
Ashish Jaind84fd6a2016-07-27 12:33:25 +05306420 bit_width = backend_cfg->bit_width;
6421 sample_rate = backend_cfg->sample_rate;
6422 channels = backend_cfg->channels;
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05306423
Satya Krishna Pindiprolif5eddfd2016-12-28 11:29:08 +05306424 ALOGI("%s:becf: afe: Codec selected backend: %d current bit width: %d sample rate: %d channels: %d "
6425 "usecase %d device (%s)", __func__, backend_idx, bit_width, sample_rate, channels,
6426 usecase->id, platform_get_snd_device_name(snd_device));
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05306427
Apoorv Raghuvanshi924b3022015-07-06 15:07:14 -07006428 // For voice calls use default configuration i.e. 16b/48K, only applicable to
6429 // default backend
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05306430 // force routing is not required here, caller will do it anyway
Ashish Jainb26edfb2016-08-25 00:10:11 +05306431 if (backend_idx == platform_get_voice_call_backend(adev)) {
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05306432 ALOGW("%s:becf: afe:Use default bw and sr for voice/voip calls ",
6433 __func__);
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05306434 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
6435 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
Preetam Singh Ranawat3e5b9e72016-11-10 16:12:25 +05306436 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
Ashish Jain8c930292017-03-13 16:33:12 +05306437 voice_call_active = true;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05306438 } else {
6439 /*
6440 * The backend should be configured at highest bit width and/or
6441 * sample rate amongst all playback usecases.
6442 * If the selected sample rate and/or bit width differ with
6443 * current backend sample rate and/or bit width, then, we set the
6444 * backend re-configuration flag.
6445 *
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05306446 * Exception: 16 bit playbacks is allowed through 16 bit/48/44.1 khz backend only
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05306447 */
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05306448 int i =0;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05306449 list_for_each(node, &adev->usecase_list) {
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05306450 struct audio_usecase *uc;
6451 uc = node_to_item(node, struct audio_usecase, list);
6452 struct stream_out *out = (struct stream_out*) uc->stream.out;
6453 if (uc->type == PCM_PLAYBACK && out && usecase != uc) {
Preetam Singh Ranawataa37d3f2016-08-23 12:25:23 +05306454 unsigned int out_channels = audio_channel_count_from_out_mask(out->channel_mask);
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05306455
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05306456 ALOGD("%s:napb: (%d) - (%s)id (%d) sr %d bw "
Ashish Jaind84fd6a2016-07-27 12:33:25 +05306457 "(%d) ch (%d) device %s", __func__, i++, use_case_table[uc->id],
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05306458 uc->id, out->sample_rate,
Ashish Jaind84fd6a2016-07-27 12:33:25 +05306459 out->bit_width, out_channels,
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05306460 platform_get_snd_device_name(uc->out_snd_device));
6461
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05306462 if (platform_check_backends_match(snd_device, uc->out_snd_device)) {
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05306463 if (bit_width < out->bit_width)
6464 bit_width = out->bit_width;
6465 if (sample_rate < out->sample_rate)
6466 sample_rate = out->sample_rate;
Revathi Uddaraju869ae492018-02-09 16:27:35 +05306467 /*
6468 * TODO: Add Support for Backend configuration for devices which support
6469 * sample rate less than 44.1
6470 */
6471 if (sample_rate < OUTPUT_SAMPLING_RATE_44100)
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05306472 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
Ashish Jaind84fd6a2016-07-27 12:33:25 +05306473 if (channels < out_channels)
6474 channels = out_channels;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05306475 }
6476 }
6477 }
6478 }
6479
Ashish Jainb26edfb2016-08-25 00:10:11 +05306480 /* Native playback is preferred for Headphone/HS device over 192Khz */
Ashish Jain8c930292017-03-13 16:33:12 +05306481 if (!voice_call_active && codec_device_supports_native_playback(usecase->devices)) {
Ashish Jainb26edfb2016-08-25 00:10:11 +05306482 if (audio_is_true_native_stream_active(adev)) {
6483 if (check_hdset_combo_device(snd_device)) {
6484 /*
6485 * In true native mode Tasha has a limitation that one port at 44.1 khz
6486 * cannot drive both spkr and hdset, to simiplify the solution lets
6487 * move the AFE to 48khzwhen a ring tone selects combo device.
6488 * or if NATIVE playback is not enabled.
6489 */
6490 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
6491 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
Ashish Jain8c930292017-03-13 16:33:12 +05306492 ALOGD("%s:becf: afe: port to run at 48k if combo device or in voice call"
6493 , __func__);
Ashish Jainb26edfb2016-08-25 00:10:11 +05306494 } else {
6495 /*
6496 * in single BE mode, if native audio playback
6497 * is active then it will take priority
6498 */
6499 sample_rate = OUTPUT_SAMPLING_RATE_44100;
6500 ALOGD("%s:becf: afe: true napb active set rate to 44.1 khz",
6501 __func__);
6502 }
Preetam Singh Ranawatb1c73232019-04-22 13:59:51 +05306503 } else if (na_mode != NATIVE_AUDIO_MODE_MULTIPLE_MIX_IN_CODEC) {
Preetam Singh Ranawat3e5b9e72016-11-10 16:12:25 +05306504 /*
6505 * Map native sampling rates to upper limit range
6506 * if multiple of native sampling rates are not supported.
6507 * This check also indicates that this is not tavil codec
6508 * And 32bit/384kHz is only supported on tavil
6509 * Hence reset 32b/384kHz to 24b/192kHz.
6510 */
6511 switch (sample_rate) {
6512 case 44100:
6513 sample_rate = 48000;
6514 break;
6515 case 88200:
6516 sample_rate = 96000;
6517 break;
6518 case 176400:
6519 case 352800:
6520 case 384000:
6521 sample_rate = 192000;
6522 break;
6523 }
6524 if (bit_width > 24)
6525 bit_width = 24;
6526
6527 ALOGD("%s:becf: afe: napb not active - set non fractional rate",
Ashish Jainb26edfb2016-08-25 00:10:11 +05306528 __func__);
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05306529 }
kunleiz6ba62d12018-06-20 13:55:46 +08006530 /*ensure AFE set to 48khz when sample rate less than 44.1khz*/
6531 if (sample_rate < OUTPUT_SAMPLING_RATE_44100) {
6532 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
6533 ALOGD("%s:becf: afe: napb set sample rate to default Sample Rate(48k)",__func__);
6534 }
Ashish Jain6fced6e2017-01-09 14:13:22 +05306535 }
6536
6537 /*
kunleiz0a99fcf2018-06-14 16:41:21 +08006538 * Handset and speaker may have diffrent backend. Check if the device is speaker or handset,
6539 * and these devices are restricited to 48kHz.
Ashish Jain6fced6e2017-01-09 14:13:22 +05306540 */
kunleiz5c3fb9a2019-02-20 17:18:19 +08006541 if (!codec_device_supports_native_playback(usecase->devices) &&
kunleiz0a99fcf2018-06-14 16:41:21 +08006542 (platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, snd_device) ||
6543 platform_check_backends_match(SND_DEVICE_OUT_HANDSET, snd_device))) {
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05306544 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
Ashish Jain058165c2016-09-28 23:18:48 +05306545
6546 if (bit_width >= 24) {
6547 bit_width = platform_get_snd_device_bit_width(SND_DEVICE_OUT_SPEAKER);
6548 ALOGD("%s:becf: afe: reset bitwidth to %d (based on supported"
6549 " value for this platform)", __func__, bit_width);
6550 }
6551
Ashish Jainb26edfb2016-08-25 00:10:11 +05306552 ALOGD("%s:becf: afe: playback on codec device not supporting native playback set "
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05306553 "default Sample Rate(48k)", __func__);
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05306554 }
6555
6556 /*
Venkata Narendra Kumar Gutta4bd09d02016-01-29 15:31:04 +05306557 * reset the sample rate to default value(48K), if hifi audio is not supported
Ashish Jainb449be32015-07-19 05:39:23 -07006558 */
Ashish Jainb26edfb2016-08-25 00:10:11 +05306559 if (!my_data->hifi_audio && (usecase->devices & AUDIO_DEVICE_OUT_ALL_CODEC_BACKEND)) {
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05306560 ALOGD("%s:becf: afe: only 48KHZ sample rate is supported "
6561 "Configure afe to default Sample Rate(48k)", __func__);
Venkata Narendra Kumar Gutta4bd09d02016-01-29 15:31:04 +05306562 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05306563 }
Ashish Jainb449be32015-07-19 05:39:23 -07006564
Ashish Jain797a4722017-03-15 10:21:12 +05306565 if ((backend_idx == HDMI_RX_BACKEND) || (backend_idx == DISP_PORT_RX_BACKEND)) {
Ashish Jaind84fd6a2016-07-27 12:33:25 +05306566 struct audio_backend_cfg hdmi_backend_cfg;
6567 hdmi_backend_cfg.bit_width = bit_width;
6568 hdmi_backend_cfg.sample_rate = sample_rate;
6569 hdmi_backend_cfg.channels = channels;
6570 hdmi_backend_cfg.passthrough_enabled = false;
6571
Ashish Jain058165c2016-09-28 23:18:48 +05306572 /*HDMI does not support 384Khz/32bit playback hence configure BE to 24b/192Khz*/
6573 /* TODO: Instead have the validation against edid return the next best match*/
6574 if (bit_width > 24)
6575 hdmi_backend_cfg.bit_width = 24;
6576 if (sample_rate > 192000)
6577 hdmi_backend_cfg.sample_rate = 192000;
6578
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07006579 platform_check_hdmi_backend_cfg(adev, usecase, backend_idx, &hdmi_backend_cfg);
Ashish Jaind84fd6a2016-07-27 12:33:25 +05306580
6581 bit_width = hdmi_backend_cfg.bit_width;
6582 sample_rate = hdmi_backend_cfg.sample_rate;
6583 channels = hdmi_backend_cfg.channels;
6584 passthrough_enabled = hdmi_backend_cfg.passthrough_enabled;
6585
6586 if (channels != my_data->current_backend_cfg[backend_idx].channels)
6587 channels_updated = true;
Rohit kumar4dbd2c02019-02-04 16:26:33 +05306588
6589 platform_set_edid_channels_configuration(adev->platform, channels, backend_idx, snd_device);
Mingming Yinddd610b2016-01-20 17:09:32 -08006590 }
6591
Manish Dewangan837dc462015-05-27 10:17:41 +05306592 //check if mulitchannel clip needs to be down sampled to 48k
Aniket Kumar Lata8fc67e62017-05-02 12:33:46 -07006593 property_get("vendor.audio.playback.mch.downsample",value,"");
Manish Dewangan837dc462015-05-27 10:17:41 +05306594 if (!strncmp("true", value, sizeof("true"))) {
6595 out = usecase->stream.out;
6596 if ((popcount(out->channel_mask) > 2) &&
6597 (out->sample_rate > CODEC_BACKEND_DEFAULT_SAMPLE_RATE) &&
6598 !(out->flags & AUDIO_OUTPUT_FLAG_COMPRESS_PASSTHROUGH)) {
6599 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
6600 /* update out sample rate to reflect current backend sample rate */
6601 out->sample_rate = sample_rate;
6602 ALOGD("%s: MCH session defaulting sample rate to %d",
6603 __func__, sample_rate);
6604 }
6605 }
6606
Kuirong Wanga9f7cee2016-03-07 11:21:52 -08006607 if (backend_idx == USB_AUDIO_RX_BACKEND) {
Kuirong Wange9894162016-08-26 15:16:39 -07006608 audio_extn_usb_is_config_supported(&bit_width, &sample_rate, &channels, true);
Kuirong Wanga9f7cee2016-03-07 11:21:52 -08006609 ALOGV("%s: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
6610 __func__, bit_width, sample_rate, channels);
Ashish Jainb26edfb2016-08-25 00:10:11 +05306611 if (channels != my_data->current_backend_cfg[backend_idx].channels)
6612 channels_updated = true;
Kuirong Wanga9f7cee2016-03-07 11:21:52 -08006613 }
6614
Satya Krishna Pindiprolif5eddfd2016-12-28 11:29:08 +05306615 ALOGI("%s:becf: afe: Codec selected backend: %d updated bit width: %d "
6616 "sample rate: %d channels: %d", __func__, backend_idx,
6617 bit_width, sample_rate, channels);
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05306618 // Force routing if the expected bitwdith or samplerate
6619 // is not same as current backend comfiguration
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05306620 if ((bit_width != my_data->current_backend_cfg[backend_idx].bit_width) ||
Ashish Jaind84fd6a2016-07-27 12:33:25 +05306621 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate) ||
6622 passthrough_enabled || channels_updated) {
6623 backend_cfg->bit_width = bit_width;
6624 backend_cfg->sample_rate = sample_rate;
6625 backend_cfg->channels = channels;
6626 backend_cfg->passthrough_enabled = passthrough_enabled;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05306627 backend_change = true;
Ashish Jaind84fd6a2016-07-27 12:33:25 +05306628 ALOGI("%s:becf: afe: Codec backend needs to be updated. new bit width: %d"
6629 " new sample rate: %d new channels %d",__func__,
6630 backend_cfg->bit_width, backend_cfg->sample_rate, backend_cfg->channels);
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05306631 }
6632
Satish Babu Patakokilac3c5d432017-07-04 22:48:59 +05306633 // Force routing if the client sends config params for this backend
6634 adev_device_cfg_ptr += backend_idx;
6635 if (adev_device_cfg_ptr->use_client_dev_cfg) {
6636 ALOGV("%s: Codec backend needs to be updated as Client provided "
6637 "config params", __func__);
6638 backend_change = true;
6639 }
6640
Preetam Singh Ranawatdc1a3952016-11-24 17:35:51 +05306641 if (snd_device == SND_DEVICE_OUT_HEADPHONES || snd_device ==
6642 SND_DEVICE_OUT_HEADPHONES_44_1) {
6643 if (sample_rate > 48000 ||
6644 (bit_width >= 24 && (sample_rate == 48000 || sample_rate == 44100))) {
6645 ALOGV("%s: apply HPH HQ mode\n", __func__);
6646 audio_route_apply_and_update_path(adev->audio_route, "hph-highquality-mode");
6647 } else {
6648 ALOGV("%s: apply HPH LP mode\n", __func__);
6649 audio_route_apply_and_update_path(adev->audio_route, "hph-lowpower-mode");
6650 }
6651 }
6652
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05306653 return backend_change;
6654}
6655
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08006656bool platform_check_and_set_codec_backend_cfg(struct audio_device* adev,
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05306657 struct audio_usecase *usecase, snd_device_t snd_device)
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05306658{
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05306659 int backend_idx = DEFAULT_CODEC_BACKEND;
Siena Richard7c2db772016-12-21 11:32:34 -08006660 int new_snd_devices[SND_DEVICE_OUT_END] = {0};
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05306661 int i, num_devices = 1;
Ashish Jaind84fd6a2016-07-27 12:33:25 +05306662 struct audio_backend_cfg backend_cfg;
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05306663 bool ret = false;
Surendar Karka45850ae2018-07-02 17:45:27 +05306664 struct platform_data *my_data = (struct platform_data *)adev->platform;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05306665
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05306666 backend_idx = platform_get_backend_index(snd_device);
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05306667
Surendar Karka93cd25a2018-08-28 14:21:37 +05306668 if (usecase->type == TRANSCODE_LOOPBACK_RX) {
Siddartha Shaik31b530e2017-05-19 15:26:33 +05306669 backend_cfg.bit_width = usecase->stream.inout->out_config.bit_width;
6670 backend_cfg.sample_rate = usecase->stream.inout->out_config.sample_rate;
6671 backend_cfg.format = usecase->stream.inout->out_config.format;
6672 backend_cfg.channels = audio_channel_count_from_out_mask(
6673 usecase->stream.inout->out_config.channel_mask);
6674 } else {
6675 backend_cfg.bit_width = usecase->stream.out->bit_width;
6676 backend_cfg.sample_rate = usecase->stream.out->sample_rate;
6677 backend_cfg.format = usecase->stream.out->format;
6678 backend_cfg.channels = audio_channel_count_from_out_mask(usecase->stream.out->channel_mask);
6679 }
Xiaojun Sang785b5da2017-08-03 15:52:29 +08006680 /* enforce AFE bitwidth mode via backend_cfg */
6681 if (audio_extn_is_dsp_bit_width_enforce_mode_supported(usecase->stream.out->flags) &&
6682 (adev->dsp_bit_width_enforce_mode > backend_cfg.bit_width))
6683 backend_cfg.bit_width = adev->dsp_bit_width_enforce_mode;
Siddartha Shaik31b530e2017-05-19 15:26:33 +05306684
Ashish Jaind84fd6a2016-07-27 12:33:25 +05306685 /*this is populated by check_codec_backend_cfg hence set default value to false*/
6686 backend_cfg.passthrough_enabled = false;
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05306687
Preetam Singh Ranawat3e5b9e72016-11-10 16:12:25 +05306688 /* Set Backend sampling rate to 176.4 for DSD64 and
6689 * 352.8Khz for DSD128.
6690 * Set Bit Width to 16
6691 */
6692 if ((backend_idx == DSD_NATIVE_BACKEND) && (backend_cfg.format == AUDIO_FORMAT_DSD)) {
6693 backend_cfg.bit_width = 16;
6694 if (backend_cfg.sample_rate == INPUT_SAMPLING_RATE_DSD64)
6695 backend_cfg.sample_rate = OUTPUT_SAMPLING_RATE_DSD64;
6696 else if (backend_cfg.sample_rate == INPUT_SAMPLING_RATE_DSD128)
6697 backend_cfg.sample_rate = OUTPUT_SAMPLING_RATE_DSD128;
6698 }
Ashish Jaind84fd6a2016-07-27 12:33:25 +05306699 ALOGI("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
6700 ", backend_idx %d usecase = %d device (%s)", __func__, backend_cfg.bit_width,
6701 backend_cfg.sample_rate, backend_cfg.channels, backend_idx, usecase->id,
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05306702 platform_get_snd_device_name(snd_device));
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05306703
Surendar Karka45850ae2018-07-02 17:45:27 +05306704 if ((my_data->spkr_ch_map != NULL) &&
6705 (platform_get_backend_index(snd_device) == DEFAULT_CODEC_BACKEND))
6706 platform_set_channel_map(my_data, my_data->spkr_ch_map->num_ch,
Rohit kumar4dbd2c02019-02-04 16:26:33 +05306707 my_data->spkr_ch_map->chmap, -1, -1);
Surendar Karka45850ae2018-07-02 17:45:27 +05306708
Haynes Mathew Georgebfe8ff42016-09-22 17:38:16 -07006709 if (platform_split_snd_device(adev->platform, snd_device,
6710 &num_devices, new_snd_devices) < 0)
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05306711 new_snd_devices[0] = snd_device;
6712
6713 for (i = 0; i < num_devices; i++) {
6714 ALOGI("%s: becf: new_snd_devices[%d] is %s", __func__, i,
6715 platform_get_snd_device_name(new_snd_devices[i]));
6716 if (platform_check_codec_backend_cfg(adev, usecase, new_snd_devices[i],
Ashish Jaind84fd6a2016-07-27 12:33:25 +05306717 &backend_cfg)) {
Satish Babu Patakokilac3c5d432017-07-04 22:48:59 +05306718 ret = platform_set_codec_backend_cfg(adev, new_snd_devices[i],
Ashish Jaind84fd6a2016-07-27 12:33:25 +05306719 backend_cfg);
Satish Babu Patakokilac3c5d432017-07-04 22:48:59 +05306720 if (!ret) {
6721 ret = true;
6722 } else {
6723 ret = false;
6724 }
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05306725 }
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05306726 }
6727
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05306728 return ret;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05306729}
6730
Manish Dewanganba9fcfa2016-03-24 16:20:06 +05306731/*
Manish Dewanganba9fcfa2016-03-24 16:20:06 +05306732 * goes through all the current usecases and picks the highest
6733 * bitwidth & samplerate
6734 */
Kuirong Wange9894162016-08-26 15:16:39 -07006735static bool platform_check_capture_codec_backend_cfg(struct audio_device* adev,
6736 int backend_idx,
6737 struct audio_backend_cfg *backend_cfg)
Manish Dewanganba9fcfa2016-03-24 16:20:06 +05306738{
6739 bool backend_change = false;
6740 unsigned int bit_width;
6741 unsigned int sample_rate;
Kuirong Wange9894162016-08-26 15:16:39 -07006742 unsigned int channels;
Siddartha Shaik44dd7702017-06-14 12:13:25 +05306743 unsigned int format;
Manish Dewanganba9fcfa2016-03-24 16:20:06 +05306744 struct platform_data *my_data = (struct platform_data *)adev->platform;
6745
Kuirong Wange9894162016-08-26 15:16:39 -07006746 bit_width = backend_cfg->bit_width;
6747 sample_rate = backend_cfg->sample_rate;
6748 channels = backend_cfg->channels;
Siddartha Shaik44dd7702017-06-14 12:13:25 +05306749 format = backend_cfg->format;
Manish Dewanganba9fcfa2016-03-24 16:20:06 +05306750
6751 ALOGI("%s:txbecf: afe: Codec selected backend: %d current bit width: %d and "
Siddartha Shaik44dd7702017-06-14 12:13:25 +05306752 "sample rate: %d, channels %d format %d",__func__,backend_idx, bit_width,
6753 sample_rate, channels,format);
Manish Dewanganba9fcfa2016-03-24 16:20:06 +05306754
6755 // For voice calls use default configuration i.e. 16b/48K, only applicable to
6756 // default backend
6757 // force routing is not required here, caller will do it anyway
6758 if ((voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) ||
6759 (!is_external_codec)) {
6760 ALOGW("%s:txbecf: afe:Use default bw and sr for voice/voip calls",
6761 __func__);
6762 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
6763 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
Dhananjay Kumar9983c372016-12-09 22:00:40 +05306764 channels = CODEC_BACKEND_DEFAULT_TX_CHANNELS;
6765 } else {
6766 struct listnode *node;
6767 struct audio_usecase *uc = NULL;
6768 unsigned int uc_channels = 0;
6769 struct stream_in *in = NULL;
6770 /* update cfg against other existing capture usecases on same backend */
6771 list_for_each(node, &adev->usecase_list) {
6772 uc = node_to_item(node, struct audio_usecase, list);
Satya Krishna Pindiproli9f566672017-02-28 11:14:01 +05306773 in = (struct stream_in *) uc->stream.in;
6774 if (in != NULL && uc->type == PCM_CAPTURE &&
Dhananjay Kumar9983c372016-12-09 22:00:40 +05306775 backend_idx == platform_get_backend_index(uc->in_snd_device)) {
Dhananjay Kumar9983c372016-12-09 22:00:40 +05306776 uc_channels = audio_channel_count_from_in_mask(in->channel_mask);
6777
6778 ALOGV("%s:txbecf: uc %s, id %d, sr %d, bw %d, ch %d, device %s",
6779 __func__, use_case_table[uc->id], uc->id, in->sample_rate,
6780 in->bit_width, uc_channels,
6781 platform_get_snd_device_name(uc->in_snd_device));
6782
6783 if (sample_rate < in->sample_rate)
6784 sample_rate = in->sample_rate;
6785 if (bit_width < in->bit_width)
6786 bit_width = in->bit_width;
6787 if (channels < uc_channels)
6788 channels = uc_channels;
6789 }
6790 }
Manish Dewanganba9fcfa2016-03-24 16:20:06 +05306791 }
Kuirong Wange9894162016-08-26 15:16:39 -07006792 if (backend_idx == USB_AUDIO_TX_BACKEND) {
6793 audio_extn_usb_is_config_supported(&bit_width, &sample_rate, &channels, false);
6794 ALOGV("%s: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
6795 __func__, bit_width, sample_rate, channels);
6796 }
Manish Dewanganba9fcfa2016-03-24 16:20:06 +05306797
Arun Mirpuri3b5fcfb2019-04-11 16:44:06 -07006798 ALOGI("%s:txbecf: afe: current backend bit_width %d sample_rate %d channels %d, format %x",
6799 __func__,
6800 my_data->current_backend_cfg[backend_idx].bit_width,
6801 my_data->current_backend_cfg[backend_idx].sample_rate,
6802 my_data->current_backend_cfg[backend_idx].channels,
6803 my_data->current_backend_cfg[backend_idx].format);
Manish Dewanganba9fcfa2016-03-24 16:20:06 +05306804 // Force routing if the expected bitwdith or samplerate
6805 // is not same as current backend comfiguration
Arun Mirpuri3b5fcfb2019-04-11 16:44:06 -07006806 // Note that below if block would be entered even if main format is same
6807 // but subformat is different for e.g. current backend is configured for 16 bit PCM
6808 // as compared to 24 bit PCM backend requested
Kuirong Wang0b947f72016-09-29 11:03:09 -07006809 if ((bit_width != my_data->current_backend_cfg[backend_idx].bit_width) ||
6810 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate) ||
Siddartha Shaik44dd7702017-06-14 12:13:25 +05306811 (channels != my_data->current_backend_cfg[backend_idx].channels) ||
Arun Mirpuri3b5fcfb2019-04-11 16:44:06 -07006812 (format != my_data->current_backend_cfg[backend_idx].format)) {
Kuirong Wange9894162016-08-26 15:16:39 -07006813 backend_cfg->bit_width = bit_width;
6814 backend_cfg->sample_rate= sample_rate;
Kuirong Wang0b947f72016-09-29 11:03:09 -07006815 backend_cfg->channels = channels;
Arun Mirpuri3b5fcfb2019-04-11 16:44:06 -07006816 backend_cfg->format = format;
Manish Dewanganba9fcfa2016-03-24 16:20:06 +05306817 backend_change = true;
6818 ALOGI("%s:txbecf: afe: Codec backend needs to be updated. new bit width: %d "
Siddartha Shaik44dd7702017-06-14 12:13:25 +05306819 "new sample rate: %d new channel: %d new format: %d",
Kuirong Wang0b947f72016-09-29 11:03:09 -07006820 __func__, backend_cfg->bit_width,
Siddartha Shaik44dd7702017-06-14 12:13:25 +05306821 backend_cfg->sample_rate, backend_cfg->channels, backend_cfg->format);
Manish Dewanganba9fcfa2016-03-24 16:20:06 +05306822 }
6823
6824 return backend_change;
6825}
6826
6827bool platform_check_and_set_capture_codec_backend_cfg(struct audio_device* adev,
6828 struct audio_usecase *usecase, snd_device_t snd_device)
6829{
Kuirong Wang0b947f72016-09-29 11:03:09 -07006830 int backend_idx = platform_get_backend_index(snd_device);
Manish Dewanganba9fcfa2016-03-24 16:20:06 +05306831 int ret = 0;
Kuirong Wange9894162016-08-26 15:16:39 -07006832 struct audio_backend_cfg backend_cfg;
Manish Dewanganba9fcfa2016-03-24 16:20:06 +05306833
Kuirong Wange9894162016-08-26 15:16:39 -07006834 backend_cfg.passthrough_enabled = false;
Siddartha Shaik31b530e2017-05-19 15:26:33 +05306835
Surendar Karka93cd25a2018-08-28 14:21:37 +05306836 if (usecase->type == TRANSCODE_LOOPBACK_TX) {
Siddartha Shaik31b530e2017-05-19 15:26:33 +05306837 backend_cfg.bit_width = usecase->stream.inout->in_config.bit_width;
6838 backend_cfg.sample_rate = usecase->stream.inout->in_config.sample_rate;
6839 backend_cfg.format = usecase->stream.inout->in_config.format;
6840 backend_cfg.channels = audio_channel_count_from_out_mask(
6841 usecase->stream.inout->in_config.channel_mask);
6842 } else if (usecase->type == PCM_CAPTURE) {
Kuirong Wange9894162016-08-26 15:16:39 -07006843 backend_cfg.sample_rate= usecase->stream.in->sample_rate;
6844 backend_cfg.bit_width= usecase->stream.in->bit_width;
6845 backend_cfg.format= usecase->stream.in->format;
6846 backend_cfg.channels = audio_channel_count_from_in_mask(usecase->stream.in->channel_mask);
Manish Dewanganba9fcfa2016-03-24 16:20:06 +05306847 } else {
Kuirong Wange9894162016-08-26 15:16:39 -07006848 backend_cfg.bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
6849 backend_cfg.sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
6850 backend_cfg.format = AUDIO_FORMAT_PCM_16_BIT;
6851 backend_cfg.channels = 1;
Manish Dewanganba9fcfa2016-03-24 16:20:06 +05306852 }
6853
Siddartha Shaik44dd7702017-06-14 12:13:25 +05306854 ALOGI("%s:txbecf: afe: bitwidth %d, samplerate %d, channel %d format %d"
Kuirong Wange9894162016-08-26 15:16:39 -07006855 ", backend_idx %d usecase = %d device (%s)", __func__,
6856 backend_cfg.bit_width,
6857 backend_cfg.sample_rate,
6858 backend_cfg.channels,
Siddartha Shaik44dd7702017-06-14 12:13:25 +05306859 backend_cfg.format,
Kuirong Wange9894162016-08-26 15:16:39 -07006860 backend_idx, usecase->id,
Manish Dewanganba9fcfa2016-03-24 16:20:06 +05306861 platform_get_snd_device_name(snd_device));
Kuirong Wange9894162016-08-26 15:16:39 -07006862 if (platform_check_capture_codec_backend_cfg(adev, backend_idx,
6863 &backend_cfg)) {
Kuirong Wang0b947f72016-09-29 11:03:09 -07006864 ret = platform_set_codec_backend_cfg(adev, snd_device,
6865 backend_cfg);
Manish Dewanganba9fcfa2016-03-24 16:20:06 +05306866 if(!ret)
6867 return true;
6868 }
6869
6870 return false;
6871}
6872
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05306873int platform_set_snd_device_backend(snd_device_t device, const char *backend_tag,
6874 const char * hw_interface)
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05306875{
6876 int ret = 0;
6877
6878 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
6879 ALOGE("%s: Invalid snd_device = %d",
6880 __func__, device);
6881 ret = -EINVAL;
6882 goto done;
6883 }
6884
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05306885 ALOGD("%s: backend_tag_table[%s]: old = %s new = %s", __func__,
6886 platform_get_snd_device_name(device),
6887 backend_tag_table[device] != NULL ? backend_tag_table[device]: "null",
6888 backend_tag);
Ashish Jaind150d4c2017-02-03 18:44:34 +05306889
6890 if (backend_tag != NULL ) {
6891 if (backend_tag_table[device]) {
6892 free(backend_tag_table[device]);
6893 }
6894 backend_tag_table[device] = strdup(backend_tag);
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05306895 }
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05306896
6897 if (hw_interface != NULL) {
6898 if (hw_interface_table[device])
6899 free(hw_interface_table[device]);
6900
6901 ALOGD("%s: hw_interface_table[%d] = %s", __func__, device, hw_interface);
6902 hw_interface_table[device] = strdup(hw_interface);
6903 }
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05306904done:
6905 return ret;
6906}
6907
Naresh Tanniru6160c712017-04-17 15:43:48 +05306908const char *platform_get_snd_device_backend_interface(snd_device_t device)
6909{
6910 const char *hw_interface_name = NULL;
6911
6912 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
6913 ALOGE("%s: Invalid snd_device = %d",
6914 __func__, device);
6915 goto done;
6916 }
6917
6918 /* Get string value of necessary backend for device */
6919 hw_interface_name = hw_interface_table[device];
6920 if (hw_interface_name == NULL)
6921 ALOGE("%s: no hw_interface set for device %d\n", __func__, device);
6922 else
6923 ALOGD("%s: hw_interface set for device %s\n", __func__, hw_interface_name);
6924done:
6925 return hw_interface_name;
6926}
6927
6928
Siena Richard7c2db772016-12-21 11:32:34 -08006929int platform_get_snd_device_backend_index(snd_device_t device)
6930{
6931 int i, be_dai_id;
6932 const char * hw_interface_name = NULL;
6933
6934 ALOGV("%s: enter with device %s\n",
6935 __func__, platform_get_snd_device_name(device));
6936
Aditya Bavanari701a6992017-03-30 19:17:16 +05306937 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
Siena Richard7c2db772016-12-21 11:32:34 -08006938 ALOGE("%s: Invalid snd_device = %d", __func__, device);
6939 be_dai_id = -EINVAL;
6940 goto done;
6941 }
6942
6943 /* Get string value of necessary backend for device */
6944 hw_interface_name = hw_interface_table[device];
6945 if (hw_interface_name == NULL) {
6946 ALOGE("%s: no hw_interface set for device %s\n",
6947 __func__, platform_get_snd_device_name(device));
6948 be_dai_id = -EINVAL;
6949 goto done;
6950 }
6951
6952 /* Check if be dai name table was retrieved successfully */
6953 if (be_dai_name_table == NULL) {
6954 ALOGE("%s: BE DAI Name Table is not present\n", __func__);
6955 be_dai_id = -EFAULT;
6956 goto done;
6957 }
6958
6959 /* Get backend ID for device specified */
6960 for (i = 0; i < max_be_dai_names; i++) {
6961 if (strcmp(hw_interface_name, be_dai_name_table[i].be_name) == 0) {
6962 be_dai_id = be_dai_name_table[i].be_id;
6963 goto done;
6964 }
6965 }
6966 ALOGE("%s: no interface matching name %s\n", __func__, hw_interface_name);
6967 be_dai_id = -EINVAL;
6968 goto done;
6969
6970done:
6971 return be_dai_id;
6972}
6973
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05306974int platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t pcm_id)
6975{
6976 int ret = 0;
6977 if ((usecase <= USECASE_INVALID) || (usecase >= AUDIO_USECASE_MAX)) {
6978 ALOGE("%s: invalid usecase case idx %d", __func__, usecase);
6979 ret = -EINVAL;
6980 goto done;
6981 }
6982
6983 if ((type != 0) && (type != 1)) {
6984 ALOGE("%s: invalid usecase type", __func__);
6985 ret = -EINVAL;
6986 }
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05306987 ALOGV("%s: pcm_device_table[%d][%d] = %d", __func__, usecase, type, pcm_id);
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05306988 pcm_device_table[usecase][type] = pcm_id;
6989done:
6990 return ret;
6991}
6992
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -07006993void platform_get_device_to_be_id_map(int **device_to_be_id, int *length)
6994{
Alexy Josephb1379942016-01-29 15:49:38 -08006995 *device_to_be_id = (int*) msm_device_to_be_id;
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -07006996 *length = msm_be_id_array_len;
6997}
Naresh Tanniru29bce4e2017-04-27 17:54:30 +05306998
Varun Balaraje49253e2017-07-06 19:48:56 +05306999int platform_set_stream_pan_scale_params(void *platform,
7000 int snd_id,
7001 struct mix_matrix_params mm_params)
7002{
7003 struct platform_data *my_data = (struct platform_data *)platform;
7004 struct audio_device *adev = my_data->adev;
7005 struct mixer_ctl *ctl = NULL;
7006 char mixer_ctl_name[MIXER_PATH_MAX_LENGTH] = {0};
7007 int ret = 0;
7008 int iter_i = 0;
7009 int iter_j = 0;
7010 int length = 0;
Varun Balarajf3cc95c2017-09-13 16:36:32 +05307011 char *pan_scale_data = NULL;
Varun Balaraje49253e2017-07-06 19:48:56 +05307012
7013 snprintf(mixer_ctl_name, sizeof(mixer_ctl_name),
7014 "Audio Stream %d Pan Scale Control", snd_id);
7015 ALOGD("%s mixer_ctl_name:%s", __func__, mixer_ctl_name);
7016
7017 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
7018 if (!ctl) {
7019 ALOGE("%s: Could not get ctl for mixer cmd - %s",
7020 __func__, mixer_ctl_name);
7021 ret = -EINVAL;
7022 goto end;
7023 }
Varun Balarajf3cc95c2017-09-13 16:36:32 +05307024 pan_scale_data = (char *) calloc(1, sizeof(mm_params));
7025 if (!pan_scale_data) {
7026 ret = -ENOMEM;
7027 goto end;
7028 }
7029 memcpy(&pan_scale_data[length], &mm_params.num_output_channels,
7030 sizeof(mm_params.num_output_channels));
7031 length += sizeof(mm_params.num_output_channels);
7032 memcpy(&pan_scale_data[length], &mm_params.num_input_channels,
7033 sizeof(mm_params.num_input_channels));
7034 length += sizeof(mm_params.num_input_channels);
Varun Balaraje49253e2017-07-06 19:48:56 +05307035
Varun Balarajf3cc95c2017-09-13 16:36:32 +05307036 memcpy(&pan_scale_data[length], &mm_params.has_output_channel_map,
7037 sizeof(mm_params.has_output_channel_map));
7038 length += sizeof(mm_params.has_output_channel_map);
Varun Balaraje49253e2017-07-06 19:48:56 +05307039 if (mm_params.has_output_channel_map &&
7040 mm_params.num_output_channels <= MAX_CHANNELS_SUPPORTED &&
Varun Balarajf3cc95c2017-09-13 16:36:32 +05307041 mm_params.num_output_channels > 0) {
7042 memcpy(&pan_scale_data[length], mm_params.output_channel_map,
7043 (mm_params.num_output_channels * sizeof(mm_params.output_channel_map[0])));
7044 length += (mm_params.num_output_channels * sizeof(mm_params.output_channel_map[0]));
7045 } else {
Varun Balaraje49253e2017-07-06 19:48:56 +05307046 ret = -EINVAL;
7047 goto end;
7048 }
7049
Varun Balarajf3cc95c2017-09-13 16:36:32 +05307050 memcpy(&pan_scale_data[length], &mm_params.has_input_channel_map,
7051 sizeof(mm_params.has_input_channel_map));
7052 length += sizeof(mm_params.has_input_channel_map);
Varun Balaraje49253e2017-07-06 19:48:56 +05307053 if (mm_params.has_input_channel_map &&
7054 mm_params.num_input_channels <= MAX_CHANNELS_SUPPORTED &&
Varun Balarajf3cc95c2017-09-13 16:36:32 +05307055 mm_params.num_input_channels > 0) {
7056 memcpy(&pan_scale_data[length], mm_params.input_channel_map,
7057 (mm_params.num_input_channels * sizeof(mm_params.input_channel_map[0])));
7058 length += (mm_params.num_input_channels * sizeof(mm_params.input_channel_map[0]));
7059 } else {
Varun Balaraje49253e2017-07-06 19:48:56 +05307060 ret = -EINVAL;
7061 goto end;
7062 }
Varun Balarajf3cc95c2017-09-13 16:36:32 +05307063 pan_scale_data[length] = mm_params.has_mixer_coeffs;
7064 length += sizeof(mm_params.has_mixer_coeffs);
Varun Balaraje49253e2017-07-06 19:48:56 +05307065 if (mm_params.has_mixer_coeffs)
7066 for (iter_i = 0; iter_i < mm_params.num_output_channels; iter_i++)
Varun Balarajf3cc95c2017-09-13 16:36:32 +05307067 for (iter_j = 0; iter_j < mm_params.num_input_channels; iter_j++) {
7068 memcpy(&pan_scale_data[length],
7069 &mm_params.mixer_coeffs[iter_i][iter_j],
7070 (sizeof(mm_params.mixer_coeffs[0][0])));
7071 length += (sizeof(mm_params.mixer_coeffs[0][0]));
7072 }
Varun Balaraje49253e2017-07-06 19:48:56 +05307073
7074 ret = mixer_ctl_set_array(ctl, pan_scale_data, length);
7075end:
Varun Balarajf3cc95c2017-09-13 16:36:32 +05307076 if (pan_scale_data)
7077 free(pan_scale_data);
Varun Balaraje49253e2017-07-06 19:48:56 +05307078 return ret;
7079}
7080
7081int platform_set_stream_downmix_params(void *platform,
7082 int snd_id,
7083 snd_device_t snd_device,
7084 struct mix_matrix_params mm_params)
7085{
7086 struct platform_data *my_data = (struct platform_data *)platform;
7087 struct audio_device *adev = my_data->adev;
7088 struct mixer_ctl *ctl;
7089 char mixer_ctl_name[MIXER_PATH_MAX_LENGTH] = {0};
Varun Balarajf3cc95c2017-09-13 16:36:32 +05307090 char *downmix_param_data = NULL;
Varun Balaraje49253e2017-07-06 19:48:56 +05307091 int ret = 0;
7092 int iter_i = 0;
7093 int iter_j = 0;
7094 int length = 0;
7095 int be_idx = 0;
7096
Varun Balaraje49253e2017-07-06 19:48:56 +05307097 snprintf(mixer_ctl_name, sizeof(mixer_ctl_name),
7098 "Audio Device %d Downmix Control", snd_id);
7099 ALOGD("%s mixer_ctl_name:%s", __func__, mixer_ctl_name);
7100
7101 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
7102 if (!ctl) {
7103 ALOGE("%s: Could not get ctl for mixer cmd - %s",
7104 __func__, mixer_ctl_name);
7105 ret = -EINVAL;
Varun Balaraje49253e2017-07-06 19:48:56 +05307106 }
7107
Varun Balarajf3cc95c2017-09-13 16:36:32 +05307108 downmix_param_data = (char *) calloc(1, sizeof(mm_params) + sizeof(be_idx));
7109 if (!downmix_param_data) {
7110 ret = -ENOMEM;
7111 goto end;
7112 }
Varun Balaraje49253e2017-07-06 19:48:56 +05307113 be_idx = platform_get_snd_device_backend_index(snd_device);
Varun Balarajf3cc95c2017-09-13 16:36:32 +05307114 memcpy(&downmix_param_data[length], &be_idx, sizeof(be_idx));
7115 length += sizeof(be_idx);
7116 memcpy(&downmix_param_data[length], &mm_params.num_output_channels,
7117 sizeof(mm_params.num_output_channels));
7118 length += sizeof(mm_params.num_output_channels);
7119 memcpy(&downmix_param_data[length], &mm_params.num_input_channels,
7120 sizeof(mm_params.num_input_channels));
7121 length += sizeof(mm_params.num_input_channels);
Varun Balaraje49253e2017-07-06 19:48:56 +05307122
Varun Balarajf3cc95c2017-09-13 16:36:32 +05307123 memcpy(&downmix_param_data[length], &mm_params.has_output_channel_map,
7124 sizeof(mm_params.has_output_channel_map));
7125 length += sizeof(mm_params.has_output_channel_map);
Varun Balaraje49253e2017-07-06 19:48:56 +05307126 if (mm_params.has_output_channel_map &&
7127 mm_params.num_output_channels <= MAX_CHANNELS_SUPPORTED &&
Varun Balarajf3cc95c2017-09-13 16:36:32 +05307128 mm_params.num_output_channels > 0) {
7129 memcpy(&downmix_param_data[length], mm_params.output_channel_map,
7130 (mm_params.num_output_channels * sizeof(mm_params.output_channel_map[0])));
7131 length += (mm_params.num_output_channels * sizeof(mm_params.output_channel_map[0]));
7132 } else {
Varun Balaraje49253e2017-07-06 19:48:56 +05307133 ret = -EINVAL;
7134 goto end;
7135 }
7136
Varun Balarajf3cc95c2017-09-13 16:36:32 +05307137 memcpy(&downmix_param_data[length], &mm_params.has_input_channel_map,
7138 sizeof(mm_params.has_input_channel_map));
7139 length += sizeof(mm_params.has_input_channel_map);
Varun Balaraje49253e2017-07-06 19:48:56 +05307140 if (mm_params.has_input_channel_map &&
7141 mm_params.num_input_channels <= MAX_CHANNELS_SUPPORTED &&
Varun Balarajf3cc95c2017-09-13 16:36:32 +05307142 mm_params.num_input_channels > 0) {
7143 memcpy(&downmix_param_data[length], mm_params.input_channel_map,
7144 (mm_params.num_input_channels * sizeof(mm_params.input_channel_map[0])));
7145 length += (mm_params.num_input_channels * sizeof(mm_params.input_channel_map[0]));
7146 } else {
Varun Balaraje49253e2017-07-06 19:48:56 +05307147 ret = -EINVAL;
7148 goto end;
7149 }
Varun Balarajf3cc95c2017-09-13 16:36:32 +05307150 memcpy(&downmix_param_data[length], &mm_params.has_mixer_coeffs,
7151 sizeof(mm_params.has_mixer_coeffs));
7152 length += sizeof(mm_params.has_mixer_coeffs);
Varun Balaraje49253e2017-07-06 19:48:56 +05307153 if (mm_params.has_mixer_coeffs)
7154 for (iter_i = 0; iter_i < mm_params.num_output_channels; iter_i++)
Varun Balarajf3cc95c2017-09-13 16:36:32 +05307155 for (iter_j = 0; iter_j < mm_params.num_input_channels; iter_j++) {
7156 memcpy((uint32_t *) &downmix_param_data[length],
7157 &mm_params.mixer_coeffs[iter_i][iter_j],
7158 (sizeof(mm_params.mixer_coeffs[0][0])));
7159 length += (sizeof(mm_params.mixer_coeffs[0][0]));
7160 }
Varun Balaraje49253e2017-07-06 19:48:56 +05307161
7162 ret = mixer_ctl_set_array(ctl, downmix_param_data, length);
7163end:
Varun Balarajf3cc95c2017-09-13 16:36:32 +05307164 if (downmix_param_data)
7165 free(downmix_param_data);
Varun Balaraje49253e2017-07-06 19:48:56 +05307166 return ret;
7167}
7168
Naresh Tanniru29bce4e2017-04-27 17:54:30 +05307169int platform_set_stream_channel_map(void *platform, audio_channel_mask_t channel_mask,
7170 int snd_id, uint8_t *input_channel_map)
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05307171{
Naresh Tanniru29bce4e2017-04-27 17:54:30 +05307172 int ret = 0, i = 0;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05307173 int channels = audio_channel_count_from_out_mask(channel_mask);
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -07007174
Naresh Tanniru29bce4e2017-04-27 17:54:30 +05307175 char channel_map[AUDIO_CHANNEL_COUNT_MAX];
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05307176 memset(channel_map, 0, sizeof(channel_map));
Naresh Tanniru29bce4e2017-04-27 17:54:30 +05307177 if (*input_channel_map) {
7178 for (i = 0; i < channels; i++) {
7179 ALOGV("%s:: Channel Map channel_map[%d] - %d", __func__, i, *input_channel_map);
7180 channel_map[i] = *input_channel_map;
7181 input_channel_map++;
7182 }
7183 } else {
7184 /* Following are all most common standard WAV channel layouts
7185 overridden by channel mask if its allowed and different */
7186 switch (channels) {
7187 case 1:
7188 /* AUDIO_CHANNEL_OUT_MONO */
7189 channel_map[0] = PCM_CHANNEL_FC;
7190 break;
7191 case 2:
7192 /* AUDIO_CHANNEL_OUT_STEREO */
7193 channel_map[0] = PCM_CHANNEL_FL;
7194 channel_map[1] = PCM_CHANNEL_FR;
7195 break;
7196 case 3:
7197 /* AUDIO_CHANNEL_OUT_2POINT1 */
7198 channel_map[0] = PCM_CHANNEL_FL;
7199 channel_map[1] = PCM_CHANNEL_FR;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05307200 channel_map[2] = PCM_CHANNEL_FC;
Naresh Tanniru29bce4e2017-04-27 17:54:30 +05307201 break;
7202 case 4:
7203 /* AUDIO_CHANNEL_OUT_QUAD_SIDE */
7204 channel_map[0] = PCM_CHANNEL_FL;
7205 channel_map[1] = PCM_CHANNEL_FR;
7206 channel_map[2] = PCM_CHANNEL_LS;
7207 channel_map[3] = PCM_CHANNEL_RS;
7208 if (channel_mask == AUDIO_CHANNEL_OUT_QUAD_BACK) {
7209 channel_map[2] = PCM_CHANNEL_LB;
7210 channel_map[3] = PCM_CHANNEL_RB;
7211 }
7212 if (channel_mask == AUDIO_CHANNEL_OUT_SURROUND) {
7213 channel_map[2] = PCM_CHANNEL_FC;
7214 channel_map[3] = PCM_CHANNEL_CS;
7215 }
7216 break;
7217 case 5:
7218 /* AUDIO_CHANNEL_OUT_PENTA */
7219 channel_map[0] = PCM_CHANNEL_FL;
7220 channel_map[1] = PCM_CHANNEL_FR;
7221 channel_map[2] = PCM_CHANNEL_FC;
7222 channel_map[3] = PCM_CHANNEL_LB;
7223 channel_map[4] = PCM_CHANNEL_RB;
7224 break;
7225 case 6:
7226 /* AUDIO_CHANNEL_OUT_5POINT1 */
7227 channel_map[0] = PCM_CHANNEL_FL;
7228 channel_map[1] = PCM_CHANNEL_FR;
7229 channel_map[2] = PCM_CHANNEL_FC;
7230 channel_map[3] = PCM_CHANNEL_LFE;
7231 channel_map[4] = PCM_CHANNEL_LB;
7232 channel_map[5] = PCM_CHANNEL_RB;
7233 if (channel_mask == AUDIO_CHANNEL_OUT_5POINT1_SIDE) {
7234 channel_map[4] = PCM_CHANNEL_LS;
7235 channel_map[5] = PCM_CHANNEL_RS;
7236 }
7237 break;
7238 case 7:
7239 /* AUDIO_CHANNEL_OUT_6POINT1 */
7240 channel_map[0] = PCM_CHANNEL_FL;
7241 channel_map[1] = PCM_CHANNEL_FR;
7242 channel_map[2] = PCM_CHANNEL_FC;
7243 channel_map[3] = PCM_CHANNEL_LFE;
7244 channel_map[4] = PCM_CHANNEL_LB;
7245 channel_map[5] = PCM_CHANNEL_RB;
7246 channel_map[6] = PCM_CHANNEL_CS;
7247 break;
7248 case 8:
7249 /* AUDIO_CHANNEL_OUT_7POINT1 */
7250 channel_map[0] = PCM_CHANNEL_FL;
7251 channel_map[1] = PCM_CHANNEL_FR;
7252 channel_map[2] = PCM_CHANNEL_FC;
7253 channel_map[3] = PCM_CHANNEL_LFE;
7254 channel_map[4] = PCM_CHANNEL_LB;
7255 channel_map[5] = PCM_CHANNEL_RB;
7256 channel_map[6] = PCM_CHANNEL_LS;
7257 channel_map[7] = PCM_CHANNEL_RS;
7258 break;
7259 default:
7260 ALOGE("unsupported channels %d for setting channel map", channels);
7261 return -1;
7262 }
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05307263 }
Rohit kumar4dbd2c02019-02-04 16:26:33 +05307264 ret = platform_set_channel_map(platform, channels, channel_map, snd_id, -1);
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05307265 return ret;
7266}
7267
Ashish Jaina052e572016-11-07 16:41:07 +05307268void platform_check_and_update_copp_sample_rate(void* platform, snd_device_t snd_device,
7269 unsigned int stream_sr, int* sample_rate)
7270{
7271 struct platform_data* my_data = (struct platform_data *)platform;
7272 int backend_idx = platform_get_backend_index(snd_device);
7273 int device_sr = my_data->current_backend_cfg[backend_idx].sample_rate;
7274 /*Check if device SR is multiple of 8K or 11.025 Khz
7275 *check if the stream SR is multiple of same base, if not set
7276 *copp sample rate equal to device sample rate.
7277 */
7278 if (!(((sample_rate_multiple(device_sr, SAMPLE_RATE_8000)) &&
7279 (sample_rate_multiple(stream_sr, SAMPLE_RATE_8000))) ||
7280 ((sample_rate_multiple(device_sr, SAMPLE_RATE_11025)) &&
7281 (sample_rate_multiple(stream_sr, SAMPLE_RATE_11025))))) {
7282 *sample_rate = device_sr;
7283 } else
7284 *sample_rate = stream_sr;
7285
Venugopal Nadipalli83134582017-09-21 22:34:50 +05307286 if (snd_device == SND_DEVICE_OUT_HDMI)
Revathi Uddaraju0553e8f2017-11-30 14:56:11 +05307287 *sample_rate = platform_get_supported_copp_sampling_rate(stream_sr);
Venugopal Nadipalli83134582017-09-21 22:34:50 +05307288
Ashish Jaina052e572016-11-07 16:41:07 +05307289 ALOGI("sn_device %d device sr %d stream sr %d copp sr %d", snd_device, device_sr, stream_sr
7290, *sample_rate);
7291
7292}
7293
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05307294int platform_get_edid_info(void *platform)
7295{
7296 struct platform_data *my_data = (struct platform_data *)platform;
7297 struct audio_device *adev = my_data->adev;
7298 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
Satya Krishna Pindiprolif1cd92b2016-04-14 19:05:23 +05307299 int ret, count;
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07007300 char *mix_ctl_name;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05307301 struct mixer_ctl *ctl;
7302 char edid_data[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE + 1] = {0};
7303 edid_audio_info *info;
7304
7305 if (my_data->edid_valid) {
7306 /* use cached edid */
7307 return 0;
7308 }
7309
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07007310 switch(my_data->ext_disp_type) {
7311 case EXT_DISPLAY_TYPE_HDMI:
7312 mix_ctl_name = "HDMI EDID";
7313 break;
7314 case EXT_DISPLAY_TYPE_DP:
7315 mix_ctl_name = "Display Port EDID";
7316 break;
7317 default:
7318 ALOGE("%s: Invalid disp_type %d", __func__, my_data->ext_disp_type);
7319 return -EINVAL;
7320 }
7321
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05307322 if (my_data->edid_info == NULL) {
7323 my_data->edid_info =
7324 (struct edid_audio_info *)calloc(1, sizeof(struct edid_audio_info));
7325 }
7326
7327 info = my_data->edid_info;
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07007328 ctl = mixer_get_ctl_by_name(adev->mixer, mix_ctl_name);
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05307329 if (!ctl) {
7330 ALOGE("%s: Could not get ctl for mixer cmd - %s",
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07007331 __func__, mix_ctl_name);
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05307332 goto fail;
7333 }
7334
7335 mixer_ctl_update(ctl);
7336
7337 count = mixer_ctl_get_num_values(ctl);
7338
7339 /* Read SAD blocks, clamping the maximum size for safety */
7340 if (count > (int)sizeof(block))
7341 count = (int)sizeof(block);
7342
7343 ret = mixer_ctl_get_array(ctl, block, count);
7344 if (ret != 0) {
7345 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
7346 goto fail;
7347 }
7348 edid_data[0] = count;
7349 memcpy(&edid_data[1], block, count);
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07007350
Arun Mirpurib1bec9c2019-01-29 16:42:45 -08007351 if (!audio_extn_edid_get_sink_caps(info, edid_data)) {
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07007352 ALOGE("%s: Failed to get extn disp sink capabilities", __func__);
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05307353 goto fail;
7354 }
7355 my_data->edid_valid = true;
7356 return 0;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05307357fail:
7358 if (my_data->edid_info) {
7359 free(my_data->edid_info);
7360 my_data->edid_info = NULL;
7361 my_data->edid_valid = false;
7362 }
7363 ALOGE("%s: return -EINVAL", __func__);
7364 return -EINVAL;
7365}
7366
7367
7368int platform_set_channel_allocation(void *platform, int channel_alloc)
7369{
7370 struct mixer_ctl *ctl;
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07007371 char *mixer_ctl_name;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05307372 int ret;
7373 struct platform_data *my_data = (struct platform_data *)platform;
7374 struct audio_device *adev = my_data->adev;
7375
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07007376 switch(my_data->ext_disp_type) {
7377 case EXT_DISPLAY_TYPE_HDMI:
7378 mixer_ctl_name = "HDMI RX CA";
7379 break;
7380 case EXT_DISPLAY_TYPE_DP:
7381 mixer_ctl_name = "Display Port RX CA";
7382 break;
7383 default:
7384 ALOGE("%s: Invalid disp_type %d", __func__, my_data->ext_disp_type);
7385 return -EINVAL;
7386 }
7387
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05307388 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
7389 if (!ctl) {
7390 ALOGE("%s: Could not get ctl for mixer cmd - %s",
7391 __func__, mixer_ctl_name);
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07007392 return -EINVAL;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05307393 }
7394 ALOGD(":%s channel allocation = 0x%x", __func__, channel_alloc);
7395 ret = mixer_ctl_set_value(ctl, 0, channel_alloc);
7396
7397 if (ret < 0) {
7398 ALOGE("%s: Could not set ctl, error:%d ", __func__, ret);
7399 }
7400
7401 return ret;
7402}
7403
Rohit kumar4dbd2c02019-02-04 16:26:33 +05307404int platform_set_channel_map(void *platform, int ch_count, char *ch_map, int snd_id, int be_idx __unused)
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05307405{
7406 struct mixer_ctl *ctl;
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07007407 char mixer_ctl_name[44] = {0}; // max length of name is 44 as defined
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05307408 int ret;
7409 unsigned int i;
Manish Dewangan338c50a2017-09-12 15:22:03 +05307410 long set_values[FCC_8] = {0};
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05307411 struct platform_data *my_data = (struct platform_data *)platform;
7412 struct audio_device *adev = my_data->adev;
7413 ALOGV("%s channel_count:%d",__func__, ch_count);
Divya Narayanan Poojary21de6aa2017-01-06 12:07:19 +05307414 if (NULL == ch_map || (ch_count < 1) || (ch_count > FCC_8)) {
7415 ALOGE("%s: Invalid channel mapping or channel count value", __func__);
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05307416 return -EINVAL;
7417 }
Satish Babu Patakokila624cc922015-06-17 21:21:06 +05307418
7419 /*
7420 * If snd_id is greater than 0, stream channel mapping
7421 * If snd_id is below 0, typically -1, device channel mapping
7422 */
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05307423 if (snd_id >= 0) {
Satish Babu Patakokila624cc922015-06-17 21:21:06 +05307424 snprintf(mixer_ctl_name, sizeof(mixer_ctl_name), "Playback Channel Map%d", snd_id);
7425 } else {
7426 strlcpy(mixer_ctl_name, "Playback Device Channel Map", sizeof(mixer_ctl_name));
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05307427 }
7428
7429 ALOGD("%s mixer_ctl_name:%s", __func__, mixer_ctl_name);
7430
7431 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
7432 if (!ctl) {
7433 ALOGE("%s: Could not get ctl for mixer cmd - %s",
7434 __func__, mixer_ctl_name);
7435 return -EINVAL;
7436 }
Divya Narayanan Poojary21de6aa2017-01-06 12:07:19 +05307437 for (i = 0; i < (unsigned int)ch_count; i++) {
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05307438 set_values[i] = ch_map[i];
7439 }
7440
Vara Prasad A V S G15294a42018-02-06 19:07:07 +05307441 ALOGD("%s: set mapping(%ld %ld %ld %ld %ld %ld %ld %ld) for channel:%d", __func__,
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05307442 set_values[0], set_values[1], set_values[2], set_values[3], set_values[4],
7443 set_values[5], set_values[6], set_values[7], ch_count);
7444
Divya Narayanan Poojary21de6aa2017-01-06 12:07:19 +05307445 ret = mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05307446 if (ret < 0) {
7447 ALOGE("%s: Could not set ctl, error:%d ch_count:%d",
7448 __func__, ret, ch_count);
7449 }
7450 return ret;
7451}
7452
7453unsigned char platform_map_to_edid_format(int audio_format)
7454{
7455 unsigned char format;
7456 switch (audio_format & AUDIO_FORMAT_MAIN_MASK) {
7457 case AUDIO_FORMAT_AC3:
7458 ALOGV("%s: AC3", __func__);
7459 format = AC3;
7460 break;
7461 case AUDIO_FORMAT_AAC:
7462 ALOGV("%s:AAC", __func__);
7463 format = AAC;
7464 break;
Manish Dewangana6fc5442015-08-24 20:30:31 +05307465 case AUDIO_FORMAT_AAC_ADTS:
7466 ALOGV("%s:AAC_ADTS", __func__);
7467 format = AAC;
7468 break;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05307469 case AUDIO_FORMAT_E_AC3:
Satish Babu Patakokilaa395a9e2016-11-01 12:18:49 +05307470 case AUDIO_FORMAT_E_AC3_JOC:
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05307471 ALOGV("%s:E_AC3", __func__);
7472 format = DOLBY_DIGITAL_PLUS;
7473 break;
Ben Romberger1aaaf862017-04-06 17:49:46 -07007474 case AUDIO_FORMAT_DOLBY_TRUEHD:
7475 ALOGV("%s:MAT", __func__);
7476 format = MAT;
7477 break;
Mingming Yin3a941d42016-02-17 18:08:05 -08007478 case AUDIO_FORMAT_DTS:
7479 ALOGV("%s:DTS", __func__);
7480 format = DTS;
7481 break;
7482 case AUDIO_FORMAT_DTS_HD:
7483 ALOGV("%s:DTS_HD", __func__);
7484 format = DTS_HD;
7485 break;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05307486 case AUDIO_FORMAT_PCM_16_BIT:
Ashish Jain5106d362016-05-11 19:23:33 +05307487 case AUDIO_FORMAT_PCM_24_BIT_PACKED:
7488 case AUDIO_FORMAT_PCM_8_24_BIT:
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05307489 ALOGV("%s:PCM", __func__);
Mingming Yin3a941d42016-02-17 18:08:05 -08007490 format = LPCM;
7491 break;
Naresh Tanniru928f0862017-04-07 16:44:23 -07007492 case AUDIO_FORMAT_IEC61937:
7493 ALOGV("%s:IEC61937", __func__);
7494 format = 0;
7495 break;
Mingming Yin3a941d42016-02-17 18:08:05 -08007496 default:
Mingming Yin3a941d42016-02-17 18:08:05 -08007497 format = -1;
Naresh Tanniru928f0862017-04-07 16:44:23 -07007498 ALOGE("%s:invalid format:0x%x", __func__, audio_format);
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05307499 break;
7500 }
7501 return format;
7502}
7503
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05307504void platform_reset_edid_info(void *platform) {
7505
7506 ALOGV("%s:", __func__);
7507 struct platform_data *my_data = (struct platform_data *)platform;
7508 if (my_data->edid_info) {
7509 ALOGV("%s :free edid", __func__);
7510 free(my_data->edid_info);
7511 my_data->edid_info = NULL;
7512 }
7513}
7514
7515bool platform_is_edid_supported_format(void *platform, int format)
7516{
7517 struct platform_data *my_data = (struct platform_data *)platform;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05307518 edid_audio_info *info = NULL;
Satya Krishna Pindiprolif1cd92b2016-04-14 19:05:23 +05307519 int i, ret;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05307520 unsigned char format_id = platform_map_to_edid_format(format);
7521
Naresh Tanniru928f0862017-04-07 16:44:23 -07007522 if (format == AUDIO_FORMAT_IEC61937)
7523 return true;
7524
Mingming Yin3a941d42016-02-17 18:08:05 -08007525 if (format_id <= 0) {
7526 ALOGE("%s invalid edid format mappting for :%x" ,__func__, format);
7527 return false;
7528 }
7529
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05307530 ret = platform_get_edid_info(platform);
7531 info = (edid_audio_info *)my_data->edid_info;
7532 if (ret == 0 && info != NULL) {
7533 for (i = 0; i < info->audio_blocks && i < MAX_EDID_BLOCKS; i++) {
7534 /*
7535 * To check
7536 * is there any special for CONFIG_HDMI_PASSTHROUGH_CONVERT
7537 * & DOLBY_DIGITAL_PLUS
7538 */
7539 if (info->audio_blocks_array[i].format_id == format_id) {
Mingming Yin3a941d42016-02-17 18:08:05 -08007540 ALOGV("%s:returns true %x",
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05307541 __func__, format);
7542 return true;
7543 }
7544 }
7545 }
Mingming Yin3a941d42016-02-17 18:08:05 -08007546 ALOGV("%s:returns false %x",
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05307547 __func__, format);
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -07007548 return false;
7549}
7550
Mingming Yin3a941d42016-02-17 18:08:05 -08007551bool platform_is_edid_supported_sample_rate(void *platform, int sample_rate)
7552{
7553 struct platform_data *my_data = (struct platform_data *)platform;
Mingming Yin3a941d42016-02-17 18:08:05 -08007554 edid_audio_info *info = NULL;
Garmond Leung2f78a672016-11-07 16:27:40 -08007555 int ret = 0;
Mingming Yin3a941d42016-02-17 18:08:05 -08007556
7557 ret = platform_get_edid_info(platform);
7558 info = (edid_audio_info *)my_data->edid_info;
7559 if (ret == 0 && info != NULL) {
Arun Mirpurib1bec9c2019-01-29 16:42:45 -08007560 return audio_extn_edid_is_supported_sr(info, sample_rate);
Mingming Yin3a941d42016-02-17 18:08:05 -08007561 }
Mingming Yin3a941d42016-02-17 18:08:05 -08007562
7563 return false;
7564}
7565
Rohit kumar4dbd2c02019-02-04 16:26:33 +05307566int platform_set_edid_channels_configuration(void *platform, int channels, int backend_idx __unused, snd_device_t snd_device __unused) {
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07007567
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05307568 struct platform_data *my_data = (struct platform_data *)platform;
Satish Babu Patakokilac3c5d432017-07-04 22:48:59 +05307569 struct audio_device *adev = my_data->adev;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05307570 edid_audio_info *info = NULL;
Weiyin Jiang8f1d7f02019-09-04 16:45:45 +08007571 int ret;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05307572 char default_channelMap[MAX_CHANNELS_SUPPORTED] = {0};
Satish Babu Patakokilac3c5d432017-07-04 22:48:59 +05307573 struct audio_device_config_param *adev_device_cfg_ptr = adev->device_cfg_params;
Weiyin Jiang8f1d7f02019-09-04 16:45:45 +08007574 int channel_alloc = 0;
7575 int max_supported_channels = 0;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07007576
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05307577 ret = platform_get_edid_info(platform);
7578 info = (edid_audio_info *)my_data->edid_info;
Satish Babu Patakokilac3c5d432017-07-04 22:48:59 +05307579 adev_device_cfg_ptr += HDMI_RX_BACKEND;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05307580 if(ret == 0 && info != NULL) {
Weiyin Jiang8f1d7f02019-09-04 16:45:45 +08007581 if ((channels > 2) && (channels <= MAX_HDMI_CHANNEL_CNT)) {
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05307582 ALOGV("%s:able to get HDMI sink capabilities multi channel playback",
7583 __func__);
Weiyin Jiang8f1d7f02019-09-04 16:45:45 +08007584 max_supported_channels = platform_edid_get_max_channels(my_data);
7585 if (channels > max_supported_channels)
7586 channels = max_supported_channels;
7587 // refer to HDMI spec CEA-861-E: Table 28 Audio InfoFrame Data Byte 4
7588 switch (channels) {
7589 case 3:
7590 channel_alloc = 0x02; break;
7591 case 4:
7592 channel_alloc = 0x06; break;
7593 case 5:
7594 channel_alloc = 0x0A; break;
7595 case 6:
7596 channel_alloc = 0x0B; break;
7597 case 7:
7598 channel_alloc = 0x12; break;
7599 case 8:
7600 channel_alloc = 0x13; break;
7601 default:
7602 ALOGE("%s: invalid channel %d", __func__, channels);
7603 return -EINVAL;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05307604 }
Weiyin Jiang8f1d7f02019-09-04 16:45:45 +08007605 ALOGVV("%s:channels:%d", __func__, channels);
7606
Satish Babu Patakokilac3c5d432017-07-04 22:48:59 +05307607 if (adev_device_cfg_ptr->use_client_dev_cfg) {
7608 platform_set_channel_map(platform, adev_device_cfg_ptr->dev_cfg_params.channels,
Rohit kumar4dbd2c02019-02-04 16:26:33 +05307609 (char *)adev_device_cfg_ptr->dev_cfg_params.channel_map, -1, -1);
Satish Babu Patakokilac3c5d432017-07-04 22:48:59 +05307610 } else {
Weiyin Jiang8f1d7f02019-09-04 16:45:45 +08007611 platform_set_channel_map(platform, channels, info->channel_map, -1, -1);
Satish Babu Patakokilac3c5d432017-07-04 22:48:59 +05307612 }
7613
7614 if (adev_device_cfg_ptr->use_client_dev_cfg) {
7615 ALOGV("%s:: Setting client selected CA %d", __func__,
7616 adev_device_cfg_ptr->dev_cfg_params.channel_allocation);
7617 platform_set_channel_allocation(platform,
7618 adev_device_cfg_ptr->dev_cfg_params.channel_allocation);
7619 } else {
Weiyin Jiang8f1d7f02019-09-04 16:45:45 +08007620 platform_set_channel_allocation(platform, channel_alloc);
7621 }
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05307622 } else {
Satish Babu Patakokilac3c5d432017-07-04 22:48:59 +05307623 if (adev_device_cfg_ptr->use_client_dev_cfg) {
7624 default_channelMap[0] = adev_device_cfg_ptr->dev_cfg_params.channel_map[0];
7625 default_channelMap[1] = adev_device_cfg_ptr->dev_cfg_params.channel_map[1];
7626 } else {
7627 default_channelMap[0] = PCM_CHANNEL_FL;
7628 default_channelMap[1] = PCM_CHANNEL_FR;
7629 }
Rohit kumar4dbd2c02019-02-04 16:26:33 +05307630 platform_set_channel_map(platform, 2, default_channelMap, -1, -1);
Weiyin Jiang8f1d7f02019-09-04 16:45:45 +08007631 platform_set_channel_allocation(platform, 0);
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05307632 }
7633 }
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07007634
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07007635 return 0;
7636}
7637
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05307638void platform_cache_edid(void * platform)
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07007639{
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05307640 platform_get_edid_info(platform);
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07007641}
7642
Dieter Luecking5d57def2018-09-07 14:23:37 +02007643bool platform_spkr_use_default_sample_rate(void *platform) {
7644 struct platform_data *my_data = (struct platform_data *)platform;
7645 return my_data->use_sprk_default_sample_rate;
7646}
7647
Siddartha Shaik44dd7702017-06-14 12:13:25 +05307648void platform_invalidate_backend_config(void * platform,snd_device_t snd_device)
7649{
7650 struct platform_data *my_data = (struct platform_data *)platform;
7651 struct audio_device *adev = my_data->adev;
7652 struct audio_backend_cfg backend_cfg;
7653 int backend_idx;
7654
7655 backend_cfg.sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
7656 backend_cfg.channels = CODEC_BACKEND_DEFAULT_CHANNELS;
7657 backend_cfg.bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
7658 backend_cfg.format = AUDIO_FORMAT_PCM_16_BIT;
7659 backend_cfg.passthrough_enabled = false;
7660
7661 backend_idx = platform_get_backend_index(snd_device);
7662 platform_set_codec_backend_cfg(adev, snd_device, backend_cfg);
7663 my_data->current_backend_cfg[backend_idx].sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
7664 my_data->current_backend_cfg[backend_idx].channels = CODEC_BACKEND_DEFAULT_CHANNELS;
7665 my_data->current_backend_cfg[backend_idx].bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
7666 my_data->current_backend_cfg[backend_idx].format = AUDIO_FORMAT_PCM_16_BIT;
7667}
7668
Mingming Yinddd610b2016-01-20 17:09:32 -08007669void platform_invalidate_hdmi_config(void * platform)
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07007670{
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07007671 //reset ext display EDID info
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05307672 struct platform_data *my_data = (struct platform_data *)platform;
Ben Rombergere9e80ee2017-04-26 16:00:10 -07007673 struct audio_device *adev = my_data->adev;
7674 struct audio_backend_cfg backend_cfg;
7675 int backend_idx;
7676 snd_device_t snd_device;
7677
7678 backend_cfg.sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
7679 backend_cfg.channels = DEFAULT_HDMI_OUT_CHANNELS;
7680 backend_cfg.bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
7681 backend_cfg.format = 0;
7682 backend_cfg.passthrough_enabled = false;
7683
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05307684 my_data->edid_valid = false;
7685 if (my_data->edid_info) {
7686 memset(my_data->edid_info, 0, sizeof(struct edid_audio_info));
7687 }
Mingming Yinddd610b2016-01-20 17:09:32 -08007688
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07007689 if (my_data->ext_disp_type == EXT_DISPLAY_TYPE_HDMI) {
7690 //reset HDMI_RX_BACKEND to default values
Ben Rombergere9e80ee2017-04-26 16:00:10 -07007691 backend_idx = HDMI_RX_BACKEND;
7692 snd_device = SND_DEVICE_OUT_HDMI;
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07007693 } else {
7694 //reset Display port BACKEND to default values
Ben Rombergere9e80ee2017-04-26 16:00:10 -07007695 backend_idx = DISP_PORT_RX_BACKEND;
7696 snd_device = SND_DEVICE_OUT_DISPLAY_PORT;
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07007697 }
Ben Rombergere9e80ee2017-04-26 16:00:10 -07007698 platform_set_codec_backend_cfg(adev, snd_device, backend_cfg);
7699 my_data->current_backend_cfg[backend_idx].sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
7700 my_data->current_backend_cfg[backend_idx].channels = DEFAULT_HDMI_OUT_CHANNELS;
7701 my_data->current_backend_cfg[backend_idx].bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07007702 my_data->ext_disp_type = EXT_DISPLAY_TYPE_NONE;
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07007703}
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05307704
7705int platform_set_mixer_control(struct stream_out *out, const char * mixer_ctl_name,
7706 const char *mixer_val)
7707{
7708 struct audio_device *adev = out->dev;
7709 struct mixer_ctl *ctl = NULL;
7710 ALOGD("setting mixer ctl %s with value %s", mixer_ctl_name, mixer_val);
7711 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
7712 if (!ctl) {
7713 ALOGE("%s: could not get ctl for mixer cmd - %s",
7714 __func__, mixer_ctl_name);
7715 return -EINVAL;
7716 }
7717
7718 return mixer_ctl_set_enum_by_string(ctl, mixer_val);
7719}
7720
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05307721int platform_set_device_params(struct stream_out *out, int param, int value)
7722{
7723 struct audio_device *adev = out->dev;
7724 struct mixer_ctl *ctl;
7725 char *mixer_ctl_name = "Device PP Params";
7726 int ret = 0;
Manish Dewangan338c50a2017-09-12 15:22:03 +05307727 long set_values[] = {0,0};
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05307728
7729 set_values[0] = param;
7730 set_values[1] = value;
7731
7732 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
7733 if (!ctl) {
7734 ALOGE("%s: Could not get ctl for mixer cmd - %s",
7735 __func__, mixer_ctl_name);
7736 ret = -EINVAL;
7737 goto end;
7738 }
7739
7740 ALOGV("%s: Setting device pp params param: %d, value %d mixer ctrl:%s",
7741 __func__,param, value, mixer_ctl_name);
7742 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
7743
7744end:
7745 return ret;
7746}
7747
Preetam Singh Ranawat2d0e4632015-02-02 12:40:59 +05307748int platform_get_subsys_image_name(char *buf)
7749{
7750 strlcpy(buf, PLATFORM_IMAGE_NAME, sizeof(PLATFORM_IMAGE_NAME));
7751 return 0;
7752}
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -08007753
Karthik Reddy Kattae4078ed2015-04-21 11:46:15 +05307754/*
7755 * This is a lookup table to map android audio input device to audio h/w interface (backend).
7756 * The table can be extended for other input devices by adding appropriate entries.
Karthik Reddy Katta508eca42015-05-11 13:43:18 +05307757 * The audio interface for a particular input device need to be added in
7758 * audio_platform_info.xml file.
Karthik Reddy Kattae4078ed2015-04-21 11:46:15 +05307759 */
7760struct audio_device_to_audio_interface audio_device_to_interface_table[] = {
Karthik Reddy Katta508eca42015-05-11 13:43:18 +05307761 {AUDIO_DEVICE_IN_BUILTIN_MIC, ENUM_TO_STRING(AUDIO_DEVICE_IN_BUILTIN_MIC), ""},
7762 {AUDIO_DEVICE_IN_BACK_MIC, ENUM_TO_STRING(AUDIO_DEVICE_IN_BACK_MIC), ""},
Karthik Reddy Kattae4078ed2015-04-21 11:46:15 +05307763};
7764
7765int audio_device_to_interface_table_len =
7766 sizeof(audio_device_to_interface_table) / sizeof(audio_device_to_interface_table[0]);
7767
Karthik Reddy Kattae4078ed2015-04-21 11:46:15 +05307768int platform_set_audio_device_interface(const char * device_name,
Karthik Reddy Katta508eca42015-05-11 13:43:18 +05307769 const char *intf_name,
7770 const char *codec_type)
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -08007771{
Karthik Reddy Kattae4078ed2015-04-21 11:46:15 +05307772 int ret = 0;
7773 int i;
7774
Karthik Reddy Katta508eca42015-05-11 13:43:18 +05307775 if (device_name == NULL || intf_name == NULL || codec_type == NULL) {
Karthik Reddy Kattae4078ed2015-04-21 11:46:15 +05307776 ALOGE("%s: Invalid input", __func__);
7777
7778 ret = -EINVAL;
7779 goto done;
7780 }
7781
Karthik Reddy Katta508eca42015-05-11 13:43:18 +05307782 ALOGD("%s: Enter, device name:%s, intf name:%s, codec_type:%s", __func__,
7783 device_name, intf_name, codec_type);
Karthik Reddy Kattae4078ed2015-04-21 11:46:15 +05307784
7785 size_t device_name_len = strlen(device_name);
7786 for (i = 0; i < audio_device_to_interface_table_len; i++) {
7787 char* name = audio_device_to_interface_table[i].device_name;
7788 size_t name_len = strlen(name);
7789 if ((name_len == device_name_len) &&
7790 (strncmp(device_name, name, name_len) == 0)) {
Karthik Reddy Katta508eca42015-05-11 13:43:18 +05307791 if (is_external_codec &&
7792 (strncmp(codec_type, "external", strlen(codec_type)) == 0)) {
7793 ALOGD("%s: Matched device name:%s, overwrite intf name with %s",
Karthik Reddy Kattae4078ed2015-04-21 11:46:15 +05307794 __func__, device_name, intf_name);
7795
Karthik Reddy Katta508eca42015-05-11 13:43:18 +05307796 strlcpy(audio_device_to_interface_table[i].interface_name, intf_name,
Karthik Reddy Kattae4078ed2015-04-21 11:46:15 +05307797 sizeof(audio_device_to_interface_table[i].interface_name));
Karthik Reddy Katta508eca42015-05-11 13:43:18 +05307798 } else if (!is_external_codec &&
7799 (strncmp(codec_type, "internal", strlen(codec_type)) == 0)) {
7800 ALOGD("%s: Matched device name:%s, overwrite intf name with %s",
7801 __func__, device_name, intf_name);
7802
7803 strlcpy(audio_device_to_interface_table[i].interface_name, intf_name,
7804 sizeof(audio_device_to_interface_table[i].interface_name));
7805 } else
7806 ALOGE("Invalid codec_type specified. Ignoring this interface entry.");
Karthik Reddy Kattae4078ed2015-04-21 11:46:15 +05307807 goto done;
7808 }
7809 }
7810 ALOGE("%s: Could not find matching device name %s",
7811 __func__, device_name);
7812
7813 ret = -EINVAL;
7814
7815done:
7816 return ret;
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -08007817}
Laxminath Kasam82252432015-05-29 18:37:11 +05307818
Venkata Narendra Kumar Gutta7f4817f2016-01-29 14:15:53 +05307819int platform_spkr_prot_is_wsa_analog_mode(void *adev)
Preetam Singh Ranawat9519e9c2015-11-18 16:05:55 +05307820{
7821 struct audio_device *adev_h = adev;
Alexy Josephb1379942016-01-29 15:49:38 -08007822 const char *snd_card_name;
Preetam Singh Ranawat9519e9c2015-11-18 16:05:55 +05307823
Venkata Narendra Kumar Gutta7f4817f2016-01-29 14:15:53 +05307824 /*
7825 * wsa analog mode is decided based on the sound card name
7826 */
Preetam Singh Ranawat9519e9c2015-11-18 16:05:55 +05307827 snd_card_name = mixer_get_name(adev_h->mixer);
7828 if ((!strcmp(snd_card_name, "msm8952-skum-snd-card")) ||
7829 (!strcmp(snd_card_name, "msm8952-snd-card")) ||
7830 (!strcmp(snd_card_name, "msm8952-snd-card-mtp")) ||
Venkata Narendra Kumar Gutta7f4817f2016-01-29 14:15:53 +05307831 (!strcmp(snd_card_name, "msm8976-skun-snd-card")) ||
Vaishnavi Kommaraju9ddcfc62018-03-23 17:26:44 +05307832 (!strcmp(snd_card_name, "msm8953-snd-card-mtp")) ||
7833 (!strcmp(snd_card_name, "msm8953-sku4-snd-card")) ||
Xiaojun Sangb3dd8f52018-06-28 21:07:12 +08007834 (!strcmp(snd_card_name, "sdm439-sku1-snd-card")) ||
Vaishnavi Kommaraju9ddcfc62018-03-23 17:26:44 +05307835 (!strcmp(snd_card_name, "sdm439-snd-card-mtp")))
Preetam Singh Ranawat9519e9c2015-11-18 16:05:55 +05307836 return 1;
7837 else
7838 return 0;
7839}
Preetam Singh Ranawat61716b12015-12-14 11:55:24 +05307840
Preetam Singh Ranawatbfec31e2017-05-04 11:51:50 +05307841static bool can_enable_mbdrc_on_device(snd_device_t snd_device)
7842{
7843 bool ret = false;
7844
7845 if (snd_device == SND_DEVICE_OUT_SPEAKER ||
7846 snd_device == SND_DEVICE_OUT_SPEAKER_WSA ||
7847 snd_device == SND_DEVICE_OUT_SPEAKER_VBAT ||
7848 snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_VBAT ||
7849 snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_2_VBAT ||
7850 snd_device == SND_DEVICE_OUT_VOICE_SPEAKER ||
7851 snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_2 ||
Manisha Agarwaled9c4542019-02-08 14:58:48 +05307852 snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_STEREO ||
Preetam Singh Ranawatbfec31e2017-05-04 11:51:50 +05307853 snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_WSA ||
7854 snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_2_WSA) {
7855 ret = true;
7856 }
7857 return ret;
7858}
7859
Sharad Sangleaca972a2017-01-25 12:38:22 +05307860bool platform_send_gain_dep_cal(void *platform,
7861 int level )
Preetam Singh Ranawat61716b12015-12-14 11:55:24 +05307862{
Sharad Sangleaca972a2017-01-25 12:38:22 +05307863 bool ret_val = false;
7864 struct platform_data *my_data = (struct platform_data *)platform;
7865 struct audio_device *adev = my_data->adev;
7866 int acdb_dev_id, app_type;
7867 int acdb_dev_type = MSM_SNDDEV_CAP_RX;
7868 int mode = CAL_MODE_RTAC;
7869 struct listnode *node;
7870 struct audio_usecase *usecase;
7871
7872 if (my_data->acdb_send_gain_dep_cal == NULL) {
7873 ALOGE("%s: dlsym error for acdb_send_gain_dep_cal", __func__);
7874 return ret_val;
7875 }
7876
7877 if (!voice_is_in_call(adev)) {
7878 ALOGV("%s: Not Voice call usecase, apply new cal for level %d",
7879 __func__, level);
7880
7881 // find the current active sound device
7882 list_for_each(node, &adev->usecase_list) {
7883 usecase = node_to_item(node, struct audio_usecase, list);
7884
Sujin Panicker390724d2019-04-26 10:43:36 +05307885 if (usecase != NULL && usecase->stream.out &&
7886 usecase->type == PCM_PLAYBACK) {
Preetam Singh Ranawatbfec31e2017-05-04 11:51:50 +05307887 int new_snd_device[2] = {0};
7888 int i, num_devices = 1;
Sharad Sangleaca972a2017-01-25 12:38:22 +05307889
7890 ALOGV("%s: out device is %d", __func__, usecase->out_snd_device);
7891 app_type = usecase->stream.out->app_type_cfg.app_type;
Preetam Singh Ranawatafe17c72017-05-16 13:12:34 +05307892 acdb_dev_id = acdb_device_table[usecase->out_snd_device];
Sharad Sangleaca972a2017-01-25 12:38:22 +05307893
Preetam Singh Ranawatbfec31e2017-05-04 11:51:50 +05307894 if (platform_split_snd_device(my_data, usecase->out_snd_device,
7895 &num_devices, new_snd_device) < 0)
7896 new_snd_device[0] = usecase->out_snd_device;
7897
7898 for (i = 0; i < num_devices; i++)
7899 if (can_enable_mbdrc_on_device(new_snd_device[i])) {
7900 if (audio_extn_spkr_prot_is_enabled())
7901 acdb_dev_id = platform_get_spkr_prot_acdb_id(new_snd_device[i]);
7902 else
7903 acdb_dev_id = acdb_device_table[new_snd_device[i]];
7904 }
Sharad Sangleaca972a2017-01-25 12:38:22 +05307905
7906 if (!my_data->acdb_send_gain_dep_cal(acdb_dev_id, app_type,
7907 acdb_dev_type, mode, level)) {
7908 // set ret_val true if at least one calibration is set successfully
7909 ret_val = true;
7910 } else {
7911 ALOGE("%s: my_data->acdb_send_gain_dep_cal failed ", __func__);
7912 }
7913 } else {
7914 ALOGW("%s: Usecase list is empty", __func__);
7915 }
7916 }
7917 } else {
7918 ALOGW("%s: Voice call in progress .. ignore setting new cal",
7919 __func__);
7920 }
7921 return ret_val;
Preetam Singh Ranawat61716b12015-12-14 11:55:24 +05307922}
Xiaojun Sang040cc9f2015-08-03 19:38:28 +08007923
7924bool platform_can_enable_spkr_prot_on_device(snd_device_t snd_device)
7925{
7926 bool ret = false;
7927
7928 if (snd_device == SND_DEVICE_OUT_SPEAKER ||
Vignesh Kulothungan3b5fae52017-09-25 12:16:30 -07007929 snd_device == SND_DEVICE_OUT_SPEAKER_REVERSE ||
Xiaojun Sang040cc9f2015-08-03 19:38:28 +08007930 snd_device == SND_DEVICE_OUT_SPEAKER_WSA ||
7931 snd_device == SND_DEVICE_OUT_SPEAKER_VBAT ||
7932 snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_VBAT ||
Rohit kumarf4120402016-08-05 19:19:48 +05307933 snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_2_VBAT ||
Xiaojun Sang040cc9f2015-08-03 19:38:28 +08007934 snd_device == SND_DEVICE_OUT_VOICE_SPEAKER ||
Rohit kumarf4120402016-08-05 19:19:48 +05307935 snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_2 ||
Manisha Agarwaled9c4542019-02-08 14:58:48 +05307936 snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_STEREO ||
Rohit kumarf4120402016-08-05 19:19:48 +05307937 snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_WSA ||
7938 snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_2_WSA) {
Xiaojun Sang040cc9f2015-08-03 19:38:28 +08007939 ret = true;
7940 }
7941
7942 return ret;
7943}
7944
7945int platform_get_spkr_prot_acdb_id(snd_device_t snd_device)
7946{
7947 int acdb_id;
7948
7949 switch(snd_device) {
7950 case SND_DEVICE_OUT_SPEAKER:
7951 case SND_DEVICE_OUT_SPEAKER_WSA:
7952 acdb_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_SPEAKER_PROTECTED);
7953 break;
7954 case SND_DEVICE_OUT_VOICE_SPEAKER:
7955 case SND_DEVICE_OUT_VOICE_SPEAKER_WSA:
7956 acdb_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED);
7957 break;
Rohit kumarf4120402016-08-05 19:19:48 +05307958 case SND_DEVICE_OUT_VOICE_SPEAKER_2:
7959 case SND_DEVICE_OUT_VOICE_SPEAKER_2_WSA:
7960 acdb_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_VOICE_SPEAKER_2_PROTECTED);
7961 break;
Vikram Panduranga8c68e862018-04-27 12:59:42 -07007962 case SND_DEVICE_OUT_VOICE_SPEAKER_STEREO:
7963 acdb_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_VOICE_SPEAKER_STEREO_PROTECTED);
7964 break;
Xiaojun Sang040cc9f2015-08-03 19:38:28 +08007965 case SND_DEVICE_OUT_SPEAKER_VBAT:
7966 acdb_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_SPEAKER_PROTECTED_VBAT);
7967 break;
7968 case SND_DEVICE_OUT_VOICE_SPEAKER_VBAT:
7969 acdb_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED_VBAT);
7970 break;
Rohit kumarf4120402016-08-05 19:19:48 +05307971 case SND_DEVICE_OUT_VOICE_SPEAKER_2_VBAT:
7972 acdb_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_VOICE_SPEAKER_2_PROTECTED_VBAT);
7973 break;
Xiaojun Sang040cc9f2015-08-03 19:38:28 +08007974 default:
7975 acdb_id = -EINVAL;
7976 break;
7977 }
7978 return acdb_id;
7979}
7980
7981int platform_get_spkr_prot_snd_device(snd_device_t snd_device)
7982{
7983 if (!audio_extn_spkr_prot_is_enabled())
7984 return snd_device;
7985
7986 switch(snd_device) {
7987 case SND_DEVICE_OUT_SPEAKER:
7988 case SND_DEVICE_OUT_SPEAKER_WSA:
7989 return SND_DEVICE_OUT_SPEAKER_PROTECTED;
7990 case SND_DEVICE_OUT_VOICE_SPEAKER:
7991 case SND_DEVICE_OUT_VOICE_SPEAKER_WSA:
7992 return SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED;
Rohit kumarf4120402016-08-05 19:19:48 +05307993 case SND_DEVICE_OUT_VOICE_SPEAKER_2:
7994 case SND_DEVICE_OUT_VOICE_SPEAKER_2_WSA:
7995 return SND_DEVICE_OUT_VOICE_SPEAKER_2_PROTECTED;
Vikram Panduranga8c68e862018-04-27 12:59:42 -07007996 case SND_DEVICE_OUT_VOICE_SPEAKER_STEREO:
7997 return SND_DEVICE_OUT_VOICE_SPEAKER_STEREO_PROTECTED;
Xiaojun Sang040cc9f2015-08-03 19:38:28 +08007998 case SND_DEVICE_OUT_SPEAKER_VBAT:
7999 return SND_DEVICE_OUT_SPEAKER_PROTECTED_VBAT;
8000 case SND_DEVICE_OUT_VOICE_SPEAKER_VBAT:
8001 return SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED_VBAT;
Rohit kumarf4120402016-08-05 19:19:48 +05308002 case SND_DEVICE_OUT_VOICE_SPEAKER_2_VBAT:
8003 return SND_DEVICE_OUT_VOICE_SPEAKER_2_PROTECTED_VBAT;
Xiaojun Sang040cc9f2015-08-03 19:38:28 +08008004 default:
8005 return snd_device;
8006 }
8007}
Kuirong Wang1cad7142016-05-24 15:21:56 -07008008
Rohit kumarf4120402016-08-05 19:19:48 +05308009int platform_get_vi_feedback_snd_device(snd_device_t snd_device)
8010{
8011 switch(snd_device) {
8012 case SND_DEVICE_OUT_SPEAKER_PROTECTED:
8013 case SND_DEVICE_OUT_SPEAKER_PROTECTED_VBAT:
Vikram Panduranga8c68e862018-04-27 12:59:42 -07008014 case SND_DEVICE_OUT_VOICE_SPEAKER_STEREO_PROTECTED:
Rohit kumarf4120402016-08-05 19:19:48 +05308015 return SND_DEVICE_IN_CAPTURE_VI_FEEDBACK;
8016 case SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED:
8017 case SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED_VBAT:
8018 return SND_DEVICE_IN_CAPTURE_VI_FEEDBACK_MONO_1;
8019 case SND_DEVICE_OUT_VOICE_SPEAKER_2_PROTECTED:
8020 case SND_DEVICE_OUT_VOICE_SPEAKER_2_PROTECTED_VBAT:
8021 return SND_DEVICE_IN_CAPTURE_VI_FEEDBACK_MONO_2;
8022 default:
8023 return SND_DEVICE_IN_CAPTURE_VI_FEEDBACK;
8024 }
8025}
8026
Garmond Leunge2433c32017-09-28 21:51:22 -07008027int platform_get_ec_ref_loopback_snd_device(int channel_count)
8028{
8029 snd_device_t snd_device;
8030
8031 if (channel_count == 1)
8032 snd_device = SND_DEVICE_IN_EC_REF_LOOPBACK_MONO;
8033 else if (channel_count == 2)
8034 snd_device = SND_DEVICE_IN_EC_REF_LOOPBACK_STEREO;
8035 else
8036 snd_device = SND_DEVICE_NONE;
8037
8038 return snd_device;
8039}
8040
Kuirong Wang1cad7142016-05-24 15:21:56 -07008041int platform_set_sidetone(struct audio_device *adev,
8042 snd_device_t out_snd_device,
8043 bool enable,
8044 char *str)
8045{
8046 int ret;
Ashish Jain3e37a702016-11-25 12:27:15 +05308047 if ((out_snd_device == SND_DEVICE_OUT_USB_HEADSET) ||
8048 (out_snd_device == SND_DEVICE_OUT_USB_HEADPHONES)) {
Aniket Kumar Lata8fc67e62017-05-02 12:33:46 -07008049 if (property_get_bool("vendor.audio.usb.disable.sidetone", 0)) {
Haynes Mathew Georgeb2789322016-11-22 11:55:40 -08008050 ALOGI("Debug: Disable sidetone");
8051 } else {
Kuirong Wang1cad7142016-05-24 15:21:56 -07008052 ret = audio_extn_usb_enable_sidetone(out_snd_device, enable);
Vikram Panduranga6e761cd2016-10-12 16:50:52 -07008053 if (ret) {
8054 /*fall back to AFE sidetone*/
8055 ALOGV("%s: No USB sidetone supported, switching to AFE sidetone",
8056 __func__);
8057
8058 if (enable)
8059 audio_route_apply_and_update_path(adev->audio_route, AFE_SIDETONE_MIXER_PATH);
8060 else
8061 audio_route_reset_and_update_path(adev->audio_route, AFE_SIDETONE_MIXER_PATH);
8062 }
8063 }
Kuirong Wang1cad7142016-05-24 15:21:56 -07008064 } else {
8065 ALOGV("%s: sidetone out device(%d) mixer cmd = %s\n",
8066 __func__, out_snd_device, str);
8067
Vikram Panduranga6e761cd2016-10-12 16:50:52 -07008068 if (enable) {
8069 ret = audio_route_apply_and_update_path(adev->audio_route, str);
8070 if (ret) {
8071 ALOGV("%s: No device sidetone supported, switching to AFE sidetone",
8072 __func__);
8073 audio_route_apply_and_update_path(adev->audio_route, AFE_SIDETONE_MIXER_PATH);
8074 }
8075 } else {
8076 ret = audio_route_reset_and_update_path(adev->audio_route, str);
8077 if (ret) {
8078 ALOGV("%s: No device sidetone supported, switching to AFE sidetone",
8079 __func__);
8080 audio_route_reset_and_update_path(adev->audio_route, AFE_SIDETONE_MIXER_PATH);
8081 }
8082 }
Kuirong Wang1cad7142016-05-24 15:21:56 -07008083 }
8084 return 0;
8085}
Preetam Singh Ranawatcb6212e2016-07-19 18:33:53 +05308086
Laxminath Kasameda80032017-04-11 23:06:32 +05308087void platform_update_aanc_path(struct audio_device *adev,
8088 snd_device_t out_snd_device,
8089 bool enable,
8090 char *str)
Vidyakumar Athotaea269c62016-10-31 09:05:59 -07008091{
Laxminath Kasameda80032017-04-11 23:06:32 +05308092 ALOGD("%s: aanc out device(%d) mixer cmd = %s, enable = %d\n",
8093 __func__, out_snd_device, str, enable);
8094
8095 if (enable)
8096 audio_route_apply_and_update_path(adev->audio_route, str);
8097 else
8098 audio_route_reset_and_update_path(adev->audio_route, str);
8099
Vidyakumar Athotaea269c62016-10-31 09:05:59 -07008100 return;
8101}
8102
Aditya Bavanari29bcea22017-10-03 20:10:35 +05308103#ifdef INSTANCE_ID_ENABLED
8104void platform_make_cal_cfg(acdb_audio_cal_cfg_t* cal, int acdb_dev_id,
8105 int acdb_device_type, int app_type, int topology_id,
8106 int sample_rate, uint32_t module_id, uint16_t instance_id,
8107 uint32_t param_id, bool persist)
8108{
8109 int persist_send_flags = 1;
8110
8111 if (!cal) {
8112 return;
8113 }
8114
8115 if (persist)
8116 persist_send_flags |= 0x2;
8117
8118 memset(cal, 0, sizeof(acdb_audio_cal_cfg_t));
8119
8120 cal->persist = persist;
8121 cal->app_type = app_type;
8122 cal->acdb_dev_id = acdb_dev_id;
8123 cal->sampling_rate = sample_rate;
8124 cal->topo_id = topology_id;
8125 //if module and param id is set to 0, the whole blob will be stored
8126 //or sent to the DSP
8127 cal->module_id = module_id;
8128 cal->instance_id = instance_id;
8129 cal->param_id = param_id;
8130 cal->cal_type = acdb_device_type;
8131}
8132#else
8133void platform_make_cal_cfg(acdb_audio_cal_cfg_t* cal, int acdb_dev_id,
Weiyin Jiang82e40942017-01-10 16:07:34 +08008134 int acdb_device_type, int app_type, int topology_id,
8135 int sample_rate, uint32_t module_id, uint32_t param_id, bool persist)
Weiyin Jiangaa80acd2016-09-21 16:42:11 +08008136{
Weiyin Jiang82e40942017-01-10 16:07:34 +08008137 int persist_send_flags = 1;
8138
8139 if (!cal) {
8140 return;
8141 }
8142
8143 if (persist)
8144 persist_send_flags |= 0x2;
8145
8146 memset(cal, 0, sizeof(acdb_audio_cal_cfg_t));
8147
8148 cal->persist = persist;
8149 cal->app_type = app_type;
8150 cal->acdb_dev_id = acdb_dev_id;
8151 cal->sampling_rate = sample_rate;
8152 cal->topo_id = topology_id;
8153 //if module and param id is set to 0, the whole blob will be stored
8154 //or sent to the DSP
8155 cal->module_id = module_id;
8156 cal->param_id = param_id;
8157 cal->cal_type = acdb_device_type;
Weiyin Jiangaa80acd2016-09-21 16:42:11 +08008158}
Aditya Bavanari29bcea22017-10-03 20:10:35 +05308159#endif
Weiyin Jiangaa80acd2016-09-21 16:42:11 +08008160
Aditya Bavanari29bcea22017-10-03 20:10:35 +05308161int platform_send_audio_cal(void* platform, acdb_audio_cal_cfg_t* cal,
8162 void* data, int length, bool persist)
Weiyin Jiangaa80acd2016-09-21 16:42:11 +08008163{
Weiyin Jiang82e40942017-01-10 16:07:34 +08008164 int ret = 0;
8165 struct platform_data *my_data = (struct platform_data *)platform;
Weiyin Jiang82e40942017-01-10 16:07:34 +08008166
8167 if (!my_data) {
8168 ret = -EINVAL;
8169 goto ERROR_RETURN;
8170 }
8171
Weiyin Jiang82e40942017-01-10 16:07:34 +08008172 if (my_data->acdb_set_audio_cal) {
8173 // persist audio cal in local cache
8174 if (persist) {
Vignesh Kulothungand477f692018-05-29 14:33:24 -07008175 ret = my_data->acdb_set_audio_cal((void*)cal, data, (uint32_t)length);
Weiyin Jiang82e40942017-01-10 16:07:34 +08008176 }
8177 // send audio cal to dsp
8178 if (ret == 0) {
Aditya Bavanari29bcea22017-10-03 20:10:35 +05308179 cal->persist = false;
Vignesh Kulothungand477f692018-05-29 14:33:24 -07008180 ret = my_data->acdb_set_audio_cal((void*)cal, data, (uint32_t)length);
Weiyin Jiang82e40942017-01-10 16:07:34 +08008181 if (persist && (ret != 0)) {
8182 ALOGV("[%s] audio cal stored with success, ignore set cal failure", __func__);
8183 ret = 0;
8184 }
8185 }
8186 }
8187
8188ERROR_RETURN:
8189 return ret;
Weiyin Jiangaa80acd2016-09-21 16:42:11 +08008190}
8191
Aditya Bavanari29bcea22017-10-03 20:10:35 +05308192int platform_get_audio_cal(void* platform, acdb_audio_cal_cfg_t* cal,
Weiyin Jiang82e40942017-01-10 16:07:34 +08008193 void* data, int* length, bool persist)
Weiyin Jiangaa80acd2016-09-21 16:42:11 +08008194{
Weiyin Jiang82e40942017-01-10 16:07:34 +08008195 int ret = 0;
8196 struct platform_data *my_data = (struct platform_data *)platform;
Weiyin Jiang82e40942017-01-10 16:07:34 +08008197
8198 if (!my_data) {
8199 ret = -EINVAL;
8200 goto ERROR_RETURN;
8201 }
8202
Weiyin Jiang82e40942017-01-10 16:07:34 +08008203 if (my_data->acdb_get_audio_cal) {
8204 // get cal from dsp
Vignesh Kulothungand477f692018-05-29 14:33:24 -07008205 ret = my_data->acdb_get_audio_cal((void*)cal, data, (uint32_t*)length);
Weiyin Jiang82e40942017-01-10 16:07:34 +08008206 // get cached cal if prevoius attempt fails and persist flag is set
8207 if ((ret != 0) && persist) {
Aditya Bavanari29bcea22017-10-03 20:10:35 +05308208 cal->persist = true;
Vignesh Kulothungand477f692018-05-29 14:33:24 -07008209 ret = my_data->acdb_get_audio_cal((void*)cal, data, (uint32_t*)length);
Weiyin Jiang82e40942017-01-10 16:07:34 +08008210 }
8211 }
8212
8213ERROR_RETURN:
8214 return ret;
Weiyin Jiangaa80acd2016-09-21 16:42:11 +08008215}
8216
Aditya Bavanari29bcea22017-10-03 20:10:35 +05308217int platform_store_audio_cal(void* platform, acdb_audio_cal_cfg_t* cal,
Weiyin Jiang82e40942017-01-10 16:07:34 +08008218 void* data, int length)
Weiyin Jiangaa80acd2016-09-21 16:42:11 +08008219{
Weiyin Jiang82e40942017-01-10 16:07:34 +08008220 int ret = 0;
8221 struct platform_data *my_data = (struct platform_data *)platform;
Weiyin Jiang82e40942017-01-10 16:07:34 +08008222
8223 if (!my_data) {
8224 ret = -EINVAL;
8225 goto ERROR_RETURN;
8226 }
8227
Weiyin Jiang82e40942017-01-10 16:07:34 +08008228 if (my_data->acdb_set_audio_cal) {
Vignesh Kulothungand477f692018-05-29 14:33:24 -07008229 ret = my_data->acdb_set_audio_cal((void*)cal, data, (uint32_t)length);
Weiyin Jiang82e40942017-01-10 16:07:34 +08008230 }
8231
8232ERROR_RETURN:
8233 return ret;
8234}
8235
Aditya Bavanari29bcea22017-10-03 20:10:35 +05308236int platform_retrieve_audio_cal(void* platform, acdb_audio_cal_cfg_t* cal,
Weiyin Jiang82e40942017-01-10 16:07:34 +08008237 void* data, int* length)
8238{
8239 int ret = 0;
8240 struct platform_data *my_data = (struct platform_data *)platform;
Weiyin Jiang82e40942017-01-10 16:07:34 +08008241
8242 if (!my_data) {
8243 ret = -EINVAL;
8244 goto ERROR_RETURN;
8245 }
8246
Weiyin Jiang82e40942017-01-10 16:07:34 +08008247 if (my_data->acdb_get_audio_cal) {
Vignesh Kulothungand477f692018-05-29 14:33:24 -07008248 ret = my_data->acdb_get_audio_cal((void*)cal, data, (uint32_t*)length);
Weiyin Jiang82e40942017-01-10 16:07:34 +08008249 }
8250
8251ERROR_RETURN:
8252 return ret;
Weiyin Jiangaa80acd2016-09-21 16:42:11 +08008253}
Divya Narayanan Poojary45f19192016-09-30 18:52:13 +05308254
8255int platform_get_max_mic_count(void *platform) {
8256 struct platform_data *my_data = (struct platform_data *)platform;
8257 return my_data->max_mic_count;
8258}
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -07008259
Vignesh Kulothungan3b5fae52017-09-25 12:16:30 -07008260#define DEFAULT_NOMINAL_SPEAKER_GAIN 20
8261int ramp_speaker_gain(struct audio_device *adev, bool ramp_up, int target_ramp_up_gain) {
8262 // backup_gain: gain to try to set in case of an error during ramp
8263 int start_gain, end_gain, step, backup_gain, i;
8264 bool error = false;
8265 const char *mixer_ctl_name_gain_left = "Left Speaker Gain";
8266 const char *mixer_ctl_name_gain_right = "Right Speaker Gain";
8267 struct mixer_ctl *ctl_left = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_left);
8268 struct mixer_ctl *ctl_right = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_right);
8269 if (!ctl_left || !ctl_right) {
8270 ALOGE("%s: Could not get ctl for mixer cmd - %s or %s, not applying speaker gain ramp",
8271 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
8272 return -EINVAL;
8273 } else if ((mixer_ctl_get_num_values(ctl_left) != 1)
8274 || (mixer_ctl_get_num_values(ctl_right) != 1)) {
8275 ALOGE("%s: Unexpected num values for mixer cmd - %s or %s, not applying speaker gain ramp",
8276 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
8277 return -EINVAL;
8278 }
8279 if (ramp_up) {
8280 start_gain = 0;
8281 end_gain = target_ramp_up_gain > 0 ? target_ramp_up_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
8282 step = +1;
8283 backup_gain = end_gain;
8284 } else {
8285 // using same gain on left and right
8286 const int left_gain = mixer_ctl_get_value(ctl_left, 0);
8287 start_gain = left_gain > 0 ? left_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
8288 end_gain = 0;
8289 step = -1;
8290 backup_gain = start_gain;
8291 }
8292 for (i = start_gain ; i != (end_gain + step) ; i += step) {
8293 if (mixer_ctl_set_value(ctl_left, 0, i)) {
8294 ALOGE("%s: error setting %s to %d during gain ramp",
8295 __func__, mixer_ctl_name_gain_left, i);
8296 error = true;
8297 break;
8298 }
8299 if (mixer_ctl_set_value(ctl_right, 0, i)) {
8300 ALOGE("%s: error setting %s to %d during gain ramp",
8301 __func__, mixer_ctl_name_gain_right, i);
8302 error = true;
8303 break;
8304 }
8305 usleep(1000);
8306 }
8307 if (error) {
8308 // an error occured during the ramp, let's still try to go back to a safe volume
8309 if (mixer_ctl_set_value(ctl_left, 0, backup_gain)) {
8310 ALOGE("%s: error restoring left gain to %d", __func__, backup_gain);
8311 }
8312 if (mixer_ctl_set_value(ctl_right, 0, backup_gain)) {
8313 ALOGE("%s: error restoring right gain to %d", __func__, backup_gain);
8314 }
8315 }
8316 return start_gain;
8317}
8318
8319int platform_set_swap_mixer(struct audio_device *adev, bool swap_channels)
8320{
8321 const char *mixer_ctl_name = "Swap channel";
8322 struct mixer_ctl *ctl;
Vignesh Kulothungan3b5fae52017-09-25 12:16:30 -07008323 struct platform_data *my_data = (struct platform_data *)adev->platform;
8324
8325 // forced to set to swap, but device not rotated ... ignore set
8326 if (swap_channels && !my_data->speaker_lr_swap)
8327 return 0;
8328
8329 ALOGV("%s:", __func__);
8330
Vignesh Kulothungan3b5fae52017-09-25 12:16:30 -07008331 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
8332 if (!ctl) {
8333 ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name);
8334 return -EINVAL;
8335 }
8336
8337 if (mixer_ctl_set_value(ctl, 0, swap_channels) < 0) {
8338 ALOGE("%s: Could not set reverse cotrol %d",__func__, swap_channels);
8339 return -EINVAL;
8340 }
8341
8342 ALOGV("platfor_force_swap_channel :: Channel orientation ( %s ) ",
8343 swap_channels?"R --> L":"L --> R");
8344
8345 return 0;
8346}
8347
8348int platform_check_and_set_swap_lr_channels(struct audio_device *adev, bool swap_channels)
8349{
8350 // only update if there is active pcm playback on speaker
8351 struct platform_data *my_data = (struct platform_data *)adev->platform;
8352
8353 my_data->speaker_lr_swap = swap_channels;
8354
8355 return platform_set_swap_channels(adev, swap_channels);
8356}
8357
8358int platform_set_swap_channels(struct audio_device *adev, bool swap_channels)
8359{
8360 // only update if there is active pcm playback on speaker
8361 struct audio_usecase *usecase;
8362 struct listnode *node;
8363
kunleiz43c4a6a2018-05-17 18:01:24 +08008364 //swap channels only for stereo spkr
8365 struct platform_data *my_data = (struct platform_data *)adev->platform;
8366 if (my_data) {
8367 if (!hw_info_is_stereo_spkr(my_data->hw_info)) {
8368 ALOGV("%s: will not swap due to it is not stereo spkr", __func__);
8369 return 0;
8370 }
8371 } else {
8372 ALOGE("%s: failed to allocate platform data", __func__);
8373 return -EINVAL;
8374 }
8375
Vignesh Kulothungan3b5fae52017-09-25 12:16:30 -07008376 // do not swap channels in audio modes with concurrent capture and playback
8377 // as this may break the echo reference
8378 if ((adev->mode == AUDIO_MODE_IN_COMMUNICATION) || (adev->mode == AUDIO_MODE_IN_CALL)) {
8379 ALOGV("%s: will not swap due to audio mode %d", __func__, adev->mode);
8380 return 0;
8381 }
8382
8383 list_for_each(node, &adev->usecase_list) {
8384 usecase = node_to_item(node, struct audio_usecase, list);
Sujin Panicker390724d2019-04-26 10:43:36 +05308385 if (usecase->stream.out && usecase->type == PCM_PLAYBACK &&
Vignesh Kulothungan3b5fae52017-09-25 12:16:30 -07008386 usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) {
8387 /*
8388 * If acdb tuning is different for SPEAKER_REVERSE, it is must
8389 * to perform device switch to disable the current backend to
8390 * enable it with new acdb data.
8391 */
kunleiz43c4a6a2018-05-17 18:01:24 +08008392 if (my_data->speaker_lr_swap &&
8393 (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
8394 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE])) {
Vignesh Kulothungan3b5fae52017-09-25 12:16:30 -07008395 const int initial_skpr_gain = ramp_speaker_gain(adev, false /*ramp_up*/, -1);
8396 select_devices(adev, usecase->id);
8397 if (initial_skpr_gain != -EINVAL)
8398 ramp_speaker_gain(adev, true /*ramp_up*/, initial_skpr_gain);
8399
8400 } else {
8401 platform_set_swap_mixer(adev, swap_channels);
8402 }
8403 break;
8404 }
8405 }
8406
8407 return 0;
8408}
8409
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -07008410bool platform_add_gain_level_mapping(struct amp_db_and_gain_table *tbl_entry __unused)
8411{
8412 return false;
8413}
8414
8415int platform_get_gain_level_mapping(struct amp_db_and_gain_table *mapping_tbl __unused,
8416 int table_size __unused)
8417{
8418 return 0;
8419}
Satish Babu Patakokilac3c5d432017-07-04 22:48:59 +05308420
8421int platform_get_max_codec_backend() {
8422
8423 return MAX_CODEC_BACKENDS;
8424}
Haynes Mathew Georgeef514882017-05-01 17:46:23 -07008425
Revathi Uddaraju0553e8f2017-11-30 14:56:11 +05308426int platform_get_supported_copp_sampling_rate(uint32_t stream_sr)
Venugopal Nadipalli83134582017-09-21 22:34:50 +05308427{
8428 int sample_rate;
8429 switch (stream_sr){
8430 case 8000:
8431 case 11025:
8432 case 16000:
8433 case 22050:
8434 case 32000:
8435 case 48000:
8436 sample_rate = 48000;
8437 break;
8438 case 44100:
8439 sample_rate = 44100;
8440 break;
8441 case 64000:
8442 case 96000:
8443 sample_rate = 96000;
8444 break;
8445 case 88200:
8446 sample_rate = 88200;
8447 break;
8448 case 176400:
8449 sample_rate = 176400;
8450 break;
8451 case 192000:
8452 sample_rate = 192000;
8453 break;
8454 case 352800:
8455 sample_rate = 352800;
8456 break;
8457 case 384000:
8458 sample_rate = 384000;
8459 break;
8460 case 144000:
8461 default:
8462 sample_rate = 48000;
8463 break;
8464 }
8465 return sample_rate;
8466}
8467
Haynes Mathew Georgeef514882017-05-01 17:46:23 -07008468#if defined(PLATFORM_MSMFALCON)
8469int platform_get_mmap_data_fd(void *platform, int fe_dev, int dir, int *fd,
8470 uint32_t *size)
8471{
8472 struct platform_data *my_data = (struct platform_data *)platform;
8473 struct audio_device *adev = my_data->adev;
8474 int hw_fd = -1;
8475 char dev_name[128];
8476 struct snd_pcm_mmap_fd mmap_fd;
8477 memset(&mmap_fd, 0, sizeof(mmap_fd));
8478 mmap_fd.dir = dir;
8479 snprintf(dev_name, sizeof(dev_name), "/dev/snd/hwC%uD%u",
8480 adev->snd_card, HWDEP_FE_BASE+fe_dev);
8481 hw_fd = open(dev_name, O_RDONLY);
8482 if (hw_fd < 0) {
8483 ALOGE("fe hw dep node open %d/%d failed", adev->snd_card, fe_dev);
8484 return -1;
8485 }
8486 if (ioctl(hw_fd, SNDRV_PCM_IOCTL_MMAP_DATA_FD, &mmap_fd) < 0) {
8487 ALOGE("fe hw dep node ioctl failed");
8488 close(hw_fd);
8489 return -1;
8490 }
8491 *fd = mmap_fd.fd;
8492 *size = mmap_fd.size;
8493 close(hw_fd); // mmap_fd should still be valid
8494 return 0;
8495}
8496#else
8497int platform_get_mmap_data_fd(void *platform __unused, int fe_dev __unused,
8498 int dir __unused, int *fd __unused,
8499 uint32_t *size __unused)
8500{
8501 return -1;
8502}
8503#endif
`Deeraj Soman676c2702017-09-18 19:25:53 +05308504
8505static const char *platform_get_mixer_control(struct mixer_ctl *ctl)
8506{
8507 int id = -1;
8508 const char *id_string = NULL;
8509
8510 if (!ctl) {
8511 ALOGD("%s: mixer ctl not obtained", __func__);
8512 } else {
8513 id = mixer_ctl_get_value(ctl, 0);
8514 if (id >= 0) {
8515 id_string = mixer_ctl_get_enum_string(ctl, id);
8516 }
8517 }
8518
8519 return id_string;
8520}
Naresh Tannirudcb47c52018-06-25 16:23:32 +05308521
Ramjee Singh33412cb2018-07-02 18:21:30 +05308522bool platform_set_microphone_characteristic(void *platform,
8523 struct audio_microphone_characteristic_t mic) {
8524 struct platform_data *my_data = (struct platform_data *)platform;
8525 if (my_data->declared_mic_count >= AUDIO_MICROPHONE_MAX_COUNT) {
8526 ALOGE("mic number is more than maximum number");
8527 return false;
8528 }
8529 for (size_t ch = 0; ch < AUDIO_CHANNEL_COUNT_MAX; ch++) {
8530 mic.channel_mapping[ch] = AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED;
8531 }
8532 my_data->microphones[my_data->declared_mic_count++] = mic;
8533 return true;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05308534}
8535
Ramjee Singh33412cb2018-07-02 18:21:30 +05308536int platform_get_microphones(void *platform,
8537 struct audio_microphone_characteristic_t *mic_array,
8538 size_t *mic_count) {
8539 struct platform_data *my_data = (struct platform_data *)platform;
8540 if (mic_count == NULL)
8541 return -EINVAL;
8542 if (mic_array == NULL)
8543 return -EINVAL;
8544
8545 if (*mic_count == 0) {
8546 *mic_count = my_data->declared_mic_count;
8547 return 0;
8548 }
8549
8550 size_t max_mic_count = *mic_count;
8551 size_t actual_mic_count = 0;
8552 for (size_t i = 0; i < max_mic_count && i < my_data->declared_mic_count; i++) {
8553 mic_array[i] = my_data->microphones[i];
8554 actual_mic_count++;
8555 }
8556 *mic_count = actual_mic_count;
8557 ALOGV("%s: returning number of mics %d", __func__, (int)*mic_count);
8558 return 0;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05308559}
8560
Ramjee Singh33412cb2018-07-02 18:21:30 +05308561bool platform_set_microphone_map(void *platform, snd_device_t in_snd_device,
8562 const struct mic_info *info) {
8563 struct platform_data *my_data = (struct platform_data *)platform;
8564 if (in_snd_device < SND_DEVICE_IN_BEGIN || in_snd_device >= SND_DEVICE_IN_END) {
8565 ALOGE("%s: Sound device not valid", __func__);
8566 return false;
8567 }
8568 size_t m_count = my_data->mic_map[in_snd_device].mic_count++;
8569 if (m_count >= AUDIO_MICROPHONE_MAX_COUNT) {
8570 ALOGE("%s: Microphone count is greater than max allowed value", __func__);
8571 my_data->mic_map[in_snd_device].mic_count--;
8572 return false;
8573 }
8574 my_data->mic_map[in_snd_device].microphones[m_count] = *info;
8575 return true;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05308576}
8577
Ramjee Singh33412cb2018-07-02 18:21:30 +05308578int platform_get_active_microphones(void *platform, unsigned int channels,
8579 audio_usecase_t uc_id,
8580 struct audio_microphone_characteristic_t *mic_array,
8581 size_t *mic_count) {
8582 struct platform_data *my_data = (struct platform_data *)platform;
8583 struct audio_usecase *usecase = get_usecase_from_list(my_data->adev, uc_id);
8584 if (mic_count == NULL || mic_array == NULL || usecase == NULL) {
8585 return -EINVAL;
8586 }
8587 size_t max_mic_count = my_data->declared_mic_count;
8588 size_t actual_mic_count = 0;
8589
8590 snd_device_t active_input_snd_device =
Eric Laurent637e2d42018-11-15 12:24:31 -08008591 platform_get_input_snd_device(platform, usecase->stream.in, AUDIO_DEVICE_NONE);
Ramjee Singh33412cb2018-07-02 18:21:30 +05308592 if (active_input_snd_device == SND_DEVICE_NONE) {
8593 ALOGI("%s: No active microphones found", __func__);
8594 goto end;
8595 }
8596
8597 size_t active_mic_count = my_data->mic_map[active_input_snd_device].mic_count;
8598 struct mic_info *m_info = my_data->mic_map[active_input_snd_device].microphones;
8599
8600 for (size_t i = 0; i < active_mic_count; i++) {
8601 unsigned int channels_for_active_mic = channels;
8602 if (channels_for_active_mic > m_info[i].channel_count) {
8603 channels_for_active_mic = m_info[i].channel_count;
8604 }
8605 for (size_t j = 0; j < max_mic_count; j++) {
8606 if (strcmp(my_data->microphones[j].device_id,
8607 m_info[i].device_id) == 0) {
8608 mic_array[actual_mic_count] = my_data->microphones[j];
8609 for (size_t ch = 0; ch < channels_for_active_mic; ch++) {
8610 mic_array[actual_mic_count].channel_mapping[ch] =
8611 m_info[i].channel_mapping[ch];
8612 }
8613 actual_mic_count++;
8614 break;
8615 }
8616 }
8617 }
8618end:
8619 *mic_count = actual_mic_count;
8620 return 0;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05308621}
Vignesh Kulothungan39fc6a22019-08-01 00:55:59 -07008622
8623int platform_get_edid_info_v2(void *platform,
8624 int controller __unused,
8625 int stream __unused)
8626{
8627 return platform_get_edid_info(platform);
8628}
8629
8630int platform_edid_get_max_channels_v2(void *platform,
8631 int controller __unused,
8632 int stream __unused)
8633{
8634 return platform_edid_get_max_channels(platform);
8635}
8636
8637bool platform_is_edid_supported_format_v2(void *platform, int format,
8638 int controller __unused,
8639 int stream __unused)
8640{
8641 return platform_is_edid_supported_format(platform, format);
8642}
8643
8644bool platform_is_edid_supported_sample_rate_v2(void *platform, int format,
8645 int controller __unused,
8646 int stream __unused)
8647{
8648 return platform_is_edid_supported_sample_rate(platform, format);
8649}
8650
8651void platform_cache_edid_v2(void * platform,
8652 int controller __unused,
8653 int stream __unused)
8654{
8655 return platform_cache_edid(platform);
8656}
8657
8658void platform_invalidate_hdmi_config_v2(void * platform,
8659 int controller __unused,
8660 int stream __unused)
8661{
8662 return platform_invalidate_hdmi_config(platform);
8663}
8664
8665int platform_set_ext_display_device(void *platform, int controller, int stream)
8666{
8667 return -1;
8668}
8669
8670int platform_get_controller_stream_from_params(struct str_parms *parms,
8671 int *controller, int *stream);
8672{
8673 return -1;
8674}
8675
8676int platform_get_ext_disp_type_v2(void *platform,
8677 int controller __unused,
8678 int stream __unused)
8679{
8680 return platform_get_ext_disp_type(platform);
8681}
8682
8683int platform_set_edid_channels_configuration_v2(void *platform, int channels,
8684 int backend_idx,
8685 snd_device_t snd_device,
8686 int controller __unused,
8687 int stream __unused)
8688{
8689 return platform_set_edid_channels_configuration(platform, channels,
8690 backend_idx, snd_device);
8691}
8692
8693int platform_set_channel_allocation_v2(void *platform,
8694 int controller __unused,
8695 int stream __unused)
8696{
8697 return platform_set_channel_allocation(platform);
8698}
8699
8700int platform_set_hdmi_channels_v2(void *platform, int channel_count,
8701 int controller __unused,
8702 int stream __unused)
8703{
8704 return platform_set_hdmi_channels(platform, channel_count);
8705}
8706
8707int platform_get_display_port_ctl_index(int controller __unused,
8708 int stream __unused)
8709{
8710 return -EINVAL;
8711}
Jaideep Sharma477917f2020-03-13 18:13:33 +05308712
8713bool platform_is_call_proxy_snd_device(snd_device_t snd_device __unused) {
8714 return false;
8715}