blob: ecb3db7eaa0d7938b55d7ab9b0ec1d74c0c092c1 [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",
juyuchend194b432018-11-16 14:15:16 +0800298 [SND_DEVICE_OUT_VOICE_HEARING_AID] = "hearing-aid",
Eric Laurentb23d5282013-05-14 15:27:20 -0700299
300 /* Capture sound devices */
301 [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700302 [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700303 [SND_DEVICE_IN_HANDSET_MIC_NS] = "handset-mic",
304 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = "handset-mic",
305 [SND_DEVICE_IN_HANDSET_DMIC] = "dmic-endfire",
306 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = "dmic-endfire",
307 [SND_DEVICE_IN_HANDSET_DMIC_NS] = "dmic-endfire",
308 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = "dmic-endfire",
309 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = "dmic-endfire",
310
311 [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
312 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "speaker-mic",
313 [SND_DEVICE_IN_SPEAKER_MIC_NS] = "speaker-mic",
314 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = "speaker-mic",
315 [SND_DEVICE_IN_SPEAKER_DMIC] = "speaker-dmic-endfire",
316 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = "speaker-dmic-endfire",
317 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = "speaker-dmic-endfire",
318 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = "speaker-dmic-endfire",
319 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = "speaker-dmic-endfire",
320
321 [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
Eric Laurentcefbbac2014-09-04 13:54:10 -0500322 [SND_DEVICE_IN_HEADSET_MIC_AEC] = "headset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700323
Eric Laurentb23d5282013-05-14 15:27:20 -0700324 [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic",
325 [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700326 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = "bt-sco-mic",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700327 [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700328 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = "bt-sco-mic-wb",
Eric Laurent5f4ca952018-10-19 17:33:43 -0700329 [SND_DEVICE_IN_CAMCORDER_LANDSCAPE] = "camcorder-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700330
331 [SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef",
332 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = "voice-dmic-ef-tmus",
333 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
334 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = "voice-speaker-dmic-ef",
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -0700335 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = "voice-speaker-mic-hfp",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700336 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700337 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
338 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
339 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
vivek mehtaa6b79742017-03-09 15:40:43 -0800340 [SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = "voice-tty-full-usb-mic",
341 [SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = "voice-tty-hco-usb-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700342
Eric Laurentb23d5282013-05-14 15:27:20 -0700343 [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700344 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = "voice-rec-mic",
vivek mehta733c1df2016-04-04 15:09:24 -0700345 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = "voice-rec-mic",
vivek mehtaf3440682016-05-11 14:24:37 -0700346 [SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700347 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = "voice-rec-dmic-ef",
348 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence",
David Linee3fe402017-03-13 10:00:42 -0700349 [SND_DEVICE_IN_USB_HEADSET_MIC] = "usb-headset-mic",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700350 [SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] ="usb-headset-mic",
351 [SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = "usb-headset-mic",
352 [SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = "usb-headset-mic",
353 [SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = "usb-headset-mic",
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700354 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = "headset-mic",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700355
Ricardo Garcia9034bc42016-04-04 07:11:46 -0700356 [SND_DEVICE_IN_UNPROCESSED_MIC] = "unprocessed-mic",
vivek mehta0125e782016-06-16 18:03:11 -0700357 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = "unprocessed-stereo-mic",
358 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = "unprocessed-three-mic",
359 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = "unprocessed-quad-mic",
360 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = "unprocessed-headset-mic",
rago90fb9612015-12-02 11:37:53 -0800361
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700362 [SND_DEVICE_IN_VOICE_RX] = "voice-rx",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700363
Prashant Malanic92c5962015-08-11 15:10:18 -0700364 [SND_DEVICE_IN_THREE_MIC] = "three-mic",
365 [SND_DEVICE_IN_QUAD_MIC] = "quad-mic",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700366 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = "vi-feedback",
Prashant Malanic92c5962015-08-11 15:10:18 -0700367 [SND_DEVICE_IN_HANDSET_TMIC] = "three-mic",
368 [SND_DEVICE_IN_HANDSET_QMIC] = "quad-mic",
vivek mehta733c1df2016-04-04 15:09:24 -0700369 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = "three-mic",
370 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = "quad-mic",
Eric Laurent5f4ca952018-10-19 17:33:43 -0700371 [SND_DEVICE_IN_CAMCORDER_INVERT_LANDSCAPE] = "camcorder-mic",
372 [SND_DEVICE_IN_CAMCORDER_PORTRAIT] = "camcorder-mic",
373 [SND_DEVICE_IN_CAMCORDER_SELFIE_LANDSCAPE] = "camcorder-mic",
374 [SND_DEVICE_IN_CAMCORDER_SELFIE_INVERT_LANDSCAPE] = "camcorder-mic",
375 [SND_DEVICE_IN_CAMCORDER_SELFIE_PORTRAIT] = "camcorder-mic",
Vignesh Kulothungan64698822018-01-23 11:25:18 -0800376 [SND_DEVICE_IN_SPEAKER_QMIC_NS] = "quad-mic",
377 [SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS] = "quad-mic",
juyuchend194b432018-11-16 14:15:16 +0800378 [SND_DEVICE_IN_VOICE_HEARING_AID] = "hearing-aid-mic",
Vignesh Kulothungan64698822018-01-23 11:25:18 -0800379};
380
381static struct audio_effect_config \
382 effect_config_table[GET_IN_DEVICE_INDEX(SND_DEVICE_MAX)][EFFECT_COUNT] = {
383 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS)][EFFECT_AEC] = \
384 {TX_VOICE_FLUENCE_PROV2, 0x0, 0x10EAF, 0x01},
385 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS)][EFFECT_NS] = \
386 {TX_VOICE_FLUENCE_PROV2, 0x0, 0x10EAF, 0x02},
387 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)][EFFECT_AEC] = \
388 {TX_VOICE_FV5ECNS_DM, 0x0, 0x10EAF, 0x01},
389 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)][EFFECT_NS] = \
390 {TX_VOICE_FV5ECNS_DM, 0x0, 0x10EAF, 0x02},
391 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)][EFFECT_AEC] = \
392 {TX_VOICE_FV5ECNS_SM, 0x0, 0x10EAF, 0x01},
393 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)][EFFECT_NS] = \
394 {TX_VOICE_FV5ECNS_SM, 0x0, 0x10EAF, 0x02},
395 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)][EFFECT_AEC] = \
396 {TX_VOICE_FV5ECNS_DM, 0x0, 0x10EAF, 0x01},
397 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)][EFFECT_NS] = \
398 {TX_VOICE_FV5ECNS_DM, 0x0, 0x10EAF, 0x02},
399 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)][EFFECT_AEC] = \
400 {TX_VOICE_FV5ECNS_SM, 0x0, 0x10EAF, 0x01},
401 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)][EFFECT_NS] = \
402 {TX_VOICE_FV5ECNS_SM, 0x0, 0x10EAF, 0x02},
Eric Laurentb23d5282013-05-14 15:27:20 -0700403};
404
405/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700406static int acdb_device_table[SND_DEVICE_MAX] = {
Eric Laurentb23d5282013-05-14 15:27:20 -0700407 [SND_DEVICE_NONE] = -1,
408 [SND_DEVICE_OUT_HANDSET] = 7,
409 [SND_DEVICE_OUT_SPEAKER] = 15,
410 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 15,
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700411 [SND_DEVICE_OUT_SPEAKER_SAFE] = 15,
Eric Laurentb23d5282013-05-14 15:27:20 -0700412 [SND_DEVICE_OUT_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500413 [SND_DEVICE_OUT_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700414 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700415 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500416 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = 77,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700417 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = 77,
Ravi Kumar Alamanda235c3482014-08-21 17:32:44 -0700418 [SND_DEVICE_OUT_VOICE_HANDSET] = ACDB_ID_VOICE_HANDSET,
419 [SND_DEVICE_OUT_VOICE_SPEAKER] = ACDB_ID_VOICE_SPEAKER,
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500420 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = 53,
Eric Laurentb23d5282013-05-14 15:27:20 -0700421 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
yixuanjiang9536e672018-09-06 18:43:36 +0800422 [SND_DEVICE_OUT_VOICE_HEADSET] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500423 [SND_DEVICE_OUT_VOICE_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700424 [SND_DEVICE_OUT_HDMI] = 18,
425 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 15,
426 [SND_DEVICE_OUT_BT_SCO] = 22,
juyuchen5351ea62018-05-16 10:54:37 +0800427 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO] = 14,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700428 [SND_DEVICE_OUT_BT_SCO_WB] = 39,
juyuchen5351ea62018-05-16 10:54:37 +0800429 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB] = 14,
Aniket Kumar Lata26483012018-01-31 20:21:42 -0800430 [SND_DEVICE_OUT_BT_A2DP] = 20,
431 [SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] = 14,
Aniket Kumar Lata9723a962018-05-16 17:41:55 -0700432 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP] = 14,
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700433 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = ACDB_ID_VOICE_HANDSET_TMUS,
Eric Laurentb23d5282013-05-14 15:27:20 -0700434 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
435 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
436 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
vivek mehtaa6b79742017-03-09 15:40:43 -0800437 [SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = 17,
438 [SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = 17,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700439 [SND_DEVICE_OUT_VOICE_TX] = 45,
juyuchen66c4ecf2018-08-06 15:39:34 +0800440 [SND_DEVICE_OUT_VOICE_MUSIC_TX] = 3,
David Linee3fe402017-03-13 10:00:42 -0700441 [SND_DEVICE_OUT_USB_HEADSET] = 45,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700442 [SND_DEVICE_OUT_VOICE_USB_HEADSET] = 45,
David Linee3fe402017-03-13 10:00:42 -0700443 [SND_DEVICE_OUT_USB_HEADPHONES] = 45,
jasmine cha270b7762018-03-30 15:41:33 +0800444 [SND_DEVICE_OUT_USB_HEADSET_SPEC] = 45,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700445 [SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = 45,
David Linee3fe402017-03-13 10:00:42 -0700446 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = 14,
Haynes Mathew George9090bfb2017-05-31 11:44:50 -0700447 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] = 14,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700448 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = 124,
449 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = 101,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700450 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = ACDB_ID_VOICE_SPEAKER,
juyuchend194b432018-11-16 14:15:16 +0800451 [SND_DEVICE_OUT_VOICE_HEARING_AID] = 45,
Eric Laurentb23d5282013-05-14 15:27:20 -0700452
453 [SND_DEVICE_IN_HANDSET_MIC] = 4,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700454 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 106,
455 [SND_DEVICE_IN_HANDSET_MIC_NS] = 107,
456 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = 108,
457 [SND_DEVICE_IN_HANDSET_DMIC] = 41,
458 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = 109,
459 [SND_DEVICE_IN_HANDSET_DMIC_NS] = 110,
460 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = 111,
461 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = 34,
462
463 [SND_DEVICE_IN_SPEAKER_MIC] = 11,
464 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 112,
465 [SND_DEVICE_IN_SPEAKER_MIC_NS] = 113,
466 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = 114,
467 [SND_DEVICE_IN_SPEAKER_DMIC] = 43,
468 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = 115,
469 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = 116,
470 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = 117,
471 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = 35,
472
rago90fb9612015-12-02 11:37:53 -0800473 [SND_DEVICE_IN_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentcefbbac2014-09-04 13:54:10 -0500474 [SND_DEVICE_IN_HEADSET_MIC_AEC] = ACDB_ID_HEADSET_MIC_AEC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700475
Eric Laurentb23d5282013-05-14 15:27:20 -0700476 [SND_DEVICE_IN_HDMI_MIC] = 4,
477 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700478 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = 21,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700479 [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700480 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = 38,
Eric Laurent5f4ca952018-10-19 17:33:43 -0700481 [SND_DEVICE_IN_CAMCORDER_LANDSCAPE] = 61,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700482
483 [SND_DEVICE_IN_VOICE_DMIC] = 41,
484 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = ACDB_ID_VOICE_DMIC_EF_TMUS,
485 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700486 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = 11,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700487 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 43,
rago90fb9612015-12-02 11:37:53 -0800488 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentb23d5282013-05-14 15:27:20 -0700489 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
490 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
491 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
vivek mehtaa6b79742017-03-09 15:40:43 -0800492 [SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = 16,
493 [SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = 16,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700494
rago90fb9612015-12-02 11:37:53 -0800495 [SND_DEVICE_IN_VOICE_REC_MIC] = ACDB_ID_VOICE_REC_MIC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700496 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = 113,
vivek mehta733c1df2016-04-04 15:09:24 -0700497 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = 112,
vivek mehtaf3440682016-05-11 14:24:37 -0700498 [SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = 114,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700499 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = 35,
500 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 43,
rago90fb9612015-12-02 11:37:53 -0800501 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
502
503 [SND_DEVICE_IN_UNPROCESSED_MIC] = ACDB_ID_VOICE_REC_MIC,
504 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
vivek mehta4ed66e62016-04-15 23:33:34 -0700505 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = 35,
506 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = 125,
507 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = 125,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700508
509 [SND_DEVICE_IN_VOICE_RX] = 44,
David Linee3fe402017-03-13 10:00:42 -0700510 [SND_DEVICE_IN_USB_HEADSET_MIC] = 44,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700511 [SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = 44,
512 [SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = 44,
513 [SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = 44,
514 [SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = 44,
Prashant Malanic92c5962015-08-11 15:10:18 -0700515 [SND_DEVICE_IN_THREE_MIC] = 46,
516 [SND_DEVICE_IN_QUAD_MIC] = 46,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700517 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = 102,
Prashant Malanic92c5962015-08-11 15:10:18 -0700518 [SND_DEVICE_IN_HANDSET_TMIC] = 125,
519 [SND_DEVICE_IN_HANDSET_QMIC] = 125,
vivek mehta733c1df2016-04-04 15:09:24 -0700520 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = 125, /* override this for new target to 140 */
521 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = 125, /* override this for new target to 140 */
Eric Laurent5f4ca952018-10-19 17:33:43 -0700522 [SND_DEVICE_IN_CAMCORDER_INVERT_LANDSCAPE] = 61,
523 [SND_DEVICE_IN_CAMCORDER_PORTRAIT] = 61,
524 [SND_DEVICE_IN_CAMCORDER_SELFIE_LANDSCAPE] = 61,
525 [SND_DEVICE_IN_CAMCORDER_SELFIE_INVERT_LANDSCAPE] = 61,
526 [SND_DEVICE_IN_CAMCORDER_SELFIE_PORTRAIT] = 61,
Vignesh Kulothungan64698822018-01-23 11:25:18 -0800527 [SND_DEVICE_IN_SPEAKER_QMIC_NS] = 129,
528 [SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS] = 129,
juyuchend194b432018-11-16 14:15:16 +0800529 [SND_DEVICE_IN_VOICE_HEARING_AID] = 44,
Eric Laurentb23d5282013-05-14 15:27:20 -0700530};
531
David Linee3fe402017-03-13 10:00:42 -0700532// Platform specific backend bit width table
533static int backend_bit_width_table[SND_DEVICE_MAX] = {0};
534
Haynes Mathew George98c95622014-06-20 19:14:25 -0700535struct name_to_index {
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700536 char name[100];
537 unsigned int index;
538};
539
540#define TO_NAME_INDEX(X) #X, X
541
Haynes Mathew George98c95622014-06-20 19:14:25 -0700542/* Used to get index from parsed string */
543static const struct name_to_index snd_device_name_index[SND_DEVICE_MAX] = {
544 /* out */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700545 {TO_NAME_INDEX(SND_DEVICE_OUT_HANDSET)},
546 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER)},
547 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_REVERSE)},
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700548 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700549 {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500550 {TO_NAME_INDEX(SND_DEVICE_OUT_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700551 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700552 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES)},
Eric Laurent744996b2014-10-01 11:40:40 -0500553 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_LINE)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700554 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700555 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET)},
556 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700557 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_HFP)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700558 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADPHONES)},
yixuanjiang9536e672018-09-06 18:43:36 +0800559 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADSET)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500560 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700561 {TO_NAME_INDEX(SND_DEVICE_OUT_HDMI)},
562 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HDMI)},
563 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO)},
juyuchen5351ea62018-05-16 10:54:37 +0800564 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700565 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO_WB)},
juyuchen5351ea62018-05-16 10:54:37 +0800566 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB)},
Aniket Kumar Lata26483012018-01-31 20:21:42 -0800567 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_A2DP)},
568 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP)},
Aniket Kumar Lata9723a962018-05-16 17:41:55 -0700569 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700570 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET_TMUS)},
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500571 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HAC_HANDSET)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700572 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES)},
573 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES)},
574 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET)},
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -0800575 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_SCO)},
576 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800577 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_USB)},
578 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_USB)},
David Linee3fe402017-03-13 10:00:42 -0700579 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADSET)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700580 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_USB_HEADSET)},
David Linee3fe402017-03-13 10:00:42 -0700581 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADPHONES)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700582 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_USB_HEADPHONES)},
David Linee3fe402017-03-13 10:00:42 -0700583 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET)},
Haynes Mathew George9090bfb2017-05-31 11:44:50 -0700584 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700585 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED)},
586 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED)},
jasmine cha270b7762018-03-30 15:41:33 +0800587 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADSET_SPEC)},
juyuchend194b432018-11-16 14:15:16 +0800588 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEARING_AID)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800589
590 /* in */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700591 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700592 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700593 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_NS)},
594 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)},
595 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC)},
596 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC)},
597 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_NS)},
598 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)},
599 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_STEREO)},
600
601 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700602 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700603 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_NS)},
604 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)},
605 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC)},
606 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC)},
607 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS)},
608 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)},
609 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_STEREO)},
610
611 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC)},
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700612 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700613
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700614 {TO_NAME_INDEX(SND_DEVICE_IN_HDMI_MIC)},
615 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700616 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700617 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700618 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB_NREC)},
Eric Laurent5f4ca952018-10-19 17:33:43 -0700619 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_LANDSCAPE)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700620
621 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC)},
622 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC_TMUS)},
623 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700624 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700625 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC)},
626 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEADSET_MIC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700627 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC)},
628 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC)},
629 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800630 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC)},
631 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC)},
632
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700633
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700634 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700635 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_NS)},
vivek mehta733c1df2016-04-04 15:09:24 -0700636 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC)},
vivek mehtaf3440682016-05-11 14:24:37 -0700637 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700638 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_STEREO)},
639 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE)},
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700640 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_HEADSET_MIC)},
David Linee3fe402017-03-13 10:00:42 -0700641 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700642 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_USB_HEADSET_MIC)},
643 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC)},
644 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC)},
645 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC_AEC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700646
rago90fb9612015-12-02 11:37:53 -0800647 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_MIC)},
648 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC)},
vivek mehta4ed66e62016-04-15 23:33:34 -0700649 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_STEREO_MIC)},
650 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_THREE_MIC)},
651 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_QUAD_MIC)},
rago90fb9612015-12-02 11:37:53 -0800652
Prashant Malanic92c5962015-08-11 15:10:18 -0700653 {TO_NAME_INDEX(SND_DEVICE_IN_THREE_MIC)},
654 {TO_NAME_INDEX(SND_DEVICE_IN_QUAD_MIC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700655 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_VI_FEEDBACK)},
Prashant Malanic92c5962015-08-11 15:10:18 -0700656 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC)},
657 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC)},
vivek mehta733c1df2016-04-04 15:09:24 -0700658 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC_AEC)},
659 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC_AEC)},
Eric Laurent5f4ca952018-10-19 17:33:43 -0700660 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_INVERT_LANDSCAPE)},
661 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_PORTRAIT)},
662 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_SELFIE_LANDSCAPE)},
663 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_SELFIE_INVERT_LANDSCAPE)},
664 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_SELFIE_PORTRAIT)},
juyuchend194b432018-11-16 14:15:16 +0800665 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEARING_AID)},
666
Eric Laurent5f4ca952018-10-19 17:33:43 -0700667 /* For legacy xml file parsing */
668 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_MIC)},
Vignesh Kulothungan64698822018-01-23 11:25:18 -0800669 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_QMIC_NS)},
670 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700671};
672
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700673static char * backend_tag_table[SND_DEVICE_MAX] = {0};
674static char * hw_interface_table[SND_DEVICE_MAX] = {0};
Haynes Mathew George98c95622014-06-20 19:14:25 -0700675
676static const struct name_to_index usecase_name_index[AUDIO_USECASE_MAX] = {
677 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_DEEP_BUFFER)},
678 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_LOW_LATENCY)},
Vignesh Kulothungan019d19b2019-01-23 11:09:18 -0800679 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_WITH_HAPTICS)},
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800680 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_HIFI)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700681 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD)},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700682 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_TTS)},
683 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_ULL)},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800684 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_MMAP)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700685 {TO_NAME_INDEX(USECASE_AUDIO_RECORD)},
686 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_LOW_LATENCY)},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800687 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_MMAP)},
Haynes Mathew George569b7482017-05-08 14:44:27 -0700688 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_HIFI)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700689 {TO_NAME_INDEX(USECASE_VOICE_CALL)},
690 {TO_NAME_INDEX(USECASE_VOICE2_CALL)},
691 {TO_NAME_INDEX(USECASE_VOLTE_CALL)},
692 {TO_NAME_INDEX(USECASE_QCHAT_CALL)},
693 {TO_NAME_INDEX(USECASE_VOWLAN_CALL)},
John Muirf1346ce2016-12-06 00:03:41 -0800694 {TO_NAME_INDEX(USECASE_VOICEMMODE1_CALL)},
695 {TO_NAME_INDEX(USECASE_VOICEMMODE2_CALL)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700696 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK)},
697 {TO_NAME_INDEX(USECASE_INCALL_REC_DOWNLINK)},
698 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK_AND_DOWNLINK)},
699 {TO_NAME_INDEX(USECASE_AUDIO_HFP_SCO)},
John Muirf1346ce2016-12-06 00:03:41 -0800700 {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_RX)},
701 {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_TX)},
702 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_AFE_PROXY)},
703 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_AFE_PROXY)},
704 {TO_NAME_INDEX(USECASE_AUDIO_DSM_FEEDBACK)},
vivek mehtaa68fea62017-06-08 19:04:02 -0700705 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_VOIP)},
706 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_VOIP)},
Nadav Bar3d72cfc2018-01-07 12:19:24 +0200707 {TO_NAME_INDEX(USECASE_INCALL_MUSIC_UPLINK)},
Aniket Kumar Lata99546312018-03-19 21:38:38 -0700708 {TO_NAME_INDEX(USECASE_AUDIO_A2DP_ABR_FEEDBACK)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700709};
710
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800711static const struct name_to_index usecase_type_index[USECASE_TYPE_MAX] = {
712 {TO_NAME_INDEX(PCM_PLAYBACK)},
713 {TO_NAME_INDEX(PCM_CAPTURE)},
714 {TO_NAME_INDEX(VOICE_CALL)},
715 {TO_NAME_INDEX(PCM_HFP_CALL)},
716};
717
718struct app_type_entry {
719 int uc_type;
720 int bit_width;
721 int app_type;
722 int max_rate;
vivek mehtaa68fea62017-06-08 19:04:02 -0700723 char *mode;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800724 struct listnode node; // membership in app_type_entry_list;
725};
726
727static struct listnode app_type_entry_list;
728
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700729#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
730#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
Eric Laurent0e46adf2016-12-16 12:49:24 -0800731#define ULL_PLATFORM_DELAY (3*1000LL)
732#define MMAP_PLATFORM_DELAY (3*1000LL)
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700733
Eric Laurentb23d5282013-05-14 15:27:20 -0700734static pthread_once_t check_op_once_ctl = PTHREAD_ONCE_INIT;
735static bool is_tmus = false;
736
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800737static int init_be_dai_name_table(struct audio_device *adev);
738
Eric Laurentb23d5282013-05-14 15:27:20 -0700739static void check_operator()
740{
741 char value[PROPERTY_VALUE_MAX];
742 int mccmnc;
743 property_get("gsm.sim.operator.numeric",value,"0");
744 mccmnc = atoi(value);
Eric Laurent2bafff12016-03-17 12:17:23 -0700745 ALOGD("%s: tmus mccmnc %d", __func__, mccmnc);
Eric Laurentb23d5282013-05-14 15:27:20 -0700746 switch(mccmnc) {
747 /* TMUS MCC(310), MNC(490, 260, 026) */
748 case 310490:
749 case 310260:
750 case 310026:
sangwon.jeonb891db52013-09-14 17:39:15 +0900751 /* Add new TMUS MNC(800, 660, 580, 310, 270, 250, 240, 230, 220, 210, 200, 160) */
752 case 310800:
753 case 310660:
754 case 310580:
755 case 310310:
756 case 310270:
757 case 310250:
758 case 310240:
759 case 310230:
760 case 310220:
761 case 310210:
762 case 310200:
763 case 310160:
Eric Laurentb23d5282013-05-14 15:27:20 -0700764 is_tmus = true;
765 break;
766 }
767}
768
769bool is_operator_tmus()
770{
771 pthread_once(&check_op_once_ctl, check_operator);
772 return is_tmus;
773}
774
keunhui.park2f7306a2015-07-16 16:48:06 +0900775static char *get_current_operator()
776{
777 struct listnode *node;
778 struct operator_info *info_item;
779 char mccmnc[PROPERTY_VALUE_MAX];
780 char *ret = NULL;
781
Tom Cherry7fea2042016-11-10 18:05:59 -0800782 property_get("gsm.sim.operator.numeric",mccmnc,"00000");
keunhui.park2f7306a2015-07-16 16:48:06 +0900783
784 list_for_each(node, &operator_info_list) {
785 info_item = node_to_item(node, struct operator_info, list);
786 if (strstr(info_item->mccmnc, mccmnc) != NULL) {
787 ret = info_item->name;
788 }
789 }
790
791 return ret;
792}
793
794static struct operator_specific_device *get_operator_specific_device(snd_device_t snd_device)
795{
796 struct listnode *node;
797 struct operator_specific_device *ret = NULL;
798 struct operator_specific_device *device_item;
799 char *operator_name;
800
801 operator_name = get_current_operator();
802 if (operator_name == NULL)
803 return ret;
804
805 list_for_each(node, operator_specific_device_table[snd_device]) {
806 device_item = node_to_item(node, struct operator_specific_device, list);
807 if (strcmp(operator_name, device_item->operator) == 0) {
808 ret = device_item;
809 }
810 }
811
812 return ret;
813}
814
815
816static int get_operator_specific_device_acdb_id(snd_device_t snd_device)
817{
818 struct operator_specific_device *device;
819 int ret = acdb_device_table[snd_device];
820
821 device = get_operator_specific_device(snd_device);
822 if (device != NULL)
823 ret = device->acdb_id;
824
825 return ret;
826}
827
828static const char *get_operator_specific_device_mixer_path(snd_device_t snd_device)
829{
830 struct operator_specific_device *device;
831 const char *ret = device_table[snd_device];
832
833 device = get_operator_specific_device(snd_device);
834 if (device != NULL)
835 ret = device->mixer_path;
836
837 return ret;
838}
839
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800840inline bool platform_supports_app_type_cfg()
841{
Thierry Strudel07f96d12018-09-20 13:31:34 -0700842#if defined (PLATFORM_MSM8998) || (PLATFORM_SDM845) || (PLATFORM_SDM710) || (PLATFORM_SM8150)
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800843 return true;
844#else
845 return false;
846#endif
847}
848
jasmine chac89321b2018-04-10 21:37:01 +0800849static int parse_audiocal_cfg(struct str_parms *parms, acdb_audio_cal_cfg_t *cal)
850{
851 int err;
852 char value[64];
853 int ret = 0;
854
855 if (parms == NULL || cal == NULL)
856 return ret;
857
858 err = str_parms_get_str(parms, "cal_persist", value, sizeof(value));
859 if (err >= 0) {
860 str_parms_del(parms, "cal_persist");
861 cal->persist = (uint32_t)strtoul(value, NULL, 0);
862 ret = ret | 0x1;
863 }
864 err = str_parms_get_str(parms, "cal_apptype", value, sizeof(value));
865 if (err >= 0) {
866 str_parms_del(parms, "cal_apptype");
867 cal->app_type = (uint32_t)strtoul(value, NULL, 0);
868 ret = ret | 0x2;
869 }
870 err = str_parms_get_str(parms, "cal_caltype", value, sizeof(value));
871 if (err >= 0) {
872 str_parms_del(parms, "cal_caltype");
873 cal->cal_type = (uint32_t)strtoul(value, NULL, 0);
874 ret = ret | 0x4;
875 }
876 err = str_parms_get_str(parms, "cal_samplerate", value, sizeof(value));
877 if (err >= 0) {
878 str_parms_del(parms, "cal_samplerate");
879 cal->sampling_rate = (uint32_t)strtoul(value, NULL, 0);
880 ret = ret | 0x8;
881 }
882 err = str_parms_get_str(parms, "cal_devid", value, sizeof(value));
883 if (err >= 0) {
884 str_parms_del(parms, "cal_devid");
885 cal->dev_id = (uint32_t)strtoul(value, NULL, 0);
886 ret = ret | 0x10;
887 }
888 err = str_parms_get_str(parms, "cal_snddevid", value, sizeof(value));
889 if (err >= 0) {
890 str_parms_del(parms, "cal_snddevid");
891 cal->snd_dev_id = (uint32_t)strtoul(value, NULL, 0);
892 ret = ret | 0x20;
893 }
894 err = str_parms_get_str(parms, "cal_topoid", value, sizeof(value));
895 if (err >= 0) {
896 str_parms_del(parms, "cal_topoid");
897 cal->topo_id = (uint32_t)strtoul(value, NULL, 0);
898 ret = ret | 0x40;
899 }
900 err = str_parms_get_str(parms, "cal_moduleid", value, sizeof(value));
901 if (err >= 0) {
902 str_parms_del(parms, "cal_moduleid");
903 cal->module_id = (uint32_t)strtoul(value, NULL, 0);
904 ret = ret | 0x80;
905 }
906 err = str_parms_get_str(parms, "cal_paramid", value, sizeof(value));
907 if (err >= 0) {
908 str_parms_del(parms, "cal_paramid");
909 cal->param_id = (uint32_t)strtoul(value, NULL, 0);
910 ret = ret | 0x100;
911 }
912 return ret;
913}
914
915static void set_audiocal(void *platform, struct str_parms *parms, char *value, int len)
916{
917 struct platform_data *my_data = (struct platform_data *)platform;
918 acdb_audio_cal_cfg_t cal;
919 uint8_t *dptr = NULL;
920 int32_t dlen = 0;
921 int err ,ret;
922
923 if (value == NULL || platform == NULL || parms == NULL) {
924 ALOGE("[%s] received null pointer, failed", __func__);
925 goto done_key_audcal;
926 }
927
928 memset(&cal, 0, sizeof(acdb_audio_cal_cfg_t));
929 /* parse audio calibration keys */
930 ret = parse_audiocal_cfg(parms, &cal);
931
932 /* handle audio calibration data now */
933 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_AUD_CALDATA, value, len);
934 if (err >= 0) {
935 str_parms_del(parms, AUDIO_PARAMETER_KEY_AUD_CALDATA);
936 dlen = strlen(value);
937 if (dlen <= 0) {
938 ALOGE("[%s] null data received", __func__);
939 goto done_key_audcal;
940 }
941 /*
942 The base64 encoded string is always larger than the binary data,
943 so b64_pton will always output less data than provided (around 1/3
944 less than the input data). That's why we can allocate input buffer
945 length and then get function work.
946 */
947 dptr = (uint8_t *)calloc(dlen, sizeof(uint8_t));
948 if (dptr == NULL) {
949 ALOGE("[%s] memory allocation failed for %d", __func__, dlen);
950 goto done_key_audcal;
951 }
952 dlen = b64_pton(value, dptr, dlen);
953 if (dlen <= 0) {
954 ALOGE("[%s] data decoding failed %d", __func__, dlen);
955 goto done_key_audcal;
956 }
957
958 if (cal.dev_id) {
959 if (audio_is_input_device(cal.dev_id)) {
Eric Laurentd1b7a9b2018-11-15 12:24:31 -0800960 // FIXME: why pass an input device whereas
961 // platform_get_input_snd_device() expects as an output device?
962 cal.snd_dev_id = platform_get_input_snd_device(platform, NULL, cal.dev_id);
jasmine chac89321b2018-04-10 21:37:01 +0800963 } else {
964 cal.snd_dev_id = platform_get_output_snd_device(platform, cal.dev_id);
965 }
966 }
967 cal.acdb_dev_id = platform_get_snd_device_acdb_id(cal.snd_dev_id);
968 ALOGD("Setting audio calibration for snd_device(%d) acdb_id(%d)",
969 cal.snd_dev_id, cal.acdb_dev_id);
970 if (cal.acdb_dev_id == -EINVAL) {
971 ALOGE("[%s] Invalid acdb_device id %d for snd device id %d",
972 __func__, cal.acdb_dev_id, cal.snd_dev_id);
973 goto done_key_audcal;
974 }
975 if (my_data->acdb_set_audio_cal) {
976 ret = my_data->acdb_set_audio_cal((void *)&cal, (void *)dptr, dlen);
977 }
978 }
979done_key_audcal:
980 if (dptr != NULL)
981 free(dptr);
982}
983
vivek mehta1a9b7c02015-06-25 11:49:38 -0700984bool platform_send_gain_dep_cal(void *platform, int level)
985{
986 bool ret_val = false;
987 struct platform_data *my_data = (struct platform_data *)platform;
988 struct audio_device *adev = my_data->adev;
989 int acdb_dev_id, app_type;
990 int acdb_dev_type = MSM_SNDDEV_CAP_RX;
991 int mode = CAL_MODE_RTAC;
992 struct listnode *node;
993 struct audio_usecase *usecase;
Haynes Mathew George67486e22017-06-26 12:58:38 -0700994 bool valid_uc_type;
995 bool valid_dev;
vivek mehta1a9b7c02015-06-25 11:49:38 -0700996
997 if (my_data->acdb_send_gain_dep_cal == NULL) {
998 ALOGE("%s: dlsym error for acdb_send_gain_dep_cal", __func__);
999 return ret_val;
1000 }
1001
1002 if (!voice_is_in_call(adev)) {
1003 ALOGV("%s: Not Voice call usecase, apply new cal for level %d",
1004 __func__, level);
vivek mehta1a9b7c02015-06-25 11:49:38 -07001005
1006 // find the current active sound device
1007 list_for_each(node, &adev->usecase_list) {
1008 usecase = node_to_item(node, struct audio_usecase, list);
Haynes Mathew George67486e22017-06-26 12:58:38 -07001009 LOG_ALWAYS_FATAL_IF(usecase == NULL,
1010 "unxpected NULL usecase in usecase_list");
1011 valid_uc_type = usecase->type == PCM_PLAYBACK;
1012 valid_dev = false;
1013 if (valid_uc_type) {
1014 audio_devices_t dev = usecase->stream.out->devices;
1015 valid_dev = (dev == AUDIO_DEVICE_OUT_SPEAKER ||
vivek mehta40125092017-08-21 18:48:51 -07001016 dev == AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Haynes Mathew George67486e22017-06-26 12:58:38 -07001017 dev == AUDIO_DEVICE_OUT_WIRED_HEADSET ||
1018 dev == AUDIO_DEVICE_OUT_WIRED_HEADPHONE);
1019 }
1020 if (valid_dev) {
vivek mehta40125092017-08-21 18:48:51 -07001021 ALOGV("%s: out device is %d", __func__, usecase->out_snd_device);
1022 if (platform_supports_app_type_cfg())
1023 app_type = usecase->stream.out->app_type_cfg.app_type;
1024 else
1025 app_type = DEFAULT_APP_TYPE_RX_PATH;
vivek mehta4cb82982015-07-13 12:05:49 -07001026
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07001027 acdb_dev_id = platform_get_snd_device_acdb_id(usecase->out_snd_device);
vivek mehta40125092017-08-21 18:48:51 -07001028
1029 if (!my_data->acdb_send_gain_dep_cal(acdb_dev_id, app_type,
vivek mehta1a9b7c02015-06-25 11:49:38 -07001030 acdb_dev_type, mode, level)) {
1031 // set ret_val true if at least one calibration is set successfully
1032 ret_val = true;
1033 } else {
1034 ALOGE("%s: my_data->acdb_send_gain_dep_cal failed ", __func__);
1035 }
1036 } else {
1037 ALOGW("%s: Usecase list is empty", __func__);
1038 }
1039 }
1040 } else {
1041 ALOGW("%s: Voice call in progress .. ignore setting new cal",
1042 __func__);
1043 }
1044 return ret_val;
1045}
1046
Eric Laurentcefbbac2014-09-04 13:54:10 -05001047void platform_set_echo_reference(struct audio_device *adev, bool enable, audio_devices_t out_device)
Eric Laurentb23d5282013-05-14 15:27:20 -07001048{
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08001049 struct platform_data *my_data = (struct platform_data *)adev->platform;
Eric Laurentcefbbac2014-09-04 13:54:10 -05001050 snd_device_t snd_device = SND_DEVICE_NONE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001051
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08001052 if (strcmp(my_data->ec_ref_mixer_path, "")) {
1053 ALOGV("%s: diabling %s", __func__, my_data->ec_ref_mixer_path);
1054 audio_route_reset_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
Eric Laurentcefbbac2014-09-04 13:54:10 -05001055 }
1056
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08001057 if (enable) {
1058 strcpy(my_data->ec_ref_mixer_path, "echo-reference");
1059 if (out_device != AUDIO_DEVICE_NONE) {
1060 snd_device = platform_get_output_snd_device(adev->platform, out_device);
1061 platform_add_backend_name(adev->platform, my_data->ec_ref_mixer_path, snd_device);
1062 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05001063
Joe Onorato188b6222016-03-01 11:02:27 -08001064 ALOGV("%s: enabling %s", __func__, my_data->ec_ref_mixer_path);
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08001065 audio_route_apply_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
1066 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001067}
1068
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001069static struct csd_data *open_csd_client(bool i2s_ext_modem)
1070{
1071 struct csd_data *csd = calloc(1, sizeof(struct csd_data));
1072
1073 csd->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
1074 if (csd->csd_client == NULL) {
1075 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
1076 goto error;
1077 } else {
1078 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
1079
1080 csd->deinit = (deinit_t)dlsym(csd->csd_client,
1081 "csd_client_deinit");
1082 if (csd->deinit == NULL) {
1083 ALOGE("%s: dlsym error %s for csd_client_deinit", __func__,
1084 dlerror());
1085 goto error;
1086 }
1087 csd->disable_device = (disable_device_t)dlsym(csd->csd_client,
1088 "csd_client_disable_device");
1089 if (csd->disable_device == NULL) {
1090 ALOGE("%s: dlsym error %s for csd_client_disable_device",
1091 __func__, dlerror());
1092 goto error;
1093 }
1094 csd->enable_device_config = (enable_device_config_t)dlsym(csd->csd_client,
1095 "csd_client_enable_device_config");
1096 if (csd->enable_device_config == NULL) {
1097 ALOGE("%s: dlsym error %s for csd_client_enable_device_config",
1098 __func__, dlerror());
1099 goto error;
1100 }
1101 csd->enable_device = (enable_device_t)dlsym(csd->csd_client,
1102 "csd_client_enable_device");
1103 if (csd->enable_device == NULL) {
1104 ALOGE("%s: dlsym error %s for csd_client_enable_device",
1105 __func__, dlerror());
1106 goto error;
1107 }
1108 csd->start_voice = (start_voice_t)dlsym(csd->csd_client,
1109 "csd_client_start_voice");
1110 if (csd->start_voice == NULL) {
1111 ALOGE("%s: dlsym error %s for csd_client_start_voice",
1112 __func__, dlerror());
1113 goto error;
1114 }
1115 csd->stop_voice = (stop_voice_t)dlsym(csd->csd_client,
1116 "csd_client_stop_voice");
1117 if (csd->stop_voice == NULL) {
1118 ALOGE("%s: dlsym error %s for csd_client_stop_voice",
1119 __func__, dlerror());
1120 goto error;
1121 }
1122 csd->volume = (volume_t)dlsym(csd->csd_client,
1123 "csd_client_volume");
1124 if (csd->volume == NULL) {
1125 ALOGE("%s: dlsym error %s for csd_client_volume",
1126 __func__, dlerror());
1127 goto error;
1128 }
1129 csd->mic_mute = (mic_mute_t)dlsym(csd->csd_client,
1130 "csd_client_mic_mute");
1131 if (csd->mic_mute == NULL) {
1132 ALOGE("%s: dlsym error %s for csd_client_mic_mute",
1133 __func__, dlerror());
1134 goto error;
1135 }
1136 csd->slow_talk = (slow_talk_t)dlsym(csd->csd_client,
1137 "csd_client_slow_talk");
1138 if (csd->slow_talk == NULL) {
1139 ALOGE("%s: dlsym error %s for csd_client_slow_talk",
1140 __func__, dlerror());
1141 goto error;
1142 }
1143 csd->start_playback = (start_playback_t)dlsym(csd->csd_client,
1144 "csd_client_start_playback");
1145 if (csd->start_playback == NULL) {
1146 ALOGE("%s: dlsym error %s for csd_client_start_playback",
1147 __func__, dlerror());
1148 goto error;
1149 }
1150 csd->stop_playback = (stop_playback_t)dlsym(csd->csd_client,
1151 "csd_client_stop_playback");
1152 if (csd->stop_playback == NULL) {
1153 ALOGE("%s: dlsym error %s for csd_client_stop_playback",
1154 __func__, dlerror());
1155 goto error;
1156 }
1157 csd->start_record = (start_record_t)dlsym(csd->csd_client,
1158 "csd_client_start_record");
1159 if (csd->start_record == NULL) {
1160 ALOGE("%s: dlsym error %s for csd_client_start_record",
1161 __func__, dlerror());
1162 goto error;
1163 }
1164 csd->stop_record = (stop_record_t)dlsym(csd->csd_client,
1165 "csd_client_stop_record");
1166 if (csd->stop_record == NULL) {
1167 ALOGE("%s: dlsym error %s for csd_client_stop_record",
1168 __func__, dlerror());
1169 goto error;
1170 }
1171
1172 csd->get_sample_rate = (get_sample_rate_t)dlsym(csd->csd_client,
1173 "csd_client_get_sample_rate");
1174 if (csd->get_sample_rate == NULL) {
1175 ALOGE("%s: dlsym error %s for csd_client_get_sample_rate",
1176 __func__, dlerror());
1177
1178 goto error;
1179 }
1180
1181 csd->init = (init_t)dlsym(csd->csd_client, "csd_client_init");
1182
1183 if (csd->init == NULL) {
1184 ALOGE("%s: dlsym error %s for csd_client_init",
1185 __func__, dlerror());
1186 goto error;
1187 } else {
1188 csd->init(i2s_ext_modem);
1189 }
1190 }
1191 return csd;
1192
1193error:
1194 free(csd);
1195 csd = NULL;
1196 return csd;
1197}
1198
1199void close_csd_client(struct csd_data *csd)
1200{
1201 if (csd != NULL) {
1202 csd->deinit();
1203 dlclose(csd->csd_client);
1204 free(csd);
1205 csd = NULL;
1206 }
1207}
1208
1209static void platform_csd_init(struct platform_data *my_data)
1210{
1211#ifdef PLATFORM_MSM8084
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001212 int32_t modems, (*count_modems)(void);
1213 const char *name = "libdetectmodem.so";
1214 const char *func = "count_modems";
1215 const char *error;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001216
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001217 my_data->csd = NULL;
1218
1219 void *lib = dlopen(name, RTLD_NOW);
1220 error = dlerror();
1221 if (!lib) {
1222 ALOGE("%s: could not find %s: %s", __func__, name, error);
1223 return;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001224 }
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001225
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001226 count_modems = NULL;
1227 *(void **)(&count_modems) = dlsym(lib, func);
1228 error = dlerror();
1229 if (!count_modems) {
1230 ALOGE("%s: could not find symbol %s in %s: %s",
1231 __func__, func, name, error);
1232 goto done;
1233 }
1234
1235 modems = count_modems();
1236 if (modems < 0) {
1237 ALOGE("%s: count_modems failed\n", __func__);
1238 goto done;
1239 }
1240
Eric Laurent2bafff12016-03-17 12:17:23 -07001241 ALOGD("%s: num_modems %d\n", __func__, modems);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001242 if (modems > 0)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001243 my_data->csd = open_csd_client(false /*is_i2s_ext_modem*/);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001244
1245done:
1246 dlclose(lib);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001247#else
1248 my_data->csd = NULL;
1249#endif
1250}
1251
Eric Laurentc6333382015-09-14 12:43:44 -07001252static void set_platform_defaults(struct platform_data * my_data)
Haynes Mathew George98c95622014-06-20 19:14:25 -07001253{
1254 int32_t dev;
1255 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001256 backend_tag_table[dev] = NULL;
1257 hw_interface_table[dev] = NULL;
keunhui.park2f7306a2015-07-16 16:48:06 +09001258 operator_specific_device_table[dev] = NULL;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001259 }
1260
David Linee3fe402017-03-13 10:00:42 -07001261 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1262 backend_bit_width_table[dev] = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
1263 }
1264
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001265 // To overwrite these go to the audio_platform_info.xml file.
1266 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("bt-sco");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07001267 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("bt-sco");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001268 backend_tag_table[SND_DEVICE_OUT_BT_SCO] = strdup("bt-sco");
1269 backend_tag_table[SND_DEVICE_OUT_HDMI] = strdup("hdmi");
1270 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("speaker-and-hdmi");
1271 backend_tag_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("bt-sco-wb");
1272 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("bt-sco-wb");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07001273 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("bt-sco-wb");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001274 backend_tag_table[SND_DEVICE_OUT_VOICE_TX] = strdup("afe-proxy");
1275 backend_tag_table[SND_DEVICE_IN_VOICE_RX] = strdup("afe-proxy");
Haynes Mathew George98c95622014-06-20 19:14:25 -07001276
David Linee3fe402017-03-13 10:00:42 -07001277 backend_tag_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("usb-headset");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001278 backend_tag_table[SND_DEVICE_OUT_VOICE_USB_HEADSET] = strdup("usb-headset");
David Linee3fe402017-03-13 10:00:42 -07001279 backend_tag_table[SND_DEVICE_OUT_USB_HEADPHONES] = strdup("usb-headphones");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001280 backend_tag_table[SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = strdup("usb-headphones");
David Linee3fe402017-03-13 10:00:42 -07001281 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] =
1282 strdup("speaker-and-usb-headphones");
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07001283 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] =
1284 strdup("speaker-safe-and-usb-headphones");
juyuchen5351ea62018-05-16 10:54:37 +08001285 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO] =
1286 strdup("speaker-safe-and-bt-sco"),
1287 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB] =
1288 strdup("speaker-safe-and-bt-sco-wb"),
David Linee3fe402017-03-13 10:00:42 -07001289 backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("usb-headset-mic");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001290 backend_tag_table[SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1291 backend_tag_table[SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1292 backend_tag_table[SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1293 backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = strdup("usb-headset-mic");
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001294 backend_tag_table[SND_DEVICE_OUT_BT_A2DP] = strdup("bt-a2dp");
1295 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] = strdup("speaker-and-bt-a2dp");
Aniket Kumar Lata9723a962018-05-16 17:41:55 -07001296 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP] = strdup("speaker-safe-and-bt-a2dp");
jasmine cha270b7762018-03-30 15:41:33 +08001297 backend_tag_table[SND_DEVICE_OUT_USB_HEADSET_SPEC] = strdup("usb-headset");
juyuchend194b432018-11-16 14:15:16 +08001298 backend_tag_table[SND_DEVICE_OUT_VOICE_HEARING_AID] = strdup("hearing-aid");
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001299
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001300 hw_interface_table[SND_DEVICE_OUT_HANDSET] = strdup("SLIMBUS_0_RX");
1301 hw_interface_table[SND_DEVICE_OUT_SPEAKER] = strdup("SLIMBUS_0_RX");
1302 hw_interface_table[SND_DEVICE_OUT_SPEAKER_REVERSE] = strdup("SLIMBUS_0_RX");
1303 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE] = strdup("SLIMBUS_0_RX");
1304 hw_interface_table[SND_DEVICE_OUT_HEADPHONES] = strdup("SLIMBUS_0_RX");
1305 hw_interface_table[SND_DEVICE_OUT_LINE] = strdup("SLIMBUS_0_RX");
1306 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001307 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001308 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001309 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001310 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET] = strdup("SLIMBUS_0_RX");
1311 hw_interface_table[SND_DEVICE_OUT_VOICE_HAC_HANDSET] = strdup("SLIMBUS_0_RX");
1312 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER] = strdup("SLIMBUS_0_RX");
1313 hw_interface_table[SND_DEVICE_OUT_VOICE_HEADPHONES] = strdup("SLIMBUS_0_RX");
yixuanjiang9536e672018-09-06 18:43:36 +08001314 hw_interface_table[SND_DEVICE_OUT_VOICE_HEADSET] = strdup("SLIMBUS_0_RX");
juyuchen66c4ecf2018-08-06 15:39:34 +08001315 hw_interface_table[SND_DEVICE_OUT_VOICE_MUSIC_TX] = strdup("VOICE_PLAYBACK_TX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001316 hw_interface_table[SND_DEVICE_OUT_VOICE_LINE] = strdup("SLIMBUS_0_RX");
1317 hw_interface_table[SND_DEVICE_OUT_HDMI] = strdup("HDMI_RX");
1318 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("SLIMBUS_0_RX-and-HDMI_RX");
1319 hw_interface_table[SND_DEVICE_OUT_BT_SCO] = strdup("SEC_AUX_PCM_RX");
1320 hw_interface_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("SEC_AUX_PCM_RX");
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001321 hw_interface_table[SND_DEVICE_OUT_BT_A2DP] = strdup("SLIMBUS_7_RX");
1322 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] =
1323 strdup("SLIMBUS_0_RX-and-SLIMBUS_7_RX");
Aniket Kumar Lata9723a962018-05-16 17:41:55 -07001324 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP] =
1325 strdup("SLIMBUS_0_RX-and-SLIMBUS_7_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001326 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = strdup("SLIMBUS_0_RX");
1327 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = strdup("SLIMBUS_0_RX");
1328 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = strdup("SLIMBUS_0_RX");
1329 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = strdup("SLIMBUS_0_RX");
David Linee3fe402017-03-13 10:00:42 -07001330 hw_interface_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("USB_AUDIO_RX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001331 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = strdup("USB_AUDIO_RX");
1332 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = strdup("USB_AUDIO_RX");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001333 hw_interface_table[SND_DEVICE_OUT_VOICE_USB_HEADSET] = strdup("USB_AUDIO_RX");
David Linee3fe402017-03-13 10:00:42 -07001334 hw_interface_table[SND_DEVICE_OUT_USB_HEADPHONES] = strdup("USB_AUDIO_RX");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001335 hw_interface_table[SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = strdup("USB_AUDIO_RX");
jasmine cha270b7762018-03-30 15:41:33 +08001336 hw_interface_table[SND_DEVICE_OUT_USB_HEADSET_SPEC] = strdup("USB_AUDIO_RX");
David Linee3fe402017-03-13 10:00:42 -07001337 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 -07001338 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 -07001339 hw_interface_table[SND_DEVICE_OUT_VOICE_TX] = strdup("AFE_PCM_RX");
1340 hw_interface_table[SND_DEVICE_OUT_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
1341 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
jasmine cha52284622018-03-23 17:21:35 +08001342 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = strdup("SLIMBUS_0_RX");
1343 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_BT_SCO] = strdup("SLIMBUS_0_RX-and-SEC_AUX_PCM_RX");
1344 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 +08001345 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO] = strdup("QUAT_TDM_RX_0-and-SLIMBUS_7_RX"),
1346 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB] = strdup("QUAT_TDM_RX_0-and-SLIMBUS_7_RX"),
juyuchend194b432018-11-16 14:15:16 +08001347 /* So far, primary hal doesn't support hearing aid device.
1348 Need snd_device to route voice call and use specific acdb tuning.
1349 Also, BT_RX is a virtual port to indicate bluetooth hearing aid. */
1350 hw_interface_table[SND_DEVICE_OUT_VOICE_HEARING_AID] = strdup("BT_RX"),
1351
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001352 hw_interface_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1353 hw_interface_table[SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1354 hw_interface_table[SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = strdup("USB_AUDIO_TX");
1355 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1356 hw_interface_table[SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1357 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = strdup("USB_AUDIO_TX");
1358 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = strdup("USB_AUDIO_TX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001359 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001360 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_AEC] = strdup("SLIMBUS_0_TX");
1361 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_NS] = strdup("SLIMBUS_0_TX");
1362 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1363 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC] = strdup("SLIMBUS_0_TX");
1364 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_AEC] = strdup("SLIMBUS_0_TX");
1365 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_NS] = strdup("SLIMBUS_0_TX");
1366 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1367 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001368 hw_interface_table[SND_DEVICE_IN_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001369 hw_interface_table[SND_DEVICE_IN_HEADSET_MIC_AEC] = strdup("SLIMBUS_0_TX");
Eric Laurent5f4ca952018-10-19 17:33:43 -07001370 hw_interface_table[SND_DEVICE_IN_CAMCORDER_LANDSCAPE] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001371 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC] = strdup("SLIMBUS_0_TX");
1372 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC_NS] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001373 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC_AEC] = strdup("SLIMBUS_0_TX");
1374 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001375 hw_interface_table[SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
1376 hw_interface_table[SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = strdup("SLIMBUS_0_TX");
David Lin93725722017-10-13 14:58:17 -07001377 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_MIC] = strdup("SLIMBUS_0_TX");
1378 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1379 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = strdup("SLIMBUS_0_TX");
1380 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = strdup("SLIMBUS_0_TX");
1381 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001382 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC] = strdup("SLIMBUS_0_TX");
1383 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_AEC] = strdup("SLIMBUS_0_TX");
1384 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_NS] = strdup("SLIMBUS_0_TX");
1385 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1386 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC] = strdup("SLIMBUS_0_TX");
1387 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_AEC] = strdup("SLIMBUS_0_TX");
1388 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_NS] = strdup("SLIMBUS_0_TX");
1389 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001390 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
1391 hw_interface_table[SND_DEVICE_IN_VOICE_DMIC] = strdup("SLIMBUS_0_TX");
1392 hw_interface_table[SND_DEVICE_IN_VOICE_DMIC_TMUS] = strdup("SLIMBUS_0_TX");
Vignesh Kulothungan64698822018-01-23 11:25:18 -08001393 hw_interface_table[SND_DEVICE_IN_SPEAKER_QMIC_NS] = strdup("SLIMBUS_0_TX");
1394 hw_interface_table[SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001395 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001396 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = strdup("SLIMBUS_0_TX");
1397 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001398 hw_interface_table[SND_DEVICE_IN_VOICE_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001399 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1400 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = strdup("SLIMBUS_0_TX");
1401 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1402 hw_interface_table[SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1403 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("SEC_AUX_PCM_TX");
1404 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("SEC_AUX_PCM_TX");
1405 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("SEC_AUX_PCM_TX");
1406 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("SEC_AUX_PCM_TX");
1407 hw_interface_table[SND_DEVICE_IN_VOICE_RX] = strdup("AFE_PCM_TX");
1408 hw_interface_table[SND_DEVICE_IN_THREE_MIC] = strdup("SLIMBUS_0_TX");
1409 hw_interface_table[SND_DEVICE_IN_QUAD_MIC] = strdup("SLIMBUS_0_TX");
1410 hw_interface_table[SND_DEVICE_IN_HANDSET_TMIC] = strdup("SLIMBUS_0_TX");
1411 hw_interface_table[SND_DEVICE_IN_HANDSET_QMIC] = strdup("SLIMBUS_0_TX");
1412 hw_interface_table[SND_DEVICE_IN_HANDSET_TMIC_AEC] = strdup("SLIMBUS_0_TX");
1413 hw_interface_table[SND_DEVICE_IN_HANDSET_QMIC_AEC] = strdup("SLIMBUS_0_TX");
Eric Laurent5f4ca952018-10-19 17:33:43 -07001414 hw_interface_table[SND_DEVICE_IN_CAMCORDER_INVERT_LANDSCAPE] = strdup("SLIMBUS_0_TX");
1415 hw_interface_table[SND_DEVICE_IN_CAMCORDER_PORTRAIT] = strdup("SLIMBUS_0_TX");
1416 hw_interface_table[SND_DEVICE_IN_CAMCORDER_SELFIE_LANDSCAPE] = strdup("SLIMBUS_0_TX");
1417 hw_interface_table[SND_DEVICE_IN_CAMCORDER_SELFIE_INVERT_LANDSCAPE] = strdup("SLIMBUS_0_TX");
1418 hw_interface_table[SND_DEVICE_IN_CAMCORDER_SELFIE_PORTRAIT] = strdup("SLIMBUS_0_TX");
juyuchend194b432018-11-16 14:15:16 +08001419 hw_interface_table[SND_DEVICE_IN_VOICE_HEARING_AID] = strdup("SLIMBUS_0_TX");
1420
Eric Laurentc6333382015-09-14 12:43:44 -07001421 my_data->max_mic_count = PLATFORM_DEFAULT_MIC_COUNT;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001422}
1423
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001424void get_cvd_version(char *cvd_version, struct audio_device *adev)
1425{
1426 struct mixer_ctl *ctl;
1427 int count;
1428 int ret = 0;
1429
1430 ctl = mixer_get_ctl_by_name(adev->mixer, CVD_VERSION_MIXER_CTL);
1431 if (!ctl) {
1432 ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__, CVD_VERSION_MIXER_CTL);
1433 goto done;
1434 }
1435 mixer_ctl_update(ctl);
1436
1437 count = mixer_ctl_get_num_values(ctl);
1438 if (count > MAX_CVD_VERSION_STRING_SIZE)
1439 count = MAX_CVD_VERSION_STRING_SIZE - 1;
1440
1441 ret = mixer_ctl_get_array(ctl, cvd_version, count);
1442 if (ret != 0) {
1443 ALOGE("%s: ERROR! mixer_ctl_get_array() failed to get CVD Version", __func__);
1444 goto done;
1445 }
1446
1447done:
1448 return;
1449}
1450
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001451static int platform_acdb_init(void *platform)
1452{
1453 struct platform_data *my_data = (struct platform_data *)platform;
1454 struct audio_device *adev = my_data->adev;
1455
1456 if (!my_data->acdb_init) {
1457 ALOGE("%s: no acdb_init fn provided", __func__);
1458 return -1;
1459 }
1460
1461 if (my_data->acdb_initialized) {
1462 ALOGW("acdb is already initialized");
1463 return 0;
1464 }
1465
Thierry Strudel07f96d12018-09-20 13:31:34 -07001466#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845) || (PLATFORM_SDM710) || (PLATFORM_SM8150)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001467 char *cvd_version = calloc(1, MAX_CVD_VERSION_STRING_SIZE);
1468 if (!cvd_version)
1469 ALOGE("failed to allocate cvd_version");
1470 else {
1471 get_cvd_version(cvd_version, adev);
1472 my_data->acdb_init((char *)my_data->snd_card_name, cvd_version, 0);
1473 free(cvd_version);
1474 }
1475#elif defined (PLATFORM_MSM8084)
1476 my_data->acdb_init((char *)my_data->snd_card_name);
1477#else
1478 my_data->acdb_init();
1479#endif
1480 my_data->acdb_initialized = true;
1481 return 0;
1482}
1483
David Linee3fe402017-03-13 10:00:42 -07001484static void
1485platform_backend_config_init(struct platform_data *pdata)
1486{
1487 int i;
1488
1489 /* initialize backend config */
1490 for (i = 0; i < MAX_CODEC_BACKENDS; i++) {
1491 pdata->current_backend_cfg[i].sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
1492 pdata->current_backend_cfg[i].bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
1493 pdata->current_backend_cfg[i].channels = CODEC_BACKEND_DEFAULT_CHANNELS;
1494
1495 if (i > MAX_RX_CODEC_BACKENDS)
1496 pdata->current_backend_cfg[i].channels = CODEC_BACKEND_DEFAULT_TX_CHANNELS;
1497
1498 pdata->current_backend_cfg[i].bitwidth_mixer_ctl = NULL;
1499 pdata->current_backend_cfg[i].samplerate_mixer_ctl = NULL;
1500 pdata->current_backend_cfg[i].channels_mixer_ctl = NULL;
1501 }
1502
1503 pdata->current_backend_cfg[DEFAULT_CODEC_BACKEND].bitwidth_mixer_ctl =
1504 strdup("SLIM_0_RX Format");
1505 pdata->current_backend_cfg[DEFAULT_CODEC_BACKEND].samplerate_mixer_ctl =
1506 strdup("SLIM_0_RX SampleRate");
1507
1508 pdata->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].bitwidth_mixer_ctl =
1509 strdup("SLIM_0_TX Format");
1510 pdata->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].samplerate_mixer_ctl =
1511 strdup("SLIM_0_TX SampleRate");
1512
1513 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].bitwidth_mixer_ctl =
1514 strdup("USB_AUDIO_TX Format");
1515 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].samplerate_mixer_ctl =
1516 strdup("USB_AUDIO_TX SampleRate");
1517 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].channels_mixer_ctl =
1518 strdup("USB_AUDIO_TX Channels");
1519
Yung Ti Su39a2b8a2018-10-05 15:43:40 +08001520 if (strstr(pdata->snd_card_name, "intcodec")) {
1521 pdata->current_backend_cfg[HEADPHONE_BACKEND].bitwidth_mixer_ctl =
1522 strdup("INT0_MI2S_RX Format");
1523 pdata->current_backend_cfg[HEADPHONE_BACKEND].samplerate_mixer_ctl =
1524 strdup("INT0_MI2S_RX SampleRate");
1525 } else {
1526 pdata->current_backend_cfg[HEADPHONE_BACKEND].bitwidth_mixer_ctl =
1527 strdup("SLIM_6_RX Format");
1528 pdata->current_backend_cfg[HEADPHONE_BACKEND].samplerate_mixer_ctl =
1529 strdup("SLIM_6_RX SampleRate");
1530 }
David Linee3fe402017-03-13 10:00:42 -07001531
1532 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].bitwidth_mixer_ctl =
1533 strdup("USB_AUDIO_RX Format");
1534 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].samplerate_mixer_ctl =
1535 strdup("USB_AUDIO_RX SampleRate");
1536
1537 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].channels = 1;
1538 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].channels_mixer_ctl =
1539 strdup("USB_AUDIO_RX Channels");
1540}
1541
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001542static int
1543platform_backend_app_type_cfg_init(struct platform_data *pdata,
1544 struct mixer *mixer)
1545{
1546 size_t app_type_cfg[128] = {0};
1547 int length, num_app_types = 0;
1548 struct mixer_ctl *ctl = NULL;
1549
1550 const char *mixer_ctl_name = "App Type Config";
1551 ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name);
1552 if (!ctl) {
1553 ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name);
1554 return -1;
1555 }
1556
1557 length = 1; // reserve index 0 for number of app types
1558
1559 struct listnode *node;
1560 struct app_type_entry *entry;
1561 list_for_each(node, &app_type_entry_list) {
1562 entry = node_to_item(node, struct app_type_entry, node);
1563 app_type_cfg[length++] = entry->app_type;
1564 app_type_cfg[length++] = entry->max_rate;
1565 app_type_cfg[length++] = entry->bit_width;
1566 ALOGI("%s add entry %d %d", __func__, entry->app_type, entry->bit_width);
1567 num_app_types += 1;
1568 }
1569
1570 // default for capture
1571 int t;
1572 platform_get_default_app_type_v2(pdata,
1573 PCM_CAPTURE,
1574 &t);
1575 app_type_cfg[length++] = t;
1576 app_type_cfg[length++] = 48000;
1577 app_type_cfg[length++] = 16;
1578 num_app_types += 1;
1579
1580 if (num_app_types) {
1581 app_type_cfg[0] = num_app_types;
1582 if (mixer_ctl_set_array(ctl, app_type_cfg, length) < 0) {
1583 ALOGE("Failed to set app type cfg");
1584 }
1585 }
1586 return 0;
1587}
1588
Xu Han1638fd12018-04-20 12:42:23 -07001589static void configure_flicker_sensor_input(struct mixer *mixer)
1590{
1591 struct mixer_ctl *ctl;
1592 const char* ctl1 = "AIF3_CAP Mixer SLIM TX2";
1593 int setting1 = 1;
1594 const char* ctl2 = "CDC_IF TX2 MUX";
1595 const char* setting2 = "DEC2";
1596 const char* ctl3 = "SLIM_1_TX Channels";
1597 const char* setting3 = "One";
1598 const char* ctl4 = "ADC MUX2";
1599 const char* setting4 = "AMIC";
1600 const char* ctl5 = "AMIC MUX2";
1601 const char* setting5 = "ADC1";
1602 const char* ctl6 = "DEC2 Volume";
1603 int setting6 = 84;
Xu Han07e07402018-05-15 14:19:25 -07001604 const char* ctl7 = "MultiMedia9 Mixer SLIM_1_TX";
Xu Han1638fd12018-04-20 12:42:23 -07001605 int setting7 = 1;
1606 const char* ctl8 = "SLIM_1_TX SampleRate";
1607 const char* setting8 = "KHZ_8";
1608
1609 ctl = mixer_get_ctl_by_name(mixer, ctl1);
1610 mixer_ctl_set_value(ctl, 0, setting1);
1611 ctl = mixer_get_ctl_by_name(mixer, ctl2);
1612 mixer_ctl_set_enum_by_string(ctl, setting2);
1613 ctl = mixer_get_ctl_by_name(mixer, ctl3);
1614 mixer_ctl_set_enum_by_string(ctl, setting3);
1615 ctl = mixer_get_ctl_by_name(mixer, ctl4);
1616 mixer_ctl_set_enum_by_string(ctl, setting4);
1617 ctl = mixer_get_ctl_by_name(mixer, ctl5);
1618 mixer_ctl_set_enum_by_string(ctl, setting5);
1619 ctl = mixer_get_ctl_by_name(mixer, ctl6);
1620 mixer_ctl_set_value(ctl, 0, setting6);
1621 ctl = mixer_get_ctl_by_name(mixer, ctl7);
1622 mixer_ctl_set_value(ctl, 0, setting7);
1623 ctl = mixer_get_ctl_by_name(mixer, ctl8);
1624 mixer_ctl_set_enum_by_string(ctl, setting8);
1625}
1626
Eric Laurentb23d5282013-05-14 15:27:20 -07001627void *platform_init(struct audio_device *adev)
1628{
1629 char value[PROPERTY_VALUE_MAX];
vivek mehta60ea4152016-02-18 17:10:26 -08001630 struct platform_data *my_data = NULL;
1631 int retry_num = 0, snd_card_num = 0, key = 0, ret = 0;
1632 bool dual_mic_config = false, use_default_mixer_path = true;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001633 const char *snd_card_name;
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001634 char *cvd_version = NULL;
vivek mehta60ea4152016-02-18 17:10:26 -08001635 char *snd_internal_name = NULL;
1636 char *tmp = NULL;
1637 char mixer_xml_file[MIXER_PATH_MAX_LENGTH]= {0};
vivek mehtade4849c2016-03-03 17:23:38 -08001638 char platform_info_file[MIXER_PATH_MAX_LENGTH]= {0};
1639 struct snd_card_split *snd_split_handle = NULL;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001640 my_data = calloc(1, sizeof(struct platform_data));
1641
1642 my_data->adev = adev;
1643
keunhui.park2f7306a2015-07-16 16:48:06 +09001644 list_init(&operator_info_list);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001645 list_init(&app_type_entry_list);
keunhui.park2f7306a2015-07-16 16:48:06 +09001646
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001647 set_platform_defaults(my_data);
1648
vivek mehta0fb11312017-05-15 19:35:32 -07001649 // audio_extn_utils_get_snd_card_num does
1650 // - open mixer and get snd card name
1651 // - parse platform info xml file and check for valid snd card name
1652 // - on failure loop through all the active snd card
sangwoo1b9f4b32013-06-21 18:22:55 -07001653
vivek mehta0fb11312017-05-15 19:35:32 -07001654 snd_card_num = audio_extn_utils_get_snd_card_num();
1655 if (-1 == snd_card_num) {
1656 ALOGE("%s: invalid sound card number (-1), bailing out ", __func__);
1657 goto init_failed;
sangwoo1b9f4b32013-06-21 18:22:55 -07001658 }
1659
vivek mehta0fb11312017-05-15 19:35:32 -07001660 adev->mixer = mixer_open(snd_card_num);
1661 snd_card_name = mixer_get_name(adev->mixer);
1662 my_data->hw_info = hw_info_init(snd_card_name);
1663
1664 audio_extn_set_snd_card_split(snd_card_name);
1665 snd_split_handle = audio_extn_get_snd_card_split();
1666
1667 /* Get the codec internal name from the sound card and/or form factor
1668 * name and form the mixer paths and platfor info file name dynamically.
1669 * This is generic way of picking any codec and forma factor name based
1670 * mixer and platform info files in future with no code change.
1671
1672 * current code extends and looks for any of the exteneded mixer path and
1673 * platform info file present based on codec and form factor.
1674
1675 * order of picking appropriate file is
1676 * <i> mixer_paths_<codec_name>_<form_factor>.xml, if file not present
1677 * <ii> mixer_paths_<codec_name>.xml, if file not present
1678 * <iii> mixer_paths.xml
1679
1680 * same order is followed for audio_platform_info.xml as well
1681 */
1682
1683 // need to carryforward old file name
1684 if (!strncmp(snd_card_name, TOMTOM_8226_SND_CARD_NAME,
1685 min(strlen(TOMTOM_8226_SND_CARD_NAME), strlen(snd_card_name)))) {
1686 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1687 MIXER_XML_BASE_STRING, TOMTOM_MIXER_FILE_SUFFIX );
1688 } else {
1689
1690 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s_%s.xml",
1691 MIXER_XML_BASE_STRING, snd_split_handle->snd_card,
1692 snd_split_handle->form_factor);
1693 if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) {
1694 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1695 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1696 MIXER_XML_BASE_STRING, snd_split_handle->snd_card);
1697
1698 if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) {
1699 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1700 strlcpy(mixer_xml_file, MIXER_XML_DEFAULT_PATH, MIXER_PATH_MAX_LENGTH);
1701 audio_extn_utils_resolve_config_file(mixer_xml_file);
1702 }
1703 }
1704 }
1705
1706 audio_extn_utils_get_platform_info(snd_card_name, platform_info_file);
1707
jiabin8962a4d2018-03-19 18:21:24 -07001708 my_data->declared_mic_count = 0;
vivek mehta0fb11312017-05-15 19:35:32 -07001709 /* Initialize platform specific ids and/or backends*/
juyuchenbf6571f2018-11-30 18:50:47 +08001710 platform_info_init(platform_info_file, my_data,
1711 true, &platform_set_parameters);
vivek mehta0fb11312017-05-15 19:35:32 -07001712
1713 ALOGD("%s: Loading mixer file: %s", __func__, mixer_xml_file);
1714 adev->audio_route = audio_route_init(snd_card_num, mixer_xml_file);
1715
1716 if (!adev->audio_route) {
1717 ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
1718 mixer_close(adev->mixer);
1719 adev->mixer = NULL;
1720 hw_info_deinit(my_data->hw_info);
1721 my_data->hw_info = NULL;
1722 goto init_failed;
1723 }
1724 adev->snd_card = snd_card_num;
1725 ALOGD("%s: Opened sound card:%d", __func__, snd_card_num);
1726
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09001727 //set max volume step for voice call
1728 property_get("ro.config.vc_call_vol_steps", value, TOSTRING(MAX_VOL_INDEX));
1729 my_data->max_vol_index = atoi(value);
1730
vivek mehta65ad12d2015-08-13 18:32:48 -07001731 property_get("persist.audio.dualmic.config",value,"");
1732 if (!strcmp("endfire", value)) {
1733 dual_mic_config = true;
1734 }
1735
John Muir9e59a962018-01-10 13:30:00 -08001736 my_data->source_mic_type = 0;
Prashant Malanic92c5962015-08-11 15:10:18 -07001737
Eric Laurentb23d5282013-05-14 15:27:20 -07001738 my_data->fluence_in_spkr_mode = false;
1739 my_data->fluence_in_voice_call = false;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001740 my_data->fluence_in_voice_comm = false;
Eric Laurentb23d5282013-05-14 15:27:20 -07001741 my_data->fluence_in_voice_rec = false;
1742
vivek mehta65ad12d2015-08-13 18:32:48 -07001743 property_get("ro.qc.sdk.audio.fluencetype", value, "none");
Prashant Malanic92c5962015-08-11 15:10:18 -07001744 if (!strcmp("fluencepro", value)) {
1745 my_data->fluence_type = FLUENCE_PRO_ENABLE;
vivek mehta65ad12d2015-08-13 18:32:48 -07001746 } else if (!strcmp("fluence", value) || (dual_mic_config)) {
Prashant Malanic92c5962015-08-11 15:10:18 -07001747 my_data->fluence_type = FLUENCE_ENABLE;
1748 } else if (!strcmp("none", value)) {
1749 my_data->fluence_type = FLUENCE_DISABLE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001750 }
1751
Prashant Malanic92c5962015-08-11 15:10:18 -07001752 if (my_data->fluence_type != FLUENCE_DISABLE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001753 property_get("persist.audio.fluence.voicecall",value,"");
1754 if (!strcmp("true", value)) {
1755 my_data->fluence_in_voice_call = true;
1756 }
1757
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001758 property_get("persist.audio.fluence.voicecomm",value,"");
1759 if (!strcmp("true", value)) {
1760 my_data->fluence_in_voice_comm = true;
1761 }
1762
Eric Laurentb23d5282013-05-14 15:27:20 -07001763 property_get("persist.audio.fluence.voicerec",value,"");
1764 if (!strcmp("true", value)) {
1765 my_data->fluence_in_voice_rec = true;
1766 }
1767
1768 property_get("persist.audio.fluence.speaker",value,"");
1769 if (!strcmp("true", value)) {
1770 my_data->fluence_in_spkr_mode = true;
1771 }
1772 }
1773
Prashant Malanic92c5962015-08-11 15:10:18 -07001774 // support max to mono, example if max count is 3, usecase supports Three, dual and mono mic
1775 switch (my_data->max_mic_count) {
1776 case 4:
1777 my_data->source_mic_type |= SOURCE_QUAD_MIC;
1778 case 3:
1779 my_data->source_mic_type |= SOURCE_THREE_MIC;
1780 case 2:
1781 my_data->source_mic_type |= SOURCE_DUAL_MIC;
1782 case 1:
1783 my_data->source_mic_type |= SOURCE_MONO_MIC;
1784 break;
1785 default:
1786 ALOGE("%s: max_mic_count (%d), is not supported, setting to default",
1787 __func__, my_data->max_mic_count);
1788 my_data->source_mic_type = SOURCE_MONO_MIC|SOURCE_DUAL_MIC;
1789 break;
1790 }
1791
1792 ALOGV("%s: Fluence_Type(%d) max_mic_count(%d) mic_type(0x%x) fluence_in_voice_call(%d)"
1793 " fluence_in_voice_comm(%d) fluence_in_voice_rec(%d) fluence_in_spkr_mode(%d) ",
1794 __func__, my_data->fluence_type, my_data->max_mic_count, my_data->source_mic_type,
1795 my_data->fluence_in_voice_call, my_data->fluence_in_voice_comm,
1796 my_data->fluence_in_voice_rec, my_data->fluence_in_spkr_mode);
1797
Eric Laurentb23d5282013-05-14 15:27:20 -07001798 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
1799 if (my_data->acdb_handle == NULL) {
1800 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
1801 } else {
1802 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
1803 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
1804 "acdb_loader_deallocate_ACDB");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001805 if (!my_data->acdb_deallocate)
1806 ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s",
1807 __func__, LIB_ACDB_LOADER);
1808
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001809 my_data->acdb_send_audio_cal_v3 = (acdb_send_audio_cal_v3_t)dlsym(my_data->acdb_handle,
1810 "acdb_loader_send_audio_cal_v3");
1811 if (!my_data->acdb_send_audio_cal_v3)
1812 ALOGE("%s: Could not find the symbol acdb_send_audio_cal_v3 from %s",
1813 __func__, LIB_ACDB_LOADER);
1814
Eric Laurentb23d5282013-05-14 15:27:20 -07001815 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
1816 "acdb_loader_send_audio_cal");
1817 if (!my_data->acdb_send_audio_cal)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001818 ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s",
Eric Laurentb23d5282013-05-14 15:27:20 -07001819 __func__, LIB_ACDB_LOADER);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001820
Eric Laurentb23d5282013-05-14 15:27:20 -07001821 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
1822 "acdb_loader_send_voice_cal");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001823 if (!my_data->acdb_send_voice_cal)
1824 ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s",
1825 __func__, LIB_ACDB_LOADER);
1826
1827 my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle,
1828 "acdb_loader_reload_vocvoltable");
1829 if (!my_data->acdb_reload_vocvoltable)
1830 ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s",
1831 __func__, LIB_ACDB_LOADER);
vivek mehta1a9b7c02015-06-25 11:49:38 -07001832
1833 my_data->acdb_send_gain_dep_cal = (acdb_send_gain_dep_cal_t)dlsym(my_data->acdb_handle,
1834 "acdb_loader_send_gain_dep_cal");
1835 if (!my_data->acdb_send_gain_dep_cal)
1836 ALOGV("%s: Could not find the symbol acdb_loader_send_gain_dep_cal from %s",
1837 __func__, LIB_ACDB_LOADER);
1838
Xu Han1638fd12018-04-20 12:42:23 -07001839#if defined (FLICKER_SENSOR_INPUT)
1840 configure_flicker_sensor_input(adev->mixer);
1841#endif
1842
Thierry Strudel07f96d12018-09-20 13:31:34 -07001843#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845) || (PLATFORM_SDM710) || (PLATFORM_SM8150)
vivek mehta0fb11312017-05-15 19:35:32 -07001844 acdb_init_v2_cvd_t acdb_init_local;
1845 acdb_init_local = (acdb_init_v2_cvd_t)dlsym(my_data->acdb_handle,
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001846 "acdb_loader_init_v2");
vivek mehta0fb11312017-05-15 19:35:32 -07001847 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001848 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1849 dlerror());
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001850
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001851#elif defined (PLATFORM_MSM8084)
vivek mehta0fb11312017-05-15 19:35:32 -07001852 acdb_init_v2_t acdb_init_local;
1853 acdb_init_local = (acdb_init_v2_t)dlsym(my_data->acdb_handle,
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001854 "acdb_loader_init_v2");
vivek mehta0fb11312017-05-15 19:35:32 -07001855 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001856 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1857 dlerror());
1858
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001859#else
vivek mehta0fb11312017-05-15 19:35:32 -07001860 acdb_init_t acdb_init_local;
1861 acdb_init_local = (acdb_init_t)dlsym(my_data->acdb_handle,
Eric Laurentb23d5282013-05-14 15:27:20 -07001862 "acdb_loader_init_ACDB");
vivek mehta0fb11312017-05-15 19:35:32 -07001863 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001864 ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__,
1865 dlerror());
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001866#endif
vivek mehta0fb11312017-05-15 19:35:32 -07001867 my_data->acdb_init = acdb_init_local;
Eric Laurentb23d5282013-05-14 15:27:20 -07001868
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001869 my_data->acdb_send_custom_top = (acdb_send_custom_top_t)
1870 dlsym(my_data->acdb_handle,
1871 "acdb_loader_send_common_custom_topology");
1872
1873 if (!my_data->acdb_send_custom_top)
1874 ALOGE("%s: Could not find the symbol acdb_get_default_app_type from %s",
1875 __func__, LIB_ACDB_LOADER);
1876
jasmine chac89321b2018-04-10 21:37:01 +08001877 my_data->acdb_set_audio_cal = (acdb_set_audio_cal_t)dlsym(my_data->acdb_handle,
1878 "acdb_loader_set_audio_cal_v2");
1879 if (!my_data->acdb_set_audio_cal)
1880 ALOGE("%s: Could not find the symbol acdb_set_audio_cal_v2 from %s",
1881 __func__, LIB_ACDB_LOADER);
1882
vivek mehta0fb11312017-05-15 19:35:32 -07001883 int result = acdb_init(adev->snd_card);
1884 if (!result) {
1885 my_data->acdb_initialized = true;
1886 ALOGD("ACDB initialized");
1887 } else {
1888 my_data->acdb_initialized = false;
1889 ALOGD("ACDB initialization failed");
1890 }
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001891 }
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001892
David Linee3fe402017-03-13 10:00:42 -07001893 /* init usb */
1894 audio_extn_usb_init(adev);
1895
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001896 /* init a2dp */
1897 audio_extn_a2dp_init(adev);
1898
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001899 audio_extn_spkr_prot_init(adev);
Haynes Mathew George98c95622014-06-20 19:14:25 -07001900
Ravi Kumar Alamanda76315572015-04-23 13:13:56 -07001901 audio_extn_hwdep_cal_send(adev->snd_card, my_data->acdb_handle);
1902
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001903 /* load csd client */
1904 platform_csd_init(my_data);
1905
David Linee3fe402017-03-13 10:00:42 -07001906 platform_backend_config_init(my_data);
1907
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001908 init_be_dai_name_table(adev);
1909
1910 if (platform_supports_app_type_cfg())
1911 platform_backend_app_type_cfg_init(my_data, adev->mixer);
1912
Eric Laurentb23d5282013-05-14 15:27:20 -07001913 return my_data;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001914
1915init_failed:
1916 if (my_data)
1917 free(my_data);
1918 return NULL;
Eric Laurentb23d5282013-05-14 15:27:20 -07001919}
1920
1921void platform_deinit(void *platform)
1922{
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001923 int32_t dev;
keunhui.park2f7306a2015-07-16 16:48:06 +09001924 struct operator_info *info_item;
1925 struct operator_specific_device *device_item;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001926 struct app_type_entry *ap;
keunhui.park2f7306a2015-07-16 16:48:06 +09001927 struct listnode *node;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001928
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001929 struct platform_data *my_data = (struct platform_data *)platform;
1930 close_csd_client(my_data->csd);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001931
David Lin41b4fe42018-07-08 16:14:24 -07001932 audio_extn_spkr_prot_deinit(my_data->adev);
1933
vivek mehtade4849c2016-03-03 17:23:38 -08001934 hw_info_deinit(my_data->hw_info);
1935
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001936 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1937 if (backend_tag_table[dev])
1938 free(backend_tag_table[dev]);
1939 if (hw_interface_table[dev])
1940 free(hw_interface_table[dev]);
keunhui.park2f7306a2015-07-16 16:48:06 +09001941 if (operator_specific_device_table[dev]) {
1942 while (!list_empty(operator_specific_device_table[dev])) {
1943 node = list_head(operator_specific_device_table[dev]);
1944 list_remove(node);
1945 device_item = node_to_item(node, struct operator_specific_device, list);
1946 free(device_item->operator);
1947 free(device_item->mixer_path);
1948 free(device_item);
1949 }
1950 free(operator_specific_device_table[dev]);
1951 }
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001952 }
1953
1954 if (my_data->snd_card_name)
1955 free(my_data->snd_card_name);
1956
keunhui.park2f7306a2015-07-16 16:48:06 +09001957 while (!list_empty(&operator_info_list)) {
1958 node = list_head(&operator_info_list);
1959 list_remove(node);
1960 info_item = node_to_item(node, struct operator_info, list);
1961 free(info_item->name);
1962 free(info_item->mccmnc);
1963 free(info_item);
1964 }
1965
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001966 while (!list_empty(&app_type_entry_list)) {
1967 node = list_head(&app_type_entry_list);
1968 list_remove(node);
1969 ap = node_to_item(node, struct app_type_entry, node);
vivek mehtaa68fea62017-06-08 19:04:02 -07001970 if (ap->mode) free(ap->mode);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001971 free(ap);
1972 }
1973
Kevin Rocarde35d4af2017-05-02 16:55:28 -07001974 mixer_close(my_data->adev->mixer);
Eric Laurentb23d5282013-05-14 15:27:20 -07001975 free(platform);
David Linee3fe402017-03-13 10:00:42 -07001976
1977 /* deinit usb */
1978 audio_extn_usb_deinit();
Eric Laurentb23d5282013-05-14 15:27:20 -07001979}
1980
1981const char *platform_get_snd_device_name(snd_device_t snd_device)
1982{
keunhui.park2f7306a2015-07-16 16:48:06 +09001983 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1984 if (operator_specific_device_table[snd_device] != NULL) {
1985 return get_operator_specific_device_mixer_path(snd_device);
1986 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001987 return device_table[snd_device];
keunhui.park2f7306a2015-07-16 16:48:06 +09001988 } else
Ravi Kumar Alamanda64026462014-09-15 00:08:58 -07001989 return "none";
Eric Laurentb23d5282013-05-14 15:27:20 -07001990}
1991
vivek mehtade4849c2016-03-03 17:23:38 -08001992int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
1993 char *device_name)
1994{
1995 struct platform_data *my_data = (struct platform_data *)platform;
1996
David Benjamin1565f992016-09-21 12:10:34 -04001997 if (platform == NULL) {
vivek mehtade4849c2016-03-03 17:23:38 -08001998 ALOGW("%s: something wrong, use legacy get_snd_device name", __func__);
David Benjamin1565f992016-09-21 12:10:34 -04001999 strlcpy(device_name, platform_get_snd_device_name(snd_device),
2000 DEVICE_NAME_MAX_SIZE);
vivek mehtade4849c2016-03-03 17:23:38 -08002001 } else if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
2002 if (operator_specific_device_table[snd_device] != NULL) {
2003 strlcpy(device_name, get_operator_specific_device_mixer_path(snd_device),
2004 DEVICE_NAME_MAX_SIZE);
2005 } else {
2006 strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE);
2007 }
2008 hw_info_append_hw_type(my_data->hw_info, snd_device, device_name);
2009 } else {
2010 strlcpy(device_name, "none", DEVICE_NAME_MAX_SIZE);
Aniket Kumar Lataa158e862018-05-11 17:28:40 -07002011 return -EINVAL;
vivek mehtade4849c2016-03-03 17:23:38 -08002012 }
2013
2014 return 0;
2015}
2016
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05002017void platform_add_backend_name(void *platform, char *mixer_path,
2018 snd_device_t snd_device)
Eric Laurentb23d5282013-05-14 15:27:20 -07002019{
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05002020 struct platform_data *my_data = (struct platform_data *)platform;
2021
Haynes Mathew George98c95622014-06-20 19:14:25 -07002022 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
2023 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
2024 return;
Ravi Kumar Alamanda1de6e5a2014-06-19 21:55:39 -05002025 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07002026
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002027 const char * suffix = backend_tag_table[snd_device];
Haynes Mathew George98c95622014-06-20 19:14:25 -07002028
2029 if (suffix != NULL) {
2030 strcat(mixer_path, " ");
2031 strcat(mixer_path, suffix);
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05002032 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002033}
2034
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002035bool platform_check_backends_match(snd_device_t snd_device1, snd_device_t snd_device2)
2036{
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002037 ALOGV("%s: snd_device1 = %s, snd_device2 = %s", __func__,
2038 platform_get_snd_device_name(snd_device1),
2039 platform_get_snd_device_name(snd_device2));
2040
2041 if ((snd_device1 < SND_DEVICE_MIN) || (snd_device1 >= SND_DEVICE_MAX)) {
2042 ALOGE("%s: Invalid snd_device = %s", __func__,
2043 platform_get_snd_device_name(snd_device1));
2044 return false;
2045 }
2046 if ((snd_device2 < SND_DEVICE_MIN) || (snd_device2 >= SND_DEVICE_MAX)) {
2047 ALOGE("%s: Invalid snd_device = %s", __func__,
2048 platform_get_snd_device_name(snd_device2));
2049 return false;
2050 }
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07002051
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002052 const char * be_itf1 = hw_interface_table[snd_device1];
2053 const char * be_itf2 = hw_interface_table[snd_device2];
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07002054 /*
2055 hw_interface_table has overrides for a snd_device.
2056 if there is no entry for a device, assume DEFAULT_RX_BACKEND
2057 */
2058 if (be_itf1 == NULL) {
2059 be_itf1 = DEFAULT_RX_BACKEND;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002060 }
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07002061 if (be_itf2 == NULL) {
2062 be_itf2 = DEFAULT_RX_BACKEND;
2063 }
2064 ALOGV("%s: be_itf1 = %s, be_itf2 = %s", __func__, be_itf1, be_itf2);
2065 /*
2066 this takes care of finding a device within a combo device pair as well
2067 */
2068 return strstr(be_itf1, be_itf2) != NULL || strstr(be_itf2, be_itf1) != NULL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002069}
2070
Eric Laurentb23d5282013-05-14 15:27:20 -07002071int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
2072{
2073 int device_id;
2074 if (device_type == PCM_PLAYBACK)
2075 device_id = pcm_device_table[usecase][0];
2076 else
2077 device_id = pcm_device_table[usecase][1];
2078 return device_id;
2079}
2080
Vignesh Kulothungan019d19b2019-01-23 11:09:18 -08002081int platform_get_haptics_pcm_device_id()
2082{
2083 return HAPTICS_PCM_DEVICE;
2084}
2085
Haynes Mathew George98c95622014-06-20 19:14:25 -07002086static int find_index(const struct name_to_index * table, int32_t len,
2087 const char * name)
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002088{
2089 int ret = 0;
Haynes Mathew George98c95622014-06-20 19:14:25 -07002090 int32_t i;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002091
Haynes Mathew George98c95622014-06-20 19:14:25 -07002092 if (table == NULL) {
2093 ALOGE("%s: table is NULL", __func__);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002094 ret = -ENODEV;
2095 goto done;
2096 }
2097
Haynes Mathew George98c95622014-06-20 19:14:25 -07002098 if (name == NULL) {
2099 ALOGE("null key");
2100 ret = -ENODEV;
2101 goto done;
2102 }
2103
2104 for (i=0; i < len; i++) {
2105 if (!strcmp(table[i].name, name)) {
2106 ret = table[i].index;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002107 goto done;
2108 }
2109 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07002110 ALOGE("%s: Could not find index for name = %s",
2111 __func__, name);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002112 ret = -ENODEV;
2113done:
2114 return ret;
2115}
2116
Haynes Mathew George98c95622014-06-20 19:14:25 -07002117int platform_get_snd_device_index(char *device_name)
2118{
2119 return find_index(snd_device_name_index, SND_DEVICE_MAX, device_name);
2120}
2121
2122int platform_get_usecase_index(const char *usecase_name)
2123{
2124 return find_index(usecase_name_index, AUDIO_USECASE_MAX, usecase_name);
2125}
2126
Vignesh Kulothungan64698822018-01-23 11:25:18 -08002127int platform_get_effect_config_data(snd_device_t snd_device,
2128 struct audio_effect_config *effect_config,
2129 effect_type_t effect_type)
2130{
2131 int ret = 0;
2132
2133 if ((snd_device < SND_DEVICE_IN_BEGIN) || (snd_device >= SND_DEVICE_MAX) ||
2134 (effect_type <= EFFECT_NONE) || (effect_type >= EFFECT_COUNT)) {
2135 ALOGE("%s: Invalid snd_device = %d or effect_type = %d",
2136 __func__, snd_device, effect_type);
2137 ret = -EINVAL;
2138 goto done;
2139 }
2140
2141 if (effect_config == NULL) {
2142 ALOGE("%s: Invalid effect_config", __func__);
2143 ret = -EINVAL;
2144 goto done;
2145 }
2146
2147 ALOGV("%s: snd_device = %d module_id = %d",
2148 __func__, snd_device, effect_config_table[GET_IN_DEVICE_INDEX(snd_device)][effect_type].module_id);
2149 *effect_config = effect_config_table[GET_IN_DEVICE_INDEX(snd_device)][effect_type];
2150
2151done:
2152 return ret;
2153}
2154
2155int platform_set_effect_config_data(snd_device_t snd_device,
2156 struct audio_effect_config effect_config,
2157 effect_type_t effect_type)
2158{
2159 int ret = 0;
2160
2161 if ((snd_device < SND_DEVICE_IN_BEGIN) || (snd_device >= SND_DEVICE_MAX) ||
2162 (effect_type <= EFFECT_NONE) || (effect_type >= EFFECT_COUNT)) {
2163 ALOGE("%s: Invalid snd_device = %d or effect_type = %d",
2164 __func__, snd_device, effect_type);
2165 ret = -EINVAL;
2166 goto done;
2167 }
2168
2169 ALOGV("%s 0x%x 0x%x 0x%x 0x%x", __func__, effect_config.module_id,
2170 effect_config.instance_id, effect_config.param_id,
2171 effect_config.param_value);
2172 effect_config_table[GET_IN_DEVICE_INDEX(snd_device)][effect_type] = effect_config;
2173
2174done:
2175 return ret;
2176}
2177
keunhui.park2f7306a2015-07-16 16:48:06 +09002178void platform_add_operator_specific_device(snd_device_t snd_device,
2179 const char *operator,
2180 const char *mixer_path,
2181 unsigned int acdb_id)
2182{
2183 struct operator_specific_device *device;
2184
2185 if (operator_specific_device_table[snd_device] == NULL) {
2186 operator_specific_device_table[snd_device] =
2187 (struct listnode *)calloc(1, sizeof(struct listnode));
2188 list_init(operator_specific_device_table[snd_device]);
2189 }
2190
2191 device = (struct operator_specific_device *)calloc(1, sizeof(struct operator_specific_device));
2192
2193 device->operator = strdup(operator);
2194 device->mixer_path = strdup(mixer_path);
2195 device->acdb_id = acdb_id;
2196
2197 list_add_tail(operator_specific_device_table[snd_device], &device->list);
2198
Eric Laurent2bafff12016-03-17 12:17:23 -07002199 ALOGD("%s: device[%s] -> operator[%s] mixer_path[%s] acdb_id[%d]", __func__,
keunhui.park2f7306a2015-07-16 16:48:06 +09002200 platform_get_snd_device_name(snd_device), operator, mixer_path, acdb_id);
2201
2202}
2203
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002204int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
2205{
2206 int ret = 0;
2207
2208 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
2209 ALOGE("%s: Invalid snd_device = %d",
2210 __func__, snd_device);
2211 ret = -EINVAL;
2212 goto done;
2213 }
2214
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002215 ALOGV("%s: acdb_device_table[%s]: old = %d new = %d", __func__,
2216 platform_get_snd_device_name(snd_device), acdb_device_table[snd_device], acdb_id);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002217 acdb_device_table[snd_device] = acdb_id;
2218done:
2219 return ret;
2220}
2221
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07002222int platform_get_snd_device_acdb_id(snd_device_t snd_device)
2223{
2224 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
2225 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
2226 return -EINVAL;
2227 }
keunhui.park2f7306a2015-07-16 16:48:06 +09002228
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002229 /*
2230 * If speaker protection is enabled, function returns supported
2231 * sound device for speaker. Else same sound device is returned.
2232 */
2233 snd_device = audio_extn_get_spkr_prot_snd_device(snd_device);
2234
keunhui.park2f7306a2015-07-16 16:48:06 +09002235 if (operator_specific_device_table[snd_device] != NULL)
2236 return get_operator_specific_device_acdb_id(snd_device);
2237 else
2238 return acdb_device_table[snd_device];
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07002239}
2240
David Linee3fe402017-03-13 10:00:42 -07002241static int platform_get_backend_index(snd_device_t snd_device)
2242{
2243 int32_t port = DEFAULT_CODEC_BACKEND;
2244
2245 if (snd_device >= SND_DEVICE_OUT_BEGIN && snd_device < SND_DEVICE_OUT_END) {
2246 if (backend_tag_table[snd_device] != NULL) {
2247 if (strncmp(backend_tag_table[snd_device], "headphones",
2248 sizeof("headphones")) == 0)
2249 port = HEADPHONE_BACKEND;
2250 else if (strcmp(backend_tag_table[snd_device], "hdmi") == 0)
2251 port = HDMI_RX_BACKEND;
2252 else if ((strcmp(backend_tag_table[snd_device], "usb-headphones") == 0) ||
2253 (strcmp(backend_tag_table[snd_device], "usb-headset") == 0))
2254 port = USB_AUDIO_RX_BACKEND;
2255 }
2256 } else if (snd_device >= SND_DEVICE_IN_BEGIN && snd_device < SND_DEVICE_IN_END) {
2257 port = DEFAULT_CODEC_TX_BACKEND;
2258 if (backend_tag_table[snd_device] != NULL) {
2259 if (strcmp(backend_tag_table[snd_device], "usb-headset-mic") == 0)
2260 port = USB_AUDIO_TX_BACKEND;
2261 else if (strstr(backend_tag_table[snd_device], "bt-sco") != NULL)
2262 port = BT_SCO_TX_BACKEND;
2263 }
2264 } else {
2265 ALOGW("%s:napb: Invalid device - %d ", __func__, snd_device);
2266 }
2267
2268 ALOGV("%s:napb: backend port - %d device - %d ", __func__, port, snd_device);
2269
2270 return port;
2271}
2272
Eric Laurentb23d5282013-05-14 15:27:20 -07002273int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
2274{
2275 struct platform_data *my_data = (struct platform_data *)platform;
2276 int acdb_dev_id, acdb_dev_type;
2277
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002278 if (platform_supports_app_type_cfg()) // use v2 instead
2279 return -ENOSYS;
2280
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002281 acdb_dev_id = platform_get_snd_device_acdb_id(snd_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07002282 if (acdb_dev_id < 0) {
2283 ALOGE("%s: Could not find acdb id for device(%d)",
2284 __func__, snd_device);
2285 return -EINVAL;
2286 }
2287 if (my_data->acdb_send_audio_cal) {
Joe Onorato188b6222016-03-01 11:02:27 -08002288 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Eric Laurentb23d5282013-05-14 15:27:20 -07002289 __func__, snd_device, acdb_dev_id);
2290 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
2291 snd_device < SND_DEVICE_OUT_END)
2292 acdb_dev_type = ACDB_DEV_TYPE_OUT;
2293 else
2294 acdb_dev_type = ACDB_DEV_TYPE_IN;
2295 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
2296 }
2297 return 0;
2298}
2299
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002300int platform_send_audio_calibration_v2(void *platform, struct audio_usecase *usecase,
2301 int app_type, int sample_rate)
2302{
2303 struct platform_data *my_data = (struct platform_data *)platform;
2304 int acdb_dev_id, acdb_dev_type;
vivek mehta7e573672018-03-13 17:41:41 -07002305 int snd_device = usecase->out_snd_device;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002306 int new_snd_device[SND_DEVICE_OUT_END] = {0};
2307 int i, num_devices = 1;
2308
2309 if (!platform_supports_app_type_cfg()) // use v1 instead
2310 return -ENOSYS;
2311
vivek mehta7e573672018-03-13 17:41:41 -07002312 if ((usecase->type == PCM_HFP_CALL) || (usecase->type == PCM_CAPTURE))
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002313 snd_device = usecase->in_snd_device;
2314
2315 // skipped over get_spkr_prot_device
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002316 acdb_dev_id = platform_get_snd_device_acdb_id(snd_device);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002317 if (acdb_dev_id < 0) {
2318 ALOGE("%s: Could not find acdb id for device(%d)",
2319 __func__, snd_device);
2320 return -EINVAL;
2321 }
2322
2323 if (platform_can_split_snd_device(snd_device,
2324 &num_devices, new_snd_device) < 0) {
2325 new_snd_device[0] = snd_device;
2326 }
2327
2328 for (i = 0; i < num_devices; i++) {
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002329 acdb_dev_id = platform_get_snd_device_acdb_id(new_snd_device[i]);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002330 if (acdb_dev_id < 0) {
2331 ALOGE("%s: Could not find acdb id for device(%d)",
2332 __func__, new_snd_device[i]);
2333 return -EINVAL;
2334 }
2335 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
2336 __func__, new_snd_device[i], acdb_dev_id);
2337 if (new_snd_device[i] >= SND_DEVICE_OUT_BEGIN &&
2338 new_snd_device[i] < SND_DEVICE_OUT_END)
2339 acdb_dev_type = ACDB_DEV_TYPE_OUT;
2340 else
2341 acdb_dev_type = ACDB_DEV_TYPE_IN;
2342
2343 if (my_data->acdb_send_audio_cal_v3) {
2344 my_data->acdb_send_audio_cal_v3(acdb_dev_id, acdb_dev_type,
2345 app_type, sample_rate, i);
2346 } else if (my_data->acdb_send_audio_cal) {
2347 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type); // this version differs from internal
2348 }
2349 }
2350
2351 return 0;
2352}
2353
2354
Eric Laurentb23d5282013-05-14 15:27:20 -07002355int platform_switch_voice_call_device_pre(void *platform)
2356{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002357 struct platform_data *my_data = (struct platform_data *)platform;
2358 int ret = 0;
2359
2360 if (my_data->csd != NULL &&
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002361 voice_is_in_call(my_data->adev)) {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002362 /* This must be called before disabling mixer controls on APQ side */
2363 ret = my_data->csd->disable_device();
2364 if (ret < 0) {
2365 ALOGE("%s: csd_client_disable_device, failed, error %d",
2366 __func__, ret);
2367 }
2368 }
2369 return ret;
2370}
2371
2372int platform_switch_voice_call_enable_device_config(void *platform,
2373 snd_device_t out_snd_device,
2374 snd_device_t in_snd_device)
2375{
2376 struct platform_data *my_data = (struct platform_data *)platform;
2377 int acdb_rx_id, acdb_tx_id;
2378 int ret = 0;
2379
2380 if (my_data->csd == NULL)
2381 return ret;
2382
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002383 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
keunhui.park2f7306a2015-07-16 16:48:06 +09002384 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002385
2386 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
2387 ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
2388 if (ret < 0) {
2389 ALOGE("%s: csd_enable_device_config, failed, error %d",
2390 __func__, ret);
2391 }
2392 } else {
2393 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2394 acdb_rx_id, acdb_tx_id);
2395 }
2396
2397 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002398}
2399
2400int platform_switch_voice_call_device_post(void *platform,
2401 snd_device_t out_snd_device,
2402 snd_device_t in_snd_device)
2403{
2404 struct platform_data *my_data = (struct platform_data *)platform;
2405 int acdb_rx_id, acdb_tx_id;
2406
2407 if (my_data->acdb_send_voice_cal == NULL) {
2408 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
2409 } else {
keunhui.park2f7306a2015-07-16 16:48:06 +09002410 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
2411 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07002412
2413 if (acdb_rx_id > 0 && acdb_tx_id > 0)
2414 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
2415 else
2416 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2417 acdb_rx_id, acdb_tx_id);
2418 }
2419
2420 return 0;
2421}
2422
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002423int platform_switch_voice_call_usecase_route_post(void *platform,
2424 snd_device_t out_snd_device,
2425 snd_device_t in_snd_device)
2426{
2427 struct platform_data *my_data = (struct platform_data *)platform;
2428 int acdb_rx_id, acdb_tx_id;
2429 int ret = 0;
2430
2431 if (my_data->csd == NULL)
2432 return ret;
2433
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002434 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
keunhui.park2f7306a2015-07-16 16:48:06 +09002435 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002436
2437 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
2438 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
2439 my_data->adev->acdb_settings);
2440 if (ret < 0) {
2441 ALOGE("%s: csd_enable_device, failed, error %d", __func__, ret);
2442 }
2443 } else {
2444 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2445 acdb_rx_id, acdb_tx_id);
2446 }
2447
2448 return ret;
2449}
2450
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002451int platform_start_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07002452{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002453 struct platform_data *my_data = (struct platform_data *)platform;
2454 int ret = 0;
2455
2456 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002457 ret = my_data->csd->start_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002458 if (ret < 0) {
2459 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
2460 }
2461 }
2462 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002463}
2464
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002465int platform_stop_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07002466{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002467 struct platform_data *my_data = (struct platform_data *)platform;
2468 int ret = 0;
2469
2470 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002471 ret = my_data->csd->stop_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002472 if (ret < 0) {
2473 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
2474 }
2475 }
2476 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002477}
2478
Vignesh Kulothunganb6f0a9c2018-03-22 13:50:22 -07002479int platform_set_mic_break_det(void *platform, bool enable)
2480{
2481 int ret = 0;
2482 struct platform_data *my_data = (struct platform_data *)platform;
2483 struct audio_device *adev = my_data->adev;
2484 const char *mixer_ctl_name = "Voice Mic Break Enable";
2485 struct mixer_ctl *ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2486 if (!ctl) {
2487 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2488 __func__, mixer_ctl_name);
2489 return -EINVAL;
2490 }
2491
2492 ret = mixer_ctl_set_value(ctl, 0, enable);
2493 if(ret)
2494 ALOGE("%s: Failed to set mixer ctl: %s", __func__, mixer_ctl_name);
2495
2496 return ret;
2497}
2498
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002499int platform_get_sample_rate(void *platform, uint32_t *rate)
2500{
2501 struct platform_data *my_data = (struct platform_data *)platform;
2502 int ret = 0;
2503
2504 if (my_data->csd != NULL) {
2505 ret = my_data->csd->get_sample_rate(rate);
2506 if (ret < 0) {
2507 ALOGE("%s: csd_get_sample_rate error %d\n", __func__, ret);
2508 }
2509 }
2510 return ret;
2511}
2512
vivek mehtab6506412015-08-07 16:55:17 -07002513void platform_set_speaker_gain_in_combo(struct audio_device *adev,
2514 snd_device_t snd_device,
2515 bool enable)
2516{
2517 const char* name;
2518 switch (snd_device) {
2519 case SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES:
2520 if (enable)
2521 name = "spkr-gain-in-headphone-combo";
2522 else
2523 name = "speaker-gain-default";
2524 break;
2525 case SND_DEVICE_OUT_SPEAKER_AND_LINE:
2526 if (enable)
2527 name = "spkr-gain-in-line-combo";
2528 else
2529 name = "speaker-gain-default";
2530 break;
2531 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES:
2532 if (enable)
2533 name = "spkr-safe-gain-in-headphone-combo";
2534 else
2535 name = "speaker-safe-gain-default";
2536 break;
2537 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE:
2538 if (enable)
2539 name = "spkr-safe-gain-in-line-combo";
2540 else
2541 name = "speaker-safe-gain-default";
2542 break;
2543 default:
2544 return;
2545 }
2546
2547 audio_route_apply_and_update_path(adev->audio_route, name);
2548}
2549
Eric Laurentb23d5282013-05-14 15:27:20 -07002550int platform_set_voice_volume(void *platform, int volume)
2551{
2552 struct platform_data *my_data = (struct platform_data *)platform;
2553 struct audio_device *adev = my_data->adev;
2554 struct mixer_ctl *ctl;
sangwoo53b2cf02013-07-25 19:18:44 -07002555 const char *mixer_ctl_name = "Voice Rx Gain";
Nadav Barc46d0fa2017-12-24 14:50:37 +02002556 const char *mute_mixer_ctl_name = "Voice Rx Device Mute";
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002557 int vol_index = 0, ret = 0;
2558 uint32_t set_values[ ] = {0,
2559 ALL_SESSION_VSID,
2560 DEFAULT_VOLUME_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07002561
2562 // Voice volume levels are mapped to adsp volume levels as follows.
2563 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
2564 // But this values don't changed in kernel. So, below change is need.
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09002565 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, my_data->max_vol_index);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002566 set_values[0] = vol_index;
Eric Laurentb23d5282013-05-14 15:27:20 -07002567
2568 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2569 if (!ctl) {
2570 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2571 __func__, mixer_ctl_name);
2572 return -EINVAL;
2573 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002574 ALOGV("Setting voice volume index: %d", set_values[0]);
2575 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2576
Nadav Barc46d0fa2017-12-24 14:50:37 +02002577 // Send mute command in case volume index is max since indexes are inverted
2578 // for mixer controls.
2579 if (vol_index == my_data->max_vol_index) {
2580 set_values[0] = 1;
2581 }
2582 else {
2583 set_values[0] = 0;
2584 }
2585
2586 ctl = mixer_get_ctl_by_name(adev->mixer, mute_mixer_ctl_name);
2587 if (!ctl) {
2588 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2589 __func__, mute_mixer_ctl_name);
2590 return -EINVAL;
2591 }
2592 ALOGV("%s: Setting RX Device Mute to: %d", __func__, set_values[0]);
2593 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2594
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002595 if (my_data->csd != NULL) {
2596 ret = my_data->csd->volume(ALL_SESSION_VSID, volume,
2597 DEFAULT_VOLUME_RAMP_DURATION_MS);
2598 if (ret < 0) {
2599 ALOGE("%s: csd_volume error %d", __func__, ret);
2600 }
2601 }
2602 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002603}
2604
2605int platform_set_mic_mute(void *platform, bool state)
2606{
2607 struct platform_data *my_data = (struct platform_data *)platform;
2608 struct audio_device *adev = my_data->adev;
2609 struct mixer_ctl *ctl;
2610 const char *mixer_ctl_name = "Voice Tx Mute";
sangwoo53b2cf02013-07-25 19:18:44 -07002611 int ret = 0;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002612 uint32_t set_values[ ] = {0,
2613 ALL_SESSION_VSID,
2614 DEFAULT_MUTE_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07002615
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09002616 if (adev->mode != AUDIO_MODE_IN_CALL &&
2617 adev->mode != AUDIO_MODE_IN_COMMUNICATION)
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002618 return 0;
2619
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09002620 if (adev->enable_hfp)
2621 mixer_ctl_name = "HFP Tx Mute";
2622
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002623 set_values[0] = state;
2624 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2625 if (!ctl) {
2626 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2627 __func__, mixer_ctl_name);
2628 return -EINVAL;
2629 }
Arun Mirpuri0cc2f312018-05-29 17:26:07 -07002630 ALOGV("%s: Setting voice mute state: %d", __func__, state);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002631 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2632
2633 if (my_data->csd != NULL) {
2634 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state,
2635 DEFAULT_MUTE_RAMP_DURATION_MS);
sangwoo53b2cf02013-07-25 19:18:44 -07002636 if (ret < 0) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002637 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
sangwoo53b2cf02013-07-25 19:18:44 -07002638 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002639 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002640 return ret;
2641}
Eric Laurentb23d5282013-05-14 15:27:20 -07002642
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002643int platform_set_device_mute(void *platform, bool state, char *dir)
2644{
2645 struct platform_data *my_data = (struct platform_data *)platform;
2646 struct audio_device *adev = my_data->adev;
2647 struct mixer_ctl *ctl;
2648 char *mixer_ctl_name = NULL;
2649 int ret = 0;
2650 uint32_t set_values[ ] = {0,
2651 ALL_SESSION_VSID,
2652 0};
2653 if(dir == NULL) {
2654 ALOGE("%s: Invalid direction:%s", __func__, dir);
2655 return -EINVAL;
2656 }
2657
2658 if (!strncmp("rx", dir, sizeof("rx"))) {
2659 mixer_ctl_name = "Voice Rx Device Mute";
2660 } else if (!strncmp("tx", dir, sizeof("tx"))) {
2661 mixer_ctl_name = "Voice Tx Device Mute";
2662 } else {
2663 return -EINVAL;
2664 }
2665
2666 set_values[0] = state;
2667 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2668 if (!ctl) {
2669 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2670 __func__, mixer_ctl_name);
2671 return -EINVAL;
2672 }
2673
2674 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
2675 __func__,state, mixer_ctl_name);
2676 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2677
2678 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002679}
2680
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002681int platform_can_split_snd_device(snd_device_t snd_device,
2682 int *num_devices,
2683 snd_device_t *new_snd_devices)
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002684{
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002685 int ret = -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002686 if (NULL == num_devices || NULL == new_snd_devices) {
2687 ALOGE("%s: NULL pointer ..", __func__);
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002688 return -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002689 }
2690
2691 /*
2692 * If wired headset/headphones/line devices share the same backend
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002693 * with speaker/earpiece this routine returns -EINVAL.
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002694 */
2695 if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES &&
2696 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_HEADPHONES)) {
2697 *num_devices = 2;
2698 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2699 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002700 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002701 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_LINE &&
2702 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_LINE)) {
2703 *num_devices = 2;
2704 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2705 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002706 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002707 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES &&
2708 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_HEADPHONES)) {
2709 *num_devices = 2;
2710 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2711 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002712 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002713 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE &&
2714 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_LINE)) {
2715 *num_devices = 2;
2716 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2717 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002718 ret = 0;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002719 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO &&
2720 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2721 SND_DEVICE_OUT_BT_SCO)) {
2722 *num_devices = 2;
2723 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2724 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO;
2725 ret = 0;
juyuchen5351ea62018-05-16 10:54:37 +08002726 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO &&
2727 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE,
2728 SND_DEVICE_OUT_BT_SCO)) {
2729 *num_devices = 2;
2730 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2731 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO;
2732 ret = 0;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002733 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB &&
2734 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2735 SND_DEVICE_OUT_BT_SCO_WB)) {
2736 *num_devices = 2;
2737 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2738 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO_WB;
2739 ret = 0;
juyuchen5351ea62018-05-16 10:54:37 +08002740 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB &&
2741 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE,
2742 SND_DEVICE_OUT_BT_SCO_WB)) {
2743 *num_devices = 2;
2744 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2745 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO_WB;
2746 ret = 0;
David Linee3fe402017-03-13 10:00:42 -07002747 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET &&
2748 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_USB_HEADSET)) {
2749 *num_devices = 2;
2750 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2751 new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
2752 ret = 0;
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07002753 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET &&
2754 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_USB_HEADSET)) {
2755 *num_devices = 2;
2756 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2757 new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
2758 ret = 0;
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002759 } else if (SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP == snd_device &&
2760 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2761 SND_DEVICE_OUT_BT_A2DP)) {
2762 *num_devices = 2;
2763 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2764 new_snd_devices[1] = SND_DEVICE_OUT_BT_A2DP;
2765 ret = 0;
Aniket Kumar Lata9723a962018-05-16 17:41:55 -07002766 } else if (SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP == snd_device &&
2767 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE,
2768 SND_DEVICE_OUT_BT_A2DP)) {
2769 *num_devices = 2;
2770 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2771 new_snd_devices[1] = SND_DEVICE_OUT_BT_A2DP;
2772 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002773 }
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002774
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002775 return ret;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002776}
2777
Eric Laurentb23d5282013-05-14 15:27:20 -07002778snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
2779{
2780 struct platform_data *my_data = (struct platform_data *)platform;
2781 struct audio_device *adev = my_data->adev;
2782 audio_mode_t mode = adev->mode;
2783 snd_device_t snd_device = SND_DEVICE_NONE;
2784
2785 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
2786 if (devices == AUDIO_DEVICE_NONE ||
2787 devices & AUDIO_DEVICE_BIT_IN) {
2788 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
2789 goto exit;
2790 }
2791
Eric Laurent1b491552015-09-15 17:52:41 -07002792 if (popcount(devices) == 2) {
2793 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2794 AUDIO_DEVICE_OUT_SPEAKER) ||
2795 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2796 AUDIO_DEVICE_OUT_SPEAKER)) {
2797 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
2798 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2799 AUDIO_DEVICE_OUT_SPEAKER)) {
2800 snd_device = SND_DEVICE_OUT_SPEAKER_AND_LINE;
2801 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2802 AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
2803 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2804 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2805 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES;
2806 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2807 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2808 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE;
2809 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
2810 AUDIO_DEVICE_OUT_SPEAKER)) {
2811 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002812 } else if ((devices & AUDIO_DEVICE_OUT_ALL_SCO) &&
2813 ((devices & ~AUDIO_DEVICE_OUT_ALL_SCO) == AUDIO_DEVICE_OUT_SPEAKER)) {
2814 snd_device = adev->bt_wb_speech_enabled ?
2815 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB :
2816 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO;
juyuchen5351ea62018-05-16 10:54:37 +08002817 } else if ((devices & AUDIO_DEVICE_OUT_ALL_SCO) &&
2818 ((devices & ~AUDIO_DEVICE_OUT_ALL_SCO) == AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2819 snd_device = adev->bt_wb_speech_enabled ?
2820 SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB :
2821 SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO;
Eric Laurent99dab492017-06-17 15:19:08 -07002822 } else if ((devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
2823 AUDIO_DEVICE_OUT_SPEAKER)) ||
2824 (devices == (AUDIO_DEVICE_OUT_USB_HEADSET |
2825 AUDIO_DEVICE_OUT_SPEAKER))) {
David Linee3fe402017-03-13 10:00:42 -07002826 snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET;
Eric Laurentd0f7c262017-07-05 09:09:12 -07002827 } else if ((devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
2828 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) ||
2829 (devices == (AUDIO_DEVICE_OUT_USB_HEADSET |
2830 AUDIO_DEVICE_OUT_SPEAKER_SAFE))) {
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07002831 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET;
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002832 } else if ((devices & AUDIO_DEVICE_OUT_SPEAKER) &&
2833 (devices & AUDIO_DEVICE_OUT_ALL_A2DP)) {
2834 snd_device = SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP;
Aniket Kumar Lata9723a962018-05-16 17:41:55 -07002835 } else if ((devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) &&
2836 (devices & AUDIO_DEVICE_OUT_ALL_A2DP)) {
2837 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP;
Eric Laurent1b491552015-09-15 17:52:41 -07002838 } else {
2839 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
2840 goto exit;
2841 }
2842 if (snd_device != SND_DEVICE_NONE) {
2843 goto exit;
2844 }
2845 }
2846
2847 if (popcount(devices) != 1) {
2848 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
2849 goto exit;
2850 }
2851
Madhuri Athota3f6051b2016-10-13 23:25:38 +05302852 if (voice_is_in_call(adev) || adev->enable_voicerx || audio_extn_hfp_is_active(adev)) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002853 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002854 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2855 devices & AUDIO_DEVICE_OUT_LINE) {
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002856 if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002857 (adev->voice.tty_mode == TTY_MODE_FULL))
Eric Laurentb23d5282013-05-14 15:27:20 -07002858 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002859 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002860 (adev->voice.tty_mode == TTY_MODE_VCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002861 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002862 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002863 (adev->voice.tty_mode == TTY_MODE_HCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002864 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002865 else {
2866 if (devices & AUDIO_DEVICE_OUT_LINE)
2867 snd_device = SND_DEVICE_OUT_VOICE_LINE;
yixuanjiang9536e672018-09-06 18:43:36 +08002868 else if (devices & AUDIO_DEVICE_OUT_WIRED_HEADSET)
2869 snd_device = SND_DEVICE_OUT_VOICE_HEADSET;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002870 else
2871 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
2872 }
Eric Laurent99dab492017-06-17 15:19:08 -07002873 } else if (audio_is_usb_out_device(devices)) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002874 if (voice_is_in_call(adev)) {
2875 switch (adev->voice.tty_mode) {
2876 case TTY_MODE_FULL:
2877 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_USB;
2878 break;
2879 case TTY_MODE_VCO:
2880 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_USB;
2881 break;
2882 case TTY_MODE_HCO:
2883 // since Hearing will be on handset\speaker, use existing device
2884 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
2885 break;
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002886 case TTY_MODE_OFF:
2887 break;
vivek mehtaa6b79742017-03-09 15:40:43 -08002888 default:
2889 ALOGE("%s: Invalid TTY mode (%#x)",
2890 __func__, adev->voice.tty_mode);
2891 }
2892 }
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002893 if (snd_device == SND_DEVICE_NONE) {
2894 snd_device = audio_extn_usb_is_capture_supported() ?
2895 SND_DEVICE_OUT_VOICE_USB_HEADSET :
2896 SND_DEVICE_OUT_VOICE_USB_HEADPHONES;
2897 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002898 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002899 if (adev->bt_wb_speech_enabled) {
2900 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2901 } else {
2902 snd_device = SND_DEVICE_OUT_BT_SCO;
2903 }
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002904 } else if (devices & AUDIO_DEVICE_OUT_ALL_A2DP) {
2905 snd_device = SND_DEVICE_OUT_BT_A2DP;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002906 } else if (devices & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002907 if (!adev->enable_hfp) {
2908 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
2909 } else {
2910 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_HFP;
2911 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002912 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002913 if(adev->voice.hac)
2914 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2915 else if (is_operator_tmus())
Eric Laurentb23d5282013-05-14 15:27:20 -07002916 snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS;
2917 else
Eric Laurentb4d368e2014-06-25 10:21:54 -05002918 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
juyuchend194b432018-11-16 14:15:16 +08002919 } else if (devices & AUDIO_DEVICE_OUT_TELEPHONY_TX) {
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002920 snd_device = SND_DEVICE_OUT_VOICE_TX;
juyuchend194b432018-11-16 14:15:16 +08002921 } else if (devices & AUDIO_DEVICE_OUT_HEARING_AID) {
2922 snd_device = SND_DEVICE_OUT_VOICE_HEARING_AID;
2923 }
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002924
Eric Laurentb23d5282013-05-14 15:27:20 -07002925 if (snd_device != SND_DEVICE_NONE) {
2926 goto exit;
2927 }
2928 }
2929
Eric Laurentb23d5282013-05-14 15:27:20 -07002930 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2931 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2932 snd_device = SND_DEVICE_OUT_HEADPHONES;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002933 } else if (devices & AUDIO_DEVICE_OUT_LINE) {
2934 snd_device = SND_DEVICE_OUT_LINE;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002935 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) {
2936 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE;
Eric Laurentb23d5282013-05-14 15:27:20 -07002937 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
andysu5b30b062018-04-20 16:34:06 +08002938 /*
2939 * Perform device switch only if acdb tuning is different between SPEAKER & SPEAKER_REVERSE,
2940 * Or there will be a small pause while performing device switch.
2941 */
2942 if (my_data->speaker_lr_swap &&
2943 (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
2944 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]))
Eric Laurentb23d5282013-05-14 15:27:20 -07002945 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
2946 else
2947 snd_device = SND_DEVICE_OUT_SPEAKER;
2948 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002949 if (adev->bt_wb_speech_enabled) {
2950 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2951 } else {
2952 snd_device = SND_DEVICE_OUT_BT_SCO;
2953 }
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002954 } else if (devices & AUDIO_DEVICE_OUT_ALL_A2DP) {
2955 snd_device = SND_DEVICE_OUT_BT_A2DP;
Eric Laurentb23d5282013-05-14 15:27:20 -07002956 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2957 snd_device = SND_DEVICE_OUT_HDMI ;
Eric Laurent99dab492017-06-17 15:19:08 -07002958 } else if (audio_is_usb_out_device(devices)) {
jasmine cha270b7762018-03-30 15:41:33 +08002959 if (audio_extn_ma_supported_usb())
2960 snd_device = SND_DEVICE_OUT_USB_HEADSET_SPEC;
2961 else if (audio_extn_usb_is_capture_supported())
David Linee3fe402017-03-13 10:00:42 -07002962 snd_device = SND_DEVICE_OUT_USB_HEADSET;
2963 else
2964 snd_device = SND_DEVICE_OUT_USB_HEADPHONES;
2965 }else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002966 /*HAC support for voice-ish audio (eg visual voicemail)*/
2967 if(adev->voice.hac)
2968 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2969 else
2970 snd_device = SND_DEVICE_OUT_HANDSET;
Eric Laurentb23d5282013-05-14 15:27:20 -07002971 } else {
2972 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
2973 }
2974exit:
2975 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
2976 return snd_device;
2977}
2978
Vignesh Kulothungan64698822018-01-23 11:25:18 -08002979#ifdef DYNAMIC_ECNS_ENABLED
2980static snd_device_t get_snd_device_for_voice_comm(struct platform_data *my_data,
2981 struct stream_in *in __unused,
2982 audio_devices_t out_device,
2983 audio_devices_t in_device)
2984{
2985 struct audio_device *adev = my_data->adev;
2986 snd_device_t snd_device = SND_DEVICE_NONE;
2987
2988 if (my_data->fluence_type != FLUENCE_DISABLE) {
2989 switch(AUDIO_DEVICE_BIT_IN | in_device) {
2990 case AUDIO_DEVICE_IN_BACK_MIC:
2991 if (my_data->fluence_in_spkr_mode) {
2992 if ((my_data->fluence_type & FLUENCE_PRO_ENABLE) &&
2993 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2994 snd_device = SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS;
2995 } else if (((my_data->fluence_type & FLUENCE_PRO_ENABLE) ||
2996 (my_data->fluence_type & FLUENCE_ENABLE)) &&
2997 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2998 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
2999 }
3000 adev->acdb_settings |= DMIC_FLAG;
3001 } else
3002 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
3003 break;
3004 case AUDIO_DEVICE_IN_BUILTIN_MIC:
3005 if (((my_data->fluence_type & FLUENCE_PRO_ENABLE) ||
3006 (my_data->fluence_type & FLUENCE_ENABLE)) &&
3007 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
3008 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
3009 adev->acdb_settings |= DMIC_FLAG;
3010 } else
3011 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
3012 break;
3013 default:
3014 ALOGE("%s: Unsupported in_device %#x", __func__, in_device);
3015 break;
3016 }
3017 platform_set_echo_reference(adev, true, out_device);
3018 }
3019
3020 return snd_device;
3021}
3022#else
3023static snd_device_t get_snd_device_for_voice_comm(struct platform_data *my_data,
3024 struct stream_in *in,
3025 audio_devices_t out_device,
3026 audio_devices_t in_device)
3027{
3028 struct audio_device *adev = my_data->adev;
3029 snd_device_t snd_device = SND_DEVICE_NONE;
3030
3031 if (in->enable_aec &&
3032 in->enable_ns) {
3033 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
3034 if (my_data->fluence_in_spkr_mode &&
3035 my_data->fluence_in_voice_comm &&
3036 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
3037 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
3038 } else {
3039 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
3040 }
3041 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
3042 if (my_data->fluence_in_voice_comm &&
3043 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
3044 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
3045 } else {
3046 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
3047 }
3048 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3049 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
3050 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
3051 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
3052 }
3053 platform_set_echo_reference(adev, true, out_device);
3054 } else if (in->enable_aec) {
3055 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
3056 if (my_data->fluence_in_spkr_mode &&
3057 my_data->fluence_in_voice_comm &&
3058 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
3059 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
3060 } else {
3061 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
3062 }
3063 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
3064 if (my_data->fluence_in_voice_comm &&
3065 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
3066 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
3067 } else {
3068 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
3069 }
3070 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3071 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
3072 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
3073 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
3074 }
3075 platform_set_echo_reference(adev, true, out_device);
3076 } else if (in->enable_ns) {
3077 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
3078 if (my_data->fluence_in_spkr_mode &&
3079 my_data->fluence_in_voice_comm &&
3080 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
3081 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
3082 } else {
3083 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
3084 }
3085 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
3086 if (my_data->fluence_in_voice_comm &&
3087 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
3088 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
3089 } else {
3090 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
3091 }
3092 }
3093 }
3094
3095 return snd_device;
3096}
3097#endif //DYNAMIC_ECNS_ENABLED
3098
Eric Laurentd1b7a9b2018-11-15 12:24:31 -08003099snd_device_t platform_get_input_snd_device(void *platform,
3100 struct stream_in *in,
3101 audio_devices_t out_device)
Eric Laurentb23d5282013-05-14 15:27:20 -07003102{
3103 struct platform_data *my_data = (struct platform_data *)platform;
3104 struct audio_device *adev = my_data->adev;
Eric Laurentd1b7a9b2018-11-15 12:24:31 -08003105 audio_mode_t mode = adev->mode;
Eric Laurentb23d5282013-05-14 15:27:20 -07003106 snd_device_t snd_device = SND_DEVICE_NONE;
Eric Laurentd1b7a9b2018-11-15 12:24:31 -08003107
3108 if (in == NULL) {
3109 in = adev_get_active_input(adev);
3110 }
3111
3112 audio_source_t source = (in == NULL) ? AUDIO_SOURCE_DEFAULT : in->source;
3113 audio_devices_t in_device =
3114 ((in == NULL) ? AUDIO_DEVICE_NONE : in->device) & ~AUDIO_DEVICE_BIT_IN;
3115 audio_channel_mask_t channel_mask = (in == NULL) ? AUDIO_CHANNEL_IN_MONO : in->channel_mask;
3116 int channel_count = audio_channel_count_from_in_mask(channel_mask);
Eric Laurentb23d5282013-05-14 15:27:20 -07003117
Prashant Malanic92c5962015-08-11 15:10:18 -07003118 ALOGV("%s: enter: out_device(%#x) in_device(%#x) channel_count (%d) channel_mask (0x%x)",
3119 __func__, out_device, in_device, channel_count, channel_mask);
Eric Laurentd1b7a9b2018-11-15 12:24:31 -08003120
Devin Kimd789e432016-10-26 15:07:27 -07003121 if ((out_device != AUDIO_DEVICE_NONE) && (voice_is_in_call(adev) ||
3122 audio_extn_hfp_is_active(adev))) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07003123 if (adev->voice.tty_mode != TTY_MODE_OFF) {
Eric Laurentb23d5282013-05-14 15:27:20 -07003124 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05003125 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
3126 out_device & AUDIO_DEVICE_OUT_LINE) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07003127 switch (adev->voice.tty_mode) {
vivek mehtaa6b79742017-03-09 15:40:43 -08003128 case TTY_MODE_FULL:
3129 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
3130 break;
3131 case TTY_MODE_VCO:
3132 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
3133 break;
3134 case TTY_MODE_HCO:
3135 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
3136 break;
3137 default:
3138 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
3139 }
3140 goto exit;
Eric Laurent99dab492017-06-17 15:19:08 -07003141 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
vivek mehtaa6b79742017-03-09 15:40:43 -08003142 switch (adev->voice.tty_mode) {
3143 case TTY_MODE_FULL:
3144 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC;
3145 break;
3146 case TTY_MODE_VCO:
3147 // since voice will be captured from handset mic, use existing device
3148 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
3149 break;
3150 case TTY_MODE_HCO:
3151 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC;
3152 break;
3153 default:
3154 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
Eric Laurentb23d5282013-05-14 15:27:20 -07003155 }
3156 goto exit;
3157 }
3158 }
Eric Laurentb991fb02014-08-29 15:23:17 -05003159 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07003160 if (my_data->fluence_in_voice_call == false) {
3161 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3162 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003163 if (is_operator_tmus())
3164 snd_device = SND_DEVICE_IN_VOICE_DMIC_TMUS;
Eric Laurentb23d5282013-05-14 15:27:20 -07003165 else
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003166 snd_device = SND_DEVICE_IN_VOICE_DMIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07003167 }
3168 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
3169 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
3170 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003171 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003172 if (adev->bluetooth_nrec)
3173 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
3174 else
3175 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003176 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003177 if (adev->bluetooth_nrec)
3178 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
3179 else
3180 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003181 }
Eric Laurentb991fb02014-08-29 15:23:17 -05003182 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Prashant Malanic92c5962015-08-11 15:10:18 -07003183 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
3184 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
3185 out_device & AUDIO_DEVICE_OUT_LINE) {
3186 if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
3187 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
3188 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
3189 } else {
3190 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
3191 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003192 }
vivek mehtafe121d52015-08-10 23:39:23 -07003193
3194 //select default
3195 if (snd_device == SND_DEVICE_NONE) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07003196 if (!adev->enable_hfp) {
3197 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
3198 } else {
3199 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP;
3200 platform_set_echo_reference(adev, true, out_device);
3201 }
vivek mehtafe121d52015-08-10 23:39:23 -07003202 }
Prashant Malanic92c5962015-08-11 15:10:18 -07003203 } else if (out_device & AUDIO_DEVICE_OUT_TELEPHONY_TX) {
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07003204 snd_device = SND_DEVICE_IN_VOICE_RX;
Eric Laurent99dab492017-06-17 15:19:08 -07003205 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
David Lin40b07892017-08-07 15:02:48 -07003206 if (audio_extn_usb_is_capture_supported()) {
3207 snd_device = SND_DEVICE_IN_VOICE_USB_HEADSET_MIC;
3208 } else if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
3209 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
3210 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
3211 } else {
3212 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
3213 }
3214 }
juyuchend194b432018-11-16 14:15:16 +08003215 } else if (out_device & AUDIO_DEVICE_OUT_HEARING_AID) {
3216 snd_device = SND_DEVICE_IN_VOICE_HEARING_AID;
Prashant Malanic92c5962015-08-11 15:10:18 -07003217 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003218 } else if (source == AUDIO_SOURCE_CAMCORDER) {
3219 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
3220 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Eric Laurent5f4ca952018-10-19 17:33:43 -07003221 switch (adev->camera_orientation) {
3222 case CAMERA_BACK_LANDSCAPE:
3223 snd_device = SND_DEVICE_IN_CAMCORDER_LANDSCAPE;
3224 break;
3225 case CAMERA_BACK_INVERT_LANDSCAPE:
3226 snd_device = SND_DEVICE_IN_CAMCORDER_INVERT_LANDSCAPE;
3227 break;
3228 case CAMERA_BACK_PORTRAIT:
3229 snd_device = SND_DEVICE_IN_CAMCORDER_PORTRAIT;
3230 break;
3231 case CAMERA_FRONT_LANDSCAPE:
3232 snd_device = SND_DEVICE_IN_CAMCORDER_SELFIE_LANDSCAPE;
3233 break;
3234 case CAMERA_FRONT_INVERT_LANDSCAPE:
3235 snd_device = SND_DEVICE_IN_CAMCORDER_SELFIE_INVERT_LANDSCAPE;
3236 break;
3237 case CAMERA_FRONT_PORTRAIT:
3238 snd_device = SND_DEVICE_IN_CAMCORDER_SELFIE_PORTRAIT;
3239 break;
3240 default:
3241 ALOGW("%s: invalid camera orientation %08x", __func__, adev->camera_orientation);
3242 snd_device = SND_DEVICE_IN_CAMCORDER_LANDSCAPE;
3243 break;
3244 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003245 }
3246 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
3247 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003248 if (my_data->fluence_in_voice_rec && channel_count == 1) {
3249 if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
3250 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
Eric Laurentd1b7a9b2018-11-15 12:24:31 -08003251 if (in->enable_aec)
vivek mehta733c1df2016-04-04 15:09:24 -07003252 snd_device = SND_DEVICE_IN_HANDSET_QMIC_AEC;
3253 else
3254 snd_device = SND_DEVICE_IN_HANDSET_QMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003255 } else if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
3256 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
Eric Laurentd1b7a9b2018-11-15 12:24:31 -08003257 if (in->enable_aec)
vivek mehta733c1df2016-04-04 15:09:24 -07003258 snd_device = SND_DEVICE_IN_HANDSET_TMIC_AEC;
3259 else
3260 snd_device = SND_DEVICE_IN_HANDSET_TMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003261 } else if (((my_data->fluence_type == FLUENCE_PRO_ENABLE) ||
3262 (my_data->fluence_type == FLUENCE_ENABLE)) &&
3263 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Eric Laurentd1b7a9b2018-11-15 12:24:31 -08003264 if (in->enable_aec)
vivek mehta733c1df2016-04-04 15:09:24 -07003265 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
3266 else
3267 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
Prashant Malanic92c5962015-08-11 15:10:18 -07003268 }
3269 platform_set_echo_reference(adev, true, out_device);
3270 } else if ((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) &&
3271 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
3272 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003273 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003274 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
3275 snd_device = SND_DEVICE_IN_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003276 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003277 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
3278 snd_device = SND_DEVICE_IN_QUAD_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07003279 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003280 if (snd_device == SND_DEVICE_NONE) {
Eric Laurentd1b7a9b2018-11-15 12:24:31 -08003281 if (in->enable_aec) {
3282 if (in->enable_ns) {
vivek mehtaf3440682016-05-11 14:24:37 -07003283 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS;
3284 } else {
3285 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC;
3286 }
vivek mehta733c1df2016-04-04 15:09:24 -07003287 platform_set_echo_reference(adev, true, out_device);
Eric Laurentd1b7a9b2018-11-15 12:24:31 -08003288 } else if (in->enable_ns) {
vivek mehtaf3440682016-05-11 14:24:37 -07003289 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
3290 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003291 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
vivek mehtaf3440682016-05-11 14:24:37 -07003292 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003293 }
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -07003294 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3295 snd_device = SND_DEVICE_IN_VOICE_REC_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_VOICE_RECOG_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07003298 }
rago90fb9612015-12-02 11:37:53 -08003299 } else if (source == AUDIO_SOURCE_UNPROCESSED) {
3300 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
vivek mehta4ed66e62016-04-15 23:33:34 -07003301 if (((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) ||
3302 (channel_mask == AUDIO_CHANNEL_IN_STEREO)) &&
3303 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
3304 snd_device = SND_DEVICE_IN_UNPROCESSED_STEREO_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003305 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07003306 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
3307 snd_device = SND_DEVICE_IN_UNPROCESSED_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003308 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07003309 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
3310 snd_device = SND_DEVICE_IN_UNPROCESSED_QUAD_MIC;
3311 } else {
3312 snd_device = SND_DEVICE_IN_UNPROCESSED_MIC;
3313 }
rago90fb9612015-12-02 11:37:53 -08003314 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3315 snd_device = SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07003316 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07003317 snd_device = SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC;
rago90fb9612015-12-02 11:37:53 -08003318 }
Eric Laurent50a38ed2015-10-14 18:48:06 -07003319 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION ||
rago90fb9612015-12-02 11:37:53 -08003320 mode == AUDIO_MODE_IN_COMMUNICATION) {
David Lin40b07892017-08-07 15:02:48 -07003321 if (out_device & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
3322 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
3323 (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE | AUDIO_DEVICE_OUT_USB_HEADSET) &&
3324 !audio_extn_usb_is_capture_supported())) {
Eric Laurentb23d5282013-05-14 15:27:20 -07003325 in_device = AUDIO_DEVICE_IN_BACK_MIC;
David Lin40b07892017-08-07 15:02:48 -07003326 }
Vignesh Kulothungan64698822018-01-23 11:25:18 -08003327
Eric Laurentd1b7a9b2018-11-15 12:24:31 -08003328 if (in) {
Vignesh Kulothungan64698822018-01-23 11:25:18 -08003329 snd_device = get_snd_device_for_voice_comm(my_data, in, out_device, in_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07003330 }
3331 } else if (source == AUDIO_SOURCE_DEFAULT) {
3332 goto exit;
3333 }
3334
3335
3336 if (snd_device != SND_DEVICE_NONE) {
3337 goto exit;
3338 }
3339
3340 if (in_device != AUDIO_DEVICE_NONE &&
3341 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
3342 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
3343 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003344 if ((my_data->source_mic_type & SOURCE_QUAD_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003345 channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003346 snd_device = SND_DEVICE_IN_QUAD_MIC;
3347 } else if ((my_data->source_mic_type & SOURCE_THREE_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003348 channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003349 snd_device = SND_DEVICE_IN_THREE_MIC;
3350 } else if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
3351 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003352 snd_device = SND_DEVICE_IN_HANDSET_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07003353 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
3354 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003355 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003356 } else {
3357 ALOGE("%s: something wrong (1): source type (%d) channel_count (%d) .."
3358 " channel mask (0x%x) no combination found .. setting to mono", __func__,
3359 my_data->source_mic_type, channel_count, channel_mask);
3360 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3361 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003362 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003363 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
3364 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003365 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07003366 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
3367 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003368 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003369 } else {
3370 ALOGE("%s: something wrong (2): source type (%d) channel_count (%d) .."
3371 " no combination found .. setting to mono", __func__,
3372 my_data->source_mic_type, channel_count);
3373 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
3374 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003375 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3376 snd_device = SND_DEVICE_IN_HEADSET_MIC;
3377 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003378 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003379 if (adev->bluetooth_nrec)
3380 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
3381 else
3382 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003383 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003384 if (adev->bluetooth_nrec)
3385 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
3386 else
3387 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003388 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003389 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
3390 snd_device = SND_DEVICE_IN_HDMI_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07003391 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
David Linee3fe402017-03-13 10:00:42 -07003392 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07003393 } else {
3394 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
3395 ALOGW("%s: Using default handset-mic", __func__);
3396 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3397 }
3398 } else {
3399 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
3400 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3401 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
3402 snd_device = SND_DEVICE_IN_HEADSET_MIC;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003403 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07003404 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003405 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05003406 out_device & AUDIO_DEVICE_OUT_LINE) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003407 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
3408 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003409 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07003410 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
3411 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003412 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003413 } else {
3414 ALOGE("%s: something wrong (3): source type (%d) channel_count (%d) .."
3415 " no combination found .. setting to mono", __func__,
3416 my_data->source_mic_type, channel_count);
3417 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
3418 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003419 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003420 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003421 if (adev->bluetooth_nrec)
3422 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
3423 else
3424 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003425 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003426 if (adev->bluetooth_nrec)
3427 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
3428 else
3429 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003430 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003431 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
3432 snd_device = SND_DEVICE_IN_HDMI_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07003433 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
David Linee3fe402017-03-13 10:00:42 -07003434 if (audio_extn_usb_is_capture_supported())
3435 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
3436 else
3437 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07003438 } else {
3439 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
3440 ALOGW("%s: Using default handset-mic", __func__);
3441 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3442 }
3443 }
3444exit:
3445 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
3446 return snd_device;
3447}
3448
3449int platform_set_hdmi_channels(void *platform, int channel_count)
3450{
3451 struct platform_data *my_data = (struct platform_data *)platform;
3452 struct audio_device *adev = my_data->adev;
3453 struct mixer_ctl *ctl;
3454 const char *channel_cnt_str = NULL;
3455 const char *mixer_ctl_name = "HDMI_RX Channels";
3456 switch (channel_count) {
3457 case 8:
3458 channel_cnt_str = "Eight"; break;
3459 case 7:
3460 channel_cnt_str = "Seven"; break;
3461 case 6:
3462 channel_cnt_str = "Six"; break;
3463 case 5:
3464 channel_cnt_str = "Five"; break;
3465 case 4:
3466 channel_cnt_str = "Four"; break;
3467 case 3:
3468 channel_cnt_str = "Three"; break;
3469 default:
3470 channel_cnt_str = "Two"; break;
3471 }
3472 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3473 if (!ctl) {
3474 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3475 __func__, mixer_ctl_name);
3476 return -EINVAL;
3477 }
3478 ALOGV("HDMI channel count: %s", channel_cnt_str);
3479 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
3480 return 0;
3481}
3482
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003483int platform_edid_get_max_channels(void *platform)
Eric Laurentb23d5282013-05-14 15:27:20 -07003484{
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003485 struct platform_data *my_data = (struct platform_data *)platform;
3486 struct audio_device *adev = my_data->adev;
Eric Laurentb23d5282013-05-14 15:27:20 -07003487 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
3488 char *sad = block;
3489 int num_audio_blocks;
3490 int channel_count;
3491 int max_channels = 0;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003492 int i, ret, count;
Eric Laurentb23d5282013-05-14 15:27:20 -07003493
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003494 struct mixer_ctl *ctl;
3495
3496 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
3497 if (!ctl) {
3498 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3499 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
Eric Laurentb23d5282013-05-14 15:27:20 -07003500 return 0;
3501 }
3502
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003503 mixer_ctl_update(ctl);
3504
3505 count = mixer_ctl_get_num_values(ctl);
Eric Laurentb23d5282013-05-14 15:27:20 -07003506
3507 /* Read SAD blocks, clamping the maximum size for safety */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003508 if (count > (int)sizeof(block))
3509 count = (int)sizeof(block);
Eric Laurentb23d5282013-05-14 15:27:20 -07003510
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003511 ret = mixer_ctl_get_array(ctl, block, count);
3512 if (ret != 0) {
3513 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
3514 return 0;
3515 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003516
3517 /* Calculate the number of SAD blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003518 num_audio_blocks = count / SAD_BLOCK_SIZE;
Eric Laurentb23d5282013-05-14 15:27:20 -07003519
3520 for (i = 0; i < num_audio_blocks; i++) {
3521 /* Only consider LPCM blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003522 if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
3523 sad += 3;
Eric Laurentb23d5282013-05-14 15:27:20 -07003524 continue;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003525 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003526
3527 channel_count = (sad[0] & 0x7) + 1;
3528 if (channel_count > max_channels)
3529 max_channels = channel_count;
3530
3531 /* Advance to next block */
3532 sad += 3;
3533 }
3534
3535 return max_channels;
3536}
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003537
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07003538int platform_set_incall_recording_session_id(void *platform,
3539 uint32_t session_id, int rec_mode)
3540{
3541 int ret = 0;
3542 struct platform_data *my_data = (struct platform_data *)platform;
3543 struct audio_device *adev = my_data->adev;
3544 struct mixer_ctl *ctl;
3545 const char *mixer_ctl_name = "Voc VSID";
3546 int num_ctl_values;
3547 int i;
3548
3549 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3550 if (!ctl) {
3551 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3552 __func__, mixer_ctl_name);
3553 ret = -EINVAL;
3554 } else {
3555 num_ctl_values = mixer_ctl_get_num_values(ctl);
3556 for (i = 0; i < num_ctl_values; i++) {
3557 if (mixer_ctl_set_value(ctl, i, session_id)) {
3558 ALOGV("Error: invalid session_id: %x", session_id);
3559 ret = -EINVAL;
3560 break;
3561 }
3562 }
3563 }
3564
3565 if (my_data->csd != NULL) {
3566 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
3567 if (ret < 0) {
3568 ALOGE("%s: csd_client_start_record failed, error %d",
3569 __func__, ret);
3570 }
3571 }
3572
3573 return ret;
3574}
3575
Arun Mirpuriba2749a2018-04-17 14:32:24 -07003576int platform_set_incall_recording_session_channels(void *platform,
3577 uint32_t channel_count)
3578{
3579 int ret = 0;
3580 struct platform_data *my_data = (struct platform_data *)platform;
3581 struct audio_device *adev = my_data->adev;
3582 const char *mixer_ctl_name = "Voc Rec Config";
3583 int num_ctl_values;
3584 int i;
3585 struct mixer_ctl *ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3586
3587 if (!ctl) {
3588 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3589 __func__, mixer_ctl_name);
3590 ret = -EINVAL;
3591 } else {
3592 num_ctl_values = mixer_ctl_get_num_values(ctl);
3593 for (i = 0; i < num_ctl_values; i++) {
3594 if (mixer_ctl_set_value(ctl, i, channel_count)) {
3595 ALOGE("Error: invalid channel count: %x", channel_count);
3596 ret = -EINVAL;
3597 break;
3598 }
3599 }
3600 }
3601
3602 return ret;
3603}
3604
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07003605int platform_stop_incall_recording_usecase(void *platform)
3606{
3607 int ret = 0;
3608 struct platform_data *my_data = (struct platform_data *)platform;
3609
3610 if (my_data->csd != NULL) {
3611 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
3612 if (ret < 0) {
3613 ALOGE("%s: csd_client_stop_record failed, error %d",
3614 __func__, ret);
3615 }
3616 }
3617
3618 return ret;
3619}
3620
3621int platform_start_incall_music_usecase(void *platform)
3622{
3623 int ret = 0;
3624 struct platform_data *my_data = (struct platform_data *)platform;
3625
3626 if (my_data->csd != NULL) {
3627 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
3628 if (ret < 0) {
3629 ALOGE("%s: csd_client_start_playback failed, error %d",
3630 __func__, ret);
3631 }
3632 }
3633
3634 return ret;
3635}
3636
3637int platform_stop_incall_music_usecase(void *platform)
3638{
3639 int ret = 0;
3640 struct platform_data *my_data = (struct platform_data *)platform;
3641
3642 if (my_data->csd != NULL) {
3643 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
3644 if (ret < 0) {
3645 ALOGE("%s: csd_client_stop_playback failed, error %d",
3646 __func__, ret);
3647 }
3648 }
3649
3650 return ret;
3651}
3652
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003653int platform_set_parameters(void *platform, struct str_parms *parms)
3654{
3655 struct platform_data *my_data = (struct platform_data *)platform;
jasmine chac89321b2018-04-10 21:37:01 +08003656 char *value = NULL;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003657 char *kv_pairs = str_parms_to_str(parms);
jasmine chac89321b2018-04-10 21:37:01 +08003658 int len;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003659 int ret = 0, err;
3660
3661 if (kv_pairs == NULL) {
3662 ret = -EINVAL;
Jasmine Chaa314e192018-05-09 17:46:28 +08003663 ALOGE("%s: key-value pair is NULL", __func__);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003664 goto done;
3665 }
3666
3667 ALOGV("%s: enter: %s", __func__, kv_pairs);
3668
jasmine chac89321b2018-04-10 21:37:01 +08003669 len = strlen(kv_pairs);
Jasmine Chaa314e192018-05-09 17:46:28 +08003670 value = (char*)calloc(len + 1, sizeof(char));
jasmine chac89321b2018-04-10 21:37:01 +08003671 if (value == NULL) {
3672 ret = -ENOMEM;
Jasmine Chaa314e192018-05-09 17:46:28 +08003673 ALOGE("[%s] failed to allocate memory", __func__);
jasmine chac89321b2018-04-10 21:37:01 +08003674 goto done;
3675 }
3676
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003677 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME,
jasmine chac89321b2018-04-10 21:37:01 +08003678 value, len);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003679 if (err >= 0) {
3680 str_parms_del(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME);
3681 my_data->snd_card_name = strdup(value);
3682 ALOGV("%s: sound card name %s", __func__, my_data->snd_card_name);
3683 }
3684
keunhui.park2f7306a2015-07-16 16:48:06 +09003685 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO,
jasmine chac89321b2018-04-10 21:37:01 +08003686 value, len);
keunhui.park2f7306a2015-07-16 16:48:06 +09003687 if (err >= 0) {
3688 struct operator_info *info;
3689 char *str = value;
3690 char *name;
3691
3692 str_parms_del(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO);
3693 info = (struct operator_info *)calloc(1, sizeof(struct operator_info));
3694 name = strtok(str, ";");
3695 info->name = strdup(name);
3696 info->mccmnc = strdup(str + strlen(name) + 1);
3697
3698 list_add_tail(&operator_info_list, &info->list);
Joe Onorato188b6222016-03-01 11:02:27 -08003699 ALOGV("%s: add operator[%s] mccmnc[%s]", __func__, info->name, info->mccmnc);
keunhui.park2f7306a2015-07-16 16:48:06 +09003700 }
Prashant Malanic92c5962015-08-11 15:10:18 -07003701
Jasmine Chaa314e192018-05-09 17:46:28 +08003702 memset(value, 0, len + 1);
Eric Laurentc6333382015-09-14 12:43:44 -07003703 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT,
jasmine chac89321b2018-04-10 21:37:01 +08003704 value, len);
Prashant Malanic92c5962015-08-11 15:10:18 -07003705 if (err >= 0) {
Eric Laurentc6333382015-09-14 12:43:44 -07003706 str_parms_del(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT);
Prashant Malanic92c5962015-08-11 15:10:18 -07003707 my_data->max_mic_count = atoi(value);
3708 ALOGV("%s: max_mic_count %s/%d", __func__, value, my_data->max_mic_count);
Prashant Malanic92c5962015-08-11 15:10:18 -07003709 }
3710
jasmine chac89321b2018-04-10 21:37:01 +08003711 /* handle audio calibration parameters */
3712 set_audiocal(platform, parms, value, len);
3713
vivek mehta90933872017-06-15 18:04:39 -07003714 // to-do: disable setting sidetone gain, will revist this later
3715 // audio_extn_usb_set_sidetone_gain(parms, value, len);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003716done:
3717 ALOGV("%s: exit with code(%d)", __func__, ret);
3718 if (kv_pairs != NULL)
3719 free(kv_pairs);
jasmine chac89321b2018-04-10 21:37:01 +08003720 if (value != NULL)
3721 free(value);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003722
3723 return ret;
3724}
3725
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003726/* Delay in Us */
3727int64_t platform_render_latency(audio_usecase_t usecase)
3728{
3729 switch (usecase) {
3730 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
3731 return DEEP_BUFFER_PLATFORM_DELAY;
3732 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
Vignesh Kulothungan019d19b2019-01-23 11:09:18 -08003733 case USECASE_AUDIO_PLAYBACK_WITH_HAPTICS:
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003734 return LOW_LATENCY_PLATFORM_DELAY;
Haynes Mathew George03c40102016-01-29 17:57:48 -08003735 case USECASE_AUDIO_PLAYBACK_ULL:
3736 return ULL_PLATFORM_DELAY;
Eric Laurent0e46adf2016-12-16 12:49:24 -08003737 case USECASE_AUDIO_PLAYBACK_MMAP:
3738 return MMAP_PLATFORM_DELAY;
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003739 default:
3740 return 0;
3741 }
3742}
Haynes Mathew George98c95622014-06-20 19:14:25 -07003743
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003744int platform_set_snd_device_backend(snd_device_t device, const char *backend_tag,
3745 const char * hw_interface)
Haynes Mathew George98c95622014-06-20 19:14:25 -07003746{
3747 int ret = 0;
3748
3749 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
3750 ALOGE("%s: Invalid snd_device = %d",
3751 __func__, device);
3752 ret = -EINVAL;
3753 goto done;
3754 }
3755
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003756 ALOGV("%s: backend_tag_table[%s]: old = %s new = %s", __func__,
3757 platform_get_snd_device_name(device),
3758 backend_tag_table[device] != NULL ? backend_tag_table[device]: "null", backend_tag);
3759 if (backend_tag_table[device]) {
3760 free(backend_tag_table[device]);
Haynes Mathew George98c95622014-06-20 19:14:25 -07003761 }
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003762 backend_tag_table[device] = strdup(backend_tag);
3763
3764 if (hw_interface != NULL) {
3765 if (hw_interface_table[device])
3766 free(hw_interface_table[device]);
3767 ALOGV("%s: hw_interface_table[%d] = %s", __func__, device, hw_interface);
3768 hw_interface_table[device] = strdup(hw_interface);
3769 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07003770done:
3771 return ret;
3772}
3773
3774int platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t pcm_id)
3775{
3776 int ret = 0;
3777 if ((usecase <= USECASE_INVALID) || (usecase >= AUDIO_USECASE_MAX)) {
3778 ALOGE("%s: invalid usecase case idx %d", __func__, usecase);
3779 ret = -EINVAL;
3780 goto done;
3781 }
3782
3783 if ((type != 0) && (type != 1)) {
3784 ALOGE("%s: invalid usecase type", __func__);
3785 ret = -EINVAL;
3786 }
vivek mehtaa68fea62017-06-08 19:04:02 -07003787 ALOGV("%s: pcm_device_table[%d %s][%d] = %d", __func__, usecase,
3788 use_case_table[usecase],
3789 type, pcm_id);
Haynes Mathew George98c95622014-06-20 19:14:25 -07003790 pcm_device_table[usecase][type] = pcm_id;
3791done:
3792 return ret;
3793}
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003794
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07003795#define DEFAULT_NOMINAL_SPEAKER_GAIN 20
3796int ramp_speaker_gain(struct audio_device *adev, bool ramp_up, int target_ramp_up_gain) {
3797 // backup_gain: gain to try to set in case of an error during ramp
3798 int start_gain, end_gain, step, backup_gain, i;
3799 bool error = false;
3800 const struct mixer_ctl *ctl;
3801 const char *mixer_ctl_name_gain_left = "Left Speaker Gain";
3802 const char *mixer_ctl_name_gain_right = "Right Speaker Gain";
3803 struct mixer_ctl *ctl_left = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_left);
3804 struct mixer_ctl *ctl_right = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_right);
3805 if (!ctl_left || !ctl_right) {
3806 ALOGE("%s: Could not get ctl for mixer cmd - %s or %s, not applying speaker gain ramp",
3807 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
3808 return -EINVAL;
3809 } else if ((mixer_ctl_get_num_values(ctl_left) != 1)
3810 || (mixer_ctl_get_num_values(ctl_right) != 1)) {
3811 ALOGE("%s: Unexpected num values for mixer cmd - %s or %s, not applying speaker gain ramp",
3812 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
3813 return -EINVAL;
3814 }
3815 if (ramp_up) {
3816 start_gain = 0;
3817 end_gain = target_ramp_up_gain > 0 ? target_ramp_up_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
3818 step = +1;
3819 backup_gain = end_gain;
3820 } else {
3821 // using same gain on left and right
3822 const int left_gain = mixer_ctl_get_value(ctl_left, 0);
3823 start_gain = left_gain > 0 ? left_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
3824 end_gain = 0;
3825 step = -1;
3826 backup_gain = start_gain;
3827 }
3828 for (i = start_gain ; i != (end_gain + step) ; i += step) {
3829 //ALOGV("setting speaker gain to %d", i);
3830 if (mixer_ctl_set_value(ctl_left, 0, i)) {
3831 ALOGE("%s: error setting %s to %d during gain ramp",
3832 __func__, mixer_ctl_name_gain_left, i);
3833 error = true;
3834 break;
3835 }
3836 if (mixer_ctl_set_value(ctl_right, 0, i)) {
3837 ALOGE("%s: error setting %s to %d during gain ramp",
3838 __func__, mixer_ctl_name_gain_right, i);
3839 error = true;
3840 break;
3841 }
3842 usleep(1000);
3843 }
3844 if (error) {
3845 // an error occured during the ramp, let's still try to go back to a safe volume
3846 if (mixer_ctl_set_value(ctl_left, 0, backup_gain)) {
3847 ALOGE("%s: error restoring left gain to %d", __func__, backup_gain);
3848 }
3849 if (mixer_ctl_set_value(ctl_right, 0, backup_gain)) {
3850 ALOGE("%s: error restoring right gain to %d", __func__, backup_gain);
3851 }
3852 }
3853 return start_gain;
3854}
3855
vivek mehtae59cfb22017-06-16 15:57:11 -07003856int platform_set_swap_mixer(struct audio_device *adev, bool swap_channels)
3857{
3858 const char *mixer_ctl_name = "Swap channel";
3859 struct mixer_ctl *ctl;
3860 const char *mixer_path;
3861 struct platform_data *my_data = (struct platform_data *)adev->platform;
3862
3863 // forced to set to swap, but device not rotated ... ignore set
3864 if (swap_channels && !my_data->speaker_lr_swap)
3865 return 0;
3866
3867 ALOGV("%s:", __func__);
3868
3869 if (swap_channels) {
3870 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER_REVERSE);
3871 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
3872 } else {
3873 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER);
3874 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
3875 }
3876
3877 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3878 if (!ctl) {
3879 ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name);
3880 return -EINVAL;
3881 }
3882
3883 if (mixer_ctl_set_value(ctl, 0, swap_channels) < 0) {
3884 ALOGE("%s: Could not set reverse cotrol %d",__func__, swap_channels);
3885 return -EINVAL;
3886 }
3887
3888 ALOGV("platfor_force_swap_channel :: Channel orientation ( %s ) ",
3889 swap_channels?"R --> L":"L --> R");
3890
3891 return 0;
3892}
3893
3894int platform_check_and_set_swap_lr_channels(struct audio_device *adev, bool swap_channels)
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003895{
3896 // only update if there is active pcm playback on speaker
3897 struct audio_usecase *usecase;
3898 struct listnode *node;
3899 struct platform_data *my_data = (struct platform_data *)adev->platform;
3900
vivek mehtae59cfb22017-06-16 15:57:11 -07003901 my_data->speaker_lr_swap = swap_channels;
Jean-Michel Trivif7148702016-09-16 18:23:05 -07003902
vivek mehtae59cfb22017-06-16 15:57:11 -07003903 return platform_set_swap_channels(adev, swap_channels);
3904}
Jean-Michel Trivif7148702016-09-16 18:23:05 -07003905
vivek mehtae59cfb22017-06-16 15:57:11 -07003906int platform_set_swap_channels(struct audio_device *adev, bool swap_channels)
3907{
3908 // only update if there is active pcm playback on speaker
3909 struct audio_usecase *usecase;
3910 struct listnode *node;
3911 struct platform_data *my_data = (struct platform_data *)adev->platform;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003912
vivek mehtae59cfb22017-06-16 15:57:11 -07003913 // do not swap channels in audio modes with concurrent capture and playback
3914 // as this may break the echo reference
3915 if ((adev->mode == AUDIO_MODE_IN_COMMUNICATION) || (adev->mode == AUDIO_MODE_IN_CALL)) {
3916 ALOGV("%s: will not swap due to audio mode %d", __func__, adev->mode);
3917 return 0;
3918 }
3919
3920 list_for_each(node, &adev->usecase_list) {
3921 usecase = node_to_item(node, struct audio_usecase, list);
3922 if (usecase->type == PCM_PLAYBACK &&
3923 usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) {
3924 /*
3925 * If acdb tuning is different for SPEAKER_REVERSE, it is must
3926 * to perform device switch to disable the current backend to
3927 * enable it with new acdb data.
3928 */
3929 if (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
3930 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]) {
3931 const int initial_skpr_gain = ramp_speaker_gain(adev, false /*ramp_up*/, -1);
3932 select_devices(adev, usecase->id);
3933 if (initial_skpr_gain != -EINVAL)
3934 ramp_speaker_gain(adev, true /*ramp_up*/, initial_skpr_gain);
3935
3936 } else {
3937 platform_set_swap_mixer(adev, swap_channels);
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003938 }
vivek mehtae59cfb22017-06-16 15:57:11 -07003939 break;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003940 }
3941 }
vivek mehtae59cfb22017-06-16 15:57:11 -07003942
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003943 return 0;
3944}
vivek mehtaa8d7c922016-05-25 14:40:44 -07003945
3946static struct amp_db_and_gain_table tbl_mapping[MAX_VOLUME_CAL_STEPS];
3947static int num_gain_tbl_entry = 0;
3948
3949bool platform_add_gain_level_mapping(struct amp_db_and_gain_table *tbl_entry) {
3950
3951 ALOGV("%s: enter .. add %f %f %d", __func__, tbl_entry->amp, tbl_entry->db, tbl_entry->level);
3952 if (num_gain_tbl_entry == -1) {
3953 ALOGE("%s: num entry beyond valid step levels or corrupted..rejecting custom mapping",
3954 __func__);
3955 return false;
3956 }
3957
3958 if (num_gain_tbl_entry >= MAX_VOLUME_CAL_STEPS) {
3959 ALOGE("%s: max entry reached max[%d] current index[%d] .. rejecting", __func__,
3960 MAX_VOLUME_CAL_STEPS, num_gain_tbl_entry);
3961 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
3962 return false;
3963 }
3964
3965 if (num_gain_tbl_entry > 0 && tbl_mapping[num_gain_tbl_entry - 1].amp >= tbl_entry->amp) {
3966 ALOGE("%s: value not in ascending order .. rejecting custom mapping", __func__);
3967 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
3968 return false;
3969 }
3970
3971 tbl_mapping[num_gain_tbl_entry] = *tbl_entry;
3972 ++num_gain_tbl_entry;
3973
3974 return true;
3975}
3976
3977int platform_get_gain_level_mapping(struct amp_db_and_gain_table *mapping_tbl,
3978 int table_size) {
3979 int itt = 0;
3980 ALOGV("platform_get_gain_level_mapping called ");
3981
3982 if (num_gain_tbl_entry <= 0 || num_gain_tbl_entry > MAX_VOLUME_CAL_STEPS) {
3983 ALOGD("%s: empty or currupted gain_mapping_table", __func__);
3984 return 0;
3985 }
3986
3987 for (; itt < num_gain_tbl_entry && itt <= table_size; itt++) {
3988 mapping_tbl[itt] = tbl_mapping[itt];
3989 ALOGV("%s: added amp[%f] db[%f] level[%d]", __func__,
3990 mapping_tbl[itt].amp, mapping_tbl[itt].db, mapping_tbl[itt].level);
3991 }
3992
3993 return num_gain_tbl_entry;
3994}
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07003995
3996int platform_snd_card_update(void *platform, card_status_t status)
3997{
3998 struct platform_data *my_data = (struct platform_data *)platform;
3999 struct audio_device *adev = my_data->adev;
4000
4001 if (status == CARD_STATUS_ONLINE) {
4002 if (my_data->acdb_send_custom_top)
4003 my_data->acdb_send_custom_top();
4004 }
4005 return 0;
4006}
David Linee3fe402017-03-13 10:00:42 -07004007
4008/*
4009 * configures afe with bit width and Sample Rate
4010 */
Haynes Mathew George65f6b432018-02-27 17:44:55 -08004011int platform_set_backend_cfg(const struct audio_device* adev,
4012 snd_device_t snd_device,
4013 const struct audio_backend_cfg *backend_cfg)
David Linee3fe402017-03-13 10:00:42 -07004014{
4015
4016 int ret = 0;
4017 const int backend_idx = platform_get_backend_index(snd_device);
4018 struct platform_data *my_data = (struct platform_data *)adev->platform;
4019 const unsigned int bit_width = backend_cfg->bit_width;
4020 const unsigned int sample_rate = backend_cfg->sample_rate;
4021 const unsigned int channels = backend_cfg->channels;
4022 const audio_format_t format = backend_cfg->format;
4023 const bool passthrough_enabled = backend_cfg->passthrough_enabled;
4024
4025
4026 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
4027 ", backend_idx %d device (%s)", __func__, bit_width,
4028 sample_rate, channels, backend_idx,
4029 platform_get_snd_device_name(snd_device));
4030
4031 if ((my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl) &&
4032 (bit_width != my_data->current_backend_cfg[backend_idx].bit_width)) {
4033
4034 struct mixer_ctl *ctl = NULL;
4035 ctl = mixer_get_ctl_by_name(adev->mixer,
4036 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
4037 if (!ctl) {
4038 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
4039 __func__,
4040 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
4041 return -EINVAL;
4042 }
4043
4044 if (bit_width == 24) {
4045 if (format == AUDIO_FORMAT_PCM_24_BIT_PACKED)
4046 ret = mixer_ctl_set_enum_by_string(ctl, "S24_3LE");
4047 else
4048 ret = mixer_ctl_set_enum_by_string(ctl, "S24_LE");
4049 } else if (bit_width == 32) {
4050 ret = mixer_ctl_set_enum_by_string(ctl, "S32_LE");
4051 } else {
4052 ret = mixer_ctl_set_enum_by_string(ctl, "S16_LE");
4053 }
4054 if ( ret < 0) {
4055 ALOGE("%s:becf: afe: fail for %s mixer set to %d bit for %x format", __func__,
4056 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
4057 } else {
4058 my_data->current_backend_cfg[backend_idx].bit_width = bit_width;
4059 ALOGD("%s:becf: afe: %s mixer set to %d bit for %x format", __func__,
4060 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
4061 }
4062 /* set the ret as 0 and not pass back to upper layer */
4063 ret = 0;
4064 }
4065
4066 if (passthrough_enabled || ((my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl) &&
4067 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate))) {
4068 char *rate_str = NULL;
4069 struct mixer_ctl *ctl = NULL;
4070
4071 switch (sample_rate) {
4072 case 32000:
4073 if (passthrough_enabled) {
4074 rate_str = "KHZ_32";
4075 break;
4076 }
4077 case 8000:
4078 case 11025:
4079 case 16000:
4080 case 22050:
4081 case 48000:
4082 rate_str = "KHZ_48";
4083 break;
4084 case 44100:
4085 rate_str = "KHZ_44P1";
4086 break;
4087 case 64000:
4088 case 96000:
4089 rate_str = "KHZ_96";
4090 break;
4091 case 88200:
4092 rate_str = "KHZ_88P2";
4093 break;
4094 case 176400:
4095 rate_str = "KHZ_176P4";
4096 break;
4097 case 192000:
4098 rate_str = "KHZ_192";
4099 break;
4100 case 352800:
4101 rate_str = "KHZ_352P8";
4102 break;
4103 case 384000:
4104 rate_str = "KHZ_384";
4105 break;
4106 case 144000:
4107 if (passthrough_enabled) {
4108 rate_str = "KHZ_144";
4109 break;
4110 }
4111 default:
4112 rate_str = "KHZ_48";
4113 break;
4114 }
4115
4116 ctl = mixer_get_ctl_by_name(adev->mixer,
4117 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
4118 if(!ctl) {
4119 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
4120 __func__,
4121 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
4122 return -EINVAL;
4123 }
4124
4125 ALOGD("%s:becf: afe: %s set to %s", __func__,
4126 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl, rate_str);
4127 mixer_ctl_set_enum_by_string(ctl, rate_str);
4128 my_data->current_backend_cfg[backend_idx].sample_rate = sample_rate;
4129 }
4130 if ((my_data->current_backend_cfg[backend_idx].channels_mixer_ctl) &&
4131 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
4132 struct mixer_ctl *ctl = NULL;
4133 char *channel_cnt_str = NULL;
4134
4135 switch (channels) {
4136 case 8:
4137 channel_cnt_str = "Eight"; break;
4138 case 7:
4139 channel_cnt_str = "Seven"; break;
4140 case 6:
4141 channel_cnt_str = "Six"; break;
4142 case 5:
4143 channel_cnt_str = "Five"; break;
4144 case 4:
4145 channel_cnt_str = "Four"; break;
4146 case 3:
4147 channel_cnt_str = "Three"; break;
4148 case 1:
4149 channel_cnt_str = "One"; break;
4150 case 2:
4151 default:
4152 channel_cnt_str = "Two"; break;
4153 }
4154
4155 ctl = mixer_get_ctl_by_name(adev->mixer,
4156 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
4157 if (!ctl) {
4158 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
4159 __func__,
4160 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
4161 return -EINVAL;
4162 }
4163 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
4164 my_data->current_backend_cfg[backend_idx].channels = channels;
4165
4166 // skip EDID configuration for HDMI backend
4167
4168 ALOGD("%s:becf: afe: %s set to %s", __func__,
4169 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl,
4170 channel_cnt_str);
4171 }
4172
4173 // skip set ext_display format mixer control
4174 return ret;
4175}
4176
4177static int platform_get_snd_device_bit_width(snd_device_t snd_device)
4178{
4179 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
4180 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
4181 return CODEC_BACKEND_DEFAULT_BIT_WIDTH;
4182 }
4183
4184 return backend_bit_width_table[snd_device];
4185}
4186
4187/*
4188 * return backend_idx on which voice call is active
4189 */
4190static int platform_get_voice_call_backend(struct audio_device* adev)
4191{
4192 struct audio_usecase *uc = NULL;
4193 struct listnode *node;
4194 snd_device_t out_snd_device = SND_DEVICE_NONE;
4195
4196 int backend_idx = -1;
4197
4198 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
4199 list_for_each(node, &adev->usecase_list) {
4200 uc = node_to_item(node, struct audio_usecase, list);
4201 if (uc && uc->type == VOICE_CALL && uc->stream.out) {
4202 out_snd_device = platform_get_output_snd_device(adev->platform,
4203 uc->stream.out->devices);
4204 backend_idx = platform_get_backend_index(out_snd_device);
4205 break;
4206 }
4207 }
4208 }
4209 return backend_idx;
4210}
4211
4212/*
4213 * goes through all the current usecases and picks the highest
4214 * bitwidth & samplerate
4215 */
4216static bool platform_check_capture_backend_cfg(struct audio_device* adev,
4217 int backend_idx,
4218 struct audio_backend_cfg *backend_cfg)
4219{
4220 bool backend_change = false;
4221 unsigned int bit_width;
4222 unsigned int sample_rate;
4223 unsigned int channels;
4224 struct platform_data *my_data = (struct platform_data *)adev->platform;
4225
4226 bit_width = backend_cfg->bit_width;
4227 sample_rate = backend_cfg->sample_rate;
4228 channels = backend_cfg->channels;
4229
4230 ALOGV("%s:txbecf: afe: Codec selected backend: %d current bit width: %d and "
4231 "sample rate: %d, channels %d",__func__,backend_idx, bit_width,
4232 sample_rate, channels);
4233
4234 // For voice calls use default configuration i.e. 16b/48K, only applicable to
4235 // default backend
4236 // force routing is not required here, caller will do it anyway
4237 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
4238 ALOGW("%s:txbecf: afe: Use default bw and sr for voice/voip calls and "
4239 "for unprocessed/camera source", __func__);
4240 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
4241 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4242 }
4243
4244 if (backend_idx == USB_AUDIO_TX_BACKEND) {
4245 audio_extn_usb_is_config_supported(&bit_width, &sample_rate, &channels, false);
4246 ALOGV("%s:txbecf: afe: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
4247 __func__, bit_width, sample_rate, channels);
4248 }
4249
4250 ALOGV("%s:txbecf: afe: Codec selected backend: %d updated bit width: %d and "
4251 "sample rate: %d", __func__, backend_idx, bit_width, sample_rate);
4252
4253 // Force routing if the expected bitwdith or samplerate
4254 // is not same as current backend comfiguration
4255 if ((bit_width != my_data->current_backend_cfg[backend_idx].bit_width) ||
4256 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate) ||
4257 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
4258 backend_cfg->bit_width = bit_width;
4259 backend_cfg->sample_rate= sample_rate;
4260 backend_cfg->channels = channels;
4261 backend_change = true;
4262 ALOGI("%s:txbecf: afe: Codec backend needs to be updated. new bit width: %d "
4263 "new sample rate: %d new channel: %d",
4264 __func__, backend_cfg->bit_width,
4265 backend_cfg->sample_rate, backend_cfg->channels);
4266 }
4267
4268 return backend_change;
4269}
4270
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004271static void pick_playback_cfg_for_uc(struct audio_device *adev,
4272 struct audio_usecase *usecase,
4273 snd_device_t snd_device,
4274 unsigned int *bit_width,
4275 unsigned int *sample_rate,
4276 unsigned int *channels)
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004277{
4278 int i =0;
4279 struct listnode *node;
4280 list_for_each(node, &adev->usecase_list) {
4281 struct audio_usecase *uc;
4282 uc = node_to_item(node, struct audio_usecase, list);
4283 struct stream_out *out = (struct stream_out*) uc->stream.out;
4284 if (uc->type == PCM_PLAYBACK && out && usecase != uc) {
4285 unsigned int out_channels = audio_channel_count_from_out_mask(out->channel_mask);
4286 ALOGV("%s:napb: (%d) - (%s)id (%d) sr %d bw "
4287 "(%d) ch (%d) device %s", __func__, i++, use_case_table[uc->id],
4288 uc->id, out->sample_rate,
4289 pcm_format_to_bits(out->config.format), out_channels,
4290 platform_get_snd_device_name(uc->out_snd_device));
4291
4292 if (platform_check_backends_match(snd_device, uc->out_snd_device)) {
4293 if (*bit_width < pcm_format_to_bits(out->config.format))
4294 *bit_width = pcm_format_to_bits(out->config.format);
4295 if (*sample_rate < out->sample_rate)
4296 *sample_rate = out->sample_rate;
4297 if (out->sample_rate < OUTPUT_SAMPLING_RATE_44100)
4298 *sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4299 if (*channels < out_channels)
4300 *channels = out_channels;
4301 }
4302 }
4303 }
4304 return;
4305}
4306
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004307static void headset_is_config_supported(unsigned int *bit_width,
4308 unsigned int *sample_rate,
4309 unsigned int *channels) {
4310 switch (*bit_width) {
4311 case 16:
4312 case 24:
4313 break;
4314 default:
4315 *bit_width = 16;
4316 break;
4317 }
4318
4319 if (*sample_rate > 192000) {
4320 *sample_rate = 192000;
4321 }
4322
4323 if (*channels > 2) {
4324 *channels = 2;
4325 }
4326}
4327
David Linee3fe402017-03-13 10:00:42 -07004328static bool platform_check_playback_backend_cfg(struct audio_device* adev,
4329 struct audio_usecase* usecase,
4330 snd_device_t snd_device,
4331 struct audio_backend_cfg *backend_cfg)
4332{
4333 bool backend_change = false;
David Linee3fe402017-03-13 10:00:42 -07004334 unsigned int bit_width;
4335 unsigned int sample_rate;
4336 unsigned int channels;
David Linee3fe402017-03-13 10:00:42 -07004337 int backend_idx = DEFAULT_CODEC_BACKEND;
Haynes Mathew George65f6b432018-02-27 17:44:55 -08004338 unsigned long service_interval = 0; // 0 is invalid
David Linee3fe402017-03-13 10:00:42 -07004339 struct platform_data *my_data = (struct platform_data *)adev->platform;
David Linee3fe402017-03-13 10:00:42 -07004340
4341 if (snd_device == SND_DEVICE_OUT_BT_SCO ||
4342 snd_device == SND_DEVICE_OUT_BT_SCO_WB) {
4343 backend_change = false;
4344 return backend_change;
4345 }
4346
4347 backend_idx = platform_get_backend_index(snd_device);
4348 bit_width = backend_cfg->bit_width;
4349 sample_rate = backend_cfg->sample_rate;
4350 channels = backend_cfg->channels;
4351
4352 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
4353 ", backend_idx %d usecase = %d device (%s)", __func__, bit_width,
4354 sample_rate, channels, backend_idx, usecase->id,
4355 platform_get_snd_device_name(snd_device));
4356
4357 if (backend_idx == platform_get_voice_call_backend(adev)) {
4358 ALOGW("%s:becf: afe:Use default bw and sr for voice/voip calls ",
4359 __func__);
4360 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
4361 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4362 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
4363 } else {
4364 /*
4365 * The backend should be configured at highest bit width and/or
4366 * sample rate amongst all playback usecases.
4367 * If the selected sample rate and/or bit width differ with
4368 * current backend sample rate and/or bit width, then, we set the
4369 * backend re-configuration flag.
4370 *
4371 * Exception: 16 bit playbacks is allowed through 16 bit/48/44.1 khz backend only
4372 */
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004373 pick_playback_cfg_for_uc(adev, usecase, snd_device,
4374 &bit_width,
4375 &sample_rate,
4376 &channels);
David Linee3fe402017-03-13 10:00:42 -07004377 }
4378
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004379 switch (backend_idx) {
4380 case USB_AUDIO_RX_BACKEND:
4381 audio_extn_usb_is_config_supported(&bit_width,
4382 &sample_rate, &channels, true);
Haynes Mathew George65f6b432018-02-27 17:44:55 -08004383 if (platform_get_usb_service_interval(adev->platform, true,
4384 &service_interval) == 0) {
4385 /* overwrite with best altset for this service interval */
4386 int ret =
4387 audio_extn_usb_altset_for_service_interval(true /*playback*/,
4388 service_interval,
4389 &bit_width,
4390 &sample_rate,
4391 &channels);
4392 if (ret < 0) {
4393 ALOGE("Failed to find altset for service interval %lu, skip reconfig",
4394 service_interval);
4395 return false;
4396 }
4397 }
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004398 ALOGV("%s: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
4399 __func__, bit_width, sample_rate, channels);
4400 break;
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004401 case HEADPHONE_BACKEND:
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004402 headset_is_config_supported(&bit_width, &sample_rate, &channels);
4403 break;
4404 case DEFAULT_CODEC_BACKEND:
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004405 default:
4406 bit_width = platform_get_snd_device_bit_width(snd_device);
4407 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4408 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
4409 break;
David Linee3fe402017-03-13 10:00:42 -07004410 }
4411
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004412 ALOGV("%s:becf: afe: Codec selected backend: %d updated bit width: %d and"
4413 "sample rate: %d",
David Linee3fe402017-03-13 10:00:42 -07004414 __func__, backend_idx , bit_width, sample_rate);
4415
4416 // Force routing if the expected bitwdith or samplerate
4417 // is not same as current backend comfiguration
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004418 if (bit_width != my_data->current_backend_cfg[backend_idx].bit_width ||
4419 sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate ||
4420 channels != my_data->current_backend_cfg[backend_idx].channels) {
David Linee3fe402017-03-13 10:00:42 -07004421 backend_cfg->bit_width = bit_width;
4422 backend_cfg->sample_rate = sample_rate;
4423 backend_cfg->channels = channels;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004424 backend_cfg->passthrough_enabled = false;
David Linee3fe402017-03-13 10:00:42 -07004425 backend_change = true;
4426 ALOGV("%s:becf: afe: Codec backend needs to be updated. new bit width: %d"
4427 "new sample rate: %d new channels: %d",
4428 __func__, backend_cfg->bit_width, backend_cfg->sample_rate, backend_cfg->channels);
4429 }
4430
4431 return backend_change;
4432}
4433
4434bool platform_check_and_set_playback_backend_cfg(struct audio_device* adev,
4435 struct audio_usecase *usecase, snd_device_t snd_device)
4436{
4437 int backend_idx = DEFAULT_CODEC_BACKEND;
4438 int new_snd_devices[SND_DEVICE_OUT_END];
4439 int i, num_devices = 1;
4440 bool ret = false;
4441 struct platform_data *my_data = (struct platform_data *)adev->platform;
4442 struct audio_backend_cfg backend_cfg;
4443
4444 backend_idx = platform_get_backend_index(snd_device);
4445
4446 backend_cfg.bit_width = pcm_format_to_bits(usecase->stream.out->config.format);
4447 backend_cfg.sample_rate = usecase->stream.out->sample_rate;
4448 backend_cfg.format = usecase->stream.out->format;
4449 backend_cfg.channels = audio_channel_count_from_out_mask(usecase->stream.out->channel_mask);
4450 /*this is populated by check_codec_backend_cfg hence set default value to false*/
4451 backend_cfg.passthrough_enabled = false;
4452
4453 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
4454 ", backend_idx %d usecase = %d device (%s)", __func__, backend_cfg.bit_width,
4455 backend_cfg.sample_rate, backend_cfg.channels, backend_idx, usecase->id,
4456 platform_get_snd_device_name(snd_device));
4457
4458 if (platform_can_split_snd_device(snd_device, &num_devices, new_snd_devices) < 0)
4459 new_snd_devices[0] = snd_device;
4460
4461 for (i = 0; i < num_devices; i++) {
4462 ALOGV("%s: new_snd_devices[%d] is %d", __func__, i, new_snd_devices[i]);
4463 if ((platform_check_playback_backend_cfg(adev, usecase, new_snd_devices[i],
4464 &backend_cfg))) {
4465 platform_set_backend_cfg(adev, new_snd_devices[i],
4466 &backend_cfg);
4467 ret = true;
4468 }
4469 }
4470 return ret;
4471}
4472
4473bool platform_check_and_set_capture_backend_cfg(struct audio_device* adev,
4474 struct audio_usecase *usecase, snd_device_t snd_device)
4475{
4476 int backend_idx = platform_get_backend_index(snd_device);
4477 int ret = 0;
4478 struct audio_backend_cfg backend_cfg;
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004479 memset(&backend_cfg, 0, sizeof(struct audio_backend_cfg));
David Linee3fe402017-03-13 10:00:42 -07004480
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004481 if (usecase->type == PCM_CAPTURE) {
4482 backend_cfg.format = usecase->stream.in->format;
David Linee3fe402017-03-13 10:00:42 -07004483 backend_cfg.channels = audio_channel_count_from_in_mask(usecase->stream.in->channel_mask);
4484 } else {
4485 backend_cfg.bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
4486 backend_cfg.sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4487 backend_cfg.format = AUDIO_FORMAT_PCM_16_BIT;
4488 backend_cfg.channels = 1;
4489 }
4490
4491 ALOGV("%s:txbecf: afe: bitwidth %d, samplerate %d, channel %d"
4492 ", backend_idx %d usecase = %d device (%s)", __func__,
4493 backend_cfg.bit_width,
4494 backend_cfg.sample_rate,
4495 backend_cfg.channels,
4496 backend_idx, usecase->id,
4497 platform_get_snd_device_name(snd_device));
4498
4499 if (platform_check_capture_backend_cfg(adev, backend_idx, &backend_cfg)) {
4500 ret = platform_set_backend_cfg(adev, snd_device,
4501 &backend_cfg);
4502 if(!ret)
4503 return true;
4504 }
4505
4506 return false;
4507}
4508
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004509static int max_be_dai_names = 0;
4510static const struct be_dai_name_struct *be_dai_name_table;
4511
4512/*
4513 * Retrieves the be_dai_name_table from kernel to enable a mapping
4514 * between sound device hw interfaces and backend IDs. This allows HAL to
4515 * specify the backend a specific calibration is needed for.
4516 */
4517static int init_be_dai_name_table(struct audio_device *adev)
4518{
4519 const char *mixer_ctl_name = "Backend DAI Name Table";
4520 struct mixer_ctl *ctl;
4521 int i, j, ret, size;
4522 bool valid_hw_interface;
4523
4524 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
4525 if (!ctl) {
4526 ALOGE("%s: Could not get ctl for mixer name %s\n",
4527 __func__, mixer_ctl_name);
4528 ret = -EINVAL;
4529 goto done;
4530 }
4531
4532 mixer_ctl_update(ctl);
4533
4534 size = mixer_ctl_get_num_values(ctl);
4535 if (size <= 0){
4536 ALOGE("%s: Failed to get %s size %d\n",
4537 __func__, mixer_ctl_name, size);
4538 ret = -EFAULT;
4539 goto done;
4540 }
4541
vivek mehtaa68fea62017-06-08 19:04:02 -07004542 be_dai_name_table =
4543 (const struct be_dai_name_struct *)calloc(1, size);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004544 if (be_dai_name_table == NULL) {
4545 ALOGE("%s: Failed to allocate memory for %s\n",
4546 __func__, mixer_ctl_name);
4547 ret = -ENOMEM;
4548 goto freeMem;
4549 }
4550
4551 ret = mixer_ctl_get_array(ctl, (void *)be_dai_name_table, size);
4552 if (ret) {
4553 ALOGE("%s: Failed to get %s, ret %d\n",
4554 __func__, mixer_ctl_name, ret);
4555 ret = -EFAULT;
4556 goto freeMem;
4557 }
4558
4559 if (be_dai_name_table != NULL) {
4560 max_be_dai_names = size / sizeof(struct be_dai_name_struct);
4561 ALOGV("%s: Successfully got %s, number of be dais is %d\n",
4562 __func__, mixer_ctl_name, max_be_dai_names);
4563 ret = 0;
4564 } else {
4565 ALOGE("%s: Failed to get %s\n", __func__, mixer_ctl_name);
4566 ret = -EFAULT;
4567 goto freeMem;
4568 }
4569
4570 /*
4571 * Validate all sound devices have a valid backend set to catch
4572 * errors for uncommon sound devices
4573 */
4574 for (i = 0; i < SND_DEVICE_MAX; i++) {
4575 valid_hw_interface = false;
4576
4577 if (hw_interface_table[i] == NULL) {
4578 ALOGW("%s: sound device %s has no hw interface set\n",
4579 __func__, platform_get_snd_device_name(i));
4580 continue;
4581 }
4582
4583 for (j = 0; j < max_be_dai_names; j++) {
4584 if (strcmp(hw_interface_table[i], be_dai_name_table[j].be_name)
4585 == 0) {
4586 valid_hw_interface = true;
4587 break;
4588 }
4589 }
4590 if (!valid_hw_interface)
4591 ALOGD("%s: sound device %s does not have a valid hw interface set "
4592 "(disregard for combo devices) %s\n",
4593 __func__, platform_get_snd_device_name(i),
4594 hw_interface_table[i]);
4595 }
4596
4597 goto done;
4598
4599freeMem:
4600 if (be_dai_name_table) {
4601 free((void *)be_dai_name_table);
4602 be_dai_name_table = NULL;
4603 }
4604
4605done:
4606 return ret;
4607}
4608
4609int platform_get_snd_device_backend_index(snd_device_t device)
4610{
4611 int i, be_dai_id;
4612 const char * hw_interface_name = NULL;
4613
4614 ALOGV("%s: enter with device %d\n", __func__, device);
4615
vivek mehtaa68fea62017-06-08 19:04:02 -07004616 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004617 ALOGE("%s: Invalid snd_device = %d",
4618 __func__, device);
4619 be_dai_id = -EINVAL;
4620 goto done;
4621 }
4622
4623 /* Get string value of necessary backend for device */
4624 hw_interface_name = hw_interface_table[device];
4625 if (hw_interface_name == NULL) {
4626 ALOGE("%s: no hw_interface set for device %d\n", __func__, device);
4627 be_dai_id = -EINVAL;
4628 goto done;
4629 }
4630
4631 /* Check if be dai name table was retrieved successfully */
4632 if (be_dai_name_table == NULL) {
4633 ALOGE("%s: BE DAI Name Table is not present\n", __func__);
4634 be_dai_id = -EFAULT;
4635 goto done;
4636 }
4637
4638 /* Get backend ID for device specified */
4639 for (i = 0; i < max_be_dai_names; i++) {
4640 if (strcmp(hw_interface_name, be_dai_name_table[i].be_name) == 0) {
4641 be_dai_id = be_dai_name_table[i].be_id;
4642 goto done;
4643 }
4644 }
4645 ALOGE("%s: no interface matching name %s\n", __func__, hw_interface_name);
4646 be_dai_id = -EINVAL;
4647 goto done;
4648
4649done:
4650 return be_dai_id;
4651}
4652
4653void platform_check_and_update_copp_sample_rate(void* platform, snd_device_t snd_device,
4654 unsigned int stream_sr, int* sample_rate)
4655{
4656 struct platform_data* my_data = (struct platform_data *)platform;
4657 int backend_idx = platform_get_backend_index(snd_device);
4658 int device_sr = my_data->current_backend_cfg[backend_idx].sample_rate;
4659 /*
4660 *Check if device SR is multiple of 8K or 11.025 Khz
4661 *check if the stream SR is multiple of same base, if yes
4662 *then have copp SR equal to stream SR, this ensures that
4663 *post processing happens at stream SR, else have
4664 *copp SR equal to device SR.
4665 */
4666 if (!(((sample_rate_multiple(device_sr, SAMPLE_RATE_8000)) &&
4667 (sample_rate_multiple(stream_sr, SAMPLE_RATE_8000))) ||
4668 ((sample_rate_multiple(device_sr, SAMPLE_RATE_11025)) &&
4669 (sample_rate_multiple(stream_sr, SAMPLE_RATE_11025))))) {
4670 *sample_rate = device_sr;
4671 } else
4672 *sample_rate = stream_sr;
4673
4674 ALOGI("sn_device %d device sr %d stream sr %d copp sr %d", snd_device, device_sr, stream_sr
4675 , *sample_rate);
4676
4677}
4678
4679// called from info parser
vivek mehtaa68fea62017-06-08 19:04:02 -07004680void platform_add_app_type(const char *uc_type,
4681 const char *mode,
4682 int bw,
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004683 int app_type, int max_rate) {
4684 struct app_type_entry *ap =
4685 (struct app_type_entry *)calloc(1, sizeof(struct app_type_entry));
4686
4687 if (!ap) {
4688 ALOGE("%s failed to allocate mem for app type", __func__);
4689 return;
4690 }
4691
4692 ap->uc_type = -1;
4693 for (int i=0; i<USECASE_TYPE_MAX; i++) {
4694 if (!strcmp(uc_type, usecase_type_index[i].name)) {
4695 ap->uc_type = usecase_type_index[i].index;
4696 break;
4697 }
4698 }
4699
4700 if (ap->uc_type == -1) {
4701 free(ap);
4702 return;
4703 }
4704
vivek mehtaa68fea62017-06-08 19:04:02 -07004705 ALOGI("%s uc %s mode %s bw %d app_type %d max_rate %d",
4706 __func__, uc_type, mode, bw, app_type, max_rate);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004707 ap->bit_width = bw;
4708 ap->app_type = app_type;
4709 ap->max_rate = max_rate;
vivek mehtaa68fea62017-06-08 19:04:02 -07004710 ap->mode = strdup(mode);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004711 list_add_tail(&app_type_entry_list, &ap->node);
4712}
4713
4714
4715int platform_get_default_app_type_v2(void *platform __unused,
4716 usecase_type_t type,
4717 int *app_type )
4718{
4719 if (type == PCM_PLAYBACK)
4720 *app_type = DEFAULT_APP_TYPE_RX_PATH;
4721 else
4722 *app_type = DEFAULT_APP_TYPE_TX_PATH;
4723 return 0;
4724}
4725
vivek mehtaa68fea62017-06-08 19:04:02 -07004726int platform_get_app_type_v2(void *platform,
4727 usecase_type_t uc_type,
4728 const char *mode,
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004729 int bw, int sr __unused,
4730 int *app_type)
4731{
4732 struct listnode *node;
4733 struct app_type_entry *entry;
4734 *app_type = -1;
vivek mehtaa68fea62017-06-08 19:04:02 -07004735
4736 ALOGV("%s find match for uc %d mode %s bw %d rate %d",
4737 __func__, uc_type, mode, bw, sr);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004738 list_for_each(node, &app_type_entry_list) {
4739 entry = node_to_item(node, struct app_type_entry, node);
vivek mehtaa68fea62017-06-08 19:04:02 -07004740 ALOGV("%s uc %d mode %s bw %d app_type %d max_rate %d",
4741 __func__, entry->uc_type, entry->mode, entry->bit_width,
4742 entry->app_type, entry->max_rate);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004743 if (entry->bit_width == bw &&
vivek mehtaa68fea62017-06-08 19:04:02 -07004744 entry->uc_type == uc_type &&
4745 sr <= entry->max_rate &&
4746 entry->mode && !strcmp(mode, entry->mode)) {
4747 ALOGV("%s found match %d", __func__, entry->app_type);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004748 *app_type = entry->app_type;
4749 break;
4750 }
4751 }
4752
4753 if (*app_type == -1) {
vivek mehtaa68fea62017-06-08 19:04:02 -07004754 ALOGV("%s no match found, return default", __func__);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004755 return platform_get_default_app_type_v2(platform, uc_type, app_type);
4756 }
4757 return 0;
4758}
vivek mehta90933872017-06-15 18:04:39 -07004759
4760int platform_set_sidetone(struct audio_device *adev,
4761 snd_device_t out_snd_device,
4762 bool enable, char *str)
4763{
4764 int ret;
4765 if (out_snd_device == SND_DEVICE_OUT_USB_HEADSET ||
4766 out_snd_device == SND_DEVICE_OUT_VOICE_USB_HEADSET) {
4767 ret = audio_extn_usb_enable_sidetone(out_snd_device, enable);
4768 if (ret)
4769 ALOGI("%s: usb device %d does not support device sidetone\n",
4770 __func__, out_snd_device);
4771 } else {
4772 ALOGV("%s: sidetone out device(%d) mixer cmd = %s\n",
4773 __func__, out_snd_device, str);
4774 if (enable)
4775 audio_route_apply_and_update_path(adev->audio_route, str);
4776 else
4777 audio_route_reset_and_update_path(adev->audio_route, str);
4778 }
4779 return 0;
4780}
Haynes Mathew George96483a22017-03-28 14:52:47 -07004781
4782int platform_get_mmap_data_fd(void *platform __unused, int fe_dev __unused, int dir __unused,
4783 int *fd __unused, uint32_t *size __unused)
4784{
Thierry Strudel07f96d12018-09-20 13:31:34 -07004785#if defined (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845) || (PLATFORM_SDM710) || (PLATFORM_SM8150)
Haynes Mathew George96483a22017-03-28 14:52:47 -07004786 struct platform_data *my_data = (struct platform_data *)platform;
4787 struct audio_device *adev = my_data->adev;
4788 int hw_fd = -1;
4789 char dev_name[128];
4790 struct snd_pcm_mmap_fd mmap_fd;
4791 memset(&mmap_fd, 0, sizeof(mmap_fd));
4792 mmap_fd.dir = dir;
4793 snprintf(dev_name, sizeof(dev_name), "/dev/snd/hwC%uD%u",
4794 adev->snd_card, HWDEP_FE_BASE+fe_dev);
4795 hw_fd = open(dev_name, O_RDONLY);
4796 if (hw_fd < 0) {
4797 ALOGE("fe hw dep node open %d/%d failed", adev->snd_card, fe_dev);
4798 return -1;
4799 }
4800 if (ioctl(hw_fd, SNDRV_PCM_IOCTL_MMAP_DATA_FD, &mmap_fd) < 0) {
4801 ALOGE("fe hw dep node ioctl failed");
4802 close(hw_fd);
4803 return -1;
4804 }
4805 *fd = mmap_fd.fd;
4806 *size = mmap_fd.size;
4807 close(hw_fd); // mmap_fd should still be valid
4808 return 0;
4809#else
4810 return -1;
4811#endif
4812}
Mikhail Naganov4ee6e3e2018-03-21 16:28:35 +00004813
4814bool platform_sound_trigger_usecase_needs_event(audio_usecase_t uc_id)
4815{
4816 bool needs_event = false;
4817
4818 switch (uc_id) {
4819 /* concurrent capture usecases which needs event */
4820 case USECASE_AUDIO_RECORD:
4821 case USECASE_AUDIO_RECORD_LOW_LATENCY:
4822 case USECASE_AUDIO_RECORD_MMAP:
4823 case USECASE_AUDIO_RECORD_HIFI:
4824 case USECASE_AUDIO_RECORD_VOIP:
4825 case USECASE_VOICEMMODE1_CALL:
4826 case USECASE_VOICEMMODE2_CALL:
4827 /* concurrent playback usecases that needs event */
4828 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
4829 case USECASE_AUDIO_PLAYBACK_OFFLOAD:
4830 needs_event = true;
4831 break;
4832 default:
4833 ALOGV("%s:usecase_id[%d] no need to raise event.", __func__, uc_id);
4834 }
4835 return needs_event;
4836}
4837
4838bool platform_snd_device_has_speaker(snd_device_t dev) {
4839 int num_devs = 2;
4840 snd_device_t split_devs[2] = {SND_DEVICE_NONE, SND_DEVICE_NONE};
4841 if (platform_can_split_snd_device(dev, &num_devs, split_devs) == 0) {
4842 return platform_snd_device_has_speaker(split_devs[0]) ||
4843 platform_snd_device_has_speaker(split_devs[1]);
4844 }
4845
4846 switch (dev) {
4847 case SND_DEVICE_OUT_SPEAKER:
4848 case SND_DEVICE_OUT_SPEAKER_SAFE:
4849 case SND_DEVICE_OUT_SPEAKER_REVERSE:
4850 case SND_DEVICE_OUT_SPEAKER_PROTECTED:
4851 case SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED:
4852 case SND_DEVICE_OUT_VOICE_SPEAKER_HFP:
4853 return true;
4854 default:
4855 break;
4856 }
4857 return false;
4858}
jiabin8962a4d2018-03-19 18:21:24 -07004859
4860bool platform_set_microphone_characteristic(void *platform,
4861 struct audio_microphone_characteristic_t mic) {
4862 struct platform_data *my_data = (struct platform_data *)platform;
4863 if (my_data->declared_mic_count >= AUDIO_MICROPHONE_MAX_COUNT) {
4864 ALOGE("mic number is more than maximum number");
4865 return false;
4866 }
4867 for (size_t ch = 0; ch < AUDIO_CHANNEL_COUNT_MAX; ch++) {
4868 mic.channel_mapping[ch] = AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED;
4869 }
4870 my_data->microphones[my_data->declared_mic_count++] = mic;
4871 return true;
4872}
4873
4874int platform_get_microphones(void *platform,
4875 struct audio_microphone_characteristic_t *mic_array,
4876 size_t *mic_count) {
4877 struct platform_data *my_data = (struct platform_data *)platform;
4878 if (mic_count == NULL) {
4879 return -EINVAL;
4880 }
4881 if (mic_array == NULL) {
4882 return -EINVAL;
4883 }
4884
4885 if (*mic_count == 0) {
4886 *mic_count = my_data->declared_mic_count;
4887 return 0;
4888 }
4889
4890 size_t max_mic_count = *mic_count;
4891 size_t actual_mic_count = 0;
4892 for (size_t i = 0; i < max_mic_count && i < my_data->declared_mic_count; i++) {
4893 mic_array[i] = my_data->microphones[i];
4894 actual_mic_count++;
4895 }
4896 *mic_count = actual_mic_count;
4897 return 0;
4898}
4899
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004900bool platform_set_microphone_map(void *platform, snd_device_t in_snd_device,
4901 const struct mic_info *info) {
4902 struct platform_data *my_data = (struct platform_data *)platform;
4903 if (in_snd_device < SND_DEVICE_IN_BEGIN || in_snd_device >= SND_DEVICE_IN_END) {
4904 ALOGE("%s: Sound device not valid", __func__);
4905 return false;
4906 }
4907 size_t m_count = my_data->mic_map[in_snd_device].mic_count++;
4908 if (m_count >= AUDIO_MICROPHONE_MAX_COUNT) {
4909 ALOGE("%s: Microphone count is greater than max allowed value", __func__);
4910 my_data->mic_map[in_snd_device].mic_count--;
4911 return false;
4912 }
4913 my_data->mic_map[in_snd_device].microphones[m_count] = *info;
4914 return true;
4915}
4916
4917int platform_get_active_microphones(void *platform, unsigned int channels,
4918 audio_usecase_t uc_id,
jiabin8962a4d2018-03-19 18:21:24 -07004919 struct audio_microphone_characteristic_t *mic_array,
4920 size_t *mic_count) {
4921 struct platform_data *my_data = (struct platform_data *)platform;
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004922 struct audio_usecase *usecase = get_usecase_from_list(my_data->adev, uc_id);
4923 if (mic_count == NULL || mic_array == NULL || usecase == NULL) {
jiabin8962a4d2018-03-19 18:21:24 -07004924 return -EINVAL;
4925 }
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004926 size_t max_mic_count = my_data->declared_mic_count;
jiabin8962a4d2018-03-19 18:21:24 -07004927 size_t actual_mic_count = 0;
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004928
4929 snd_device_t active_input_snd_device =
Eric Laurentd1b7a9b2018-11-15 12:24:31 -08004930 platform_get_input_snd_device(platform, usecase->stream.in, AUDIO_DEVICE_NONE);
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004931 if (active_input_snd_device == SND_DEVICE_NONE) {
4932 ALOGI("%s: No active microphones found", __func__);
4933 goto end;
4934 }
4935
4936 size_t active_mic_count = my_data->mic_map[active_input_snd_device].mic_count;
4937 struct mic_info *m_info = my_data->mic_map[active_input_snd_device].microphones;
4938
4939 for (size_t i = 0; i < active_mic_count; i++) {
4940 unsigned int channels_for_active_mic = channels;
4941 if (channels_for_active_mic > m_info[i].channel_count) {
4942 channels_for_active_mic = m_info[i].channel_count;
4943 }
4944 for (size_t j = 0; j < max_mic_count; j++) {
4945 if (strcmp(my_data->microphones[j].device_id,
4946 m_info[i].device_id) == 0) {
4947 mic_array[actual_mic_count] = my_data->microphones[j];
4948 for (size_t ch = 0; ch < channels_for_active_mic; ch++) {
4949 mic_array[actual_mic_count].channel_mapping[ch] =
4950 m_info[i].channel_mapping[ch];
4951 }
4952 actual_mic_count++;
4953 break;
jiabin8962a4d2018-03-19 18:21:24 -07004954 }
jiabin8962a4d2018-03-19 18:21:24 -07004955 }
4956 }
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004957end:
jiabin8962a4d2018-03-19 18:21:24 -07004958 *mic_count = actual_mic_count;
4959 return 0;
4960}
Haynes Mathew George65f6b432018-02-27 17:44:55 -08004961
4962int platform_set_usb_service_interval(void *platform,
4963 bool playback,
4964 unsigned long service_interval,
4965 bool *reconfig)
4966{
4967#if defined (USB_SERVICE_INTERVAL_ENABLED)
4968 struct platform_data *_platform = (struct platform_data *)platform;
4969 *reconfig = false;
4970 if (!playback) {
4971 ALOGE("%s not valid for capture", __func__);
4972 return -1;
4973 }
4974 const char *ctl_name = "USB_AUDIO_RX service_interval";
4975 struct mixer_ctl *ctl = mixer_get_ctl_by_name(_platform->adev->mixer,
4976 ctl_name);
4977 if (!ctl) {
4978 ALOGV("%s: could not get mixer %s", __func__, ctl_name);
4979 return -1;
4980 }
4981 if (mixer_ctl_get_value(ctl, 0) != (int)service_interval) {
4982 mixer_ctl_set_value(ctl, 0, service_interval);
4983 *reconfig = true;
4984 }
4985 return 0;
4986#else
4987 *reconfig = false;
4988 (void)platform;
4989 (void)playback;
4990 (void)service_interval;
4991 return -1;
4992#endif
4993}
4994
4995int platform_get_usb_service_interval(void *platform,
4996 bool playback,
4997 unsigned long *service_interval)
4998{
4999#if defined (USB_SERVICE_INTERVAL_ENABLED)
5000 struct platform_data *_platform = (struct platform_data *)platform;
5001 if (!playback) {
5002 ALOGE("%s not valid for capture", __func__);
5003 return -1;
5004 }
5005 const char *ctl_name = "USB_AUDIO_RX service_interval";
5006 struct mixer_ctl *ctl = mixer_get_ctl_by_name(_platform->adev->mixer,
5007 ctl_name);
5008 if (!ctl) {
5009 ALOGV("%s: could not get mixer %s", __func__, ctl_name);
5010 return -1;
5011 }
5012 *service_interval = mixer_ctl_get_value(ctl, 0);
5013 return 0;
5014#else
5015 (void)platform;
5016 (void)playback;
5017 (void)service_interval;
5018 return -1;
5019#endif
5020}
Ashish Jain1c849702018-05-11 20:11:55 +05305021
5022int platform_set_acdb_metainfo_key(void *platform __unused,
5023 char *name __unused,
5024 int key __unused)
5025{
5026 return -ENOSYS;
5027}