blob: f03356babb97d18ffa69e1c37ff4adbd1ab9b3c6 [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},
187 [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
188 LOWLATENCY_PCM_DEVICE},
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800189 [USECASE_AUDIO_PLAYBACK_HIFI] = {MULTIMEDIA2_PCM_DEVICE,
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700190 MULTIMEDIA2_PCM_DEVICE},
191 [USECASE_AUDIO_PLAYBACK_OFFLOAD] = {PLAYBACK_OFFLOAD_DEVICE,
192 PLAYBACK_OFFLOAD_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700193 [USECASE_AUDIO_PLAYBACK_TTS] = {MULTIMEDIA2_PCM_DEVICE,
194 MULTIMEDIA2_PCM_DEVICE},
195 [USECASE_AUDIO_PLAYBACK_ULL] = {MULTIMEDIA3_PCM_DEVICE,
196 MULTIMEDIA3_PCM_DEVICE},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800197 [USECASE_AUDIO_PLAYBACK_MMAP] = {MMAP_PLAYBACK_PCM_DEVICE,
198 MMAP_PLAYBACK_PCM_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700199
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700200 [USECASE_AUDIO_RECORD] = {AUDIO_RECORD_PCM_DEVICE,
201 AUDIO_RECORD_PCM_DEVICE},
202 [USECASE_AUDIO_RECORD_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
203 LOWLATENCY_PCM_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700204
Eric Laurent0e46adf2016-12-16 12:49:24 -0800205 [USECASE_AUDIO_RECORD_MMAP] = {MMAP_RECORD_PCM_DEVICE,
206 MMAP_RECORD_PCM_DEVICE},
Haynes Mathew George569b7482017-05-08 14:44:27 -0700207 [USECASE_AUDIO_RECORD_HIFI] = {MULTIMEDIA2_PCM_DEVICE,
208 MULTIMEDIA2_PCM_DEVICE},
209
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700210 [USECASE_VOICE_CALL] = {VOICE_CALL_PCM_DEVICE,
211 VOICE_CALL_PCM_DEVICE},
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700212 [USECASE_VOICE2_CALL] = {VOICE2_CALL_PCM_DEVICE, VOICE2_CALL_PCM_DEVICE},
213 [USECASE_VOLTE_CALL] = {VOLTE_CALL_PCM_DEVICE, VOLTE_CALL_PCM_DEVICE},
214 [USECASE_QCHAT_CALL] = {QCHAT_CALL_PCM_DEVICE, QCHAT_CALL_PCM_DEVICE},
215 [USECASE_VOWLAN_CALL] = {VOWLAN_CALL_PCM_DEVICE, VOWLAN_CALL_PCM_DEVICE},
vivek mehtaa51fd402016-02-04 19:49:33 -0800216 [USECASE_VOICEMMODE1_CALL] = {VOICEMMODE1_CALL_PCM_DEVICE,
217 VOICEMMODE1_CALL_PCM_DEVICE},
218 [USECASE_VOICEMMODE2_CALL] = {VOICEMMODE2_CALL_PCM_DEVICE,
219 VOICEMMODE2_CALL_PCM_DEVICE},
220
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700221 [USECASE_INCALL_REC_UPLINK] = {AUDIO_RECORD_PCM_DEVICE,
222 AUDIO_RECORD_PCM_DEVICE},
223 [USECASE_INCALL_REC_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
224 AUDIO_RECORD_PCM_DEVICE},
225 [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
226 AUDIO_RECORD_PCM_DEVICE},
Ravi Kumar Alamanda8e6e98f2013-11-05 15:57:39 -0800227 [USECASE_AUDIO_HFP_SCO] = {HFP_PCM_RX, HFP_SCO_RX},
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700228
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700229 [USECASE_AUDIO_SPKR_CALIB_RX] = {SPKR_PROT_CALIB_RX_PCM_DEVICE, -1},
230 [USECASE_AUDIO_SPKR_CALIB_TX] = {-1, SPKR_PROT_CALIB_TX_PCM_DEVICE},
231
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700232 [USECASE_AUDIO_PLAYBACK_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
233 AFE_PROXY_RECORD_PCM_DEVICE},
234 [USECASE_AUDIO_RECORD_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
235 AFE_PROXY_RECORD_PCM_DEVICE},
zhaoyang yin4211fad2015-06-04 21:13:25 +0800236 [USECASE_AUDIO_DSM_FEEDBACK] = {QUAT_MI2S_PCM_DEVICE, QUAT_MI2S_PCM_DEVICE},
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700237
vivek mehtaa68fea62017-06-08 19:04:02 -0700238 [USECASE_AUDIO_PLAYBACK_VOIP] = {AUDIO_PLAYBACK_VOIP_PCM_DEVICE,
239 AUDIO_PLAYBACK_VOIP_PCM_DEVICE},
240 [USECASE_AUDIO_RECORD_VOIP] = {AUDIO_RECORD_VOIP_PCM_DEVICE,
241 AUDIO_RECORD_VOIP_PCM_DEVICE},
Nadav Bar3d72cfc2018-01-07 12:19:24 +0200242
243 [USECASE_INCALL_MUSIC_UPLINK] = {INCALL_MUSIC_UPLINK_PCM_DEVICE,
244 INCALL_MUSIC_UPLINK_PCM_DEVICE},
Eric Laurentb23d5282013-05-14 15:27:20 -0700245};
246
247/* Array to store sound devices */
248static const char * const device_table[SND_DEVICE_MAX] = {
249 [SND_DEVICE_NONE] = "none",
250 /* Playback sound devices */
251 [SND_DEVICE_OUT_HANDSET] = "handset",
252 [SND_DEVICE_OUT_SPEAKER] = "speaker",
253 [SND_DEVICE_OUT_SPEAKER_REVERSE] = "speaker-reverse",
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700254 [SND_DEVICE_OUT_SPEAKER_SAFE] = "speaker-safe",
Eric Laurentb23d5282013-05-14 15:27:20 -0700255 [SND_DEVICE_OUT_HEADPHONES] = "headphones",
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500256 [SND_DEVICE_OUT_LINE] = "line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700257 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones",
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700258 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = "speaker-safe-and-headphones",
Eric Laurent744996b2014-10-01 11:40:40 -0500259 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = "speaker-and-line",
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700260 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = "speaker-safe-and-line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700261 [SND_DEVICE_OUT_VOICE_HANDSET] = "voice-handset",
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500262 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = "voice-hac-handset",
Eric Laurentb23d5282013-05-14 15:27:20 -0700263 [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker",
264 [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones",
yixuanjiang9536e672018-09-06 18:43:36 +0800265 [SND_DEVICE_OUT_VOICE_HEADSET] = "voice-headphones",
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500266 [SND_DEVICE_OUT_VOICE_LINE] = "voice-line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700267 [SND_DEVICE_OUT_HDMI] = "hdmi",
268 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi",
269 [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700270 [SND_DEVICE_OUT_BT_SCO_WB] = "bt-sco-headset-wb",
Aniket Kumar Lata26483012018-01-31 20:21:42 -0800271 [SND_DEVICE_OUT_BT_A2DP] = "bt-a2dp",
272 [SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] = "speaker-and-bt-a2dp",
Aniket Kumar Lata9723a962018-05-16 17:41:55 -0700273 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP] = "speaker-safe-and-bt-a2dp",
Eric Laurentb23d5282013-05-14 15:27:20 -0700274 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = "voice-handset-tmus",
275 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones",
276 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones",
277 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset",
vivek mehtaa6b79742017-03-09 15:40:43 -0800278 [SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = "voice-tty-full-usb",
279 [SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = "voice-tty-vco-usb",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700280 [SND_DEVICE_OUT_VOICE_TX] = "voice-tx",
juyuchen66c4ecf2018-08-06 15:39:34 +0800281 [SND_DEVICE_OUT_VOICE_MUSIC_TX] = "voice-music-tx",
David Linee3fe402017-03-13 10:00:42 -0700282 [SND_DEVICE_OUT_USB_HEADSET] = "usb-headset",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700283 [SND_DEVICE_OUT_VOICE_USB_HEADSET] = "usb-headset",
David Linee3fe402017-03-13 10:00:42 -0700284 [SND_DEVICE_OUT_USB_HEADPHONES] = "usb-headphones",
jasmine cha270b7762018-03-30 15:41:33 +0800285 [SND_DEVICE_OUT_USB_HEADSET_SPEC] = "usb-headset",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700286 [SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = "usb-headphones",
David Linee3fe402017-03-13 10:00:42 -0700287 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = "speaker-and-usb-headphones",
Haynes Mathew George9090bfb2017-05-31 11:44:50 -0700288 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] = "speaker-safe-and-usb-headphones",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700289 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = "speaker-protected",
290 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = "voice-speaker-protected",
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -0700291 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = "voice-speaker-hfp",
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -0800292 [SND_DEVICE_OUT_SPEAKER_AND_BT_SCO] = "speaker-and-bt-sco",
juyuchen5351ea62018-05-16 10:54:37 +0800293 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO] = "speaker-safe-and-bt-sco",
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -0800294 [SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB] = "speaker-and-bt-sco-wb",
juyuchen5351ea62018-05-16 10:54:37 +0800295 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB] = "speaker-safe-and-bt-sco-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700296
297 /* Capture sound devices */
298 [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700299 [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700300 [SND_DEVICE_IN_HANDSET_MIC_NS] = "handset-mic",
301 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = "handset-mic",
302 [SND_DEVICE_IN_HANDSET_DMIC] = "dmic-endfire",
303 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = "dmic-endfire",
304 [SND_DEVICE_IN_HANDSET_DMIC_NS] = "dmic-endfire",
305 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = "dmic-endfire",
306 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = "dmic-endfire",
307
308 [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
309 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "speaker-mic",
310 [SND_DEVICE_IN_SPEAKER_MIC_NS] = "speaker-mic",
311 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = "speaker-mic",
312 [SND_DEVICE_IN_SPEAKER_DMIC] = "speaker-dmic-endfire",
313 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = "speaker-dmic-endfire",
314 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = "speaker-dmic-endfire",
315 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = "speaker-dmic-endfire",
316 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = "speaker-dmic-endfire",
317
318 [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
Eric Laurentcefbbac2014-09-04 13:54:10 -0500319 [SND_DEVICE_IN_HEADSET_MIC_AEC] = "headset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700320
Eric Laurentb23d5282013-05-14 15:27:20 -0700321 [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic",
322 [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700323 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = "bt-sco-mic",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700324 [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700325 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = "bt-sco-mic-wb",
Eric Laurent5f4ca952018-10-19 17:33:43 -0700326 [SND_DEVICE_IN_CAMCORDER_LANDSCAPE] = "camcorder-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700327
328 [SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef",
329 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = "voice-dmic-ef-tmus",
330 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
331 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = "voice-speaker-dmic-ef",
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -0700332 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = "voice-speaker-mic-hfp",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700333 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700334 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
335 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
336 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
vivek mehtaa6b79742017-03-09 15:40:43 -0800337 [SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = "voice-tty-full-usb-mic",
338 [SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = "voice-tty-hco-usb-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700339
Eric Laurentb23d5282013-05-14 15:27:20 -0700340 [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700341 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = "voice-rec-mic",
vivek mehta733c1df2016-04-04 15:09:24 -0700342 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = "voice-rec-mic",
vivek mehtaf3440682016-05-11 14:24:37 -0700343 [SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700344 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = "voice-rec-dmic-ef",
345 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence",
David Linee3fe402017-03-13 10:00:42 -0700346 [SND_DEVICE_IN_USB_HEADSET_MIC] = "usb-headset-mic",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700347 [SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] ="usb-headset-mic",
348 [SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = "usb-headset-mic",
349 [SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = "usb-headset-mic",
350 [SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = "usb-headset-mic",
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700351 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = "headset-mic",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700352
Ricardo Garcia9034bc42016-04-04 07:11:46 -0700353 [SND_DEVICE_IN_UNPROCESSED_MIC] = "unprocessed-mic",
vivek mehta0125e782016-06-16 18:03:11 -0700354 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = "unprocessed-stereo-mic",
355 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = "unprocessed-three-mic",
356 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = "unprocessed-quad-mic",
357 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = "unprocessed-headset-mic",
rago90fb9612015-12-02 11:37:53 -0800358
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700359 [SND_DEVICE_IN_VOICE_RX] = "voice-rx",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700360
Prashant Malanic92c5962015-08-11 15:10:18 -0700361 [SND_DEVICE_IN_THREE_MIC] = "three-mic",
362 [SND_DEVICE_IN_QUAD_MIC] = "quad-mic",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700363 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = "vi-feedback",
Prashant Malanic92c5962015-08-11 15:10:18 -0700364 [SND_DEVICE_IN_HANDSET_TMIC] = "three-mic",
365 [SND_DEVICE_IN_HANDSET_QMIC] = "quad-mic",
vivek mehta733c1df2016-04-04 15:09:24 -0700366 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = "three-mic",
367 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = "quad-mic",
Eric Laurent5f4ca952018-10-19 17:33:43 -0700368 [SND_DEVICE_IN_CAMCORDER_INVERT_LANDSCAPE] = "camcorder-mic",
369 [SND_DEVICE_IN_CAMCORDER_PORTRAIT] = "camcorder-mic",
370 [SND_DEVICE_IN_CAMCORDER_SELFIE_LANDSCAPE] = "camcorder-mic",
371 [SND_DEVICE_IN_CAMCORDER_SELFIE_INVERT_LANDSCAPE] = "camcorder-mic",
372 [SND_DEVICE_IN_CAMCORDER_SELFIE_PORTRAIT] = "camcorder-mic",
Vignesh Kulothungan64698822018-01-23 11:25:18 -0800373 [SND_DEVICE_IN_SPEAKER_QMIC_NS] = "quad-mic",
374 [SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS] = "quad-mic",
375};
376
377static struct audio_effect_config \
378 effect_config_table[GET_IN_DEVICE_INDEX(SND_DEVICE_MAX)][EFFECT_COUNT] = {
379 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS)][EFFECT_AEC] = \
380 {TX_VOICE_FLUENCE_PROV2, 0x0, 0x10EAF, 0x01},
381 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS)][EFFECT_NS] = \
382 {TX_VOICE_FLUENCE_PROV2, 0x0, 0x10EAF, 0x02},
383 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)][EFFECT_AEC] = \
384 {TX_VOICE_FV5ECNS_DM, 0x0, 0x10EAF, 0x01},
385 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)][EFFECT_NS] = \
386 {TX_VOICE_FV5ECNS_DM, 0x0, 0x10EAF, 0x02},
387 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)][EFFECT_AEC] = \
388 {TX_VOICE_FV5ECNS_SM, 0x0, 0x10EAF, 0x01},
389 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)][EFFECT_NS] = \
390 {TX_VOICE_FV5ECNS_SM, 0x0, 0x10EAF, 0x02},
391 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)][EFFECT_AEC] = \
392 {TX_VOICE_FV5ECNS_DM, 0x0, 0x10EAF, 0x01},
393 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)][EFFECT_NS] = \
394 {TX_VOICE_FV5ECNS_DM, 0x0, 0x10EAF, 0x02},
395 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)][EFFECT_AEC] = \
396 {TX_VOICE_FV5ECNS_SM, 0x0, 0x10EAF, 0x01},
397 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)][EFFECT_NS] = \
398 {TX_VOICE_FV5ECNS_SM, 0x0, 0x10EAF, 0x02},
Eric Laurentb23d5282013-05-14 15:27:20 -0700399};
400
401/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700402static int acdb_device_table[SND_DEVICE_MAX] = {
Eric Laurentb23d5282013-05-14 15:27:20 -0700403 [SND_DEVICE_NONE] = -1,
404 [SND_DEVICE_OUT_HANDSET] = 7,
405 [SND_DEVICE_OUT_SPEAKER] = 15,
406 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 15,
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700407 [SND_DEVICE_OUT_SPEAKER_SAFE] = 15,
Eric Laurentb23d5282013-05-14 15:27:20 -0700408 [SND_DEVICE_OUT_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500409 [SND_DEVICE_OUT_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700410 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700411 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500412 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = 77,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700413 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = 77,
Ravi Kumar Alamanda235c3482014-08-21 17:32:44 -0700414 [SND_DEVICE_OUT_VOICE_HANDSET] = ACDB_ID_VOICE_HANDSET,
415 [SND_DEVICE_OUT_VOICE_SPEAKER] = ACDB_ID_VOICE_SPEAKER,
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500416 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = 53,
Eric Laurentb23d5282013-05-14 15:27:20 -0700417 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
yixuanjiang9536e672018-09-06 18:43:36 +0800418 [SND_DEVICE_OUT_VOICE_HEADSET] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500419 [SND_DEVICE_OUT_VOICE_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700420 [SND_DEVICE_OUT_HDMI] = 18,
421 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 15,
422 [SND_DEVICE_OUT_BT_SCO] = 22,
juyuchen5351ea62018-05-16 10:54:37 +0800423 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO] = 14,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700424 [SND_DEVICE_OUT_BT_SCO_WB] = 39,
juyuchen5351ea62018-05-16 10:54:37 +0800425 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB] = 14,
Aniket Kumar Lata26483012018-01-31 20:21:42 -0800426 [SND_DEVICE_OUT_BT_A2DP] = 20,
427 [SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] = 14,
Aniket Kumar Lata9723a962018-05-16 17:41:55 -0700428 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP] = 14,
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700429 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = ACDB_ID_VOICE_HANDSET_TMUS,
Eric Laurentb23d5282013-05-14 15:27:20 -0700430 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
431 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
432 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
vivek mehtaa6b79742017-03-09 15:40:43 -0800433 [SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = 17,
434 [SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = 17,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700435 [SND_DEVICE_OUT_VOICE_TX] = 45,
juyuchen66c4ecf2018-08-06 15:39:34 +0800436 [SND_DEVICE_OUT_VOICE_MUSIC_TX] = 3,
David Linee3fe402017-03-13 10:00:42 -0700437 [SND_DEVICE_OUT_USB_HEADSET] = 45,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700438 [SND_DEVICE_OUT_VOICE_USB_HEADSET] = 45,
David Linee3fe402017-03-13 10:00:42 -0700439 [SND_DEVICE_OUT_USB_HEADPHONES] = 45,
jasmine cha270b7762018-03-30 15:41:33 +0800440 [SND_DEVICE_OUT_USB_HEADSET_SPEC] = 45,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700441 [SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = 45,
David Linee3fe402017-03-13 10:00:42 -0700442 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = 14,
Haynes Mathew George9090bfb2017-05-31 11:44:50 -0700443 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] = 14,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700444 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = 124,
445 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = 101,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700446 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = ACDB_ID_VOICE_SPEAKER,
Eric Laurentb23d5282013-05-14 15:27:20 -0700447
448 [SND_DEVICE_IN_HANDSET_MIC] = 4,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700449 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 106,
450 [SND_DEVICE_IN_HANDSET_MIC_NS] = 107,
451 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = 108,
452 [SND_DEVICE_IN_HANDSET_DMIC] = 41,
453 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = 109,
454 [SND_DEVICE_IN_HANDSET_DMIC_NS] = 110,
455 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = 111,
456 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = 34,
457
458 [SND_DEVICE_IN_SPEAKER_MIC] = 11,
459 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 112,
460 [SND_DEVICE_IN_SPEAKER_MIC_NS] = 113,
461 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = 114,
462 [SND_DEVICE_IN_SPEAKER_DMIC] = 43,
463 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = 115,
464 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = 116,
465 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = 117,
466 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = 35,
467
rago90fb9612015-12-02 11:37:53 -0800468 [SND_DEVICE_IN_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentcefbbac2014-09-04 13:54:10 -0500469 [SND_DEVICE_IN_HEADSET_MIC_AEC] = ACDB_ID_HEADSET_MIC_AEC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700470
Eric Laurentb23d5282013-05-14 15:27:20 -0700471 [SND_DEVICE_IN_HDMI_MIC] = 4,
472 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700473 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = 21,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700474 [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700475 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = 38,
Eric Laurent5f4ca952018-10-19 17:33:43 -0700476 [SND_DEVICE_IN_CAMCORDER_LANDSCAPE] = 61,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700477
478 [SND_DEVICE_IN_VOICE_DMIC] = 41,
479 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = ACDB_ID_VOICE_DMIC_EF_TMUS,
480 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700481 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = 11,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700482 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 43,
rago90fb9612015-12-02 11:37:53 -0800483 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentb23d5282013-05-14 15:27:20 -0700484 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
485 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
486 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
vivek mehtaa6b79742017-03-09 15:40:43 -0800487 [SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = 16,
488 [SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = 16,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700489
rago90fb9612015-12-02 11:37:53 -0800490 [SND_DEVICE_IN_VOICE_REC_MIC] = ACDB_ID_VOICE_REC_MIC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700491 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = 113,
vivek mehta733c1df2016-04-04 15:09:24 -0700492 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = 112,
vivek mehtaf3440682016-05-11 14:24:37 -0700493 [SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = 114,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700494 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = 35,
495 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 43,
rago90fb9612015-12-02 11:37:53 -0800496 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
497
498 [SND_DEVICE_IN_UNPROCESSED_MIC] = ACDB_ID_VOICE_REC_MIC,
499 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
vivek mehta4ed66e62016-04-15 23:33:34 -0700500 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = 35,
501 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = 125,
502 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = 125,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700503
504 [SND_DEVICE_IN_VOICE_RX] = 44,
David Linee3fe402017-03-13 10:00:42 -0700505 [SND_DEVICE_IN_USB_HEADSET_MIC] = 44,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700506 [SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = 44,
507 [SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = 44,
508 [SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = 44,
509 [SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = 44,
Prashant Malanic92c5962015-08-11 15:10:18 -0700510 [SND_DEVICE_IN_THREE_MIC] = 46,
511 [SND_DEVICE_IN_QUAD_MIC] = 46,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700512 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = 102,
Prashant Malanic92c5962015-08-11 15:10:18 -0700513 [SND_DEVICE_IN_HANDSET_TMIC] = 125,
514 [SND_DEVICE_IN_HANDSET_QMIC] = 125,
vivek mehta733c1df2016-04-04 15:09:24 -0700515 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = 125, /* override this for new target to 140 */
516 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = 125, /* override this for new target to 140 */
Eric Laurent5f4ca952018-10-19 17:33:43 -0700517 [SND_DEVICE_IN_CAMCORDER_INVERT_LANDSCAPE] = 61,
518 [SND_DEVICE_IN_CAMCORDER_PORTRAIT] = 61,
519 [SND_DEVICE_IN_CAMCORDER_SELFIE_LANDSCAPE] = 61,
520 [SND_DEVICE_IN_CAMCORDER_SELFIE_INVERT_LANDSCAPE] = 61,
521 [SND_DEVICE_IN_CAMCORDER_SELFIE_PORTRAIT] = 61,
Vignesh Kulothungan64698822018-01-23 11:25:18 -0800522 [SND_DEVICE_IN_SPEAKER_QMIC_NS] = 129,
523 [SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS] = 129,
Eric Laurentb23d5282013-05-14 15:27:20 -0700524};
525
David Linee3fe402017-03-13 10:00:42 -0700526// Platform specific backend bit width table
527static int backend_bit_width_table[SND_DEVICE_MAX] = {0};
528
Haynes Mathew George98c95622014-06-20 19:14:25 -0700529struct name_to_index {
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700530 char name[100];
531 unsigned int index;
532};
533
534#define TO_NAME_INDEX(X) #X, X
535
Haynes Mathew George98c95622014-06-20 19:14:25 -0700536/* Used to get index from parsed string */
537static const struct name_to_index snd_device_name_index[SND_DEVICE_MAX] = {
538 /* out */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700539 {TO_NAME_INDEX(SND_DEVICE_OUT_HANDSET)},
540 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER)},
541 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_REVERSE)},
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700542 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700543 {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500544 {TO_NAME_INDEX(SND_DEVICE_OUT_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700545 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700546 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES)},
Eric Laurent744996b2014-10-01 11:40:40 -0500547 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_LINE)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700548 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700549 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET)},
550 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700551 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_HFP)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700552 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADPHONES)},
yixuanjiang9536e672018-09-06 18:43:36 +0800553 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADSET)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500554 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700555 {TO_NAME_INDEX(SND_DEVICE_OUT_HDMI)},
556 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HDMI)},
557 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO)},
juyuchen5351ea62018-05-16 10:54:37 +0800558 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700559 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO_WB)},
juyuchen5351ea62018-05-16 10:54:37 +0800560 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB)},
Aniket Kumar Lata26483012018-01-31 20:21:42 -0800561 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_A2DP)},
562 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP)},
Aniket Kumar Lata9723a962018-05-16 17:41:55 -0700563 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700564 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET_TMUS)},
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500565 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HAC_HANDSET)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700566 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES)},
567 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES)},
568 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET)},
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -0800569 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_SCO)},
570 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800571 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_USB)},
572 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_USB)},
David Linee3fe402017-03-13 10:00:42 -0700573 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADSET)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700574 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_USB_HEADSET)},
David Linee3fe402017-03-13 10:00:42 -0700575 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADPHONES)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700576 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_USB_HEADPHONES)},
David Linee3fe402017-03-13 10:00:42 -0700577 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET)},
Haynes Mathew George9090bfb2017-05-31 11:44:50 -0700578 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700579 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED)},
580 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED)},
jasmine cha270b7762018-03-30 15:41:33 +0800581 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADSET_SPEC)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800582
583 /* in */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700584 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700585 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700586 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_NS)},
587 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)},
588 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC)},
589 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC)},
590 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_NS)},
591 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)},
592 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_STEREO)},
593
594 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700595 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700596 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_NS)},
597 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)},
598 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC)},
599 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC)},
600 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS)},
601 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)},
602 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_STEREO)},
603
604 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC)},
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700605 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700606
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700607 {TO_NAME_INDEX(SND_DEVICE_IN_HDMI_MIC)},
608 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700609 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700610 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700611 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB_NREC)},
Eric Laurent5f4ca952018-10-19 17:33:43 -0700612 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_LANDSCAPE)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700613
614 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC)},
615 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC_TMUS)},
616 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700617 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700618 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC)},
619 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEADSET_MIC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700620 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC)},
621 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC)},
622 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800623 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC)},
624 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC)},
625
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700626
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700627 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700628 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_NS)},
vivek mehta733c1df2016-04-04 15:09:24 -0700629 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC)},
vivek mehtaf3440682016-05-11 14:24:37 -0700630 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700631 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_STEREO)},
632 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE)},
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700633 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_HEADSET_MIC)},
David Linee3fe402017-03-13 10:00:42 -0700634 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700635 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_USB_HEADSET_MIC)},
636 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC)},
637 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC)},
638 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC_AEC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700639
rago90fb9612015-12-02 11:37:53 -0800640 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_MIC)},
641 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC)},
vivek mehta4ed66e62016-04-15 23:33:34 -0700642 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_STEREO_MIC)},
643 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_THREE_MIC)},
644 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_QUAD_MIC)},
rago90fb9612015-12-02 11:37:53 -0800645
Prashant Malanic92c5962015-08-11 15:10:18 -0700646 {TO_NAME_INDEX(SND_DEVICE_IN_THREE_MIC)},
647 {TO_NAME_INDEX(SND_DEVICE_IN_QUAD_MIC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700648 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_VI_FEEDBACK)},
Prashant Malanic92c5962015-08-11 15:10:18 -0700649 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC)},
650 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC)},
vivek mehta733c1df2016-04-04 15:09:24 -0700651 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC_AEC)},
652 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC_AEC)},
Eric Laurent5f4ca952018-10-19 17:33:43 -0700653 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_INVERT_LANDSCAPE)},
654 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_PORTRAIT)},
655 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_SELFIE_LANDSCAPE)},
656 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_SELFIE_INVERT_LANDSCAPE)},
657 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_SELFIE_PORTRAIT)},
658 /* For legacy xml file parsing */
659 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_MIC)},
Vignesh Kulothungan64698822018-01-23 11:25:18 -0800660 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_QMIC_NS)},
661 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700662};
663
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700664static char * backend_tag_table[SND_DEVICE_MAX] = {0};
665static char * hw_interface_table[SND_DEVICE_MAX] = {0};
Haynes Mathew George98c95622014-06-20 19:14:25 -0700666
667static const struct name_to_index usecase_name_index[AUDIO_USECASE_MAX] = {
668 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_DEEP_BUFFER)},
669 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_LOW_LATENCY)},
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800670 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_HIFI)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700671 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD)},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700672 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_TTS)},
673 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_ULL)},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800674 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_MMAP)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700675 {TO_NAME_INDEX(USECASE_AUDIO_RECORD)},
676 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_LOW_LATENCY)},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800677 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_MMAP)},
Haynes Mathew George569b7482017-05-08 14:44:27 -0700678 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_HIFI)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700679 {TO_NAME_INDEX(USECASE_VOICE_CALL)},
680 {TO_NAME_INDEX(USECASE_VOICE2_CALL)},
681 {TO_NAME_INDEX(USECASE_VOLTE_CALL)},
682 {TO_NAME_INDEX(USECASE_QCHAT_CALL)},
683 {TO_NAME_INDEX(USECASE_VOWLAN_CALL)},
John Muirf1346ce2016-12-06 00:03:41 -0800684 {TO_NAME_INDEX(USECASE_VOICEMMODE1_CALL)},
685 {TO_NAME_INDEX(USECASE_VOICEMMODE2_CALL)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700686 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK)},
687 {TO_NAME_INDEX(USECASE_INCALL_REC_DOWNLINK)},
688 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK_AND_DOWNLINK)},
689 {TO_NAME_INDEX(USECASE_AUDIO_HFP_SCO)},
John Muirf1346ce2016-12-06 00:03:41 -0800690 {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_RX)},
691 {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_TX)},
692 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_AFE_PROXY)},
693 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_AFE_PROXY)},
694 {TO_NAME_INDEX(USECASE_AUDIO_DSM_FEEDBACK)},
vivek mehtaa68fea62017-06-08 19:04:02 -0700695 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_VOIP)},
696 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_VOIP)},
Nadav Bar3d72cfc2018-01-07 12:19:24 +0200697 {TO_NAME_INDEX(USECASE_INCALL_MUSIC_UPLINK)},
Aniket Kumar Lata99546312018-03-19 21:38:38 -0700698 {TO_NAME_INDEX(USECASE_AUDIO_A2DP_ABR_FEEDBACK)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700699};
700
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800701static const struct name_to_index usecase_type_index[USECASE_TYPE_MAX] = {
702 {TO_NAME_INDEX(PCM_PLAYBACK)},
703 {TO_NAME_INDEX(PCM_CAPTURE)},
704 {TO_NAME_INDEX(VOICE_CALL)},
705 {TO_NAME_INDEX(PCM_HFP_CALL)},
706};
707
708struct app_type_entry {
709 int uc_type;
710 int bit_width;
711 int app_type;
712 int max_rate;
vivek mehtaa68fea62017-06-08 19:04:02 -0700713 char *mode;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800714 struct listnode node; // membership in app_type_entry_list;
715};
716
717static struct listnode app_type_entry_list;
718
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700719#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
720#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
Eric Laurent0e46adf2016-12-16 12:49:24 -0800721#define ULL_PLATFORM_DELAY (3*1000LL)
722#define MMAP_PLATFORM_DELAY (3*1000LL)
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700723
Eric Laurentb23d5282013-05-14 15:27:20 -0700724static pthread_once_t check_op_once_ctl = PTHREAD_ONCE_INIT;
725static bool is_tmus = false;
726
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800727static int init_be_dai_name_table(struct audio_device *adev);
728
Eric Laurentb23d5282013-05-14 15:27:20 -0700729static void check_operator()
730{
731 char value[PROPERTY_VALUE_MAX];
732 int mccmnc;
733 property_get("gsm.sim.operator.numeric",value,"0");
734 mccmnc = atoi(value);
Eric Laurent2bafff12016-03-17 12:17:23 -0700735 ALOGD("%s: tmus mccmnc %d", __func__, mccmnc);
Eric Laurentb23d5282013-05-14 15:27:20 -0700736 switch(mccmnc) {
737 /* TMUS MCC(310), MNC(490, 260, 026) */
738 case 310490:
739 case 310260:
740 case 310026:
sangwon.jeonb891db52013-09-14 17:39:15 +0900741 /* Add new TMUS MNC(800, 660, 580, 310, 270, 250, 240, 230, 220, 210, 200, 160) */
742 case 310800:
743 case 310660:
744 case 310580:
745 case 310310:
746 case 310270:
747 case 310250:
748 case 310240:
749 case 310230:
750 case 310220:
751 case 310210:
752 case 310200:
753 case 310160:
Eric Laurentb23d5282013-05-14 15:27:20 -0700754 is_tmus = true;
755 break;
756 }
757}
758
759bool is_operator_tmus()
760{
761 pthread_once(&check_op_once_ctl, check_operator);
762 return is_tmus;
763}
764
keunhui.park2f7306a2015-07-16 16:48:06 +0900765static char *get_current_operator()
766{
767 struct listnode *node;
768 struct operator_info *info_item;
769 char mccmnc[PROPERTY_VALUE_MAX];
770 char *ret = NULL;
771
Tom Cherry7fea2042016-11-10 18:05:59 -0800772 property_get("gsm.sim.operator.numeric",mccmnc,"00000");
keunhui.park2f7306a2015-07-16 16:48:06 +0900773
774 list_for_each(node, &operator_info_list) {
775 info_item = node_to_item(node, struct operator_info, list);
776 if (strstr(info_item->mccmnc, mccmnc) != NULL) {
777 ret = info_item->name;
778 }
779 }
780
781 return ret;
782}
783
784static struct operator_specific_device *get_operator_specific_device(snd_device_t snd_device)
785{
786 struct listnode *node;
787 struct operator_specific_device *ret = NULL;
788 struct operator_specific_device *device_item;
789 char *operator_name;
790
791 operator_name = get_current_operator();
792 if (operator_name == NULL)
793 return ret;
794
795 list_for_each(node, operator_specific_device_table[snd_device]) {
796 device_item = node_to_item(node, struct operator_specific_device, list);
797 if (strcmp(operator_name, device_item->operator) == 0) {
798 ret = device_item;
799 }
800 }
801
802 return ret;
803}
804
805
806static int get_operator_specific_device_acdb_id(snd_device_t snd_device)
807{
808 struct operator_specific_device *device;
809 int ret = acdb_device_table[snd_device];
810
811 device = get_operator_specific_device(snd_device);
812 if (device != NULL)
813 ret = device->acdb_id;
814
815 return ret;
816}
817
818static const char *get_operator_specific_device_mixer_path(snd_device_t snd_device)
819{
820 struct operator_specific_device *device;
821 const char *ret = device_table[snd_device];
822
823 device = get_operator_specific_device(snd_device);
824 if (device != NULL)
825 ret = device->mixer_path;
826
827 return ret;
828}
829
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800830inline bool platform_supports_app_type_cfg()
831{
Thierry Strudel07f96d12018-09-20 13:31:34 -0700832#if defined (PLATFORM_MSM8998) || (PLATFORM_SDM845) || (PLATFORM_SDM710) || (PLATFORM_SM8150)
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800833 return true;
834#else
835 return false;
836#endif
837}
838
jasmine chac89321b2018-04-10 21:37:01 +0800839static int parse_audiocal_cfg(struct str_parms *parms, acdb_audio_cal_cfg_t *cal)
840{
841 int err;
842 char value[64];
843 int ret = 0;
844
845 if (parms == NULL || cal == NULL)
846 return ret;
847
848 err = str_parms_get_str(parms, "cal_persist", value, sizeof(value));
849 if (err >= 0) {
850 str_parms_del(parms, "cal_persist");
851 cal->persist = (uint32_t)strtoul(value, NULL, 0);
852 ret = ret | 0x1;
853 }
854 err = str_parms_get_str(parms, "cal_apptype", value, sizeof(value));
855 if (err >= 0) {
856 str_parms_del(parms, "cal_apptype");
857 cal->app_type = (uint32_t)strtoul(value, NULL, 0);
858 ret = ret | 0x2;
859 }
860 err = str_parms_get_str(parms, "cal_caltype", value, sizeof(value));
861 if (err >= 0) {
862 str_parms_del(parms, "cal_caltype");
863 cal->cal_type = (uint32_t)strtoul(value, NULL, 0);
864 ret = ret | 0x4;
865 }
866 err = str_parms_get_str(parms, "cal_samplerate", value, sizeof(value));
867 if (err >= 0) {
868 str_parms_del(parms, "cal_samplerate");
869 cal->sampling_rate = (uint32_t)strtoul(value, NULL, 0);
870 ret = ret | 0x8;
871 }
872 err = str_parms_get_str(parms, "cal_devid", value, sizeof(value));
873 if (err >= 0) {
874 str_parms_del(parms, "cal_devid");
875 cal->dev_id = (uint32_t)strtoul(value, NULL, 0);
876 ret = ret | 0x10;
877 }
878 err = str_parms_get_str(parms, "cal_snddevid", value, sizeof(value));
879 if (err >= 0) {
880 str_parms_del(parms, "cal_snddevid");
881 cal->snd_dev_id = (uint32_t)strtoul(value, NULL, 0);
882 ret = ret | 0x20;
883 }
884 err = str_parms_get_str(parms, "cal_topoid", value, sizeof(value));
885 if (err >= 0) {
886 str_parms_del(parms, "cal_topoid");
887 cal->topo_id = (uint32_t)strtoul(value, NULL, 0);
888 ret = ret | 0x40;
889 }
890 err = str_parms_get_str(parms, "cal_moduleid", value, sizeof(value));
891 if (err >= 0) {
892 str_parms_del(parms, "cal_moduleid");
893 cal->module_id = (uint32_t)strtoul(value, NULL, 0);
894 ret = ret | 0x80;
895 }
896 err = str_parms_get_str(parms, "cal_paramid", value, sizeof(value));
897 if (err >= 0) {
898 str_parms_del(parms, "cal_paramid");
899 cal->param_id = (uint32_t)strtoul(value, NULL, 0);
900 ret = ret | 0x100;
901 }
902 return ret;
903}
904
905static void set_audiocal(void *platform, struct str_parms *parms, char *value, int len)
906{
907 struct platform_data *my_data = (struct platform_data *)platform;
908 acdb_audio_cal_cfg_t cal;
909 uint8_t *dptr = NULL;
910 int32_t dlen = 0;
911 int err ,ret;
912
913 if (value == NULL || platform == NULL || parms == NULL) {
914 ALOGE("[%s] received null pointer, failed", __func__);
915 goto done_key_audcal;
916 }
917
918 memset(&cal, 0, sizeof(acdb_audio_cal_cfg_t));
919 /* parse audio calibration keys */
920 ret = parse_audiocal_cfg(parms, &cal);
921
922 /* handle audio calibration data now */
923 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_AUD_CALDATA, value, len);
924 if (err >= 0) {
925 str_parms_del(parms, AUDIO_PARAMETER_KEY_AUD_CALDATA);
926 dlen = strlen(value);
927 if (dlen <= 0) {
928 ALOGE("[%s] null data received", __func__);
929 goto done_key_audcal;
930 }
931 /*
932 The base64 encoded string is always larger than the binary data,
933 so b64_pton will always output less data than provided (around 1/3
934 less than the input data). That's why we can allocate input buffer
935 length and then get function work.
936 */
937 dptr = (uint8_t *)calloc(dlen, sizeof(uint8_t));
938 if (dptr == NULL) {
939 ALOGE("[%s] memory allocation failed for %d", __func__, dlen);
940 goto done_key_audcal;
941 }
942 dlen = b64_pton(value, dptr, dlen);
943 if (dlen <= 0) {
944 ALOGE("[%s] data decoding failed %d", __func__, dlen);
945 goto done_key_audcal;
946 }
947
948 if (cal.dev_id) {
949 if (audio_is_input_device(cal.dev_id)) {
Eric Laurentd1b7a9b2018-11-15 12:24:31 -0800950 // FIXME: why pass an input device whereas
951 // platform_get_input_snd_device() expects as an output device?
952 cal.snd_dev_id = platform_get_input_snd_device(platform, NULL, cal.dev_id);
jasmine chac89321b2018-04-10 21:37:01 +0800953 } else {
954 cal.snd_dev_id = platform_get_output_snd_device(platform, cal.dev_id);
955 }
956 }
957 cal.acdb_dev_id = platform_get_snd_device_acdb_id(cal.snd_dev_id);
958 ALOGD("Setting audio calibration for snd_device(%d) acdb_id(%d)",
959 cal.snd_dev_id, cal.acdb_dev_id);
960 if (cal.acdb_dev_id == -EINVAL) {
961 ALOGE("[%s] Invalid acdb_device id %d for snd device id %d",
962 __func__, cal.acdb_dev_id, cal.snd_dev_id);
963 goto done_key_audcal;
964 }
965 if (my_data->acdb_set_audio_cal) {
966 ret = my_data->acdb_set_audio_cal((void *)&cal, (void *)dptr, dlen);
967 }
968 }
969done_key_audcal:
970 if (dptr != NULL)
971 free(dptr);
972}
973
vivek mehta1a9b7c02015-06-25 11:49:38 -0700974bool platform_send_gain_dep_cal(void *platform, int level)
975{
976 bool ret_val = false;
977 struct platform_data *my_data = (struct platform_data *)platform;
978 struct audio_device *adev = my_data->adev;
979 int acdb_dev_id, app_type;
980 int acdb_dev_type = MSM_SNDDEV_CAP_RX;
981 int mode = CAL_MODE_RTAC;
982 struct listnode *node;
983 struct audio_usecase *usecase;
Haynes Mathew George67486e22017-06-26 12:58:38 -0700984 bool valid_uc_type;
985 bool valid_dev;
vivek mehta1a9b7c02015-06-25 11:49:38 -0700986
987 if (my_data->acdb_send_gain_dep_cal == NULL) {
988 ALOGE("%s: dlsym error for acdb_send_gain_dep_cal", __func__);
989 return ret_val;
990 }
991
992 if (!voice_is_in_call(adev)) {
993 ALOGV("%s: Not Voice call usecase, apply new cal for level %d",
994 __func__, level);
vivek mehta1a9b7c02015-06-25 11:49:38 -0700995
996 // find the current active sound device
997 list_for_each(node, &adev->usecase_list) {
998 usecase = node_to_item(node, struct audio_usecase, list);
Haynes Mathew George67486e22017-06-26 12:58:38 -0700999 LOG_ALWAYS_FATAL_IF(usecase == NULL,
1000 "unxpected NULL usecase in usecase_list");
1001 valid_uc_type = usecase->type == PCM_PLAYBACK;
1002 valid_dev = false;
1003 if (valid_uc_type) {
1004 audio_devices_t dev = usecase->stream.out->devices;
1005 valid_dev = (dev == AUDIO_DEVICE_OUT_SPEAKER ||
vivek mehta40125092017-08-21 18:48:51 -07001006 dev == AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Haynes Mathew George67486e22017-06-26 12:58:38 -07001007 dev == AUDIO_DEVICE_OUT_WIRED_HEADSET ||
1008 dev == AUDIO_DEVICE_OUT_WIRED_HEADPHONE);
1009 }
1010 if (valid_dev) {
vivek mehta40125092017-08-21 18:48:51 -07001011 ALOGV("%s: out device is %d", __func__, usecase->out_snd_device);
1012 if (platform_supports_app_type_cfg())
1013 app_type = usecase->stream.out->app_type_cfg.app_type;
1014 else
1015 app_type = DEFAULT_APP_TYPE_RX_PATH;
vivek mehta4cb82982015-07-13 12:05:49 -07001016
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07001017 acdb_dev_id = platform_get_snd_device_acdb_id(usecase->out_snd_device);
vivek mehta40125092017-08-21 18:48:51 -07001018
1019 if (!my_data->acdb_send_gain_dep_cal(acdb_dev_id, app_type,
vivek mehta1a9b7c02015-06-25 11:49:38 -07001020 acdb_dev_type, mode, level)) {
1021 // set ret_val true if at least one calibration is set successfully
1022 ret_val = true;
1023 } else {
1024 ALOGE("%s: my_data->acdb_send_gain_dep_cal failed ", __func__);
1025 }
1026 } else {
1027 ALOGW("%s: Usecase list is empty", __func__);
1028 }
1029 }
1030 } else {
1031 ALOGW("%s: Voice call in progress .. ignore setting new cal",
1032 __func__);
1033 }
1034 return ret_val;
1035}
1036
Eric Laurentcefbbac2014-09-04 13:54:10 -05001037void platform_set_echo_reference(struct audio_device *adev, bool enable, audio_devices_t out_device)
Eric Laurentb23d5282013-05-14 15:27:20 -07001038{
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08001039 struct platform_data *my_data = (struct platform_data *)adev->platform;
Eric Laurentcefbbac2014-09-04 13:54:10 -05001040 snd_device_t snd_device = SND_DEVICE_NONE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001041
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08001042 if (strcmp(my_data->ec_ref_mixer_path, "")) {
1043 ALOGV("%s: diabling %s", __func__, my_data->ec_ref_mixer_path);
1044 audio_route_reset_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
Eric Laurentcefbbac2014-09-04 13:54:10 -05001045 }
1046
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08001047 if (enable) {
1048 strcpy(my_data->ec_ref_mixer_path, "echo-reference");
1049 if (out_device != AUDIO_DEVICE_NONE) {
1050 snd_device = platform_get_output_snd_device(adev->platform, out_device);
1051 platform_add_backend_name(adev->platform, my_data->ec_ref_mixer_path, snd_device);
1052 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05001053
Joe Onorato188b6222016-03-01 11:02:27 -08001054 ALOGV("%s: enabling %s", __func__, my_data->ec_ref_mixer_path);
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08001055 audio_route_apply_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
1056 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001057}
1058
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001059static struct csd_data *open_csd_client(bool i2s_ext_modem)
1060{
1061 struct csd_data *csd = calloc(1, sizeof(struct csd_data));
1062
1063 csd->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
1064 if (csd->csd_client == NULL) {
1065 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
1066 goto error;
1067 } else {
1068 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
1069
1070 csd->deinit = (deinit_t)dlsym(csd->csd_client,
1071 "csd_client_deinit");
1072 if (csd->deinit == NULL) {
1073 ALOGE("%s: dlsym error %s for csd_client_deinit", __func__,
1074 dlerror());
1075 goto error;
1076 }
1077 csd->disable_device = (disable_device_t)dlsym(csd->csd_client,
1078 "csd_client_disable_device");
1079 if (csd->disable_device == NULL) {
1080 ALOGE("%s: dlsym error %s for csd_client_disable_device",
1081 __func__, dlerror());
1082 goto error;
1083 }
1084 csd->enable_device_config = (enable_device_config_t)dlsym(csd->csd_client,
1085 "csd_client_enable_device_config");
1086 if (csd->enable_device_config == NULL) {
1087 ALOGE("%s: dlsym error %s for csd_client_enable_device_config",
1088 __func__, dlerror());
1089 goto error;
1090 }
1091 csd->enable_device = (enable_device_t)dlsym(csd->csd_client,
1092 "csd_client_enable_device");
1093 if (csd->enable_device == NULL) {
1094 ALOGE("%s: dlsym error %s for csd_client_enable_device",
1095 __func__, dlerror());
1096 goto error;
1097 }
1098 csd->start_voice = (start_voice_t)dlsym(csd->csd_client,
1099 "csd_client_start_voice");
1100 if (csd->start_voice == NULL) {
1101 ALOGE("%s: dlsym error %s for csd_client_start_voice",
1102 __func__, dlerror());
1103 goto error;
1104 }
1105 csd->stop_voice = (stop_voice_t)dlsym(csd->csd_client,
1106 "csd_client_stop_voice");
1107 if (csd->stop_voice == NULL) {
1108 ALOGE("%s: dlsym error %s for csd_client_stop_voice",
1109 __func__, dlerror());
1110 goto error;
1111 }
1112 csd->volume = (volume_t)dlsym(csd->csd_client,
1113 "csd_client_volume");
1114 if (csd->volume == NULL) {
1115 ALOGE("%s: dlsym error %s for csd_client_volume",
1116 __func__, dlerror());
1117 goto error;
1118 }
1119 csd->mic_mute = (mic_mute_t)dlsym(csd->csd_client,
1120 "csd_client_mic_mute");
1121 if (csd->mic_mute == NULL) {
1122 ALOGE("%s: dlsym error %s for csd_client_mic_mute",
1123 __func__, dlerror());
1124 goto error;
1125 }
1126 csd->slow_talk = (slow_talk_t)dlsym(csd->csd_client,
1127 "csd_client_slow_talk");
1128 if (csd->slow_talk == NULL) {
1129 ALOGE("%s: dlsym error %s for csd_client_slow_talk",
1130 __func__, dlerror());
1131 goto error;
1132 }
1133 csd->start_playback = (start_playback_t)dlsym(csd->csd_client,
1134 "csd_client_start_playback");
1135 if (csd->start_playback == NULL) {
1136 ALOGE("%s: dlsym error %s for csd_client_start_playback",
1137 __func__, dlerror());
1138 goto error;
1139 }
1140 csd->stop_playback = (stop_playback_t)dlsym(csd->csd_client,
1141 "csd_client_stop_playback");
1142 if (csd->stop_playback == NULL) {
1143 ALOGE("%s: dlsym error %s for csd_client_stop_playback",
1144 __func__, dlerror());
1145 goto error;
1146 }
1147 csd->start_record = (start_record_t)dlsym(csd->csd_client,
1148 "csd_client_start_record");
1149 if (csd->start_record == NULL) {
1150 ALOGE("%s: dlsym error %s for csd_client_start_record",
1151 __func__, dlerror());
1152 goto error;
1153 }
1154 csd->stop_record = (stop_record_t)dlsym(csd->csd_client,
1155 "csd_client_stop_record");
1156 if (csd->stop_record == NULL) {
1157 ALOGE("%s: dlsym error %s for csd_client_stop_record",
1158 __func__, dlerror());
1159 goto error;
1160 }
1161
1162 csd->get_sample_rate = (get_sample_rate_t)dlsym(csd->csd_client,
1163 "csd_client_get_sample_rate");
1164 if (csd->get_sample_rate == NULL) {
1165 ALOGE("%s: dlsym error %s for csd_client_get_sample_rate",
1166 __func__, dlerror());
1167
1168 goto error;
1169 }
1170
1171 csd->init = (init_t)dlsym(csd->csd_client, "csd_client_init");
1172
1173 if (csd->init == NULL) {
1174 ALOGE("%s: dlsym error %s for csd_client_init",
1175 __func__, dlerror());
1176 goto error;
1177 } else {
1178 csd->init(i2s_ext_modem);
1179 }
1180 }
1181 return csd;
1182
1183error:
1184 free(csd);
1185 csd = NULL;
1186 return csd;
1187}
1188
1189void close_csd_client(struct csd_data *csd)
1190{
1191 if (csd != NULL) {
1192 csd->deinit();
1193 dlclose(csd->csd_client);
1194 free(csd);
1195 csd = NULL;
1196 }
1197}
1198
1199static void platform_csd_init(struct platform_data *my_data)
1200{
1201#ifdef PLATFORM_MSM8084
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001202 int32_t modems, (*count_modems)(void);
1203 const char *name = "libdetectmodem.so";
1204 const char *func = "count_modems";
1205 const char *error;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001206
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001207 my_data->csd = NULL;
1208
1209 void *lib = dlopen(name, RTLD_NOW);
1210 error = dlerror();
1211 if (!lib) {
1212 ALOGE("%s: could not find %s: %s", __func__, name, error);
1213 return;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001214 }
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001215
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001216 count_modems = NULL;
1217 *(void **)(&count_modems) = dlsym(lib, func);
1218 error = dlerror();
1219 if (!count_modems) {
1220 ALOGE("%s: could not find symbol %s in %s: %s",
1221 __func__, func, name, error);
1222 goto done;
1223 }
1224
1225 modems = count_modems();
1226 if (modems < 0) {
1227 ALOGE("%s: count_modems failed\n", __func__);
1228 goto done;
1229 }
1230
Eric Laurent2bafff12016-03-17 12:17:23 -07001231 ALOGD("%s: num_modems %d\n", __func__, modems);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001232 if (modems > 0)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001233 my_data->csd = open_csd_client(false /*is_i2s_ext_modem*/);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001234
1235done:
1236 dlclose(lib);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001237#else
1238 my_data->csd = NULL;
1239#endif
1240}
1241
Eric Laurentc6333382015-09-14 12:43:44 -07001242static void set_platform_defaults(struct platform_data * my_data)
Haynes Mathew George98c95622014-06-20 19:14:25 -07001243{
1244 int32_t dev;
1245 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001246 backend_tag_table[dev] = NULL;
1247 hw_interface_table[dev] = NULL;
keunhui.park2f7306a2015-07-16 16:48:06 +09001248 operator_specific_device_table[dev] = NULL;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001249 }
1250
David Linee3fe402017-03-13 10:00:42 -07001251 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1252 backend_bit_width_table[dev] = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
1253 }
1254
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001255 // To overwrite these go to the audio_platform_info.xml file.
1256 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("bt-sco");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07001257 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("bt-sco");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001258 backend_tag_table[SND_DEVICE_OUT_BT_SCO] = strdup("bt-sco");
1259 backend_tag_table[SND_DEVICE_OUT_HDMI] = strdup("hdmi");
1260 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("speaker-and-hdmi");
1261 backend_tag_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("bt-sco-wb");
1262 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("bt-sco-wb");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07001263 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("bt-sco-wb");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001264 backend_tag_table[SND_DEVICE_OUT_VOICE_TX] = strdup("afe-proxy");
1265 backend_tag_table[SND_DEVICE_IN_VOICE_RX] = strdup("afe-proxy");
Haynes Mathew George98c95622014-06-20 19:14:25 -07001266
David Linee3fe402017-03-13 10:00:42 -07001267 backend_tag_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("usb-headset");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001268 backend_tag_table[SND_DEVICE_OUT_VOICE_USB_HEADSET] = strdup("usb-headset");
David Linee3fe402017-03-13 10:00:42 -07001269 backend_tag_table[SND_DEVICE_OUT_USB_HEADPHONES] = strdup("usb-headphones");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001270 backend_tag_table[SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = strdup("usb-headphones");
David Linee3fe402017-03-13 10:00:42 -07001271 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] =
1272 strdup("speaker-and-usb-headphones");
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07001273 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] =
1274 strdup("speaker-safe-and-usb-headphones");
juyuchen5351ea62018-05-16 10:54:37 +08001275 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO] =
1276 strdup("speaker-safe-and-bt-sco"),
1277 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB] =
1278 strdup("speaker-safe-and-bt-sco-wb"),
David Linee3fe402017-03-13 10:00:42 -07001279 backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("usb-headset-mic");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001280 backend_tag_table[SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1281 backend_tag_table[SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1282 backend_tag_table[SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1283 backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = strdup("usb-headset-mic");
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001284 backend_tag_table[SND_DEVICE_OUT_BT_A2DP] = strdup("bt-a2dp");
1285 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] = strdup("speaker-and-bt-a2dp");
Aniket Kumar Lata9723a962018-05-16 17:41:55 -07001286 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP] = strdup("speaker-safe-and-bt-a2dp");
jasmine cha270b7762018-03-30 15:41:33 +08001287 backend_tag_table[SND_DEVICE_OUT_USB_HEADSET_SPEC] = strdup("usb-headset");
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001288
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001289 hw_interface_table[SND_DEVICE_OUT_HANDSET] = strdup("SLIMBUS_0_RX");
1290 hw_interface_table[SND_DEVICE_OUT_SPEAKER] = strdup("SLIMBUS_0_RX");
1291 hw_interface_table[SND_DEVICE_OUT_SPEAKER_REVERSE] = strdup("SLIMBUS_0_RX");
1292 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE] = strdup("SLIMBUS_0_RX");
1293 hw_interface_table[SND_DEVICE_OUT_HEADPHONES] = strdup("SLIMBUS_0_RX");
1294 hw_interface_table[SND_DEVICE_OUT_LINE] = strdup("SLIMBUS_0_RX");
1295 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001296 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001297 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001298 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001299 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET] = strdup("SLIMBUS_0_RX");
1300 hw_interface_table[SND_DEVICE_OUT_VOICE_HAC_HANDSET] = strdup("SLIMBUS_0_RX");
1301 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER] = strdup("SLIMBUS_0_RX");
1302 hw_interface_table[SND_DEVICE_OUT_VOICE_HEADPHONES] = strdup("SLIMBUS_0_RX");
yixuanjiang9536e672018-09-06 18:43:36 +08001303 hw_interface_table[SND_DEVICE_OUT_VOICE_HEADSET] = strdup("SLIMBUS_0_RX");
juyuchen66c4ecf2018-08-06 15:39:34 +08001304 hw_interface_table[SND_DEVICE_OUT_VOICE_MUSIC_TX] = strdup("VOICE_PLAYBACK_TX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001305 hw_interface_table[SND_DEVICE_OUT_VOICE_LINE] = strdup("SLIMBUS_0_RX");
1306 hw_interface_table[SND_DEVICE_OUT_HDMI] = strdup("HDMI_RX");
1307 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("SLIMBUS_0_RX-and-HDMI_RX");
1308 hw_interface_table[SND_DEVICE_OUT_BT_SCO] = strdup("SEC_AUX_PCM_RX");
1309 hw_interface_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("SEC_AUX_PCM_RX");
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001310 hw_interface_table[SND_DEVICE_OUT_BT_A2DP] = strdup("SLIMBUS_7_RX");
1311 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] =
1312 strdup("SLIMBUS_0_RX-and-SLIMBUS_7_RX");
Aniket Kumar Lata9723a962018-05-16 17:41:55 -07001313 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP] =
1314 strdup("SLIMBUS_0_RX-and-SLIMBUS_7_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001315 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = strdup("SLIMBUS_0_RX");
1316 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = strdup("SLIMBUS_0_RX");
1317 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = strdup("SLIMBUS_0_RX");
1318 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = strdup("SLIMBUS_0_RX");
David Linee3fe402017-03-13 10:00:42 -07001319 hw_interface_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("USB_AUDIO_RX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001320 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = strdup("USB_AUDIO_RX");
1321 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = strdup("USB_AUDIO_RX");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001322 hw_interface_table[SND_DEVICE_OUT_VOICE_USB_HEADSET] = strdup("USB_AUDIO_RX");
David Linee3fe402017-03-13 10:00:42 -07001323 hw_interface_table[SND_DEVICE_OUT_USB_HEADPHONES] = strdup("USB_AUDIO_RX");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001324 hw_interface_table[SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = strdup("USB_AUDIO_RX");
jasmine cha270b7762018-03-30 15:41:33 +08001325 hw_interface_table[SND_DEVICE_OUT_USB_HEADSET_SPEC] = strdup("USB_AUDIO_RX");
David Linee3fe402017-03-13 10:00:42 -07001326 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 -07001327 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 -07001328 hw_interface_table[SND_DEVICE_OUT_VOICE_TX] = strdup("AFE_PCM_RX");
1329 hw_interface_table[SND_DEVICE_OUT_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
1330 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
jasmine cha52284622018-03-23 17:21:35 +08001331 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = strdup("SLIMBUS_0_RX");
1332 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_BT_SCO] = strdup("SLIMBUS_0_RX-and-SEC_AUX_PCM_RX");
1333 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 +08001334 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO] = strdup("QUAT_TDM_RX_0-and-SLIMBUS_7_RX"),
1335 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB] = strdup("QUAT_TDM_RX_0-and-SLIMBUS_7_RX"),
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001336 hw_interface_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1337 hw_interface_table[SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1338 hw_interface_table[SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = strdup("USB_AUDIO_TX");
1339 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1340 hw_interface_table[SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1341 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = strdup("USB_AUDIO_TX");
1342 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = strdup("USB_AUDIO_TX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001343 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001344 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_AEC] = strdup("SLIMBUS_0_TX");
1345 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_NS] = strdup("SLIMBUS_0_TX");
1346 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1347 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC] = strdup("SLIMBUS_0_TX");
1348 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_AEC] = strdup("SLIMBUS_0_TX");
1349 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_NS] = strdup("SLIMBUS_0_TX");
1350 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1351 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001352 hw_interface_table[SND_DEVICE_IN_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001353 hw_interface_table[SND_DEVICE_IN_HEADSET_MIC_AEC] = strdup("SLIMBUS_0_TX");
Eric Laurent5f4ca952018-10-19 17:33:43 -07001354 hw_interface_table[SND_DEVICE_IN_CAMCORDER_LANDSCAPE] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001355 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC] = strdup("SLIMBUS_0_TX");
1356 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC_NS] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001357 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC_AEC] = strdup("SLIMBUS_0_TX");
1358 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001359 hw_interface_table[SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
1360 hw_interface_table[SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = strdup("SLIMBUS_0_TX");
David Lin93725722017-10-13 14:58:17 -07001361 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_MIC] = strdup("SLIMBUS_0_TX");
1362 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1363 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = strdup("SLIMBUS_0_TX");
1364 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = strdup("SLIMBUS_0_TX");
1365 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001366 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC] = strdup("SLIMBUS_0_TX");
1367 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_AEC] = strdup("SLIMBUS_0_TX");
1368 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_NS] = strdup("SLIMBUS_0_TX");
1369 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1370 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC] = strdup("SLIMBUS_0_TX");
1371 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_AEC] = strdup("SLIMBUS_0_TX");
1372 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_NS] = strdup("SLIMBUS_0_TX");
1373 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001374 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
1375 hw_interface_table[SND_DEVICE_IN_VOICE_DMIC] = strdup("SLIMBUS_0_TX");
1376 hw_interface_table[SND_DEVICE_IN_VOICE_DMIC_TMUS] = strdup("SLIMBUS_0_TX");
Vignesh Kulothungan64698822018-01-23 11:25:18 -08001377 hw_interface_table[SND_DEVICE_IN_SPEAKER_QMIC_NS] = strdup("SLIMBUS_0_TX");
1378 hw_interface_table[SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001379 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001380 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = strdup("SLIMBUS_0_TX");
1381 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001382 hw_interface_table[SND_DEVICE_IN_VOICE_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001383 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1384 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = strdup("SLIMBUS_0_TX");
1385 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1386 hw_interface_table[SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1387 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("SEC_AUX_PCM_TX");
1388 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("SEC_AUX_PCM_TX");
1389 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("SEC_AUX_PCM_TX");
1390 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("SEC_AUX_PCM_TX");
1391 hw_interface_table[SND_DEVICE_IN_VOICE_RX] = strdup("AFE_PCM_TX");
1392 hw_interface_table[SND_DEVICE_IN_THREE_MIC] = strdup("SLIMBUS_0_TX");
1393 hw_interface_table[SND_DEVICE_IN_QUAD_MIC] = strdup("SLIMBUS_0_TX");
1394 hw_interface_table[SND_DEVICE_IN_HANDSET_TMIC] = strdup("SLIMBUS_0_TX");
1395 hw_interface_table[SND_DEVICE_IN_HANDSET_QMIC] = strdup("SLIMBUS_0_TX");
1396 hw_interface_table[SND_DEVICE_IN_HANDSET_TMIC_AEC] = strdup("SLIMBUS_0_TX");
1397 hw_interface_table[SND_DEVICE_IN_HANDSET_QMIC_AEC] = strdup("SLIMBUS_0_TX");
Eric Laurent5f4ca952018-10-19 17:33:43 -07001398 hw_interface_table[SND_DEVICE_IN_CAMCORDER_INVERT_LANDSCAPE] = strdup("SLIMBUS_0_TX");
1399 hw_interface_table[SND_DEVICE_IN_CAMCORDER_PORTRAIT] = strdup("SLIMBUS_0_TX");
1400 hw_interface_table[SND_DEVICE_IN_CAMCORDER_SELFIE_LANDSCAPE] = strdup("SLIMBUS_0_TX");
1401 hw_interface_table[SND_DEVICE_IN_CAMCORDER_SELFIE_INVERT_LANDSCAPE] = strdup("SLIMBUS_0_TX");
1402 hw_interface_table[SND_DEVICE_IN_CAMCORDER_SELFIE_PORTRAIT] = strdup("SLIMBUS_0_TX");
Eric Laurentc6333382015-09-14 12:43:44 -07001403 my_data->max_mic_count = PLATFORM_DEFAULT_MIC_COUNT;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001404}
1405
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001406void get_cvd_version(char *cvd_version, struct audio_device *adev)
1407{
1408 struct mixer_ctl *ctl;
1409 int count;
1410 int ret = 0;
1411
1412 ctl = mixer_get_ctl_by_name(adev->mixer, CVD_VERSION_MIXER_CTL);
1413 if (!ctl) {
1414 ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__, CVD_VERSION_MIXER_CTL);
1415 goto done;
1416 }
1417 mixer_ctl_update(ctl);
1418
1419 count = mixer_ctl_get_num_values(ctl);
1420 if (count > MAX_CVD_VERSION_STRING_SIZE)
1421 count = MAX_CVD_VERSION_STRING_SIZE - 1;
1422
1423 ret = mixer_ctl_get_array(ctl, cvd_version, count);
1424 if (ret != 0) {
1425 ALOGE("%s: ERROR! mixer_ctl_get_array() failed to get CVD Version", __func__);
1426 goto done;
1427 }
1428
1429done:
1430 return;
1431}
1432
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001433static int platform_acdb_init(void *platform)
1434{
1435 struct platform_data *my_data = (struct platform_data *)platform;
1436 struct audio_device *adev = my_data->adev;
1437
1438 if (!my_data->acdb_init) {
1439 ALOGE("%s: no acdb_init fn provided", __func__);
1440 return -1;
1441 }
1442
1443 if (my_data->acdb_initialized) {
1444 ALOGW("acdb is already initialized");
1445 return 0;
1446 }
1447
Thierry Strudel07f96d12018-09-20 13:31:34 -07001448#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845) || (PLATFORM_SDM710) || (PLATFORM_SM8150)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001449 char *cvd_version = calloc(1, MAX_CVD_VERSION_STRING_SIZE);
1450 if (!cvd_version)
1451 ALOGE("failed to allocate cvd_version");
1452 else {
1453 get_cvd_version(cvd_version, adev);
1454 my_data->acdb_init((char *)my_data->snd_card_name, cvd_version, 0);
1455 free(cvd_version);
1456 }
1457#elif defined (PLATFORM_MSM8084)
1458 my_data->acdb_init((char *)my_data->snd_card_name);
1459#else
1460 my_data->acdb_init();
1461#endif
1462 my_data->acdb_initialized = true;
1463 return 0;
1464}
1465
David Linee3fe402017-03-13 10:00:42 -07001466static void
1467platform_backend_config_init(struct platform_data *pdata)
1468{
1469 int i;
1470
1471 /* initialize backend config */
1472 for (i = 0; i < MAX_CODEC_BACKENDS; i++) {
1473 pdata->current_backend_cfg[i].sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
1474 pdata->current_backend_cfg[i].bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
1475 pdata->current_backend_cfg[i].channels = CODEC_BACKEND_DEFAULT_CHANNELS;
1476
1477 if (i > MAX_RX_CODEC_BACKENDS)
1478 pdata->current_backend_cfg[i].channels = CODEC_BACKEND_DEFAULT_TX_CHANNELS;
1479
1480 pdata->current_backend_cfg[i].bitwidth_mixer_ctl = NULL;
1481 pdata->current_backend_cfg[i].samplerate_mixer_ctl = NULL;
1482 pdata->current_backend_cfg[i].channels_mixer_ctl = NULL;
1483 }
1484
1485 pdata->current_backend_cfg[DEFAULT_CODEC_BACKEND].bitwidth_mixer_ctl =
1486 strdup("SLIM_0_RX Format");
1487 pdata->current_backend_cfg[DEFAULT_CODEC_BACKEND].samplerate_mixer_ctl =
1488 strdup("SLIM_0_RX SampleRate");
1489
1490 pdata->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].bitwidth_mixer_ctl =
1491 strdup("SLIM_0_TX Format");
1492 pdata->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].samplerate_mixer_ctl =
1493 strdup("SLIM_0_TX SampleRate");
1494
1495 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].bitwidth_mixer_ctl =
1496 strdup("USB_AUDIO_TX Format");
1497 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].samplerate_mixer_ctl =
1498 strdup("USB_AUDIO_TX SampleRate");
1499 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].channels_mixer_ctl =
1500 strdup("USB_AUDIO_TX Channels");
1501
Yung Ti Su39a2b8a2018-10-05 15:43:40 +08001502 if (strstr(pdata->snd_card_name, "intcodec")) {
1503 pdata->current_backend_cfg[HEADPHONE_BACKEND].bitwidth_mixer_ctl =
1504 strdup("INT0_MI2S_RX Format");
1505 pdata->current_backend_cfg[HEADPHONE_BACKEND].samplerate_mixer_ctl =
1506 strdup("INT0_MI2S_RX SampleRate");
1507 } else {
1508 pdata->current_backend_cfg[HEADPHONE_BACKEND].bitwidth_mixer_ctl =
1509 strdup("SLIM_6_RX Format");
1510 pdata->current_backend_cfg[HEADPHONE_BACKEND].samplerate_mixer_ctl =
1511 strdup("SLIM_6_RX SampleRate");
1512 }
David Linee3fe402017-03-13 10:00:42 -07001513
1514 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].bitwidth_mixer_ctl =
1515 strdup("USB_AUDIO_RX Format");
1516 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].samplerate_mixer_ctl =
1517 strdup("USB_AUDIO_RX SampleRate");
1518
1519 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].channels = 1;
1520 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].channels_mixer_ctl =
1521 strdup("USB_AUDIO_RX Channels");
1522}
1523
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001524static int
1525platform_backend_app_type_cfg_init(struct platform_data *pdata,
1526 struct mixer *mixer)
1527{
1528 size_t app_type_cfg[128] = {0};
1529 int length, num_app_types = 0;
1530 struct mixer_ctl *ctl = NULL;
1531
1532 const char *mixer_ctl_name = "App Type Config";
1533 ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name);
1534 if (!ctl) {
1535 ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name);
1536 return -1;
1537 }
1538
1539 length = 1; // reserve index 0 for number of app types
1540
1541 struct listnode *node;
1542 struct app_type_entry *entry;
1543 list_for_each(node, &app_type_entry_list) {
1544 entry = node_to_item(node, struct app_type_entry, node);
1545 app_type_cfg[length++] = entry->app_type;
1546 app_type_cfg[length++] = entry->max_rate;
1547 app_type_cfg[length++] = entry->bit_width;
1548 ALOGI("%s add entry %d %d", __func__, entry->app_type, entry->bit_width);
1549 num_app_types += 1;
1550 }
1551
1552 // default for capture
1553 int t;
1554 platform_get_default_app_type_v2(pdata,
1555 PCM_CAPTURE,
1556 &t);
1557 app_type_cfg[length++] = t;
1558 app_type_cfg[length++] = 48000;
1559 app_type_cfg[length++] = 16;
1560 num_app_types += 1;
1561
1562 if (num_app_types) {
1563 app_type_cfg[0] = num_app_types;
1564 if (mixer_ctl_set_array(ctl, app_type_cfg, length) < 0) {
1565 ALOGE("Failed to set app type cfg");
1566 }
1567 }
1568 return 0;
1569}
1570
Xu Han1638fd12018-04-20 12:42:23 -07001571static void configure_flicker_sensor_input(struct mixer *mixer)
1572{
1573 struct mixer_ctl *ctl;
1574 const char* ctl1 = "AIF3_CAP Mixer SLIM TX2";
1575 int setting1 = 1;
1576 const char* ctl2 = "CDC_IF TX2 MUX";
1577 const char* setting2 = "DEC2";
1578 const char* ctl3 = "SLIM_1_TX Channels";
1579 const char* setting3 = "One";
1580 const char* ctl4 = "ADC MUX2";
1581 const char* setting4 = "AMIC";
1582 const char* ctl5 = "AMIC MUX2";
1583 const char* setting5 = "ADC1";
1584 const char* ctl6 = "DEC2 Volume";
1585 int setting6 = 84;
Xu Han07e07402018-05-15 14:19:25 -07001586 const char* ctl7 = "MultiMedia9 Mixer SLIM_1_TX";
Xu Han1638fd12018-04-20 12:42:23 -07001587 int setting7 = 1;
1588 const char* ctl8 = "SLIM_1_TX SampleRate";
1589 const char* setting8 = "KHZ_8";
1590
1591 ctl = mixer_get_ctl_by_name(mixer, ctl1);
1592 mixer_ctl_set_value(ctl, 0, setting1);
1593 ctl = mixer_get_ctl_by_name(mixer, ctl2);
1594 mixer_ctl_set_enum_by_string(ctl, setting2);
1595 ctl = mixer_get_ctl_by_name(mixer, ctl3);
1596 mixer_ctl_set_enum_by_string(ctl, setting3);
1597 ctl = mixer_get_ctl_by_name(mixer, ctl4);
1598 mixer_ctl_set_enum_by_string(ctl, setting4);
1599 ctl = mixer_get_ctl_by_name(mixer, ctl5);
1600 mixer_ctl_set_enum_by_string(ctl, setting5);
1601 ctl = mixer_get_ctl_by_name(mixer, ctl6);
1602 mixer_ctl_set_value(ctl, 0, setting6);
1603 ctl = mixer_get_ctl_by_name(mixer, ctl7);
1604 mixer_ctl_set_value(ctl, 0, setting7);
1605 ctl = mixer_get_ctl_by_name(mixer, ctl8);
1606 mixer_ctl_set_enum_by_string(ctl, setting8);
1607}
1608
Eric Laurentb23d5282013-05-14 15:27:20 -07001609void *platform_init(struct audio_device *adev)
1610{
1611 char value[PROPERTY_VALUE_MAX];
vivek mehta60ea4152016-02-18 17:10:26 -08001612 struct platform_data *my_data = NULL;
1613 int retry_num = 0, snd_card_num = 0, key = 0, ret = 0;
1614 bool dual_mic_config = false, use_default_mixer_path = true;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001615 const char *snd_card_name;
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001616 char *cvd_version = NULL;
vivek mehta60ea4152016-02-18 17:10:26 -08001617 char *snd_internal_name = NULL;
1618 char *tmp = NULL;
1619 char mixer_xml_file[MIXER_PATH_MAX_LENGTH]= {0};
vivek mehtade4849c2016-03-03 17:23:38 -08001620 char platform_info_file[MIXER_PATH_MAX_LENGTH]= {0};
1621 struct snd_card_split *snd_split_handle = NULL;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001622 my_data = calloc(1, sizeof(struct platform_data));
1623
1624 my_data->adev = adev;
1625
keunhui.park2f7306a2015-07-16 16:48:06 +09001626 list_init(&operator_info_list);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001627 list_init(&app_type_entry_list);
keunhui.park2f7306a2015-07-16 16:48:06 +09001628
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001629 set_platform_defaults(my_data);
1630
vivek mehta0fb11312017-05-15 19:35:32 -07001631 // audio_extn_utils_get_snd_card_num does
1632 // - open mixer and get snd card name
1633 // - parse platform info xml file and check for valid snd card name
1634 // - on failure loop through all the active snd card
sangwoo1b9f4b32013-06-21 18:22:55 -07001635
vivek mehta0fb11312017-05-15 19:35:32 -07001636 snd_card_num = audio_extn_utils_get_snd_card_num();
1637 if (-1 == snd_card_num) {
1638 ALOGE("%s: invalid sound card number (-1), bailing out ", __func__);
1639 goto init_failed;
sangwoo1b9f4b32013-06-21 18:22:55 -07001640 }
1641
vivek mehta0fb11312017-05-15 19:35:32 -07001642 adev->mixer = mixer_open(snd_card_num);
1643 snd_card_name = mixer_get_name(adev->mixer);
1644 my_data->hw_info = hw_info_init(snd_card_name);
1645
1646 audio_extn_set_snd_card_split(snd_card_name);
1647 snd_split_handle = audio_extn_get_snd_card_split();
1648
1649 /* Get the codec internal name from the sound card and/or form factor
1650 * name and form the mixer paths and platfor info file name dynamically.
1651 * This is generic way of picking any codec and forma factor name based
1652 * mixer and platform info files in future with no code change.
1653
1654 * current code extends and looks for any of the exteneded mixer path and
1655 * platform info file present based on codec and form factor.
1656
1657 * order of picking appropriate file is
1658 * <i> mixer_paths_<codec_name>_<form_factor>.xml, if file not present
1659 * <ii> mixer_paths_<codec_name>.xml, if file not present
1660 * <iii> mixer_paths.xml
1661
1662 * same order is followed for audio_platform_info.xml as well
1663 */
1664
1665 // need to carryforward old file name
1666 if (!strncmp(snd_card_name, TOMTOM_8226_SND_CARD_NAME,
1667 min(strlen(TOMTOM_8226_SND_CARD_NAME), strlen(snd_card_name)))) {
1668 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1669 MIXER_XML_BASE_STRING, TOMTOM_MIXER_FILE_SUFFIX );
1670 } else {
1671
1672 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s_%s.xml",
1673 MIXER_XML_BASE_STRING, snd_split_handle->snd_card,
1674 snd_split_handle->form_factor);
1675 if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) {
1676 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1677 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1678 MIXER_XML_BASE_STRING, snd_split_handle->snd_card);
1679
1680 if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) {
1681 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1682 strlcpy(mixer_xml_file, MIXER_XML_DEFAULT_PATH, MIXER_PATH_MAX_LENGTH);
1683 audio_extn_utils_resolve_config_file(mixer_xml_file);
1684 }
1685 }
1686 }
1687
1688 audio_extn_utils_get_platform_info(snd_card_name, platform_info_file);
1689
jiabin8962a4d2018-03-19 18:21:24 -07001690 my_data->declared_mic_count = 0;
vivek mehta0fb11312017-05-15 19:35:32 -07001691 /* Initialize platform specific ids and/or backends*/
juyuchenbf6571f2018-11-30 18:50:47 +08001692 platform_info_init(platform_info_file, my_data,
1693 true, &platform_set_parameters);
vivek mehta0fb11312017-05-15 19:35:32 -07001694
1695 ALOGD("%s: Loading mixer file: %s", __func__, mixer_xml_file);
1696 adev->audio_route = audio_route_init(snd_card_num, mixer_xml_file);
1697
1698 if (!adev->audio_route) {
1699 ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
1700 mixer_close(adev->mixer);
1701 adev->mixer = NULL;
1702 hw_info_deinit(my_data->hw_info);
1703 my_data->hw_info = NULL;
1704 goto init_failed;
1705 }
1706 adev->snd_card = snd_card_num;
1707 ALOGD("%s: Opened sound card:%d", __func__, snd_card_num);
1708
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09001709 //set max volume step for voice call
1710 property_get("ro.config.vc_call_vol_steps", value, TOSTRING(MAX_VOL_INDEX));
1711 my_data->max_vol_index = atoi(value);
1712
vivek mehta65ad12d2015-08-13 18:32:48 -07001713 property_get("persist.audio.dualmic.config",value,"");
1714 if (!strcmp("endfire", value)) {
1715 dual_mic_config = true;
1716 }
1717
John Muir9e59a962018-01-10 13:30:00 -08001718 my_data->source_mic_type = 0;
Prashant Malanic92c5962015-08-11 15:10:18 -07001719
Eric Laurentb23d5282013-05-14 15:27:20 -07001720 my_data->fluence_in_spkr_mode = false;
1721 my_data->fluence_in_voice_call = false;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001722 my_data->fluence_in_voice_comm = false;
Eric Laurentb23d5282013-05-14 15:27:20 -07001723 my_data->fluence_in_voice_rec = false;
1724
vivek mehta65ad12d2015-08-13 18:32:48 -07001725 property_get("ro.qc.sdk.audio.fluencetype", value, "none");
Prashant Malanic92c5962015-08-11 15:10:18 -07001726 if (!strcmp("fluencepro", value)) {
1727 my_data->fluence_type = FLUENCE_PRO_ENABLE;
vivek mehta65ad12d2015-08-13 18:32:48 -07001728 } else if (!strcmp("fluence", value) || (dual_mic_config)) {
Prashant Malanic92c5962015-08-11 15:10:18 -07001729 my_data->fluence_type = FLUENCE_ENABLE;
1730 } else if (!strcmp("none", value)) {
1731 my_data->fluence_type = FLUENCE_DISABLE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001732 }
1733
Prashant Malanic92c5962015-08-11 15:10:18 -07001734 if (my_data->fluence_type != FLUENCE_DISABLE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001735 property_get("persist.audio.fluence.voicecall",value,"");
1736 if (!strcmp("true", value)) {
1737 my_data->fluence_in_voice_call = true;
1738 }
1739
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001740 property_get("persist.audio.fluence.voicecomm",value,"");
1741 if (!strcmp("true", value)) {
1742 my_data->fluence_in_voice_comm = true;
1743 }
1744
Eric Laurentb23d5282013-05-14 15:27:20 -07001745 property_get("persist.audio.fluence.voicerec",value,"");
1746 if (!strcmp("true", value)) {
1747 my_data->fluence_in_voice_rec = true;
1748 }
1749
1750 property_get("persist.audio.fluence.speaker",value,"");
1751 if (!strcmp("true", value)) {
1752 my_data->fluence_in_spkr_mode = true;
1753 }
1754 }
1755
Prashant Malanic92c5962015-08-11 15:10:18 -07001756 // support max to mono, example if max count is 3, usecase supports Three, dual and mono mic
1757 switch (my_data->max_mic_count) {
1758 case 4:
1759 my_data->source_mic_type |= SOURCE_QUAD_MIC;
1760 case 3:
1761 my_data->source_mic_type |= SOURCE_THREE_MIC;
1762 case 2:
1763 my_data->source_mic_type |= SOURCE_DUAL_MIC;
1764 case 1:
1765 my_data->source_mic_type |= SOURCE_MONO_MIC;
1766 break;
1767 default:
1768 ALOGE("%s: max_mic_count (%d), is not supported, setting to default",
1769 __func__, my_data->max_mic_count);
1770 my_data->source_mic_type = SOURCE_MONO_MIC|SOURCE_DUAL_MIC;
1771 break;
1772 }
1773
1774 ALOGV("%s: Fluence_Type(%d) max_mic_count(%d) mic_type(0x%x) fluence_in_voice_call(%d)"
1775 " fluence_in_voice_comm(%d) fluence_in_voice_rec(%d) fluence_in_spkr_mode(%d) ",
1776 __func__, my_data->fluence_type, my_data->max_mic_count, my_data->source_mic_type,
1777 my_data->fluence_in_voice_call, my_data->fluence_in_voice_comm,
1778 my_data->fluence_in_voice_rec, my_data->fluence_in_spkr_mode);
1779
Eric Laurentb23d5282013-05-14 15:27:20 -07001780 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
1781 if (my_data->acdb_handle == NULL) {
1782 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
1783 } else {
1784 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
1785 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
1786 "acdb_loader_deallocate_ACDB");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001787 if (!my_data->acdb_deallocate)
1788 ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s",
1789 __func__, LIB_ACDB_LOADER);
1790
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001791 my_data->acdb_send_audio_cal_v3 = (acdb_send_audio_cal_v3_t)dlsym(my_data->acdb_handle,
1792 "acdb_loader_send_audio_cal_v3");
1793 if (!my_data->acdb_send_audio_cal_v3)
1794 ALOGE("%s: Could not find the symbol acdb_send_audio_cal_v3 from %s",
1795 __func__, LIB_ACDB_LOADER);
1796
Eric Laurentb23d5282013-05-14 15:27:20 -07001797 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
1798 "acdb_loader_send_audio_cal");
1799 if (!my_data->acdb_send_audio_cal)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001800 ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s",
Eric Laurentb23d5282013-05-14 15:27:20 -07001801 __func__, LIB_ACDB_LOADER);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001802
Eric Laurentb23d5282013-05-14 15:27:20 -07001803 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
1804 "acdb_loader_send_voice_cal");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001805 if (!my_data->acdb_send_voice_cal)
1806 ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s",
1807 __func__, LIB_ACDB_LOADER);
1808
1809 my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle,
1810 "acdb_loader_reload_vocvoltable");
1811 if (!my_data->acdb_reload_vocvoltable)
1812 ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s",
1813 __func__, LIB_ACDB_LOADER);
vivek mehta1a9b7c02015-06-25 11:49:38 -07001814
1815 my_data->acdb_send_gain_dep_cal = (acdb_send_gain_dep_cal_t)dlsym(my_data->acdb_handle,
1816 "acdb_loader_send_gain_dep_cal");
1817 if (!my_data->acdb_send_gain_dep_cal)
1818 ALOGV("%s: Could not find the symbol acdb_loader_send_gain_dep_cal from %s",
1819 __func__, LIB_ACDB_LOADER);
1820
Xu Han1638fd12018-04-20 12:42:23 -07001821#if defined (FLICKER_SENSOR_INPUT)
1822 configure_flicker_sensor_input(adev->mixer);
1823#endif
1824
Thierry Strudel07f96d12018-09-20 13:31:34 -07001825#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845) || (PLATFORM_SDM710) || (PLATFORM_SM8150)
vivek mehta0fb11312017-05-15 19:35:32 -07001826 acdb_init_v2_cvd_t acdb_init_local;
1827 acdb_init_local = (acdb_init_v2_cvd_t)dlsym(my_data->acdb_handle,
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001828 "acdb_loader_init_v2");
vivek mehta0fb11312017-05-15 19:35:32 -07001829 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001830 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1831 dlerror());
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001832
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001833#elif defined (PLATFORM_MSM8084)
vivek mehta0fb11312017-05-15 19:35:32 -07001834 acdb_init_v2_t acdb_init_local;
1835 acdb_init_local = (acdb_init_v2_t)dlsym(my_data->acdb_handle,
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001836 "acdb_loader_init_v2");
vivek mehta0fb11312017-05-15 19:35:32 -07001837 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001838 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1839 dlerror());
1840
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001841#else
vivek mehta0fb11312017-05-15 19:35:32 -07001842 acdb_init_t acdb_init_local;
1843 acdb_init_local = (acdb_init_t)dlsym(my_data->acdb_handle,
Eric Laurentb23d5282013-05-14 15:27:20 -07001844 "acdb_loader_init_ACDB");
vivek mehta0fb11312017-05-15 19:35:32 -07001845 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001846 ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__,
1847 dlerror());
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001848#endif
vivek mehta0fb11312017-05-15 19:35:32 -07001849 my_data->acdb_init = acdb_init_local;
Eric Laurentb23d5282013-05-14 15:27:20 -07001850
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001851 my_data->acdb_send_custom_top = (acdb_send_custom_top_t)
1852 dlsym(my_data->acdb_handle,
1853 "acdb_loader_send_common_custom_topology");
1854
1855 if (!my_data->acdb_send_custom_top)
1856 ALOGE("%s: Could not find the symbol acdb_get_default_app_type from %s",
1857 __func__, LIB_ACDB_LOADER);
1858
jasmine chac89321b2018-04-10 21:37:01 +08001859 my_data->acdb_set_audio_cal = (acdb_set_audio_cal_t)dlsym(my_data->acdb_handle,
1860 "acdb_loader_set_audio_cal_v2");
1861 if (!my_data->acdb_set_audio_cal)
1862 ALOGE("%s: Could not find the symbol acdb_set_audio_cal_v2 from %s",
1863 __func__, LIB_ACDB_LOADER);
1864
vivek mehta0fb11312017-05-15 19:35:32 -07001865 int result = acdb_init(adev->snd_card);
1866 if (!result) {
1867 my_data->acdb_initialized = true;
1868 ALOGD("ACDB initialized");
1869 } else {
1870 my_data->acdb_initialized = false;
1871 ALOGD("ACDB initialization failed");
1872 }
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001873 }
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001874
David Linee3fe402017-03-13 10:00:42 -07001875 /* init usb */
1876 audio_extn_usb_init(adev);
1877
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001878 /* init a2dp */
1879 audio_extn_a2dp_init(adev);
1880
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001881 audio_extn_spkr_prot_init(adev);
Haynes Mathew George98c95622014-06-20 19:14:25 -07001882
Ravi Kumar Alamanda76315572015-04-23 13:13:56 -07001883 audio_extn_hwdep_cal_send(adev->snd_card, my_data->acdb_handle);
1884
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001885 /* load csd client */
1886 platform_csd_init(my_data);
1887
David Linee3fe402017-03-13 10:00:42 -07001888 platform_backend_config_init(my_data);
1889
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001890 init_be_dai_name_table(adev);
1891
1892 if (platform_supports_app_type_cfg())
1893 platform_backend_app_type_cfg_init(my_data, adev->mixer);
1894
Eric Laurentb23d5282013-05-14 15:27:20 -07001895 return my_data;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001896
1897init_failed:
1898 if (my_data)
1899 free(my_data);
1900 return NULL;
Eric Laurentb23d5282013-05-14 15:27:20 -07001901}
1902
1903void platform_deinit(void *platform)
1904{
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001905 int32_t dev;
keunhui.park2f7306a2015-07-16 16:48:06 +09001906 struct operator_info *info_item;
1907 struct operator_specific_device *device_item;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001908 struct app_type_entry *ap;
keunhui.park2f7306a2015-07-16 16:48:06 +09001909 struct listnode *node;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001910
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001911 struct platform_data *my_data = (struct platform_data *)platform;
1912 close_csd_client(my_data->csd);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001913
David Lin41b4fe42018-07-08 16:14:24 -07001914 audio_extn_spkr_prot_deinit(my_data->adev);
1915
vivek mehtade4849c2016-03-03 17:23:38 -08001916 hw_info_deinit(my_data->hw_info);
1917
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001918 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1919 if (backend_tag_table[dev])
1920 free(backend_tag_table[dev]);
1921 if (hw_interface_table[dev])
1922 free(hw_interface_table[dev]);
keunhui.park2f7306a2015-07-16 16:48:06 +09001923 if (operator_specific_device_table[dev]) {
1924 while (!list_empty(operator_specific_device_table[dev])) {
1925 node = list_head(operator_specific_device_table[dev]);
1926 list_remove(node);
1927 device_item = node_to_item(node, struct operator_specific_device, list);
1928 free(device_item->operator);
1929 free(device_item->mixer_path);
1930 free(device_item);
1931 }
1932 free(operator_specific_device_table[dev]);
1933 }
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001934 }
1935
1936 if (my_data->snd_card_name)
1937 free(my_data->snd_card_name);
1938
keunhui.park2f7306a2015-07-16 16:48:06 +09001939 while (!list_empty(&operator_info_list)) {
1940 node = list_head(&operator_info_list);
1941 list_remove(node);
1942 info_item = node_to_item(node, struct operator_info, list);
1943 free(info_item->name);
1944 free(info_item->mccmnc);
1945 free(info_item);
1946 }
1947
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001948 while (!list_empty(&app_type_entry_list)) {
1949 node = list_head(&app_type_entry_list);
1950 list_remove(node);
1951 ap = node_to_item(node, struct app_type_entry, node);
vivek mehtaa68fea62017-06-08 19:04:02 -07001952 if (ap->mode) free(ap->mode);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001953 free(ap);
1954 }
1955
Kevin Rocarde35d4af2017-05-02 16:55:28 -07001956 mixer_close(my_data->adev->mixer);
Eric Laurentb23d5282013-05-14 15:27:20 -07001957 free(platform);
David Linee3fe402017-03-13 10:00:42 -07001958
1959 /* deinit usb */
1960 audio_extn_usb_deinit();
Eric Laurentb23d5282013-05-14 15:27:20 -07001961}
1962
1963const char *platform_get_snd_device_name(snd_device_t snd_device)
1964{
keunhui.park2f7306a2015-07-16 16:48:06 +09001965 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1966 if (operator_specific_device_table[snd_device] != NULL) {
1967 return get_operator_specific_device_mixer_path(snd_device);
1968 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001969 return device_table[snd_device];
keunhui.park2f7306a2015-07-16 16:48:06 +09001970 } else
Ravi Kumar Alamanda64026462014-09-15 00:08:58 -07001971 return "none";
Eric Laurentb23d5282013-05-14 15:27:20 -07001972}
1973
vivek mehtade4849c2016-03-03 17:23:38 -08001974int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
1975 char *device_name)
1976{
1977 struct platform_data *my_data = (struct platform_data *)platform;
1978
David Benjamin1565f992016-09-21 12:10:34 -04001979 if (platform == NULL) {
vivek mehtade4849c2016-03-03 17:23:38 -08001980 ALOGW("%s: something wrong, use legacy get_snd_device name", __func__);
David Benjamin1565f992016-09-21 12:10:34 -04001981 strlcpy(device_name, platform_get_snd_device_name(snd_device),
1982 DEVICE_NAME_MAX_SIZE);
vivek mehtade4849c2016-03-03 17:23:38 -08001983 } else if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1984 if (operator_specific_device_table[snd_device] != NULL) {
1985 strlcpy(device_name, get_operator_specific_device_mixer_path(snd_device),
1986 DEVICE_NAME_MAX_SIZE);
1987 } else {
1988 strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE);
1989 }
1990 hw_info_append_hw_type(my_data->hw_info, snd_device, device_name);
1991 } else {
1992 strlcpy(device_name, "none", DEVICE_NAME_MAX_SIZE);
Aniket Kumar Lataa158e862018-05-11 17:28:40 -07001993 return -EINVAL;
vivek mehtade4849c2016-03-03 17:23:38 -08001994 }
1995
1996 return 0;
1997}
1998
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001999void platform_add_backend_name(void *platform, char *mixer_path,
2000 snd_device_t snd_device)
Eric Laurentb23d5282013-05-14 15:27:20 -07002001{
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05002002 struct platform_data *my_data = (struct platform_data *)platform;
2003
Haynes Mathew George98c95622014-06-20 19:14:25 -07002004 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
2005 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
2006 return;
Ravi Kumar Alamanda1de6e5a2014-06-19 21:55:39 -05002007 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07002008
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002009 const char * suffix = backend_tag_table[snd_device];
Haynes Mathew George98c95622014-06-20 19:14:25 -07002010
2011 if (suffix != NULL) {
2012 strcat(mixer_path, " ");
2013 strcat(mixer_path, suffix);
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05002014 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002015}
2016
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002017bool platform_check_backends_match(snd_device_t snd_device1, snd_device_t snd_device2)
2018{
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002019 ALOGV("%s: snd_device1 = %s, snd_device2 = %s", __func__,
2020 platform_get_snd_device_name(snd_device1),
2021 platform_get_snd_device_name(snd_device2));
2022
2023 if ((snd_device1 < SND_DEVICE_MIN) || (snd_device1 >= SND_DEVICE_MAX)) {
2024 ALOGE("%s: Invalid snd_device = %s", __func__,
2025 platform_get_snd_device_name(snd_device1));
2026 return false;
2027 }
2028 if ((snd_device2 < SND_DEVICE_MIN) || (snd_device2 >= SND_DEVICE_MAX)) {
2029 ALOGE("%s: Invalid snd_device = %s", __func__,
2030 platform_get_snd_device_name(snd_device2));
2031 return false;
2032 }
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07002033
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002034 const char * be_itf1 = hw_interface_table[snd_device1];
2035 const char * be_itf2 = hw_interface_table[snd_device2];
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07002036 /*
2037 hw_interface_table has overrides for a snd_device.
2038 if there is no entry for a device, assume DEFAULT_RX_BACKEND
2039 */
2040 if (be_itf1 == NULL) {
2041 be_itf1 = DEFAULT_RX_BACKEND;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002042 }
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07002043 if (be_itf2 == NULL) {
2044 be_itf2 = DEFAULT_RX_BACKEND;
2045 }
2046 ALOGV("%s: be_itf1 = %s, be_itf2 = %s", __func__, be_itf1, be_itf2);
2047 /*
2048 this takes care of finding a device within a combo device pair as well
2049 */
2050 return strstr(be_itf1, be_itf2) != NULL || strstr(be_itf2, be_itf1) != NULL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002051}
2052
Eric Laurentb23d5282013-05-14 15:27:20 -07002053int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
2054{
2055 int device_id;
2056 if (device_type == PCM_PLAYBACK)
2057 device_id = pcm_device_table[usecase][0];
2058 else
2059 device_id = pcm_device_table[usecase][1];
2060 return device_id;
2061}
2062
Haynes Mathew George98c95622014-06-20 19:14:25 -07002063static int find_index(const struct name_to_index * table, int32_t len,
2064 const char * name)
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002065{
2066 int ret = 0;
Haynes Mathew George98c95622014-06-20 19:14:25 -07002067 int32_t i;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002068
Haynes Mathew George98c95622014-06-20 19:14:25 -07002069 if (table == NULL) {
2070 ALOGE("%s: table is NULL", __func__);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002071 ret = -ENODEV;
2072 goto done;
2073 }
2074
Haynes Mathew George98c95622014-06-20 19:14:25 -07002075 if (name == NULL) {
2076 ALOGE("null key");
2077 ret = -ENODEV;
2078 goto done;
2079 }
2080
2081 for (i=0; i < len; i++) {
2082 if (!strcmp(table[i].name, name)) {
2083 ret = table[i].index;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002084 goto done;
2085 }
2086 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07002087 ALOGE("%s: Could not find index for name = %s",
2088 __func__, name);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002089 ret = -ENODEV;
2090done:
2091 return ret;
2092}
2093
Haynes Mathew George98c95622014-06-20 19:14:25 -07002094int platform_get_snd_device_index(char *device_name)
2095{
2096 return find_index(snd_device_name_index, SND_DEVICE_MAX, device_name);
2097}
2098
2099int platform_get_usecase_index(const char *usecase_name)
2100{
2101 return find_index(usecase_name_index, AUDIO_USECASE_MAX, usecase_name);
2102}
2103
Vignesh Kulothungan64698822018-01-23 11:25:18 -08002104int platform_get_effect_config_data(snd_device_t snd_device,
2105 struct audio_effect_config *effect_config,
2106 effect_type_t effect_type)
2107{
2108 int ret = 0;
2109
2110 if ((snd_device < SND_DEVICE_IN_BEGIN) || (snd_device >= SND_DEVICE_MAX) ||
2111 (effect_type <= EFFECT_NONE) || (effect_type >= EFFECT_COUNT)) {
2112 ALOGE("%s: Invalid snd_device = %d or effect_type = %d",
2113 __func__, snd_device, effect_type);
2114 ret = -EINVAL;
2115 goto done;
2116 }
2117
2118 if (effect_config == NULL) {
2119 ALOGE("%s: Invalid effect_config", __func__);
2120 ret = -EINVAL;
2121 goto done;
2122 }
2123
2124 ALOGV("%s: snd_device = %d module_id = %d",
2125 __func__, snd_device, effect_config_table[GET_IN_DEVICE_INDEX(snd_device)][effect_type].module_id);
2126 *effect_config = effect_config_table[GET_IN_DEVICE_INDEX(snd_device)][effect_type];
2127
2128done:
2129 return ret;
2130}
2131
2132int platform_set_effect_config_data(snd_device_t snd_device,
2133 struct audio_effect_config effect_config,
2134 effect_type_t effect_type)
2135{
2136 int ret = 0;
2137
2138 if ((snd_device < SND_DEVICE_IN_BEGIN) || (snd_device >= SND_DEVICE_MAX) ||
2139 (effect_type <= EFFECT_NONE) || (effect_type >= EFFECT_COUNT)) {
2140 ALOGE("%s: Invalid snd_device = %d or effect_type = %d",
2141 __func__, snd_device, effect_type);
2142 ret = -EINVAL;
2143 goto done;
2144 }
2145
2146 ALOGV("%s 0x%x 0x%x 0x%x 0x%x", __func__, effect_config.module_id,
2147 effect_config.instance_id, effect_config.param_id,
2148 effect_config.param_value);
2149 effect_config_table[GET_IN_DEVICE_INDEX(snd_device)][effect_type] = effect_config;
2150
2151done:
2152 return ret;
2153}
2154
keunhui.park2f7306a2015-07-16 16:48:06 +09002155void platform_add_operator_specific_device(snd_device_t snd_device,
2156 const char *operator,
2157 const char *mixer_path,
2158 unsigned int acdb_id)
2159{
2160 struct operator_specific_device *device;
2161
2162 if (operator_specific_device_table[snd_device] == NULL) {
2163 operator_specific_device_table[snd_device] =
2164 (struct listnode *)calloc(1, sizeof(struct listnode));
2165 list_init(operator_specific_device_table[snd_device]);
2166 }
2167
2168 device = (struct operator_specific_device *)calloc(1, sizeof(struct operator_specific_device));
2169
2170 device->operator = strdup(operator);
2171 device->mixer_path = strdup(mixer_path);
2172 device->acdb_id = acdb_id;
2173
2174 list_add_tail(operator_specific_device_table[snd_device], &device->list);
2175
Eric Laurent2bafff12016-03-17 12:17:23 -07002176 ALOGD("%s: device[%s] -> operator[%s] mixer_path[%s] acdb_id[%d]", __func__,
keunhui.park2f7306a2015-07-16 16:48:06 +09002177 platform_get_snd_device_name(snd_device), operator, mixer_path, acdb_id);
2178
2179}
2180
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002181int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
2182{
2183 int ret = 0;
2184
2185 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
2186 ALOGE("%s: Invalid snd_device = %d",
2187 __func__, snd_device);
2188 ret = -EINVAL;
2189 goto done;
2190 }
2191
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002192 ALOGV("%s: acdb_device_table[%s]: old = %d new = %d", __func__,
2193 platform_get_snd_device_name(snd_device), acdb_device_table[snd_device], acdb_id);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002194 acdb_device_table[snd_device] = acdb_id;
2195done:
2196 return ret;
2197}
2198
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07002199int platform_get_snd_device_acdb_id(snd_device_t snd_device)
2200{
2201 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
2202 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
2203 return -EINVAL;
2204 }
keunhui.park2f7306a2015-07-16 16:48:06 +09002205
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002206 /*
2207 * If speaker protection is enabled, function returns supported
2208 * sound device for speaker. Else same sound device is returned.
2209 */
2210 snd_device = audio_extn_get_spkr_prot_snd_device(snd_device);
2211
keunhui.park2f7306a2015-07-16 16:48:06 +09002212 if (operator_specific_device_table[snd_device] != NULL)
2213 return get_operator_specific_device_acdb_id(snd_device);
2214 else
2215 return acdb_device_table[snd_device];
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07002216}
2217
David Linee3fe402017-03-13 10:00:42 -07002218static int platform_get_backend_index(snd_device_t snd_device)
2219{
2220 int32_t port = DEFAULT_CODEC_BACKEND;
2221
2222 if (snd_device >= SND_DEVICE_OUT_BEGIN && snd_device < SND_DEVICE_OUT_END) {
2223 if (backend_tag_table[snd_device] != NULL) {
2224 if (strncmp(backend_tag_table[snd_device], "headphones",
2225 sizeof("headphones")) == 0)
2226 port = HEADPHONE_BACKEND;
2227 else if (strcmp(backend_tag_table[snd_device], "hdmi") == 0)
2228 port = HDMI_RX_BACKEND;
2229 else if ((strcmp(backend_tag_table[snd_device], "usb-headphones") == 0) ||
2230 (strcmp(backend_tag_table[snd_device], "usb-headset") == 0))
2231 port = USB_AUDIO_RX_BACKEND;
2232 }
2233 } else if (snd_device >= SND_DEVICE_IN_BEGIN && snd_device < SND_DEVICE_IN_END) {
2234 port = DEFAULT_CODEC_TX_BACKEND;
2235 if (backend_tag_table[snd_device] != NULL) {
2236 if (strcmp(backend_tag_table[snd_device], "usb-headset-mic") == 0)
2237 port = USB_AUDIO_TX_BACKEND;
2238 else if (strstr(backend_tag_table[snd_device], "bt-sco") != NULL)
2239 port = BT_SCO_TX_BACKEND;
2240 }
2241 } else {
2242 ALOGW("%s:napb: Invalid device - %d ", __func__, snd_device);
2243 }
2244
2245 ALOGV("%s:napb: backend port - %d device - %d ", __func__, port, snd_device);
2246
2247 return port;
2248}
2249
Eric Laurentb23d5282013-05-14 15:27:20 -07002250int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
2251{
2252 struct platform_data *my_data = (struct platform_data *)platform;
2253 int acdb_dev_id, acdb_dev_type;
2254
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002255 if (platform_supports_app_type_cfg()) // use v2 instead
2256 return -ENOSYS;
2257
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002258 acdb_dev_id = platform_get_snd_device_acdb_id(snd_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07002259 if (acdb_dev_id < 0) {
2260 ALOGE("%s: Could not find acdb id for device(%d)",
2261 __func__, snd_device);
2262 return -EINVAL;
2263 }
2264 if (my_data->acdb_send_audio_cal) {
Joe Onorato188b6222016-03-01 11:02:27 -08002265 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Eric Laurentb23d5282013-05-14 15:27:20 -07002266 __func__, snd_device, acdb_dev_id);
2267 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
2268 snd_device < SND_DEVICE_OUT_END)
2269 acdb_dev_type = ACDB_DEV_TYPE_OUT;
2270 else
2271 acdb_dev_type = ACDB_DEV_TYPE_IN;
2272 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
2273 }
2274 return 0;
2275}
2276
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002277int platform_send_audio_calibration_v2(void *platform, struct audio_usecase *usecase,
2278 int app_type, int sample_rate)
2279{
2280 struct platform_data *my_data = (struct platform_data *)platform;
2281 int acdb_dev_id, acdb_dev_type;
vivek mehta7e573672018-03-13 17:41:41 -07002282 int snd_device = usecase->out_snd_device;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002283 int new_snd_device[SND_DEVICE_OUT_END] = {0};
2284 int i, num_devices = 1;
2285
2286 if (!platform_supports_app_type_cfg()) // use v1 instead
2287 return -ENOSYS;
2288
vivek mehta7e573672018-03-13 17:41:41 -07002289 if ((usecase->type == PCM_HFP_CALL) || (usecase->type == PCM_CAPTURE))
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002290 snd_device = usecase->in_snd_device;
2291
2292 // skipped over get_spkr_prot_device
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002293 acdb_dev_id = platform_get_snd_device_acdb_id(snd_device);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002294 if (acdb_dev_id < 0) {
2295 ALOGE("%s: Could not find acdb id for device(%d)",
2296 __func__, snd_device);
2297 return -EINVAL;
2298 }
2299
2300 if (platform_can_split_snd_device(snd_device,
2301 &num_devices, new_snd_device) < 0) {
2302 new_snd_device[0] = snd_device;
2303 }
2304
2305 for (i = 0; i < num_devices; i++) {
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002306 acdb_dev_id = platform_get_snd_device_acdb_id(new_snd_device[i]);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002307 if (acdb_dev_id < 0) {
2308 ALOGE("%s: Could not find acdb id for device(%d)",
2309 __func__, new_snd_device[i]);
2310 return -EINVAL;
2311 }
2312 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
2313 __func__, new_snd_device[i], acdb_dev_id);
2314 if (new_snd_device[i] >= SND_DEVICE_OUT_BEGIN &&
2315 new_snd_device[i] < SND_DEVICE_OUT_END)
2316 acdb_dev_type = ACDB_DEV_TYPE_OUT;
2317 else
2318 acdb_dev_type = ACDB_DEV_TYPE_IN;
2319
2320 if (my_data->acdb_send_audio_cal_v3) {
2321 my_data->acdb_send_audio_cal_v3(acdb_dev_id, acdb_dev_type,
2322 app_type, sample_rate, i);
2323 } else if (my_data->acdb_send_audio_cal) {
2324 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type); // this version differs from internal
2325 }
2326 }
2327
2328 return 0;
2329}
2330
2331
Eric Laurentb23d5282013-05-14 15:27:20 -07002332int platform_switch_voice_call_device_pre(void *platform)
2333{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002334 struct platform_data *my_data = (struct platform_data *)platform;
2335 int ret = 0;
2336
2337 if (my_data->csd != NULL &&
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002338 voice_is_in_call(my_data->adev)) {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002339 /* This must be called before disabling mixer controls on APQ side */
2340 ret = my_data->csd->disable_device();
2341 if (ret < 0) {
2342 ALOGE("%s: csd_client_disable_device, failed, error %d",
2343 __func__, ret);
2344 }
2345 }
2346 return ret;
2347}
2348
2349int platform_switch_voice_call_enable_device_config(void *platform,
2350 snd_device_t out_snd_device,
2351 snd_device_t in_snd_device)
2352{
2353 struct platform_data *my_data = (struct platform_data *)platform;
2354 int acdb_rx_id, acdb_tx_id;
2355 int ret = 0;
2356
2357 if (my_data->csd == NULL)
2358 return ret;
2359
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002360 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
keunhui.park2f7306a2015-07-16 16:48:06 +09002361 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002362
2363 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
2364 ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
2365 if (ret < 0) {
2366 ALOGE("%s: csd_enable_device_config, failed, error %d",
2367 __func__, ret);
2368 }
2369 } else {
2370 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2371 acdb_rx_id, acdb_tx_id);
2372 }
2373
2374 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002375}
2376
2377int platform_switch_voice_call_device_post(void *platform,
2378 snd_device_t out_snd_device,
2379 snd_device_t in_snd_device)
2380{
2381 struct platform_data *my_data = (struct platform_data *)platform;
2382 int acdb_rx_id, acdb_tx_id;
2383
2384 if (my_data->acdb_send_voice_cal == NULL) {
2385 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
2386 } else {
keunhui.park2f7306a2015-07-16 16:48:06 +09002387 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
2388 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07002389
2390 if (acdb_rx_id > 0 && acdb_tx_id > 0)
2391 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
2392 else
2393 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2394 acdb_rx_id, acdb_tx_id);
2395 }
2396
2397 return 0;
2398}
2399
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002400int platform_switch_voice_call_usecase_route_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 int ret = 0;
2407
2408 if (my_data->csd == NULL)
2409 return ret;
2410
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002411 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
keunhui.park2f7306a2015-07-16 16:48:06 +09002412 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002413
2414 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
2415 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
2416 my_data->adev->acdb_settings);
2417 if (ret < 0) {
2418 ALOGE("%s: csd_enable_device, failed, error %d", __func__, ret);
2419 }
2420 } else {
2421 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2422 acdb_rx_id, acdb_tx_id);
2423 }
2424
2425 return ret;
2426}
2427
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002428int platform_start_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07002429{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002430 struct platform_data *my_data = (struct platform_data *)platform;
2431 int ret = 0;
2432
2433 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002434 ret = my_data->csd->start_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002435 if (ret < 0) {
2436 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
2437 }
2438 }
2439 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002440}
2441
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002442int platform_stop_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07002443{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002444 struct platform_data *my_data = (struct platform_data *)platform;
2445 int ret = 0;
2446
2447 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002448 ret = my_data->csd->stop_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002449 if (ret < 0) {
2450 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
2451 }
2452 }
2453 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002454}
2455
Vignesh Kulothunganb6f0a9c2018-03-22 13:50:22 -07002456int platform_set_mic_break_det(void *platform, bool enable)
2457{
2458 int ret = 0;
2459 struct platform_data *my_data = (struct platform_data *)platform;
2460 struct audio_device *adev = my_data->adev;
2461 const char *mixer_ctl_name = "Voice Mic Break Enable";
2462 struct mixer_ctl *ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2463 if (!ctl) {
2464 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2465 __func__, mixer_ctl_name);
2466 return -EINVAL;
2467 }
2468
2469 ret = mixer_ctl_set_value(ctl, 0, enable);
2470 if(ret)
2471 ALOGE("%s: Failed to set mixer ctl: %s", __func__, mixer_ctl_name);
2472
2473 return ret;
2474}
2475
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002476int platform_get_sample_rate(void *platform, uint32_t *rate)
2477{
2478 struct platform_data *my_data = (struct platform_data *)platform;
2479 int ret = 0;
2480
2481 if (my_data->csd != NULL) {
2482 ret = my_data->csd->get_sample_rate(rate);
2483 if (ret < 0) {
2484 ALOGE("%s: csd_get_sample_rate error %d\n", __func__, ret);
2485 }
2486 }
2487 return ret;
2488}
2489
vivek mehtab6506412015-08-07 16:55:17 -07002490void platform_set_speaker_gain_in_combo(struct audio_device *adev,
2491 snd_device_t snd_device,
2492 bool enable)
2493{
2494 const char* name;
2495 switch (snd_device) {
2496 case SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES:
2497 if (enable)
2498 name = "spkr-gain-in-headphone-combo";
2499 else
2500 name = "speaker-gain-default";
2501 break;
2502 case SND_DEVICE_OUT_SPEAKER_AND_LINE:
2503 if (enable)
2504 name = "spkr-gain-in-line-combo";
2505 else
2506 name = "speaker-gain-default";
2507 break;
2508 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES:
2509 if (enable)
2510 name = "spkr-safe-gain-in-headphone-combo";
2511 else
2512 name = "speaker-safe-gain-default";
2513 break;
2514 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE:
2515 if (enable)
2516 name = "spkr-safe-gain-in-line-combo";
2517 else
2518 name = "speaker-safe-gain-default";
2519 break;
2520 default:
2521 return;
2522 }
2523
2524 audio_route_apply_and_update_path(adev->audio_route, name);
2525}
2526
Eric Laurentb23d5282013-05-14 15:27:20 -07002527int platform_set_voice_volume(void *platform, int volume)
2528{
2529 struct platform_data *my_data = (struct platform_data *)platform;
2530 struct audio_device *adev = my_data->adev;
2531 struct mixer_ctl *ctl;
sangwoo53b2cf02013-07-25 19:18:44 -07002532 const char *mixer_ctl_name = "Voice Rx Gain";
Nadav Barc46d0fa2017-12-24 14:50:37 +02002533 const char *mute_mixer_ctl_name = "Voice Rx Device Mute";
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002534 int vol_index = 0, ret = 0;
2535 uint32_t set_values[ ] = {0,
2536 ALL_SESSION_VSID,
2537 DEFAULT_VOLUME_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07002538
2539 // Voice volume levels are mapped to adsp volume levels as follows.
2540 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
2541 // But this values don't changed in kernel. So, below change is need.
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09002542 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, my_data->max_vol_index);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002543 set_values[0] = vol_index;
Eric Laurentb23d5282013-05-14 15:27:20 -07002544
2545 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2546 if (!ctl) {
2547 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2548 __func__, mixer_ctl_name);
2549 return -EINVAL;
2550 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002551 ALOGV("Setting voice volume index: %d", set_values[0]);
2552 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2553
Nadav Barc46d0fa2017-12-24 14:50:37 +02002554 // Send mute command in case volume index is max since indexes are inverted
2555 // for mixer controls.
2556 if (vol_index == my_data->max_vol_index) {
2557 set_values[0] = 1;
2558 }
2559 else {
2560 set_values[0] = 0;
2561 }
2562
2563 ctl = mixer_get_ctl_by_name(adev->mixer, mute_mixer_ctl_name);
2564 if (!ctl) {
2565 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2566 __func__, mute_mixer_ctl_name);
2567 return -EINVAL;
2568 }
2569 ALOGV("%s: Setting RX Device Mute to: %d", __func__, set_values[0]);
2570 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2571
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002572 if (my_data->csd != NULL) {
2573 ret = my_data->csd->volume(ALL_SESSION_VSID, volume,
2574 DEFAULT_VOLUME_RAMP_DURATION_MS);
2575 if (ret < 0) {
2576 ALOGE("%s: csd_volume error %d", __func__, ret);
2577 }
2578 }
2579 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002580}
2581
2582int platform_set_mic_mute(void *platform, bool state)
2583{
2584 struct platform_data *my_data = (struct platform_data *)platform;
2585 struct audio_device *adev = my_data->adev;
2586 struct mixer_ctl *ctl;
2587 const char *mixer_ctl_name = "Voice Tx Mute";
sangwoo53b2cf02013-07-25 19:18:44 -07002588 int ret = 0;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002589 uint32_t set_values[ ] = {0,
2590 ALL_SESSION_VSID,
2591 DEFAULT_MUTE_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07002592
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09002593 if (adev->mode != AUDIO_MODE_IN_CALL &&
2594 adev->mode != AUDIO_MODE_IN_COMMUNICATION)
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002595 return 0;
2596
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09002597 if (adev->enable_hfp)
2598 mixer_ctl_name = "HFP Tx Mute";
2599
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002600 set_values[0] = state;
2601 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2602 if (!ctl) {
2603 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2604 __func__, mixer_ctl_name);
2605 return -EINVAL;
2606 }
Arun Mirpuri0cc2f312018-05-29 17:26:07 -07002607 ALOGV("%s: Setting voice mute state: %d", __func__, state);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002608 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2609
2610 if (my_data->csd != NULL) {
2611 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state,
2612 DEFAULT_MUTE_RAMP_DURATION_MS);
sangwoo53b2cf02013-07-25 19:18:44 -07002613 if (ret < 0) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002614 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
sangwoo53b2cf02013-07-25 19:18:44 -07002615 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002616 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002617 return ret;
2618}
Eric Laurentb23d5282013-05-14 15:27:20 -07002619
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002620int platform_set_device_mute(void *platform, bool state, char *dir)
2621{
2622 struct platform_data *my_data = (struct platform_data *)platform;
2623 struct audio_device *adev = my_data->adev;
2624 struct mixer_ctl *ctl;
2625 char *mixer_ctl_name = NULL;
2626 int ret = 0;
2627 uint32_t set_values[ ] = {0,
2628 ALL_SESSION_VSID,
2629 0};
2630 if(dir == NULL) {
2631 ALOGE("%s: Invalid direction:%s", __func__, dir);
2632 return -EINVAL;
2633 }
2634
2635 if (!strncmp("rx", dir, sizeof("rx"))) {
2636 mixer_ctl_name = "Voice Rx Device Mute";
2637 } else if (!strncmp("tx", dir, sizeof("tx"))) {
2638 mixer_ctl_name = "Voice Tx Device Mute";
2639 } else {
2640 return -EINVAL;
2641 }
2642
2643 set_values[0] = state;
2644 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2645 if (!ctl) {
2646 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2647 __func__, mixer_ctl_name);
2648 return -EINVAL;
2649 }
2650
2651 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
2652 __func__,state, mixer_ctl_name);
2653 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2654
2655 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002656}
2657
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002658int platform_can_split_snd_device(snd_device_t snd_device,
2659 int *num_devices,
2660 snd_device_t *new_snd_devices)
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002661{
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002662 int ret = -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002663 if (NULL == num_devices || NULL == new_snd_devices) {
2664 ALOGE("%s: NULL pointer ..", __func__);
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002665 return -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002666 }
2667
2668 /*
2669 * If wired headset/headphones/line devices share the same backend
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002670 * with speaker/earpiece this routine returns -EINVAL.
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002671 */
2672 if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES &&
2673 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_HEADPHONES)) {
2674 *num_devices = 2;
2675 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2676 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002677 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002678 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_LINE &&
2679 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_LINE)) {
2680 *num_devices = 2;
2681 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2682 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002683 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002684 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES &&
2685 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_HEADPHONES)) {
2686 *num_devices = 2;
2687 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2688 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002689 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002690 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE &&
2691 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_LINE)) {
2692 *num_devices = 2;
2693 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2694 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002695 ret = 0;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002696 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO &&
2697 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2698 SND_DEVICE_OUT_BT_SCO)) {
2699 *num_devices = 2;
2700 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2701 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO;
2702 ret = 0;
juyuchen5351ea62018-05-16 10:54:37 +08002703 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO &&
2704 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE,
2705 SND_DEVICE_OUT_BT_SCO)) {
2706 *num_devices = 2;
2707 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2708 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO;
2709 ret = 0;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002710 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB &&
2711 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2712 SND_DEVICE_OUT_BT_SCO_WB)) {
2713 *num_devices = 2;
2714 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2715 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO_WB;
2716 ret = 0;
juyuchen5351ea62018-05-16 10:54:37 +08002717 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB &&
2718 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE,
2719 SND_DEVICE_OUT_BT_SCO_WB)) {
2720 *num_devices = 2;
2721 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2722 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO_WB;
2723 ret = 0;
David Linee3fe402017-03-13 10:00:42 -07002724 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET &&
2725 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_USB_HEADSET)) {
2726 *num_devices = 2;
2727 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2728 new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
2729 ret = 0;
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07002730 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET &&
2731 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_USB_HEADSET)) {
2732 *num_devices = 2;
2733 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2734 new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
2735 ret = 0;
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002736 } else if (SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP == snd_device &&
2737 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2738 SND_DEVICE_OUT_BT_A2DP)) {
2739 *num_devices = 2;
2740 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2741 new_snd_devices[1] = SND_DEVICE_OUT_BT_A2DP;
2742 ret = 0;
Aniket Kumar Lata9723a962018-05-16 17:41:55 -07002743 } else if (SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP == snd_device &&
2744 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE,
2745 SND_DEVICE_OUT_BT_A2DP)) {
2746 *num_devices = 2;
2747 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2748 new_snd_devices[1] = SND_DEVICE_OUT_BT_A2DP;
2749 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002750 }
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002751
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002752 return ret;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002753}
2754
Eric Laurentb23d5282013-05-14 15:27:20 -07002755snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
2756{
2757 struct platform_data *my_data = (struct platform_data *)platform;
2758 struct audio_device *adev = my_data->adev;
2759 audio_mode_t mode = adev->mode;
2760 snd_device_t snd_device = SND_DEVICE_NONE;
2761
2762 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
2763 if (devices == AUDIO_DEVICE_NONE ||
2764 devices & AUDIO_DEVICE_BIT_IN) {
2765 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
2766 goto exit;
2767 }
2768
Eric Laurent1b491552015-09-15 17:52:41 -07002769 if (popcount(devices) == 2) {
2770 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2771 AUDIO_DEVICE_OUT_SPEAKER) ||
2772 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2773 AUDIO_DEVICE_OUT_SPEAKER)) {
2774 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
2775 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2776 AUDIO_DEVICE_OUT_SPEAKER)) {
2777 snd_device = SND_DEVICE_OUT_SPEAKER_AND_LINE;
2778 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2779 AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
2780 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2781 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2782 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES;
2783 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2784 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2785 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE;
2786 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
2787 AUDIO_DEVICE_OUT_SPEAKER)) {
2788 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002789 } else if ((devices & AUDIO_DEVICE_OUT_ALL_SCO) &&
2790 ((devices & ~AUDIO_DEVICE_OUT_ALL_SCO) == AUDIO_DEVICE_OUT_SPEAKER)) {
2791 snd_device = adev->bt_wb_speech_enabled ?
2792 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB :
2793 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO;
juyuchen5351ea62018-05-16 10:54:37 +08002794 } else if ((devices & AUDIO_DEVICE_OUT_ALL_SCO) &&
2795 ((devices & ~AUDIO_DEVICE_OUT_ALL_SCO) == AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2796 snd_device = adev->bt_wb_speech_enabled ?
2797 SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB :
2798 SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO;
Eric Laurent99dab492017-06-17 15:19:08 -07002799 } else if ((devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
2800 AUDIO_DEVICE_OUT_SPEAKER)) ||
2801 (devices == (AUDIO_DEVICE_OUT_USB_HEADSET |
2802 AUDIO_DEVICE_OUT_SPEAKER))) {
David Linee3fe402017-03-13 10:00:42 -07002803 snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET;
Eric Laurentd0f7c262017-07-05 09:09:12 -07002804 } else if ((devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
2805 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) ||
2806 (devices == (AUDIO_DEVICE_OUT_USB_HEADSET |
2807 AUDIO_DEVICE_OUT_SPEAKER_SAFE))) {
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07002808 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET;
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002809 } else if ((devices & AUDIO_DEVICE_OUT_SPEAKER) &&
2810 (devices & AUDIO_DEVICE_OUT_ALL_A2DP)) {
2811 snd_device = SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP;
Aniket Kumar Lata9723a962018-05-16 17:41:55 -07002812 } else if ((devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) &&
2813 (devices & AUDIO_DEVICE_OUT_ALL_A2DP)) {
2814 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP;
Eric Laurent1b491552015-09-15 17:52:41 -07002815 } else {
2816 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
2817 goto exit;
2818 }
2819 if (snd_device != SND_DEVICE_NONE) {
2820 goto exit;
2821 }
2822 }
2823
2824 if (popcount(devices) != 1) {
2825 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
2826 goto exit;
2827 }
2828
Madhuri Athota3f6051b2016-10-13 23:25:38 +05302829 if (voice_is_in_call(adev) || adev->enable_voicerx || audio_extn_hfp_is_active(adev)) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002830 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002831 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2832 devices & AUDIO_DEVICE_OUT_LINE) {
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002833 if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002834 (adev->voice.tty_mode == TTY_MODE_FULL))
Eric Laurentb23d5282013-05-14 15:27:20 -07002835 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002836 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002837 (adev->voice.tty_mode == TTY_MODE_VCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002838 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002839 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002840 (adev->voice.tty_mode == TTY_MODE_HCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002841 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002842 else {
2843 if (devices & AUDIO_DEVICE_OUT_LINE)
2844 snd_device = SND_DEVICE_OUT_VOICE_LINE;
yixuanjiang9536e672018-09-06 18:43:36 +08002845 else if (devices & AUDIO_DEVICE_OUT_WIRED_HEADSET)
2846 snd_device = SND_DEVICE_OUT_VOICE_HEADSET;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002847 else
2848 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
2849 }
Eric Laurent99dab492017-06-17 15:19:08 -07002850 } else if (audio_is_usb_out_device(devices)) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002851 if (voice_is_in_call(adev)) {
2852 switch (adev->voice.tty_mode) {
2853 case TTY_MODE_FULL:
2854 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_USB;
2855 break;
2856 case TTY_MODE_VCO:
2857 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_USB;
2858 break;
2859 case TTY_MODE_HCO:
2860 // since Hearing will be on handset\speaker, use existing device
2861 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
2862 break;
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002863 case TTY_MODE_OFF:
2864 break;
vivek mehtaa6b79742017-03-09 15:40:43 -08002865 default:
2866 ALOGE("%s: Invalid TTY mode (%#x)",
2867 __func__, adev->voice.tty_mode);
2868 }
2869 }
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002870 if (snd_device == SND_DEVICE_NONE) {
2871 snd_device = audio_extn_usb_is_capture_supported() ?
2872 SND_DEVICE_OUT_VOICE_USB_HEADSET :
2873 SND_DEVICE_OUT_VOICE_USB_HEADPHONES;
2874 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002875 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002876 if (adev->bt_wb_speech_enabled) {
2877 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2878 } else {
2879 snd_device = SND_DEVICE_OUT_BT_SCO;
2880 }
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002881 } else if (devices & AUDIO_DEVICE_OUT_ALL_A2DP) {
2882 snd_device = SND_DEVICE_OUT_BT_A2DP;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002883 } else if (devices & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002884 if (!adev->enable_hfp) {
2885 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
2886 } else {
2887 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_HFP;
2888 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002889 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002890 if(adev->voice.hac)
2891 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2892 else if (is_operator_tmus())
Eric Laurentb23d5282013-05-14 15:27:20 -07002893 snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS;
2894 else
Eric Laurentb4d368e2014-06-25 10:21:54 -05002895 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002896 } else if (devices & AUDIO_DEVICE_OUT_TELEPHONY_TX)
2897 snd_device = SND_DEVICE_OUT_VOICE_TX;
2898
Eric Laurentb23d5282013-05-14 15:27:20 -07002899 if (snd_device != SND_DEVICE_NONE) {
2900 goto exit;
2901 }
2902 }
2903
Eric Laurentb23d5282013-05-14 15:27:20 -07002904 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2905 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2906 snd_device = SND_DEVICE_OUT_HEADPHONES;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002907 } else if (devices & AUDIO_DEVICE_OUT_LINE) {
2908 snd_device = SND_DEVICE_OUT_LINE;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002909 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) {
2910 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE;
Eric Laurentb23d5282013-05-14 15:27:20 -07002911 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
andysu5b30b062018-04-20 16:34:06 +08002912 /*
2913 * Perform device switch only if acdb tuning is different between SPEAKER & SPEAKER_REVERSE,
2914 * Or there will be a small pause while performing device switch.
2915 */
2916 if (my_data->speaker_lr_swap &&
2917 (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
2918 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]))
Eric Laurentb23d5282013-05-14 15:27:20 -07002919 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
2920 else
2921 snd_device = SND_DEVICE_OUT_SPEAKER;
2922 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002923 if (adev->bt_wb_speech_enabled) {
2924 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2925 } else {
2926 snd_device = SND_DEVICE_OUT_BT_SCO;
2927 }
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002928 } else if (devices & AUDIO_DEVICE_OUT_ALL_A2DP) {
2929 snd_device = SND_DEVICE_OUT_BT_A2DP;
Eric Laurentb23d5282013-05-14 15:27:20 -07002930 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2931 snd_device = SND_DEVICE_OUT_HDMI ;
Eric Laurent99dab492017-06-17 15:19:08 -07002932 } else if (audio_is_usb_out_device(devices)) {
jasmine cha270b7762018-03-30 15:41:33 +08002933 if (audio_extn_ma_supported_usb())
2934 snd_device = SND_DEVICE_OUT_USB_HEADSET_SPEC;
2935 else if (audio_extn_usb_is_capture_supported())
David Linee3fe402017-03-13 10:00:42 -07002936 snd_device = SND_DEVICE_OUT_USB_HEADSET;
2937 else
2938 snd_device = SND_DEVICE_OUT_USB_HEADPHONES;
2939 }else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002940 /*HAC support for voice-ish audio (eg visual voicemail)*/
2941 if(adev->voice.hac)
2942 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2943 else
2944 snd_device = SND_DEVICE_OUT_HANDSET;
Eric Laurentb23d5282013-05-14 15:27:20 -07002945 } else {
2946 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
2947 }
2948exit:
2949 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
2950 return snd_device;
2951}
2952
Vignesh Kulothungan64698822018-01-23 11:25:18 -08002953#ifdef DYNAMIC_ECNS_ENABLED
2954static snd_device_t get_snd_device_for_voice_comm(struct platform_data *my_data,
2955 struct stream_in *in __unused,
2956 audio_devices_t out_device,
2957 audio_devices_t in_device)
2958{
2959 struct audio_device *adev = my_data->adev;
2960 snd_device_t snd_device = SND_DEVICE_NONE;
2961
2962 if (my_data->fluence_type != FLUENCE_DISABLE) {
2963 switch(AUDIO_DEVICE_BIT_IN | in_device) {
2964 case AUDIO_DEVICE_IN_BACK_MIC:
2965 if (my_data->fluence_in_spkr_mode) {
2966 if ((my_data->fluence_type & FLUENCE_PRO_ENABLE) &&
2967 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2968 snd_device = SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS;
2969 } else if (((my_data->fluence_type & FLUENCE_PRO_ENABLE) ||
2970 (my_data->fluence_type & FLUENCE_ENABLE)) &&
2971 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2972 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
2973 }
2974 adev->acdb_settings |= DMIC_FLAG;
2975 } else
2976 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
2977 break;
2978 case AUDIO_DEVICE_IN_BUILTIN_MIC:
2979 if (((my_data->fluence_type & FLUENCE_PRO_ENABLE) ||
2980 (my_data->fluence_type & FLUENCE_ENABLE)) &&
2981 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2982 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
2983 adev->acdb_settings |= DMIC_FLAG;
2984 } else
2985 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
2986 break;
2987 default:
2988 ALOGE("%s: Unsupported in_device %#x", __func__, in_device);
2989 break;
2990 }
2991 platform_set_echo_reference(adev, true, out_device);
2992 }
2993
2994 return snd_device;
2995}
2996#else
2997static snd_device_t get_snd_device_for_voice_comm(struct platform_data *my_data,
2998 struct stream_in *in,
2999 audio_devices_t out_device,
3000 audio_devices_t in_device)
3001{
3002 struct audio_device *adev = my_data->adev;
3003 snd_device_t snd_device = SND_DEVICE_NONE;
3004
3005 if (in->enable_aec &&
3006 in->enable_ns) {
3007 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
3008 if (my_data->fluence_in_spkr_mode &&
3009 my_data->fluence_in_voice_comm &&
3010 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
3011 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
3012 } else {
3013 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
3014 }
3015 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
3016 if (my_data->fluence_in_voice_comm &&
3017 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
3018 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
3019 } else {
3020 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
3021 }
3022 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3023 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
3024 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
3025 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
3026 }
3027 platform_set_echo_reference(adev, true, out_device);
3028 } else if (in->enable_aec) {
3029 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
3030 if (my_data->fluence_in_spkr_mode &&
3031 my_data->fluence_in_voice_comm &&
3032 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
3033 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
3034 } else {
3035 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
3036 }
3037 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
3038 if (my_data->fluence_in_voice_comm &&
3039 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
3040 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
3041 } else {
3042 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
3043 }
3044 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3045 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
3046 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
3047 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
3048 }
3049 platform_set_echo_reference(adev, true, out_device);
3050 } else if (in->enable_ns) {
3051 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
3052 if (my_data->fluence_in_spkr_mode &&
3053 my_data->fluence_in_voice_comm &&
3054 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
3055 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
3056 } else {
3057 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
3058 }
3059 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
3060 if (my_data->fluence_in_voice_comm &&
3061 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
3062 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
3063 } else {
3064 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
3065 }
3066 }
3067 }
3068
3069 return snd_device;
3070}
3071#endif //DYNAMIC_ECNS_ENABLED
3072
Eric Laurentd1b7a9b2018-11-15 12:24:31 -08003073snd_device_t platform_get_input_snd_device(void *platform,
3074 struct stream_in *in,
3075 audio_devices_t out_device)
Eric Laurentb23d5282013-05-14 15:27:20 -07003076{
3077 struct platform_data *my_data = (struct platform_data *)platform;
3078 struct audio_device *adev = my_data->adev;
Eric Laurentd1b7a9b2018-11-15 12:24:31 -08003079 audio_mode_t mode = adev->mode;
Eric Laurentb23d5282013-05-14 15:27:20 -07003080 snd_device_t snd_device = SND_DEVICE_NONE;
Eric Laurentd1b7a9b2018-11-15 12:24:31 -08003081
3082 if (in == NULL) {
3083 in = adev_get_active_input(adev);
3084 }
3085
3086 audio_source_t source = (in == NULL) ? AUDIO_SOURCE_DEFAULT : in->source;
3087 audio_devices_t in_device =
3088 ((in == NULL) ? AUDIO_DEVICE_NONE : in->device) & ~AUDIO_DEVICE_BIT_IN;
3089 audio_channel_mask_t channel_mask = (in == NULL) ? AUDIO_CHANNEL_IN_MONO : in->channel_mask;
3090 int channel_count = audio_channel_count_from_in_mask(channel_mask);
Eric Laurentb23d5282013-05-14 15:27:20 -07003091
Prashant Malanic92c5962015-08-11 15:10:18 -07003092 ALOGV("%s: enter: out_device(%#x) in_device(%#x) channel_count (%d) channel_mask (0x%x)",
3093 __func__, out_device, in_device, channel_count, channel_mask);
Eric Laurentd1b7a9b2018-11-15 12:24:31 -08003094
Devin Kimd789e432016-10-26 15:07:27 -07003095 if ((out_device != AUDIO_DEVICE_NONE) && (voice_is_in_call(adev) ||
3096 audio_extn_hfp_is_active(adev))) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07003097 if (adev->voice.tty_mode != TTY_MODE_OFF) {
Eric Laurentb23d5282013-05-14 15:27:20 -07003098 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05003099 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
3100 out_device & AUDIO_DEVICE_OUT_LINE) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07003101 switch (adev->voice.tty_mode) {
vivek mehtaa6b79742017-03-09 15:40:43 -08003102 case TTY_MODE_FULL:
3103 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
3104 break;
3105 case TTY_MODE_VCO:
3106 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
3107 break;
3108 case TTY_MODE_HCO:
3109 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
3110 break;
3111 default:
3112 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
3113 }
3114 goto exit;
Eric Laurent99dab492017-06-17 15:19:08 -07003115 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
vivek mehtaa6b79742017-03-09 15:40:43 -08003116 switch (adev->voice.tty_mode) {
3117 case TTY_MODE_FULL:
3118 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC;
3119 break;
3120 case TTY_MODE_VCO:
3121 // since voice will be captured from handset mic, use existing device
3122 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
3123 break;
3124 case TTY_MODE_HCO:
3125 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC;
3126 break;
3127 default:
3128 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
Eric Laurentb23d5282013-05-14 15:27:20 -07003129 }
3130 goto exit;
3131 }
3132 }
Eric Laurentb991fb02014-08-29 15:23:17 -05003133 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07003134 if (my_data->fluence_in_voice_call == false) {
3135 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3136 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003137 if (is_operator_tmus())
3138 snd_device = SND_DEVICE_IN_VOICE_DMIC_TMUS;
Eric Laurentb23d5282013-05-14 15:27:20 -07003139 else
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003140 snd_device = SND_DEVICE_IN_VOICE_DMIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07003141 }
3142 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
3143 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
3144 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003145 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003146 if (adev->bluetooth_nrec)
3147 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
3148 else
3149 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003150 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003151 if (adev->bluetooth_nrec)
3152 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
3153 else
3154 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003155 }
Eric Laurentb991fb02014-08-29 15:23:17 -05003156 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Prashant Malanic92c5962015-08-11 15:10:18 -07003157 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
3158 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
3159 out_device & AUDIO_DEVICE_OUT_LINE) {
3160 if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
3161 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
3162 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
3163 } else {
3164 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
3165 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003166 }
vivek mehtafe121d52015-08-10 23:39:23 -07003167
3168 //select default
3169 if (snd_device == SND_DEVICE_NONE) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07003170 if (!adev->enable_hfp) {
3171 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
3172 } else {
3173 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP;
3174 platform_set_echo_reference(adev, true, out_device);
3175 }
vivek mehtafe121d52015-08-10 23:39:23 -07003176 }
Prashant Malanic92c5962015-08-11 15:10:18 -07003177 } else if (out_device & AUDIO_DEVICE_OUT_TELEPHONY_TX) {
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07003178 snd_device = SND_DEVICE_IN_VOICE_RX;
Eric Laurent99dab492017-06-17 15:19:08 -07003179 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
David Lin40b07892017-08-07 15:02:48 -07003180 if (audio_extn_usb_is_capture_supported()) {
3181 snd_device = SND_DEVICE_IN_VOICE_USB_HEADSET_MIC;
3182 } else if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
3183 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
3184 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
3185 } else {
3186 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
3187 }
3188 }
Prashant Malanic92c5962015-08-11 15:10:18 -07003189 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003190 } else if (source == AUDIO_SOURCE_CAMCORDER) {
3191 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
3192 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Eric Laurent5f4ca952018-10-19 17:33:43 -07003193 switch (adev->camera_orientation) {
3194 case CAMERA_BACK_LANDSCAPE:
3195 snd_device = SND_DEVICE_IN_CAMCORDER_LANDSCAPE;
3196 break;
3197 case CAMERA_BACK_INVERT_LANDSCAPE:
3198 snd_device = SND_DEVICE_IN_CAMCORDER_INVERT_LANDSCAPE;
3199 break;
3200 case CAMERA_BACK_PORTRAIT:
3201 snd_device = SND_DEVICE_IN_CAMCORDER_PORTRAIT;
3202 break;
3203 case CAMERA_FRONT_LANDSCAPE:
3204 snd_device = SND_DEVICE_IN_CAMCORDER_SELFIE_LANDSCAPE;
3205 break;
3206 case CAMERA_FRONT_INVERT_LANDSCAPE:
3207 snd_device = SND_DEVICE_IN_CAMCORDER_SELFIE_INVERT_LANDSCAPE;
3208 break;
3209 case CAMERA_FRONT_PORTRAIT:
3210 snd_device = SND_DEVICE_IN_CAMCORDER_SELFIE_PORTRAIT;
3211 break;
3212 default:
3213 ALOGW("%s: invalid camera orientation %08x", __func__, adev->camera_orientation);
3214 snd_device = SND_DEVICE_IN_CAMCORDER_LANDSCAPE;
3215 break;
3216 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003217 }
3218 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
3219 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003220 if (my_data->fluence_in_voice_rec && channel_count == 1) {
3221 if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
3222 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
Eric Laurentd1b7a9b2018-11-15 12:24:31 -08003223 if (in->enable_aec)
vivek mehta733c1df2016-04-04 15:09:24 -07003224 snd_device = SND_DEVICE_IN_HANDSET_QMIC_AEC;
3225 else
3226 snd_device = SND_DEVICE_IN_HANDSET_QMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003227 } else if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
3228 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
Eric Laurentd1b7a9b2018-11-15 12:24:31 -08003229 if (in->enable_aec)
vivek mehta733c1df2016-04-04 15:09:24 -07003230 snd_device = SND_DEVICE_IN_HANDSET_TMIC_AEC;
3231 else
3232 snd_device = SND_DEVICE_IN_HANDSET_TMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003233 } else if (((my_data->fluence_type == FLUENCE_PRO_ENABLE) ||
3234 (my_data->fluence_type == FLUENCE_ENABLE)) &&
3235 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Eric Laurentd1b7a9b2018-11-15 12:24:31 -08003236 if (in->enable_aec)
vivek mehta733c1df2016-04-04 15:09:24 -07003237 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
3238 else
3239 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
Prashant Malanic92c5962015-08-11 15:10:18 -07003240 }
3241 platform_set_echo_reference(adev, true, out_device);
3242 } else if ((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) &&
3243 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
3244 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003245 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003246 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
3247 snd_device = SND_DEVICE_IN_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003248 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003249 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
3250 snd_device = SND_DEVICE_IN_QUAD_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07003251 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003252 if (snd_device == SND_DEVICE_NONE) {
Eric Laurentd1b7a9b2018-11-15 12:24:31 -08003253 if (in->enable_aec) {
3254 if (in->enable_ns) {
vivek mehtaf3440682016-05-11 14:24:37 -07003255 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS;
3256 } else {
3257 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC;
3258 }
vivek mehta733c1df2016-04-04 15:09:24 -07003259 platform_set_echo_reference(adev, true, out_device);
Eric Laurentd1b7a9b2018-11-15 12:24:31 -08003260 } else if (in->enable_ns) {
vivek mehtaf3440682016-05-11 14:24:37 -07003261 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
3262 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003263 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
vivek mehtaf3440682016-05-11 14:24:37 -07003264 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003265 }
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -07003266 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3267 snd_device = SND_DEVICE_IN_VOICE_REC_HEADSET_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07003268 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07003269 snd_device = SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07003270 }
rago90fb9612015-12-02 11:37:53 -08003271 } else if (source == AUDIO_SOURCE_UNPROCESSED) {
3272 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
vivek mehta4ed66e62016-04-15 23:33:34 -07003273 if (((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) ||
3274 (channel_mask == AUDIO_CHANNEL_IN_STEREO)) &&
3275 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
3276 snd_device = SND_DEVICE_IN_UNPROCESSED_STEREO_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003277 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07003278 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
3279 snd_device = SND_DEVICE_IN_UNPROCESSED_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003280 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07003281 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
3282 snd_device = SND_DEVICE_IN_UNPROCESSED_QUAD_MIC;
3283 } else {
3284 snd_device = SND_DEVICE_IN_UNPROCESSED_MIC;
3285 }
rago90fb9612015-12-02 11:37:53 -08003286 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3287 snd_device = SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07003288 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07003289 snd_device = SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC;
rago90fb9612015-12-02 11:37:53 -08003290 }
Eric Laurent50a38ed2015-10-14 18:48:06 -07003291 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION ||
rago90fb9612015-12-02 11:37:53 -08003292 mode == AUDIO_MODE_IN_COMMUNICATION) {
David Lin40b07892017-08-07 15:02:48 -07003293 if (out_device & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
3294 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
3295 (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE | AUDIO_DEVICE_OUT_USB_HEADSET) &&
3296 !audio_extn_usb_is_capture_supported())) {
Eric Laurentb23d5282013-05-14 15:27:20 -07003297 in_device = AUDIO_DEVICE_IN_BACK_MIC;
David Lin40b07892017-08-07 15:02:48 -07003298 }
Vignesh Kulothungan64698822018-01-23 11:25:18 -08003299
Eric Laurentd1b7a9b2018-11-15 12:24:31 -08003300 if (in) {
Vignesh Kulothungan64698822018-01-23 11:25:18 -08003301 snd_device = get_snd_device_for_voice_comm(my_data, in, out_device, in_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07003302 }
3303 } else if (source == AUDIO_SOURCE_DEFAULT) {
3304 goto exit;
3305 }
3306
3307
3308 if (snd_device != SND_DEVICE_NONE) {
3309 goto exit;
3310 }
3311
3312 if (in_device != AUDIO_DEVICE_NONE &&
3313 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
3314 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
3315 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003316 if ((my_data->source_mic_type & SOURCE_QUAD_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003317 channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003318 snd_device = SND_DEVICE_IN_QUAD_MIC;
3319 } else if ((my_data->source_mic_type & SOURCE_THREE_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003320 channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003321 snd_device = SND_DEVICE_IN_THREE_MIC;
3322 } else if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
3323 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003324 snd_device = SND_DEVICE_IN_HANDSET_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07003325 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
3326 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003327 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003328 } else {
3329 ALOGE("%s: something wrong (1): source type (%d) channel_count (%d) .."
3330 " channel mask (0x%x) no combination found .. setting to mono", __func__,
3331 my_data->source_mic_type, channel_count, channel_mask);
3332 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3333 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003334 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003335 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
3336 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003337 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07003338 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
3339 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003340 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003341 } else {
3342 ALOGE("%s: something wrong (2): source type (%d) channel_count (%d) .."
3343 " no combination found .. setting to mono", __func__,
3344 my_data->source_mic_type, channel_count);
3345 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
3346 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003347 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3348 snd_device = SND_DEVICE_IN_HEADSET_MIC;
3349 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003350 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003351 if (adev->bluetooth_nrec)
3352 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
3353 else
3354 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003355 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003356 if (adev->bluetooth_nrec)
3357 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
3358 else
3359 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003360 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003361 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
3362 snd_device = SND_DEVICE_IN_HDMI_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07003363 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
David Linee3fe402017-03-13 10:00:42 -07003364 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07003365 } else {
3366 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
3367 ALOGW("%s: Using default handset-mic", __func__);
3368 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3369 }
3370 } else {
3371 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
3372 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3373 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
3374 snd_device = SND_DEVICE_IN_HEADSET_MIC;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003375 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07003376 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003377 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05003378 out_device & AUDIO_DEVICE_OUT_LINE) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003379 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
3380 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003381 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07003382 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
3383 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003384 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003385 } else {
3386 ALOGE("%s: something wrong (3): source type (%d) channel_count (%d) .."
3387 " no combination found .. setting to mono", __func__,
3388 my_data->source_mic_type, channel_count);
3389 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
3390 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003391 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003392 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003393 if (adev->bluetooth_nrec)
3394 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
3395 else
3396 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003397 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003398 if (adev->bluetooth_nrec)
3399 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
3400 else
3401 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003402 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003403 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
3404 snd_device = SND_DEVICE_IN_HDMI_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07003405 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
David Linee3fe402017-03-13 10:00:42 -07003406 if (audio_extn_usb_is_capture_supported())
3407 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
3408 else
3409 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07003410 } else {
3411 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
3412 ALOGW("%s: Using default handset-mic", __func__);
3413 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3414 }
3415 }
3416exit:
3417 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
3418 return snd_device;
3419}
3420
3421int platform_set_hdmi_channels(void *platform, int channel_count)
3422{
3423 struct platform_data *my_data = (struct platform_data *)platform;
3424 struct audio_device *adev = my_data->adev;
3425 struct mixer_ctl *ctl;
3426 const char *channel_cnt_str = NULL;
3427 const char *mixer_ctl_name = "HDMI_RX Channels";
3428 switch (channel_count) {
3429 case 8:
3430 channel_cnt_str = "Eight"; break;
3431 case 7:
3432 channel_cnt_str = "Seven"; break;
3433 case 6:
3434 channel_cnt_str = "Six"; break;
3435 case 5:
3436 channel_cnt_str = "Five"; break;
3437 case 4:
3438 channel_cnt_str = "Four"; break;
3439 case 3:
3440 channel_cnt_str = "Three"; break;
3441 default:
3442 channel_cnt_str = "Two"; break;
3443 }
3444 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3445 if (!ctl) {
3446 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3447 __func__, mixer_ctl_name);
3448 return -EINVAL;
3449 }
3450 ALOGV("HDMI channel count: %s", channel_cnt_str);
3451 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
3452 return 0;
3453}
3454
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003455int platform_edid_get_max_channels(void *platform)
Eric Laurentb23d5282013-05-14 15:27:20 -07003456{
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003457 struct platform_data *my_data = (struct platform_data *)platform;
3458 struct audio_device *adev = my_data->adev;
Eric Laurentb23d5282013-05-14 15:27:20 -07003459 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
3460 char *sad = block;
3461 int num_audio_blocks;
3462 int channel_count;
3463 int max_channels = 0;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003464 int i, ret, count;
Eric Laurentb23d5282013-05-14 15:27:20 -07003465
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003466 struct mixer_ctl *ctl;
3467
3468 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
3469 if (!ctl) {
3470 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3471 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
Eric Laurentb23d5282013-05-14 15:27:20 -07003472 return 0;
3473 }
3474
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003475 mixer_ctl_update(ctl);
3476
3477 count = mixer_ctl_get_num_values(ctl);
Eric Laurentb23d5282013-05-14 15:27:20 -07003478
3479 /* Read SAD blocks, clamping the maximum size for safety */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003480 if (count > (int)sizeof(block))
3481 count = (int)sizeof(block);
Eric Laurentb23d5282013-05-14 15:27:20 -07003482
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003483 ret = mixer_ctl_get_array(ctl, block, count);
3484 if (ret != 0) {
3485 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
3486 return 0;
3487 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003488
3489 /* Calculate the number of SAD blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003490 num_audio_blocks = count / SAD_BLOCK_SIZE;
Eric Laurentb23d5282013-05-14 15:27:20 -07003491
3492 for (i = 0; i < num_audio_blocks; i++) {
3493 /* Only consider LPCM blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003494 if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
3495 sad += 3;
Eric Laurentb23d5282013-05-14 15:27:20 -07003496 continue;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003497 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003498
3499 channel_count = (sad[0] & 0x7) + 1;
3500 if (channel_count > max_channels)
3501 max_channels = channel_count;
3502
3503 /* Advance to next block */
3504 sad += 3;
3505 }
3506
3507 return max_channels;
3508}
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003509
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07003510int platform_set_incall_recording_session_id(void *platform,
3511 uint32_t session_id, int rec_mode)
3512{
3513 int ret = 0;
3514 struct platform_data *my_data = (struct platform_data *)platform;
3515 struct audio_device *adev = my_data->adev;
3516 struct mixer_ctl *ctl;
3517 const char *mixer_ctl_name = "Voc VSID";
3518 int num_ctl_values;
3519 int i;
3520
3521 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3522 if (!ctl) {
3523 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3524 __func__, mixer_ctl_name);
3525 ret = -EINVAL;
3526 } else {
3527 num_ctl_values = mixer_ctl_get_num_values(ctl);
3528 for (i = 0; i < num_ctl_values; i++) {
3529 if (mixer_ctl_set_value(ctl, i, session_id)) {
3530 ALOGV("Error: invalid session_id: %x", session_id);
3531 ret = -EINVAL;
3532 break;
3533 }
3534 }
3535 }
3536
3537 if (my_data->csd != NULL) {
3538 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
3539 if (ret < 0) {
3540 ALOGE("%s: csd_client_start_record failed, error %d",
3541 __func__, ret);
3542 }
3543 }
3544
3545 return ret;
3546}
3547
Arun Mirpuriba2749a2018-04-17 14:32:24 -07003548int platform_set_incall_recording_session_channels(void *platform,
3549 uint32_t channel_count)
3550{
3551 int ret = 0;
3552 struct platform_data *my_data = (struct platform_data *)platform;
3553 struct audio_device *adev = my_data->adev;
3554 const char *mixer_ctl_name = "Voc Rec Config";
3555 int num_ctl_values;
3556 int i;
3557 struct mixer_ctl *ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3558
3559 if (!ctl) {
3560 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3561 __func__, mixer_ctl_name);
3562 ret = -EINVAL;
3563 } else {
3564 num_ctl_values = mixer_ctl_get_num_values(ctl);
3565 for (i = 0; i < num_ctl_values; i++) {
3566 if (mixer_ctl_set_value(ctl, i, channel_count)) {
3567 ALOGE("Error: invalid channel count: %x", channel_count);
3568 ret = -EINVAL;
3569 break;
3570 }
3571 }
3572 }
3573
3574 return ret;
3575}
3576
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07003577int platform_stop_incall_recording_usecase(void *platform)
3578{
3579 int ret = 0;
3580 struct platform_data *my_data = (struct platform_data *)platform;
3581
3582 if (my_data->csd != NULL) {
3583 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
3584 if (ret < 0) {
3585 ALOGE("%s: csd_client_stop_record failed, error %d",
3586 __func__, ret);
3587 }
3588 }
3589
3590 return ret;
3591}
3592
3593int platform_start_incall_music_usecase(void *platform)
3594{
3595 int ret = 0;
3596 struct platform_data *my_data = (struct platform_data *)platform;
3597
3598 if (my_data->csd != NULL) {
3599 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
3600 if (ret < 0) {
3601 ALOGE("%s: csd_client_start_playback failed, error %d",
3602 __func__, ret);
3603 }
3604 }
3605
3606 return ret;
3607}
3608
3609int platform_stop_incall_music_usecase(void *platform)
3610{
3611 int ret = 0;
3612 struct platform_data *my_data = (struct platform_data *)platform;
3613
3614 if (my_data->csd != NULL) {
3615 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
3616 if (ret < 0) {
3617 ALOGE("%s: csd_client_stop_playback failed, error %d",
3618 __func__, ret);
3619 }
3620 }
3621
3622 return ret;
3623}
3624
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003625int platform_set_parameters(void *platform, struct str_parms *parms)
3626{
3627 struct platform_data *my_data = (struct platform_data *)platform;
jasmine chac89321b2018-04-10 21:37:01 +08003628 char *value = NULL;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003629 char *kv_pairs = str_parms_to_str(parms);
jasmine chac89321b2018-04-10 21:37:01 +08003630 int len;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003631 int ret = 0, err;
3632
3633 if (kv_pairs == NULL) {
3634 ret = -EINVAL;
Jasmine Chaa314e192018-05-09 17:46:28 +08003635 ALOGE("%s: key-value pair is NULL", __func__);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003636 goto done;
3637 }
3638
3639 ALOGV("%s: enter: %s", __func__, kv_pairs);
3640
jasmine chac89321b2018-04-10 21:37:01 +08003641 len = strlen(kv_pairs);
Jasmine Chaa314e192018-05-09 17:46:28 +08003642 value = (char*)calloc(len + 1, sizeof(char));
jasmine chac89321b2018-04-10 21:37:01 +08003643 if (value == NULL) {
3644 ret = -ENOMEM;
Jasmine Chaa314e192018-05-09 17:46:28 +08003645 ALOGE("[%s] failed to allocate memory", __func__);
jasmine chac89321b2018-04-10 21:37:01 +08003646 goto done;
3647 }
3648
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003649 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME,
jasmine chac89321b2018-04-10 21:37:01 +08003650 value, len);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003651 if (err >= 0) {
3652 str_parms_del(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME);
3653 my_data->snd_card_name = strdup(value);
3654 ALOGV("%s: sound card name %s", __func__, my_data->snd_card_name);
3655 }
3656
keunhui.park2f7306a2015-07-16 16:48:06 +09003657 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO,
jasmine chac89321b2018-04-10 21:37:01 +08003658 value, len);
keunhui.park2f7306a2015-07-16 16:48:06 +09003659 if (err >= 0) {
3660 struct operator_info *info;
3661 char *str = value;
3662 char *name;
3663
3664 str_parms_del(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO);
3665 info = (struct operator_info *)calloc(1, sizeof(struct operator_info));
3666 name = strtok(str, ";");
3667 info->name = strdup(name);
3668 info->mccmnc = strdup(str + strlen(name) + 1);
3669
3670 list_add_tail(&operator_info_list, &info->list);
Joe Onorato188b6222016-03-01 11:02:27 -08003671 ALOGV("%s: add operator[%s] mccmnc[%s]", __func__, info->name, info->mccmnc);
keunhui.park2f7306a2015-07-16 16:48:06 +09003672 }
Prashant Malanic92c5962015-08-11 15:10:18 -07003673
Jasmine Chaa314e192018-05-09 17:46:28 +08003674 memset(value, 0, len + 1);
Eric Laurentc6333382015-09-14 12:43:44 -07003675 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT,
jasmine chac89321b2018-04-10 21:37:01 +08003676 value, len);
Prashant Malanic92c5962015-08-11 15:10:18 -07003677 if (err >= 0) {
Eric Laurentc6333382015-09-14 12:43:44 -07003678 str_parms_del(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT);
Prashant Malanic92c5962015-08-11 15:10:18 -07003679 my_data->max_mic_count = atoi(value);
3680 ALOGV("%s: max_mic_count %s/%d", __func__, value, my_data->max_mic_count);
Prashant Malanic92c5962015-08-11 15:10:18 -07003681 }
3682
jasmine chac89321b2018-04-10 21:37:01 +08003683 /* handle audio calibration parameters */
3684 set_audiocal(platform, parms, value, len);
3685
vivek mehta90933872017-06-15 18:04:39 -07003686 // to-do: disable setting sidetone gain, will revist this later
3687 // audio_extn_usb_set_sidetone_gain(parms, value, len);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003688done:
3689 ALOGV("%s: exit with code(%d)", __func__, ret);
3690 if (kv_pairs != NULL)
3691 free(kv_pairs);
jasmine chac89321b2018-04-10 21:37:01 +08003692 if (value != NULL)
3693 free(value);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003694
3695 return ret;
3696}
3697
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003698/* Delay in Us */
3699int64_t platform_render_latency(audio_usecase_t usecase)
3700{
3701 switch (usecase) {
3702 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
3703 return DEEP_BUFFER_PLATFORM_DELAY;
3704 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
3705 return LOW_LATENCY_PLATFORM_DELAY;
Haynes Mathew George03c40102016-01-29 17:57:48 -08003706 case USECASE_AUDIO_PLAYBACK_ULL:
3707 return ULL_PLATFORM_DELAY;
Eric Laurent0e46adf2016-12-16 12:49:24 -08003708 case USECASE_AUDIO_PLAYBACK_MMAP:
3709 return MMAP_PLATFORM_DELAY;
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003710 default:
3711 return 0;
3712 }
3713}
Haynes Mathew George98c95622014-06-20 19:14:25 -07003714
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003715int platform_set_snd_device_backend(snd_device_t device, const char *backend_tag,
3716 const char * hw_interface)
Haynes Mathew George98c95622014-06-20 19:14:25 -07003717{
3718 int ret = 0;
3719
3720 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
3721 ALOGE("%s: Invalid snd_device = %d",
3722 __func__, device);
3723 ret = -EINVAL;
3724 goto done;
3725 }
3726
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003727 ALOGV("%s: backend_tag_table[%s]: old = %s new = %s", __func__,
3728 platform_get_snd_device_name(device),
3729 backend_tag_table[device] != NULL ? backend_tag_table[device]: "null", backend_tag);
3730 if (backend_tag_table[device]) {
3731 free(backend_tag_table[device]);
Haynes Mathew George98c95622014-06-20 19:14:25 -07003732 }
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003733 backend_tag_table[device] = strdup(backend_tag);
3734
3735 if (hw_interface != NULL) {
3736 if (hw_interface_table[device])
3737 free(hw_interface_table[device]);
3738 ALOGV("%s: hw_interface_table[%d] = %s", __func__, device, hw_interface);
3739 hw_interface_table[device] = strdup(hw_interface);
3740 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07003741done:
3742 return ret;
3743}
3744
3745int platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t pcm_id)
3746{
3747 int ret = 0;
3748 if ((usecase <= USECASE_INVALID) || (usecase >= AUDIO_USECASE_MAX)) {
3749 ALOGE("%s: invalid usecase case idx %d", __func__, usecase);
3750 ret = -EINVAL;
3751 goto done;
3752 }
3753
3754 if ((type != 0) && (type != 1)) {
3755 ALOGE("%s: invalid usecase type", __func__);
3756 ret = -EINVAL;
3757 }
vivek mehtaa68fea62017-06-08 19:04:02 -07003758 ALOGV("%s: pcm_device_table[%d %s][%d] = %d", __func__, usecase,
3759 use_case_table[usecase],
3760 type, pcm_id);
Haynes Mathew George98c95622014-06-20 19:14:25 -07003761 pcm_device_table[usecase][type] = pcm_id;
3762done:
3763 return ret;
3764}
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003765
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07003766#define DEFAULT_NOMINAL_SPEAKER_GAIN 20
3767int ramp_speaker_gain(struct audio_device *adev, bool ramp_up, int target_ramp_up_gain) {
3768 // backup_gain: gain to try to set in case of an error during ramp
3769 int start_gain, end_gain, step, backup_gain, i;
3770 bool error = false;
3771 const struct mixer_ctl *ctl;
3772 const char *mixer_ctl_name_gain_left = "Left Speaker Gain";
3773 const char *mixer_ctl_name_gain_right = "Right Speaker Gain";
3774 struct mixer_ctl *ctl_left = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_left);
3775 struct mixer_ctl *ctl_right = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_right);
3776 if (!ctl_left || !ctl_right) {
3777 ALOGE("%s: Could not get ctl for mixer cmd - %s or %s, not applying speaker gain ramp",
3778 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
3779 return -EINVAL;
3780 } else if ((mixer_ctl_get_num_values(ctl_left) != 1)
3781 || (mixer_ctl_get_num_values(ctl_right) != 1)) {
3782 ALOGE("%s: Unexpected num values for mixer cmd - %s or %s, not applying speaker gain ramp",
3783 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
3784 return -EINVAL;
3785 }
3786 if (ramp_up) {
3787 start_gain = 0;
3788 end_gain = target_ramp_up_gain > 0 ? target_ramp_up_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
3789 step = +1;
3790 backup_gain = end_gain;
3791 } else {
3792 // using same gain on left and right
3793 const int left_gain = mixer_ctl_get_value(ctl_left, 0);
3794 start_gain = left_gain > 0 ? left_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
3795 end_gain = 0;
3796 step = -1;
3797 backup_gain = start_gain;
3798 }
3799 for (i = start_gain ; i != (end_gain + step) ; i += step) {
3800 //ALOGV("setting speaker gain to %d", i);
3801 if (mixer_ctl_set_value(ctl_left, 0, i)) {
3802 ALOGE("%s: error setting %s to %d during gain ramp",
3803 __func__, mixer_ctl_name_gain_left, i);
3804 error = true;
3805 break;
3806 }
3807 if (mixer_ctl_set_value(ctl_right, 0, i)) {
3808 ALOGE("%s: error setting %s to %d during gain ramp",
3809 __func__, mixer_ctl_name_gain_right, i);
3810 error = true;
3811 break;
3812 }
3813 usleep(1000);
3814 }
3815 if (error) {
3816 // an error occured during the ramp, let's still try to go back to a safe volume
3817 if (mixer_ctl_set_value(ctl_left, 0, backup_gain)) {
3818 ALOGE("%s: error restoring left gain to %d", __func__, backup_gain);
3819 }
3820 if (mixer_ctl_set_value(ctl_right, 0, backup_gain)) {
3821 ALOGE("%s: error restoring right gain to %d", __func__, backup_gain);
3822 }
3823 }
3824 return start_gain;
3825}
3826
vivek mehtae59cfb22017-06-16 15:57:11 -07003827int platform_set_swap_mixer(struct audio_device *adev, bool swap_channels)
3828{
3829 const char *mixer_ctl_name = "Swap channel";
3830 struct mixer_ctl *ctl;
3831 const char *mixer_path;
3832 struct platform_data *my_data = (struct platform_data *)adev->platform;
3833
3834 // forced to set to swap, but device not rotated ... ignore set
3835 if (swap_channels && !my_data->speaker_lr_swap)
3836 return 0;
3837
3838 ALOGV("%s:", __func__);
3839
3840 if (swap_channels) {
3841 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER_REVERSE);
3842 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
3843 } else {
3844 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER);
3845 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
3846 }
3847
3848 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3849 if (!ctl) {
3850 ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name);
3851 return -EINVAL;
3852 }
3853
3854 if (mixer_ctl_set_value(ctl, 0, swap_channels) < 0) {
3855 ALOGE("%s: Could not set reverse cotrol %d",__func__, swap_channels);
3856 return -EINVAL;
3857 }
3858
3859 ALOGV("platfor_force_swap_channel :: Channel orientation ( %s ) ",
3860 swap_channels?"R --> L":"L --> R");
3861
3862 return 0;
3863}
3864
3865int platform_check_and_set_swap_lr_channels(struct audio_device *adev, bool swap_channels)
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003866{
3867 // only update if there is active pcm playback on speaker
3868 struct audio_usecase *usecase;
3869 struct listnode *node;
3870 struct platform_data *my_data = (struct platform_data *)adev->platform;
3871
vivek mehtae59cfb22017-06-16 15:57:11 -07003872 my_data->speaker_lr_swap = swap_channels;
Jean-Michel Trivif7148702016-09-16 18:23:05 -07003873
vivek mehtae59cfb22017-06-16 15:57:11 -07003874 return platform_set_swap_channels(adev, swap_channels);
3875}
Jean-Michel Trivif7148702016-09-16 18:23:05 -07003876
vivek mehtae59cfb22017-06-16 15:57:11 -07003877int platform_set_swap_channels(struct audio_device *adev, bool swap_channels)
3878{
3879 // only update if there is active pcm playback on speaker
3880 struct audio_usecase *usecase;
3881 struct listnode *node;
3882 struct platform_data *my_data = (struct platform_data *)adev->platform;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003883
vivek mehtae59cfb22017-06-16 15:57:11 -07003884 // do not swap channels in audio modes with concurrent capture and playback
3885 // as this may break the echo reference
3886 if ((adev->mode == AUDIO_MODE_IN_COMMUNICATION) || (adev->mode == AUDIO_MODE_IN_CALL)) {
3887 ALOGV("%s: will not swap due to audio mode %d", __func__, adev->mode);
3888 return 0;
3889 }
3890
3891 list_for_each(node, &adev->usecase_list) {
3892 usecase = node_to_item(node, struct audio_usecase, list);
3893 if (usecase->type == PCM_PLAYBACK &&
3894 usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) {
3895 /*
3896 * If acdb tuning is different for SPEAKER_REVERSE, it is must
3897 * to perform device switch to disable the current backend to
3898 * enable it with new acdb data.
3899 */
3900 if (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
3901 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]) {
3902 const int initial_skpr_gain = ramp_speaker_gain(adev, false /*ramp_up*/, -1);
3903 select_devices(adev, usecase->id);
3904 if (initial_skpr_gain != -EINVAL)
3905 ramp_speaker_gain(adev, true /*ramp_up*/, initial_skpr_gain);
3906
3907 } else {
3908 platform_set_swap_mixer(adev, swap_channels);
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003909 }
vivek mehtae59cfb22017-06-16 15:57:11 -07003910 break;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003911 }
3912 }
vivek mehtae59cfb22017-06-16 15:57:11 -07003913
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003914 return 0;
3915}
vivek mehtaa8d7c922016-05-25 14:40:44 -07003916
3917static struct amp_db_and_gain_table tbl_mapping[MAX_VOLUME_CAL_STEPS];
3918static int num_gain_tbl_entry = 0;
3919
3920bool platform_add_gain_level_mapping(struct amp_db_and_gain_table *tbl_entry) {
3921
3922 ALOGV("%s: enter .. add %f %f %d", __func__, tbl_entry->amp, tbl_entry->db, tbl_entry->level);
3923 if (num_gain_tbl_entry == -1) {
3924 ALOGE("%s: num entry beyond valid step levels or corrupted..rejecting custom mapping",
3925 __func__);
3926 return false;
3927 }
3928
3929 if (num_gain_tbl_entry >= MAX_VOLUME_CAL_STEPS) {
3930 ALOGE("%s: max entry reached max[%d] current index[%d] .. rejecting", __func__,
3931 MAX_VOLUME_CAL_STEPS, num_gain_tbl_entry);
3932 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
3933 return false;
3934 }
3935
3936 if (num_gain_tbl_entry > 0 && tbl_mapping[num_gain_tbl_entry - 1].amp >= tbl_entry->amp) {
3937 ALOGE("%s: value not in ascending order .. rejecting custom mapping", __func__);
3938 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
3939 return false;
3940 }
3941
3942 tbl_mapping[num_gain_tbl_entry] = *tbl_entry;
3943 ++num_gain_tbl_entry;
3944
3945 return true;
3946}
3947
3948int platform_get_gain_level_mapping(struct amp_db_and_gain_table *mapping_tbl,
3949 int table_size) {
3950 int itt = 0;
3951 ALOGV("platform_get_gain_level_mapping called ");
3952
3953 if (num_gain_tbl_entry <= 0 || num_gain_tbl_entry > MAX_VOLUME_CAL_STEPS) {
3954 ALOGD("%s: empty or currupted gain_mapping_table", __func__);
3955 return 0;
3956 }
3957
3958 for (; itt < num_gain_tbl_entry && itt <= table_size; itt++) {
3959 mapping_tbl[itt] = tbl_mapping[itt];
3960 ALOGV("%s: added amp[%f] db[%f] level[%d]", __func__,
3961 mapping_tbl[itt].amp, mapping_tbl[itt].db, mapping_tbl[itt].level);
3962 }
3963
3964 return num_gain_tbl_entry;
3965}
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07003966
3967int platform_snd_card_update(void *platform, card_status_t status)
3968{
3969 struct platform_data *my_data = (struct platform_data *)platform;
3970 struct audio_device *adev = my_data->adev;
3971
3972 if (status == CARD_STATUS_ONLINE) {
3973 if (my_data->acdb_send_custom_top)
3974 my_data->acdb_send_custom_top();
3975 }
3976 return 0;
3977}
David Linee3fe402017-03-13 10:00:42 -07003978
3979/*
3980 * configures afe with bit width and Sample Rate
3981 */
Haynes Mathew George65f6b432018-02-27 17:44:55 -08003982int platform_set_backend_cfg(const struct audio_device* adev,
3983 snd_device_t snd_device,
3984 const struct audio_backend_cfg *backend_cfg)
David Linee3fe402017-03-13 10:00:42 -07003985{
3986
3987 int ret = 0;
3988 const int backend_idx = platform_get_backend_index(snd_device);
3989 struct platform_data *my_data = (struct platform_data *)adev->platform;
3990 const unsigned int bit_width = backend_cfg->bit_width;
3991 const unsigned int sample_rate = backend_cfg->sample_rate;
3992 const unsigned int channels = backend_cfg->channels;
3993 const audio_format_t format = backend_cfg->format;
3994 const bool passthrough_enabled = backend_cfg->passthrough_enabled;
3995
3996
3997 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
3998 ", backend_idx %d device (%s)", __func__, bit_width,
3999 sample_rate, channels, backend_idx,
4000 platform_get_snd_device_name(snd_device));
4001
4002 if ((my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl) &&
4003 (bit_width != my_data->current_backend_cfg[backend_idx].bit_width)) {
4004
4005 struct mixer_ctl *ctl = NULL;
4006 ctl = mixer_get_ctl_by_name(adev->mixer,
4007 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
4008 if (!ctl) {
4009 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
4010 __func__,
4011 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
4012 return -EINVAL;
4013 }
4014
4015 if (bit_width == 24) {
4016 if (format == AUDIO_FORMAT_PCM_24_BIT_PACKED)
4017 ret = mixer_ctl_set_enum_by_string(ctl, "S24_3LE");
4018 else
4019 ret = mixer_ctl_set_enum_by_string(ctl, "S24_LE");
4020 } else if (bit_width == 32) {
4021 ret = mixer_ctl_set_enum_by_string(ctl, "S32_LE");
4022 } else {
4023 ret = mixer_ctl_set_enum_by_string(ctl, "S16_LE");
4024 }
4025 if ( ret < 0) {
4026 ALOGE("%s:becf: afe: fail for %s mixer set to %d bit for %x format", __func__,
4027 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
4028 } else {
4029 my_data->current_backend_cfg[backend_idx].bit_width = bit_width;
4030 ALOGD("%s:becf: afe: %s mixer set to %d bit for %x format", __func__,
4031 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
4032 }
4033 /* set the ret as 0 and not pass back to upper layer */
4034 ret = 0;
4035 }
4036
4037 if (passthrough_enabled || ((my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl) &&
4038 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate))) {
4039 char *rate_str = NULL;
4040 struct mixer_ctl *ctl = NULL;
4041
4042 switch (sample_rate) {
4043 case 32000:
4044 if (passthrough_enabled) {
4045 rate_str = "KHZ_32";
4046 break;
4047 }
4048 case 8000:
4049 case 11025:
4050 case 16000:
4051 case 22050:
4052 case 48000:
4053 rate_str = "KHZ_48";
4054 break;
4055 case 44100:
4056 rate_str = "KHZ_44P1";
4057 break;
4058 case 64000:
4059 case 96000:
4060 rate_str = "KHZ_96";
4061 break;
4062 case 88200:
4063 rate_str = "KHZ_88P2";
4064 break;
4065 case 176400:
4066 rate_str = "KHZ_176P4";
4067 break;
4068 case 192000:
4069 rate_str = "KHZ_192";
4070 break;
4071 case 352800:
4072 rate_str = "KHZ_352P8";
4073 break;
4074 case 384000:
4075 rate_str = "KHZ_384";
4076 break;
4077 case 144000:
4078 if (passthrough_enabled) {
4079 rate_str = "KHZ_144";
4080 break;
4081 }
4082 default:
4083 rate_str = "KHZ_48";
4084 break;
4085 }
4086
4087 ctl = mixer_get_ctl_by_name(adev->mixer,
4088 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
4089 if(!ctl) {
4090 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
4091 __func__,
4092 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
4093 return -EINVAL;
4094 }
4095
4096 ALOGD("%s:becf: afe: %s set to %s", __func__,
4097 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl, rate_str);
4098 mixer_ctl_set_enum_by_string(ctl, rate_str);
4099 my_data->current_backend_cfg[backend_idx].sample_rate = sample_rate;
4100 }
4101 if ((my_data->current_backend_cfg[backend_idx].channels_mixer_ctl) &&
4102 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
4103 struct mixer_ctl *ctl = NULL;
4104 char *channel_cnt_str = NULL;
4105
4106 switch (channels) {
4107 case 8:
4108 channel_cnt_str = "Eight"; break;
4109 case 7:
4110 channel_cnt_str = "Seven"; break;
4111 case 6:
4112 channel_cnt_str = "Six"; break;
4113 case 5:
4114 channel_cnt_str = "Five"; break;
4115 case 4:
4116 channel_cnt_str = "Four"; break;
4117 case 3:
4118 channel_cnt_str = "Three"; break;
4119 case 1:
4120 channel_cnt_str = "One"; break;
4121 case 2:
4122 default:
4123 channel_cnt_str = "Two"; break;
4124 }
4125
4126 ctl = mixer_get_ctl_by_name(adev->mixer,
4127 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
4128 if (!ctl) {
4129 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
4130 __func__,
4131 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
4132 return -EINVAL;
4133 }
4134 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
4135 my_data->current_backend_cfg[backend_idx].channels = channels;
4136
4137 // skip EDID configuration for HDMI backend
4138
4139 ALOGD("%s:becf: afe: %s set to %s", __func__,
4140 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl,
4141 channel_cnt_str);
4142 }
4143
4144 // skip set ext_display format mixer control
4145 return ret;
4146}
4147
4148static int platform_get_snd_device_bit_width(snd_device_t snd_device)
4149{
4150 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
4151 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
4152 return CODEC_BACKEND_DEFAULT_BIT_WIDTH;
4153 }
4154
4155 return backend_bit_width_table[snd_device];
4156}
4157
4158/*
4159 * return backend_idx on which voice call is active
4160 */
4161static int platform_get_voice_call_backend(struct audio_device* adev)
4162{
4163 struct audio_usecase *uc = NULL;
4164 struct listnode *node;
4165 snd_device_t out_snd_device = SND_DEVICE_NONE;
4166
4167 int backend_idx = -1;
4168
4169 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
4170 list_for_each(node, &adev->usecase_list) {
4171 uc = node_to_item(node, struct audio_usecase, list);
4172 if (uc && uc->type == VOICE_CALL && uc->stream.out) {
4173 out_snd_device = platform_get_output_snd_device(adev->platform,
4174 uc->stream.out->devices);
4175 backend_idx = platform_get_backend_index(out_snd_device);
4176 break;
4177 }
4178 }
4179 }
4180 return backend_idx;
4181}
4182
4183/*
4184 * goes through all the current usecases and picks the highest
4185 * bitwidth & samplerate
4186 */
4187static bool platform_check_capture_backend_cfg(struct audio_device* adev,
4188 int backend_idx,
4189 struct audio_backend_cfg *backend_cfg)
4190{
4191 bool backend_change = false;
4192 unsigned int bit_width;
4193 unsigned int sample_rate;
4194 unsigned int channels;
4195 struct platform_data *my_data = (struct platform_data *)adev->platform;
4196
4197 bit_width = backend_cfg->bit_width;
4198 sample_rate = backend_cfg->sample_rate;
4199 channels = backend_cfg->channels;
4200
4201 ALOGV("%s:txbecf: afe: Codec selected backend: %d current bit width: %d and "
4202 "sample rate: %d, channels %d",__func__,backend_idx, bit_width,
4203 sample_rate, channels);
4204
4205 // For voice calls use default configuration i.e. 16b/48K, only applicable to
4206 // default backend
4207 // force routing is not required here, caller will do it anyway
4208 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
4209 ALOGW("%s:txbecf: afe: Use default bw and sr for voice/voip calls and "
4210 "for unprocessed/camera source", __func__);
4211 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
4212 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4213 }
4214
4215 if (backend_idx == USB_AUDIO_TX_BACKEND) {
4216 audio_extn_usb_is_config_supported(&bit_width, &sample_rate, &channels, false);
4217 ALOGV("%s:txbecf: afe: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
4218 __func__, bit_width, sample_rate, channels);
4219 }
4220
4221 ALOGV("%s:txbecf: afe: Codec selected backend: %d updated bit width: %d and "
4222 "sample rate: %d", __func__, backend_idx, bit_width, sample_rate);
4223
4224 // Force routing if the expected bitwdith or samplerate
4225 // is not same as current backend comfiguration
4226 if ((bit_width != my_data->current_backend_cfg[backend_idx].bit_width) ||
4227 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate) ||
4228 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
4229 backend_cfg->bit_width = bit_width;
4230 backend_cfg->sample_rate= sample_rate;
4231 backend_cfg->channels = channels;
4232 backend_change = true;
4233 ALOGI("%s:txbecf: afe: Codec backend needs to be updated. new bit width: %d "
4234 "new sample rate: %d new channel: %d",
4235 __func__, backend_cfg->bit_width,
4236 backend_cfg->sample_rate, backend_cfg->channels);
4237 }
4238
4239 return backend_change;
4240}
4241
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004242static void pick_playback_cfg_for_uc(struct audio_device *adev,
4243 struct audio_usecase *usecase,
4244 snd_device_t snd_device,
4245 unsigned int *bit_width,
4246 unsigned int *sample_rate,
4247 unsigned int *channels)
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004248{
4249 int i =0;
4250 struct listnode *node;
4251 list_for_each(node, &adev->usecase_list) {
4252 struct audio_usecase *uc;
4253 uc = node_to_item(node, struct audio_usecase, list);
4254 struct stream_out *out = (struct stream_out*) uc->stream.out;
4255 if (uc->type == PCM_PLAYBACK && out && usecase != uc) {
4256 unsigned int out_channels = audio_channel_count_from_out_mask(out->channel_mask);
4257 ALOGV("%s:napb: (%d) - (%s)id (%d) sr %d bw "
4258 "(%d) ch (%d) device %s", __func__, i++, use_case_table[uc->id],
4259 uc->id, out->sample_rate,
4260 pcm_format_to_bits(out->config.format), out_channels,
4261 platform_get_snd_device_name(uc->out_snd_device));
4262
4263 if (platform_check_backends_match(snd_device, uc->out_snd_device)) {
4264 if (*bit_width < pcm_format_to_bits(out->config.format))
4265 *bit_width = pcm_format_to_bits(out->config.format);
4266 if (*sample_rate < out->sample_rate)
4267 *sample_rate = out->sample_rate;
4268 if (out->sample_rate < OUTPUT_SAMPLING_RATE_44100)
4269 *sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4270 if (*channels < out_channels)
4271 *channels = out_channels;
4272 }
4273 }
4274 }
4275 return;
4276}
4277
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004278static void headset_is_config_supported(unsigned int *bit_width,
4279 unsigned int *sample_rate,
4280 unsigned int *channels) {
4281 switch (*bit_width) {
4282 case 16:
4283 case 24:
4284 break;
4285 default:
4286 *bit_width = 16;
4287 break;
4288 }
4289
4290 if (*sample_rate > 192000) {
4291 *sample_rate = 192000;
4292 }
4293
4294 if (*channels > 2) {
4295 *channels = 2;
4296 }
4297}
4298
David Linee3fe402017-03-13 10:00:42 -07004299static bool platform_check_playback_backend_cfg(struct audio_device* adev,
4300 struct audio_usecase* usecase,
4301 snd_device_t snd_device,
4302 struct audio_backend_cfg *backend_cfg)
4303{
4304 bool backend_change = false;
David Linee3fe402017-03-13 10:00:42 -07004305 unsigned int bit_width;
4306 unsigned int sample_rate;
4307 unsigned int channels;
David Linee3fe402017-03-13 10:00:42 -07004308 int backend_idx = DEFAULT_CODEC_BACKEND;
Haynes Mathew George65f6b432018-02-27 17:44:55 -08004309 unsigned long service_interval = 0; // 0 is invalid
David Linee3fe402017-03-13 10:00:42 -07004310 struct platform_data *my_data = (struct platform_data *)adev->platform;
David Linee3fe402017-03-13 10:00:42 -07004311
4312 if (snd_device == SND_DEVICE_OUT_BT_SCO ||
4313 snd_device == SND_DEVICE_OUT_BT_SCO_WB) {
4314 backend_change = false;
4315 return backend_change;
4316 }
4317
4318 backend_idx = platform_get_backend_index(snd_device);
4319 bit_width = backend_cfg->bit_width;
4320 sample_rate = backend_cfg->sample_rate;
4321 channels = backend_cfg->channels;
4322
4323 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
4324 ", backend_idx %d usecase = %d device (%s)", __func__, bit_width,
4325 sample_rate, channels, backend_idx, usecase->id,
4326 platform_get_snd_device_name(snd_device));
4327
4328 if (backend_idx == platform_get_voice_call_backend(adev)) {
4329 ALOGW("%s:becf: afe:Use default bw and sr for voice/voip calls ",
4330 __func__);
4331 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
4332 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4333 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
4334 } else {
4335 /*
4336 * The backend should be configured at highest bit width and/or
4337 * sample rate amongst all playback usecases.
4338 * If the selected sample rate and/or bit width differ with
4339 * current backend sample rate and/or bit width, then, we set the
4340 * backend re-configuration flag.
4341 *
4342 * Exception: 16 bit playbacks is allowed through 16 bit/48/44.1 khz backend only
4343 */
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004344 pick_playback_cfg_for_uc(adev, usecase, snd_device,
4345 &bit_width,
4346 &sample_rate,
4347 &channels);
David Linee3fe402017-03-13 10:00:42 -07004348 }
4349
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004350 switch (backend_idx) {
4351 case USB_AUDIO_RX_BACKEND:
4352 audio_extn_usb_is_config_supported(&bit_width,
4353 &sample_rate, &channels, true);
Haynes Mathew George65f6b432018-02-27 17:44:55 -08004354 if (platform_get_usb_service_interval(adev->platform, true,
4355 &service_interval) == 0) {
4356 /* overwrite with best altset for this service interval */
4357 int ret =
4358 audio_extn_usb_altset_for_service_interval(true /*playback*/,
4359 service_interval,
4360 &bit_width,
4361 &sample_rate,
4362 &channels);
4363 if (ret < 0) {
4364 ALOGE("Failed to find altset for service interval %lu, skip reconfig",
4365 service_interval);
4366 return false;
4367 }
4368 }
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004369 ALOGV("%s: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
4370 __func__, bit_width, sample_rate, channels);
4371 break;
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004372 case HEADPHONE_BACKEND:
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004373 headset_is_config_supported(&bit_width, &sample_rate, &channels);
4374 break;
4375 case DEFAULT_CODEC_BACKEND:
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004376 default:
4377 bit_width = platform_get_snd_device_bit_width(snd_device);
4378 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4379 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
4380 break;
David Linee3fe402017-03-13 10:00:42 -07004381 }
4382
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004383 ALOGV("%s:becf: afe: Codec selected backend: %d updated bit width: %d and"
4384 "sample rate: %d",
David Linee3fe402017-03-13 10:00:42 -07004385 __func__, backend_idx , bit_width, sample_rate);
4386
4387 // Force routing if the expected bitwdith or samplerate
4388 // is not same as current backend comfiguration
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004389 if (bit_width != my_data->current_backend_cfg[backend_idx].bit_width ||
4390 sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate ||
4391 channels != my_data->current_backend_cfg[backend_idx].channels) {
David Linee3fe402017-03-13 10:00:42 -07004392 backend_cfg->bit_width = bit_width;
4393 backend_cfg->sample_rate = sample_rate;
4394 backend_cfg->channels = channels;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004395 backend_cfg->passthrough_enabled = false;
David Linee3fe402017-03-13 10:00:42 -07004396 backend_change = true;
4397 ALOGV("%s:becf: afe: Codec backend needs to be updated. new bit width: %d"
4398 "new sample rate: %d new channels: %d",
4399 __func__, backend_cfg->bit_width, backend_cfg->sample_rate, backend_cfg->channels);
4400 }
4401
4402 return backend_change;
4403}
4404
4405bool platform_check_and_set_playback_backend_cfg(struct audio_device* adev,
4406 struct audio_usecase *usecase, snd_device_t snd_device)
4407{
4408 int backend_idx = DEFAULT_CODEC_BACKEND;
4409 int new_snd_devices[SND_DEVICE_OUT_END];
4410 int i, num_devices = 1;
4411 bool ret = false;
4412 struct platform_data *my_data = (struct platform_data *)adev->platform;
4413 struct audio_backend_cfg backend_cfg;
4414
4415 backend_idx = platform_get_backend_index(snd_device);
4416
4417 backend_cfg.bit_width = pcm_format_to_bits(usecase->stream.out->config.format);
4418 backend_cfg.sample_rate = usecase->stream.out->sample_rate;
4419 backend_cfg.format = usecase->stream.out->format;
4420 backend_cfg.channels = audio_channel_count_from_out_mask(usecase->stream.out->channel_mask);
4421 /*this is populated by check_codec_backend_cfg hence set default value to false*/
4422 backend_cfg.passthrough_enabled = false;
4423
4424 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
4425 ", backend_idx %d usecase = %d device (%s)", __func__, backend_cfg.bit_width,
4426 backend_cfg.sample_rate, backend_cfg.channels, backend_idx, usecase->id,
4427 platform_get_snd_device_name(snd_device));
4428
4429 if (platform_can_split_snd_device(snd_device, &num_devices, new_snd_devices) < 0)
4430 new_snd_devices[0] = snd_device;
4431
4432 for (i = 0; i < num_devices; i++) {
4433 ALOGV("%s: new_snd_devices[%d] is %d", __func__, i, new_snd_devices[i]);
4434 if ((platform_check_playback_backend_cfg(adev, usecase, new_snd_devices[i],
4435 &backend_cfg))) {
4436 platform_set_backend_cfg(adev, new_snd_devices[i],
4437 &backend_cfg);
4438 ret = true;
4439 }
4440 }
4441 return ret;
4442}
4443
4444bool platform_check_and_set_capture_backend_cfg(struct audio_device* adev,
4445 struct audio_usecase *usecase, snd_device_t snd_device)
4446{
4447 int backend_idx = platform_get_backend_index(snd_device);
4448 int ret = 0;
4449 struct audio_backend_cfg backend_cfg;
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004450 memset(&backend_cfg, 0, sizeof(struct audio_backend_cfg));
David Linee3fe402017-03-13 10:00:42 -07004451
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004452 if (usecase->type == PCM_CAPTURE) {
4453 backend_cfg.format = usecase->stream.in->format;
David Linee3fe402017-03-13 10:00:42 -07004454 backend_cfg.channels = audio_channel_count_from_in_mask(usecase->stream.in->channel_mask);
4455 } else {
4456 backend_cfg.bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
4457 backend_cfg.sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4458 backend_cfg.format = AUDIO_FORMAT_PCM_16_BIT;
4459 backend_cfg.channels = 1;
4460 }
4461
4462 ALOGV("%s:txbecf: afe: bitwidth %d, samplerate %d, channel %d"
4463 ", backend_idx %d usecase = %d device (%s)", __func__,
4464 backend_cfg.bit_width,
4465 backend_cfg.sample_rate,
4466 backend_cfg.channels,
4467 backend_idx, usecase->id,
4468 platform_get_snd_device_name(snd_device));
4469
4470 if (platform_check_capture_backend_cfg(adev, backend_idx, &backend_cfg)) {
4471 ret = platform_set_backend_cfg(adev, snd_device,
4472 &backend_cfg);
4473 if(!ret)
4474 return true;
4475 }
4476
4477 return false;
4478}
4479
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004480static int max_be_dai_names = 0;
4481static const struct be_dai_name_struct *be_dai_name_table;
4482
4483/*
4484 * Retrieves the be_dai_name_table from kernel to enable a mapping
4485 * between sound device hw interfaces and backend IDs. This allows HAL to
4486 * specify the backend a specific calibration is needed for.
4487 */
4488static int init_be_dai_name_table(struct audio_device *adev)
4489{
4490 const char *mixer_ctl_name = "Backend DAI Name Table";
4491 struct mixer_ctl *ctl;
4492 int i, j, ret, size;
4493 bool valid_hw_interface;
4494
4495 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
4496 if (!ctl) {
4497 ALOGE("%s: Could not get ctl for mixer name %s\n",
4498 __func__, mixer_ctl_name);
4499 ret = -EINVAL;
4500 goto done;
4501 }
4502
4503 mixer_ctl_update(ctl);
4504
4505 size = mixer_ctl_get_num_values(ctl);
4506 if (size <= 0){
4507 ALOGE("%s: Failed to get %s size %d\n",
4508 __func__, mixer_ctl_name, size);
4509 ret = -EFAULT;
4510 goto done;
4511 }
4512
vivek mehtaa68fea62017-06-08 19:04:02 -07004513 be_dai_name_table =
4514 (const struct be_dai_name_struct *)calloc(1, size);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004515 if (be_dai_name_table == NULL) {
4516 ALOGE("%s: Failed to allocate memory for %s\n",
4517 __func__, mixer_ctl_name);
4518 ret = -ENOMEM;
4519 goto freeMem;
4520 }
4521
4522 ret = mixer_ctl_get_array(ctl, (void *)be_dai_name_table, size);
4523 if (ret) {
4524 ALOGE("%s: Failed to get %s, ret %d\n",
4525 __func__, mixer_ctl_name, ret);
4526 ret = -EFAULT;
4527 goto freeMem;
4528 }
4529
4530 if (be_dai_name_table != NULL) {
4531 max_be_dai_names = size / sizeof(struct be_dai_name_struct);
4532 ALOGV("%s: Successfully got %s, number of be dais is %d\n",
4533 __func__, mixer_ctl_name, max_be_dai_names);
4534 ret = 0;
4535 } else {
4536 ALOGE("%s: Failed to get %s\n", __func__, mixer_ctl_name);
4537 ret = -EFAULT;
4538 goto freeMem;
4539 }
4540
4541 /*
4542 * Validate all sound devices have a valid backend set to catch
4543 * errors for uncommon sound devices
4544 */
4545 for (i = 0; i < SND_DEVICE_MAX; i++) {
4546 valid_hw_interface = false;
4547
4548 if (hw_interface_table[i] == NULL) {
4549 ALOGW("%s: sound device %s has no hw interface set\n",
4550 __func__, platform_get_snd_device_name(i));
4551 continue;
4552 }
4553
4554 for (j = 0; j < max_be_dai_names; j++) {
4555 if (strcmp(hw_interface_table[i], be_dai_name_table[j].be_name)
4556 == 0) {
4557 valid_hw_interface = true;
4558 break;
4559 }
4560 }
4561 if (!valid_hw_interface)
4562 ALOGD("%s: sound device %s does not have a valid hw interface set "
4563 "(disregard for combo devices) %s\n",
4564 __func__, platform_get_snd_device_name(i),
4565 hw_interface_table[i]);
4566 }
4567
4568 goto done;
4569
4570freeMem:
4571 if (be_dai_name_table) {
4572 free((void *)be_dai_name_table);
4573 be_dai_name_table = NULL;
4574 }
4575
4576done:
4577 return ret;
4578}
4579
4580int platform_get_snd_device_backend_index(snd_device_t device)
4581{
4582 int i, be_dai_id;
4583 const char * hw_interface_name = NULL;
4584
4585 ALOGV("%s: enter with device %d\n", __func__, device);
4586
vivek mehtaa68fea62017-06-08 19:04:02 -07004587 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004588 ALOGE("%s: Invalid snd_device = %d",
4589 __func__, device);
4590 be_dai_id = -EINVAL;
4591 goto done;
4592 }
4593
4594 /* Get string value of necessary backend for device */
4595 hw_interface_name = hw_interface_table[device];
4596 if (hw_interface_name == NULL) {
4597 ALOGE("%s: no hw_interface set for device %d\n", __func__, device);
4598 be_dai_id = -EINVAL;
4599 goto done;
4600 }
4601
4602 /* Check if be dai name table was retrieved successfully */
4603 if (be_dai_name_table == NULL) {
4604 ALOGE("%s: BE DAI Name Table is not present\n", __func__);
4605 be_dai_id = -EFAULT;
4606 goto done;
4607 }
4608
4609 /* Get backend ID for device specified */
4610 for (i = 0; i < max_be_dai_names; i++) {
4611 if (strcmp(hw_interface_name, be_dai_name_table[i].be_name) == 0) {
4612 be_dai_id = be_dai_name_table[i].be_id;
4613 goto done;
4614 }
4615 }
4616 ALOGE("%s: no interface matching name %s\n", __func__, hw_interface_name);
4617 be_dai_id = -EINVAL;
4618 goto done;
4619
4620done:
4621 return be_dai_id;
4622}
4623
4624void platform_check_and_update_copp_sample_rate(void* platform, snd_device_t snd_device,
4625 unsigned int stream_sr, int* sample_rate)
4626{
4627 struct platform_data* my_data = (struct platform_data *)platform;
4628 int backend_idx = platform_get_backend_index(snd_device);
4629 int device_sr = my_data->current_backend_cfg[backend_idx].sample_rate;
4630 /*
4631 *Check if device SR is multiple of 8K or 11.025 Khz
4632 *check if the stream SR is multiple of same base, if yes
4633 *then have copp SR equal to stream SR, this ensures that
4634 *post processing happens at stream SR, else have
4635 *copp SR equal to device SR.
4636 */
4637 if (!(((sample_rate_multiple(device_sr, SAMPLE_RATE_8000)) &&
4638 (sample_rate_multiple(stream_sr, SAMPLE_RATE_8000))) ||
4639 ((sample_rate_multiple(device_sr, SAMPLE_RATE_11025)) &&
4640 (sample_rate_multiple(stream_sr, SAMPLE_RATE_11025))))) {
4641 *sample_rate = device_sr;
4642 } else
4643 *sample_rate = stream_sr;
4644
4645 ALOGI("sn_device %d device sr %d stream sr %d copp sr %d", snd_device, device_sr, stream_sr
4646 , *sample_rate);
4647
4648}
4649
4650// called from info parser
vivek mehtaa68fea62017-06-08 19:04:02 -07004651void platform_add_app_type(const char *uc_type,
4652 const char *mode,
4653 int bw,
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004654 int app_type, int max_rate) {
4655 struct app_type_entry *ap =
4656 (struct app_type_entry *)calloc(1, sizeof(struct app_type_entry));
4657
4658 if (!ap) {
4659 ALOGE("%s failed to allocate mem for app type", __func__);
4660 return;
4661 }
4662
4663 ap->uc_type = -1;
4664 for (int i=0; i<USECASE_TYPE_MAX; i++) {
4665 if (!strcmp(uc_type, usecase_type_index[i].name)) {
4666 ap->uc_type = usecase_type_index[i].index;
4667 break;
4668 }
4669 }
4670
4671 if (ap->uc_type == -1) {
4672 free(ap);
4673 return;
4674 }
4675
vivek mehtaa68fea62017-06-08 19:04:02 -07004676 ALOGI("%s uc %s mode %s bw %d app_type %d max_rate %d",
4677 __func__, uc_type, mode, bw, app_type, max_rate);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004678 ap->bit_width = bw;
4679 ap->app_type = app_type;
4680 ap->max_rate = max_rate;
vivek mehtaa68fea62017-06-08 19:04:02 -07004681 ap->mode = strdup(mode);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004682 list_add_tail(&app_type_entry_list, &ap->node);
4683}
4684
4685
4686int platform_get_default_app_type_v2(void *platform __unused,
4687 usecase_type_t type,
4688 int *app_type )
4689{
4690 if (type == PCM_PLAYBACK)
4691 *app_type = DEFAULT_APP_TYPE_RX_PATH;
4692 else
4693 *app_type = DEFAULT_APP_TYPE_TX_PATH;
4694 return 0;
4695}
4696
vivek mehtaa68fea62017-06-08 19:04:02 -07004697int platform_get_app_type_v2(void *platform,
4698 usecase_type_t uc_type,
4699 const char *mode,
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004700 int bw, int sr __unused,
4701 int *app_type)
4702{
4703 struct listnode *node;
4704 struct app_type_entry *entry;
4705 *app_type = -1;
vivek mehtaa68fea62017-06-08 19:04:02 -07004706
4707 ALOGV("%s find match for uc %d mode %s bw %d rate %d",
4708 __func__, uc_type, mode, bw, sr);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004709 list_for_each(node, &app_type_entry_list) {
4710 entry = node_to_item(node, struct app_type_entry, node);
vivek mehtaa68fea62017-06-08 19:04:02 -07004711 ALOGV("%s uc %d mode %s bw %d app_type %d max_rate %d",
4712 __func__, entry->uc_type, entry->mode, entry->bit_width,
4713 entry->app_type, entry->max_rate);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004714 if (entry->bit_width == bw &&
vivek mehtaa68fea62017-06-08 19:04:02 -07004715 entry->uc_type == uc_type &&
4716 sr <= entry->max_rate &&
4717 entry->mode && !strcmp(mode, entry->mode)) {
4718 ALOGV("%s found match %d", __func__, entry->app_type);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004719 *app_type = entry->app_type;
4720 break;
4721 }
4722 }
4723
4724 if (*app_type == -1) {
vivek mehtaa68fea62017-06-08 19:04:02 -07004725 ALOGV("%s no match found, return default", __func__);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004726 return platform_get_default_app_type_v2(platform, uc_type, app_type);
4727 }
4728 return 0;
4729}
vivek mehta90933872017-06-15 18:04:39 -07004730
4731int platform_set_sidetone(struct audio_device *adev,
4732 snd_device_t out_snd_device,
4733 bool enable, char *str)
4734{
4735 int ret;
4736 if (out_snd_device == SND_DEVICE_OUT_USB_HEADSET ||
4737 out_snd_device == SND_DEVICE_OUT_VOICE_USB_HEADSET) {
4738 ret = audio_extn_usb_enable_sidetone(out_snd_device, enable);
4739 if (ret)
4740 ALOGI("%s: usb device %d does not support device sidetone\n",
4741 __func__, out_snd_device);
4742 } else {
4743 ALOGV("%s: sidetone out device(%d) mixer cmd = %s\n",
4744 __func__, out_snd_device, str);
4745 if (enable)
4746 audio_route_apply_and_update_path(adev->audio_route, str);
4747 else
4748 audio_route_reset_and_update_path(adev->audio_route, str);
4749 }
4750 return 0;
4751}
Haynes Mathew George96483a22017-03-28 14:52:47 -07004752
4753int platform_get_mmap_data_fd(void *platform __unused, int fe_dev __unused, int dir __unused,
4754 int *fd __unused, uint32_t *size __unused)
4755{
Thierry Strudel07f96d12018-09-20 13:31:34 -07004756#if defined (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845) || (PLATFORM_SDM710) || (PLATFORM_SM8150)
Haynes Mathew George96483a22017-03-28 14:52:47 -07004757 struct platform_data *my_data = (struct platform_data *)platform;
4758 struct audio_device *adev = my_data->adev;
4759 int hw_fd = -1;
4760 char dev_name[128];
4761 struct snd_pcm_mmap_fd mmap_fd;
4762 memset(&mmap_fd, 0, sizeof(mmap_fd));
4763 mmap_fd.dir = dir;
4764 snprintf(dev_name, sizeof(dev_name), "/dev/snd/hwC%uD%u",
4765 adev->snd_card, HWDEP_FE_BASE+fe_dev);
4766 hw_fd = open(dev_name, O_RDONLY);
4767 if (hw_fd < 0) {
4768 ALOGE("fe hw dep node open %d/%d failed", adev->snd_card, fe_dev);
4769 return -1;
4770 }
4771 if (ioctl(hw_fd, SNDRV_PCM_IOCTL_MMAP_DATA_FD, &mmap_fd) < 0) {
4772 ALOGE("fe hw dep node ioctl failed");
4773 close(hw_fd);
4774 return -1;
4775 }
4776 *fd = mmap_fd.fd;
4777 *size = mmap_fd.size;
4778 close(hw_fd); // mmap_fd should still be valid
4779 return 0;
4780#else
4781 return -1;
4782#endif
4783}
Mikhail Naganov4ee6e3e2018-03-21 16:28:35 +00004784
4785bool platform_sound_trigger_usecase_needs_event(audio_usecase_t uc_id)
4786{
4787 bool needs_event = false;
4788
4789 switch (uc_id) {
4790 /* concurrent capture usecases which needs event */
4791 case USECASE_AUDIO_RECORD:
4792 case USECASE_AUDIO_RECORD_LOW_LATENCY:
4793 case USECASE_AUDIO_RECORD_MMAP:
4794 case USECASE_AUDIO_RECORD_HIFI:
4795 case USECASE_AUDIO_RECORD_VOIP:
4796 case USECASE_VOICEMMODE1_CALL:
4797 case USECASE_VOICEMMODE2_CALL:
4798 /* concurrent playback usecases that needs event */
4799 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
4800 case USECASE_AUDIO_PLAYBACK_OFFLOAD:
4801 needs_event = true;
4802 break;
4803 default:
4804 ALOGV("%s:usecase_id[%d] no need to raise event.", __func__, uc_id);
4805 }
4806 return needs_event;
4807}
4808
4809bool platform_snd_device_has_speaker(snd_device_t dev) {
4810 int num_devs = 2;
4811 snd_device_t split_devs[2] = {SND_DEVICE_NONE, SND_DEVICE_NONE};
4812 if (platform_can_split_snd_device(dev, &num_devs, split_devs) == 0) {
4813 return platform_snd_device_has_speaker(split_devs[0]) ||
4814 platform_snd_device_has_speaker(split_devs[1]);
4815 }
4816
4817 switch (dev) {
4818 case SND_DEVICE_OUT_SPEAKER:
4819 case SND_DEVICE_OUT_SPEAKER_SAFE:
4820 case SND_DEVICE_OUT_SPEAKER_REVERSE:
4821 case SND_DEVICE_OUT_SPEAKER_PROTECTED:
4822 case SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED:
4823 case SND_DEVICE_OUT_VOICE_SPEAKER_HFP:
4824 return true;
4825 default:
4826 break;
4827 }
4828 return false;
4829}
jiabin8962a4d2018-03-19 18:21:24 -07004830
4831bool platform_set_microphone_characteristic(void *platform,
4832 struct audio_microphone_characteristic_t mic) {
4833 struct platform_data *my_data = (struct platform_data *)platform;
4834 if (my_data->declared_mic_count >= AUDIO_MICROPHONE_MAX_COUNT) {
4835 ALOGE("mic number is more than maximum number");
4836 return false;
4837 }
4838 for (size_t ch = 0; ch < AUDIO_CHANNEL_COUNT_MAX; ch++) {
4839 mic.channel_mapping[ch] = AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED;
4840 }
4841 my_data->microphones[my_data->declared_mic_count++] = mic;
4842 return true;
4843}
4844
4845int platform_get_microphones(void *platform,
4846 struct audio_microphone_characteristic_t *mic_array,
4847 size_t *mic_count) {
4848 struct platform_data *my_data = (struct platform_data *)platform;
4849 if (mic_count == NULL) {
4850 return -EINVAL;
4851 }
4852 if (mic_array == NULL) {
4853 return -EINVAL;
4854 }
4855
4856 if (*mic_count == 0) {
4857 *mic_count = my_data->declared_mic_count;
4858 return 0;
4859 }
4860
4861 size_t max_mic_count = *mic_count;
4862 size_t actual_mic_count = 0;
4863 for (size_t i = 0; i < max_mic_count && i < my_data->declared_mic_count; i++) {
4864 mic_array[i] = my_data->microphones[i];
4865 actual_mic_count++;
4866 }
4867 *mic_count = actual_mic_count;
4868 return 0;
4869}
4870
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004871bool platform_set_microphone_map(void *platform, snd_device_t in_snd_device,
4872 const struct mic_info *info) {
4873 struct platform_data *my_data = (struct platform_data *)platform;
4874 if (in_snd_device < SND_DEVICE_IN_BEGIN || in_snd_device >= SND_DEVICE_IN_END) {
4875 ALOGE("%s: Sound device not valid", __func__);
4876 return false;
4877 }
4878 size_t m_count = my_data->mic_map[in_snd_device].mic_count++;
4879 if (m_count >= AUDIO_MICROPHONE_MAX_COUNT) {
4880 ALOGE("%s: Microphone count is greater than max allowed value", __func__);
4881 my_data->mic_map[in_snd_device].mic_count--;
4882 return false;
4883 }
4884 my_data->mic_map[in_snd_device].microphones[m_count] = *info;
4885 return true;
4886}
4887
4888int platform_get_active_microphones(void *platform, unsigned int channels,
4889 audio_usecase_t uc_id,
jiabin8962a4d2018-03-19 18:21:24 -07004890 struct audio_microphone_characteristic_t *mic_array,
4891 size_t *mic_count) {
4892 struct platform_data *my_data = (struct platform_data *)platform;
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004893 struct audio_usecase *usecase = get_usecase_from_list(my_data->adev, uc_id);
4894 if (mic_count == NULL || mic_array == NULL || usecase == NULL) {
jiabin8962a4d2018-03-19 18:21:24 -07004895 return -EINVAL;
4896 }
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004897 size_t max_mic_count = my_data->declared_mic_count;
jiabin8962a4d2018-03-19 18:21:24 -07004898 size_t actual_mic_count = 0;
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004899
4900 snd_device_t active_input_snd_device =
Eric Laurentd1b7a9b2018-11-15 12:24:31 -08004901 platform_get_input_snd_device(platform, usecase->stream.in, AUDIO_DEVICE_NONE);
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004902 if (active_input_snd_device == SND_DEVICE_NONE) {
4903 ALOGI("%s: No active microphones found", __func__);
4904 goto end;
4905 }
4906
4907 size_t active_mic_count = my_data->mic_map[active_input_snd_device].mic_count;
4908 struct mic_info *m_info = my_data->mic_map[active_input_snd_device].microphones;
4909
4910 for (size_t i = 0; i < active_mic_count; i++) {
4911 unsigned int channels_for_active_mic = channels;
4912 if (channels_for_active_mic > m_info[i].channel_count) {
4913 channels_for_active_mic = m_info[i].channel_count;
4914 }
4915 for (size_t j = 0; j < max_mic_count; j++) {
4916 if (strcmp(my_data->microphones[j].device_id,
4917 m_info[i].device_id) == 0) {
4918 mic_array[actual_mic_count] = my_data->microphones[j];
4919 for (size_t ch = 0; ch < channels_for_active_mic; ch++) {
4920 mic_array[actual_mic_count].channel_mapping[ch] =
4921 m_info[i].channel_mapping[ch];
4922 }
4923 actual_mic_count++;
4924 break;
jiabin8962a4d2018-03-19 18:21:24 -07004925 }
jiabin8962a4d2018-03-19 18:21:24 -07004926 }
4927 }
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004928end:
jiabin8962a4d2018-03-19 18:21:24 -07004929 *mic_count = actual_mic_count;
4930 return 0;
4931}
Haynes Mathew George65f6b432018-02-27 17:44:55 -08004932
4933int platform_set_usb_service_interval(void *platform,
4934 bool playback,
4935 unsigned long service_interval,
4936 bool *reconfig)
4937{
4938#if defined (USB_SERVICE_INTERVAL_ENABLED)
4939 struct platform_data *_platform = (struct platform_data *)platform;
4940 *reconfig = false;
4941 if (!playback) {
4942 ALOGE("%s not valid for capture", __func__);
4943 return -1;
4944 }
4945 const char *ctl_name = "USB_AUDIO_RX service_interval";
4946 struct mixer_ctl *ctl = mixer_get_ctl_by_name(_platform->adev->mixer,
4947 ctl_name);
4948 if (!ctl) {
4949 ALOGV("%s: could not get mixer %s", __func__, ctl_name);
4950 return -1;
4951 }
4952 if (mixer_ctl_get_value(ctl, 0) != (int)service_interval) {
4953 mixer_ctl_set_value(ctl, 0, service_interval);
4954 *reconfig = true;
4955 }
4956 return 0;
4957#else
4958 *reconfig = false;
4959 (void)platform;
4960 (void)playback;
4961 (void)service_interval;
4962 return -1;
4963#endif
4964}
4965
4966int platform_get_usb_service_interval(void *platform,
4967 bool playback,
4968 unsigned long *service_interval)
4969{
4970#if defined (USB_SERVICE_INTERVAL_ENABLED)
4971 struct platform_data *_platform = (struct platform_data *)platform;
4972 if (!playback) {
4973 ALOGE("%s not valid for capture", __func__);
4974 return -1;
4975 }
4976 const char *ctl_name = "USB_AUDIO_RX service_interval";
4977 struct mixer_ctl *ctl = mixer_get_ctl_by_name(_platform->adev->mixer,
4978 ctl_name);
4979 if (!ctl) {
4980 ALOGV("%s: could not get mixer %s", __func__, ctl_name);
4981 return -1;
4982 }
4983 *service_interval = mixer_ctl_get_value(ctl, 0);
4984 return 0;
4985#else
4986 (void)platform;
4987 (void)playback;
4988 (void)service_interval;
4989 return -1;
4990#endif
4991}
Ashish Jain1c849702018-05-11 20:11:55 +05304992
4993int platform_set_acdb_metainfo_key(void *platform __unused,
4994 char *name __unused,
4995 int key __unused)
4996{
4997 return -ENOSYS;
4998}