blob: 21f7cf5722903b200d4da1e11a7452c6c593d83a [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
Carter Hsu017c63a2018-10-15 15:01:42 -0700104struct external_specific_device {
105 struct listnode list;
106 char *usbid;
107 int acdb_id;
108};
109
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800110#define BE_DAI_NAME_MAX_LENGTH 24
111struct be_dai_name_struct {
112 unsigned int be_id;
113 char be_name[BE_DAI_NAME_MAX_LENGTH];
114};
115
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -0700116struct snd_device_to_mic_map {
117 struct mic_info microphones[AUDIO_MICROPHONE_MAX_COUNT];
118 size_t mic_count;
119};
120
keunhui.park2f7306a2015-07-16 16:48:06 +0900121static struct listnode operator_info_list;
122static struct listnode *operator_specific_device_table[SND_DEVICE_MAX];
Carter Hsu017c63a2018-10-15 15:01:42 -0700123static struct listnode *external_specific_device_table[SND_DEVICE_MAX];
keunhui.park2f7306a2015-07-16 16:48:06 +0900124
jasmine chac89321b2018-04-10 21:37:01 +0800125#define AUDIO_PARAMETER_KEY_AUD_CALDATA "cal_data"
126
127typedef struct acdb_audio_cal_cfg {
128 uint32_t persist;
129 uint32_t snd_dev_id;
130 audio_devices_t dev_id;
131 int32_t acdb_dev_id;
132 uint32_t app_type;
133 uint32_t topo_id;
134 uint32_t sampling_rate;
135 uint32_t cal_type;
136 uint32_t module_id;
justinwenge880e0c2018-11-22 13:49:38 +0800137#ifdef PLATFORM_SM8150
138 uint16_t instance_id;
139 uint16_t reserved;
140#endif
jasmine chac89321b2018-04-10 21:37:01 +0800141 uint32_t param_id;
142} acdb_audio_cal_cfg_t;
143
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700144/* Audio calibration related functions */
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800145typedef void (*acdb_send_audio_cal_v3_t)(int, int, int, int, int);
Eric Laurentb23d5282013-05-14 15:27:20 -0700146
Eric Laurentb23d5282013-05-14 15:27:20 -0700147struct platform_data {
148 struct audio_device *adev;
149 bool fluence_in_spkr_mode;
150 bool fluence_in_voice_call;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700151 bool fluence_in_voice_comm;
Eric Laurentb23d5282013-05-14 15:27:20 -0700152 bool fluence_in_voice_rec;
Prashant Malanic92c5962015-08-11 15:10:18 -0700153 /* 0 = no fluence, 1 = fluence, 2 = fluence pro */
154 int fluence_type;
155 int source_mic_type;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -0700156 bool speaker_lr_swap;
157
Eric Laurentb23d5282013-05-14 15:27:20 -0700158 void *acdb_handle;
Thierry Strudel07f96d12018-09-20 13:31:34 -0700159#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845) || (PLATFORM_SDM710) || (PLATFORM_SM8150)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -0700160 acdb_init_v2_cvd_t acdb_init;
161#elif defined (PLATFORM_MSM8084)
162 acdb_init_v2_t acdb_init;
163#else
164 acdb_init_t acdb_init;
165#endif
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700166 acdb_deallocate_t acdb_deallocate;
167 acdb_send_audio_cal_t acdb_send_audio_cal;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800168 acdb_send_audio_cal_v3_t acdb_send_audio_cal_v3;
jasmine chac89321b2018-04-10 21:37:01 +0800169 acdb_set_audio_cal_t acdb_set_audio_cal;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700170 acdb_send_voice_cal_t acdb_send_voice_cal;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700171 acdb_reload_vocvoltable_t acdb_reload_vocvoltable;
vivek mehta1a9b7c02015-06-25 11:49:38 -0700172 acdb_send_gain_dep_cal_t acdb_send_gain_dep_cal;
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -0700173 acdb_send_custom_top_t acdb_send_custom_top;
174 bool acdb_initialized;
175
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700176 struct csd_data *csd;
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800177 char ec_ref_mixer_path[64];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700178
David Linee3fe402017-03-13 10:00:42 -0700179 codec_backend_cfg_t current_backend_cfg[MAX_CODEC_BACKENDS];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700180 char *snd_card_name;
keunhui.parkc5aaa0e2015-07-13 10:57:37 +0900181 int max_vol_index;
Prashant Malanic92c5962015-08-11 15:10:18 -0700182 int max_mic_count;
vivek mehtade4849c2016-03-03 17:23:38 -0800183
184 void *hw_info;
jiabin8962a4d2018-03-19 18:21:24 -0700185
186 uint32_t declared_mic_count;
187 struct audio_microphone_characteristic_t microphones[AUDIO_MICROPHONE_MAX_COUNT];
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -0700188 struct snd_device_to_mic_map mic_map[SND_DEVICE_MAX];
Eric Laurentb23d5282013-05-14 15:27:20 -0700189};
190
Haynes Mathew George98c95622014-06-20 19:14:25 -0700191static int pcm_device_table[AUDIO_USECASE_MAX][2] = {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700192 [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = {DEEP_BUFFER_PCM_DEVICE,
193 DEEP_BUFFER_PCM_DEVICE},
Vignesh Kulothungan019d19b2019-01-23 11:09:18 -0800194 [USECASE_AUDIO_PLAYBACK_WITH_HAPTICS] = {AUDIO_HAPTICS_PCM_DEVICE,
195 AUDIO_HAPTICS_PCM_DEVICE},
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700196 [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
197 LOWLATENCY_PCM_DEVICE},
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800198 [USECASE_AUDIO_PLAYBACK_HIFI] = {MULTIMEDIA2_PCM_DEVICE,
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700199 MULTIMEDIA2_PCM_DEVICE},
200 [USECASE_AUDIO_PLAYBACK_OFFLOAD] = {PLAYBACK_OFFLOAD_DEVICE,
201 PLAYBACK_OFFLOAD_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700202 [USECASE_AUDIO_PLAYBACK_TTS] = {MULTIMEDIA2_PCM_DEVICE,
203 MULTIMEDIA2_PCM_DEVICE},
204 [USECASE_AUDIO_PLAYBACK_ULL] = {MULTIMEDIA3_PCM_DEVICE,
205 MULTIMEDIA3_PCM_DEVICE},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800206 [USECASE_AUDIO_PLAYBACK_MMAP] = {MMAP_PLAYBACK_PCM_DEVICE,
207 MMAP_PLAYBACK_PCM_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700208
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700209 [USECASE_AUDIO_RECORD] = {AUDIO_RECORD_PCM_DEVICE,
210 AUDIO_RECORD_PCM_DEVICE},
211 [USECASE_AUDIO_RECORD_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
212 LOWLATENCY_PCM_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700213
Eric Laurent0e46adf2016-12-16 12:49:24 -0800214 [USECASE_AUDIO_RECORD_MMAP] = {MMAP_RECORD_PCM_DEVICE,
215 MMAP_RECORD_PCM_DEVICE},
Haynes Mathew George569b7482017-05-08 14:44:27 -0700216 [USECASE_AUDIO_RECORD_HIFI] = {MULTIMEDIA2_PCM_DEVICE,
217 MULTIMEDIA2_PCM_DEVICE},
218
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700219 [USECASE_VOICE_CALL] = {VOICE_CALL_PCM_DEVICE,
220 VOICE_CALL_PCM_DEVICE},
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700221 [USECASE_VOICE2_CALL] = {VOICE2_CALL_PCM_DEVICE, VOICE2_CALL_PCM_DEVICE},
222 [USECASE_VOLTE_CALL] = {VOLTE_CALL_PCM_DEVICE, VOLTE_CALL_PCM_DEVICE},
223 [USECASE_QCHAT_CALL] = {QCHAT_CALL_PCM_DEVICE, QCHAT_CALL_PCM_DEVICE},
224 [USECASE_VOWLAN_CALL] = {VOWLAN_CALL_PCM_DEVICE, VOWLAN_CALL_PCM_DEVICE},
vivek mehtaa51fd402016-02-04 19:49:33 -0800225 [USECASE_VOICEMMODE1_CALL] = {VOICEMMODE1_CALL_PCM_DEVICE,
226 VOICEMMODE1_CALL_PCM_DEVICE},
227 [USECASE_VOICEMMODE2_CALL] = {VOICEMMODE2_CALL_PCM_DEVICE,
228 VOICEMMODE2_CALL_PCM_DEVICE},
229
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700230 [USECASE_INCALL_REC_UPLINK] = {AUDIO_RECORD_PCM_DEVICE,
231 AUDIO_RECORD_PCM_DEVICE},
232 [USECASE_INCALL_REC_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
233 AUDIO_RECORD_PCM_DEVICE},
234 [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
235 AUDIO_RECORD_PCM_DEVICE},
Ravi Kumar Alamanda8e6e98f2013-11-05 15:57:39 -0800236 [USECASE_AUDIO_HFP_SCO] = {HFP_PCM_RX, HFP_SCO_RX},
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700237
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700238 [USECASE_AUDIO_SPKR_CALIB_RX] = {SPKR_PROT_CALIB_RX_PCM_DEVICE, -1},
239 [USECASE_AUDIO_SPKR_CALIB_TX] = {-1, SPKR_PROT_CALIB_TX_PCM_DEVICE},
240
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700241 [USECASE_AUDIO_PLAYBACK_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
242 AFE_PROXY_RECORD_PCM_DEVICE},
243 [USECASE_AUDIO_RECORD_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
244 AFE_PROXY_RECORD_PCM_DEVICE},
zhaoyang yin4211fad2015-06-04 21:13:25 +0800245 [USECASE_AUDIO_DSM_FEEDBACK] = {QUAT_MI2S_PCM_DEVICE, QUAT_MI2S_PCM_DEVICE},
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700246
vivek mehtaa68fea62017-06-08 19:04:02 -0700247 [USECASE_AUDIO_PLAYBACK_VOIP] = {AUDIO_PLAYBACK_VOIP_PCM_DEVICE,
248 AUDIO_PLAYBACK_VOIP_PCM_DEVICE},
249 [USECASE_AUDIO_RECORD_VOIP] = {AUDIO_RECORD_VOIP_PCM_DEVICE,
250 AUDIO_RECORD_VOIP_PCM_DEVICE},
Nadav Bar3d72cfc2018-01-07 12:19:24 +0200251
252 [USECASE_INCALL_MUSIC_UPLINK] = {INCALL_MUSIC_UPLINK_PCM_DEVICE,
253 INCALL_MUSIC_UPLINK_PCM_DEVICE},
Eric Laurentb23d5282013-05-14 15:27:20 -0700254};
255
256/* Array to store sound devices */
257static const char * const device_table[SND_DEVICE_MAX] = {
258 [SND_DEVICE_NONE] = "none",
259 /* Playback sound devices */
260 [SND_DEVICE_OUT_HANDSET] = "handset",
261 [SND_DEVICE_OUT_SPEAKER] = "speaker",
262 [SND_DEVICE_OUT_SPEAKER_REVERSE] = "speaker-reverse",
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700263 [SND_DEVICE_OUT_SPEAKER_SAFE] = "speaker-safe",
Eric Laurentb23d5282013-05-14 15:27:20 -0700264 [SND_DEVICE_OUT_HEADPHONES] = "headphones",
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500265 [SND_DEVICE_OUT_LINE] = "line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700266 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones",
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700267 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = "speaker-safe-and-headphones",
Eric Laurent744996b2014-10-01 11:40:40 -0500268 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = "speaker-and-line",
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700269 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = "speaker-safe-and-line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700270 [SND_DEVICE_OUT_VOICE_HANDSET] = "voice-handset",
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500271 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = "voice-hac-handset",
Eric Laurentb23d5282013-05-14 15:27:20 -0700272 [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker",
273 [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones",
yixuanjiang9536e672018-09-06 18:43:36 +0800274 [SND_DEVICE_OUT_VOICE_HEADSET] = "voice-headphones",
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500275 [SND_DEVICE_OUT_VOICE_LINE] = "voice-line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700276 [SND_DEVICE_OUT_HDMI] = "hdmi",
277 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi",
278 [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700279 [SND_DEVICE_OUT_BT_SCO_WB] = "bt-sco-headset-wb",
Aniket Kumar Lata26483012018-01-31 20:21:42 -0800280 [SND_DEVICE_OUT_BT_A2DP] = "bt-a2dp",
281 [SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] = "speaker-and-bt-a2dp",
Aniket Kumar Lata9723a962018-05-16 17:41:55 -0700282 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP] = "speaker-safe-and-bt-a2dp",
Eric Laurentb23d5282013-05-14 15:27:20 -0700283 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = "voice-handset-tmus",
284 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones",
285 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones",
286 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset",
vivek mehtaa6b79742017-03-09 15:40:43 -0800287 [SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = "voice-tty-full-usb",
288 [SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = "voice-tty-vco-usb",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700289 [SND_DEVICE_OUT_VOICE_TX] = "voice-tx",
juyuchen66c4ecf2018-08-06 15:39:34 +0800290 [SND_DEVICE_OUT_VOICE_MUSIC_TX] = "voice-music-tx",
David Linee3fe402017-03-13 10:00:42 -0700291 [SND_DEVICE_OUT_USB_HEADSET] = "usb-headset",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700292 [SND_DEVICE_OUT_VOICE_USB_HEADSET] = "usb-headset",
David Linee3fe402017-03-13 10:00:42 -0700293 [SND_DEVICE_OUT_USB_HEADPHONES] = "usb-headphones",
jasmine cha270b7762018-03-30 15:41:33 +0800294 [SND_DEVICE_OUT_USB_HEADSET_SPEC] = "usb-headset",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700295 [SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = "usb-headphones",
David Linee3fe402017-03-13 10:00:42 -0700296 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = "speaker-and-usb-headphones",
Haynes Mathew George9090bfb2017-05-31 11:44:50 -0700297 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] = "speaker-safe-and-usb-headphones",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700298 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = "speaker-protected",
299 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = "voice-speaker-protected",
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -0700300 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = "voice-speaker-hfp",
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -0800301 [SND_DEVICE_OUT_SPEAKER_AND_BT_SCO] = "speaker-and-bt-sco",
juyuchen5351ea62018-05-16 10:54:37 +0800302 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO] = "speaker-safe-and-bt-sco",
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -0800303 [SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB] = "speaker-and-bt-sco-wb",
juyuchen5351ea62018-05-16 10:54:37 +0800304 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB] = "speaker-safe-and-bt-sco-wb",
juyuchend194b432018-11-16 14:15:16 +0800305 [SND_DEVICE_OUT_VOICE_HEARING_AID] = "hearing-aid",
Eric Laurentb23d5282013-05-14 15:27:20 -0700306
307 /* Capture sound devices */
308 [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700309 [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700310 [SND_DEVICE_IN_HANDSET_MIC_NS] = "handset-mic",
311 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = "handset-mic",
312 [SND_DEVICE_IN_HANDSET_DMIC] = "dmic-endfire",
313 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = "dmic-endfire",
314 [SND_DEVICE_IN_HANDSET_DMIC_NS] = "dmic-endfire",
315 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = "dmic-endfire",
316 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = "dmic-endfire",
317
318 [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
319 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "speaker-mic",
320 [SND_DEVICE_IN_SPEAKER_MIC_NS] = "speaker-mic",
321 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = "speaker-mic",
322 [SND_DEVICE_IN_SPEAKER_DMIC] = "speaker-dmic-endfire",
323 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = "speaker-dmic-endfire",
324 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = "speaker-dmic-endfire",
325 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = "speaker-dmic-endfire",
326 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = "speaker-dmic-endfire",
327
328 [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
Eric Laurentcefbbac2014-09-04 13:54:10 -0500329 [SND_DEVICE_IN_HEADSET_MIC_AEC] = "headset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700330
Eric Laurentb23d5282013-05-14 15:27:20 -0700331 [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic",
332 [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700333 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = "bt-sco-mic",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700334 [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700335 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = "bt-sco-mic-wb",
Eric Laurent5f4ca952018-10-19 17:33:43 -0700336 [SND_DEVICE_IN_CAMCORDER_LANDSCAPE] = "camcorder-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700337
338 [SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef",
339 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = "voice-dmic-ef-tmus",
340 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
341 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = "voice-speaker-dmic-ef",
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -0700342 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = "voice-speaker-mic-hfp",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700343 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700344 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
345 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
346 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
vivek mehtaa6b79742017-03-09 15:40:43 -0800347 [SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = "voice-tty-full-usb-mic",
348 [SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = "voice-tty-hco-usb-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700349
Eric Laurentb23d5282013-05-14 15:27:20 -0700350 [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700351 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = "voice-rec-mic",
vivek mehta733c1df2016-04-04 15:09:24 -0700352 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = "voice-rec-mic",
vivek mehtaf3440682016-05-11 14:24:37 -0700353 [SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700354 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = "voice-rec-dmic-ef",
355 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence",
David Linee3fe402017-03-13 10:00:42 -0700356 [SND_DEVICE_IN_USB_HEADSET_MIC] = "usb-headset-mic",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700357 [SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] ="usb-headset-mic",
358 [SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = "usb-headset-mic",
359 [SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = "usb-headset-mic",
360 [SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = "usb-headset-mic",
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700361 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = "headset-mic",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700362
Ricardo Garcia9034bc42016-04-04 07:11:46 -0700363 [SND_DEVICE_IN_UNPROCESSED_MIC] = "unprocessed-mic",
vivek mehta0125e782016-06-16 18:03:11 -0700364 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = "unprocessed-stereo-mic",
365 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = "unprocessed-three-mic",
366 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = "unprocessed-quad-mic",
367 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = "unprocessed-headset-mic",
rago90fb9612015-12-02 11:37:53 -0800368
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700369 [SND_DEVICE_IN_VOICE_RX] = "voice-rx",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700370
Prashant Malanic92c5962015-08-11 15:10:18 -0700371 [SND_DEVICE_IN_THREE_MIC] = "three-mic",
372 [SND_DEVICE_IN_QUAD_MIC] = "quad-mic",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700373 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = "vi-feedback",
Prashant Malanic92c5962015-08-11 15:10:18 -0700374 [SND_DEVICE_IN_HANDSET_TMIC] = "three-mic",
375 [SND_DEVICE_IN_HANDSET_QMIC] = "quad-mic",
vivek mehta733c1df2016-04-04 15:09:24 -0700376 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = "three-mic",
377 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = "quad-mic",
Eric Laurent5f4ca952018-10-19 17:33:43 -0700378 [SND_DEVICE_IN_CAMCORDER_INVERT_LANDSCAPE] = "camcorder-mic",
379 [SND_DEVICE_IN_CAMCORDER_PORTRAIT] = "camcorder-mic",
380 [SND_DEVICE_IN_CAMCORDER_SELFIE_LANDSCAPE] = "camcorder-mic",
381 [SND_DEVICE_IN_CAMCORDER_SELFIE_INVERT_LANDSCAPE] = "camcorder-mic",
382 [SND_DEVICE_IN_CAMCORDER_SELFIE_PORTRAIT] = "camcorder-mic",
Vignesh Kulothungan64698822018-01-23 11:25:18 -0800383 [SND_DEVICE_IN_SPEAKER_QMIC_NS] = "quad-mic",
384 [SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS] = "quad-mic",
juyuchend194b432018-11-16 14:15:16 +0800385 [SND_DEVICE_IN_VOICE_HEARING_AID] = "hearing-aid-mic",
Vignesh Kulothungan64698822018-01-23 11:25:18 -0800386};
387
388static struct audio_effect_config \
389 effect_config_table[GET_IN_DEVICE_INDEX(SND_DEVICE_MAX)][EFFECT_COUNT] = {
390 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS)][EFFECT_AEC] = \
391 {TX_VOICE_FLUENCE_PROV2, 0x0, 0x10EAF, 0x01},
392 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS)][EFFECT_NS] = \
393 {TX_VOICE_FLUENCE_PROV2, 0x0, 0x10EAF, 0x02},
394 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)][EFFECT_AEC] = \
395 {TX_VOICE_FV5ECNS_DM, 0x0, 0x10EAF, 0x01},
396 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)][EFFECT_NS] = \
397 {TX_VOICE_FV5ECNS_DM, 0x0, 0x10EAF, 0x02},
398 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)][EFFECT_AEC] = \
399 {TX_VOICE_FV5ECNS_SM, 0x0, 0x10EAF, 0x01},
400 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)][EFFECT_NS] = \
401 {TX_VOICE_FV5ECNS_SM, 0x0, 0x10EAF, 0x02},
402 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)][EFFECT_AEC] = \
403 {TX_VOICE_FV5ECNS_DM, 0x0, 0x10EAF, 0x01},
404 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)][EFFECT_NS] = \
405 {TX_VOICE_FV5ECNS_DM, 0x0, 0x10EAF, 0x02},
406 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)][EFFECT_AEC] = \
407 {TX_VOICE_FV5ECNS_SM, 0x0, 0x10EAF, 0x01},
408 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)][EFFECT_NS] = \
409 {TX_VOICE_FV5ECNS_SM, 0x0, 0x10EAF, 0x02},
Eric Laurentb23d5282013-05-14 15:27:20 -0700410};
411
412/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700413static int acdb_device_table[SND_DEVICE_MAX] = {
Eric Laurentb23d5282013-05-14 15:27:20 -0700414 [SND_DEVICE_NONE] = -1,
415 [SND_DEVICE_OUT_HANDSET] = 7,
416 [SND_DEVICE_OUT_SPEAKER] = 15,
417 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 15,
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700418 [SND_DEVICE_OUT_SPEAKER_SAFE] = 15,
Eric Laurentb23d5282013-05-14 15:27:20 -0700419 [SND_DEVICE_OUT_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500420 [SND_DEVICE_OUT_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700421 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700422 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500423 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = 77,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700424 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = 77,
Ravi Kumar Alamanda235c3482014-08-21 17:32:44 -0700425 [SND_DEVICE_OUT_VOICE_HANDSET] = ACDB_ID_VOICE_HANDSET,
426 [SND_DEVICE_OUT_VOICE_SPEAKER] = ACDB_ID_VOICE_SPEAKER,
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500427 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = 53,
Eric Laurentb23d5282013-05-14 15:27:20 -0700428 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
yixuanjiang9536e672018-09-06 18:43:36 +0800429 [SND_DEVICE_OUT_VOICE_HEADSET] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500430 [SND_DEVICE_OUT_VOICE_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700431 [SND_DEVICE_OUT_HDMI] = 18,
432 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 15,
433 [SND_DEVICE_OUT_BT_SCO] = 22,
juyuchen5351ea62018-05-16 10:54:37 +0800434 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO] = 14,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700435 [SND_DEVICE_OUT_BT_SCO_WB] = 39,
juyuchen5351ea62018-05-16 10:54:37 +0800436 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB] = 14,
Aniket Kumar Lata26483012018-01-31 20:21:42 -0800437 [SND_DEVICE_OUT_BT_A2DP] = 20,
438 [SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] = 14,
Aniket Kumar Lata9723a962018-05-16 17:41:55 -0700439 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP] = 14,
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700440 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = ACDB_ID_VOICE_HANDSET_TMUS,
Eric Laurentb23d5282013-05-14 15:27:20 -0700441 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
442 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
443 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
vivek mehtaa6b79742017-03-09 15:40:43 -0800444 [SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = 17,
445 [SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = 17,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700446 [SND_DEVICE_OUT_VOICE_TX] = 45,
juyuchen66c4ecf2018-08-06 15:39:34 +0800447 [SND_DEVICE_OUT_VOICE_MUSIC_TX] = 3,
David Linee3fe402017-03-13 10:00:42 -0700448 [SND_DEVICE_OUT_USB_HEADSET] = 45,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700449 [SND_DEVICE_OUT_VOICE_USB_HEADSET] = 45,
David Linee3fe402017-03-13 10:00:42 -0700450 [SND_DEVICE_OUT_USB_HEADPHONES] = 45,
jasmine cha270b7762018-03-30 15:41:33 +0800451 [SND_DEVICE_OUT_USB_HEADSET_SPEC] = 45,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700452 [SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = 45,
David Linee3fe402017-03-13 10:00:42 -0700453 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = 14,
Haynes Mathew George9090bfb2017-05-31 11:44:50 -0700454 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] = 14,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700455 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = 124,
456 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = 101,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700457 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = ACDB_ID_VOICE_SPEAKER,
juyuchend194b432018-11-16 14:15:16 +0800458 [SND_DEVICE_OUT_VOICE_HEARING_AID] = 45,
Eric Laurentb23d5282013-05-14 15:27:20 -0700459
460 [SND_DEVICE_IN_HANDSET_MIC] = 4,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700461 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 106,
462 [SND_DEVICE_IN_HANDSET_MIC_NS] = 107,
463 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = 108,
464 [SND_DEVICE_IN_HANDSET_DMIC] = 41,
465 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = 109,
466 [SND_DEVICE_IN_HANDSET_DMIC_NS] = 110,
467 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = 111,
468 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = 34,
469
470 [SND_DEVICE_IN_SPEAKER_MIC] = 11,
471 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 112,
472 [SND_DEVICE_IN_SPEAKER_MIC_NS] = 113,
473 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = 114,
474 [SND_DEVICE_IN_SPEAKER_DMIC] = 43,
475 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = 115,
476 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = 116,
477 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = 117,
478 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = 35,
479
rago90fb9612015-12-02 11:37:53 -0800480 [SND_DEVICE_IN_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentcefbbac2014-09-04 13:54:10 -0500481 [SND_DEVICE_IN_HEADSET_MIC_AEC] = ACDB_ID_HEADSET_MIC_AEC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700482
Eric Laurentb23d5282013-05-14 15:27:20 -0700483 [SND_DEVICE_IN_HDMI_MIC] = 4,
484 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700485 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = 21,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700486 [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700487 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = 38,
Eric Laurent5f4ca952018-10-19 17:33:43 -0700488 [SND_DEVICE_IN_CAMCORDER_LANDSCAPE] = 61,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700489
490 [SND_DEVICE_IN_VOICE_DMIC] = 41,
491 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = ACDB_ID_VOICE_DMIC_EF_TMUS,
492 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700493 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = 11,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700494 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 43,
rago90fb9612015-12-02 11:37:53 -0800495 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentb23d5282013-05-14 15:27:20 -0700496 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
497 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
498 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
vivek mehtaa6b79742017-03-09 15:40:43 -0800499 [SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = 16,
500 [SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = 16,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700501
rago90fb9612015-12-02 11:37:53 -0800502 [SND_DEVICE_IN_VOICE_REC_MIC] = ACDB_ID_VOICE_REC_MIC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700503 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = 113,
vivek mehta733c1df2016-04-04 15:09:24 -0700504 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = 112,
vivek mehtaf3440682016-05-11 14:24:37 -0700505 [SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = 114,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700506 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = 35,
507 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 43,
rago90fb9612015-12-02 11:37:53 -0800508 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
509
510 [SND_DEVICE_IN_UNPROCESSED_MIC] = ACDB_ID_VOICE_REC_MIC,
511 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
vivek mehta4ed66e62016-04-15 23:33:34 -0700512 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = 35,
513 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = 125,
514 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = 125,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700515
516 [SND_DEVICE_IN_VOICE_RX] = 44,
David Linee3fe402017-03-13 10:00:42 -0700517 [SND_DEVICE_IN_USB_HEADSET_MIC] = 44,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700518 [SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = 44,
519 [SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = 44,
520 [SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = 44,
521 [SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = 44,
Prashant Malanic92c5962015-08-11 15:10:18 -0700522 [SND_DEVICE_IN_THREE_MIC] = 46,
523 [SND_DEVICE_IN_QUAD_MIC] = 46,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700524 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = 102,
Prashant Malanic92c5962015-08-11 15:10:18 -0700525 [SND_DEVICE_IN_HANDSET_TMIC] = 125,
526 [SND_DEVICE_IN_HANDSET_QMIC] = 125,
vivek mehta733c1df2016-04-04 15:09:24 -0700527 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = 125, /* override this for new target to 140 */
528 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = 125, /* override this for new target to 140 */
Eric Laurent5f4ca952018-10-19 17:33:43 -0700529 [SND_DEVICE_IN_CAMCORDER_INVERT_LANDSCAPE] = 61,
530 [SND_DEVICE_IN_CAMCORDER_PORTRAIT] = 61,
531 [SND_DEVICE_IN_CAMCORDER_SELFIE_LANDSCAPE] = 61,
532 [SND_DEVICE_IN_CAMCORDER_SELFIE_INVERT_LANDSCAPE] = 61,
533 [SND_DEVICE_IN_CAMCORDER_SELFIE_PORTRAIT] = 61,
Vignesh Kulothungan64698822018-01-23 11:25:18 -0800534 [SND_DEVICE_IN_SPEAKER_QMIC_NS] = 129,
535 [SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS] = 129,
juyuchend194b432018-11-16 14:15:16 +0800536 [SND_DEVICE_IN_VOICE_HEARING_AID] = 44,
Eric Laurentb23d5282013-05-14 15:27:20 -0700537};
538
David Linee3fe402017-03-13 10:00:42 -0700539// Platform specific backend bit width table
540static int backend_bit_width_table[SND_DEVICE_MAX] = {0};
541
Haynes Mathew George98c95622014-06-20 19:14:25 -0700542struct name_to_index {
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700543 char name[100];
544 unsigned int index;
545};
546
547#define TO_NAME_INDEX(X) #X, X
548
Haynes Mathew George98c95622014-06-20 19:14:25 -0700549/* Used to get index from parsed string */
550static const struct name_to_index snd_device_name_index[SND_DEVICE_MAX] = {
551 /* out */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700552 {TO_NAME_INDEX(SND_DEVICE_OUT_HANDSET)},
553 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER)},
554 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_REVERSE)},
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700555 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700556 {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500557 {TO_NAME_INDEX(SND_DEVICE_OUT_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700558 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700559 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES)},
Eric Laurent744996b2014-10-01 11:40:40 -0500560 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_LINE)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700561 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700562 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET)},
563 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700564 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_HFP)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700565 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADPHONES)},
yixuanjiang9536e672018-09-06 18:43:36 +0800566 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADSET)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500567 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700568 {TO_NAME_INDEX(SND_DEVICE_OUT_HDMI)},
569 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HDMI)},
570 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO)},
juyuchen5351ea62018-05-16 10:54:37 +0800571 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700572 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO_WB)},
juyuchen5351ea62018-05-16 10:54:37 +0800573 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB)},
Aniket Kumar Lata26483012018-01-31 20:21:42 -0800574 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_A2DP)},
575 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP)},
Aniket Kumar Lata9723a962018-05-16 17:41:55 -0700576 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700577 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET_TMUS)},
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500578 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HAC_HANDSET)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700579 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES)},
580 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES)},
581 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET)},
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -0800582 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_SCO)},
583 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800584 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_USB)},
585 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_USB)},
David Linee3fe402017-03-13 10:00:42 -0700586 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADSET)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700587 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_USB_HEADSET)},
David Linee3fe402017-03-13 10:00:42 -0700588 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADPHONES)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700589 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_USB_HEADPHONES)},
David Linee3fe402017-03-13 10:00:42 -0700590 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET)},
Haynes Mathew George9090bfb2017-05-31 11:44:50 -0700591 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700592 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED)},
593 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED)},
jasmine cha270b7762018-03-30 15:41:33 +0800594 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADSET_SPEC)},
juyuchend194b432018-11-16 14:15:16 +0800595 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEARING_AID)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800596
597 /* in */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700598 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700599 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700600 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_NS)},
601 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)},
602 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC)},
603 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC)},
604 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_NS)},
605 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)},
606 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_STEREO)},
607
608 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700609 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700610 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_NS)},
611 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)},
612 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC)},
613 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC)},
614 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS)},
615 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)},
616 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_STEREO)},
617
618 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC)},
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700619 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700620
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700621 {TO_NAME_INDEX(SND_DEVICE_IN_HDMI_MIC)},
622 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700623 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700624 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700625 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB_NREC)},
Eric Laurent5f4ca952018-10-19 17:33:43 -0700626 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_LANDSCAPE)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700627
628 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC)},
629 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC_TMUS)},
630 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700631 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700632 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC)},
633 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEADSET_MIC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700634 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC)},
635 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC)},
636 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800637 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC)},
638 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC)},
639
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700640
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700641 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700642 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_NS)},
vivek mehta733c1df2016-04-04 15:09:24 -0700643 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC)},
vivek mehtaf3440682016-05-11 14:24:37 -0700644 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700645 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_STEREO)},
646 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE)},
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700647 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_HEADSET_MIC)},
David Linee3fe402017-03-13 10:00:42 -0700648 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700649 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_USB_HEADSET_MIC)},
650 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC)},
651 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC)},
652 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC_AEC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700653
rago90fb9612015-12-02 11:37:53 -0800654 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_MIC)},
655 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC)},
vivek mehta4ed66e62016-04-15 23:33:34 -0700656 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_STEREO_MIC)},
657 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_THREE_MIC)},
658 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_QUAD_MIC)},
rago90fb9612015-12-02 11:37:53 -0800659
Prashant Malanic92c5962015-08-11 15:10:18 -0700660 {TO_NAME_INDEX(SND_DEVICE_IN_THREE_MIC)},
661 {TO_NAME_INDEX(SND_DEVICE_IN_QUAD_MIC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700662 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_VI_FEEDBACK)},
Prashant Malanic92c5962015-08-11 15:10:18 -0700663 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC)},
664 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC)},
vivek mehta733c1df2016-04-04 15:09:24 -0700665 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC_AEC)},
666 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC_AEC)},
Eric Laurent5f4ca952018-10-19 17:33:43 -0700667 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_INVERT_LANDSCAPE)},
668 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_PORTRAIT)},
669 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_SELFIE_LANDSCAPE)},
670 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_SELFIE_INVERT_LANDSCAPE)},
671 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_SELFIE_PORTRAIT)},
juyuchend194b432018-11-16 14:15:16 +0800672 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEARING_AID)},
673
Eric Laurent5f4ca952018-10-19 17:33:43 -0700674 /* For legacy xml file parsing */
675 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_MIC)},
Vignesh Kulothungan64698822018-01-23 11:25:18 -0800676 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_QMIC_NS)},
677 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700678};
679
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700680static char * backend_tag_table[SND_DEVICE_MAX] = {0};
681static char * hw_interface_table[SND_DEVICE_MAX] = {0};
Haynes Mathew George98c95622014-06-20 19:14:25 -0700682
683static const struct name_to_index usecase_name_index[AUDIO_USECASE_MAX] = {
684 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_DEEP_BUFFER)},
685 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_LOW_LATENCY)},
Vignesh Kulothungan019d19b2019-01-23 11:09:18 -0800686 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_WITH_HAPTICS)},
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800687 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_HIFI)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700688 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD)},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700689 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_TTS)},
690 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_ULL)},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800691 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_MMAP)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700692 {TO_NAME_INDEX(USECASE_AUDIO_RECORD)},
693 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_LOW_LATENCY)},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800694 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_MMAP)},
Haynes Mathew George569b7482017-05-08 14:44:27 -0700695 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_HIFI)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700696 {TO_NAME_INDEX(USECASE_VOICE_CALL)},
697 {TO_NAME_INDEX(USECASE_VOICE2_CALL)},
698 {TO_NAME_INDEX(USECASE_VOLTE_CALL)},
699 {TO_NAME_INDEX(USECASE_QCHAT_CALL)},
700 {TO_NAME_INDEX(USECASE_VOWLAN_CALL)},
John Muirf1346ce2016-12-06 00:03:41 -0800701 {TO_NAME_INDEX(USECASE_VOICEMMODE1_CALL)},
702 {TO_NAME_INDEX(USECASE_VOICEMMODE2_CALL)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700703 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK)},
704 {TO_NAME_INDEX(USECASE_INCALL_REC_DOWNLINK)},
705 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK_AND_DOWNLINK)},
706 {TO_NAME_INDEX(USECASE_AUDIO_HFP_SCO)},
John Muirf1346ce2016-12-06 00:03:41 -0800707 {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_RX)},
708 {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_TX)},
709 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_AFE_PROXY)},
710 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_AFE_PROXY)},
711 {TO_NAME_INDEX(USECASE_AUDIO_DSM_FEEDBACK)},
vivek mehtaa68fea62017-06-08 19:04:02 -0700712 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_VOIP)},
713 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_VOIP)},
Nadav Bar3d72cfc2018-01-07 12:19:24 +0200714 {TO_NAME_INDEX(USECASE_INCALL_MUSIC_UPLINK)},
Aniket Kumar Lata99546312018-03-19 21:38:38 -0700715 {TO_NAME_INDEX(USECASE_AUDIO_A2DP_ABR_FEEDBACK)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700716};
717
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800718static const struct name_to_index usecase_type_index[USECASE_TYPE_MAX] = {
719 {TO_NAME_INDEX(PCM_PLAYBACK)},
720 {TO_NAME_INDEX(PCM_CAPTURE)},
721 {TO_NAME_INDEX(VOICE_CALL)},
722 {TO_NAME_INDEX(PCM_HFP_CALL)},
723};
724
725struct app_type_entry {
726 int uc_type;
727 int bit_width;
728 int app_type;
729 int max_rate;
vivek mehtaa68fea62017-06-08 19:04:02 -0700730 char *mode;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800731 struct listnode node; // membership in app_type_entry_list;
732};
733
734static struct listnode app_type_entry_list;
735
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700736#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
737#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
Eric Laurent0e46adf2016-12-16 12:49:24 -0800738#define ULL_PLATFORM_DELAY (3*1000LL)
739#define MMAP_PLATFORM_DELAY (3*1000LL)
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700740
Eric Laurentb23d5282013-05-14 15:27:20 -0700741static pthread_once_t check_op_once_ctl = PTHREAD_ONCE_INIT;
742static bool is_tmus = false;
743
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800744static int init_be_dai_name_table(struct audio_device *adev);
745
Carter Hsu017c63a2018-10-15 15:01:42 -0700746static bool is_usb_snd_dev(snd_device_t snd_device)
747{
748 if (snd_device < SND_DEVICE_IN_BEGIN) {
749 if (snd_device == SND_DEVICE_OUT_USB_HEADSET ||\
750 snd_device == SND_DEVICE_OUT_USB_HEADPHONES ||\
751 snd_device == SND_DEVICE_OUT_VOICE_USB_HEADPHONES ||\
752 snd_device == SND_DEVICE_OUT_VOICE_USB_HEADSET ||\
753 snd_device == SND_DEVICE_OUT_VOICE_TTY_FULL_USB ||\
754 snd_device == SND_DEVICE_OUT_VOICE_TTY_VCO_USB)
755 return true;
756 } else {
757 if (snd_device == SND_DEVICE_IN_USB_HEADSET_MIC ||\
758 snd_device == SND_DEVICE_IN_USB_HEADSET_MIC_AEC ||\
759 snd_device == SND_DEVICE_IN_VOICE_USB_HEADSET_MIC ||\
760 snd_device == SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC ||\
761 snd_device == SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC)
762 return true;
763 }
764 return false;
765}
766
Eric Laurentb23d5282013-05-14 15:27:20 -0700767static void check_operator()
768{
769 char value[PROPERTY_VALUE_MAX];
770 int mccmnc;
771 property_get("gsm.sim.operator.numeric",value,"0");
772 mccmnc = atoi(value);
Eric Laurent2bafff12016-03-17 12:17:23 -0700773 ALOGD("%s: tmus mccmnc %d", __func__, mccmnc);
Eric Laurentb23d5282013-05-14 15:27:20 -0700774 switch(mccmnc) {
775 /* TMUS MCC(310), MNC(490, 260, 026) */
776 case 310490:
777 case 310260:
778 case 310026:
sangwon.jeonb891db52013-09-14 17:39:15 +0900779 /* Add new TMUS MNC(800, 660, 580, 310, 270, 250, 240, 230, 220, 210, 200, 160) */
780 case 310800:
781 case 310660:
782 case 310580:
783 case 310310:
784 case 310270:
785 case 310250:
786 case 310240:
787 case 310230:
788 case 310220:
789 case 310210:
790 case 310200:
791 case 310160:
Eric Laurentb23d5282013-05-14 15:27:20 -0700792 is_tmus = true;
793 break;
794 }
795}
796
797bool is_operator_tmus()
798{
799 pthread_once(&check_op_once_ctl, check_operator);
800 return is_tmus;
801}
802
keunhui.park2f7306a2015-07-16 16:48:06 +0900803static char *get_current_operator()
804{
805 struct listnode *node;
806 struct operator_info *info_item;
807 char mccmnc[PROPERTY_VALUE_MAX];
808 char *ret = NULL;
809
Tom Cherry7fea2042016-11-10 18:05:59 -0800810 property_get("gsm.sim.operator.numeric",mccmnc,"00000");
keunhui.park2f7306a2015-07-16 16:48:06 +0900811
812 list_for_each(node, &operator_info_list) {
813 info_item = node_to_item(node, struct operator_info, list);
814 if (strstr(info_item->mccmnc, mccmnc) != NULL) {
815 ret = info_item->name;
816 }
817 }
818
819 return ret;
820}
821
822static struct operator_specific_device *get_operator_specific_device(snd_device_t snd_device)
823{
824 struct listnode *node;
825 struct operator_specific_device *ret = NULL;
826 struct operator_specific_device *device_item;
827 char *operator_name;
828
829 operator_name = get_current_operator();
830 if (operator_name == NULL)
831 return ret;
832
833 list_for_each(node, operator_specific_device_table[snd_device]) {
834 device_item = node_to_item(node, struct operator_specific_device, list);
835 if (strcmp(operator_name, device_item->operator) == 0) {
836 ret = device_item;
837 }
838 }
839
840 return ret;
841}
842
843
844static int get_operator_specific_device_acdb_id(snd_device_t snd_device)
845{
846 struct operator_specific_device *device;
847 int ret = acdb_device_table[snd_device];
848
849 device = get_operator_specific_device(snd_device);
850 if (device != NULL)
851 ret = device->acdb_id;
852
853 return ret;
854}
855
Carter Hsu017c63a2018-10-15 15:01:42 -0700856static int get_external_specific_device_acdb_id(snd_device_t snd_device)
857{
858 struct external_specific_device *ext_dev;
859 int ret = acdb_device_table[snd_device];
860 char *usbid = NULL;
861 struct listnode *node;
862
863 if (is_usb_snd_dev(snd_device))
864 usbid = audio_extn_usb_usbid();
865
866 if (usbid) {
867 list_for_each(node, external_specific_device_table[snd_device]) {
868 ext_dev = node_to_item(node, struct external_specific_device, list);
869 if (ext_dev->usbid && !strcmp(usbid, ext_dev->usbid)) {
870 ret = ext_dev->acdb_id;
871 break;
872 }
873 }
874
875 free(usbid);
876 }
877 return ret;
878}
879
keunhui.park2f7306a2015-07-16 16:48:06 +0900880static const char *get_operator_specific_device_mixer_path(snd_device_t snd_device)
881{
882 struct operator_specific_device *device;
883 const char *ret = device_table[snd_device];
884
885 device = get_operator_specific_device(snd_device);
886 if (device != NULL)
887 ret = device->mixer_path;
888
889 return ret;
890}
891
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800892inline bool platform_supports_app_type_cfg()
893{
Thierry Strudel07f96d12018-09-20 13:31:34 -0700894#if defined (PLATFORM_MSM8998) || (PLATFORM_SDM845) || (PLATFORM_SDM710) || (PLATFORM_SM8150)
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800895 return true;
896#else
897 return false;
898#endif
899}
900
jasmine chac89321b2018-04-10 21:37:01 +0800901static int parse_audiocal_cfg(struct str_parms *parms, acdb_audio_cal_cfg_t *cal)
902{
903 int err;
904 char value[64];
905 int ret = 0;
906
907 if (parms == NULL || cal == NULL)
908 return ret;
909
910 err = str_parms_get_str(parms, "cal_persist", value, sizeof(value));
911 if (err >= 0) {
912 str_parms_del(parms, "cal_persist");
913 cal->persist = (uint32_t)strtoul(value, NULL, 0);
914 ret = ret | 0x1;
915 }
916 err = str_parms_get_str(parms, "cal_apptype", value, sizeof(value));
917 if (err >= 0) {
918 str_parms_del(parms, "cal_apptype");
919 cal->app_type = (uint32_t)strtoul(value, NULL, 0);
920 ret = ret | 0x2;
921 }
922 err = str_parms_get_str(parms, "cal_caltype", value, sizeof(value));
923 if (err >= 0) {
924 str_parms_del(parms, "cal_caltype");
925 cal->cal_type = (uint32_t)strtoul(value, NULL, 0);
926 ret = ret | 0x4;
927 }
928 err = str_parms_get_str(parms, "cal_samplerate", value, sizeof(value));
929 if (err >= 0) {
930 str_parms_del(parms, "cal_samplerate");
931 cal->sampling_rate = (uint32_t)strtoul(value, NULL, 0);
932 ret = ret | 0x8;
933 }
934 err = str_parms_get_str(parms, "cal_devid", value, sizeof(value));
935 if (err >= 0) {
936 str_parms_del(parms, "cal_devid");
937 cal->dev_id = (uint32_t)strtoul(value, NULL, 0);
938 ret = ret | 0x10;
939 }
940 err = str_parms_get_str(parms, "cal_snddevid", value, sizeof(value));
941 if (err >= 0) {
942 str_parms_del(parms, "cal_snddevid");
943 cal->snd_dev_id = (uint32_t)strtoul(value, NULL, 0);
944 ret = ret | 0x20;
945 }
946 err = str_parms_get_str(parms, "cal_topoid", value, sizeof(value));
947 if (err >= 0) {
948 str_parms_del(parms, "cal_topoid");
949 cal->topo_id = (uint32_t)strtoul(value, NULL, 0);
950 ret = ret | 0x40;
951 }
952 err = str_parms_get_str(parms, "cal_moduleid", value, sizeof(value));
953 if (err >= 0) {
954 str_parms_del(parms, "cal_moduleid");
955 cal->module_id = (uint32_t)strtoul(value, NULL, 0);
956 ret = ret | 0x80;
957 }
958 err = str_parms_get_str(parms, "cal_paramid", value, sizeof(value));
959 if (err >= 0) {
960 str_parms_del(parms, "cal_paramid");
961 cal->param_id = (uint32_t)strtoul(value, NULL, 0);
962 ret = ret | 0x100;
963 }
justinwengc6347db2019-02-21 18:49:00 +0800964#ifdef PLATFORM_SM8150
965 err = str_parms_get_str(parms, "cal_instanceid", value, sizeof(value));
966 if (err >= 0) {
967 str_parms_del(parms, "cal_instanceid");
968 cal->instance_id = (uint32_t)strtoul(value, NULL, 0);
969 ret = ret | 0x200;
970 }
971#endif
972
jasmine chac89321b2018-04-10 21:37:01 +0800973 return ret;
974}
975
976static void set_audiocal(void *platform, struct str_parms *parms, char *value, int len)
977{
978 struct platform_data *my_data = (struct platform_data *)platform;
979 acdb_audio_cal_cfg_t cal;
980 uint8_t *dptr = NULL;
981 int32_t dlen = 0;
982 int err ,ret;
983
984 if (value == NULL || platform == NULL || parms == NULL) {
985 ALOGE("[%s] received null pointer, failed", __func__);
986 goto done_key_audcal;
987 }
988
989 memset(&cal, 0, sizeof(acdb_audio_cal_cfg_t));
990 /* parse audio calibration keys */
991 ret = parse_audiocal_cfg(parms, &cal);
992
993 /* handle audio calibration data now */
994 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_AUD_CALDATA, value, len);
995 if (err >= 0) {
996 str_parms_del(parms, AUDIO_PARAMETER_KEY_AUD_CALDATA);
997 dlen = strlen(value);
998 if (dlen <= 0) {
999 ALOGE("[%s] null data received", __func__);
1000 goto done_key_audcal;
1001 }
1002 /*
1003 The base64 encoded string is always larger than the binary data,
1004 so b64_pton will always output less data than provided (around 1/3
1005 less than the input data). That's why we can allocate input buffer
1006 length and then get function work.
1007 */
1008 dptr = (uint8_t *)calloc(dlen, sizeof(uint8_t));
1009 if (dptr == NULL) {
1010 ALOGE("[%s] memory allocation failed for %d", __func__, dlen);
1011 goto done_key_audcal;
1012 }
1013 dlen = b64_pton(value, dptr, dlen);
1014 if (dlen <= 0) {
1015 ALOGE("[%s] data decoding failed %d", __func__, dlen);
1016 goto done_key_audcal;
1017 }
1018
1019 if (cal.dev_id) {
1020 if (audio_is_input_device(cal.dev_id)) {
Eric Laurentd1b7a9b2018-11-15 12:24:31 -08001021 // FIXME: why pass an input device whereas
1022 // platform_get_input_snd_device() expects as an output device?
1023 cal.snd_dev_id = platform_get_input_snd_device(platform, NULL, cal.dev_id);
jasmine chac89321b2018-04-10 21:37:01 +08001024 } else {
1025 cal.snd_dev_id = platform_get_output_snd_device(platform, cal.dev_id);
1026 }
1027 }
1028 cal.acdb_dev_id = platform_get_snd_device_acdb_id(cal.snd_dev_id);
1029 ALOGD("Setting audio calibration for snd_device(%d) acdb_id(%d)",
1030 cal.snd_dev_id, cal.acdb_dev_id);
1031 if (cal.acdb_dev_id == -EINVAL) {
1032 ALOGE("[%s] Invalid acdb_device id %d for snd device id %d",
1033 __func__, cal.acdb_dev_id, cal.snd_dev_id);
1034 goto done_key_audcal;
1035 }
1036 if (my_data->acdb_set_audio_cal) {
1037 ret = my_data->acdb_set_audio_cal((void *)&cal, (void *)dptr, dlen);
1038 }
1039 }
1040done_key_audcal:
1041 if (dptr != NULL)
1042 free(dptr);
1043}
1044
vivek mehta1a9b7c02015-06-25 11:49:38 -07001045bool platform_send_gain_dep_cal(void *platform, int level)
1046{
1047 bool ret_val = false;
1048 struct platform_data *my_data = (struct platform_data *)platform;
1049 struct audio_device *adev = my_data->adev;
1050 int acdb_dev_id, app_type;
1051 int acdb_dev_type = MSM_SNDDEV_CAP_RX;
1052 int mode = CAL_MODE_RTAC;
1053 struct listnode *node;
1054 struct audio_usecase *usecase;
Haynes Mathew George67486e22017-06-26 12:58:38 -07001055 bool valid_uc_type;
1056 bool valid_dev;
vivek mehta1a9b7c02015-06-25 11:49:38 -07001057
1058 if (my_data->acdb_send_gain_dep_cal == NULL) {
1059 ALOGE("%s: dlsym error for acdb_send_gain_dep_cal", __func__);
1060 return ret_val;
1061 }
1062
1063 if (!voice_is_in_call(adev)) {
1064 ALOGV("%s: Not Voice call usecase, apply new cal for level %d",
1065 __func__, level);
vivek mehta1a9b7c02015-06-25 11:49:38 -07001066
1067 // find the current active sound device
1068 list_for_each(node, &adev->usecase_list) {
1069 usecase = node_to_item(node, struct audio_usecase, list);
Haynes Mathew George67486e22017-06-26 12:58:38 -07001070 LOG_ALWAYS_FATAL_IF(usecase == NULL,
1071 "unxpected NULL usecase in usecase_list");
1072 valid_uc_type = usecase->type == PCM_PLAYBACK;
1073 valid_dev = false;
1074 if (valid_uc_type) {
1075 audio_devices_t dev = usecase->stream.out->devices;
1076 valid_dev = (dev == AUDIO_DEVICE_OUT_SPEAKER ||
vivek mehta40125092017-08-21 18:48:51 -07001077 dev == AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Haynes Mathew George67486e22017-06-26 12:58:38 -07001078 dev == AUDIO_DEVICE_OUT_WIRED_HEADSET ||
1079 dev == AUDIO_DEVICE_OUT_WIRED_HEADPHONE);
1080 }
1081 if (valid_dev) {
vivek mehta40125092017-08-21 18:48:51 -07001082 ALOGV("%s: out device is %d", __func__, usecase->out_snd_device);
1083 if (platform_supports_app_type_cfg())
1084 app_type = usecase->stream.out->app_type_cfg.app_type;
1085 else
1086 app_type = DEFAULT_APP_TYPE_RX_PATH;
vivek mehta4cb82982015-07-13 12:05:49 -07001087
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07001088 acdb_dev_id = platform_get_snd_device_acdb_id(usecase->out_snd_device);
vivek mehta40125092017-08-21 18:48:51 -07001089
1090 if (!my_data->acdb_send_gain_dep_cal(acdb_dev_id, app_type,
vivek mehta1a9b7c02015-06-25 11:49:38 -07001091 acdb_dev_type, mode, level)) {
1092 // set ret_val true if at least one calibration is set successfully
1093 ret_val = true;
1094 } else {
1095 ALOGE("%s: my_data->acdb_send_gain_dep_cal failed ", __func__);
1096 }
1097 } else {
1098 ALOGW("%s: Usecase list is empty", __func__);
1099 }
1100 }
1101 } else {
1102 ALOGW("%s: Voice call in progress .. ignore setting new cal",
1103 __func__);
1104 }
1105 return ret_val;
1106}
1107
Eric Laurentcefbbac2014-09-04 13:54:10 -05001108void platform_set_echo_reference(struct audio_device *adev, bool enable, audio_devices_t out_device)
Eric Laurentb23d5282013-05-14 15:27:20 -07001109{
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08001110 struct platform_data *my_data = (struct platform_data *)adev->platform;
Eric Laurentcefbbac2014-09-04 13:54:10 -05001111 snd_device_t snd_device = SND_DEVICE_NONE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001112
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08001113 if (strcmp(my_data->ec_ref_mixer_path, "")) {
1114 ALOGV("%s: diabling %s", __func__, my_data->ec_ref_mixer_path);
1115 audio_route_reset_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
Eric Laurentcefbbac2014-09-04 13:54:10 -05001116 }
1117
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08001118 if (enable) {
1119 strcpy(my_data->ec_ref_mixer_path, "echo-reference");
1120 if (out_device != AUDIO_DEVICE_NONE) {
1121 snd_device = platform_get_output_snd_device(adev->platform, out_device);
1122 platform_add_backend_name(adev->platform, my_data->ec_ref_mixer_path, snd_device);
1123 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05001124
Joe Onorato188b6222016-03-01 11:02:27 -08001125 ALOGV("%s: enabling %s", __func__, my_data->ec_ref_mixer_path);
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08001126 audio_route_apply_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
1127 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001128}
1129
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001130static struct csd_data *open_csd_client(bool i2s_ext_modem)
1131{
1132 struct csd_data *csd = calloc(1, sizeof(struct csd_data));
1133
1134 csd->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
1135 if (csd->csd_client == NULL) {
1136 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
1137 goto error;
1138 } else {
1139 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
1140
1141 csd->deinit = (deinit_t)dlsym(csd->csd_client,
1142 "csd_client_deinit");
1143 if (csd->deinit == NULL) {
1144 ALOGE("%s: dlsym error %s for csd_client_deinit", __func__,
1145 dlerror());
1146 goto error;
1147 }
1148 csd->disable_device = (disable_device_t)dlsym(csd->csd_client,
1149 "csd_client_disable_device");
1150 if (csd->disable_device == NULL) {
1151 ALOGE("%s: dlsym error %s for csd_client_disable_device",
1152 __func__, dlerror());
1153 goto error;
1154 }
1155 csd->enable_device_config = (enable_device_config_t)dlsym(csd->csd_client,
1156 "csd_client_enable_device_config");
1157 if (csd->enable_device_config == NULL) {
1158 ALOGE("%s: dlsym error %s for csd_client_enable_device_config",
1159 __func__, dlerror());
1160 goto error;
1161 }
1162 csd->enable_device = (enable_device_t)dlsym(csd->csd_client,
1163 "csd_client_enable_device");
1164 if (csd->enable_device == NULL) {
1165 ALOGE("%s: dlsym error %s for csd_client_enable_device",
1166 __func__, dlerror());
1167 goto error;
1168 }
1169 csd->start_voice = (start_voice_t)dlsym(csd->csd_client,
1170 "csd_client_start_voice");
1171 if (csd->start_voice == NULL) {
1172 ALOGE("%s: dlsym error %s for csd_client_start_voice",
1173 __func__, dlerror());
1174 goto error;
1175 }
1176 csd->stop_voice = (stop_voice_t)dlsym(csd->csd_client,
1177 "csd_client_stop_voice");
1178 if (csd->stop_voice == NULL) {
1179 ALOGE("%s: dlsym error %s for csd_client_stop_voice",
1180 __func__, dlerror());
1181 goto error;
1182 }
1183 csd->volume = (volume_t)dlsym(csd->csd_client,
1184 "csd_client_volume");
1185 if (csd->volume == NULL) {
1186 ALOGE("%s: dlsym error %s for csd_client_volume",
1187 __func__, dlerror());
1188 goto error;
1189 }
1190 csd->mic_mute = (mic_mute_t)dlsym(csd->csd_client,
1191 "csd_client_mic_mute");
1192 if (csd->mic_mute == NULL) {
1193 ALOGE("%s: dlsym error %s for csd_client_mic_mute",
1194 __func__, dlerror());
1195 goto error;
1196 }
1197 csd->slow_talk = (slow_talk_t)dlsym(csd->csd_client,
1198 "csd_client_slow_talk");
1199 if (csd->slow_talk == NULL) {
1200 ALOGE("%s: dlsym error %s for csd_client_slow_talk",
1201 __func__, dlerror());
1202 goto error;
1203 }
1204 csd->start_playback = (start_playback_t)dlsym(csd->csd_client,
1205 "csd_client_start_playback");
1206 if (csd->start_playback == NULL) {
1207 ALOGE("%s: dlsym error %s for csd_client_start_playback",
1208 __func__, dlerror());
1209 goto error;
1210 }
1211 csd->stop_playback = (stop_playback_t)dlsym(csd->csd_client,
1212 "csd_client_stop_playback");
1213 if (csd->stop_playback == NULL) {
1214 ALOGE("%s: dlsym error %s for csd_client_stop_playback",
1215 __func__, dlerror());
1216 goto error;
1217 }
1218 csd->start_record = (start_record_t)dlsym(csd->csd_client,
1219 "csd_client_start_record");
1220 if (csd->start_record == NULL) {
1221 ALOGE("%s: dlsym error %s for csd_client_start_record",
1222 __func__, dlerror());
1223 goto error;
1224 }
1225 csd->stop_record = (stop_record_t)dlsym(csd->csd_client,
1226 "csd_client_stop_record");
1227 if (csd->stop_record == NULL) {
1228 ALOGE("%s: dlsym error %s for csd_client_stop_record",
1229 __func__, dlerror());
1230 goto error;
1231 }
1232
1233 csd->get_sample_rate = (get_sample_rate_t)dlsym(csd->csd_client,
1234 "csd_client_get_sample_rate");
1235 if (csd->get_sample_rate == NULL) {
1236 ALOGE("%s: dlsym error %s for csd_client_get_sample_rate",
1237 __func__, dlerror());
1238
1239 goto error;
1240 }
1241
1242 csd->init = (init_t)dlsym(csd->csd_client, "csd_client_init");
1243
1244 if (csd->init == NULL) {
1245 ALOGE("%s: dlsym error %s for csd_client_init",
1246 __func__, dlerror());
1247 goto error;
1248 } else {
1249 csd->init(i2s_ext_modem);
1250 }
1251 }
1252 return csd;
1253
1254error:
1255 free(csd);
1256 csd = NULL;
1257 return csd;
1258}
1259
1260void close_csd_client(struct csd_data *csd)
1261{
1262 if (csd != NULL) {
1263 csd->deinit();
1264 dlclose(csd->csd_client);
1265 free(csd);
1266 csd = NULL;
1267 }
1268}
1269
1270static void platform_csd_init(struct platform_data *my_data)
1271{
1272#ifdef PLATFORM_MSM8084
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001273 int32_t modems, (*count_modems)(void);
1274 const char *name = "libdetectmodem.so";
1275 const char *func = "count_modems";
1276 const char *error;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001277
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001278 my_data->csd = NULL;
1279
1280 void *lib = dlopen(name, RTLD_NOW);
1281 error = dlerror();
1282 if (!lib) {
1283 ALOGE("%s: could not find %s: %s", __func__, name, error);
1284 return;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001285 }
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001286
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001287 count_modems = NULL;
1288 *(void **)(&count_modems) = dlsym(lib, func);
1289 error = dlerror();
1290 if (!count_modems) {
1291 ALOGE("%s: could not find symbol %s in %s: %s",
1292 __func__, func, name, error);
1293 goto done;
1294 }
1295
1296 modems = count_modems();
1297 if (modems < 0) {
1298 ALOGE("%s: count_modems failed\n", __func__);
1299 goto done;
1300 }
1301
Eric Laurent2bafff12016-03-17 12:17:23 -07001302 ALOGD("%s: num_modems %d\n", __func__, modems);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001303 if (modems > 0)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001304 my_data->csd = open_csd_client(false /*is_i2s_ext_modem*/);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001305
1306done:
1307 dlclose(lib);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001308#else
1309 my_data->csd = NULL;
1310#endif
1311}
1312
Eric Laurentc6333382015-09-14 12:43:44 -07001313static void set_platform_defaults(struct platform_data * my_data)
Haynes Mathew George98c95622014-06-20 19:14:25 -07001314{
1315 int32_t dev;
1316 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001317 backend_tag_table[dev] = NULL;
1318 hw_interface_table[dev] = NULL;
keunhui.park2f7306a2015-07-16 16:48:06 +09001319 operator_specific_device_table[dev] = NULL;
Carter Hsu017c63a2018-10-15 15:01:42 -07001320 external_specific_device_table[dev] = NULL;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001321 }
1322
David Linee3fe402017-03-13 10:00:42 -07001323 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1324 backend_bit_width_table[dev] = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
1325 }
1326
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001327 // To overwrite these go to the audio_platform_info.xml file.
1328 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("bt-sco");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07001329 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("bt-sco");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001330 backend_tag_table[SND_DEVICE_OUT_BT_SCO] = strdup("bt-sco");
1331 backend_tag_table[SND_DEVICE_OUT_HDMI] = strdup("hdmi");
1332 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("speaker-and-hdmi");
1333 backend_tag_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("bt-sco-wb");
1334 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("bt-sco-wb");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07001335 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("bt-sco-wb");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001336 backend_tag_table[SND_DEVICE_OUT_VOICE_TX] = strdup("afe-proxy");
1337 backend_tag_table[SND_DEVICE_IN_VOICE_RX] = strdup("afe-proxy");
Haynes Mathew George98c95622014-06-20 19:14:25 -07001338
David Linee3fe402017-03-13 10:00:42 -07001339 backend_tag_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("usb-headset");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001340 backend_tag_table[SND_DEVICE_OUT_VOICE_USB_HEADSET] = strdup("usb-headset");
David Linee3fe402017-03-13 10:00:42 -07001341 backend_tag_table[SND_DEVICE_OUT_USB_HEADPHONES] = strdup("usb-headphones");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001342 backend_tag_table[SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = strdup("usb-headphones");
David Linee3fe402017-03-13 10:00:42 -07001343 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] =
1344 strdup("speaker-and-usb-headphones");
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07001345 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] =
1346 strdup("speaker-safe-and-usb-headphones");
juyuchen5351ea62018-05-16 10:54:37 +08001347 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO] =
1348 strdup("speaker-safe-and-bt-sco"),
1349 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB] =
1350 strdup("speaker-safe-and-bt-sco-wb"),
David Linee3fe402017-03-13 10:00:42 -07001351 backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("usb-headset-mic");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001352 backend_tag_table[SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1353 backend_tag_table[SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1354 backend_tag_table[SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1355 backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = strdup("usb-headset-mic");
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001356 backend_tag_table[SND_DEVICE_OUT_BT_A2DP] = strdup("bt-a2dp");
1357 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] = strdup("speaker-and-bt-a2dp");
Aniket Kumar Lata9723a962018-05-16 17:41:55 -07001358 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP] = strdup("speaker-safe-and-bt-a2dp");
jasmine cha270b7762018-03-30 15:41:33 +08001359 backend_tag_table[SND_DEVICE_OUT_USB_HEADSET_SPEC] = strdup("usb-headset");
juyuchend194b432018-11-16 14:15:16 +08001360 backend_tag_table[SND_DEVICE_OUT_VOICE_HEARING_AID] = strdup("hearing-aid");
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001361
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001362 hw_interface_table[SND_DEVICE_OUT_HANDSET] = strdup("SLIMBUS_0_RX");
1363 hw_interface_table[SND_DEVICE_OUT_SPEAKER] = strdup("SLIMBUS_0_RX");
1364 hw_interface_table[SND_DEVICE_OUT_SPEAKER_REVERSE] = strdup("SLIMBUS_0_RX");
1365 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE] = strdup("SLIMBUS_0_RX");
1366 hw_interface_table[SND_DEVICE_OUT_HEADPHONES] = strdup("SLIMBUS_0_RX");
1367 hw_interface_table[SND_DEVICE_OUT_LINE] = strdup("SLIMBUS_0_RX");
1368 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001369 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001370 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001371 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001372 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET] = strdup("SLIMBUS_0_RX");
1373 hw_interface_table[SND_DEVICE_OUT_VOICE_HAC_HANDSET] = strdup("SLIMBUS_0_RX");
1374 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER] = strdup("SLIMBUS_0_RX");
1375 hw_interface_table[SND_DEVICE_OUT_VOICE_HEADPHONES] = strdup("SLIMBUS_0_RX");
yixuanjiang9536e672018-09-06 18:43:36 +08001376 hw_interface_table[SND_DEVICE_OUT_VOICE_HEADSET] = strdup("SLIMBUS_0_RX");
juyuchen66c4ecf2018-08-06 15:39:34 +08001377 hw_interface_table[SND_DEVICE_OUT_VOICE_MUSIC_TX] = strdup("VOICE_PLAYBACK_TX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001378 hw_interface_table[SND_DEVICE_OUT_VOICE_LINE] = strdup("SLIMBUS_0_RX");
1379 hw_interface_table[SND_DEVICE_OUT_HDMI] = strdup("HDMI_RX");
1380 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("SLIMBUS_0_RX-and-HDMI_RX");
1381 hw_interface_table[SND_DEVICE_OUT_BT_SCO] = strdup("SEC_AUX_PCM_RX");
1382 hw_interface_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("SEC_AUX_PCM_RX");
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001383 hw_interface_table[SND_DEVICE_OUT_BT_A2DP] = strdup("SLIMBUS_7_RX");
1384 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] =
1385 strdup("SLIMBUS_0_RX-and-SLIMBUS_7_RX");
Aniket Kumar Lata9723a962018-05-16 17:41:55 -07001386 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP] =
1387 strdup("SLIMBUS_0_RX-and-SLIMBUS_7_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001388 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = strdup("SLIMBUS_0_RX");
1389 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = strdup("SLIMBUS_0_RX");
1390 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = strdup("SLIMBUS_0_RX");
1391 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = strdup("SLIMBUS_0_RX");
David Linee3fe402017-03-13 10:00:42 -07001392 hw_interface_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("USB_AUDIO_RX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001393 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = strdup("USB_AUDIO_RX");
1394 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = strdup("USB_AUDIO_RX");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001395 hw_interface_table[SND_DEVICE_OUT_VOICE_USB_HEADSET] = strdup("USB_AUDIO_RX");
David Linee3fe402017-03-13 10:00:42 -07001396 hw_interface_table[SND_DEVICE_OUT_USB_HEADPHONES] = strdup("USB_AUDIO_RX");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001397 hw_interface_table[SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = strdup("USB_AUDIO_RX");
jasmine cha270b7762018-03-30 15:41:33 +08001398 hw_interface_table[SND_DEVICE_OUT_USB_HEADSET_SPEC] = strdup("USB_AUDIO_RX");
David Linee3fe402017-03-13 10:00:42 -07001399 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 -07001400 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 -07001401 hw_interface_table[SND_DEVICE_OUT_VOICE_TX] = strdup("AFE_PCM_RX");
1402 hw_interface_table[SND_DEVICE_OUT_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
1403 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
jasmine cha52284622018-03-23 17:21:35 +08001404 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = strdup("SLIMBUS_0_RX");
1405 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_BT_SCO] = strdup("SLIMBUS_0_RX-and-SEC_AUX_PCM_RX");
1406 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 +08001407 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO] = strdup("QUAT_TDM_RX_0-and-SLIMBUS_7_RX"),
1408 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB] = strdup("QUAT_TDM_RX_0-and-SLIMBUS_7_RX"),
juyuchend194b432018-11-16 14:15:16 +08001409 /* So far, primary hal doesn't support hearing aid device.
1410 Need snd_device to route voice call and use specific acdb tuning.
1411 Also, BT_RX is a virtual port to indicate bluetooth hearing aid. */
1412 hw_interface_table[SND_DEVICE_OUT_VOICE_HEARING_AID] = strdup("BT_RX"),
1413
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001414 hw_interface_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1415 hw_interface_table[SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1416 hw_interface_table[SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = strdup("USB_AUDIO_TX");
1417 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1418 hw_interface_table[SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1419 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = strdup("USB_AUDIO_TX");
1420 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = strdup("USB_AUDIO_TX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001421 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001422 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_AEC] = strdup("SLIMBUS_0_TX");
1423 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_NS] = strdup("SLIMBUS_0_TX");
1424 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1425 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC] = strdup("SLIMBUS_0_TX");
1426 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_AEC] = strdup("SLIMBUS_0_TX");
1427 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_NS] = strdup("SLIMBUS_0_TX");
1428 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1429 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001430 hw_interface_table[SND_DEVICE_IN_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001431 hw_interface_table[SND_DEVICE_IN_HEADSET_MIC_AEC] = strdup("SLIMBUS_0_TX");
Eric Laurent5f4ca952018-10-19 17:33:43 -07001432 hw_interface_table[SND_DEVICE_IN_CAMCORDER_LANDSCAPE] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001433 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC] = strdup("SLIMBUS_0_TX");
1434 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC_NS] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001435 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC_AEC] = strdup("SLIMBUS_0_TX");
1436 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001437 hw_interface_table[SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
1438 hw_interface_table[SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = strdup("SLIMBUS_0_TX");
David Lin93725722017-10-13 14:58:17 -07001439 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_MIC] = strdup("SLIMBUS_0_TX");
1440 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1441 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = strdup("SLIMBUS_0_TX");
1442 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = strdup("SLIMBUS_0_TX");
1443 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001444 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC] = strdup("SLIMBUS_0_TX");
1445 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_AEC] = strdup("SLIMBUS_0_TX");
1446 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_NS] = strdup("SLIMBUS_0_TX");
1447 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1448 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC] = strdup("SLIMBUS_0_TX");
1449 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_AEC] = strdup("SLIMBUS_0_TX");
1450 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_NS] = strdup("SLIMBUS_0_TX");
1451 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001452 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
1453 hw_interface_table[SND_DEVICE_IN_VOICE_DMIC] = strdup("SLIMBUS_0_TX");
1454 hw_interface_table[SND_DEVICE_IN_VOICE_DMIC_TMUS] = strdup("SLIMBUS_0_TX");
Vignesh Kulothungan64698822018-01-23 11:25:18 -08001455 hw_interface_table[SND_DEVICE_IN_SPEAKER_QMIC_NS] = strdup("SLIMBUS_0_TX");
1456 hw_interface_table[SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001457 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001458 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = strdup("SLIMBUS_0_TX");
1459 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001460 hw_interface_table[SND_DEVICE_IN_VOICE_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001461 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1462 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = strdup("SLIMBUS_0_TX");
1463 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1464 hw_interface_table[SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1465 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("SEC_AUX_PCM_TX");
1466 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("SEC_AUX_PCM_TX");
1467 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("SEC_AUX_PCM_TX");
1468 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("SEC_AUX_PCM_TX");
1469 hw_interface_table[SND_DEVICE_IN_VOICE_RX] = strdup("AFE_PCM_TX");
1470 hw_interface_table[SND_DEVICE_IN_THREE_MIC] = strdup("SLIMBUS_0_TX");
1471 hw_interface_table[SND_DEVICE_IN_QUAD_MIC] = strdup("SLIMBUS_0_TX");
1472 hw_interface_table[SND_DEVICE_IN_HANDSET_TMIC] = strdup("SLIMBUS_0_TX");
1473 hw_interface_table[SND_DEVICE_IN_HANDSET_QMIC] = strdup("SLIMBUS_0_TX");
1474 hw_interface_table[SND_DEVICE_IN_HANDSET_TMIC_AEC] = strdup("SLIMBUS_0_TX");
1475 hw_interface_table[SND_DEVICE_IN_HANDSET_QMIC_AEC] = strdup("SLIMBUS_0_TX");
Eric Laurent5f4ca952018-10-19 17:33:43 -07001476 hw_interface_table[SND_DEVICE_IN_CAMCORDER_INVERT_LANDSCAPE] = strdup("SLIMBUS_0_TX");
1477 hw_interface_table[SND_DEVICE_IN_CAMCORDER_PORTRAIT] = strdup("SLIMBUS_0_TX");
1478 hw_interface_table[SND_DEVICE_IN_CAMCORDER_SELFIE_LANDSCAPE] = strdup("SLIMBUS_0_TX");
1479 hw_interface_table[SND_DEVICE_IN_CAMCORDER_SELFIE_INVERT_LANDSCAPE] = strdup("SLIMBUS_0_TX");
1480 hw_interface_table[SND_DEVICE_IN_CAMCORDER_SELFIE_PORTRAIT] = strdup("SLIMBUS_0_TX");
juyuchend194b432018-11-16 14:15:16 +08001481 hw_interface_table[SND_DEVICE_IN_VOICE_HEARING_AID] = strdup("SLIMBUS_0_TX");
1482
Eric Laurentc6333382015-09-14 12:43:44 -07001483 my_data->max_mic_count = PLATFORM_DEFAULT_MIC_COUNT;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001484}
1485
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001486void get_cvd_version(char *cvd_version, struct audio_device *adev)
1487{
1488 struct mixer_ctl *ctl;
1489 int count;
1490 int ret = 0;
1491
1492 ctl = mixer_get_ctl_by_name(adev->mixer, CVD_VERSION_MIXER_CTL);
1493 if (!ctl) {
1494 ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__, CVD_VERSION_MIXER_CTL);
1495 goto done;
1496 }
1497 mixer_ctl_update(ctl);
1498
1499 count = mixer_ctl_get_num_values(ctl);
1500 if (count > MAX_CVD_VERSION_STRING_SIZE)
1501 count = MAX_CVD_VERSION_STRING_SIZE - 1;
1502
1503 ret = mixer_ctl_get_array(ctl, cvd_version, count);
1504 if (ret != 0) {
1505 ALOGE("%s: ERROR! mixer_ctl_get_array() failed to get CVD Version", __func__);
1506 goto done;
1507 }
1508
1509done:
1510 return;
1511}
1512
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001513static int platform_acdb_init(void *platform)
1514{
1515 struct platform_data *my_data = (struct platform_data *)platform;
1516 struct audio_device *adev = my_data->adev;
1517
1518 if (!my_data->acdb_init) {
1519 ALOGE("%s: no acdb_init fn provided", __func__);
1520 return -1;
1521 }
1522
1523 if (my_data->acdb_initialized) {
1524 ALOGW("acdb is already initialized");
1525 return 0;
1526 }
1527
Thierry Strudel07f96d12018-09-20 13:31:34 -07001528#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845) || (PLATFORM_SDM710) || (PLATFORM_SM8150)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001529 char *cvd_version = calloc(1, MAX_CVD_VERSION_STRING_SIZE);
1530 if (!cvd_version)
1531 ALOGE("failed to allocate cvd_version");
1532 else {
1533 get_cvd_version(cvd_version, adev);
1534 my_data->acdb_init((char *)my_data->snd_card_name, cvd_version, 0);
1535 free(cvd_version);
1536 }
1537#elif defined (PLATFORM_MSM8084)
1538 my_data->acdb_init((char *)my_data->snd_card_name);
1539#else
1540 my_data->acdb_init();
1541#endif
1542 my_data->acdb_initialized = true;
1543 return 0;
1544}
1545
David Linee3fe402017-03-13 10:00:42 -07001546static void
1547platform_backend_config_init(struct platform_data *pdata)
1548{
1549 int i;
1550
1551 /* initialize backend config */
1552 for (i = 0; i < MAX_CODEC_BACKENDS; i++) {
1553 pdata->current_backend_cfg[i].sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
1554 pdata->current_backend_cfg[i].bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
1555 pdata->current_backend_cfg[i].channels = CODEC_BACKEND_DEFAULT_CHANNELS;
1556
1557 if (i > MAX_RX_CODEC_BACKENDS)
1558 pdata->current_backend_cfg[i].channels = CODEC_BACKEND_DEFAULT_TX_CHANNELS;
1559
1560 pdata->current_backend_cfg[i].bitwidth_mixer_ctl = NULL;
1561 pdata->current_backend_cfg[i].samplerate_mixer_ctl = NULL;
1562 pdata->current_backend_cfg[i].channels_mixer_ctl = NULL;
1563 }
1564
1565 pdata->current_backend_cfg[DEFAULT_CODEC_BACKEND].bitwidth_mixer_ctl =
1566 strdup("SLIM_0_RX Format");
1567 pdata->current_backend_cfg[DEFAULT_CODEC_BACKEND].samplerate_mixer_ctl =
1568 strdup("SLIM_0_RX SampleRate");
1569
1570 pdata->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].bitwidth_mixer_ctl =
1571 strdup("SLIM_0_TX Format");
1572 pdata->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].samplerate_mixer_ctl =
1573 strdup("SLIM_0_TX SampleRate");
1574
1575 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].bitwidth_mixer_ctl =
1576 strdup("USB_AUDIO_TX Format");
1577 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].samplerate_mixer_ctl =
1578 strdup("USB_AUDIO_TX SampleRate");
1579 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].channels_mixer_ctl =
1580 strdup("USB_AUDIO_TX Channels");
1581
Yung Ti Su39a2b8a2018-10-05 15:43:40 +08001582 if (strstr(pdata->snd_card_name, "intcodec")) {
1583 pdata->current_backend_cfg[HEADPHONE_BACKEND].bitwidth_mixer_ctl =
1584 strdup("INT0_MI2S_RX Format");
1585 pdata->current_backend_cfg[HEADPHONE_BACKEND].samplerate_mixer_ctl =
1586 strdup("INT0_MI2S_RX SampleRate");
1587 } else {
1588 pdata->current_backend_cfg[HEADPHONE_BACKEND].bitwidth_mixer_ctl =
1589 strdup("SLIM_6_RX Format");
1590 pdata->current_backend_cfg[HEADPHONE_BACKEND].samplerate_mixer_ctl =
1591 strdup("SLIM_6_RX SampleRate");
1592 }
David Linee3fe402017-03-13 10:00:42 -07001593
1594 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].bitwidth_mixer_ctl =
1595 strdup("USB_AUDIO_RX Format");
1596 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].samplerate_mixer_ctl =
1597 strdup("USB_AUDIO_RX SampleRate");
1598
1599 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].channels = 1;
1600 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].channels_mixer_ctl =
1601 strdup("USB_AUDIO_RX Channels");
1602}
1603
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001604static int
1605platform_backend_app_type_cfg_init(struct platform_data *pdata,
1606 struct mixer *mixer)
1607{
1608 size_t app_type_cfg[128] = {0};
1609 int length, num_app_types = 0;
1610 struct mixer_ctl *ctl = NULL;
1611
1612 const char *mixer_ctl_name = "App Type Config";
1613 ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name);
1614 if (!ctl) {
1615 ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name);
1616 return -1;
1617 }
1618
1619 length = 1; // reserve index 0 for number of app types
1620
1621 struct listnode *node;
1622 struct app_type_entry *entry;
1623 list_for_each(node, &app_type_entry_list) {
1624 entry = node_to_item(node, struct app_type_entry, node);
1625 app_type_cfg[length++] = entry->app_type;
1626 app_type_cfg[length++] = entry->max_rate;
1627 app_type_cfg[length++] = entry->bit_width;
1628 ALOGI("%s add entry %d %d", __func__, entry->app_type, entry->bit_width);
1629 num_app_types += 1;
1630 }
1631
1632 // default for capture
1633 int t;
1634 platform_get_default_app_type_v2(pdata,
1635 PCM_CAPTURE,
1636 &t);
1637 app_type_cfg[length++] = t;
1638 app_type_cfg[length++] = 48000;
1639 app_type_cfg[length++] = 16;
1640 num_app_types += 1;
1641
1642 if (num_app_types) {
1643 app_type_cfg[0] = num_app_types;
1644 if (mixer_ctl_set_array(ctl, app_type_cfg, length) < 0) {
1645 ALOGE("Failed to set app type cfg");
1646 }
1647 }
1648 return 0;
1649}
1650
Xu Han1638fd12018-04-20 12:42:23 -07001651static void configure_flicker_sensor_input(struct mixer *mixer)
1652{
1653 struct mixer_ctl *ctl;
1654 const char* ctl1 = "AIF3_CAP Mixer SLIM TX2";
1655 int setting1 = 1;
1656 const char* ctl2 = "CDC_IF TX2 MUX";
1657 const char* setting2 = "DEC2";
1658 const char* ctl3 = "SLIM_1_TX Channels";
1659 const char* setting3 = "One";
1660 const char* ctl4 = "ADC MUX2";
1661 const char* setting4 = "AMIC";
1662 const char* ctl5 = "AMIC MUX2";
1663 const char* setting5 = "ADC1";
1664 const char* ctl6 = "DEC2 Volume";
1665 int setting6 = 84;
Xu Han07e07402018-05-15 14:19:25 -07001666 const char* ctl7 = "MultiMedia9 Mixer SLIM_1_TX";
Xu Han1638fd12018-04-20 12:42:23 -07001667 int setting7 = 1;
1668 const char* ctl8 = "SLIM_1_TX SampleRate";
1669 const char* setting8 = "KHZ_8";
1670
1671 ctl = mixer_get_ctl_by_name(mixer, ctl1);
1672 mixer_ctl_set_value(ctl, 0, setting1);
1673 ctl = mixer_get_ctl_by_name(mixer, ctl2);
1674 mixer_ctl_set_enum_by_string(ctl, setting2);
1675 ctl = mixer_get_ctl_by_name(mixer, ctl3);
1676 mixer_ctl_set_enum_by_string(ctl, setting3);
1677 ctl = mixer_get_ctl_by_name(mixer, ctl4);
1678 mixer_ctl_set_enum_by_string(ctl, setting4);
1679 ctl = mixer_get_ctl_by_name(mixer, ctl5);
1680 mixer_ctl_set_enum_by_string(ctl, setting5);
1681 ctl = mixer_get_ctl_by_name(mixer, ctl6);
1682 mixer_ctl_set_value(ctl, 0, setting6);
1683 ctl = mixer_get_ctl_by_name(mixer, ctl7);
1684 mixer_ctl_set_value(ctl, 0, setting7);
1685 ctl = mixer_get_ctl_by_name(mixer, ctl8);
1686 mixer_ctl_set_enum_by_string(ctl, setting8);
1687}
1688
Eric Laurentb23d5282013-05-14 15:27:20 -07001689void *platform_init(struct audio_device *adev)
1690{
1691 char value[PROPERTY_VALUE_MAX];
vivek mehta60ea4152016-02-18 17:10:26 -08001692 struct platform_data *my_data = NULL;
1693 int retry_num = 0, snd_card_num = 0, key = 0, ret = 0;
1694 bool dual_mic_config = false, use_default_mixer_path = true;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001695 const char *snd_card_name;
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001696 char *cvd_version = NULL;
vivek mehta60ea4152016-02-18 17:10:26 -08001697 char *snd_internal_name = NULL;
1698 char *tmp = NULL;
1699 char mixer_xml_file[MIXER_PATH_MAX_LENGTH]= {0};
vivek mehtade4849c2016-03-03 17:23:38 -08001700 char platform_info_file[MIXER_PATH_MAX_LENGTH]= {0};
1701 struct snd_card_split *snd_split_handle = NULL;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001702 my_data = calloc(1, sizeof(struct platform_data));
1703
1704 my_data->adev = adev;
1705
keunhui.park2f7306a2015-07-16 16:48:06 +09001706 list_init(&operator_info_list);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001707 list_init(&app_type_entry_list);
keunhui.park2f7306a2015-07-16 16:48:06 +09001708
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001709 set_platform_defaults(my_data);
1710
vivek mehta0fb11312017-05-15 19:35:32 -07001711 // audio_extn_utils_get_snd_card_num does
1712 // - open mixer and get snd card name
1713 // - parse platform info xml file and check for valid snd card name
1714 // - on failure loop through all the active snd card
sangwoo1b9f4b32013-06-21 18:22:55 -07001715
vivek mehta0fb11312017-05-15 19:35:32 -07001716 snd_card_num = audio_extn_utils_get_snd_card_num();
1717 if (-1 == snd_card_num) {
1718 ALOGE("%s: invalid sound card number (-1), bailing out ", __func__);
1719 goto init_failed;
sangwoo1b9f4b32013-06-21 18:22:55 -07001720 }
1721
vivek mehta0fb11312017-05-15 19:35:32 -07001722 adev->mixer = mixer_open(snd_card_num);
1723 snd_card_name = mixer_get_name(adev->mixer);
1724 my_data->hw_info = hw_info_init(snd_card_name);
1725
1726 audio_extn_set_snd_card_split(snd_card_name);
1727 snd_split_handle = audio_extn_get_snd_card_split();
1728
1729 /* Get the codec internal name from the sound card and/or form factor
1730 * name and form the mixer paths and platfor info file name dynamically.
1731 * This is generic way of picking any codec and forma factor name based
1732 * mixer and platform info files in future with no code change.
1733
1734 * current code extends and looks for any of the exteneded mixer path and
1735 * platform info file present based on codec and form factor.
1736
1737 * order of picking appropriate file is
1738 * <i> mixer_paths_<codec_name>_<form_factor>.xml, if file not present
1739 * <ii> mixer_paths_<codec_name>.xml, if file not present
1740 * <iii> mixer_paths.xml
1741
1742 * same order is followed for audio_platform_info.xml as well
1743 */
1744
1745 // need to carryforward old file name
1746 if (!strncmp(snd_card_name, TOMTOM_8226_SND_CARD_NAME,
1747 min(strlen(TOMTOM_8226_SND_CARD_NAME), strlen(snd_card_name)))) {
1748 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1749 MIXER_XML_BASE_STRING, TOMTOM_MIXER_FILE_SUFFIX );
1750 } else {
1751
1752 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s_%s.xml",
1753 MIXER_XML_BASE_STRING, snd_split_handle->snd_card,
1754 snd_split_handle->form_factor);
1755 if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) {
1756 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1757 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1758 MIXER_XML_BASE_STRING, snd_split_handle->snd_card);
1759
1760 if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) {
1761 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1762 strlcpy(mixer_xml_file, MIXER_XML_DEFAULT_PATH, MIXER_PATH_MAX_LENGTH);
1763 audio_extn_utils_resolve_config_file(mixer_xml_file);
1764 }
1765 }
1766 }
1767
1768 audio_extn_utils_get_platform_info(snd_card_name, platform_info_file);
1769
jiabin8962a4d2018-03-19 18:21:24 -07001770 my_data->declared_mic_count = 0;
vivek mehta0fb11312017-05-15 19:35:32 -07001771 /* Initialize platform specific ids and/or backends*/
juyuchenbf6571f2018-11-30 18:50:47 +08001772 platform_info_init(platform_info_file, my_data,
1773 true, &platform_set_parameters);
vivek mehta0fb11312017-05-15 19:35:32 -07001774
1775 ALOGD("%s: Loading mixer file: %s", __func__, mixer_xml_file);
1776 adev->audio_route = audio_route_init(snd_card_num, mixer_xml_file);
1777
1778 if (!adev->audio_route) {
1779 ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
1780 mixer_close(adev->mixer);
1781 adev->mixer = NULL;
1782 hw_info_deinit(my_data->hw_info);
1783 my_data->hw_info = NULL;
1784 goto init_failed;
1785 }
1786 adev->snd_card = snd_card_num;
1787 ALOGD("%s: Opened sound card:%d", __func__, snd_card_num);
1788
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09001789 //set max volume step for voice call
1790 property_get("ro.config.vc_call_vol_steps", value, TOSTRING(MAX_VOL_INDEX));
1791 my_data->max_vol_index = atoi(value);
1792
vivek mehta65ad12d2015-08-13 18:32:48 -07001793 property_get("persist.audio.dualmic.config",value,"");
1794 if (!strcmp("endfire", value)) {
1795 dual_mic_config = true;
1796 }
1797
John Muir9e59a962018-01-10 13:30:00 -08001798 my_data->source_mic_type = 0;
Prashant Malanic92c5962015-08-11 15:10:18 -07001799
Eric Laurentb23d5282013-05-14 15:27:20 -07001800 my_data->fluence_in_spkr_mode = false;
1801 my_data->fluence_in_voice_call = false;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001802 my_data->fluence_in_voice_comm = false;
Eric Laurentb23d5282013-05-14 15:27:20 -07001803 my_data->fluence_in_voice_rec = false;
1804
vivek mehta65ad12d2015-08-13 18:32:48 -07001805 property_get("ro.qc.sdk.audio.fluencetype", value, "none");
Prashant Malanic92c5962015-08-11 15:10:18 -07001806 if (!strcmp("fluencepro", value)) {
1807 my_data->fluence_type = FLUENCE_PRO_ENABLE;
vivek mehta65ad12d2015-08-13 18:32:48 -07001808 } else if (!strcmp("fluence", value) || (dual_mic_config)) {
Prashant Malanic92c5962015-08-11 15:10:18 -07001809 my_data->fluence_type = FLUENCE_ENABLE;
1810 } else if (!strcmp("none", value)) {
1811 my_data->fluence_type = FLUENCE_DISABLE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001812 }
1813
Prashant Malanic92c5962015-08-11 15:10:18 -07001814 if (my_data->fluence_type != FLUENCE_DISABLE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001815 property_get("persist.audio.fluence.voicecall",value,"");
1816 if (!strcmp("true", value)) {
1817 my_data->fluence_in_voice_call = true;
1818 }
1819
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001820 property_get("persist.audio.fluence.voicecomm",value,"");
1821 if (!strcmp("true", value)) {
1822 my_data->fluence_in_voice_comm = true;
1823 }
1824
Eric Laurentb23d5282013-05-14 15:27:20 -07001825 property_get("persist.audio.fluence.voicerec",value,"");
1826 if (!strcmp("true", value)) {
1827 my_data->fluence_in_voice_rec = true;
1828 }
1829
1830 property_get("persist.audio.fluence.speaker",value,"");
1831 if (!strcmp("true", value)) {
1832 my_data->fluence_in_spkr_mode = true;
1833 }
1834 }
1835
Prashant Malanic92c5962015-08-11 15:10:18 -07001836 // support max to mono, example if max count is 3, usecase supports Three, dual and mono mic
1837 switch (my_data->max_mic_count) {
1838 case 4:
1839 my_data->source_mic_type |= SOURCE_QUAD_MIC;
1840 case 3:
1841 my_data->source_mic_type |= SOURCE_THREE_MIC;
1842 case 2:
1843 my_data->source_mic_type |= SOURCE_DUAL_MIC;
1844 case 1:
1845 my_data->source_mic_type |= SOURCE_MONO_MIC;
1846 break;
1847 default:
1848 ALOGE("%s: max_mic_count (%d), is not supported, setting to default",
1849 __func__, my_data->max_mic_count);
1850 my_data->source_mic_type = SOURCE_MONO_MIC|SOURCE_DUAL_MIC;
1851 break;
1852 }
1853
1854 ALOGV("%s: Fluence_Type(%d) max_mic_count(%d) mic_type(0x%x) fluence_in_voice_call(%d)"
1855 " fluence_in_voice_comm(%d) fluence_in_voice_rec(%d) fluence_in_spkr_mode(%d) ",
1856 __func__, my_data->fluence_type, my_data->max_mic_count, my_data->source_mic_type,
1857 my_data->fluence_in_voice_call, my_data->fluence_in_voice_comm,
1858 my_data->fluence_in_voice_rec, my_data->fluence_in_spkr_mode);
1859
Eric Laurentb23d5282013-05-14 15:27:20 -07001860 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
1861 if (my_data->acdb_handle == NULL) {
1862 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
1863 } else {
1864 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
1865 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
1866 "acdb_loader_deallocate_ACDB");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001867 if (!my_data->acdb_deallocate)
1868 ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s",
1869 __func__, LIB_ACDB_LOADER);
1870
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001871 my_data->acdb_send_audio_cal_v3 = (acdb_send_audio_cal_v3_t)dlsym(my_data->acdb_handle,
1872 "acdb_loader_send_audio_cal_v3");
1873 if (!my_data->acdb_send_audio_cal_v3)
1874 ALOGE("%s: Could not find the symbol acdb_send_audio_cal_v3 from %s",
1875 __func__, LIB_ACDB_LOADER);
1876
Eric Laurentb23d5282013-05-14 15:27:20 -07001877 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
1878 "acdb_loader_send_audio_cal");
1879 if (!my_data->acdb_send_audio_cal)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001880 ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s",
Eric Laurentb23d5282013-05-14 15:27:20 -07001881 __func__, LIB_ACDB_LOADER);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001882
Eric Laurentb23d5282013-05-14 15:27:20 -07001883 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
1884 "acdb_loader_send_voice_cal");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001885 if (!my_data->acdb_send_voice_cal)
1886 ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s",
1887 __func__, LIB_ACDB_LOADER);
1888
1889 my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle,
1890 "acdb_loader_reload_vocvoltable");
1891 if (!my_data->acdb_reload_vocvoltable)
1892 ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s",
1893 __func__, LIB_ACDB_LOADER);
vivek mehta1a9b7c02015-06-25 11:49:38 -07001894
1895 my_data->acdb_send_gain_dep_cal = (acdb_send_gain_dep_cal_t)dlsym(my_data->acdb_handle,
1896 "acdb_loader_send_gain_dep_cal");
1897 if (!my_data->acdb_send_gain_dep_cal)
1898 ALOGV("%s: Could not find the symbol acdb_loader_send_gain_dep_cal from %s",
1899 __func__, LIB_ACDB_LOADER);
1900
Xu Han1638fd12018-04-20 12:42:23 -07001901#if defined (FLICKER_SENSOR_INPUT)
1902 configure_flicker_sensor_input(adev->mixer);
1903#endif
1904
Thierry Strudel07f96d12018-09-20 13:31:34 -07001905#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845) || (PLATFORM_SDM710) || (PLATFORM_SM8150)
vivek mehta0fb11312017-05-15 19:35:32 -07001906 acdb_init_v2_cvd_t acdb_init_local;
1907 acdb_init_local = (acdb_init_v2_cvd_t)dlsym(my_data->acdb_handle,
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001908 "acdb_loader_init_v2");
vivek mehta0fb11312017-05-15 19:35:32 -07001909 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001910 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1911 dlerror());
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001912
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001913#elif defined (PLATFORM_MSM8084)
vivek mehta0fb11312017-05-15 19:35:32 -07001914 acdb_init_v2_t acdb_init_local;
1915 acdb_init_local = (acdb_init_v2_t)dlsym(my_data->acdb_handle,
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001916 "acdb_loader_init_v2");
vivek mehta0fb11312017-05-15 19:35:32 -07001917 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001918 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1919 dlerror());
1920
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001921#else
vivek mehta0fb11312017-05-15 19:35:32 -07001922 acdb_init_t acdb_init_local;
1923 acdb_init_local = (acdb_init_t)dlsym(my_data->acdb_handle,
Eric Laurentb23d5282013-05-14 15:27:20 -07001924 "acdb_loader_init_ACDB");
vivek mehta0fb11312017-05-15 19:35:32 -07001925 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001926 ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__,
1927 dlerror());
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001928#endif
vivek mehta0fb11312017-05-15 19:35:32 -07001929 my_data->acdb_init = acdb_init_local;
Eric Laurentb23d5282013-05-14 15:27:20 -07001930
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001931 my_data->acdb_send_custom_top = (acdb_send_custom_top_t)
1932 dlsym(my_data->acdb_handle,
1933 "acdb_loader_send_common_custom_topology");
1934
1935 if (!my_data->acdb_send_custom_top)
1936 ALOGE("%s: Could not find the symbol acdb_get_default_app_type from %s",
1937 __func__, LIB_ACDB_LOADER);
1938
jasmine chac89321b2018-04-10 21:37:01 +08001939 my_data->acdb_set_audio_cal = (acdb_set_audio_cal_t)dlsym(my_data->acdb_handle,
1940 "acdb_loader_set_audio_cal_v2");
1941 if (!my_data->acdb_set_audio_cal)
1942 ALOGE("%s: Could not find the symbol acdb_set_audio_cal_v2 from %s",
1943 __func__, LIB_ACDB_LOADER);
1944
vivek mehta0fb11312017-05-15 19:35:32 -07001945 int result = acdb_init(adev->snd_card);
1946 if (!result) {
1947 my_data->acdb_initialized = true;
1948 ALOGD("ACDB initialized");
1949 } else {
1950 my_data->acdb_initialized = false;
1951 ALOGD("ACDB initialization failed");
1952 }
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001953 }
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001954
David Linee3fe402017-03-13 10:00:42 -07001955 /* init usb */
1956 audio_extn_usb_init(adev);
1957
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001958 /* init a2dp */
1959 audio_extn_a2dp_init(adev);
1960
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001961 audio_extn_spkr_prot_init(adev);
Haynes Mathew George98c95622014-06-20 19:14:25 -07001962
Ravi Kumar Alamanda76315572015-04-23 13:13:56 -07001963 audio_extn_hwdep_cal_send(adev->snd_card, my_data->acdb_handle);
1964
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001965 /* load csd client */
1966 platform_csd_init(my_data);
1967
David Linee3fe402017-03-13 10:00:42 -07001968 platform_backend_config_init(my_data);
1969
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001970 init_be_dai_name_table(adev);
1971
1972 if (platform_supports_app_type_cfg())
1973 platform_backend_app_type_cfg_init(my_data, adev->mixer);
1974
Eric Laurentb23d5282013-05-14 15:27:20 -07001975 return my_data;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001976
1977init_failed:
1978 if (my_data)
1979 free(my_data);
1980 return NULL;
Eric Laurentb23d5282013-05-14 15:27:20 -07001981}
1982
1983void platform_deinit(void *platform)
1984{
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001985 int32_t dev;
keunhui.park2f7306a2015-07-16 16:48:06 +09001986 struct operator_info *info_item;
1987 struct operator_specific_device *device_item;
Carter Hsu017c63a2018-10-15 15:01:42 -07001988 struct external_specific_device *ext_dev;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001989 struct app_type_entry *ap;
keunhui.park2f7306a2015-07-16 16:48:06 +09001990 struct listnode *node;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001991
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001992 struct platform_data *my_data = (struct platform_data *)platform;
1993 close_csd_client(my_data->csd);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001994
David Lin41b4fe42018-07-08 16:14:24 -07001995 audio_extn_spkr_prot_deinit(my_data->adev);
1996
vivek mehtade4849c2016-03-03 17:23:38 -08001997 hw_info_deinit(my_data->hw_info);
1998
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001999 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
2000 if (backend_tag_table[dev])
2001 free(backend_tag_table[dev]);
2002 if (hw_interface_table[dev])
2003 free(hw_interface_table[dev]);
keunhui.park2f7306a2015-07-16 16:48:06 +09002004 if (operator_specific_device_table[dev]) {
2005 while (!list_empty(operator_specific_device_table[dev])) {
2006 node = list_head(operator_specific_device_table[dev]);
2007 list_remove(node);
2008 device_item = node_to_item(node, struct operator_specific_device, list);
2009 free(device_item->operator);
2010 free(device_item->mixer_path);
2011 free(device_item);
2012 }
2013 free(operator_specific_device_table[dev]);
2014 }
Carter Hsu017c63a2018-10-15 15:01:42 -07002015
2016 if (external_specific_device_table[dev]) {
2017 while (!list_empty(external_specific_device_table[dev])) {
2018 node = list_head(external_specific_device_table[dev]);
2019 list_remove(node);
2020 ext_dev = node_to_item(node, struct external_specific_device, list);
2021 free(ext_dev->usbid);
2022 free(ext_dev);
2023 }
2024 free(external_specific_device_table[dev]);
2025 }
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002026 }
2027
2028 if (my_data->snd_card_name)
2029 free(my_data->snd_card_name);
2030
keunhui.park2f7306a2015-07-16 16:48:06 +09002031 while (!list_empty(&operator_info_list)) {
2032 node = list_head(&operator_info_list);
2033 list_remove(node);
2034 info_item = node_to_item(node, struct operator_info, list);
2035 free(info_item->name);
2036 free(info_item->mccmnc);
2037 free(info_item);
2038 }
2039
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002040 while (!list_empty(&app_type_entry_list)) {
2041 node = list_head(&app_type_entry_list);
2042 list_remove(node);
2043 ap = node_to_item(node, struct app_type_entry, node);
vivek mehtaa68fea62017-06-08 19:04:02 -07002044 if (ap->mode) free(ap->mode);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002045 free(ap);
2046 }
2047
Kevin Rocarde35d4af2017-05-02 16:55:28 -07002048 mixer_close(my_data->adev->mixer);
Eric Laurentb23d5282013-05-14 15:27:20 -07002049 free(platform);
David Linee3fe402017-03-13 10:00:42 -07002050
2051 /* deinit usb */
2052 audio_extn_usb_deinit();
Eric Laurentb23d5282013-05-14 15:27:20 -07002053}
2054
2055const char *platform_get_snd_device_name(snd_device_t snd_device)
2056{
keunhui.park2f7306a2015-07-16 16:48:06 +09002057 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
2058 if (operator_specific_device_table[snd_device] != NULL) {
2059 return get_operator_specific_device_mixer_path(snd_device);
2060 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002061 return device_table[snd_device];
keunhui.park2f7306a2015-07-16 16:48:06 +09002062 } else
Ravi Kumar Alamanda64026462014-09-15 00:08:58 -07002063 return "none";
Eric Laurentb23d5282013-05-14 15:27:20 -07002064}
2065
vivek mehtade4849c2016-03-03 17:23:38 -08002066int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
2067 char *device_name)
2068{
2069 struct platform_data *my_data = (struct platform_data *)platform;
2070
David Benjamin1565f992016-09-21 12:10:34 -04002071 if (platform == NULL) {
vivek mehtade4849c2016-03-03 17:23:38 -08002072 ALOGW("%s: something wrong, use legacy get_snd_device name", __func__);
David Benjamin1565f992016-09-21 12:10:34 -04002073 strlcpy(device_name, platform_get_snd_device_name(snd_device),
2074 DEVICE_NAME_MAX_SIZE);
vivek mehtade4849c2016-03-03 17:23:38 -08002075 } else if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
2076 if (operator_specific_device_table[snd_device] != NULL) {
2077 strlcpy(device_name, get_operator_specific_device_mixer_path(snd_device),
2078 DEVICE_NAME_MAX_SIZE);
2079 } else {
2080 strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE);
2081 }
2082 hw_info_append_hw_type(my_data->hw_info, snd_device, device_name);
2083 } else {
2084 strlcpy(device_name, "none", DEVICE_NAME_MAX_SIZE);
Aniket Kumar Lataa158e862018-05-11 17:28:40 -07002085 return -EINVAL;
vivek mehtade4849c2016-03-03 17:23:38 -08002086 }
2087
2088 return 0;
2089}
2090
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05002091void platform_add_backend_name(void *platform, char *mixer_path,
2092 snd_device_t snd_device)
Eric Laurentb23d5282013-05-14 15:27:20 -07002093{
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05002094 struct platform_data *my_data = (struct platform_data *)platform;
2095
Haynes Mathew George98c95622014-06-20 19:14:25 -07002096 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
2097 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
2098 return;
Ravi Kumar Alamanda1de6e5a2014-06-19 21:55:39 -05002099 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07002100
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002101 const char * suffix = backend_tag_table[snd_device];
Haynes Mathew George98c95622014-06-20 19:14:25 -07002102
2103 if (suffix != NULL) {
2104 strcat(mixer_path, " ");
2105 strcat(mixer_path, suffix);
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05002106 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002107}
2108
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002109bool platform_check_backends_match(snd_device_t snd_device1, snd_device_t snd_device2)
2110{
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002111 ALOGV("%s: snd_device1 = %s, snd_device2 = %s", __func__,
2112 platform_get_snd_device_name(snd_device1),
2113 platform_get_snd_device_name(snd_device2));
2114
2115 if ((snd_device1 < SND_DEVICE_MIN) || (snd_device1 >= SND_DEVICE_MAX)) {
2116 ALOGE("%s: Invalid snd_device = %s", __func__,
2117 platform_get_snd_device_name(snd_device1));
2118 return false;
2119 }
2120 if ((snd_device2 < SND_DEVICE_MIN) || (snd_device2 >= SND_DEVICE_MAX)) {
2121 ALOGE("%s: Invalid snd_device = %s", __func__,
2122 platform_get_snd_device_name(snd_device2));
2123 return false;
2124 }
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07002125
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002126 const char * be_itf1 = hw_interface_table[snd_device1];
2127 const char * be_itf2 = hw_interface_table[snd_device2];
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07002128 /*
2129 hw_interface_table has overrides for a snd_device.
2130 if there is no entry for a device, assume DEFAULT_RX_BACKEND
2131 */
2132 if (be_itf1 == NULL) {
2133 be_itf1 = DEFAULT_RX_BACKEND;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002134 }
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07002135 if (be_itf2 == NULL) {
2136 be_itf2 = DEFAULT_RX_BACKEND;
2137 }
2138 ALOGV("%s: be_itf1 = %s, be_itf2 = %s", __func__, be_itf1, be_itf2);
2139 /*
2140 this takes care of finding a device within a combo device pair as well
2141 */
2142 return strstr(be_itf1, be_itf2) != NULL || strstr(be_itf2, be_itf1) != NULL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002143}
2144
Eric Laurentb23d5282013-05-14 15:27:20 -07002145int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
2146{
2147 int device_id;
2148 if (device_type == PCM_PLAYBACK)
2149 device_id = pcm_device_table[usecase][0];
2150 else
2151 device_id = pcm_device_table[usecase][1];
2152 return device_id;
2153}
2154
Vignesh Kulothungan019d19b2019-01-23 11:09:18 -08002155int platform_get_haptics_pcm_device_id()
2156{
2157 return HAPTICS_PCM_DEVICE;
2158}
2159
Haynes Mathew George98c95622014-06-20 19:14:25 -07002160static int find_index(const struct name_to_index * table, int32_t len,
2161 const char * name)
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002162{
2163 int ret = 0;
Haynes Mathew George98c95622014-06-20 19:14:25 -07002164 int32_t i;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002165
Haynes Mathew George98c95622014-06-20 19:14:25 -07002166 if (table == NULL) {
2167 ALOGE("%s: table is NULL", __func__);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002168 ret = -ENODEV;
2169 goto done;
2170 }
2171
Haynes Mathew George98c95622014-06-20 19:14:25 -07002172 if (name == NULL) {
2173 ALOGE("null key");
2174 ret = -ENODEV;
2175 goto done;
2176 }
2177
2178 for (i=0; i < len; i++) {
2179 if (!strcmp(table[i].name, name)) {
2180 ret = table[i].index;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002181 goto done;
2182 }
2183 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07002184 ALOGE("%s: Could not find index for name = %s",
2185 __func__, name);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002186 ret = -ENODEV;
2187done:
2188 return ret;
2189}
2190
Haynes Mathew George98c95622014-06-20 19:14:25 -07002191int platform_get_snd_device_index(char *device_name)
2192{
2193 return find_index(snd_device_name_index, SND_DEVICE_MAX, device_name);
2194}
2195
2196int platform_get_usecase_index(const char *usecase_name)
2197{
2198 return find_index(usecase_name_index, AUDIO_USECASE_MAX, usecase_name);
2199}
2200
Vignesh Kulothungan64698822018-01-23 11:25:18 -08002201int platform_get_effect_config_data(snd_device_t snd_device,
2202 struct audio_effect_config *effect_config,
2203 effect_type_t effect_type)
2204{
2205 int ret = 0;
2206
2207 if ((snd_device < SND_DEVICE_IN_BEGIN) || (snd_device >= SND_DEVICE_MAX) ||
2208 (effect_type <= EFFECT_NONE) || (effect_type >= EFFECT_COUNT)) {
2209 ALOGE("%s: Invalid snd_device = %d or effect_type = %d",
2210 __func__, snd_device, effect_type);
2211 ret = -EINVAL;
2212 goto done;
2213 }
2214
2215 if (effect_config == NULL) {
2216 ALOGE("%s: Invalid effect_config", __func__);
2217 ret = -EINVAL;
2218 goto done;
2219 }
2220
2221 ALOGV("%s: snd_device = %d module_id = %d",
2222 __func__, snd_device, effect_config_table[GET_IN_DEVICE_INDEX(snd_device)][effect_type].module_id);
2223 *effect_config = effect_config_table[GET_IN_DEVICE_INDEX(snd_device)][effect_type];
2224
2225done:
2226 return ret;
2227}
2228
2229int platform_set_effect_config_data(snd_device_t snd_device,
2230 struct audio_effect_config effect_config,
2231 effect_type_t effect_type)
2232{
2233 int ret = 0;
2234
2235 if ((snd_device < SND_DEVICE_IN_BEGIN) || (snd_device >= SND_DEVICE_MAX) ||
2236 (effect_type <= EFFECT_NONE) || (effect_type >= EFFECT_COUNT)) {
2237 ALOGE("%s: Invalid snd_device = %d or effect_type = %d",
2238 __func__, snd_device, effect_type);
2239 ret = -EINVAL;
2240 goto done;
2241 }
2242
2243 ALOGV("%s 0x%x 0x%x 0x%x 0x%x", __func__, effect_config.module_id,
2244 effect_config.instance_id, effect_config.param_id,
2245 effect_config.param_value);
2246 effect_config_table[GET_IN_DEVICE_INDEX(snd_device)][effect_type] = effect_config;
2247
2248done:
2249 return ret;
2250}
2251
keunhui.park2f7306a2015-07-16 16:48:06 +09002252void platform_add_operator_specific_device(snd_device_t snd_device,
2253 const char *operator,
2254 const char *mixer_path,
2255 unsigned int acdb_id)
2256{
2257 struct operator_specific_device *device;
2258
2259 if (operator_specific_device_table[snd_device] == NULL) {
2260 operator_specific_device_table[snd_device] =
2261 (struct listnode *)calloc(1, sizeof(struct listnode));
2262 list_init(operator_specific_device_table[snd_device]);
2263 }
2264
2265 device = (struct operator_specific_device *)calloc(1, sizeof(struct operator_specific_device));
2266
2267 device->operator = strdup(operator);
2268 device->mixer_path = strdup(mixer_path);
2269 device->acdb_id = acdb_id;
2270
2271 list_add_tail(operator_specific_device_table[snd_device], &device->list);
2272
Eric Laurent2bafff12016-03-17 12:17:23 -07002273 ALOGD("%s: device[%s] -> operator[%s] mixer_path[%s] acdb_id[%d]", __func__,
keunhui.park2f7306a2015-07-16 16:48:06 +09002274 platform_get_snd_device_name(snd_device), operator, mixer_path, acdb_id);
2275
2276}
2277
Carter Hsu017c63a2018-10-15 15:01:42 -07002278void platform_add_external_specific_device(snd_device_t snd_device,
2279 const char *usbid,
2280 unsigned int acdb_id)
2281{
2282 struct external_specific_device *device;
2283
2284 if (external_specific_device_table[snd_device] == NULL) {
2285 external_specific_device_table[snd_device] =
2286 (struct listnode *)calloc(1, sizeof(struct listnode));
2287 list_init(external_specific_device_table[snd_device]);
2288 }
2289
2290 device = (struct external_specific_device *)calloc(1, sizeof(struct external_specific_device));
2291
2292 device->usbid = strdup(usbid);
2293 device->acdb_id = acdb_id;
2294
2295 list_add_tail(external_specific_device_table[snd_device], &device->list);
2296
2297 ALOGD("%s: device[%s] usbid[%s] -> acdb_id[%d]", __func__,
2298 platform_get_snd_device_name(snd_device), usbid, acdb_id);
2299}
2300
2301
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002302int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
2303{
2304 int ret = 0;
2305
2306 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
2307 ALOGE("%s: Invalid snd_device = %d",
2308 __func__, snd_device);
2309 ret = -EINVAL;
2310 goto done;
2311 }
2312
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002313 ALOGV("%s: acdb_device_table[%s]: old = %d new = %d", __func__,
2314 platform_get_snd_device_name(snd_device), acdb_device_table[snd_device], acdb_id);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002315 acdb_device_table[snd_device] = acdb_id;
2316done:
2317 return ret;
2318}
2319
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07002320int platform_get_snd_device_acdb_id(snd_device_t snd_device)
2321{
2322 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
2323 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
2324 return -EINVAL;
2325 }
keunhui.park2f7306a2015-07-16 16:48:06 +09002326
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002327 /*
2328 * If speaker protection is enabled, function returns supported
2329 * sound device for speaker. Else same sound device is returned.
2330 */
2331 snd_device = audio_extn_get_spkr_prot_snd_device(snd_device);
2332
keunhui.park2f7306a2015-07-16 16:48:06 +09002333 if (operator_specific_device_table[snd_device] != NULL)
2334 return get_operator_specific_device_acdb_id(snd_device);
Carter Hsu017c63a2018-10-15 15:01:42 -07002335 else if (external_specific_device_table[snd_device] != NULL)
2336 return get_external_specific_device_acdb_id(snd_device);
keunhui.park2f7306a2015-07-16 16:48:06 +09002337 else
2338 return acdb_device_table[snd_device];
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07002339}
2340
David Linee3fe402017-03-13 10:00:42 -07002341static int platform_get_backend_index(snd_device_t snd_device)
2342{
2343 int32_t port = DEFAULT_CODEC_BACKEND;
2344
2345 if (snd_device >= SND_DEVICE_OUT_BEGIN && snd_device < SND_DEVICE_OUT_END) {
2346 if (backend_tag_table[snd_device] != NULL) {
2347 if (strncmp(backend_tag_table[snd_device], "headphones",
2348 sizeof("headphones")) == 0)
2349 port = HEADPHONE_BACKEND;
2350 else if (strcmp(backend_tag_table[snd_device], "hdmi") == 0)
2351 port = HDMI_RX_BACKEND;
2352 else if ((strcmp(backend_tag_table[snd_device], "usb-headphones") == 0) ||
2353 (strcmp(backend_tag_table[snd_device], "usb-headset") == 0))
2354 port = USB_AUDIO_RX_BACKEND;
2355 }
2356 } else if (snd_device >= SND_DEVICE_IN_BEGIN && snd_device < SND_DEVICE_IN_END) {
2357 port = DEFAULT_CODEC_TX_BACKEND;
2358 if (backend_tag_table[snd_device] != NULL) {
2359 if (strcmp(backend_tag_table[snd_device], "usb-headset-mic") == 0)
2360 port = USB_AUDIO_TX_BACKEND;
2361 else if (strstr(backend_tag_table[snd_device], "bt-sco") != NULL)
2362 port = BT_SCO_TX_BACKEND;
2363 }
2364 } else {
2365 ALOGW("%s:napb: Invalid device - %d ", __func__, snd_device);
2366 }
2367
2368 ALOGV("%s:napb: backend port - %d device - %d ", __func__, port, snd_device);
2369
2370 return port;
2371}
2372
Eric Laurentb23d5282013-05-14 15:27:20 -07002373int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
2374{
2375 struct platform_data *my_data = (struct platform_data *)platform;
2376 int acdb_dev_id, acdb_dev_type;
2377
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002378 if (platform_supports_app_type_cfg()) // use v2 instead
2379 return -ENOSYS;
2380
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002381 acdb_dev_id = platform_get_snd_device_acdb_id(snd_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07002382 if (acdb_dev_id < 0) {
2383 ALOGE("%s: Could not find acdb id for device(%d)",
2384 __func__, snd_device);
2385 return -EINVAL;
2386 }
2387 if (my_data->acdb_send_audio_cal) {
Joe Onorato188b6222016-03-01 11:02:27 -08002388 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Eric Laurentb23d5282013-05-14 15:27:20 -07002389 __func__, snd_device, acdb_dev_id);
2390 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
2391 snd_device < SND_DEVICE_OUT_END)
2392 acdb_dev_type = ACDB_DEV_TYPE_OUT;
2393 else
2394 acdb_dev_type = ACDB_DEV_TYPE_IN;
2395 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
2396 }
2397 return 0;
2398}
2399
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002400int platform_send_audio_calibration_v2(void *platform, struct audio_usecase *usecase,
2401 int app_type, int sample_rate)
2402{
2403 struct platform_data *my_data = (struct platform_data *)platform;
2404 int acdb_dev_id, acdb_dev_type;
vivek mehta7e573672018-03-13 17:41:41 -07002405 int snd_device = usecase->out_snd_device;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002406 int new_snd_device[SND_DEVICE_OUT_END] = {0};
2407 int i, num_devices = 1;
2408
2409 if (!platform_supports_app_type_cfg()) // use v1 instead
2410 return -ENOSYS;
2411
vivek mehta7e573672018-03-13 17:41:41 -07002412 if ((usecase->type == PCM_HFP_CALL) || (usecase->type == PCM_CAPTURE))
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002413 snd_device = usecase->in_snd_device;
2414
2415 // skipped over get_spkr_prot_device
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002416 acdb_dev_id = platform_get_snd_device_acdb_id(snd_device);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002417 if (acdb_dev_id < 0) {
2418 ALOGE("%s: Could not find acdb id for device(%d)",
2419 __func__, snd_device);
2420 return -EINVAL;
2421 }
2422
2423 if (platform_can_split_snd_device(snd_device,
2424 &num_devices, new_snd_device) < 0) {
2425 new_snd_device[0] = snd_device;
2426 }
2427
2428 for (i = 0; i < num_devices; i++) {
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002429 acdb_dev_id = platform_get_snd_device_acdb_id(new_snd_device[i]);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002430 if (acdb_dev_id < 0) {
2431 ALOGE("%s: Could not find acdb id for device(%d)",
2432 __func__, new_snd_device[i]);
2433 return -EINVAL;
2434 }
2435 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
2436 __func__, new_snd_device[i], acdb_dev_id);
2437 if (new_snd_device[i] >= SND_DEVICE_OUT_BEGIN &&
2438 new_snd_device[i] < SND_DEVICE_OUT_END)
2439 acdb_dev_type = ACDB_DEV_TYPE_OUT;
2440 else
2441 acdb_dev_type = ACDB_DEV_TYPE_IN;
2442
2443 if (my_data->acdb_send_audio_cal_v3) {
2444 my_data->acdb_send_audio_cal_v3(acdb_dev_id, acdb_dev_type,
2445 app_type, sample_rate, i);
2446 } else if (my_data->acdb_send_audio_cal) {
2447 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type); // this version differs from internal
2448 }
2449 }
2450
2451 return 0;
2452}
2453
2454
Eric Laurentb23d5282013-05-14 15:27:20 -07002455int platform_switch_voice_call_device_pre(void *platform)
2456{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002457 struct platform_data *my_data = (struct platform_data *)platform;
2458 int ret = 0;
2459
2460 if (my_data->csd != NULL &&
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002461 voice_is_in_call(my_data->adev)) {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002462 /* This must be called before disabling mixer controls on APQ side */
2463 ret = my_data->csd->disable_device();
2464 if (ret < 0) {
2465 ALOGE("%s: csd_client_disable_device, failed, error %d",
2466 __func__, ret);
2467 }
2468 }
2469 return ret;
2470}
2471
2472int platform_switch_voice_call_enable_device_config(void *platform,
2473 snd_device_t out_snd_device,
2474 snd_device_t in_snd_device)
2475{
2476 struct platform_data *my_data = (struct platform_data *)platform;
2477 int acdb_rx_id, acdb_tx_id;
2478 int ret = 0;
2479
2480 if (my_data->csd == NULL)
2481 return ret;
2482
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002483 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
keunhui.park2f7306a2015-07-16 16:48:06 +09002484 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002485
2486 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
2487 ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
2488 if (ret < 0) {
2489 ALOGE("%s: csd_enable_device_config, failed, error %d",
2490 __func__, ret);
2491 }
2492 } else {
2493 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2494 acdb_rx_id, acdb_tx_id);
2495 }
2496
2497 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002498}
2499
2500int platform_switch_voice_call_device_post(void *platform,
2501 snd_device_t out_snd_device,
2502 snd_device_t in_snd_device)
2503{
2504 struct platform_data *my_data = (struct platform_data *)platform;
2505 int acdb_rx_id, acdb_tx_id;
2506
2507 if (my_data->acdb_send_voice_cal == NULL) {
2508 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
2509 } else {
keunhui.park2f7306a2015-07-16 16:48:06 +09002510 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
2511 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07002512
2513 if (acdb_rx_id > 0 && acdb_tx_id > 0)
2514 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
2515 else
2516 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2517 acdb_rx_id, acdb_tx_id);
2518 }
2519
2520 return 0;
2521}
2522
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002523int platform_switch_voice_call_usecase_route_post(void *platform,
2524 snd_device_t out_snd_device,
2525 snd_device_t in_snd_device)
2526{
2527 struct platform_data *my_data = (struct platform_data *)platform;
2528 int acdb_rx_id, acdb_tx_id;
2529 int ret = 0;
2530
2531 if (my_data->csd == NULL)
2532 return ret;
2533
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002534 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
keunhui.park2f7306a2015-07-16 16:48:06 +09002535 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002536
2537 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
2538 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
2539 my_data->adev->acdb_settings);
2540 if (ret < 0) {
2541 ALOGE("%s: csd_enable_device, failed, error %d", __func__, ret);
2542 }
2543 } else {
2544 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2545 acdb_rx_id, acdb_tx_id);
2546 }
2547
2548 return ret;
2549}
2550
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002551int platform_start_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07002552{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002553 struct platform_data *my_data = (struct platform_data *)platform;
2554 int ret = 0;
2555
2556 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002557 ret = my_data->csd->start_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002558 if (ret < 0) {
2559 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
2560 }
2561 }
2562 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002563}
2564
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002565int platform_stop_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07002566{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002567 struct platform_data *my_data = (struct platform_data *)platform;
2568 int ret = 0;
2569
2570 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002571 ret = my_data->csd->stop_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002572 if (ret < 0) {
2573 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
2574 }
2575 }
2576 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002577}
2578
Vignesh Kulothunganb6f0a9c2018-03-22 13:50:22 -07002579int platform_set_mic_break_det(void *platform, bool enable)
2580{
2581 int ret = 0;
2582 struct platform_data *my_data = (struct platform_data *)platform;
2583 struct audio_device *adev = my_data->adev;
2584 const char *mixer_ctl_name = "Voice Mic Break Enable";
2585 struct mixer_ctl *ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2586 if (!ctl) {
2587 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2588 __func__, mixer_ctl_name);
2589 return -EINVAL;
2590 }
2591
2592 ret = mixer_ctl_set_value(ctl, 0, enable);
2593 if(ret)
2594 ALOGE("%s: Failed to set mixer ctl: %s", __func__, mixer_ctl_name);
2595
2596 return ret;
2597}
2598
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002599int platform_get_sample_rate(void *platform, uint32_t *rate)
2600{
2601 struct platform_data *my_data = (struct platform_data *)platform;
2602 int ret = 0;
2603
2604 if (my_data->csd != NULL) {
2605 ret = my_data->csd->get_sample_rate(rate);
2606 if (ret < 0) {
2607 ALOGE("%s: csd_get_sample_rate error %d\n", __func__, ret);
2608 }
2609 }
2610 return ret;
2611}
2612
vivek mehtab6506412015-08-07 16:55:17 -07002613void platform_set_speaker_gain_in_combo(struct audio_device *adev,
2614 snd_device_t snd_device,
2615 bool enable)
2616{
2617 const char* name;
2618 switch (snd_device) {
2619 case SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES:
2620 if (enable)
2621 name = "spkr-gain-in-headphone-combo";
2622 else
2623 name = "speaker-gain-default";
2624 break;
2625 case SND_DEVICE_OUT_SPEAKER_AND_LINE:
2626 if (enable)
2627 name = "spkr-gain-in-line-combo";
2628 else
2629 name = "speaker-gain-default";
2630 break;
2631 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES:
2632 if (enable)
2633 name = "spkr-safe-gain-in-headphone-combo";
2634 else
2635 name = "speaker-safe-gain-default";
2636 break;
2637 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE:
2638 if (enable)
2639 name = "spkr-safe-gain-in-line-combo";
2640 else
2641 name = "speaker-safe-gain-default";
2642 break;
2643 default:
2644 return;
2645 }
2646
2647 audio_route_apply_and_update_path(adev->audio_route, name);
2648}
2649
Eric Laurentb23d5282013-05-14 15:27:20 -07002650int platform_set_voice_volume(void *platform, int volume)
2651{
2652 struct platform_data *my_data = (struct platform_data *)platform;
2653 struct audio_device *adev = my_data->adev;
2654 struct mixer_ctl *ctl;
sangwoo53b2cf02013-07-25 19:18:44 -07002655 const char *mixer_ctl_name = "Voice Rx Gain";
Nadav Barc46d0fa2017-12-24 14:50:37 +02002656 const char *mute_mixer_ctl_name = "Voice Rx Device Mute";
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002657 int vol_index = 0, ret = 0;
2658 uint32_t set_values[ ] = {0,
2659 ALL_SESSION_VSID,
2660 DEFAULT_VOLUME_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07002661
2662 // Voice volume levels are mapped to adsp volume levels as follows.
2663 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
2664 // But this values don't changed in kernel. So, below change is need.
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09002665 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, my_data->max_vol_index);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002666 set_values[0] = vol_index;
Eric Laurentb23d5282013-05-14 15:27:20 -07002667
2668 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2669 if (!ctl) {
2670 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2671 __func__, mixer_ctl_name);
2672 return -EINVAL;
2673 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002674 ALOGV("Setting voice volume index: %d", set_values[0]);
2675 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2676
Nadav Barc46d0fa2017-12-24 14:50:37 +02002677 // Send mute command in case volume index is max since indexes are inverted
2678 // for mixer controls.
2679 if (vol_index == my_data->max_vol_index) {
2680 set_values[0] = 1;
2681 }
2682 else {
2683 set_values[0] = 0;
2684 }
2685
2686 ctl = mixer_get_ctl_by_name(adev->mixer, mute_mixer_ctl_name);
2687 if (!ctl) {
2688 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2689 __func__, mute_mixer_ctl_name);
2690 return -EINVAL;
2691 }
2692 ALOGV("%s: Setting RX Device Mute to: %d", __func__, set_values[0]);
2693 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2694
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002695 if (my_data->csd != NULL) {
2696 ret = my_data->csd->volume(ALL_SESSION_VSID, volume,
2697 DEFAULT_VOLUME_RAMP_DURATION_MS);
2698 if (ret < 0) {
2699 ALOGE("%s: csd_volume error %d", __func__, ret);
2700 }
2701 }
2702 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002703}
2704
2705int platform_set_mic_mute(void *platform, bool state)
2706{
2707 struct platform_data *my_data = (struct platform_data *)platform;
2708 struct audio_device *adev = my_data->adev;
2709 struct mixer_ctl *ctl;
2710 const char *mixer_ctl_name = "Voice Tx Mute";
sangwoo53b2cf02013-07-25 19:18:44 -07002711 int ret = 0;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002712 uint32_t set_values[ ] = {0,
2713 ALL_SESSION_VSID,
2714 DEFAULT_MUTE_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07002715
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09002716 if (adev->mode != AUDIO_MODE_IN_CALL &&
2717 adev->mode != AUDIO_MODE_IN_COMMUNICATION)
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002718 return 0;
2719
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09002720 if (adev->enable_hfp)
2721 mixer_ctl_name = "HFP Tx Mute";
2722
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002723 set_values[0] = state;
2724 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2725 if (!ctl) {
2726 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2727 __func__, mixer_ctl_name);
2728 return -EINVAL;
2729 }
Arun Mirpuri0cc2f312018-05-29 17:26:07 -07002730 ALOGV("%s: Setting voice mute state: %d", __func__, state);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002731 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2732
2733 if (my_data->csd != NULL) {
2734 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state,
2735 DEFAULT_MUTE_RAMP_DURATION_MS);
sangwoo53b2cf02013-07-25 19:18:44 -07002736 if (ret < 0) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002737 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
sangwoo53b2cf02013-07-25 19:18:44 -07002738 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002739 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002740 return ret;
2741}
Eric Laurentb23d5282013-05-14 15:27:20 -07002742
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002743int platform_set_device_mute(void *platform, bool state, char *dir)
2744{
2745 struct platform_data *my_data = (struct platform_data *)platform;
2746 struct audio_device *adev = my_data->adev;
2747 struct mixer_ctl *ctl;
2748 char *mixer_ctl_name = NULL;
2749 int ret = 0;
2750 uint32_t set_values[ ] = {0,
2751 ALL_SESSION_VSID,
2752 0};
2753 if(dir == NULL) {
2754 ALOGE("%s: Invalid direction:%s", __func__, dir);
2755 return -EINVAL;
2756 }
2757
2758 if (!strncmp("rx", dir, sizeof("rx"))) {
2759 mixer_ctl_name = "Voice Rx Device Mute";
2760 } else if (!strncmp("tx", dir, sizeof("tx"))) {
2761 mixer_ctl_name = "Voice Tx Device Mute";
2762 } else {
2763 return -EINVAL;
2764 }
2765
2766 set_values[0] = state;
2767 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2768 if (!ctl) {
2769 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2770 __func__, mixer_ctl_name);
2771 return -EINVAL;
2772 }
2773
2774 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
2775 __func__,state, mixer_ctl_name);
2776 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2777
2778 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002779}
2780
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002781int platform_can_split_snd_device(snd_device_t snd_device,
2782 int *num_devices,
2783 snd_device_t *new_snd_devices)
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002784{
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002785 int ret = -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002786 if (NULL == num_devices || NULL == new_snd_devices) {
2787 ALOGE("%s: NULL pointer ..", __func__);
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002788 return -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002789 }
2790
2791 /*
2792 * If wired headset/headphones/line devices share the same backend
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002793 * with speaker/earpiece this routine returns -EINVAL.
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002794 */
2795 if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES &&
2796 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_HEADPHONES)) {
2797 *num_devices = 2;
2798 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2799 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002800 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002801 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_LINE &&
2802 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_LINE)) {
2803 *num_devices = 2;
2804 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2805 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002806 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002807 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES &&
2808 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_HEADPHONES)) {
2809 *num_devices = 2;
2810 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2811 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002812 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002813 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE &&
2814 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_LINE)) {
2815 *num_devices = 2;
2816 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2817 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002818 ret = 0;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002819 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO &&
2820 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2821 SND_DEVICE_OUT_BT_SCO)) {
2822 *num_devices = 2;
2823 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2824 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO;
2825 ret = 0;
juyuchen5351ea62018-05-16 10:54:37 +08002826 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO &&
2827 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE,
2828 SND_DEVICE_OUT_BT_SCO)) {
2829 *num_devices = 2;
2830 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2831 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO;
2832 ret = 0;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002833 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB &&
2834 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2835 SND_DEVICE_OUT_BT_SCO_WB)) {
2836 *num_devices = 2;
2837 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2838 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO_WB;
2839 ret = 0;
juyuchen5351ea62018-05-16 10:54:37 +08002840 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB &&
2841 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE,
2842 SND_DEVICE_OUT_BT_SCO_WB)) {
2843 *num_devices = 2;
2844 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2845 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO_WB;
2846 ret = 0;
David Linee3fe402017-03-13 10:00:42 -07002847 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET &&
2848 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_USB_HEADSET)) {
2849 *num_devices = 2;
2850 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2851 new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
2852 ret = 0;
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07002853 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET &&
2854 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_USB_HEADSET)) {
2855 *num_devices = 2;
2856 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2857 new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
2858 ret = 0;
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002859 } else if (SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP == snd_device &&
2860 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2861 SND_DEVICE_OUT_BT_A2DP)) {
2862 *num_devices = 2;
2863 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2864 new_snd_devices[1] = SND_DEVICE_OUT_BT_A2DP;
2865 ret = 0;
Aniket Kumar Lata9723a962018-05-16 17:41:55 -07002866 } else if (SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP == snd_device &&
2867 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE,
2868 SND_DEVICE_OUT_BT_A2DP)) {
2869 *num_devices = 2;
2870 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2871 new_snd_devices[1] = SND_DEVICE_OUT_BT_A2DP;
2872 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002873 }
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002874
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002875 return ret;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002876}
2877
Eric Laurentb23d5282013-05-14 15:27:20 -07002878snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
2879{
2880 struct platform_data *my_data = (struct platform_data *)platform;
2881 struct audio_device *adev = my_data->adev;
2882 audio_mode_t mode = adev->mode;
2883 snd_device_t snd_device = SND_DEVICE_NONE;
2884
2885 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
2886 if (devices == AUDIO_DEVICE_NONE ||
2887 devices & AUDIO_DEVICE_BIT_IN) {
2888 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
2889 goto exit;
2890 }
2891
Eric Laurent1b491552015-09-15 17:52:41 -07002892 if (popcount(devices) == 2) {
2893 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2894 AUDIO_DEVICE_OUT_SPEAKER) ||
2895 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2896 AUDIO_DEVICE_OUT_SPEAKER)) {
2897 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
2898 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2899 AUDIO_DEVICE_OUT_SPEAKER)) {
2900 snd_device = SND_DEVICE_OUT_SPEAKER_AND_LINE;
2901 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2902 AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
2903 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2904 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2905 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES;
2906 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2907 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2908 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE;
2909 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
2910 AUDIO_DEVICE_OUT_SPEAKER)) {
2911 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002912 } else if ((devices & AUDIO_DEVICE_OUT_ALL_SCO) &&
2913 ((devices & ~AUDIO_DEVICE_OUT_ALL_SCO) == AUDIO_DEVICE_OUT_SPEAKER)) {
2914 snd_device = adev->bt_wb_speech_enabled ?
2915 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB :
2916 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO;
juyuchen5351ea62018-05-16 10:54:37 +08002917 } else if ((devices & AUDIO_DEVICE_OUT_ALL_SCO) &&
2918 ((devices & ~AUDIO_DEVICE_OUT_ALL_SCO) == AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2919 snd_device = adev->bt_wb_speech_enabled ?
2920 SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB :
2921 SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO;
Eric Laurent99dab492017-06-17 15:19:08 -07002922 } else if ((devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
2923 AUDIO_DEVICE_OUT_SPEAKER)) ||
2924 (devices == (AUDIO_DEVICE_OUT_USB_HEADSET |
2925 AUDIO_DEVICE_OUT_SPEAKER))) {
David Linee3fe402017-03-13 10:00:42 -07002926 snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET;
Eric Laurentd0f7c262017-07-05 09:09:12 -07002927 } else if ((devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
2928 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) ||
2929 (devices == (AUDIO_DEVICE_OUT_USB_HEADSET |
2930 AUDIO_DEVICE_OUT_SPEAKER_SAFE))) {
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07002931 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET;
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002932 } else if ((devices & AUDIO_DEVICE_OUT_SPEAKER) &&
2933 (devices & AUDIO_DEVICE_OUT_ALL_A2DP)) {
2934 snd_device = SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP;
Aniket Kumar Lata9723a962018-05-16 17:41:55 -07002935 } else if ((devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) &&
2936 (devices & AUDIO_DEVICE_OUT_ALL_A2DP)) {
2937 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP;
Eric Laurent1b491552015-09-15 17:52:41 -07002938 } else {
2939 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
2940 goto exit;
2941 }
2942 if (snd_device != SND_DEVICE_NONE) {
2943 goto exit;
2944 }
2945 }
2946
2947 if (popcount(devices) != 1) {
2948 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
2949 goto exit;
2950 }
2951
Madhuri Athota3f6051b2016-10-13 23:25:38 +05302952 if (voice_is_in_call(adev) || adev->enable_voicerx || audio_extn_hfp_is_active(adev)) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002953 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002954 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2955 devices & AUDIO_DEVICE_OUT_LINE) {
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002956 if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002957 (adev->voice.tty_mode == TTY_MODE_FULL))
Eric Laurentb23d5282013-05-14 15:27:20 -07002958 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002959 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002960 (adev->voice.tty_mode == TTY_MODE_VCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002961 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002962 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002963 (adev->voice.tty_mode == TTY_MODE_HCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002964 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002965 else {
2966 if (devices & AUDIO_DEVICE_OUT_LINE)
2967 snd_device = SND_DEVICE_OUT_VOICE_LINE;
yixuanjiang9536e672018-09-06 18:43:36 +08002968 else if (devices & AUDIO_DEVICE_OUT_WIRED_HEADSET)
2969 snd_device = SND_DEVICE_OUT_VOICE_HEADSET;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002970 else
2971 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
2972 }
Eric Laurent99dab492017-06-17 15:19:08 -07002973 } else if (audio_is_usb_out_device(devices)) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002974 if (voice_is_in_call(adev)) {
2975 switch (adev->voice.tty_mode) {
2976 case TTY_MODE_FULL:
2977 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_USB;
2978 break;
2979 case TTY_MODE_VCO:
2980 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_USB;
2981 break;
2982 case TTY_MODE_HCO:
2983 // since Hearing will be on handset\speaker, use existing device
2984 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
2985 break;
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002986 case TTY_MODE_OFF:
2987 break;
vivek mehtaa6b79742017-03-09 15:40:43 -08002988 default:
2989 ALOGE("%s: Invalid TTY mode (%#x)",
2990 __func__, adev->voice.tty_mode);
2991 }
2992 }
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002993 if (snd_device == SND_DEVICE_NONE) {
2994 snd_device = audio_extn_usb_is_capture_supported() ?
2995 SND_DEVICE_OUT_VOICE_USB_HEADSET :
2996 SND_DEVICE_OUT_VOICE_USB_HEADPHONES;
2997 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002998 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002999 if (adev->bt_wb_speech_enabled) {
3000 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
3001 } else {
3002 snd_device = SND_DEVICE_OUT_BT_SCO;
3003 }
Aniket Kumar Lata26483012018-01-31 20:21:42 -08003004 } else if (devices & AUDIO_DEVICE_OUT_ALL_A2DP) {
3005 snd_device = SND_DEVICE_OUT_BT_A2DP;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07003006 } else if (devices & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07003007 if (!adev->enable_hfp) {
3008 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
3009 } else {
3010 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_HFP;
3011 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003012 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05003013 if(adev->voice.hac)
3014 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
3015 else if (is_operator_tmus())
Eric Laurentb23d5282013-05-14 15:27:20 -07003016 snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS;
3017 else
Eric Laurentb4d368e2014-06-25 10:21:54 -05003018 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
juyuchend194b432018-11-16 14:15:16 +08003019 } else if (devices & AUDIO_DEVICE_OUT_TELEPHONY_TX) {
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07003020 snd_device = SND_DEVICE_OUT_VOICE_TX;
juyuchend194b432018-11-16 14:15:16 +08003021 } else if (devices & AUDIO_DEVICE_OUT_HEARING_AID) {
3022 snd_device = SND_DEVICE_OUT_VOICE_HEARING_AID;
3023 }
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07003024
Eric Laurentb23d5282013-05-14 15:27:20 -07003025 if (snd_device != SND_DEVICE_NONE) {
3026 goto exit;
3027 }
3028 }
3029
Eric Laurentb23d5282013-05-14 15:27:20 -07003030 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
3031 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
3032 snd_device = SND_DEVICE_OUT_HEADPHONES;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05003033 } else if (devices & AUDIO_DEVICE_OUT_LINE) {
3034 snd_device = SND_DEVICE_OUT_LINE;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07003035 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) {
3036 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE;
Eric Laurentb23d5282013-05-14 15:27:20 -07003037 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
andysu5b30b062018-04-20 16:34:06 +08003038 /*
3039 * Perform device switch only if acdb tuning is different between SPEAKER & SPEAKER_REVERSE,
3040 * Or there will be a small pause while performing device switch.
3041 */
3042 if (my_data->speaker_lr_swap &&
3043 (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
3044 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]))
Eric Laurentb23d5282013-05-14 15:27:20 -07003045 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
3046 else
3047 snd_device = SND_DEVICE_OUT_SPEAKER;
3048 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003049 if (adev->bt_wb_speech_enabled) {
3050 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
3051 } else {
3052 snd_device = SND_DEVICE_OUT_BT_SCO;
3053 }
Aniket Kumar Lata26483012018-01-31 20:21:42 -08003054 } else if (devices & AUDIO_DEVICE_OUT_ALL_A2DP) {
3055 snd_device = SND_DEVICE_OUT_BT_A2DP;
Eric Laurentb23d5282013-05-14 15:27:20 -07003056 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
3057 snd_device = SND_DEVICE_OUT_HDMI ;
Eric Laurent99dab492017-06-17 15:19:08 -07003058 } else if (audio_is_usb_out_device(devices)) {
jasmine cha270b7762018-03-30 15:41:33 +08003059 if (audio_extn_ma_supported_usb())
3060 snd_device = SND_DEVICE_OUT_USB_HEADSET_SPEC;
3061 else if (audio_extn_usb_is_capture_supported())
David Linee3fe402017-03-13 10:00:42 -07003062 snd_device = SND_DEVICE_OUT_USB_HEADSET;
3063 else
3064 snd_device = SND_DEVICE_OUT_USB_HEADPHONES;
3065 }else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05003066 /*HAC support for voice-ish audio (eg visual voicemail)*/
3067 if(adev->voice.hac)
3068 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
3069 else
3070 snd_device = SND_DEVICE_OUT_HANDSET;
Eric Laurentb23d5282013-05-14 15:27:20 -07003071 } else {
3072 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
3073 }
3074exit:
3075 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
3076 return snd_device;
3077}
3078
Vignesh Kulothungan64698822018-01-23 11:25:18 -08003079#ifdef DYNAMIC_ECNS_ENABLED
3080static snd_device_t get_snd_device_for_voice_comm(struct platform_data *my_data,
3081 struct stream_in *in __unused,
3082 audio_devices_t out_device,
3083 audio_devices_t in_device)
3084{
3085 struct audio_device *adev = my_data->adev;
3086 snd_device_t snd_device = SND_DEVICE_NONE;
3087
3088 if (my_data->fluence_type != FLUENCE_DISABLE) {
3089 switch(AUDIO_DEVICE_BIT_IN | in_device) {
3090 case AUDIO_DEVICE_IN_BACK_MIC:
3091 if (my_data->fluence_in_spkr_mode) {
3092 if ((my_data->fluence_type & FLUENCE_PRO_ENABLE) &&
3093 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
3094 snd_device = SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS;
3095 } else if (((my_data->fluence_type & FLUENCE_PRO_ENABLE) ||
3096 (my_data->fluence_type & FLUENCE_ENABLE)) &&
3097 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
3098 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
3099 }
3100 adev->acdb_settings |= DMIC_FLAG;
3101 } else
3102 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
3103 break;
3104 case AUDIO_DEVICE_IN_BUILTIN_MIC:
3105 if (((my_data->fluence_type & FLUENCE_PRO_ENABLE) ||
3106 (my_data->fluence_type & FLUENCE_ENABLE)) &&
3107 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
3108 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
3109 adev->acdb_settings |= DMIC_FLAG;
3110 } else
3111 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
3112 break;
3113 default:
3114 ALOGE("%s: Unsupported in_device %#x", __func__, in_device);
3115 break;
3116 }
3117 platform_set_echo_reference(adev, true, out_device);
3118 }
3119
3120 return snd_device;
3121}
3122#else
3123static snd_device_t get_snd_device_for_voice_comm(struct platform_data *my_data,
3124 struct stream_in *in,
3125 audio_devices_t out_device,
3126 audio_devices_t in_device)
3127{
3128 struct audio_device *adev = my_data->adev;
3129 snd_device_t snd_device = SND_DEVICE_NONE;
3130
3131 if (in->enable_aec &&
3132 in->enable_ns) {
3133 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
3134 if (my_data->fluence_in_spkr_mode &&
3135 my_data->fluence_in_voice_comm &&
3136 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
3137 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
3138 } else {
3139 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
3140 }
3141 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
3142 if (my_data->fluence_in_voice_comm &&
3143 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
3144 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
3145 } else {
3146 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
3147 }
3148 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3149 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
3150 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
3151 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
3152 }
3153 platform_set_echo_reference(adev, true, out_device);
3154 } else if (in->enable_aec) {
3155 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
3156 if (my_data->fluence_in_spkr_mode &&
3157 my_data->fluence_in_voice_comm &&
3158 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
3159 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
3160 } else {
3161 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
3162 }
3163 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
3164 if (my_data->fluence_in_voice_comm &&
3165 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
3166 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
3167 } else {
3168 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
3169 }
3170 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3171 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
3172 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
3173 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
3174 }
3175 platform_set_echo_reference(adev, true, out_device);
3176 } else if (in->enable_ns) {
3177 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
3178 if (my_data->fluence_in_spkr_mode &&
3179 my_data->fluence_in_voice_comm &&
3180 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
3181 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
3182 } else {
3183 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
3184 }
3185 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
3186 if (my_data->fluence_in_voice_comm &&
3187 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
3188 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
3189 } else {
3190 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
3191 }
3192 }
3193 }
3194
3195 return snd_device;
3196}
3197#endif //DYNAMIC_ECNS_ENABLED
3198
Eric Laurentd1b7a9b2018-11-15 12:24:31 -08003199snd_device_t platform_get_input_snd_device(void *platform,
3200 struct stream_in *in,
3201 audio_devices_t out_device)
Eric Laurentb23d5282013-05-14 15:27:20 -07003202{
3203 struct platform_data *my_data = (struct platform_data *)platform;
3204 struct audio_device *adev = my_data->adev;
Eric Laurentd1b7a9b2018-11-15 12:24:31 -08003205 audio_mode_t mode = adev->mode;
Eric Laurentb23d5282013-05-14 15:27:20 -07003206 snd_device_t snd_device = SND_DEVICE_NONE;
Eric Laurentd1b7a9b2018-11-15 12:24:31 -08003207
3208 if (in == NULL) {
3209 in = adev_get_active_input(adev);
3210 }
3211
3212 audio_source_t source = (in == NULL) ? AUDIO_SOURCE_DEFAULT : in->source;
3213 audio_devices_t in_device =
3214 ((in == NULL) ? AUDIO_DEVICE_NONE : in->device) & ~AUDIO_DEVICE_BIT_IN;
3215 audio_channel_mask_t channel_mask = (in == NULL) ? AUDIO_CHANNEL_IN_MONO : in->channel_mask;
3216 int channel_count = audio_channel_count_from_in_mask(channel_mask);
Eric Laurentb23d5282013-05-14 15:27:20 -07003217
Prashant Malanic92c5962015-08-11 15:10:18 -07003218 ALOGV("%s: enter: out_device(%#x) in_device(%#x) channel_count (%d) channel_mask (0x%x)",
3219 __func__, out_device, in_device, channel_count, channel_mask);
Eric Laurentd1b7a9b2018-11-15 12:24:31 -08003220
Devin Kimd789e432016-10-26 15:07:27 -07003221 if ((out_device != AUDIO_DEVICE_NONE) && (voice_is_in_call(adev) ||
3222 audio_extn_hfp_is_active(adev))) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07003223 if (adev->voice.tty_mode != TTY_MODE_OFF) {
Eric Laurentb23d5282013-05-14 15:27:20 -07003224 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05003225 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
3226 out_device & AUDIO_DEVICE_OUT_LINE) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07003227 switch (adev->voice.tty_mode) {
vivek mehtaa6b79742017-03-09 15:40:43 -08003228 case TTY_MODE_FULL:
3229 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
3230 break;
3231 case TTY_MODE_VCO:
3232 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
3233 break;
3234 case TTY_MODE_HCO:
3235 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
3236 break;
3237 default:
3238 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
3239 }
3240 goto exit;
Eric Laurent99dab492017-06-17 15:19:08 -07003241 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
vivek mehtaa6b79742017-03-09 15:40:43 -08003242 switch (adev->voice.tty_mode) {
3243 case TTY_MODE_FULL:
3244 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC;
3245 break;
3246 case TTY_MODE_VCO:
3247 // since voice will be captured from handset mic, use existing device
3248 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
3249 break;
3250 case TTY_MODE_HCO:
3251 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC;
3252 break;
3253 default:
3254 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
Eric Laurentb23d5282013-05-14 15:27:20 -07003255 }
3256 goto exit;
3257 }
3258 }
Eric Laurentb991fb02014-08-29 15:23:17 -05003259 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07003260 if (my_data->fluence_in_voice_call == false) {
3261 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3262 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003263 if (is_operator_tmus())
3264 snd_device = SND_DEVICE_IN_VOICE_DMIC_TMUS;
Eric Laurentb23d5282013-05-14 15:27:20 -07003265 else
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003266 snd_device = SND_DEVICE_IN_VOICE_DMIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07003267 }
3268 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
3269 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
3270 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003271 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003272 if (adev->bluetooth_nrec)
3273 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
3274 else
3275 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003276 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003277 if (adev->bluetooth_nrec)
3278 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
3279 else
3280 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003281 }
Eric Laurentb991fb02014-08-29 15:23:17 -05003282 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Prashant Malanic92c5962015-08-11 15:10:18 -07003283 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
3284 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
3285 out_device & AUDIO_DEVICE_OUT_LINE) {
3286 if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
3287 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
3288 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
3289 } else {
3290 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
3291 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003292 }
vivek mehtafe121d52015-08-10 23:39:23 -07003293
3294 //select default
3295 if (snd_device == SND_DEVICE_NONE) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07003296 if (!adev->enable_hfp) {
3297 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
3298 } else {
3299 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP;
3300 platform_set_echo_reference(adev, true, out_device);
3301 }
vivek mehtafe121d52015-08-10 23:39:23 -07003302 }
Prashant Malanic92c5962015-08-11 15:10:18 -07003303 } else if (out_device & AUDIO_DEVICE_OUT_TELEPHONY_TX) {
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07003304 snd_device = SND_DEVICE_IN_VOICE_RX;
Eric Laurent99dab492017-06-17 15:19:08 -07003305 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
David Lin40b07892017-08-07 15:02:48 -07003306 if (audio_extn_usb_is_capture_supported()) {
3307 snd_device = SND_DEVICE_IN_VOICE_USB_HEADSET_MIC;
3308 } else if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
3309 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
3310 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
3311 } else {
3312 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
3313 }
3314 }
juyuchend194b432018-11-16 14:15:16 +08003315 } else if (out_device & AUDIO_DEVICE_OUT_HEARING_AID) {
3316 snd_device = SND_DEVICE_IN_VOICE_HEARING_AID;
Prashant Malanic92c5962015-08-11 15:10:18 -07003317 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003318 } else if (source == AUDIO_SOURCE_CAMCORDER) {
3319 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
3320 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Eric Laurent5f4ca952018-10-19 17:33:43 -07003321 switch (adev->camera_orientation) {
3322 case CAMERA_BACK_LANDSCAPE:
3323 snd_device = SND_DEVICE_IN_CAMCORDER_LANDSCAPE;
3324 break;
3325 case CAMERA_BACK_INVERT_LANDSCAPE:
3326 snd_device = SND_DEVICE_IN_CAMCORDER_INVERT_LANDSCAPE;
3327 break;
3328 case CAMERA_BACK_PORTRAIT:
3329 snd_device = SND_DEVICE_IN_CAMCORDER_PORTRAIT;
3330 break;
3331 case CAMERA_FRONT_LANDSCAPE:
3332 snd_device = SND_DEVICE_IN_CAMCORDER_SELFIE_LANDSCAPE;
3333 break;
3334 case CAMERA_FRONT_INVERT_LANDSCAPE:
3335 snd_device = SND_DEVICE_IN_CAMCORDER_SELFIE_INVERT_LANDSCAPE;
3336 break;
3337 case CAMERA_FRONT_PORTRAIT:
3338 snd_device = SND_DEVICE_IN_CAMCORDER_SELFIE_PORTRAIT;
3339 break;
3340 default:
3341 ALOGW("%s: invalid camera orientation %08x", __func__, adev->camera_orientation);
3342 snd_device = SND_DEVICE_IN_CAMCORDER_LANDSCAPE;
3343 break;
3344 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003345 }
3346 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
3347 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003348 if (my_data->fluence_in_voice_rec && channel_count == 1) {
3349 if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
3350 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
Eric Laurentd1b7a9b2018-11-15 12:24:31 -08003351 if (in->enable_aec)
vivek mehta733c1df2016-04-04 15:09:24 -07003352 snd_device = SND_DEVICE_IN_HANDSET_QMIC_AEC;
3353 else
3354 snd_device = SND_DEVICE_IN_HANDSET_QMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003355 } else if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
3356 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
Eric Laurentd1b7a9b2018-11-15 12:24:31 -08003357 if (in->enable_aec)
vivek mehta733c1df2016-04-04 15:09:24 -07003358 snd_device = SND_DEVICE_IN_HANDSET_TMIC_AEC;
3359 else
3360 snd_device = SND_DEVICE_IN_HANDSET_TMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003361 } else if (((my_data->fluence_type == FLUENCE_PRO_ENABLE) ||
3362 (my_data->fluence_type == FLUENCE_ENABLE)) &&
3363 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Eric Laurentd1b7a9b2018-11-15 12:24:31 -08003364 if (in->enable_aec)
vivek mehta733c1df2016-04-04 15:09:24 -07003365 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
3366 else
3367 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
Prashant Malanic92c5962015-08-11 15:10:18 -07003368 }
3369 platform_set_echo_reference(adev, true, out_device);
3370 } else if ((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) &&
3371 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
3372 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003373 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003374 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
3375 snd_device = SND_DEVICE_IN_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003376 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003377 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
3378 snd_device = SND_DEVICE_IN_QUAD_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07003379 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003380 if (snd_device == SND_DEVICE_NONE) {
Eric Laurentd1b7a9b2018-11-15 12:24:31 -08003381 if (in->enable_aec) {
3382 if (in->enable_ns) {
vivek mehtaf3440682016-05-11 14:24:37 -07003383 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS;
3384 } else {
3385 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC;
3386 }
vivek mehta733c1df2016-04-04 15:09:24 -07003387 platform_set_echo_reference(adev, true, out_device);
Eric Laurentd1b7a9b2018-11-15 12:24:31 -08003388 } else if (in->enable_ns) {
vivek mehtaf3440682016-05-11 14:24:37 -07003389 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
3390 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003391 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
vivek mehtaf3440682016-05-11 14:24:37 -07003392 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003393 }
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -07003394 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3395 snd_device = SND_DEVICE_IN_VOICE_REC_HEADSET_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07003396 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07003397 snd_device = SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07003398 }
rago90fb9612015-12-02 11:37:53 -08003399 } else if (source == AUDIO_SOURCE_UNPROCESSED) {
3400 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
vivek mehta4ed66e62016-04-15 23:33:34 -07003401 if (((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) ||
3402 (channel_mask == AUDIO_CHANNEL_IN_STEREO)) &&
3403 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
3404 snd_device = SND_DEVICE_IN_UNPROCESSED_STEREO_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003405 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07003406 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
3407 snd_device = SND_DEVICE_IN_UNPROCESSED_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003408 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07003409 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
3410 snd_device = SND_DEVICE_IN_UNPROCESSED_QUAD_MIC;
3411 } else {
3412 snd_device = SND_DEVICE_IN_UNPROCESSED_MIC;
3413 }
rago90fb9612015-12-02 11:37:53 -08003414 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3415 snd_device = SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07003416 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07003417 snd_device = SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC;
rago90fb9612015-12-02 11:37:53 -08003418 }
Eric Laurent50a38ed2015-10-14 18:48:06 -07003419 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION ||
rago90fb9612015-12-02 11:37:53 -08003420 mode == AUDIO_MODE_IN_COMMUNICATION) {
David Lin40b07892017-08-07 15:02:48 -07003421 if (out_device & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
3422 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
3423 (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE | AUDIO_DEVICE_OUT_USB_HEADSET) &&
3424 !audio_extn_usb_is_capture_supported())) {
Eric Laurentb23d5282013-05-14 15:27:20 -07003425 in_device = AUDIO_DEVICE_IN_BACK_MIC;
David Lin40b07892017-08-07 15:02:48 -07003426 }
Vignesh Kulothungan64698822018-01-23 11:25:18 -08003427
Eric Laurentd1b7a9b2018-11-15 12:24:31 -08003428 if (in) {
Vignesh Kulothungan64698822018-01-23 11:25:18 -08003429 snd_device = get_snd_device_for_voice_comm(my_data, in, out_device, in_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07003430 }
3431 } else if (source == AUDIO_SOURCE_DEFAULT) {
3432 goto exit;
3433 }
3434
3435
3436 if (snd_device != SND_DEVICE_NONE) {
3437 goto exit;
3438 }
3439
3440 if (in_device != AUDIO_DEVICE_NONE &&
3441 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
3442 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
3443 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003444 if ((my_data->source_mic_type & SOURCE_QUAD_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003445 channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003446 snd_device = SND_DEVICE_IN_QUAD_MIC;
3447 } else if ((my_data->source_mic_type & SOURCE_THREE_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003448 channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003449 snd_device = SND_DEVICE_IN_THREE_MIC;
3450 } else if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
3451 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003452 snd_device = SND_DEVICE_IN_HANDSET_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07003453 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
3454 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003455 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003456 } else {
3457 ALOGE("%s: something wrong (1): source type (%d) channel_count (%d) .."
3458 " channel mask (0x%x) no combination found .. setting to mono", __func__,
3459 my_data->source_mic_type, channel_count, channel_mask);
3460 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3461 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003462 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003463 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
3464 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003465 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07003466 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
3467 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003468 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003469 } else {
3470 ALOGE("%s: something wrong (2): source type (%d) channel_count (%d) .."
3471 " no combination found .. setting to mono", __func__,
3472 my_data->source_mic_type, channel_count);
3473 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
3474 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003475 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3476 snd_device = SND_DEVICE_IN_HEADSET_MIC;
3477 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003478 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003479 if (adev->bluetooth_nrec)
3480 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
3481 else
3482 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003483 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003484 if (adev->bluetooth_nrec)
3485 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
3486 else
3487 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003488 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003489 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
3490 snd_device = SND_DEVICE_IN_HDMI_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07003491 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
David Linee3fe402017-03-13 10:00:42 -07003492 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07003493 } else {
3494 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
3495 ALOGW("%s: Using default handset-mic", __func__);
3496 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3497 }
3498 } else {
3499 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
3500 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3501 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
3502 snd_device = SND_DEVICE_IN_HEADSET_MIC;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003503 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07003504 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003505 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05003506 out_device & AUDIO_DEVICE_OUT_LINE) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003507 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
3508 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003509 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07003510 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
3511 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003512 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003513 } else {
3514 ALOGE("%s: something wrong (3): source type (%d) channel_count (%d) .."
3515 " no combination found .. setting to mono", __func__,
3516 my_data->source_mic_type, channel_count);
3517 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
3518 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003519 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003520 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003521 if (adev->bluetooth_nrec)
3522 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
3523 else
3524 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003525 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003526 if (adev->bluetooth_nrec)
3527 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
3528 else
3529 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003530 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003531 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
3532 snd_device = SND_DEVICE_IN_HDMI_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07003533 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
David Linee3fe402017-03-13 10:00:42 -07003534 if (audio_extn_usb_is_capture_supported())
3535 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
3536 else
3537 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07003538 } else {
3539 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
3540 ALOGW("%s: Using default handset-mic", __func__);
3541 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3542 }
3543 }
3544exit:
3545 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
3546 return snd_device;
3547}
3548
3549int platform_set_hdmi_channels(void *platform, int channel_count)
3550{
3551 struct platform_data *my_data = (struct platform_data *)platform;
3552 struct audio_device *adev = my_data->adev;
3553 struct mixer_ctl *ctl;
3554 const char *channel_cnt_str = NULL;
3555 const char *mixer_ctl_name = "HDMI_RX Channels";
3556 switch (channel_count) {
3557 case 8:
3558 channel_cnt_str = "Eight"; break;
3559 case 7:
3560 channel_cnt_str = "Seven"; break;
3561 case 6:
3562 channel_cnt_str = "Six"; break;
3563 case 5:
3564 channel_cnt_str = "Five"; break;
3565 case 4:
3566 channel_cnt_str = "Four"; break;
3567 case 3:
3568 channel_cnt_str = "Three"; break;
3569 default:
3570 channel_cnt_str = "Two"; break;
3571 }
3572 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3573 if (!ctl) {
3574 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3575 __func__, mixer_ctl_name);
3576 return -EINVAL;
3577 }
3578 ALOGV("HDMI channel count: %s", channel_cnt_str);
3579 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
3580 return 0;
3581}
3582
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003583int platform_edid_get_max_channels(void *platform)
Eric Laurentb23d5282013-05-14 15:27:20 -07003584{
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003585 struct platform_data *my_data = (struct platform_data *)platform;
3586 struct audio_device *adev = my_data->adev;
Eric Laurentb23d5282013-05-14 15:27:20 -07003587 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
3588 char *sad = block;
3589 int num_audio_blocks;
3590 int channel_count;
3591 int max_channels = 0;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003592 int i, ret, count;
Eric Laurentb23d5282013-05-14 15:27:20 -07003593
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003594 struct mixer_ctl *ctl;
3595
3596 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
3597 if (!ctl) {
3598 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3599 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
Eric Laurentb23d5282013-05-14 15:27:20 -07003600 return 0;
3601 }
3602
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003603 mixer_ctl_update(ctl);
3604
3605 count = mixer_ctl_get_num_values(ctl);
Eric Laurentb23d5282013-05-14 15:27:20 -07003606
3607 /* Read SAD blocks, clamping the maximum size for safety */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003608 if (count > (int)sizeof(block))
3609 count = (int)sizeof(block);
Eric Laurentb23d5282013-05-14 15:27:20 -07003610
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003611 ret = mixer_ctl_get_array(ctl, block, count);
3612 if (ret != 0) {
3613 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
3614 return 0;
3615 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003616
3617 /* Calculate the number of SAD blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003618 num_audio_blocks = count / SAD_BLOCK_SIZE;
Eric Laurentb23d5282013-05-14 15:27:20 -07003619
3620 for (i = 0; i < num_audio_blocks; i++) {
3621 /* Only consider LPCM blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003622 if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
3623 sad += 3;
Eric Laurentb23d5282013-05-14 15:27:20 -07003624 continue;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003625 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003626
3627 channel_count = (sad[0] & 0x7) + 1;
3628 if (channel_count > max_channels)
3629 max_channels = channel_count;
3630
3631 /* Advance to next block */
3632 sad += 3;
3633 }
3634
3635 return max_channels;
3636}
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003637
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07003638int platform_set_incall_recording_session_id(void *platform,
3639 uint32_t session_id, int rec_mode)
3640{
3641 int ret = 0;
3642 struct platform_data *my_data = (struct platform_data *)platform;
3643 struct audio_device *adev = my_data->adev;
3644 struct mixer_ctl *ctl;
3645 const char *mixer_ctl_name = "Voc VSID";
3646 int num_ctl_values;
3647 int i;
3648
3649 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3650 if (!ctl) {
3651 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3652 __func__, mixer_ctl_name);
3653 ret = -EINVAL;
3654 } else {
3655 num_ctl_values = mixer_ctl_get_num_values(ctl);
3656 for (i = 0; i < num_ctl_values; i++) {
3657 if (mixer_ctl_set_value(ctl, i, session_id)) {
3658 ALOGV("Error: invalid session_id: %x", session_id);
3659 ret = -EINVAL;
3660 break;
3661 }
3662 }
3663 }
3664
3665 if (my_data->csd != NULL) {
3666 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
3667 if (ret < 0) {
3668 ALOGE("%s: csd_client_start_record failed, error %d",
3669 __func__, ret);
3670 }
3671 }
3672
3673 return ret;
3674}
3675
Arun Mirpuriba2749a2018-04-17 14:32:24 -07003676int platform_set_incall_recording_session_channels(void *platform,
3677 uint32_t channel_count)
3678{
3679 int ret = 0;
3680 struct platform_data *my_data = (struct platform_data *)platform;
3681 struct audio_device *adev = my_data->adev;
3682 const char *mixer_ctl_name = "Voc Rec Config";
3683 int num_ctl_values;
3684 int i;
3685 struct mixer_ctl *ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3686
3687 if (!ctl) {
3688 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3689 __func__, mixer_ctl_name);
3690 ret = -EINVAL;
3691 } else {
3692 num_ctl_values = mixer_ctl_get_num_values(ctl);
3693 for (i = 0; i < num_ctl_values; i++) {
3694 if (mixer_ctl_set_value(ctl, i, channel_count)) {
3695 ALOGE("Error: invalid channel count: %x", channel_count);
3696 ret = -EINVAL;
3697 break;
3698 }
3699 }
3700 }
3701
3702 return ret;
3703}
3704
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07003705int platform_stop_incall_recording_usecase(void *platform)
3706{
3707 int ret = 0;
3708 struct platform_data *my_data = (struct platform_data *)platform;
3709
3710 if (my_data->csd != NULL) {
3711 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
3712 if (ret < 0) {
3713 ALOGE("%s: csd_client_stop_record failed, error %d",
3714 __func__, ret);
3715 }
3716 }
3717
3718 return ret;
3719}
3720
3721int platform_start_incall_music_usecase(void *platform)
3722{
3723 int ret = 0;
3724 struct platform_data *my_data = (struct platform_data *)platform;
3725
3726 if (my_data->csd != NULL) {
3727 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
3728 if (ret < 0) {
3729 ALOGE("%s: csd_client_start_playback failed, error %d",
3730 __func__, ret);
3731 }
3732 }
3733
3734 return ret;
3735}
3736
3737int platform_stop_incall_music_usecase(void *platform)
3738{
3739 int ret = 0;
3740 struct platform_data *my_data = (struct platform_data *)platform;
3741
3742 if (my_data->csd != NULL) {
3743 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
3744 if (ret < 0) {
3745 ALOGE("%s: csd_client_stop_playback failed, error %d",
3746 __func__, ret);
3747 }
3748 }
3749
3750 return ret;
3751}
3752
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003753int platform_set_parameters(void *platform, struct str_parms *parms)
3754{
3755 struct platform_data *my_data = (struct platform_data *)platform;
jasmine chac89321b2018-04-10 21:37:01 +08003756 char *value = NULL;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003757 char *kv_pairs = str_parms_to_str(parms);
jasmine chac89321b2018-04-10 21:37:01 +08003758 int len;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003759 int ret = 0, err;
3760
3761 if (kv_pairs == NULL) {
3762 ret = -EINVAL;
Jasmine Chaa314e192018-05-09 17:46:28 +08003763 ALOGE("%s: key-value pair is NULL", __func__);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003764 goto done;
3765 }
3766
3767 ALOGV("%s: enter: %s", __func__, kv_pairs);
3768
jasmine chac89321b2018-04-10 21:37:01 +08003769 len = strlen(kv_pairs);
Jasmine Chaa314e192018-05-09 17:46:28 +08003770 value = (char*)calloc(len + 1, sizeof(char));
jasmine chac89321b2018-04-10 21:37:01 +08003771 if (value == NULL) {
3772 ret = -ENOMEM;
Jasmine Chaa314e192018-05-09 17:46:28 +08003773 ALOGE("[%s] failed to allocate memory", __func__);
jasmine chac89321b2018-04-10 21:37:01 +08003774 goto done;
3775 }
3776
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003777 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME,
jasmine chac89321b2018-04-10 21:37:01 +08003778 value, len);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003779 if (err >= 0) {
3780 str_parms_del(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME);
3781 my_data->snd_card_name = strdup(value);
3782 ALOGV("%s: sound card name %s", __func__, my_data->snd_card_name);
3783 }
3784
keunhui.park2f7306a2015-07-16 16:48:06 +09003785 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO,
jasmine chac89321b2018-04-10 21:37:01 +08003786 value, len);
keunhui.park2f7306a2015-07-16 16:48:06 +09003787 if (err >= 0) {
3788 struct operator_info *info;
3789 char *str = value;
3790 char *name;
3791
3792 str_parms_del(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO);
3793 info = (struct operator_info *)calloc(1, sizeof(struct operator_info));
3794 name = strtok(str, ";");
3795 info->name = strdup(name);
3796 info->mccmnc = strdup(str + strlen(name) + 1);
3797
3798 list_add_tail(&operator_info_list, &info->list);
Joe Onorato188b6222016-03-01 11:02:27 -08003799 ALOGV("%s: add operator[%s] mccmnc[%s]", __func__, info->name, info->mccmnc);
keunhui.park2f7306a2015-07-16 16:48:06 +09003800 }
Prashant Malanic92c5962015-08-11 15:10:18 -07003801
Jasmine Chaa314e192018-05-09 17:46:28 +08003802 memset(value, 0, len + 1);
Eric Laurentc6333382015-09-14 12:43:44 -07003803 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT,
jasmine chac89321b2018-04-10 21:37:01 +08003804 value, len);
Prashant Malanic92c5962015-08-11 15:10:18 -07003805 if (err >= 0) {
Eric Laurentc6333382015-09-14 12:43:44 -07003806 str_parms_del(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT);
Prashant Malanic92c5962015-08-11 15:10:18 -07003807 my_data->max_mic_count = atoi(value);
3808 ALOGV("%s: max_mic_count %s/%d", __func__, value, my_data->max_mic_count);
Prashant Malanic92c5962015-08-11 15:10:18 -07003809 }
3810
jasmine chac89321b2018-04-10 21:37:01 +08003811 /* handle audio calibration parameters */
3812 set_audiocal(platform, parms, value, len);
3813
vivek mehta90933872017-06-15 18:04:39 -07003814 // to-do: disable setting sidetone gain, will revist this later
3815 // audio_extn_usb_set_sidetone_gain(parms, value, len);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003816done:
3817 ALOGV("%s: exit with code(%d)", __func__, ret);
3818 if (kv_pairs != NULL)
3819 free(kv_pairs);
jasmine chac89321b2018-04-10 21:37:01 +08003820 if (value != NULL)
3821 free(value);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003822
3823 return ret;
3824}
3825
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003826/* Delay in Us */
3827int64_t platform_render_latency(audio_usecase_t usecase)
3828{
3829 switch (usecase) {
3830 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
3831 return DEEP_BUFFER_PLATFORM_DELAY;
3832 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
Vignesh Kulothungan019d19b2019-01-23 11:09:18 -08003833 case USECASE_AUDIO_PLAYBACK_WITH_HAPTICS:
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003834 return LOW_LATENCY_PLATFORM_DELAY;
Haynes Mathew George03c40102016-01-29 17:57:48 -08003835 case USECASE_AUDIO_PLAYBACK_ULL:
3836 return ULL_PLATFORM_DELAY;
Eric Laurent0e46adf2016-12-16 12:49:24 -08003837 case USECASE_AUDIO_PLAYBACK_MMAP:
3838 return MMAP_PLATFORM_DELAY;
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003839 default:
3840 return 0;
3841 }
3842}
Haynes Mathew George98c95622014-06-20 19:14:25 -07003843
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003844int platform_set_snd_device_backend(snd_device_t device, const char *backend_tag,
3845 const char * hw_interface)
Haynes Mathew George98c95622014-06-20 19:14:25 -07003846{
3847 int ret = 0;
3848
3849 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
3850 ALOGE("%s: Invalid snd_device = %d",
3851 __func__, device);
3852 ret = -EINVAL;
3853 goto done;
3854 }
3855
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003856 ALOGV("%s: backend_tag_table[%s]: old = %s new = %s", __func__,
3857 platform_get_snd_device_name(device),
3858 backend_tag_table[device] != NULL ? backend_tag_table[device]: "null", backend_tag);
3859 if (backend_tag_table[device]) {
3860 free(backend_tag_table[device]);
Haynes Mathew George98c95622014-06-20 19:14:25 -07003861 }
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003862 backend_tag_table[device] = strdup(backend_tag);
3863
3864 if (hw_interface != NULL) {
3865 if (hw_interface_table[device])
3866 free(hw_interface_table[device]);
3867 ALOGV("%s: hw_interface_table[%d] = %s", __func__, device, hw_interface);
3868 hw_interface_table[device] = strdup(hw_interface);
3869 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07003870done:
3871 return ret;
3872}
3873
3874int platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t pcm_id)
3875{
3876 int ret = 0;
3877 if ((usecase <= USECASE_INVALID) || (usecase >= AUDIO_USECASE_MAX)) {
3878 ALOGE("%s: invalid usecase case idx %d", __func__, usecase);
3879 ret = -EINVAL;
3880 goto done;
3881 }
3882
3883 if ((type != 0) && (type != 1)) {
3884 ALOGE("%s: invalid usecase type", __func__);
3885 ret = -EINVAL;
3886 }
vivek mehtaa68fea62017-06-08 19:04:02 -07003887 ALOGV("%s: pcm_device_table[%d %s][%d] = %d", __func__, usecase,
3888 use_case_table[usecase],
3889 type, pcm_id);
Haynes Mathew George98c95622014-06-20 19:14:25 -07003890 pcm_device_table[usecase][type] = pcm_id;
3891done:
3892 return ret;
3893}
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003894
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07003895#define DEFAULT_NOMINAL_SPEAKER_GAIN 20
3896int ramp_speaker_gain(struct audio_device *adev, bool ramp_up, int target_ramp_up_gain) {
3897 // backup_gain: gain to try to set in case of an error during ramp
3898 int start_gain, end_gain, step, backup_gain, i;
3899 bool error = false;
3900 const struct mixer_ctl *ctl;
3901 const char *mixer_ctl_name_gain_left = "Left Speaker Gain";
3902 const char *mixer_ctl_name_gain_right = "Right Speaker Gain";
3903 struct mixer_ctl *ctl_left = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_left);
3904 struct mixer_ctl *ctl_right = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_right);
3905 if (!ctl_left || !ctl_right) {
3906 ALOGE("%s: Could not get ctl for mixer cmd - %s or %s, not applying speaker gain ramp",
3907 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
3908 return -EINVAL;
3909 } else if ((mixer_ctl_get_num_values(ctl_left) != 1)
3910 || (mixer_ctl_get_num_values(ctl_right) != 1)) {
3911 ALOGE("%s: Unexpected num values for mixer cmd - %s or %s, not applying speaker gain ramp",
3912 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
3913 return -EINVAL;
3914 }
3915 if (ramp_up) {
3916 start_gain = 0;
3917 end_gain = target_ramp_up_gain > 0 ? target_ramp_up_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
3918 step = +1;
3919 backup_gain = end_gain;
3920 } else {
3921 // using same gain on left and right
3922 const int left_gain = mixer_ctl_get_value(ctl_left, 0);
3923 start_gain = left_gain > 0 ? left_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
3924 end_gain = 0;
3925 step = -1;
3926 backup_gain = start_gain;
3927 }
3928 for (i = start_gain ; i != (end_gain + step) ; i += step) {
3929 //ALOGV("setting speaker gain to %d", i);
3930 if (mixer_ctl_set_value(ctl_left, 0, i)) {
3931 ALOGE("%s: error setting %s to %d during gain ramp",
3932 __func__, mixer_ctl_name_gain_left, i);
3933 error = true;
3934 break;
3935 }
3936 if (mixer_ctl_set_value(ctl_right, 0, i)) {
3937 ALOGE("%s: error setting %s to %d during gain ramp",
3938 __func__, mixer_ctl_name_gain_right, i);
3939 error = true;
3940 break;
3941 }
3942 usleep(1000);
3943 }
3944 if (error) {
3945 // an error occured during the ramp, let's still try to go back to a safe volume
3946 if (mixer_ctl_set_value(ctl_left, 0, backup_gain)) {
3947 ALOGE("%s: error restoring left gain to %d", __func__, backup_gain);
3948 }
3949 if (mixer_ctl_set_value(ctl_right, 0, backup_gain)) {
3950 ALOGE("%s: error restoring right gain to %d", __func__, backup_gain);
3951 }
3952 }
3953 return start_gain;
3954}
3955
vivek mehtae59cfb22017-06-16 15:57:11 -07003956int platform_set_swap_mixer(struct audio_device *adev, bool swap_channels)
3957{
3958 const char *mixer_ctl_name = "Swap channel";
3959 struct mixer_ctl *ctl;
3960 const char *mixer_path;
3961 struct platform_data *my_data = (struct platform_data *)adev->platform;
3962
3963 // forced to set to swap, but device not rotated ... ignore set
3964 if (swap_channels && !my_data->speaker_lr_swap)
3965 return 0;
3966
3967 ALOGV("%s:", __func__);
3968
3969 if (swap_channels) {
3970 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER_REVERSE);
3971 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
3972 } else {
3973 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER);
3974 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
3975 }
3976
3977 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3978 if (!ctl) {
3979 ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name);
3980 return -EINVAL;
3981 }
3982
3983 if (mixer_ctl_set_value(ctl, 0, swap_channels) < 0) {
3984 ALOGE("%s: Could not set reverse cotrol %d",__func__, swap_channels);
3985 return -EINVAL;
3986 }
3987
3988 ALOGV("platfor_force_swap_channel :: Channel orientation ( %s ) ",
3989 swap_channels?"R --> L":"L --> R");
3990
3991 return 0;
3992}
3993
3994int platform_check_and_set_swap_lr_channels(struct audio_device *adev, bool swap_channels)
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003995{
3996 // only update if there is active pcm playback on speaker
3997 struct audio_usecase *usecase;
3998 struct listnode *node;
3999 struct platform_data *my_data = (struct platform_data *)adev->platform;
4000
vivek mehtae59cfb22017-06-16 15:57:11 -07004001 my_data->speaker_lr_swap = swap_channels;
Jean-Michel Trivif7148702016-09-16 18:23:05 -07004002
vivek mehtae59cfb22017-06-16 15:57:11 -07004003 return platform_set_swap_channels(adev, swap_channels);
4004}
Jean-Michel Trivif7148702016-09-16 18:23:05 -07004005
vivek mehtae59cfb22017-06-16 15:57:11 -07004006int platform_set_swap_channels(struct audio_device *adev, bool swap_channels)
4007{
4008 // only update if there is active pcm playback on speaker
4009 struct audio_usecase *usecase;
4010 struct listnode *node;
4011 struct platform_data *my_data = (struct platform_data *)adev->platform;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07004012
vivek mehtae59cfb22017-06-16 15:57:11 -07004013 // do not swap channels in audio modes with concurrent capture and playback
4014 // as this may break the echo reference
4015 if ((adev->mode == AUDIO_MODE_IN_COMMUNICATION) || (adev->mode == AUDIO_MODE_IN_CALL)) {
4016 ALOGV("%s: will not swap due to audio mode %d", __func__, adev->mode);
4017 return 0;
4018 }
4019
4020 list_for_each(node, &adev->usecase_list) {
4021 usecase = node_to_item(node, struct audio_usecase, list);
4022 if (usecase->type == PCM_PLAYBACK &&
4023 usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) {
4024 /*
4025 * If acdb tuning is different for SPEAKER_REVERSE, it is must
4026 * to perform device switch to disable the current backend to
4027 * enable it with new acdb data.
4028 */
4029 if (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
4030 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]) {
4031 const int initial_skpr_gain = ramp_speaker_gain(adev, false /*ramp_up*/, -1);
4032 select_devices(adev, usecase->id);
4033 if (initial_skpr_gain != -EINVAL)
4034 ramp_speaker_gain(adev, true /*ramp_up*/, initial_skpr_gain);
4035
4036 } else {
4037 platform_set_swap_mixer(adev, swap_channels);
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07004038 }
vivek mehtae59cfb22017-06-16 15:57:11 -07004039 break;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07004040 }
4041 }
vivek mehtae59cfb22017-06-16 15:57:11 -07004042
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07004043 return 0;
4044}
vivek mehtaa8d7c922016-05-25 14:40:44 -07004045
4046static struct amp_db_and_gain_table tbl_mapping[MAX_VOLUME_CAL_STEPS];
4047static int num_gain_tbl_entry = 0;
4048
4049bool platform_add_gain_level_mapping(struct amp_db_and_gain_table *tbl_entry) {
4050
4051 ALOGV("%s: enter .. add %f %f %d", __func__, tbl_entry->amp, tbl_entry->db, tbl_entry->level);
4052 if (num_gain_tbl_entry == -1) {
4053 ALOGE("%s: num entry beyond valid step levels or corrupted..rejecting custom mapping",
4054 __func__);
4055 return false;
4056 }
4057
4058 if (num_gain_tbl_entry >= MAX_VOLUME_CAL_STEPS) {
4059 ALOGE("%s: max entry reached max[%d] current index[%d] .. rejecting", __func__,
4060 MAX_VOLUME_CAL_STEPS, num_gain_tbl_entry);
4061 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
4062 return false;
4063 }
4064
4065 if (num_gain_tbl_entry > 0 && tbl_mapping[num_gain_tbl_entry - 1].amp >= tbl_entry->amp) {
4066 ALOGE("%s: value not in ascending order .. rejecting custom mapping", __func__);
4067 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
4068 return false;
4069 }
4070
4071 tbl_mapping[num_gain_tbl_entry] = *tbl_entry;
4072 ++num_gain_tbl_entry;
4073
4074 return true;
4075}
4076
4077int platform_get_gain_level_mapping(struct amp_db_and_gain_table *mapping_tbl,
4078 int table_size) {
4079 int itt = 0;
4080 ALOGV("platform_get_gain_level_mapping called ");
4081
4082 if (num_gain_tbl_entry <= 0 || num_gain_tbl_entry > MAX_VOLUME_CAL_STEPS) {
4083 ALOGD("%s: empty or currupted gain_mapping_table", __func__);
4084 return 0;
4085 }
4086
4087 for (; itt < num_gain_tbl_entry && itt <= table_size; itt++) {
4088 mapping_tbl[itt] = tbl_mapping[itt];
4089 ALOGV("%s: added amp[%f] db[%f] level[%d]", __func__,
4090 mapping_tbl[itt].amp, mapping_tbl[itt].db, mapping_tbl[itt].level);
4091 }
4092
4093 return num_gain_tbl_entry;
4094}
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07004095
4096int platform_snd_card_update(void *platform, card_status_t status)
4097{
4098 struct platform_data *my_data = (struct platform_data *)platform;
4099 struct audio_device *adev = my_data->adev;
4100
4101 if (status == CARD_STATUS_ONLINE) {
4102 if (my_data->acdb_send_custom_top)
4103 my_data->acdb_send_custom_top();
4104 }
4105 return 0;
4106}
David Linee3fe402017-03-13 10:00:42 -07004107
4108/*
4109 * configures afe with bit width and Sample Rate
4110 */
Haynes Mathew George65f6b432018-02-27 17:44:55 -08004111int platform_set_backend_cfg(const struct audio_device* adev,
4112 snd_device_t snd_device,
4113 const struct audio_backend_cfg *backend_cfg)
David Linee3fe402017-03-13 10:00:42 -07004114{
4115
4116 int ret = 0;
4117 const int backend_idx = platform_get_backend_index(snd_device);
4118 struct platform_data *my_data = (struct platform_data *)adev->platform;
4119 const unsigned int bit_width = backend_cfg->bit_width;
4120 const unsigned int sample_rate = backend_cfg->sample_rate;
4121 const unsigned int channels = backend_cfg->channels;
4122 const audio_format_t format = backend_cfg->format;
4123 const bool passthrough_enabled = backend_cfg->passthrough_enabled;
4124
4125
4126 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
4127 ", backend_idx %d device (%s)", __func__, bit_width,
4128 sample_rate, channels, backend_idx,
4129 platform_get_snd_device_name(snd_device));
4130
4131 if ((my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl) &&
4132 (bit_width != my_data->current_backend_cfg[backend_idx].bit_width)) {
4133
4134 struct mixer_ctl *ctl = NULL;
4135 ctl = mixer_get_ctl_by_name(adev->mixer,
4136 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
4137 if (!ctl) {
4138 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
4139 __func__,
4140 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
4141 return -EINVAL;
4142 }
4143
4144 if (bit_width == 24) {
4145 if (format == AUDIO_FORMAT_PCM_24_BIT_PACKED)
4146 ret = mixer_ctl_set_enum_by_string(ctl, "S24_3LE");
4147 else
4148 ret = mixer_ctl_set_enum_by_string(ctl, "S24_LE");
4149 } else if (bit_width == 32) {
4150 ret = mixer_ctl_set_enum_by_string(ctl, "S32_LE");
4151 } else {
4152 ret = mixer_ctl_set_enum_by_string(ctl, "S16_LE");
4153 }
4154 if ( ret < 0) {
4155 ALOGE("%s:becf: afe: fail for %s mixer set to %d bit for %x format", __func__,
4156 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
4157 } else {
4158 my_data->current_backend_cfg[backend_idx].bit_width = bit_width;
4159 ALOGD("%s:becf: afe: %s mixer set to %d bit for %x format", __func__,
4160 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
4161 }
4162 /* set the ret as 0 and not pass back to upper layer */
4163 ret = 0;
4164 }
4165
4166 if (passthrough_enabled || ((my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl) &&
4167 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate))) {
4168 char *rate_str = NULL;
4169 struct mixer_ctl *ctl = NULL;
4170
4171 switch (sample_rate) {
4172 case 32000:
4173 if (passthrough_enabled) {
4174 rate_str = "KHZ_32";
4175 break;
4176 }
4177 case 8000:
4178 case 11025:
4179 case 16000:
4180 case 22050:
4181 case 48000:
4182 rate_str = "KHZ_48";
4183 break;
4184 case 44100:
4185 rate_str = "KHZ_44P1";
4186 break;
4187 case 64000:
4188 case 96000:
4189 rate_str = "KHZ_96";
4190 break;
4191 case 88200:
4192 rate_str = "KHZ_88P2";
4193 break;
4194 case 176400:
4195 rate_str = "KHZ_176P4";
4196 break;
4197 case 192000:
4198 rate_str = "KHZ_192";
4199 break;
4200 case 352800:
4201 rate_str = "KHZ_352P8";
4202 break;
4203 case 384000:
4204 rate_str = "KHZ_384";
4205 break;
4206 case 144000:
4207 if (passthrough_enabled) {
4208 rate_str = "KHZ_144";
4209 break;
4210 }
4211 default:
4212 rate_str = "KHZ_48";
4213 break;
4214 }
4215
4216 ctl = mixer_get_ctl_by_name(adev->mixer,
4217 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
4218 if(!ctl) {
4219 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
4220 __func__,
4221 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
4222 return -EINVAL;
4223 }
4224
4225 ALOGD("%s:becf: afe: %s set to %s", __func__,
4226 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl, rate_str);
4227 mixer_ctl_set_enum_by_string(ctl, rate_str);
4228 my_data->current_backend_cfg[backend_idx].sample_rate = sample_rate;
4229 }
4230 if ((my_data->current_backend_cfg[backend_idx].channels_mixer_ctl) &&
4231 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
4232 struct mixer_ctl *ctl = NULL;
4233 char *channel_cnt_str = NULL;
4234
4235 switch (channels) {
4236 case 8:
4237 channel_cnt_str = "Eight"; break;
4238 case 7:
4239 channel_cnt_str = "Seven"; break;
4240 case 6:
4241 channel_cnt_str = "Six"; break;
4242 case 5:
4243 channel_cnt_str = "Five"; break;
4244 case 4:
4245 channel_cnt_str = "Four"; break;
4246 case 3:
4247 channel_cnt_str = "Three"; break;
4248 case 1:
4249 channel_cnt_str = "One"; break;
4250 case 2:
4251 default:
4252 channel_cnt_str = "Two"; break;
4253 }
4254
4255 ctl = mixer_get_ctl_by_name(adev->mixer,
4256 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
4257 if (!ctl) {
4258 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
4259 __func__,
4260 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
4261 return -EINVAL;
4262 }
4263 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
4264 my_data->current_backend_cfg[backend_idx].channels = channels;
4265
4266 // skip EDID configuration for HDMI backend
4267
4268 ALOGD("%s:becf: afe: %s set to %s", __func__,
4269 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl,
4270 channel_cnt_str);
4271 }
4272
4273 // skip set ext_display format mixer control
4274 return ret;
4275}
4276
4277static int platform_get_snd_device_bit_width(snd_device_t snd_device)
4278{
4279 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
4280 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
4281 return CODEC_BACKEND_DEFAULT_BIT_WIDTH;
4282 }
4283
4284 return backend_bit_width_table[snd_device];
4285}
4286
4287/*
4288 * return backend_idx on which voice call is active
4289 */
4290static int platform_get_voice_call_backend(struct audio_device* adev)
4291{
4292 struct audio_usecase *uc = NULL;
4293 struct listnode *node;
4294 snd_device_t out_snd_device = SND_DEVICE_NONE;
4295
4296 int backend_idx = -1;
4297
4298 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
4299 list_for_each(node, &adev->usecase_list) {
4300 uc = node_to_item(node, struct audio_usecase, list);
4301 if (uc && uc->type == VOICE_CALL && uc->stream.out) {
4302 out_snd_device = platform_get_output_snd_device(adev->platform,
4303 uc->stream.out->devices);
4304 backend_idx = platform_get_backend_index(out_snd_device);
4305 break;
4306 }
4307 }
4308 }
4309 return backend_idx;
4310}
4311
4312/*
4313 * goes through all the current usecases and picks the highest
4314 * bitwidth & samplerate
4315 */
4316static bool platform_check_capture_backend_cfg(struct audio_device* adev,
4317 int backend_idx,
4318 struct audio_backend_cfg *backend_cfg)
4319{
4320 bool backend_change = false;
4321 unsigned int bit_width;
4322 unsigned int sample_rate;
4323 unsigned int channels;
4324 struct platform_data *my_data = (struct platform_data *)adev->platform;
4325
4326 bit_width = backend_cfg->bit_width;
4327 sample_rate = backend_cfg->sample_rate;
4328 channels = backend_cfg->channels;
4329
4330 ALOGV("%s:txbecf: afe: Codec selected backend: %d current bit width: %d and "
4331 "sample rate: %d, channels %d",__func__,backend_idx, bit_width,
4332 sample_rate, channels);
4333
4334 // For voice calls use default configuration i.e. 16b/48K, only applicable to
4335 // default backend
4336 // force routing is not required here, caller will do it anyway
4337 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
4338 ALOGW("%s:txbecf: afe: Use default bw and sr for voice/voip calls and "
4339 "for unprocessed/camera source", __func__);
4340 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
4341 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4342 }
4343
4344 if (backend_idx == USB_AUDIO_TX_BACKEND) {
4345 audio_extn_usb_is_config_supported(&bit_width, &sample_rate, &channels, false);
4346 ALOGV("%s:txbecf: afe: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
4347 __func__, bit_width, sample_rate, channels);
4348 }
4349
4350 ALOGV("%s:txbecf: afe: Codec selected backend: %d updated bit width: %d and "
4351 "sample rate: %d", __func__, backend_idx, bit_width, sample_rate);
4352
4353 // Force routing if the expected bitwdith or samplerate
4354 // is not same as current backend comfiguration
4355 if ((bit_width != my_data->current_backend_cfg[backend_idx].bit_width) ||
4356 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate) ||
4357 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
4358 backend_cfg->bit_width = bit_width;
4359 backend_cfg->sample_rate= sample_rate;
4360 backend_cfg->channels = channels;
4361 backend_change = true;
4362 ALOGI("%s:txbecf: afe: Codec backend needs to be updated. new bit width: %d "
4363 "new sample rate: %d new channel: %d",
4364 __func__, backend_cfg->bit_width,
4365 backend_cfg->sample_rate, backend_cfg->channels);
4366 }
4367
4368 return backend_change;
4369}
4370
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004371static void pick_playback_cfg_for_uc(struct audio_device *adev,
4372 struct audio_usecase *usecase,
4373 snd_device_t snd_device,
4374 unsigned int *bit_width,
4375 unsigned int *sample_rate,
4376 unsigned int *channels)
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004377{
4378 int i =0;
4379 struct listnode *node;
4380 list_for_each(node, &adev->usecase_list) {
4381 struct audio_usecase *uc;
4382 uc = node_to_item(node, struct audio_usecase, list);
4383 struct stream_out *out = (struct stream_out*) uc->stream.out;
4384 if (uc->type == PCM_PLAYBACK && out && usecase != uc) {
4385 unsigned int out_channels = audio_channel_count_from_out_mask(out->channel_mask);
4386 ALOGV("%s:napb: (%d) - (%s)id (%d) sr %d bw "
4387 "(%d) ch (%d) device %s", __func__, i++, use_case_table[uc->id],
4388 uc->id, out->sample_rate,
4389 pcm_format_to_bits(out->config.format), out_channels,
4390 platform_get_snd_device_name(uc->out_snd_device));
4391
4392 if (platform_check_backends_match(snd_device, uc->out_snd_device)) {
4393 if (*bit_width < pcm_format_to_bits(out->config.format))
4394 *bit_width = pcm_format_to_bits(out->config.format);
4395 if (*sample_rate < out->sample_rate)
4396 *sample_rate = out->sample_rate;
4397 if (out->sample_rate < OUTPUT_SAMPLING_RATE_44100)
4398 *sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4399 if (*channels < out_channels)
4400 *channels = out_channels;
4401 }
4402 }
4403 }
4404 return;
4405}
4406
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004407static void headset_is_config_supported(unsigned int *bit_width,
4408 unsigned int *sample_rate,
4409 unsigned int *channels) {
4410 switch (*bit_width) {
4411 case 16:
4412 case 24:
4413 break;
4414 default:
4415 *bit_width = 16;
4416 break;
4417 }
4418
4419 if (*sample_rate > 192000) {
4420 *sample_rate = 192000;
4421 }
4422
4423 if (*channels > 2) {
4424 *channels = 2;
4425 }
4426}
4427
David Linee3fe402017-03-13 10:00:42 -07004428static bool platform_check_playback_backend_cfg(struct audio_device* adev,
4429 struct audio_usecase* usecase,
4430 snd_device_t snd_device,
4431 struct audio_backend_cfg *backend_cfg)
4432{
4433 bool backend_change = false;
David Linee3fe402017-03-13 10:00:42 -07004434 unsigned int bit_width;
4435 unsigned int sample_rate;
4436 unsigned int channels;
David Linee3fe402017-03-13 10:00:42 -07004437 int backend_idx = DEFAULT_CODEC_BACKEND;
Haynes Mathew George65f6b432018-02-27 17:44:55 -08004438 unsigned long service_interval = 0; // 0 is invalid
David Linee3fe402017-03-13 10:00:42 -07004439 struct platform_data *my_data = (struct platform_data *)adev->platform;
David Linee3fe402017-03-13 10:00:42 -07004440
4441 if (snd_device == SND_DEVICE_OUT_BT_SCO ||
4442 snd_device == SND_DEVICE_OUT_BT_SCO_WB) {
4443 backend_change = false;
4444 return backend_change;
4445 }
4446
4447 backend_idx = platform_get_backend_index(snd_device);
4448 bit_width = backend_cfg->bit_width;
4449 sample_rate = backend_cfg->sample_rate;
4450 channels = backend_cfg->channels;
4451
4452 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
4453 ", backend_idx %d usecase = %d device (%s)", __func__, bit_width,
4454 sample_rate, channels, backend_idx, usecase->id,
4455 platform_get_snd_device_name(snd_device));
4456
4457 if (backend_idx == platform_get_voice_call_backend(adev)) {
4458 ALOGW("%s:becf: afe:Use default bw and sr for voice/voip calls ",
4459 __func__);
4460 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
4461 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4462 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
4463 } else {
4464 /*
4465 * The backend should be configured at highest bit width and/or
4466 * sample rate amongst all playback usecases.
4467 * If the selected sample rate and/or bit width differ with
4468 * current backend sample rate and/or bit width, then, we set the
4469 * backend re-configuration flag.
4470 *
4471 * Exception: 16 bit playbacks is allowed through 16 bit/48/44.1 khz backend only
4472 */
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004473 pick_playback_cfg_for_uc(adev, usecase, snd_device,
4474 &bit_width,
4475 &sample_rate,
4476 &channels);
David Linee3fe402017-03-13 10:00:42 -07004477 }
4478
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004479 switch (backend_idx) {
4480 case USB_AUDIO_RX_BACKEND:
4481 audio_extn_usb_is_config_supported(&bit_width,
4482 &sample_rate, &channels, true);
Haynes Mathew George65f6b432018-02-27 17:44:55 -08004483 if (platform_get_usb_service_interval(adev->platform, true,
4484 &service_interval) == 0) {
4485 /* overwrite with best altset for this service interval */
4486 int ret =
4487 audio_extn_usb_altset_for_service_interval(true /*playback*/,
4488 service_interval,
4489 &bit_width,
4490 &sample_rate,
4491 &channels);
4492 if (ret < 0) {
4493 ALOGE("Failed to find altset for service interval %lu, skip reconfig",
4494 service_interval);
4495 return false;
4496 }
4497 }
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004498 ALOGV("%s: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
4499 __func__, bit_width, sample_rate, channels);
4500 break;
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004501 case HEADPHONE_BACKEND:
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004502 headset_is_config_supported(&bit_width, &sample_rate, &channels);
4503 break;
4504 case DEFAULT_CODEC_BACKEND:
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004505 default:
4506 bit_width = platform_get_snd_device_bit_width(snd_device);
4507 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4508 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
4509 break;
David Linee3fe402017-03-13 10:00:42 -07004510 }
4511
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004512 ALOGV("%s:becf: afe: Codec selected backend: %d updated bit width: %d and"
4513 "sample rate: %d",
David Linee3fe402017-03-13 10:00:42 -07004514 __func__, backend_idx , bit_width, sample_rate);
4515
4516 // Force routing if the expected bitwdith or samplerate
4517 // is not same as current backend comfiguration
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004518 if (bit_width != my_data->current_backend_cfg[backend_idx].bit_width ||
4519 sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate ||
4520 channels != my_data->current_backend_cfg[backend_idx].channels) {
David Linee3fe402017-03-13 10:00:42 -07004521 backend_cfg->bit_width = bit_width;
4522 backend_cfg->sample_rate = sample_rate;
4523 backend_cfg->channels = channels;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004524 backend_cfg->passthrough_enabled = false;
David Linee3fe402017-03-13 10:00:42 -07004525 backend_change = true;
4526 ALOGV("%s:becf: afe: Codec backend needs to be updated. new bit width: %d"
4527 "new sample rate: %d new channels: %d",
4528 __func__, backend_cfg->bit_width, backend_cfg->sample_rate, backend_cfg->channels);
4529 }
4530
4531 return backend_change;
4532}
4533
4534bool platform_check_and_set_playback_backend_cfg(struct audio_device* adev,
4535 struct audio_usecase *usecase, snd_device_t snd_device)
4536{
4537 int backend_idx = DEFAULT_CODEC_BACKEND;
4538 int new_snd_devices[SND_DEVICE_OUT_END];
4539 int i, num_devices = 1;
4540 bool ret = false;
4541 struct platform_data *my_data = (struct platform_data *)adev->platform;
4542 struct audio_backend_cfg backend_cfg;
4543
4544 backend_idx = platform_get_backend_index(snd_device);
4545
4546 backend_cfg.bit_width = pcm_format_to_bits(usecase->stream.out->config.format);
4547 backend_cfg.sample_rate = usecase->stream.out->sample_rate;
4548 backend_cfg.format = usecase->stream.out->format;
4549 backend_cfg.channels = audio_channel_count_from_out_mask(usecase->stream.out->channel_mask);
4550 /*this is populated by check_codec_backend_cfg hence set default value to false*/
4551 backend_cfg.passthrough_enabled = false;
4552
4553 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
4554 ", backend_idx %d usecase = %d device (%s)", __func__, backend_cfg.bit_width,
4555 backend_cfg.sample_rate, backend_cfg.channels, backend_idx, usecase->id,
4556 platform_get_snd_device_name(snd_device));
4557
4558 if (platform_can_split_snd_device(snd_device, &num_devices, new_snd_devices) < 0)
4559 new_snd_devices[0] = snd_device;
4560
4561 for (i = 0; i < num_devices; i++) {
4562 ALOGV("%s: new_snd_devices[%d] is %d", __func__, i, new_snd_devices[i]);
4563 if ((platform_check_playback_backend_cfg(adev, usecase, new_snd_devices[i],
4564 &backend_cfg))) {
4565 platform_set_backend_cfg(adev, new_snd_devices[i],
4566 &backend_cfg);
4567 ret = true;
4568 }
4569 }
4570 return ret;
4571}
4572
4573bool platform_check_and_set_capture_backend_cfg(struct audio_device* adev,
4574 struct audio_usecase *usecase, snd_device_t snd_device)
4575{
4576 int backend_idx = platform_get_backend_index(snd_device);
4577 int ret = 0;
4578 struct audio_backend_cfg backend_cfg;
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004579 memset(&backend_cfg, 0, sizeof(struct audio_backend_cfg));
David Linee3fe402017-03-13 10:00:42 -07004580
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004581 if (usecase->type == PCM_CAPTURE) {
4582 backend_cfg.format = usecase->stream.in->format;
David Linee3fe402017-03-13 10:00:42 -07004583 backend_cfg.channels = audio_channel_count_from_in_mask(usecase->stream.in->channel_mask);
4584 } else {
4585 backend_cfg.bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
4586 backend_cfg.sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4587 backend_cfg.format = AUDIO_FORMAT_PCM_16_BIT;
4588 backend_cfg.channels = 1;
4589 }
4590
4591 ALOGV("%s:txbecf: afe: bitwidth %d, samplerate %d, channel %d"
4592 ", backend_idx %d usecase = %d device (%s)", __func__,
4593 backend_cfg.bit_width,
4594 backend_cfg.sample_rate,
4595 backend_cfg.channels,
4596 backend_idx, usecase->id,
4597 platform_get_snd_device_name(snd_device));
4598
4599 if (platform_check_capture_backend_cfg(adev, backend_idx, &backend_cfg)) {
4600 ret = platform_set_backend_cfg(adev, snd_device,
4601 &backend_cfg);
4602 if(!ret)
4603 return true;
4604 }
4605
4606 return false;
4607}
4608
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004609static int max_be_dai_names = 0;
4610static const struct be_dai_name_struct *be_dai_name_table;
4611
4612/*
4613 * Retrieves the be_dai_name_table from kernel to enable a mapping
4614 * between sound device hw interfaces and backend IDs. This allows HAL to
4615 * specify the backend a specific calibration is needed for.
4616 */
4617static int init_be_dai_name_table(struct audio_device *adev)
4618{
4619 const char *mixer_ctl_name = "Backend DAI Name Table";
4620 struct mixer_ctl *ctl;
4621 int i, j, ret, size;
4622 bool valid_hw_interface;
4623
4624 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
4625 if (!ctl) {
4626 ALOGE("%s: Could not get ctl for mixer name %s\n",
4627 __func__, mixer_ctl_name);
4628 ret = -EINVAL;
4629 goto done;
4630 }
4631
4632 mixer_ctl_update(ctl);
4633
4634 size = mixer_ctl_get_num_values(ctl);
4635 if (size <= 0){
4636 ALOGE("%s: Failed to get %s size %d\n",
4637 __func__, mixer_ctl_name, size);
4638 ret = -EFAULT;
4639 goto done;
4640 }
4641
vivek mehtaa68fea62017-06-08 19:04:02 -07004642 be_dai_name_table =
4643 (const struct be_dai_name_struct *)calloc(1, size);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004644 if (be_dai_name_table == NULL) {
4645 ALOGE("%s: Failed to allocate memory for %s\n",
4646 __func__, mixer_ctl_name);
4647 ret = -ENOMEM;
4648 goto freeMem;
4649 }
4650
4651 ret = mixer_ctl_get_array(ctl, (void *)be_dai_name_table, size);
4652 if (ret) {
4653 ALOGE("%s: Failed to get %s, ret %d\n",
4654 __func__, mixer_ctl_name, ret);
4655 ret = -EFAULT;
4656 goto freeMem;
4657 }
4658
4659 if (be_dai_name_table != NULL) {
4660 max_be_dai_names = size / sizeof(struct be_dai_name_struct);
4661 ALOGV("%s: Successfully got %s, number of be dais is %d\n",
4662 __func__, mixer_ctl_name, max_be_dai_names);
4663 ret = 0;
4664 } else {
4665 ALOGE("%s: Failed to get %s\n", __func__, mixer_ctl_name);
4666 ret = -EFAULT;
4667 goto freeMem;
4668 }
4669
4670 /*
4671 * Validate all sound devices have a valid backend set to catch
4672 * errors for uncommon sound devices
4673 */
4674 for (i = 0; i < SND_DEVICE_MAX; i++) {
4675 valid_hw_interface = false;
4676
4677 if (hw_interface_table[i] == NULL) {
4678 ALOGW("%s: sound device %s has no hw interface set\n",
4679 __func__, platform_get_snd_device_name(i));
4680 continue;
4681 }
4682
4683 for (j = 0; j < max_be_dai_names; j++) {
4684 if (strcmp(hw_interface_table[i], be_dai_name_table[j].be_name)
4685 == 0) {
4686 valid_hw_interface = true;
4687 break;
4688 }
4689 }
4690 if (!valid_hw_interface)
4691 ALOGD("%s: sound device %s does not have a valid hw interface set "
4692 "(disregard for combo devices) %s\n",
4693 __func__, platform_get_snd_device_name(i),
4694 hw_interface_table[i]);
4695 }
4696
4697 goto done;
4698
4699freeMem:
4700 if (be_dai_name_table) {
4701 free((void *)be_dai_name_table);
4702 be_dai_name_table = NULL;
4703 }
4704
4705done:
4706 return ret;
4707}
4708
4709int platform_get_snd_device_backend_index(snd_device_t device)
4710{
4711 int i, be_dai_id;
4712 const char * hw_interface_name = NULL;
4713
4714 ALOGV("%s: enter with device %d\n", __func__, device);
4715
vivek mehtaa68fea62017-06-08 19:04:02 -07004716 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004717 ALOGE("%s: Invalid snd_device = %d",
4718 __func__, device);
4719 be_dai_id = -EINVAL;
4720 goto done;
4721 }
4722
4723 /* Get string value of necessary backend for device */
4724 hw_interface_name = hw_interface_table[device];
4725 if (hw_interface_name == NULL) {
4726 ALOGE("%s: no hw_interface set for device %d\n", __func__, device);
4727 be_dai_id = -EINVAL;
4728 goto done;
4729 }
4730
4731 /* Check if be dai name table was retrieved successfully */
4732 if (be_dai_name_table == NULL) {
4733 ALOGE("%s: BE DAI Name Table is not present\n", __func__);
4734 be_dai_id = -EFAULT;
4735 goto done;
4736 }
4737
4738 /* Get backend ID for device specified */
4739 for (i = 0; i < max_be_dai_names; i++) {
4740 if (strcmp(hw_interface_name, be_dai_name_table[i].be_name) == 0) {
4741 be_dai_id = be_dai_name_table[i].be_id;
4742 goto done;
4743 }
4744 }
4745 ALOGE("%s: no interface matching name %s\n", __func__, hw_interface_name);
4746 be_dai_id = -EINVAL;
4747 goto done;
4748
4749done:
4750 return be_dai_id;
4751}
4752
4753void platform_check_and_update_copp_sample_rate(void* platform, snd_device_t snd_device,
4754 unsigned int stream_sr, int* sample_rate)
4755{
4756 struct platform_data* my_data = (struct platform_data *)platform;
4757 int backend_idx = platform_get_backend_index(snd_device);
4758 int device_sr = my_data->current_backend_cfg[backend_idx].sample_rate;
4759 /*
4760 *Check if device SR is multiple of 8K or 11.025 Khz
4761 *check if the stream SR is multiple of same base, if yes
4762 *then have copp SR equal to stream SR, this ensures that
4763 *post processing happens at stream SR, else have
4764 *copp SR equal to device SR.
4765 */
4766 if (!(((sample_rate_multiple(device_sr, SAMPLE_RATE_8000)) &&
4767 (sample_rate_multiple(stream_sr, SAMPLE_RATE_8000))) ||
4768 ((sample_rate_multiple(device_sr, SAMPLE_RATE_11025)) &&
4769 (sample_rate_multiple(stream_sr, SAMPLE_RATE_11025))))) {
4770 *sample_rate = device_sr;
4771 } else
4772 *sample_rate = stream_sr;
4773
4774 ALOGI("sn_device %d device sr %d stream sr %d copp sr %d", snd_device, device_sr, stream_sr
4775 , *sample_rate);
4776
4777}
4778
4779// called from info parser
vivek mehtaa68fea62017-06-08 19:04:02 -07004780void platform_add_app_type(const char *uc_type,
4781 const char *mode,
4782 int bw,
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004783 int app_type, int max_rate) {
4784 struct app_type_entry *ap =
4785 (struct app_type_entry *)calloc(1, sizeof(struct app_type_entry));
4786
4787 if (!ap) {
4788 ALOGE("%s failed to allocate mem for app type", __func__);
4789 return;
4790 }
4791
4792 ap->uc_type = -1;
4793 for (int i=0; i<USECASE_TYPE_MAX; i++) {
4794 if (!strcmp(uc_type, usecase_type_index[i].name)) {
4795 ap->uc_type = usecase_type_index[i].index;
4796 break;
4797 }
4798 }
4799
4800 if (ap->uc_type == -1) {
4801 free(ap);
4802 return;
4803 }
4804
vivek mehtaa68fea62017-06-08 19:04:02 -07004805 ALOGI("%s uc %s mode %s bw %d app_type %d max_rate %d",
4806 __func__, uc_type, mode, bw, app_type, max_rate);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004807 ap->bit_width = bw;
4808 ap->app_type = app_type;
4809 ap->max_rate = max_rate;
vivek mehtaa68fea62017-06-08 19:04:02 -07004810 ap->mode = strdup(mode);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004811 list_add_tail(&app_type_entry_list, &ap->node);
4812}
4813
4814
4815int platform_get_default_app_type_v2(void *platform __unused,
4816 usecase_type_t type,
4817 int *app_type )
4818{
4819 if (type == PCM_PLAYBACK)
4820 *app_type = DEFAULT_APP_TYPE_RX_PATH;
4821 else
4822 *app_type = DEFAULT_APP_TYPE_TX_PATH;
4823 return 0;
4824}
4825
vivek mehtaa68fea62017-06-08 19:04:02 -07004826int platform_get_app_type_v2(void *platform,
4827 usecase_type_t uc_type,
4828 const char *mode,
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004829 int bw, int sr __unused,
4830 int *app_type)
4831{
4832 struct listnode *node;
4833 struct app_type_entry *entry;
4834 *app_type = -1;
vivek mehtaa68fea62017-06-08 19:04:02 -07004835
4836 ALOGV("%s find match for uc %d mode %s bw %d rate %d",
4837 __func__, uc_type, mode, bw, sr);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004838 list_for_each(node, &app_type_entry_list) {
4839 entry = node_to_item(node, struct app_type_entry, node);
vivek mehtaa68fea62017-06-08 19:04:02 -07004840 ALOGV("%s uc %d mode %s bw %d app_type %d max_rate %d",
4841 __func__, entry->uc_type, entry->mode, entry->bit_width,
4842 entry->app_type, entry->max_rate);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004843 if (entry->bit_width == bw &&
vivek mehtaa68fea62017-06-08 19:04:02 -07004844 entry->uc_type == uc_type &&
4845 sr <= entry->max_rate &&
4846 entry->mode && !strcmp(mode, entry->mode)) {
4847 ALOGV("%s found match %d", __func__, entry->app_type);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004848 *app_type = entry->app_type;
4849 break;
4850 }
4851 }
4852
4853 if (*app_type == -1) {
vivek mehtaa68fea62017-06-08 19:04:02 -07004854 ALOGV("%s no match found, return default", __func__);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004855 return platform_get_default_app_type_v2(platform, uc_type, app_type);
4856 }
4857 return 0;
4858}
vivek mehta90933872017-06-15 18:04:39 -07004859
4860int platform_set_sidetone(struct audio_device *adev,
4861 snd_device_t out_snd_device,
4862 bool enable, char *str)
4863{
4864 int ret;
4865 if (out_snd_device == SND_DEVICE_OUT_USB_HEADSET ||
4866 out_snd_device == SND_DEVICE_OUT_VOICE_USB_HEADSET) {
4867 ret = audio_extn_usb_enable_sidetone(out_snd_device, enable);
4868 if (ret)
4869 ALOGI("%s: usb device %d does not support device sidetone\n",
4870 __func__, out_snd_device);
4871 } else {
4872 ALOGV("%s: sidetone out device(%d) mixer cmd = %s\n",
4873 __func__, out_snd_device, str);
4874 if (enable)
4875 audio_route_apply_and_update_path(adev->audio_route, str);
4876 else
4877 audio_route_reset_and_update_path(adev->audio_route, str);
4878 }
4879 return 0;
4880}
Haynes Mathew George96483a22017-03-28 14:52:47 -07004881
4882int platform_get_mmap_data_fd(void *platform __unused, int fe_dev __unused, int dir __unused,
4883 int *fd __unused, uint32_t *size __unused)
4884{
Thierry Strudel07f96d12018-09-20 13:31:34 -07004885#if defined (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845) || (PLATFORM_SDM710) || (PLATFORM_SM8150)
Haynes Mathew George96483a22017-03-28 14:52:47 -07004886 struct platform_data *my_data = (struct platform_data *)platform;
4887 struct audio_device *adev = my_data->adev;
4888 int hw_fd = -1;
4889 char dev_name[128];
4890 struct snd_pcm_mmap_fd mmap_fd;
4891 memset(&mmap_fd, 0, sizeof(mmap_fd));
4892 mmap_fd.dir = dir;
4893 snprintf(dev_name, sizeof(dev_name), "/dev/snd/hwC%uD%u",
4894 adev->snd_card, HWDEP_FE_BASE+fe_dev);
4895 hw_fd = open(dev_name, O_RDONLY);
4896 if (hw_fd < 0) {
4897 ALOGE("fe hw dep node open %d/%d failed", adev->snd_card, fe_dev);
4898 return -1;
4899 }
4900 if (ioctl(hw_fd, SNDRV_PCM_IOCTL_MMAP_DATA_FD, &mmap_fd) < 0) {
4901 ALOGE("fe hw dep node ioctl failed");
4902 close(hw_fd);
4903 return -1;
4904 }
4905 *fd = mmap_fd.fd;
4906 *size = mmap_fd.size;
4907 close(hw_fd); // mmap_fd should still be valid
4908 return 0;
4909#else
4910 return -1;
4911#endif
4912}
Mikhail Naganov4ee6e3e2018-03-21 16:28:35 +00004913
4914bool platform_sound_trigger_usecase_needs_event(audio_usecase_t uc_id)
4915{
4916 bool needs_event = false;
4917
4918 switch (uc_id) {
4919 /* concurrent capture usecases which needs event */
4920 case USECASE_AUDIO_RECORD:
4921 case USECASE_AUDIO_RECORD_LOW_LATENCY:
4922 case USECASE_AUDIO_RECORD_MMAP:
4923 case USECASE_AUDIO_RECORD_HIFI:
4924 case USECASE_AUDIO_RECORD_VOIP:
4925 case USECASE_VOICEMMODE1_CALL:
4926 case USECASE_VOICEMMODE2_CALL:
4927 /* concurrent playback usecases that needs event */
4928 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
4929 case USECASE_AUDIO_PLAYBACK_OFFLOAD:
4930 needs_event = true;
4931 break;
4932 default:
4933 ALOGV("%s:usecase_id[%d] no need to raise event.", __func__, uc_id);
4934 }
4935 return needs_event;
4936}
4937
4938bool platform_snd_device_has_speaker(snd_device_t dev) {
4939 int num_devs = 2;
4940 snd_device_t split_devs[2] = {SND_DEVICE_NONE, SND_DEVICE_NONE};
4941 if (platform_can_split_snd_device(dev, &num_devs, split_devs) == 0) {
4942 return platform_snd_device_has_speaker(split_devs[0]) ||
4943 platform_snd_device_has_speaker(split_devs[1]);
4944 }
4945
4946 switch (dev) {
4947 case SND_DEVICE_OUT_SPEAKER:
4948 case SND_DEVICE_OUT_SPEAKER_SAFE:
4949 case SND_DEVICE_OUT_SPEAKER_REVERSE:
4950 case SND_DEVICE_OUT_SPEAKER_PROTECTED:
4951 case SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED:
4952 case SND_DEVICE_OUT_VOICE_SPEAKER_HFP:
4953 return true;
4954 default:
4955 break;
4956 }
4957 return false;
4958}
jiabin8962a4d2018-03-19 18:21:24 -07004959
4960bool platform_set_microphone_characteristic(void *platform,
4961 struct audio_microphone_characteristic_t mic) {
4962 struct platform_data *my_data = (struct platform_data *)platform;
4963 if (my_data->declared_mic_count >= AUDIO_MICROPHONE_MAX_COUNT) {
4964 ALOGE("mic number is more than maximum number");
4965 return false;
4966 }
4967 for (size_t ch = 0; ch < AUDIO_CHANNEL_COUNT_MAX; ch++) {
4968 mic.channel_mapping[ch] = AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED;
4969 }
4970 my_data->microphones[my_data->declared_mic_count++] = mic;
4971 return true;
4972}
4973
4974int platform_get_microphones(void *platform,
4975 struct audio_microphone_characteristic_t *mic_array,
4976 size_t *mic_count) {
4977 struct platform_data *my_data = (struct platform_data *)platform;
4978 if (mic_count == NULL) {
4979 return -EINVAL;
4980 }
4981 if (mic_array == NULL) {
4982 return -EINVAL;
4983 }
4984
4985 if (*mic_count == 0) {
4986 *mic_count = my_data->declared_mic_count;
4987 return 0;
4988 }
4989
4990 size_t max_mic_count = *mic_count;
4991 size_t actual_mic_count = 0;
4992 for (size_t i = 0; i < max_mic_count && i < my_data->declared_mic_count; i++) {
4993 mic_array[i] = my_data->microphones[i];
4994 actual_mic_count++;
4995 }
4996 *mic_count = actual_mic_count;
4997 return 0;
4998}
4999
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07005000bool platform_set_microphone_map(void *platform, snd_device_t in_snd_device,
5001 const struct mic_info *info) {
5002 struct platform_data *my_data = (struct platform_data *)platform;
5003 if (in_snd_device < SND_DEVICE_IN_BEGIN || in_snd_device >= SND_DEVICE_IN_END) {
5004 ALOGE("%s: Sound device not valid", __func__);
5005 return false;
5006 }
5007 size_t m_count = my_data->mic_map[in_snd_device].mic_count++;
5008 if (m_count >= AUDIO_MICROPHONE_MAX_COUNT) {
5009 ALOGE("%s: Microphone count is greater than max allowed value", __func__);
5010 my_data->mic_map[in_snd_device].mic_count--;
5011 return false;
5012 }
5013 my_data->mic_map[in_snd_device].microphones[m_count] = *info;
5014 return true;
5015}
5016
5017int platform_get_active_microphones(void *platform, unsigned int channels,
5018 audio_usecase_t uc_id,
jiabin8962a4d2018-03-19 18:21:24 -07005019 struct audio_microphone_characteristic_t *mic_array,
5020 size_t *mic_count) {
5021 struct platform_data *my_data = (struct platform_data *)platform;
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07005022 struct audio_usecase *usecase = get_usecase_from_list(my_data->adev, uc_id);
5023 if (mic_count == NULL || mic_array == NULL || usecase == NULL) {
jiabin8962a4d2018-03-19 18:21:24 -07005024 return -EINVAL;
5025 }
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07005026 size_t max_mic_count = my_data->declared_mic_count;
jiabin8962a4d2018-03-19 18:21:24 -07005027 size_t actual_mic_count = 0;
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07005028
5029 snd_device_t active_input_snd_device =
Eric Laurentd1b7a9b2018-11-15 12:24:31 -08005030 platform_get_input_snd_device(platform, usecase->stream.in, AUDIO_DEVICE_NONE);
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07005031 if (active_input_snd_device == SND_DEVICE_NONE) {
5032 ALOGI("%s: No active microphones found", __func__);
5033 goto end;
5034 }
5035
5036 size_t active_mic_count = my_data->mic_map[active_input_snd_device].mic_count;
5037 struct mic_info *m_info = my_data->mic_map[active_input_snd_device].microphones;
5038
5039 for (size_t i = 0; i < active_mic_count; i++) {
5040 unsigned int channels_for_active_mic = channels;
5041 if (channels_for_active_mic > m_info[i].channel_count) {
5042 channels_for_active_mic = m_info[i].channel_count;
5043 }
5044 for (size_t j = 0; j < max_mic_count; j++) {
5045 if (strcmp(my_data->microphones[j].device_id,
5046 m_info[i].device_id) == 0) {
5047 mic_array[actual_mic_count] = my_data->microphones[j];
5048 for (size_t ch = 0; ch < channels_for_active_mic; ch++) {
5049 mic_array[actual_mic_count].channel_mapping[ch] =
5050 m_info[i].channel_mapping[ch];
5051 }
5052 actual_mic_count++;
5053 break;
jiabin8962a4d2018-03-19 18:21:24 -07005054 }
jiabin8962a4d2018-03-19 18:21:24 -07005055 }
5056 }
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07005057end:
jiabin8962a4d2018-03-19 18:21:24 -07005058 *mic_count = actual_mic_count;
5059 return 0;
5060}
Haynes Mathew George65f6b432018-02-27 17:44:55 -08005061
5062int platform_set_usb_service_interval(void *platform,
5063 bool playback,
5064 unsigned long service_interval,
5065 bool *reconfig)
5066{
5067#if defined (USB_SERVICE_INTERVAL_ENABLED)
5068 struct platform_data *_platform = (struct platform_data *)platform;
5069 *reconfig = false;
5070 if (!playback) {
5071 ALOGE("%s not valid for capture", __func__);
5072 return -1;
5073 }
5074 const char *ctl_name = "USB_AUDIO_RX service_interval";
5075 struct mixer_ctl *ctl = mixer_get_ctl_by_name(_platform->adev->mixer,
5076 ctl_name);
5077 if (!ctl) {
5078 ALOGV("%s: could not get mixer %s", __func__, ctl_name);
5079 return -1;
5080 }
5081 if (mixer_ctl_get_value(ctl, 0) != (int)service_interval) {
5082 mixer_ctl_set_value(ctl, 0, service_interval);
5083 *reconfig = true;
5084 }
5085 return 0;
5086#else
5087 *reconfig = false;
5088 (void)platform;
5089 (void)playback;
5090 (void)service_interval;
5091 return -1;
5092#endif
5093}
5094
5095int platform_get_usb_service_interval(void *platform,
5096 bool playback,
5097 unsigned long *service_interval)
5098{
5099#if defined (USB_SERVICE_INTERVAL_ENABLED)
5100 struct platform_data *_platform = (struct platform_data *)platform;
5101 if (!playback) {
5102 ALOGE("%s not valid for capture", __func__);
5103 return -1;
5104 }
5105 const char *ctl_name = "USB_AUDIO_RX service_interval";
5106 struct mixer_ctl *ctl = mixer_get_ctl_by_name(_platform->adev->mixer,
5107 ctl_name);
5108 if (!ctl) {
5109 ALOGV("%s: could not get mixer %s", __func__, ctl_name);
5110 return -1;
5111 }
5112 *service_interval = mixer_ctl_get_value(ctl, 0);
5113 return 0;
5114#else
5115 (void)platform;
5116 (void)playback;
5117 (void)service_interval;
5118 return -1;
5119#endif
5120}
Ashish Jain1c849702018-05-11 20:11:55 +05305121
5122int platform_set_acdb_metainfo_key(void *platform __unused,
5123 char *name __unused,
5124 int key __unused)
5125{
5126 return -ENOSYS;
5127}