blob: f547f1c10452c7162b6ebf7a2eb5739b01a7552b [file] [log] [blame]
Eric Laurentb23d5282013-05-14 15:27:20 -07001/*
vivek mehtaa6b79742017-03-09 15:40:43 -08002 * Copyright (C) 2013-2017 The Android Open Source Project
Eric Laurentb23d5282013-05-14 15:27:20 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Eric Laurentb23d5282013-05-14 15:27:20 -070016#define LOG_TAG "msm8974_platform"
17/*#define LOG_NDEBUG 0*/
18#define LOG_NDDEBUG 0
19
20#include <stdlib.h>
21#include <dlfcn.h>
Jiyong Park6431fe62017-06-29 15:15:58 +090022#include <pthread.h>
23#include <unistd.h>
Haynes Mathew Georgee6e2d442018-02-22 18:51:56 -080024#include <log/log.h>
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -070025#include <cutils/str_parms.h>
Eric Laurentb23d5282013-05-14 15:27:20 -070026#include <cutils/properties.h>
27#include <audio_hw.h>
28#include <platform_api.h>
vivek mehta0fb11312017-05-15 19:35:32 -070029#include "acdb.h"
Eric Laurentb23d5282013-05-14 15:27:20 -070030#include "platform.h"
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -070031#include "audio_extn.h"
vivek mehta1a9b7c02015-06-25 11:49:38 -070032#include <linux/msm_audio.h>
Thierry Strudel07f96d12018-09-20 13:31:34 -070033#if defined (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845) || (PLATFORM_SDM710) || (PLATFORM_SM8150)
Haynes Mathew George96483a22017-03-28 14:52:47 -070034#include <sound/devdep_params.h>
35#endif
Eric Laurentb23d5282013-05-14 15:27:20 -070036
jasmine cha270b7762018-03-30 15:41:33 +080037#include "maxxaudio.h"
jasmine chac89321b2018-04-10 21:37:01 +080038#include <resolv.h>
39
Jaekyun Seokf62e17d2017-03-08 17:15:28 +090040#define MIXER_XML_DEFAULT_PATH "mixer_paths.xml"
41#define MIXER_XML_BASE_STRING "mixer_paths"
vivek mehta60ea4152016-02-18 17:10:26 -080042#define TOMTOM_8226_SND_CARD_NAME "msm8226-tomtom-snd-card"
43#define TOMTOM_MIXER_FILE_SUFFIX "wcd9330"
44
Eric Laurentb23d5282013-05-14 15:27:20 -070045#define LIB_ACDB_LOADER "libacdbloader.so"
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -070046#define AUDIO_DATA_BLOCK_MIXER_CTL "HDMI EDID"
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +090047#define CVD_VERSION_MIXER_CTL "CVD Version"
Eric Laurentb23d5282013-05-14 15:27:20 -070048
Eric Laurentf9583c32016-03-28 13:50:50 -070049#define min(a, b) ((a) < (b) ? (a) : (b))
Eric Laurentb23d5282013-05-14 15:27:20 -070050
51/*
Eric Laurentb23d5282013-05-14 15:27:20 -070052 * This file will have a maximum of 38 bytes:
53 *
54 * 4 bytes: number of audio blocks
55 * 4 bytes: total length of Short Audio Descriptor (SAD) blocks
56 * Maximum 10 * 3 bytes: SAD blocks
57 */
58#define MAX_SAD_BLOCKS 10
59#define SAD_BLOCK_SIZE 3
60
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +090061#define MAX_CVD_VERSION_STRING_SIZE 100
62
Eric Laurentb23d5282013-05-14 15:27:20 -070063/* EDID format ID for LPCM audio */
64#define EDID_FORMAT_LPCM 1
65
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -070066#define MAX_SND_CARD_NAME_LEN 31
67
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -080068#define DEFAULT_APP_TYPE_RX_PATH 69936
69#define DEFAULT_APP_TYPE_TX_PATH 69938
Haynes Mathew George39c55dc2017-07-11 19:31:23 -070070#define DEFAULT_RX_BACKEND "SLIMBUS_0_RX"
vivek mehta1a9b7c02015-06-25 11:49:38 -070071
keunhui.parkc5aaa0e2015-07-13 10:57:37 +090072#define TOSTRING_(x) #x
73#define TOSTRING(x) TOSTRING_(x)
74
Vignesh Kulothungan64698822018-01-23 11:25:18 -080075#define GET_IN_DEVICE_INDEX(SND_DEVICE) ((SND_DEVICE) - (SND_DEVICE_IN_BEGIN))
76
Eric Laurentb23d5282013-05-14 15:27:20 -070077struct audio_block_header
78{
79 int reserved;
80 int length;
81};
82
vivek mehta1a9b7c02015-06-25 11:49:38 -070083enum {
84 CAL_MODE_SEND = 0x1,
85 CAL_MODE_PERSIST = 0x2,
86 CAL_MODE_RTAC = 0x4
87};
88
keunhui.park2f7306a2015-07-16 16:48:06 +090089#define PLATFORM_CONFIG_KEY_OPERATOR_INFO "operator_info"
90
91struct operator_info {
92 struct listnode list;
93 char *name;
94 char *mccmnc;
95};
96
97struct operator_specific_device {
98 struct listnode list;
99 char *operator;
100 char *mixer_path;
101 int acdb_id;
102};
103
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800104#define BE_DAI_NAME_MAX_LENGTH 24
105struct be_dai_name_struct {
106 unsigned int be_id;
107 char be_name[BE_DAI_NAME_MAX_LENGTH];
108};
109
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -0700110struct snd_device_to_mic_map {
111 struct mic_info microphones[AUDIO_MICROPHONE_MAX_COUNT];
112 size_t mic_count;
113};
114
keunhui.park2f7306a2015-07-16 16:48:06 +0900115static struct listnode operator_info_list;
116static struct listnode *operator_specific_device_table[SND_DEVICE_MAX];
117
jasmine chac89321b2018-04-10 21:37:01 +0800118#define AUDIO_PARAMETER_KEY_AUD_CALDATA "cal_data"
119
120typedef struct acdb_audio_cal_cfg {
121 uint32_t persist;
122 uint32_t snd_dev_id;
123 audio_devices_t dev_id;
124 int32_t acdb_dev_id;
125 uint32_t app_type;
126 uint32_t topo_id;
127 uint32_t sampling_rate;
128 uint32_t cal_type;
129 uint32_t module_id;
justinwenge880e0c2018-11-22 13:49:38 +0800130#ifdef PLATFORM_SM8150
131 uint16_t instance_id;
132 uint16_t reserved;
133#endif
jasmine chac89321b2018-04-10 21:37:01 +0800134 uint32_t param_id;
135} acdb_audio_cal_cfg_t;
136
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700137/* Audio calibration related functions */
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800138typedef void (*acdb_send_audio_cal_v3_t)(int, int, int, int, int);
Eric Laurentb23d5282013-05-14 15:27:20 -0700139
Eric Laurentb23d5282013-05-14 15:27:20 -0700140struct platform_data {
141 struct audio_device *adev;
142 bool fluence_in_spkr_mode;
143 bool fluence_in_voice_call;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700144 bool fluence_in_voice_comm;
Eric Laurentb23d5282013-05-14 15:27:20 -0700145 bool fluence_in_voice_rec;
Prashant Malanic92c5962015-08-11 15:10:18 -0700146 /* 0 = no fluence, 1 = fluence, 2 = fluence pro */
147 int fluence_type;
148 int source_mic_type;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -0700149 bool speaker_lr_swap;
150
Eric Laurentb23d5282013-05-14 15:27:20 -0700151 void *acdb_handle;
Thierry Strudel07f96d12018-09-20 13:31:34 -0700152#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845) || (PLATFORM_SDM710) || (PLATFORM_SM8150)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -0700153 acdb_init_v2_cvd_t acdb_init;
154#elif defined (PLATFORM_MSM8084)
155 acdb_init_v2_t acdb_init;
156#else
157 acdb_init_t acdb_init;
158#endif
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700159 acdb_deallocate_t acdb_deallocate;
160 acdb_send_audio_cal_t acdb_send_audio_cal;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800161 acdb_send_audio_cal_v3_t acdb_send_audio_cal_v3;
jasmine chac89321b2018-04-10 21:37:01 +0800162 acdb_set_audio_cal_t acdb_set_audio_cal;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700163 acdb_send_voice_cal_t acdb_send_voice_cal;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700164 acdb_reload_vocvoltable_t acdb_reload_vocvoltable;
vivek mehta1a9b7c02015-06-25 11:49:38 -0700165 acdb_send_gain_dep_cal_t acdb_send_gain_dep_cal;
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -0700166 acdb_send_custom_top_t acdb_send_custom_top;
167 bool acdb_initialized;
168
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700169 struct csd_data *csd;
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800170 char ec_ref_mixer_path[64];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700171
David Linee3fe402017-03-13 10:00:42 -0700172 codec_backend_cfg_t current_backend_cfg[MAX_CODEC_BACKENDS];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700173 char *snd_card_name;
keunhui.parkc5aaa0e2015-07-13 10:57:37 +0900174 int max_vol_index;
Prashant Malanic92c5962015-08-11 15:10:18 -0700175 int max_mic_count;
vivek mehtade4849c2016-03-03 17:23:38 -0800176
177 void *hw_info;
jiabin8962a4d2018-03-19 18:21:24 -0700178
179 uint32_t declared_mic_count;
180 struct audio_microphone_characteristic_t microphones[AUDIO_MICROPHONE_MAX_COUNT];
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -0700181 struct snd_device_to_mic_map mic_map[SND_DEVICE_MAX];
Eric Laurentb23d5282013-05-14 15:27:20 -0700182};
183
Haynes Mathew George98c95622014-06-20 19:14:25 -0700184static int pcm_device_table[AUDIO_USECASE_MAX][2] = {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700185 [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = {DEEP_BUFFER_PCM_DEVICE,
186 DEEP_BUFFER_PCM_DEVICE},
Vignesh Kulothungan019d19b2019-01-23 11:09:18 -0800187 [USECASE_AUDIO_PLAYBACK_WITH_HAPTICS] = {AUDIO_HAPTICS_PCM_DEVICE,
188 AUDIO_HAPTICS_PCM_DEVICE},
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700189 [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
190 LOWLATENCY_PCM_DEVICE},
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800191 [USECASE_AUDIO_PLAYBACK_HIFI] = {MULTIMEDIA2_PCM_DEVICE,
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700192 MULTIMEDIA2_PCM_DEVICE},
193 [USECASE_AUDIO_PLAYBACK_OFFLOAD] = {PLAYBACK_OFFLOAD_DEVICE,
194 PLAYBACK_OFFLOAD_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700195 [USECASE_AUDIO_PLAYBACK_TTS] = {MULTIMEDIA2_PCM_DEVICE,
196 MULTIMEDIA2_PCM_DEVICE},
197 [USECASE_AUDIO_PLAYBACK_ULL] = {MULTIMEDIA3_PCM_DEVICE,
198 MULTIMEDIA3_PCM_DEVICE},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800199 [USECASE_AUDIO_PLAYBACK_MMAP] = {MMAP_PLAYBACK_PCM_DEVICE,
200 MMAP_PLAYBACK_PCM_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700201
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700202 [USECASE_AUDIO_RECORD] = {AUDIO_RECORD_PCM_DEVICE,
203 AUDIO_RECORD_PCM_DEVICE},
204 [USECASE_AUDIO_RECORD_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
205 LOWLATENCY_PCM_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700206
Eric Laurent0e46adf2016-12-16 12:49:24 -0800207 [USECASE_AUDIO_RECORD_MMAP] = {MMAP_RECORD_PCM_DEVICE,
208 MMAP_RECORD_PCM_DEVICE},
Haynes Mathew George569b7482017-05-08 14:44:27 -0700209 [USECASE_AUDIO_RECORD_HIFI] = {MULTIMEDIA2_PCM_DEVICE,
210 MULTIMEDIA2_PCM_DEVICE},
211
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700212 [USECASE_VOICE_CALL] = {VOICE_CALL_PCM_DEVICE,
213 VOICE_CALL_PCM_DEVICE},
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700214 [USECASE_VOICE2_CALL] = {VOICE2_CALL_PCM_DEVICE, VOICE2_CALL_PCM_DEVICE},
215 [USECASE_VOLTE_CALL] = {VOLTE_CALL_PCM_DEVICE, VOLTE_CALL_PCM_DEVICE},
216 [USECASE_QCHAT_CALL] = {QCHAT_CALL_PCM_DEVICE, QCHAT_CALL_PCM_DEVICE},
217 [USECASE_VOWLAN_CALL] = {VOWLAN_CALL_PCM_DEVICE, VOWLAN_CALL_PCM_DEVICE},
vivek mehtaa51fd402016-02-04 19:49:33 -0800218 [USECASE_VOICEMMODE1_CALL] = {VOICEMMODE1_CALL_PCM_DEVICE,
219 VOICEMMODE1_CALL_PCM_DEVICE},
220 [USECASE_VOICEMMODE2_CALL] = {VOICEMMODE2_CALL_PCM_DEVICE,
221 VOICEMMODE2_CALL_PCM_DEVICE},
222
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700223 [USECASE_INCALL_REC_UPLINK] = {AUDIO_RECORD_PCM_DEVICE,
224 AUDIO_RECORD_PCM_DEVICE},
225 [USECASE_INCALL_REC_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
226 AUDIO_RECORD_PCM_DEVICE},
227 [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
228 AUDIO_RECORD_PCM_DEVICE},
Ravi Kumar Alamanda8e6e98f2013-11-05 15:57:39 -0800229 [USECASE_AUDIO_HFP_SCO] = {HFP_PCM_RX, HFP_SCO_RX},
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700230
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700231 [USECASE_AUDIO_SPKR_CALIB_RX] = {SPKR_PROT_CALIB_RX_PCM_DEVICE, -1},
232 [USECASE_AUDIO_SPKR_CALIB_TX] = {-1, SPKR_PROT_CALIB_TX_PCM_DEVICE},
233
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700234 [USECASE_AUDIO_PLAYBACK_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
235 AFE_PROXY_RECORD_PCM_DEVICE},
236 [USECASE_AUDIO_RECORD_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
237 AFE_PROXY_RECORD_PCM_DEVICE},
zhaoyang yin4211fad2015-06-04 21:13:25 +0800238 [USECASE_AUDIO_DSM_FEEDBACK] = {QUAT_MI2S_PCM_DEVICE, QUAT_MI2S_PCM_DEVICE},
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700239
vivek mehtaa68fea62017-06-08 19:04:02 -0700240 [USECASE_AUDIO_PLAYBACK_VOIP] = {AUDIO_PLAYBACK_VOIP_PCM_DEVICE,
241 AUDIO_PLAYBACK_VOIP_PCM_DEVICE},
242 [USECASE_AUDIO_RECORD_VOIP] = {AUDIO_RECORD_VOIP_PCM_DEVICE,
243 AUDIO_RECORD_VOIP_PCM_DEVICE},
Nadav Bar3d72cfc2018-01-07 12:19:24 +0200244
245 [USECASE_INCALL_MUSIC_UPLINK] = {INCALL_MUSIC_UPLINK_PCM_DEVICE,
246 INCALL_MUSIC_UPLINK_PCM_DEVICE},
Eric Laurentb23d5282013-05-14 15:27:20 -0700247};
248
249/* Array to store sound devices */
250static const char * const device_table[SND_DEVICE_MAX] = {
251 [SND_DEVICE_NONE] = "none",
252 /* Playback sound devices */
253 [SND_DEVICE_OUT_HANDSET] = "handset",
254 [SND_DEVICE_OUT_SPEAKER] = "speaker",
255 [SND_DEVICE_OUT_SPEAKER_REVERSE] = "speaker-reverse",
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700256 [SND_DEVICE_OUT_SPEAKER_SAFE] = "speaker-safe",
Eric Laurentb23d5282013-05-14 15:27:20 -0700257 [SND_DEVICE_OUT_HEADPHONES] = "headphones",
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500258 [SND_DEVICE_OUT_LINE] = "line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700259 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones",
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700260 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = "speaker-safe-and-headphones",
Eric Laurent744996b2014-10-01 11:40:40 -0500261 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = "speaker-and-line",
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700262 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = "speaker-safe-and-line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700263 [SND_DEVICE_OUT_VOICE_HANDSET] = "voice-handset",
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500264 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = "voice-hac-handset",
Eric Laurentb23d5282013-05-14 15:27:20 -0700265 [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker",
266 [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones",
yixuanjiang9536e672018-09-06 18:43:36 +0800267 [SND_DEVICE_OUT_VOICE_HEADSET] = "voice-headphones",
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500268 [SND_DEVICE_OUT_VOICE_LINE] = "voice-line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700269 [SND_DEVICE_OUT_HDMI] = "hdmi",
270 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi",
271 [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700272 [SND_DEVICE_OUT_BT_SCO_WB] = "bt-sco-headset-wb",
Aniket Kumar Lata26483012018-01-31 20:21:42 -0800273 [SND_DEVICE_OUT_BT_A2DP] = "bt-a2dp",
274 [SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] = "speaker-and-bt-a2dp",
Aniket Kumar Lata9723a962018-05-16 17:41:55 -0700275 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP] = "speaker-safe-and-bt-a2dp",
Eric Laurentb23d5282013-05-14 15:27:20 -0700276 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = "voice-handset-tmus",
277 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones",
278 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones",
279 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset",
vivek mehtaa6b79742017-03-09 15:40:43 -0800280 [SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = "voice-tty-full-usb",
281 [SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = "voice-tty-vco-usb",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700282 [SND_DEVICE_OUT_VOICE_TX] = "voice-tx",
juyuchen66c4ecf2018-08-06 15:39:34 +0800283 [SND_DEVICE_OUT_VOICE_MUSIC_TX] = "voice-music-tx",
David Linee3fe402017-03-13 10:00:42 -0700284 [SND_DEVICE_OUT_USB_HEADSET] = "usb-headset",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700285 [SND_DEVICE_OUT_VOICE_USB_HEADSET] = "usb-headset",
David Linee3fe402017-03-13 10:00:42 -0700286 [SND_DEVICE_OUT_USB_HEADPHONES] = "usb-headphones",
jasmine cha270b7762018-03-30 15:41:33 +0800287 [SND_DEVICE_OUT_USB_HEADSET_SPEC] = "usb-headset",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700288 [SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = "usb-headphones",
David Linee3fe402017-03-13 10:00:42 -0700289 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = "speaker-and-usb-headphones",
Haynes Mathew George9090bfb2017-05-31 11:44:50 -0700290 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] = "speaker-safe-and-usb-headphones",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700291 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = "speaker-protected",
292 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = "voice-speaker-protected",
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -0700293 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = "voice-speaker-hfp",
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -0800294 [SND_DEVICE_OUT_SPEAKER_AND_BT_SCO] = "speaker-and-bt-sco",
juyuchen5351ea62018-05-16 10:54:37 +0800295 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO] = "speaker-safe-and-bt-sco",
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -0800296 [SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB] = "speaker-and-bt-sco-wb",
juyuchen5351ea62018-05-16 10:54:37 +0800297 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB] = "speaker-safe-and-bt-sco-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700298
299 /* Capture sound devices */
300 [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700301 [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700302 [SND_DEVICE_IN_HANDSET_MIC_NS] = "handset-mic",
303 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = "handset-mic",
304 [SND_DEVICE_IN_HANDSET_DMIC] = "dmic-endfire",
305 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = "dmic-endfire",
306 [SND_DEVICE_IN_HANDSET_DMIC_NS] = "dmic-endfire",
307 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = "dmic-endfire",
308 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = "dmic-endfire",
309
310 [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
311 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "speaker-mic",
312 [SND_DEVICE_IN_SPEAKER_MIC_NS] = "speaker-mic",
313 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = "speaker-mic",
314 [SND_DEVICE_IN_SPEAKER_DMIC] = "speaker-dmic-endfire",
315 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = "speaker-dmic-endfire",
316 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = "speaker-dmic-endfire",
317 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = "speaker-dmic-endfire",
318 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = "speaker-dmic-endfire",
319
320 [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
Eric Laurentcefbbac2014-09-04 13:54:10 -0500321 [SND_DEVICE_IN_HEADSET_MIC_AEC] = "headset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700322
Eric Laurentb23d5282013-05-14 15:27:20 -0700323 [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic",
324 [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700325 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = "bt-sco-mic",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700326 [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700327 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = "bt-sco-mic-wb",
Eric Laurent5f4ca952018-10-19 17:33:43 -0700328 [SND_DEVICE_IN_CAMCORDER_LANDSCAPE] = "camcorder-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700329
330 [SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef",
331 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = "voice-dmic-ef-tmus",
332 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
333 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = "voice-speaker-dmic-ef",
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -0700334 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = "voice-speaker-mic-hfp",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700335 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700336 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
337 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
338 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
vivek mehtaa6b79742017-03-09 15:40:43 -0800339 [SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = "voice-tty-full-usb-mic",
340 [SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = "voice-tty-hco-usb-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700341
Eric Laurentb23d5282013-05-14 15:27:20 -0700342 [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700343 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = "voice-rec-mic",
vivek mehta733c1df2016-04-04 15:09:24 -0700344 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = "voice-rec-mic",
vivek mehtaf3440682016-05-11 14:24:37 -0700345 [SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700346 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = "voice-rec-dmic-ef",
347 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence",
David Linee3fe402017-03-13 10:00:42 -0700348 [SND_DEVICE_IN_USB_HEADSET_MIC] = "usb-headset-mic",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700349 [SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] ="usb-headset-mic",
350 [SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = "usb-headset-mic",
351 [SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = "usb-headset-mic",
352 [SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = "usb-headset-mic",
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700353 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = "headset-mic",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700354
Ricardo Garcia9034bc42016-04-04 07:11:46 -0700355 [SND_DEVICE_IN_UNPROCESSED_MIC] = "unprocessed-mic",
vivek mehta0125e782016-06-16 18:03:11 -0700356 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = "unprocessed-stereo-mic",
357 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = "unprocessed-three-mic",
358 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = "unprocessed-quad-mic",
359 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = "unprocessed-headset-mic",
rago90fb9612015-12-02 11:37:53 -0800360
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700361 [SND_DEVICE_IN_VOICE_RX] = "voice-rx",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700362
Prashant Malanic92c5962015-08-11 15:10:18 -0700363 [SND_DEVICE_IN_THREE_MIC] = "three-mic",
364 [SND_DEVICE_IN_QUAD_MIC] = "quad-mic",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700365 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = "vi-feedback",
Prashant Malanic92c5962015-08-11 15:10:18 -0700366 [SND_DEVICE_IN_HANDSET_TMIC] = "three-mic",
367 [SND_DEVICE_IN_HANDSET_QMIC] = "quad-mic",
vivek mehta733c1df2016-04-04 15:09:24 -0700368 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = "three-mic",
369 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = "quad-mic",
Eric Laurent5f4ca952018-10-19 17:33:43 -0700370 [SND_DEVICE_IN_CAMCORDER_INVERT_LANDSCAPE] = "camcorder-mic",
371 [SND_DEVICE_IN_CAMCORDER_PORTRAIT] = "camcorder-mic",
372 [SND_DEVICE_IN_CAMCORDER_SELFIE_LANDSCAPE] = "camcorder-mic",
373 [SND_DEVICE_IN_CAMCORDER_SELFIE_INVERT_LANDSCAPE] = "camcorder-mic",
374 [SND_DEVICE_IN_CAMCORDER_SELFIE_PORTRAIT] = "camcorder-mic",
Vignesh Kulothungan64698822018-01-23 11:25:18 -0800375 [SND_DEVICE_IN_SPEAKER_QMIC_NS] = "quad-mic",
376 [SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS] = "quad-mic",
377};
378
379static struct audio_effect_config \
380 effect_config_table[GET_IN_DEVICE_INDEX(SND_DEVICE_MAX)][EFFECT_COUNT] = {
381 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS)][EFFECT_AEC] = \
382 {TX_VOICE_FLUENCE_PROV2, 0x0, 0x10EAF, 0x01},
383 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS)][EFFECT_NS] = \
384 {TX_VOICE_FLUENCE_PROV2, 0x0, 0x10EAF, 0x02},
385 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)][EFFECT_AEC] = \
386 {TX_VOICE_FV5ECNS_DM, 0x0, 0x10EAF, 0x01},
387 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)][EFFECT_NS] = \
388 {TX_VOICE_FV5ECNS_DM, 0x0, 0x10EAF, 0x02},
389 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)][EFFECT_AEC] = \
390 {TX_VOICE_FV5ECNS_SM, 0x0, 0x10EAF, 0x01},
391 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)][EFFECT_NS] = \
392 {TX_VOICE_FV5ECNS_SM, 0x0, 0x10EAF, 0x02},
393 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)][EFFECT_AEC] = \
394 {TX_VOICE_FV5ECNS_DM, 0x0, 0x10EAF, 0x01},
395 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)][EFFECT_NS] = \
396 {TX_VOICE_FV5ECNS_DM, 0x0, 0x10EAF, 0x02},
397 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)][EFFECT_AEC] = \
398 {TX_VOICE_FV5ECNS_SM, 0x0, 0x10EAF, 0x01},
399 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)][EFFECT_NS] = \
400 {TX_VOICE_FV5ECNS_SM, 0x0, 0x10EAF, 0x02},
Eric Laurentb23d5282013-05-14 15:27:20 -0700401};
402
403/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700404static int acdb_device_table[SND_DEVICE_MAX] = {
Eric Laurentb23d5282013-05-14 15:27:20 -0700405 [SND_DEVICE_NONE] = -1,
406 [SND_DEVICE_OUT_HANDSET] = 7,
407 [SND_DEVICE_OUT_SPEAKER] = 15,
408 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 15,
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700409 [SND_DEVICE_OUT_SPEAKER_SAFE] = 15,
Eric Laurentb23d5282013-05-14 15:27:20 -0700410 [SND_DEVICE_OUT_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500411 [SND_DEVICE_OUT_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700412 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700413 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500414 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = 77,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700415 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = 77,
Ravi Kumar Alamanda235c3482014-08-21 17:32:44 -0700416 [SND_DEVICE_OUT_VOICE_HANDSET] = ACDB_ID_VOICE_HANDSET,
417 [SND_DEVICE_OUT_VOICE_SPEAKER] = ACDB_ID_VOICE_SPEAKER,
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500418 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = 53,
Eric Laurentb23d5282013-05-14 15:27:20 -0700419 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
yixuanjiang9536e672018-09-06 18:43:36 +0800420 [SND_DEVICE_OUT_VOICE_HEADSET] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500421 [SND_DEVICE_OUT_VOICE_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700422 [SND_DEVICE_OUT_HDMI] = 18,
423 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 15,
424 [SND_DEVICE_OUT_BT_SCO] = 22,
juyuchen5351ea62018-05-16 10:54:37 +0800425 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO] = 14,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700426 [SND_DEVICE_OUT_BT_SCO_WB] = 39,
juyuchen5351ea62018-05-16 10:54:37 +0800427 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB] = 14,
Aniket Kumar Lata26483012018-01-31 20:21:42 -0800428 [SND_DEVICE_OUT_BT_A2DP] = 20,
429 [SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] = 14,
Aniket Kumar Lata9723a962018-05-16 17:41:55 -0700430 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP] = 14,
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700431 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = ACDB_ID_VOICE_HANDSET_TMUS,
Eric Laurentb23d5282013-05-14 15:27:20 -0700432 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
433 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
434 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
vivek mehtaa6b79742017-03-09 15:40:43 -0800435 [SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = 17,
436 [SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = 17,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700437 [SND_DEVICE_OUT_VOICE_TX] = 45,
juyuchen66c4ecf2018-08-06 15:39:34 +0800438 [SND_DEVICE_OUT_VOICE_MUSIC_TX] = 3,
David Linee3fe402017-03-13 10:00:42 -0700439 [SND_DEVICE_OUT_USB_HEADSET] = 45,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700440 [SND_DEVICE_OUT_VOICE_USB_HEADSET] = 45,
David Linee3fe402017-03-13 10:00:42 -0700441 [SND_DEVICE_OUT_USB_HEADPHONES] = 45,
jasmine cha270b7762018-03-30 15:41:33 +0800442 [SND_DEVICE_OUT_USB_HEADSET_SPEC] = 45,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700443 [SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = 45,
David Linee3fe402017-03-13 10:00:42 -0700444 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = 14,
Haynes Mathew George9090bfb2017-05-31 11:44:50 -0700445 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] = 14,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700446 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = 124,
447 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = 101,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700448 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = ACDB_ID_VOICE_SPEAKER,
Eric Laurentb23d5282013-05-14 15:27:20 -0700449
450 [SND_DEVICE_IN_HANDSET_MIC] = 4,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700451 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 106,
452 [SND_DEVICE_IN_HANDSET_MIC_NS] = 107,
453 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = 108,
454 [SND_DEVICE_IN_HANDSET_DMIC] = 41,
455 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = 109,
456 [SND_DEVICE_IN_HANDSET_DMIC_NS] = 110,
457 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = 111,
458 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = 34,
459
460 [SND_DEVICE_IN_SPEAKER_MIC] = 11,
461 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 112,
462 [SND_DEVICE_IN_SPEAKER_MIC_NS] = 113,
463 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = 114,
464 [SND_DEVICE_IN_SPEAKER_DMIC] = 43,
465 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = 115,
466 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = 116,
467 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = 117,
468 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = 35,
469
rago90fb9612015-12-02 11:37:53 -0800470 [SND_DEVICE_IN_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentcefbbac2014-09-04 13:54:10 -0500471 [SND_DEVICE_IN_HEADSET_MIC_AEC] = ACDB_ID_HEADSET_MIC_AEC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700472
Eric Laurentb23d5282013-05-14 15:27:20 -0700473 [SND_DEVICE_IN_HDMI_MIC] = 4,
474 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700475 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = 21,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700476 [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700477 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = 38,
Eric Laurent5f4ca952018-10-19 17:33:43 -0700478 [SND_DEVICE_IN_CAMCORDER_LANDSCAPE] = 61,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700479
480 [SND_DEVICE_IN_VOICE_DMIC] = 41,
481 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = ACDB_ID_VOICE_DMIC_EF_TMUS,
482 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700483 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = 11,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700484 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 43,
rago90fb9612015-12-02 11:37:53 -0800485 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentb23d5282013-05-14 15:27:20 -0700486 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
487 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
488 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
vivek mehtaa6b79742017-03-09 15:40:43 -0800489 [SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = 16,
490 [SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = 16,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700491
rago90fb9612015-12-02 11:37:53 -0800492 [SND_DEVICE_IN_VOICE_REC_MIC] = ACDB_ID_VOICE_REC_MIC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700493 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = 113,
vivek mehta733c1df2016-04-04 15:09:24 -0700494 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = 112,
vivek mehtaf3440682016-05-11 14:24:37 -0700495 [SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = 114,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700496 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = 35,
497 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 43,
rago90fb9612015-12-02 11:37:53 -0800498 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
499
500 [SND_DEVICE_IN_UNPROCESSED_MIC] = ACDB_ID_VOICE_REC_MIC,
501 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
vivek mehta4ed66e62016-04-15 23:33:34 -0700502 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = 35,
503 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = 125,
504 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = 125,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700505
506 [SND_DEVICE_IN_VOICE_RX] = 44,
David Linee3fe402017-03-13 10:00:42 -0700507 [SND_DEVICE_IN_USB_HEADSET_MIC] = 44,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700508 [SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = 44,
509 [SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = 44,
510 [SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = 44,
511 [SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = 44,
Prashant Malanic92c5962015-08-11 15:10:18 -0700512 [SND_DEVICE_IN_THREE_MIC] = 46,
513 [SND_DEVICE_IN_QUAD_MIC] = 46,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700514 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = 102,
Prashant Malanic92c5962015-08-11 15:10:18 -0700515 [SND_DEVICE_IN_HANDSET_TMIC] = 125,
516 [SND_DEVICE_IN_HANDSET_QMIC] = 125,
vivek mehta733c1df2016-04-04 15:09:24 -0700517 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = 125, /* override this for new target to 140 */
518 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = 125, /* override this for new target to 140 */
Eric Laurent5f4ca952018-10-19 17:33:43 -0700519 [SND_DEVICE_IN_CAMCORDER_INVERT_LANDSCAPE] = 61,
520 [SND_DEVICE_IN_CAMCORDER_PORTRAIT] = 61,
521 [SND_DEVICE_IN_CAMCORDER_SELFIE_LANDSCAPE] = 61,
522 [SND_DEVICE_IN_CAMCORDER_SELFIE_INVERT_LANDSCAPE] = 61,
523 [SND_DEVICE_IN_CAMCORDER_SELFIE_PORTRAIT] = 61,
Vignesh Kulothungan64698822018-01-23 11:25:18 -0800524 [SND_DEVICE_IN_SPEAKER_QMIC_NS] = 129,
525 [SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS] = 129,
Eric Laurentb23d5282013-05-14 15:27:20 -0700526};
527
David Linee3fe402017-03-13 10:00:42 -0700528// Platform specific backend bit width table
529static int backend_bit_width_table[SND_DEVICE_MAX] = {0};
530
Haynes Mathew George98c95622014-06-20 19:14:25 -0700531struct name_to_index {
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700532 char name[100];
533 unsigned int index;
534};
535
536#define TO_NAME_INDEX(X) #X, X
537
Haynes Mathew George98c95622014-06-20 19:14:25 -0700538/* Used to get index from parsed string */
539static const struct name_to_index snd_device_name_index[SND_DEVICE_MAX] = {
540 /* out */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700541 {TO_NAME_INDEX(SND_DEVICE_OUT_HANDSET)},
542 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER)},
543 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_REVERSE)},
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700544 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700545 {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500546 {TO_NAME_INDEX(SND_DEVICE_OUT_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700547 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700548 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES)},
Eric Laurent744996b2014-10-01 11:40:40 -0500549 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_LINE)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700550 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700551 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET)},
552 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700553 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_HFP)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700554 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADPHONES)},
yixuanjiang9536e672018-09-06 18:43:36 +0800555 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADSET)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500556 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700557 {TO_NAME_INDEX(SND_DEVICE_OUT_HDMI)},
558 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HDMI)},
559 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO)},
juyuchen5351ea62018-05-16 10:54:37 +0800560 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700561 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO_WB)},
juyuchen5351ea62018-05-16 10:54:37 +0800562 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB)},
Aniket Kumar Lata26483012018-01-31 20:21:42 -0800563 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_A2DP)},
564 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP)},
Aniket Kumar Lata9723a962018-05-16 17:41:55 -0700565 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700566 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET_TMUS)},
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500567 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HAC_HANDSET)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700568 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES)},
569 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES)},
570 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET)},
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -0800571 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_SCO)},
572 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800573 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_USB)},
574 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_USB)},
David Linee3fe402017-03-13 10:00:42 -0700575 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADSET)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700576 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_USB_HEADSET)},
David Linee3fe402017-03-13 10:00:42 -0700577 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADPHONES)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700578 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_USB_HEADPHONES)},
David Linee3fe402017-03-13 10:00:42 -0700579 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET)},
Haynes Mathew George9090bfb2017-05-31 11:44:50 -0700580 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700581 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED)},
582 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED)},
jasmine cha270b7762018-03-30 15:41:33 +0800583 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADSET_SPEC)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800584
585 /* in */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700586 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700587 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700588 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_NS)},
589 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)},
590 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC)},
591 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC)},
592 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_NS)},
593 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)},
594 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_STEREO)},
595
596 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700597 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700598 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_NS)},
599 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)},
600 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC)},
601 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC)},
602 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS)},
603 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)},
604 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_STEREO)},
605
606 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC)},
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700607 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700608
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700609 {TO_NAME_INDEX(SND_DEVICE_IN_HDMI_MIC)},
610 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700611 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700612 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700613 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB_NREC)},
Eric Laurent5f4ca952018-10-19 17:33:43 -0700614 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_LANDSCAPE)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700615
616 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC)},
617 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC_TMUS)},
618 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700619 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700620 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC)},
621 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEADSET_MIC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700622 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC)},
623 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC)},
624 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800625 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC)},
626 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC)},
627
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700628
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700629 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700630 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_NS)},
vivek mehta733c1df2016-04-04 15:09:24 -0700631 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC)},
vivek mehtaf3440682016-05-11 14:24:37 -0700632 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700633 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_STEREO)},
634 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE)},
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700635 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_HEADSET_MIC)},
David Linee3fe402017-03-13 10:00:42 -0700636 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700637 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_USB_HEADSET_MIC)},
638 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC)},
639 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC)},
640 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC_AEC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700641
rago90fb9612015-12-02 11:37:53 -0800642 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_MIC)},
643 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC)},
vivek mehta4ed66e62016-04-15 23:33:34 -0700644 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_STEREO_MIC)},
645 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_THREE_MIC)},
646 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_QUAD_MIC)},
rago90fb9612015-12-02 11:37:53 -0800647
Prashant Malanic92c5962015-08-11 15:10:18 -0700648 {TO_NAME_INDEX(SND_DEVICE_IN_THREE_MIC)},
649 {TO_NAME_INDEX(SND_DEVICE_IN_QUAD_MIC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700650 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_VI_FEEDBACK)},
Prashant Malanic92c5962015-08-11 15:10:18 -0700651 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC)},
652 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC)},
vivek mehta733c1df2016-04-04 15:09:24 -0700653 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC_AEC)},
654 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC_AEC)},
Eric Laurent5f4ca952018-10-19 17:33:43 -0700655 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_INVERT_LANDSCAPE)},
656 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_PORTRAIT)},
657 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_SELFIE_LANDSCAPE)},
658 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_SELFIE_INVERT_LANDSCAPE)},
659 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_SELFIE_PORTRAIT)},
660 /* For legacy xml file parsing */
661 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_MIC)},
Vignesh Kulothungan64698822018-01-23 11:25:18 -0800662 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_QMIC_NS)},
663 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700664};
665
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700666static char * backend_tag_table[SND_DEVICE_MAX] = {0};
667static char * hw_interface_table[SND_DEVICE_MAX] = {0};
Haynes Mathew George98c95622014-06-20 19:14:25 -0700668
669static const struct name_to_index usecase_name_index[AUDIO_USECASE_MAX] = {
670 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_DEEP_BUFFER)},
671 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_LOW_LATENCY)},
Vignesh Kulothungan019d19b2019-01-23 11:09:18 -0800672 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_WITH_HAPTICS)},
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800673 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_HIFI)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700674 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD)},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700675 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_TTS)},
676 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_ULL)},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800677 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_MMAP)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700678 {TO_NAME_INDEX(USECASE_AUDIO_RECORD)},
679 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_LOW_LATENCY)},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800680 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_MMAP)},
Haynes Mathew George569b7482017-05-08 14:44:27 -0700681 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_HIFI)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700682 {TO_NAME_INDEX(USECASE_VOICE_CALL)},
683 {TO_NAME_INDEX(USECASE_VOICE2_CALL)},
684 {TO_NAME_INDEX(USECASE_VOLTE_CALL)},
685 {TO_NAME_INDEX(USECASE_QCHAT_CALL)},
686 {TO_NAME_INDEX(USECASE_VOWLAN_CALL)},
John Muirf1346ce2016-12-06 00:03:41 -0800687 {TO_NAME_INDEX(USECASE_VOICEMMODE1_CALL)},
688 {TO_NAME_INDEX(USECASE_VOICEMMODE2_CALL)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700689 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK)},
690 {TO_NAME_INDEX(USECASE_INCALL_REC_DOWNLINK)},
691 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK_AND_DOWNLINK)},
692 {TO_NAME_INDEX(USECASE_AUDIO_HFP_SCO)},
John Muirf1346ce2016-12-06 00:03:41 -0800693 {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_RX)},
694 {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_TX)},
695 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_AFE_PROXY)},
696 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_AFE_PROXY)},
697 {TO_NAME_INDEX(USECASE_AUDIO_DSM_FEEDBACK)},
vivek mehtaa68fea62017-06-08 19:04:02 -0700698 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_VOIP)},
699 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_VOIP)},
Nadav Bar3d72cfc2018-01-07 12:19:24 +0200700 {TO_NAME_INDEX(USECASE_INCALL_MUSIC_UPLINK)},
Aniket Kumar Lata99546312018-03-19 21:38:38 -0700701 {TO_NAME_INDEX(USECASE_AUDIO_A2DP_ABR_FEEDBACK)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700702};
703
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800704static const struct name_to_index usecase_type_index[USECASE_TYPE_MAX] = {
705 {TO_NAME_INDEX(PCM_PLAYBACK)},
706 {TO_NAME_INDEX(PCM_CAPTURE)},
707 {TO_NAME_INDEX(VOICE_CALL)},
708 {TO_NAME_INDEX(PCM_HFP_CALL)},
709};
710
711struct app_type_entry {
712 int uc_type;
713 int bit_width;
714 int app_type;
715 int max_rate;
vivek mehtaa68fea62017-06-08 19:04:02 -0700716 char *mode;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800717 struct listnode node; // membership in app_type_entry_list;
718};
719
720static struct listnode app_type_entry_list;
721
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700722#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
723#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
Eric Laurent0e46adf2016-12-16 12:49:24 -0800724#define ULL_PLATFORM_DELAY (3*1000LL)
725#define MMAP_PLATFORM_DELAY (3*1000LL)
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700726
Eric Laurentb23d5282013-05-14 15:27:20 -0700727static pthread_once_t check_op_once_ctl = PTHREAD_ONCE_INIT;
728static bool is_tmus = false;
729
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800730static int init_be_dai_name_table(struct audio_device *adev);
731
Eric Laurentb23d5282013-05-14 15:27:20 -0700732static void check_operator()
733{
734 char value[PROPERTY_VALUE_MAX];
735 int mccmnc;
736 property_get("gsm.sim.operator.numeric",value,"0");
737 mccmnc = atoi(value);
Eric Laurent2bafff12016-03-17 12:17:23 -0700738 ALOGD("%s: tmus mccmnc %d", __func__, mccmnc);
Eric Laurentb23d5282013-05-14 15:27:20 -0700739 switch(mccmnc) {
740 /* TMUS MCC(310), MNC(490, 260, 026) */
741 case 310490:
742 case 310260:
743 case 310026:
sangwon.jeonb891db52013-09-14 17:39:15 +0900744 /* Add new TMUS MNC(800, 660, 580, 310, 270, 250, 240, 230, 220, 210, 200, 160) */
745 case 310800:
746 case 310660:
747 case 310580:
748 case 310310:
749 case 310270:
750 case 310250:
751 case 310240:
752 case 310230:
753 case 310220:
754 case 310210:
755 case 310200:
756 case 310160:
Eric Laurentb23d5282013-05-14 15:27:20 -0700757 is_tmus = true;
758 break;
759 }
760}
761
762bool is_operator_tmus()
763{
764 pthread_once(&check_op_once_ctl, check_operator);
765 return is_tmus;
766}
767
keunhui.park2f7306a2015-07-16 16:48:06 +0900768static char *get_current_operator()
769{
770 struct listnode *node;
771 struct operator_info *info_item;
772 char mccmnc[PROPERTY_VALUE_MAX];
773 char *ret = NULL;
774
Tom Cherry7fea2042016-11-10 18:05:59 -0800775 property_get("gsm.sim.operator.numeric",mccmnc,"00000");
keunhui.park2f7306a2015-07-16 16:48:06 +0900776
777 list_for_each(node, &operator_info_list) {
778 info_item = node_to_item(node, struct operator_info, list);
779 if (strstr(info_item->mccmnc, mccmnc) != NULL) {
780 ret = info_item->name;
781 }
782 }
783
784 return ret;
785}
786
787static struct operator_specific_device *get_operator_specific_device(snd_device_t snd_device)
788{
789 struct listnode *node;
790 struct operator_specific_device *ret = NULL;
791 struct operator_specific_device *device_item;
792 char *operator_name;
793
794 operator_name = get_current_operator();
795 if (operator_name == NULL)
796 return ret;
797
798 list_for_each(node, operator_specific_device_table[snd_device]) {
799 device_item = node_to_item(node, struct operator_specific_device, list);
800 if (strcmp(operator_name, device_item->operator) == 0) {
801 ret = device_item;
802 }
803 }
804
805 return ret;
806}
807
808
809static int get_operator_specific_device_acdb_id(snd_device_t snd_device)
810{
811 struct operator_specific_device *device;
812 int ret = acdb_device_table[snd_device];
813
814 device = get_operator_specific_device(snd_device);
815 if (device != NULL)
816 ret = device->acdb_id;
817
818 return ret;
819}
820
821static const char *get_operator_specific_device_mixer_path(snd_device_t snd_device)
822{
823 struct operator_specific_device *device;
824 const char *ret = device_table[snd_device];
825
826 device = get_operator_specific_device(snd_device);
827 if (device != NULL)
828 ret = device->mixer_path;
829
830 return ret;
831}
832
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800833inline bool platform_supports_app_type_cfg()
834{
Thierry Strudel07f96d12018-09-20 13:31:34 -0700835#if defined (PLATFORM_MSM8998) || (PLATFORM_SDM845) || (PLATFORM_SDM710) || (PLATFORM_SM8150)
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800836 return true;
837#else
838 return false;
839#endif
840}
841
jasmine chac89321b2018-04-10 21:37:01 +0800842static int parse_audiocal_cfg(struct str_parms *parms, acdb_audio_cal_cfg_t *cal)
843{
844 int err;
845 char value[64];
846 int ret = 0;
847
848 if (parms == NULL || cal == NULL)
849 return ret;
850
851 err = str_parms_get_str(parms, "cal_persist", value, sizeof(value));
852 if (err >= 0) {
853 str_parms_del(parms, "cal_persist");
854 cal->persist = (uint32_t)strtoul(value, NULL, 0);
855 ret = ret | 0x1;
856 }
857 err = str_parms_get_str(parms, "cal_apptype", value, sizeof(value));
858 if (err >= 0) {
859 str_parms_del(parms, "cal_apptype");
860 cal->app_type = (uint32_t)strtoul(value, NULL, 0);
861 ret = ret | 0x2;
862 }
863 err = str_parms_get_str(parms, "cal_caltype", value, sizeof(value));
864 if (err >= 0) {
865 str_parms_del(parms, "cal_caltype");
866 cal->cal_type = (uint32_t)strtoul(value, NULL, 0);
867 ret = ret | 0x4;
868 }
869 err = str_parms_get_str(parms, "cal_samplerate", value, sizeof(value));
870 if (err >= 0) {
871 str_parms_del(parms, "cal_samplerate");
872 cal->sampling_rate = (uint32_t)strtoul(value, NULL, 0);
873 ret = ret | 0x8;
874 }
875 err = str_parms_get_str(parms, "cal_devid", value, sizeof(value));
876 if (err >= 0) {
877 str_parms_del(parms, "cal_devid");
878 cal->dev_id = (uint32_t)strtoul(value, NULL, 0);
879 ret = ret | 0x10;
880 }
881 err = str_parms_get_str(parms, "cal_snddevid", value, sizeof(value));
882 if (err >= 0) {
883 str_parms_del(parms, "cal_snddevid");
884 cal->snd_dev_id = (uint32_t)strtoul(value, NULL, 0);
885 ret = ret | 0x20;
886 }
887 err = str_parms_get_str(parms, "cal_topoid", value, sizeof(value));
888 if (err >= 0) {
889 str_parms_del(parms, "cal_topoid");
890 cal->topo_id = (uint32_t)strtoul(value, NULL, 0);
891 ret = ret | 0x40;
892 }
893 err = str_parms_get_str(parms, "cal_moduleid", value, sizeof(value));
894 if (err >= 0) {
895 str_parms_del(parms, "cal_moduleid");
896 cal->module_id = (uint32_t)strtoul(value, NULL, 0);
897 ret = ret | 0x80;
898 }
899 err = str_parms_get_str(parms, "cal_paramid", value, sizeof(value));
900 if (err >= 0) {
901 str_parms_del(parms, "cal_paramid");
902 cal->param_id = (uint32_t)strtoul(value, NULL, 0);
903 ret = ret | 0x100;
904 }
905 return ret;
906}
907
908static void set_audiocal(void *platform, struct str_parms *parms, char *value, int len)
909{
910 struct platform_data *my_data = (struct platform_data *)platform;
911 acdb_audio_cal_cfg_t cal;
912 uint8_t *dptr = NULL;
913 int32_t dlen = 0;
914 int err ,ret;
915
916 if (value == NULL || platform == NULL || parms == NULL) {
917 ALOGE("[%s] received null pointer, failed", __func__);
918 goto done_key_audcal;
919 }
920
921 memset(&cal, 0, sizeof(acdb_audio_cal_cfg_t));
922 /* parse audio calibration keys */
923 ret = parse_audiocal_cfg(parms, &cal);
924
925 /* handle audio calibration data now */
926 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_AUD_CALDATA, value, len);
927 if (err >= 0) {
928 str_parms_del(parms, AUDIO_PARAMETER_KEY_AUD_CALDATA);
929 dlen = strlen(value);
930 if (dlen <= 0) {
931 ALOGE("[%s] null data received", __func__);
932 goto done_key_audcal;
933 }
934 /*
935 The base64 encoded string is always larger than the binary data,
936 so b64_pton will always output less data than provided (around 1/3
937 less than the input data). That's why we can allocate input buffer
938 length and then get function work.
939 */
940 dptr = (uint8_t *)calloc(dlen, sizeof(uint8_t));
941 if (dptr == NULL) {
942 ALOGE("[%s] memory allocation failed for %d", __func__, dlen);
943 goto done_key_audcal;
944 }
945 dlen = b64_pton(value, dptr, dlen);
946 if (dlen <= 0) {
947 ALOGE("[%s] data decoding failed %d", __func__, dlen);
948 goto done_key_audcal;
949 }
950
951 if (cal.dev_id) {
952 if (audio_is_input_device(cal.dev_id)) {
Eric Laurentd1b7a9b2018-11-15 12:24:31 -0800953 // FIXME: why pass an input device whereas
954 // platform_get_input_snd_device() expects as an output device?
955 cal.snd_dev_id = platform_get_input_snd_device(platform, NULL, cal.dev_id);
jasmine chac89321b2018-04-10 21:37:01 +0800956 } else {
957 cal.snd_dev_id = platform_get_output_snd_device(platform, cal.dev_id);
958 }
959 }
960 cal.acdb_dev_id = platform_get_snd_device_acdb_id(cal.snd_dev_id);
961 ALOGD("Setting audio calibration for snd_device(%d) acdb_id(%d)",
962 cal.snd_dev_id, cal.acdb_dev_id);
963 if (cal.acdb_dev_id == -EINVAL) {
964 ALOGE("[%s] Invalid acdb_device id %d for snd device id %d",
965 __func__, cal.acdb_dev_id, cal.snd_dev_id);
966 goto done_key_audcal;
967 }
968 if (my_data->acdb_set_audio_cal) {
969 ret = my_data->acdb_set_audio_cal((void *)&cal, (void *)dptr, dlen);
970 }
971 }
972done_key_audcal:
973 if (dptr != NULL)
974 free(dptr);
975}
976
vivek mehta1a9b7c02015-06-25 11:49:38 -0700977bool platform_send_gain_dep_cal(void *platform, int level)
978{
979 bool ret_val = false;
980 struct platform_data *my_data = (struct platform_data *)platform;
981 struct audio_device *adev = my_data->adev;
982 int acdb_dev_id, app_type;
983 int acdb_dev_type = MSM_SNDDEV_CAP_RX;
984 int mode = CAL_MODE_RTAC;
985 struct listnode *node;
986 struct audio_usecase *usecase;
Haynes Mathew George67486e22017-06-26 12:58:38 -0700987 bool valid_uc_type;
988 bool valid_dev;
vivek mehta1a9b7c02015-06-25 11:49:38 -0700989
990 if (my_data->acdb_send_gain_dep_cal == NULL) {
991 ALOGE("%s: dlsym error for acdb_send_gain_dep_cal", __func__);
992 return ret_val;
993 }
994
995 if (!voice_is_in_call(adev)) {
996 ALOGV("%s: Not Voice call usecase, apply new cal for level %d",
997 __func__, level);
vivek mehta1a9b7c02015-06-25 11:49:38 -0700998
999 // find the current active sound device
1000 list_for_each(node, &adev->usecase_list) {
1001 usecase = node_to_item(node, struct audio_usecase, list);
Haynes Mathew George67486e22017-06-26 12:58:38 -07001002 LOG_ALWAYS_FATAL_IF(usecase == NULL,
1003 "unxpected NULL usecase in usecase_list");
1004 valid_uc_type = usecase->type == PCM_PLAYBACK;
1005 valid_dev = false;
1006 if (valid_uc_type) {
1007 audio_devices_t dev = usecase->stream.out->devices;
1008 valid_dev = (dev == AUDIO_DEVICE_OUT_SPEAKER ||
vivek mehta40125092017-08-21 18:48:51 -07001009 dev == AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Haynes Mathew George67486e22017-06-26 12:58:38 -07001010 dev == AUDIO_DEVICE_OUT_WIRED_HEADSET ||
1011 dev == AUDIO_DEVICE_OUT_WIRED_HEADPHONE);
1012 }
1013 if (valid_dev) {
vivek mehta40125092017-08-21 18:48:51 -07001014 ALOGV("%s: out device is %d", __func__, usecase->out_snd_device);
1015 if (platform_supports_app_type_cfg())
1016 app_type = usecase->stream.out->app_type_cfg.app_type;
1017 else
1018 app_type = DEFAULT_APP_TYPE_RX_PATH;
vivek mehta4cb82982015-07-13 12:05:49 -07001019
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07001020 acdb_dev_id = platform_get_snd_device_acdb_id(usecase->out_snd_device);
vivek mehta40125092017-08-21 18:48:51 -07001021
1022 if (!my_data->acdb_send_gain_dep_cal(acdb_dev_id, app_type,
vivek mehta1a9b7c02015-06-25 11:49:38 -07001023 acdb_dev_type, mode, level)) {
1024 // set ret_val true if at least one calibration is set successfully
1025 ret_val = true;
1026 } else {
1027 ALOGE("%s: my_data->acdb_send_gain_dep_cal failed ", __func__);
1028 }
1029 } else {
1030 ALOGW("%s: Usecase list is empty", __func__);
1031 }
1032 }
1033 } else {
1034 ALOGW("%s: Voice call in progress .. ignore setting new cal",
1035 __func__);
1036 }
1037 return ret_val;
1038}
1039
Eric Laurentcefbbac2014-09-04 13:54:10 -05001040void platform_set_echo_reference(struct audio_device *adev, bool enable, audio_devices_t out_device)
Eric Laurentb23d5282013-05-14 15:27:20 -07001041{
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08001042 struct platform_data *my_data = (struct platform_data *)adev->platform;
Eric Laurentcefbbac2014-09-04 13:54:10 -05001043 snd_device_t snd_device = SND_DEVICE_NONE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001044
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08001045 if (strcmp(my_data->ec_ref_mixer_path, "")) {
1046 ALOGV("%s: diabling %s", __func__, my_data->ec_ref_mixer_path);
1047 audio_route_reset_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
Eric Laurentcefbbac2014-09-04 13:54:10 -05001048 }
1049
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08001050 if (enable) {
1051 strcpy(my_data->ec_ref_mixer_path, "echo-reference");
1052 if (out_device != AUDIO_DEVICE_NONE) {
1053 snd_device = platform_get_output_snd_device(adev->platform, out_device);
1054 platform_add_backend_name(adev->platform, my_data->ec_ref_mixer_path, snd_device);
1055 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05001056
Joe Onorato188b6222016-03-01 11:02:27 -08001057 ALOGV("%s: enabling %s", __func__, my_data->ec_ref_mixer_path);
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08001058 audio_route_apply_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
1059 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001060}
1061
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001062static struct csd_data *open_csd_client(bool i2s_ext_modem)
1063{
1064 struct csd_data *csd = calloc(1, sizeof(struct csd_data));
1065
1066 csd->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
1067 if (csd->csd_client == NULL) {
1068 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
1069 goto error;
1070 } else {
1071 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
1072
1073 csd->deinit = (deinit_t)dlsym(csd->csd_client,
1074 "csd_client_deinit");
1075 if (csd->deinit == NULL) {
1076 ALOGE("%s: dlsym error %s for csd_client_deinit", __func__,
1077 dlerror());
1078 goto error;
1079 }
1080 csd->disable_device = (disable_device_t)dlsym(csd->csd_client,
1081 "csd_client_disable_device");
1082 if (csd->disable_device == NULL) {
1083 ALOGE("%s: dlsym error %s for csd_client_disable_device",
1084 __func__, dlerror());
1085 goto error;
1086 }
1087 csd->enable_device_config = (enable_device_config_t)dlsym(csd->csd_client,
1088 "csd_client_enable_device_config");
1089 if (csd->enable_device_config == NULL) {
1090 ALOGE("%s: dlsym error %s for csd_client_enable_device_config",
1091 __func__, dlerror());
1092 goto error;
1093 }
1094 csd->enable_device = (enable_device_t)dlsym(csd->csd_client,
1095 "csd_client_enable_device");
1096 if (csd->enable_device == NULL) {
1097 ALOGE("%s: dlsym error %s for csd_client_enable_device",
1098 __func__, dlerror());
1099 goto error;
1100 }
1101 csd->start_voice = (start_voice_t)dlsym(csd->csd_client,
1102 "csd_client_start_voice");
1103 if (csd->start_voice == NULL) {
1104 ALOGE("%s: dlsym error %s for csd_client_start_voice",
1105 __func__, dlerror());
1106 goto error;
1107 }
1108 csd->stop_voice = (stop_voice_t)dlsym(csd->csd_client,
1109 "csd_client_stop_voice");
1110 if (csd->stop_voice == NULL) {
1111 ALOGE("%s: dlsym error %s for csd_client_stop_voice",
1112 __func__, dlerror());
1113 goto error;
1114 }
1115 csd->volume = (volume_t)dlsym(csd->csd_client,
1116 "csd_client_volume");
1117 if (csd->volume == NULL) {
1118 ALOGE("%s: dlsym error %s for csd_client_volume",
1119 __func__, dlerror());
1120 goto error;
1121 }
1122 csd->mic_mute = (mic_mute_t)dlsym(csd->csd_client,
1123 "csd_client_mic_mute");
1124 if (csd->mic_mute == NULL) {
1125 ALOGE("%s: dlsym error %s for csd_client_mic_mute",
1126 __func__, dlerror());
1127 goto error;
1128 }
1129 csd->slow_talk = (slow_talk_t)dlsym(csd->csd_client,
1130 "csd_client_slow_talk");
1131 if (csd->slow_talk == NULL) {
1132 ALOGE("%s: dlsym error %s for csd_client_slow_talk",
1133 __func__, dlerror());
1134 goto error;
1135 }
1136 csd->start_playback = (start_playback_t)dlsym(csd->csd_client,
1137 "csd_client_start_playback");
1138 if (csd->start_playback == NULL) {
1139 ALOGE("%s: dlsym error %s for csd_client_start_playback",
1140 __func__, dlerror());
1141 goto error;
1142 }
1143 csd->stop_playback = (stop_playback_t)dlsym(csd->csd_client,
1144 "csd_client_stop_playback");
1145 if (csd->stop_playback == NULL) {
1146 ALOGE("%s: dlsym error %s for csd_client_stop_playback",
1147 __func__, dlerror());
1148 goto error;
1149 }
1150 csd->start_record = (start_record_t)dlsym(csd->csd_client,
1151 "csd_client_start_record");
1152 if (csd->start_record == NULL) {
1153 ALOGE("%s: dlsym error %s for csd_client_start_record",
1154 __func__, dlerror());
1155 goto error;
1156 }
1157 csd->stop_record = (stop_record_t)dlsym(csd->csd_client,
1158 "csd_client_stop_record");
1159 if (csd->stop_record == NULL) {
1160 ALOGE("%s: dlsym error %s for csd_client_stop_record",
1161 __func__, dlerror());
1162 goto error;
1163 }
1164
1165 csd->get_sample_rate = (get_sample_rate_t)dlsym(csd->csd_client,
1166 "csd_client_get_sample_rate");
1167 if (csd->get_sample_rate == NULL) {
1168 ALOGE("%s: dlsym error %s for csd_client_get_sample_rate",
1169 __func__, dlerror());
1170
1171 goto error;
1172 }
1173
1174 csd->init = (init_t)dlsym(csd->csd_client, "csd_client_init");
1175
1176 if (csd->init == NULL) {
1177 ALOGE("%s: dlsym error %s for csd_client_init",
1178 __func__, dlerror());
1179 goto error;
1180 } else {
1181 csd->init(i2s_ext_modem);
1182 }
1183 }
1184 return csd;
1185
1186error:
1187 free(csd);
1188 csd = NULL;
1189 return csd;
1190}
1191
1192void close_csd_client(struct csd_data *csd)
1193{
1194 if (csd != NULL) {
1195 csd->deinit();
1196 dlclose(csd->csd_client);
1197 free(csd);
1198 csd = NULL;
1199 }
1200}
1201
1202static void platform_csd_init(struct platform_data *my_data)
1203{
1204#ifdef PLATFORM_MSM8084
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001205 int32_t modems, (*count_modems)(void);
1206 const char *name = "libdetectmodem.so";
1207 const char *func = "count_modems";
1208 const char *error;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001209
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001210 my_data->csd = NULL;
1211
1212 void *lib = dlopen(name, RTLD_NOW);
1213 error = dlerror();
1214 if (!lib) {
1215 ALOGE("%s: could not find %s: %s", __func__, name, error);
1216 return;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001217 }
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001218
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001219 count_modems = NULL;
1220 *(void **)(&count_modems) = dlsym(lib, func);
1221 error = dlerror();
1222 if (!count_modems) {
1223 ALOGE("%s: could not find symbol %s in %s: %s",
1224 __func__, func, name, error);
1225 goto done;
1226 }
1227
1228 modems = count_modems();
1229 if (modems < 0) {
1230 ALOGE("%s: count_modems failed\n", __func__);
1231 goto done;
1232 }
1233
Eric Laurent2bafff12016-03-17 12:17:23 -07001234 ALOGD("%s: num_modems %d\n", __func__, modems);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001235 if (modems > 0)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001236 my_data->csd = open_csd_client(false /*is_i2s_ext_modem*/);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001237
1238done:
1239 dlclose(lib);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001240#else
1241 my_data->csd = NULL;
1242#endif
1243}
1244
Eric Laurentc6333382015-09-14 12:43:44 -07001245static void set_platform_defaults(struct platform_data * my_data)
Haynes Mathew George98c95622014-06-20 19:14:25 -07001246{
1247 int32_t dev;
1248 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001249 backend_tag_table[dev] = NULL;
1250 hw_interface_table[dev] = NULL;
keunhui.park2f7306a2015-07-16 16:48:06 +09001251 operator_specific_device_table[dev] = NULL;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001252 }
1253
David Linee3fe402017-03-13 10:00:42 -07001254 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1255 backend_bit_width_table[dev] = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
1256 }
1257
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001258 // To overwrite these go to the audio_platform_info.xml file.
1259 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("bt-sco");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07001260 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("bt-sco");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001261 backend_tag_table[SND_DEVICE_OUT_BT_SCO] = strdup("bt-sco");
1262 backend_tag_table[SND_DEVICE_OUT_HDMI] = strdup("hdmi");
1263 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("speaker-and-hdmi");
1264 backend_tag_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("bt-sco-wb");
1265 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("bt-sco-wb");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07001266 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("bt-sco-wb");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001267 backend_tag_table[SND_DEVICE_OUT_VOICE_TX] = strdup("afe-proxy");
1268 backend_tag_table[SND_DEVICE_IN_VOICE_RX] = strdup("afe-proxy");
Haynes Mathew George98c95622014-06-20 19:14:25 -07001269
David Linee3fe402017-03-13 10:00:42 -07001270 backend_tag_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("usb-headset");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001271 backend_tag_table[SND_DEVICE_OUT_VOICE_USB_HEADSET] = strdup("usb-headset");
David Linee3fe402017-03-13 10:00:42 -07001272 backend_tag_table[SND_DEVICE_OUT_USB_HEADPHONES] = strdup("usb-headphones");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001273 backend_tag_table[SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = strdup("usb-headphones");
David Linee3fe402017-03-13 10:00:42 -07001274 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] =
1275 strdup("speaker-and-usb-headphones");
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07001276 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] =
1277 strdup("speaker-safe-and-usb-headphones");
juyuchen5351ea62018-05-16 10:54:37 +08001278 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO] =
1279 strdup("speaker-safe-and-bt-sco"),
1280 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB] =
1281 strdup("speaker-safe-and-bt-sco-wb"),
David Linee3fe402017-03-13 10:00:42 -07001282 backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("usb-headset-mic");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001283 backend_tag_table[SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1284 backend_tag_table[SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1285 backend_tag_table[SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1286 backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = strdup("usb-headset-mic");
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001287 backend_tag_table[SND_DEVICE_OUT_BT_A2DP] = strdup("bt-a2dp");
1288 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] = strdup("speaker-and-bt-a2dp");
Aniket Kumar Lata9723a962018-05-16 17:41:55 -07001289 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP] = strdup("speaker-safe-and-bt-a2dp");
jasmine cha270b7762018-03-30 15:41:33 +08001290 backend_tag_table[SND_DEVICE_OUT_USB_HEADSET_SPEC] = strdup("usb-headset");
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001291
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001292 hw_interface_table[SND_DEVICE_OUT_HANDSET] = strdup("SLIMBUS_0_RX");
1293 hw_interface_table[SND_DEVICE_OUT_SPEAKER] = strdup("SLIMBUS_0_RX");
1294 hw_interface_table[SND_DEVICE_OUT_SPEAKER_REVERSE] = strdup("SLIMBUS_0_RX");
1295 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE] = strdup("SLIMBUS_0_RX");
1296 hw_interface_table[SND_DEVICE_OUT_HEADPHONES] = strdup("SLIMBUS_0_RX");
1297 hw_interface_table[SND_DEVICE_OUT_LINE] = strdup("SLIMBUS_0_RX");
1298 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001299 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001300 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001301 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001302 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET] = strdup("SLIMBUS_0_RX");
1303 hw_interface_table[SND_DEVICE_OUT_VOICE_HAC_HANDSET] = strdup("SLIMBUS_0_RX");
1304 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER] = strdup("SLIMBUS_0_RX");
1305 hw_interface_table[SND_DEVICE_OUT_VOICE_HEADPHONES] = strdup("SLIMBUS_0_RX");
yixuanjiang9536e672018-09-06 18:43:36 +08001306 hw_interface_table[SND_DEVICE_OUT_VOICE_HEADSET] = strdup("SLIMBUS_0_RX");
juyuchen66c4ecf2018-08-06 15:39:34 +08001307 hw_interface_table[SND_DEVICE_OUT_VOICE_MUSIC_TX] = strdup("VOICE_PLAYBACK_TX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001308 hw_interface_table[SND_DEVICE_OUT_VOICE_LINE] = strdup("SLIMBUS_0_RX");
1309 hw_interface_table[SND_DEVICE_OUT_HDMI] = strdup("HDMI_RX");
1310 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("SLIMBUS_0_RX-and-HDMI_RX");
1311 hw_interface_table[SND_DEVICE_OUT_BT_SCO] = strdup("SEC_AUX_PCM_RX");
1312 hw_interface_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("SEC_AUX_PCM_RX");
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001313 hw_interface_table[SND_DEVICE_OUT_BT_A2DP] = strdup("SLIMBUS_7_RX");
1314 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] =
1315 strdup("SLIMBUS_0_RX-and-SLIMBUS_7_RX");
Aniket Kumar Lata9723a962018-05-16 17:41:55 -07001316 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP] =
1317 strdup("SLIMBUS_0_RX-and-SLIMBUS_7_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001318 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = strdup("SLIMBUS_0_RX");
1319 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = strdup("SLIMBUS_0_RX");
1320 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = strdup("SLIMBUS_0_RX");
1321 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = strdup("SLIMBUS_0_RX");
David Linee3fe402017-03-13 10:00:42 -07001322 hw_interface_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("USB_AUDIO_RX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001323 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = strdup("USB_AUDIO_RX");
1324 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = strdup("USB_AUDIO_RX");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001325 hw_interface_table[SND_DEVICE_OUT_VOICE_USB_HEADSET] = strdup("USB_AUDIO_RX");
David Linee3fe402017-03-13 10:00:42 -07001326 hw_interface_table[SND_DEVICE_OUT_USB_HEADPHONES] = strdup("USB_AUDIO_RX");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001327 hw_interface_table[SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = strdup("USB_AUDIO_RX");
jasmine cha270b7762018-03-30 15:41:33 +08001328 hw_interface_table[SND_DEVICE_OUT_USB_HEADSET_SPEC] = strdup("USB_AUDIO_RX");
David Linee3fe402017-03-13 10:00:42 -07001329 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = strdup("SLIMBUS_0_RX-and-USB_AUDIO_RX");
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07001330 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] = strdup("SLIMBUS_0_RX-and-USB_AUDIO_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001331 hw_interface_table[SND_DEVICE_OUT_VOICE_TX] = strdup("AFE_PCM_RX");
1332 hw_interface_table[SND_DEVICE_OUT_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
1333 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
jasmine cha52284622018-03-23 17:21:35 +08001334 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = strdup("SLIMBUS_0_RX");
1335 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_BT_SCO] = strdup("SLIMBUS_0_RX-and-SEC_AUX_PCM_RX");
1336 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB] = strdup("SLIMBUS_0_RX-and-SEC_AUX_PCM_RX");
juyuchen5351ea62018-05-16 10:54:37 +08001337 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO] = strdup("QUAT_TDM_RX_0-and-SLIMBUS_7_RX"),
1338 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB] = strdup("QUAT_TDM_RX_0-and-SLIMBUS_7_RX"),
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001339 hw_interface_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1340 hw_interface_table[SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1341 hw_interface_table[SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = strdup("USB_AUDIO_TX");
1342 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1343 hw_interface_table[SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1344 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = strdup("USB_AUDIO_TX");
1345 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = strdup("USB_AUDIO_TX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001346 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001347 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_AEC] = strdup("SLIMBUS_0_TX");
1348 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_NS] = strdup("SLIMBUS_0_TX");
1349 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1350 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC] = strdup("SLIMBUS_0_TX");
1351 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_AEC] = strdup("SLIMBUS_0_TX");
1352 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_NS] = strdup("SLIMBUS_0_TX");
1353 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1354 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001355 hw_interface_table[SND_DEVICE_IN_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001356 hw_interface_table[SND_DEVICE_IN_HEADSET_MIC_AEC] = strdup("SLIMBUS_0_TX");
Eric Laurent5f4ca952018-10-19 17:33:43 -07001357 hw_interface_table[SND_DEVICE_IN_CAMCORDER_LANDSCAPE] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001358 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC] = strdup("SLIMBUS_0_TX");
1359 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC_NS] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001360 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC_AEC] = strdup("SLIMBUS_0_TX");
1361 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001362 hw_interface_table[SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
1363 hw_interface_table[SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = strdup("SLIMBUS_0_TX");
David Lin93725722017-10-13 14:58:17 -07001364 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_MIC] = strdup("SLIMBUS_0_TX");
1365 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1366 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = strdup("SLIMBUS_0_TX");
1367 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = strdup("SLIMBUS_0_TX");
1368 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001369 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC] = strdup("SLIMBUS_0_TX");
1370 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_AEC] = strdup("SLIMBUS_0_TX");
1371 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_NS] = strdup("SLIMBUS_0_TX");
1372 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1373 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC] = strdup("SLIMBUS_0_TX");
1374 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_AEC] = strdup("SLIMBUS_0_TX");
1375 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_NS] = strdup("SLIMBUS_0_TX");
1376 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001377 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
1378 hw_interface_table[SND_DEVICE_IN_VOICE_DMIC] = strdup("SLIMBUS_0_TX");
1379 hw_interface_table[SND_DEVICE_IN_VOICE_DMIC_TMUS] = strdup("SLIMBUS_0_TX");
Vignesh Kulothungan64698822018-01-23 11:25:18 -08001380 hw_interface_table[SND_DEVICE_IN_SPEAKER_QMIC_NS] = strdup("SLIMBUS_0_TX");
1381 hw_interface_table[SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001382 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001383 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = strdup("SLIMBUS_0_TX");
1384 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001385 hw_interface_table[SND_DEVICE_IN_VOICE_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001386 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1387 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = strdup("SLIMBUS_0_TX");
1388 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1389 hw_interface_table[SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1390 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("SEC_AUX_PCM_TX");
1391 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("SEC_AUX_PCM_TX");
1392 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("SEC_AUX_PCM_TX");
1393 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("SEC_AUX_PCM_TX");
1394 hw_interface_table[SND_DEVICE_IN_VOICE_RX] = strdup("AFE_PCM_TX");
1395 hw_interface_table[SND_DEVICE_IN_THREE_MIC] = strdup("SLIMBUS_0_TX");
1396 hw_interface_table[SND_DEVICE_IN_QUAD_MIC] = strdup("SLIMBUS_0_TX");
1397 hw_interface_table[SND_DEVICE_IN_HANDSET_TMIC] = strdup("SLIMBUS_0_TX");
1398 hw_interface_table[SND_DEVICE_IN_HANDSET_QMIC] = strdup("SLIMBUS_0_TX");
1399 hw_interface_table[SND_DEVICE_IN_HANDSET_TMIC_AEC] = strdup("SLIMBUS_0_TX");
1400 hw_interface_table[SND_DEVICE_IN_HANDSET_QMIC_AEC] = strdup("SLIMBUS_0_TX");
Eric Laurent5f4ca952018-10-19 17:33:43 -07001401 hw_interface_table[SND_DEVICE_IN_CAMCORDER_INVERT_LANDSCAPE] = strdup("SLIMBUS_0_TX");
1402 hw_interface_table[SND_DEVICE_IN_CAMCORDER_PORTRAIT] = strdup("SLIMBUS_0_TX");
1403 hw_interface_table[SND_DEVICE_IN_CAMCORDER_SELFIE_LANDSCAPE] = strdup("SLIMBUS_0_TX");
1404 hw_interface_table[SND_DEVICE_IN_CAMCORDER_SELFIE_INVERT_LANDSCAPE] = strdup("SLIMBUS_0_TX");
1405 hw_interface_table[SND_DEVICE_IN_CAMCORDER_SELFIE_PORTRAIT] = strdup("SLIMBUS_0_TX");
Eric Laurentc6333382015-09-14 12:43:44 -07001406 my_data->max_mic_count = PLATFORM_DEFAULT_MIC_COUNT;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001407}
1408
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001409void get_cvd_version(char *cvd_version, struct audio_device *adev)
1410{
1411 struct mixer_ctl *ctl;
1412 int count;
1413 int ret = 0;
1414
1415 ctl = mixer_get_ctl_by_name(adev->mixer, CVD_VERSION_MIXER_CTL);
1416 if (!ctl) {
1417 ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__, CVD_VERSION_MIXER_CTL);
1418 goto done;
1419 }
1420 mixer_ctl_update(ctl);
1421
1422 count = mixer_ctl_get_num_values(ctl);
1423 if (count > MAX_CVD_VERSION_STRING_SIZE)
1424 count = MAX_CVD_VERSION_STRING_SIZE - 1;
1425
1426 ret = mixer_ctl_get_array(ctl, cvd_version, count);
1427 if (ret != 0) {
1428 ALOGE("%s: ERROR! mixer_ctl_get_array() failed to get CVD Version", __func__);
1429 goto done;
1430 }
1431
1432done:
1433 return;
1434}
1435
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001436static int platform_acdb_init(void *platform)
1437{
1438 struct platform_data *my_data = (struct platform_data *)platform;
1439 struct audio_device *adev = my_data->adev;
1440
1441 if (!my_data->acdb_init) {
1442 ALOGE("%s: no acdb_init fn provided", __func__);
1443 return -1;
1444 }
1445
1446 if (my_data->acdb_initialized) {
1447 ALOGW("acdb is already initialized");
1448 return 0;
1449 }
1450
Thierry Strudel07f96d12018-09-20 13:31:34 -07001451#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845) || (PLATFORM_SDM710) || (PLATFORM_SM8150)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001452 char *cvd_version = calloc(1, MAX_CVD_VERSION_STRING_SIZE);
1453 if (!cvd_version)
1454 ALOGE("failed to allocate cvd_version");
1455 else {
1456 get_cvd_version(cvd_version, adev);
1457 my_data->acdb_init((char *)my_data->snd_card_name, cvd_version, 0);
1458 free(cvd_version);
1459 }
1460#elif defined (PLATFORM_MSM8084)
1461 my_data->acdb_init((char *)my_data->snd_card_name);
1462#else
1463 my_data->acdb_init();
1464#endif
1465 my_data->acdb_initialized = true;
1466 return 0;
1467}
1468
David Linee3fe402017-03-13 10:00:42 -07001469static void
1470platform_backend_config_init(struct platform_data *pdata)
1471{
1472 int i;
1473
1474 /* initialize backend config */
1475 for (i = 0; i < MAX_CODEC_BACKENDS; i++) {
1476 pdata->current_backend_cfg[i].sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
1477 pdata->current_backend_cfg[i].bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
1478 pdata->current_backend_cfg[i].channels = CODEC_BACKEND_DEFAULT_CHANNELS;
1479
1480 if (i > MAX_RX_CODEC_BACKENDS)
1481 pdata->current_backend_cfg[i].channels = CODEC_BACKEND_DEFAULT_TX_CHANNELS;
1482
1483 pdata->current_backend_cfg[i].bitwidth_mixer_ctl = NULL;
1484 pdata->current_backend_cfg[i].samplerate_mixer_ctl = NULL;
1485 pdata->current_backend_cfg[i].channels_mixer_ctl = NULL;
1486 }
1487
1488 pdata->current_backend_cfg[DEFAULT_CODEC_BACKEND].bitwidth_mixer_ctl =
1489 strdup("SLIM_0_RX Format");
1490 pdata->current_backend_cfg[DEFAULT_CODEC_BACKEND].samplerate_mixer_ctl =
1491 strdup("SLIM_0_RX SampleRate");
1492
1493 pdata->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].bitwidth_mixer_ctl =
1494 strdup("SLIM_0_TX Format");
1495 pdata->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].samplerate_mixer_ctl =
1496 strdup("SLIM_0_TX SampleRate");
1497
1498 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].bitwidth_mixer_ctl =
1499 strdup("USB_AUDIO_TX Format");
1500 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].samplerate_mixer_ctl =
1501 strdup("USB_AUDIO_TX SampleRate");
1502 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].channels_mixer_ctl =
1503 strdup("USB_AUDIO_TX Channels");
1504
Yung Ti Su39a2b8a2018-10-05 15:43:40 +08001505 if (strstr(pdata->snd_card_name, "intcodec")) {
1506 pdata->current_backend_cfg[HEADPHONE_BACKEND].bitwidth_mixer_ctl =
1507 strdup("INT0_MI2S_RX Format");
1508 pdata->current_backend_cfg[HEADPHONE_BACKEND].samplerate_mixer_ctl =
1509 strdup("INT0_MI2S_RX SampleRate");
1510 } else {
1511 pdata->current_backend_cfg[HEADPHONE_BACKEND].bitwidth_mixer_ctl =
1512 strdup("SLIM_6_RX Format");
1513 pdata->current_backend_cfg[HEADPHONE_BACKEND].samplerate_mixer_ctl =
1514 strdup("SLIM_6_RX SampleRate");
1515 }
David Linee3fe402017-03-13 10:00:42 -07001516
1517 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].bitwidth_mixer_ctl =
1518 strdup("USB_AUDIO_RX Format");
1519 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].samplerate_mixer_ctl =
1520 strdup("USB_AUDIO_RX SampleRate");
1521
1522 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].channels = 1;
1523 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].channels_mixer_ctl =
1524 strdup("USB_AUDIO_RX Channels");
1525}
1526
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001527static int
1528platform_backend_app_type_cfg_init(struct platform_data *pdata,
1529 struct mixer *mixer)
1530{
1531 size_t app_type_cfg[128] = {0};
1532 int length, num_app_types = 0;
1533 struct mixer_ctl *ctl = NULL;
1534
1535 const char *mixer_ctl_name = "App Type Config";
1536 ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name);
1537 if (!ctl) {
1538 ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name);
1539 return -1;
1540 }
1541
1542 length = 1; // reserve index 0 for number of app types
1543
1544 struct listnode *node;
1545 struct app_type_entry *entry;
1546 list_for_each(node, &app_type_entry_list) {
1547 entry = node_to_item(node, struct app_type_entry, node);
1548 app_type_cfg[length++] = entry->app_type;
1549 app_type_cfg[length++] = entry->max_rate;
1550 app_type_cfg[length++] = entry->bit_width;
1551 ALOGI("%s add entry %d %d", __func__, entry->app_type, entry->bit_width);
1552 num_app_types += 1;
1553 }
1554
1555 // default for capture
1556 int t;
1557 platform_get_default_app_type_v2(pdata,
1558 PCM_CAPTURE,
1559 &t);
1560 app_type_cfg[length++] = t;
1561 app_type_cfg[length++] = 48000;
1562 app_type_cfg[length++] = 16;
1563 num_app_types += 1;
1564
1565 if (num_app_types) {
1566 app_type_cfg[0] = num_app_types;
1567 if (mixer_ctl_set_array(ctl, app_type_cfg, length) < 0) {
1568 ALOGE("Failed to set app type cfg");
1569 }
1570 }
1571 return 0;
1572}
1573
Xu Han1638fd12018-04-20 12:42:23 -07001574static void configure_flicker_sensor_input(struct mixer *mixer)
1575{
1576 struct mixer_ctl *ctl;
1577 const char* ctl1 = "AIF3_CAP Mixer SLIM TX2";
1578 int setting1 = 1;
1579 const char* ctl2 = "CDC_IF TX2 MUX";
1580 const char* setting2 = "DEC2";
1581 const char* ctl3 = "SLIM_1_TX Channels";
1582 const char* setting3 = "One";
1583 const char* ctl4 = "ADC MUX2";
1584 const char* setting4 = "AMIC";
1585 const char* ctl5 = "AMIC MUX2";
1586 const char* setting5 = "ADC1";
1587 const char* ctl6 = "DEC2 Volume";
1588 int setting6 = 84;
Xu Han07e07402018-05-15 14:19:25 -07001589 const char* ctl7 = "MultiMedia9 Mixer SLIM_1_TX";
Xu Han1638fd12018-04-20 12:42:23 -07001590 int setting7 = 1;
1591 const char* ctl8 = "SLIM_1_TX SampleRate";
1592 const char* setting8 = "KHZ_8";
1593
1594 ctl = mixer_get_ctl_by_name(mixer, ctl1);
1595 mixer_ctl_set_value(ctl, 0, setting1);
1596 ctl = mixer_get_ctl_by_name(mixer, ctl2);
1597 mixer_ctl_set_enum_by_string(ctl, setting2);
1598 ctl = mixer_get_ctl_by_name(mixer, ctl3);
1599 mixer_ctl_set_enum_by_string(ctl, setting3);
1600 ctl = mixer_get_ctl_by_name(mixer, ctl4);
1601 mixer_ctl_set_enum_by_string(ctl, setting4);
1602 ctl = mixer_get_ctl_by_name(mixer, ctl5);
1603 mixer_ctl_set_enum_by_string(ctl, setting5);
1604 ctl = mixer_get_ctl_by_name(mixer, ctl6);
1605 mixer_ctl_set_value(ctl, 0, setting6);
1606 ctl = mixer_get_ctl_by_name(mixer, ctl7);
1607 mixer_ctl_set_value(ctl, 0, setting7);
1608 ctl = mixer_get_ctl_by_name(mixer, ctl8);
1609 mixer_ctl_set_enum_by_string(ctl, setting8);
1610}
1611
Eric Laurentb23d5282013-05-14 15:27:20 -07001612void *platform_init(struct audio_device *adev)
1613{
1614 char value[PROPERTY_VALUE_MAX];
vivek mehta60ea4152016-02-18 17:10:26 -08001615 struct platform_data *my_data = NULL;
1616 int retry_num = 0, snd_card_num = 0, key = 0, ret = 0;
1617 bool dual_mic_config = false, use_default_mixer_path = true;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001618 const char *snd_card_name;
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001619 char *cvd_version = NULL;
vivek mehta60ea4152016-02-18 17:10:26 -08001620 char *snd_internal_name = NULL;
1621 char *tmp = NULL;
1622 char mixer_xml_file[MIXER_PATH_MAX_LENGTH]= {0};
vivek mehtade4849c2016-03-03 17:23:38 -08001623 char platform_info_file[MIXER_PATH_MAX_LENGTH]= {0};
1624 struct snd_card_split *snd_split_handle = NULL;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001625 my_data = calloc(1, sizeof(struct platform_data));
1626
1627 my_data->adev = adev;
1628
keunhui.park2f7306a2015-07-16 16:48:06 +09001629 list_init(&operator_info_list);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001630 list_init(&app_type_entry_list);
keunhui.park2f7306a2015-07-16 16:48:06 +09001631
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001632 set_platform_defaults(my_data);
1633
vivek mehta0fb11312017-05-15 19:35:32 -07001634 // audio_extn_utils_get_snd_card_num does
1635 // - open mixer and get snd card name
1636 // - parse platform info xml file and check for valid snd card name
1637 // - on failure loop through all the active snd card
sangwoo1b9f4b32013-06-21 18:22:55 -07001638
vivek mehta0fb11312017-05-15 19:35:32 -07001639 snd_card_num = audio_extn_utils_get_snd_card_num();
1640 if (-1 == snd_card_num) {
1641 ALOGE("%s: invalid sound card number (-1), bailing out ", __func__);
1642 goto init_failed;
sangwoo1b9f4b32013-06-21 18:22:55 -07001643 }
1644
vivek mehta0fb11312017-05-15 19:35:32 -07001645 adev->mixer = mixer_open(snd_card_num);
1646 snd_card_name = mixer_get_name(adev->mixer);
1647 my_data->hw_info = hw_info_init(snd_card_name);
1648
1649 audio_extn_set_snd_card_split(snd_card_name);
1650 snd_split_handle = audio_extn_get_snd_card_split();
1651
1652 /* Get the codec internal name from the sound card and/or form factor
1653 * name and form the mixer paths and platfor info file name dynamically.
1654 * This is generic way of picking any codec and forma factor name based
1655 * mixer and platform info files in future with no code change.
1656
1657 * current code extends and looks for any of the exteneded mixer path and
1658 * platform info file present based on codec and form factor.
1659
1660 * order of picking appropriate file is
1661 * <i> mixer_paths_<codec_name>_<form_factor>.xml, if file not present
1662 * <ii> mixer_paths_<codec_name>.xml, if file not present
1663 * <iii> mixer_paths.xml
1664
1665 * same order is followed for audio_platform_info.xml as well
1666 */
1667
1668 // need to carryforward old file name
1669 if (!strncmp(snd_card_name, TOMTOM_8226_SND_CARD_NAME,
1670 min(strlen(TOMTOM_8226_SND_CARD_NAME), strlen(snd_card_name)))) {
1671 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1672 MIXER_XML_BASE_STRING, TOMTOM_MIXER_FILE_SUFFIX );
1673 } else {
1674
1675 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s_%s.xml",
1676 MIXER_XML_BASE_STRING, snd_split_handle->snd_card,
1677 snd_split_handle->form_factor);
1678 if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) {
1679 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1680 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1681 MIXER_XML_BASE_STRING, snd_split_handle->snd_card);
1682
1683 if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) {
1684 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1685 strlcpy(mixer_xml_file, MIXER_XML_DEFAULT_PATH, MIXER_PATH_MAX_LENGTH);
1686 audio_extn_utils_resolve_config_file(mixer_xml_file);
1687 }
1688 }
1689 }
1690
1691 audio_extn_utils_get_platform_info(snd_card_name, platform_info_file);
1692
jiabin8962a4d2018-03-19 18:21:24 -07001693 my_data->declared_mic_count = 0;
vivek mehta0fb11312017-05-15 19:35:32 -07001694 /* Initialize platform specific ids and/or backends*/
juyuchenbf6571f2018-11-30 18:50:47 +08001695 platform_info_init(platform_info_file, my_data,
1696 true, &platform_set_parameters);
vivek mehta0fb11312017-05-15 19:35:32 -07001697
1698 ALOGD("%s: Loading mixer file: %s", __func__, mixer_xml_file);
1699 adev->audio_route = audio_route_init(snd_card_num, mixer_xml_file);
1700
1701 if (!adev->audio_route) {
1702 ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
1703 mixer_close(adev->mixer);
1704 adev->mixer = NULL;
1705 hw_info_deinit(my_data->hw_info);
1706 my_data->hw_info = NULL;
1707 goto init_failed;
1708 }
1709 adev->snd_card = snd_card_num;
1710 ALOGD("%s: Opened sound card:%d", __func__, snd_card_num);
1711
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09001712 //set max volume step for voice call
1713 property_get("ro.config.vc_call_vol_steps", value, TOSTRING(MAX_VOL_INDEX));
1714 my_data->max_vol_index = atoi(value);
1715
vivek mehta65ad12d2015-08-13 18:32:48 -07001716 property_get("persist.audio.dualmic.config",value,"");
1717 if (!strcmp("endfire", value)) {
1718 dual_mic_config = true;
1719 }
1720
John Muir9e59a962018-01-10 13:30:00 -08001721 my_data->source_mic_type = 0;
Prashant Malanic92c5962015-08-11 15:10:18 -07001722
Eric Laurentb23d5282013-05-14 15:27:20 -07001723 my_data->fluence_in_spkr_mode = false;
1724 my_data->fluence_in_voice_call = false;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001725 my_data->fluence_in_voice_comm = false;
Eric Laurentb23d5282013-05-14 15:27:20 -07001726 my_data->fluence_in_voice_rec = false;
1727
vivek mehta65ad12d2015-08-13 18:32:48 -07001728 property_get("ro.qc.sdk.audio.fluencetype", value, "none");
Prashant Malanic92c5962015-08-11 15:10:18 -07001729 if (!strcmp("fluencepro", value)) {
1730 my_data->fluence_type = FLUENCE_PRO_ENABLE;
vivek mehta65ad12d2015-08-13 18:32:48 -07001731 } else if (!strcmp("fluence", value) || (dual_mic_config)) {
Prashant Malanic92c5962015-08-11 15:10:18 -07001732 my_data->fluence_type = FLUENCE_ENABLE;
1733 } else if (!strcmp("none", value)) {
1734 my_data->fluence_type = FLUENCE_DISABLE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001735 }
1736
Prashant Malanic92c5962015-08-11 15:10:18 -07001737 if (my_data->fluence_type != FLUENCE_DISABLE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001738 property_get("persist.audio.fluence.voicecall",value,"");
1739 if (!strcmp("true", value)) {
1740 my_data->fluence_in_voice_call = true;
1741 }
1742
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001743 property_get("persist.audio.fluence.voicecomm",value,"");
1744 if (!strcmp("true", value)) {
1745 my_data->fluence_in_voice_comm = true;
1746 }
1747
Eric Laurentb23d5282013-05-14 15:27:20 -07001748 property_get("persist.audio.fluence.voicerec",value,"");
1749 if (!strcmp("true", value)) {
1750 my_data->fluence_in_voice_rec = true;
1751 }
1752
1753 property_get("persist.audio.fluence.speaker",value,"");
1754 if (!strcmp("true", value)) {
1755 my_data->fluence_in_spkr_mode = true;
1756 }
1757 }
1758
Prashant Malanic92c5962015-08-11 15:10:18 -07001759 // support max to mono, example if max count is 3, usecase supports Three, dual and mono mic
1760 switch (my_data->max_mic_count) {
1761 case 4:
1762 my_data->source_mic_type |= SOURCE_QUAD_MIC;
1763 case 3:
1764 my_data->source_mic_type |= SOURCE_THREE_MIC;
1765 case 2:
1766 my_data->source_mic_type |= SOURCE_DUAL_MIC;
1767 case 1:
1768 my_data->source_mic_type |= SOURCE_MONO_MIC;
1769 break;
1770 default:
1771 ALOGE("%s: max_mic_count (%d), is not supported, setting to default",
1772 __func__, my_data->max_mic_count);
1773 my_data->source_mic_type = SOURCE_MONO_MIC|SOURCE_DUAL_MIC;
1774 break;
1775 }
1776
1777 ALOGV("%s: Fluence_Type(%d) max_mic_count(%d) mic_type(0x%x) fluence_in_voice_call(%d)"
1778 " fluence_in_voice_comm(%d) fluence_in_voice_rec(%d) fluence_in_spkr_mode(%d) ",
1779 __func__, my_data->fluence_type, my_data->max_mic_count, my_data->source_mic_type,
1780 my_data->fluence_in_voice_call, my_data->fluence_in_voice_comm,
1781 my_data->fluence_in_voice_rec, my_data->fluence_in_spkr_mode);
1782
Eric Laurentb23d5282013-05-14 15:27:20 -07001783 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
1784 if (my_data->acdb_handle == NULL) {
1785 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
1786 } else {
1787 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
1788 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
1789 "acdb_loader_deallocate_ACDB");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001790 if (!my_data->acdb_deallocate)
1791 ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s",
1792 __func__, LIB_ACDB_LOADER);
1793
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001794 my_data->acdb_send_audio_cal_v3 = (acdb_send_audio_cal_v3_t)dlsym(my_data->acdb_handle,
1795 "acdb_loader_send_audio_cal_v3");
1796 if (!my_data->acdb_send_audio_cal_v3)
1797 ALOGE("%s: Could not find the symbol acdb_send_audio_cal_v3 from %s",
1798 __func__, LIB_ACDB_LOADER);
1799
Eric Laurentb23d5282013-05-14 15:27:20 -07001800 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
1801 "acdb_loader_send_audio_cal");
1802 if (!my_data->acdb_send_audio_cal)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001803 ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s",
Eric Laurentb23d5282013-05-14 15:27:20 -07001804 __func__, LIB_ACDB_LOADER);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001805
Eric Laurentb23d5282013-05-14 15:27:20 -07001806 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
1807 "acdb_loader_send_voice_cal");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001808 if (!my_data->acdb_send_voice_cal)
1809 ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s",
1810 __func__, LIB_ACDB_LOADER);
1811
1812 my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle,
1813 "acdb_loader_reload_vocvoltable");
1814 if (!my_data->acdb_reload_vocvoltable)
1815 ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s",
1816 __func__, LIB_ACDB_LOADER);
vivek mehta1a9b7c02015-06-25 11:49:38 -07001817
1818 my_data->acdb_send_gain_dep_cal = (acdb_send_gain_dep_cal_t)dlsym(my_data->acdb_handle,
1819 "acdb_loader_send_gain_dep_cal");
1820 if (!my_data->acdb_send_gain_dep_cal)
1821 ALOGV("%s: Could not find the symbol acdb_loader_send_gain_dep_cal from %s",
1822 __func__, LIB_ACDB_LOADER);
1823
Xu Han1638fd12018-04-20 12:42:23 -07001824#if defined (FLICKER_SENSOR_INPUT)
1825 configure_flicker_sensor_input(adev->mixer);
1826#endif
1827
Thierry Strudel07f96d12018-09-20 13:31:34 -07001828#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845) || (PLATFORM_SDM710) || (PLATFORM_SM8150)
vivek mehta0fb11312017-05-15 19:35:32 -07001829 acdb_init_v2_cvd_t acdb_init_local;
1830 acdb_init_local = (acdb_init_v2_cvd_t)dlsym(my_data->acdb_handle,
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001831 "acdb_loader_init_v2");
vivek mehta0fb11312017-05-15 19:35:32 -07001832 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001833 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1834 dlerror());
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001835
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001836#elif defined (PLATFORM_MSM8084)
vivek mehta0fb11312017-05-15 19:35:32 -07001837 acdb_init_v2_t acdb_init_local;
1838 acdb_init_local = (acdb_init_v2_t)dlsym(my_data->acdb_handle,
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001839 "acdb_loader_init_v2");
vivek mehta0fb11312017-05-15 19:35:32 -07001840 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001841 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1842 dlerror());
1843
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001844#else
vivek mehta0fb11312017-05-15 19:35:32 -07001845 acdb_init_t acdb_init_local;
1846 acdb_init_local = (acdb_init_t)dlsym(my_data->acdb_handle,
Eric Laurentb23d5282013-05-14 15:27:20 -07001847 "acdb_loader_init_ACDB");
vivek mehta0fb11312017-05-15 19:35:32 -07001848 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001849 ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__,
1850 dlerror());
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001851#endif
vivek mehta0fb11312017-05-15 19:35:32 -07001852 my_data->acdb_init = acdb_init_local;
Eric Laurentb23d5282013-05-14 15:27:20 -07001853
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001854 my_data->acdb_send_custom_top = (acdb_send_custom_top_t)
1855 dlsym(my_data->acdb_handle,
1856 "acdb_loader_send_common_custom_topology");
1857
1858 if (!my_data->acdb_send_custom_top)
1859 ALOGE("%s: Could not find the symbol acdb_get_default_app_type from %s",
1860 __func__, LIB_ACDB_LOADER);
1861
jasmine chac89321b2018-04-10 21:37:01 +08001862 my_data->acdb_set_audio_cal = (acdb_set_audio_cal_t)dlsym(my_data->acdb_handle,
1863 "acdb_loader_set_audio_cal_v2");
1864 if (!my_data->acdb_set_audio_cal)
1865 ALOGE("%s: Could not find the symbol acdb_set_audio_cal_v2 from %s",
1866 __func__, LIB_ACDB_LOADER);
1867
vivek mehta0fb11312017-05-15 19:35:32 -07001868 int result = acdb_init(adev->snd_card);
1869 if (!result) {
1870 my_data->acdb_initialized = true;
1871 ALOGD("ACDB initialized");
1872 } else {
1873 my_data->acdb_initialized = false;
1874 ALOGD("ACDB initialization failed");
1875 }
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001876 }
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001877
David Linee3fe402017-03-13 10:00:42 -07001878 /* init usb */
1879 audio_extn_usb_init(adev);
1880
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001881 /* init a2dp */
1882 audio_extn_a2dp_init(adev);
1883
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001884 audio_extn_spkr_prot_init(adev);
Haynes Mathew George98c95622014-06-20 19:14:25 -07001885
Ravi Kumar Alamanda76315572015-04-23 13:13:56 -07001886 audio_extn_hwdep_cal_send(adev->snd_card, my_data->acdb_handle);
1887
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001888 /* load csd client */
1889 platform_csd_init(my_data);
1890
David Linee3fe402017-03-13 10:00:42 -07001891 platform_backend_config_init(my_data);
1892
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001893 init_be_dai_name_table(adev);
1894
1895 if (platform_supports_app_type_cfg())
1896 platform_backend_app_type_cfg_init(my_data, adev->mixer);
1897
Eric Laurentb23d5282013-05-14 15:27:20 -07001898 return my_data;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001899
1900init_failed:
1901 if (my_data)
1902 free(my_data);
1903 return NULL;
Eric Laurentb23d5282013-05-14 15:27:20 -07001904}
1905
1906void platform_deinit(void *platform)
1907{
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001908 int32_t dev;
keunhui.park2f7306a2015-07-16 16:48:06 +09001909 struct operator_info *info_item;
1910 struct operator_specific_device *device_item;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001911 struct app_type_entry *ap;
keunhui.park2f7306a2015-07-16 16:48:06 +09001912 struct listnode *node;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001913
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001914 struct platform_data *my_data = (struct platform_data *)platform;
1915 close_csd_client(my_data->csd);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001916
David Lin41b4fe42018-07-08 16:14:24 -07001917 audio_extn_spkr_prot_deinit(my_data->adev);
1918
vivek mehtade4849c2016-03-03 17:23:38 -08001919 hw_info_deinit(my_data->hw_info);
1920
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001921 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1922 if (backend_tag_table[dev])
1923 free(backend_tag_table[dev]);
1924 if (hw_interface_table[dev])
1925 free(hw_interface_table[dev]);
keunhui.park2f7306a2015-07-16 16:48:06 +09001926 if (operator_specific_device_table[dev]) {
1927 while (!list_empty(operator_specific_device_table[dev])) {
1928 node = list_head(operator_specific_device_table[dev]);
1929 list_remove(node);
1930 device_item = node_to_item(node, struct operator_specific_device, list);
1931 free(device_item->operator);
1932 free(device_item->mixer_path);
1933 free(device_item);
1934 }
1935 free(operator_specific_device_table[dev]);
1936 }
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001937 }
1938
1939 if (my_data->snd_card_name)
1940 free(my_data->snd_card_name);
1941
keunhui.park2f7306a2015-07-16 16:48:06 +09001942 while (!list_empty(&operator_info_list)) {
1943 node = list_head(&operator_info_list);
1944 list_remove(node);
1945 info_item = node_to_item(node, struct operator_info, list);
1946 free(info_item->name);
1947 free(info_item->mccmnc);
1948 free(info_item);
1949 }
1950
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001951 while (!list_empty(&app_type_entry_list)) {
1952 node = list_head(&app_type_entry_list);
1953 list_remove(node);
1954 ap = node_to_item(node, struct app_type_entry, node);
vivek mehtaa68fea62017-06-08 19:04:02 -07001955 if (ap->mode) free(ap->mode);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001956 free(ap);
1957 }
1958
Kevin Rocarde35d4af2017-05-02 16:55:28 -07001959 mixer_close(my_data->adev->mixer);
Eric Laurentb23d5282013-05-14 15:27:20 -07001960 free(platform);
David Linee3fe402017-03-13 10:00:42 -07001961
1962 /* deinit usb */
1963 audio_extn_usb_deinit();
Eric Laurentb23d5282013-05-14 15:27:20 -07001964}
1965
1966const char *platform_get_snd_device_name(snd_device_t snd_device)
1967{
keunhui.park2f7306a2015-07-16 16:48:06 +09001968 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1969 if (operator_specific_device_table[snd_device] != NULL) {
1970 return get_operator_specific_device_mixer_path(snd_device);
1971 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001972 return device_table[snd_device];
keunhui.park2f7306a2015-07-16 16:48:06 +09001973 } else
Ravi Kumar Alamanda64026462014-09-15 00:08:58 -07001974 return "none";
Eric Laurentb23d5282013-05-14 15:27:20 -07001975}
1976
vivek mehtade4849c2016-03-03 17:23:38 -08001977int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
1978 char *device_name)
1979{
1980 struct platform_data *my_data = (struct platform_data *)platform;
1981
David Benjamin1565f992016-09-21 12:10:34 -04001982 if (platform == NULL) {
vivek mehtade4849c2016-03-03 17:23:38 -08001983 ALOGW("%s: something wrong, use legacy get_snd_device name", __func__);
David Benjamin1565f992016-09-21 12:10:34 -04001984 strlcpy(device_name, platform_get_snd_device_name(snd_device),
1985 DEVICE_NAME_MAX_SIZE);
vivek mehtade4849c2016-03-03 17:23:38 -08001986 } else if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1987 if (operator_specific_device_table[snd_device] != NULL) {
1988 strlcpy(device_name, get_operator_specific_device_mixer_path(snd_device),
1989 DEVICE_NAME_MAX_SIZE);
1990 } else {
1991 strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE);
1992 }
1993 hw_info_append_hw_type(my_data->hw_info, snd_device, device_name);
1994 } else {
1995 strlcpy(device_name, "none", DEVICE_NAME_MAX_SIZE);
Aniket Kumar Lataa158e862018-05-11 17:28:40 -07001996 return -EINVAL;
vivek mehtade4849c2016-03-03 17:23:38 -08001997 }
1998
1999 return 0;
2000}
2001
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05002002void platform_add_backend_name(void *platform, char *mixer_path,
2003 snd_device_t snd_device)
Eric Laurentb23d5282013-05-14 15:27:20 -07002004{
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05002005 struct platform_data *my_data = (struct platform_data *)platform;
2006
Haynes Mathew George98c95622014-06-20 19:14:25 -07002007 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
2008 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
2009 return;
Ravi Kumar Alamanda1de6e5a2014-06-19 21:55:39 -05002010 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07002011
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002012 const char * suffix = backend_tag_table[snd_device];
Haynes Mathew George98c95622014-06-20 19:14:25 -07002013
2014 if (suffix != NULL) {
2015 strcat(mixer_path, " ");
2016 strcat(mixer_path, suffix);
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05002017 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002018}
2019
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002020bool platform_check_backends_match(snd_device_t snd_device1, snd_device_t snd_device2)
2021{
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002022 ALOGV("%s: snd_device1 = %s, snd_device2 = %s", __func__,
2023 platform_get_snd_device_name(snd_device1),
2024 platform_get_snd_device_name(snd_device2));
2025
2026 if ((snd_device1 < SND_DEVICE_MIN) || (snd_device1 >= SND_DEVICE_MAX)) {
2027 ALOGE("%s: Invalid snd_device = %s", __func__,
2028 platform_get_snd_device_name(snd_device1));
2029 return false;
2030 }
2031 if ((snd_device2 < SND_DEVICE_MIN) || (snd_device2 >= SND_DEVICE_MAX)) {
2032 ALOGE("%s: Invalid snd_device = %s", __func__,
2033 platform_get_snd_device_name(snd_device2));
2034 return false;
2035 }
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07002036
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002037 const char * be_itf1 = hw_interface_table[snd_device1];
2038 const char * be_itf2 = hw_interface_table[snd_device2];
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07002039 /*
2040 hw_interface_table has overrides for a snd_device.
2041 if there is no entry for a device, assume DEFAULT_RX_BACKEND
2042 */
2043 if (be_itf1 == NULL) {
2044 be_itf1 = DEFAULT_RX_BACKEND;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002045 }
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07002046 if (be_itf2 == NULL) {
2047 be_itf2 = DEFAULT_RX_BACKEND;
2048 }
2049 ALOGV("%s: be_itf1 = %s, be_itf2 = %s", __func__, be_itf1, be_itf2);
2050 /*
2051 this takes care of finding a device within a combo device pair as well
2052 */
2053 return strstr(be_itf1, be_itf2) != NULL || strstr(be_itf2, be_itf1) != NULL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002054}
2055
Eric Laurentb23d5282013-05-14 15:27:20 -07002056int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
2057{
2058 int device_id;
2059 if (device_type == PCM_PLAYBACK)
2060 device_id = pcm_device_table[usecase][0];
2061 else
2062 device_id = pcm_device_table[usecase][1];
2063 return device_id;
2064}
2065
Vignesh Kulothungan019d19b2019-01-23 11:09:18 -08002066int platform_get_haptics_pcm_device_id()
2067{
2068 return HAPTICS_PCM_DEVICE;
2069}
2070
Haynes Mathew George98c95622014-06-20 19:14:25 -07002071static int find_index(const struct name_to_index * table, int32_t len,
2072 const char * name)
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002073{
2074 int ret = 0;
Haynes Mathew George98c95622014-06-20 19:14:25 -07002075 int32_t i;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002076
Haynes Mathew George98c95622014-06-20 19:14:25 -07002077 if (table == NULL) {
2078 ALOGE("%s: table is NULL", __func__);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002079 ret = -ENODEV;
2080 goto done;
2081 }
2082
Haynes Mathew George98c95622014-06-20 19:14:25 -07002083 if (name == NULL) {
2084 ALOGE("null key");
2085 ret = -ENODEV;
2086 goto done;
2087 }
2088
2089 for (i=0; i < len; i++) {
2090 if (!strcmp(table[i].name, name)) {
2091 ret = table[i].index;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002092 goto done;
2093 }
2094 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07002095 ALOGE("%s: Could not find index for name = %s",
2096 __func__, name);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002097 ret = -ENODEV;
2098done:
2099 return ret;
2100}
2101
Haynes Mathew George98c95622014-06-20 19:14:25 -07002102int platform_get_snd_device_index(char *device_name)
2103{
2104 return find_index(snd_device_name_index, SND_DEVICE_MAX, device_name);
2105}
2106
2107int platform_get_usecase_index(const char *usecase_name)
2108{
2109 return find_index(usecase_name_index, AUDIO_USECASE_MAX, usecase_name);
2110}
2111
Vignesh Kulothungan64698822018-01-23 11:25:18 -08002112int platform_get_effect_config_data(snd_device_t snd_device,
2113 struct audio_effect_config *effect_config,
2114 effect_type_t effect_type)
2115{
2116 int ret = 0;
2117
2118 if ((snd_device < SND_DEVICE_IN_BEGIN) || (snd_device >= SND_DEVICE_MAX) ||
2119 (effect_type <= EFFECT_NONE) || (effect_type >= EFFECT_COUNT)) {
2120 ALOGE("%s: Invalid snd_device = %d or effect_type = %d",
2121 __func__, snd_device, effect_type);
2122 ret = -EINVAL;
2123 goto done;
2124 }
2125
2126 if (effect_config == NULL) {
2127 ALOGE("%s: Invalid effect_config", __func__);
2128 ret = -EINVAL;
2129 goto done;
2130 }
2131
2132 ALOGV("%s: snd_device = %d module_id = %d",
2133 __func__, snd_device, effect_config_table[GET_IN_DEVICE_INDEX(snd_device)][effect_type].module_id);
2134 *effect_config = effect_config_table[GET_IN_DEVICE_INDEX(snd_device)][effect_type];
2135
2136done:
2137 return ret;
2138}
2139
2140int platform_set_effect_config_data(snd_device_t snd_device,
2141 struct audio_effect_config effect_config,
2142 effect_type_t effect_type)
2143{
2144 int ret = 0;
2145
2146 if ((snd_device < SND_DEVICE_IN_BEGIN) || (snd_device >= SND_DEVICE_MAX) ||
2147 (effect_type <= EFFECT_NONE) || (effect_type >= EFFECT_COUNT)) {
2148 ALOGE("%s: Invalid snd_device = %d or effect_type = %d",
2149 __func__, snd_device, effect_type);
2150 ret = -EINVAL;
2151 goto done;
2152 }
2153
2154 ALOGV("%s 0x%x 0x%x 0x%x 0x%x", __func__, effect_config.module_id,
2155 effect_config.instance_id, effect_config.param_id,
2156 effect_config.param_value);
2157 effect_config_table[GET_IN_DEVICE_INDEX(snd_device)][effect_type] = effect_config;
2158
2159done:
2160 return ret;
2161}
2162
keunhui.park2f7306a2015-07-16 16:48:06 +09002163void platform_add_operator_specific_device(snd_device_t snd_device,
2164 const char *operator,
2165 const char *mixer_path,
2166 unsigned int acdb_id)
2167{
2168 struct operator_specific_device *device;
2169
2170 if (operator_specific_device_table[snd_device] == NULL) {
2171 operator_specific_device_table[snd_device] =
2172 (struct listnode *)calloc(1, sizeof(struct listnode));
2173 list_init(operator_specific_device_table[snd_device]);
2174 }
2175
2176 device = (struct operator_specific_device *)calloc(1, sizeof(struct operator_specific_device));
2177
2178 device->operator = strdup(operator);
2179 device->mixer_path = strdup(mixer_path);
2180 device->acdb_id = acdb_id;
2181
2182 list_add_tail(operator_specific_device_table[snd_device], &device->list);
2183
Eric Laurent2bafff12016-03-17 12:17:23 -07002184 ALOGD("%s: device[%s] -> operator[%s] mixer_path[%s] acdb_id[%d]", __func__,
keunhui.park2f7306a2015-07-16 16:48:06 +09002185 platform_get_snd_device_name(snd_device), operator, mixer_path, acdb_id);
2186
2187}
2188
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002189int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
2190{
2191 int ret = 0;
2192
2193 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
2194 ALOGE("%s: Invalid snd_device = %d",
2195 __func__, snd_device);
2196 ret = -EINVAL;
2197 goto done;
2198 }
2199
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002200 ALOGV("%s: acdb_device_table[%s]: old = %d new = %d", __func__,
2201 platform_get_snd_device_name(snd_device), acdb_device_table[snd_device], acdb_id);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002202 acdb_device_table[snd_device] = acdb_id;
2203done:
2204 return ret;
2205}
2206
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07002207int platform_get_snd_device_acdb_id(snd_device_t snd_device)
2208{
2209 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
2210 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
2211 return -EINVAL;
2212 }
keunhui.park2f7306a2015-07-16 16:48:06 +09002213
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002214 /*
2215 * If speaker protection is enabled, function returns supported
2216 * sound device for speaker. Else same sound device is returned.
2217 */
2218 snd_device = audio_extn_get_spkr_prot_snd_device(snd_device);
2219
keunhui.park2f7306a2015-07-16 16:48:06 +09002220 if (operator_specific_device_table[snd_device] != NULL)
2221 return get_operator_specific_device_acdb_id(snd_device);
2222 else
2223 return acdb_device_table[snd_device];
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07002224}
2225
David Linee3fe402017-03-13 10:00:42 -07002226static int platform_get_backend_index(snd_device_t snd_device)
2227{
2228 int32_t port = DEFAULT_CODEC_BACKEND;
2229
2230 if (snd_device >= SND_DEVICE_OUT_BEGIN && snd_device < SND_DEVICE_OUT_END) {
2231 if (backend_tag_table[snd_device] != NULL) {
2232 if (strncmp(backend_tag_table[snd_device], "headphones",
2233 sizeof("headphones")) == 0)
2234 port = HEADPHONE_BACKEND;
2235 else if (strcmp(backend_tag_table[snd_device], "hdmi") == 0)
2236 port = HDMI_RX_BACKEND;
2237 else if ((strcmp(backend_tag_table[snd_device], "usb-headphones") == 0) ||
2238 (strcmp(backend_tag_table[snd_device], "usb-headset") == 0))
2239 port = USB_AUDIO_RX_BACKEND;
2240 }
2241 } else if (snd_device >= SND_DEVICE_IN_BEGIN && snd_device < SND_DEVICE_IN_END) {
2242 port = DEFAULT_CODEC_TX_BACKEND;
2243 if (backend_tag_table[snd_device] != NULL) {
2244 if (strcmp(backend_tag_table[snd_device], "usb-headset-mic") == 0)
2245 port = USB_AUDIO_TX_BACKEND;
2246 else if (strstr(backend_tag_table[snd_device], "bt-sco") != NULL)
2247 port = BT_SCO_TX_BACKEND;
2248 }
2249 } else {
2250 ALOGW("%s:napb: Invalid device - %d ", __func__, snd_device);
2251 }
2252
2253 ALOGV("%s:napb: backend port - %d device - %d ", __func__, port, snd_device);
2254
2255 return port;
2256}
2257
Eric Laurentb23d5282013-05-14 15:27:20 -07002258int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
2259{
2260 struct platform_data *my_data = (struct platform_data *)platform;
2261 int acdb_dev_id, acdb_dev_type;
2262
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002263 if (platform_supports_app_type_cfg()) // use v2 instead
2264 return -ENOSYS;
2265
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002266 acdb_dev_id = platform_get_snd_device_acdb_id(snd_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07002267 if (acdb_dev_id < 0) {
2268 ALOGE("%s: Could not find acdb id for device(%d)",
2269 __func__, snd_device);
2270 return -EINVAL;
2271 }
2272 if (my_data->acdb_send_audio_cal) {
Joe Onorato188b6222016-03-01 11:02:27 -08002273 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Eric Laurentb23d5282013-05-14 15:27:20 -07002274 __func__, snd_device, acdb_dev_id);
2275 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
2276 snd_device < SND_DEVICE_OUT_END)
2277 acdb_dev_type = ACDB_DEV_TYPE_OUT;
2278 else
2279 acdb_dev_type = ACDB_DEV_TYPE_IN;
2280 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
2281 }
2282 return 0;
2283}
2284
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002285int platform_send_audio_calibration_v2(void *platform, struct audio_usecase *usecase,
2286 int app_type, int sample_rate)
2287{
2288 struct platform_data *my_data = (struct platform_data *)platform;
2289 int acdb_dev_id, acdb_dev_type;
vivek mehta7e573672018-03-13 17:41:41 -07002290 int snd_device = usecase->out_snd_device;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002291 int new_snd_device[SND_DEVICE_OUT_END] = {0};
2292 int i, num_devices = 1;
2293
2294 if (!platform_supports_app_type_cfg()) // use v1 instead
2295 return -ENOSYS;
2296
vivek mehta7e573672018-03-13 17:41:41 -07002297 if ((usecase->type == PCM_HFP_CALL) || (usecase->type == PCM_CAPTURE))
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002298 snd_device = usecase->in_snd_device;
2299
2300 // skipped over get_spkr_prot_device
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002301 acdb_dev_id = platform_get_snd_device_acdb_id(snd_device);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002302 if (acdb_dev_id < 0) {
2303 ALOGE("%s: Could not find acdb id for device(%d)",
2304 __func__, snd_device);
2305 return -EINVAL;
2306 }
2307
2308 if (platform_can_split_snd_device(snd_device,
2309 &num_devices, new_snd_device) < 0) {
2310 new_snd_device[0] = snd_device;
2311 }
2312
2313 for (i = 0; i < num_devices; i++) {
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002314 acdb_dev_id = platform_get_snd_device_acdb_id(new_snd_device[i]);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002315 if (acdb_dev_id < 0) {
2316 ALOGE("%s: Could not find acdb id for device(%d)",
2317 __func__, new_snd_device[i]);
2318 return -EINVAL;
2319 }
2320 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
2321 __func__, new_snd_device[i], acdb_dev_id);
2322 if (new_snd_device[i] >= SND_DEVICE_OUT_BEGIN &&
2323 new_snd_device[i] < SND_DEVICE_OUT_END)
2324 acdb_dev_type = ACDB_DEV_TYPE_OUT;
2325 else
2326 acdb_dev_type = ACDB_DEV_TYPE_IN;
2327
2328 if (my_data->acdb_send_audio_cal_v3) {
2329 my_data->acdb_send_audio_cal_v3(acdb_dev_id, acdb_dev_type,
2330 app_type, sample_rate, i);
2331 } else if (my_data->acdb_send_audio_cal) {
2332 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type); // this version differs from internal
2333 }
2334 }
2335
2336 return 0;
2337}
2338
2339
Eric Laurentb23d5282013-05-14 15:27:20 -07002340int platform_switch_voice_call_device_pre(void *platform)
2341{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002342 struct platform_data *my_data = (struct platform_data *)platform;
2343 int ret = 0;
2344
2345 if (my_data->csd != NULL &&
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002346 voice_is_in_call(my_data->adev)) {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002347 /* This must be called before disabling mixer controls on APQ side */
2348 ret = my_data->csd->disable_device();
2349 if (ret < 0) {
2350 ALOGE("%s: csd_client_disable_device, failed, error %d",
2351 __func__, ret);
2352 }
2353 }
2354 return ret;
2355}
2356
2357int platform_switch_voice_call_enable_device_config(void *platform,
2358 snd_device_t out_snd_device,
2359 snd_device_t in_snd_device)
2360{
2361 struct platform_data *my_data = (struct platform_data *)platform;
2362 int acdb_rx_id, acdb_tx_id;
2363 int ret = 0;
2364
2365 if (my_data->csd == NULL)
2366 return ret;
2367
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002368 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
keunhui.park2f7306a2015-07-16 16:48:06 +09002369 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002370
2371 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
2372 ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
2373 if (ret < 0) {
2374 ALOGE("%s: csd_enable_device_config, failed, error %d",
2375 __func__, ret);
2376 }
2377 } else {
2378 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2379 acdb_rx_id, acdb_tx_id);
2380 }
2381
2382 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002383}
2384
2385int platform_switch_voice_call_device_post(void *platform,
2386 snd_device_t out_snd_device,
2387 snd_device_t in_snd_device)
2388{
2389 struct platform_data *my_data = (struct platform_data *)platform;
2390 int acdb_rx_id, acdb_tx_id;
2391
2392 if (my_data->acdb_send_voice_cal == NULL) {
2393 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
2394 } else {
keunhui.park2f7306a2015-07-16 16:48:06 +09002395 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
2396 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07002397
2398 if (acdb_rx_id > 0 && acdb_tx_id > 0)
2399 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
2400 else
2401 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2402 acdb_rx_id, acdb_tx_id);
2403 }
2404
2405 return 0;
2406}
2407
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002408int platform_switch_voice_call_usecase_route_post(void *platform,
2409 snd_device_t out_snd_device,
2410 snd_device_t in_snd_device)
2411{
2412 struct platform_data *my_data = (struct platform_data *)platform;
2413 int acdb_rx_id, acdb_tx_id;
2414 int ret = 0;
2415
2416 if (my_data->csd == NULL)
2417 return ret;
2418
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002419 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
keunhui.park2f7306a2015-07-16 16:48:06 +09002420 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002421
2422 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
2423 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
2424 my_data->adev->acdb_settings);
2425 if (ret < 0) {
2426 ALOGE("%s: csd_enable_device, failed, error %d", __func__, ret);
2427 }
2428 } else {
2429 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2430 acdb_rx_id, acdb_tx_id);
2431 }
2432
2433 return ret;
2434}
2435
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002436int platform_start_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07002437{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002438 struct platform_data *my_data = (struct platform_data *)platform;
2439 int ret = 0;
2440
2441 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002442 ret = my_data->csd->start_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002443 if (ret < 0) {
2444 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
2445 }
2446 }
2447 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002448}
2449
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002450int platform_stop_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07002451{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002452 struct platform_data *my_data = (struct platform_data *)platform;
2453 int ret = 0;
2454
2455 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002456 ret = my_data->csd->stop_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002457 if (ret < 0) {
2458 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
2459 }
2460 }
2461 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002462}
2463
Vignesh Kulothunganb6f0a9c2018-03-22 13:50:22 -07002464int platform_set_mic_break_det(void *platform, bool enable)
2465{
2466 int ret = 0;
2467 struct platform_data *my_data = (struct platform_data *)platform;
2468 struct audio_device *adev = my_data->adev;
2469 const char *mixer_ctl_name = "Voice Mic Break Enable";
2470 struct mixer_ctl *ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2471 if (!ctl) {
2472 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2473 __func__, mixer_ctl_name);
2474 return -EINVAL;
2475 }
2476
2477 ret = mixer_ctl_set_value(ctl, 0, enable);
2478 if(ret)
2479 ALOGE("%s: Failed to set mixer ctl: %s", __func__, mixer_ctl_name);
2480
2481 return ret;
2482}
2483
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002484int platform_get_sample_rate(void *platform, uint32_t *rate)
2485{
2486 struct platform_data *my_data = (struct platform_data *)platform;
2487 int ret = 0;
2488
2489 if (my_data->csd != NULL) {
2490 ret = my_data->csd->get_sample_rate(rate);
2491 if (ret < 0) {
2492 ALOGE("%s: csd_get_sample_rate error %d\n", __func__, ret);
2493 }
2494 }
2495 return ret;
2496}
2497
vivek mehtab6506412015-08-07 16:55:17 -07002498void platform_set_speaker_gain_in_combo(struct audio_device *adev,
2499 snd_device_t snd_device,
2500 bool enable)
2501{
2502 const char* name;
2503 switch (snd_device) {
2504 case SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES:
2505 if (enable)
2506 name = "spkr-gain-in-headphone-combo";
2507 else
2508 name = "speaker-gain-default";
2509 break;
2510 case SND_DEVICE_OUT_SPEAKER_AND_LINE:
2511 if (enable)
2512 name = "spkr-gain-in-line-combo";
2513 else
2514 name = "speaker-gain-default";
2515 break;
2516 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES:
2517 if (enable)
2518 name = "spkr-safe-gain-in-headphone-combo";
2519 else
2520 name = "speaker-safe-gain-default";
2521 break;
2522 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE:
2523 if (enable)
2524 name = "spkr-safe-gain-in-line-combo";
2525 else
2526 name = "speaker-safe-gain-default";
2527 break;
2528 default:
2529 return;
2530 }
2531
2532 audio_route_apply_and_update_path(adev->audio_route, name);
2533}
2534
Eric Laurentb23d5282013-05-14 15:27:20 -07002535int platform_set_voice_volume(void *platform, int volume)
2536{
2537 struct platform_data *my_data = (struct platform_data *)platform;
2538 struct audio_device *adev = my_data->adev;
2539 struct mixer_ctl *ctl;
sangwoo53b2cf02013-07-25 19:18:44 -07002540 const char *mixer_ctl_name = "Voice Rx Gain";
Nadav Barc46d0fa2017-12-24 14:50:37 +02002541 const char *mute_mixer_ctl_name = "Voice Rx Device Mute";
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002542 int vol_index = 0, ret = 0;
2543 uint32_t set_values[ ] = {0,
2544 ALL_SESSION_VSID,
2545 DEFAULT_VOLUME_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07002546
2547 // Voice volume levels are mapped to adsp volume levels as follows.
2548 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
2549 // But this values don't changed in kernel. So, below change is need.
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09002550 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, my_data->max_vol_index);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002551 set_values[0] = vol_index;
Eric Laurentb23d5282013-05-14 15:27:20 -07002552
2553 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2554 if (!ctl) {
2555 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2556 __func__, mixer_ctl_name);
2557 return -EINVAL;
2558 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002559 ALOGV("Setting voice volume index: %d", set_values[0]);
2560 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2561
Nadav Barc46d0fa2017-12-24 14:50:37 +02002562 // Send mute command in case volume index is max since indexes are inverted
2563 // for mixer controls.
2564 if (vol_index == my_data->max_vol_index) {
2565 set_values[0] = 1;
2566 }
2567 else {
2568 set_values[0] = 0;
2569 }
2570
2571 ctl = mixer_get_ctl_by_name(adev->mixer, mute_mixer_ctl_name);
2572 if (!ctl) {
2573 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2574 __func__, mute_mixer_ctl_name);
2575 return -EINVAL;
2576 }
2577 ALOGV("%s: Setting RX Device Mute to: %d", __func__, set_values[0]);
2578 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2579
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002580 if (my_data->csd != NULL) {
2581 ret = my_data->csd->volume(ALL_SESSION_VSID, volume,
2582 DEFAULT_VOLUME_RAMP_DURATION_MS);
2583 if (ret < 0) {
2584 ALOGE("%s: csd_volume error %d", __func__, ret);
2585 }
2586 }
2587 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002588}
2589
2590int platform_set_mic_mute(void *platform, bool state)
2591{
2592 struct platform_data *my_data = (struct platform_data *)platform;
2593 struct audio_device *adev = my_data->adev;
2594 struct mixer_ctl *ctl;
2595 const char *mixer_ctl_name = "Voice Tx Mute";
sangwoo53b2cf02013-07-25 19:18:44 -07002596 int ret = 0;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002597 uint32_t set_values[ ] = {0,
2598 ALL_SESSION_VSID,
2599 DEFAULT_MUTE_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07002600
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09002601 if (adev->mode != AUDIO_MODE_IN_CALL &&
2602 adev->mode != AUDIO_MODE_IN_COMMUNICATION)
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002603 return 0;
2604
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09002605 if (adev->enable_hfp)
2606 mixer_ctl_name = "HFP Tx Mute";
2607
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002608 set_values[0] = state;
2609 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2610 if (!ctl) {
2611 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2612 __func__, mixer_ctl_name);
2613 return -EINVAL;
2614 }
Arun Mirpuri0cc2f312018-05-29 17:26:07 -07002615 ALOGV("%s: Setting voice mute state: %d", __func__, state);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002616 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2617
2618 if (my_data->csd != NULL) {
2619 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state,
2620 DEFAULT_MUTE_RAMP_DURATION_MS);
sangwoo53b2cf02013-07-25 19:18:44 -07002621 if (ret < 0) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002622 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
sangwoo53b2cf02013-07-25 19:18:44 -07002623 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002624 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002625 return ret;
2626}
Eric Laurentb23d5282013-05-14 15:27:20 -07002627
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002628int platform_set_device_mute(void *platform, bool state, char *dir)
2629{
2630 struct platform_data *my_data = (struct platform_data *)platform;
2631 struct audio_device *adev = my_data->adev;
2632 struct mixer_ctl *ctl;
2633 char *mixer_ctl_name = NULL;
2634 int ret = 0;
2635 uint32_t set_values[ ] = {0,
2636 ALL_SESSION_VSID,
2637 0};
2638 if(dir == NULL) {
2639 ALOGE("%s: Invalid direction:%s", __func__, dir);
2640 return -EINVAL;
2641 }
2642
2643 if (!strncmp("rx", dir, sizeof("rx"))) {
2644 mixer_ctl_name = "Voice Rx Device Mute";
2645 } else if (!strncmp("tx", dir, sizeof("tx"))) {
2646 mixer_ctl_name = "Voice Tx Device Mute";
2647 } else {
2648 return -EINVAL;
2649 }
2650
2651 set_values[0] = state;
2652 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2653 if (!ctl) {
2654 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2655 __func__, mixer_ctl_name);
2656 return -EINVAL;
2657 }
2658
2659 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
2660 __func__,state, mixer_ctl_name);
2661 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2662
2663 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002664}
2665
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002666int platform_can_split_snd_device(snd_device_t snd_device,
2667 int *num_devices,
2668 snd_device_t *new_snd_devices)
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002669{
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002670 int ret = -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002671 if (NULL == num_devices || NULL == new_snd_devices) {
2672 ALOGE("%s: NULL pointer ..", __func__);
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002673 return -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002674 }
2675
2676 /*
2677 * If wired headset/headphones/line devices share the same backend
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002678 * with speaker/earpiece this routine returns -EINVAL.
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002679 */
2680 if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES &&
2681 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_HEADPHONES)) {
2682 *num_devices = 2;
2683 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2684 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002685 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002686 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_LINE &&
2687 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_LINE)) {
2688 *num_devices = 2;
2689 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2690 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002691 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002692 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES &&
2693 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_HEADPHONES)) {
2694 *num_devices = 2;
2695 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2696 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002697 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002698 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE &&
2699 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_LINE)) {
2700 *num_devices = 2;
2701 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2702 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002703 ret = 0;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002704 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO &&
2705 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2706 SND_DEVICE_OUT_BT_SCO)) {
2707 *num_devices = 2;
2708 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2709 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO;
2710 ret = 0;
juyuchen5351ea62018-05-16 10:54:37 +08002711 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO &&
2712 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE,
2713 SND_DEVICE_OUT_BT_SCO)) {
2714 *num_devices = 2;
2715 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2716 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO;
2717 ret = 0;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002718 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB &&
2719 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2720 SND_DEVICE_OUT_BT_SCO_WB)) {
2721 *num_devices = 2;
2722 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2723 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO_WB;
2724 ret = 0;
juyuchen5351ea62018-05-16 10:54:37 +08002725 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB &&
2726 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE,
2727 SND_DEVICE_OUT_BT_SCO_WB)) {
2728 *num_devices = 2;
2729 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2730 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO_WB;
2731 ret = 0;
David Linee3fe402017-03-13 10:00:42 -07002732 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET &&
2733 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_USB_HEADSET)) {
2734 *num_devices = 2;
2735 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2736 new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
2737 ret = 0;
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07002738 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET &&
2739 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_USB_HEADSET)) {
2740 *num_devices = 2;
2741 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2742 new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
2743 ret = 0;
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002744 } else if (SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP == snd_device &&
2745 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2746 SND_DEVICE_OUT_BT_A2DP)) {
2747 *num_devices = 2;
2748 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2749 new_snd_devices[1] = SND_DEVICE_OUT_BT_A2DP;
2750 ret = 0;
Aniket Kumar Lata9723a962018-05-16 17:41:55 -07002751 } else if (SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP == snd_device &&
2752 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE,
2753 SND_DEVICE_OUT_BT_A2DP)) {
2754 *num_devices = 2;
2755 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2756 new_snd_devices[1] = SND_DEVICE_OUT_BT_A2DP;
2757 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002758 }
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002759
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002760 return ret;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002761}
2762
Eric Laurentb23d5282013-05-14 15:27:20 -07002763snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
2764{
2765 struct platform_data *my_data = (struct platform_data *)platform;
2766 struct audio_device *adev = my_data->adev;
2767 audio_mode_t mode = adev->mode;
2768 snd_device_t snd_device = SND_DEVICE_NONE;
2769
2770 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
2771 if (devices == AUDIO_DEVICE_NONE ||
2772 devices & AUDIO_DEVICE_BIT_IN) {
2773 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
2774 goto exit;
2775 }
2776
Eric Laurent1b491552015-09-15 17:52:41 -07002777 if (popcount(devices) == 2) {
2778 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2779 AUDIO_DEVICE_OUT_SPEAKER) ||
2780 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2781 AUDIO_DEVICE_OUT_SPEAKER)) {
2782 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
2783 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2784 AUDIO_DEVICE_OUT_SPEAKER)) {
2785 snd_device = SND_DEVICE_OUT_SPEAKER_AND_LINE;
2786 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2787 AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
2788 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2789 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2790 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES;
2791 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2792 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2793 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE;
2794 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
2795 AUDIO_DEVICE_OUT_SPEAKER)) {
2796 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002797 } else if ((devices & AUDIO_DEVICE_OUT_ALL_SCO) &&
2798 ((devices & ~AUDIO_DEVICE_OUT_ALL_SCO) == AUDIO_DEVICE_OUT_SPEAKER)) {
2799 snd_device = adev->bt_wb_speech_enabled ?
2800 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB :
2801 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO;
juyuchen5351ea62018-05-16 10:54:37 +08002802 } else if ((devices & AUDIO_DEVICE_OUT_ALL_SCO) &&
2803 ((devices & ~AUDIO_DEVICE_OUT_ALL_SCO) == AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2804 snd_device = adev->bt_wb_speech_enabled ?
2805 SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB :
2806 SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO;
Eric Laurent99dab492017-06-17 15:19:08 -07002807 } else if ((devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
2808 AUDIO_DEVICE_OUT_SPEAKER)) ||
2809 (devices == (AUDIO_DEVICE_OUT_USB_HEADSET |
2810 AUDIO_DEVICE_OUT_SPEAKER))) {
David Linee3fe402017-03-13 10:00:42 -07002811 snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET;
Eric Laurentd0f7c262017-07-05 09:09:12 -07002812 } else if ((devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
2813 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) ||
2814 (devices == (AUDIO_DEVICE_OUT_USB_HEADSET |
2815 AUDIO_DEVICE_OUT_SPEAKER_SAFE))) {
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07002816 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET;
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002817 } else if ((devices & AUDIO_DEVICE_OUT_SPEAKER) &&
2818 (devices & AUDIO_DEVICE_OUT_ALL_A2DP)) {
2819 snd_device = SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP;
Aniket Kumar Lata9723a962018-05-16 17:41:55 -07002820 } else if ((devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) &&
2821 (devices & AUDIO_DEVICE_OUT_ALL_A2DP)) {
2822 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP;
Eric Laurent1b491552015-09-15 17:52:41 -07002823 } else {
2824 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
2825 goto exit;
2826 }
2827 if (snd_device != SND_DEVICE_NONE) {
2828 goto exit;
2829 }
2830 }
2831
2832 if (popcount(devices) != 1) {
2833 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
2834 goto exit;
2835 }
2836
Madhuri Athota3f6051b2016-10-13 23:25:38 +05302837 if (voice_is_in_call(adev) || adev->enable_voicerx || audio_extn_hfp_is_active(adev)) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002838 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002839 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2840 devices & AUDIO_DEVICE_OUT_LINE) {
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002841 if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002842 (adev->voice.tty_mode == TTY_MODE_FULL))
Eric Laurentb23d5282013-05-14 15:27:20 -07002843 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002844 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002845 (adev->voice.tty_mode == TTY_MODE_VCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002846 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002847 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002848 (adev->voice.tty_mode == TTY_MODE_HCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002849 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002850 else {
2851 if (devices & AUDIO_DEVICE_OUT_LINE)
2852 snd_device = SND_DEVICE_OUT_VOICE_LINE;
yixuanjiang9536e672018-09-06 18:43:36 +08002853 else if (devices & AUDIO_DEVICE_OUT_WIRED_HEADSET)
2854 snd_device = SND_DEVICE_OUT_VOICE_HEADSET;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002855 else
2856 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
2857 }
Eric Laurent99dab492017-06-17 15:19:08 -07002858 } else if (audio_is_usb_out_device(devices)) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002859 if (voice_is_in_call(adev)) {
2860 switch (adev->voice.tty_mode) {
2861 case TTY_MODE_FULL:
2862 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_USB;
2863 break;
2864 case TTY_MODE_VCO:
2865 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_USB;
2866 break;
2867 case TTY_MODE_HCO:
2868 // since Hearing will be on handset\speaker, use existing device
2869 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
2870 break;
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002871 case TTY_MODE_OFF:
2872 break;
vivek mehtaa6b79742017-03-09 15:40:43 -08002873 default:
2874 ALOGE("%s: Invalid TTY mode (%#x)",
2875 __func__, adev->voice.tty_mode);
2876 }
2877 }
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002878 if (snd_device == SND_DEVICE_NONE) {
2879 snd_device = audio_extn_usb_is_capture_supported() ?
2880 SND_DEVICE_OUT_VOICE_USB_HEADSET :
2881 SND_DEVICE_OUT_VOICE_USB_HEADPHONES;
2882 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002883 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002884 if (adev->bt_wb_speech_enabled) {
2885 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2886 } else {
2887 snd_device = SND_DEVICE_OUT_BT_SCO;
2888 }
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002889 } else if (devices & AUDIO_DEVICE_OUT_ALL_A2DP) {
2890 snd_device = SND_DEVICE_OUT_BT_A2DP;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002891 } else if (devices & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002892 if (!adev->enable_hfp) {
2893 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
2894 } else {
2895 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_HFP;
2896 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002897 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002898 if(adev->voice.hac)
2899 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2900 else if (is_operator_tmus())
Eric Laurentb23d5282013-05-14 15:27:20 -07002901 snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS;
2902 else
Eric Laurentb4d368e2014-06-25 10:21:54 -05002903 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002904 } else if (devices & AUDIO_DEVICE_OUT_TELEPHONY_TX)
2905 snd_device = SND_DEVICE_OUT_VOICE_TX;
2906
Eric Laurentb23d5282013-05-14 15:27:20 -07002907 if (snd_device != SND_DEVICE_NONE) {
2908 goto exit;
2909 }
2910 }
2911
Eric Laurentb23d5282013-05-14 15:27:20 -07002912 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2913 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2914 snd_device = SND_DEVICE_OUT_HEADPHONES;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002915 } else if (devices & AUDIO_DEVICE_OUT_LINE) {
2916 snd_device = SND_DEVICE_OUT_LINE;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002917 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) {
2918 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE;
Eric Laurentb23d5282013-05-14 15:27:20 -07002919 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
andysu5b30b062018-04-20 16:34:06 +08002920 /*
2921 * Perform device switch only if acdb tuning is different between SPEAKER & SPEAKER_REVERSE,
2922 * Or there will be a small pause while performing device switch.
2923 */
2924 if (my_data->speaker_lr_swap &&
2925 (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
2926 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]))
Eric Laurentb23d5282013-05-14 15:27:20 -07002927 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
2928 else
2929 snd_device = SND_DEVICE_OUT_SPEAKER;
2930 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002931 if (adev->bt_wb_speech_enabled) {
2932 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2933 } else {
2934 snd_device = SND_DEVICE_OUT_BT_SCO;
2935 }
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002936 } else if (devices & AUDIO_DEVICE_OUT_ALL_A2DP) {
2937 snd_device = SND_DEVICE_OUT_BT_A2DP;
Eric Laurentb23d5282013-05-14 15:27:20 -07002938 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2939 snd_device = SND_DEVICE_OUT_HDMI ;
Eric Laurent99dab492017-06-17 15:19:08 -07002940 } else if (audio_is_usb_out_device(devices)) {
jasmine cha270b7762018-03-30 15:41:33 +08002941 if (audio_extn_ma_supported_usb())
2942 snd_device = SND_DEVICE_OUT_USB_HEADSET_SPEC;
2943 else if (audio_extn_usb_is_capture_supported())
David Linee3fe402017-03-13 10:00:42 -07002944 snd_device = SND_DEVICE_OUT_USB_HEADSET;
2945 else
2946 snd_device = SND_DEVICE_OUT_USB_HEADPHONES;
2947 }else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002948 /*HAC support for voice-ish audio (eg visual voicemail)*/
2949 if(adev->voice.hac)
2950 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2951 else
2952 snd_device = SND_DEVICE_OUT_HANDSET;
Eric Laurentb23d5282013-05-14 15:27:20 -07002953 } else {
2954 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
2955 }
2956exit:
2957 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
2958 return snd_device;
2959}
2960
Vignesh Kulothungan64698822018-01-23 11:25:18 -08002961#ifdef DYNAMIC_ECNS_ENABLED
2962static snd_device_t get_snd_device_for_voice_comm(struct platform_data *my_data,
2963 struct stream_in *in __unused,
2964 audio_devices_t out_device,
2965 audio_devices_t in_device)
2966{
2967 struct audio_device *adev = my_data->adev;
2968 snd_device_t snd_device = SND_DEVICE_NONE;
2969
2970 if (my_data->fluence_type != FLUENCE_DISABLE) {
2971 switch(AUDIO_DEVICE_BIT_IN | in_device) {
2972 case AUDIO_DEVICE_IN_BACK_MIC:
2973 if (my_data->fluence_in_spkr_mode) {
2974 if ((my_data->fluence_type & FLUENCE_PRO_ENABLE) &&
2975 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2976 snd_device = SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS;
2977 } else if (((my_data->fluence_type & FLUENCE_PRO_ENABLE) ||
2978 (my_data->fluence_type & FLUENCE_ENABLE)) &&
2979 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2980 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
2981 }
2982 adev->acdb_settings |= DMIC_FLAG;
2983 } else
2984 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
2985 break;
2986 case AUDIO_DEVICE_IN_BUILTIN_MIC:
2987 if (((my_data->fluence_type & FLUENCE_PRO_ENABLE) ||
2988 (my_data->fluence_type & FLUENCE_ENABLE)) &&
2989 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2990 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
2991 adev->acdb_settings |= DMIC_FLAG;
2992 } else
2993 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
2994 break;
2995 default:
2996 ALOGE("%s: Unsupported in_device %#x", __func__, in_device);
2997 break;
2998 }
2999 platform_set_echo_reference(adev, true, out_device);
3000 }
3001
3002 return snd_device;
3003}
3004#else
3005static snd_device_t get_snd_device_for_voice_comm(struct platform_data *my_data,
3006 struct stream_in *in,
3007 audio_devices_t out_device,
3008 audio_devices_t in_device)
3009{
3010 struct audio_device *adev = my_data->adev;
3011 snd_device_t snd_device = SND_DEVICE_NONE;
3012
3013 if (in->enable_aec &&
3014 in->enable_ns) {
3015 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
3016 if (my_data->fluence_in_spkr_mode &&
3017 my_data->fluence_in_voice_comm &&
3018 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
3019 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
3020 } else {
3021 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
3022 }
3023 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
3024 if (my_data->fluence_in_voice_comm &&
3025 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
3026 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
3027 } else {
3028 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
3029 }
3030 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3031 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
3032 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
3033 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
3034 }
3035 platform_set_echo_reference(adev, true, out_device);
3036 } else if (in->enable_aec) {
3037 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
3038 if (my_data->fluence_in_spkr_mode &&
3039 my_data->fluence_in_voice_comm &&
3040 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
3041 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
3042 } else {
3043 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
3044 }
3045 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
3046 if (my_data->fluence_in_voice_comm &&
3047 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
3048 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
3049 } else {
3050 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
3051 }
3052 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3053 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
3054 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
3055 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
3056 }
3057 platform_set_echo_reference(adev, true, out_device);
3058 } else if (in->enable_ns) {
3059 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
3060 if (my_data->fluence_in_spkr_mode &&
3061 my_data->fluence_in_voice_comm &&
3062 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
3063 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
3064 } else {
3065 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
3066 }
3067 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
3068 if (my_data->fluence_in_voice_comm &&
3069 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
3070 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
3071 } else {
3072 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
3073 }
3074 }
3075 }
3076
3077 return snd_device;
3078}
3079#endif //DYNAMIC_ECNS_ENABLED
3080
Eric Laurentd1b7a9b2018-11-15 12:24:31 -08003081snd_device_t platform_get_input_snd_device(void *platform,
3082 struct stream_in *in,
3083 audio_devices_t out_device)
Eric Laurentb23d5282013-05-14 15:27:20 -07003084{
3085 struct platform_data *my_data = (struct platform_data *)platform;
3086 struct audio_device *adev = my_data->adev;
Eric Laurentd1b7a9b2018-11-15 12:24:31 -08003087 audio_mode_t mode = adev->mode;
Eric Laurentb23d5282013-05-14 15:27:20 -07003088 snd_device_t snd_device = SND_DEVICE_NONE;
Eric Laurentd1b7a9b2018-11-15 12:24:31 -08003089
3090 if (in == NULL) {
3091 in = adev_get_active_input(adev);
3092 }
3093
3094 audio_source_t source = (in == NULL) ? AUDIO_SOURCE_DEFAULT : in->source;
3095 audio_devices_t in_device =
3096 ((in == NULL) ? AUDIO_DEVICE_NONE : in->device) & ~AUDIO_DEVICE_BIT_IN;
3097 audio_channel_mask_t channel_mask = (in == NULL) ? AUDIO_CHANNEL_IN_MONO : in->channel_mask;
3098 int channel_count = audio_channel_count_from_in_mask(channel_mask);
Eric Laurentb23d5282013-05-14 15:27:20 -07003099
Prashant Malanic92c5962015-08-11 15:10:18 -07003100 ALOGV("%s: enter: out_device(%#x) in_device(%#x) channel_count (%d) channel_mask (0x%x)",
3101 __func__, out_device, in_device, channel_count, channel_mask);
Eric Laurentd1b7a9b2018-11-15 12:24:31 -08003102
Devin Kimd789e432016-10-26 15:07:27 -07003103 if ((out_device != AUDIO_DEVICE_NONE) && (voice_is_in_call(adev) ||
3104 audio_extn_hfp_is_active(adev))) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07003105 if (adev->voice.tty_mode != TTY_MODE_OFF) {
Eric Laurentb23d5282013-05-14 15:27:20 -07003106 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05003107 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
3108 out_device & AUDIO_DEVICE_OUT_LINE) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07003109 switch (adev->voice.tty_mode) {
vivek mehtaa6b79742017-03-09 15:40:43 -08003110 case TTY_MODE_FULL:
3111 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
3112 break;
3113 case TTY_MODE_VCO:
3114 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
3115 break;
3116 case TTY_MODE_HCO:
3117 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
3118 break;
3119 default:
3120 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
3121 }
3122 goto exit;
Eric Laurent99dab492017-06-17 15:19:08 -07003123 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
vivek mehtaa6b79742017-03-09 15:40:43 -08003124 switch (adev->voice.tty_mode) {
3125 case TTY_MODE_FULL:
3126 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC;
3127 break;
3128 case TTY_MODE_VCO:
3129 // since voice will be captured from handset mic, use existing device
3130 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
3131 break;
3132 case TTY_MODE_HCO:
3133 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC;
3134 break;
3135 default:
3136 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
Eric Laurentb23d5282013-05-14 15:27:20 -07003137 }
3138 goto exit;
3139 }
3140 }
Eric Laurentb991fb02014-08-29 15:23:17 -05003141 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07003142 if (my_data->fluence_in_voice_call == false) {
3143 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3144 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003145 if (is_operator_tmus())
3146 snd_device = SND_DEVICE_IN_VOICE_DMIC_TMUS;
Eric Laurentb23d5282013-05-14 15:27:20 -07003147 else
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003148 snd_device = SND_DEVICE_IN_VOICE_DMIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07003149 }
3150 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
3151 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
3152 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003153 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003154 if (adev->bluetooth_nrec)
3155 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
3156 else
3157 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003158 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003159 if (adev->bluetooth_nrec)
3160 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
3161 else
3162 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003163 }
Eric Laurentb991fb02014-08-29 15:23:17 -05003164 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Prashant Malanic92c5962015-08-11 15:10:18 -07003165 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
3166 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
3167 out_device & AUDIO_DEVICE_OUT_LINE) {
3168 if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
3169 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
3170 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
3171 } else {
3172 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
3173 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003174 }
vivek mehtafe121d52015-08-10 23:39:23 -07003175
3176 //select default
3177 if (snd_device == SND_DEVICE_NONE) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07003178 if (!adev->enable_hfp) {
3179 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
3180 } else {
3181 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP;
3182 platform_set_echo_reference(adev, true, out_device);
3183 }
vivek mehtafe121d52015-08-10 23:39:23 -07003184 }
Prashant Malanic92c5962015-08-11 15:10:18 -07003185 } else if (out_device & AUDIO_DEVICE_OUT_TELEPHONY_TX) {
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07003186 snd_device = SND_DEVICE_IN_VOICE_RX;
Eric Laurent99dab492017-06-17 15:19:08 -07003187 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
David Lin40b07892017-08-07 15:02:48 -07003188 if (audio_extn_usb_is_capture_supported()) {
3189 snd_device = SND_DEVICE_IN_VOICE_USB_HEADSET_MIC;
3190 } else if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
3191 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
3192 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
3193 } else {
3194 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
3195 }
3196 }
Prashant Malanic92c5962015-08-11 15:10:18 -07003197 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003198 } else if (source == AUDIO_SOURCE_CAMCORDER) {
3199 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
3200 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Eric Laurent5f4ca952018-10-19 17:33:43 -07003201 switch (adev->camera_orientation) {
3202 case CAMERA_BACK_LANDSCAPE:
3203 snd_device = SND_DEVICE_IN_CAMCORDER_LANDSCAPE;
3204 break;
3205 case CAMERA_BACK_INVERT_LANDSCAPE:
3206 snd_device = SND_DEVICE_IN_CAMCORDER_INVERT_LANDSCAPE;
3207 break;
3208 case CAMERA_BACK_PORTRAIT:
3209 snd_device = SND_DEVICE_IN_CAMCORDER_PORTRAIT;
3210 break;
3211 case CAMERA_FRONT_LANDSCAPE:
3212 snd_device = SND_DEVICE_IN_CAMCORDER_SELFIE_LANDSCAPE;
3213 break;
3214 case CAMERA_FRONT_INVERT_LANDSCAPE:
3215 snd_device = SND_DEVICE_IN_CAMCORDER_SELFIE_INVERT_LANDSCAPE;
3216 break;
3217 case CAMERA_FRONT_PORTRAIT:
3218 snd_device = SND_DEVICE_IN_CAMCORDER_SELFIE_PORTRAIT;
3219 break;
3220 default:
3221 ALOGW("%s: invalid camera orientation %08x", __func__, adev->camera_orientation);
3222 snd_device = SND_DEVICE_IN_CAMCORDER_LANDSCAPE;
3223 break;
3224 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003225 }
3226 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
3227 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003228 if (my_data->fluence_in_voice_rec && channel_count == 1) {
3229 if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
3230 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
Eric Laurentd1b7a9b2018-11-15 12:24:31 -08003231 if (in->enable_aec)
vivek mehta733c1df2016-04-04 15:09:24 -07003232 snd_device = SND_DEVICE_IN_HANDSET_QMIC_AEC;
3233 else
3234 snd_device = SND_DEVICE_IN_HANDSET_QMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003235 } else if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
3236 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
Eric Laurentd1b7a9b2018-11-15 12:24:31 -08003237 if (in->enable_aec)
vivek mehta733c1df2016-04-04 15:09:24 -07003238 snd_device = SND_DEVICE_IN_HANDSET_TMIC_AEC;
3239 else
3240 snd_device = SND_DEVICE_IN_HANDSET_TMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003241 } else if (((my_data->fluence_type == FLUENCE_PRO_ENABLE) ||
3242 (my_data->fluence_type == FLUENCE_ENABLE)) &&
3243 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Eric Laurentd1b7a9b2018-11-15 12:24:31 -08003244 if (in->enable_aec)
vivek mehta733c1df2016-04-04 15:09:24 -07003245 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
3246 else
3247 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
Prashant Malanic92c5962015-08-11 15:10:18 -07003248 }
3249 platform_set_echo_reference(adev, true, out_device);
3250 } else if ((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) &&
3251 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
3252 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003253 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003254 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
3255 snd_device = SND_DEVICE_IN_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003256 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003257 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
3258 snd_device = SND_DEVICE_IN_QUAD_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07003259 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003260 if (snd_device == SND_DEVICE_NONE) {
Eric Laurentd1b7a9b2018-11-15 12:24:31 -08003261 if (in->enable_aec) {
3262 if (in->enable_ns) {
vivek mehtaf3440682016-05-11 14:24:37 -07003263 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS;
3264 } else {
3265 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC;
3266 }
vivek mehta733c1df2016-04-04 15:09:24 -07003267 platform_set_echo_reference(adev, true, out_device);
Eric Laurentd1b7a9b2018-11-15 12:24:31 -08003268 } else if (in->enable_ns) {
vivek mehtaf3440682016-05-11 14:24:37 -07003269 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
3270 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003271 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
vivek mehtaf3440682016-05-11 14:24:37 -07003272 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003273 }
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -07003274 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3275 snd_device = SND_DEVICE_IN_VOICE_REC_HEADSET_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07003276 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07003277 snd_device = SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07003278 }
rago90fb9612015-12-02 11:37:53 -08003279 } else if (source == AUDIO_SOURCE_UNPROCESSED) {
3280 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
vivek mehta4ed66e62016-04-15 23:33:34 -07003281 if (((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) ||
3282 (channel_mask == AUDIO_CHANNEL_IN_STEREO)) &&
3283 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
3284 snd_device = SND_DEVICE_IN_UNPROCESSED_STEREO_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003285 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07003286 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
3287 snd_device = SND_DEVICE_IN_UNPROCESSED_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003288 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07003289 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
3290 snd_device = SND_DEVICE_IN_UNPROCESSED_QUAD_MIC;
3291 } else {
3292 snd_device = SND_DEVICE_IN_UNPROCESSED_MIC;
3293 }
rago90fb9612015-12-02 11:37:53 -08003294 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3295 snd_device = SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07003296 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07003297 snd_device = SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC;
rago90fb9612015-12-02 11:37:53 -08003298 }
Eric Laurent50a38ed2015-10-14 18:48:06 -07003299 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION ||
rago90fb9612015-12-02 11:37:53 -08003300 mode == AUDIO_MODE_IN_COMMUNICATION) {
David Lin40b07892017-08-07 15:02:48 -07003301 if (out_device & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
3302 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
3303 (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE | AUDIO_DEVICE_OUT_USB_HEADSET) &&
3304 !audio_extn_usb_is_capture_supported())) {
Eric Laurentb23d5282013-05-14 15:27:20 -07003305 in_device = AUDIO_DEVICE_IN_BACK_MIC;
David Lin40b07892017-08-07 15:02:48 -07003306 }
Vignesh Kulothungan64698822018-01-23 11:25:18 -08003307
Eric Laurentd1b7a9b2018-11-15 12:24:31 -08003308 if (in) {
Vignesh Kulothungan64698822018-01-23 11:25:18 -08003309 snd_device = get_snd_device_for_voice_comm(my_data, in, out_device, in_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07003310 }
3311 } else if (source == AUDIO_SOURCE_DEFAULT) {
3312 goto exit;
3313 }
3314
3315
3316 if (snd_device != SND_DEVICE_NONE) {
3317 goto exit;
3318 }
3319
3320 if (in_device != AUDIO_DEVICE_NONE &&
3321 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
3322 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
3323 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003324 if ((my_data->source_mic_type & SOURCE_QUAD_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003325 channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003326 snd_device = SND_DEVICE_IN_QUAD_MIC;
3327 } else if ((my_data->source_mic_type & SOURCE_THREE_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003328 channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003329 snd_device = SND_DEVICE_IN_THREE_MIC;
3330 } else if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
3331 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003332 snd_device = SND_DEVICE_IN_HANDSET_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07003333 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
3334 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003335 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003336 } else {
3337 ALOGE("%s: something wrong (1): source type (%d) channel_count (%d) .."
3338 " channel mask (0x%x) no combination found .. setting to mono", __func__,
3339 my_data->source_mic_type, channel_count, channel_mask);
3340 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3341 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003342 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003343 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
3344 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003345 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07003346 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
3347 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003348 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003349 } else {
3350 ALOGE("%s: something wrong (2): source type (%d) channel_count (%d) .."
3351 " no combination found .. setting to mono", __func__,
3352 my_data->source_mic_type, channel_count);
3353 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
3354 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003355 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3356 snd_device = SND_DEVICE_IN_HEADSET_MIC;
3357 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003358 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003359 if (adev->bluetooth_nrec)
3360 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
3361 else
3362 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003363 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003364 if (adev->bluetooth_nrec)
3365 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
3366 else
3367 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003368 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003369 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
3370 snd_device = SND_DEVICE_IN_HDMI_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07003371 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
David Linee3fe402017-03-13 10:00:42 -07003372 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07003373 } else {
3374 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
3375 ALOGW("%s: Using default handset-mic", __func__);
3376 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3377 }
3378 } else {
3379 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
3380 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3381 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
3382 snd_device = SND_DEVICE_IN_HEADSET_MIC;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003383 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07003384 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003385 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05003386 out_device & AUDIO_DEVICE_OUT_LINE) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003387 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
3388 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003389 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07003390 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
3391 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003392 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003393 } else {
3394 ALOGE("%s: something wrong (3): source type (%d) channel_count (%d) .."
3395 " no combination found .. setting to mono", __func__,
3396 my_data->source_mic_type, channel_count);
3397 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
3398 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003399 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003400 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003401 if (adev->bluetooth_nrec)
3402 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
3403 else
3404 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003405 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003406 if (adev->bluetooth_nrec)
3407 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
3408 else
3409 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003410 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003411 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
3412 snd_device = SND_DEVICE_IN_HDMI_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07003413 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
David Linee3fe402017-03-13 10:00:42 -07003414 if (audio_extn_usb_is_capture_supported())
3415 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
3416 else
3417 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07003418 } else {
3419 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
3420 ALOGW("%s: Using default handset-mic", __func__);
3421 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3422 }
3423 }
3424exit:
3425 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
3426 return snd_device;
3427}
3428
3429int platform_set_hdmi_channels(void *platform, int channel_count)
3430{
3431 struct platform_data *my_data = (struct platform_data *)platform;
3432 struct audio_device *adev = my_data->adev;
3433 struct mixer_ctl *ctl;
3434 const char *channel_cnt_str = NULL;
3435 const char *mixer_ctl_name = "HDMI_RX Channels";
3436 switch (channel_count) {
3437 case 8:
3438 channel_cnt_str = "Eight"; break;
3439 case 7:
3440 channel_cnt_str = "Seven"; break;
3441 case 6:
3442 channel_cnt_str = "Six"; break;
3443 case 5:
3444 channel_cnt_str = "Five"; break;
3445 case 4:
3446 channel_cnt_str = "Four"; break;
3447 case 3:
3448 channel_cnt_str = "Three"; break;
3449 default:
3450 channel_cnt_str = "Two"; break;
3451 }
3452 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3453 if (!ctl) {
3454 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3455 __func__, mixer_ctl_name);
3456 return -EINVAL;
3457 }
3458 ALOGV("HDMI channel count: %s", channel_cnt_str);
3459 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
3460 return 0;
3461}
3462
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003463int platform_edid_get_max_channels(void *platform)
Eric Laurentb23d5282013-05-14 15:27:20 -07003464{
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003465 struct platform_data *my_data = (struct platform_data *)platform;
3466 struct audio_device *adev = my_data->adev;
Eric Laurentb23d5282013-05-14 15:27:20 -07003467 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
3468 char *sad = block;
3469 int num_audio_blocks;
3470 int channel_count;
3471 int max_channels = 0;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003472 int i, ret, count;
Eric Laurentb23d5282013-05-14 15:27:20 -07003473
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003474 struct mixer_ctl *ctl;
3475
3476 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
3477 if (!ctl) {
3478 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3479 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
Eric Laurentb23d5282013-05-14 15:27:20 -07003480 return 0;
3481 }
3482
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003483 mixer_ctl_update(ctl);
3484
3485 count = mixer_ctl_get_num_values(ctl);
Eric Laurentb23d5282013-05-14 15:27:20 -07003486
3487 /* Read SAD blocks, clamping the maximum size for safety */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003488 if (count > (int)sizeof(block))
3489 count = (int)sizeof(block);
Eric Laurentb23d5282013-05-14 15:27:20 -07003490
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003491 ret = mixer_ctl_get_array(ctl, block, count);
3492 if (ret != 0) {
3493 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
3494 return 0;
3495 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003496
3497 /* Calculate the number of SAD blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003498 num_audio_blocks = count / SAD_BLOCK_SIZE;
Eric Laurentb23d5282013-05-14 15:27:20 -07003499
3500 for (i = 0; i < num_audio_blocks; i++) {
3501 /* Only consider LPCM blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003502 if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
3503 sad += 3;
Eric Laurentb23d5282013-05-14 15:27:20 -07003504 continue;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003505 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003506
3507 channel_count = (sad[0] & 0x7) + 1;
3508 if (channel_count > max_channels)
3509 max_channels = channel_count;
3510
3511 /* Advance to next block */
3512 sad += 3;
3513 }
3514
3515 return max_channels;
3516}
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003517
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07003518int platform_set_incall_recording_session_id(void *platform,
3519 uint32_t session_id, int rec_mode)
3520{
3521 int ret = 0;
3522 struct platform_data *my_data = (struct platform_data *)platform;
3523 struct audio_device *adev = my_data->adev;
3524 struct mixer_ctl *ctl;
3525 const char *mixer_ctl_name = "Voc VSID";
3526 int num_ctl_values;
3527 int i;
3528
3529 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3530 if (!ctl) {
3531 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3532 __func__, mixer_ctl_name);
3533 ret = -EINVAL;
3534 } else {
3535 num_ctl_values = mixer_ctl_get_num_values(ctl);
3536 for (i = 0; i < num_ctl_values; i++) {
3537 if (mixer_ctl_set_value(ctl, i, session_id)) {
3538 ALOGV("Error: invalid session_id: %x", session_id);
3539 ret = -EINVAL;
3540 break;
3541 }
3542 }
3543 }
3544
3545 if (my_data->csd != NULL) {
3546 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
3547 if (ret < 0) {
3548 ALOGE("%s: csd_client_start_record failed, error %d",
3549 __func__, ret);
3550 }
3551 }
3552
3553 return ret;
3554}
3555
Arun Mirpuriba2749a2018-04-17 14:32:24 -07003556int platform_set_incall_recording_session_channels(void *platform,
3557 uint32_t channel_count)
3558{
3559 int ret = 0;
3560 struct platform_data *my_data = (struct platform_data *)platform;
3561 struct audio_device *adev = my_data->adev;
3562 const char *mixer_ctl_name = "Voc Rec Config";
3563 int num_ctl_values;
3564 int i;
3565 struct mixer_ctl *ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3566
3567 if (!ctl) {
3568 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3569 __func__, mixer_ctl_name);
3570 ret = -EINVAL;
3571 } else {
3572 num_ctl_values = mixer_ctl_get_num_values(ctl);
3573 for (i = 0; i < num_ctl_values; i++) {
3574 if (mixer_ctl_set_value(ctl, i, channel_count)) {
3575 ALOGE("Error: invalid channel count: %x", channel_count);
3576 ret = -EINVAL;
3577 break;
3578 }
3579 }
3580 }
3581
3582 return ret;
3583}
3584
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07003585int platform_stop_incall_recording_usecase(void *platform)
3586{
3587 int ret = 0;
3588 struct platform_data *my_data = (struct platform_data *)platform;
3589
3590 if (my_data->csd != NULL) {
3591 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
3592 if (ret < 0) {
3593 ALOGE("%s: csd_client_stop_record failed, error %d",
3594 __func__, ret);
3595 }
3596 }
3597
3598 return ret;
3599}
3600
3601int platform_start_incall_music_usecase(void *platform)
3602{
3603 int ret = 0;
3604 struct platform_data *my_data = (struct platform_data *)platform;
3605
3606 if (my_data->csd != NULL) {
3607 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
3608 if (ret < 0) {
3609 ALOGE("%s: csd_client_start_playback failed, error %d",
3610 __func__, ret);
3611 }
3612 }
3613
3614 return ret;
3615}
3616
3617int platform_stop_incall_music_usecase(void *platform)
3618{
3619 int ret = 0;
3620 struct platform_data *my_data = (struct platform_data *)platform;
3621
3622 if (my_data->csd != NULL) {
3623 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
3624 if (ret < 0) {
3625 ALOGE("%s: csd_client_stop_playback failed, error %d",
3626 __func__, ret);
3627 }
3628 }
3629
3630 return ret;
3631}
3632
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003633int platform_set_parameters(void *platform, struct str_parms *parms)
3634{
3635 struct platform_data *my_data = (struct platform_data *)platform;
jasmine chac89321b2018-04-10 21:37:01 +08003636 char *value = NULL;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003637 char *kv_pairs = str_parms_to_str(parms);
jasmine chac89321b2018-04-10 21:37:01 +08003638 int len;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003639 int ret = 0, err;
3640
3641 if (kv_pairs == NULL) {
3642 ret = -EINVAL;
Jasmine Chaa314e192018-05-09 17:46:28 +08003643 ALOGE("%s: key-value pair is NULL", __func__);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003644 goto done;
3645 }
3646
3647 ALOGV("%s: enter: %s", __func__, kv_pairs);
3648
jasmine chac89321b2018-04-10 21:37:01 +08003649 len = strlen(kv_pairs);
Jasmine Chaa314e192018-05-09 17:46:28 +08003650 value = (char*)calloc(len + 1, sizeof(char));
jasmine chac89321b2018-04-10 21:37:01 +08003651 if (value == NULL) {
3652 ret = -ENOMEM;
Jasmine Chaa314e192018-05-09 17:46:28 +08003653 ALOGE("[%s] failed to allocate memory", __func__);
jasmine chac89321b2018-04-10 21:37:01 +08003654 goto done;
3655 }
3656
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003657 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME,
jasmine chac89321b2018-04-10 21:37:01 +08003658 value, len);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003659 if (err >= 0) {
3660 str_parms_del(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME);
3661 my_data->snd_card_name = strdup(value);
3662 ALOGV("%s: sound card name %s", __func__, my_data->snd_card_name);
3663 }
3664
keunhui.park2f7306a2015-07-16 16:48:06 +09003665 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO,
jasmine chac89321b2018-04-10 21:37:01 +08003666 value, len);
keunhui.park2f7306a2015-07-16 16:48:06 +09003667 if (err >= 0) {
3668 struct operator_info *info;
3669 char *str = value;
3670 char *name;
3671
3672 str_parms_del(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO);
3673 info = (struct operator_info *)calloc(1, sizeof(struct operator_info));
3674 name = strtok(str, ";");
3675 info->name = strdup(name);
3676 info->mccmnc = strdup(str + strlen(name) + 1);
3677
3678 list_add_tail(&operator_info_list, &info->list);
Joe Onorato188b6222016-03-01 11:02:27 -08003679 ALOGV("%s: add operator[%s] mccmnc[%s]", __func__, info->name, info->mccmnc);
keunhui.park2f7306a2015-07-16 16:48:06 +09003680 }
Prashant Malanic92c5962015-08-11 15:10:18 -07003681
Jasmine Chaa314e192018-05-09 17:46:28 +08003682 memset(value, 0, len + 1);
Eric Laurentc6333382015-09-14 12:43:44 -07003683 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT,
jasmine chac89321b2018-04-10 21:37:01 +08003684 value, len);
Prashant Malanic92c5962015-08-11 15:10:18 -07003685 if (err >= 0) {
Eric Laurentc6333382015-09-14 12:43:44 -07003686 str_parms_del(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT);
Prashant Malanic92c5962015-08-11 15:10:18 -07003687 my_data->max_mic_count = atoi(value);
3688 ALOGV("%s: max_mic_count %s/%d", __func__, value, my_data->max_mic_count);
Prashant Malanic92c5962015-08-11 15:10:18 -07003689 }
3690
jasmine chac89321b2018-04-10 21:37:01 +08003691 /* handle audio calibration parameters */
3692 set_audiocal(platform, parms, value, len);
3693
vivek mehta90933872017-06-15 18:04:39 -07003694 // to-do: disable setting sidetone gain, will revist this later
3695 // audio_extn_usb_set_sidetone_gain(parms, value, len);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003696done:
3697 ALOGV("%s: exit with code(%d)", __func__, ret);
3698 if (kv_pairs != NULL)
3699 free(kv_pairs);
jasmine chac89321b2018-04-10 21:37:01 +08003700 if (value != NULL)
3701 free(value);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003702
3703 return ret;
3704}
3705
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003706/* Delay in Us */
3707int64_t platform_render_latency(audio_usecase_t usecase)
3708{
3709 switch (usecase) {
3710 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
3711 return DEEP_BUFFER_PLATFORM_DELAY;
3712 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
Vignesh Kulothungan019d19b2019-01-23 11:09:18 -08003713 case USECASE_AUDIO_PLAYBACK_WITH_HAPTICS:
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003714 return LOW_LATENCY_PLATFORM_DELAY;
Haynes Mathew George03c40102016-01-29 17:57:48 -08003715 case USECASE_AUDIO_PLAYBACK_ULL:
3716 return ULL_PLATFORM_DELAY;
Eric Laurent0e46adf2016-12-16 12:49:24 -08003717 case USECASE_AUDIO_PLAYBACK_MMAP:
3718 return MMAP_PLATFORM_DELAY;
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003719 default:
3720 return 0;
3721 }
3722}
Haynes Mathew George98c95622014-06-20 19:14:25 -07003723
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003724int platform_set_snd_device_backend(snd_device_t device, const char *backend_tag,
3725 const char * hw_interface)
Haynes Mathew George98c95622014-06-20 19:14:25 -07003726{
3727 int ret = 0;
3728
3729 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
3730 ALOGE("%s: Invalid snd_device = %d",
3731 __func__, device);
3732 ret = -EINVAL;
3733 goto done;
3734 }
3735
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003736 ALOGV("%s: backend_tag_table[%s]: old = %s new = %s", __func__,
3737 platform_get_snd_device_name(device),
3738 backend_tag_table[device] != NULL ? backend_tag_table[device]: "null", backend_tag);
3739 if (backend_tag_table[device]) {
3740 free(backend_tag_table[device]);
Haynes Mathew George98c95622014-06-20 19:14:25 -07003741 }
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003742 backend_tag_table[device] = strdup(backend_tag);
3743
3744 if (hw_interface != NULL) {
3745 if (hw_interface_table[device])
3746 free(hw_interface_table[device]);
3747 ALOGV("%s: hw_interface_table[%d] = %s", __func__, device, hw_interface);
3748 hw_interface_table[device] = strdup(hw_interface);
3749 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07003750done:
3751 return ret;
3752}
3753
3754int platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t pcm_id)
3755{
3756 int ret = 0;
3757 if ((usecase <= USECASE_INVALID) || (usecase >= AUDIO_USECASE_MAX)) {
3758 ALOGE("%s: invalid usecase case idx %d", __func__, usecase);
3759 ret = -EINVAL;
3760 goto done;
3761 }
3762
3763 if ((type != 0) && (type != 1)) {
3764 ALOGE("%s: invalid usecase type", __func__);
3765 ret = -EINVAL;
3766 }
vivek mehtaa68fea62017-06-08 19:04:02 -07003767 ALOGV("%s: pcm_device_table[%d %s][%d] = %d", __func__, usecase,
3768 use_case_table[usecase],
3769 type, pcm_id);
Haynes Mathew George98c95622014-06-20 19:14:25 -07003770 pcm_device_table[usecase][type] = pcm_id;
3771done:
3772 return ret;
3773}
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003774
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07003775#define DEFAULT_NOMINAL_SPEAKER_GAIN 20
3776int ramp_speaker_gain(struct audio_device *adev, bool ramp_up, int target_ramp_up_gain) {
3777 // backup_gain: gain to try to set in case of an error during ramp
3778 int start_gain, end_gain, step, backup_gain, i;
3779 bool error = false;
3780 const struct mixer_ctl *ctl;
3781 const char *mixer_ctl_name_gain_left = "Left Speaker Gain";
3782 const char *mixer_ctl_name_gain_right = "Right Speaker Gain";
3783 struct mixer_ctl *ctl_left = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_left);
3784 struct mixer_ctl *ctl_right = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_right);
3785 if (!ctl_left || !ctl_right) {
3786 ALOGE("%s: Could not get ctl for mixer cmd - %s or %s, not applying speaker gain ramp",
3787 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
3788 return -EINVAL;
3789 } else if ((mixer_ctl_get_num_values(ctl_left) != 1)
3790 || (mixer_ctl_get_num_values(ctl_right) != 1)) {
3791 ALOGE("%s: Unexpected num values for mixer cmd - %s or %s, not applying speaker gain ramp",
3792 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
3793 return -EINVAL;
3794 }
3795 if (ramp_up) {
3796 start_gain = 0;
3797 end_gain = target_ramp_up_gain > 0 ? target_ramp_up_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
3798 step = +1;
3799 backup_gain = end_gain;
3800 } else {
3801 // using same gain on left and right
3802 const int left_gain = mixer_ctl_get_value(ctl_left, 0);
3803 start_gain = left_gain > 0 ? left_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
3804 end_gain = 0;
3805 step = -1;
3806 backup_gain = start_gain;
3807 }
3808 for (i = start_gain ; i != (end_gain + step) ; i += step) {
3809 //ALOGV("setting speaker gain to %d", i);
3810 if (mixer_ctl_set_value(ctl_left, 0, i)) {
3811 ALOGE("%s: error setting %s to %d during gain ramp",
3812 __func__, mixer_ctl_name_gain_left, i);
3813 error = true;
3814 break;
3815 }
3816 if (mixer_ctl_set_value(ctl_right, 0, i)) {
3817 ALOGE("%s: error setting %s to %d during gain ramp",
3818 __func__, mixer_ctl_name_gain_right, i);
3819 error = true;
3820 break;
3821 }
3822 usleep(1000);
3823 }
3824 if (error) {
3825 // an error occured during the ramp, let's still try to go back to a safe volume
3826 if (mixer_ctl_set_value(ctl_left, 0, backup_gain)) {
3827 ALOGE("%s: error restoring left gain to %d", __func__, backup_gain);
3828 }
3829 if (mixer_ctl_set_value(ctl_right, 0, backup_gain)) {
3830 ALOGE("%s: error restoring right gain to %d", __func__, backup_gain);
3831 }
3832 }
3833 return start_gain;
3834}
3835
vivek mehtae59cfb22017-06-16 15:57:11 -07003836int platform_set_swap_mixer(struct audio_device *adev, bool swap_channels)
3837{
3838 const char *mixer_ctl_name = "Swap channel";
3839 struct mixer_ctl *ctl;
3840 const char *mixer_path;
3841 struct platform_data *my_data = (struct platform_data *)adev->platform;
3842
3843 // forced to set to swap, but device not rotated ... ignore set
3844 if (swap_channels && !my_data->speaker_lr_swap)
3845 return 0;
3846
3847 ALOGV("%s:", __func__);
3848
3849 if (swap_channels) {
3850 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER_REVERSE);
3851 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
3852 } else {
3853 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER);
3854 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
3855 }
3856
3857 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3858 if (!ctl) {
3859 ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name);
3860 return -EINVAL;
3861 }
3862
3863 if (mixer_ctl_set_value(ctl, 0, swap_channels) < 0) {
3864 ALOGE("%s: Could not set reverse cotrol %d",__func__, swap_channels);
3865 return -EINVAL;
3866 }
3867
3868 ALOGV("platfor_force_swap_channel :: Channel orientation ( %s ) ",
3869 swap_channels?"R --> L":"L --> R");
3870
3871 return 0;
3872}
3873
3874int platform_check_and_set_swap_lr_channels(struct audio_device *adev, bool swap_channels)
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003875{
3876 // only update if there is active pcm playback on speaker
3877 struct audio_usecase *usecase;
3878 struct listnode *node;
3879 struct platform_data *my_data = (struct platform_data *)adev->platform;
3880
vivek mehtae59cfb22017-06-16 15:57:11 -07003881 my_data->speaker_lr_swap = swap_channels;
Jean-Michel Trivif7148702016-09-16 18:23:05 -07003882
vivek mehtae59cfb22017-06-16 15:57:11 -07003883 return platform_set_swap_channels(adev, swap_channels);
3884}
Jean-Michel Trivif7148702016-09-16 18:23:05 -07003885
vivek mehtae59cfb22017-06-16 15:57:11 -07003886int platform_set_swap_channels(struct audio_device *adev, bool swap_channels)
3887{
3888 // only update if there is active pcm playback on speaker
3889 struct audio_usecase *usecase;
3890 struct listnode *node;
3891 struct platform_data *my_data = (struct platform_data *)adev->platform;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003892
vivek mehtae59cfb22017-06-16 15:57:11 -07003893 // do not swap channels in audio modes with concurrent capture and playback
3894 // as this may break the echo reference
3895 if ((adev->mode == AUDIO_MODE_IN_COMMUNICATION) || (adev->mode == AUDIO_MODE_IN_CALL)) {
3896 ALOGV("%s: will not swap due to audio mode %d", __func__, adev->mode);
3897 return 0;
3898 }
3899
3900 list_for_each(node, &adev->usecase_list) {
3901 usecase = node_to_item(node, struct audio_usecase, list);
3902 if (usecase->type == PCM_PLAYBACK &&
3903 usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) {
3904 /*
3905 * If acdb tuning is different for SPEAKER_REVERSE, it is must
3906 * to perform device switch to disable the current backend to
3907 * enable it with new acdb data.
3908 */
3909 if (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
3910 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]) {
3911 const int initial_skpr_gain = ramp_speaker_gain(adev, false /*ramp_up*/, -1);
3912 select_devices(adev, usecase->id);
3913 if (initial_skpr_gain != -EINVAL)
3914 ramp_speaker_gain(adev, true /*ramp_up*/, initial_skpr_gain);
3915
3916 } else {
3917 platform_set_swap_mixer(adev, swap_channels);
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003918 }
vivek mehtae59cfb22017-06-16 15:57:11 -07003919 break;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003920 }
3921 }
vivek mehtae59cfb22017-06-16 15:57:11 -07003922
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003923 return 0;
3924}
vivek mehtaa8d7c922016-05-25 14:40:44 -07003925
3926static struct amp_db_and_gain_table tbl_mapping[MAX_VOLUME_CAL_STEPS];
3927static int num_gain_tbl_entry = 0;
3928
3929bool platform_add_gain_level_mapping(struct amp_db_and_gain_table *tbl_entry) {
3930
3931 ALOGV("%s: enter .. add %f %f %d", __func__, tbl_entry->amp, tbl_entry->db, tbl_entry->level);
3932 if (num_gain_tbl_entry == -1) {
3933 ALOGE("%s: num entry beyond valid step levels or corrupted..rejecting custom mapping",
3934 __func__);
3935 return false;
3936 }
3937
3938 if (num_gain_tbl_entry >= MAX_VOLUME_CAL_STEPS) {
3939 ALOGE("%s: max entry reached max[%d] current index[%d] .. rejecting", __func__,
3940 MAX_VOLUME_CAL_STEPS, num_gain_tbl_entry);
3941 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
3942 return false;
3943 }
3944
3945 if (num_gain_tbl_entry > 0 && tbl_mapping[num_gain_tbl_entry - 1].amp >= tbl_entry->amp) {
3946 ALOGE("%s: value not in ascending order .. rejecting custom mapping", __func__);
3947 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
3948 return false;
3949 }
3950
3951 tbl_mapping[num_gain_tbl_entry] = *tbl_entry;
3952 ++num_gain_tbl_entry;
3953
3954 return true;
3955}
3956
3957int platform_get_gain_level_mapping(struct amp_db_and_gain_table *mapping_tbl,
3958 int table_size) {
3959 int itt = 0;
3960 ALOGV("platform_get_gain_level_mapping called ");
3961
3962 if (num_gain_tbl_entry <= 0 || num_gain_tbl_entry > MAX_VOLUME_CAL_STEPS) {
3963 ALOGD("%s: empty or currupted gain_mapping_table", __func__);
3964 return 0;
3965 }
3966
3967 for (; itt < num_gain_tbl_entry && itt <= table_size; itt++) {
3968 mapping_tbl[itt] = tbl_mapping[itt];
3969 ALOGV("%s: added amp[%f] db[%f] level[%d]", __func__,
3970 mapping_tbl[itt].amp, mapping_tbl[itt].db, mapping_tbl[itt].level);
3971 }
3972
3973 return num_gain_tbl_entry;
3974}
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07003975
3976int platform_snd_card_update(void *platform, card_status_t status)
3977{
3978 struct platform_data *my_data = (struct platform_data *)platform;
3979 struct audio_device *adev = my_data->adev;
3980
3981 if (status == CARD_STATUS_ONLINE) {
3982 if (my_data->acdb_send_custom_top)
3983 my_data->acdb_send_custom_top();
3984 }
3985 return 0;
3986}
David Linee3fe402017-03-13 10:00:42 -07003987
3988/*
3989 * configures afe with bit width and Sample Rate
3990 */
Haynes Mathew George65f6b432018-02-27 17:44:55 -08003991int platform_set_backend_cfg(const struct audio_device* adev,
3992 snd_device_t snd_device,
3993 const struct audio_backend_cfg *backend_cfg)
David Linee3fe402017-03-13 10:00:42 -07003994{
3995
3996 int ret = 0;
3997 const int backend_idx = platform_get_backend_index(snd_device);
3998 struct platform_data *my_data = (struct platform_data *)adev->platform;
3999 const unsigned int bit_width = backend_cfg->bit_width;
4000 const unsigned int sample_rate = backend_cfg->sample_rate;
4001 const unsigned int channels = backend_cfg->channels;
4002 const audio_format_t format = backend_cfg->format;
4003 const bool passthrough_enabled = backend_cfg->passthrough_enabled;
4004
4005
4006 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
4007 ", backend_idx %d device (%s)", __func__, bit_width,
4008 sample_rate, channels, backend_idx,
4009 platform_get_snd_device_name(snd_device));
4010
4011 if ((my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl) &&
4012 (bit_width != my_data->current_backend_cfg[backend_idx].bit_width)) {
4013
4014 struct mixer_ctl *ctl = NULL;
4015 ctl = mixer_get_ctl_by_name(adev->mixer,
4016 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
4017 if (!ctl) {
4018 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
4019 __func__,
4020 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
4021 return -EINVAL;
4022 }
4023
4024 if (bit_width == 24) {
4025 if (format == AUDIO_FORMAT_PCM_24_BIT_PACKED)
4026 ret = mixer_ctl_set_enum_by_string(ctl, "S24_3LE");
4027 else
4028 ret = mixer_ctl_set_enum_by_string(ctl, "S24_LE");
4029 } else if (bit_width == 32) {
4030 ret = mixer_ctl_set_enum_by_string(ctl, "S32_LE");
4031 } else {
4032 ret = mixer_ctl_set_enum_by_string(ctl, "S16_LE");
4033 }
4034 if ( ret < 0) {
4035 ALOGE("%s:becf: afe: fail for %s mixer set to %d bit for %x format", __func__,
4036 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
4037 } else {
4038 my_data->current_backend_cfg[backend_idx].bit_width = bit_width;
4039 ALOGD("%s:becf: afe: %s mixer set to %d bit for %x format", __func__,
4040 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
4041 }
4042 /* set the ret as 0 and not pass back to upper layer */
4043 ret = 0;
4044 }
4045
4046 if (passthrough_enabled || ((my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl) &&
4047 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate))) {
4048 char *rate_str = NULL;
4049 struct mixer_ctl *ctl = NULL;
4050
4051 switch (sample_rate) {
4052 case 32000:
4053 if (passthrough_enabled) {
4054 rate_str = "KHZ_32";
4055 break;
4056 }
4057 case 8000:
4058 case 11025:
4059 case 16000:
4060 case 22050:
4061 case 48000:
4062 rate_str = "KHZ_48";
4063 break;
4064 case 44100:
4065 rate_str = "KHZ_44P1";
4066 break;
4067 case 64000:
4068 case 96000:
4069 rate_str = "KHZ_96";
4070 break;
4071 case 88200:
4072 rate_str = "KHZ_88P2";
4073 break;
4074 case 176400:
4075 rate_str = "KHZ_176P4";
4076 break;
4077 case 192000:
4078 rate_str = "KHZ_192";
4079 break;
4080 case 352800:
4081 rate_str = "KHZ_352P8";
4082 break;
4083 case 384000:
4084 rate_str = "KHZ_384";
4085 break;
4086 case 144000:
4087 if (passthrough_enabled) {
4088 rate_str = "KHZ_144";
4089 break;
4090 }
4091 default:
4092 rate_str = "KHZ_48";
4093 break;
4094 }
4095
4096 ctl = mixer_get_ctl_by_name(adev->mixer,
4097 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
4098 if(!ctl) {
4099 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
4100 __func__,
4101 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
4102 return -EINVAL;
4103 }
4104
4105 ALOGD("%s:becf: afe: %s set to %s", __func__,
4106 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl, rate_str);
4107 mixer_ctl_set_enum_by_string(ctl, rate_str);
4108 my_data->current_backend_cfg[backend_idx].sample_rate = sample_rate;
4109 }
4110 if ((my_data->current_backend_cfg[backend_idx].channels_mixer_ctl) &&
4111 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
4112 struct mixer_ctl *ctl = NULL;
4113 char *channel_cnt_str = NULL;
4114
4115 switch (channels) {
4116 case 8:
4117 channel_cnt_str = "Eight"; break;
4118 case 7:
4119 channel_cnt_str = "Seven"; break;
4120 case 6:
4121 channel_cnt_str = "Six"; break;
4122 case 5:
4123 channel_cnt_str = "Five"; break;
4124 case 4:
4125 channel_cnt_str = "Four"; break;
4126 case 3:
4127 channel_cnt_str = "Three"; break;
4128 case 1:
4129 channel_cnt_str = "One"; break;
4130 case 2:
4131 default:
4132 channel_cnt_str = "Two"; break;
4133 }
4134
4135 ctl = mixer_get_ctl_by_name(adev->mixer,
4136 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
4137 if (!ctl) {
4138 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
4139 __func__,
4140 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
4141 return -EINVAL;
4142 }
4143 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
4144 my_data->current_backend_cfg[backend_idx].channels = channels;
4145
4146 // skip EDID configuration for HDMI backend
4147
4148 ALOGD("%s:becf: afe: %s set to %s", __func__,
4149 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl,
4150 channel_cnt_str);
4151 }
4152
4153 // skip set ext_display format mixer control
4154 return ret;
4155}
4156
4157static int platform_get_snd_device_bit_width(snd_device_t snd_device)
4158{
4159 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
4160 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
4161 return CODEC_BACKEND_DEFAULT_BIT_WIDTH;
4162 }
4163
4164 return backend_bit_width_table[snd_device];
4165}
4166
4167/*
4168 * return backend_idx on which voice call is active
4169 */
4170static int platform_get_voice_call_backend(struct audio_device* adev)
4171{
4172 struct audio_usecase *uc = NULL;
4173 struct listnode *node;
4174 snd_device_t out_snd_device = SND_DEVICE_NONE;
4175
4176 int backend_idx = -1;
4177
4178 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
4179 list_for_each(node, &adev->usecase_list) {
4180 uc = node_to_item(node, struct audio_usecase, list);
4181 if (uc && uc->type == VOICE_CALL && uc->stream.out) {
4182 out_snd_device = platform_get_output_snd_device(adev->platform,
4183 uc->stream.out->devices);
4184 backend_idx = platform_get_backend_index(out_snd_device);
4185 break;
4186 }
4187 }
4188 }
4189 return backend_idx;
4190}
4191
4192/*
4193 * goes through all the current usecases and picks the highest
4194 * bitwidth & samplerate
4195 */
4196static bool platform_check_capture_backend_cfg(struct audio_device* adev,
4197 int backend_idx,
4198 struct audio_backend_cfg *backend_cfg)
4199{
4200 bool backend_change = false;
4201 unsigned int bit_width;
4202 unsigned int sample_rate;
4203 unsigned int channels;
4204 struct platform_data *my_data = (struct platform_data *)adev->platform;
4205
4206 bit_width = backend_cfg->bit_width;
4207 sample_rate = backend_cfg->sample_rate;
4208 channels = backend_cfg->channels;
4209
4210 ALOGV("%s:txbecf: afe: Codec selected backend: %d current bit width: %d and "
4211 "sample rate: %d, channels %d",__func__,backend_idx, bit_width,
4212 sample_rate, channels);
4213
4214 // For voice calls use default configuration i.e. 16b/48K, only applicable to
4215 // default backend
4216 // force routing is not required here, caller will do it anyway
4217 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
4218 ALOGW("%s:txbecf: afe: Use default bw and sr for voice/voip calls and "
4219 "for unprocessed/camera source", __func__);
4220 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
4221 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4222 }
4223
4224 if (backend_idx == USB_AUDIO_TX_BACKEND) {
4225 audio_extn_usb_is_config_supported(&bit_width, &sample_rate, &channels, false);
4226 ALOGV("%s:txbecf: afe: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
4227 __func__, bit_width, sample_rate, channels);
4228 }
4229
4230 ALOGV("%s:txbecf: afe: Codec selected backend: %d updated bit width: %d and "
4231 "sample rate: %d", __func__, backend_idx, bit_width, sample_rate);
4232
4233 // Force routing if the expected bitwdith or samplerate
4234 // is not same as current backend comfiguration
4235 if ((bit_width != my_data->current_backend_cfg[backend_idx].bit_width) ||
4236 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate) ||
4237 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
4238 backend_cfg->bit_width = bit_width;
4239 backend_cfg->sample_rate= sample_rate;
4240 backend_cfg->channels = channels;
4241 backend_change = true;
4242 ALOGI("%s:txbecf: afe: Codec backend needs to be updated. new bit width: %d "
4243 "new sample rate: %d new channel: %d",
4244 __func__, backend_cfg->bit_width,
4245 backend_cfg->sample_rate, backend_cfg->channels);
4246 }
4247
4248 return backend_change;
4249}
4250
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004251static void pick_playback_cfg_for_uc(struct audio_device *adev,
4252 struct audio_usecase *usecase,
4253 snd_device_t snd_device,
4254 unsigned int *bit_width,
4255 unsigned int *sample_rate,
4256 unsigned int *channels)
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004257{
4258 int i =0;
4259 struct listnode *node;
4260 list_for_each(node, &adev->usecase_list) {
4261 struct audio_usecase *uc;
4262 uc = node_to_item(node, struct audio_usecase, list);
4263 struct stream_out *out = (struct stream_out*) uc->stream.out;
4264 if (uc->type == PCM_PLAYBACK && out && usecase != uc) {
4265 unsigned int out_channels = audio_channel_count_from_out_mask(out->channel_mask);
4266 ALOGV("%s:napb: (%d) - (%s)id (%d) sr %d bw "
4267 "(%d) ch (%d) device %s", __func__, i++, use_case_table[uc->id],
4268 uc->id, out->sample_rate,
4269 pcm_format_to_bits(out->config.format), out_channels,
4270 platform_get_snd_device_name(uc->out_snd_device));
4271
4272 if (platform_check_backends_match(snd_device, uc->out_snd_device)) {
4273 if (*bit_width < pcm_format_to_bits(out->config.format))
4274 *bit_width = pcm_format_to_bits(out->config.format);
4275 if (*sample_rate < out->sample_rate)
4276 *sample_rate = out->sample_rate;
4277 if (out->sample_rate < OUTPUT_SAMPLING_RATE_44100)
4278 *sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4279 if (*channels < out_channels)
4280 *channels = out_channels;
4281 }
4282 }
4283 }
4284 return;
4285}
4286
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004287static void headset_is_config_supported(unsigned int *bit_width,
4288 unsigned int *sample_rate,
4289 unsigned int *channels) {
4290 switch (*bit_width) {
4291 case 16:
4292 case 24:
4293 break;
4294 default:
4295 *bit_width = 16;
4296 break;
4297 }
4298
4299 if (*sample_rate > 192000) {
4300 *sample_rate = 192000;
4301 }
4302
4303 if (*channels > 2) {
4304 *channels = 2;
4305 }
4306}
4307
David Linee3fe402017-03-13 10:00:42 -07004308static bool platform_check_playback_backend_cfg(struct audio_device* adev,
4309 struct audio_usecase* usecase,
4310 snd_device_t snd_device,
4311 struct audio_backend_cfg *backend_cfg)
4312{
4313 bool backend_change = false;
David Linee3fe402017-03-13 10:00:42 -07004314 unsigned int bit_width;
4315 unsigned int sample_rate;
4316 unsigned int channels;
David Linee3fe402017-03-13 10:00:42 -07004317 int backend_idx = DEFAULT_CODEC_BACKEND;
Haynes Mathew George65f6b432018-02-27 17:44:55 -08004318 unsigned long service_interval = 0; // 0 is invalid
David Linee3fe402017-03-13 10:00:42 -07004319 struct platform_data *my_data = (struct platform_data *)adev->platform;
David Linee3fe402017-03-13 10:00:42 -07004320
4321 if (snd_device == SND_DEVICE_OUT_BT_SCO ||
4322 snd_device == SND_DEVICE_OUT_BT_SCO_WB) {
4323 backend_change = false;
4324 return backend_change;
4325 }
4326
4327 backend_idx = platform_get_backend_index(snd_device);
4328 bit_width = backend_cfg->bit_width;
4329 sample_rate = backend_cfg->sample_rate;
4330 channels = backend_cfg->channels;
4331
4332 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
4333 ", backend_idx %d usecase = %d device (%s)", __func__, bit_width,
4334 sample_rate, channels, backend_idx, usecase->id,
4335 platform_get_snd_device_name(snd_device));
4336
4337 if (backend_idx == platform_get_voice_call_backend(adev)) {
4338 ALOGW("%s:becf: afe:Use default bw and sr for voice/voip calls ",
4339 __func__);
4340 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
4341 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4342 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
4343 } else {
4344 /*
4345 * The backend should be configured at highest bit width and/or
4346 * sample rate amongst all playback usecases.
4347 * If the selected sample rate and/or bit width differ with
4348 * current backend sample rate and/or bit width, then, we set the
4349 * backend re-configuration flag.
4350 *
4351 * Exception: 16 bit playbacks is allowed through 16 bit/48/44.1 khz backend only
4352 */
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004353 pick_playback_cfg_for_uc(adev, usecase, snd_device,
4354 &bit_width,
4355 &sample_rate,
4356 &channels);
David Linee3fe402017-03-13 10:00:42 -07004357 }
4358
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004359 switch (backend_idx) {
4360 case USB_AUDIO_RX_BACKEND:
4361 audio_extn_usb_is_config_supported(&bit_width,
4362 &sample_rate, &channels, true);
Haynes Mathew George65f6b432018-02-27 17:44:55 -08004363 if (platform_get_usb_service_interval(adev->platform, true,
4364 &service_interval) == 0) {
4365 /* overwrite with best altset for this service interval */
4366 int ret =
4367 audio_extn_usb_altset_for_service_interval(true /*playback*/,
4368 service_interval,
4369 &bit_width,
4370 &sample_rate,
4371 &channels);
4372 if (ret < 0) {
4373 ALOGE("Failed to find altset for service interval %lu, skip reconfig",
4374 service_interval);
4375 return false;
4376 }
4377 }
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004378 ALOGV("%s: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
4379 __func__, bit_width, sample_rate, channels);
4380 break;
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004381 case HEADPHONE_BACKEND:
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004382 headset_is_config_supported(&bit_width, &sample_rate, &channels);
4383 break;
4384 case DEFAULT_CODEC_BACKEND:
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004385 default:
4386 bit_width = platform_get_snd_device_bit_width(snd_device);
4387 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4388 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
4389 break;
David Linee3fe402017-03-13 10:00:42 -07004390 }
4391
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004392 ALOGV("%s:becf: afe: Codec selected backend: %d updated bit width: %d and"
4393 "sample rate: %d",
David Linee3fe402017-03-13 10:00:42 -07004394 __func__, backend_idx , bit_width, sample_rate);
4395
4396 // Force routing if the expected bitwdith or samplerate
4397 // is not same as current backend comfiguration
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004398 if (bit_width != my_data->current_backend_cfg[backend_idx].bit_width ||
4399 sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate ||
4400 channels != my_data->current_backend_cfg[backend_idx].channels) {
David Linee3fe402017-03-13 10:00:42 -07004401 backend_cfg->bit_width = bit_width;
4402 backend_cfg->sample_rate = sample_rate;
4403 backend_cfg->channels = channels;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004404 backend_cfg->passthrough_enabled = false;
David Linee3fe402017-03-13 10:00:42 -07004405 backend_change = true;
4406 ALOGV("%s:becf: afe: Codec backend needs to be updated. new bit width: %d"
4407 "new sample rate: %d new channels: %d",
4408 __func__, backend_cfg->bit_width, backend_cfg->sample_rate, backend_cfg->channels);
4409 }
4410
4411 return backend_change;
4412}
4413
4414bool platform_check_and_set_playback_backend_cfg(struct audio_device* adev,
4415 struct audio_usecase *usecase, snd_device_t snd_device)
4416{
4417 int backend_idx = DEFAULT_CODEC_BACKEND;
4418 int new_snd_devices[SND_DEVICE_OUT_END];
4419 int i, num_devices = 1;
4420 bool ret = false;
4421 struct platform_data *my_data = (struct platform_data *)adev->platform;
4422 struct audio_backend_cfg backend_cfg;
4423
4424 backend_idx = platform_get_backend_index(snd_device);
4425
4426 backend_cfg.bit_width = pcm_format_to_bits(usecase->stream.out->config.format);
4427 backend_cfg.sample_rate = usecase->stream.out->sample_rate;
4428 backend_cfg.format = usecase->stream.out->format;
4429 backend_cfg.channels = audio_channel_count_from_out_mask(usecase->stream.out->channel_mask);
4430 /*this is populated by check_codec_backend_cfg hence set default value to false*/
4431 backend_cfg.passthrough_enabled = false;
4432
4433 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
4434 ", backend_idx %d usecase = %d device (%s)", __func__, backend_cfg.bit_width,
4435 backend_cfg.sample_rate, backend_cfg.channels, backend_idx, usecase->id,
4436 platform_get_snd_device_name(snd_device));
4437
4438 if (platform_can_split_snd_device(snd_device, &num_devices, new_snd_devices) < 0)
4439 new_snd_devices[0] = snd_device;
4440
4441 for (i = 0; i < num_devices; i++) {
4442 ALOGV("%s: new_snd_devices[%d] is %d", __func__, i, new_snd_devices[i]);
4443 if ((platform_check_playback_backend_cfg(adev, usecase, new_snd_devices[i],
4444 &backend_cfg))) {
4445 platform_set_backend_cfg(adev, new_snd_devices[i],
4446 &backend_cfg);
4447 ret = true;
4448 }
4449 }
4450 return ret;
4451}
4452
4453bool platform_check_and_set_capture_backend_cfg(struct audio_device* adev,
4454 struct audio_usecase *usecase, snd_device_t snd_device)
4455{
4456 int backend_idx = platform_get_backend_index(snd_device);
4457 int ret = 0;
4458 struct audio_backend_cfg backend_cfg;
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004459 memset(&backend_cfg, 0, sizeof(struct audio_backend_cfg));
David Linee3fe402017-03-13 10:00:42 -07004460
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004461 if (usecase->type == PCM_CAPTURE) {
4462 backend_cfg.format = usecase->stream.in->format;
David Linee3fe402017-03-13 10:00:42 -07004463 backend_cfg.channels = audio_channel_count_from_in_mask(usecase->stream.in->channel_mask);
4464 } else {
4465 backend_cfg.bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
4466 backend_cfg.sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4467 backend_cfg.format = AUDIO_FORMAT_PCM_16_BIT;
4468 backend_cfg.channels = 1;
4469 }
4470
4471 ALOGV("%s:txbecf: afe: bitwidth %d, samplerate %d, channel %d"
4472 ", backend_idx %d usecase = %d device (%s)", __func__,
4473 backend_cfg.bit_width,
4474 backend_cfg.sample_rate,
4475 backend_cfg.channels,
4476 backend_idx, usecase->id,
4477 platform_get_snd_device_name(snd_device));
4478
4479 if (platform_check_capture_backend_cfg(adev, backend_idx, &backend_cfg)) {
4480 ret = platform_set_backend_cfg(adev, snd_device,
4481 &backend_cfg);
4482 if(!ret)
4483 return true;
4484 }
4485
4486 return false;
4487}
4488
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004489static int max_be_dai_names = 0;
4490static const struct be_dai_name_struct *be_dai_name_table;
4491
4492/*
4493 * Retrieves the be_dai_name_table from kernel to enable a mapping
4494 * between sound device hw interfaces and backend IDs. This allows HAL to
4495 * specify the backend a specific calibration is needed for.
4496 */
4497static int init_be_dai_name_table(struct audio_device *adev)
4498{
4499 const char *mixer_ctl_name = "Backend DAI Name Table";
4500 struct mixer_ctl *ctl;
4501 int i, j, ret, size;
4502 bool valid_hw_interface;
4503
4504 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
4505 if (!ctl) {
4506 ALOGE("%s: Could not get ctl for mixer name %s\n",
4507 __func__, mixer_ctl_name);
4508 ret = -EINVAL;
4509 goto done;
4510 }
4511
4512 mixer_ctl_update(ctl);
4513
4514 size = mixer_ctl_get_num_values(ctl);
4515 if (size <= 0){
4516 ALOGE("%s: Failed to get %s size %d\n",
4517 __func__, mixer_ctl_name, size);
4518 ret = -EFAULT;
4519 goto done;
4520 }
4521
vivek mehtaa68fea62017-06-08 19:04:02 -07004522 be_dai_name_table =
4523 (const struct be_dai_name_struct *)calloc(1, size);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004524 if (be_dai_name_table == NULL) {
4525 ALOGE("%s: Failed to allocate memory for %s\n",
4526 __func__, mixer_ctl_name);
4527 ret = -ENOMEM;
4528 goto freeMem;
4529 }
4530
4531 ret = mixer_ctl_get_array(ctl, (void *)be_dai_name_table, size);
4532 if (ret) {
4533 ALOGE("%s: Failed to get %s, ret %d\n",
4534 __func__, mixer_ctl_name, ret);
4535 ret = -EFAULT;
4536 goto freeMem;
4537 }
4538
4539 if (be_dai_name_table != NULL) {
4540 max_be_dai_names = size / sizeof(struct be_dai_name_struct);
4541 ALOGV("%s: Successfully got %s, number of be dais is %d\n",
4542 __func__, mixer_ctl_name, max_be_dai_names);
4543 ret = 0;
4544 } else {
4545 ALOGE("%s: Failed to get %s\n", __func__, mixer_ctl_name);
4546 ret = -EFAULT;
4547 goto freeMem;
4548 }
4549
4550 /*
4551 * Validate all sound devices have a valid backend set to catch
4552 * errors for uncommon sound devices
4553 */
4554 for (i = 0; i < SND_DEVICE_MAX; i++) {
4555 valid_hw_interface = false;
4556
4557 if (hw_interface_table[i] == NULL) {
4558 ALOGW("%s: sound device %s has no hw interface set\n",
4559 __func__, platform_get_snd_device_name(i));
4560 continue;
4561 }
4562
4563 for (j = 0; j < max_be_dai_names; j++) {
4564 if (strcmp(hw_interface_table[i], be_dai_name_table[j].be_name)
4565 == 0) {
4566 valid_hw_interface = true;
4567 break;
4568 }
4569 }
4570 if (!valid_hw_interface)
4571 ALOGD("%s: sound device %s does not have a valid hw interface set "
4572 "(disregard for combo devices) %s\n",
4573 __func__, platform_get_snd_device_name(i),
4574 hw_interface_table[i]);
4575 }
4576
4577 goto done;
4578
4579freeMem:
4580 if (be_dai_name_table) {
4581 free((void *)be_dai_name_table);
4582 be_dai_name_table = NULL;
4583 }
4584
4585done:
4586 return ret;
4587}
4588
4589int platform_get_snd_device_backend_index(snd_device_t device)
4590{
4591 int i, be_dai_id;
4592 const char * hw_interface_name = NULL;
4593
4594 ALOGV("%s: enter with device %d\n", __func__, device);
4595
vivek mehtaa68fea62017-06-08 19:04:02 -07004596 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004597 ALOGE("%s: Invalid snd_device = %d",
4598 __func__, device);
4599 be_dai_id = -EINVAL;
4600 goto done;
4601 }
4602
4603 /* Get string value of necessary backend for device */
4604 hw_interface_name = hw_interface_table[device];
4605 if (hw_interface_name == NULL) {
4606 ALOGE("%s: no hw_interface set for device %d\n", __func__, device);
4607 be_dai_id = -EINVAL;
4608 goto done;
4609 }
4610
4611 /* Check if be dai name table was retrieved successfully */
4612 if (be_dai_name_table == NULL) {
4613 ALOGE("%s: BE DAI Name Table is not present\n", __func__);
4614 be_dai_id = -EFAULT;
4615 goto done;
4616 }
4617
4618 /* Get backend ID for device specified */
4619 for (i = 0; i < max_be_dai_names; i++) {
4620 if (strcmp(hw_interface_name, be_dai_name_table[i].be_name) == 0) {
4621 be_dai_id = be_dai_name_table[i].be_id;
4622 goto done;
4623 }
4624 }
4625 ALOGE("%s: no interface matching name %s\n", __func__, hw_interface_name);
4626 be_dai_id = -EINVAL;
4627 goto done;
4628
4629done:
4630 return be_dai_id;
4631}
4632
4633void platform_check_and_update_copp_sample_rate(void* platform, snd_device_t snd_device,
4634 unsigned int stream_sr, int* sample_rate)
4635{
4636 struct platform_data* my_data = (struct platform_data *)platform;
4637 int backend_idx = platform_get_backend_index(snd_device);
4638 int device_sr = my_data->current_backend_cfg[backend_idx].sample_rate;
4639 /*
4640 *Check if device SR is multiple of 8K or 11.025 Khz
4641 *check if the stream SR is multiple of same base, if yes
4642 *then have copp SR equal to stream SR, this ensures that
4643 *post processing happens at stream SR, else have
4644 *copp SR equal to device SR.
4645 */
4646 if (!(((sample_rate_multiple(device_sr, SAMPLE_RATE_8000)) &&
4647 (sample_rate_multiple(stream_sr, SAMPLE_RATE_8000))) ||
4648 ((sample_rate_multiple(device_sr, SAMPLE_RATE_11025)) &&
4649 (sample_rate_multiple(stream_sr, SAMPLE_RATE_11025))))) {
4650 *sample_rate = device_sr;
4651 } else
4652 *sample_rate = stream_sr;
4653
4654 ALOGI("sn_device %d device sr %d stream sr %d copp sr %d", snd_device, device_sr, stream_sr
4655 , *sample_rate);
4656
4657}
4658
4659// called from info parser
vivek mehtaa68fea62017-06-08 19:04:02 -07004660void platform_add_app_type(const char *uc_type,
4661 const char *mode,
4662 int bw,
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004663 int app_type, int max_rate) {
4664 struct app_type_entry *ap =
4665 (struct app_type_entry *)calloc(1, sizeof(struct app_type_entry));
4666
4667 if (!ap) {
4668 ALOGE("%s failed to allocate mem for app type", __func__);
4669 return;
4670 }
4671
4672 ap->uc_type = -1;
4673 for (int i=0; i<USECASE_TYPE_MAX; i++) {
4674 if (!strcmp(uc_type, usecase_type_index[i].name)) {
4675 ap->uc_type = usecase_type_index[i].index;
4676 break;
4677 }
4678 }
4679
4680 if (ap->uc_type == -1) {
4681 free(ap);
4682 return;
4683 }
4684
vivek mehtaa68fea62017-06-08 19:04:02 -07004685 ALOGI("%s uc %s mode %s bw %d app_type %d max_rate %d",
4686 __func__, uc_type, mode, bw, app_type, max_rate);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004687 ap->bit_width = bw;
4688 ap->app_type = app_type;
4689 ap->max_rate = max_rate;
vivek mehtaa68fea62017-06-08 19:04:02 -07004690 ap->mode = strdup(mode);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004691 list_add_tail(&app_type_entry_list, &ap->node);
4692}
4693
4694
4695int platform_get_default_app_type_v2(void *platform __unused,
4696 usecase_type_t type,
4697 int *app_type )
4698{
4699 if (type == PCM_PLAYBACK)
4700 *app_type = DEFAULT_APP_TYPE_RX_PATH;
4701 else
4702 *app_type = DEFAULT_APP_TYPE_TX_PATH;
4703 return 0;
4704}
4705
vivek mehtaa68fea62017-06-08 19:04:02 -07004706int platform_get_app_type_v2(void *platform,
4707 usecase_type_t uc_type,
4708 const char *mode,
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004709 int bw, int sr __unused,
4710 int *app_type)
4711{
4712 struct listnode *node;
4713 struct app_type_entry *entry;
4714 *app_type = -1;
vivek mehtaa68fea62017-06-08 19:04:02 -07004715
4716 ALOGV("%s find match for uc %d mode %s bw %d rate %d",
4717 __func__, uc_type, mode, bw, sr);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004718 list_for_each(node, &app_type_entry_list) {
4719 entry = node_to_item(node, struct app_type_entry, node);
vivek mehtaa68fea62017-06-08 19:04:02 -07004720 ALOGV("%s uc %d mode %s bw %d app_type %d max_rate %d",
4721 __func__, entry->uc_type, entry->mode, entry->bit_width,
4722 entry->app_type, entry->max_rate);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004723 if (entry->bit_width == bw &&
vivek mehtaa68fea62017-06-08 19:04:02 -07004724 entry->uc_type == uc_type &&
4725 sr <= entry->max_rate &&
4726 entry->mode && !strcmp(mode, entry->mode)) {
4727 ALOGV("%s found match %d", __func__, entry->app_type);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004728 *app_type = entry->app_type;
4729 break;
4730 }
4731 }
4732
4733 if (*app_type == -1) {
vivek mehtaa68fea62017-06-08 19:04:02 -07004734 ALOGV("%s no match found, return default", __func__);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004735 return platform_get_default_app_type_v2(platform, uc_type, app_type);
4736 }
4737 return 0;
4738}
vivek mehta90933872017-06-15 18:04:39 -07004739
4740int platform_set_sidetone(struct audio_device *adev,
4741 snd_device_t out_snd_device,
4742 bool enable, char *str)
4743{
4744 int ret;
4745 if (out_snd_device == SND_DEVICE_OUT_USB_HEADSET ||
4746 out_snd_device == SND_DEVICE_OUT_VOICE_USB_HEADSET) {
4747 ret = audio_extn_usb_enable_sidetone(out_snd_device, enable);
4748 if (ret)
4749 ALOGI("%s: usb device %d does not support device sidetone\n",
4750 __func__, out_snd_device);
4751 } else {
4752 ALOGV("%s: sidetone out device(%d) mixer cmd = %s\n",
4753 __func__, out_snd_device, str);
4754 if (enable)
4755 audio_route_apply_and_update_path(adev->audio_route, str);
4756 else
4757 audio_route_reset_and_update_path(adev->audio_route, str);
4758 }
4759 return 0;
4760}
Haynes Mathew George96483a22017-03-28 14:52:47 -07004761
4762int platform_get_mmap_data_fd(void *platform __unused, int fe_dev __unused, int dir __unused,
4763 int *fd __unused, uint32_t *size __unused)
4764{
Thierry Strudel07f96d12018-09-20 13:31:34 -07004765#if defined (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845) || (PLATFORM_SDM710) || (PLATFORM_SM8150)
Haynes Mathew George96483a22017-03-28 14:52:47 -07004766 struct platform_data *my_data = (struct platform_data *)platform;
4767 struct audio_device *adev = my_data->adev;
4768 int hw_fd = -1;
4769 char dev_name[128];
4770 struct snd_pcm_mmap_fd mmap_fd;
4771 memset(&mmap_fd, 0, sizeof(mmap_fd));
4772 mmap_fd.dir = dir;
4773 snprintf(dev_name, sizeof(dev_name), "/dev/snd/hwC%uD%u",
4774 adev->snd_card, HWDEP_FE_BASE+fe_dev);
4775 hw_fd = open(dev_name, O_RDONLY);
4776 if (hw_fd < 0) {
4777 ALOGE("fe hw dep node open %d/%d failed", adev->snd_card, fe_dev);
4778 return -1;
4779 }
4780 if (ioctl(hw_fd, SNDRV_PCM_IOCTL_MMAP_DATA_FD, &mmap_fd) < 0) {
4781 ALOGE("fe hw dep node ioctl failed");
4782 close(hw_fd);
4783 return -1;
4784 }
4785 *fd = mmap_fd.fd;
4786 *size = mmap_fd.size;
4787 close(hw_fd); // mmap_fd should still be valid
4788 return 0;
4789#else
4790 return -1;
4791#endif
4792}
Mikhail Naganov4ee6e3e2018-03-21 16:28:35 +00004793
4794bool platform_sound_trigger_usecase_needs_event(audio_usecase_t uc_id)
4795{
4796 bool needs_event = false;
4797
4798 switch (uc_id) {
4799 /* concurrent capture usecases which needs event */
4800 case USECASE_AUDIO_RECORD:
4801 case USECASE_AUDIO_RECORD_LOW_LATENCY:
4802 case USECASE_AUDIO_RECORD_MMAP:
4803 case USECASE_AUDIO_RECORD_HIFI:
4804 case USECASE_AUDIO_RECORD_VOIP:
4805 case USECASE_VOICEMMODE1_CALL:
4806 case USECASE_VOICEMMODE2_CALL:
4807 /* concurrent playback usecases that needs event */
4808 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
4809 case USECASE_AUDIO_PLAYBACK_OFFLOAD:
4810 needs_event = true;
4811 break;
4812 default:
4813 ALOGV("%s:usecase_id[%d] no need to raise event.", __func__, uc_id);
4814 }
4815 return needs_event;
4816}
4817
4818bool platform_snd_device_has_speaker(snd_device_t dev) {
4819 int num_devs = 2;
4820 snd_device_t split_devs[2] = {SND_DEVICE_NONE, SND_DEVICE_NONE};
4821 if (platform_can_split_snd_device(dev, &num_devs, split_devs) == 0) {
4822 return platform_snd_device_has_speaker(split_devs[0]) ||
4823 platform_snd_device_has_speaker(split_devs[1]);
4824 }
4825
4826 switch (dev) {
4827 case SND_DEVICE_OUT_SPEAKER:
4828 case SND_DEVICE_OUT_SPEAKER_SAFE:
4829 case SND_DEVICE_OUT_SPEAKER_REVERSE:
4830 case SND_DEVICE_OUT_SPEAKER_PROTECTED:
4831 case SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED:
4832 case SND_DEVICE_OUT_VOICE_SPEAKER_HFP:
4833 return true;
4834 default:
4835 break;
4836 }
4837 return false;
4838}
jiabin8962a4d2018-03-19 18:21:24 -07004839
4840bool platform_set_microphone_characteristic(void *platform,
4841 struct audio_microphone_characteristic_t mic) {
4842 struct platform_data *my_data = (struct platform_data *)platform;
4843 if (my_data->declared_mic_count >= AUDIO_MICROPHONE_MAX_COUNT) {
4844 ALOGE("mic number is more than maximum number");
4845 return false;
4846 }
4847 for (size_t ch = 0; ch < AUDIO_CHANNEL_COUNT_MAX; ch++) {
4848 mic.channel_mapping[ch] = AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED;
4849 }
4850 my_data->microphones[my_data->declared_mic_count++] = mic;
4851 return true;
4852}
4853
4854int platform_get_microphones(void *platform,
4855 struct audio_microphone_characteristic_t *mic_array,
4856 size_t *mic_count) {
4857 struct platform_data *my_data = (struct platform_data *)platform;
4858 if (mic_count == NULL) {
4859 return -EINVAL;
4860 }
4861 if (mic_array == NULL) {
4862 return -EINVAL;
4863 }
4864
4865 if (*mic_count == 0) {
4866 *mic_count = my_data->declared_mic_count;
4867 return 0;
4868 }
4869
4870 size_t max_mic_count = *mic_count;
4871 size_t actual_mic_count = 0;
4872 for (size_t i = 0; i < max_mic_count && i < my_data->declared_mic_count; i++) {
4873 mic_array[i] = my_data->microphones[i];
4874 actual_mic_count++;
4875 }
4876 *mic_count = actual_mic_count;
4877 return 0;
4878}
4879
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004880bool platform_set_microphone_map(void *platform, snd_device_t in_snd_device,
4881 const struct mic_info *info) {
4882 struct platform_data *my_data = (struct platform_data *)platform;
4883 if (in_snd_device < SND_DEVICE_IN_BEGIN || in_snd_device >= SND_DEVICE_IN_END) {
4884 ALOGE("%s: Sound device not valid", __func__);
4885 return false;
4886 }
4887 size_t m_count = my_data->mic_map[in_snd_device].mic_count++;
4888 if (m_count >= AUDIO_MICROPHONE_MAX_COUNT) {
4889 ALOGE("%s: Microphone count is greater than max allowed value", __func__);
4890 my_data->mic_map[in_snd_device].mic_count--;
4891 return false;
4892 }
4893 my_data->mic_map[in_snd_device].microphones[m_count] = *info;
4894 return true;
4895}
4896
4897int platform_get_active_microphones(void *platform, unsigned int channels,
4898 audio_usecase_t uc_id,
jiabin8962a4d2018-03-19 18:21:24 -07004899 struct audio_microphone_characteristic_t *mic_array,
4900 size_t *mic_count) {
4901 struct platform_data *my_data = (struct platform_data *)platform;
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004902 struct audio_usecase *usecase = get_usecase_from_list(my_data->adev, uc_id);
4903 if (mic_count == NULL || mic_array == NULL || usecase == NULL) {
jiabin8962a4d2018-03-19 18:21:24 -07004904 return -EINVAL;
4905 }
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004906 size_t max_mic_count = my_data->declared_mic_count;
jiabin8962a4d2018-03-19 18:21:24 -07004907 size_t actual_mic_count = 0;
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004908
4909 snd_device_t active_input_snd_device =
Eric Laurentd1b7a9b2018-11-15 12:24:31 -08004910 platform_get_input_snd_device(platform, usecase->stream.in, AUDIO_DEVICE_NONE);
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004911 if (active_input_snd_device == SND_DEVICE_NONE) {
4912 ALOGI("%s: No active microphones found", __func__);
4913 goto end;
4914 }
4915
4916 size_t active_mic_count = my_data->mic_map[active_input_snd_device].mic_count;
4917 struct mic_info *m_info = my_data->mic_map[active_input_snd_device].microphones;
4918
4919 for (size_t i = 0; i < active_mic_count; i++) {
4920 unsigned int channels_for_active_mic = channels;
4921 if (channels_for_active_mic > m_info[i].channel_count) {
4922 channels_for_active_mic = m_info[i].channel_count;
4923 }
4924 for (size_t j = 0; j < max_mic_count; j++) {
4925 if (strcmp(my_data->microphones[j].device_id,
4926 m_info[i].device_id) == 0) {
4927 mic_array[actual_mic_count] = my_data->microphones[j];
4928 for (size_t ch = 0; ch < channels_for_active_mic; ch++) {
4929 mic_array[actual_mic_count].channel_mapping[ch] =
4930 m_info[i].channel_mapping[ch];
4931 }
4932 actual_mic_count++;
4933 break;
jiabin8962a4d2018-03-19 18:21:24 -07004934 }
jiabin8962a4d2018-03-19 18:21:24 -07004935 }
4936 }
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004937end:
jiabin8962a4d2018-03-19 18:21:24 -07004938 *mic_count = actual_mic_count;
4939 return 0;
4940}
Haynes Mathew George65f6b432018-02-27 17:44:55 -08004941
4942int platform_set_usb_service_interval(void *platform,
4943 bool playback,
4944 unsigned long service_interval,
4945 bool *reconfig)
4946{
4947#if defined (USB_SERVICE_INTERVAL_ENABLED)
4948 struct platform_data *_platform = (struct platform_data *)platform;
4949 *reconfig = false;
4950 if (!playback) {
4951 ALOGE("%s not valid for capture", __func__);
4952 return -1;
4953 }
4954 const char *ctl_name = "USB_AUDIO_RX service_interval";
4955 struct mixer_ctl *ctl = mixer_get_ctl_by_name(_platform->adev->mixer,
4956 ctl_name);
4957 if (!ctl) {
4958 ALOGV("%s: could not get mixer %s", __func__, ctl_name);
4959 return -1;
4960 }
4961 if (mixer_ctl_get_value(ctl, 0) != (int)service_interval) {
4962 mixer_ctl_set_value(ctl, 0, service_interval);
4963 *reconfig = true;
4964 }
4965 return 0;
4966#else
4967 *reconfig = false;
4968 (void)platform;
4969 (void)playback;
4970 (void)service_interval;
4971 return -1;
4972#endif
4973}
4974
4975int platform_get_usb_service_interval(void *platform,
4976 bool playback,
4977 unsigned long *service_interval)
4978{
4979#if defined (USB_SERVICE_INTERVAL_ENABLED)
4980 struct platform_data *_platform = (struct platform_data *)platform;
4981 if (!playback) {
4982 ALOGE("%s not valid for capture", __func__);
4983 return -1;
4984 }
4985 const char *ctl_name = "USB_AUDIO_RX service_interval";
4986 struct mixer_ctl *ctl = mixer_get_ctl_by_name(_platform->adev->mixer,
4987 ctl_name);
4988 if (!ctl) {
4989 ALOGV("%s: could not get mixer %s", __func__, ctl_name);
4990 return -1;
4991 }
4992 *service_interval = mixer_ctl_get_value(ctl, 0);
4993 return 0;
4994#else
4995 (void)platform;
4996 (void)playback;
4997 (void)service_interval;
4998 return -1;
4999#endif
5000}
Ashish Jain1c849702018-05-11 20:11:55 +05305001
5002int platform_set_acdb_metainfo_key(void *platform __unused,
5003 char *name __unused,
5004 int key __unused)
5005{
5006 return -ENOSYS;
5007}