blob: 6991a12e934dd1cc4d4da1037fc140c0ef2fdd8f [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)) {
918 cal.snd_dev_id = platform_get_input_snd_device(platform, cal.dev_id);
919 } else {
920 cal.snd_dev_id = platform_get_output_snd_device(platform, cal.dev_id);
921 }
922 }
923 cal.acdb_dev_id = platform_get_snd_device_acdb_id(cal.snd_dev_id);
924 ALOGD("Setting audio calibration for snd_device(%d) acdb_id(%d)",
925 cal.snd_dev_id, cal.acdb_dev_id);
926 if (cal.acdb_dev_id == -EINVAL) {
927 ALOGE("[%s] Invalid acdb_device id %d for snd device id %d",
928 __func__, cal.acdb_dev_id, cal.snd_dev_id);
929 goto done_key_audcal;
930 }
931 if (my_data->acdb_set_audio_cal) {
932 ret = my_data->acdb_set_audio_cal((void *)&cal, (void *)dptr, dlen);
933 }
934 }
935done_key_audcal:
936 if (dptr != NULL)
937 free(dptr);
938}
939
vivek mehta1a9b7c02015-06-25 11:49:38 -0700940bool platform_send_gain_dep_cal(void *platform, int level)
941{
942 bool ret_val = false;
943 struct platform_data *my_data = (struct platform_data *)platform;
944 struct audio_device *adev = my_data->adev;
945 int acdb_dev_id, app_type;
946 int acdb_dev_type = MSM_SNDDEV_CAP_RX;
947 int mode = CAL_MODE_RTAC;
948 struct listnode *node;
949 struct audio_usecase *usecase;
Haynes Mathew George67486e22017-06-26 12:58:38 -0700950 bool valid_uc_type;
951 bool valid_dev;
vivek mehta1a9b7c02015-06-25 11:49:38 -0700952
953 if (my_data->acdb_send_gain_dep_cal == NULL) {
954 ALOGE("%s: dlsym error for acdb_send_gain_dep_cal", __func__);
955 return ret_val;
956 }
957
958 if (!voice_is_in_call(adev)) {
959 ALOGV("%s: Not Voice call usecase, apply new cal for level %d",
960 __func__, level);
vivek mehta1a9b7c02015-06-25 11:49:38 -0700961
962 // find the current active sound device
963 list_for_each(node, &adev->usecase_list) {
964 usecase = node_to_item(node, struct audio_usecase, list);
Haynes Mathew George67486e22017-06-26 12:58:38 -0700965 LOG_ALWAYS_FATAL_IF(usecase == NULL,
966 "unxpected NULL usecase in usecase_list");
967 valid_uc_type = usecase->type == PCM_PLAYBACK;
968 valid_dev = false;
969 if (valid_uc_type) {
970 audio_devices_t dev = usecase->stream.out->devices;
971 valid_dev = (dev == AUDIO_DEVICE_OUT_SPEAKER ||
vivek mehta40125092017-08-21 18:48:51 -0700972 dev == AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Haynes Mathew George67486e22017-06-26 12:58:38 -0700973 dev == AUDIO_DEVICE_OUT_WIRED_HEADSET ||
974 dev == AUDIO_DEVICE_OUT_WIRED_HEADPHONE);
975 }
976 if (valid_dev) {
vivek mehta40125092017-08-21 18:48:51 -0700977 ALOGV("%s: out device is %d", __func__, usecase->out_snd_device);
978 if (platform_supports_app_type_cfg())
979 app_type = usecase->stream.out->app_type_cfg.app_type;
980 else
981 app_type = DEFAULT_APP_TYPE_RX_PATH;
vivek mehta4cb82982015-07-13 12:05:49 -0700982
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -0700983 acdb_dev_id = platform_get_snd_device_acdb_id(usecase->out_snd_device);
vivek mehta40125092017-08-21 18:48:51 -0700984
985 if (!my_data->acdb_send_gain_dep_cal(acdb_dev_id, app_type,
vivek mehta1a9b7c02015-06-25 11:49:38 -0700986 acdb_dev_type, mode, level)) {
987 // set ret_val true if at least one calibration is set successfully
988 ret_val = true;
989 } else {
990 ALOGE("%s: my_data->acdb_send_gain_dep_cal failed ", __func__);
991 }
992 } else {
993 ALOGW("%s: Usecase list is empty", __func__);
994 }
995 }
996 } else {
997 ALOGW("%s: Voice call in progress .. ignore setting new cal",
998 __func__);
999 }
1000 return ret_val;
1001}
1002
Eric Laurentcefbbac2014-09-04 13:54:10 -05001003void platform_set_echo_reference(struct audio_device *adev, bool enable, audio_devices_t out_device)
Eric Laurentb23d5282013-05-14 15:27:20 -07001004{
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08001005 struct platform_data *my_data = (struct platform_data *)adev->platform;
Eric Laurentcefbbac2014-09-04 13:54:10 -05001006 snd_device_t snd_device = SND_DEVICE_NONE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001007
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08001008 if (strcmp(my_data->ec_ref_mixer_path, "")) {
1009 ALOGV("%s: diabling %s", __func__, my_data->ec_ref_mixer_path);
1010 audio_route_reset_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
Eric Laurentcefbbac2014-09-04 13:54:10 -05001011 }
1012
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08001013 if (enable) {
1014 strcpy(my_data->ec_ref_mixer_path, "echo-reference");
1015 if (out_device != AUDIO_DEVICE_NONE) {
1016 snd_device = platform_get_output_snd_device(adev->platform, out_device);
1017 platform_add_backend_name(adev->platform, my_data->ec_ref_mixer_path, snd_device);
1018 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05001019
Joe Onorato188b6222016-03-01 11:02:27 -08001020 ALOGV("%s: enabling %s", __func__, my_data->ec_ref_mixer_path);
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08001021 audio_route_apply_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
1022 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001023}
1024
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001025static struct csd_data *open_csd_client(bool i2s_ext_modem)
1026{
1027 struct csd_data *csd = calloc(1, sizeof(struct csd_data));
1028
1029 csd->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
1030 if (csd->csd_client == NULL) {
1031 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
1032 goto error;
1033 } else {
1034 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
1035
1036 csd->deinit = (deinit_t)dlsym(csd->csd_client,
1037 "csd_client_deinit");
1038 if (csd->deinit == NULL) {
1039 ALOGE("%s: dlsym error %s for csd_client_deinit", __func__,
1040 dlerror());
1041 goto error;
1042 }
1043 csd->disable_device = (disable_device_t)dlsym(csd->csd_client,
1044 "csd_client_disable_device");
1045 if (csd->disable_device == NULL) {
1046 ALOGE("%s: dlsym error %s for csd_client_disable_device",
1047 __func__, dlerror());
1048 goto error;
1049 }
1050 csd->enable_device_config = (enable_device_config_t)dlsym(csd->csd_client,
1051 "csd_client_enable_device_config");
1052 if (csd->enable_device_config == NULL) {
1053 ALOGE("%s: dlsym error %s for csd_client_enable_device_config",
1054 __func__, dlerror());
1055 goto error;
1056 }
1057 csd->enable_device = (enable_device_t)dlsym(csd->csd_client,
1058 "csd_client_enable_device");
1059 if (csd->enable_device == NULL) {
1060 ALOGE("%s: dlsym error %s for csd_client_enable_device",
1061 __func__, dlerror());
1062 goto error;
1063 }
1064 csd->start_voice = (start_voice_t)dlsym(csd->csd_client,
1065 "csd_client_start_voice");
1066 if (csd->start_voice == NULL) {
1067 ALOGE("%s: dlsym error %s for csd_client_start_voice",
1068 __func__, dlerror());
1069 goto error;
1070 }
1071 csd->stop_voice = (stop_voice_t)dlsym(csd->csd_client,
1072 "csd_client_stop_voice");
1073 if (csd->stop_voice == NULL) {
1074 ALOGE("%s: dlsym error %s for csd_client_stop_voice",
1075 __func__, dlerror());
1076 goto error;
1077 }
1078 csd->volume = (volume_t)dlsym(csd->csd_client,
1079 "csd_client_volume");
1080 if (csd->volume == NULL) {
1081 ALOGE("%s: dlsym error %s for csd_client_volume",
1082 __func__, dlerror());
1083 goto error;
1084 }
1085 csd->mic_mute = (mic_mute_t)dlsym(csd->csd_client,
1086 "csd_client_mic_mute");
1087 if (csd->mic_mute == NULL) {
1088 ALOGE("%s: dlsym error %s for csd_client_mic_mute",
1089 __func__, dlerror());
1090 goto error;
1091 }
1092 csd->slow_talk = (slow_talk_t)dlsym(csd->csd_client,
1093 "csd_client_slow_talk");
1094 if (csd->slow_talk == NULL) {
1095 ALOGE("%s: dlsym error %s for csd_client_slow_talk",
1096 __func__, dlerror());
1097 goto error;
1098 }
1099 csd->start_playback = (start_playback_t)dlsym(csd->csd_client,
1100 "csd_client_start_playback");
1101 if (csd->start_playback == NULL) {
1102 ALOGE("%s: dlsym error %s for csd_client_start_playback",
1103 __func__, dlerror());
1104 goto error;
1105 }
1106 csd->stop_playback = (stop_playback_t)dlsym(csd->csd_client,
1107 "csd_client_stop_playback");
1108 if (csd->stop_playback == NULL) {
1109 ALOGE("%s: dlsym error %s for csd_client_stop_playback",
1110 __func__, dlerror());
1111 goto error;
1112 }
1113 csd->start_record = (start_record_t)dlsym(csd->csd_client,
1114 "csd_client_start_record");
1115 if (csd->start_record == NULL) {
1116 ALOGE("%s: dlsym error %s for csd_client_start_record",
1117 __func__, dlerror());
1118 goto error;
1119 }
1120 csd->stop_record = (stop_record_t)dlsym(csd->csd_client,
1121 "csd_client_stop_record");
1122 if (csd->stop_record == NULL) {
1123 ALOGE("%s: dlsym error %s for csd_client_stop_record",
1124 __func__, dlerror());
1125 goto error;
1126 }
1127
1128 csd->get_sample_rate = (get_sample_rate_t)dlsym(csd->csd_client,
1129 "csd_client_get_sample_rate");
1130 if (csd->get_sample_rate == NULL) {
1131 ALOGE("%s: dlsym error %s for csd_client_get_sample_rate",
1132 __func__, dlerror());
1133
1134 goto error;
1135 }
1136
1137 csd->init = (init_t)dlsym(csd->csd_client, "csd_client_init");
1138
1139 if (csd->init == NULL) {
1140 ALOGE("%s: dlsym error %s for csd_client_init",
1141 __func__, dlerror());
1142 goto error;
1143 } else {
1144 csd->init(i2s_ext_modem);
1145 }
1146 }
1147 return csd;
1148
1149error:
1150 free(csd);
1151 csd = NULL;
1152 return csd;
1153}
1154
1155void close_csd_client(struct csd_data *csd)
1156{
1157 if (csd != NULL) {
1158 csd->deinit();
1159 dlclose(csd->csd_client);
1160 free(csd);
1161 csd = NULL;
1162 }
1163}
1164
1165static void platform_csd_init(struct platform_data *my_data)
1166{
1167#ifdef PLATFORM_MSM8084
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001168 int32_t modems, (*count_modems)(void);
1169 const char *name = "libdetectmodem.so";
1170 const char *func = "count_modems";
1171 const char *error;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001172
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001173 my_data->csd = NULL;
1174
1175 void *lib = dlopen(name, RTLD_NOW);
1176 error = dlerror();
1177 if (!lib) {
1178 ALOGE("%s: could not find %s: %s", __func__, name, error);
1179 return;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001180 }
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001181
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001182 count_modems = NULL;
1183 *(void **)(&count_modems) = dlsym(lib, func);
1184 error = dlerror();
1185 if (!count_modems) {
1186 ALOGE("%s: could not find symbol %s in %s: %s",
1187 __func__, func, name, error);
1188 goto done;
1189 }
1190
1191 modems = count_modems();
1192 if (modems < 0) {
1193 ALOGE("%s: count_modems failed\n", __func__);
1194 goto done;
1195 }
1196
Eric Laurent2bafff12016-03-17 12:17:23 -07001197 ALOGD("%s: num_modems %d\n", __func__, modems);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001198 if (modems > 0)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001199 my_data->csd = open_csd_client(false /*is_i2s_ext_modem*/);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001200
1201done:
1202 dlclose(lib);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001203#else
1204 my_data->csd = NULL;
1205#endif
1206}
1207
Eric Laurentc6333382015-09-14 12:43:44 -07001208static void set_platform_defaults(struct platform_data * my_data)
Haynes Mathew George98c95622014-06-20 19:14:25 -07001209{
1210 int32_t dev;
1211 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001212 backend_tag_table[dev] = NULL;
1213 hw_interface_table[dev] = NULL;
keunhui.park2f7306a2015-07-16 16:48:06 +09001214 operator_specific_device_table[dev] = NULL;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001215 }
1216
David Linee3fe402017-03-13 10:00:42 -07001217 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1218 backend_bit_width_table[dev] = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
1219 }
1220
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001221 // To overwrite these go to the audio_platform_info.xml file.
1222 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("bt-sco");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07001223 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("bt-sco");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001224 backend_tag_table[SND_DEVICE_OUT_BT_SCO] = strdup("bt-sco");
1225 backend_tag_table[SND_DEVICE_OUT_HDMI] = strdup("hdmi");
1226 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("speaker-and-hdmi");
1227 backend_tag_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("bt-sco-wb");
1228 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("bt-sco-wb");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07001229 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("bt-sco-wb");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001230 backend_tag_table[SND_DEVICE_OUT_VOICE_TX] = strdup("afe-proxy");
1231 backend_tag_table[SND_DEVICE_IN_VOICE_RX] = strdup("afe-proxy");
Haynes Mathew George98c95622014-06-20 19:14:25 -07001232
David Linee3fe402017-03-13 10:00:42 -07001233 backend_tag_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("usb-headset");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001234 backend_tag_table[SND_DEVICE_OUT_VOICE_USB_HEADSET] = strdup("usb-headset");
David Linee3fe402017-03-13 10:00:42 -07001235 backend_tag_table[SND_DEVICE_OUT_USB_HEADPHONES] = strdup("usb-headphones");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001236 backend_tag_table[SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = strdup("usb-headphones");
David Linee3fe402017-03-13 10:00:42 -07001237 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] =
1238 strdup("speaker-and-usb-headphones");
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07001239 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] =
1240 strdup("speaker-safe-and-usb-headphones");
juyuchen5351ea62018-05-16 10:54:37 +08001241 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO] =
1242 strdup("speaker-safe-and-bt-sco"),
1243 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB] =
1244 strdup("speaker-safe-and-bt-sco-wb"),
David Linee3fe402017-03-13 10:00:42 -07001245 backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("usb-headset-mic");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001246 backend_tag_table[SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1247 backend_tag_table[SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1248 backend_tag_table[SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1249 backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = strdup("usb-headset-mic");
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001250 backend_tag_table[SND_DEVICE_OUT_BT_A2DP] = strdup("bt-a2dp");
1251 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] = strdup("speaker-and-bt-a2dp");
Aniket Kumar Lata9723a962018-05-16 17:41:55 -07001252 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP] = strdup("speaker-safe-and-bt-a2dp");
jasmine cha270b7762018-03-30 15:41:33 +08001253 backend_tag_table[SND_DEVICE_OUT_USB_HEADSET_SPEC] = strdup("usb-headset");
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001254
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001255 hw_interface_table[SND_DEVICE_OUT_HANDSET] = strdup("SLIMBUS_0_RX");
1256 hw_interface_table[SND_DEVICE_OUT_SPEAKER] = strdup("SLIMBUS_0_RX");
1257 hw_interface_table[SND_DEVICE_OUT_SPEAKER_REVERSE] = strdup("SLIMBUS_0_RX");
1258 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE] = strdup("SLIMBUS_0_RX");
1259 hw_interface_table[SND_DEVICE_OUT_HEADPHONES] = strdup("SLIMBUS_0_RX");
1260 hw_interface_table[SND_DEVICE_OUT_LINE] = strdup("SLIMBUS_0_RX");
1261 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001262 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001263 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001264 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001265 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET] = strdup("SLIMBUS_0_RX");
1266 hw_interface_table[SND_DEVICE_OUT_VOICE_HAC_HANDSET] = strdup("SLIMBUS_0_RX");
1267 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER] = strdup("SLIMBUS_0_RX");
1268 hw_interface_table[SND_DEVICE_OUT_VOICE_HEADPHONES] = strdup("SLIMBUS_0_RX");
yixuanjiang9536e672018-09-06 18:43:36 +08001269 hw_interface_table[SND_DEVICE_OUT_VOICE_HEADSET] = strdup("SLIMBUS_0_RX");
juyuchen66c4ecf2018-08-06 15:39:34 +08001270 hw_interface_table[SND_DEVICE_OUT_VOICE_MUSIC_TX] = strdup("VOICE_PLAYBACK_TX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001271 hw_interface_table[SND_DEVICE_OUT_VOICE_LINE] = strdup("SLIMBUS_0_RX");
1272 hw_interface_table[SND_DEVICE_OUT_HDMI] = strdup("HDMI_RX");
1273 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("SLIMBUS_0_RX-and-HDMI_RX");
1274 hw_interface_table[SND_DEVICE_OUT_BT_SCO] = strdup("SEC_AUX_PCM_RX");
1275 hw_interface_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("SEC_AUX_PCM_RX");
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001276 hw_interface_table[SND_DEVICE_OUT_BT_A2DP] = strdup("SLIMBUS_7_RX");
1277 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] =
1278 strdup("SLIMBUS_0_RX-and-SLIMBUS_7_RX");
Aniket Kumar Lata9723a962018-05-16 17:41:55 -07001279 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP] =
1280 strdup("SLIMBUS_0_RX-and-SLIMBUS_7_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001281 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = strdup("SLIMBUS_0_RX");
1282 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = strdup("SLIMBUS_0_RX");
1283 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = strdup("SLIMBUS_0_RX");
1284 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = strdup("SLIMBUS_0_RX");
David Linee3fe402017-03-13 10:00:42 -07001285 hw_interface_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("USB_AUDIO_RX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001286 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = strdup("USB_AUDIO_RX");
1287 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = strdup("USB_AUDIO_RX");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001288 hw_interface_table[SND_DEVICE_OUT_VOICE_USB_HEADSET] = strdup("USB_AUDIO_RX");
David Linee3fe402017-03-13 10:00:42 -07001289 hw_interface_table[SND_DEVICE_OUT_USB_HEADPHONES] = strdup("USB_AUDIO_RX");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001290 hw_interface_table[SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = strdup("USB_AUDIO_RX");
jasmine cha270b7762018-03-30 15:41:33 +08001291 hw_interface_table[SND_DEVICE_OUT_USB_HEADSET_SPEC] = strdup("USB_AUDIO_RX");
David Linee3fe402017-03-13 10:00:42 -07001292 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 -07001293 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 -07001294 hw_interface_table[SND_DEVICE_OUT_VOICE_TX] = strdup("AFE_PCM_RX");
1295 hw_interface_table[SND_DEVICE_OUT_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
1296 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
jasmine cha52284622018-03-23 17:21:35 +08001297 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = strdup("SLIMBUS_0_RX");
1298 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_BT_SCO] = strdup("SLIMBUS_0_RX-and-SEC_AUX_PCM_RX");
1299 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 +08001300 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO] = strdup("QUAT_TDM_RX_0-and-SLIMBUS_7_RX"),
1301 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 -07001302 hw_interface_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1303 hw_interface_table[SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1304 hw_interface_table[SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = strdup("USB_AUDIO_TX");
1305 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1306 hw_interface_table[SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1307 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = strdup("USB_AUDIO_TX");
1308 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = strdup("USB_AUDIO_TX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001309 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001310 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_AEC] = strdup("SLIMBUS_0_TX");
1311 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_NS] = strdup("SLIMBUS_0_TX");
1312 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1313 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC] = strdup("SLIMBUS_0_TX");
1314 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_AEC] = strdup("SLIMBUS_0_TX");
1315 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_NS] = strdup("SLIMBUS_0_TX");
1316 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1317 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001318 hw_interface_table[SND_DEVICE_IN_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001319 hw_interface_table[SND_DEVICE_IN_HEADSET_MIC_AEC] = strdup("SLIMBUS_0_TX");
Eric Laurent5f4ca952018-10-19 17:33:43 -07001320 hw_interface_table[SND_DEVICE_IN_CAMCORDER_LANDSCAPE] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001321 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC] = strdup("SLIMBUS_0_TX");
1322 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC_NS] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001323 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC_AEC] = strdup("SLIMBUS_0_TX");
1324 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001325 hw_interface_table[SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
1326 hw_interface_table[SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = strdup("SLIMBUS_0_TX");
David Lin93725722017-10-13 14:58:17 -07001327 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_MIC] = strdup("SLIMBUS_0_TX");
1328 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1329 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = strdup("SLIMBUS_0_TX");
1330 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = strdup("SLIMBUS_0_TX");
1331 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001332 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC] = strdup("SLIMBUS_0_TX");
1333 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_AEC] = strdup("SLIMBUS_0_TX");
1334 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_NS] = strdup("SLIMBUS_0_TX");
1335 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1336 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC] = strdup("SLIMBUS_0_TX");
1337 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_AEC] = strdup("SLIMBUS_0_TX");
1338 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_NS] = strdup("SLIMBUS_0_TX");
1339 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001340 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
1341 hw_interface_table[SND_DEVICE_IN_VOICE_DMIC] = strdup("SLIMBUS_0_TX");
1342 hw_interface_table[SND_DEVICE_IN_VOICE_DMIC_TMUS] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001343 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001344 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = strdup("SLIMBUS_0_TX");
1345 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001346 hw_interface_table[SND_DEVICE_IN_VOICE_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001347 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1348 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = strdup("SLIMBUS_0_TX");
1349 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1350 hw_interface_table[SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1351 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("SEC_AUX_PCM_TX");
1352 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("SEC_AUX_PCM_TX");
1353 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("SEC_AUX_PCM_TX");
1354 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("SEC_AUX_PCM_TX");
1355 hw_interface_table[SND_DEVICE_IN_VOICE_RX] = strdup("AFE_PCM_TX");
1356 hw_interface_table[SND_DEVICE_IN_THREE_MIC] = strdup("SLIMBUS_0_TX");
1357 hw_interface_table[SND_DEVICE_IN_QUAD_MIC] = strdup("SLIMBUS_0_TX");
1358 hw_interface_table[SND_DEVICE_IN_HANDSET_TMIC] = strdup("SLIMBUS_0_TX");
1359 hw_interface_table[SND_DEVICE_IN_HANDSET_QMIC] = strdup("SLIMBUS_0_TX");
1360 hw_interface_table[SND_DEVICE_IN_HANDSET_TMIC_AEC] = strdup("SLIMBUS_0_TX");
1361 hw_interface_table[SND_DEVICE_IN_HANDSET_QMIC_AEC] = strdup("SLIMBUS_0_TX");
Eric Laurent5f4ca952018-10-19 17:33:43 -07001362 hw_interface_table[SND_DEVICE_IN_CAMCORDER_INVERT_LANDSCAPE] = strdup("SLIMBUS_0_TX");
1363 hw_interface_table[SND_DEVICE_IN_CAMCORDER_PORTRAIT] = strdup("SLIMBUS_0_TX");
1364 hw_interface_table[SND_DEVICE_IN_CAMCORDER_SELFIE_LANDSCAPE] = strdup("SLIMBUS_0_TX");
1365 hw_interface_table[SND_DEVICE_IN_CAMCORDER_SELFIE_INVERT_LANDSCAPE] = strdup("SLIMBUS_0_TX");
1366 hw_interface_table[SND_DEVICE_IN_CAMCORDER_SELFIE_PORTRAIT] = strdup("SLIMBUS_0_TX");
Eric Laurentc6333382015-09-14 12:43:44 -07001367 my_data->max_mic_count = PLATFORM_DEFAULT_MIC_COUNT;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001368}
1369
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001370void get_cvd_version(char *cvd_version, struct audio_device *adev)
1371{
1372 struct mixer_ctl *ctl;
1373 int count;
1374 int ret = 0;
1375
1376 ctl = mixer_get_ctl_by_name(adev->mixer, CVD_VERSION_MIXER_CTL);
1377 if (!ctl) {
1378 ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__, CVD_VERSION_MIXER_CTL);
1379 goto done;
1380 }
1381 mixer_ctl_update(ctl);
1382
1383 count = mixer_ctl_get_num_values(ctl);
1384 if (count > MAX_CVD_VERSION_STRING_SIZE)
1385 count = MAX_CVD_VERSION_STRING_SIZE - 1;
1386
1387 ret = mixer_ctl_get_array(ctl, cvd_version, count);
1388 if (ret != 0) {
1389 ALOGE("%s: ERROR! mixer_ctl_get_array() failed to get CVD Version", __func__);
1390 goto done;
1391 }
1392
1393done:
1394 return;
1395}
1396
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001397static int platform_acdb_init(void *platform)
1398{
1399 struct platform_data *my_data = (struct platform_data *)platform;
1400 struct audio_device *adev = my_data->adev;
1401
1402 if (!my_data->acdb_init) {
1403 ALOGE("%s: no acdb_init fn provided", __func__);
1404 return -1;
1405 }
1406
1407 if (my_data->acdb_initialized) {
1408 ALOGW("acdb is already initialized");
1409 return 0;
1410 }
1411
Thierry Strudel07f96d12018-09-20 13:31:34 -07001412#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845) || (PLATFORM_SDM710) || (PLATFORM_SM8150)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001413 char *cvd_version = calloc(1, MAX_CVD_VERSION_STRING_SIZE);
1414 if (!cvd_version)
1415 ALOGE("failed to allocate cvd_version");
1416 else {
1417 get_cvd_version(cvd_version, adev);
1418 my_data->acdb_init((char *)my_data->snd_card_name, cvd_version, 0);
1419 free(cvd_version);
1420 }
1421#elif defined (PLATFORM_MSM8084)
1422 my_data->acdb_init((char *)my_data->snd_card_name);
1423#else
1424 my_data->acdb_init();
1425#endif
1426 my_data->acdb_initialized = true;
1427 return 0;
1428}
1429
David Linee3fe402017-03-13 10:00:42 -07001430static void
1431platform_backend_config_init(struct platform_data *pdata)
1432{
1433 int i;
1434
1435 /* initialize backend config */
1436 for (i = 0; i < MAX_CODEC_BACKENDS; i++) {
1437 pdata->current_backend_cfg[i].sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
1438 pdata->current_backend_cfg[i].bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
1439 pdata->current_backend_cfg[i].channels = CODEC_BACKEND_DEFAULT_CHANNELS;
1440
1441 if (i > MAX_RX_CODEC_BACKENDS)
1442 pdata->current_backend_cfg[i].channels = CODEC_BACKEND_DEFAULT_TX_CHANNELS;
1443
1444 pdata->current_backend_cfg[i].bitwidth_mixer_ctl = NULL;
1445 pdata->current_backend_cfg[i].samplerate_mixer_ctl = NULL;
1446 pdata->current_backend_cfg[i].channels_mixer_ctl = NULL;
1447 }
1448
1449 pdata->current_backend_cfg[DEFAULT_CODEC_BACKEND].bitwidth_mixer_ctl =
1450 strdup("SLIM_0_RX Format");
1451 pdata->current_backend_cfg[DEFAULT_CODEC_BACKEND].samplerate_mixer_ctl =
1452 strdup("SLIM_0_RX SampleRate");
1453
1454 pdata->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].bitwidth_mixer_ctl =
1455 strdup("SLIM_0_TX Format");
1456 pdata->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].samplerate_mixer_ctl =
1457 strdup("SLIM_0_TX SampleRate");
1458
1459 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].bitwidth_mixer_ctl =
1460 strdup("USB_AUDIO_TX Format");
1461 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].samplerate_mixer_ctl =
1462 strdup("USB_AUDIO_TX SampleRate");
1463 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].channels_mixer_ctl =
1464 strdup("USB_AUDIO_TX Channels");
1465
Yung Ti Su39a2b8a2018-10-05 15:43:40 +08001466 if (strstr(pdata->snd_card_name, "intcodec")) {
1467 pdata->current_backend_cfg[HEADPHONE_BACKEND].bitwidth_mixer_ctl =
1468 strdup("INT0_MI2S_RX Format");
1469 pdata->current_backend_cfg[HEADPHONE_BACKEND].samplerate_mixer_ctl =
1470 strdup("INT0_MI2S_RX SampleRate");
1471 } else {
1472 pdata->current_backend_cfg[HEADPHONE_BACKEND].bitwidth_mixer_ctl =
1473 strdup("SLIM_6_RX Format");
1474 pdata->current_backend_cfg[HEADPHONE_BACKEND].samplerate_mixer_ctl =
1475 strdup("SLIM_6_RX SampleRate");
1476 }
David Linee3fe402017-03-13 10:00:42 -07001477
1478 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].bitwidth_mixer_ctl =
1479 strdup("USB_AUDIO_RX Format");
1480 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].samplerate_mixer_ctl =
1481 strdup("USB_AUDIO_RX SampleRate");
1482
1483 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].channels = 1;
1484 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].channels_mixer_ctl =
1485 strdup("USB_AUDIO_RX Channels");
1486}
1487
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001488static int
1489platform_backend_app_type_cfg_init(struct platform_data *pdata,
1490 struct mixer *mixer)
1491{
1492 size_t app_type_cfg[128] = {0};
1493 int length, num_app_types = 0;
1494 struct mixer_ctl *ctl = NULL;
1495
1496 const char *mixer_ctl_name = "App Type Config";
1497 ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name);
1498 if (!ctl) {
1499 ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name);
1500 return -1;
1501 }
1502
1503 length = 1; // reserve index 0 for number of app types
1504
1505 struct listnode *node;
1506 struct app_type_entry *entry;
1507 list_for_each(node, &app_type_entry_list) {
1508 entry = node_to_item(node, struct app_type_entry, node);
1509 app_type_cfg[length++] = entry->app_type;
1510 app_type_cfg[length++] = entry->max_rate;
1511 app_type_cfg[length++] = entry->bit_width;
1512 ALOGI("%s add entry %d %d", __func__, entry->app_type, entry->bit_width);
1513 num_app_types += 1;
1514 }
1515
1516 // default for capture
1517 int t;
1518 platform_get_default_app_type_v2(pdata,
1519 PCM_CAPTURE,
1520 &t);
1521 app_type_cfg[length++] = t;
1522 app_type_cfg[length++] = 48000;
1523 app_type_cfg[length++] = 16;
1524 num_app_types += 1;
1525
1526 if (num_app_types) {
1527 app_type_cfg[0] = num_app_types;
1528 if (mixer_ctl_set_array(ctl, app_type_cfg, length) < 0) {
1529 ALOGE("Failed to set app type cfg");
1530 }
1531 }
1532 return 0;
1533}
1534
Xu Han1638fd12018-04-20 12:42:23 -07001535static void configure_flicker_sensor_input(struct mixer *mixer)
1536{
1537 struct mixer_ctl *ctl;
1538 const char* ctl1 = "AIF3_CAP Mixer SLIM TX2";
1539 int setting1 = 1;
1540 const char* ctl2 = "CDC_IF TX2 MUX";
1541 const char* setting2 = "DEC2";
1542 const char* ctl3 = "SLIM_1_TX Channels";
1543 const char* setting3 = "One";
1544 const char* ctl4 = "ADC MUX2";
1545 const char* setting4 = "AMIC";
1546 const char* ctl5 = "AMIC MUX2";
1547 const char* setting5 = "ADC1";
1548 const char* ctl6 = "DEC2 Volume";
1549 int setting6 = 84;
Xu Han07e07402018-05-15 14:19:25 -07001550 const char* ctl7 = "MultiMedia9 Mixer SLIM_1_TX";
Xu Han1638fd12018-04-20 12:42:23 -07001551 int setting7 = 1;
1552 const char* ctl8 = "SLIM_1_TX SampleRate";
1553 const char* setting8 = "KHZ_8";
1554
1555 ctl = mixer_get_ctl_by_name(mixer, ctl1);
1556 mixer_ctl_set_value(ctl, 0, setting1);
1557 ctl = mixer_get_ctl_by_name(mixer, ctl2);
1558 mixer_ctl_set_enum_by_string(ctl, setting2);
1559 ctl = mixer_get_ctl_by_name(mixer, ctl3);
1560 mixer_ctl_set_enum_by_string(ctl, setting3);
1561 ctl = mixer_get_ctl_by_name(mixer, ctl4);
1562 mixer_ctl_set_enum_by_string(ctl, setting4);
1563 ctl = mixer_get_ctl_by_name(mixer, ctl5);
1564 mixer_ctl_set_enum_by_string(ctl, setting5);
1565 ctl = mixer_get_ctl_by_name(mixer, ctl6);
1566 mixer_ctl_set_value(ctl, 0, setting6);
1567 ctl = mixer_get_ctl_by_name(mixer, ctl7);
1568 mixer_ctl_set_value(ctl, 0, setting7);
1569 ctl = mixer_get_ctl_by_name(mixer, ctl8);
1570 mixer_ctl_set_enum_by_string(ctl, setting8);
1571}
1572
Eric Laurentb23d5282013-05-14 15:27:20 -07001573void *platform_init(struct audio_device *adev)
1574{
1575 char value[PROPERTY_VALUE_MAX];
vivek mehta60ea4152016-02-18 17:10:26 -08001576 struct platform_data *my_data = NULL;
1577 int retry_num = 0, snd_card_num = 0, key = 0, ret = 0;
1578 bool dual_mic_config = false, use_default_mixer_path = true;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001579 const char *snd_card_name;
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001580 char *cvd_version = NULL;
vivek mehta60ea4152016-02-18 17:10:26 -08001581 char *snd_internal_name = NULL;
1582 char *tmp = NULL;
1583 char mixer_xml_file[MIXER_PATH_MAX_LENGTH]= {0};
vivek mehtade4849c2016-03-03 17:23:38 -08001584 char platform_info_file[MIXER_PATH_MAX_LENGTH]= {0};
1585 struct snd_card_split *snd_split_handle = NULL;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001586 my_data = calloc(1, sizeof(struct platform_data));
1587
1588 my_data->adev = adev;
1589
keunhui.park2f7306a2015-07-16 16:48:06 +09001590 list_init(&operator_info_list);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001591 list_init(&app_type_entry_list);
keunhui.park2f7306a2015-07-16 16:48:06 +09001592
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001593 set_platform_defaults(my_data);
1594
vivek mehta0fb11312017-05-15 19:35:32 -07001595 // audio_extn_utils_get_snd_card_num does
1596 // - open mixer and get snd card name
1597 // - parse platform info xml file and check for valid snd card name
1598 // - on failure loop through all the active snd card
sangwoo1b9f4b32013-06-21 18:22:55 -07001599
vivek mehta0fb11312017-05-15 19:35:32 -07001600 snd_card_num = audio_extn_utils_get_snd_card_num();
1601 if (-1 == snd_card_num) {
1602 ALOGE("%s: invalid sound card number (-1), bailing out ", __func__);
1603 goto init_failed;
sangwoo1b9f4b32013-06-21 18:22:55 -07001604 }
1605
vivek mehta0fb11312017-05-15 19:35:32 -07001606 adev->mixer = mixer_open(snd_card_num);
1607 snd_card_name = mixer_get_name(adev->mixer);
1608 my_data->hw_info = hw_info_init(snd_card_name);
1609
1610 audio_extn_set_snd_card_split(snd_card_name);
1611 snd_split_handle = audio_extn_get_snd_card_split();
1612
1613 /* Get the codec internal name from the sound card and/or form factor
1614 * name and form the mixer paths and platfor info file name dynamically.
1615 * This is generic way of picking any codec and forma factor name based
1616 * mixer and platform info files in future with no code change.
1617
1618 * current code extends and looks for any of the exteneded mixer path and
1619 * platform info file present based on codec and form factor.
1620
1621 * order of picking appropriate file is
1622 * <i> mixer_paths_<codec_name>_<form_factor>.xml, if file not present
1623 * <ii> mixer_paths_<codec_name>.xml, if file not present
1624 * <iii> mixer_paths.xml
1625
1626 * same order is followed for audio_platform_info.xml as well
1627 */
1628
1629 // need to carryforward old file name
1630 if (!strncmp(snd_card_name, TOMTOM_8226_SND_CARD_NAME,
1631 min(strlen(TOMTOM_8226_SND_CARD_NAME), strlen(snd_card_name)))) {
1632 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1633 MIXER_XML_BASE_STRING, TOMTOM_MIXER_FILE_SUFFIX );
1634 } else {
1635
1636 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s_%s.xml",
1637 MIXER_XML_BASE_STRING, snd_split_handle->snd_card,
1638 snd_split_handle->form_factor);
1639 if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) {
1640 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1641 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1642 MIXER_XML_BASE_STRING, snd_split_handle->snd_card);
1643
1644 if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) {
1645 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1646 strlcpy(mixer_xml_file, MIXER_XML_DEFAULT_PATH, MIXER_PATH_MAX_LENGTH);
1647 audio_extn_utils_resolve_config_file(mixer_xml_file);
1648 }
1649 }
1650 }
1651
1652 audio_extn_utils_get_platform_info(snd_card_name, platform_info_file);
1653
jiabin8962a4d2018-03-19 18:21:24 -07001654 my_data->declared_mic_count = 0;
vivek mehta0fb11312017-05-15 19:35:32 -07001655 /* Initialize platform specific ids and/or backends*/
juyuchenbf6571f2018-11-30 18:50:47 +08001656 platform_info_init(platform_info_file, my_data,
1657 true, &platform_set_parameters);
vivek mehta0fb11312017-05-15 19:35:32 -07001658
1659 ALOGD("%s: Loading mixer file: %s", __func__, mixer_xml_file);
1660 adev->audio_route = audio_route_init(snd_card_num, mixer_xml_file);
1661
1662 if (!adev->audio_route) {
1663 ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
1664 mixer_close(adev->mixer);
1665 adev->mixer = NULL;
1666 hw_info_deinit(my_data->hw_info);
1667 my_data->hw_info = NULL;
1668 goto init_failed;
1669 }
1670 adev->snd_card = snd_card_num;
1671 ALOGD("%s: Opened sound card:%d", __func__, snd_card_num);
1672
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09001673 //set max volume step for voice call
1674 property_get("ro.config.vc_call_vol_steps", value, TOSTRING(MAX_VOL_INDEX));
1675 my_data->max_vol_index = atoi(value);
1676
vivek mehta65ad12d2015-08-13 18:32:48 -07001677 property_get("persist.audio.dualmic.config",value,"");
1678 if (!strcmp("endfire", value)) {
1679 dual_mic_config = true;
1680 }
1681
John Muir9e59a962018-01-10 13:30:00 -08001682 my_data->source_mic_type = 0;
Prashant Malanic92c5962015-08-11 15:10:18 -07001683
Eric Laurentb23d5282013-05-14 15:27:20 -07001684 my_data->fluence_in_spkr_mode = false;
1685 my_data->fluence_in_voice_call = false;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001686 my_data->fluence_in_voice_comm = false;
Eric Laurentb23d5282013-05-14 15:27:20 -07001687 my_data->fluence_in_voice_rec = false;
1688
vivek mehta65ad12d2015-08-13 18:32:48 -07001689 property_get("ro.qc.sdk.audio.fluencetype", value, "none");
Prashant Malanic92c5962015-08-11 15:10:18 -07001690 if (!strcmp("fluencepro", value)) {
1691 my_data->fluence_type = FLUENCE_PRO_ENABLE;
vivek mehta65ad12d2015-08-13 18:32:48 -07001692 } else if (!strcmp("fluence", value) || (dual_mic_config)) {
Prashant Malanic92c5962015-08-11 15:10:18 -07001693 my_data->fluence_type = FLUENCE_ENABLE;
1694 } else if (!strcmp("none", value)) {
1695 my_data->fluence_type = FLUENCE_DISABLE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001696 }
1697
Prashant Malanic92c5962015-08-11 15:10:18 -07001698 if (my_data->fluence_type != FLUENCE_DISABLE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001699 property_get("persist.audio.fluence.voicecall",value,"");
1700 if (!strcmp("true", value)) {
1701 my_data->fluence_in_voice_call = true;
1702 }
1703
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001704 property_get("persist.audio.fluence.voicecomm",value,"");
1705 if (!strcmp("true", value)) {
1706 my_data->fluence_in_voice_comm = true;
1707 }
1708
Eric Laurentb23d5282013-05-14 15:27:20 -07001709 property_get("persist.audio.fluence.voicerec",value,"");
1710 if (!strcmp("true", value)) {
1711 my_data->fluence_in_voice_rec = true;
1712 }
1713
1714 property_get("persist.audio.fluence.speaker",value,"");
1715 if (!strcmp("true", value)) {
1716 my_data->fluence_in_spkr_mode = true;
1717 }
1718 }
1719
Prashant Malanic92c5962015-08-11 15:10:18 -07001720 // support max to mono, example if max count is 3, usecase supports Three, dual and mono mic
1721 switch (my_data->max_mic_count) {
1722 case 4:
1723 my_data->source_mic_type |= SOURCE_QUAD_MIC;
1724 case 3:
1725 my_data->source_mic_type |= SOURCE_THREE_MIC;
1726 case 2:
1727 my_data->source_mic_type |= SOURCE_DUAL_MIC;
1728 case 1:
1729 my_data->source_mic_type |= SOURCE_MONO_MIC;
1730 break;
1731 default:
1732 ALOGE("%s: max_mic_count (%d), is not supported, setting to default",
1733 __func__, my_data->max_mic_count);
1734 my_data->source_mic_type = SOURCE_MONO_MIC|SOURCE_DUAL_MIC;
1735 break;
1736 }
1737
1738 ALOGV("%s: Fluence_Type(%d) max_mic_count(%d) mic_type(0x%x) fluence_in_voice_call(%d)"
1739 " fluence_in_voice_comm(%d) fluence_in_voice_rec(%d) fluence_in_spkr_mode(%d) ",
1740 __func__, my_data->fluence_type, my_data->max_mic_count, my_data->source_mic_type,
1741 my_data->fluence_in_voice_call, my_data->fluence_in_voice_comm,
1742 my_data->fluence_in_voice_rec, my_data->fluence_in_spkr_mode);
1743
Eric Laurentb23d5282013-05-14 15:27:20 -07001744 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
1745 if (my_data->acdb_handle == NULL) {
1746 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
1747 } else {
1748 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
1749 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
1750 "acdb_loader_deallocate_ACDB");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001751 if (!my_data->acdb_deallocate)
1752 ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s",
1753 __func__, LIB_ACDB_LOADER);
1754
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001755 my_data->acdb_send_audio_cal_v3 = (acdb_send_audio_cal_v3_t)dlsym(my_data->acdb_handle,
1756 "acdb_loader_send_audio_cal_v3");
1757 if (!my_data->acdb_send_audio_cal_v3)
1758 ALOGE("%s: Could not find the symbol acdb_send_audio_cal_v3 from %s",
1759 __func__, LIB_ACDB_LOADER);
1760
Eric Laurentb23d5282013-05-14 15:27:20 -07001761 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
1762 "acdb_loader_send_audio_cal");
1763 if (!my_data->acdb_send_audio_cal)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001764 ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s",
Eric Laurentb23d5282013-05-14 15:27:20 -07001765 __func__, LIB_ACDB_LOADER);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001766
Eric Laurentb23d5282013-05-14 15:27:20 -07001767 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
1768 "acdb_loader_send_voice_cal");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001769 if (!my_data->acdb_send_voice_cal)
1770 ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s",
1771 __func__, LIB_ACDB_LOADER);
1772
1773 my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle,
1774 "acdb_loader_reload_vocvoltable");
1775 if (!my_data->acdb_reload_vocvoltable)
1776 ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s",
1777 __func__, LIB_ACDB_LOADER);
vivek mehta1a9b7c02015-06-25 11:49:38 -07001778
1779 my_data->acdb_send_gain_dep_cal = (acdb_send_gain_dep_cal_t)dlsym(my_data->acdb_handle,
1780 "acdb_loader_send_gain_dep_cal");
1781 if (!my_data->acdb_send_gain_dep_cal)
1782 ALOGV("%s: Could not find the symbol acdb_loader_send_gain_dep_cal from %s",
1783 __func__, LIB_ACDB_LOADER);
1784
Xu Han1638fd12018-04-20 12:42:23 -07001785#if defined (FLICKER_SENSOR_INPUT)
1786 configure_flicker_sensor_input(adev->mixer);
1787#endif
1788
Thierry Strudel07f96d12018-09-20 13:31:34 -07001789#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845) || (PLATFORM_SDM710) || (PLATFORM_SM8150)
vivek mehta0fb11312017-05-15 19:35:32 -07001790 acdb_init_v2_cvd_t acdb_init_local;
1791 acdb_init_local = (acdb_init_v2_cvd_t)dlsym(my_data->acdb_handle,
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001792 "acdb_loader_init_v2");
vivek mehta0fb11312017-05-15 19:35:32 -07001793 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001794 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1795 dlerror());
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001796
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001797#elif defined (PLATFORM_MSM8084)
vivek mehta0fb11312017-05-15 19:35:32 -07001798 acdb_init_v2_t acdb_init_local;
1799 acdb_init_local = (acdb_init_v2_t)dlsym(my_data->acdb_handle,
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001800 "acdb_loader_init_v2");
vivek mehta0fb11312017-05-15 19:35:32 -07001801 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001802 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1803 dlerror());
1804
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001805#else
vivek mehta0fb11312017-05-15 19:35:32 -07001806 acdb_init_t acdb_init_local;
1807 acdb_init_local = (acdb_init_t)dlsym(my_data->acdb_handle,
Eric Laurentb23d5282013-05-14 15:27:20 -07001808 "acdb_loader_init_ACDB");
vivek mehta0fb11312017-05-15 19:35:32 -07001809 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001810 ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__,
1811 dlerror());
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001812#endif
vivek mehta0fb11312017-05-15 19:35:32 -07001813 my_data->acdb_init = acdb_init_local;
Eric Laurentb23d5282013-05-14 15:27:20 -07001814
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001815 my_data->acdb_send_custom_top = (acdb_send_custom_top_t)
1816 dlsym(my_data->acdb_handle,
1817 "acdb_loader_send_common_custom_topology");
1818
1819 if (!my_data->acdb_send_custom_top)
1820 ALOGE("%s: Could not find the symbol acdb_get_default_app_type from %s",
1821 __func__, LIB_ACDB_LOADER);
1822
jasmine chac89321b2018-04-10 21:37:01 +08001823 my_data->acdb_set_audio_cal = (acdb_set_audio_cal_t)dlsym(my_data->acdb_handle,
1824 "acdb_loader_set_audio_cal_v2");
1825 if (!my_data->acdb_set_audio_cal)
1826 ALOGE("%s: Could not find the symbol acdb_set_audio_cal_v2 from %s",
1827 __func__, LIB_ACDB_LOADER);
1828
vivek mehta0fb11312017-05-15 19:35:32 -07001829 int result = acdb_init(adev->snd_card);
1830 if (!result) {
1831 my_data->acdb_initialized = true;
1832 ALOGD("ACDB initialized");
1833 } else {
1834 my_data->acdb_initialized = false;
1835 ALOGD("ACDB initialization failed");
1836 }
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001837 }
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001838
David Linee3fe402017-03-13 10:00:42 -07001839 /* init usb */
1840 audio_extn_usb_init(adev);
1841
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001842 /* init a2dp */
1843 audio_extn_a2dp_init(adev);
1844
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001845 audio_extn_spkr_prot_init(adev);
Haynes Mathew George98c95622014-06-20 19:14:25 -07001846
Ravi Kumar Alamanda76315572015-04-23 13:13:56 -07001847 audio_extn_hwdep_cal_send(adev->snd_card, my_data->acdb_handle);
1848
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001849 /* load csd client */
1850 platform_csd_init(my_data);
1851
David Linee3fe402017-03-13 10:00:42 -07001852 platform_backend_config_init(my_data);
1853
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001854 init_be_dai_name_table(adev);
1855
1856 if (platform_supports_app_type_cfg())
1857 platform_backend_app_type_cfg_init(my_data, adev->mixer);
1858
Eric Laurentb23d5282013-05-14 15:27:20 -07001859 return my_data;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001860
1861init_failed:
1862 if (my_data)
1863 free(my_data);
1864 return NULL;
Eric Laurentb23d5282013-05-14 15:27:20 -07001865}
1866
1867void platform_deinit(void *platform)
1868{
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001869 int32_t dev;
keunhui.park2f7306a2015-07-16 16:48:06 +09001870 struct operator_info *info_item;
1871 struct operator_specific_device *device_item;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001872 struct app_type_entry *ap;
keunhui.park2f7306a2015-07-16 16:48:06 +09001873 struct listnode *node;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001874
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001875 struct platform_data *my_data = (struct platform_data *)platform;
1876 close_csd_client(my_data->csd);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001877
David Lin41b4fe42018-07-08 16:14:24 -07001878 audio_extn_spkr_prot_deinit(my_data->adev);
1879
vivek mehtade4849c2016-03-03 17:23:38 -08001880 hw_info_deinit(my_data->hw_info);
1881
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001882 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1883 if (backend_tag_table[dev])
1884 free(backend_tag_table[dev]);
1885 if (hw_interface_table[dev])
1886 free(hw_interface_table[dev]);
keunhui.park2f7306a2015-07-16 16:48:06 +09001887 if (operator_specific_device_table[dev]) {
1888 while (!list_empty(operator_specific_device_table[dev])) {
1889 node = list_head(operator_specific_device_table[dev]);
1890 list_remove(node);
1891 device_item = node_to_item(node, struct operator_specific_device, list);
1892 free(device_item->operator);
1893 free(device_item->mixer_path);
1894 free(device_item);
1895 }
1896 free(operator_specific_device_table[dev]);
1897 }
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001898 }
1899
1900 if (my_data->snd_card_name)
1901 free(my_data->snd_card_name);
1902
keunhui.park2f7306a2015-07-16 16:48:06 +09001903 while (!list_empty(&operator_info_list)) {
1904 node = list_head(&operator_info_list);
1905 list_remove(node);
1906 info_item = node_to_item(node, struct operator_info, list);
1907 free(info_item->name);
1908 free(info_item->mccmnc);
1909 free(info_item);
1910 }
1911
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001912 while (!list_empty(&app_type_entry_list)) {
1913 node = list_head(&app_type_entry_list);
1914 list_remove(node);
1915 ap = node_to_item(node, struct app_type_entry, node);
vivek mehtaa68fea62017-06-08 19:04:02 -07001916 if (ap->mode) free(ap->mode);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001917 free(ap);
1918 }
1919
Kevin Rocarde35d4af2017-05-02 16:55:28 -07001920 mixer_close(my_data->adev->mixer);
Eric Laurentb23d5282013-05-14 15:27:20 -07001921 free(platform);
David Linee3fe402017-03-13 10:00:42 -07001922
1923 /* deinit usb */
1924 audio_extn_usb_deinit();
Eric Laurentb23d5282013-05-14 15:27:20 -07001925}
1926
1927const char *platform_get_snd_device_name(snd_device_t snd_device)
1928{
keunhui.park2f7306a2015-07-16 16:48:06 +09001929 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1930 if (operator_specific_device_table[snd_device] != NULL) {
1931 return get_operator_specific_device_mixer_path(snd_device);
1932 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001933 return device_table[snd_device];
keunhui.park2f7306a2015-07-16 16:48:06 +09001934 } else
Ravi Kumar Alamanda64026462014-09-15 00:08:58 -07001935 return "none";
Eric Laurentb23d5282013-05-14 15:27:20 -07001936}
1937
vivek mehtade4849c2016-03-03 17:23:38 -08001938int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
1939 char *device_name)
1940{
1941 struct platform_data *my_data = (struct platform_data *)platform;
1942
David Benjamin1565f992016-09-21 12:10:34 -04001943 if (platform == NULL) {
vivek mehtade4849c2016-03-03 17:23:38 -08001944 ALOGW("%s: something wrong, use legacy get_snd_device name", __func__);
David Benjamin1565f992016-09-21 12:10:34 -04001945 strlcpy(device_name, platform_get_snd_device_name(snd_device),
1946 DEVICE_NAME_MAX_SIZE);
vivek mehtade4849c2016-03-03 17:23:38 -08001947 } else if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1948 if (operator_specific_device_table[snd_device] != NULL) {
1949 strlcpy(device_name, get_operator_specific_device_mixer_path(snd_device),
1950 DEVICE_NAME_MAX_SIZE);
1951 } else {
1952 strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE);
1953 }
1954 hw_info_append_hw_type(my_data->hw_info, snd_device, device_name);
1955 } else {
1956 strlcpy(device_name, "none", DEVICE_NAME_MAX_SIZE);
Aniket Kumar Lataa158e862018-05-11 17:28:40 -07001957 return -EINVAL;
vivek mehtade4849c2016-03-03 17:23:38 -08001958 }
1959
1960 return 0;
1961}
1962
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001963void platform_add_backend_name(void *platform, char *mixer_path,
1964 snd_device_t snd_device)
Eric Laurentb23d5282013-05-14 15:27:20 -07001965{
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001966 struct platform_data *my_data = (struct platform_data *)platform;
1967
Haynes Mathew George98c95622014-06-20 19:14:25 -07001968 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1969 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1970 return;
Ravi Kumar Alamanda1de6e5a2014-06-19 21:55:39 -05001971 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001972
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001973 const char * suffix = backend_tag_table[snd_device];
Haynes Mathew George98c95622014-06-20 19:14:25 -07001974
1975 if (suffix != NULL) {
1976 strcat(mixer_path, " ");
1977 strcat(mixer_path, suffix);
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001978 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001979}
1980
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001981bool platform_check_backends_match(snd_device_t snd_device1, snd_device_t snd_device2)
1982{
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001983 ALOGV("%s: snd_device1 = %s, snd_device2 = %s", __func__,
1984 platform_get_snd_device_name(snd_device1),
1985 platform_get_snd_device_name(snd_device2));
1986
1987 if ((snd_device1 < SND_DEVICE_MIN) || (snd_device1 >= SND_DEVICE_MAX)) {
1988 ALOGE("%s: Invalid snd_device = %s", __func__,
1989 platform_get_snd_device_name(snd_device1));
1990 return false;
1991 }
1992 if ((snd_device2 < SND_DEVICE_MIN) || (snd_device2 >= SND_DEVICE_MAX)) {
1993 ALOGE("%s: Invalid snd_device = %s", __func__,
1994 platform_get_snd_device_name(snd_device2));
1995 return false;
1996 }
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07001997
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001998 const char * be_itf1 = hw_interface_table[snd_device1];
1999 const char * be_itf2 = hw_interface_table[snd_device2];
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07002000 /*
2001 hw_interface_table has overrides for a snd_device.
2002 if there is no entry for a device, assume DEFAULT_RX_BACKEND
2003 */
2004 if (be_itf1 == NULL) {
2005 be_itf1 = DEFAULT_RX_BACKEND;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002006 }
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07002007 if (be_itf2 == NULL) {
2008 be_itf2 = DEFAULT_RX_BACKEND;
2009 }
2010 ALOGV("%s: be_itf1 = %s, be_itf2 = %s", __func__, be_itf1, be_itf2);
2011 /*
2012 this takes care of finding a device within a combo device pair as well
2013 */
2014 return strstr(be_itf1, be_itf2) != NULL || strstr(be_itf2, be_itf1) != NULL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002015}
2016
Eric Laurentb23d5282013-05-14 15:27:20 -07002017int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
2018{
2019 int device_id;
2020 if (device_type == PCM_PLAYBACK)
2021 device_id = pcm_device_table[usecase][0];
2022 else
2023 device_id = pcm_device_table[usecase][1];
2024 return device_id;
2025}
2026
Haynes Mathew George98c95622014-06-20 19:14:25 -07002027static int find_index(const struct name_to_index * table, int32_t len,
2028 const char * name)
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002029{
2030 int ret = 0;
Haynes Mathew George98c95622014-06-20 19:14:25 -07002031 int32_t i;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002032
Haynes Mathew George98c95622014-06-20 19:14:25 -07002033 if (table == NULL) {
2034 ALOGE("%s: table is NULL", __func__);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002035 ret = -ENODEV;
2036 goto done;
2037 }
2038
Haynes Mathew George98c95622014-06-20 19:14:25 -07002039 if (name == NULL) {
2040 ALOGE("null key");
2041 ret = -ENODEV;
2042 goto done;
2043 }
2044
2045 for (i=0; i < len; i++) {
2046 if (!strcmp(table[i].name, name)) {
2047 ret = table[i].index;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002048 goto done;
2049 }
2050 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07002051 ALOGE("%s: Could not find index for name = %s",
2052 __func__, name);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002053 ret = -ENODEV;
2054done:
2055 return ret;
2056}
2057
Haynes Mathew George98c95622014-06-20 19:14:25 -07002058int platform_get_snd_device_index(char *device_name)
2059{
2060 return find_index(snd_device_name_index, SND_DEVICE_MAX, device_name);
2061}
2062
2063int platform_get_usecase_index(const char *usecase_name)
2064{
2065 return find_index(usecase_name_index, AUDIO_USECASE_MAX, usecase_name);
2066}
2067
keunhui.park2f7306a2015-07-16 16:48:06 +09002068void platform_add_operator_specific_device(snd_device_t snd_device,
2069 const char *operator,
2070 const char *mixer_path,
2071 unsigned int acdb_id)
2072{
2073 struct operator_specific_device *device;
2074
2075 if (operator_specific_device_table[snd_device] == NULL) {
2076 operator_specific_device_table[snd_device] =
2077 (struct listnode *)calloc(1, sizeof(struct listnode));
2078 list_init(operator_specific_device_table[snd_device]);
2079 }
2080
2081 device = (struct operator_specific_device *)calloc(1, sizeof(struct operator_specific_device));
2082
2083 device->operator = strdup(operator);
2084 device->mixer_path = strdup(mixer_path);
2085 device->acdb_id = acdb_id;
2086
2087 list_add_tail(operator_specific_device_table[snd_device], &device->list);
2088
Eric Laurent2bafff12016-03-17 12:17:23 -07002089 ALOGD("%s: device[%s] -> operator[%s] mixer_path[%s] acdb_id[%d]", __func__,
keunhui.park2f7306a2015-07-16 16:48:06 +09002090 platform_get_snd_device_name(snd_device), operator, mixer_path, acdb_id);
2091
2092}
2093
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002094int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
2095{
2096 int ret = 0;
2097
2098 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
2099 ALOGE("%s: Invalid snd_device = %d",
2100 __func__, snd_device);
2101 ret = -EINVAL;
2102 goto done;
2103 }
2104
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002105 ALOGV("%s: acdb_device_table[%s]: old = %d new = %d", __func__,
2106 platform_get_snd_device_name(snd_device), acdb_device_table[snd_device], acdb_id);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002107 acdb_device_table[snd_device] = acdb_id;
2108done:
2109 return ret;
2110}
2111
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07002112int platform_get_snd_device_acdb_id(snd_device_t snd_device)
2113{
2114 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
2115 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
2116 return -EINVAL;
2117 }
keunhui.park2f7306a2015-07-16 16:48:06 +09002118
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002119 /*
2120 * If speaker protection is enabled, function returns supported
2121 * sound device for speaker. Else same sound device is returned.
2122 */
2123 snd_device = audio_extn_get_spkr_prot_snd_device(snd_device);
2124
keunhui.park2f7306a2015-07-16 16:48:06 +09002125 if (operator_specific_device_table[snd_device] != NULL)
2126 return get_operator_specific_device_acdb_id(snd_device);
2127 else
2128 return acdb_device_table[snd_device];
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07002129}
2130
David Linee3fe402017-03-13 10:00:42 -07002131static int platform_get_backend_index(snd_device_t snd_device)
2132{
2133 int32_t port = DEFAULT_CODEC_BACKEND;
2134
2135 if (snd_device >= SND_DEVICE_OUT_BEGIN && snd_device < SND_DEVICE_OUT_END) {
2136 if (backend_tag_table[snd_device] != NULL) {
2137 if (strncmp(backend_tag_table[snd_device], "headphones",
2138 sizeof("headphones")) == 0)
2139 port = HEADPHONE_BACKEND;
2140 else if (strcmp(backend_tag_table[snd_device], "hdmi") == 0)
2141 port = HDMI_RX_BACKEND;
2142 else if ((strcmp(backend_tag_table[snd_device], "usb-headphones") == 0) ||
2143 (strcmp(backend_tag_table[snd_device], "usb-headset") == 0))
2144 port = USB_AUDIO_RX_BACKEND;
2145 }
2146 } else if (snd_device >= SND_DEVICE_IN_BEGIN && snd_device < SND_DEVICE_IN_END) {
2147 port = DEFAULT_CODEC_TX_BACKEND;
2148 if (backend_tag_table[snd_device] != NULL) {
2149 if (strcmp(backend_tag_table[snd_device], "usb-headset-mic") == 0)
2150 port = USB_AUDIO_TX_BACKEND;
2151 else if (strstr(backend_tag_table[snd_device], "bt-sco") != NULL)
2152 port = BT_SCO_TX_BACKEND;
2153 }
2154 } else {
2155 ALOGW("%s:napb: Invalid device - %d ", __func__, snd_device);
2156 }
2157
2158 ALOGV("%s:napb: backend port - %d device - %d ", __func__, port, snd_device);
2159
2160 return port;
2161}
2162
Eric Laurentb23d5282013-05-14 15:27:20 -07002163int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
2164{
2165 struct platform_data *my_data = (struct platform_data *)platform;
2166 int acdb_dev_id, acdb_dev_type;
2167
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002168 if (platform_supports_app_type_cfg()) // use v2 instead
2169 return -ENOSYS;
2170
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002171 acdb_dev_id = platform_get_snd_device_acdb_id(snd_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07002172 if (acdb_dev_id < 0) {
2173 ALOGE("%s: Could not find acdb id for device(%d)",
2174 __func__, snd_device);
2175 return -EINVAL;
2176 }
2177 if (my_data->acdb_send_audio_cal) {
Joe Onorato188b6222016-03-01 11:02:27 -08002178 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Eric Laurentb23d5282013-05-14 15:27:20 -07002179 __func__, snd_device, acdb_dev_id);
2180 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
2181 snd_device < SND_DEVICE_OUT_END)
2182 acdb_dev_type = ACDB_DEV_TYPE_OUT;
2183 else
2184 acdb_dev_type = ACDB_DEV_TYPE_IN;
2185 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
2186 }
2187 return 0;
2188}
2189
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002190int platform_send_audio_calibration_v2(void *platform, struct audio_usecase *usecase,
2191 int app_type, int sample_rate)
2192{
2193 struct platform_data *my_data = (struct platform_data *)platform;
2194 int acdb_dev_id, acdb_dev_type;
vivek mehta7e573672018-03-13 17:41:41 -07002195 int snd_device = usecase->out_snd_device;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002196 int new_snd_device[SND_DEVICE_OUT_END] = {0};
2197 int i, num_devices = 1;
2198
2199 if (!platform_supports_app_type_cfg()) // use v1 instead
2200 return -ENOSYS;
2201
vivek mehta7e573672018-03-13 17:41:41 -07002202 if ((usecase->type == PCM_HFP_CALL) || (usecase->type == PCM_CAPTURE))
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002203 snd_device = usecase->in_snd_device;
2204
2205 // skipped over get_spkr_prot_device
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002206 acdb_dev_id = platform_get_snd_device_acdb_id(snd_device);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002207 if (acdb_dev_id < 0) {
2208 ALOGE("%s: Could not find acdb id for device(%d)",
2209 __func__, snd_device);
2210 return -EINVAL;
2211 }
2212
2213 if (platform_can_split_snd_device(snd_device,
2214 &num_devices, new_snd_device) < 0) {
2215 new_snd_device[0] = snd_device;
2216 }
2217
2218 for (i = 0; i < num_devices; i++) {
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002219 acdb_dev_id = platform_get_snd_device_acdb_id(new_snd_device[i]);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002220 if (acdb_dev_id < 0) {
2221 ALOGE("%s: Could not find acdb id for device(%d)",
2222 __func__, new_snd_device[i]);
2223 return -EINVAL;
2224 }
2225 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
2226 __func__, new_snd_device[i], acdb_dev_id);
2227 if (new_snd_device[i] >= SND_DEVICE_OUT_BEGIN &&
2228 new_snd_device[i] < SND_DEVICE_OUT_END)
2229 acdb_dev_type = ACDB_DEV_TYPE_OUT;
2230 else
2231 acdb_dev_type = ACDB_DEV_TYPE_IN;
2232
2233 if (my_data->acdb_send_audio_cal_v3) {
2234 my_data->acdb_send_audio_cal_v3(acdb_dev_id, acdb_dev_type,
2235 app_type, sample_rate, i);
2236 } else if (my_data->acdb_send_audio_cal) {
2237 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type); // this version differs from internal
2238 }
2239 }
2240
2241 return 0;
2242}
2243
2244
Eric Laurentb23d5282013-05-14 15:27:20 -07002245int platform_switch_voice_call_device_pre(void *platform)
2246{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002247 struct platform_data *my_data = (struct platform_data *)platform;
2248 int ret = 0;
2249
2250 if (my_data->csd != NULL &&
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002251 voice_is_in_call(my_data->adev)) {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002252 /* This must be called before disabling mixer controls on APQ side */
2253 ret = my_data->csd->disable_device();
2254 if (ret < 0) {
2255 ALOGE("%s: csd_client_disable_device, failed, error %d",
2256 __func__, ret);
2257 }
2258 }
2259 return ret;
2260}
2261
2262int platform_switch_voice_call_enable_device_config(void *platform,
2263 snd_device_t out_snd_device,
2264 snd_device_t in_snd_device)
2265{
2266 struct platform_data *my_data = (struct platform_data *)platform;
2267 int acdb_rx_id, acdb_tx_id;
2268 int ret = 0;
2269
2270 if (my_data->csd == NULL)
2271 return ret;
2272
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002273 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
keunhui.park2f7306a2015-07-16 16:48:06 +09002274 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002275
2276 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
2277 ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
2278 if (ret < 0) {
2279 ALOGE("%s: csd_enable_device_config, failed, error %d",
2280 __func__, ret);
2281 }
2282 } else {
2283 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2284 acdb_rx_id, acdb_tx_id);
2285 }
2286
2287 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002288}
2289
2290int platform_switch_voice_call_device_post(void *platform,
2291 snd_device_t out_snd_device,
2292 snd_device_t in_snd_device)
2293{
2294 struct platform_data *my_data = (struct platform_data *)platform;
2295 int acdb_rx_id, acdb_tx_id;
2296
2297 if (my_data->acdb_send_voice_cal == NULL) {
2298 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
2299 } else {
keunhui.park2f7306a2015-07-16 16:48:06 +09002300 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
2301 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07002302
2303 if (acdb_rx_id > 0 && acdb_tx_id > 0)
2304 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
2305 else
2306 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2307 acdb_rx_id, acdb_tx_id);
2308 }
2309
2310 return 0;
2311}
2312
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002313int platform_switch_voice_call_usecase_route_post(void *platform,
2314 snd_device_t out_snd_device,
2315 snd_device_t in_snd_device)
2316{
2317 struct platform_data *my_data = (struct platform_data *)platform;
2318 int acdb_rx_id, acdb_tx_id;
2319 int ret = 0;
2320
2321 if (my_data->csd == NULL)
2322 return ret;
2323
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002324 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
keunhui.park2f7306a2015-07-16 16:48:06 +09002325 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002326
2327 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
2328 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
2329 my_data->adev->acdb_settings);
2330 if (ret < 0) {
2331 ALOGE("%s: csd_enable_device, failed, error %d", __func__, ret);
2332 }
2333 } else {
2334 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2335 acdb_rx_id, acdb_tx_id);
2336 }
2337
2338 return ret;
2339}
2340
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002341int platform_start_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07002342{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002343 struct platform_data *my_data = (struct platform_data *)platform;
2344 int ret = 0;
2345
2346 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002347 ret = my_data->csd->start_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002348 if (ret < 0) {
2349 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
2350 }
2351 }
2352 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002353}
2354
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002355int platform_stop_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07002356{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002357 struct platform_data *my_data = (struct platform_data *)platform;
2358 int ret = 0;
2359
2360 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002361 ret = my_data->csd->stop_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002362 if (ret < 0) {
2363 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
2364 }
2365 }
2366 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002367}
2368
Vignesh Kulothunganb6f0a9c2018-03-22 13:50:22 -07002369int platform_set_mic_break_det(void *platform, bool enable)
2370{
2371 int ret = 0;
2372 struct platform_data *my_data = (struct platform_data *)platform;
2373 struct audio_device *adev = my_data->adev;
2374 const char *mixer_ctl_name = "Voice Mic Break Enable";
2375 struct mixer_ctl *ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2376 if (!ctl) {
2377 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2378 __func__, mixer_ctl_name);
2379 return -EINVAL;
2380 }
2381
2382 ret = mixer_ctl_set_value(ctl, 0, enable);
2383 if(ret)
2384 ALOGE("%s: Failed to set mixer ctl: %s", __func__, mixer_ctl_name);
2385
2386 return ret;
2387}
2388
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002389int platform_get_sample_rate(void *platform, uint32_t *rate)
2390{
2391 struct platform_data *my_data = (struct platform_data *)platform;
2392 int ret = 0;
2393
2394 if (my_data->csd != NULL) {
2395 ret = my_data->csd->get_sample_rate(rate);
2396 if (ret < 0) {
2397 ALOGE("%s: csd_get_sample_rate error %d\n", __func__, ret);
2398 }
2399 }
2400 return ret;
2401}
2402
vivek mehtab6506412015-08-07 16:55:17 -07002403void platform_set_speaker_gain_in_combo(struct audio_device *adev,
2404 snd_device_t snd_device,
2405 bool enable)
2406{
2407 const char* name;
2408 switch (snd_device) {
2409 case SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES:
2410 if (enable)
2411 name = "spkr-gain-in-headphone-combo";
2412 else
2413 name = "speaker-gain-default";
2414 break;
2415 case SND_DEVICE_OUT_SPEAKER_AND_LINE:
2416 if (enable)
2417 name = "spkr-gain-in-line-combo";
2418 else
2419 name = "speaker-gain-default";
2420 break;
2421 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES:
2422 if (enable)
2423 name = "spkr-safe-gain-in-headphone-combo";
2424 else
2425 name = "speaker-safe-gain-default";
2426 break;
2427 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE:
2428 if (enable)
2429 name = "spkr-safe-gain-in-line-combo";
2430 else
2431 name = "speaker-safe-gain-default";
2432 break;
2433 default:
2434 return;
2435 }
2436
2437 audio_route_apply_and_update_path(adev->audio_route, name);
2438}
2439
Eric Laurentb23d5282013-05-14 15:27:20 -07002440int platform_set_voice_volume(void *platform, int volume)
2441{
2442 struct platform_data *my_data = (struct platform_data *)platform;
2443 struct audio_device *adev = my_data->adev;
2444 struct mixer_ctl *ctl;
sangwoo53b2cf02013-07-25 19:18:44 -07002445 const char *mixer_ctl_name = "Voice Rx Gain";
Nadav Barc46d0fa2017-12-24 14:50:37 +02002446 const char *mute_mixer_ctl_name = "Voice Rx Device Mute";
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002447 int vol_index = 0, ret = 0;
2448 uint32_t set_values[ ] = {0,
2449 ALL_SESSION_VSID,
2450 DEFAULT_VOLUME_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07002451
2452 // Voice volume levels are mapped to adsp volume levels as follows.
2453 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
2454 // But this values don't changed in kernel. So, below change is need.
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09002455 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, my_data->max_vol_index);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002456 set_values[0] = vol_index;
Eric Laurentb23d5282013-05-14 15:27:20 -07002457
2458 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2459 if (!ctl) {
2460 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2461 __func__, mixer_ctl_name);
2462 return -EINVAL;
2463 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002464 ALOGV("Setting voice volume index: %d", set_values[0]);
2465 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2466
Nadav Barc46d0fa2017-12-24 14:50:37 +02002467 // Send mute command in case volume index is max since indexes are inverted
2468 // for mixer controls.
2469 if (vol_index == my_data->max_vol_index) {
2470 set_values[0] = 1;
2471 }
2472 else {
2473 set_values[0] = 0;
2474 }
2475
2476 ctl = mixer_get_ctl_by_name(adev->mixer, mute_mixer_ctl_name);
2477 if (!ctl) {
2478 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2479 __func__, mute_mixer_ctl_name);
2480 return -EINVAL;
2481 }
2482 ALOGV("%s: Setting RX Device Mute to: %d", __func__, set_values[0]);
2483 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2484
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002485 if (my_data->csd != NULL) {
2486 ret = my_data->csd->volume(ALL_SESSION_VSID, volume,
2487 DEFAULT_VOLUME_RAMP_DURATION_MS);
2488 if (ret < 0) {
2489 ALOGE("%s: csd_volume error %d", __func__, ret);
2490 }
2491 }
2492 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002493}
2494
2495int platform_set_mic_mute(void *platform, bool state)
2496{
2497 struct platform_data *my_data = (struct platform_data *)platform;
2498 struct audio_device *adev = my_data->adev;
2499 struct mixer_ctl *ctl;
2500 const char *mixer_ctl_name = "Voice Tx Mute";
sangwoo53b2cf02013-07-25 19:18:44 -07002501 int ret = 0;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002502 uint32_t set_values[ ] = {0,
2503 ALL_SESSION_VSID,
2504 DEFAULT_MUTE_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07002505
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09002506 if (adev->mode != AUDIO_MODE_IN_CALL &&
2507 adev->mode != AUDIO_MODE_IN_COMMUNICATION)
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002508 return 0;
2509
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09002510 if (adev->enable_hfp)
2511 mixer_ctl_name = "HFP Tx Mute";
2512
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002513 set_values[0] = state;
2514 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2515 if (!ctl) {
2516 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2517 __func__, mixer_ctl_name);
2518 return -EINVAL;
2519 }
Arun Mirpuri0cc2f312018-05-29 17:26:07 -07002520 ALOGV("%s: Setting voice mute state: %d", __func__, state);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002521 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2522
2523 if (my_data->csd != NULL) {
2524 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state,
2525 DEFAULT_MUTE_RAMP_DURATION_MS);
sangwoo53b2cf02013-07-25 19:18:44 -07002526 if (ret < 0) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002527 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
sangwoo53b2cf02013-07-25 19:18:44 -07002528 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002529 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002530 return ret;
2531}
Eric Laurentb23d5282013-05-14 15:27:20 -07002532
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002533int platform_set_device_mute(void *platform, bool state, char *dir)
2534{
2535 struct platform_data *my_data = (struct platform_data *)platform;
2536 struct audio_device *adev = my_data->adev;
2537 struct mixer_ctl *ctl;
2538 char *mixer_ctl_name = NULL;
2539 int ret = 0;
2540 uint32_t set_values[ ] = {0,
2541 ALL_SESSION_VSID,
2542 0};
2543 if(dir == NULL) {
2544 ALOGE("%s: Invalid direction:%s", __func__, dir);
2545 return -EINVAL;
2546 }
2547
2548 if (!strncmp("rx", dir, sizeof("rx"))) {
2549 mixer_ctl_name = "Voice Rx Device Mute";
2550 } else if (!strncmp("tx", dir, sizeof("tx"))) {
2551 mixer_ctl_name = "Voice Tx Device Mute";
2552 } else {
2553 return -EINVAL;
2554 }
2555
2556 set_values[0] = state;
2557 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2558 if (!ctl) {
2559 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2560 __func__, mixer_ctl_name);
2561 return -EINVAL;
2562 }
2563
2564 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
2565 __func__,state, mixer_ctl_name);
2566 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2567
2568 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002569}
2570
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002571int platform_can_split_snd_device(snd_device_t snd_device,
2572 int *num_devices,
2573 snd_device_t *new_snd_devices)
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002574{
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002575 int ret = -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002576 if (NULL == num_devices || NULL == new_snd_devices) {
2577 ALOGE("%s: NULL pointer ..", __func__);
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002578 return -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002579 }
2580
2581 /*
2582 * If wired headset/headphones/line devices share the same backend
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002583 * with speaker/earpiece this routine returns -EINVAL.
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002584 */
2585 if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES &&
2586 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_HEADPHONES)) {
2587 *num_devices = 2;
2588 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2589 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002590 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002591 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_LINE &&
2592 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_LINE)) {
2593 *num_devices = 2;
2594 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2595 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002596 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002597 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES &&
2598 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_HEADPHONES)) {
2599 *num_devices = 2;
2600 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2601 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002602 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002603 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE &&
2604 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_LINE)) {
2605 *num_devices = 2;
2606 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2607 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002608 ret = 0;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002609 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO &&
2610 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2611 SND_DEVICE_OUT_BT_SCO)) {
2612 *num_devices = 2;
2613 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2614 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO;
2615 ret = 0;
juyuchen5351ea62018-05-16 10:54:37 +08002616 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO &&
2617 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE,
2618 SND_DEVICE_OUT_BT_SCO)) {
2619 *num_devices = 2;
2620 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2621 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO;
2622 ret = 0;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002623 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB &&
2624 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2625 SND_DEVICE_OUT_BT_SCO_WB)) {
2626 *num_devices = 2;
2627 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2628 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO_WB;
2629 ret = 0;
juyuchen5351ea62018-05-16 10:54:37 +08002630 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB &&
2631 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE,
2632 SND_DEVICE_OUT_BT_SCO_WB)) {
2633 *num_devices = 2;
2634 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2635 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO_WB;
2636 ret = 0;
David Linee3fe402017-03-13 10:00:42 -07002637 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET &&
2638 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_USB_HEADSET)) {
2639 *num_devices = 2;
2640 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2641 new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
2642 ret = 0;
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07002643 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET &&
2644 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_USB_HEADSET)) {
2645 *num_devices = 2;
2646 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2647 new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
2648 ret = 0;
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002649 } else if (SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP == snd_device &&
2650 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2651 SND_DEVICE_OUT_BT_A2DP)) {
2652 *num_devices = 2;
2653 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2654 new_snd_devices[1] = SND_DEVICE_OUT_BT_A2DP;
2655 ret = 0;
Aniket Kumar Lata9723a962018-05-16 17:41:55 -07002656 } else if (SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP == snd_device &&
2657 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE,
2658 SND_DEVICE_OUT_BT_A2DP)) {
2659 *num_devices = 2;
2660 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2661 new_snd_devices[1] = SND_DEVICE_OUT_BT_A2DP;
2662 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002663 }
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002664
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002665 return ret;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002666}
2667
Eric Laurentb23d5282013-05-14 15:27:20 -07002668snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
2669{
2670 struct platform_data *my_data = (struct platform_data *)platform;
2671 struct audio_device *adev = my_data->adev;
2672 audio_mode_t mode = adev->mode;
2673 snd_device_t snd_device = SND_DEVICE_NONE;
2674
2675 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
2676 if (devices == AUDIO_DEVICE_NONE ||
2677 devices & AUDIO_DEVICE_BIT_IN) {
2678 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
2679 goto exit;
2680 }
2681
Eric Laurent1b491552015-09-15 17:52:41 -07002682 if (popcount(devices) == 2) {
2683 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2684 AUDIO_DEVICE_OUT_SPEAKER) ||
2685 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2686 AUDIO_DEVICE_OUT_SPEAKER)) {
2687 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
2688 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2689 AUDIO_DEVICE_OUT_SPEAKER)) {
2690 snd_device = SND_DEVICE_OUT_SPEAKER_AND_LINE;
2691 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2692 AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
2693 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2694 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2695 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES;
2696 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2697 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2698 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE;
2699 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
2700 AUDIO_DEVICE_OUT_SPEAKER)) {
2701 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002702 } else if ((devices & AUDIO_DEVICE_OUT_ALL_SCO) &&
2703 ((devices & ~AUDIO_DEVICE_OUT_ALL_SCO) == AUDIO_DEVICE_OUT_SPEAKER)) {
2704 snd_device = adev->bt_wb_speech_enabled ?
2705 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB :
2706 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO;
juyuchen5351ea62018-05-16 10:54:37 +08002707 } else if ((devices & AUDIO_DEVICE_OUT_ALL_SCO) &&
2708 ((devices & ~AUDIO_DEVICE_OUT_ALL_SCO) == AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2709 snd_device = adev->bt_wb_speech_enabled ?
2710 SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB :
2711 SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO;
Eric Laurent99dab492017-06-17 15:19:08 -07002712 } else if ((devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
2713 AUDIO_DEVICE_OUT_SPEAKER)) ||
2714 (devices == (AUDIO_DEVICE_OUT_USB_HEADSET |
2715 AUDIO_DEVICE_OUT_SPEAKER))) {
David Linee3fe402017-03-13 10:00:42 -07002716 snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET;
Eric Laurentd0f7c262017-07-05 09:09:12 -07002717 } else if ((devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
2718 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) ||
2719 (devices == (AUDIO_DEVICE_OUT_USB_HEADSET |
2720 AUDIO_DEVICE_OUT_SPEAKER_SAFE))) {
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07002721 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET;
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002722 } else if ((devices & AUDIO_DEVICE_OUT_SPEAKER) &&
2723 (devices & AUDIO_DEVICE_OUT_ALL_A2DP)) {
2724 snd_device = SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP;
Aniket Kumar Lata9723a962018-05-16 17:41:55 -07002725 } else if ((devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) &&
2726 (devices & AUDIO_DEVICE_OUT_ALL_A2DP)) {
2727 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP;
Eric Laurent1b491552015-09-15 17:52:41 -07002728 } else {
2729 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
2730 goto exit;
2731 }
2732 if (snd_device != SND_DEVICE_NONE) {
2733 goto exit;
2734 }
2735 }
2736
2737 if (popcount(devices) != 1) {
2738 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
2739 goto exit;
2740 }
2741
Madhuri Athota3f6051b2016-10-13 23:25:38 +05302742 if (voice_is_in_call(adev) || adev->enable_voicerx || audio_extn_hfp_is_active(adev)) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002743 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002744 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2745 devices & AUDIO_DEVICE_OUT_LINE) {
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002746 if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002747 (adev->voice.tty_mode == TTY_MODE_FULL))
Eric Laurentb23d5282013-05-14 15:27:20 -07002748 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002749 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002750 (adev->voice.tty_mode == TTY_MODE_VCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002751 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002752 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002753 (adev->voice.tty_mode == TTY_MODE_HCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002754 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002755 else {
2756 if (devices & AUDIO_DEVICE_OUT_LINE)
2757 snd_device = SND_DEVICE_OUT_VOICE_LINE;
yixuanjiang9536e672018-09-06 18:43:36 +08002758 else if (devices & AUDIO_DEVICE_OUT_WIRED_HEADSET)
2759 snd_device = SND_DEVICE_OUT_VOICE_HEADSET;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002760 else
2761 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
2762 }
Eric Laurent99dab492017-06-17 15:19:08 -07002763 } else if (audio_is_usb_out_device(devices)) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002764 if (voice_is_in_call(adev)) {
2765 switch (adev->voice.tty_mode) {
2766 case TTY_MODE_FULL:
2767 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_USB;
2768 break;
2769 case TTY_MODE_VCO:
2770 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_USB;
2771 break;
2772 case TTY_MODE_HCO:
2773 // since Hearing will be on handset\speaker, use existing device
2774 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
2775 break;
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002776 case TTY_MODE_OFF:
2777 break;
vivek mehtaa6b79742017-03-09 15:40:43 -08002778 default:
2779 ALOGE("%s: Invalid TTY mode (%#x)",
2780 __func__, adev->voice.tty_mode);
2781 }
2782 }
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002783 if (snd_device == SND_DEVICE_NONE) {
2784 snd_device = audio_extn_usb_is_capture_supported() ?
2785 SND_DEVICE_OUT_VOICE_USB_HEADSET :
2786 SND_DEVICE_OUT_VOICE_USB_HEADPHONES;
2787 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002788 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002789 if (adev->bt_wb_speech_enabled) {
2790 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2791 } else {
2792 snd_device = SND_DEVICE_OUT_BT_SCO;
2793 }
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002794 } else if (devices & AUDIO_DEVICE_OUT_ALL_A2DP) {
2795 snd_device = SND_DEVICE_OUT_BT_A2DP;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002796 } else if (devices & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002797 if (!adev->enable_hfp) {
2798 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
2799 } else {
2800 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_HFP;
2801 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002802 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002803 if(adev->voice.hac)
2804 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2805 else if (is_operator_tmus())
Eric Laurentb23d5282013-05-14 15:27:20 -07002806 snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS;
2807 else
Eric Laurentb4d368e2014-06-25 10:21:54 -05002808 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002809 } else if (devices & AUDIO_DEVICE_OUT_TELEPHONY_TX)
2810 snd_device = SND_DEVICE_OUT_VOICE_TX;
2811
Eric Laurentb23d5282013-05-14 15:27:20 -07002812 if (snd_device != SND_DEVICE_NONE) {
2813 goto exit;
2814 }
2815 }
2816
Eric Laurentb23d5282013-05-14 15:27:20 -07002817 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2818 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2819 snd_device = SND_DEVICE_OUT_HEADPHONES;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002820 } else if (devices & AUDIO_DEVICE_OUT_LINE) {
2821 snd_device = SND_DEVICE_OUT_LINE;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002822 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) {
2823 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE;
Eric Laurentb23d5282013-05-14 15:27:20 -07002824 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
andysu5b30b062018-04-20 16:34:06 +08002825 /*
2826 * Perform device switch only if acdb tuning is different between SPEAKER & SPEAKER_REVERSE,
2827 * Or there will be a small pause while performing device switch.
2828 */
2829 if (my_data->speaker_lr_swap &&
2830 (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
2831 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]))
Eric Laurentb23d5282013-05-14 15:27:20 -07002832 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
2833 else
2834 snd_device = SND_DEVICE_OUT_SPEAKER;
2835 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002836 if (adev->bt_wb_speech_enabled) {
2837 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2838 } else {
2839 snd_device = SND_DEVICE_OUT_BT_SCO;
2840 }
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002841 } else if (devices & AUDIO_DEVICE_OUT_ALL_A2DP) {
2842 snd_device = SND_DEVICE_OUT_BT_A2DP;
Eric Laurentb23d5282013-05-14 15:27:20 -07002843 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2844 snd_device = SND_DEVICE_OUT_HDMI ;
Eric Laurent99dab492017-06-17 15:19:08 -07002845 } else if (audio_is_usb_out_device(devices)) {
jasmine cha270b7762018-03-30 15:41:33 +08002846 if (audio_extn_ma_supported_usb())
2847 snd_device = SND_DEVICE_OUT_USB_HEADSET_SPEC;
2848 else if (audio_extn_usb_is_capture_supported())
David Linee3fe402017-03-13 10:00:42 -07002849 snd_device = SND_DEVICE_OUT_USB_HEADSET;
2850 else
2851 snd_device = SND_DEVICE_OUT_USB_HEADPHONES;
2852 }else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002853 /*HAC support for voice-ish audio (eg visual voicemail)*/
2854 if(adev->voice.hac)
2855 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2856 else
2857 snd_device = SND_DEVICE_OUT_HANDSET;
Eric Laurentb23d5282013-05-14 15:27:20 -07002858 } else {
2859 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
2860 }
2861exit:
2862 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
2863 return snd_device;
2864}
2865
2866snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
2867{
2868 struct platform_data *my_data = (struct platform_data *)platform;
2869 struct audio_device *adev = my_data->adev;
2870 audio_source_t source = (adev->active_input == NULL) ?
2871 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
2872
2873 audio_mode_t mode = adev->mode;
2874 audio_devices_t in_device = ((adev->active_input == NULL) ?
2875 AUDIO_DEVICE_NONE : adev->active_input->device)
2876 & ~AUDIO_DEVICE_BIT_IN;
2877 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
2878 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
2879 snd_device_t snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002880 int channel_count = popcount(channel_mask);
Eric Laurentb23d5282013-05-14 15:27:20 -07002881
Prashant Malanic92c5962015-08-11 15:10:18 -07002882 ALOGV("%s: enter: out_device(%#x) in_device(%#x) channel_count (%d) channel_mask (0x%x)",
2883 __func__, out_device, in_device, channel_count, channel_mask);
Devin Kimd789e432016-10-26 15:07:27 -07002884 if ((out_device != AUDIO_DEVICE_NONE) && (voice_is_in_call(adev) ||
2885 audio_extn_hfp_is_active(adev))) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002886 if (adev->voice.tty_mode != TTY_MODE_OFF) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002887 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002888 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2889 out_device & AUDIO_DEVICE_OUT_LINE) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002890 switch (adev->voice.tty_mode) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002891 case TTY_MODE_FULL:
2892 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
2893 break;
2894 case TTY_MODE_VCO:
2895 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
2896 break;
2897 case TTY_MODE_HCO:
2898 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
2899 break;
2900 default:
2901 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
2902 }
2903 goto exit;
Eric Laurent99dab492017-06-17 15:19:08 -07002904 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002905 switch (adev->voice.tty_mode) {
2906 case TTY_MODE_FULL:
2907 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC;
2908 break;
2909 case TTY_MODE_VCO:
2910 // since voice will be captured from handset mic, use existing device
2911 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
2912 break;
2913 case TTY_MODE_HCO:
2914 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC;
2915 break;
2916 default:
2917 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
Eric Laurentb23d5282013-05-14 15:27:20 -07002918 }
2919 goto exit;
2920 }
2921 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002922 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002923 if (my_data->fluence_in_voice_call == false) {
2924 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2925 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002926 if (is_operator_tmus())
2927 snd_device = SND_DEVICE_IN_VOICE_DMIC_TMUS;
Eric Laurentb23d5282013-05-14 15:27:20 -07002928 else
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002929 snd_device = SND_DEVICE_IN_VOICE_DMIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002930 }
2931 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2932 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
2933 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002934 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002935 if (adev->bluetooth_nrec)
2936 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2937 else
2938 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002939 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002940 if (adev->bluetooth_nrec)
2941 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2942 else
2943 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002944 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002945 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Prashant Malanic92c5962015-08-11 15:10:18 -07002946 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
2947 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2948 out_device & AUDIO_DEVICE_OUT_LINE) {
2949 if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
2950 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
2951 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
2952 } else {
2953 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2954 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002955 }
vivek mehtafe121d52015-08-10 23:39:23 -07002956
2957 //select default
2958 if (snd_device == SND_DEVICE_NONE) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002959 if (!adev->enable_hfp) {
2960 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2961 } else {
2962 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP;
2963 platform_set_echo_reference(adev, true, out_device);
2964 }
vivek mehtafe121d52015-08-10 23:39:23 -07002965 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002966 } else if (out_device & AUDIO_DEVICE_OUT_TELEPHONY_TX) {
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002967 snd_device = SND_DEVICE_IN_VOICE_RX;
Eric Laurent99dab492017-06-17 15:19:08 -07002968 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
David Lin40b07892017-08-07 15:02:48 -07002969 if (audio_extn_usb_is_capture_supported()) {
2970 snd_device = SND_DEVICE_IN_VOICE_USB_HEADSET_MIC;
2971 } else if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
2972 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
2973 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
2974 } else {
2975 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2976 }
2977 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002978 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002979 } else if (source == AUDIO_SOURCE_CAMCORDER) {
2980 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
2981 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Eric Laurent5f4ca952018-10-19 17:33:43 -07002982 switch (adev->camera_orientation) {
2983 case CAMERA_BACK_LANDSCAPE:
2984 snd_device = SND_DEVICE_IN_CAMCORDER_LANDSCAPE;
2985 break;
2986 case CAMERA_BACK_INVERT_LANDSCAPE:
2987 snd_device = SND_DEVICE_IN_CAMCORDER_INVERT_LANDSCAPE;
2988 break;
2989 case CAMERA_BACK_PORTRAIT:
2990 snd_device = SND_DEVICE_IN_CAMCORDER_PORTRAIT;
2991 break;
2992 case CAMERA_FRONT_LANDSCAPE:
2993 snd_device = SND_DEVICE_IN_CAMCORDER_SELFIE_LANDSCAPE;
2994 break;
2995 case CAMERA_FRONT_INVERT_LANDSCAPE:
2996 snd_device = SND_DEVICE_IN_CAMCORDER_SELFIE_INVERT_LANDSCAPE;
2997 break;
2998 case CAMERA_FRONT_PORTRAIT:
2999 snd_device = SND_DEVICE_IN_CAMCORDER_SELFIE_PORTRAIT;
3000 break;
3001 default:
3002 ALOGW("%s: invalid camera orientation %08x", __func__, adev->camera_orientation);
3003 snd_device = SND_DEVICE_IN_CAMCORDER_LANDSCAPE;
3004 break;
3005 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003006 }
3007 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
3008 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003009 if (my_data->fluence_in_voice_rec && channel_count == 1) {
3010 if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
3011 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07003012 if (adev->active_input->enable_aec)
3013 snd_device = SND_DEVICE_IN_HANDSET_QMIC_AEC;
3014 else
3015 snd_device = SND_DEVICE_IN_HANDSET_QMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003016 } else if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
3017 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07003018 if (adev->active_input->enable_aec)
3019 snd_device = SND_DEVICE_IN_HANDSET_TMIC_AEC;
3020 else
3021 snd_device = SND_DEVICE_IN_HANDSET_TMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003022 } else if (((my_data->fluence_type == FLUENCE_PRO_ENABLE) ||
3023 (my_data->fluence_type == FLUENCE_ENABLE)) &&
3024 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07003025 if (adev->active_input->enable_aec)
3026 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
3027 else
3028 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
Prashant Malanic92c5962015-08-11 15:10:18 -07003029 }
3030 platform_set_echo_reference(adev, true, out_device);
3031 } else if ((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) &&
3032 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
3033 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003034 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003035 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
3036 snd_device = SND_DEVICE_IN_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003037 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003038 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
3039 snd_device = SND_DEVICE_IN_QUAD_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07003040 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003041 if (snd_device == SND_DEVICE_NONE) {
vivek mehtaf3440682016-05-11 14:24:37 -07003042 if (adev->active_input->enable_aec) {
3043 if (adev->active_input->enable_ns) {
3044 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS;
3045 } else {
3046 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC;
3047 }
vivek mehta733c1df2016-04-04 15:09:24 -07003048 platform_set_echo_reference(adev, true, out_device);
vivek mehtaf3440682016-05-11 14:24:37 -07003049 } else if (adev->active_input->enable_ns) {
3050 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
3051 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003052 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
vivek mehtaf3440682016-05-11 14:24:37 -07003053 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003054 }
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -07003055 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3056 snd_device = SND_DEVICE_IN_VOICE_REC_HEADSET_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07003057 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07003058 snd_device = SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07003059 }
rago90fb9612015-12-02 11:37:53 -08003060 } else if (source == AUDIO_SOURCE_UNPROCESSED) {
3061 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
vivek mehta4ed66e62016-04-15 23:33:34 -07003062 if (((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) ||
3063 (channel_mask == AUDIO_CHANNEL_IN_STEREO)) &&
3064 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
3065 snd_device = SND_DEVICE_IN_UNPROCESSED_STEREO_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003066 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07003067 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
3068 snd_device = SND_DEVICE_IN_UNPROCESSED_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003069 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07003070 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
3071 snd_device = SND_DEVICE_IN_UNPROCESSED_QUAD_MIC;
3072 } else {
3073 snd_device = SND_DEVICE_IN_UNPROCESSED_MIC;
3074 }
rago90fb9612015-12-02 11:37:53 -08003075 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3076 snd_device = SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07003077 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07003078 snd_device = SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC;
rago90fb9612015-12-02 11:37:53 -08003079 }
Eric Laurent50a38ed2015-10-14 18:48:06 -07003080 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION ||
rago90fb9612015-12-02 11:37:53 -08003081 mode == AUDIO_MODE_IN_COMMUNICATION) {
David Lin40b07892017-08-07 15:02:48 -07003082 if (out_device & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
3083 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
3084 (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE | AUDIO_DEVICE_OUT_USB_HEADSET) &&
3085 !audio_extn_usb_is_capture_supported())) {
Eric Laurentb23d5282013-05-14 15:27:20 -07003086 in_device = AUDIO_DEVICE_IN_BACK_MIC;
David Lin40b07892017-08-07 15:02:48 -07003087 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003088 if (adev->active_input) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003089 if (adev->active_input->enable_aec &&
3090 adev->active_input->enable_ns) {
Eric Laurentb23d5282013-05-14 15:27:20 -07003091 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003092 if (my_data->fluence_in_spkr_mode &&
3093 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003094 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003095 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003096 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003097 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003098 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003099 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003100 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003101 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003102 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003103 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003104 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003105 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05003106 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3107 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Eric Laurent99dab492017-06-17 15:19:08 -07003108 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07003109 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
Eric Laurentb23d5282013-05-14 15:27:20 -07003110 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05003111 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003112 } else if (adev->active_input->enable_aec) {
3113 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
3114 if (my_data->fluence_in_spkr_mode &&
3115 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003116 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003117 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003118 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003119 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003120 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003121 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
3122 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003123 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003124 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003125 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003126 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003127 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05003128 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3129 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Eric Laurent99dab492017-06-17 15:19:08 -07003130 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07003131 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
Eric Laurentcefbbac2014-09-04 13:54:10 -05003132 }
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08003133 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003134 } else if (adev->active_input->enable_ns) {
3135 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
3136 if (my_data->fluence_in_spkr_mode &&
3137 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003138 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003139 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003140 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003141 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003142 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003143 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
3144 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003145 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003146 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003147 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003148 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003149 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003150 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05003151 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003152 }
3153 } else if (source == AUDIO_SOURCE_DEFAULT) {
3154 goto exit;
3155 }
3156
3157
3158 if (snd_device != SND_DEVICE_NONE) {
3159 goto exit;
3160 }
3161
3162 if (in_device != AUDIO_DEVICE_NONE &&
3163 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
3164 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
3165 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003166 if ((my_data->source_mic_type & SOURCE_QUAD_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003167 channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003168 snd_device = SND_DEVICE_IN_QUAD_MIC;
3169 } else if ((my_data->source_mic_type & SOURCE_THREE_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003170 channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003171 snd_device = SND_DEVICE_IN_THREE_MIC;
3172 } else if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
3173 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003174 snd_device = SND_DEVICE_IN_HANDSET_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07003175 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
3176 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003177 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003178 } else {
3179 ALOGE("%s: something wrong (1): source type (%d) channel_count (%d) .."
3180 " channel mask (0x%x) no combination found .. setting to mono", __func__,
3181 my_data->source_mic_type, channel_count, channel_mask);
3182 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3183 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003184 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003185 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
3186 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003187 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07003188 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
3189 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003190 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003191 } else {
3192 ALOGE("%s: something wrong (2): source type (%d) channel_count (%d) .."
3193 " no combination found .. setting to mono", __func__,
3194 my_data->source_mic_type, channel_count);
3195 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
3196 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003197 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3198 snd_device = SND_DEVICE_IN_HEADSET_MIC;
3199 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003200 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003201 if (adev->bluetooth_nrec)
3202 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
3203 else
3204 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003205 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003206 if (adev->bluetooth_nrec)
3207 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
3208 else
3209 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003210 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003211 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
3212 snd_device = SND_DEVICE_IN_HDMI_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07003213 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
David Linee3fe402017-03-13 10:00:42 -07003214 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07003215 } else {
3216 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
3217 ALOGW("%s: Using default handset-mic", __func__);
3218 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3219 }
3220 } else {
3221 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
3222 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3223 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
3224 snd_device = SND_DEVICE_IN_HEADSET_MIC;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003225 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07003226 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003227 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05003228 out_device & AUDIO_DEVICE_OUT_LINE) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003229 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
3230 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003231 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07003232 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
3233 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003234 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003235 } else {
3236 ALOGE("%s: something wrong (3): source type (%d) channel_count (%d) .."
3237 " no combination found .. setting to mono", __func__,
3238 my_data->source_mic_type, channel_count);
3239 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
3240 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003241 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003242 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003243 if (adev->bluetooth_nrec)
3244 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
3245 else
3246 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003247 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003248 if (adev->bluetooth_nrec)
3249 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
3250 else
3251 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003252 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003253 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
3254 snd_device = SND_DEVICE_IN_HDMI_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07003255 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
David Linee3fe402017-03-13 10:00:42 -07003256 if (audio_extn_usb_is_capture_supported())
3257 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
3258 else
3259 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07003260 } else {
3261 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
3262 ALOGW("%s: Using default handset-mic", __func__);
3263 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3264 }
3265 }
3266exit:
3267 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
3268 return snd_device;
3269}
3270
3271int platform_set_hdmi_channels(void *platform, int channel_count)
3272{
3273 struct platform_data *my_data = (struct platform_data *)platform;
3274 struct audio_device *adev = my_data->adev;
3275 struct mixer_ctl *ctl;
3276 const char *channel_cnt_str = NULL;
3277 const char *mixer_ctl_name = "HDMI_RX Channels";
3278 switch (channel_count) {
3279 case 8:
3280 channel_cnt_str = "Eight"; break;
3281 case 7:
3282 channel_cnt_str = "Seven"; break;
3283 case 6:
3284 channel_cnt_str = "Six"; break;
3285 case 5:
3286 channel_cnt_str = "Five"; break;
3287 case 4:
3288 channel_cnt_str = "Four"; break;
3289 case 3:
3290 channel_cnt_str = "Three"; break;
3291 default:
3292 channel_cnt_str = "Two"; break;
3293 }
3294 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3295 if (!ctl) {
3296 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3297 __func__, mixer_ctl_name);
3298 return -EINVAL;
3299 }
3300 ALOGV("HDMI channel count: %s", channel_cnt_str);
3301 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
3302 return 0;
3303}
3304
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003305int platform_edid_get_max_channels(void *platform)
Eric Laurentb23d5282013-05-14 15:27:20 -07003306{
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003307 struct platform_data *my_data = (struct platform_data *)platform;
3308 struct audio_device *adev = my_data->adev;
Eric Laurentb23d5282013-05-14 15:27:20 -07003309 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
3310 char *sad = block;
3311 int num_audio_blocks;
3312 int channel_count;
3313 int max_channels = 0;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003314 int i, ret, count;
Eric Laurentb23d5282013-05-14 15:27:20 -07003315
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003316 struct mixer_ctl *ctl;
3317
3318 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
3319 if (!ctl) {
3320 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3321 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
Eric Laurentb23d5282013-05-14 15:27:20 -07003322 return 0;
3323 }
3324
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003325 mixer_ctl_update(ctl);
3326
3327 count = mixer_ctl_get_num_values(ctl);
Eric Laurentb23d5282013-05-14 15:27:20 -07003328
3329 /* Read SAD blocks, clamping the maximum size for safety */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003330 if (count > (int)sizeof(block))
3331 count = (int)sizeof(block);
Eric Laurentb23d5282013-05-14 15:27:20 -07003332
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003333 ret = mixer_ctl_get_array(ctl, block, count);
3334 if (ret != 0) {
3335 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
3336 return 0;
3337 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003338
3339 /* Calculate the number of SAD blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003340 num_audio_blocks = count / SAD_BLOCK_SIZE;
Eric Laurentb23d5282013-05-14 15:27:20 -07003341
3342 for (i = 0; i < num_audio_blocks; i++) {
3343 /* Only consider LPCM blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003344 if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
3345 sad += 3;
Eric Laurentb23d5282013-05-14 15:27:20 -07003346 continue;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003347 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003348
3349 channel_count = (sad[0] & 0x7) + 1;
3350 if (channel_count > max_channels)
3351 max_channels = channel_count;
3352
3353 /* Advance to next block */
3354 sad += 3;
3355 }
3356
3357 return max_channels;
3358}
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003359
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07003360int platform_set_incall_recording_session_id(void *platform,
3361 uint32_t session_id, int rec_mode)
3362{
3363 int ret = 0;
3364 struct platform_data *my_data = (struct platform_data *)platform;
3365 struct audio_device *adev = my_data->adev;
3366 struct mixer_ctl *ctl;
3367 const char *mixer_ctl_name = "Voc VSID";
3368 int num_ctl_values;
3369 int i;
3370
3371 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3372 if (!ctl) {
3373 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3374 __func__, mixer_ctl_name);
3375 ret = -EINVAL;
3376 } else {
3377 num_ctl_values = mixer_ctl_get_num_values(ctl);
3378 for (i = 0; i < num_ctl_values; i++) {
3379 if (mixer_ctl_set_value(ctl, i, session_id)) {
3380 ALOGV("Error: invalid session_id: %x", session_id);
3381 ret = -EINVAL;
3382 break;
3383 }
3384 }
3385 }
3386
3387 if (my_data->csd != NULL) {
3388 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
3389 if (ret < 0) {
3390 ALOGE("%s: csd_client_start_record failed, error %d",
3391 __func__, ret);
3392 }
3393 }
3394
3395 return ret;
3396}
3397
Arun Mirpuriba2749a2018-04-17 14:32:24 -07003398int platform_set_incall_recording_session_channels(void *platform,
3399 uint32_t channel_count)
3400{
3401 int ret = 0;
3402 struct platform_data *my_data = (struct platform_data *)platform;
3403 struct audio_device *adev = my_data->adev;
3404 const char *mixer_ctl_name = "Voc Rec Config";
3405 int num_ctl_values;
3406 int i;
3407 struct mixer_ctl *ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3408
3409 if (!ctl) {
3410 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3411 __func__, mixer_ctl_name);
3412 ret = -EINVAL;
3413 } else {
3414 num_ctl_values = mixer_ctl_get_num_values(ctl);
3415 for (i = 0; i < num_ctl_values; i++) {
3416 if (mixer_ctl_set_value(ctl, i, channel_count)) {
3417 ALOGE("Error: invalid channel count: %x", channel_count);
3418 ret = -EINVAL;
3419 break;
3420 }
3421 }
3422 }
3423
3424 return ret;
3425}
3426
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07003427int platform_stop_incall_recording_usecase(void *platform)
3428{
3429 int ret = 0;
3430 struct platform_data *my_data = (struct platform_data *)platform;
3431
3432 if (my_data->csd != NULL) {
3433 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
3434 if (ret < 0) {
3435 ALOGE("%s: csd_client_stop_record failed, error %d",
3436 __func__, ret);
3437 }
3438 }
3439
3440 return ret;
3441}
3442
3443int platform_start_incall_music_usecase(void *platform)
3444{
3445 int ret = 0;
3446 struct platform_data *my_data = (struct platform_data *)platform;
3447
3448 if (my_data->csd != NULL) {
3449 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
3450 if (ret < 0) {
3451 ALOGE("%s: csd_client_start_playback failed, error %d",
3452 __func__, ret);
3453 }
3454 }
3455
3456 return ret;
3457}
3458
3459int platform_stop_incall_music_usecase(void *platform)
3460{
3461 int ret = 0;
3462 struct platform_data *my_data = (struct platform_data *)platform;
3463
3464 if (my_data->csd != NULL) {
3465 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
3466 if (ret < 0) {
3467 ALOGE("%s: csd_client_stop_playback failed, error %d",
3468 __func__, ret);
3469 }
3470 }
3471
3472 return ret;
3473}
3474
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003475int platform_set_parameters(void *platform, struct str_parms *parms)
3476{
3477 struct platform_data *my_data = (struct platform_data *)platform;
jasmine chac89321b2018-04-10 21:37:01 +08003478 char *value = NULL;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003479 char *kv_pairs = str_parms_to_str(parms);
jasmine chac89321b2018-04-10 21:37:01 +08003480 int len;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003481 int ret = 0, err;
3482
3483 if (kv_pairs == NULL) {
3484 ret = -EINVAL;
Jasmine Chaa314e192018-05-09 17:46:28 +08003485 ALOGE("%s: key-value pair is NULL", __func__);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003486 goto done;
3487 }
3488
3489 ALOGV("%s: enter: %s", __func__, kv_pairs);
3490
jasmine chac89321b2018-04-10 21:37:01 +08003491 len = strlen(kv_pairs);
Jasmine Chaa314e192018-05-09 17:46:28 +08003492 value = (char*)calloc(len + 1, sizeof(char));
jasmine chac89321b2018-04-10 21:37:01 +08003493 if (value == NULL) {
3494 ret = -ENOMEM;
Jasmine Chaa314e192018-05-09 17:46:28 +08003495 ALOGE("[%s] failed to allocate memory", __func__);
jasmine chac89321b2018-04-10 21:37:01 +08003496 goto done;
3497 }
3498
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003499 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME,
jasmine chac89321b2018-04-10 21:37:01 +08003500 value, len);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003501 if (err >= 0) {
3502 str_parms_del(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME);
3503 my_data->snd_card_name = strdup(value);
3504 ALOGV("%s: sound card name %s", __func__, my_data->snd_card_name);
3505 }
3506
keunhui.park2f7306a2015-07-16 16:48:06 +09003507 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO,
jasmine chac89321b2018-04-10 21:37:01 +08003508 value, len);
keunhui.park2f7306a2015-07-16 16:48:06 +09003509 if (err >= 0) {
3510 struct operator_info *info;
3511 char *str = value;
3512 char *name;
3513
3514 str_parms_del(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO);
3515 info = (struct operator_info *)calloc(1, sizeof(struct operator_info));
3516 name = strtok(str, ";");
3517 info->name = strdup(name);
3518 info->mccmnc = strdup(str + strlen(name) + 1);
3519
3520 list_add_tail(&operator_info_list, &info->list);
Joe Onorato188b6222016-03-01 11:02:27 -08003521 ALOGV("%s: add operator[%s] mccmnc[%s]", __func__, info->name, info->mccmnc);
keunhui.park2f7306a2015-07-16 16:48:06 +09003522 }
Prashant Malanic92c5962015-08-11 15:10:18 -07003523
Jasmine Chaa314e192018-05-09 17:46:28 +08003524 memset(value, 0, len + 1);
Eric Laurentc6333382015-09-14 12:43:44 -07003525 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT,
jasmine chac89321b2018-04-10 21:37:01 +08003526 value, len);
Prashant Malanic92c5962015-08-11 15:10:18 -07003527 if (err >= 0) {
Eric Laurentc6333382015-09-14 12:43:44 -07003528 str_parms_del(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT);
Prashant Malanic92c5962015-08-11 15:10:18 -07003529 my_data->max_mic_count = atoi(value);
3530 ALOGV("%s: max_mic_count %s/%d", __func__, value, my_data->max_mic_count);
Prashant Malanic92c5962015-08-11 15:10:18 -07003531 }
3532
jasmine chac89321b2018-04-10 21:37:01 +08003533 /* handle audio calibration parameters */
3534 set_audiocal(platform, parms, value, len);
3535
vivek mehta90933872017-06-15 18:04:39 -07003536 // to-do: disable setting sidetone gain, will revist this later
3537 // audio_extn_usb_set_sidetone_gain(parms, value, len);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003538done:
3539 ALOGV("%s: exit with code(%d)", __func__, ret);
3540 if (kv_pairs != NULL)
3541 free(kv_pairs);
jasmine chac89321b2018-04-10 21:37:01 +08003542 if (value != NULL)
3543 free(value);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003544
3545 return ret;
3546}
3547
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003548/* Delay in Us */
3549int64_t platform_render_latency(audio_usecase_t usecase)
3550{
3551 switch (usecase) {
3552 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
3553 return DEEP_BUFFER_PLATFORM_DELAY;
3554 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
3555 return LOW_LATENCY_PLATFORM_DELAY;
Haynes Mathew George03c40102016-01-29 17:57:48 -08003556 case USECASE_AUDIO_PLAYBACK_ULL:
3557 return ULL_PLATFORM_DELAY;
Eric Laurent0e46adf2016-12-16 12:49:24 -08003558 case USECASE_AUDIO_PLAYBACK_MMAP:
3559 return MMAP_PLATFORM_DELAY;
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003560 default:
3561 return 0;
3562 }
3563}
Haynes Mathew George98c95622014-06-20 19:14:25 -07003564
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003565int platform_set_snd_device_backend(snd_device_t device, const char *backend_tag,
3566 const char * hw_interface)
Haynes Mathew George98c95622014-06-20 19:14:25 -07003567{
3568 int ret = 0;
3569
3570 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
3571 ALOGE("%s: Invalid snd_device = %d",
3572 __func__, device);
3573 ret = -EINVAL;
3574 goto done;
3575 }
3576
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003577 ALOGV("%s: backend_tag_table[%s]: old = %s new = %s", __func__,
3578 platform_get_snd_device_name(device),
3579 backend_tag_table[device] != NULL ? backend_tag_table[device]: "null", backend_tag);
3580 if (backend_tag_table[device]) {
3581 free(backend_tag_table[device]);
Haynes Mathew George98c95622014-06-20 19:14:25 -07003582 }
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003583 backend_tag_table[device] = strdup(backend_tag);
3584
3585 if (hw_interface != NULL) {
3586 if (hw_interface_table[device])
3587 free(hw_interface_table[device]);
3588 ALOGV("%s: hw_interface_table[%d] = %s", __func__, device, hw_interface);
3589 hw_interface_table[device] = strdup(hw_interface);
3590 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07003591done:
3592 return ret;
3593}
3594
3595int platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t pcm_id)
3596{
3597 int ret = 0;
3598 if ((usecase <= USECASE_INVALID) || (usecase >= AUDIO_USECASE_MAX)) {
3599 ALOGE("%s: invalid usecase case idx %d", __func__, usecase);
3600 ret = -EINVAL;
3601 goto done;
3602 }
3603
3604 if ((type != 0) && (type != 1)) {
3605 ALOGE("%s: invalid usecase type", __func__);
3606 ret = -EINVAL;
3607 }
vivek mehtaa68fea62017-06-08 19:04:02 -07003608 ALOGV("%s: pcm_device_table[%d %s][%d] = %d", __func__, usecase,
3609 use_case_table[usecase],
3610 type, pcm_id);
Haynes Mathew George98c95622014-06-20 19:14:25 -07003611 pcm_device_table[usecase][type] = pcm_id;
3612done:
3613 return ret;
3614}
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003615
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07003616#define DEFAULT_NOMINAL_SPEAKER_GAIN 20
3617int ramp_speaker_gain(struct audio_device *adev, bool ramp_up, int target_ramp_up_gain) {
3618 // backup_gain: gain to try to set in case of an error during ramp
3619 int start_gain, end_gain, step, backup_gain, i;
3620 bool error = false;
3621 const struct mixer_ctl *ctl;
3622 const char *mixer_ctl_name_gain_left = "Left Speaker Gain";
3623 const char *mixer_ctl_name_gain_right = "Right Speaker Gain";
3624 struct mixer_ctl *ctl_left = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_left);
3625 struct mixer_ctl *ctl_right = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_right);
3626 if (!ctl_left || !ctl_right) {
3627 ALOGE("%s: Could not get ctl for mixer cmd - %s or %s, not applying speaker gain ramp",
3628 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
3629 return -EINVAL;
3630 } else if ((mixer_ctl_get_num_values(ctl_left) != 1)
3631 || (mixer_ctl_get_num_values(ctl_right) != 1)) {
3632 ALOGE("%s: Unexpected num values for mixer cmd - %s or %s, not applying speaker gain ramp",
3633 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
3634 return -EINVAL;
3635 }
3636 if (ramp_up) {
3637 start_gain = 0;
3638 end_gain = target_ramp_up_gain > 0 ? target_ramp_up_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
3639 step = +1;
3640 backup_gain = end_gain;
3641 } else {
3642 // using same gain on left and right
3643 const int left_gain = mixer_ctl_get_value(ctl_left, 0);
3644 start_gain = left_gain > 0 ? left_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
3645 end_gain = 0;
3646 step = -1;
3647 backup_gain = start_gain;
3648 }
3649 for (i = start_gain ; i != (end_gain + step) ; i += step) {
3650 //ALOGV("setting speaker gain to %d", i);
3651 if (mixer_ctl_set_value(ctl_left, 0, i)) {
3652 ALOGE("%s: error setting %s to %d during gain ramp",
3653 __func__, mixer_ctl_name_gain_left, i);
3654 error = true;
3655 break;
3656 }
3657 if (mixer_ctl_set_value(ctl_right, 0, i)) {
3658 ALOGE("%s: error setting %s to %d during gain ramp",
3659 __func__, mixer_ctl_name_gain_right, i);
3660 error = true;
3661 break;
3662 }
3663 usleep(1000);
3664 }
3665 if (error) {
3666 // an error occured during the ramp, let's still try to go back to a safe volume
3667 if (mixer_ctl_set_value(ctl_left, 0, backup_gain)) {
3668 ALOGE("%s: error restoring left gain to %d", __func__, backup_gain);
3669 }
3670 if (mixer_ctl_set_value(ctl_right, 0, backup_gain)) {
3671 ALOGE("%s: error restoring right gain to %d", __func__, backup_gain);
3672 }
3673 }
3674 return start_gain;
3675}
3676
vivek mehtae59cfb22017-06-16 15:57:11 -07003677int platform_set_swap_mixer(struct audio_device *adev, bool swap_channels)
3678{
3679 const char *mixer_ctl_name = "Swap channel";
3680 struct mixer_ctl *ctl;
3681 const char *mixer_path;
3682 struct platform_data *my_data = (struct platform_data *)adev->platform;
3683
3684 // forced to set to swap, but device not rotated ... ignore set
3685 if (swap_channels && !my_data->speaker_lr_swap)
3686 return 0;
3687
3688 ALOGV("%s:", __func__);
3689
3690 if (swap_channels) {
3691 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER_REVERSE);
3692 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
3693 } else {
3694 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER);
3695 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
3696 }
3697
3698 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3699 if (!ctl) {
3700 ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name);
3701 return -EINVAL;
3702 }
3703
3704 if (mixer_ctl_set_value(ctl, 0, swap_channels) < 0) {
3705 ALOGE("%s: Could not set reverse cotrol %d",__func__, swap_channels);
3706 return -EINVAL;
3707 }
3708
3709 ALOGV("platfor_force_swap_channel :: Channel orientation ( %s ) ",
3710 swap_channels?"R --> L":"L --> R");
3711
3712 return 0;
3713}
3714
3715int platform_check_and_set_swap_lr_channels(struct audio_device *adev, bool swap_channels)
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003716{
3717 // only update if there is active pcm playback on speaker
3718 struct audio_usecase *usecase;
3719 struct listnode *node;
3720 struct platform_data *my_data = (struct platform_data *)adev->platform;
3721
vivek mehtae59cfb22017-06-16 15:57:11 -07003722 my_data->speaker_lr_swap = swap_channels;
Jean-Michel Trivif7148702016-09-16 18:23:05 -07003723
vivek mehtae59cfb22017-06-16 15:57:11 -07003724 return platform_set_swap_channels(adev, swap_channels);
3725}
Jean-Michel Trivif7148702016-09-16 18:23:05 -07003726
vivek mehtae59cfb22017-06-16 15:57:11 -07003727int platform_set_swap_channels(struct audio_device *adev, bool swap_channels)
3728{
3729 // only update if there is active pcm playback on speaker
3730 struct audio_usecase *usecase;
3731 struct listnode *node;
3732 struct platform_data *my_data = (struct platform_data *)adev->platform;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003733
vivek mehtae59cfb22017-06-16 15:57:11 -07003734 // do not swap channels in audio modes with concurrent capture and playback
3735 // as this may break the echo reference
3736 if ((adev->mode == AUDIO_MODE_IN_COMMUNICATION) || (adev->mode == AUDIO_MODE_IN_CALL)) {
3737 ALOGV("%s: will not swap due to audio mode %d", __func__, adev->mode);
3738 return 0;
3739 }
3740
3741 list_for_each(node, &adev->usecase_list) {
3742 usecase = node_to_item(node, struct audio_usecase, list);
3743 if (usecase->type == PCM_PLAYBACK &&
3744 usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) {
3745 /*
3746 * If acdb tuning is different for SPEAKER_REVERSE, it is must
3747 * to perform device switch to disable the current backend to
3748 * enable it with new acdb data.
3749 */
3750 if (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
3751 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]) {
3752 const int initial_skpr_gain = ramp_speaker_gain(adev, false /*ramp_up*/, -1);
3753 select_devices(adev, usecase->id);
3754 if (initial_skpr_gain != -EINVAL)
3755 ramp_speaker_gain(adev, true /*ramp_up*/, initial_skpr_gain);
3756
3757 } else {
3758 platform_set_swap_mixer(adev, swap_channels);
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003759 }
vivek mehtae59cfb22017-06-16 15:57:11 -07003760 break;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003761 }
3762 }
vivek mehtae59cfb22017-06-16 15:57:11 -07003763
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003764 return 0;
3765}
vivek mehtaa8d7c922016-05-25 14:40:44 -07003766
3767static struct amp_db_and_gain_table tbl_mapping[MAX_VOLUME_CAL_STEPS];
3768static int num_gain_tbl_entry = 0;
3769
3770bool platform_add_gain_level_mapping(struct amp_db_and_gain_table *tbl_entry) {
3771
3772 ALOGV("%s: enter .. add %f %f %d", __func__, tbl_entry->amp, tbl_entry->db, tbl_entry->level);
3773 if (num_gain_tbl_entry == -1) {
3774 ALOGE("%s: num entry beyond valid step levels or corrupted..rejecting custom mapping",
3775 __func__);
3776 return false;
3777 }
3778
3779 if (num_gain_tbl_entry >= MAX_VOLUME_CAL_STEPS) {
3780 ALOGE("%s: max entry reached max[%d] current index[%d] .. rejecting", __func__,
3781 MAX_VOLUME_CAL_STEPS, num_gain_tbl_entry);
3782 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
3783 return false;
3784 }
3785
3786 if (num_gain_tbl_entry > 0 && tbl_mapping[num_gain_tbl_entry - 1].amp >= tbl_entry->amp) {
3787 ALOGE("%s: value not in ascending order .. rejecting custom mapping", __func__);
3788 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
3789 return false;
3790 }
3791
3792 tbl_mapping[num_gain_tbl_entry] = *tbl_entry;
3793 ++num_gain_tbl_entry;
3794
3795 return true;
3796}
3797
3798int platform_get_gain_level_mapping(struct amp_db_and_gain_table *mapping_tbl,
3799 int table_size) {
3800 int itt = 0;
3801 ALOGV("platform_get_gain_level_mapping called ");
3802
3803 if (num_gain_tbl_entry <= 0 || num_gain_tbl_entry > MAX_VOLUME_CAL_STEPS) {
3804 ALOGD("%s: empty or currupted gain_mapping_table", __func__);
3805 return 0;
3806 }
3807
3808 for (; itt < num_gain_tbl_entry && itt <= table_size; itt++) {
3809 mapping_tbl[itt] = tbl_mapping[itt];
3810 ALOGV("%s: added amp[%f] db[%f] level[%d]", __func__,
3811 mapping_tbl[itt].amp, mapping_tbl[itt].db, mapping_tbl[itt].level);
3812 }
3813
3814 return num_gain_tbl_entry;
3815}
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07003816
3817int platform_snd_card_update(void *platform, card_status_t status)
3818{
3819 struct platform_data *my_data = (struct platform_data *)platform;
3820 struct audio_device *adev = my_data->adev;
3821
3822 if (status == CARD_STATUS_ONLINE) {
3823 if (my_data->acdb_send_custom_top)
3824 my_data->acdb_send_custom_top();
3825 }
3826 return 0;
3827}
David Linee3fe402017-03-13 10:00:42 -07003828
3829/*
3830 * configures afe with bit width and Sample Rate
3831 */
Haynes Mathew George65f6b432018-02-27 17:44:55 -08003832int platform_set_backend_cfg(const struct audio_device* adev,
3833 snd_device_t snd_device,
3834 const struct audio_backend_cfg *backend_cfg)
David Linee3fe402017-03-13 10:00:42 -07003835{
3836
3837 int ret = 0;
3838 const int backend_idx = platform_get_backend_index(snd_device);
3839 struct platform_data *my_data = (struct platform_data *)adev->platform;
3840 const unsigned int bit_width = backend_cfg->bit_width;
3841 const unsigned int sample_rate = backend_cfg->sample_rate;
3842 const unsigned int channels = backend_cfg->channels;
3843 const audio_format_t format = backend_cfg->format;
3844 const bool passthrough_enabled = backend_cfg->passthrough_enabled;
3845
3846
3847 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
3848 ", backend_idx %d device (%s)", __func__, bit_width,
3849 sample_rate, channels, backend_idx,
3850 platform_get_snd_device_name(snd_device));
3851
3852 if ((my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl) &&
3853 (bit_width != my_data->current_backend_cfg[backend_idx].bit_width)) {
3854
3855 struct mixer_ctl *ctl = NULL;
3856 ctl = mixer_get_ctl_by_name(adev->mixer,
3857 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
3858 if (!ctl) {
3859 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3860 __func__,
3861 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
3862 return -EINVAL;
3863 }
3864
3865 if (bit_width == 24) {
3866 if (format == AUDIO_FORMAT_PCM_24_BIT_PACKED)
3867 ret = mixer_ctl_set_enum_by_string(ctl, "S24_3LE");
3868 else
3869 ret = mixer_ctl_set_enum_by_string(ctl, "S24_LE");
3870 } else if (bit_width == 32) {
3871 ret = mixer_ctl_set_enum_by_string(ctl, "S32_LE");
3872 } else {
3873 ret = mixer_ctl_set_enum_by_string(ctl, "S16_LE");
3874 }
3875 if ( ret < 0) {
3876 ALOGE("%s:becf: afe: fail for %s mixer set to %d bit for %x format", __func__,
3877 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
3878 } else {
3879 my_data->current_backend_cfg[backend_idx].bit_width = bit_width;
3880 ALOGD("%s:becf: afe: %s mixer set to %d bit for %x format", __func__,
3881 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
3882 }
3883 /* set the ret as 0 and not pass back to upper layer */
3884 ret = 0;
3885 }
3886
3887 if (passthrough_enabled || ((my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl) &&
3888 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate))) {
3889 char *rate_str = NULL;
3890 struct mixer_ctl *ctl = NULL;
3891
3892 switch (sample_rate) {
3893 case 32000:
3894 if (passthrough_enabled) {
3895 rate_str = "KHZ_32";
3896 break;
3897 }
3898 case 8000:
3899 case 11025:
3900 case 16000:
3901 case 22050:
3902 case 48000:
3903 rate_str = "KHZ_48";
3904 break;
3905 case 44100:
3906 rate_str = "KHZ_44P1";
3907 break;
3908 case 64000:
3909 case 96000:
3910 rate_str = "KHZ_96";
3911 break;
3912 case 88200:
3913 rate_str = "KHZ_88P2";
3914 break;
3915 case 176400:
3916 rate_str = "KHZ_176P4";
3917 break;
3918 case 192000:
3919 rate_str = "KHZ_192";
3920 break;
3921 case 352800:
3922 rate_str = "KHZ_352P8";
3923 break;
3924 case 384000:
3925 rate_str = "KHZ_384";
3926 break;
3927 case 144000:
3928 if (passthrough_enabled) {
3929 rate_str = "KHZ_144";
3930 break;
3931 }
3932 default:
3933 rate_str = "KHZ_48";
3934 break;
3935 }
3936
3937 ctl = mixer_get_ctl_by_name(adev->mixer,
3938 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
3939 if(!ctl) {
3940 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3941 __func__,
3942 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
3943 return -EINVAL;
3944 }
3945
3946 ALOGD("%s:becf: afe: %s set to %s", __func__,
3947 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl, rate_str);
3948 mixer_ctl_set_enum_by_string(ctl, rate_str);
3949 my_data->current_backend_cfg[backend_idx].sample_rate = sample_rate;
3950 }
3951 if ((my_data->current_backend_cfg[backend_idx].channels_mixer_ctl) &&
3952 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
3953 struct mixer_ctl *ctl = NULL;
3954 char *channel_cnt_str = NULL;
3955
3956 switch (channels) {
3957 case 8:
3958 channel_cnt_str = "Eight"; break;
3959 case 7:
3960 channel_cnt_str = "Seven"; break;
3961 case 6:
3962 channel_cnt_str = "Six"; break;
3963 case 5:
3964 channel_cnt_str = "Five"; break;
3965 case 4:
3966 channel_cnt_str = "Four"; break;
3967 case 3:
3968 channel_cnt_str = "Three"; break;
3969 case 1:
3970 channel_cnt_str = "One"; break;
3971 case 2:
3972 default:
3973 channel_cnt_str = "Two"; break;
3974 }
3975
3976 ctl = mixer_get_ctl_by_name(adev->mixer,
3977 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
3978 if (!ctl) {
3979 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3980 __func__,
3981 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
3982 return -EINVAL;
3983 }
3984 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
3985 my_data->current_backend_cfg[backend_idx].channels = channels;
3986
3987 // skip EDID configuration for HDMI backend
3988
3989 ALOGD("%s:becf: afe: %s set to %s", __func__,
3990 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl,
3991 channel_cnt_str);
3992 }
3993
3994 // skip set ext_display format mixer control
3995 return ret;
3996}
3997
3998static int platform_get_snd_device_bit_width(snd_device_t snd_device)
3999{
4000 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
4001 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
4002 return CODEC_BACKEND_DEFAULT_BIT_WIDTH;
4003 }
4004
4005 return backend_bit_width_table[snd_device];
4006}
4007
4008/*
4009 * return backend_idx on which voice call is active
4010 */
4011static int platform_get_voice_call_backend(struct audio_device* adev)
4012{
4013 struct audio_usecase *uc = NULL;
4014 struct listnode *node;
4015 snd_device_t out_snd_device = SND_DEVICE_NONE;
4016
4017 int backend_idx = -1;
4018
4019 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
4020 list_for_each(node, &adev->usecase_list) {
4021 uc = node_to_item(node, struct audio_usecase, list);
4022 if (uc && uc->type == VOICE_CALL && uc->stream.out) {
4023 out_snd_device = platform_get_output_snd_device(adev->platform,
4024 uc->stream.out->devices);
4025 backend_idx = platform_get_backend_index(out_snd_device);
4026 break;
4027 }
4028 }
4029 }
4030 return backend_idx;
4031}
4032
4033/*
4034 * goes through all the current usecases and picks the highest
4035 * bitwidth & samplerate
4036 */
4037static bool platform_check_capture_backend_cfg(struct audio_device* adev,
4038 int backend_idx,
4039 struct audio_backend_cfg *backend_cfg)
4040{
4041 bool backend_change = false;
4042 unsigned int bit_width;
4043 unsigned int sample_rate;
4044 unsigned int channels;
4045 struct platform_data *my_data = (struct platform_data *)adev->platform;
4046
4047 bit_width = backend_cfg->bit_width;
4048 sample_rate = backend_cfg->sample_rate;
4049 channels = backend_cfg->channels;
4050
4051 ALOGV("%s:txbecf: afe: Codec selected backend: %d current bit width: %d and "
4052 "sample rate: %d, channels %d",__func__,backend_idx, bit_width,
4053 sample_rate, channels);
4054
4055 // For voice calls use default configuration i.e. 16b/48K, only applicable to
4056 // default backend
4057 // force routing is not required here, caller will do it anyway
4058 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
4059 ALOGW("%s:txbecf: afe: Use default bw and sr for voice/voip calls and "
4060 "for unprocessed/camera source", __func__);
4061 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
4062 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4063 }
4064
4065 if (backend_idx == USB_AUDIO_TX_BACKEND) {
4066 audio_extn_usb_is_config_supported(&bit_width, &sample_rate, &channels, false);
4067 ALOGV("%s:txbecf: afe: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
4068 __func__, bit_width, sample_rate, channels);
4069 }
4070
4071 ALOGV("%s:txbecf: afe: Codec selected backend: %d updated bit width: %d and "
4072 "sample rate: %d", __func__, backend_idx, bit_width, sample_rate);
4073
4074 // Force routing if the expected bitwdith or samplerate
4075 // is not same as current backend comfiguration
4076 if ((bit_width != my_data->current_backend_cfg[backend_idx].bit_width) ||
4077 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate) ||
4078 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
4079 backend_cfg->bit_width = bit_width;
4080 backend_cfg->sample_rate= sample_rate;
4081 backend_cfg->channels = channels;
4082 backend_change = true;
4083 ALOGI("%s:txbecf: afe: Codec backend needs to be updated. new bit width: %d "
4084 "new sample rate: %d new channel: %d",
4085 __func__, backend_cfg->bit_width,
4086 backend_cfg->sample_rate, backend_cfg->channels);
4087 }
4088
4089 return backend_change;
4090}
4091
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004092static void pick_playback_cfg_for_uc(struct audio_device *adev,
4093 struct audio_usecase *usecase,
4094 snd_device_t snd_device,
4095 unsigned int *bit_width,
4096 unsigned int *sample_rate,
4097 unsigned int *channels)
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004098{
4099 int i =0;
4100 struct listnode *node;
4101 list_for_each(node, &adev->usecase_list) {
4102 struct audio_usecase *uc;
4103 uc = node_to_item(node, struct audio_usecase, list);
4104 struct stream_out *out = (struct stream_out*) uc->stream.out;
4105 if (uc->type == PCM_PLAYBACK && out && usecase != uc) {
4106 unsigned int out_channels = audio_channel_count_from_out_mask(out->channel_mask);
4107 ALOGV("%s:napb: (%d) - (%s)id (%d) sr %d bw "
4108 "(%d) ch (%d) device %s", __func__, i++, use_case_table[uc->id],
4109 uc->id, out->sample_rate,
4110 pcm_format_to_bits(out->config.format), out_channels,
4111 platform_get_snd_device_name(uc->out_snd_device));
4112
4113 if (platform_check_backends_match(snd_device, uc->out_snd_device)) {
4114 if (*bit_width < pcm_format_to_bits(out->config.format))
4115 *bit_width = pcm_format_to_bits(out->config.format);
4116 if (*sample_rate < out->sample_rate)
4117 *sample_rate = out->sample_rate;
4118 if (out->sample_rate < OUTPUT_SAMPLING_RATE_44100)
4119 *sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4120 if (*channels < out_channels)
4121 *channels = out_channels;
4122 }
4123 }
4124 }
4125 return;
4126}
4127
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004128static void headset_is_config_supported(unsigned int *bit_width,
4129 unsigned int *sample_rate,
4130 unsigned int *channels) {
4131 switch (*bit_width) {
4132 case 16:
4133 case 24:
4134 break;
4135 default:
4136 *bit_width = 16;
4137 break;
4138 }
4139
4140 if (*sample_rate > 192000) {
4141 *sample_rate = 192000;
4142 }
4143
4144 if (*channels > 2) {
4145 *channels = 2;
4146 }
4147}
4148
David Linee3fe402017-03-13 10:00:42 -07004149static bool platform_check_playback_backend_cfg(struct audio_device* adev,
4150 struct audio_usecase* usecase,
4151 snd_device_t snd_device,
4152 struct audio_backend_cfg *backend_cfg)
4153{
4154 bool backend_change = false;
David Linee3fe402017-03-13 10:00:42 -07004155 unsigned int bit_width;
4156 unsigned int sample_rate;
4157 unsigned int channels;
David Linee3fe402017-03-13 10:00:42 -07004158 int backend_idx = DEFAULT_CODEC_BACKEND;
Haynes Mathew George65f6b432018-02-27 17:44:55 -08004159 unsigned long service_interval = 0; // 0 is invalid
David Linee3fe402017-03-13 10:00:42 -07004160 struct platform_data *my_data = (struct platform_data *)adev->platform;
David Linee3fe402017-03-13 10:00:42 -07004161
4162 if (snd_device == SND_DEVICE_OUT_BT_SCO ||
4163 snd_device == SND_DEVICE_OUT_BT_SCO_WB) {
4164 backend_change = false;
4165 return backend_change;
4166 }
4167
4168 backend_idx = platform_get_backend_index(snd_device);
4169 bit_width = backend_cfg->bit_width;
4170 sample_rate = backend_cfg->sample_rate;
4171 channels = backend_cfg->channels;
4172
4173 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
4174 ", backend_idx %d usecase = %d device (%s)", __func__, bit_width,
4175 sample_rate, channels, backend_idx, usecase->id,
4176 platform_get_snd_device_name(snd_device));
4177
4178 if (backend_idx == platform_get_voice_call_backend(adev)) {
4179 ALOGW("%s:becf: afe:Use default bw and sr for voice/voip calls ",
4180 __func__);
4181 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
4182 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4183 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
4184 } else {
4185 /*
4186 * The backend should be configured at highest bit width and/or
4187 * sample rate amongst all playback usecases.
4188 * If the selected sample rate and/or bit width differ with
4189 * current backend sample rate and/or bit width, then, we set the
4190 * backend re-configuration flag.
4191 *
4192 * Exception: 16 bit playbacks is allowed through 16 bit/48/44.1 khz backend only
4193 */
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004194 pick_playback_cfg_for_uc(adev, usecase, snd_device,
4195 &bit_width,
4196 &sample_rate,
4197 &channels);
David Linee3fe402017-03-13 10:00:42 -07004198 }
4199
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004200 switch (backend_idx) {
4201 case USB_AUDIO_RX_BACKEND:
4202 audio_extn_usb_is_config_supported(&bit_width,
4203 &sample_rate, &channels, true);
Haynes Mathew George65f6b432018-02-27 17:44:55 -08004204 if (platform_get_usb_service_interval(adev->platform, true,
4205 &service_interval) == 0) {
4206 /* overwrite with best altset for this service interval */
4207 int ret =
4208 audio_extn_usb_altset_for_service_interval(true /*playback*/,
4209 service_interval,
4210 &bit_width,
4211 &sample_rate,
4212 &channels);
4213 if (ret < 0) {
4214 ALOGE("Failed to find altset for service interval %lu, skip reconfig",
4215 service_interval);
4216 return false;
4217 }
4218 }
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004219 ALOGV("%s: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
4220 __func__, bit_width, sample_rate, channels);
4221 break;
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004222 case HEADPHONE_BACKEND:
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004223 headset_is_config_supported(&bit_width, &sample_rate, &channels);
4224 break;
4225 case DEFAULT_CODEC_BACKEND:
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004226 default:
4227 bit_width = platform_get_snd_device_bit_width(snd_device);
4228 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4229 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
4230 break;
David Linee3fe402017-03-13 10:00:42 -07004231 }
4232
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004233 ALOGV("%s:becf: afe: Codec selected backend: %d updated bit width: %d and"
4234 "sample rate: %d",
David Linee3fe402017-03-13 10:00:42 -07004235 __func__, backend_idx , bit_width, sample_rate);
4236
4237 // Force routing if the expected bitwdith or samplerate
4238 // is not same as current backend comfiguration
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004239 if (bit_width != my_data->current_backend_cfg[backend_idx].bit_width ||
4240 sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate ||
4241 channels != my_data->current_backend_cfg[backend_idx].channels) {
David Linee3fe402017-03-13 10:00:42 -07004242 backend_cfg->bit_width = bit_width;
4243 backend_cfg->sample_rate = sample_rate;
4244 backend_cfg->channels = channels;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004245 backend_cfg->passthrough_enabled = false;
David Linee3fe402017-03-13 10:00:42 -07004246 backend_change = true;
4247 ALOGV("%s:becf: afe: Codec backend needs to be updated. new bit width: %d"
4248 "new sample rate: %d new channels: %d",
4249 __func__, backend_cfg->bit_width, backend_cfg->sample_rate, backend_cfg->channels);
4250 }
4251
4252 return backend_change;
4253}
4254
4255bool platform_check_and_set_playback_backend_cfg(struct audio_device* adev,
4256 struct audio_usecase *usecase, snd_device_t snd_device)
4257{
4258 int backend_idx = DEFAULT_CODEC_BACKEND;
4259 int new_snd_devices[SND_DEVICE_OUT_END];
4260 int i, num_devices = 1;
4261 bool ret = false;
4262 struct platform_data *my_data = (struct platform_data *)adev->platform;
4263 struct audio_backend_cfg backend_cfg;
4264
4265 backend_idx = platform_get_backend_index(snd_device);
4266
4267 backend_cfg.bit_width = pcm_format_to_bits(usecase->stream.out->config.format);
4268 backend_cfg.sample_rate = usecase->stream.out->sample_rate;
4269 backend_cfg.format = usecase->stream.out->format;
4270 backend_cfg.channels = audio_channel_count_from_out_mask(usecase->stream.out->channel_mask);
4271 /*this is populated by check_codec_backend_cfg hence set default value to false*/
4272 backend_cfg.passthrough_enabled = false;
4273
4274 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
4275 ", backend_idx %d usecase = %d device (%s)", __func__, backend_cfg.bit_width,
4276 backend_cfg.sample_rate, backend_cfg.channels, backend_idx, usecase->id,
4277 platform_get_snd_device_name(snd_device));
4278
4279 if (platform_can_split_snd_device(snd_device, &num_devices, new_snd_devices) < 0)
4280 new_snd_devices[0] = snd_device;
4281
4282 for (i = 0; i < num_devices; i++) {
4283 ALOGV("%s: new_snd_devices[%d] is %d", __func__, i, new_snd_devices[i]);
4284 if ((platform_check_playback_backend_cfg(adev, usecase, new_snd_devices[i],
4285 &backend_cfg))) {
4286 platform_set_backend_cfg(adev, new_snd_devices[i],
4287 &backend_cfg);
4288 ret = true;
4289 }
4290 }
4291 return ret;
4292}
4293
4294bool platform_check_and_set_capture_backend_cfg(struct audio_device* adev,
4295 struct audio_usecase *usecase, snd_device_t snd_device)
4296{
4297 int backend_idx = platform_get_backend_index(snd_device);
4298 int ret = 0;
4299 struct audio_backend_cfg backend_cfg;
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004300 memset(&backend_cfg, 0, sizeof(struct audio_backend_cfg));
David Linee3fe402017-03-13 10:00:42 -07004301
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004302 if (usecase->type == PCM_CAPTURE) {
4303 backend_cfg.format = usecase->stream.in->format;
David Linee3fe402017-03-13 10:00:42 -07004304 backend_cfg.channels = audio_channel_count_from_in_mask(usecase->stream.in->channel_mask);
4305 } else {
4306 backend_cfg.bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
4307 backend_cfg.sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4308 backend_cfg.format = AUDIO_FORMAT_PCM_16_BIT;
4309 backend_cfg.channels = 1;
4310 }
4311
4312 ALOGV("%s:txbecf: afe: bitwidth %d, samplerate %d, channel %d"
4313 ", backend_idx %d usecase = %d device (%s)", __func__,
4314 backend_cfg.bit_width,
4315 backend_cfg.sample_rate,
4316 backend_cfg.channels,
4317 backend_idx, usecase->id,
4318 platform_get_snd_device_name(snd_device));
4319
4320 if (platform_check_capture_backend_cfg(adev, backend_idx, &backend_cfg)) {
4321 ret = platform_set_backend_cfg(adev, snd_device,
4322 &backend_cfg);
4323 if(!ret)
4324 return true;
4325 }
4326
4327 return false;
4328}
4329
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004330static int max_be_dai_names = 0;
4331static const struct be_dai_name_struct *be_dai_name_table;
4332
4333/*
4334 * Retrieves the be_dai_name_table from kernel to enable a mapping
4335 * between sound device hw interfaces and backend IDs. This allows HAL to
4336 * specify the backend a specific calibration is needed for.
4337 */
4338static int init_be_dai_name_table(struct audio_device *adev)
4339{
4340 const char *mixer_ctl_name = "Backend DAI Name Table";
4341 struct mixer_ctl *ctl;
4342 int i, j, ret, size;
4343 bool valid_hw_interface;
4344
4345 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
4346 if (!ctl) {
4347 ALOGE("%s: Could not get ctl for mixer name %s\n",
4348 __func__, mixer_ctl_name);
4349 ret = -EINVAL;
4350 goto done;
4351 }
4352
4353 mixer_ctl_update(ctl);
4354
4355 size = mixer_ctl_get_num_values(ctl);
4356 if (size <= 0){
4357 ALOGE("%s: Failed to get %s size %d\n",
4358 __func__, mixer_ctl_name, size);
4359 ret = -EFAULT;
4360 goto done;
4361 }
4362
vivek mehtaa68fea62017-06-08 19:04:02 -07004363 be_dai_name_table =
4364 (const struct be_dai_name_struct *)calloc(1, size);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004365 if (be_dai_name_table == NULL) {
4366 ALOGE("%s: Failed to allocate memory for %s\n",
4367 __func__, mixer_ctl_name);
4368 ret = -ENOMEM;
4369 goto freeMem;
4370 }
4371
4372 ret = mixer_ctl_get_array(ctl, (void *)be_dai_name_table, size);
4373 if (ret) {
4374 ALOGE("%s: Failed to get %s, ret %d\n",
4375 __func__, mixer_ctl_name, ret);
4376 ret = -EFAULT;
4377 goto freeMem;
4378 }
4379
4380 if (be_dai_name_table != NULL) {
4381 max_be_dai_names = size / sizeof(struct be_dai_name_struct);
4382 ALOGV("%s: Successfully got %s, number of be dais is %d\n",
4383 __func__, mixer_ctl_name, max_be_dai_names);
4384 ret = 0;
4385 } else {
4386 ALOGE("%s: Failed to get %s\n", __func__, mixer_ctl_name);
4387 ret = -EFAULT;
4388 goto freeMem;
4389 }
4390
4391 /*
4392 * Validate all sound devices have a valid backend set to catch
4393 * errors for uncommon sound devices
4394 */
4395 for (i = 0; i < SND_DEVICE_MAX; i++) {
4396 valid_hw_interface = false;
4397
4398 if (hw_interface_table[i] == NULL) {
4399 ALOGW("%s: sound device %s has no hw interface set\n",
4400 __func__, platform_get_snd_device_name(i));
4401 continue;
4402 }
4403
4404 for (j = 0; j < max_be_dai_names; j++) {
4405 if (strcmp(hw_interface_table[i], be_dai_name_table[j].be_name)
4406 == 0) {
4407 valid_hw_interface = true;
4408 break;
4409 }
4410 }
4411 if (!valid_hw_interface)
4412 ALOGD("%s: sound device %s does not have a valid hw interface set "
4413 "(disregard for combo devices) %s\n",
4414 __func__, platform_get_snd_device_name(i),
4415 hw_interface_table[i]);
4416 }
4417
4418 goto done;
4419
4420freeMem:
4421 if (be_dai_name_table) {
4422 free((void *)be_dai_name_table);
4423 be_dai_name_table = NULL;
4424 }
4425
4426done:
4427 return ret;
4428}
4429
4430int platform_get_snd_device_backend_index(snd_device_t device)
4431{
4432 int i, be_dai_id;
4433 const char * hw_interface_name = NULL;
4434
4435 ALOGV("%s: enter with device %d\n", __func__, device);
4436
vivek mehtaa68fea62017-06-08 19:04:02 -07004437 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004438 ALOGE("%s: Invalid snd_device = %d",
4439 __func__, device);
4440 be_dai_id = -EINVAL;
4441 goto done;
4442 }
4443
4444 /* Get string value of necessary backend for device */
4445 hw_interface_name = hw_interface_table[device];
4446 if (hw_interface_name == NULL) {
4447 ALOGE("%s: no hw_interface set for device %d\n", __func__, device);
4448 be_dai_id = -EINVAL;
4449 goto done;
4450 }
4451
4452 /* Check if be dai name table was retrieved successfully */
4453 if (be_dai_name_table == NULL) {
4454 ALOGE("%s: BE DAI Name Table is not present\n", __func__);
4455 be_dai_id = -EFAULT;
4456 goto done;
4457 }
4458
4459 /* Get backend ID for device specified */
4460 for (i = 0; i < max_be_dai_names; i++) {
4461 if (strcmp(hw_interface_name, be_dai_name_table[i].be_name) == 0) {
4462 be_dai_id = be_dai_name_table[i].be_id;
4463 goto done;
4464 }
4465 }
4466 ALOGE("%s: no interface matching name %s\n", __func__, hw_interface_name);
4467 be_dai_id = -EINVAL;
4468 goto done;
4469
4470done:
4471 return be_dai_id;
4472}
4473
4474void platform_check_and_update_copp_sample_rate(void* platform, snd_device_t snd_device,
4475 unsigned int stream_sr, int* sample_rate)
4476{
4477 struct platform_data* my_data = (struct platform_data *)platform;
4478 int backend_idx = platform_get_backend_index(snd_device);
4479 int device_sr = my_data->current_backend_cfg[backend_idx].sample_rate;
4480 /*
4481 *Check if device SR is multiple of 8K or 11.025 Khz
4482 *check if the stream SR is multiple of same base, if yes
4483 *then have copp SR equal to stream SR, this ensures that
4484 *post processing happens at stream SR, else have
4485 *copp SR equal to device SR.
4486 */
4487 if (!(((sample_rate_multiple(device_sr, SAMPLE_RATE_8000)) &&
4488 (sample_rate_multiple(stream_sr, SAMPLE_RATE_8000))) ||
4489 ((sample_rate_multiple(device_sr, SAMPLE_RATE_11025)) &&
4490 (sample_rate_multiple(stream_sr, SAMPLE_RATE_11025))))) {
4491 *sample_rate = device_sr;
4492 } else
4493 *sample_rate = stream_sr;
4494
4495 ALOGI("sn_device %d device sr %d stream sr %d copp sr %d", snd_device, device_sr, stream_sr
4496 , *sample_rate);
4497
4498}
4499
4500// called from info parser
vivek mehtaa68fea62017-06-08 19:04:02 -07004501void platform_add_app_type(const char *uc_type,
4502 const char *mode,
4503 int bw,
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004504 int app_type, int max_rate) {
4505 struct app_type_entry *ap =
4506 (struct app_type_entry *)calloc(1, sizeof(struct app_type_entry));
4507
4508 if (!ap) {
4509 ALOGE("%s failed to allocate mem for app type", __func__);
4510 return;
4511 }
4512
4513 ap->uc_type = -1;
4514 for (int i=0; i<USECASE_TYPE_MAX; i++) {
4515 if (!strcmp(uc_type, usecase_type_index[i].name)) {
4516 ap->uc_type = usecase_type_index[i].index;
4517 break;
4518 }
4519 }
4520
4521 if (ap->uc_type == -1) {
4522 free(ap);
4523 return;
4524 }
4525
vivek mehtaa68fea62017-06-08 19:04:02 -07004526 ALOGI("%s uc %s mode %s bw %d app_type %d max_rate %d",
4527 __func__, uc_type, mode, bw, app_type, max_rate);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004528 ap->bit_width = bw;
4529 ap->app_type = app_type;
4530 ap->max_rate = max_rate;
vivek mehtaa68fea62017-06-08 19:04:02 -07004531 ap->mode = strdup(mode);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004532 list_add_tail(&app_type_entry_list, &ap->node);
4533}
4534
4535
4536int platform_get_default_app_type_v2(void *platform __unused,
4537 usecase_type_t type,
4538 int *app_type )
4539{
4540 if (type == PCM_PLAYBACK)
4541 *app_type = DEFAULT_APP_TYPE_RX_PATH;
4542 else
4543 *app_type = DEFAULT_APP_TYPE_TX_PATH;
4544 return 0;
4545}
4546
vivek mehtaa68fea62017-06-08 19:04:02 -07004547int platform_get_app_type_v2(void *platform,
4548 usecase_type_t uc_type,
4549 const char *mode,
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004550 int bw, int sr __unused,
4551 int *app_type)
4552{
4553 struct listnode *node;
4554 struct app_type_entry *entry;
4555 *app_type = -1;
vivek mehtaa68fea62017-06-08 19:04:02 -07004556
4557 ALOGV("%s find match for uc %d mode %s bw %d rate %d",
4558 __func__, uc_type, mode, bw, sr);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004559 list_for_each(node, &app_type_entry_list) {
4560 entry = node_to_item(node, struct app_type_entry, node);
vivek mehtaa68fea62017-06-08 19:04:02 -07004561 ALOGV("%s uc %d mode %s bw %d app_type %d max_rate %d",
4562 __func__, entry->uc_type, entry->mode, entry->bit_width,
4563 entry->app_type, entry->max_rate);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004564 if (entry->bit_width == bw &&
vivek mehtaa68fea62017-06-08 19:04:02 -07004565 entry->uc_type == uc_type &&
4566 sr <= entry->max_rate &&
4567 entry->mode && !strcmp(mode, entry->mode)) {
4568 ALOGV("%s found match %d", __func__, entry->app_type);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004569 *app_type = entry->app_type;
4570 break;
4571 }
4572 }
4573
4574 if (*app_type == -1) {
vivek mehtaa68fea62017-06-08 19:04:02 -07004575 ALOGV("%s no match found, return default", __func__);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004576 return platform_get_default_app_type_v2(platform, uc_type, app_type);
4577 }
4578 return 0;
4579}
vivek mehta90933872017-06-15 18:04:39 -07004580
4581int platform_set_sidetone(struct audio_device *adev,
4582 snd_device_t out_snd_device,
4583 bool enable, char *str)
4584{
4585 int ret;
4586 if (out_snd_device == SND_DEVICE_OUT_USB_HEADSET ||
4587 out_snd_device == SND_DEVICE_OUT_VOICE_USB_HEADSET) {
4588 ret = audio_extn_usb_enable_sidetone(out_snd_device, enable);
4589 if (ret)
4590 ALOGI("%s: usb device %d does not support device sidetone\n",
4591 __func__, out_snd_device);
4592 } else {
4593 ALOGV("%s: sidetone out device(%d) mixer cmd = %s\n",
4594 __func__, out_snd_device, str);
4595 if (enable)
4596 audio_route_apply_and_update_path(adev->audio_route, str);
4597 else
4598 audio_route_reset_and_update_path(adev->audio_route, str);
4599 }
4600 return 0;
4601}
Haynes Mathew George96483a22017-03-28 14:52:47 -07004602
4603int platform_get_mmap_data_fd(void *platform __unused, int fe_dev __unused, int dir __unused,
4604 int *fd __unused, uint32_t *size __unused)
4605{
Thierry Strudel07f96d12018-09-20 13:31:34 -07004606#if defined (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845) || (PLATFORM_SDM710) || (PLATFORM_SM8150)
Haynes Mathew George96483a22017-03-28 14:52:47 -07004607 struct platform_data *my_data = (struct platform_data *)platform;
4608 struct audio_device *adev = my_data->adev;
4609 int hw_fd = -1;
4610 char dev_name[128];
4611 struct snd_pcm_mmap_fd mmap_fd;
4612 memset(&mmap_fd, 0, sizeof(mmap_fd));
4613 mmap_fd.dir = dir;
4614 snprintf(dev_name, sizeof(dev_name), "/dev/snd/hwC%uD%u",
4615 adev->snd_card, HWDEP_FE_BASE+fe_dev);
4616 hw_fd = open(dev_name, O_RDONLY);
4617 if (hw_fd < 0) {
4618 ALOGE("fe hw dep node open %d/%d failed", adev->snd_card, fe_dev);
4619 return -1;
4620 }
4621 if (ioctl(hw_fd, SNDRV_PCM_IOCTL_MMAP_DATA_FD, &mmap_fd) < 0) {
4622 ALOGE("fe hw dep node ioctl failed");
4623 close(hw_fd);
4624 return -1;
4625 }
4626 *fd = mmap_fd.fd;
4627 *size = mmap_fd.size;
4628 close(hw_fd); // mmap_fd should still be valid
4629 return 0;
4630#else
4631 return -1;
4632#endif
4633}
Mikhail Naganov4ee6e3e2018-03-21 16:28:35 +00004634
4635bool platform_sound_trigger_usecase_needs_event(audio_usecase_t uc_id)
4636{
4637 bool needs_event = false;
4638
4639 switch (uc_id) {
4640 /* concurrent capture usecases which needs event */
4641 case USECASE_AUDIO_RECORD:
4642 case USECASE_AUDIO_RECORD_LOW_LATENCY:
4643 case USECASE_AUDIO_RECORD_MMAP:
4644 case USECASE_AUDIO_RECORD_HIFI:
4645 case USECASE_AUDIO_RECORD_VOIP:
4646 case USECASE_VOICEMMODE1_CALL:
4647 case USECASE_VOICEMMODE2_CALL:
4648 /* concurrent playback usecases that needs event */
4649 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
4650 case USECASE_AUDIO_PLAYBACK_OFFLOAD:
4651 needs_event = true;
4652 break;
4653 default:
4654 ALOGV("%s:usecase_id[%d] no need to raise event.", __func__, uc_id);
4655 }
4656 return needs_event;
4657}
4658
4659bool platform_snd_device_has_speaker(snd_device_t dev) {
4660 int num_devs = 2;
4661 snd_device_t split_devs[2] = {SND_DEVICE_NONE, SND_DEVICE_NONE};
4662 if (platform_can_split_snd_device(dev, &num_devs, split_devs) == 0) {
4663 return platform_snd_device_has_speaker(split_devs[0]) ||
4664 platform_snd_device_has_speaker(split_devs[1]);
4665 }
4666
4667 switch (dev) {
4668 case SND_DEVICE_OUT_SPEAKER:
4669 case SND_DEVICE_OUT_SPEAKER_SAFE:
4670 case SND_DEVICE_OUT_SPEAKER_REVERSE:
4671 case SND_DEVICE_OUT_SPEAKER_PROTECTED:
4672 case SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED:
4673 case SND_DEVICE_OUT_VOICE_SPEAKER_HFP:
4674 return true;
4675 default:
4676 break;
4677 }
4678 return false;
4679}
jiabin8962a4d2018-03-19 18:21:24 -07004680
4681bool platform_set_microphone_characteristic(void *platform,
4682 struct audio_microphone_characteristic_t mic) {
4683 struct platform_data *my_data = (struct platform_data *)platform;
4684 if (my_data->declared_mic_count >= AUDIO_MICROPHONE_MAX_COUNT) {
4685 ALOGE("mic number is more than maximum number");
4686 return false;
4687 }
4688 for (size_t ch = 0; ch < AUDIO_CHANNEL_COUNT_MAX; ch++) {
4689 mic.channel_mapping[ch] = AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED;
4690 }
4691 my_data->microphones[my_data->declared_mic_count++] = mic;
4692 return true;
4693}
4694
4695int platform_get_microphones(void *platform,
4696 struct audio_microphone_characteristic_t *mic_array,
4697 size_t *mic_count) {
4698 struct platform_data *my_data = (struct platform_data *)platform;
4699 if (mic_count == NULL) {
4700 return -EINVAL;
4701 }
4702 if (mic_array == NULL) {
4703 return -EINVAL;
4704 }
4705
4706 if (*mic_count == 0) {
4707 *mic_count = my_data->declared_mic_count;
4708 return 0;
4709 }
4710
4711 size_t max_mic_count = *mic_count;
4712 size_t actual_mic_count = 0;
4713 for (size_t i = 0; i < max_mic_count && i < my_data->declared_mic_count; i++) {
4714 mic_array[i] = my_data->microphones[i];
4715 actual_mic_count++;
4716 }
4717 *mic_count = actual_mic_count;
4718 return 0;
4719}
4720
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004721bool platform_set_microphone_map(void *platform, snd_device_t in_snd_device,
4722 const struct mic_info *info) {
4723 struct platform_data *my_data = (struct platform_data *)platform;
4724 if (in_snd_device < SND_DEVICE_IN_BEGIN || in_snd_device >= SND_DEVICE_IN_END) {
4725 ALOGE("%s: Sound device not valid", __func__);
4726 return false;
4727 }
4728 size_t m_count = my_data->mic_map[in_snd_device].mic_count++;
4729 if (m_count >= AUDIO_MICROPHONE_MAX_COUNT) {
4730 ALOGE("%s: Microphone count is greater than max allowed value", __func__);
4731 my_data->mic_map[in_snd_device].mic_count--;
4732 return false;
4733 }
4734 my_data->mic_map[in_snd_device].microphones[m_count] = *info;
4735 return true;
4736}
4737
4738int platform_get_active_microphones(void *platform, unsigned int channels,
4739 audio_usecase_t uc_id,
jiabin8962a4d2018-03-19 18:21:24 -07004740 struct audio_microphone_characteristic_t *mic_array,
4741 size_t *mic_count) {
4742 struct platform_data *my_data = (struct platform_data *)platform;
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004743 struct audio_usecase *usecase = get_usecase_from_list(my_data->adev, uc_id);
4744 if (mic_count == NULL || mic_array == NULL || usecase == NULL) {
jiabin8962a4d2018-03-19 18:21:24 -07004745 return -EINVAL;
4746 }
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004747 size_t max_mic_count = my_data->declared_mic_count;
jiabin8962a4d2018-03-19 18:21:24 -07004748 size_t actual_mic_count = 0;
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004749
4750 snd_device_t active_input_snd_device =
4751 platform_get_input_snd_device(platform, usecase->stream.in->device);
4752 if (active_input_snd_device == SND_DEVICE_NONE) {
4753 ALOGI("%s: No active microphones found", __func__);
4754 goto end;
4755 }
4756
4757 size_t active_mic_count = my_data->mic_map[active_input_snd_device].mic_count;
4758 struct mic_info *m_info = my_data->mic_map[active_input_snd_device].microphones;
4759
4760 for (size_t i = 0; i < active_mic_count; i++) {
4761 unsigned int channels_for_active_mic = channels;
4762 if (channels_for_active_mic > m_info[i].channel_count) {
4763 channels_for_active_mic = m_info[i].channel_count;
4764 }
4765 for (size_t j = 0; j < max_mic_count; j++) {
4766 if (strcmp(my_data->microphones[j].device_id,
4767 m_info[i].device_id) == 0) {
4768 mic_array[actual_mic_count] = my_data->microphones[j];
4769 for (size_t ch = 0; ch < channels_for_active_mic; ch++) {
4770 mic_array[actual_mic_count].channel_mapping[ch] =
4771 m_info[i].channel_mapping[ch];
4772 }
4773 actual_mic_count++;
4774 break;
jiabin8962a4d2018-03-19 18:21:24 -07004775 }
jiabin8962a4d2018-03-19 18:21:24 -07004776 }
4777 }
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004778end:
jiabin8962a4d2018-03-19 18:21:24 -07004779 *mic_count = actual_mic_count;
4780 return 0;
4781}
Haynes Mathew George65f6b432018-02-27 17:44:55 -08004782
4783int platform_set_usb_service_interval(void *platform,
4784 bool playback,
4785 unsigned long service_interval,
4786 bool *reconfig)
4787{
4788#if defined (USB_SERVICE_INTERVAL_ENABLED)
4789 struct platform_data *_platform = (struct platform_data *)platform;
4790 *reconfig = false;
4791 if (!playback) {
4792 ALOGE("%s not valid for capture", __func__);
4793 return -1;
4794 }
4795 const char *ctl_name = "USB_AUDIO_RX service_interval";
4796 struct mixer_ctl *ctl = mixer_get_ctl_by_name(_platform->adev->mixer,
4797 ctl_name);
4798 if (!ctl) {
4799 ALOGV("%s: could not get mixer %s", __func__, ctl_name);
4800 return -1;
4801 }
4802 if (mixer_ctl_get_value(ctl, 0) != (int)service_interval) {
4803 mixer_ctl_set_value(ctl, 0, service_interval);
4804 *reconfig = true;
4805 }
4806 return 0;
4807#else
4808 *reconfig = false;
4809 (void)platform;
4810 (void)playback;
4811 (void)service_interval;
4812 return -1;
4813#endif
4814}
4815
4816int platform_get_usb_service_interval(void *platform,
4817 bool playback,
4818 unsigned long *service_interval)
4819{
4820#if defined (USB_SERVICE_INTERVAL_ENABLED)
4821 struct platform_data *_platform = (struct platform_data *)platform;
4822 if (!playback) {
4823 ALOGE("%s not valid for capture", __func__);
4824 return -1;
4825 }
4826 const char *ctl_name = "USB_AUDIO_RX service_interval";
4827 struct mixer_ctl *ctl = mixer_get_ctl_by_name(_platform->adev->mixer,
4828 ctl_name);
4829 if (!ctl) {
4830 ALOGV("%s: could not get mixer %s", __func__, ctl_name);
4831 return -1;
4832 }
4833 *service_interval = mixer_ctl_get_value(ctl, 0);
4834 return 0;
4835#else
4836 (void)platform;
4837 (void)playback;
4838 (void)service_interval;
4839 return -1;
4840#endif
4841}
Ashish Jain1c849702018-05-11 20:11:55 +05304842
4843int platform_set_acdb_metainfo_key(void *platform __unused,
4844 char *name __unused,
4845 int key __unused)
4846{
4847 return -ENOSYS;
4848}