blob: 481b57d7e86a52dd6a1176419842425ee7bdda71 [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
Eric Laurentb23d5282013-05-14 15:27:20 -070075struct audio_block_header
76{
77 int reserved;
78 int length;
79};
80
vivek mehta1a9b7c02015-06-25 11:49:38 -070081enum {
82 CAL_MODE_SEND = 0x1,
83 CAL_MODE_PERSIST = 0x2,
84 CAL_MODE_RTAC = 0x4
85};
86
keunhui.park2f7306a2015-07-16 16:48:06 +090087#define PLATFORM_CONFIG_KEY_OPERATOR_INFO "operator_info"
88
89struct operator_info {
90 struct listnode list;
91 char *name;
92 char *mccmnc;
93};
94
95struct operator_specific_device {
96 struct listnode list;
97 char *operator;
98 char *mixer_path;
99 int acdb_id;
100};
101
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800102#define BE_DAI_NAME_MAX_LENGTH 24
103struct be_dai_name_struct {
104 unsigned int be_id;
105 char be_name[BE_DAI_NAME_MAX_LENGTH];
106};
107
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -0700108struct snd_device_to_mic_map {
109 struct mic_info microphones[AUDIO_MICROPHONE_MAX_COUNT];
110 size_t mic_count;
111};
112
keunhui.park2f7306a2015-07-16 16:48:06 +0900113static struct listnode operator_info_list;
114static struct listnode *operator_specific_device_table[SND_DEVICE_MAX];
115
jasmine chac89321b2018-04-10 21:37:01 +0800116#define AUDIO_PARAMETER_KEY_AUD_CALDATA "cal_data"
117
118typedef struct acdb_audio_cal_cfg {
119 uint32_t persist;
120 uint32_t snd_dev_id;
121 audio_devices_t dev_id;
122 int32_t acdb_dev_id;
123 uint32_t app_type;
124 uint32_t topo_id;
125 uint32_t sampling_rate;
126 uint32_t cal_type;
127 uint32_t module_id;
justinwenge880e0c2018-11-22 13:49:38 +0800128#ifdef PLATFORM_SM8150
129 uint16_t instance_id;
130 uint16_t reserved;
131#endif
jasmine chac89321b2018-04-10 21:37:01 +0800132 uint32_t param_id;
133} acdb_audio_cal_cfg_t;
134
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700135/* Audio calibration related functions */
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800136typedef void (*acdb_send_audio_cal_v3_t)(int, int, int, int, int);
Eric Laurentb23d5282013-05-14 15:27:20 -0700137
Eric Laurentb23d5282013-05-14 15:27:20 -0700138struct platform_data {
139 struct audio_device *adev;
140 bool fluence_in_spkr_mode;
141 bool fluence_in_voice_call;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700142 bool fluence_in_voice_comm;
Eric Laurentb23d5282013-05-14 15:27:20 -0700143 bool fluence_in_voice_rec;
Prashant Malanic92c5962015-08-11 15:10:18 -0700144 /* 0 = no fluence, 1 = fluence, 2 = fluence pro */
145 int fluence_type;
146 int source_mic_type;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -0700147 bool speaker_lr_swap;
148
Eric Laurentb23d5282013-05-14 15:27:20 -0700149 void *acdb_handle;
Thierry Strudel07f96d12018-09-20 13:31:34 -0700150#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845) || (PLATFORM_SDM710) || (PLATFORM_SM8150)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -0700151 acdb_init_v2_cvd_t acdb_init;
152#elif defined (PLATFORM_MSM8084)
153 acdb_init_v2_t acdb_init;
154#else
155 acdb_init_t acdb_init;
156#endif
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700157 acdb_deallocate_t acdb_deallocate;
158 acdb_send_audio_cal_t acdb_send_audio_cal;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800159 acdb_send_audio_cal_v3_t acdb_send_audio_cal_v3;
jasmine chac89321b2018-04-10 21:37:01 +0800160 acdb_set_audio_cal_t acdb_set_audio_cal;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700161 acdb_send_voice_cal_t acdb_send_voice_cal;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700162 acdb_reload_vocvoltable_t acdb_reload_vocvoltable;
vivek mehta1a9b7c02015-06-25 11:49:38 -0700163 acdb_send_gain_dep_cal_t acdb_send_gain_dep_cal;
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -0700164 acdb_send_custom_top_t acdb_send_custom_top;
165 bool acdb_initialized;
166
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700167 struct csd_data *csd;
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800168 char ec_ref_mixer_path[64];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700169
David Linee3fe402017-03-13 10:00:42 -0700170 codec_backend_cfg_t current_backend_cfg[MAX_CODEC_BACKENDS];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700171 char *snd_card_name;
keunhui.parkc5aaa0e2015-07-13 10:57:37 +0900172 int max_vol_index;
Prashant Malanic92c5962015-08-11 15:10:18 -0700173 int max_mic_count;
vivek mehtade4849c2016-03-03 17:23:38 -0800174
175 void *hw_info;
jiabin8962a4d2018-03-19 18:21:24 -0700176
177 uint32_t declared_mic_count;
178 struct audio_microphone_characteristic_t microphones[AUDIO_MICROPHONE_MAX_COUNT];
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -0700179 struct snd_device_to_mic_map mic_map[SND_DEVICE_MAX];
Eric Laurentb23d5282013-05-14 15:27:20 -0700180};
181
Haynes Mathew George98c95622014-06-20 19:14:25 -0700182static int pcm_device_table[AUDIO_USECASE_MAX][2] = {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700183 [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = {DEEP_BUFFER_PCM_DEVICE,
184 DEEP_BUFFER_PCM_DEVICE},
185 [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
186 LOWLATENCY_PCM_DEVICE},
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800187 [USECASE_AUDIO_PLAYBACK_HIFI] = {MULTIMEDIA2_PCM_DEVICE,
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700188 MULTIMEDIA2_PCM_DEVICE},
189 [USECASE_AUDIO_PLAYBACK_OFFLOAD] = {PLAYBACK_OFFLOAD_DEVICE,
190 PLAYBACK_OFFLOAD_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700191 [USECASE_AUDIO_PLAYBACK_TTS] = {MULTIMEDIA2_PCM_DEVICE,
192 MULTIMEDIA2_PCM_DEVICE},
193 [USECASE_AUDIO_PLAYBACK_ULL] = {MULTIMEDIA3_PCM_DEVICE,
194 MULTIMEDIA3_PCM_DEVICE},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800195 [USECASE_AUDIO_PLAYBACK_MMAP] = {MMAP_PLAYBACK_PCM_DEVICE,
196 MMAP_PLAYBACK_PCM_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700197
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700198 [USECASE_AUDIO_RECORD] = {AUDIO_RECORD_PCM_DEVICE,
199 AUDIO_RECORD_PCM_DEVICE},
200 [USECASE_AUDIO_RECORD_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
201 LOWLATENCY_PCM_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700202
Eric Laurent0e46adf2016-12-16 12:49:24 -0800203 [USECASE_AUDIO_RECORD_MMAP] = {MMAP_RECORD_PCM_DEVICE,
204 MMAP_RECORD_PCM_DEVICE},
Haynes Mathew George569b7482017-05-08 14:44:27 -0700205 [USECASE_AUDIO_RECORD_HIFI] = {MULTIMEDIA2_PCM_DEVICE,
206 MULTIMEDIA2_PCM_DEVICE},
207
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700208 [USECASE_VOICE_CALL] = {VOICE_CALL_PCM_DEVICE,
209 VOICE_CALL_PCM_DEVICE},
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700210 [USECASE_VOICE2_CALL] = {VOICE2_CALL_PCM_DEVICE, VOICE2_CALL_PCM_DEVICE},
211 [USECASE_VOLTE_CALL] = {VOLTE_CALL_PCM_DEVICE, VOLTE_CALL_PCM_DEVICE},
212 [USECASE_QCHAT_CALL] = {QCHAT_CALL_PCM_DEVICE, QCHAT_CALL_PCM_DEVICE},
213 [USECASE_VOWLAN_CALL] = {VOWLAN_CALL_PCM_DEVICE, VOWLAN_CALL_PCM_DEVICE},
vivek mehtaa51fd402016-02-04 19:49:33 -0800214 [USECASE_VOICEMMODE1_CALL] = {VOICEMMODE1_CALL_PCM_DEVICE,
215 VOICEMMODE1_CALL_PCM_DEVICE},
216 [USECASE_VOICEMMODE2_CALL] = {VOICEMMODE2_CALL_PCM_DEVICE,
217 VOICEMMODE2_CALL_PCM_DEVICE},
218
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700219 [USECASE_INCALL_REC_UPLINK] = {AUDIO_RECORD_PCM_DEVICE,
220 AUDIO_RECORD_PCM_DEVICE},
221 [USECASE_INCALL_REC_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
222 AUDIO_RECORD_PCM_DEVICE},
223 [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
224 AUDIO_RECORD_PCM_DEVICE},
Ravi Kumar Alamanda8e6e98f2013-11-05 15:57:39 -0800225 [USECASE_AUDIO_HFP_SCO] = {HFP_PCM_RX, HFP_SCO_RX},
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700226
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700227 [USECASE_AUDIO_SPKR_CALIB_RX] = {SPKR_PROT_CALIB_RX_PCM_DEVICE, -1},
228 [USECASE_AUDIO_SPKR_CALIB_TX] = {-1, SPKR_PROT_CALIB_TX_PCM_DEVICE},
229
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700230 [USECASE_AUDIO_PLAYBACK_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
231 AFE_PROXY_RECORD_PCM_DEVICE},
232 [USECASE_AUDIO_RECORD_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
233 AFE_PROXY_RECORD_PCM_DEVICE},
zhaoyang yin4211fad2015-06-04 21:13:25 +0800234 [USECASE_AUDIO_DSM_FEEDBACK] = {QUAT_MI2S_PCM_DEVICE, QUAT_MI2S_PCM_DEVICE},
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700235
vivek mehtaa68fea62017-06-08 19:04:02 -0700236 [USECASE_AUDIO_PLAYBACK_VOIP] = {AUDIO_PLAYBACK_VOIP_PCM_DEVICE,
237 AUDIO_PLAYBACK_VOIP_PCM_DEVICE},
238 [USECASE_AUDIO_RECORD_VOIP] = {AUDIO_RECORD_VOIP_PCM_DEVICE,
239 AUDIO_RECORD_VOIP_PCM_DEVICE},
Nadav Bar3d72cfc2018-01-07 12:19:24 +0200240
241 [USECASE_INCALL_MUSIC_UPLINK] = {INCALL_MUSIC_UPLINK_PCM_DEVICE,
242 INCALL_MUSIC_UPLINK_PCM_DEVICE},
Eric Laurentb23d5282013-05-14 15:27:20 -0700243};
244
245/* Array to store sound devices */
246static const char * const device_table[SND_DEVICE_MAX] = {
247 [SND_DEVICE_NONE] = "none",
248 /* Playback sound devices */
249 [SND_DEVICE_OUT_HANDSET] = "handset",
250 [SND_DEVICE_OUT_SPEAKER] = "speaker",
251 [SND_DEVICE_OUT_SPEAKER_REVERSE] = "speaker-reverse",
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700252 [SND_DEVICE_OUT_SPEAKER_SAFE] = "speaker-safe",
Eric Laurentb23d5282013-05-14 15:27:20 -0700253 [SND_DEVICE_OUT_HEADPHONES] = "headphones",
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500254 [SND_DEVICE_OUT_LINE] = "line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700255 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones",
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700256 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = "speaker-safe-and-headphones",
Eric Laurent744996b2014-10-01 11:40:40 -0500257 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = "speaker-and-line",
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700258 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = "speaker-safe-and-line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700259 [SND_DEVICE_OUT_VOICE_HANDSET] = "voice-handset",
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500260 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = "voice-hac-handset",
Eric Laurentb23d5282013-05-14 15:27:20 -0700261 [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker",
262 [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones",
yixuanjiang9536e672018-09-06 18:43:36 +0800263 [SND_DEVICE_OUT_VOICE_HEADSET] = "voice-headphones",
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500264 [SND_DEVICE_OUT_VOICE_LINE] = "voice-line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700265 [SND_DEVICE_OUT_HDMI] = "hdmi",
266 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi",
267 [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700268 [SND_DEVICE_OUT_BT_SCO_WB] = "bt-sco-headset-wb",
Aniket Kumar Lata26483012018-01-31 20:21:42 -0800269 [SND_DEVICE_OUT_BT_A2DP] = "bt-a2dp",
270 [SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] = "speaker-and-bt-a2dp",
Aniket Kumar Lata9723a962018-05-16 17:41:55 -0700271 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP] = "speaker-safe-and-bt-a2dp",
Eric Laurentb23d5282013-05-14 15:27:20 -0700272 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = "voice-handset-tmus",
273 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones",
274 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones",
275 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset",
vivek mehtaa6b79742017-03-09 15:40:43 -0800276 [SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = "voice-tty-full-usb",
277 [SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = "voice-tty-vco-usb",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700278 [SND_DEVICE_OUT_VOICE_TX] = "voice-tx",
juyuchen66c4ecf2018-08-06 15:39:34 +0800279 [SND_DEVICE_OUT_VOICE_MUSIC_TX] = "voice-music-tx",
David Linee3fe402017-03-13 10:00:42 -0700280 [SND_DEVICE_OUT_USB_HEADSET] = "usb-headset",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700281 [SND_DEVICE_OUT_VOICE_USB_HEADSET] = "usb-headset",
David Linee3fe402017-03-13 10:00:42 -0700282 [SND_DEVICE_OUT_USB_HEADPHONES] = "usb-headphones",
jasmine cha270b7762018-03-30 15:41:33 +0800283 [SND_DEVICE_OUT_USB_HEADSET_SPEC] = "usb-headset",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700284 [SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = "usb-headphones",
David Linee3fe402017-03-13 10:00:42 -0700285 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = "speaker-and-usb-headphones",
Haynes Mathew George9090bfb2017-05-31 11:44:50 -0700286 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] = "speaker-safe-and-usb-headphones",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700287 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = "speaker-protected",
288 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = "voice-speaker-protected",
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -0700289 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = "voice-speaker-hfp",
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -0800290 [SND_DEVICE_OUT_SPEAKER_AND_BT_SCO] = "speaker-and-bt-sco",
juyuchen5351ea62018-05-16 10:54:37 +0800291 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO] = "speaker-safe-and-bt-sco",
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -0800292 [SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB] = "speaker-and-bt-sco-wb",
juyuchen5351ea62018-05-16 10:54:37 +0800293 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB] = "speaker-safe-and-bt-sco-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700294
295 /* Capture sound devices */
296 [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700297 [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700298 [SND_DEVICE_IN_HANDSET_MIC_NS] = "handset-mic",
299 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = "handset-mic",
300 [SND_DEVICE_IN_HANDSET_DMIC] = "dmic-endfire",
301 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = "dmic-endfire",
302 [SND_DEVICE_IN_HANDSET_DMIC_NS] = "dmic-endfire",
303 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = "dmic-endfire",
304 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = "dmic-endfire",
305
306 [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
307 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "speaker-mic",
308 [SND_DEVICE_IN_SPEAKER_MIC_NS] = "speaker-mic",
309 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = "speaker-mic",
310 [SND_DEVICE_IN_SPEAKER_DMIC] = "speaker-dmic-endfire",
311 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = "speaker-dmic-endfire",
312 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = "speaker-dmic-endfire",
313 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = "speaker-dmic-endfire",
314 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = "speaker-dmic-endfire",
315
316 [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
Eric Laurentcefbbac2014-09-04 13:54:10 -0500317 [SND_DEVICE_IN_HEADSET_MIC_AEC] = "headset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700318
Eric Laurentb23d5282013-05-14 15:27:20 -0700319 [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic",
320 [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700321 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = "bt-sco-mic",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700322 [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700323 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = "bt-sco-mic-wb",
Eric Laurent5f4ca952018-10-19 17:33:43 -0700324 [SND_DEVICE_IN_CAMCORDER_LANDSCAPE] = "camcorder-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700325
326 [SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef",
327 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = "voice-dmic-ef-tmus",
328 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
329 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = "voice-speaker-dmic-ef",
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -0700330 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = "voice-speaker-mic-hfp",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700331 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700332 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
333 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
334 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
vivek mehtaa6b79742017-03-09 15:40:43 -0800335 [SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = "voice-tty-full-usb-mic",
336 [SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = "voice-tty-hco-usb-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700337
Eric Laurentb23d5282013-05-14 15:27:20 -0700338 [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700339 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = "voice-rec-mic",
vivek mehta733c1df2016-04-04 15:09:24 -0700340 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = "voice-rec-mic",
vivek mehtaf3440682016-05-11 14:24:37 -0700341 [SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700342 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = "voice-rec-dmic-ef",
343 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence",
David Linee3fe402017-03-13 10:00:42 -0700344 [SND_DEVICE_IN_USB_HEADSET_MIC] = "usb-headset-mic",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700345 [SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] ="usb-headset-mic",
346 [SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = "usb-headset-mic",
347 [SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = "usb-headset-mic",
348 [SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = "usb-headset-mic",
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700349 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = "headset-mic",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700350
Ricardo Garcia9034bc42016-04-04 07:11:46 -0700351 [SND_DEVICE_IN_UNPROCESSED_MIC] = "unprocessed-mic",
vivek mehta0125e782016-06-16 18:03:11 -0700352 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = "unprocessed-stereo-mic",
353 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = "unprocessed-three-mic",
354 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = "unprocessed-quad-mic",
355 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = "unprocessed-headset-mic",
rago90fb9612015-12-02 11:37:53 -0800356
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700357 [SND_DEVICE_IN_VOICE_RX] = "voice-rx",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700358
Prashant Malanic92c5962015-08-11 15:10:18 -0700359 [SND_DEVICE_IN_THREE_MIC] = "three-mic",
360 [SND_DEVICE_IN_QUAD_MIC] = "quad-mic",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700361 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = "vi-feedback",
Prashant Malanic92c5962015-08-11 15:10:18 -0700362 [SND_DEVICE_IN_HANDSET_TMIC] = "three-mic",
363 [SND_DEVICE_IN_HANDSET_QMIC] = "quad-mic",
vivek mehta733c1df2016-04-04 15:09:24 -0700364 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = "three-mic",
365 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = "quad-mic",
Eric Laurent5f4ca952018-10-19 17:33:43 -0700366 [SND_DEVICE_IN_CAMCORDER_INVERT_LANDSCAPE] = "camcorder-mic",
367 [SND_DEVICE_IN_CAMCORDER_PORTRAIT] = "camcorder-mic",
368 [SND_DEVICE_IN_CAMCORDER_SELFIE_LANDSCAPE] = "camcorder-mic",
369 [SND_DEVICE_IN_CAMCORDER_SELFIE_INVERT_LANDSCAPE] = "camcorder-mic",
370 [SND_DEVICE_IN_CAMCORDER_SELFIE_PORTRAIT] = "camcorder-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700371};
372
373/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700374static int acdb_device_table[SND_DEVICE_MAX] = {
Eric Laurentb23d5282013-05-14 15:27:20 -0700375 [SND_DEVICE_NONE] = -1,
376 [SND_DEVICE_OUT_HANDSET] = 7,
377 [SND_DEVICE_OUT_SPEAKER] = 15,
378 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 15,
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700379 [SND_DEVICE_OUT_SPEAKER_SAFE] = 15,
Eric Laurentb23d5282013-05-14 15:27:20 -0700380 [SND_DEVICE_OUT_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500381 [SND_DEVICE_OUT_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700382 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700383 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500384 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = 77,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700385 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = 77,
Ravi Kumar Alamanda235c3482014-08-21 17:32:44 -0700386 [SND_DEVICE_OUT_VOICE_HANDSET] = ACDB_ID_VOICE_HANDSET,
387 [SND_DEVICE_OUT_VOICE_SPEAKER] = ACDB_ID_VOICE_SPEAKER,
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500388 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = 53,
Eric Laurentb23d5282013-05-14 15:27:20 -0700389 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
yixuanjiang9536e672018-09-06 18:43:36 +0800390 [SND_DEVICE_OUT_VOICE_HEADSET] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500391 [SND_DEVICE_OUT_VOICE_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700392 [SND_DEVICE_OUT_HDMI] = 18,
393 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 15,
394 [SND_DEVICE_OUT_BT_SCO] = 22,
juyuchen5351ea62018-05-16 10:54:37 +0800395 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO] = 14,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700396 [SND_DEVICE_OUT_BT_SCO_WB] = 39,
juyuchen5351ea62018-05-16 10:54:37 +0800397 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB] = 14,
Aniket Kumar Lata26483012018-01-31 20:21:42 -0800398 [SND_DEVICE_OUT_BT_A2DP] = 20,
399 [SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] = 14,
Aniket Kumar Lata9723a962018-05-16 17:41:55 -0700400 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP] = 14,
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700401 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = ACDB_ID_VOICE_HANDSET_TMUS,
Eric Laurentb23d5282013-05-14 15:27:20 -0700402 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
403 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
404 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
vivek mehtaa6b79742017-03-09 15:40:43 -0800405 [SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = 17,
406 [SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = 17,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700407 [SND_DEVICE_OUT_VOICE_TX] = 45,
juyuchen66c4ecf2018-08-06 15:39:34 +0800408 [SND_DEVICE_OUT_VOICE_MUSIC_TX] = 3,
David Linee3fe402017-03-13 10:00:42 -0700409 [SND_DEVICE_OUT_USB_HEADSET] = 45,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700410 [SND_DEVICE_OUT_VOICE_USB_HEADSET] = 45,
David Linee3fe402017-03-13 10:00:42 -0700411 [SND_DEVICE_OUT_USB_HEADPHONES] = 45,
jasmine cha270b7762018-03-30 15:41:33 +0800412 [SND_DEVICE_OUT_USB_HEADSET_SPEC] = 45,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700413 [SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = 45,
David Linee3fe402017-03-13 10:00:42 -0700414 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = 14,
Haynes Mathew George9090bfb2017-05-31 11:44:50 -0700415 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] = 14,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700416 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = 124,
417 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = 101,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700418 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = ACDB_ID_VOICE_SPEAKER,
Eric Laurentb23d5282013-05-14 15:27:20 -0700419
420 [SND_DEVICE_IN_HANDSET_MIC] = 4,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700421 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 106,
422 [SND_DEVICE_IN_HANDSET_MIC_NS] = 107,
423 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = 108,
424 [SND_DEVICE_IN_HANDSET_DMIC] = 41,
425 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = 109,
426 [SND_DEVICE_IN_HANDSET_DMIC_NS] = 110,
427 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = 111,
428 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = 34,
429
430 [SND_DEVICE_IN_SPEAKER_MIC] = 11,
431 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 112,
432 [SND_DEVICE_IN_SPEAKER_MIC_NS] = 113,
433 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = 114,
434 [SND_DEVICE_IN_SPEAKER_DMIC] = 43,
435 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = 115,
436 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = 116,
437 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = 117,
438 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = 35,
439
rago90fb9612015-12-02 11:37:53 -0800440 [SND_DEVICE_IN_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentcefbbac2014-09-04 13:54:10 -0500441 [SND_DEVICE_IN_HEADSET_MIC_AEC] = ACDB_ID_HEADSET_MIC_AEC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700442
Eric Laurentb23d5282013-05-14 15:27:20 -0700443 [SND_DEVICE_IN_HDMI_MIC] = 4,
444 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700445 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = 21,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700446 [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700447 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = 38,
Eric Laurent5f4ca952018-10-19 17:33:43 -0700448 [SND_DEVICE_IN_CAMCORDER_LANDSCAPE] = 61,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700449
450 [SND_DEVICE_IN_VOICE_DMIC] = 41,
451 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = ACDB_ID_VOICE_DMIC_EF_TMUS,
452 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700453 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = 11,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700454 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 43,
rago90fb9612015-12-02 11:37:53 -0800455 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentb23d5282013-05-14 15:27:20 -0700456 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
457 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
458 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
vivek mehtaa6b79742017-03-09 15:40:43 -0800459 [SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = 16,
460 [SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = 16,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700461
rago90fb9612015-12-02 11:37:53 -0800462 [SND_DEVICE_IN_VOICE_REC_MIC] = ACDB_ID_VOICE_REC_MIC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700463 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = 113,
vivek mehta733c1df2016-04-04 15:09:24 -0700464 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = 112,
vivek mehtaf3440682016-05-11 14:24:37 -0700465 [SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = 114,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700466 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = 35,
467 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 43,
rago90fb9612015-12-02 11:37:53 -0800468 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
469
470 [SND_DEVICE_IN_UNPROCESSED_MIC] = ACDB_ID_VOICE_REC_MIC,
471 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
vivek mehta4ed66e62016-04-15 23:33:34 -0700472 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = 35,
473 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = 125,
474 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = 125,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700475
476 [SND_DEVICE_IN_VOICE_RX] = 44,
David Linee3fe402017-03-13 10:00:42 -0700477 [SND_DEVICE_IN_USB_HEADSET_MIC] = 44,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700478 [SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = 44,
479 [SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = 44,
480 [SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = 44,
481 [SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = 44,
Prashant Malanic92c5962015-08-11 15:10:18 -0700482 [SND_DEVICE_IN_THREE_MIC] = 46,
483 [SND_DEVICE_IN_QUAD_MIC] = 46,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700484 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = 102,
Prashant Malanic92c5962015-08-11 15:10:18 -0700485 [SND_DEVICE_IN_HANDSET_TMIC] = 125,
486 [SND_DEVICE_IN_HANDSET_QMIC] = 125,
vivek mehta733c1df2016-04-04 15:09:24 -0700487 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = 125, /* override this for new target to 140 */
488 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = 125, /* override this for new target to 140 */
Eric Laurent5f4ca952018-10-19 17:33:43 -0700489 [SND_DEVICE_IN_CAMCORDER_INVERT_LANDSCAPE] = 61,
490 [SND_DEVICE_IN_CAMCORDER_PORTRAIT] = 61,
491 [SND_DEVICE_IN_CAMCORDER_SELFIE_LANDSCAPE] = 61,
492 [SND_DEVICE_IN_CAMCORDER_SELFIE_INVERT_LANDSCAPE] = 61,
493 [SND_DEVICE_IN_CAMCORDER_SELFIE_PORTRAIT] = 61,
Eric Laurentb23d5282013-05-14 15:27:20 -0700494};
495
David Linee3fe402017-03-13 10:00:42 -0700496// Platform specific backend bit width table
497static int backend_bit_width_table[SND_DEVICE_MAX] = {0};
498
Haynes Mathew George98c95622014-06-20 19:14:25 -0700499struct name_to_index {
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700500 char name[100];
501 unsigned int index;
502};
503
504#define TO_NAME_INDEX(X) #X, X
505
Haynes Mathew George98c95622014-06-20 19:14:25 -0700506/* Used to get index from parsed string */
507static const struct name_to_index snd_device_name_index[SND_DEVICE_MAX] = {
508 /* out */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700509 {TO_NAME_INDEX(SND_DEVICE_OUT_HANDSET)},
510 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER)},
511 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_REVERSE)},
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700512 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700513 {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500514 {TO_NAME_INDEX(SND_DEVICE_OUT_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700515 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700516 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES)},
Eric Laurent744996b2014-10-01 11:40:40 -0500517 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_LINE)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700518 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700519 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET)},
520 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700521 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_HFP)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700522 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADPHONES)},
yixuanjiang9536e672018-09-06 18:43:36 +0800523 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADSET)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500524 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700525 {TO_NAME_INDEX(SND_DEVICE_OUT_HDMI)},
526 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HDMI)},
527 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO)},
juyuchen5351ea62018-05-16 10:54:37 +0800528 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700529 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO_WB)},
juyuchen5351ea62018-05-16 10:54:37 +0800530 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB)},
Aniket Kumar Lata26483012018-01-31 20:21:42 -0800531 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_A2DP)},
532 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP)},
Aniket Kumar Lata9723a962018-05-16 17:41:55 -0700533 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700534 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET_TMUS)},
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500535 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HAC_HANDSET)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700536 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES)},
537 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES)},
538 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET)},
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -0800539 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_SCO)},
540 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800541 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_USB)},
542 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_USB)},
David Linee3fe402017-03-13 10:00:42 -0700543 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADSET)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700544 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_USB_HEADSET)},
David Linee3fe402017-03-13 10:00:42 -0700545 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADPHONES)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700546 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_USB_HEADPHONES)},
David Linee3fe402017-03-13 10:00:42 -0700547 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET)},
Haynes Mathew George9090bfb2017-05-31 11:44:50 -0700548 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700549 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED)},
550 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED)},
jasmine cha270b7762018-03-30 15:41:33 +0800551 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADSET_SPEC)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800552
553 /* in */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700554 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700555 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700556 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_NS)},
557 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)},
558 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC)},
559 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC)},
560 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_NS)},
561 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)},
562 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_STEREO)},
563
564 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700565 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700566 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_NS)},
567 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)},
568 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC)},
569 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC)},
570 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS)},
571 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)},
572 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_STEREO)},
573
574 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC)},
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700575 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700576
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700577 {TO_NAME_INDEX(SND_DEVICE_IN_HDMI_MIC)},
578 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700579 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700580 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700581 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB_NREC)},
Eric Laurent5f4ca952018-10-19 17:33:43 -0700582 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_LANDSCAPE)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700583
584 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC)},
585 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC_TMUS)},
586 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700587 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700588 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC)},
589 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEADSET_MIC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700590 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC)},
591 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC)},
592 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800593 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC)},
594 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC)},
595
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700596
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700597 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700598 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_NS)},
vivek mehta733c1df2016-04-04 15:09:24 -0700599 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC)},
vivek mehtaf3440682016-05-11 14:24:37 -0700600 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700601 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_STEREO)},
602 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE)},
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700603 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_HEADSET_MIC)},
David Linee3fe402017-03-13 10:00:42 -0700604 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700605 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_USB_HEADSET_MIC)},
606 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC)},
607 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC)},
608 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC_AEC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700609
rago90fb9612015-12-02 11:37:53 -0800610 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_MIC)},
611 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC)},
vivek mehta4ed66e62016-04-15 23:33:34 -0700612 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_STEREO_MIC)},
613 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_THREE_MIC)},
614 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_QUAD_MIC)},
rago90fb9612015-12-02 11:37:53 -0800615
Prashant Malanic92c5962015-08-11 15:10:18 -0700616 {TO_NAME_INDEX(SND_DEVICE_IN_THREE_MIC)},
617 {TO_NAME_INDEX(SND_DEVICE_IN_QUAD_MIC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700618 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_VI_FEEDBACK)},
Prashant Malanic92c5962015-08-11 15:10:18 -0700619 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC)},
620 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC)},
vivek mehta733c1df2016-04-04 15:09:24 -0700621 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC_AEC)},
622 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC_AEC)},
Eric Laurent5f4ca952018-10-19 17:33:43 -0700623 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_INVERT_LANDSCAPE)},
624 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_PORTRAIT)},
625 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_SELFIE_LANDSCAPE)},
626 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_SELFIE_INVERT_LANDSCAPE)},
627 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_SELFIE_PORTRAIT)},
628 /* For legacy xml file parsing */
629 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700630};
631
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700632static char * backend_tag_table[SND_DEVICE_MAX] = {0};
633static char * hw_interface_table[SND_DEVICE_MAX] = {0};
Haynes Mathew George98c95622014-06-20 19:14:25 -0700634
635static const struct name_to_index usecase_name_index[AUDIO_USECASE_MAX] = {
636 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_DEEP_BUFFER)},
637 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_LOW_LATENCY)},
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800638 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_HIFI)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700639 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD)},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700640 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_TTS)},
641 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_ULL)},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800642 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_MMAP)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700643 {TO_NAME_INDEX(USECASE_AUDIO_RECORD)},
644 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_LOW_LATENCY)},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800645 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_MMAP)},
Haynes Mathew George569b7482017-05-08 14:44:27 -0700646 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_HIFI)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700647 {TO_NAME_INDEX(USECASE_VOICE_CALL)},
648 {TO_NAME_INDEX(USECASE_VOICE2_CALL)},
649 {TO_NAME_INDEX(USECASE_VOLTE_CALL)},
650 {TO_NAME_INDEX(USECASE_QCHAT_CALL)},
651 {TO_NAME_INDEX(USECASE_VOWLAN_CALL)},
John Muirf1346ce2016-12-06 00:03:41 -0800652 {TO_NAME_INDEX(USECASE_VOICEMMODE1_CALL)},
653 {TO_NAME_INDEX(USECASE_VOICEMMODE2_CALL)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700654 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK)},
655 {TO_NAME_INDEX(USECASE_INCALL_REC_DOWNLINK)},
656 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK_AND_DOWNLINK)},
657 {TO_NAME_INDEX(USECASE_AUDIO_HFP_SCO)},
John Muirf1346ce2016-12-06 00:03:41 -0800658 {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_RX)},
659 {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_TX)},
660 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_AFE_PROXY)},
661 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_AFE_PROXY)},
662 {TO_NAME_INDEX(USECASE_AUDIO_DSM_FEEDBACK)},
vivek mehtaa68fea62017-06-08 19:04:02 -0700663 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_VOIP)},
664 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_VOIP)},
Nadav Bar3d72cfc2018-01-07 12:19:24 +0200665 {TO_NAME_INDEX(USECASE_INCALL_MUSIC_UPLINK)},
Aniket Kumar Lata99546312018-03-19 21:38:38 -0700666 {TO_NAME_INDEX(USECASE_AUDIO_A2DP_ABR_FEEDBACK)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700667};
668
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800669static const struct name_to_index usecase_type_index[USECASE_TYPE_MAX] = {
670 {TO_NAME_INDEX(PCM_PLAYBACK)},
671 {TO_NAME_INDEX(PCM_CAPTURE)},
672 {TO_NAME_INDEX(VOICE_CALL)},
673 {TO_NAME_INDEX(PCM_HFP_CALL)},
674};
675
676struct app_type_entry {
677 int uc_type;
678 int bit_width;
679 int app_type;
680 int max_rate;
vivek mehtaa68fea62017-06-08 19:04:02 -0700681 char *mode;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800682 struct listnode node; // membership in app_type_entry_list;
683};
684
685static struct listnode app_type_entry_list;
686
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700687#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
688#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
Eric Laurent0e46adf2016-12-16 12:49:24 -0800689#define ULL_PLATFORM_DELAY (3*1000LL)
690#define MMAP_PLATFORM_DELAY (3*1000LL)
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700691
Eric Laurentb23d5282013-05-14 15:27:20 -0700692static pthread_once_t check_op_once_ctl = PTHREAD_ONCE_INIT;
693static bool is_tmus = false;
694
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800695static int init_be_dai_name_table(struct audio_device *adev);
696
Eric Laurentb23d5282013-05-14 15:27:20 -0700697static void check_operator()
698{
699 char value[PROPERTY_VALUE_MAX];
700 int mccmnc;
701 property_get("gsm.sim.operator.numeric",value,"0");
702 mccmnc = atoi(value);
Eric Laurent2bafff12016-03-17 12:17:23 -0700703 ALOGD("%s: tmus mccmnc %d", __func__, mccmnc);
Eric Laurentb23d5282013-05-14 15:27:20 -0700704 switch(mccmnc) {
705 /* TMUS MCC(310), MNC(490, 260, 026) */
706 case 310490:
707 case 310260:
708 case 310026:
sangwon.jeonb891db52013-09-14 17:39:15 +0900709 /* Add new TMUS MNC(800, 660, 580, 310, 270, 250, 240, 230, 220, 210, 200, 160) */
710 case 310800:
711 case 310660:
712 case 310580:
713 case 310310:
714 case 310270:
715 case 310250:
716 case 310240:
717 case 310230:
718 case 310220:
719 case 310210:
720 case 310200:
721 case 310160:
Eric Laurentb23d5282013-05-14 15:27:20 -0700722 is_tmus = true;
723 break;
724 }
725}
726
727bool is_operator_tmus()
728{
729 pthread_once(&check_op_once_ctl, check_operator);
730 return is_tmus;
731}
732
keunhui.park2f7306a2015-07-16 16:48:06 +0900733static char *get_current_operator()
734{
735 struct listnode *node;
736 struct operator_info *info_item;
737 char mccmnc[PROPERTY_VALUE_MAX];
738 char *ret = NULL;
739
Tom Cherry7fea2042016-11-10 18:05:59 -0800740 property_get("gsm.sim.operator.numeric",mccmnc,"00000");
keunhui.park2f7306a2015-07-16 16:48:06 +0900741
742 list_for_each(node, &operator_info_list) {
743 info_item = node_to_item(node, struct operator_info, list);
744 if (strstr(info_item->mccmnc, mccmnc) != NULL) {
745 ret = info_item->name;
746 }
747 }
748
749 return ret;
750}
751
752static struct operator_specific_device *get_operator_specific_device(snd_device_t snd_device)
753{
754 struct listnode *node;
755 struct operator_specific_device *ret = NULL;
756 struct operator_specific_device *device_item;
757 char *operator_name;
758
759 operator_name = get_current_operator();
760 if (operator_name == NULL)
761 return ret;
762
763 list_for_each(node, operator_specific_device_table[snd_device]) {
764 device_item = node_to_item(node, struct operator_specific_device, list);
765 if (strcmp(operator_name, device_item->operator) == 0) {
766 ret = device_item;
767 }
768 }
769
770 return ret;
771}
772
773
774static int get_operator_specific_device_acdb_id(snd_device_t snd_device)
775{
776 struct operator_specific_device *device;
777 int ret = acdb_device_table[snd_device];
778
779 device = get_operator_specific_device(snd_device);
780 if (device != NULL)
781 ret = device->acdb_id;
782
783 return ret;
784}
785
786static const char *get_operator_specific_device_mixer_path(snd_device_t snd_device)
787{
788 struct operator_specific_device *device;
789 const char *ret = device_table[snd_device];
790
791 device = get_operator_specific_device(snd_device);
792 if (device != NULL)
793 ret = device->mixer_path;
794
795 return ret;
796}
797
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800798inline bool platform_supports_app_type_cfg()
799{
Thierry Strudel07f96d12018-09-20 13:31:34 -0700800#if defined (PLATFORM_MSM8998) || (PLATFORM_SDM845) || (PLATFORM_SDM710) || (PLATFORM_SM8150)
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800801 return true;
802#else
803 return false;
804#endif
805}
806
jasmine chac89321b2018-04-10 21:37:01 +0800807static int parse_audiocal_cfg(struct str_parms *parms, acdb_audio_cal_cfg_t *cal)
808{
809 int err;
810 char value[64];
811 int ret = 0;
812
813 if (parms == NULL || cal == NULL)
814 return ret;
815
816 err = str_parms_get_str(parms, "cal_persist", value, sizeof(value));
817 if (err >= 0) {
818 str_parms_del(parms, "cal_persist");
819 cal->persist = (uint32_t)strtoul(value, NULL, 0);
820 ret = ret | 0x1;
821 }
822 err = str_parms_get_str(parms, "cal_apptype", value, sizeof(value));
823 if (err >= 0) {
824 str_parms_del(parms, "cal_apptype");
825 cal->app_type = (uint32_t)strtoul(value, NULL, 0);
826 ret = ret | 0x2;
827 }
828 err = str_parms_get_str(parms, "cal_caltype", value, sizeof(value));
829 if (err >= 0) {
830 str_parms_del(parms, "cal_caltype");
831 cal->cal_type = (uint32_t)strtoul(value, NULL, 0);
832 ret = ret | 0x4;
833 }
834 err = str_parms_get_str(parms, "cal_samplerate", value, sizeof(value));
835 if (err >= 0) {
836 str_parms_del(parms, "cal_samplerate");
837 cal->sampling_rate = (uint32_t)strtoul(value, NULL, 0);
838 ret = ret | 0x8;
839 }
840 err = str_parms_get_str(parms, "cal_devid", value, sizeof(value));
841 if (err >= 0) {
842 str_parms_del(parms, "cal_devid");
843 cal->dev_id = (uint32_t)strtoul(value, NULL, 0);
844 ret = ret | 0x10;
845 }
846 err = str_parms_get_str(parms, "cal_snddevid", value, sizeof(value));
847 if (err >= 0) {
848 str_parms_del(parms, "cal_snddevid");
849 cal->snd_dev_id = (uint32_t)strtoul(value, NULL, 0);
850 ret = ret | 0x20;
851 }
852 err = str_parms_get_str(parms, "cal_topoid", value, sizeof(value));
853 if (err >= 0) {
854 str_parms_del(parms, "cal_topoid");
855 cal->topo_id = (uint32_t)strtoul(value, NULL, 0);
856 ret = ret | 0x40;
857 }
858 err = str_parms_get_str(parms, "cal_moduleid", value, sizeof(value));
859 if (err >= 0) {
860 str_parms_del(parms, "cal_moduleid");
861 cal->module_id = (uint32_t)strtoul(value, NULL, 0);
862 ret = ret | 0x80;
863 }
864 err = str_parms_get_str(parms, "cal_paramid", value, sizeof(value));
865 if (err >= 0) {
866 str_parms_del(parms, "cal_paramid");
867 cal->param_id = (uint32_t)strtoul(value, NULL, 0);
868 ret = ret | 0x100;
869 }
870 return ret;
871}
872
873static void set_audiocal(void *platform, struct str_parms *parms, char *value, int len)
874{
875 struct platform_data *my_data = (struct platform_data *)platform;
876 acdb_audio_cal_cfg_t cal;
877 uint8_t *dptr = NULL;
878 int32_t dlen = 0;
879 int err ,ret;
880
881 if (value == NULL || platform == NULL || parms == NULL) {
882 ALOGE("[%s] received null pointer, failed", __func__);
883 goto done_key_audcal;
884 }
885
886 memset(&cal, 0, sizeof(acdb_audio_cal_cfg_t));
887 /* parse audio calibration keys */
888 ret = parse_audiocal_cfg(parms, &cal);
889
890 /* handle audio calibration data now */
891 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_AUD_CALDATA, value, len);
892 if (err >= 0) {
893 str_parms_del(parms, AUDIO_PARAMETER_KEY_AUD_CALDATA);
894 dlen = strlen(value);
895 if (dlen <= 0) {
896 ALOGE("[%s] null data received", __func__);
897 goto done_key_audcal;
898 }
899 /*
900 The base64 encoded string is always larger than the binary data,
901 so b64_pton will always output less data than provided (around 1/3
902 less than the input data). That's why we can allocate input buffer
903 length and then get function work.
904 */
905 dptr = (uint8_t *)calloc(dlen, sizeof(uint8_t));
906 if (dptr == NULL) {
907 ALOGE("[%s] memory allocation failed for %d", __func__, dlen);
908 goto done_key_audcal;
909 }
910 dlen = b64_pton(value, dptr, dlen);
911 if (dlen <= 0) {
912 ALOGE("[%s] data decoding failed %d", __func__, dlen);
913 goto done_key_audcal;
914 }
915
916 if (cal.dev_id) {
917 if (audio_is_input_device(cal.dev_id)) {
Eric Laurentd1b7a9b2018-11-15 12:24:31 -0800918 // FIXME: why pass an input device whereas
919 // platform_get_input_snd_device() expects as an output device?
920 cal.snd_dev_id = platform_get_input_snd_device(platform, NULL, cal.dev_id);
jasmine chac89321b2018-04-10 21:37:01 +0800921 } else {
922 cal.snd_dev_id = platform_get_output_snd_device(platform, cal.dev_id);
923 }
924 }
925 cal.acdb_dev_id = platform_get_snd_device_acdb_id(cal.snd_dev_id);
926 ALOGD("Setting audio calibration for snd_device(%d) acdb_id(%d)",
927 cal.snd_dev_id, cal.acdb_dev_id);
928 if (cal.acdb_dev_id == -EINVAL) {
929 ALOGE("[%s] Invalid acdb_device id %d for snd device id %d",
930 __func__, cal.acdb_dev_id, cal.snd_dev_id);
931 goto done_key_audcal;
932 }
933 if (my_data->acdb_set_audio_cal) {
934 ret = my_data->acdb_set_audio_cal((void *)&cal, (void *)dptr, dlen);
935 }
936 }
937done_key_audcal:
938 if (dptr != NULL)
939 free(dptr);
940}
941
vivek mehta1a9b7c02015-06-25 11:49:38 -0700942bool platform_send_gain_dep_cal(void *platform, int level)
943{
944 bool ret_val = false;
945 struct platform_data *my_data = (struct platform_data *)platform;
946 struct audio_device *adev = my_data->adev;
947 int acdb_dev_id, app_type;
948 int acdb_dev_type = MSM_SNDDEV_CAP_RX;
949 int mode = CAL_MODE_RTAC;
950 struct listnode *node;
951 struct audio_usecase *usecase;
Haynes Mathew George67486e22017-06-26 12:58:38 -0700952 bool valid_uc_type;
953 bool valid_dev;
vivek mehta1a9b7c02015-06-25 11:49:38 -0700954
955 if (my_data->acdb_send_gain_dep_cal == NULL) {
956 ALOGE("%s: dlsym error for acdb_send_gain_dep_cal", __func__);
957 return ret_val;
958 }
959
960 if (!voice_is_in_call(adev)) {
961 ALOGV("%s: Not Voice call usecase, apply new cal for level %d",
962 __func__, level);
vivek mehta1a9b7c02015-06-25 11:49:38 -0700963
964 // find the current active sound device
965 list_for_each(node, &adev->usecase_list) {
966 usecase = node_to_item(node, struct audio_usecase, list);
Haynes Mathew George67486e22017-06-26 12:58:38 -0700967 LOG_ALWAYS_FATAL_IF(usecase == NULL,
968 "unxpected NULL usecase in usecase_list");
969 valid_uc_type = usecase->type == PCM_PLAYBACK;
970 valid_dev = false;
971 if (valid_uc_type) {
972 audio_devices_t dev = usecase->stream.out->devices;
973 valid_dev = (dev == AUDIO_DEVICE_OUT_SPEAKER ||
vivek mehta40125092017-08-21 18:48:51 -0700974 dev == AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Haynes Mathew George67486e22017-06-26 12:58:38 -0700975 dev == AUDIO_DEVICE_OUT_WIRED_HEADSET ||
976 dev == AUDIO_DEVICE_OUT_WIRED_HEADPHONE);
977 }
978 if (valid_dev) {
vivek mehta40125092017-08-21 18:48:51 -0700979 ALOGV("%s: out device is %d", __func__, usecase->out_snd_device);
980 if (platform_supports_app_type_cfg())
981 app_type = usecase->stream.out->app_type_cfg.app_type;
982 else
983 app_type = DEFAULT_APP_TYPE_RX_PATH;
vivek mehta4cb82982015-07-13 12:05:49 -0700984
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -0700985 acdb_dev_id = platform_get_snd_device_acdb_id(usecase->out_snd_device);
vivek mehta40125092017-08-21 18:48:51 -0700986
987 if (!my_data->acdb_send_gain_dep_cal(acdb_dev_id, app_type,
vivek mehta1a9b7c02015-06-25 11:49:38 -0700988 acdb_dev_type, mode, level)) {
989 // set ret_val true if at least one calibration is set successfully
990 ret_val = true;
991 } else {
992 ALOGE("%s: my_data->acdb_send_gain_dep_cal failed ", __func__);
993 }
994 } else {
995 ALOGW("%s: Usecase list is empty", __func__);
996 }
997 }
998 } else {
999 ALOGW("%s: Voice call in progress .. ignore setting new cal",
1000 __func__);
1001 }
1002 return ret_val;
1003}
1004
Eric Laurentcefbbac2014-09-04 13:54:10 -05001005void platform_set_echo_reference(struct audio_device *adev, bool enable, audio_devices_t out_device)
Eric Laurentb23d5282013-05-14 15:27:20 -07001006{
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08001007 struct platform_data *my_data = (struct platform_data *)adev->platform;
Eric Laurentcefbbac2014-09-04 13:54:10 -05001008 snd_device_t snd_device = SND_DEVICE_NONE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001009
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08001010 if (strcmp(my_data->ec_ref_mixer_path, "")) {
1011 ALOGV("%s: diabling %s", __func__, my_data->ec_ref_mixer_path);
1012 audio_route_reset_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
Eric Laurentcefbbac2014-09-04 13:54:10 -05001013 }
1014
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08001015 if (enable) {
1016 strcpy(my_data->ec_ref_mixer_path, "echo-reference");
1017 if (out_device != AUDIO_DEVICE_NONE) {
1018 snd_device = platform_get_output_snd_device(adev->platform, out_device);
1019 platform_add_backend_name(adev->platform, my_data->ec_ref_mixer_path, snd_device);
1020 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05001021
Joe Onorato188b6222016-03-01 11:02:27 -08001022 ALOGV("%s: enabling %s", __func__, my_data->ec_ref_mixer_path);
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08001023 audio_route_apply_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
1024 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001025}
1026
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001027static struct csd_data *open_csd_client(bool i2s_ext_modem)
1028{
1029 struct csd_data *csd = calloc(1, sizeof(struct csd_data));
1030
1031 csd->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
1032 if (csd->csd_client == NULL) {
1033 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
1034 goto error;
1035 } else {
1036 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
1037
1038 csd->deinit = (deinit_t)dlsym(csd->csd_client,
1039 "csd_client_deinit");
1040 if (csd->deinit == NULL) {
1041 ALOGE("%s: dlsym error %s for csd_client_deinit", __func__,
1042 dlerror());
1043 goto error;
1044 }
1045 csd->disable_device = (disable_device_t)dlsym(csd->csd_client,
1046 "csd_client_disable_device");
1047 if (csd->disable_device == NULL) {
1048 ALOGE("%s: dlsym error %s for csd_client_disable_device",
1049 __func__, dlerror());
1050 goto error;
1051 }
1052 csd->enable_device_config = (enable_device_config_t)dlsym(csd->csd_client,
1053 "csd_client_enable_device_config");
1054 if (csd->enable_device_config == NULL) {
1055 ALOGE("%s: dlsym error %s for csd_client_enable_device_config",
1056 __func__, dlerror());
1057 goto error;
1058 }
1059 csd->enable_device = (enable_device_t)dlsym(csd->csd_client,
1060 "csd_client_enable_device");
1061 if (csd->enable_device == NULL) {
1062 ALOGE("%s: dlsym error %s for csd_client_enable_device",
1063 __func__, dlerror());
1064 goto error;
1065 }
1066 csd->start_voice = (start_voice_t)dlsym(csd->csd_client,
1067 "csd_client_start_voice");
1068 if (csd->start_voice == NULL) {
1069 ALOGE("%s: dlsym error %s for csd_client_start_voice",
1070 __func__, dlerror());
1071 goto error;
1072 }
1073 csd->stop_voice = (stop_voice_t)dlsym(csd->csd_client,
1074 "csd_client_stop_voice");
1075 if (csd->stop_voice == NULL) {
1076 ALOGE("%s: dlsym error %s for csd_client_stop_voice",
1077 __func__, dlerror());
1078 goto error;
1079 }
1080 csd->volume = (volume_t)dlsym(csd->csd_client,
1081 "csd_client_volume");
1082 if (csd->volume == NULL) {
1083 ALOGE("%s: dlsym error %s for csd_client_volume",
1084 __func__, dlerror());
1085 goto error;
1086 }
1087 csd->mic_mute = (mic_mute_t)dlsym(csd->csd_client,
1088 "csd_client_mic_mute");
1089 if (csd->mic_mute == NULL) {
1090 ALOGE("%s: dlsym error %s for csd_client_mic_mute",
1091 __func__, dlerror());
1092 goto error;
1093 }
1094 csd->slow_talk = (slow_talk_t)dlsym(csd->csd_client,
1095 "csd_client_slow_talk");
1096 if (csd->slow_talk == NULL) {
1097 ALOGE("%s: dlsym error %s for csd_client_slow_talk",
1098 __func__, dlerror());
1099 goto error;
1100 }
1101 csd->start_playback = (start_playback_t)dlsym(csd->csd_client,
1102 "csd_client_start_playback");
1103 if (csd->start_playback == NULL) {
1104 ALOGE("%s: dlsym error %s for csd_client_start_playback",
1105 __func__, dlerror());
1106 goto error;
1107 }
1108 csd->stop_playback = (stop_playback_t)dlsym(csd->csd_client,
1109 "csd_client_stop_playback");
1110 if (csd->stop_playback == NULL) {
1111 ALOGE("%s: dlsym error %s for csd_client_stop_playback",
1112 __func__, dlerror());
1113 goto error;
1114 }
1115 csd->start_record = (start_record_t)dlsym(csd->csd_client,
1116 "csd_client_start_record");
1117 if (csd->start_record == NULL) {
1118 ALOGE("%s: dlsym error %s for csd_client_start_record",
1119 __func__, dlerror());
1120 goto error;
1121 }
1122 csd->stop_record = (stop_record_t)dlsym(csd->csd_client,
1123 "csd_client_stop_record");
1124 if (csd->stop_record == NULL) {
1125 ALOGE("%s: dlsym error %s for csd_client_stop_record",
1126 __func__, dlerror());
1127 goto error;
1128 }
1129
1130 csd->get_sample_rate = (get_sample_rate_t)dlsym(csd->csd_client,
1131 "csd_client_get_sample_rate");
1132 if (csd->get_sample_rate == NULL) {
1133 ALOGE("%s: dlsym error %s for csd_client_get_sample_rate",
1134 __func__, dlerror());
1135
1136 goto error;
1137 }
1138
1139 csd->init = (init_t)dlsym(csd->csd_client, "csd_client_init");
1140
1141 if (csd->init == NULL) {
1142 ALOGE("%s: dlsym error %s for csd_client_init",
1143 __func__, dlerror());
1144 goto error;
1145 } else {
1146 csd->init(i2s_ext_modem);
1147 }
1148 }
1149 return csd;
1150
1151error:
1152 free(csd);
1153 csd = NULL;
1154 return csd;
1155}
1156
1157void close_csd_client(struct csd_data *csd)
1158{
1159 if (csd != NULL) {
1160 csd->deinit();
1161 dlclose(csd->csd_client);
1162 free(csd);
1163 csd = NULL;
1164 }
1165}
1166
1167static void platform_csd_init(struct platform_data *my_data)
1168{
1169#ifdef PLATFORM_MSM8084
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001170 int32_t modems, (*count_modems)(void);
1171 const char *name = "libdetectmodem.so";
1172 const char *func = "count_modems";
1173 const char *error;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001174
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001175 my_data->csd = NULL;
1176
1177 void *lib = dlopen(name, RTLD_NOW);
1178 error = dlerror();
1179 if (!lib) {
1180 ALOGE("%s: could not find %s: %s", __func__, name, error);
1181 return;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001182 }
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001183
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001184 count_modems = NULL;
1185 *(void **)(&count_modems) = dlsym(lib, func);
1186 error = dlerror();
1187 if (!count_modems) {
1188 ALOGE("%s: could not find symbol %s in %s: %s",
1189 __func__, func, name, error);
1190 goto done;
1191 }
1192
1193 modems = count_modems();
1194 if (modems < 0) {
1195 ALOGE("%s: count_modems failed\n", __func__);
1196 goto done;
1197 }
1198
Eric Laurent2bafff12016-03-17 12:17:23 -07001199 ALOGD("%s: num_modems %d\n", __func__, modems);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001200 if (modems > 0)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001201 my_data->csd = open_csd_client(false /*is_i2s_ext_modem*/);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001202
1203done:
1204 dlclose(lib);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001205#else
1206 my_data->csd = NULL;
1207#endif
1208}
1209
Eric Laurentc6333382015-09-14 12:43:44 -07001210static void set_platform_defaults(struct platform_data * my_data)
Haynes Mathew George98c95622014-06-20 19:14:25 -07001211{
1212 int32_t dev;
1213 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001214 backend_tag_table[dev] = NULL;
1215 hw_interface_table[dev] = NULL;
keunhui.park2f7306a2015-07-16 16:48:06 +09001216 operator_specific_device_table[dev] = NULL;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001217 }
1218
David Linee3fe402017-03-13 10:00:42 -07001219 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1220 backend_bit_width_table[dev] = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
1221 }
1222
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001223 // To overwrite these go to the audio_platform_info.xml file.
1224 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("bt-sco");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07001225 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("bt-sco");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001226 backend_tag_table[SND_DEVICE_OUT_BT_SCO] = strdup("bt-sco");
1227 backend_tag_table[SND_DEVICE_OUT_HDMI] = strdup("hdmi");
1228 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("speaker-and-hdmi");
1229 backend_tag_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("bt-sco-wb");
1230 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("bt-sco-wb");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07001231 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("bt-sco-wb");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001232 backend_tag_table[SND_DEVICE_OUT_VOICE_TX] = strdup("afe-proxy");
1233 backend_tag_table[SND_DEVICE_IN_VOICE_RX] = strdup("afe-proxy");
Haynes Mathew George98c95622014-06-20 19:14:25 -07001234
David Linee3fe402017-03-13 10:00:42 -07001235 backend_tag_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("usb-headset");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001236 backend_tag_table[SND_DEVICE_OUT_VOICE_USB_HEADSET] = strdup("usb-headset");
David Linee3fe402017-03-13 10:00:42 -07001237 backend_tag_table[SND_DEVICE_OUT_USB_HEADPHONES] = strdup("usb-headphones");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001238 backend_tag_table[SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = strdup("usb-headphones");
David Linee3fe402017-03-13 10:00:42 -07001239 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] =
1240 strdup("speaker-and-usb-headphones");
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07001241 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] =
1242 strdup("speaker-safe-and-usb-headphones");
juyuchen5351ea62018-05-16 10:54:37 +08001243 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO] =
1244 strdup("speaker-safe-and-bt-sco"),
1245 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB] =
1246 strdup("speaker-safe-and-bt-sco-wb"),
David Linee3fe402017-03-13 10:00:42 -07001247 backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("usb-headset-mic");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001248 backend_tag_table[SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1249 backend_tag_table[SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1250 backend_tag_table[SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1251 backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = strdup("usb-headset-mic");
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001252 backend_tag_table[SND_DEVICE_OUT_BT_A2DP] = strdup("bt-a2dp");
1253 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] = strdup("speaker-and-bt-a2dp");
Aniket Kumar Lata9723a962018-05-16 17:41:55 -07001254 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP] = strdup("speaker-safe-and-bt-a2dp");
jasmine cha270b7762018-03-30 15:41:33 +08001255 backend_tag_table[SND_DEVICE_OUT_USB_HEADSET_SPEC] = strdup("usb-headset");
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001256
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001257 hw_interface_table[SND_DEVICE_OUT_HANDSET] = strdup("SLIMBUS_0_RX");
1258 hw_interface_table[SND_DEVICE_OUT_SPEAKER] = strdup("SLIMBUS_0_RX");
1259 hw_interface_table[SND_DEVICE_OUT_SPEAKER_REVERSE] = strdup("SLIMBUS_0_RX");
1260 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE] = strdup("SLIMBUS_0_RX");
1261 hw_interface_table[SND_DEVICE_OUT_HEADPHONES] = strdup("SLIMBUS_0_RX");
1262 hw_interface_table[SND_DEVICE_OUT_LINE] = strdup("SLIMBUS_0_RX");
1263 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001264 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001265 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001266 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001267 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET] = strdup("SLIMBUS_0_RX");
1268 hw_interface_table[SND_DEVICE_OUT_VOICE_HAC_HANDSET] = strdup("SLIMBUS_0_RX");
1269 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER] = strdup("SLIMBUS_0_RX");
1270 hw_interface_table[SND_DEVICE_OUT_VOICE_HEADPHONES] = strdup("SLIMBUS_0_RX");
yixuanjiang9536e672018-09-06 18:43:36 +08001271 hw_interface_table[SND_DEVICE_OUT_VOICE_HEADSET] = strdup("SLIMBUS_0_RX");
juyuchen66c4ecf2018-08-06 15:39:34 +08001272 hw_interface_table[SND_DEVICE_OUT_VOICE_MUSIC_TX] = strdup("VOICE_PLAYBACK_TX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001273 hw_interface_table[SND_DEVICE_OUT_VOICE_LINE] = strdup("SLIMBUS_0_RX");
1274 hw_interface_table[SND_DEVICE_OUT_HDMI] = strdup("HDMI_RX");
1275 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("SLIMBUS_0_RX-and-HDMI_RX");
1276 hw_interface_table[SND_DEVICE_OUT_BT_SCO] = strdup("SEC_AUX_PCM_RX");
1277 hw_interface_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("SEC_AUX_PCM_RX");
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001278 hw_interface_table[SND_DEVICE_OUT_BT_A2DP] = strdup("SLIMBUS_7_RX");
1279 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] =
1280 strdup("SLIMBUS_0_RX-and-SLIMBUS_7_RX");
Aniket Kumar Lata9723a962018-05-16 17:41:55 -07001281 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP] =
1282 strdup("SLIMBUS_0_RX-and-SLIMBUS_7_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001283 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = strdup("SLIMBUS_0_RX");
1284 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = strdup("SLIMBUS_0_RX");
1285 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = strdup("SLIMBUS_0_RX");
1286 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = strdup("SLIMBUS_0_RX");
David Linee3fe402017-03-13 10:00:42 -07001287 hw_interface_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("USB_AUDIO_RX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001288 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = strdup("USB_AUDIO_RX");
1289 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = strdup("USB_AUDIO_RX");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001290 hw_interface_table[SND_DEVICE_OUT_VOICE_USB_HEADSET] = strdup("USB_AUDIO_RX");
David Linee3fe402017-03-13 10:00:42 -07001291 hw_interface_table[SND_DEVICE_OUT_USB_HEADPHONES] = strdup("USB_AUDIO_RX");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001292 hw_interface_table[SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = strdup("USB_AUDIO_RX");
jasmine cha270b7762018-03-30 15:41:33 +08001293 hw_interface_table[SND_DEVICE_OUT_USB_HEADSET_SPEC] = strdup("USB_AUDIO_RX");
David Linee3fe402017-03-13 10:00:42 -07001294 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 -07001295 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 -07001296 hw_interface_table[SND_DEVICE_OUT_VOICE_TX] = strdup("AFE_PCM_RX");
1297 hw_interface_table[SND_DEVICE_OUT_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
1298 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
jasmine cha52284622018-03-23 17:21:35 +08001299 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = strdup("SLIMBUS_0_RX");
1300 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_BT_SCO] = strdup("SLIMBUS_0_RX-and-SEC_AUX_PCM_RX");
1301 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 +08001302 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO] = strdup("QUAT_TDM_RX_0-and-SLIMBUS_7_RX"),
1303 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB] = strdup("QUAT_TDM_RX_0-and-SLIMBUS_7_RX"),
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001304 hw_interface_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1305 hw_interface_table[SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1306 hw_interface_table[SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = strdup("USB_AUDIO_TX");
1307 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1308 hw_interface_table[SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1309 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = strdup("USB_AUDIO_TX");
1310 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = strdup("USB_AUDIO_TX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001311 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001312 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_AEC] = strdup("SLIMBUS_0_TX");
1313 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_NS] = strdup("SLIMBUS_0_TX");
1314 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1315 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC] = strdup("SLIMBUS_0_TX");
1316 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_AEC] = strdup("SLIMBUS_0_TX");
1317 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_NS] = strdup("SLIMBUS_0_TX");
1318 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1319 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001320 hw_interface_table[SND_DEVICE_IN_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001321 hw_interface_table[SND_DEVICE_IN_HEADSET_MIC_AEC] = strdup("SLIMBUS_0_TX");
Eric Laurent5f4ca952018-10-19 17:33:43 -07001322 hw_interface_table[SND_DEVICE_IN_CAMCORDER_LANDSCAPE] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001323 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC] = strdup("SLIMBUS_0_TX");
1324 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC_NS] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001325 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC_AEC] = strdup("SLIMBUS_0_TX");
1326 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001327 hw_interface_table[SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
1328 hw_interface_table[SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = strdup("SLIMBUS_0_TX");
David Lin93725722017-10-13 14:58:17 -07001329 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_MIC] = strdup("SLIMBUS_0_TX");
1330 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1331 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = strdup("SLIMBUS_0_TX");
1332 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = strdup("SLIMBUS_0_TX");
1333 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001334 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC] = strdup("SLIMBUS_0_TX");
1335 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_AEC] = strdup("SLIMBUS_0_TX");
1336 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_NS] = strdup("SLIMBUS_0_TX");
1337 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1338 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC] = strdup("SLIMBUS_0_TX");
1339 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_AEC] = strdup("SLIMBUS_0_TX");
1340 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_NS] = strdup("SLIMBUS_0_TX");
1341 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001342 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
1343 hw_interface_table[SND_DEVICE_IN_VOICE_DMIC] = strdup("SLIMBUS_0_TX");
1344 hw_interface_table[SND_DEVICE_IN_VOICE_DMIC_TMUS] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001345 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001346 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = strdup("SLIMBUS_0_TX");
1347 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001348 hw_interface_table[SND_DEVICE_IN_VOICE_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001349 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1350 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = strdup("SLIMBUS_0_TX");
1351 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1352 hw_interface_table[SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1353 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("SEC_AUX_PCM_TX");
1354 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("SEC_AUX_PCM_TX");
1355 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("SEC_AUX_PCM_TX");
1356 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("SEC_AUX_PCM_TX");
1357 hw_interface_table[SND_DEVICE_IN_VOICE_RX] = strdup("AFE_PCM_TX");
1358 hw_interface_table[SND_DEVICE_IN_THREE_MIC] = strdup("SLIMBUS_0_TX");
1359 hw_interface_table[SND_DEVICE_IN_QUAD_MIC] = strdup("SLIMBUS_0_TX");
1360 hw_interface_table[SND_DEVICE_IN_HANDSET_TMIC] = strdup("SLIMBUS_0_TX");
1361 hw_interface_table[SND_DEVICE_IN_HANDSET_QMIC] = strdup("SLIMBUS_0_TX");
1362 hw_interface_table[SND_DEVICE_IN_HANDSET_TMIC_AEC] = strdup("SLIMBUS_0_TX");
1363 hw_interface_table[SND_DEVICE_IN_HANDSET_QMIC_AEC] = strdup("SLIMBUS_0_TX");
Eric Laurent5f4ca952018-10-19 17:33:43 -07001364 hw_interface_table[SND_DEVICE_IN_CAMCORDER_INVERT_LANDSCAPE] = strdup("SLIMBUS_0_TX");
1365 hw_interface_table[SND_DEVICE_IN_CAMCORDER_PORTRAIT] = strdup("SLIMBUS_0_TX");
1366 hw_interface_table[SND_DEVICE_IN_CAMCORDER_SELFIE_LANDSCAPE] = strdup("SLIMBUS_0_TX");
1367 hw_interface_table[SND_DEVICE_IN_CAMCORDER_SELFIE_INVERT_LANDSCAPE] = strdup("SLIMBUS_0_TX");
1368 hw_interface_table[SND_DEVICE_IN_CAMCORDER_SELFIE_PORTRAIT] = strdup("SLIMBUS_0_TX");
Eric Laurentc6333382015-09-14 12:43:44 -07001369 my_data->max_mic_count = PLATFORM_DEFAULT_MIC_COUNT;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001370}
1371
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001372void get_cvd_version(char *cvd_version, struct audio_device *adev)
1373{
1374 struct mixer_ctl *ctl;
1375 int count;
1376 int ret = 0;
1377
1378 ctl = mixer_get_ctl_by_name(adev->mixer, CVD_VERSION_MIXER_CTL);
1379 if (!ctl) {
1380 ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__, CVD_VERSION_MIXER_CTL);
1381 goto done;
1382 }
1383 mixer_ctl_update(ctl);
1384
1385 count = mixer_ctl_get_num_values(ctl);
1386 if (count > MAX_CVD_VERSION_STRING_SIZE)
1387 count = MAX_CVD_VERSION_STRING_SIZE - 1;
1388
1389 ret = mixer_ctl_get_array(ctl, cvd_version, count);
1390 if (ret != 0) {
1391 ALOGE("%s: ERROR! mixer_ctl_get_array() failed to get CVD Version", __func__);
1392 goto done;
1393 }
1394
1395done:
1396 return;
1397}
1398
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001399static int platform_acdb_init(void *platform)
1400{
1401 struct platform_data *my_data = (struct platform_data *)platform;
1402 struct audio_device *adev = my_data->adev;
1403
1404 if (!my_data->acdb_init) {
1405 ALOGE("%s: no acdb_init fn provided", __func__);
1406 return -1;
1407 }
1408
1409 if (my_data->acdb_initialized) {
1410 ALOGW("acdb is already initialized");
1411 return 0;
1412 }
1413
Thierry Strudel07f96d12018-09-20 13:31:34 -07001414#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845) || (PLATFORM_SDM710) || (PLATFORM_SM8150)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001415 char *cvd_version = calloc(1, MAX_CVD_VERSION_STRING_SIZE);
1416 if (!cvd_version)
1417 ALOGE("failed to allocate cvd_version");
1418 else {
1419 get_cvd_version(cvd_version, adev);
1420 my_data->acdb_init((char *)my_data->snd_card_name, cvd_version, 0);
1421 free(cvd_version);
1422 }
1423#elif defined (PLATFORM_MSM8084)
1424 my_data->acdb_init((char *)my_data->snd_card_name);
1425#else
1426 my_data->acdb_init();
1427#endif
1428 my_data->acdb_initialized = true;
1429 return 0;
1430}
1431
David Linee3fe402017-03-13 10:00:42 -07001432static void
1433platform_backend_config_init(struct platform_data *pdata)
1434{
1435 int i;
1436
1437 /* initialize backend config */
1438 for (i = 0; i < MAX_CODEC_BACKENDS; i++) {
1439 pdata->current_backend_cfg[i].sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
1440 pdata->current_backend_cfg[i].bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
1441 pdata->current_backend_cfg[i].channels = CODEC_BACKEND_DEFAULT_CHANNELS;
1442
1443 if (i > MAX_RX_CODEC_BACKENDS)
1444 pdata->current_backend_cfg[i].channels = CODEC_BACKEND_DEFAULT_TX_CHANNELS;
1445
1446 pdata->current_backend_cfg[i].bitwidth_mixer_ctl = NULL;
1447 pdata->current_backend_cfg[i].samplerate_mixer_ctl = NULL;
1448 pdata->current_backend_cfg[i].channels_mixer_ctl = NULL;
1449 }
1450
1451 pdata->current_backend_cfg[DEFAULT_CODEC_BACKEND].bitwidth_mixer_ctl =
1452 strdup("SLIM_0_RX Format");
1453 pdata->current_backend_cfg[DEFAULT_CODEC_BACKEND].samplerate_mixer_ctl =
1454 strdup("SLIM_0_RX SampleRate");
1455
1456 pdata->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].bitwidth_mixer_ctl =
1457 strdup("SLIM_0_TX Format");
1458 pdata->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].samplerate_mixer_ctl =
1459 strdup("SLIM_0_TX SampleRate");
1460
1461 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].bitwidth_mixer_ctl =
1462 strdup("USB_AUDIO_TX Format");
1463 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].samplerate_mixer_ctl =
1464 strdup("USB_AUDIO_TX SampleRate");
1465 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].channels_mixer_ctl =
1466 strdup("USB_AUDIO_TX Channels");
1467
Yung Ti Su39a2b8a2018-10-05 15:43:40 +08001468 if (strstr(pdata->snd_card_name, "intcodec")) {
1469 pdata->current_backend_cfg[HEADPHONE_BACKEND].bitwidth_mixer_ctl =
1470 strdup("INT0_MI2S_RX Format");
1471 pdata->current_backend_cfg[HEADPHONE_BACKEND].samplerate_mixer_ctl =
1472 strdup("INT0_MI2S_RX SampleRate");
1473 } else {
1474 pdata->current_backend_cfg[HEADPHONE_BACKEND].bitwidth_mixer_ctl =
1475 strdup("SLIM_6_RX Format");
1476 pdata->current_backend_cfg[HEADPHONE_BACKEND].samplerate_mixer_ctl =
1477 strdup("SLIM_6_RX SampleRate");
1478 }
David Linee3fe402017-03-13 10:00:42 -07001479
1480 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].bitwidth_mixer_ctl =
1481 strdup("USB_AUDIO_RX Format");
1482 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].samplerate_mixer_ctl =
1483 strdup("USB_AUDIO_RX SampleRate");
1484
1485 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].channels = 1;
1486 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].channels_mixer_ctl =
1487 strdup("USB_AUDIO_RX Channels");
1488}
1489
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001490static int
1491platform_backend_app_type_cfg_init(struct platform_data *pdata,
1492 struct mixer *mixer)
1493{
1494 size_t app_type_cfg[128] = {0};
1495 int length, num_app_types = 0;
1496 struct mixer_ctl *ctl = NULL;
1497
1498 const char *mixer_ctl_name = "App Type Config";
1499 ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name);
1500 if (!ctl) {
1501 ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name);
1502 return -1;
1503 }
1504
1505 length = 1; // reserve index 0 for number of app types
1506
1507 struct listnode *node;
1508 struct app_type_entry *entry;
1509 list_for_each(node, &app_type_entry_list) {
1510 entry = node_to_item(node, struct app_type_entry, node);
1511 app_type_cfg[length++] = entry->app_type;
1512 app_type_cfg[length++] = entry->max_rate;
1513 app_type_cfg[length++] = entry->bit_width;
1514 ALOGI("%s add entry %d %d", __func__, entry->app_type, entry->bit_width);
1515 num_app_types += 1;
1516 }
1517
1518 // default for capture
1519 int t;
1520 platform_get_default_app_type_v2(pdata,
1521 PCM_CAPTURE,
1522 &t);
1523 app_type_cfg[length++] = t;
1524 app_type_cfg[length++] = 48000;
1525 app_type_cfg[length++] = 16;
1526 num_app_types += 1;
1527
1528 if (num_app_types) {
1529 app_type_cfg[0] = num_app_types;
1530 if (mixer_ctl_set_array(ctl, app_type_cfg, length) < 0) {
1531 ALOGE("Failed to set app type cfg");
1532 }
1533 }
1534 return 0;
1535}
1536
Xu Han1638fd12018-04-20 12:42:23 -07001537static void configure_flicker_sensor_input(struct mixer *mixer)
1538{
1539 struct mixer_ctl *ctl;
1540 const char* ctl1 = "AIF3_CAP Mixer SLIM TX2";
1541 int setting1 = 1;
1542 const char* ctl2 = "CDC_IF TX2 MUX";
1543 const char* setting2 = "DEC2";
1544 const char* ctl3 = "SLIM_1_TX Channels";
1545 const char* setting3 = "One";
1546 const char* ctl4 = "ADC MUX2";
1547 const char* setting4 = "AMIC";
1548 const char* ctl5 = "AMIC MUX2";
1549 const char* setting5 = "ADC1";
1550 const char* ctl6 = "DEC2 Volume";
1551 int setting6 = 84;
Xu Han07e07402018-05-15 14:19:25 -07001552 const char* ctl7 = "MultiMedia9 Mixer SLIM_1_TX";
Xu Han1638fd12018-04-20 12:42:23 -07001553 int setting7 = 1;
1554 const char* ctl8 = "SLIM_1_TX SampleRate";
1555 const char* setting8 = "KHZ_8";
1556
1557 ctl = mixer_get_ctl_by_name(mixer, ctl1);
1558 mixer_ctl_set_value(ctl, 0, setting1);
1559 ctl = mixer_get_ctl_by_name(mixer, ctl2);
1560 mixer_ctl_set_enum_by_string(ctl, setting2);
1561 ctl = mixer_get_ctl_by_name(mixer, ctl3);
1562 mixer_ctl_set_enum_by_string(ctl, setting3);
1563 ctl = mixer_get_ctl_by_name(mixer, ctl4);
1564 mixer_ctl_set_enum_by_string(ctl, setting4);
1565 ctl = mixer_get_ctl_by_name(mixer, ctl5);
1566 mixer_ctl_set_enum_by_string(ctl, setting5);
1567 ctl = mixer_get_ctl_by_name(mixer, ctl6);
1568 mixer_ctl_set_value(ctl, 0, setting6);
1569 ctl = mixer_get_ctl_by_name(mixer, ctl7);
1570 mixer_ctl_set_value(ctl, 0, setting7);
1571 ctl = mixer_get_ctl_by_name(mixer, ctl8);
1572 mixer_ctl_set_enum_by_string(ctl, setting8);
1573}
1574
Eric Laurentb23d5282013-05-14 15:27:20 -07001575void *platform_init(struct audio_device *adev)
1576{
1577 char value[PROPERTY_VALUE_MAX];
vivek mehta60ea4152016-02-18 17:10:26 -08001578 struct platform_data *my_data = NULL;
1579 int retry_num = 0, snd_card_num = 0, key = 0, ret = 0;
1580 bool dual_mic_config = false, use_default_mixer_path = true;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001581 const char *snd_card_name;
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001582 char *cvd_version = NULL;
vivek mehta60ea4152016-02-18 17:10:26 -08001583 char *snd_internal_name = NULL;
1584 char *tmp = NULL;
1585 char mixer_xml_file[MIXER_PATH_MAX_LENGTH]= {0};
vivek mehtade4849c2016-03-03 17:23:38 -08001586 char platform_info_file[MIXER_PATH_MAX_LENGTH]= {0};
1587 struct snd_card_split *snd_split_handle = NULL;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001588 my_data = calloc(1, sizeof(struct platform_data));
1589
1590 my_data->adev = adev;
1591
keunhui.park2f7306a2015-07-16 16:48:06 +09001592 list_init(&operator_info_list);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001593 list_init(&app_type_entry_list);
keunhui.park2f7306a2015-07-16 16:48:06 +09001594
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001595 set_platform_defaults(my_data);
1596
vivek mehta0fb11312017-05-15 19:35:32 -07001597 // audio_extn_utils_get_snd_card_num does
1598 // - open mixer and get snd card name
1599 // - parse platform info xml file and check for valid snd card name
1600 // - on failure loop through all the active snd card
sangwoo1b9f4b32013-06-21 18:22:55 -07001601
vivek mehta0fb11312017-05-15 19:35:32 -07001602 snd_card_num = audio_extn_utils_get_snd_card_num();
1603 if (-1 == snd_card_num) {
1604 ALOGE("%s: invalid sound card number (-1), bailing out ", __func__);
1605 goto init_failed;
sangwoo1b9f4b32013-06-21 18:22:55 -07001606 }
1607
vivek mehta0fb11312017-05-15 19:35:32 -07001608 adev->mixer = mixer_open(snd_card_num);
1609 snd_card_name = mixer_get_name(adev->mixer);
1610 my_data->hw_info = hw_info_init(snd_card_name);
1611
1612 audio_extn_set_snd_card_split(snd_card_name);
1613 snd_split_handle = audio_extn_get_snd_card_split();
1614
1615 /* Get the codec internal name from the sound card and/or form factor
1616 * name and form the mixer paths and platfor info file name dynamically.
1617 * This is generic way of picking any codec and forma factor name based
1618 * mixer and platform info files in future with no code change.
1619
1620 * current code extends and looks for any of the exteneded mixer path and
1621 * platform info file present based on codec and form factor.
1622
1623 * order of picking appropriate file is
1624 * <i> mixer_paths_<codec_name>_<form_factor>.xml, if file not present
1625 * <ii> mixer_paths_<codec_name>.xml, if file not present
1626 * <iii> mixer_paths.xml
1627
1628 * same order is followed for audio_platform_info.xml as well
1629 */
1630
1631 // need to carryforward old file name
1632 if (!strncmp(snd_card_name, TOMTOM_8226_SND_CARD_NAME,
1633 min(strlen(TOMTOM_8226_SND_CARD_NAME), strlen(snd_card_name)))) {
1634 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1635 MIXER_XML_BASE_STRING, TOMTOM_MIXER_FILE_SUFFIX );
1636 } else {
1637
1638 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s_%s.xml",
1639 MIXER_XML_BASE_STRING, snd_split_handle->snd_card,
1640 snd_split_handle->form_factor);
1641 if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) {
1642 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1643 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1644 MIXER_XML_BASE_STRING, snd_split_handle->snd_card);
1645
1646 if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) {
1647 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1648 strlcpy(mixer_xml_file, MIXER_XML_DEFAULT_PATH, MIXER_PATH_MAX_LENGTH);
1649 audio_extn_utils_resolve_config_file(mixer_xml_file);
1650 }
1651 }
1652 }
1653
1654 audio_extn_utils_get_platform_info(snd_card_name, platform_info_file);
1655
jiabin8962a4d2018-03-19 18:21:24 -07001656 my_data->declared_mic_count = 0;
vivek mehta0fb11312017-05-15 19:35:32 -07001657 /* Initialize platform specific ids and/or backends*/
juyuchenbf6571f2018-11-30 18:50:47 +08001658 platform_info_init(platform_info_file, my_data,
1659 true, &platform_set_parameters);
vivek mehta0fb11312017-05-15 19:35:32 -07001660
1661 ALOGD("%s: Loading mixer file: %s", __func__, mixer_xml_file);
1662 adev->audio_route = audio_route_init(snd_card_num, mixer_xml_file);
1663
1664 if (!adev->audio_route) {
1665 ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
1666 mixer_close(adev->mixer);
1667 adev->mixer = NULL;
1668 hw_info_deinit(my_data->hw_info);
1669 my_data->hw_info = NULL;
1670 goto init_failed;
1671 }
1672 adev->snd_card = snd_card_num;
1673 ALOGD("%s: Opened sound card:%d", __func__, snd_card_num);
1674
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09001675 //set max volume step for voice call
1676 property_get("ro.config.vc_call_vol_steps", value, TOSTRING(MAX_VOL_INDEX));
1677 my_data->max_vol_index = atoi(value);
1678
vivek mehta65ad12d2015-08-13 18:32:48 -07001679 property_get("persist.audio.dualmic.config",value,"");
1680 if (!strcmp("endfire", value)) {
1681 dual_mic_config = true;
1682 }
1683
John Muir9e59a962018-01-10 13:30:00 -08001684 my_data->source_mic_type = 0;
Prashant Malanic92c5962015-08-11 15:10:18 -07001685
Eric Laurentb23d5282013-05-14 15:27:20 -07001686 my_data->fluence_in_spkr_mode = false;
1687 my_data->fluence_in_voice_call = false;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001688 my_data->fluence_in_voice_comm = false;
Eric Laurentb23d5282013-05-14 15:27:20 -07001689 my_data->fluence_in_voice_rec = false;
1690
vivek mehta65ad12d2015-08-13 18:32:48 -07001691 property_get("ro.qc.sdk.audio.fluencetype", value, "none");
Prashant Malanic92c5962015-08-11 15:10:18 -07001692 if (!strcmp("fluencepro", value)) {
1693 my_data->fluence_type = FLUENCE_PRO_ENABLE;
vivek mehta65ad12d2015-08-13 18:32:48 -07001694 } else if (!strcmp("fluence", value) || (dual_mic_config)) {
Prashant Malanic92c5962015-08-11 15:10:18 -07001695 my_data->fluence_type = FLUENCE_ENABLE;
1696 } else if (!strcmp("none", value)) {
1697 my_data->fluence_type = FLUENCE_DISABLE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001698 }
1699
Prashant Malanic92c5962015-08-11 15:10:18 -07001700 if (my_data->fluence_type != FLUENCE_DISABLE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001701 property_get("persist.audio.fluence.voicecall",value,"");
1702 if (!strcmp("true", value)) {
1703 my_data->fluence_in_voice_call = true;
1704 }
1705
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001706 property_get("persist.audio.fluence.voicecomm",value,"");
1707 if (!strcmp("true", value)) {
1708 my_data->fluence_in_voice_comm = true;
1709 }
1710
Eric Laurentb23d5282013-05-14 15:27:20 -07001711 property_get("persist.audio.fluence.voicerec",value,"");
1712 if (!strcmp("true", value)) {
1713 my_data->fluence_in_voice_rec = true;
1714 }
1715
1716 property_get("persist.audio.fluence.speaker",value,"");
1717 if (!strcmp("true", value)) {
1718 my_data->fluence_in_spkr_mode = true;
1719 }
1720 }
1721
Prashant Malanic92c5962015-08-11 15:10:18 -07001722 // support max to mono, example if max count is 3, usecase supports Three, dual and mono mic
1723 switch (my_data->max_mic_count) {
1724 case 4:
1725 my_data->source_mic_type |= SOURCE_QUAD_MIC;
1726 case 3:
1727 my_data->source_mic_type |= SOURCE_THREE_MIC;
1728 case 2:
1729 my_data->source_mic_type |= SOURCE_DUAL_MIC;
1730 case 1:
1731 my_data->source_mic_type |= SOURCE_MONO_MIC;
1732 break;
1733 default:
1734 ALOGE("%s: max_mic_count (%d), is not supported, setting to default",
1735 __func__, my_data->max_mic_count);
1736 my_data->source_mic_type = SOURCE_MONO_MIC|SOURCE_DUAL_MIC;
1737 break;
1738 }
1739
1740 ALOGV("%s: Fluence_Type(%d) max_mic_count(%d) mic_type(0x%x) fluence_in_voice_call(%d)"
1741 " fluence_in_voice_comm(%d) fluence_in_voice_rec(%d) fluence_in_spkr_mode(%d) ",
1742 __func__, my_data->fluence_type, my_data->max_mic_count, my_data->source_mic_type,
1743 my_data->fluence_in_voice_call, my_data->fluence_in_voice_comm,
1744 my_data->fluence_in_voice_rec, my_data->fluence_in_spkr_mode);
1745
Eric Laurentb23d5282013-05-14 15:27:20 -07001746 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
1747 if (my_data->acdb_handle == NULL) {
1748 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
1749 } else {
1750 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
1751 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
1752 "acdb_loader_deallocate_ACDB");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001753 if (!my_data->acdb_deallocate)
1754 ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s",
1755 __func__, LIB_ACDB_LOADER);
1756
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001757 my_data->acdb_send_audio_cal_v3 = (acdb_send_audio_cal_v3_t)dlsym(my_data->acdb_handle,
1758 "acdb_loader_send_audio_cal_v3");
1759 if (!my_data->acdb_send_audio_cal_v3)
1760 ALOGE("%s: Could not find the symbol acdb_send_audio_cal_v3 from %s",
1761 __func__, LIB_ACDB_LOADER);
1762
Eric Laurentb23d5282013-05-14 15:27:20 -07001763 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
1764 "acdb_loader_send_audio_cal");
1765 if (!my_data->acdb_send_audio_cal)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001766 ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s",
Eric Laurentb23d5282013-05-14 15:27:20 -07001767 __func__, LIB_ACDB_LOADER);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001768
Eric Laurentb23d5282013-05-14 15:27:20 -07001769 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
1770 "acdb_loader_send_voice_cal");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001771 if (!my_data->acdb_send_voice_cal)
1772 ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s",
1773 __func__, LIB_ACDB_LOADER);
1774
1775 my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle,
1776 "acdb_loader_reload_vocvoltable");
1777 if (!my_data->acdb_reload_vocvoltable)
1778 ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s",
1779 __func__, LIB_ACDB_LOADER);
vivek mehta1a9b7c02015-06-25 11:49:38 -07001780
1781 my_data->acdb_send_gain_dep_cal = (acdb_send_gain_dep_cal_t)dlsym(my_data->acdb_handle,
1782 "acdb_loader_send_gain_dep_cal");
1783 if (!my_data->acdb_send_gain_dep_cal)
1784 ALOGV("%s: Could not find the symbol acdb_loader_send_gain_dep_cal from %s",
1785 __func__, LIB_ACDB_LOADER);
1786
Xu Han1638fd12018-04-20 12:42:23 -07001787#if defined (FLICKER_SENSOR_INPUT)
1788 configure_flicker_sensor_input(adev->mixer);
1789#endif
1790
Thierry Strudel07f96d12018-09-20 13:31:34 -07001791#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845) || (PLATFORM_SDM710) || (PLATFORM_SM8150)
vivek mehta0fb11312017-05-15 19:35:32 -07001792 acdb_init_v2_cvd_t acdb_init_local;
1793 acdb_init_local = (acdb_init_v2_cvd_t)dlsym(my_data->acdb_handle,
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001794 "acdb_loader_init_v2");
vivek mehta0fb11312017-05-15 19:35:32 -07001795 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001796 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1797 dlerror());
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001798
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001799#elif defined (PLATFORM_MSM8084)
vivek mehta0fb11312017-05-15 19:35:32 -07001800 acdb_init_v2_t acdb_init_local;
1801 acdb_init_local = (acdb_init_v2_t)dlsym(my_data->acdb_handle,
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001802 "acdb_loader_init_v2");
vivek mehta0fb11312017-05-15 19:35:32 -07001803 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001804 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1805 dlerror());
1806
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001807#else
vivek mehta0fb11312017-05-15 19:35:32 -07001808 acdb_init_t acdb_init_local;
1809 acdb_init_local = (acdb_init_t)dlsym(my_data->acdb_handle,
Eric Laurentb23d5282013-05-14 15:27:20 -07001810 "acdb_loader_init_ACDB");
vivek mehta0fb11312017-05-15 19:35:32 -07001811 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001812 ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__,
1813 dlerror());
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001814#endif
vivek mehta0fb11312017-05-15 19:35:32 -07001815 my_data->acdb_init = acdb_init_local;
Eric Laurentb23d5282013-05-14 15:27:20 -07001816
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001817 my_data->acdb_send_custom_top = (acdb_send_custom_top_t)
1818 dlsym(my_data->acdb_handle,
1819 "acdb_loader_send_common_custom_topology");
1820
1821 if (!my_data->acdb_send_custom_top)
1822 ALOGE("%s: Could not find the symbol acdb_get_default_app_type from %s",
1823 __func__, LIB_ACDB_LOADER);
1824
jasmine chac89321b2018-04-10 21:37:01 +08001825 my_data->acdb_set_audio_cal = (acdb_set_audio_cal_t)dlsym(my_data->acdb_handle,
1826 "acdb_loader_set_audio_cal_v2");
1827 if (!my_data->acdb_set_audio_cal)
1828 ALOGE("%s: Could not find the symbol acdb_set_audio_cal_v2 from %s",
1829 __func__, LIB_ACDB_LOADER);
1830
vivek mehta0fb11312017-05-15 19:35:32 -07001831 int result = acdb_init(adev->snd_card);
1832 if (!result) {
1833 my_data->acdb_initialized = true;
1834 ALOGD("ACDB initialized");
1835 } else {
1836 my_data->acdb_initialized = false;
1837 ALOGD("ACDB initialization failed");
1838 }
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001839 }
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001840
David Linee3fe402017-03-13 10:00:42 -07001841 /* init usb */
1842 audio_extn_usb_init(adev);
1843
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001844 /* init a2dp */
1845 audio_extn_a2dp_init(adev);
1846
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001847 audio_extn_spkr_prot_init(adev);
Haynes Mathew George98c95622014-06-20 19:14:25 -07001848
Ravi Kumar Alamanda76315572015-04-23 13:13:56 -07001849 audio_extn_hwdep_cal_send(adev->snd_card, my_data->acdb_handle);
1850
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001851 /* load csd client */
1852 platform_csd_init(my_data);
1853
David Linee3fe402017-03-13 10:00:42 -07001854 platform_backend_config_init(my_data);
1855
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001856 init_be_dai_name_table(adev);
1857
1858 if (platform_supports_app_type_cfg())
1859 platform_backend_app_type_cfg_init(my_data, adev->mixer);
1860
Eric Laurentb23d5282013-05-14 15:27:20 -07001861 return my_data;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001862
1863init_failed:
1864 if (my_data)
1865 free(my_data);
1866 return NULL;
Eric Laurentb23d5282013-05-14 15:27:20 -07001867}
1868
1869void platform_deinit(void *platform)
1870{
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001871 int32_t dev;
keunhui.park2f7306a2015-07-16 16:48:06 +09001872 struct operator_info *info_item;
1873 struct operator_specific_device *device_item;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001874 struct app_type_entry *ap;
keunhui.park2f7306a2015-07-16 16:48:06 +09001875 struct listnode *node;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001876
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001877 struct platform_data *my_data = (struct platform_data *)platform;
1878 close_csd_client(my_data->csd);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001879
David Lin41b4fe42018-07-08 16:14:24 -07001880 audio_extn_spkr_prot_deinit(my_data->adev);
1881
vivek mehtade4849c2016-03-03 17:23:38 -08001882 hw_info_deinit(my_data->hw_info);
1883
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001884 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1885 if (backend_tag_table[dev])
1886 free(backend_tag_table[dev]);
1887 if (hw_interface_table[dev])
1888 free(hw_interface_table[dev]);
keunhui.park2f7306a2015-07-16 16:48:06 +09001889 if (operator_specific_device_table[dev]) {
1890 while (!list_empty(operator_specific_device_table[dev])) {
1891 node = list_head(operator_specific_device_table[dev]);
1892 list_remove(node);
1893 device_item = node_to_item(node, struct operator_specific_device, list);
1894 free(device_item->operator);
1895 free(device_item->mixer_path);
1896 free(device_item);
1897 }
1898 free(operator_specific_device_table[dev]);
1899 }
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001900 }
1901
1902 if (my_data->snd_card_name)
1903 free(my_data->snd_card_name);
1904
keunhui.park2f7306a2015-07-16 16:48:06 +09001905 while (!list_empty(&operator_info_list)) {
1906 node = list_head(&operator_info_list);
1907 list_remove(node);
1908 info_item = node_to_item(node, struct operator_info, list);
1909 free(info_item->name);
1910 free(info_item->mccmnc);
1911 free(info_item);
1912 }
1913
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001914 while (!list_empty(&app_type_entry_list)) {
1915 node = list_head(&app_type_entry_list);
1916 list_remove(node);
1917 ap = node_to_item(node, struct app_type_entry, node);
vivek mehtaa68fea62017-06-08 19:04:02 -07001918 if (ap->mode) free(ap->mode);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001919 free(ap);
1920 }
1921
Kevin Rocarde35d4af2017-05-02 16:55:28 -07001922 mixer_close(my_data->adev->mixer);
Eric Laurentb23d5282013-05-14 15:27:20 -07001923 free(platform);
David Linee3fe402017-03-13 10:00:42 -07001924
1925 /* deinit usb */
1926 audio_extn_usb_deinit();
Eric Laurentb23d5282013-05-14 15:27:20 -07001927}
1928
1929const char *platform_get_snd_device_name(snd_device_t snd_device)
1930{
keunhui.park2f7306a2015-07-16 16:48:06 +09001931 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1932 if (operator_specific_device_table[snd_device] != NULL) {
1933 return get_operator_specific_device_mixer_path(snd_device);
1934 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001935 return device_table[snd_device];
keunhui.park2f7306a2015-07-16 16:48:06 +09001936 } else
Ravi Kumar Alamanda64026462014-09-15 00:08:58 -07001937 return "none";
Eric Laurentb23d5282013-05-14 15:27:20 -07001938}
1939
vivek mehtade4849c2016-03-03 17:23:38 -08001940int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
1941 char *device_name)
1942{
1943 struct platform_data *my_data = (struct platform_data *)platform;
1944
David Benjamin1565f992016-09-21 12:10:34 -04001945 if (platform == NULL) {
vivek mehtade4849c2016-03-03 17:23:38 -08001946 ALOGW("%s: something wrong, use legacy get_snd_device name", __func__);
David Benjamin1565f992016-09-21 12:10:34 -04001947 strlcpy(device_name, platform_get_snd_device_name(snd_device),
1948 DEVICE_NAME_MAX_SIZE);
vivek mehtade4849c2016-03-03 17:23:38 -08001949 } else if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1950 if (operator_specific_device_table[snd_device] != NULL) {
1951 strlcpy(device_name, get_operator_specific_device_mixer_path(snd_device),
1952 DEVICE_NAME_MAX_SIZE);
1953 } else {
1954 strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE);
1955 }
1956 hw_info_append_hw_type(my_data->hw_info, snd_device, device_name);
1957 } else {
1958 strlcpy(device_name, "none", DEVICE_NAME_MAX_SIZE);
Aniket Kumar Lataa158e862018-05-11 17:28:40 -07001959 return -EINVAL;
vivek mehtade4849c2016-03-03 17:23:38 -08001960 }
1961
1962 return 0;
1963}
1964
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001965void platform_add_backend_name(void *platform, char *mixer_path,
1966 snd_device_t snd_device)
Eric Laurentb23d5282013-05-14 15:27:20 -07001967{
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001968 struct platform_data *my_data = (struct platform_data *)platform;
1969
Haynes Mathew George98c95622014-06-20 19:14:25 -07001970 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1971 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1972 return;
Ravi Kumar Alamanda1de6e5a2014-06-19 21:55:39 -05001973 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001974
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001975 const char * suffix = backend_tag_table[snd_device];
Haynes Mathew George98c95622014-06-20 19:14:25 -07001976
1977 if (suffix != NULL) {
1978 strcat(mixer_path, " ");
1979 strcat(mixer_path, suffix);
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001980 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001981}
1982
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001983bool platform_check_backends_match(snd_device_t snd_device1, snd_device_t snd_device2)
1984{
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001985 ALOGV("%s: snd_device1 = %s, snd_device2 = %s", __func__,
1986 platform_get_snd_device_name(snd_device1),
1987 platform_get_snd_device_name(snd_device2));
1988
1989 if ((snd_device1 < SND_DEVICE_MIN) || (snd_device1 >= SND_DEVICE_MAX)) {
1990 ALOGE("%s: Invalid snd_device = %s", __func__,
1991 platform_get_snd_device_name(snd_device1));
1992 return false;
1993 }
1994 if ((snd_device2 < SND_DEVICE_MIN) || (snd_device2 >= SND_DEVICE_MAX)) {
1995 ALOGE("%s: Invalid snd_device = %s", __func__,
1996 platform_get_snd_device_name(snd_device2));
1997 return false;
1998 }
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07001999
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002000 const char * be_itf1 = hw_interface_table[snd_device1];
2001 const char * be_itf2 = hw_interface_table[snd_device2];
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07002002 /*
2003 hw_interface_table has overrides for a snd_device.
2004 if there is no entry for a device, assume DEFAULT_RX_BACKEND
2005 */
2006 if (be_itf1 == NULL) {
2007 be_itf1 = DEFAULT_RX_BACKEND;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002008 }
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07002009 if (be_itf2 == NULL) {
2010 be_itf2 = DEFAULT_RX_BACKEND;
2011 }
2012 ALOGV("%s: be_itf1 = %s, be_itf2 = %s", __func__, be_itf1, be_itf2);
2013 /*
2014 this takes care of finding a device within a combo device pair as well
2015 */
2016 return strstr(be_itf1, be_itf2) != NULL || strstr(be_itf2, be_itf1) != NULL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002017}
2018
Eric Laurentb23d5282013-05-14 15:27:20 -07002019int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
2020{
2021 int device_id;
2022 if (device_type == PCM_PLAYBACK)
2023 device_id = pcm_device_table[usecase][0];
2024 else
2025 device_id = pcm_device_table[usecase][1];
2026 return device_id;
2027}
2028
Haynes Mathew George98c95622014-06-20 19:14:25 -07002029static int find_index(const struct name_to_index * table, int32_t len,
2030 const char * name)
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002031{
2032 int ret = 0;
Haynes Mathew George98c95622014-06-20 19:14:25 -07002033 int32_t i;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002034
Haynes Mathew George98c95622014-06-20 19:14:25 -07002035 if (table == NULL) {
2036 ALOGE("%s: table is NULL", __func__);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002037 ret = -ENODEV;
2038 goto done;
2039 }
2040
Haynes Mathew George98c95622014-06-20 19:14:25 -07002041 if (name == NULL) {
2042 ALOGE("null key");
2043 ret = -ENODEV;
2044 goto done;
2045 }
2046
2047 for (i=0; i < len; i++) {
2048 if (!strcmp(table[i].name, name)) {
2049 ret = table[i].index;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002050 goto done;
2051 }
2052 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07002053 ALOGE("%s: Could not find index for name = %s",
2054 __func__, name);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002055 ret = -ENODEV;
2056done:
2057 return ret;
2058}
2059
Haynes Mathew George98c95622014-06-20 19:14:25 -07002060int platform_get_snd_device_index(char *device_name)
2061{
2062 return find_index(snd_device_name_index, SND_DEVICE_MAX, device_name);
2063}
2064
2065int platform_get_usecase_index(const char *usecase_name)
2066{
2067 return find_index(usecase_name_index, AUDIO_USECASE_MAX, usecase_name);
2068}
2069
keunhui.park2f7306a2015-07-16 16:48:06 +09002070void platform_add_operator_specific_device(snd_device_t snd_device,
2071 const char *operator,
2072 const char *mixer_path,
2073 unsigned int acdb_id)
2074{
2075 struct operator_specific_device *device;
2076
2077 if (operator_specific_device_table[snd_device] == NULL) {
2078 operator_specific_device_table[snd_device] =
2079 (struct listnode *)calloc(1, sizeof(struct listnode));
2080 list_init(operator_specific_device_table[snd_device]);
2081 }
2082
2083 device = (struct operator_specific_device *)calloc(1, sizeof(struct operator_specific_device));
2084
2085 device->operator = strdup(operator);
2086 device->mixer_path = strdup(mixer_path);
2087 device->acdb_id = acdb_id;
2088
2089 list_add_tail(operator_specific_device_table[snd_device], &device->list);
2090
Eric Laurent2bafff12016-03-17 12:17:23 -07002091 ALOGD("%s: device[%s] -> operator[%s] mixer_path[%s] acdb_id[%d]", __func__,
keunhui.park2f7306a2015-07-16 16:48:06 +09002092 platform_get_snd_device_name(snd_device), operator, mixer_path, acdb_id);
2093
2094}
2095
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002096int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
2097{
2098 int ret = 0;
2099
2100 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
2101 ALOGE("%s: Invalid snd_device = %d",
2102 __func__, snd_device);
2103 ret = -EINVAL;
2104 goto done;
2105 }
2106
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002107 ALOGV("%s: acdb_device_table[%s]: old = %d new = %d", __func__,
2108 platform_get_snd_device_name(snd_device), acdb_device_table[snd_device], acdb_id);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002109 acdb_device_table[snd_device] = acdb_id;
2110done:
2111 return ret;
2112}
2113
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07002114int platform_get_snd_device_acdb_id(snd_device_t snd_device)
2115{
2116 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
2117 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
2118 return -EINVAL;
2119 }
keunhui.park2f7306a2015-07-16 16:48:06 +09002120
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002121 /*
2122 * If speaker protection is enabled, function returns supported
2123 * sound device for speaker. Else same sound device is returned.
2124 */
2125 snd_device = audio_extn_get_spkr_prot_snd_device(snd_device);
2126
keunhui.park2f7306a2015-07-16 16:48:06 +09002127 if (operator_specific_device_table[snd_device] != NULL)
2128 return get_operator_specific_device_acdb_id(snd_device);
2129 else
2130 return acdb_device_table[snd_device];
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07002131}
2132
David Linee3fe402017-03-13 10:00:42 -07002133static int platform_get_backend_index(snd_device_t snd_device)
2134{
2135 int32_t port = DEFAULT_CODEC_BACKEND;
2136
2137 if (snd_device >= SND_DEVICE_OUT_BEGIN && snd_device < SND_DEVICE_OUT_END) {
2138 if (backend_tag_table[snd_device] != NULL) {
2139 if (strncmp(backend_tag_table[snd_device], "headphones",
2140 sizeof("headphones")) == 0)
2141 port = HEADPHONE_BACKEND;
2142 else if (strcmp(backend_tag_table[snd_device], "hdmi") == 0)
2143 port = HDMI_RX_BACKEND;
2144 else if ((strcmp(backend_tag_table[snd_device], "usb-headphones") == 0) ||
2145 (strcmp(backend_tag_table[snd_device], "usb-headset") == 0))
2146 port = USB_AUDIO_RX_BACKEND;
2147 }
2148 } else if (snd_device >= SND_DEVICE_IN_BEGIN && snd_device < SND_DEVICE_IN_END) {
2149 port = DEFAULT_CODEC_TX_BACKEND;
2150 if (backend_tag_table[snd_device] != NULL) {
2151 if (strcmp(backend_tag_table[snd_device], "usb-headset-mic") == 0)
2152 port = USB_AUDIO_TX_BACKEND;
2153 else if (strstr(backend_tag_table[snd_device], "bt-sco") != NULL)
2154 port = BT_SCO_TX_BACKEND;
2155 }
2156 } else {
2157 ALOGW("%s:napb: Invalid device - %d ", __func__, snd_device);
2158 }
2159
2160 ALOGV("%s:napb: backend port - %d device - %d ", __func__, port, snd_device);
2161
2162 return port;
2163}
2164
Eric Laurentb23d5282013-05-14 15:27:20 -07002165int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
2166{
2167 struct platform_data *my_data = (struct platform_data *)platform;
2168 int acdb_dev_id, acdb_dev_type;
2169
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002170 if (platform_supports_app_type_cfg()) // use v2 instead
2171 return -ENOSYS;
2172
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002173 acdb_dev_id = platform_get_snd_device_acdb_id(snd_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07002174 if (acdb_dev_id < 0) {
2175 ALOGE("%s: Could not find acdb id for device(%d)",
2176 __func__, snd_device);
2177 return -EINVAL;
2178 }
2179 if (my_data->acdb_send_audio_cal) {
Joe Onorato188b6222016-03-01 11:02:27 -08002180 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Eric Laurentb23d5282013-05-14 15:27:20 -07002181 __func__, snd_device, acdb_dev_id);
2182 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
2183 snd_device < SND_DEVICE_OUT_END)
2184 acdb_dev_type = ACDB_DEV_TYPE_OUT;
2185 else
2186 acdb_dev_type = ACDB_DEV_TYPE_IN;
2187 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
2188 }
2189 return 0;
2190}
2191
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002192int platform_send_audio_calibration_v2(void *platform, struct audio_usecase *usecase,
2193 int app_type, int sample_rate)
2194{
2195 struct platform_data *my_data = (struct platform_data *)platform;
2196 int acdb_dev_id, acdb_dev_type;
vivek mehta7e573672018-03-13 17:41:41 -07002197 int snd_device = usecase->out_snd_device;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002198 int new_snd_device[SND_DEVICE_OUT_END] = {0};
2199 int i, num_devices = 1;
2200
2201 if (!platform_supports_app_type_cfg()) // use v1 instead
2202 return -ENOSYS;
2203
vivek mehta7e573672018-03-13 17:41:41 -07002204 if ((usecase->type == PCM_HFP_CALL) || (usecase->type == PCM_CAPTURE))
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002205 snd_device = usecase->in_snd_device;
2206
2207 // skipped over get_spkr_prot_device
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002208 acdb_dev_id = platform_get_snd_device_acdb_id(snd_device);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002209 if (acdb_dev_id < 0) {
2210 ALOGE("%s: Could not find acdb id for device(%d)",
2211 __func__, snd_device);
2212 return -EINVAL;
2213 }
2214
2215 if (platform_can_split_snd_device(snd_device,
2216 &num_devices, new_snd_device) < 0) {
2217 new_snd_device[0] = snd_device;
2218 }
2219
2220 for (i = 0; i < num_devices; i++) {
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002221 acdb_dev_id = platform_get_snd_device_acdb_id(new_snd_device[i]);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002222 if (acdb_dev_id < 0) {
2223 ALOGE("%s: Could not find acdb id for device(%d)",
2224 __func__, new_snd_device[i]);
2225 return -EINVAL;
2226 }
2227 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
2228 __func__, new_snd_device[i], acdb_dev_id);
2229 if (new_snd_device[i] >= SND_DEVICE_OUT_BEGIN &&
2230 new_snd_device[i] < SND_DEVICE_OUT_END)
2231 acdb_dev_type = ACDB_DEV_TYPE_OUT;
2232 else
2233 acdb_dev_type = ACDB_DEV_TYPE_IN;
2234
2235 if (my_data->acdb_send_audio_cal_v3) {
2236 my_data->acdb_send_audio_cal_v3(acdb_dev_id, acdb_dev_type,
2237 app_type, sample_rate, i);
2238 } else if (my_data->acdb_send_audio_cal) {
2239 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type); // this version differs from internal
2240 }
2241 }
2242
2243 return 0;
2244}
2245
2246
Eric Laurentb23d5282013-05-14 15:27:20 -07002247int platform_switch_voice_call_device_pre(void *platform)
2248{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002249 struct platform_data *my_data = (struct platform_data *)platform;
2250 int ret = 0;
2251
2252 if (my_data->csd != NULL &&
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002253 voice_is_in_call(my_data->adev)) {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002254 /* This must be called before disabling mixer controls on APQ side */
2255 ret = my_data->csd->disable_device();
2256 if (ret < 0) {
2257 ALOGE("%s: csd_client_disable_device, failed, error %d",
2258 __func__, ret);
2259 }
2260 }
2261 return ret;
2262}
2263
2264int platform_switch_voice_call_enable_device_config(void *platform,
2265 snd_device_t out_snd_device,
2266 snd_device_t in_snd_device)
2267{
2268 struct platform_data *my_data = (struct platform_data *)platform;
2269 int acdb_rx_id, acdb_tx_id;
2270 int ret = 0;
2271
2272 if (my_data->csd == NULL)
2273 return ret;
2274
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002275 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
keunhui.park2f7306a2015-07-16 16:48:06 +09002276 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002277
2278 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
2279 ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
2280 if (ret < 0) {
2281 ALOGE("%s: csd_enable_device_config, failed, error %d",
2282 __func__, ret);
2283 }
2284 } else {
2285 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2286 acdb_rx_id, acdb_tx_id);
2287 }
2288
2289 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002290}
2291
2292int platform_switch_voice_call_device_post(void *platform,
2293 snd_device_t out_snd_device,
2294 snd_device_t in_snd_device)
2295{
2296 struct platform_data *my_data = (struct platform_data *)platform;
2297 int acdb_rx_id, acdb_tx_id;
2298
2299 if (my_data->acdb_send_voice_cal == NULL) {
2300 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
2301 } else {
keunhui.park2f7306a2015-07-16 16:48:06 +09002302 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
2303 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07002304
2305 if (acdb_rx_id > 0 && acdb_tx_id > 0)
2306 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
2307 else
2308 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2309 acdb_rx_id, acdb_tx_id);
2310 }
2311
2312 return 0;
2313}
2314
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002315int platform_switch_voice_call_usecase_route_post(void *platform,
2316 snd_device_t out_snd_device,
2317 snd_device_t in_snd_device)
2318{
2319 struct platform_data *my_data = (struct platform_data *)platform;
2320 int acdb_rx_id, acdb_tx_id;
2321 int ret = 0;
2322
2323 if (my_data->csd == NULL)
2324 return ret;
2325
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002326 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
keunhui.park2f7306a2015-07-16 16:48:06 +09002327 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002328
2329 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
2330 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
2331 my_data->adev->acdb_settings);
2332 if (ret < 0) {
2333 ALOGE("%s: csd_enable_device, failed, error %d", __func__, ret);
2334 }
2335 } else {
2336 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2337 acdb_rx_id, acdb_tx_id);
2338 }
2339
2340 return ret;
2341}
2342
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002343int platform_start_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07002344{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002345 struct platform_data *my_data = (struct platform_data *)platform;
2346 int ret = 0;
2347
2348 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002349 ret = my_data->csd->start_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002350 if (ret < 0) {
2351 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
2352 }
2353 }
2354 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002355}
2356
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002357int platform_stop_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07002358{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002359 struct platform_data *my_data = (struct platform_data *)platform;
2360 int ret = 0;
2361
2362 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002363 ret = my_data->csd->stop_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002364 if (ret < 0) {
2365 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
2366 }
2367 }
2368 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002369}
2370
Vignesh Kulothunganb6f0a9c2018-03-22 13:50:22 -07002371int platform_set_mic_break_det(void *platform, bool enable)
2372{
2373 int ret = 0;
2374 struct platform_data *my_data = (struct platform_data *)platform;
2375 struct audio_device *adev = my_data->adev;
2376 const char *mixer_ctl_name = "Voice Mic Break Enable";
2377 struct mixer_ctl *ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2378 if (!ctl) {
2379 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2380 __func__, mixer_ctl_name);
2381 return -EINVAL;
2382 }
2383
2384 ret = mixer_ctl_set_value(ctl, 0, enable);
2385 if(ret)
2386 ALOGE("%s: Failed to set mixer ctl: %s", __func__, mixer_ctl_name);
2387
2388 return ret;
2389}
2390
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002391int platform_get_sample_rate(void *platform, uint32_t *rate)
2392{
2393 struct platform_data *my_data = (struct platform_data *)platform;
2394 int ret = 0;
2395
2396 if (my_data->csd != NULL) {
2397 ret = my_data->csd->get_sample_rate(rate);
2398 if (ret < 0) {
2399 ALOGE("%s: csd_get_sample_rate error %d\n", __func__, ret);
2400 }
2401 }
2402 return ret;
2403}
2404
vivek mehtab6506412015-08-07 16:55:17 -07002405void platform_set_speaker_gain_in_combo(struct audio_device *adev,
2406 snd_device_t snd_device,
2407 bool enable)
2408{
2409 const char* name;
2410 switch (snd_device) {
2411 case SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES:
2412 if (enable)
2413 name = "spkr-gain-in-headphone-combo";
2414 else
2415 name = "speaker-gain-default";
2416 break;
2417 case SND_DEVICE_OUT_SPEAKER_AND_LINE:
2418 if (enable)
2419 name = "spkr-gain-in-line-combo";
2420 else
2421 name = "speaker-gain-default";
2422 break;
2423 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES:
2424 if (enable)
2425 name = "spkr-safe-gain-in-headphone-combo";
2426 else
2427 name = "speaker-safe-gain-default";
2428 break;
2429 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE:
2430 if (enable)
2431 name = "spkr-safe-gain-in-line-combo";
2432 else
2433 name = "speaker-safe-gain-default";
2434 break;
2435 default:
2436 return;
2437 }
2438
2439 audio_route_apply_and_update_path(adev->audio_route, name);
2440}
2441
Eric Laurentb23d5282013-05-14 15:27:20 -07002442int platform_set_voice_volume(void *platform, int volume)
2443{
2444 struct platform_data *my_data = (struct platform_data *)platform;
2445 struct audio_device *adev = my_data->adev;
2446 struct mixer_ctl *ctl;
sangwoo53b2cf02013-07-25 19:18:44 -07002447 const char *mixer_ctl_name = "Voice Rx Gain";
Nadav Barc46d0fa2017-12-24 14:50:37 +02002448 const char *mute_mixer_ctl_name = "Voice Rx Device Mute";
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002449 int vol_index = 0, ret = 0;
2450 uint32_t set_values[ ] = {0,
2451 ALL_SESSION_VSID,
2452 DEFAULT_VOLUME_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07002453
2454 // Voice volume levels are mapped to adsp volume levels as follows.
2455 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
2456 // But this values don't changed in kernel. So, below change is need.
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09002457 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, my_data->max_vol_index);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002458 set_values[0] = vol_index;
Eric Laurentb23d5282013-05-14 15:27:20 -07002459
2460 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2461 if (!ctl) {
2462 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2463 __func__, mixer_ctl_name);
2464 return -EINVAL;
2465 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002466 ALOGV("Setting voice volume index: %d", set_values[0]);
2467 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2468
Nadav Barc46d0fa2017-12-24 14:50:37 +02002469 // Send mute command in case volume index is max since indexes are inverted
2470 // for mixer controls.
2471 if (vol_index == my_data->max_vol_index) {
2472 set_values[0] = 1;
2473 }
2474 else {
2475 set_values[0] = 0;
2476 }
2477
2478 ctl = mixer_get_ctl_by_name(adev->mixer, mute_mixer_ctl_name);
2479 if (!ctl) {
2480 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2481 __func__, mute_mixer_ctl_name);
2482 return -EINVAL;
2483 }
2484 ALOGV("%s: Setting RX Device Mute to: %d", __func__, set_values[0]);
2485 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2486
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002487 if (my_data->csd != NULL) {
2488 ret = my_data->csd->volume(ALL_SESSION_VSID, volume,
2489 DEFAULT_VOLUME_RAMP_DURATION_MS);
2490 if (ret < 0) {
2491 ALOGE("%s: csd_volume error %d", __func__, ret);
2492 }
2493 }
2494 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002495}
2496
2497int platform_set_mic_mute(void *platform, bool state)
2498{
2499 struct platform_data *my_data = (struct platform_data *)platform;
2500 struct audio_device *adev = my_data->adev;
2501 struct mixer_ctl *ctl;
2502 const char *mixer_ctl_name = "Voice Tx Mute";
sangwoo53b2cf02013-07-25 19:18:44 -07002503 int ret = 0;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002504 uint32_t set_values[ ] = {0,
2505 ALL_SESSION_VSID,
2506 DEFAULT_MUTE_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07002507
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09002508 if (adev->mode != AUDIO_MODE_IN_CALL &&
2509 adev->mode != AUDIO_MODE_IN_COMMUNICATION)
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002510 return 0;
2511
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09002512 if (adev->enable_hfp)
2513 mixer_ctl_name = "HFP Tx Mute";
2514
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002515 set_values[0] = state;
2516 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2517 if (!ctl) {
2518 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2519 __func__, mixer_ctl_name);
2520 return -EINVAL;
2521 }
Arun Mirpuri0cc2f312018-05-29 17:26:07 -07002522 ALOGV("%s: Setting voice mute state: %d", __func__, state);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002523 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2524
2525 if (my_data->csd != NULL) {
2526 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state,
2527 DEFAULT_MUTE_RAMP_DURATION_MS);
sangwoo53b2cf02013-07-25 19:18:44 -07002528 if (ret < 0) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002529 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
sangwoo53b2cf02013-07-25 19:18:44 -07002530 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002531 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002532 return ret;
2533}
Eric Laurentb23d5282013-05-14 15:27:20 -07002534
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002535int platform_set_device_mute(void *platform, bool state, char *dir)
2536{
2537 struct platform_data *my_data = (struct platform_data *)platform;
2538 struct audio_device *adev = my_data->adev;
2539 struct mixer_ctl *ctl;
2540 char *mixer_ctl_name = NULL;
2541 int ret = 0;
2542 uint32_t set_values[ ] = {0,
2543 ALL_SESSION_VSID,
2544 0};
2545 if(dir == NULL) {
2546 ALOGE("%s: Invalid direction:%s", __func__, dir);
2547 return -EINVAL;
2548 }
2549
2550 if (!strncmp("rx", dir, sizeof("rx"))) {
2551 mixer_ctl_name = "Voice Rx Device Mute";
2552 } else if (!strncmp("tx", dir, sizeof("tx"))) {
2553 mixer_ctl_name = "Voice Tx Device Mute";
2554 } else {
2555 return -EINVAL;
2556 }
2557
2558 set_values[0] = state;
2559 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2560 if (!ctl) {
2561 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2562 __func__, mixer_ctl_name);
2563 return -EINVAL;
2564 }
2565
2566 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
2567 __func__,state, mixer_ctl_name);
2568 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2569
2570 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002571}
2572
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002573int platform_can_split_snd_device(snd_device_t snd_device,
2574 int *num_devices,
2575 snd_device_t *new_snd_devices)
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002576{
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002577 int ret = -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002578 if (NULL == num_devices || NULL == new_snd_devices) {
2579 ALOGE("%s: NULL pointer ..", __func__);
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002580 return -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002581 }
2582
2583 /*
2584 * If wired headset/headphones/line devices share the same backend
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002585 * with speaker/earpiece this routine returns -EINVAL.
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002586 */
2587 if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES &&
2588 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_HEADPHONES)) {
2589 *num_devices = 2;
2590 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2591 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002592 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002593 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_LINE &&
2594 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_LINE)) {
2595 *num_devices = 2;
2596 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2597 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002598 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002599 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES &&
2600 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_HEADPHONES)) {
2601 *num_devices = 2;
2602 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2603 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002604 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002605 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE &&
2606 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_LINE)) {
2607 *num_devices = 2;
2608 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2609 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002610 ret = 0;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002611 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO &&
2612 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2613 SND_DEVICE_OUT_BT_SCO)) {
2614 *num_devices = 2;
2615 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2616 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO;
2617 ret = 0;
juyuchen5351ea62018-05-16 10:54:37 +08002618 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO &&
2619 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE,
2620 SND_DEVICE_OUT_BT_SCO)) {
2621 *num_devices = 2;
2622 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2623 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO;
2624 ret = 0;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002625 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB &&
2626 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2627 SND_DEVICE_OUT_BT_SCO_WB)) {
2628 *num_devices = 2;
2629 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2630 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO_WB;
2631 ret = 0;
juyuchen5351ea62018-05-16 10:54:37 +08002632 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB &&
2633 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE,
2634 SND_DEVICE_OUT_BT_SCO_WB)) {
2635 *num_devices = 2;
2636 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2637 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO_WB;
2638 ret = 0;
David Linee3fe402017-03-13 10:00:42 -07002639 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET &&
2640 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_USB_HEADSET)) {
2641 *num_devices = 2;
2642 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2643 new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
2644 ret = 0;
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07002645 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET &&
2646 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_USB_HEADSET)) {
2647 *num_devices = 2;
2648 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2649 new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
2650 ret = 0;
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002651 } else if (SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP == snd_device &&
2652 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2653 SND_DEVICE_OUT_BT_A2DP)) {
2654 *num_devices = 2;
2655 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2656 new_snd_devices[1] = SND_DEVICE_OUT_BT_A2DP;
2657 ret = 0;
Aniket Kumar Lata9723a962018-05-16 17:41:55 -07002658 } else if (SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP == snd_device &&
2659 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE,
2660 SND_DEVICE_OUT_BT_A2DP)) {
2661 *num_devices = 2;
2662 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2663 new_snd_devices[1] = SND_DEVICE_OUT_BT_A2DP;
2664 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002665 }
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002666
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002667 return ret;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002668}
2669
Eric Laurentb23d5282013-05-14 15:27:20 -07002670snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
2671{
2672 struct platform_data *my_data = (struct platform_data *)platform;
2673 struct audio_device *adev = my_data->adev;
2674 audio_mode_t mode = adev->mode;
2675 snd_device_t snd_device = SND_DEVICE_NONE;
2676
2677 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
2678 if (devices == AUDIO_DEVICE_NONE ||
2679 devices & AUDIO_DEVICE_BIT_IN) {
2680 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
2681 goto exit;
2682 }
2683
Eric Laurent1b491552015-09-15 17:52:41 -07002684 if (popcount(devices) == 2) {
2685 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2686 AUDIO_DEVICE_OUT_SPEAKER) ||
2687 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2688 AUDIO_DEVICE_OUT_SPEAKER)) {
2689 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
2690 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2691 AUDIO_DEVICE_OUT_SPEAKER)) {
2692 snd_device = SND_DEVICE_OUT_SPEAKER_AND_LINE;
2693 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2694 AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
2695 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2696 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2697 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES;
2698 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2699 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2700 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE;
2701 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
2702 AUDIO_DEVICE_OUT_SPEAKER)) {
2703 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002704 } else if ((devices & AUDIO_DEVICE_OUT_ALL_SCO) &&
2705 ((devices & ~AUDIO_DEVICE_OUT_ALL_SCO) == AUDIO_DEVICE_OUT_SPEAKER)) {
2706 snd_device = adev->bt_wb_speech_enabled ?
2707 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB :
2708 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO;
juyuchen5351ea62018-05-16 10:54:37 +08002709 } else if ((devices & AUDIO_DEVICE_OUT_ALL_SCO) &&
2710 ((devices & ~AUDIO_DEVICE_OUT_ALL_SCO) == AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2711 snd_device = adev->bt_wb_speech_enabled ?
2712 SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB :
2713 SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO;
Eric Laurent99dab492017-06-17 15:19:08 -07002714 } else if ((devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
2715 AUDIO_DEVICE_OUT_SPEAKER)) ||
2716 (devices == (AUDIO_DEVICE_OUT_USB_HEADSET |
2717 AUDIO_DEVICE_OUT_SPEAKER))) {
David Linee3fe402017-03-13 10:00:42 -07002718 snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET;
Eric Laurentd0f7c262017-07-05 09:09:12 -07002719 } else if ((devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
2720 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) ||
2721 (devices == (AUDIO_DEVICE_OUT_USB_HEADSET |
2722 AUDIO_DEVICE_OUT_SPEAKER_SAFE))) {
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07002723 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET;
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002724 } else if ((devices & AUDIO_DEVICE_OUT_SPEAKER) &&
2725 (devices & AUDIO_DEVICE_OUT_ALL_A2DP)) {
2726 snd_device = SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP;
Aniket Kumar Lata9723a962018-05-16 17:41:55 -07002727 } else if ((devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) &&
2728 (devices & AUDIO_DEVICE_OUT_ALL_A2DP)) {
2729 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP;
Eric Laurent1b491552015-09-15 17:52:41 -07002730 } else {
2731 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
2732 goto exit;
2733 }
2734 if (snd_device != SND_DEVICE_NONE) {
2735 goto exit;
2736 }
2737 }
2738
2739 if (popcount(devices) != 1) {
2740 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
2741 goto exit;
2742 }
2743
Madhuri Athota3f6051b2016-10-13 23:25:38 +05302744 if (voice_is_in_call(adev) || adev->enable_voicerx || audio_extn_hfp_is_active(adev)) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002745 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002746 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2747 devices & AUDIO_DEVICE_OUT_LINE) {
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002748 if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002749 (adev->voice.tty_mode == TTY_MODE_FULL))
Eric Laurentb23d5282013-05-14 15:27:20 -07002750 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002751 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002752 (adev->voice.tty_mode == TTY_MODE_VCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002753 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002754 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002755 (adev->voice.tty_mode == TTY_MODE_HCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002756 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002757 else {
2758 if (devices & AUDIO_DEVICE_OUT_LINE)
2759 snd_device = SND_DEVICE_OUT_VOICE_LINE;
yixuanjiang9536e672018-09-06 18:43:36 +08002760 else if (devices & AUDIO_DEVICE_OUT_WIRED_HEADSET)
2761 snd_device = SND_DEVICE_OUT_VOICE_HEADSET;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002762 else
2763 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
2764 }
Eric Laurent99dab492017-06-17 15:19:08 -07002765 } else if (audio_is_usb_out_device(devices)) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002766 if (voice_is_in_call(adev)) {
2767 switch (adev->voice.tty_mode) {
2768 case TTY_MODE_FULL:
2769 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_USB;
2770 break;
2771 case TTY_MODE_VCO:
2772 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_USB;
2773 break;
2774 case TTY_MODE_HCO:
2775 // since Hearing will be on handset\speaker, use existing device
2776 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
2777 break;
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002778 case TTY_MODE_OFF:
2779 break;
vivek mehtaa6b79742017-03-09 15:40:43 -08002780 default:
2781 ALOGE("%s: Invalid TTY mode (%#x)",
2782 __func__, adev->voice.tty_mode);
2783 }
2784 }
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002785 if (snd_device == SND_DEVICE_NONE) {
2786 snd_device = audio_extn_usb_is_capture_supported() ?
2787 SND_DEVICE_OUT_VOICE_USB_HEADSET :
2788 SND_DEVICE_OUT_VOICE_USB_HEADPHONES;
2789 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002790 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002791 if (adev->bt_wb_speech_enabled) {
2792 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2793 } else {
2794 snd_device = SND_DEVICE_OUT_BT_SCO;
2795 }
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002796 } else if (devices & AUDIO_DEVICE_OUT_ALL_A2DP) {
2797 snd_device = SND_DEVICE_OUT_BT_A2DP;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002798 } else if (devices & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002799 if (!adev->enable_hfp) {
2800 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
2801 } else {
2802 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_HFP;
2803 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002804 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002805 if(adev->voice.hac)
2806 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2807 else if (is_operator_tmus())
Eric Laurentb23d5282013-05-14 15:27:20 -07002808 snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS;
2809 else
Eric Laurentb4d368e2014-06-25 10:21:54 -05002810 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002811 } else if (devices & AUDIO_DEVICE_OUT_TELEPHONY_TX)
2812 snd_device = SND_DEVICE_OUT_VOICE_TX;
2813
Eric Laurentb23d5282013-05-14 15:27:20 -07002814 if (snd_device != SND_DEVICE_NONE) {
2815 goto exit;
2816 }
2817 }
2818
Eric Laurentb23d5282013-05-14 15:27:20 -07002819 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2820 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2821 snd_device = SND_DEVICE_OUT_HEADPHONES;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002822 } else if (devices & AUDIO_DEVICE_OUT_LINE) {
2823 snd_device = SND_DEVICE_OUT_LINE;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002824 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) {
2825 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE;
Eric Laurentb23d5282013-05-14 15:27:20 -07002826 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
andysu5b30b062018-04-20 16:34:06 +08002827 /*
2828 * Perform device switch only if acdb tuning is different between SPEAKER & SPEAKER_REVERSE,
2829 * Or there will be a small pause while performing device switch.
2830 */
2831 if (my_data->speaker_lr_swap &&
2832 (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
2833 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]))
Eric Laurentb23d5282013-05-14 15:27:20 -07002834 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
2835 else
2836 snd_device = SND_DEVICE_OUT_SPEAKER;
2837 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002838 if (adev->bt_wb_speech_enabled) {
2839 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2840 } else {
2841 snd_device = SND_DEVICE_OUT_BT_SCO;
2842 }
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002843 } else if (devices & AUDIO_DEVICE_OUT_ALL_A2DP) {
2844 snd_device = SND_DEVICE_OUT_BT_A2DP;
Eric Laurentb23d5282013-05-14 15:27:20 -07002845 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2846 snd_device = SND_DEVICE_OUT_HDMI ;
Eric Laurent99dab492017-06-17 15:19:08 -07002847 } else if (audio_is_usb_out_device(devices)) {
jasmine cha270b7762018-03-30 15:41:33 +08002848 if (audio_extn_ma_supported_usb())
2849 snd_device = SND_DEVICE_OUT_USB_HEADSET_SPEC;
2850 else if (audio_extn_usb_is_capture_supported())
David Linee3fe402017-03-13 10:00:42 -07002851 snd_device = SND_DEVICE_OUT_USB_HEADSET;
2852 else
2853 snd_device = SND_DEVICE_OUT_USB_HEADPHONES;
2854 }else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002855 /*HAC support for voice-ish audio (eg visual voicemail)*/
2856 if(adev->voice.hac)
2857 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2858 else
2859 snd_device = SND_DEVICE_OUT_HANDSET;
Eric Laurentb23d5282013-05-14 15:27:20 -07002860 } else {
2861 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
2862 }
2863exit:
2864 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
2865 return snd_device;
2866}
2867
Eric Laurentd1b7a9b2018-11-15 12:24:31 -08002868snd_device_t platform_get_input_snd_device(void *platform,
2869 struct stream_in *in,
2870 audio_devices_t out_device)
Eric Laurentb23d5282013-05-14 15:27:20 -07002871{
2872 struct platform_data *my_data = (struct platform_data *)platform;
2873 struct audio_device *adev = my_data->adev;
Eric Laurentd1b7a9b2018-11-15 12:24:31 -08002874 audio_mode_t mode = adev->mode;
Eric Laurentb23d5282013-05-14 15:27:20 -07002875 snd_device_t snd_device = SND_DEVICE_NONE;
Eric Laurentd1b7a9b2018-11-15 12:24:31 -08002876
2877 if (in == NULL) {
2878 in = adev_get_active_input(adev);
2879 }
2880
2881 audio_source_t source = (in == NULL) ? AUDIO_SOURCE_DEFAULT : in->source;
2882 audio_devices_t in_device =
2883 ((in == NULL) ? AUDIO_DEVICE_NONE : in->device) & ~AUDIO_DEVICE_BIT_IN;
2884 audio_channel_mask_t channel_mask = (in == NULL) ? AUDIO_CHANNEL_IN_MONO : in->channel_mask;
2885 int channel_count = audio_channel_count_from_in_mask(channel_mask);
Eric Laurentb23d5282013-05-14 15:27:20 -07002886
Prashant Malanic92c5962015-08-11 15:10:18 -07002887 ALOGV("%s: enter: out_device(%#x) in_device(%#x) channel_count (%d) channel_mask (0x%x)",
2888 __func__, out_device, in_device, channel_count, channel_mask);
Eric Laurentd1b7a9b2018-11-15 12:24:31 -08002889
Devin Kimd789e432016-10-26 15:07:27 -07002890 if ((out_device != AUDIO_DEVICE_NONE) && (voice_is_in_call(adev) ||
2891 audio_extn_hfp_is_active(adev))) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002892 if (adev->voice.tty_mode != TTY_MODE_OFF) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002893 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002894 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2895 out_device & AUDIO_DEVICE_OUT_LINE) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002896 switch (adev->voice.tty_mode) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002897 case TTY_MODE_FULL:
2898 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
2899 break;
2900 case TTY_MODE_VCO:
2901 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
2902 break;
2903 case TTY_MODE_HCO:
2904 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
2905 break;
2906 default:
2907 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
2908 }
2909 goto exit;
Eric Laurent99dab492017-06-17 15:19:08 -07002910 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002911 switch (adev->voice.tty_mode) {
2912 case TTY_MODE_FULL:
2913 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC;
2914 break;
2915 case TTY_MODE_VCO:
2916 // since voice will be captured from handset mic, use existing device
2917 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
2918 break;
2919 case TTY_MODE_HCO:
2920 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC;
2921 break;
2922 default:
2923 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
Eric Laurentb23d5282013-05-14 15:27:20 -07002924 }
2925 goto exit;
2926 }
2927 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002928 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002929 if (my_data->fluence_in_voice_call == false) {
2930 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2931 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002932 if (is_operator_tmus())
2933 snd_device = SND_DEVICE_IN_VOICE_DMIC_TMUS;
Eric Laurentb23d5282013-05-14 15:27:20 -07002934 else
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002935 snd_device = SND_DEVICE_IN_VOICE_DMIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002936 }
2937 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2938 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
2939 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002940 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002941 if (adev->bluetooth_nrec)
2942 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2943 else
2944 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002945 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002946 if (adev->bluetooth_nrec)
2947 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2948 else
2949 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002950 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002951 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Prashant Malanic92c5962015-08-11 15:10:18 -07002952 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
2953 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2954 out_device & AUDIO_DEVICE_OUT_LINE) {
2955 if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
2956 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
2957 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
2958 } else {
2959 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2960 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002961 }
vivek mehtafe121d52015-08-10 23:39:23 -07002962
2963 //select default
2964 if (snd_device == SND_DEVICE_NONE) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002965 if (!adev->enable_hfp) {
2966 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2967 } else {
2968 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP;
2969 platform_set_echo_reference(adev, true, out_device);
2970 }
vivek mehtafe121d52015-08-10 23:39:23 -07002971 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002972 } else if (out_device & AUDIO_DEVICE_OUT_TELEPHONY_TX) {
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002973 snd_device = SND_DEVICE_IN_VOICE_RX;
Eric Laurent99dab492017-06-17 15:19:08 -07002974 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
David Lin40b07892017-08-07 15:02:48 -07002975 if (audio_extn_usb_is_capture_supported()) {
2976 snd_device = SND_DEVICE_IN_VOICE_USB_HEADSET_MIC;
2977 } else if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
2978 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
2979 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
2980 } else {
2981 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2982 }
2983 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002984 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002985 } else if (source == AUDIO_SOURCE_CAMCORDER) {
2986 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
2987 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Eric Laurent5f4ca952018-10-19 17:33:43 -07002988 switch (adev->camera_orientation) {
2989 case CAMERA_BACK_LANDSCAPE:
2990 snd_device = SND_DEVICE_IN_CAMCORDER_LANDSCAPE;
2991 break;
2992 case CAMERA_BACK_INVERT_LANDSCAPE:
2993 snd_device = SND_DEVICE_IN_CAMCORDER_INVERT_LANDSCAPE;
2994 break;
2995 case CAMERA_BACK_PORTRAIT:
2996 snd_device = SND_DEVICE_IN_CAMCORDER_PORTRAIT;
2997 break;
2998 case CAMERA_FRONT_LANDSCAPE:
2999 snd_device = SND_DEVICE_IN_CAMCORDER_SELFIE_LANDSCAPE;
3000 break;
3001 case CAMERA_FRONT_INVERT_LANDSCAPE:
3002 snd_device = SND_DEVICE_IN_CAMCORDER_SELFIE_INVERT_LANDSCAPE;
3003 break;
3004 case CAMERA_FRONT_PORTRAIT:
3005 snd_device = SND_DEVICE_IN_CAMCORDER_SELFIE_PORTRAIT;
3006 break;
3007 default:
3008 ALOGW("%s: invalid camera orientation %08x", __func__, adev->camera_orientation);
3009 snd_device = SND_DEVICE_IN_CAMCORDER_LANDSCAPE;
3010 break;
3011 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003012 }
3013 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
3014 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003015 if (my_data->fluence_in_voice_rec && channel_count == 1) {
3016 if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
3017 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
Eric Laurentd1b7a9b2018-11-15 12:24:31 -08003018 if (in->enable_aec)
vivek mehta733c1df2016-04-04 15:09:24 -07003019 snd_device = SND_DEVICE_IN_HANDSET_QMIC_AEC;
3020 else
3021 snd_device = SND_DEVICE_IN_HANDSET_QMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003022 } else if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
3023 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
Eric Laurentd1b7a9b2018-11-15 12:24:31 -08003024 if (in->enable_aec)
vivek mehta733c1df2016-04-04 15:09:24 -07003025 snd_device = SND_DEVICE_IN_HANDSET_TMIC_AEC;
3026 else
3027 snd_device = SND_DEVICE_IN_HANDSET_TMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003028 } else if (((my_data->fluence_type == FLUENCE_PRO_ENABLE) ||
3029 (my_data->fluence_type == FLUENCE_ENABLE)) &&
3030 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Eric Laurentd1b7a9b2018-11-15 12:24:31 -08003031 if (in->enable_aec)
vivek mehta733c1df2016-04-04 15:09:24 -07003032 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
3033 else
3034 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
Prashant Malanic92c5962015-08-11 15:10:18 -07003035 }
3036 platform_set_echo_reference(adev, true, out_device);
3037 } else if ((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) &&
3038 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
3039 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003040 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003041 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
3042 snd_device = SND_DEVICE_IN_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003043 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003044 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
3045 snd_device = SND_DEVICE_IN_QUAD_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07003046 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003047 if (snd_device == SND_DEVICE_NONE) {
Eric Laurentd1b7a9b2018-11-15 12:24:31 -08003048 if (in->enable_aec) {
3049 if (in->enable_ns) {
vivek mehtaf3440682016-05-11 14:24:37 -07003050 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS;
3051 } else {
3052 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC;
3053 }
vivek mehta733c1df2016-04-04 15:09:24 -07003054 platform_set_echo_reference(adev, true, out_device);
Eric Laurentd1b7a9b2018-11-15 12:24:31 -08003055 } else if (in->enable_ns) {
vivek mehtaf3440682016-05-11 14:24:37 -07003056 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
3057 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003058 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
vivek mehtaf3440682016-05-11 14:24:37 -07003059 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003060 }
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -07003061 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3062 snd_device = SND_DEVICE_IN_VOICE_REC_HEADSET_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07003063 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07003064 snd_device = SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07003065 }
rago90fb9612015-12-02 11:37:53 -08003066 } else if (source == AUDIO_SOURCE_UNPROCESSED) {
3067 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
vivek mehta4ed66e62016-04-15 23:33:34 -07003068 if (((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) ||
3069 (channel_mask == AUDIO_CHANNEL_IN_STEREO)) &&
3070 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
3071 snd_device = SND_DEVICE_IN_UNPROCESSED_STEREO_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003072 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07003073 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
3074 snd_device = SND_DEVICE_IN_UNPROCESSED_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003075 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07003076 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
3077 snd_device = SND_DEVICE_IN_UNPROCESSED_QUAD_MIC;
3078 } else {
3079 snd_device = SND_DEVICE_IN_UNPROCESSED_MIC;
3080 }
rago90fb9612015-12-02 11:37:53 -08003081 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3082 snd_device = SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07003083 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07003084 snd_device = SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC;
rago90fb9612015-12-02 11:37:53 -08003085 }
Eric Laurent50a38ed2015-10-14 18:48:06 -07003086 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION ||
rago90fb9612015-12-02 11:37:53 -08003087 mode == AUDIO_MODE_IN_COMMUNICATION) {
David Lin40b07892017-08-07 15:02:48 -07003088 if (out_device & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
3089 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
3090 (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE | AUDIO_DEVICE_OUT_USB_HEADSET) &&
3091 !audio_extn_usb_is_capture_supported())) {
Eric Laurentb23d5282013-05-14 15:27:20 -07003092 in_device = AUDIO_DEVICE_IN_BACK_MIC;
David Lin40b07892017-08-07 15:02:48 -07003093 }
Eric Laurentd1b7a9b2018-11-15 12:24:31 -08003094 if (in) {
3095 if (in->enable_aec &&
3096 in->enable_ns) {
Eric Laurentb23d5282013-05-14 15:27:20 -07003097 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003098 if (my_data->fluence_in_spkr_mode &&
3099 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003100 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003101 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003102 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003103 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003104 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003105 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003106 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003107 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003108 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003109 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003110 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003111 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05003112 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3113 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Eric Laurent99dab492017-06-17 15:19:08 -07003114 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07003115 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
Eric Laurentb23d5282013-05-14 15:27:20 -07003116 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05003117 platform_set_echo_reference(adev, true, out_device);
Eric Laurentd1b7a9b2018-11-15 12:24:31 -08003118 } else if (in->enable_aec) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003119 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
3120 if (my_data->fluence_in_spkr_mode &&
3121 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003122 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003123 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003124 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003125 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003126 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003127 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
3128 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003129 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003130 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003131 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003132 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003133 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05003134 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3135 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Eric Laurent99dab492017-06-17 15:19:08 -07003136 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07003137 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
Eric Laurentcefbbac2014-09-04 13:54:10 -05003138 }
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08003139 platform_set_echo_reference(adev, true, out_device);
Eric Laurentd1b7a9b2018-11-15 12:24:31 -08003140 } else if (in->enable_ns) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003141 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
3142 if (my_data->fluence_in_spkr_mode &&
3143 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003144 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003145 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003146 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003147 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003148 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003149 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
3150 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003151 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003152 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003153 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003154 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003155 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003156 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05003157 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003158 }
3159 } else if (source == AUDIO_SOURCE_DEFAULT) {
3160 goto exit;
3161 }
3162
3163
3164 if (snd_device != SND_DEVICE_NONE) {
3165 goto exit;
3166 }
3167
3168 if (in_device != AUDIO_DEVICE_NONE &&
3169 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
3170 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
3171 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003172 if ((my_data->source_mic_type & SOURCE_QUAD_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003173 channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003174 snd_device = SND_DEVICE_IN_QUAD_MIC;
3175 } else if ((my_data->source_mic_type & SOURCE_THREE_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003176 channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003177 snd_device = SND_DEVICE_IN_THREE_MIC;
3178 } else if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
3179 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003180 snd_device = SND_DEVICE_IN_HANDSET_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07003181 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
3182 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003183 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003184 } else {
3185 ALOGE("%s: something wrong (1): source type (%d) channel_count (%d) .."
3186 " channel mask (0x%x) no combination found .. setting to mono", __func__,
3187 my_data->source_mic_type, channel_count, channel_mask);
3188 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3189 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003190 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003191 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
3192 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003193 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07003194 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
3195 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003196 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003197 } else {
3198 ALOGE("%s: something wrong (2): source type (%d) channel_count (%d) .."
3199 " no combination found .. setting to mono", __func__,
3200 my_data->source_mic_type, channel_count);
3201 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
3202 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003203 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3204 snd_device = SND_DEVICE_IN_HEADSET_MIC;
3205 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003206 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003207 if (adev->bluetooth_nrec)
3208 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
3209 else
3210 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003211 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003212 if (adev->bluetooth_nrec)
3213 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
3214 else
3215 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003216 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003217 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
3218 snd_device = SND_DEVICE_IN_HDMI_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07003219 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
David Linee3fe402017-03-13 10:00:42 -07003220 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07003221 } else {
3222 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
3223 ALOGW("%s: Using default handset-mic", __func__);
3224 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3225 }
3226 } else {
3227 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
3228 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3229 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
3230 snd_device = SND_DEVICE_IN_HEADSET_MIC;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003231 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07003232 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003233 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05003234 out_device & AUDIO_DEVICE_OUT_LINE) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003235 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
3236 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003237 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07003238 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
3239 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003240 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003241 } else {
3242 ALOGE("%s: something wrong (3): source type (%d) channel_count (%d) .."
3243 " no combination found .. setting to mono", __func__,
3244 my_data->source_mic_type, channel_count);
3245 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
3246 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003247 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003248 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003249 if (adev->bluetooth_nrec)
3250 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
3251 else
3252 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003253 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003254 if (adev->bluetooth_nrec)
3255 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
3256 else
3257 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003258 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003259 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
3260 snd_device = SND_DEVICE_IN_HDMI_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07003261 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
David Linee3fe402017-03-13 10:00:42 -07003262 if (audio_extn_usb_is_capture_supported())
3263 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
3264 else
3265 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07003266 } else {
3267 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
3268 ALOGW("%s: Using default handset-mic", __func__);
3269 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3270 }
3271 }
3272exit:
3273 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
3274 return snd_device;
3275}
3276
3277int platform_set_hdmi_channels(void *platform, int channel_count)
3278{
3279 struct platform_data *my_data = (struct platform_data *)platform;
3280 struct audio_device *adev = my_data->adev;
3281 struct mixer_ctl *ctl;
3282 const char *channel_cnt_str = NULL;
3283 const char *mixer_ctl_name = "HDMI_RX Channels";
3284 switch (channel_count) {
3285 case 8:
3286 channel_cnt_str = "Eight"; break;
3287 case 7:
3288 channel_cnt_str = "Seven"; break;
3289 case 6:
3290 channel_cnt_str = "Six"; break;
3291 case 5:
3292 channel_cnt_str = "Five"; break;
3293 case 4:
3294 channel_cnt_str = "Four"; break;
3295 case 3:
3296 channel_cnt_str = "Three"; break;
3297 default:
3298 channel_cnt_str = "Two"; break;
3299 }
3300 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3301 if (!ctl) {
3302 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3303 __func__, mixer_ctl_name);
3304 return -EINVAL;
3305 }
3306 ALOGV("HDMI channel count: %s", channel_cnt_str);
3307 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
3308 return 0;
3309}
3310
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003311int platform_edid_get_max_channels(void *platform)
Eric Laurentb23d5282013-05-14 15:27:20 -07003312{
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003313 struct platform_data *my_data = (struct platform_data *)platform;
3314 struct audio_device *adev = my_data->adev;
Eric Laurentb23d5282013-05-14 15:27:20 -07003315 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
3316 char *sad = block;
3317 int num_audio_blocks;
3318 int channel_count;
3319 int max_channels = 0;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003320 int i, ret, count;
Eric Laurentb23d5282013-05-14 15:27:20 -07003321
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003322 struct mixer_ctl *ctl;
3323
3324 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
3325 if (!ctl) {
3326 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3327 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
Eric Laurentb23d5282013-05-14 15:27:20 -07003328 return 0;
3329 }
3330
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003331 mixer_ctl_update(ctl);
3332
3333 count = mixer_ctl_get_num_values(ctl);
Eric Laurentb23d5282013-05-14 15:27:20 -07003334
3335 /* Read SAD blocks, clamping the maximum size for safety */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003336 if (count > (int)sizeof(block))
3337 count = (int)sizeof(block);
Eric Laurentb23d5282013-05-14 15:27:20 -07003338
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003339 ret = mixer_ctl_get_array(ctl, block, count);
3340 if (ret != 0) {
3341 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
3342 return 0;
3343 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003344
3345 /* Calculate the number of SAD blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003346 num_audio_blocks = count / SAD_BLOCK_SIZE;
Eric Laurentb23d5282013-05-14 15:27:20 -07003347
3348 for (i = 0; i < num_audio_blocks; i++) {
3349 /* Only consider LPCM blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003350 if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
3351 sad += 3;
Eric Laurentb23d5282013-05-14 15:27:20 -07003352 continue;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003353 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003354
3355 channel_count = (sad[0] & 0x7) + 1;
3356 if (channel_count > max_channels)
3357 max_channels = channel_count;
3358
3359 /* Advance to next block */
3360 sad += 3;
3361 }
3362
3363 return max_channels;
3364}
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003365
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07003366int platform_set_incall_recording_session_id(void *platform,
3367 uint32_t session_id, int rec_mode)
3368{
3369 int ret = 0;
3370 struct platform_data *my_data = (struct platform_data *)platform;
3371 struct audio_device *adev = my_data->adev;
3372 struct mixer_ctl *ctl;
3373 const char *mixer_ctl_name = "Voc VSID";
3374 int num_ctl_values;
3375 int i;
3376
3377 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3378 if (!ctl) {
3379 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3380 __func__, mixer_ctl_name);
3381 ret = -EINVAL;
3382 } else {
3383 num_ctl_values = mixer_ctl_get_num_values(ctl);
3384 for (i = 0; i < num_ctl_values; i++) {
3385 if (mixer_ctl_set_value(ctl, i, session_id)) {
3386 ALOGV("Error: invalid session_id: %x", session_id);
3387 ret = -EINVAL;
3388 break;
3389 }
3390 }
3391 }
3392
3393 if (my_data->csd != NULL) {
3394 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
3395 if (ret < 0) {
3396 ALOGE("%s: csd_client_start_record failed, error %d",
3397 __func__, ret);
3398 }
3399 }
3400
3401 return ret;
3402}
3403
Arun Mirpuriba2749a2018-04-17 14:32:24 -07003404int platform_set_incall_recording_session_channels(void *platform,
3405 uint32_t channel_count)
3406{
3407 int ret = 0;
3408 struct platform_data *my_data = (struct platform_data *)platform;
3409 struct audio_device *adev = my_data->adev;
3410 const char *mixer_ctl_name = "Voc Rec Config";
3411 int num_ctl_values;
3412 int i;
3413 struct mixer_ctl *ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3414
3415 if (!ctl) {
3416 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3417 __func__, mixer_ctl_name);
3418 ret = -EINVAL;
3419 } else {
3420 num_ctl_values = mixer_ctl_get_num_values(ctl);
3421 for (i = 0; i < num_ctl_values; i++) {
3422 if (mixer_ctl_set_value(ctl, i, channel_count)) {
3423 ALOGE("Error: invalid channel count: %x", channel_count);
3424 ret = -EINVAL;
3425 break;
3426 }
3427 }
3428 }
3429
3430 return ret;
3431}
3432
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07003433int platform_stop_incall_recording_usecase(void *platform)
3434{
3435 int ret = 0;
3436 struct platform_data *my_data = (struct platform_data *)platform;
3437
3438 if (my_data->csd != NULL) {
3439 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
3440 if (ret < 0) {
3441 ALOGE("%s: csd_client_stop_record failed, error %d",
3442 __func__, ret);
3443 }
3444 }
3445
3446 return ret;
3447}
3448
3449int platform_start_incall_music_usecase(void *platform)
3450{
3451 int ret = 0;
3452 struct platform_data *my_data = (struct platform_data *)platform;
3453
3454 if (my_data->csd != NULL) {
3455 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
3456 if (ret < 0) {
3457 ALOGE("%s: csd_client_start_playback failed, error %d",
3458 __func__, ret);
3459 }
3460 }
3461
3462 return ret;
3463}
3464
3465int platform_stop_incall_music_usecase(void *platform)
3466{
3467 int ret = 0;
3468 struct platform_data *my_data = (struct platform_data *)platform;
3469
3470 if (my_data->csd != NULL) {
3471 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
3472 if (ret < 0) {
3473 ALOGE("%s: csd_client_stop_playback failed, error %d",
3474 __func__, ret);
3475 }
3476 }
3477
3478 return ret;
3479}
3480
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003481int platform_set_parameters(void *platform, struct str_parms *parms)
3482{
3483 struct platform_data *my_data = (struct platform_data *)platform;
jasmine chac89321b2018-04-10 21:37:01 +08003484 char *value = NULL;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003485 char *kv_pairs = str_parms_to_str(parms);
jasmine chac89321b2018-04-10 21:37:01 +08003486 int len;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003487 int ret = 0, err;
3488
3489 if (kv_pairs == NULL) {
3490 ret = -EINVAL;
Jasmine Chaa314e192018-05-09 17:46:28 +08003491 ALOGE("%s: key-value pair is NULL", __func__);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003492 goto done;
3493 }
3494
3495 ALOGV("%s: enter: %s", __func__, kv_pairs);
3496
jasmine chac89321b2018-04-10 21:37:01 +08003497 len = strlen(kv_pairs);
Jasmine Chaa314e192018-05-09 17:46:28 +08003498 value = (char*)calloc(len + 1, sizeof(char));
jasmine chac89321b2018-04-10 21:37:01 +08003499 if (value == NULL) {
3500 ret = -ENOMEM;
Jasmine Chaa314e192018-05-09 17:46:28 +08003501 ALOGE("[%s] failed to allocate memory", __func__);
jasmine chac89321b2018-04-10 21:37:01 +08003502 goto done;
3503 }
3504
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003505 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME,
jasmine chac89321b2018-04-10 21:37:01 +08003506 value, len);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003507 if (err >= 0) {
3508 str_parms_del(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME);
3509 my_data->snd_card_name = strdup(value);
3510 ALOGV("%s: sound card name %s", __func__, my_data->snd_card_name);
3511 }
3512
keunhui.park2f7306a2015-07-16 16:48:06 +09003513 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO,
jasmine chac89321b2018-04-10 21:37:01 +08003514 value, len);
keunhui.park2f7306a2015-07-16 16:48:06 +09003515 if (err >= 0) {
3516 struct operator_info *info;
3517 char *str = value;
3518 char *name;
3519
3520 str_parms_del(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO);
3521 info = (struct operator_info *)calloc(1, sizeof(struct operator_info));
3522 name = strtok(str, ";");
3523 info->name = strdup(name);
3524 info->mccmnc = strdup(str + strlen(name) + 1);
3525
3526 list_add_tail(&operator_info_list, &info->list);
Joe Onorato188b6222016-03-01 11:02:27 -08003527 ALOGV("%s: add operator[%s] mccmnc[%s]", __func__, info->name, info->mccmnc);
keunhui.park2f7306a2015-07-16 16:48:06 +09003528 }
Prashant Malanic92c5962015-08-11 15:10:18 -07003529
Jasmine Chaa314e192018-05-09 17:46:28 +08003530 memset(value, 0, len + 1);
Eric Laurentc6333382015-09-14 12:43:44 -07003531 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT,
jasmine chac89321b2018-04-10 21:37:01 +08003532 value, len);
Prashant Malanic92c5962015-08-11 15:10:18 -07003533 if (err >= 0) {
Eric Laurentc6333382015-09-14 12:43:44 -07003534 str_parms_del(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT);
Prashant Malanic92c5962015-08-11 15:10:18 -07003535 my_data->max_mic_count = atoi(value);
3536 ALOGV("%s: max_mic_count %s/%d", __func__, value, my_data->max_mic_count);
Prashant Malanic92c5962015-08-11 15:10:18 -07003537 }
3538
jasmine chac89321b2018-04-10 21:37:01 +08003539 /* handle audio calibration parameters */
3540 set_audiocal(platform, parms, value, len);
3541
vivek mehta90933872017-06-15 18:04:39 -07003542 // to-do: disable setting sidetone gain, will revist this later
3543 // audio_extn_usb_set_sidetone_gain(parms, value, len);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003544done:
3545 ALOGV("%s: exit with code(%d)", __func__, ret);
3546 if (kv_pairs != NULL)
3547 free(kv_pairs);
jasmine chac89321b2018-04-10 21:37:01 +08003548 if (value != NULL)
3549 free(value);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003550
3551 return ret;
3552}
3553
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003554/* Delay in Us */
3555int64_t platform_render_latency(audio_usecase_t usecase)
3556{
3557 switch (usecase) {
3558 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
3559 return DEEP_BUFFER_PLATFORM_DELAY;
3560 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
3561 return LOW_LATENCY_PLATFORM_DELAY;
Haynes Mathew George03c40102016-01-29 17:57:48 -08003562 case USECASE_AUDIO_PLAYBACK_ULL:
3563 return ULL_PLATFORM_DELAY;
Eric Laurent0e46adf2016-12-16 12:49:24 -08003564 case USECASE_AUDIO_PLAYBACK_MMAP:
3565 return MMAP_PLATFORM_DELAY;
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003566 default:
3567 return 0;
3568 }
3569}
Haynes Mathew George98c95622014-06-20 19:14:25 -07003570
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003571int platform_set_snd_device_backend(snd_device_t device, const char *backend_tag,
3572 const char * hw_interface)
Haynes Mathew George98c95622014-06-20 19:14:25 -07003573{
3574 int ret = 0;
3575
3576 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
3577 ALOGE("%s: Invalid snd_device = %d",
3578 __func__, device);
3579 ret = -EINVAL;
3580 goto done;
3581 }
3582
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003583 ALOGV("%s: backend_tag_table[%s]: old = %s new = %s", __func__,
3584 platform_get_snd_device_name(device),
3585 backend_tag_table[device] != NULL ? backend_tag_table[device]: "null", backend_tag);
3586 if (backend_tag_table[device]) {
3587 free(backend_tag_table[device]);
Haynes Mathew George98c95622014-06-20 19:14:25 -07003588 }
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003589 backend_tag_table[device] = strdup(backend_tag);
3590
3591 if (hw_interface != NULL) {
3592 if (hw_interface_table[device])
3593 free(hw_interface_table[device]);
3594 ALOGV("%s: hw_interface_table[%d] = %s", __func__, device, hw_interface);
3595 hw_interface_table[device] = strdup(hw_interface);
3596 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07003597done:
3598 return ret;
3599}
3600
3601int platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t pcm_id)
3602{
3603 int ret = 0;
3604 if ((usecase <= USECASE_INVALID) || (usecase >= AUDIO_USECASE_MAX)) {
3605 ALOGE("%s: invalid usecase case idx %d", __func__, usecase);
3606 ret = -EINVAL;
3607 goto done;
3608 }
3609
3610 if ((type != 0) && (type != 1)) {
3611 ALOGE("%s: invalid usecase type", __func__);
3612 ret = -EINVAL;
3613 }
vivek mehtaa68fea62017-06-08 19:04:02 -07003614 ALOGV("%s: pcm_device_table[%d %s][%d] = %d", __func__, usecase,
3615 use_case_table[usecase],
3616 type, pcm_id);
Haynes Mathew George98c95622014-06-20 19:14:25 -07003617 pcm_device_table[usecase][type] = pcm_id;
3618done:
3619 return ret;
3620}
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003621
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07003622#define DEFAULT_NOMINAL_SPEAKER_GAIN 20
3623int ramp_speaker_gain(struct audio_device *adev, bool ramp_up, int target_ramp_up_gain) {
3624 // backup_gain: gain to try to set in case of an error during ramp
3625 int start_gain, end_gain, step, backup_gain, i;
3626 bool error = false;
3627 const struct mixer_ctl *ctl;
3628 const char *mixer_ctl_name_gain_left = "Left Speaker Gain";
3629 const char *mixer_ctl_name_gain_right = "Right Speaker Gain";
3630 struct mixer_ctl *ctl_left = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_left);
3631 struct mixer_ctl *ctl_right = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_right);
3632 if (!ctl_left || !ctl_right) {
3633 ALOGE("%s: Could not get ctl for mixer cmd - %s or %s, not applying speaker gain ramp",
3634 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
3635 return -EINVAL;
3636 } else if ((mixer_ctl_get_num_values(ctl_left) != 1)
3637 || (mixer_ctl_get_num_values(ctl_right) != 1)) {
3638 ALOGE("%s: Unexpected num values for mixer cmd - %s or %s, not applying speaker gain ramp",
3639 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
3640 return -EINVAL;
3641 }
3642 if (ramp_up) {
3643 start_gain = 0;
3644 end_gain = target_ramp_up_gain > 0 ? target_ramp_up_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
3645 step = +1;
3646 backup_gain = end_gain;
3647 } else {
3648 // using same gain on left and right
3649 const int left_gain = mixer_ctl_get_value(ctl_left, 0);
3650 start_gain = left_gain > 0 ? left_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
3651 end_gain = 0;
3652 step = -1;
3653 backup_gain = start_gain;
3654 }
3655 for (i = start_gain ; i != (end_gain + step) ; i += step) {
3656 //ALOGV("setting speaker gain to %d", i);
3657 if (mixer_ctl_set_value(ctl_left, 0, i)) {
3658 ALOGE("%s: error setting %s to %d during gain ramp",
3659 __func__, mixer_ctl_name_gain_left, i);
3660 error = true;
3661 break;
3662 }
3663 if (mixer_ctl_set_value(ctl_right, 0, i)) {
3664 ALOGE("%s: error setting %s to %d during gain ramp",
3665 __func__, mixer_ctl_name_gain_right, i);
3666 error = true;
3667 break;
3668 }
3669 usleep(1000);
3670 }
3671 if (error) {
3672 // an error occured during the ramp, let's still try to go back to a safe volume
3673 if (mixer_ctl_set_value(ctl_left, 0, backup_gain)) {
3674 ALOGE("%s: error restoring left gain to %d", __func__, backup_gain);
3675 }
3676 if (mixer_ctl_set_value(ctl_right, 0, backup_gain)) {
3677 ALOGE("%s: error restoring right gain to %d", __func__, backup_gain);
3678 }
3679 }
3680 return start_gain;
3681}
3682
vivek mehtae59cfb22017-06-16 15:57:11 -07003683int platform_set_swap_mixer(struct audio_device *adev, bool swap_channels)
3684{
3685 const char *mixer_ctl_name = "Swap channel";
3686 struct mixer_ctl *ctl;
3687 const char *mixer_path;
3688 struct platform_data *my_data = (struct platform_data *)adev->platform;
3689
3690 // forced to set to swap, but device not rotated ... ignore set
3691 if (swap_channels && !my_data->speaker_lr_swap)
3692 return 0;
3693
3694 ALOGV("%s:", __func__);
3695
3696 if (swap_channels) {
3697 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER_REVERSE);
3698 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
3699 } else {
3700 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER);
3701 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
3702 }
3703
3704 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3705 if (!ctl) {
3706 ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name);
3707 return -EINVAL;
3708 }
3709
3710 if (mixer_ctl_set_value(ctl, 0, swap_channels) < 0) {
3711 ALOGE("%s: Could not set reverse cotrol %d",__func__, swap_channels);
3712 return -EINVAL;
3713 }
3714
3715 ALOGV("platfor_force_swap_channel :: Channel orientation ( %s ) ",
3716 swap_channels?"R --> L":"L --> R");
3717
3718 return 0;
3719}
3720
3721int platform_check_and_set_swap_lr_channels(struct audio_device *adev, bool swap_channels)
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003722{
3723 // only update if there is active pcm playback on speaker
3724 struct audio_usecase *usecase;
3725 struct listnode *node;
3726 struct platform_data *my_data = (struct platform_data *)adev->platform;
3727
vivek mehtae59cfb22017-06-16 15:57:11 -07003728 my_data->speaker_lr_swap = swap_channels;
Jean-Michel Trivif7148702016-09-16 18:23:05 -07003729
vivek mehtae59cfb22017-06-16 15:57:11 -07003730 return platform_set_swap_channels(adev, swap_channels);
3731}
Jean-Michel Trivif7148702016-09-16 18:23:05 -07003732
vivek mehtae59cfb22017-06-16 15:57:11 -07003733int platform_set_swap_channels(struct audio_device *adev, bool swap_channels)
3734{
3735 // only update if there is active pcm playback on speaker
3736 struct audio_usecase *usecase;
3737 struct listnode *node;
3738 struct platform_data *my_data = (struct platform_data *)adev->platform;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003739
vivek mehtae59cfb22017-06-16 15:57:11 -07003740 // do not swap channels in audio modes with concurrent capture and playback
3741 // as this may break the echo reference
3742 if ((adev->mode == AUDIO_MODE_IN_COMMUNICATION) || (adev->mode == AUDIO_MODE_IN_CALL)) {
3743 ALOGV("%s: will not swap due to audio mode %d", __func__, adev->mode);
3744 return 0;
3745 }
3746
3747 list_for_each(node, &adev->usecase_list) {
3748 usecase = node_to_item(node, struct audio_usecase, list);
3749 if (usecase->type == PCM_PLAYBACK &&
3750 usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) {
3751 /*
3752 * If acdb tuning is different for SPEAKER_REVERSE, it is must
3753 * to perform device switch to disable the current backend to
3754 * enable it with new acdb data.
3755 */
3756 if (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
3757 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]) {
3758 const int initial_skpr_gain = ramp_speaker_gain(adev, false /*ramp_up*/, -1);
3759 select_devices(adev, usecase->id);
3760 if (initial_skpr_gain != -EINVAL)
3761 ramp_speaker_gain(adev, true /*ramp_up*/, initial_skpr_gain);
3762
3763 } else {
3764 platform_set_swap_mixer(adev, swap_channels);
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003765 }
vivek mehtae59cfb22017-06-16 15:57:11 -07003766 break;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003767 }
3768 }
vivek mehtae59cfb22017-06-16 15:57:11 -07003769
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003770 return 0;
3771}
vivek mehtaa8d7c922016-05-25 14:40:44 -07003772
3773static struct amp_db_and_gain_table tbl_mapping[MAX_VOLUME_CAL_STEPS];
3774static int num_gain_tbl_entry = 0;
3775
3776bool platform_add_gain_level_mapping(struct amp_db_and_gain_table *tbl_entry) {
3777
3778 ALOGV("%s: enter .. add %f %f %d", __func__, tbl_entry->amp, tbl_entry->db, tbl_entry->level);
3779 if (num_gain_tbl_entry == -1) {
3780 ALOGE("%s: num entry beyond valid step levels or corrupted..rejecting custom mapping",
3781 __func__);
3782 return false;
3783 }
3784
3785 if (num_gain_tbl_entry >= MAX_VOLUME_CAL_STEPS) {
3786 ALOGE("%s: max entry reached max[%d] current index[%d] .. rejecting", __func__,
3787 MAX_VOLUME_CAL_STEPS, num_gain_tbl_entry);
3788 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
3789 return false;
3790 }
3791
3792 if (num_gain_tbl_entry > 0 && tbl_mapping[num_gain_tbl_entry - 1].amp >= tbl_entry->amp) {
3793 ALOGE("%s: value not in ascending order .. rejecting custom mapping", __func__);
3794 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
3795 return false;
3796 }
3797
3798 tbl_mapping[num_gain_tbl_entry] = *tbl_entry;
3799 ++num_gain_tbl_entry;
3800
3801 return true;
3802}
3803
3804int platform_get_gain_level_mapping(struct amp_db_and_gain_table *mapping_tbl,
3805 int table_size) {
3806 int itt = 0;
3807 ALOGV("platform_get_gain_level_mapping called ");
3808
3809 if (num_gain_tbl_entry <= 0 || num_gain_tbl_entry > MAX_VOLUME_CAL_STEPS) {
3810 ALOGD("%s: empty or currupted gain_mapping_table", __func__);
3811 return 0;
3812 }
3813
3814 for (; itt < num_gain_tbl_entry && itt <= table_size; itt++) {
3815 mapping_tbl[itt] = tbl_mapping[itt];
3816 ALOGV("%s: added amp[%f] db[%f] level[%d]", __func__,
3817 mapping_tbl[itt].amp, mapping_tbl[itt].db, mapping_tbl[itt].level);
3818 }
3819
3820 return num_gain_tbl_entry;
3821}
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07003822
3823int platform_snd_card_update(void *platform, card_status_t status)
3824{
3825 struct platform_data *my_data = (struct platform_data *)platform;
3826 struct audio_device *adev = my_data->adev;
3827
3828 if (status == CARD_STATUS_ONLINE) {
3829 if (my_data->acdb_send_custom_top)
3830 my_data->acdb_send_custom_top();
3831 }
3832 return 0;
3833}
David Linee3fe402017-03-13 10:00:42 -07003834
3835/*
3836 * configures afe with bit width and Sample Rate
3837 */
Haynes Mathew George65f6b432018-02-27 17:44:55 -08003838int platform_set_backend_cfg(const struct audio_device* adev,
3839 snd_device_t snd_device,
3840 const struct audio_backend_cfg *backend_cfg)
David Linee3fe402017-03-13 10:00:42 -07003841{
3842
3843 int ret = 0;
3844 const int backend_idx = platform_get_backend_index(snd_device);
3845 struct platform_data *my_data = (struct platform_data *)adev->platform;
3846 const unsigned int bit_width = backend_cfg->bit_width;
3847 const unsigned int sample_rate = backend_cfg->sample_rate;
3848 const unsigned int channels = backend_cfg->channels;
3849 const audio_format_t format = backend_cfg->format;
3850 const bool passthrough_enabled = backend_cfg->passthrough_enabled;
3851
3852
3853 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
3854 ", backend_idx %d device (%s)", __func__, bit_width,
3855 sample_rate, channels, backend_idx,
3856 platform_get_snd_device_name(snd_device));
3857
3858 if ((my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl) &&
3859 (bit_width != my_data->current_backend_cfg[backend_idx].bit_width)) {
3860
3861 struct mixer_ctl *ctl = NULL;
3862 ctl = mixer_get_ctl_by_name(adev->mixer,
3863 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
3864 if (!ctl) {
3865 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3866 __func__,
3867 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
3868 return -EINVAL;
3869 }
3870
3871 if (bit_width == 24) {
3872 if (format == AUDIO_FORMAT_PCM_24_BIT_PACKED)
3873 ret = mixer_ctl_set_enum_by_string(ctl, "S24_3LE");
3874 else
3875 ret = mixer_ctl_set_enum_by_string(ctl, "S24_LE");
3876 } else if (bit_width == 32) {
3877 ret = mixer_ctl_set_enum_by_string(ctl, "S32_LE");
3878 } else {
3879 ret = mixer_ctl_set_enum_by_string(ctl, "S16_LE");
3880 }
3881 if ( ret < 0) {
3882 ALOGE("%s:becf: afe: fail for %s mixer set to %d bit for %x format", __func__,
3883 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
3884 } else {
3885 my_data->current_backend_cfg[backend_idx].bit_width = bit_width;
3886 ALOGD("%s:becf: afe: %s mixer set to %d bit for %x format", __func__,
3887 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
3888 }
3889 /* set the ret as 0 and not pass back to upper layer */
3890 ret = 0;
3891 }
3892
3893 if (passthrough_enabled || ((my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl) &&
3894 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate))) {
3895 char *rate_str = NULL;
3896 struct mixer_ctl *ctl = NULL;
3897
3898 switch (sample_rate) {
3899 case 32000:
3900 if (passthrough_enabled) {
3901 rate_str = "KHZ_32";
3902 break;
3903 }
3904 case 8000:
3905 case 11025:
3906 case 16000:
3907 case 22050:
3908 case 48000:
3909 rate_str = "KHZ_48";
3910 break;
3911 case 44100:
3912 rate_str = "KHZ_44P1";
3913 break;
3914 case 64000:
3915 case 96000:
3916 rate_str = "KHZ_96";
3917 break;
3918 case 88200:
3919 rate_str = "KHZ_88P2";
3920 break;
3921 case 176400:
3922 rate_str = "KHZ_176P4";
3923 break;
3924 case 192000:
3925 rate_str = "KHZ_192";
3926 break;
3927 case 352800:
3928 rate_str = "KHZ_352P8";
3929 break;
3930 case 384000:
3931 rate_str = "KHZ_384";
3932 break;
3933 case 144000:
3934 if (passthrough_enabled) {
3935 rate_str = "KHZ_144";
3936 break;
3937 }
3938 default:
3939 rate_str = "KHZ_48";
3940 break;
3941 }
3942
3943 ctl = mixer_get_ctl_by_name(adev->mixer,
3944 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
3945 if(!ctl) {
3946 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3947 __func__,
3948 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
3949 return -EINVAL;
3950 }
3951
3952 ALOGD("%s:becf: afe: %s set to %s", __func__,
3953 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl, rate_str);
3954 mixer_ctl_set_enum_by_string(ctl, rate_str);
3955 my_data->current_backend_cfg[backend_idx].sample_rate = sample_rate;
3956 }
3957 if ((my_data->current_backend_cfg[backend_idx].channels_mixer_ctl) &&
3958 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
3959 struct mixer_ctl *ctl = NULL;
3960 char *channel_cnt_str = NULL;
3961
3962 switch (channels) {
3963 case 8:
3964 channel_cnt_str = "Eight"; break;
3965 case 7:
3966 channel_cnt_str = "Seven"; break;
3967 case 6:
3968 channel_cnt_str = "Six"; break;
3969 case 5:
3970 channel_cnt_str = "Five"; break;
3971 case 4:
3972 channel_cnt_str = "Four"; break;
3973 case 3:
3974 channel_cnt_str = "Three"; break;
3975 case 1:
3976 channel_cnt_str = "One"; break;
3977 case 2:
3978 default:
3979 channel_cnt_str = "Two"; break;
3980 }
3981
3982 ctl = mixer_get_ctl_by_name(adev->mixer,
3983 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
3984 if (!ctl) {
3985 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3986 __func__,
3987 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
3988 return -EINVAL;
3989 }
3990 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
3991 my_data->current_backend_cfg[backend_idx].channels = channels;
3992
3993 // skip EDID configuration for HDMI backend
3994
3995 ALOGD("%s:becf: afe: %s set to %s", __func__,
3996 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl,
3997 channel_cnt_str);
3998 }
3999
4000 // skip set ext_display format mixer control
4001 return ret;
4002}
4003
4004static int platform_get_snd_device_bit_width(snd_device_t snd_device)
4005{
4006 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
4007 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
4008 return CODEC_BACKEND_DEFAULT_BIT_WIDTH;
4009 }
4010
4011 return backend_bit_width_table[snd_device];
4012}
4013
4014/*
4015 * return backend_idx on which voice call is active
4016 */
4017static int platform_get_voice_call_backend(struct audio_device* adev)
4018{
4019 struct audio_usecase *uc = NULL;
4020 struct listnode *node;
4021 snd_device_t out_snd_device = SND_DEVICE_NONE;
4022
4023 int backend_idx = -1;
4024
4025 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
4026 list_for_each(node, &adev->usecase_list) {
4027 uc = node_to_item(node, struct audio_usecase, list);
4028 if (uc && uc->type == VOICE_CALL && uc->stream.out) {
4029 out_snd_device = platform_get_output_snd_device(adev->platform,
4030 uc->stream.out->devices);
4031 backend_idx = platform_get_backend_index(out_snd_device);
4032 break;
4033 }
4034 }
4035 }
4036 return backend_idx;
4037}
4038
4039/*
4040 * goes through all the current usecases and picks the highest
4041 * bitwidth & samplerate
4042 */
4043static bool platform_check_capture_backend_cfg(struct audio_device* adev,
4044 int backend_idx,
4045 struct audio_backend_cfg *backend_cfg)
4046{
4047 bool backend_change = false;
4048 unsigned int bit_width;
4049 unsigned int sample_rate;
4050 unsigned int channels;
4051 struct platform_data *my_data = (struct platform_data *)adev->platform;
4052
4053 bit_width = backend_cfg->bit_width;
4054 sample_rate = backend_cfg->sample_rate;
4055 channels = backend_cfg->channels;
4056
4057 ALOGV("%s:txbecf: afe: Codec selected backend: %d current bit width: %d and "
4058 "sample rate: %d, channels %d",__func__,backend_idx, bit_width,
4059 sample_rate, channels);
4060
4061 // For voice calls use default configuration i.e. 16b/48K, only applicable to
4062 // default backend
4063 // force routing is not required here, caller will do it anyway
4064 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
4065 ALOGW("%s:txbecf: afe: Use default bw and sr for voice/voip calls and "
4066 "for unprocessed/camera source", __func__);
4067 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
4068 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4069 }
4070
4071 if (backend_idx == USB_AUDIO_TX_BACKEND) {
4072 audio_extn_usb_is_config_supported(&bit_width, &sample_rate, &channels, false);
4073 ALOGV("%s:txbecf: afe: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
4074 __func__, bit_width, sample_rate, channels);
4075 }
4076
4077 ALOGV("%s:txbecf: afe: Codec selected backend: %d updated bit width: %d and "
4078 "sample rate: %d", __func__, backend_idx, bit_width, sample_rate);
4079
4080 // Force routing if the expected bitwdith or samplerate
4081 // is not same as current backend comfiguration
4082 if ((bit_width != my_data->current_backend_cfg[backend_idx].bit_width) ||
4083 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate) ||
4084 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
4085 backend_cfg->bit_width = bit_width;
4086 backend_cfg->sample_rate= sample_rate;
4087 backend_cfg->channels = channels;
4088 backend_change = true;
4089 ALOGI("%s:txbecf: afe: Codec backend needs to be updated. new bit width: %d "
4090 "new sample rate: %d new channel: %d",
4091 __func__, backend_cfg->bit_width,
4092 backend_cfg->sample_rate, backend_cfg->channels);
4093 }
4094
4095 return backend_change;
4096}
4097
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004098static void pick_playback_cfg_for_uc(struct audio_device *adev,
4099 struct audio_usecase *usecase,
4100 snd_device_t snd_device,
4101 unsigned int *bit_width,
4102 unsigned int *sample_rate,
4103 unsigned int *channels)
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004104{
4105 int i =0;
4106 struct listnode *node;
4107 list_for_each(node, &adev->usecase_list) {
4108 struct audio_usecase *uc;
4109 uc = node_to_item(node, struct audio_usecase, list);
4110 struct stream_out *out = (struct stream_out*) uc->stream.out;
4111 if (uc->type == PCM_PLAYBACK && out && usecase != uc) {
4112 unsigned int out_channels = audio_channel_count_from_out_mask(out->channel_mask);
4113 ALOGV("%s:napb: (%d) - (%s)id (%d) sr %d bw "
4114 "(%d) ch (%d) device %s", __func__, i++, use_case_table[uc->id],
4115 uc->id, out->sample_rate,
4116 pcm_format_to_bits(out->config.format), out_channels,
4117 platform_get_snd_device_name(uc->out_snd_device));
4118
4119 if (platform_check_backends_match(snd_device, uc->out_snd_device)) {
4120 if (*bit_width < pcm_format_to_bits(out->config.format))
4121 *bit_width = pcm_format_to_bits(out->config.format);
4122 if (*sample_rate < out->sample_rate)
4123 *sample_rate = out->sample_rate;
4124 if (out->sample_rate < OUTPUT_SAMPLING_RATE_44100)
4125 *sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4126 if (*channels < out_channels)
4127 *channels = out_channels;
4128 }
4129 }
4130 }
4131 return;
4132}
4133
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004134static void headset_is_config_supported(unsigned int *bit_width,
4135 unsigned int *sample_rate,
4136 unsigned int *channels) {
4137 switch (*bit_width) {
4138 case 16:
4139 case 24:
4140 break;
4141 default:
4142 *bit_width = 16;
4143 break;
4144 }
4145
4146 if (*sample_rate > 192000) {
4147 *sample_rate = 192000;
4148 }
4149
4150 if (*channels > 2) {
4151 *channels = 2;
4152 }
4153}
4154
David Linee3fe402017-03-13 10:00:42 -07004155static bool platform_check_playback_backend_cfg(struct audio_device* adev,
4156 struct audio_usecase* usecase,
4157 snd_device_t snd_device,
4158 struct audio_backend_cfg *backend_cfg)
4159{
4160 bool backend_change = false;
David Linee3fe402017-03-13 10:00:42 -07004161 unsigned int bit_width;
4162 unsigned int sample_rate;
4163 unsigned int channels;
David Linee3fe402017-03-13 10:00:42 -07004164 int backend_idx = DEFAULT_CODEC_BACKEND;
Haynes Mathew George65f6b432018-02-27 17:44:55 -08004165 unsigned long service_interval = 0; // 0 is invalid
David Linee3fe402017-03-13 10:00:42 -07004166 struct platform_data *my_data = (struct platform_data *)adev->platform;
David Linee3fe402017-03-13 10:00:42 -07004167
4168 if (snd_device == SND_DEVICE_OUT_BT_SCO ||
4169 snd_device == SND_DEVICE_OUT_BT_SCO_WB) {
4170 backend_change = false;
4171 return backend_change;
4172 }
4173
4174 backend_idx = platform_get_backend_index(snd_device);
4175 bit_width = backend_cfg->bit_width;
4176 sample_rate = backend_cfg->sample_rate;
4177 channels = backend_cfg->channels;
4178
4179 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
4180 ", backend_idx %d usecase = %d device (%s)", __func__, bit_width,
4181 sample_rate, channels, backend_idx, usecase->id,
4182 platform_get_snd_device_name(snd_device));
4183
4184 if (backend_idx == platform_get_voice_call_backend(adev)) {
4185 ALOGW("%s:becf: afe:Use default bw and sr for voice/voip calls ",
4186 __func__);
4187 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
4188 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4189 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
4190 } else {
4191 /*
4192 * The backend should be configured at highest bit width and/or
4193 * sample rate amongst all playback usecases.
4194 * If the selected sample rate and/or bit width differ with
4195 * current backend sample rate and/or bit width, then, we set the
4196 * backend re-configuration flag.
4197 *
4198 * Exception: 16 bit playbacks is allowed through 16 bit/48/44.1 khz backend only
4199 */
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004200 pick_playback_cfg_for_uc(adev, usecase, snd_device,
4201 &bit_width,
4202 &sample_rate,
4203 &channels);
David Linee3fe402017-03-13 10:00:42 -07004204 }
4205
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004206 switch (backend_idx) {
4207 case USB_AUDIO_RX_BACKEND:
4208 audio_extn_usb_is_config_supported(&bit_width,
4209 &sample_rate, &channels, true);
Haynes Mathew George65f6b432018-02-27 17:44:55 -08004210 if (platform_get_usb_service_interval(adev->platform, true,
4211 &service_interval) == 0) {
4212 /* overwrite with best altset for this service interval */
4213 int ret =
4214 audio_extn_usb_altset_for_service_interval(true /*playback*/,
4215 service_interval,
4216 &bit_width,
4217 &sample_rate,
4218 &channels);
4219 if (ret < 0) {
4220 ALOGE("Failed to find altset for service interval %lu, skip reconfig",
4221 service_interval);
4222 return false;
4223 }
4224 }
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004225 ALOGV("%s: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
4226 __func__, bit_width, sample_rate, channels);
4227 break;
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004228 case HEADPHONE_BACKEND:
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004229 headset_is_config_supported(&bit_width, &sample_rate, &channels);
4230 break;
4231 case DEFAULT_CODEC_BACKEND:
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004232 default:
4233 bit_width = platform_get_snd_device_bit_width(snd_device);
4234 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4235 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
4236 break;
David Linee3fe402017-03-13 10:00:42 -07004237 }
4238
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004239 ALOGV("%s:becf: afe: Codec selected backend: %d updated bit width: %d and"
4240 "sample rate: %d",
David Linee3fe402017-03-13 10:00:42 -07004241 __func__, backend_idx , bit_width, sample_rate);
4242
4243 // Force routing if the expected bitwdith or samplerate
4244 // is not same as current backend comfiguration
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004245 if (bit_width != my_data->current_backend_cfg[backend_idx].bit_width ||
4246 sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate ||
4247 channels != my_data->current_backend_cfg[backend_idx].channels) {
David Linee3fe402017-03-13 10:00:42 -07004248 backend_cfg->bit_width = bit_width;
4249 backend_cfg->sample_rate = sample_rate;
4250 backend_cfg->channels = channels;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004251 backend_cfg->passthrough_enabled = false;
David Linee3fe402017-03-13 10:00:42 -07004252 backend_change = true;
4253 ALOGV("%s:becf: afe: Codec backend needs to be updated. new bit width: %d"
4254 "new sample rate: %d new channels: %d",
4255 __func__, backend_cfg->bit_width, backend_cfg->sample_rate, backend_cfg->channels);
4256 }
4257
4258 return backend_change;
4259}
4260
4261bool platform_check_and_set_playback_backend_cfg(struct audio_device* adev,
4262 struct audio_usecase *usecase, snd_device_t snd_device)
4263{
4264 int backend_idx = DEFAULT_CODEC_BACKEND;
4265 int new_snd_devices[SND_DEVICE_OUT_END];
4266 int i, num_devices = 1;
4267 bool ret = false;
4268 struct platform_data *my_data = (struct platform_data *)adev->platform;
4269 struct audio_backend_cfg backend_cfg;
4270
4271 backend_idx = platform_get_backend_index(snd_device);
4272
4273 backend_cfg.bit_width = pcm_format_to_bits(usecase->stream.out->config.format);
4274 backend_cfg.sample_rate = usecase->stream.out->sample_rate;
4275 backend_cfg.format = usecase->stream.out->format;
4276 backend_cfg.channels = audio_channel_count_from_out_mask(usecase->stream.out->channel_mask);
4277 /*this is populated by check_codec_backend_cfg hence set default value to false*/
4278 backend_cfg.passthrough_enabled = false;
4279
4280 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
4281 ", backend_idx %d usecase = %d device (%s)", __func__, backend_cfg.bit_width,
4282 backend_cfg.sample_rate, backend_cfg.channels, backend_idx, usecase->id,
4283 platform_get_snd_device_name(snd_device));
4284
4285 if (platform_can_split_snd_device(snd_device, &num_devices, new_snd_devices) < 0)
4286 new_snd_devices[0] = snd_device;
4287
4288 for (i = 0; i < num_devices; i++) {
4289 ALOGV("%s: new_snd_devices[%d] is %d", __func__, i, new_snd_devices[i]);
4290 if ((platform_check_playback_backend_cfg(adev, usecase, new_snd_devices[i],
4291 &backend_cfg))) {
4292 platform_set_backend_cfg(adev, new_snd_devices[i],
4293 &backend_cfg);
4294 ret = true;
4295 }
4296 }
4297 return ret;
4298}
4299
4300bool platform_check_and_set_capture_backend_cfg(struct audio_device* adev,
4301 struct audio_usecase *usecase, snd_device_t snd_device)
4302{
4303 int backend_idx = platform_get_backend_index(snd_device);
4304 int ret = 0;
4305 struct audio_backend_cfg backend_cfg;
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004306 memset(&backend_cfg, 0, sizeof(struct audio_backend_cfg));
David Linee3fe402017-03-13 10:00:42 -07004307
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004308 if (usecase->type == PCM_CAPTURE) {
4309 backend_cfg.format = usecase->stream.in->format;
David Linee3fe402017-03-13 10:00:42 -07004310 backend_cfg.channels = audio_channel_count_from_in_mask(usecase->stream.in->channel_mask);
4311 } else {
4312 backend_cfg.bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
4313 backend_cfg.sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4314 backend_cfg.format = AUDIO_FORMAT_PCM_16_BIT;
4315 backend_cfg.channels = 1;
4316 }
4317
4318 ALOGV("%s:txbecf: afe: bitwidth %d, samplerate %d, channel %d"
4319 ", backend_idx %d usecase = %d device (%s)", __func__,
4320 backend_cfg.bit_width,
4321 backend_cfg.sample_rate,
4322 backend_cfg.channels,
4323 backend_idx, usecase->id,
4324 platform_get_snd_device_name(snd_device));
4325
4326 if (platform_check_capture_backend_cfg(adev, backend_idx, &backend_cfg)) {
4327 ret = platform_set_backend_cfg(adev, snd_device,
4328 &backend_cfg);
4329 if(!ret)
4330 return true;
4331 }
4332
4333 return false;
4334}
4335
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004336static int max_be_dai_names = 0;
4337static const struct be_dai_name_struct *be_dai_name_table;
4338
4339/*
4340 * Retrieves the be_dai_name_table from kernel to enable a mapping
4341 * between sound device hw interfaces and backend IDs. This allows HAL to
4342 * specify the backend a specific calibration is needed for.
4343 */
4344static int init_be_dai_name_table(struct audio_device *adev)
4345{
4346 const char *mixer_ctl_name = "Backend DAI Name Table";
4347 struct mixer_ctl *ctl;
4348 int i, j, ret, size;
4349 bool valid_hw_interface;
4350
4351 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
4352 if (!ctl) {
4353 ALOGE("%s: Could not get ctl for mixer name %s\n",
4354 __func__, mixer_ctl_name);
4355 ret = -EINVAL;
4356 goto done;
4357 }
4358
4359 mixer_ctl_update(ctl);
4360
4361 size = mixer_ctl_get_num_values(ctl);
4362 if (size <= 0){
4363 ALOGE("%s: Failed to get %s size %d\n",
4364 __func__, mixer_ctl_name, size);
4365 ret = -EFAULT;
4366 goto done;
4367 }
4368
vivek mehtaa68fea62017-06-08 19:04:02 -07004369 be_dai_name_table =
4370 (const struct be_dai_name_struct *)calloc(1, size);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004371 if (be_dai_name_table == NULL) {
4372 ALOGE("%s: Failed to allocate memory for %s\n",
4373 __func__, mixer_ctl_name);
4374 ret = -ENOMEM;
4375 goto freeMem;
4376 }
4377
4378 ret = mixer_ctl_get_array(ctl, (void *)be_dai_name_table, size);
4379 if (ret) {
4380 ALOGE("%s: Failed to get %s, ret %d\n",
4381 __func__, mixer_ctl_name, ret);
4382 ret = -EFAULT;
4383 goto freeMem;
4384 }
4385
4386 if (be_dai_name_table != NULL) {
4387 max_be_dai_names = size / sizeof(struct be_dai_name_struct);
4388 ALOGV("%s: Successfully got %s, number of be dais is %d\n",
4389 __func__, mixer_ctl_name, max_be_dai_names);
4390 ret = 0;
4391 } else {
4392 ALOGE("%s: Failed to get %s\n", __func__, mixer_ctl_name);
4393 ret = -EFAULT;
4394 goto freeMem;
4395 }
4396
4397 /*
4398 * Validate all sound devices have a valid backend set to catch
4399 * errors for uncommon sound devices
4400 */
4401 for (i = 0; i < SND_DEVICE_MAX; i++) {
4402 valid_hw_interface = false;
4403
4404 if (hw_interface_table[i] == NULL) {
4405 ALOGW("%s: sound device %s has no hw interface set\n",
4406 __func__, platform_get_snd_device_name(i));
4407 continue;
4408 }
4409
4410 for (j = 0; j < max_be_dai_names; j++) {
4411 if (strcmp(hw_interface_table[i], be_dai_name_table[j].be_name)
4412 == 0) {
4413 valid_hw_interface = true;
4414 break;
4415 }
4416 }
4417 if (!valid_hw_interface)
4418 ALOGD("%s: sound device %s does not have a valid hw interface set "
4419 "(disregard for combo devices) %s\n",
4420 __func__, platform_get_snd_device_name(i),
4421 hw_interface_table[i]);
4422 }
4423
4424 goto done;
4425
4426freeMem:
4427 if (be_dai_name_table) {
4428 free((void *)be_dai_name_table);
4429 be_dai_name_table = NULL;
4430 }
4431
4432done:
4433 return ret;
4434}
4435
4436int platform_get_snd_device_backend_index(snd_device_t device)
4437{
4438 int i, be_dai_id;
4439 const char * hw_interface_name = NULL;
4440
4441 ALOGV("%s: enter with device %d\n", __func__, device);
4442
vivek mehtaa68fea62017-06-08 19:04:02 -07004443 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004444 ALOGE("%s: Invalid snd_device = %d",
4445 __func__, device);
4446 be_dai_id = -EINVAL;
4447 goto done;
4448 }
4449
4450 /* Get string value of necessary backend for device */
4451 hw_interface_name = hw_interface_table[device];
4452 if (hw_interface_name == NULL) {
4453 ALOGE("%s: no hw_interface set for device %d\n", __func__, device);
4454 be_dai_id = -EINVAL;
4455 goto done;
4456 }
4457
4458 /* Check if be dai name table was retrieved successfully */
4459 if (be_dai_name_table == NULL) {
4460 ALOGE("%s: BE DAI Name Table is not present\n", __func__);
4461 be_dai_id = -EFAULT;
4462 goto done;
4463 }
4464
4465 /* Get backend ID for device specified */
4466 for (i = 0; i < max_be_dai_names; i++) {
4467 if (strcmp(hw_interface_name, be_dai_name_table[i].be_name) == 0) {
4468 be_dai_id = be_dai_name_table[i].be_id;
4469 goto done;
4470 }
4471 }
4472 ALOGE("%s: no interface matching name %s\n", __func__, hw_interface_name);
4473 be_dai_id = -EINVAL;
4474 goto done;
4475
4476done:
4477 return be_dai_id;
4478}
4479
4480void platform_check_and_update_copp_sample_rate(void* platform, snd_device_t snd_device,
4481 unsigned int stream_sr, int* sample_rate)
4482{
4483 struct platform_data* my_data = (struct platform_data *)platform;
4484 int backend_idx = platform_get_backend_index(snd_device);
4485 int device_sr = my_data->current_backend_cfg[backend_idx].sample_rate;
4486 /*
4487 *Check if device SR is multiple of 8K or 11.025 Khz
4488 *check if the stream SR is multiple of same base, if yes
4489 *then have copp SR equal to stream SR, this ensures that
4490 *post processing happens at stream SR, else have
4491 *copp SR equal to device SR.
4492 */
4493 if (!(((sample_rate_multiple(device_sr, SAMPLE_RATE_8000)) &&
4494 (sample_rate_multiple(stream_sr, SAMPLE_RATE_8000))) ||
4495 ((sample_rate_multiple(device_sr, SAMPLE_RATE_11025)) &&
4496 (sample_rate_multiple(stream_sr, SAMPLE_RATE_11025))))) {
4497 *sample_rate = device_sr;
4498 } else
4499 *sample_rate = stream_sr;
4500
4501 ALOGI("sn_device %d device sr %d stream sr %d copp sr %d", snd_device, device_sr, stream_sr
4502 , *sample_rate);
4503
4504}
4505
4506// called from info parser
vivek mehtaa68fea62017-06-08 19:04:02 -07004507void platform_add_app_type(const char *uc_type,
4508 const char *mode,
4509 int bw,
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004510 int app_type, int max_rate) {
4511 struct app_type_entry *ap =
4512 (struct app_type_entry *)calloc(1, sizeof(struct app_type_entry));
4513
4514 if (!ap) {
4515 ALOGE("%s failed to allocate mem for app type", __func__);
4516 return;
4517 }
4518
4519 ap->uc_type = -1;
4520 for (int i=0; i<USECASE_TYPE_MAX; i++) {
4521 if (!strcmp(uc_type, usecase_type_index[i].name)) {
4522 ap->uc_type = usecase_type_index[i].index;
4523 break;
4524 }
4525 }
4526
4527 if (ap->uc_type == -1) {
4528 free(ap);
4529 return;
4530 }
4531
vivek mehtaa68fea62017-06-08 19:04:02 -07004532 ALOGI("%s uc %s mode %s bw %d app_type %d max_rate %d",
4533 __func__, uc_type, mode, bw, app_type, max_rate);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004534 ap->bit_width = bw;
4535 ap->app_type = app_type;
4536 ap->max_rate = max_rate;
vivek mehtaa68fea62017-06-08 19:04:02 -07004537 ap->mode = strdup(mode);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004538 list_add_tail(&app_type_entry_list, &ap->node);
4539}
4540
4541
4542int platform_get_default_app_type_v2(void *platform __unused,
4543 usecase_type_t type,
4544 int *app_type )
4545{
4546 if (type == PCM_PLAYBACK)
4547 *app_type = DEFAULT_APP_TYPE_RX_PATH;
4548 else
4549 *app_type = DEFAULT_APP_TYPE_TX_PATH;
4550 return 0;
4551}
4552
vivek mehtaa68fea62017-06-08 19:04:02 -07004553int platform_get_app_type_v2(void *platform,
4554 usecase_type_t uc_type,
4555 const char *mode,
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004556 int bw, int sr __unused,
4557 int *app_type)
4558{
4559 struct listnode *node;
4560 struct app_type_entry *entry;
4561 *app_type = -1;
vivek mehtaa68fea62017-06-08 19:04:02 -07004562
4563 ALOGV("%s find match for uc %d mode %s bw %d rate %d",
4564 __func__, uc_type, mode, bw, sr);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004565 list_for_each(node, &app_type_entry_list) {
4566 entry = node_to_item(node, struct app_type_entry, node);
vivek mehtaa68fea62017-06-08 19:04:02 -07004567 ALOGV("%s uc %d mode %s bw %d app_type %d max_rate %d",
4568 __func__, entry->uc_type, entry->mode, entry->bit_width,
4569 entry->app_type, entry->max_rate);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004570 if (entry->bit_width == bw &&
vivek mehtaa68fea62017-06-08 19:04:02 -07004571 entry->uc_type == uc_type &&
4572 sr <= entry->max_rate &&
4573 entry->mode && !strcmp(mode, entry->mode)) {
4574 ALOGV("%s found match %d", __func__, entry->app_type);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004575 *app_type = entry->app_type;
4576 break;
4577 }
4578 }
4579
4580 if (*app_type == -1) {
vivek mehtaa68fea62017-06-08 19:04:02 -07004581 ALOGV("%s no match found, return default", __func__);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004582 return platform_get_default_app_type_v2(platform, uc_type, app_type);
4583 }
4584 return 0;
4585}
vivek mehta90933872017-06-15 18:04:39 -07004586
4587int platform_set_sidetone(struct audio_device *adev,
4588 snd_device_t out_snd_device,
4589 bool enable, char *str)
4590{
4591 int ret;
4592 if (out_snd_device == SND_DEVICE_OUT_USB_HEADSET ||
4593 out_snd_device == SND_DEVICE_OUT_VOICE_USB_HEADSET) {
4594 ret = audio_extn_usb_enable_sidetone(out_snd_device, enable);
4595 if (ret)
4596 ALOGI("%s: usb device %d does not support device sidetone\n",
4597 __func__, out_snd_device);
4598 } else {
4599 ALOGV("%s: sidetone out device(%d) mixer cmd = %s\n",
4600 __func__, out_snd_device, str);
4601 if (enable)
4602 audio_route_apply_and_update_path(adev->audio_route, str);
4603 else
4604 audio_route_reset_and_update_path(adev->audio_route, str);
4605 }
4606 return 0;
4607}
Haynes Mathew George96483a22017-03-28 14:52:47 -07004608
4609int platform_get_mmap_data_fd(void *platform __unused, int fe_dev __unused, int dir __unused,
4610 int *fd __unused, uint32_t *size __unused)
4611{
Thierry Strudel07f96d12018-09-20 13:31:34 -07004612#if defined (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845) || (PLATFORM_SDM710) || (PLATFORM_SM8150)
Haynes Mathew George96483a22017-03-28 14:52:47 -07004613 struct platform_data *my_data = (struct platform_data *)platform;
4614 struct audio_device *adev = my_data->adev;
4615 int hw_fd = -1;
4616 char dev_name[128];
4617 struct snd_pcm_mmap_fd mmap_fd;
4618 memset(&mmap_fd, 0, sizeof(mmap_fd));
4619 mmap_fd.dir = dir;
4620 snprintf(dev_name, sizeof(dev_name), "/dev/snd/hwC%uD%u",
4621 adev->snd_card, HWDEP_FE_BASE+fe_dev);
4622 hw_fd = open(dev_name, O_RDONLY);
4623 if (hw_fd < 0) {
4624 ALOGE("fe hw dep node open %d/%d failed", adev->snd_card, fe_dev);
4625 return -1;
4626 }
4627 if (ioctl(hw_fd, SNDRV_PCM_IOCTL_MMAP_DATA_FD, &mmap_fd) < 0) {
4628 ALOGE("fe hw dep node ioctl failed");
4629 close(hw_fd);
4630 return -1;
4631 }
4632 *fd = mmap_fd.fd;
4633 *size = mmap_fd.size;
4634 close(hw_fd); // mmap_fd should still be valid
4635 return 0;
4636#else
4637 return -1;
4638#endif
4639}
Mikhail Naganov4ee6e3e2018-03-21 16:28:35 +00004640
4641bool platform_sound_trigger_usecase_needs_event(audio_usecase_t uc_id)
4642{
4643 bool needs_event = false;
4644
4645 switch (uc_id) {
4646 /* concurrent capture usecases which needs event */
4647 case USECASE_AUDIO_RECORD:
4648 case USECASE_AUDIO_RECORD_LOW_LATENCY:
4649 case USECASE_AUDIO_RECORD_MMAP:
4650 case USECASE_AUDIO_RECORD_HIFI:
4651 case USECASE_AUDIO_RECORD_VOIP:
4652 case USECASE_VOICEMMODE1_CALL:
4653 case USECASE_VOICEMMODE2_CALL:
4654 /* concurrent playback usecases that needs event */
4655 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
4656 case USECASE_AUDIO_PLAYBACK_OFFLOAD:
4657 needs_event = true;
4658 break;
4659 default:
4660 ALOGV("%s:usecase_id[%d] no need to raise event.", __func__, uc_id);
4661 }
4662 return needs_event;
4663}
4664
4665bool platform_snd_device_has_speaker(snd_device_t dev) {
4666 int num_devs = 2;
4667 snd_device_t split_devs[2] = {SND_DEVICE_NONE, SND_DEVICE_NONE};
4668 if (platform_can_split_snd_device(dev, &num_devs, split_devs) == 0) {
4669 return platform_snd_device_has_speaker(split_devs[0]) ||
4670 platform_snd_device_has_speaker(split_devs[1]);
4671 }
4672
4673 switch (dev) {
4674 case SND_DEVICE_OUT_SPEAKER:
4675 case SND_DEVICE_OUT_SPEAKER_SAFE:
4676 case SND_DEVICE_OUT_SPEAKER_REVERSE:
4677 case SND_DEVICE_OUT_SPEAKER_PROTECTED:
4678 case SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED:
4679 case SND_DEVICE_OUT_VOICE_SPEAKER_HFP:
4680 return true;
4681 default:
4682 break;
4683 }
4684 return false;
4685}
jiabin8962a4d2018-03-19 18:21:24 -07004686
4687bool platform_set_microphone_characteristic(void *platform,
4688 struct audio_microphone_characteristic_t mic) {
4689 struct platform_data *my_data = (struct platform_data *)platform;
4690 if (my_data->declared_mic_count >= AUDIO_MICROPHONE_MAX_COUNT) {
4691 ALOGE("mic number is more than maximum number");
4692 return false;
4693 }
4694 for (size_t ch = 0; ch < AUDIO_CHANNEL_COUNT_MAX; ch++) {
4695 mic.channel_mapping[ch] = AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED;
4696 }
4697 my_data->microphones[my_data->declared_mic_count++] = mic;
4698 return true;
4699}
4700
4701int platform_get_microphones(void *platform,
4702 struct audio_microphone_characteristic_t *mic_array,
4703 size_t *mic_count) {
4704 struct platform_data *my_data = (struct platform_data *)platform;
4705 if (mic_count == NULL) {
4706 return -EINVAL;
4707 }
4708 if (mic_array == NULL) {
4709 return -EINVAL;
4710 }
4711
4712 if (*mic_count == 0) {
4713 *mic_count = my_data->declared_mic_count;
4714 return 0;
4715 }
4716
4717 size_t max_mic_count = *mic_count;
4718 size_t actual_mic_count = 0;
4719 for (size_t i = 0; i < max_mic_count && i < my_data->declared_mic_count; i++) {
4720 mic_array[i] = my_data->microphones[i];
4721 actual_mic_count++;
4722 }
4723 *mic_count = actual_mic_count;
4724 return 0;
4725}
4726
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004727bool platform_set_microphone_map(void *platform, snd_device_t in_snd_device,
4728 const struct mic_info *info) {
4729 struct platform_data *my_data = (struct platform_data *)platform;
4730 if (in_snd_device < SND_DEVICE_IN_BEGIN || in_snd_device >= SND_DEVICE_IN_END) {
4731 ALOGE("%s: Sound device not valid", __func__);
4732 return false;
4733 }
4734 size_t m_count = my_data->mic_map[in_snd_device].mic_count++;
4735 if (m_count >= AUDIO_MICROPHONE_MAX_COUNT) {
4736 ALOGE("%s: Microphone count is greater than max allowed value", __func__);
4737 my_data->mic_map[in_snd_device].mic_count--;
4738 return false;
4739 }
4740 my_data->mic_map[in_snd_device].microphones[m_count] = *info;
4741 return true;
4742}
4743
4744int platform_get_active_microphones(void *platform, unsigned int channels,
4745 audio_usecase_t uc_id,
jiabin8962a4d2018-03-19 18:21:24 -07004746 struct audio_microphone_characteristic_t *mic_array,
4747 size_t *mic_count) {
4748 struct platform_data *my_data = (struct platform_data *)platform;
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004749 struct audio_usecase *usecase = get_usecase_from_list(my_data->adev, uc_id);
4750 if (mic_count == NULL || mic_array == NULL || usecase == NULL) {
jiabin8962a4d2018-03-19 18:21:24 -07004751 return -EINVAL;
4752 }
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004753 size_t max_mic_count = my_data->declared_mic_count;
jiabin8962a4d2018-03-19 18:21:24 -07004754 size_t actual_mic_count = 0;
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004755
4756 snd_device_t active_input_snd_device =
Eric Laurentd1b7a9b2018-11-15 12:24:31 -08004757 platform_get_input_snd_device(platform, usecase->stream.in, AUDIO_DEVICE_NONE);
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004758 if (active_input_snd_device == SND_DEVICE_NONE) {
4759 ALOGI("%s: No active microphones found", __func__);
4760 goto end;
4761 }
4762
4763 size_t active_mic_count = my_data->mic_map[active_input_snd_device].mic_count;
4764 struct mic_info *m_info = my_data->mic_map[active_input_snd_device].microphones;
4765
4766 for (size_t i = 0; i < active_mic_count; i++) {
4767 unsigned int channels_for_active_mic = channels;
4768 if (channels_for_active_mic > m_info[i].channel_count) {
4769 channels_for_active_mic = m_info[i].channel_count;
4770 }
4771 for (size_t j = 0; j < max_mic_count; j++) {
4772 if (strcmp(my_data->microphones[j].device_id,
4773 m_info[i].device_id) == 0) {
4774 mic_array[actual_mic_count] = my_data->microphones[j];
4775 for (size_t ch = 0; ch < channels_for_active_mic; ch++) {
4776 mic_array[actual_mic_count].channel_mapping[ch] =
4777 m_info[i].channel_mapping[ch];
4778 }
4779 actual_mic_count++;
4780 break;
jiabin8962a4d2018-03-19 18:21:24 -07004781 }
jiabin8962a4d2018-03-19 18:21:24 -07004782 }
4783 }
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004784end:
jiabin8962a4d2018-03-19 18:21:24 -07004785 *mic_count = actual_mic_count;
4786 return 0;
4787}
Haynes Mathew George65f6b432018-02-27 17:44:55 -08004788
4789int platform_set_usb_service_interval(void *platform,
4790 bool playback,
4791 unsigned long service_interval,
4792 bool *reconfig)
4793{
4794#if defined (USB_SERVICE_INTERVAL_ENABLED)
4795 struct platform_data *_platform = (struct platform_data *)platform;
4796 *reconfig = false;
4797 if (!playback) {
4798 ALOGE("%s not valid for capture", __func__);
4799 return -1;
4800 }
4801 const char *ctl_name = "USB_AUDIO_RX service_interval";
4802 struct mixer_ctl *ctl = mixer_get_ctl_by_name(_platform->adev->mixer,
4803 ctl_name);
4804 if (!ctl) {
4805 ALOGV("%s: could not get mixer %s", __func__, ctl_name);
4806 return -1;
4807 }
4808 if (mixer_ctl_get_value(ctl, 0) != (int)service_interval) {
4809 mixer_ctl_set_value(ctl, 0, service_interval);
4810 *reconfig = true;
4811 }
4812 return 0;
4813#else
4814 *reconfig = false;
4815 (void)platform;
4816 (void)playback;
4817 (void)service_interval;
4818 return -1;
4819#endif
4820}
4821
4822int platform_get_usb_service_interval(void *platform,
4823 bool playback,
4824 unsigned long *service_interval)
4825{
4826#if defined (USB_SERVICE_INTERVAL_ENABLED)
4827 struct platform_data *_platform = (struct platform_data *)platform;
4828 if (!playback) {
4829 ALOGE("%s not valid for capture", __func__);
4830 return -1;
4831 }
4832 const char *ctl_name = "USB_AUDIO_RX service_interval";
4833 struct mixer_ctl *ctl = mixer_get_ctl_by_name(_platform->adev->mixer,
4834 ctl_name);
4835 if (!ctl) {
4836 ALOGV("%s: could not get mixer %s", __func__, ctl_name);
4837 return -1;
4838 }
4839 *service_interval = mixer_ctl_get_value(ctl, 0);
4840 return 0;
4841#else
4842 (void)platform;
4843 (void)playback;
4844 (void)service_interval;
4845 return -1;
4846#endif
4847}
Ashish Jain1c849702018-05-11 20:11:55 +05304848
4849int platform_set_acdb_metainfo_key(void *platform __unused,
4850 char *name __unused,
4851 int key __unused)
4852{
4853 return -ENOSYS;
4854}