blob: eb4bb4a11c6c0243a7a0f2e7760b9f3fc7ee0075 [file] [log] [blame]
Eric Laurentb23d5282013-05-14 15:27:20 -07001/*
vivek mehtaa6b79742017-03-09 15:40:43 -08002 * Copyright (C) 2013-2017 The Android Open Source Project
Eric Laurentb23d5282013-05-14 15:27:20 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Eric Laurentb23d5282013-05-14 15:27:20 -070016#define LOG_TAG "msm8974_platform"
17/*#define LOG_NDEBUG 0*/
18#define LOG_NDDEBUG 0
19
20#include <stdlib.h>
21#include <dlfcn.h>
Jiyong Park6431fe62017-06-29 15:15:58 +090022#include <pthread.h>
23#include <unistd.h>
Haynes Mathew Georgee6e2d442018-02-22 18:51:56 -080024#include <log/log.h>
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -070025#include <cutils/str_parms.h>
Eric Laurentb23d5282013-05-14 15:27:20 -070026#include <cutils/properties.h>
27#include <audio_hw.h>
28#include <platform_api.h>
vivek mehta0fb11312017-05-15 19:35:32 -070029#include "acdb.h"
Eric Laurentb23d5282013-05-14 15:27:20 -070030#include "platform.h"
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -070031#include "audio_extn.h"
vivek mehta1a9b7c02015-06-25 11:49:38 -070032#include <linux/msm_audio.h>
Thierry Strudel07f96d12018-09-20 13:31:34 -070033#if defined (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845) || (PLATFORM_SDM710) || (PLATFORM_SM8150)
Haynes Mathew George96483a22017-03-28 14:52:47 -070034#include <sound/devdep_params.h>
35#endif
Eric Laurentb23d5282013-05-14 15:27:20 -070036
jasmine cha270b7762018-03-30 15:41:33 +080037#include "maxxaudio.h"
jasmine chac89321b2018-04-10 21:37:01 +080038#include <resolv.h>
39
Jaekyun Seokf62e17d2017-03-08 17:15:28 +090040#define MIXER_XML_DEFAULT_PATH "mixer_paths.xml"
41#define MIXER_XML_BASE_STRING "mixer_paths"
vivek mehta60ea4152016-02-18 17:10:26 -080042#define TOMTOM_8226_SND_CARD_NAME "msm8226-tomtom-snd-card"
43#define TOMTOM_MIXER_FILE_SUFFIX "wcd9330"
44
Eric Laurentb23d5282013-05-14 15:27:20 -070045#define LIB_ACDB_LOADER "libacdbloader.so"
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -070046#define AUDIO_DATA_BLOCK_MIXER_CTL "HDMI EDID"
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +090047#define CVD_VERSION_MIXER_CTL "CVD Version"
Eric Laurentb23d5282013-05-14 15:27:20 -070048
Eric Laurentf9583c32016-03-28 13:50:50 -070049#define min(a, b) ((a) < (b) ? (a) : (b))
Eric Laurentb23d5282013-05-14 15:27:20 -070050
51/*
Eric Laurentb23d5282013-05-14 15:27:20 -070052 * This file will have a maximum of 38 bytes:
53 *
54 * 4 bytes: number of audio blocks
55 * 4 bytes: total length of Short Audio Descriptor (SAD) blocks
56 * Maximum 10 * 3 bytes: SAD blocks
57 */
58#define MAX_SAD_BLOCKS 10
59#define SAD_BLOCK_SIZE 3
60
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +090061#define MAX_CVD_VERSION_STRING_SIZE 100
62
Eric Laurentb23d5282013-05-14 15:27:20 -070063/* EDID format ID for LPCM audio */
64#define EDID_FORMAT_LPCM 1
65
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -070066#define MAX_SND_CARD_NAME_LEN 31
67
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -080068#define DEFAULT_APP_TYPE_RX_PATH 69936
69#define DEFAULT_APP_TYPE_TX_PATH 69938
Haynes Mathew George39c55dc2017-07-11 19:31:23 -070070#define DEFAULT_RX_BACKEND "SLIMBUS_0_RX"
vivek mehta1a9b7c02015-06-25 11:49:38 -070071
keunhui.parkc5aaa0e2015-07-13 10:57:37 +090072#define TOSTRING_(x) #x
73#define TOSTRING(x) TOSTRING_(x)
74
Vignesh Kulothungan64698822018-01-23 11:25:18 -080075#define GET_IN_DEVICE_INDEX(SND_DEVICE) ((SND_DEVICE) - (SND_DEVICE_IN_BEGIN))
76
Eric Laurentb23d5282013-05-14 15:27:20 -070077struct audio_block_header
78{
79 int reserved;
80 int length;
81};
82
vivek mehta1a9b7c02015-06-25 11:49:38 -070083enum {
84 CAL_MODE_SEND = 0x1,
85 CAL_MODE_PERSIST = 0x2,
86 CAL_MODE_RTAC = 0x4
87};
88
keunhui.park2f7306a2015-07-16 16:48:06 +090089#define PLATFORM_CONFIG_KEY_OPERATOR_INFO "operator_info"
90
91struct operator_info {
92 struct listnode list;
93 char *name;
94 char *mccmnc;
95};
96
97struct operator_specific_device {
98 struct listnode list;
99 char *operator;
100 char *mixer_path;
101 int acdb_id;
102};
103
Carter Hsu017c63a2018-10-15 15:01:42 -0700104struct external_specific_device {
105 struct listnode list;
106 char *usbid;
107 int acdb_id;
108};
109
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800110#define BE_DAI_NAME_MAX_LENGTH 24
111struct be_dai_name_struct {
112 unsigned int be_id;
113 char be_name[BE_DAI_NAME_MAX_LENGTH];
114};
115
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -0700116struct snd_device_to_mic_map {
117 struct mic_info microphones[AUDIO_MICROPHONE_MAX_COUNT];
118 size_t mic_count;
119};
120
keunhui.park2f7306a2015-07-16 16:48:06 +0900121static struct listnode operator_info_list;
122static struct listnode *operator_specific_device_table[SND_DEVICE_MAX];
Carter Hsu017c63a2018-10-15 15:01:42 -0700123static struct listnode *external_specific_device_table[SND_DEVICE_MAX];
keunhui.park2f7306a2015-07-16 16:48:06 +0900124
jasmine chac89321b2018-04-10 21:37:01 +0800125#define AUDIO_PARAMETER_KEY_AUD_CALDATA "cal_data"
126
127typedef struct acdb_audio_cal_cfg {
128 uint32_t persist;
129 uint32_t snd_dev_id;
130 audio_devices_t dev_id;
131 int32_t acdb_dev_id;
132 uint32_t app_type;
133 uint32_t topo_id;
134 uint32_t sampling_rate;
135 uint32_t cal_type;
136 uint32_t module_id;
justinwenge880e0c2018-11-22 13:49:38 +0800137#ifdef PLATFORM_SM8150
138 uint16_t instance_id;
139 uint16_t reserved;
140#endif
jasmine chac89321b2018-04-10 21:37:01 +0800141 uint32_t param_id;
142} acdb_audio_cal_cfg_t;
143
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700144/* Audio calibration related functions */
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800145typedef void (*acdb_send_audio_cal_v3_t)(int, int, int, int, int);
Eric Laurentb23d5282013-05-14 15:27:20 -0700146
Eric Laurentb23d5282013-05-14 15:27:20 -0700147struct platform_data {
148 struct audio_device *adev;
149 bool fluence_in_spkr_mode;
150 bool fluence_in_voice_call;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700151 bool fluence_in_voice_comm;
Eric Laurentb23d5282013-05-14 15:27:20 -0700152 bool fluence_in_voice_rec;
Prashant Malanic92c5962015-08-11 15:10:18 -0700153 /* 0 = no fluence, 1 = fluence, 2 = fluence pro */
154 int fluence_type;
155 int source_mic_type;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -0700156 bool speaker_lr_swap;
157
Eric Laurentb23d5282013-05-14 15:27:20 -0700158 void *acdb_handle;
Thierry Strudel07f96d12018-09-20 13:31:34 -0700159#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845) || (PLATFORM_SDM710) || (PLATFORM_SM8150)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -0700160 acdb_init_v2_cvd_t acdb_init;
161#elif defined (PLATFORM_MSM8084)
162 acdb_init_v2_t acdb_init;
163#else
164 acdb_init_t acdb_init;
165#endif
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700166 acdb_deallocate_t acdb_deallocate;
167 acdb_send_audio_cal_t acdb_send_audio_cal;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800168 acdb_send_audio_cal_v3_t acdb_send_audio_cal_v3;
jasmine chac89321b2018-04-10 21:37:01 +0800169 acdb_set_audio_cal_t acdb_set_audio_cal;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700170 acdb_send_voice_cal_t acdb_send_voice_cal;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700171 acdb_reload_vocvoltable_t acdb_reload_vocvoltable;
vivek mehta1a9b7c02015-06-25 11:49:38 -0700172 acdb_send_gain_dep_cal_t acdb_send_gain_dep_cal;
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -0700173 acdb_send_custom_top_t acdb_send_custom_top;
174 bool acdb_initialized;
175
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700176 struct csd_data *csd;
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800177 char ec_ref_mixer_path[64];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700178
David Linee3fe402017-03-13 10:00:42 -0700179 codec_backend_cfg_t current_backend_cfg[MAX_CODEC_BACKENDS];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700180 char *snd_card_name;
keunhui.parkc5aaa0e2015-07-13 10:57:37 +0900181 int max_vol_index;
Prashant Malanic92c5962015-08-11 15:10:18 -0700182 int max_mic_count;
vivek mehtade4849c2016-03-03 17:23:38 -0800183
184 void *hw_info;
jiabin8962a4d2018-03-19 18:21:24 -0700185
186 uint32_t declared_mic_count;
187 struct audio_microphone_characteristic_t microphones[AUDIO_MICROPHONE_MAX_COUNT];
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -0700188 struct snd_device_to_mic_map mic_map[SND_DEVICE_MAX];
Eric Laurentb23d5282013-05-14 15:27:20 -0700189};
190
Haynes Mathew George98c95622014-06-20 19:14:25 -0700191static int pcm_device_table[AUDIO_USECASE_MAX][2] = {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700192 [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = {DEEP_BUFFER_PCM_DEVICE,
193 DEEP_BUFFER_PCM_DEVICE},
Vignesh Kulothungan019d19b2019-01-23 11:09:18 -0800194 [USECASE_AUDIO_PLAYBACK_WITH_HAPTICS] = {AUDIO_HAPTICS_PCM_DEVICE,
195 AUDIO_HAPTICS_PCM_DEVICE},
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700196 [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
197 LOWLATENCY_PCM_DEVICE},
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800198 [USECASE_AUDIO_PLAYBACK_HIFI] = {MULTIMEDIA2_PCM_DEVICE,
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700199 MULTIMEDIA2_PCM_DEVICE},
200 [USECASE_AUDIO_PLAYBACK_OFFLOAD] = {PLAYBACK_OFFLOAD_DEVICE,
201 PLAYBACK_OFFLOAD_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700202 [USECASE_AUDIO_PLAYBACK_TTS] = {MULTIMEDIA2_PCM_DEVICE,
203 MULTIMEDIA2_PCM_DEVICE},
204 [USECASE_AUDIO_PLAYBACK_ULL] = {MULTIMEDIA3_PCM_DEVICE,
205 MULTIMEDIA3_PCM_DEVICE},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800206 [USECASE_AUDIO_PLAYBACK_MMAP] = {MMAP_PLAYBACK_PCM_DEVICE,
207 MMAP_PLAYBACK_PCM_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700208
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700209 [USECASE_AUDIO_RECORD] = {AUDIO_RECORD_PCM_DEVICE,
210 AUDIO_RECORD_PCM_DEVICE},
211 [USECASE_AUDIO_RECORD_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
212 LOWLATENCY_PCM_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700213
Eric Laurent0e46adf2016-12-16 12:49:24 -0800214 [USECASE_AUDIO_RECORD_MMAP] = {MMAP_RECORD_PCM_DEVICE,
215 MMAP_RECORD_PCM_DEVICE},
Haynes Mathew George569b7482017-05-08 14:44:27 -0700216 [USECASE_AUDIO_RECORD_HIFI] = {MULTIMEDIA2_PCM_DEVICE,
217 MULTIMEDIA2_PCM_DEVICE},
218
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700219 [USECASE_VOICE_CALL] = {VOICE_CALL_PCM_DEVICE,
220 VOICE_CALL_PCM_DEVICE},
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700221 [USECASE_VOICE2_CALL] = {VOICE2_CALL_PCM_DEVICE, VOICE2_CALL_PCM_DEVICE},
222 [USECASE_VOLTE_CALL] = {VOLTE_CALL_PCM_DEVICE, VOLTE_CALL_PCM_DEVICE},
223 [USECASE_QCHAT_CALL] = {QCHAT_CALL_PCM_DEVICE, QCHAT_CALL_PCM_DEVICE},
224 [USECASE_VOWLAN_CALL] = {VOWLAN_CALL_PCM_DEVICE, VOWLAN_CALL_PCM_DEVICE},
vivek mehtaa51fd402016-02-04 19:49:33 -0800225 [USECASE_VOICEMMODE1_CALL] = {VOICEMMODE1_CALL_PCM_DEVICE,
226 VOICEMMODE1_CALL_PCM_DEVICE},
227 [USECASE_VOICEMMODE2_CALL] = {VOICEMMODE2_CALL_PCM_DEVICE,
228 VOICEMMODE2_CALL_PCM_DEVICE},
229
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700230 [USECASE_INCALL_REC_UPLINK] = {AUDIO_RECORD_PCM_DEVICE,
231 AUDIO_RECORD_PCM_DEVICE},
232 [USECASE_INCALL_REC_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
233 AUDIO_RECORD_PCM_DEVICE},
234 [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
235 AUDIO_RECORD_PCM_DEVICE},
Ravi Kumar Alamanda8e6e98f2013-11-05 15:57:39 -0800236 [USECASE_AUDIO_HFP_SCO] = {HFP_PCM_RX, HFP_SCO_RX},
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700237
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700238 [USECASE_AUDIO_SPKR_CALIB_RX] = {SPKR_PROT_CALIB_RX_PCM_DEVICE, -1},
239 [USECASE_AUDIO_SPKR_CALIB_TX] = {-1, SPKR_PROT_CALIB_TX_PCM_DEVICE},
240
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700241 [USECASE_AUDIO_PLAYBACK_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
242 AFE_PROXY_RECORD_PCM_DEVICE},
243 [USECASE_AUDIO_RECORD_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
244 AFE_PROXY_RECORD_PCM_DEVICE},
zhaoyang yin4211fad2015-06-04 21:13:25 +0800245 [USECASE_AUDIO_DSM_FEEDBACK] = {QUAT_MI2S_PCM_DEVICE, QUAT_MI2S_PCM_DEVICE},
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700246
vivek mehtaa68fea62017-06-08 19:04:02 -0700247 [USECASE_AUDIO_PLAYBACK_VOIP] = {AUDIO_PLAYBACK_VOIP_PCM_DEVICE,
248 AUDIO_PLAYBACK_VOIP_PCM_DEVICE},
249 [USECASE_AUDIO_RECORD_VOIP] = {AUDIO_RECORD_VOIP_PCM_DEVICE,
250 AUDIO_RECORD_VOIP_PCM_DEVICE},
Nadav Bar3d72cfc2018-01-07 12:19:24 +0200251
252 [USECASE_INCALL_MUSIC_UPLINK] = {INCALL_MUSIC_UPLINK_PCM_DEVICE,
253 INCALL_MUSIC_UPLINK_PCM_DEVICE},
Eric Laurentb23d5282013-05-14 15:27:20 -0700254};
255
256/* Array to store sound devices */
257static const char * const device_table[SND_DEVICE_MAX] = {
258 [SND_DEVICE_NONE] = "none",
259 /* Playback sound devices */
260 [SND_DEVICE_OUT_HANDSET] = "handset",
261 [SND_DEVICE_OUT_SPEAKER] = "speaker",
262 [SND_DEVICE_OUT_SPEAKER_REVERSE] = "speaker-reverse",
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700263 [SND_DEVICE_OUT_SPEAKER_SAFE] = "speaker-safe",
Eric Laurentb23d5282013-05-14 15:27:20 -0700264 [SND_DEVICE_OUT_HEADPHONES] = "headphones",
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500265 [SND_DEVICE_OUT_LINE] = "line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700266 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones",
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700267 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = "speaker-safe-and-headphones",
Eric Laurent744996b2014-10-01 11:40:40 -0500268 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = "speaker-and-line",
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700269 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = "speaker-safe-and-line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700270 [SND_DEVICE_OUT_VOICE_HANDSET] = "voice-handset",
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500271 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = "voice-hac-handset",
Eric Laurentb23d5282013-05-14 15:27:20 -0700272 [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker",
273 [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones",
yixuanjiang9536e672018-09-06 18:43:36 +0800274 [SND_DEVICE_OUT_VOICE_HEADSET] = "voice-headphones",
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500275 [SND_DEVICE_OUT_VOICE_LINE] = "voice-line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700276 [SND_DEVICE_OUT_HDMI] = "hdmi",
277 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi",
278 [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700279 [SND_DEVICE_OUT_BT_SCO_WB] = "bt-sco-headset-wb",
Aniket Kumar Lata26483012018-01-31 20:21:42 -0800280 [SND_DEVICE_OUT_BT_A2DP] = "bt-a2dp",
281 [SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] = "speaker-and-bt-a2dp",
Aniket Kumar Lata9723a962018-05-16 17:41:55 -0700282 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP] = "speaker-safe-and-bt-a2dp",
Eric Laurentb23d5282013-05-14 15:27:20 -0700283 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = "voice-handset-tmus",
284 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones",
285 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones",
286 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset",
vivek mehtaa6b79742017-03-09 15:40:43 -0800287 [SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = "voice-tty-full-usb",
288 [SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = "voice-tty-vco-usb",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700289 [SND_DEVICE_OUT_VOICE_TX] = "voice-tx",
juyuchen66c4ecf2018-08-06 15:39:34 +0800290 [SND_DEVICE_OUT_VOICE_MUSIC_TX] = "voice-music-tx",
David Linee3fe402017-03-13 10:00:42 -0700291 [SND_DEVICE_OUT_USB_HEADSET] = "usb-headset",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700292 [SND_DEVICE_OUT_VOICE_USB_HEADSET] = "usb-headset",
David Linee3fe402017-03-13 10:00:42 -0700293 [SND_DEVICE_OUT_USB_HEADPHONES] = "usb-headphones",
jasmine cha270b7762018-03-30 15:41:33 +0800294 [SND_DEVICE_OUT_USB_HEADSET_SPEC] = "usb-headset",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700295 [SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = "usb-headphones",
David Linee3fe402017-03-13 10:00:42 -0700296 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = "speaker-and-usb-headphones",
Haynes Mathew George9090bfb2017-05-31 11:44:50 -0700297 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] = "speaker-safe-and-usb-headphones",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700298 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = "speaker-protected",
299 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = "voice-speaker-protected",
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -0700300 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = "voice-speaker-hfp",
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -0800301 [SND_DEVICE_OUT_SPEAKER_AND_BT_SCO] = "speaker-and-bt-sco",
juyuchen5351ea62018-05-16 10:54:37 +0800302 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO] = "speaker-safe-and-bt-sco",
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -0800303 [SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB] = "speaker-and-bt-sco-wb",
juyuchen5351ea62018-05-16 10:54:37 +0800304 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB] = "speaker-safe-and-bt-sco-wb",
juyuchend194b432018-11-16 14:15:16 +0800305 [SND_DEVICE_OUT_VOICE_HEARING_AID] = "hearing-aid",
Eric Laurentb23d5282013-05-14 15:27:20 -0700306
307 /* Capture sound devices */
308 [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700309 [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700310 [SND_DEVICE_IN_HANDSET_MIC_NS] = "handset-mic",
311 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = "handset-mic",
312 [SND_DEVICE_IN_HANDSET_DMIC] = "dmic-endfire",
313 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = "dmic-endfire",
314 [SND_DEVICE_IN_HANDSET_DMIC_NS] = "dmic-endfire",
315 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = "dmic-endfire",
316 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = "dmic-endfire",
317
318 [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
319 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "speaker-mic",
320 [SND_DEVICE_IN_SPEAKER_MIC_NS] = "speaker-mic",
321 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = "speaker-mic",
322 [SND_DEVICE_IN_SPEAKER_DMIC] = "speaker-dmic-endfire",
323 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = "speaker-dmic-endfire",
324 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = "speaker-dmic-endfire",
325 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = "speaker-dmic-endfire",
326 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = "speaker-dmic-endfire",
327
328 [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
Eric Laurentcefbbac2014-09-04 13:54:10 -0500329 [SND_DEVICE_IN_HEADSET_MIC_AEC] = "headset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700330
Eric Laurentb23d5282013-05-14 15:27:20 -0700331 [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic",
332 [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700333 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = "bt-sco-mic",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700334 [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700335 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = "bt-sco-mic-wb",
Eric Laurent5f4ca952018-10-19 17:33:43 -0700336 [SND_DEVICE_IN_CAMCORDER_LANDSCAPE] = "camcorder-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700337
338 [SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef",
339 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = "voice-dmic-ef-tmus",
340 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
341 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = "voice-speaker-dmic-ef",
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -0700342 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = "voice-speaker-mic-hfp",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700343 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700344 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
345 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
346 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
vivek mehtaa6b79742017-03-09 15:40:43 -0800347 [SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = "voice-tty-full-usb-mic",
348 [SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = "voice-tty-hco-usb-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700349
Eric Laurentb23d5282013-05-14 15:27:20 -0700350 [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700351 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = "voice-rec-mic",
vivek mehta733c1df2016-04-04 15:09:24 -0700352 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = "voice-rec-mic",
vivek mehtaf3440682016-05-11 14:24:37 -0700353 [SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700354 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = "voice-rec-dmic-ef",
355 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence",
David Linee3fe402017-03-13 10:00:42 -0700356 [SND_DEVICE_IN_USB_HEADSET_MIC] = "usb-headset-mic",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700357 [SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] ="usb-headset-mic",
358 [SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = "usb-headset-mic",
359 [SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = "usb-headset-mic",
360 [SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = "usb-headset-mic",
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700361 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = "headset-mic",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700362
Ricardo Garcia9034bc42016-04-04 07:11:46 -0700363 [SND_DEVICE_IN_UNPROCESSED_MIC] = "unprocessed-mic",
vivek mehta0125e782016-06-16 18:03:11 -0700364 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = "unprocessed-stereo-mic",
365 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = "unprocessed-three-mic",
366 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = "unprocessed-quad-mic",
367 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = "unprocessed-headset-mic",
rago90fb9612015-12-02 11:37:53 -0800368
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700369 [SND_DEVICE_IN_VOICE_RX] = "voice-rx",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700370
Prashant Malanic92c5962015-08-11 15:10:18 -0700371 [SND_DEVICE_IN_THREE_MIC] = "three-mic",
372 [SND_DEVICE_IN_QUAD_MIC] = "quad-mic",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700373 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = "vi-feedback",
Prashant Malanic92c5962015-08-11 15:10:18 -0700374 [SND_DEVICE_IN_HANDSET_TMIC] = "three-mic",
375 [SND_DEVICE_IN_HANDSET_QMIC] = "quad-mic",
vivek mehta733c1df2016-04-04 15:09:24 -0700376 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = "three-mic",
377 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = "quad-mic",
Eric Laurent5f4ca952018-10-19 17:33:43 -0700378 [SND_DEVICE_IN_CAMCORDER_INVERT_LANDSCAPE] = "camcorder-mic",
379 [SND_DEVICE_IN_CAMCORDER_PORTRAIT] = "camcorder-mic",
380 [SND_DEVICE_IN_CAMCORDER_SELFIE_LANDSCAPE] = "camcorder-mic",
381 [SND_DEVICE_IN_CAMCORDER_SELFIE_INVERT_LANDSCAPE] = "camcorder-mic",
382 [SND_DEVICE_IN_CAMCORDER_SELFIE_PORTRAIT] = "camcorder-mic",
Vignesh Kulothungan64698822018-01-23 11:25:18 -0800383 [SND_DEVICE_IN_SPEAKER_QMIC_NS] = "quad-mic",
384 [SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS] = "quad-mic",
juyuchend194b432018-11-16 14:15:16 +0800385 [SND_DEVICE_IN_VOICE_HEARING_AID] = "hearing-aid-mic",
Vignesh Kulothungan64698822018-01-23 11:25:18 -0800386};
387
388static struct audio_effect_config \
389 effect_config_table[GET_IN_DEVICE_INDEX(SND_DEVICE_MAX)][EFFECT_COUNT] = {
390 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS)][EFFECT_AEC] = \
391 {TX_VOICE_FLUENCE_PROV2, 0x0, 0x10EAF, 0x01},
392 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS)][EFFECT_NS] = \
393 {TX_VOICE_FLUENCE_PROV2, 0x0, 0x10EAF, 0x02},
394 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)][EFFECT_AEC] = \
395 {TX_VOICE_FV5ECNS_DM, 0x0, 0x10EAF, 0x01},
396 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)][EFFECT_NS] = \
397 {TX_VOICE_FV5ECNS_DM, 0x0, 0x10EAF, 0x02},
398 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)][EFFECT_AEC] = \
399 {TX_VOICE_FV5ECNS_SM, 0x0, 0x10EAF, 0x01},
400 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)][EFFECT_NS] = \
401 {TX_VOICE_FV5ECNS_SM, 0x0, 0x10EAF, 0x02},
402 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)][EFFECT_AEC] = \
403 {TX_VOICE_FV5ECNS_DM, 0x0, 0x10EAF, 0x01},
404 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)][EFFECT_NS] = \
405 {TX_VOICE_FV5ECNS_DM, 0x0, 0x10EAF, 0x02},
406 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)][EFFECT_AEC] = \
407 {TX_VOICE_FV5ECNS_SM, 0x0, 0x10EAF, 0x01},
408 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)][EFFECT_NS] = \
409 {TX_VOICE_FV5ECNS_SM, 0x0, 0x10EAF, 0x02},
Eric Laurentb23d5282013-05-14 15:27:20 -0700410};
411
412/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700413static int acdb_device_table[SND_DEVICE_MAX] = {
Eric Laurentb23d5282013-05-14 15:27:20 -0700414 [SND_DEVICE_NONE] = -1,
415 [SND_DEVICE_OUT_HANDSET] = 7,
416 [SND_DEVICE_OUT_SPEAKER] = 15,
417 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 15,
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700418 [SND_DEVICE_OUT_SPEAKER_SAFE] = 15,
Eric Laurentb23d5282013-05-14 15:27:20 -0700419 [SND_DEVICE_OUT_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500420 [SND_DEVICE_OUT_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700421 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700422 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500423 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = 77,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700424 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = 77,
Ravi Kumar Alamanda235c3482014-08-21 17:32:44 -0700425 [SND_DEVICE_OUT_VOICE_HANDSET] = ACDB_ID_VOICE_HANDSET,
426 [SND_DEVICE_OUT_VOICE_SPEAKER] = ACDB_ID_VOICE_SPEAKER,
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500427 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = 53,
Eric Laurentb23d5282013-05-14 15:27:20 -0700428 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
yixuanjiang9536e672018-09-06 18:43:36 +0800429 [SND_DEVICE_OUT_VOICE_HEADSET] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500430 [SND_DEVICE_OUT_VOICE_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700431 [SND_DEVICE_OUT_HDMI] = 18,
432 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 15,
433 [SND_DEVICE_OUT_BT_SCO] = 22,
juyuchen5351ea62018-05-16 10:54:37 +0800434 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO] = 14,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700435 [SND_DEVICE_OUT_BT_SCO_WB] = 39,
juyuchen5351ea62018-05-16 10:54:37 +0800436 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB] = 14,
Aniket Kumar Lata26483012018-01-31 20:21:42 -0800437 [SND_DEVICE_OUT_BT_A2DP] = 20,
438 [SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] = 14,
Aniket Kumar Lata9723a962018-05-16 17:41:55 -0700439 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP] = 14,
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700440 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = ACDB_ID_VOICE_HANDSET_TMUS,
Eric Laurentb23d5282013-05-14 15:27:20 -0700441 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
442 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
443 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
vivek mehtaa6b79742017-03-09 15:40:43 -0800444 [SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = 17,
445 [SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = 17,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700446 [SND_DEVICE_OUT_VOICE_TX] = 45,
juyuchen66c4ecf2018-08-06 15:39:34 +0800447 [SND_DEVICE_OUT_VOICE_MUSIC_TX] = 3,
David Linee3fe402017-03-13 10:00:42 -0700448 [SND_DEVICE_OUT_USB_HEADSET] = 45,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700449 [SND_DEVICE_OUT_VOICE_USB_HEADSET] = 45,
David Linee3fe402017-03-13 10:00:42 -0700450 [SND_DEVICE_OUT_USB_HEADPHONES] = 45,
jasmine cha270b7762018-03-30 15:41:33 +0800451 [SND_DEVICE_OUT_USB_HEADSET_SPEC] = 45,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700452 [SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = 45,
David Linee3fe402017-03-13 10:00:42 -0700453 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = 14,
Haynes Mathew George9090bfb2017-05-31 11:44:50 -0700454 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] = 14,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700455 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = 124,
456 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = 101,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700457 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = ACDB_ID_VOICE_SPEAKER,
juyuchend194b432018-11-16 14:15:16 +0800458 [SND_DEVICE_OUT_VOICE_HEARING_AID] = 45,
Eric Laurentb23d5282013-05-14 15:27:20 -0700459
460 [SND_DEVICE_IN_HANDSET_MIC] = 4,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700461 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 106,
462 [SND_DEVICE_IN_HANDSET_MIC_NS] = 107,
463 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = 108,
464 [SND_DEVICE_IN_HANDSET_DMIC] = 41,
465 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = 109,
466 [SND_DEVICE_IN_HANDSET_DMIC_NS] = 110,
467 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = 111,
468 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = 34,
469
470 [SND_DEVICE_IN_SPEAKER_MIC] = 11,
471 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 112,
472 [SND_DEVICE_IN_SPEAKER_MIC_NS] = 113,
473 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = 114,
474 [SND_DEVICE_IN_SPEAKER_DMIC] = 43,
475 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = 115,
476 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = 116,
477 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = 117,
478 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = 35,
479
rago90fb9612015-12-02 11:37:53 -0800480 [SND_DEVICE_IN_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentcefbbac2014-09-04 13:54:10 -0500481 [SND_DEVICE_IN_HEADSET_MIC_AEC] = ACDB_ID_HEADSET_MIC_AEC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700482
Eric Laurentb23d5282013-05-14 15:27:20 -0700483 [SND_DEVICE_IN_HDMI_MIC] = 4,
484 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700485 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = 21,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700486 [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700487 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = 38,
Eric Laurent5f4ca952018-10-19 17:33:43 -0700488 [SND_DEVICE_IN_CAMCORDER_LANDSCAPE] = 61,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700489
490 [SND_DEVICE_IN_VOICE_DMIC] = 41,
491 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = ACDB_ID_VOICE_DMIC_EF_TMUS,
492 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700493 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = 11,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700494 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 43,
rago90fb9612015-12-02 11:37:53 -0800495 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentb23d5282013-05-14 15:27:20 -0700496 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
497 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
498 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
vivek mehtaa6b79742017-03-09 15:40:43 -0800499 [SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = 16,
500 [SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = 16,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700501
rago90fb9612015-12-02 11:37:53 -0800502 [SND_DEVICE_IN_VOICE_REC_MIC] = ACDB_ID_VOICE_REC_MIC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700503 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = 113,
vivek mehta733c1df2016-04-04 15:09:24 -0700504 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = 112,
vivek mehtaf3440682016-05-11 14:24:37 -0700505 [SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = 114,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700506 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = 35,
507 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 43,
rago90fb9612015-12-02 11:37:53 -0800508 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
509
510 [SND_DEVICE_IN_UNPROCESSED_MIC] = ACDB_ID_VOICE_REC_MIC,
511 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
vivek mehta4ed66e62016-04-15 23:33:34 -0700512 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = 35,
513 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = 125,
514 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = 125,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700515
516 [SND_DEVICE_IN_VOICE_RX] = 44,
David Linee3fe402017-03-13 10:00:42 -0700517 [SND_DEVICE_IN_USB_HEADSET_MIC] = 44,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700518 [SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = 44,
519 [SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = 44,
520 [SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = 44,
521 [SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = 44,
Prashant Malanic92c5962015-08-11 15:10:18 -0700522 [SND_DEVICE_IN_THREE_MIC] = 46,
523 [SND_DEVICE_IN_QUAD_MIC] = 46,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700524 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = 102,
Prashant Malanic92c5962015-08-11 15:10:18 -0700525 [SND_DEVICE_IN_HANDSET_TMIC] = 125,
526 [SND_DEVICE_IN_HANDSET_QMIC] = 125,
vivek mehta733c1df2016-04-04 15:09:24 -0700527 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = 125, /* override this for new target to 140 */
528 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = 125, /* override this for new target to 140 */
Eric Laurent5f4ca952018-10-19 17:33:43 -0700529 [SND_DEVICE_IN_CAMCORDER_INVERT_LANDSCAPE] = 61,
530 [SND_DEVICE_IN_CAMCORDER_PORTRAIT] = 61,
531 [SND_DEVICE_IN_CAMCORDER_SELFIE_LANDSCAPE] = 61,
532 [SND_DEVICE_IN_CAMCORDER_SELFIE_INVERT_LANDSCAPE] = 61,
533 [SND_DEVICE_IN_CAMCORDER_SELFIE_PORTRAIT] = 61,
Vignesh Kulothungan64698822018-01-23 11:25:18 -0800534 [SND_DEVICE_IN_SPEAKER_QMIC_NS] = 129,
535 [SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS] = 129,
juyuchend194b432018-11-16 14:15:16 +0800536 [SND_DEVICE_IN_VOICE_HEARING_AID] = 44,
Eric Laurentb23d5282013-05-14 15:27:20 -0700537};
538
David Linee3fe402017-03-13 10:00:42 -0700539// Platform specific backend bit width table
540static int backend_bit_width_table[SND_DEVICE_MAX] = {0};
541
Haynes Mathew George98c95622014-06-20 19:14:25 -0700542struct name_to_index {
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700543 char name[100];
544 unsigned int index;
545};
546
547#define TO_NAME_INDEX(X) #X, X
548
Haynes Mathew George98c95622014-06-20 19:14:25 -0700549/* Used to get index from parsed string */
550static const struct name_to_index snd_device_name_index[SND_DEVICE_MAX] = {
551 /* out */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700552 {TO_NAME_INDEX(SND_DEVICE_OUT_HANDSET)},
553 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER)},
554 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_REVERSE)},
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700555 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700556 {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500557 {TO_NAME_INDEX(SND_DEVICE_OUT_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700558 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700559 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES)},
Eric Laurent744996b2014-10-01 11:40:40 -0500560 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_LINE)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700561 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700562 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET)},
563 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700564 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_HFP)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700565 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADPHONES)},
yixuanjiang9536e672018-09-06 18:43:36 +0800566 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADSET)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500567 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700568 {TO_NAME_INDEX(SND_DEVICE_OUT_HDMI)},
569 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HDMI)},
570 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO)},
juyuchen5351ea62018-05-16 10:54:37 +0800571 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700572 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO_WB)},
juyuchen5351ea62018-05-16 10:54:37 +0800573 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB)},
Aniket Kumar Lata26483012018-01-31 20:21:42 -0800574 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_A2DP)},
575 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP)},
Aniket Kumar Lata9723a962018-05-16 17:41:55 -0700576 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700577 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET_TMUS)},
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500578 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HAC_HANDSET)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700579 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES)},
580 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES)},
581 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET)},
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -0800582 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_SCO)},
583 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800584 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_USB)},
585 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_USB)},
David Linee3fe402017-03-13 10:00:42 -0700586 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADSET)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700587 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_USB_HEADSET)},
David Linee3fe402017-03-13 10:00:42 -0700588 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADPHONES)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700589 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_USB_HEADPHONES)},
David Linee3fe402017-03-13 10:00:42 -0700590 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET)},
Haynes Mathew George9090bfb2017-05-31 11:44:50 -0700591 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700592 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED)},
593 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED)},
jasmine cha270b7762018-03-30 15:41:33 +0800594 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADSET_SPEC)},
juyuchend194b432018-11-16 14:15:16 +0800595 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEARING_AID)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800596
597 /* in */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700598 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700599 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700600 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_NS)},
601 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)},
602 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC)},
603 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC)},
604 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_NS)},
605 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)},
606 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_STEREO)},
607
608 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700609 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700610 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_NS)},
611 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)},
612 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC)},
613 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC)},
614 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS)},
615 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)},
616 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_STEREO)},
617
618 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC)},
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700619 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700620
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700621 {TO_NAME_INDEX(SND_DEVICE_IN_HDMI_MIC)},
622 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700623 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700624 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700625 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB_NREC)},
Eric Laurent5f4ca952018-10-19 17:33:43 -0700626 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_LANDSCAPE)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700627
628 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC)},
629 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC_TMUS)},
630 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700631 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700632 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC)},
633 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEADSET_MIC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700634 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC)},
635 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC)},
636 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800637 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC)},
638 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC)},
639
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700640
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700641 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700642 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_NS)},
vivek mehta733c1df2016-04-04 15:09:24 -0700643 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC)},
vivek mehtaf3440682016-05-11 14:24:37 -0700644 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700645 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_STEREO)},
646 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE)},
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700647 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_HEADSET_MIC)},
David Linee3fe402017-03-13 10:00:42 -0700648 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700649 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_USB_HEADSET_MIC)},
650 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC)},
651 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC)},
652 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC_AEC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700653
rago90fb9612015-12-02 11:37:53 -0800654 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_MIC)},
655 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC)},
vivek mehta4ed66e62016-04-15 23:33:34 -0700656 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_STEREO_MIC)},
657 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_THREE_MIC)},
658 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_QUAD_MIC)},
rago90fb9612015-12-02 11:37:53 -0800659
Prashant Malanic92c5962015-08-11 15:10:18 -0700660 {TO_NAME_INDEX(SND_DEVICE_IN_THREE_MIC)},
661 {TO_NAME_INDEX(SND_DEVICE_IN_QUAD_MIC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700662 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_VI_FEEDBACK)},
Prashant Malanic92c5962015-08-11 15:10:18 -0700663 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC)},
664 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC)},
vivek mehta733c1df2016-04-04 15:09:24 -0700665 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC_AEC)},
666 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC_AEC)},
Eric Laurent5f4ca952018-10-19 17:33:43 -0700667 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_INVERT_LANDSCAPE)},
668 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_PORTRAIT)},
669 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_SELFIE_LANDSCAPE)},
670 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_SELFIE_INVERT_LANDSCAPE)},
671 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_SELFIE_PORTRAIT)},
juyuchend194b432018-11-16 14:15:16 +0800672 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEARING_AID)},
673
Eric Laurent5f4ca952018-10-19 17:33:43 -0700674 /* For legacy xml file parsing */
675 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_MIC)},
Vignesh Kulothungan64698822018-01-23 11:25:18 -0800676 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_QMIC_NS)},
677 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700678};
679
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700680static char * backend_tag_table[SND_DEVICE_MAX] = {0};
681static char * hw_interface_table[SND_DEVICE_MAX] = {0};
Haynes Mathew George98c95622014-06-20 19:14:25 -0700682
683static const struct name_to_index usecase_name_index[AUDIO_USECASE_MAX] = {
684 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_DEEP_BUFFER)},
685 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_LOW_LATENCY)},
Vignesh Kulothungan019d19b2019-01-23 11:09:18 -0800686 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_WITH_HAPTICS)},
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800687 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_HIFI)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700688 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD)},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700689 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_TTS)},
690 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_ULL)},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800691 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_MMAP)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700692 {TO_NAME_INDEX(USECASE_AUDIO_RECORD)},
693 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_LOW_LATENCY)},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800694 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_MMAP)},
Haynes Mathew George569b7482017-05-08 14:44:27 -0700695 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_HIFI)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700696 {TO_NAME_INDEX(USECASE_VOICE_CALL)},
697 {TO_NAME_INDEX(USECASE_VOICE2_CALL)},
698 {TO_NAME_INDEX(USECASE_VOLTE_CALL)},
699 {TO_NAME_INDEX(USECASE_QCHAT_CALL)},
700 {TO_NAME_INDEX(USECASE_VOWLAN_CALL)},
John Muirf1346ce2016-12-06 00:03:41 -0800701 {TO_NAME_INDEX(USECASE_VOICEMMODE1_CALL)},
702 {TO_NAME_INDEX(USECASE_VOICEMMODE2_CALL)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700703 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK)},
704 {TO_NAME_INDEX(USECASE_INCALL_REC_DOWNLINK)},
705 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK_AND_DOWNLINK)},
706 {TO_NAME_INDEX(USECASE_AUDIO_HFP_SCO)},
John Muirf1346ce2016-12-06 00:03:41 -0800707 {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_RX)},
708 {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_TX)},
709 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_AFE_PROXY)},
710 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_AFE_PROXY)},
711 {TO_NAME_INDEX(USECASE_AUDIO_DSM_FEEDBACK)},
vivek mehtaa68fea62017-06-08 19:04:02 -0700712 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_VOIP)},
713 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_VOIP)},
Nadav Bar3d72cfc2018-01-07 12:19:24 +0200714 {TO_NAME_INDEX(USECASE_INCALL_MUSIC_UPLINK)},
Aniket Kumar Lata99546312018-03-19 21:38:38 -0700715 {TO_NAME_INDEX(USECASE_AUDIO_A2DP_ABR_FEEDBACK)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700716};
717
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800718static const struct name_to_index usecase_type_index[USECASE_TYPE_MAX] = {
719 {TO_NAME_INDEX(PCM_PLAYBACK)},
720 {TO_NAME_INDEX(PCM_CAPTURE)},
721 {TO_NAME_INDEX(VOICE_CALL)},
722 {TO_NAME_INDEX(PCM_HFP_CALL)},
723};
724
725struct app_type_entry {
726 int uc_type;
727 int bit_width;
728 int app_type;
729 int max_rate;
vivek mehtaa68fea62017-06-08 19:04:02 -0700730 char *mode;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800731 struct listnode node; // membership in app_type_entry_list;
732};
733
734static struct listnode app_type_entry_list;
735
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700736#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
737#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
Eric Laurent0e46adf2016-12-16 12:49:24 -0800738#define ULL_PLATFORM_DELAY (3*1000LL)
739#define MMAP_PLATFORM_DELAY (3*1000LL)
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700740
Eric Laurentb23d5282013-05-14 15:27:20 -0700741static pthread_once_t check_op_once_ctl = PTHREAD_ONCE_INIT;
742static bool is_tmus = false;
743
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800744static int init_be_dai_name_table(struct audio_device *adev);
745
Carter Hsu017c63a2018-10-15 15:01:42 -0700746static bool is_usb_snd_dev(snd_device_t snd_device)
747{
748 if (snd_device < SND_DEVICE_IN_BEGIN) {
749 if (snd_device == SND_DEVICE_OUT_USB_HEADSET ||\
750 snd_device == SND_DEVICE_OUT_USB_HEADPHONES ||\
751 snd_device == SND_DEVICE_OUT_VOICE_USB_HEADPHONES ||\
752 snd_device == SND_DEVICE_OUT_VOICE_USB_HEADSET ||\
753 snd_device == SND_DEVICE_OUT_VOICE_TTY_FULL_USB ||\
754 snd_device == SND_DEVICE_OUT_VOICE_TTY_VCO_USB)
755 return true;
756 } else {
757 if (snd_device == SND_DEVICE_IN_USB_HEADSET_MIC ||\
758 snd_device == SND_DEVICE_IN_USB_HEADSET_MIC_AEC ||\
759 snd_device == SND_DEVICE_IN_VOICE_USB_HEADSET_MIC ||\
760 snd_device == SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC ||\
761 snd_device == SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC)
762 return true;
763 }
764 return false;
765}
766
Eric Laurentb23d5282013-05-14 15:27:20 -0700767static void check_operator()
768{
769 char value[PROPERTY_VALUE_MAX];
770 int mccmnc;
771 property_get("gsm.sim.operator.numeric",value,"0");
772 mccmnc = atoi(value);
Eric Laurent2bafff12016-03-17 12:17:23 -0700773 ALOGD("%s: tmus mccmnc %d", __func__, mccmnc);
Eric Laurentb23d5282013-05-14 15:27:20 -0700774 switch(mccmnc) {
775 /* TMUS MCC(310), MNC(490, 260, 026) */
776 case 310490:
777 case 310260:
778 case 310026:
sangwon.jeonb891db52013-09-14 17:39:15 +0900779 /* Add new TMUS MNC(800, 660, 580, 310, 270, 250, 240, 230, 220, 210, 200, 160) */
780 case 310800:
781 case 310660:
782 case 310580:
783 case 310310:
784 case 310270:
785 case 310250:
786 case 310240:
787 case 310230:
788 case 310220:
789 case 310210:
790 case 310200:
791 case 310160:
Eric Laurentb23d5282013-05-14 15:27:20 -0700792 is_tmus = true;
793 break;
794 }
795}
796
797bool is_operator_tmus()
798{
799 pthread_once(&check_op_once_ctl, check_operator);
800 return is_tmus;
801}
802
keunhui.park2f7306a2015-07-16 16:48:06 +0900803static char *get_current_operator()
804{
805 struct listnode *node;
806 struct operator_info *info_item;
807 char mccmnc[PROPERTY_VALUE_MAX];
808 char *ret = NULL;
809
Tom Cherry7fea2042016-11-10 18:05:59 -0800810 property_get("gsm.sim.operator.numeric",mccmnc,"00000");
keunhui.park2f7306a2015-07-16 16:48:06 +0900811
812 list_for_each(node, &operator_info_list) {
813 info_item = node_to_item(node, struct operator_info, list);
814 if (strstr(info_item->mccmnc, mccmnc) != NULL) {
815 ret = info_item->name;
816 }
817 }
818
819 return ret;
820}
821
822static struct operator_specific_device *get_operator_specific_device(snd_device_t snd_device)
823{
824 struct listnode *node;
825 struct operator_specific_device *ret = NULL;
826 struct operator_specific_device *device_item;
827 char *operator_name;
828
829 operator_name = get_current_operator();
830 if (operator_name == NULL)
831 return ret;
832
833 list_for_each(node, operator_specific_device_table[snd_device]) {
834 device_item = node_to_item(node, struct operator_specific_device, list);
835 if (strcmp(operator_name, device_item->operator) == 0) {
836 ret = device_item;
837 }
838 }
839
840 return ret;
841}
842
843
844static int get_operator_specific_device_acdb_id(snd_device_t snd_device)
845{
846 struct operator_specific_device *device;
847 int ret = acdb_device_table[snd_device];
848
849 device = get_operator_specific_device(snd_device);
850 if (device != NULL)
851 ret = device->acdb_id;
852
853 return ret;
854}
855
Carter Hsu017c63a2018-10-15 15:01:42 -0700856static int get_external_specific_device_acdb_id(snd_device_t snd_device)
857{
858 struct external_specific_device *ext_dev;
859 int ret = acdb_device_table[snd_device];
860 char *usbid = NULL;
861 struct listnode *node;
862
863 if (is_usb_snd_dev(snd_device))
864 usbid = audio_extn_usb_usbid();
865
866 if (usbid) {
867 list_for_each(node, external_specific_device_table[snd_device]) {
868 ext_dev = node_to_item(node, struct external_specific_device, list);
869 if (ext_dev->usbid && !strcmp(usbid, ext_dev->usbid)) {
870 ret = ext_dev->acdb_id;
871 break;
872 }
873 }
874
875 free(usbid);
876 }
877 return ret;
878}
879
keunhui.park2f7306a2015-07-16 16:48:06 +0900880static const char *get_operator_specific_device_mixer_path(snd_device_t snd_device)
881{
882 struct operator_specific_device *device;
883 const char *ret = device_table[snd_device];
884
885 device = get_operator_specific_device(snd_device);
886 if (device != NULL)
887 ret = device->mixer_path;
888
889 return ret;
890}
891
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800892inline bool platform_supports_app_type_cfg()
893{
Thierry Strudel07f96d12018-09-20 13:31:34 -0700894#if defined (PLATFORM_MSM8998) || (PLATFORM_SDM845) || (PLATFORM_SDM710) || (PLATFORM_SM8150)
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800895 return true;
896#else
897 return false;
898#endif
899}
900
jasmine chac89321b2018-04-10 21:37:01 +0800901static int parse_audiocal_cfg(struct str_parms *parms, acdb_audio_cal_cfg_t *cal)
902{
903 int err;
904 char value[64];
905 int ret = 0;
906
907 if (parms == NULL || cal == NULL)
908 return ret;
909
910 err = str_parms_get_str(parms, "cal_persist", value, sizeof(value));
911 if (err >= 0) {
912 str_parms_del(parms, "cal_persist");
913 cal->persist = (uint32_t)strtoul(value, NULL, 0);
914 ret = ret | 0x1;
915 }
916 err = str_parms_get_str(parms, "cal_apptype", value, sizeof(value));
917 if (err >= 0) {
918 str_parms_del(parms, "cal_apptype");
919 cal->app_type = (uint32_t)strtoul(value, NULL, 0);
920 ret = ret | 0x2;
921 }
922 err = str_parms_get_str(parms, "cal_caltype", value, sizeof(value));
923 if (err >= 0) {
924 str_parms_del(parms, "cal_caltype");
925 cal->cal_type = (uint32_t)strtoul(value, NULL, 0);
926 ret = ret | 0x4;
927 }
928 err = str_parms_get_str(parms, "cal_samplerate", value, sizeof(value));
929 if (err >= 0) {
930 str_parms_del(parms, "cal_samplerate");
931 cal->sampling_rate = (uint32_t)strtoul(value, NULL, 0);
932 ret = ret | 0x8;
933 }
934 err = str_parms_get_str(parms, "cal_devid", value, sizeof(value));
935 if (err >= 0) {
936 str_parms_del(parms, "cal_devid");
937 cal->dev_id = (uint32_t)strtoul(value, NULL, 0);
938 ret = ret | 0x10;
939 }
940 err = str_parms_get_str(parms, "cal_snddevid", value, sizeof(value));
941 if (err >= 0) {
942 str_parms_del(parms, "cal_snddevid");
943 cal->snd_dev_id = (uint32_t)strtoul(value, NULL, 0);
944 ret = ret | 0x20;
945 }
946 err = str_parms_get_str(parms, "cal_topoid", value, sizeof(value));
947 if (err >= 0) {
948 str_parms_del(parms, "cal_topoid");
949 cal->topo_id = (uint32_t)strtoul(value, NULL, 0);
950 ret = ret | 0x40;
951 }
952 err = str_parms_get_str(parms, "cal_moduleid", value, sizeof(value));
953 if (err >= 0) {
954 str_parms_del(parms, "cal_moduleid");
955 cal->module_id = (uint32_t)strtoul(value, NULL, 0);
956 ret = ret | 0x80;
957 }
958 err = str_parms_get_str(parms, "cal_paramid", value, sizeof(value));
959 if (err >= 0) {
960 str_parms_del(parms, "cal_paramid");
961 cal->param_id = (uint32_t)strtoul(value, NULL, 0);
962 ret = ret | 0x100;
963 }
964 return ret;
965}
966
967static void set_audiocal(void *platform, struct str_parms *parms, char *value, int len)
968{
969 struct platform_data *my_data = (struct platform_data *)platform;
970 acdb_audio_cal_cfg_t cal;
971 uint8_t *dptr = NULL;
972 int32_t dlen = 0;
973 int err ,ret;
974
975 if (value == NULL || platform == NULL || parms == NULL) {
976 ALOGE("[%s] received null pointer, failed", __func__);
977 goto done_key_audcal;
978 }
979
980 memset(&cal, 0, sizeof(acdb_audio_cal_cfg_t));
981 /* parse audio calibration keys */
982 ret = parse_audiocal_cfg(parms, &cal);
983
984 /* handle audio calibration data now */
985 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_AUD_CALDATA, value, len);
986 if (err >= 0) {
987 str_parms_del(parms, AUDIO_PARAMETER_KEY_AUD_CALDATA);
988 dlen = strlen(value);
989 if (dlen <= 0) {
990 ALOGE("[%s] null data received", __func__);
991 goto done_key_audcal;
992 }
993 /*
994 The base64 encoded string is always larger than the binary data,
995 so b64_pton will always output less data than provided (around 1/3
996 less than the input data). That's why we can allocate input buffer
997 length and then get function work.
998 */
999 dptr = (uint8_t *)calloc(dlen, sizeof(uint8_t));
1000 if (dptr == NULL) {
1001 ALOGE("[%s] memory allocation failed for %d", __func__, dlen);
1002 goto done_key_audcal;
1003 }
1004 dlen = b64_pton(value, dptr, dlen);
1005 if (dlen <= 0) {
1006 ALOGE("[%s] data decoding failed %d", __func__, dlen);
1007 goto done_key_audcal;
1008 }
1009
1010 if (cal.dev_id) {
1011 if (audio_is_input_device(cal.dev_id)) {
Eric Laurentd1b7a9b2018-11-15 12:24:31 -08001012 // FIXME: why pass an input device whereas
1013 // platform_get_input_snd_device() expects as an output device?
1014 cal.snd_dev_id = platform_get_input_snd_device(platform, NULL, cal.dev_id);
jasmine chac89321b2018-04-10 21:37:01 +08001015 } else {
1016 cal.snd_dev_id = platform_get_output_snd_device(platform, cal.dev_id);
1017 }
1018 }
1019 cal.acdb_dev_id = platform_get_snd_device_acdb_id(cal.snd_dev_id);
1020 ALOGD("Setting audio calibration for snd_device(%d) acdb_id(%d)",
1021 cal.snd_dev_id, cal.acdb_dev_id);
1022 if (cal.acdb_dev_id == -EINVAL) {
1023 ALOGE("[%s] Invalid acdb_device id %d for snd device id %d",
1024 __func__, cal.acdb_dev_id, cal.snd_dev_id);
1025 goto done_key_audcal;
1026 }
1027 if (my_data->acdb_set_audio_cal) {
1028 ret = my_data->acdb_set_audio_cal((void *)&cal, (void *)dptr, dlen);
1029 }
1030 }
1031done_key_audcal:
1032 if (dptr != NULL)
1033 free(dptr);
1034}
1035
vivek mehta1a9b7c02015-06-25 11:49:38 -07001036bool platform_send_gain_dep_cal(void *platform, int level)
1037{
1038 bool ret_val = false;
1039 struct platform_data *my_data = (struct platform_data *)platform;
1040 struct audio_device *adev = my_data->adev;
1041 int acdb_dev_id, app_type;
1042 int acdb_dev_type = MSM_SNDDEV_CAP_RX;
1043 int mode = CAL_MODE_RTAC;
1044 struct listnode *node;
1045 struct audio_usecase *usecase;
Haynes Mathew George67486e22017-06-26 12:58:38 -07001046 bool valid_uc_type;
1047 bool valid_dev;
vivek mehta1a9b7c02015-06-25 11:49:38 -07001048
1049 if (my_data->acdb_send_gain_dep_cal == NULL) {
1050 ALOGE("%s: dlsym error for acdb_send_gain_dep_cal", __func__);
1051 return ret_val;
1052 }
1053
1054 if (!voice_is_in_call(adev)) {
1055 ALOGV("%s: Not Voice call usecase, apply new cal for level %d",
1056 __func__, level);
vivek mehta1a9b7c02015-06-25 11:49:38 -07001057
1058 // find the current active sound device
1059 list_for_each(node, &adev->usecase_list) {
1060 usecase = node_to_item(node, struct audio_usecase, list);
Haynes Mathew George67486e22017-06-26 12:58:38 -07001061 LOG_ALWAYS_FATAL_IF(usecase == NULL,
1062 "unxpected NULL usecase in usecase_list");
1063 valid_uc_type = usecase->type == PCM_PLAYBACK;
1064 valid_dev = false;
1065 if (valid_uc_type) {
1066 audio_devices_t dev = usecase->stream.out->devices;
1067 valid_dev = (dev == AUDIO_DEVICE_OUT_SPEAKER ||
vivek mehta40125092017-08-21 18:48:51 -07001068 dev == AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Haynes Mathew George67486e22017-06-26 12:58:38 -07001069 dev == AUDIO_DEVICE_OUT_WIRED_HEADSET ||
1070 dev == AUDIO_DEVICE_OUT_WIRED_HEADPHONE);
1071 }
1072 if (valid_dev) {
vivek mehta40125092017-08-21 18:48:51 -07001073 ALOGV("%s: out device is %d", __func__, usecase->out_snd_device);
1074 if (platform_supports_app_type_cfg())
1075 app_type = usecase->stream.out->app_type_cfg.app_type;
1076 else
1077 app_type = DEFAULT_APP_TYPE_RX_PATH;
vivek mehta4cb82982015-07-13 12:05:49 -07001078
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07001079 acdb_dev_id = platform_get_snd_device_acdb_id(usecase->out_snd_device);
vivek mehta40125092017-08-21 18:48:51 -07001080
1081 if (!my_data->acdb_send_gain_dep_cal(acdb_dev_id, app_type,
vivek mehta1a9b7c02015-06-25 11:49:38 -07001082 acdb_dev_type, mode, level)) {
1083 // set ret_val true if at least one calibration is set successfully
1084 ret_val = true;
1085 } else {
1086 ALOGE("%s: my_data->acdb_send_gain_dep_cal failed ", __func__);
1087 }
1088 } else {
1089 ALOGW("%s: Usecase list is empty", __func__);
1090 }
1091 }
1092 } else {
1093 ALOGW("%s: Voice call in progress .. ignore setting new cal",
1094 __func__);
1095 }
1096 return ret_val;
1097}
1098
Eric Laurentcefbbac2014-09-04 13:54:10 -05001099void platform_set_echo_reference(struct audio_device *adev, bool enable, audio_devices_t out_device)
Eric Laurentb23d5282013-05-14 15:27:20 -07001100{
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08001101 struct platform_data *my_data = (struct platform_data *)adev->platform;
Eric Laurentcefbbac2014-09-04 13:54:10 -05001102 snd_device_t snd_device = SND_DEVICE_NONE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001103
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08001104 if (strcmp(my_data->ec_ref_mixer_path, "")) {
1105 ALOGV("%s: diabling %s", __func__, my_data->ec_ref_mixer_path);
1106 audio_route_reset_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
Eric Laurentcefbbac2014-09-04 13:54:10 -05001107 }
1108
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08001109 if (enable) {
1110 strcpy(my_data->ec_ref_mixer_path, "echo-reference");
1111 if (out_device != AUDIO_DEVICE_NONE) {
1112 snd_device = platform_get_output_snd_device(adev->platform, out_device);
1113 platform_add_backend_name(adev->platform, my_data->ec_ref_mixer_path, snd_device);
1114 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05001115
Joe Onorato188b6222016-03-01 11:02:27 -08001116 ALOGV("%s: enabling %s", __func__, my_data->ec_ref_mixer_path);
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08001117 audio_route_apply_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
1118 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001119}
1120
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001121static struct csd_data *open_csd_client(bool i2s_ext_modem)
1122{
1123 struct csd_data *csd = calloc(1, sizeof(struct csd_data));
1124
1125 csd->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
1126 if (csd->csd_client == NULL) {
1127 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
1128 goto error;
1129 } else {
1130 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
1131
1132 csd->deinit = (deinit_t)dlsym(csd->csd_client,
1133 "csd_client_deinit");
1134 if (csd->deinit == NULL) {
1135 ALOGE("%s: dlsym error %s for csd_client_deinit", __func__,
1136 dlerror());
1137 goto error;
1138 }
1139 csd->disable_device = (disable_device_t)dlsym(csd->csd_client,
1140 "csd_client_disable_device");
1141 if (csd->disable_device == NULL) {
1142 ALOGE("%s: dlsym error %s for csd_client_disable_device",
1143 __func__, dlerror());
1144 goto error;
1145 }
1146 csd->enable_device_config = (enable_device_config_t)dlsym(csd->csd_client,
1147 "csd_client_enable_device_config");
1148 if (csd->enable_device_config == NULL) {
1149 ALOGE("%s: dlsym error %s for csd_client_enable_device_config",
1150 __func__, dlerror());
1151 goto error;
1152 }
1153 csd->enable_device = (enable_device_t)dlsym(csd->csd_client,
1154 "csd_client_enable_device");
1155 if (csd->enable_device == NULL) {
1156 ALOGE("%s: dlsym error %s for csd_client_enable_device",
1157 __func__, dlerror());
1158 goto error;
1159 }
1160 csd->start_voice = (start_voice_t)dlsym(csd->csd_client,
1161 "csd_client_start_voice");
1162 if (csd->start_voice == NULL) {
1163 ALOGE("%s: dlsym error %s for csd_client_start_voice",
1164 __func__, dlerror());
1165 goto error;
1166 }
1167 csd->stop_voice = (stop_voice_t)dlsym(csd->csd_client,
1168 "csd_client_stop_voice");
1169 if (csd->stop_voice == NULL) {
1170 ALOGE("%s: dlsym error %s for csd_client_stop_voice",
1171 __func__, dlerror());
1172 goto error;
1173 }
1174 csd->volume = (volume_t)dlsym(csd->csd_client,
1175 "csd_client_volume");
1176 if (csd->volume == NULL) {
1177 ALOGE("%s: dlsym error %s for csd_client_volume",
1178 __func__, dlerror());
1179 goto error;
1180 }
1181 csd->mic_mute = (mic_mute_t)dlsym(csd->csd_client,
1182 "csd_client_mic_mute");
1183 if (csd->mic_mute == NULL) {
1184 ALOGE("%s: dlsym error %s for csd_client_mic_mute",
1185 __func__, dlerror());
1186 goto error;
1187 }
1188 csd->slow_talk = (slow_talk_t)dlsym(csd->csd_client,
1189 "csd_client_slow_talk");
1190 if (csd->slow_talk == NULL) {
1191 ALOGE("%s: dlsym error %s for csd_client_slow_talk",
1192 __func__, dlerror());
1193 goto error;
1194 }
1195 csd->start_playback = (start_playback_t)dlsym(csd->csd_client,
1196 "csd_client_start_playback");
1197 if (csd->start_playback == NULL) {
1198 ALOGE("%s: dlsym error %s for csd_client_start_playback",
1199 __func__, dlerror());
1200 goto error;
1201 }
1202 csd->stop_playback = (stop_playback_t)dlsym(csd->csd_client,
1203 "csd_client_stop_playback");
1204 if (csd->stop_playback == NULL) {
1205 ALOGE("%s: dlsym error %s for csd_client_stop_playback",
1206 __func__, dlerror());
1207 goto error;
1208 }
1209 csd->start_record = (start_record_t)dlsym(csd->csd_client,
1210 "csd_client_start_record");
1211 if (csd->start_record == NULL) {
1212 ALOGE("%s: dlsym error %s for csd_client_start_record",
1213 __func__, dlerror());
1214 goto error;
1215 }
1216 csd->stop_record = (stop_record_t)dlsym(csd->csd_client,
1217 "csd_client_stop_record");
1218 if (csd->stop_record == NULL) {
1219 ALOGE("%s: dlsym error %s for csd_client_stop_record",
1220 __func__, dlerror());
1221 goto error;
1222 }
1223
1224 csd->get_sample_rate = (get_sample_rate_t)dlsym(csd->csd_client,
1225 "csd_client_get_sample_rate");
1226 if (csd->get_sample_rate == NULL) {
1227 ALOGE("%s: dlsym error %s for csd_client_get_sample_rate",
1228 __func__, dlerror());
1229
1230 goto error;
1231 }
1232
1233 csd->init = (init_t)dlsym(csd->csd_client, "csd_client_init");
1234
1235 if (csd->init == NULL) {
1236 ALOGE("%s: dlsym error %s for csd_client_init",
1237 __func__, dlerror());
1238 goto error;
1239 } else {
1240 csd->init(i2s_ext_modem);
1241 }
1242 }
1243 return csd;
1244
1245error:
1246 free(csd);
1247 csd = NULL;
1248 return csd;
1249}
1250
1251void close_csd_client(struct csd_data *csd)
1252{
1253 if (csd != NULL) {
1254 csd->deinit();
1255 dlclose(csd->csd_client);
1256 free(csd);
1257 csd = NULL;
1258 }
1259}
1260
1261static void platform_csd_init(struct platform_data *my_data)
1262{
1263#ifdef PLATFORM_MSM8084
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001264 int32_t modems, (*count_modems)(void);
1265 const char *name = "libdetectmodem.so";
1266 const char *func = "count_modems";
1267 const char *error;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001268
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001269 my_data->csd = NULL;
1270
1271 void *lib = dlopen(name, RTLD_NOW);
1272 error = dlerror();
1273 if (!lib) {
1274 ALOGE("%s: could not find %s: %s", __func__, name, error);
1275 return;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001276 }
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001277
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001278 count_modems = NULL;
1279 *(void **)(&count_modems) = dlsym(lib, func);
1280 error = dlerror();
1281 if (!count_modems) {
1282 ALOGE("%s: could not find symbol %s in %s: %s",
1283 __func__, func, name, error);
1284 goto done;
1285 }
1286
1287 modems = count_modems();
1288 if (modems < 0) {
1289 ALOGE("%s: count_modems failed\n", __func__);
1290 goto done;
1291 }
1292
Eric Laurent2bafff12016-03-17 12:17:23 -07001293 ALOGD("%s: num_modems %d\n", __func__, modems);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001294 if (modems > 0)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001295 my_data->csd = open_csd_client(false /*is_i2s_ext_modem*/);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001296
1297done:
1298 dlclose(lib);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001299#else
1300 my_data->csd = NULL;
1301#endif
1302}
1303
Eric Laurentc6333382015-09-14 12:43:44 -07001304static void set_platform_defaults(struct platform_data * my_data)
Haynes Mathew George98c95622014-06-20 19:14:25 -07001305{
1306 int32_t dev;
1307 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001308 backend_tag_table[dev] = NULL;
1309 hw_interface_table[dev] = NULL;
keunhui.park2f7306a2015-07-16 16:48:06 +09001310 operator_specific_device_table[dev] = NULL;
Carter Hsu017c63a2018-10-15 15:01:42 -07001311 external_specific_device_table[dev] = NULL;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001312 }
1313
David Linee3fe402017-03-13 10:00:42 -07001314 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1315 backend_bit_width_table[dev] = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
1316 }
1317
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001318 // To overwrite these go to the audio_platform_info.xml file.
1319 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("bt-sco");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07001320 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("bt-sco");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001321 backend_tag_table[SND_DEVICE_OUT_BT_SCO] = strdup("bt-sco");
1322 backend_tag_table[SND_DEVICE_OUT_HDMI] = strdup("hdmi");
1323 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("speaker-and-hdmi");
1324 backend_tag_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("bt-sco-wb");
1325 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("bt-sco-wb");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07001326 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("bt-sco-wb");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001327 backend_tag_table[SND_DEVICE_OUT_VOICE_TX] = strdup("afe-proxy");
1328 backend_tag_table[SND_DEVICE_IN_VOICE_RX] = strdup("afe-proxy");
Haynes Mathew George98c95622014-06-20 19:14:25 -07001329
David Linee3fe402017-03-13 10:00:42 -07001330 backend_tag_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("usb-headset");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001331 backend_tag_table[SND_DEVICE_OUT_VOICE_USB_HEADSET] = strdup("usb-headset");
David Linee3fe402017-03-13 10:00:42 -07001332 backend_tag_table[SND_DEVICE_OUT_USB_HEADPHONES] = strdup("usb-headphones");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001333 backend_tag_table[SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = strdup("usb-headphones");
David Linee3fe402017-03-13 10:00:42 -07001334 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] =
1335 strdup("speaker-and-usb-headphones");
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07001336 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] =
1337 strdup("speaker-safe-and-usb-headphones");
juyuchen5351ea62018-05-16 10:54:37 +08001338 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO] =
1339 strdup("speaker-safe-and-bt-sco"),
1340 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB] =
1341 strdup("speaker-safe-and-bt-sco-wb"),
David Linee3fe402017-03-13 10:00:42 -07001342 backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("usb-headset-mic");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001343 backend_tag_table[SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1344 backend_tag_table[SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1345 backend_tag_table[SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1346 backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = strdup("usb-headset-mic");
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001347 backend_tag_table[SND_DEVICE_OUT_BT_A2DP] = strdup("bt-a2dp");
1348 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] = strdup("speaker-and-bt-a2dp");
Aniket Kumar Lata9723a962018-05-16 17:41:55 -07001349 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP] = strdup("speaker-safe-and-bt-a2dp");
jasmine cha270b7762018-03-30 15:41:33 +08001350 backend_tag_table[SND_DEVICE_OUT_USB_HEADSET_SPEC] = strdup("usb-headset");
juyuchend194b432018-11-16 14:15:16 +08001351 backend_tag_table[SND_DEVICE_OUT_VOICE_HEARING_AID] = strdup("hearing-aid");
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001352
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001353 hw_interface_table[SND_DEVICE_OUT_HANDSET] = strdup("SLIMBUS_0_RX");
1354 hw_interface_table[SND_DEVICE_OUT_SPEAKER] = strdup("SLIMBUS_0_RX");
1355 hw_interface_table[SND_DEVICE_OUT_SPEAKER_REVERSE] = strdup("SLIMBUS_0_RX");
1356 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE] = strdup("SLIMBUS_0_RX");
1357 hw_interface_table[SND_DEVICE_OUT_HEADPHONES] = strdup("SLIMBUS_0_RX");
1358 hw_interface_table[SND_DEVICE_OUT_LINE] = strdup("SLIMBUS_0_RX");
1359 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001360 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001361 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001362 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001363 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET] = strdup("SLIMBUS_0_RX");
1364 hw_interface_table[SND_DEVICE_OUT_VOICE_HAC_HANDSET] = strdup("SLIMBUS_0_RX");
1365 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER] = strdup("SLIMBUS_0_RX");
1366 hw_interface_table[SND_DEVICE_OUT_VOICE_HEADPHONES] = strdup("SLIMBUS_0_RX");
yixuanjiang9536e672018-09-06 18:43:36 +08001367 hw_interface_table[SND_DEVICE_OUT_VOICE_HEADSET] = strdup("SLIMBUS_0_RX");
juyuchen66c4ecf2018-08-06 15:39:34 +08001368 hw_interface_table[SND_DEVICE_OUT_VOICE_MUSIC_TX] = strdup("VOICE_PLAYBACK_TX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001369 hw_interface_table[SND_DEVICE_OUT_VOICE_LINE] = strdup("SLIMBUS_0_RX");
1370 hw_interface_table[SND_DEVICE_OUT_HDMI] = strdup("HDMI_RX");
1371 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("SLIMBUS_0_RX-and-HDMI_RX");
1372 hw_interface_table[SND_DEVICE_OUT_BT_SCO] = strdup("SEC_AUX_PCM_RX");
1373 hw_interface_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("SEC_AUX_PCM_RX");
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001374 hw_interface_table[SND_DEVICE_OUT_BT_A2DP] = strdup("SLIMBUS_7_RX");
1375 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] =
1376 strdup("SLIMBUS_0_RX-and-SLIMBUS_7_RX");
Aniket Kumar Lata9723a962018-05-16 17:41:55 -07001377 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP] =
1378 strdup("SLIMBUS_0_RX-and-SLIMBUS_7_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001379 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = strdup("SLIMBUS_0_RX");
1380 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = strdup("SLIMBUS_0_RX");
1381 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = strdup("SLIMBUS_0_RX");
1382 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = strdup("SLIMBUS_0_RX");
David Linee3fe402017-03-13 10:00:42 -07001383 hw_interface_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("USB_AUDIO_RX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001384 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = strdup("USB_AUDIO_RX");
1385 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = strdup("USB_AUDIO_RX");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001386 hw_interface_table[SND_DEVICE_OUT_VOICE_USB_HEADSET] = strdup("USB_AUDIO_RX");
David Linee3fe402017-03-13 10:00:42 -07001387 hw_interface_table[SND_DEVICE_OUT_USB_HEADPHONES] = strdup("USB_AUDIO_RX");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001388 hw_interface_table[SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = strdup("USB_AUDIO_RX");
jasmine cha270b7762018-03-30 15:41:33 +08001389 hw_interface_table[SND_DEVICE_OUT_USB_HEADSET_SPEC] = strdup("USB_AUDIO_RX");
David Linee3fe402017-03-13 10:00:42 -07001390 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 -07001391 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 -07001392 hw_interface_table[SND_DEVICE_OUT_VOICE_TX] = strdup("AFE_PCM_RX");
1393 hw_interface_table[SND_DEVICE_OUT_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
1394 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
jasmine cha52284622018-03-23 17:21:35 +08001395 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = strdup("SLIMBUS_0_RX");
1396 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_BT_SCO] = strdup("SLIMBUS_0_RX-and-SEC_AUX_PCM_RX");
1397 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 +08001398 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO] = strdup("QUAT_TDM_RX_0-and-SLIMBUS_7_RX"),
1399 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB] = strdup("QUAT_TDM_RX_0-and-SLIMBUS_7_RX"),
juyuchend194b432018-11-16 14:15:16 +08001400 /* So far, primary hal doesn't support hearing aid device.
1401 Need snd_device to route voice call and use specific acdb tuning.
1402 Also, BT_RX is a virtual port to indicate bluetooth hearing aid. */
1403 hw_interface_table[SND_DEVICE_OUT_VOICE_HEARING_AID] = strdup("BT_RX"),
1404
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001405 hw_interface_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1406 hw_interface_table[SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1407 hw_interface_table[SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = strdup("USB_AUDIO_TX");
1408 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1409 hw_interface_table[SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1410 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = strdup("USB_AUDIO_TX");
1411 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = strdup("USB_AUDIO_TX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001412 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001413 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_AEC] = strdup("SLIMBUS_0_TX");
1414 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_NS] = strdup("SLIMBUS_0_TX");
1415 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1416 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC] = strdup("SLIMBUS_0_TX");
1417 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_AEC] = strdup("SLIMBUS_0_TX");
1418 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_NS] = strdup("SLIMBUS_0_TX");
1419 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1420 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001421 hw_interface_table[SND_DEVICE_IN_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001422 hw_interface_table[SND_DEVICE_IN_HEADSET_MIC_AEC] = strdup("SLIMBUS_0_TX");
Eric Laurent5f4ca952018-10-19 17:33:43 -07001423 hw_interface_table[SND_DEVICE_IN_CAMCORDER_LANDSCAPE] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001424 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC] = strdup("SLIMBUS_0_TX");
1425 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC_NS] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001426 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC_AEC] = strdup("SLIMBUS_0_TX");
1427 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001428 hw_interface_table[SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
1429 hw_interface_table[SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = strdup("SLIMBUS_0_TX");
David Lin93725722017-10-13 14:58:17 -07001430 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_MIC] = strdup("SLIMBUS_0_TX");
1431 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1432 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = strdup("SLIMBUS_0_TX");
1433 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = strdup("SLIMBUS_0_TX");
1434 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001435 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC] = strdup("SLIMBUS_0_TX");
1436 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_AEC] = strdup("SLIMBUS_0_TX");
1437 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_NS] = strdup("SLIMBUS_0_TX");
1438 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1439 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC] = strdup("SLIMBUS_0_TX");
1440 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_AEC] = strdup("SLIMBUS_0_TX");
1441 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_NS] = strdup("SLIMBUS_0_TX");
1442 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001443 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
1444 hw_interface_table[SND_DEVICE_IN_VOICE_DMIC] = strdup("SLIMBUS_0_TX");
1445 hw_interface_table[SND_DEVICE_IN_VOICE_DMIC_TMUS] = strdup("SLIMBUS_0_TX");
Vignesh Kulothungan64698822018-01-23 11:25:18 -08001446 hw_interface_table[SND_DEVICE_IN_SPEAKER_QMIC_NS] = strdup("SLIMBUS_0_TX");
1447 hw_interface_table[SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001448 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001449 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = strdup("SLIMBUS_0_TX");
1450 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001451 hw_interface_table[SND_DEVICE_IN_VOICE_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001452 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1453 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = strdup("SLIMBUS_0_TX");
1454 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1455 hw_interface_table[SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1456 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("SEC_AUX_PCM_TX");
1457 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("SEC_AUX_PCM_TX");
1458 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("SEC_AUX_PCM_TX");
1459 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("SEC_AUX_PCM_TX");
1460 hw_interface_table[SND_DEVICE_IN_VOICE_RX] = strdup("AFE_PCM_TX");
1461 hw_interface_table[SND_DEVICE_IN_THREE_MIC] = strdup("SLIMBUS_0_TX");
1462 hw_interface_table[SND_DEVICE_IN_QUAD_MIC] = strdup("SLIMBUS_0_TX");
1463 hw_interface_table[SND_DEVICE_IN_HANDSET_TMIC] = strdup("SLIMBUS_0_TX");
1464 hw_interface_table[SND_DEVICE_IN_HANDSET_QMIC] = strdup("SLIMBUS_0_TX");
1465 hw_interface_table[SND_DEVICE_IN_HANDSET_TMIC_AEC] = strdup("SLIMBUS_0_TX");
1466 hw_interface_table[SND_DEVICE_IN_HANDSET_QMIC_AEC] = strdup("SLIMBUS_0_TX");
Eric Laurent5f4ca952018-10-19 17:33:43 -07001467 hw_interface_table[SND_DEVICE_IN_CAMCORDER_INVERT_LANDSCAPE] = strdup("SLIMBUS_0_TX");
1468 hw_interface_table[SND_DEVICE_IN_CAMCORDER_PORTRAIT] = strdup("SLIMBUS_0_TX");
1469 hw_interface_table[SND_DEVICE_IN_CAMCORDER_SELFIE_LANDSCAPE] = strdup("SLIMBUS_0_TX");
1470 hw_interface_table[SND_DEVICE_IN_CAMCORDER_SELFIE_INVERT_LANDSCAPE] = strdup("SLIMBUS_0_TX");
1471 hw_interface_table[SND_DEVICE_IN_CAMCORDER_SELFIE_PORTRAIT] = strdup("SLIMBUS_0_TX");
juyuchend194b432018-11-16 14:15:16 +08001472 hw_interface_table[SND_DEVICE_IN_VOICE_HEARING_AID] = strdup("SLIMBUS_0_TX");
1473
Eric Laurentc6333382015-09-14 12:43:44 -07001474 my_data->max_mic_count = PLATFORM_DEFAULT_MIC_COUNT;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001475}
1476
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001477void get_cvd_version(char *cvd_version, struct audio_device *adev)
1478{
1479 struct mixer_ctl *ctl;
1480 int count;
1481 int ret = 0;
1482
1483 ctl = mixer_get_ctl_by_name(adev->mixer, CVD_VERSION_MIXER_CTL);
1484 if (!ctl) {
1485 ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__, CVD_VERSION_MIXER_CTL);
1486 goto done;
1487 }
1488 mixer_ctl_update(ctl);
1489
1490 count = mixer_ctl_get_num_values(ctl);
1491 if (count > MAX_CVD_VERSION_STRING_SIZE)
1492 count = MAX_CVD_VERSION_STRING_SIZE - 1;
1493
1494 ret = mixer_ctl_get_array(ctl, cvd_version, count);
1495 if (ret != 0) {
1496 ALOGE("%s: ERROR! mixer_ctl_get_array() failed to get CVD Version", __func__);
1497 goto done;
1498 }
1499
1500done:
1501 return;
1502}
1503
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001504static int platform_acdb_init(void *platform)
1505{
1506 struct platform_data *my_data = (struct platform_data *)platform;
1507 struct audio_device *adev = my_data->adev;
1508
1509 if (!my_data->acdb_init) {
1510 ALOGE("%s: no acdb_init fn provided", __func__);
1511 return -1;
1512 }
1513
1514 if (my_data->acdb_initialized) {
1515 ALOGW("acdb is already initialized");
1516 return 0;
1517 }
1518
Thierry Strudel07f96d12018-09-20 13:31:34 -07001519#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845) || (PLATFORM_SDM710) || (PLATFORM_SM8150)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001520 char *cvd_version = calloc(1, MAX_CVD_VERSION_STRING_SIZE);
1521 if (!cvd_version)
1522 ALOGE("failed to allocate cvd_version");
1523 else {
1524 get_cvd_version(cvd_version, adev);
1525 my_data->acdb_init((char *)my_data->snd_card_name, cvd_version, 0);
1526 free(cvd_version);
1527 }
1528#elif defined (PLATFORM_MSM8084)
1529 my_data->acdb_init((char *)my_data->snd_card_name);
1530#else
1531 my_data->acdb_init();
1532#endif
1533 my_data->acdb_initialized = true;
1534 return 0;
1535}
1536
David Linee3fe402017-03-13 10:00:42 -07001537static void
1538platform_backend_config_init(struct platform_data *pdata)
1539{
1540 int i;
1541
1542 /* initialize backend config */
1543 for (i = 0; i < MAX_CODEC_BACKENDS; i++) {
1544 pdata->current_backend_cfg[i].sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
1545 pdata->current_backend_cfg[i].bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
1546 pdata->current_backend_cfg[i].channels = CODEC_BACKEND_DEFAULT_CHANNELS;
1547
1548 if (i > MAX_RX_CODEC_BACKENDS)
1549 pdata->current_backend_cfg[i].channels = CODEC_BACKEND_DEFAULT_TX_CHANNELS;
1550
1551 pdata->current_backend_cfg[i].bitwidth_mixer_ctl = NULL;
1552 pdata->current_backend_cfg[i].samplerate_mixer_ctl = NULL;
1553 pdata->current_backend_cfg[i].channels_mixer_ctl = NULL;
1554 }
1555
1556 pdata->current_backend_cfg[DEFAULT_CODEC_BACKEND].bitwidth_mixer_ctl =
1557 strdup("SLIM_0_RX Format");
1558 pdata->current_backend_cfg[DEFAULT_CODEC_BACKEND].samplerate_mixer_ctl =
1559 strdup("SLIM_0_RX SampleRate");
1560
1561 pdata->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].bitwidth_mixer_ctl =
1562 strdup("SLIM_0_TX Format");
1563 pdata->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].samplerate_mixer_ctl =
1564 strdup("SLIM_0_TX SampleRate");
1565
1566 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].bitwidth_mixer_ctl =
1567 strdup("USB_AUDIO_TX Format");
1568 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].samplerate_mixer_ctl =
1569 strdup("USB_AUDIO_TX SampleRate");
1570 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].channels_mixer_ctl =
1571 strdup("USB_AUDIO_TX Channels");
1572
Yung Ti Su39a2b8a2018-10-05 15:43:40 +08001573 if (strstr(pdata->snd_card_name, "intcodec")) {
1574 pdata->current_backend_cfg[HEADPHONE_BACKEND].bitwidth_mixer_ctl =
1575 strdup("INT0_MI2S_RX Format");
1576 pdata->current_backend_cfg[HEADPHONE_BACKEND].samplerate_mixer_ctl =
1577 strdup("INT0_MI2S_RX SampleRate");
1578 } else {
1579 pdata->current_backend_cfg[HEADPHONE_BACKEND].bitwidth_mixer_ctl =
1580 strdup("SLIM_6_RX Format");
1581 pdata->current_backend_cfg[HEADPHONE_BACKEND].samplerate_mixer_ctl =
1582 strdup("SLIM_6_RX SampleRate");
1583 }
David Linee3fe402017-03-13 10:00:42 -07001584
1585 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].bitwidth_mixer_ctl =
1586 strdup("USB_AUDIO_RX Format");
1587 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].samplerate_mixer_ctl =
1588 strdup("USB_AUDIO_RX SampleRate");
1589
1590 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].channels = 1;
1591 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].channels_mixer_ctl =
1592 strdup("USB_AUDIO_RX Channels");
1593}
1594
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001595static int
1596platform_backend_app_type_cfg_init(struct platform_data *pdata,
1597 struct mixer *mixer)
1598{
1599 size_t app_type_cfg[128] = {0};
1600 int length, num_app_types = 0;
1601 struct mixer_ctl *ctl = NULL;
1602
1603 const char *mixer_ctl_name = "App Type Config";
1604 ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name);
1605 if (!ctl) {
1606 ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name);
1607 return -1;
1608 }
1609
1610 length = 1; // reserve index 0 for number of app types
1611
1612 struct listnode *node;
1613 struct app_type_entry *entry;
1614 list_for_each(node, &app_type_entry_list) {
1615 entry = node_to_item(node, struct app_type_entry, node);
1616 app_type_cfg[length++] = entry->app_type;
1617 app_type_cfg[length++] = entry->max_rate;
1618 app_type_cfg[length++] = entry->bit_width;
1619 ALOGI("%s add entry %d %d", __func__, entry->app_type, entry->bit_width);
1620 num_app_types += 1;
1621 }
1622
1623 // default for capture
1624 int t;
1625 platform_get_default_app_type_v2(pdata,
1626 PCM_CAPTURE,
1627 &t);
1628 app_type_cfg[length++] = t;
1629 app_type_cfg[length++] = 48000;
1630 app_type_cfg[length++] = 16;
1631 num_app_types += 1;
1632
1633 if (num_app_types) {
1634 app_type_cfg[0] = num_app_types;
1635 if (mixer_ctl_set_array(ctl, app_type_cfg, length) < 0) {
1636 ALOGE("Failed to set app type cfg");
1637 }
1638 }
1639 return 0;
1640}
1641
Xu Han1638fd12018-04-20 12:42:23 -07001642static void configure_flicker_sensor_input(struct mixer *mixer)
1643{
1644 struct mixer_ctl *ctl;
1645 const char* ctl1 = "AIF3_CAP Mixer SLIM TX2";
1646 int setting1 = 1;
1647 const char* ctl2 = "CDC_IF TX2 MUX";
1648 const char* setting2 = "DEC2";
1649 const char* ctl3 = "SLIM_1_TX Channels";
1650 const char* setting3 = "One";
1651 const char* ctl4 = "ADC MUX2";
1652 const char* setting4 = "AMIC";
1653 const char* ctl5 = "AMIC MUX2";
1654 const char* setting5 = "ADC1";
1655 const char* ctl6 = "DEC2 Volume";
1656 int setting6 = 84;
Xu Han07e07402018-05-15 14:19:25 -07001657 const char* ctl7 = "MultiMedia9 Mixer SLIM_1_TX";
Xu Han1638fd12018-04-20 12:42:23 -07001658 int setting7 = 1;
1659 const char* ctl8 = "SLIM_1_TX SampleRate";
1660 const char* setting8 = "KHZ_8";
1661
1662 ctl = mixer_get_ctl_by_name(mixer, ctl1);
1663 mixer_ctl_set_value(ctl, 0, setting1);
1664 ctl = mixer_get_ctl_by_name(mixer, ctl2);
1665 mixer_ctl_set_enum_by_string(ctl, setting2);
1666 ctl = mixer_get_ctl_by_name(mixer, ctl3);
1667 mixer_ctl_set_enum_by_string(ctl, setting3);
1668 ctl = mixer_get_ctl_by_name(mixer, ctl4);
1669 mixer_ctl_set_enum_by_string(ctl, setting4);
1670 ctl = mixer_get_ctl_by_name(mixer, ctl5);
1671 mixer_ctl_set_enum_by_string(ctl, setting5);
1672 ctl = mixer_get_ctl_by_name(mixer, ctl6);
1673 mixer_ctl_set_value(ctl, 0, setting6);
1674 ctl = mixer_get_ctl_by_name(mixer, ctl7);
1675 mixer_ctl_set_value(ctl, 0, setting7);
1676 ctl = mixer_get_ctl_by_name(mixer, ctl8);
1677 mixer_ctl_set_enum_by_string(ctl, setting8);
1678}
1679
Eric Laurentb23d5282013-05-14 15:27:20 -07001680void *platform_init(struct audio_device *adev)
1681{
1682 char value[PROPERTY_VALUE_MAX];
vivek mehta60ea4152016-02-18 17:10:26 -08001683 struct platform_data *my_data = NULL;
1684 int retry_num = 0, snd_card_num = 0, key = 0, ret = 0;
1685 bool dual_mic_config = false, use_default_mixer_path = true;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001686 const char *snd_card_name;
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001687 char *cvd_version = NULL;
vivek mehta60ea4152016-02-18 17:10:26 -08001688 char *snd_internal_name = NULL;
1689 char *tmp = NULL;
1690 char mixer_xml_file[MIXER_PATH_MAX_LENGTH]= {0};
vivek mehtade4849c2016-03-03 17:23:38 -08001691 char platform_info_file[MIXER_PATH_MAX_LENGTH]= {0};
1692 struct snd_card_split *snd_split_handle = NULL;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001693 my_data = calloc(1, sizeof(struct platform_data));
1694
1695 my_data->adev = adev;
1696
keunhui.park2f7306a2015-07-16 16:48:06 +09001697 list_init(&operator_info_list);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001698 list_init(&app_type_entry_list);
keunhui.park2f7306a2015-07-16 16:48:06 +09001699
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001700 set_platform_defaults(my_data);
1701
vivek mehta0fb11312017-05-15 19:35:32 -07001702 // audio_extn_utils_get_snd_card_num does
1703 // - open mixer and get snd card name
1704 // - parse platform info xml file and check for valid snd card name
1705 // - on failure loop through all the active snd card
sangwoo1b9f4b32013-06-21 18:22:55 -07001706
vivek mehta0fb11312017-05-15 19:35:32 -07001707 snd_card_num = audio_extn_utils_get_snd_card_num();
1708 if (-1 == snd_card_num) {
1709 ALOGE("%s: invalid sound card number (-1), bailing out ", __func__);
1710 goto init_failed;
sangwoo1b9f4b32013-06-21 18:22:55 -07001711 }
1712
vivek mehta0fb11312017-05-15 19:35:32 -07001713 adev->mixer = mixer_open(snd_card_num);
1714 snd_card_name = mixer_get_name(adev->mixer);
1715 my_data->hw_info = hw_info_init(snd_card_name);
1716
1717 audio_extn_set_snd_card_split(snd_card_name);
1718 snd_split_handle = audio_extn_get_snd_card_split();
1719
1720 /* Get the codec internal name from the sound card and/or form factor
1721 * name and form the mixer paths and platfor info file name dynamically.
1722 * This is generic way of picking any codec and forma factor name based
1723 * mixer and platform info files in future with no code change.
1724
1725 * current code extends and looks for any of the exteneded mixer path and
1726 * platform info file present based on codec and form factor.
1727
1728 * order of picking appropriate file is
1729 * <i> mixer_paths_<codec_name>_<form_factor>.xml, if file not present
1730 * <ii> mixer_paths_<codec_name>.xml, if file not present
1731 * <iii> mixer_paths.xml
1732
1733 * same order is followed for audio_platform_info.xml as well
1734 */
1735
1736 // need to carryforward old file name
1737 if (!strncmp(snd_card_name, TOMTOM_8226_SND_CARD_NAME,
1738 min(strlen(TOMTOM_8226_SND_CARD_NAME), strlen(snd_card_name)))) {
1739 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1740 MIXER_XML_BASE_STRING, TOMTOM_MIXER_FILE_SUFFIX );
1741 } else {
1742
1743 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s_%s.xml",
1744 MIXER_XML_BASE_STRING, snd_split_handle->snd_card,
1745 snd_split_handle->form_factor);
1746 if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) {
1747 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1748 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1749 MIXER_XML_BASE_STRING, snd_split_handle->snd_card);
1750
1751 if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) {
1752 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1753 strlcpy(mixer_xml_file, MIXER_XML_DEFAULT_PATH, MIXER_PATH_MAX_LENGTH);
1754 audio_extn_utils_resolve_config_file(mixer_xml_file);
1755 }
1756 }
1757 }
1758
1759 audio_extn_utils_get_platform_info(snd_card_name, platform_info_file);
1760
jiabin8962a4d2018-03-19 18:21:24 -07001761 my_data->declared_mic_count = 0;
vivek mehta0fb11312017-05-15 19:35:32 -07001762 /* Initialize platform specific ids and/or backends*/
juyuchenbf6571f2018-11-30 18:50:47 +08001763 platform_info_init(platform_info_file, my_data,
1764 true, &platform_set_parameters);
vivek mehta0fb11312017-05-15 19:35:32 -07001765
1766 ALOGD("%s: Loading mixer file: %s", __func__, mixer_xml_file);
1767 adev->audio_route = audio_route_init(snd_card_num, mixer_xml_file);
1768
1769 if (!adev->audio_route) {
1770 ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
1771 mixer_close(adev->mixer);
1772 adev->mixer = NULL;
1773 hw_info_deinit(my_data->hw_info);
1774 my_data->hw_info = NULL;
1775 goto init_failed;
1776 }
1777 adev->snd_card = snd_card_num;
1778 ALOGD("%s: Opened sound card:%d", __func__, snd_card_num);
1779
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09001780 //set max volume step for voice call
1781 property_get("ro.config.vc_call_vol_steps", value, TOSTRING(MAX_VOL_INDEX));
1782 my_data->max_vol_index = atoi(value);
1783
vivek mehta65ad12d2015-08-13 18:32:48 -07001784 property_get("persist.audio.dualmic.config",value,"");
1785 if (!strcmp("endfire", value)) {
1786 dual_mic_config = true;
1787 }
1788
John Muir9e59a962018-01-10 13:30:00 -08001789 my_data->source_mic_type = 0;
Prashant Malanic92c5962015-08-11 15:10:18 -07001790
Eric Laurentb23d5282013-05-14 15:27:20 -07001791 my_data->fluence_in_spkr_mode = false;
1792 my_data->fluence_in_voice_call = false;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001793 my_data->fluence_in_voice_comm = false;
Eric Laurentb23d5282013-05-14 15:27:20 -07001794 my_data->fluence_in_voice_rec = false;
1795
vivek mehta65ad12d2015-08-13 18:32:48 -07001796 property_get("ro.qc.sdk.audio.fluencetype", value, "none");
Prashant Malanic92c5962015-08-11 15:10:18 -07001797 if (!strcmp("fluencepro", value)) {
1798 my_data->fluence_type = FLUENCE_PRO_ENABLE;
vivek mehta65ad12d2015-08-13 18:32:48 -07001799 } else if (!strcmp("fluence", value) || (dual_mic_config)) {
Prashant Malanic92c5962015-08-11 15:10:18 -07001800 my_data->fluence_type = FLUENCE_ENABLE;
1801 } else if (!strcmp("none", value)) {
1802 my_data->fluence_type = FLUENCE_DISABLE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001803 }
1804
Prashant Malanic92c5962015-08-11 15:10:18 -07001805 if (my_data->fluence_type != FLUENCE_DISABLE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001806 property_get("persist.audio.fluence.voicecall",value,"");
1807 if (!strcmp("true", value)) {
1808 my_data->fluence_in_voice_call = true;
1809 }
1810
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001811 property_get("persist.audio.fluence.voicecomm",value,"");
1812 if (!strcmp("true", value)) {
1813 my_data->fluence_in_voice_comm = true;
1814 }
1815
Eric Laurentb23d5282013-05-14 15:27:20 -07001816 property_get("persist.audio.fluence.voicerec",value,"");
1817 if (!strcmp("true", value)) {
1818 my_data->fluence_in_voice_rec = true;
1819 }
1820
1821 property_get("persist.audio.fluence.speaker",value,"");
1822 if (!strcmp("true", value)) {
1823 my_data->fluence_in_spkr_mode = true;
1824 }
1825 }
1826
Prashant Malanic92c5962015-08-11 15:10:18 -07001827 // support max to mono, example if max count is 3, usecase supports Three, dual and mono mic
1828 switch (my_data->max_mic_count) {
1829 case 4:
1830 my_data->source_mic_type |= SOURCE_QUAD_MIC;
1831 case 3:
1832 my_data->source_mic_type |= SOURCE_THREE_MIC;
1833 case 2:
1834 my_data->source_mic_type |= SOURCE_DUAL_MIC;
1835 case 1:
1836 my_data->source_mic_type |= SOURCE_MONO_MIC;
1837 break;
1838 default:
1839 ALOGE("%s: max_mic_count (%d), is not supported, setting to default",
1840 __func__, my_data->max_mic_count);
1841 my_data->source_mic_type = SOURCE_MONO_MIC|SOURCE_DUAL_MIC;
1842 break;
1843 }
1844
1845 ALOGV("%s: Fluence_Type(%d) max_mic_count(%d) mic_type(0x%x) fluence_in_voice_call(%d)"
1846 " fluence_in_voice_comm(%d) fluence_in_voice_rec(%d) fluence_in_spkr_mode(%d) ",
1847 __func__, my_data->fluence_type, my_data->max_mic_count, my_data->source_mic_type,
1848 my_data->fluence_in_voice_call, my_data->fluence_in_voice_comm,
1849 my_data->fluence_in_voice_rec, my_data->fluence_in_spkr_mode);
1850
Eric Laurentb23d5282013-05-14 15:27:20 -07001851 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
1852 if (my_data->acdb_handle == NULL) {
1853 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
1854 } else {
1855 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
1856 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
1857 "acdb_loader_deallocate_ACDB");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001858 if (!my_data->acdb_deallocate)
1859 ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s",
1860 __func__, LIB_ACDB_LOADER);
1861
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001862 my_data->acdb_send_audio_cal_v3 = (acdb_send_audio_cal_v3_t)dlsym(my_data->acdb_handle,
1863 "acdb_loader_send_audio_cal_v3");
1864 if (!my_data->acdb_send_audio_cal_v3)
1865 ALOGE("%s: Could not find the symbol acdb_send_audio_cal_v3 from %s",
1866 __func__, LIB_ACDB_LOADER);
1867
Eric Laurentb23d5282013-05-14 15:27:20 -07001868 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
1869 "acdb_loader_send_audio_cal");
1870 if (!my_data->acdb_send_audio_cal)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001871 ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s",
Eric Laurentb23d5282013-05-14 15:27:20 -07001872 __func__, LIB_ACDB_LOADER);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001873
Eric Laurentb23d5282013-05-14 15:27:20 -07001874 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
1875 "acdb_loader_send_voice_cal");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001876 if (!my_data->acdb_send_voice_cal)
1877 ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s",
1878 __func__, LIB_ACDB_LOADER);
1879
1880 my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle,
1881 "acdb_loader_reload_vocvoltable");
1882 if (!my_data->acdb_reload_vocvoltable)
1883 ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s",
1884 __func__, LIB_ACDB_LOADER);
vivek mehta1a9b7c02015-06-25 11:49:38 -07001885
1886 my_data->acdb_send_gain_dep_cal = (acdb_send_gain_dep_cal_t)dlsym(my_data->acdb_handle,
1887 "acdb_loader_send_gain_dep_cal");
1888 if (!my_data->acdb_send_gain_dep_cal)
1889 ALOGV("%s: Could not find the symbol acdb_loader_send_gain_dep_cal from %s",
1890 __func__, LIB_ACDB_LOADER);
1891
Xu Han1638fd12018-04-20 12:42:23 -07001892#if defined (FLICKER_SENSOR_INPUT)
1893 configure_flicker_sensor_input(adev->mixer);
1894#endif
1895
Thierry Strudel07f96d12018-09-20 13:31:34 -07001896#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845) || (PLATFORM_SDM710) || (PLATFORM_SM8150)
vivek mehta0fb11312017-05-15 19:35:32 -07001897 acdb_init_v2_cvd_t acdb_init_local;
1898 acdb_init_local = (acdb_init_v2_cvd_t)dlsym(my_data->acdb_handle,
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001899 "acdb_loader_init_v2");
vivek mehta0fb11312017-05-15 19:35:32 -07001900 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001901 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1902 dlerror());
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001903
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001904#elif defined (PLATFORM_MSM8084)
vivek mehta0fb11312017-05-15 19:35:32 -07001905 acdb_init_v2_t acdb_init_local;
1906 acdb_init_local = (acdb_init_v2_t)dlsym(my_data->acdb_handle,
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001907 "acdb_loader_init_v2");
vivek mehta0fb11312017-05-15 19:35:32 -07001908 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001909 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1910 dlerror());
1911
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001912#else
vivek mehta0fb11312017-05-15 19:35:32 -07001913 acdb_init_t acdb_init_local;
1914 acdb_init_local = (acdb_init_t)dlsym(my_data->acdb_handle,
Eric Laurentb23d5282013-05-14 15:27:20 -07001915 "acdb_loader_init_ACDB");
vivek mehta0fb11312017-05-15 19:35:32 -07001916 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001917 ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__,
1918 dlerror());
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001919#endif
vivek mehta0fb11312017-05-15 19:35:32 -07001920 my_data->acdb_init = acdb_init_local;
Eric Laurentb23d5282013-05-14 15:27:20 -07001921
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001922 my_data->acdb_send_custom_top = (acdb_send_custom_top_t)
1923 dlsym(my_data->acdb_handle,
1924 "acdb_loader_send_common_custom_topology");
1925
1926 if (!my_data->acdb_send_custom_top)
1927 ALOGE("%s: Could not find the symbol acdb_get_default_app_type from %s",
1928 __func__, LIB_ACDB_LOADER);
1929
jasmine chac89321b2018-04-10 21:37:01 +08001930 my_data->acdb_set_audio_cal = (acdb_set_audio_cal_t)dlsym(my_data->acdb_handle,
1931 "acdb_loader_set_audio_cal_v2");
1932 if (!my_data->acdb_set_audio_cal)
1933 ALOGE("%s: Could not find the symbol acdb_set_audio_cal_v2 from %s",
1934 __func__, LIB_ACDB_LOADER);
1935
vivek mehta0fb11312017-05-15 19:35:32 -07001936 int result = acdb_init(adev->snd_card);
1937 if (!result) {
1938 my_data->acdb_initialized = true;
1939 ALOGD("ACDB initialized");
1940 } else {
1941 my_data->acdb_initialized = false;
1942 ALOGD("ACDB initialization failed");
1943 }
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001944 }
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001945
David Linee3fe402017-03-13 10:00:42 -07001946 /* init usb */
1947 audio_extn_usb_init(adev);
1948
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001949 /* init a2dp */
1950 audio_extn_a2dp_init(adev);
1951
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001952 audio_extn_spkr_prot_init(adev);
Haynes Mathew George98c95622014-06-20 19:14:25 -07001953
Ravi Kumar Alamanda76315572015-04-23 13:13:56 -07001954 audio_extn_hwdep_cal_send(adev->snd_card, my_data->acdb_handle);
1955
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001956 /* load csd client */
1957 platform_csd_init(my_data);
1958
David Linee3fe402017-03-13 10:00:42 -07001959 platform_backend_config_init(my_data);
1960
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001961 init_be_dai_name_table(adev);
1962
1963 if (platform_supports_app_type_cfg())
1964 platform_backend_app_type_cfg_init(my_data, adev->mixer);
1965
Eric Laurentb23d5282013-05-14 15:27:20 -07001966 return my_data;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001967
1968init_failed:
1969 if (my_data)
1970 free(my_data);
1971 return NULL;
Eric Laurentb23d5282013-05-14 15:27:20 -07001972}
1973
1974void platform_deinit(void *platform)
1975{
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001976 int32_t dev;
keunhui.park2f7306a2015-07-16 16:48:06 +09001977 struct operator_info *info_item;
1978 struct operator_specific_device *device_item;
Carter Hsu017c63a2018-10-15 15:01:42 -07001979 struct external_specific_device *ext_dev;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001980 struct app_type_entry *ap;
keunhui.park2f7306a2015-07-16 16:48:06 +09001981 struct listnode *node;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001982
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001983 struct platform_data *my_data = (struct platform_data *)platform;
1984 close_csd_client(my_data->csd);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001985
David Lin41b4fe42018-07-08 16:14:24 -07001986 audio_extn_spkr_prot_deinit(my_data->adev);
1987
vivek mehtade4849c2016-03-03 17:23:38 -08001988 hw_info_deinit(my_data->hw_info);
1989
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001990 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1991 if (backend_tag_table[dev])
1992 free(backend_tag_table[dev]);
1993 if (hw_interface_table[dev])
1994 free(hw_interface_table[dev]);
keunhui.park2f7306a2015-07-16 16:48:06 +09001995 if (operator_specific_device_table[dev]) {
1996 while (!list_empty(operator_specific_device_table[dev])) {
1997 node = list_head(operator_specific_device_table[dev]);
1998 list_remove(node);
1999 device_item = node_to_item(node, struct operator_specific_device, list);
2000 free(device_item->operator);
2001 free(device_item->mixer_path);
2002 free(device_item);
2003 }
2004 free(operator_specific_device_table[dev]);
2005 }
Carter Hsu017c63a2018-10-15 15:01:42 -07002006
2007 if (external_specific_device_table[dev]) {
2008 while (!list_empty(external_specific_device_table[dev])) {
2009 node = list_head(external_specific_device_table[dev]);
2010 list_remove(node);
2011 ext_dev = node_to_item(node, struct external_specific_device, list);
2012 free(ext_dev->usbid);
2013 free(ext_dev);
2014 }
2015 free(external_specific_device_table[dev]);
2016 }
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002017 }
2018
2019 if (my_data->snd_card_name)
2020 free(my_data->snd_card_name);
2021
keunhui.park2f7306a2015-07-16 16:48:06 +09002022 while (!list_empty(&operator_info_list)) {
2023 node = list_head(&operator_info_list);
2024 list_remove(node);
2025 info_item = node_to_item(node, struct operator_info, list);
2026 free(info_item->name);
2027 free(info_item->mccmnc);
2028 free(info_item);
2029 }
2030
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002031 while (!list_empty(&app_type_entry_list)) {
2032 node = list_head(&app_type_entry_list);
2033 list_remove(node);
2034 ap = node_to_item(node, struct app_type_entry, node);
vivek mehtaa68fea62017-06-08 19:04:02 -07002035 if (ap->mode) free(ap->mode);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002036 free(ap);
2037 }
2038
Kevin Rocarde35d4af2017-05-02 16:55:28 -07002039 mixer_close(my_data->adev->mixer);
Eric Laurentb23d5282013-05-14 15:27:20 -07002040 free(platform);
David Linee3fe402017-03-13 10:00:42 -07002041
2042 /* deinit usb */
2043 audio_extn_usb_deinit();
Eric Laurentb23d5282013-05-14 15:27:20 -07002044}
2045
2046const char *platform_get_snd_device_name(snd_device_t snd_device)
2047{
keunhui.park2f7306a2015-07-16 16:48:06 +09002048 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
2049 if (operator_specific_device_table[snd_device] != NULL) {
2050 return get_operator_specific_device_mixer_path(snd_device);
2051 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002052 return device_table[snd_device];
keunhui.park2f7306a2015-07-16 16:48:06 +09002053 } else
Ravi Kumar Alamanda64026462014-09-15 00:08:58 -07002054 return "none";
Eric Laurentb23d5282013-05-14 15:27:20 -07002055}
2056
vivek mehtade4849c2016-03-03 17:23:38 -08002057int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
2058 char *device_name)
2059{
2060 struct platform_data *my_data = (struct platform_data *)platform;
2061
David Benjamin1565f992016-09-21 12:10:34 -04002062 if (platform == NULL) {
vivek mehtade4849c2016-03-03 17:23:38 -08002063 ALOGW("%s: something wrong, use legacy get_snd_device name", __func__);
David Benjamin1565f992016-09-21 12:10:34 -04002064 strlcpy(device_name, platform_get_snd_device_name(snd_device),
2065 DEVICE_NAME_MAX_SIZE);
vivek mehtade4849c2016-03-03 17:23:38 -08002066 } else if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
2067 if (operator_specific_device_table[snd_device] != NULL) {
2068 strlcpy(device_name, get_operator_specific_device_mixer_path(snd_device),
2069 DEVICE_NAME_MAX_SIZE);
2070 } else {
2071 strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE);
2072 }
2073 hw_info_append_hw_type(my_data->hw_info, snd_device, device_name);
2074 } else {
2075 strlcpy(device_name, "none", DEVICE_NAME_MAX_SIZE);
Aniket Kumar Lataa158e862018-05-11 17:28:40 -07002076 return -EINVAL;
vivek mehtade4849c2016-03-03 17:23:38 -08002077 }
2078
2079 return 0;
2080}
2081
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05002082void platform_add_backend_name(void *platform, char *mixer_path,
2083 snd_device_t snd_device)
Eric Laurentb23d5282013-05-14 15:27:20 -07002084{
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05002085 struct platform_data *my_data = (struct platform_data *)platform;
2086
Haynes Mathew George98c95622014-06-20 19:14:25 -07002087 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
2088 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
2089 return;
Ravi Kumar Alamanda1de6e5a2014-06-19 21:55:39 -05002090 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07002091
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002092 const char * suffix = backend_tag_table[snd_device];
Haynes Mathew George98c95622014-06-20 19:14:25 -07002093
2094 if (suffix != NULL) {
2095 strcat(mixer_path, " ");
2096 strcat(mixer_path, suffix);
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05002097 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002098}
2099
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002100bool platform_check_backends_match(snd_device_t snd_device1, snd_device_t snd_device2)
2101{
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002102 ALOGV("%s: snd_device1 = %s, snd_device2 = %s", __func__,
2103 platform_get_snd_device_name(snd_device1),
2104 platform_get_snd_device_name(snd_device2));
2105
2106 if ((snd_device1 < SND_DEVICE_MIN) || (snd_device1 >= SND_DEVICE_MAX)) {
2107 ALOGE("%s: Invalid snd_device = %s", __func__,
2108 platform_get_snd_device_name(snd_device1));
2109 return false;
2110 }
2111 if ((snd_device2 < SND_DEVICE_MIN) || (snd_device2 >= SND_DEVICE_MAX)) {
2112 ALOGE("%s: Invalid snd_device = %s", __func__,
2113 platform_get_snd_device_name(snd_device2));
2114 return false;
2115 }
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07002116
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002117 const char * be_itf1 = hw_interface_table[snd_device1];
2118 const char * be_itf2 = hw_interface_table[snd_device2];
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07002119 /*
2120 hw_interface_table has overrides for a snd_device.
2121 if there is no entry for a device, assume DEFAULT_RX_BACKEND
2122 */
2123 if (be_itf1 == NULL) {
2124 be_itf1 = DEFAULT_RX_BACKEND;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002125 }
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07002126 if (be_itf2 == NULL) {
2127 be_itf2 = DEFAULT_RX_BACKEND;
2128 }
2129 ALOGV("%s: be_itf1 = %s, be_itf2 = %s", __func__, be_itf1, be_itf2);
2130 /*
2131 this takes care of finding a device within a combo device pair as well
2132 */
2133 return strstr(be_itf1, be_itf2) != NULL || strstr(be_itf2, be_itf1) != NULL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002134}
2135
Eric Laurentb23d5282013-05-14 15:27:20 -07002136int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
2137{
2138 int device_id;
2139 if (device_type == PCM_PLAYBACK)
2140 device_id = pcm_device_table[usecase][0];
2141 else
2142 device_id = pcm_device_table[usecase][1];
2143 return device_id;
2144}
2145
Vignesh Kulothungan019d19b2019-01-23 11:09:18 -08002146int platform_get_haptics_pcm_device_id()
2147{
2148 return HAPTICS_PCM_DEVICE;
2149}
2150
Haynes Mathew George98c95622014-06-20 19:14:25 -07002151static int find_index(const struct name_to_index * table, int32_t len,
2152 const char * name)
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002153{
2154 int ret = 0;
Haynes Mathew George98c95622014-06-20 19:14:25 -07002155 int32_t i;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002156
Haynes Mathew George98c95622014-06-20 19:14:25 -07002157 if (table == NULL) {
2158 ALOGE("%s: table is NULL", __func__);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002159 ret = -ENODEV;
2160 goto done;
2161 }
2162
Haynes Mathew George98c95622014-06-20 19:14:25 -07002163 if (name == NULL) {
2164 ALOGE("null key");
2165 ret = -ENODEV;
2166 goto done;
2167 }
2168
2169 for (i=0; i < len; i++) {
2170 if (!strcmp(table[i].name, name)) {
2171 ret = table[i].index;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002172 goto done;
2173 }
2174 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07002175 ALOGE("%s: Could not find index for name = %s",
2176 __func__, name);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002177 ret = -ENODEV;
2178done:
2179 return ret;
2180}
2181
Haynes Mathew George98c95622014-06-20 19:14:25 -07002182int platform_get_snd_device_index(char *device_name)
2183{
2184 return find_index(snd_device_name_index, SND_DEVICE_MAX, device_name);
2185}
2186
2187int platform_get_usecase_index(const char *usecase_name)
2188{
2189 return find_index(usecase_name_index, AUDIO_USECASE_MAX, usecase_name);
2190}
2191
Vignesh Kulothungan64698822018-01-23 11:25:18 -08002192int platform_get_effect_config_data(snd_device_t snd_device,
2193 struct audio_effect_config *effect_config,
2194 effect_type_t effect_type)
2195{
2196 int ret = 0;
2197
2198 if ((snd_device < SND_DEVICE_IN_BEGIN) || (snd_device >= SND_DEVICE_MAX) ||
2199 (effect_type <= EFFECT_NONE) || (effect_type >= EFFECT_COUNT)) {
2200 ALOGE("%s: Invalid snd_device = %d or effect_type = %d",
2201 __func__, snd_device, effect_type);
2202 ret = -EINVAL;
2203 goto done;
2204 }
2205
2206 if (effect_config == NULL) {
2207 ALOGE("%s: Invalid effect_config", __func__);
2208 ret = -EINVAL;
2209 goto done;
2210 }
2211
2212 ALOGV("%s: snd_device = %d module_id = %d",
2213 __func__, snd_device, effect_config_table[GET_IN_DEVICE_INDEX(snd_device)][effect_type].module_id);
2214 *effect_config = effect_config_table[GET_IN_DEVICE_INDEX(snd_device)][effect_type];
2215
2216done:
2217 return ret;
2218}
2219
2220int platform_set_effect_config_data(snd_device_t snd_device,
2221 struct audio_effect_config effect_config,
2222 effect_type_t effect_type)
2223{
2224 int ret = 0;
2225
2226 if ((snd_device < SND_DEVICE_IN_BEGIN) || (snd_device >= SND_DEVICE_MAX) ||
2227 (effect_type <= EFFECT_NONE) || (effect_type >= EFFECT_COUNT)) {
2228 ALOGE("%s: Invalid snd_device = %d or effect_type = %d",
2229 __func__, snd_device, effect_type);
2230 ret = -EINVAL;
2231 goto done;
2232 }
2233
2234 ALOGV("%s 0x%x 0x%x 0x%x 0x%x", __func__, effect_config.module_id,
2235 effect_config.instance_id, effect_config.param_id,
2236 effect_config.param_value);
2237 effect_config_table[GET_IN_DEVICE_INDEX(snd_device)][effect_type] = effect_config;
2238
2239done:
2240 return ret;
2241}
2242
keunhui.park2f7306a2015-07-16 16:48:06 +09002243void platform_add_operator_specific_device(snd_device_t snd_device,
2244 const char *operator,
2245 const char *mixer_path,
2246 unsigned int acdb_id)
2247{
2248 struct operator_specific_device *device;
2249
2250 if (operator_specific_device_table[snd_device] == NULL) {
2251 operator_specific_device_table[snd_device] =
2252 (struct listnode *)calloc(1, sizeof(struct listnode));
2253 list_init(operator_specific_device_table[snd_device]);
2254 }
2255
2256 device = (struct operator_specific_device *)calloc(1, sizeof(struct operator_specific_device));
2257
2258 device->operator = strdup(operator);
2259 device->mixer_path = strdup(mixer_path);
2260 device->acdb_id = acdb_id;
2261
2262 list_add_tail(operator_specific_device_table[snd_device], &device->list);
2263
Eric Laurent2bafff12016-03-17 12:17:23 -07002264 ALOGD("%s: device[%s] -> operator[%s] mixer_path[%s] acdb_id[%d]", __func__,
keunhui.park2f7306a2015-07-16 16:48:06 +09002265 platform_get_snd_device_name(snd_device), operator, mixer_path, acdb_id);
2266
2267}
2268
Carter Hsu017c63a2018-10-15 15:01:42 -07002269void platform_add_external_specific_device(snd_device_t snd_device,
2270 const char *usbid,
2271 unsigned int acdb_id)
2272{
2273 struct external_specific_device *device;
2274
2275 if (external_specific_device_table[snd_device] == NULL) {
2276 external_specific_device_table[snd_device] =
2277 (struct listnode *)calloc(1, sizeof(struct listnode));
2278 list_init(external_specific_device_table[snd_device]);
2279 }
2280
2281 device = (struct external_specific_device *)calloc(1, sizeof(struct external_specific_device));
2282
2283 device->usbid = strdup(usbid);
2284 device->acdb_id = acdb_id;
2285
2286 list_add_tail(external_specific_device_table[snd_device], &device->list);
2287
2288 ALOGD("%s: device[%s] usbid[%s] -> acdb_id[%d]", __func__,
2289 platform_get_snd_device_name(snd_device), usbid, acdb_id);
2290}
2291
2292
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002293int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
2294{
2295 int ret = 0;
2296
2297 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
2298 ALOGE("%s: Invalid snd_device = %d",
2299 __func__, snd_device);
2300 ret = -EINVAL;
2301 goto done;
2302 }
2303
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002304 ALOGV("%s: acdb_device_table[%s]: old = %d new = %d", __func__,
2305 platform_get_snd_device_name(snd_device), acdb_device_table[snd_device], acdb_id);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002306 acdb_device_table[snd_device] = acdb_id;
2307done:
2308 return ret;
2309}
2310
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07002311int platform_get_snd_device_acdb_id(snd_device_t snd_device)
2312{
2313 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
2314 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
2315 return -EINVAL;
2316 }
keunhui.park2f7306a2015-07-16 16:48:06 +09002317
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002318 /*
2319 * If speaker protection is enabled, function returns supported
2320 * sound device for speaker. Else same sound device is returned.
2321 */
2322 snd_device = audio_extn_get_spkr_prot_snd_device(snd_device);
2323
keunhui.park2f7306a2015-07-16 16:48:06 +09002324 if (operator_specific_device_table[snd_device] != NULL)
2325 return get_operator_specific_device_acdb_id(snd_device);
Carter Hsu017c63a2018-10-15 15:01:42 -07002326 else if (external_specific_device_table[snd_device] != NULL)
2327 return get_external_specific_device_acdb_id(snd_device);
keunhui.park2f7306a2015-07-16 16:48:06 +09002328 else
2329 return acdb_device_table[snd_device];
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07002330}
2331
David Linee3fe402017-03-13 10:00:42 -07002332static int platform_get_backend_index(snd_device_t snd_device)
2333{
2334 int32_t port = DEFAULT_CODEC_BACKEND;
2335
2336 if (snd_device >= SND_DEVICE_OUT_BEGIN && snd_device < SND_DEVICE_OUT_END) {
2337 if (backend_tag_table[snd_device] != NULL) {
2338 if (strncmp(backend_tag_table[snd_device], "headphones",
2339 sizeof("headphones")) == 0)
2340 port = HEADPHONE_BACKEND;
2341 else if (strcmp(backend_tag_table[snd_device], "hdmi") == 0)
2342 port = HDMI_RX_BACKEND;
2343 else if ((strcmp(backend_tag_table[snd_device], "usb-headphones") == 0) ||
2344 (strcmp(backend_tag_table[snd_device], "usb-headset") == 0))
2345 port = USB_AUDIO_RX_BACKEND;
2346 }
2347 } else if (snd_device >= SND_DEVICE_IN_BEGIN && snd_device < SND_DEVICE_IN_END) {
2348 port = DEFAULT_CODEC_TX_BACKEND;
2349 if (backend_tag_table[snd_device] != NULL) {
2350 if (strcmp(backend_tag_table[snd_device], "usb-headset-mic") == 0)
2351 port = USB_AUDIO_TX_BACKEND;
2352 else if (strstr(backend_tag_table[snd_device], "bt-sco") != NULL)
2353 port = BT_SCO_TX_BACKEND;
2354 }
2355 } else {
2356 ALOGW("%s:napb: Invalid device - %d ", __func__, snd_device);
2357 }
2358
2359 ALOGV("%s:napb: backend port - %d device - %d ", __func__, port, snd_device);
2360
2361 return port;
2362}
2363
Eric Laurentb23d5282013-05-14 15:27:20 -07002364int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
2365{
2366 struct platform_data *my_data = (struct platform_data *)platform;
2367 int acdb_dev_id, acdb_dev_type;
2368
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002369 if (platform_supports_app_type_cfg()) // use v2 instead
2370 return -ENOSYS;
2371
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002372 acdb_dev_id = platform_get_snd_device_acdb_id(snd_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07002373 if (acdb_dev_id < 0) {
2374 ALOGE("%s: Could not find acdb id for device(%d)",
2375 __func__, snd_device);
2376 return -EINVAL;
2377 }
2378 if (my_data->acdb_send_audio_cal) {
Joe Onorato188b6222016-03-01 11:02:27 -08002379 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Eric Laurentb23d5282013-05-14 15:27:20 -07002380 __func__, snd_device, acdb_dev_id);
2381 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
2382 snd_device < SND_DEVICE_OUT_END)
2383 acdb_dev_type = ACDB_DEV_TYPE_OUT;
2384 else
2385 acdb_dev_type = ACDB_DEV_TYPE_IN;
2386 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
2387 }
2388 return 0;
2389}
2390
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002391int platform_send_audio_calibration_v2(void *platform, struct audio_usecase *usecase,
2392 int app_type, int sample_rate)
2393{
2394 struct platform_data *my_data = (struct platform_data *)platform;
2395 int acdb_dev_id, acdb_dev_type;
vivek mehta7e573672018-03-13 17:41:41 -07002396 int snd_device = usecase->out_snd_device;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002397 int new_snd_device[SND_DEVICE_OUT_END] = {0};
2398 int i, num_devices = 1;
2399
2400 if (!platform_supports_app_type_cfg()) // use v1 instead
2401 return -ENOSYS;
2402
vivek mehta7e573672018-03-13 17:41:41 -07002403 if ((usecase->type == PCM_HFP_CALL) || (usecase->type == PCM_CAPTURE))
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002404 snd_device = usecase->in_snd_device;
2405
2406 // skipped over get_spkr_prot_device
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002407 acdb_dev_id = platform_get_snd_device_acdb_id(snd_device);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002408 if (acdb_dev_id < 0) {
2409 ALOGE("%s: Could not find acdb id for device(%d)",
2410 __func__, snd_device);
2411 return -EINVAL;
2412 }
2413
2414 if (platform_can_split_snd_device(snd_device,
2415 &num_devices, new_snd_device) < 0) {
2416 new_snd_device[0] = snd_device;
2417 }
2418
2419 for (i = 0; i < num_devices; i++) {
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002420 acdb_dev_id = platform_get_snd_device_acdb_id(new_snd_device[i]);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002421 if (acdb_dev_id < 0) {
2422 ALOGE("%s: Could not find acdb id for device(%d)",
2423 __func__, new_snd_device[i]);
2424 return -EINVAL;
2425 }
2426 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
2427 __func__, new_snd_device[i], acdb_dev_id);
2428 if (new_snd_device[i] >= SND_DEVICE_OUT_BEGIN &&
2429 new_snd_device[i] < SND_DEVICE_OUT_END)
2430 acdb_dev_type = ACDB_DEV_TYPE_OUT;
2431 else
2432 acdb_dev_type = ACDB_DEV_TYPE_IN;
2433
2434 if (my_data->acdb_send_audio_cal_v3) {
2435 my_data->acdb_send_audio_cal_v3(acdb_dev_id, acdb_dev_type,
2436 app_type, sample_rate, i);
2437 } else if (my_data->acdb_send_audio_cal) {
2438 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type); // this version differs from internal
2439 }
2440 }
2441
2442 return 0;
2443}
2444
2445
Eric Laurentb23d5282013-05-14 15:27:20 -07002446int platform_switch_voice_call_device_pre(void *platform)
2447{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002448 struct platform_data *my_data = (struct platform_data *)platform;
2449 int ret = 0;
2450
2451 if (my_data->csd != NULL &&
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002452 voice_is_in_call(my_data->adev)) {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002453 /* This must be called before disabling mixer controls on APQ side */
2454 ret = my_data->csd->disable_device();
2455 if (ret < 0) {
2456 ALOGE("%s: csd_client_disable_device, failed, error %d",
2457 __func__, ret);
2458 }
2459 }
2460 return ret;
2461}
2462
2463int platform_switch_voice_call_enable_device_config(void *platform,
2464 snd_device_t out_snd_device,
2465 snd_device_t in_snd_device)
2466{
2467 struct platform_data *my_data = (struct platform_data *)platform;
2468 int acdb_rx_id, acdb_tx_id;
2469 int ret = 0;
2470
2471 if (my_data->csd == NULL)
2472 return ret;
2473
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002474 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
keunhui.park2f7306a2015-07-16 16:48:06 +09002475 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002476
2477 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
2478 ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
2479 if (ret < 0) {
2480 ALOGE("%s: csd_enable_device_config, failed, error %d",
2481 __func__, ret);
2482 }
2483 } else {
2484 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2485 acdb_rx_id, acdb_tx_id);
2486 }
2487
2488 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002489}
2490
2491int platform_switch_voice_call_device_post(void *platform,
2492 snd_device_t out_snd_device,
2493 snd_device_t in_snd_device)
2494{
2495 struct platform_data *my_data = (struct platform_data *)platform;
2496 int acdb_rx_id, acdb_tx_id;
2497
2498 if (my_data->acdb_send_voice_cal == NULL) {
2499 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
2500 } else {
keunhui.park2f7306a2015-07-16 16:48:06 +09002501 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
2502 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07002503
2504 if (acdb_rx_id > 0 && acdb_tx_id > 0)
2505 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
2506 else
2507 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2508 acdb_rx_id, acdb_tx_id);
2509 }
2510
2511 return 0;
2512}
2513
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002514int platform_switch_voice_call_usecase_route_post(void *platform,
2515 snd_device_t out_snd_device,
2516 snd_device_t in_snd_device)
2517{
2518 struct platform_data *my_data = (struct platform_data *)platform;
2519 int acdb_rx_id, acdb_tx_id;
2520 int ret = 0;
2521
2522 if (my_data->csd == NULL)
2523 return ret;
2524
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002525 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
keunhui.park2f7306a2015-07-16 16:48:06 +09002526 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002527
2528 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
2529 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
2530 my_data->adev->acdb_settings);
2531 if (ret < 0) {
2532 ALOGE("%s: csd_enable_device, failed, error %d", __func__, ret);
2533 }
2534 } else {
2535 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2536 acdb_rx_id, acdb_tx_id);
2537 }
2538
2539 return ret;
2540}
2541
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002542int platform_start_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07002543{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002544 struct platform_data *my_data = (struct platform_data *)platform;
2545 int ret = 0;
2546
2547 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002548 ret = my_data->csd->start_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002549 if (ret < 0) {
2550 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
2551 }
2552 }
2553 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002554}
2555
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002556int platform_stop_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07002557{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002558 struct platform_data *my_data = (struct platform_data *)platform;
2559 int ret = 0;
2560
2561 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002562 ret = my_data->csd->stop_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002563 if (ret < 0) {
2564 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
2565 }
2566 }
2567 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002568}
2569
Vignesh Kulothunganb6f0a9c2018-03-22 13:50:22 -07002570int platform_set_mic_break_det(void *platform, bool enable)
2571{
2572 int ret = 0;
2573 struct platform_data *my_data = (struct platform_data *)platform;
2574 struct audio_device *adev = my_data->adev;
2575 const char *mixer_ctl_name = "Voice Mic Break Enable";
2576 struct mixer_ctl *ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2577 if (!ctl) {
2578 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2579 __func__, mixer_ctl_name);
2580 return -EINVAL;
2581 }
2582
2583 ret = mixer_ctl_set_value(ctl, 0, enable);
2584 if(ret)
2585 ALOGE("%s: Failed to set mixer ctl: %s", __func__, mixer_ctl_name);
2586
2587 return ret;
2588}
2589
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002590int platform_get_sample_rate(void *platform, uint32_t *rate)
2591{
2592 struct platform_data *my_data = (struct platform_data *)platform;
2593 int ret = 0;
2594
2595 if (my_data->csd != NULL) {
2596 ret = my_data->csd->get_sample_rate(rate);
2597 if (ret < 0) {
2598 ALOGE("%s: csd_get_sample_rate error %d\n", __func__, ret);
2599 }
2600 }
2601 return ret;
2602}
2603
vivek mehtab6506412015-08-07 16:55:17 -07002604void platform_set_speaker_gain_in_combo(struct audio_device *adev,
2605 snd_device_t snd_device,
2606 bool enable)
2607{
2608 const char* name;
2609 switch (snd_device) {
2610 case SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES:
2611 if (enable)
2612 name = "spkr-gain-in-headphone-combo";
2613 else
2614 name = "speaker-gain-default";
2615 break;
2616 case SND_DEVICE_OUT_SPEAKER_AND_LINE:
2617 if (enable)
2618 name = "spkr-gain-in-line-combo";
2619 else
2620 name = "speaker-gain-default";
2621 break;
2622 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES:
2623 if (enable)
2624 name = "spkr-safe-gain-in-headphone-combo";
2625 else
2626 name = "speaker-safe-gain-default";
2627 break;
2628 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE:
2629 if (enable)
2630 name = "spkr-safe-gain-in-line-combo";
2631 else
2632 name = "speaker-safe-gain-default";
2633 break;
2634 default:
2635 return;
2636 }
2637
2638 audio_route_apply_and_update_path(adev->audio_route, name);
2639}
2640
Eric Laurentb23d5282013-05-14 15:27:20 -07002641int platform_set_voice_volume(void *platform, int volume)
2642{
2643 struct platform_data *my_data = (struct platform_data *)platform;
2644 struct audio_device *adev = my_data->adev;
2645 struct mixer_ctl *ctl;
sangwoo53b2cf02013-07-25 19:18:44 -07002646 const char *mixer_ctl_name = "Voice Rx Gain";
Nadav Barc46d0fa2017-12-24 14:50:37 +02002647 const char *mute_mixer_ctl_name = "Voice Rx Device Mute";
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002648 int vol_index = 0, ret = 0;
2649 uint32_t set_values[ ] = {0,
2650 ALL_SESSION_VSID,
2651 DEFAULT_VOLUME_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07002652
2653 // Voice volume levels are mapped to adsp volume levels as follows.
2654 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
2655 // But this values don't changed in kernel. So, below change is need.
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09002656 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, my_data->max_vol_index);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002657 set_values[0] = vol_index;
Eric Laurentb23d5282013-05-14 15:27:20 -07002658
2659 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2660 if (!ctl) {
2661 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2662 __func__, mixer_ctl_name);
2663 return -EINVAL;
2664 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002665 ALOGV("Setting voice volume index: %d", set_values[0]);
2666 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2667
Nadav Barc46d0fa2017-12-24 14:50:37 +02002668 // Send mute command in case volume index is max since indexes are inverted
2669 // for mixer controls.
2670 if (vol_index == my_data->max_vol_index) {
2671 set_values[0] = 1;
2672 }
2673 else {
2674 set_values[0] = 0;
2675 }
2676
2677 ctl = mixer_get_ctl_by_name(adev->mixer, mute_mixer_ctl_name);
2678 if (!ctl) {
2679 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2680 __func__, mute_mixer_ctl_name);
2681 return -EINVAL;
2682 }
2683 ALOGV("%s: Setting RX Device Mute to: %d", __func__, set_values[0]);
2684 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2685
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002686 if (my_data->csd != NULL) {
2687 ret = my_data->csd->volume(ALL_SESSION_VSID, volume,
2688 DEFAULT_VOLUME_RAMP_DURATION_MS);
2689 if (ret < 0) {
2690 ALOGE("%s: csd_volume error %d", __func__, ret);
2691 }
2692 }
2693 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002694}
2695
2696int platform_set_mic_mute(void *platform, bool state)
2697{
2698 struct platform_data *my_data = (struct platform_data *)platform;
2699 struct audio_device *adev = my_data->adev;
2700 struct mixer_ctl *ctl;
2701 const char *mixer_ctl_name = "Voice Tx Mute";
sangwoo53b2cf02013-07-25 19:18:44 -07002702 int ret = 0;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002703 uint32_t set_values[ ] = {0,
2704 ALL_SESSION_VSID,
2705 DEFAULT_MUTE_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07002706
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09002707 if (adev->mode != AUDIO_MODE_IN_CALL &&
2708 adev->mode != AUDIO_MODE_IN_COMMUNICATION)
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002709 return 0;
2710
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09002711 if (adev->enable_hfp)
2712 mixer_ctl_name = "HFP Tx Mute";
2713
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002714 set_values[0] = state;
2715 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2716 if (!ctl) {
2717 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2718 __func__, mixer_ctl_name);
2719 return -EINVAL;
2720 }
Arun Mirpuri0cc2f312018-05-29 17:26:07 -07002721 ALOGV("%s: Setting voice mute state: %d", __func__, state);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002722 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2723
2724 if (my_data->csd != NULL) {
2725 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state,
2726 DEFAULT_MUTE_RAMP_DURATION_MS);
sangwoo53b2cf02013-07-25 19:18:44 -07002727 if (ret < 0) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002728 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
sangwoo53b2cf02013-07-25 19:18:44 -07002729 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002730 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002731 return ret;
2732}
Eric Laurentb23d5282013-05-14 15:27:20 -07002733
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002734int platform_set_device_mute(void *platform, bool state, char *dir)
2735{
2736 struct platform_data *my_data = (struct platform_data *)platform;
2737 struct audio_device *adev = my_data->adev;
2738 struct mixer_ctl *ctl;
2739 char *mixer_ctl_name = NULL;
2740 int ret = 0;
2741 uint32_t set_values[ ] = {0,
2742 ALL_SESSION_VSID,
2743 0};
2744 if(dir == NULL) {
2745 ALOGE("%s: Invalid direction:%s", __func__, dir);
2746 return -EINVAL;
2747 }
2748
2749 if (!strncmp("rx", dir, sizeof("rx"))) {
2750 mixer_ctl_name = "Voice Rx Device Mute";
2751 } else if (!strncmp("tx", dir, sizeof("tx"))) {
2752 mixer_ctl_name = "Voice Tx Device Mute";
2753 } else {
2754 return -EINVAL;
2755 }
2756
2757 set_values[0] = state;
2758 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2759 if (!ctl) {
2760 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2761 __func__, mixer_ctl_name);
2762 return -EINVAL;
2763 }
2764
2765 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
2766 __func__,state, mixer_ctl_name);
2767 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2768
2769 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002770}
2771
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002772int platform_can_split_snd_device(snd_device_t snd_device,
2773 int *num_devices,
2774 snd_device_t *new_snd_devices)
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002775{
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002776 int ret = -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002777 if (NULL == num_devices || NULL == new_snd_devices) {
2778 ALOGE("%s: NULL pointer ..", __func__);
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002779 return -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002780 }
2781
2782 /*
2783 * If wired headset/headphones/line devices share the same backend
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002784 * with speaker/earpiece this routine returns -EINVAL.
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002785 */
2786 if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES &&
2787 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_HEADPHONES)) {
2788 *num_devices = 2;
2789 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2790 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002791 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002792 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_LINE &&
2793 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_LINE)) {
2794 *num_devices = 2;
2795 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2796 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002797 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002798 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES &&
2799 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_HEADPHONES)) {
2800 *num_devices = 2;
2801 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2802 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002803 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002804 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE &&
2805 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_LINE)) {
2806 *num_devices = 2;
2807 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2808 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002809 ret = 0;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002810 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO &&
2811 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2812 SND_DEVICE_OUT_BT_SCO)) {
2813 *num_devices = 2;
2814 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2815 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO;
2816 ret = 0;
juyuchen5351ea62018-05-16 10:54:37 +08002817 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO &&
2818 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE,
2819 SND_DEVICE_OUT_BT_SCO)) {
2820 *num_devices = 2;
2821 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2822 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO;
2823 ret = 0;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002824 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB &&
2825 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2826 SND_DEVICE_OUT_BT_SCO_WB)) {
2827 *num_devices = 2;
2828 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2829 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO_WB;
2830 ret = 0;
juyuchen5351ea62018-05-16 10:54:37 +08002831 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB &&
2832 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE,
2833 SND_DEVICE_OUT_BT_SCO_WB)) {
2834 *num_devices = 2;
2835 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2836 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO_WB;
2837 ret = 0;
David Linee3fe402017-03-13 10:00:42 -07002838 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET &&
2839 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_USB_HEADSET)) {
2840 *num_devices = 2;
2841 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2842 new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
2843 ret = 0;
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07002844 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET &&
2845 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_USB_HEADSET)) {
2846 *num_devices = 2;
2847 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2848 new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
2849 ret = 0;
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002850 } else if (SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP == snd_device &&
2851 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2852 SND_DEVICE_OUT_BT_A2DP)) {
2853 *num_devices = 2;
2854 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2855 new_snd_devices[1] = SND_DEVICE_OUT_BT_A2DP;
2856 ret = 0;
Aniket Kumar Lata9723a962018-05-16 17:41:55 -07002857 } else if (SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP == snd_device &&
2858 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE,
2859 SND_DEVICE_OUT_BT_A2DP)) {
2860 *num_devices = 2;
2861 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2862 new_snd_devices[1] = SND_DEVICE_OUT_BT_A2DP;
2863 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002864 }
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002865
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002866 return ret;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002867}
2868
Eric Laurentb23d5282013-05-14 15:27:20 -07002869snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
2870{
2871 struct platform_data *my_data = (struct platform_data *)platform;
2872 struct audio_device *adev = my_data->adev;
2873 audio_mode_t mode = adev->mode;
2874 snd_device_t snd_device = SND_DEVICE_NONE;
2875
2876 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
2877 if (devices == AUDIO_DEVICE_NONE ||
2878 devices & AUDIO_DEVICE_BIT_IN) {
2879 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
2880 goto exit;
2881 }
2882
Eric Laurent1b491552015-09-15 17:52:41 -07002883 if (popcount(devices) == 2) {
2884 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2885 AUDIO_DEVICE_OUT_SPEAKER) ||
2886 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2887 AUDIO_DEVICE_OUT_SPEAKER)) {
2888 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
2889 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2890 AUDIO_DEVICE_OUT_SPEAKER)) {
2891 snd_device = SND_DEVICE_OUT_SPEAKER_AND_LINE;
2892 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2893 AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
2894 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2895 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2896 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES;
2897 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2898 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2899 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE;
2900 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
2901 AUDIO_DEVICE_OUT_SPEAKER)) {
2902 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002903 } else if ((devices & AUDIO_DEVICE_OUT_ALL_SCO) &&
2904 ((devices & ~AUDIO_DEVICE_OUT_ALL_SCO) == AUDIO_DEVICE_OUT_SPEAKER)) {
2905 snd_device = adev->bt_wb_speech_enabled ?
2906 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB :
2907 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO;
juyuchen5351ea62018-05-16 10:54:37 +08002908 } else if ((devices & AUDIO_DEVICE_OUT_ALL_SCO) &&
2909 ((devices & ~AUDIO_DEVICE_OUT_ALL_SCO) == AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2910 snd_device = adev->bt_wb_speech_enabled ?
2911 SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB :
2912 SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO;
Eric Laurent99dab492017-06-17 15:19:08 -07002913 } else if ((devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
2914 AUDIO_DEVICE_OUT_SPEAKER)) ||
2915 (devices == (AUDIO_DEVICE_OUT_USB_HEADSET |
2916 AUDIO_DEVICE_OUT_SPEAKER))) {
David Linee3fe402017-03-13 10:00:42 -07002917 snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET;
Eric Laurentd0f7c262017-07-05 09:09:12 -07002918 } else if ((devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
2919 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) ||
2920 (devices == (AUDIO_DEVICE_OUT_USB_HEADSET |
2921 AUDIO_DEVICE_OUT_SPEAKER_SAFE))) {
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07002922 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET;
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002923 } else if ((devices & AUDIO_DEVICE_OUT_SPEAKER) &&
2924 (devices & AUDIO_DEVICE_OUT_ALL_A2DP)) {
2925 snd_device = SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP;
Aniket Kumar Lata9723a962018-05-16 17:41:55 -07002926 } else if ((devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) &&
2927 (devices & AUDIO_DEVICE_OUT_ALL_A2DP)) {
2928 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP;
Eric Laurent1b491552015-09-15 17:52:41 -07002929 } else {
2930 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
2931 goto exit;
2932 }
2933 if (snd_device != SND_DEVICE_NONE) {
2934 goto exit;
2935 }
2936 }
2937
2938 if (popcount(devices) != 1) {
2939 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
2940 goto exit;
2941 }
2942
Madhuri Athota3f6051b2016-10-13 23:25:38 +05302943 if (voice_is_in_call(adev) || adev->enable_voicerx || audio_extn_hfp_is_active(adev)) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002944 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002945 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2946 devices & AUDIO_DEVICE_OUT_LINE) {
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002947 if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002948 (adev->voice.tty_mode == TTY_MODE_FULL))
Eric Laurentb23d5282013-05-14 15:27:20 -07002949 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002950 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002951 (adev->voice.tty_mode == TTY_MODE_VCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002952 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002953 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002954 (adev->voice.tty_mode == TTY_MODE_HCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002955 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002956 else {
2957 if (devices & AUDIO_DEVICE_OUT_LINE)
2958 snd_device = SND_DEVICE_OUT_VOICE_LINE;
yixuanjiang9536e672018-09-06 18:43:36 +08002959 else if (devices & AUDIO_DEVICE_OUT_WIRED_HEADSET)
2960 snd_device = SND_DEVICE_OUT_VOICE_HEADSET;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002961 else
2962 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
2963 }
Eric Laurent99dab492017-06-17 15:19:08 -07002964 } else if (audio_is_usb_out_device(devices)) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002965 if (voice_is_in_call(adev)) {
2966 switch (adev->voice.tty_mode) {
2967 case TTY_MODE_FULL:
2968 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_USB;
2969 break;
2970 case TTY_MODE_VCO:
2971 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_USB;
2972 break;
2973 case TTY_MODE_HCO:
2974 // since Hearing will be on handset\speaker, use existing device
2975 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
2976 break;
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002977 case TTY_MODE_OFF:
2978 break;
vivek mehtaa6b79742017-03-09 15:40:43 -08002979 default:
2980 ALOGE("%s: Invalid TTY mode (%#x)",
2981 __func__, adev->voice.tty_mode);
2982 }
2983 }
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002984 if (snd_device == SND_DEVICE_NONE) {
2985 snd_device = audio_extn_usb_is_capture_supported() ?
2986 SND_DEVICE_OUT_VOICE_USB_HEADSET :
2987 SND_DEVICE_OUT_VOICE_USB_HEADPHONES;
2988 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002989 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002990 if (adev->bt_wb_speech_enabled) {
2991 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2992 } else {
2993 snd_device = SND_DEVICE_OUT_BT_SCO;
2994 }
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002995 } else if (devices & AUDIO_DEVICE_OUT_ALL_A2DP) {
2996 snd_device = SND_DEVICE_OUT_BT_A2DP;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002997 } else if (devices & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002998 if (!adev->enable_hfp) {
2999 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
3000 } else {
3001 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_HFP;
3002 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003003 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05003004 if(adev->voice.hac)
3005 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
3006 else if (is_operator_tmus())
Eric Laurentb23d5282013-05-14 15:27:20 -07003007 snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS;
3008 else
Eric Laurentb4d368e2014-06-25 10:21:54 -05003009 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
juyuchend194b432018-11-16 14:15:16 +08003010 } else if (devices & AUDIO_DEVICE_OUT_TELEPHONY_TX) {
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07003011 snd_device = SND_DEVICE_OUT_VOICE_TX;
juyuchend194b432018-11-16 14:15:16 +08003012 } else if (devices & AUDIO_DEVICE_OUT_HEARING_AID) {
3013 snd_device = SND_DEVICE_OUT_VOICE_HEARING_AID;
3014 }
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07003015
Eric Laurentb23d5282013-05-14 15:27:20 -07003016 if (snd_device != SND_DEVICE_NONE) {
3017 goto exit;
3018 }
3019 }
3020
Eric Laurentb23d5282013-05-14 15:27:20 -07003021 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
3022 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
3023 snd_device = SND_DEVICE_OUT_HEADPHONES;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05003024 } else if (devices & AUDIO_DEVICE_OUT_LINE) {
3025 snd_device = SND_DEVICE_OUT_LINE;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07003026 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) {
3027 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE;
Eric Laurentb23d5282013-05-14 15:27:20 -07003028 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
andysu5b30b062018-04-20 16:34:06 +08003029 /*
3030 * Perform device switch only if acdb tuning is different between SPEAKER & SPEAKER_REVERSE,
3031 * Or there will be a small pause while performing device switch.
3032 */
3033 if (my_data->speaker_lr_swap &&
3034 (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
3035 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]))
Eric Laurentb23d5282013-05-14 15:27:20 -07003036 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
3037 else
3038 snd_device = SND_DEVICE_OUT_SPEAKER;
3039 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003040 if (adev->bt_wb_speech_enabled) {
3041 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
3042 } else {
3043 snd_device = SND_DEVICE_OUT_BT_SCO;
3044 }
Aniket Kumar Lata26483012018-01-31 20:21:42 -08003045 } else if (devices & AUDIO_DEVICE_OUT_ALL_A2DP) {
3046 snd_device = SND_DEVICE_OUT_BT_A2DP;
Eric Laurentb23d5282013-05-14 15:27:20 -07003047 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
3048 snd_device = SND_DEVICE_OUT_HDMI ;
Eric Laurent99dab492017-06-17 15:19:08 -07003049 } else if (audio_is_usb_out_device(devices)) {
jasmine cha270b7762018-03-30 15:41:33 +08003050 if (audio_extn_ma_supported_usb())
3051 snd_device = SND_DEVICE_OUT_USB_HEADSET_SPEC;
3052 else if (audio_extn_usb_is_capture_supported())
David Linee3fe402017-03-13 10:00:42 -07003053 snd_device = SND_DEVICE_OUT_USB_HEADSET;
3054 else
3055 snd_device = SND_DEVICE_OUT_USB_HEADPHONES;
3056 }else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05003057 /*HAC support for voice-ish audio (eg visual voicemail)*/
3058 if(adev->voice.hac)
3059 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
3060 else
3061 snd_device = SND_DEVICE_OUT_HANDSET;
Eric Laurentb23d5282013-05-14 15:27:20 -07003062 } else {
3063 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
3064 }
3065exit:
3066 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
3067 return snd_device;
3068}
3069
Vignesh Kulothungan64698822018-01-23 11:25:18 -08003070#ifdef DYNAMIC_ECNS_ENABLED
3071static snd_device_t get_snd_device_for_voice_comm(struct platform_data *my_data,
3072 struct stream_in *in __unused,
3073 audio_devices_t out_device,
3074 audio_devices_t in_device)
3075{
3076 struct audio_device *adev = my_data->adev;
3077 snd_device_t snd_device = SND_DEVICE_NONE;
3078
3079 if (my_data->fluence_type != FLUENCE_DISABLE) {
3080 switch(AUDIO_DEVICE_BIT_IN | in_device) {
3081 case AUDIO_DEVICE_IN_BACK_MIC:
3082 if (my_data->fluence_in_spkr_mode) {
3083 if ((my_data->fluence_type & FLUENCE_PRO_ENABLE) &&
3084 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
3085 snd_device = SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS;
3086 } else if (((my_data->fluence_type & FLUENCE_PRO_ENABLE) ||
3087 (my_data->fluence_type & FLUENCE_ENABLE)) &&
3088 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
3089 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
3090 }
3091 adev->acdb_settings |= DMIC_FLAG;
3092 } else
3093 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
3094 break;
3095 case AUDIO_DEVICE_IN_BUILTIN_MIC:
3096 if (((my_data->fluence_type & FLUENCE_PRO_ENABLE) ||
3097 (my_data->fluence_type & FLUENCE_ENABLE)) &&
3098 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
3099 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
3100 adev->acdb_settings |= DMIC_FLAG;
3101 } else
3102 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
3103 break;
3104 default:
3105 ALOGE("%s: Unsupported in_device %#x", __func__, in_device);
3106 break;
3107 }
3108 platform_set_echo_reference(adev, true, out_device);
3109 }
3110
3111 return snd_device;
3112}
3113#else
3114static snd_device_t get_snd_device_for_voice_comm(struct platform_data *my_data,
3115 struct stream_in *in,
3116 audio_devices_t out_device,
3117 audio_devices_t in_device)
3118{
3119 struct audio_device *adev = my_data->adev;
3120 snd_device_t snd_device = SND_DEVICE_NONE;
3121
3122 if (in->enable_aec &&
3123 in->enable_ns) {
3124 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
3125 if (my_data->fluence_in_spkr_mode &&
3126 my_data->fluence_in_voice_comm &&
3127 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
3128 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
3129 } else {
3130 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
3131 }
3132 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
3133 if (my_data->fluence_in_voice_comm &&
3134 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
3135 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
3136 } else {
3137 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
3138 }
3139 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3140 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
3141 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
3142 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
3143 }
3144 platform_set_echo_reference(adev, true, out_device);
3145 } else if (in->enable_aec) {
3146 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
3147 if (my_data->fluence_in_spkr_mode &&
3148 my_data->fluence_in_voice_comm &&
3149 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
3150 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
3151 } else {
3152 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
3153 }
3154 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
3155 if (my_data->fluence_in_voice_comm &&
3156 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
3157 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
3158 } else {
3159 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
3160 }
3161 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3162 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
3163 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
3164 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
3165 }
3166 platform_set_echo_reference(adev, true, out_device);
3167 } else if (in->enable_ns) {
3168 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
3169 if (my_data->fluence_in_spkr_mode &&
3170 my_data->fluence_in_voice_comm &&
3171 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
3172 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
3173 } else {
3174 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
3175 }
3176 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
3177 if (my_data->fluence_in_voice_comm &&
3178 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
3179 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
3180 } else {
3181 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
3182 }
3183 }
3184 }
3185
3186 return snd_device;
3187}
3188#endif //DYNAMIC_ECNS_ENABLED
3189
Eric Laurentd1b7a9b2018-11-15 12:24:31 -08003190snd_device_t platform_get_input_snd_device(void *platform,
3191 struct stream_in *in,
3192 audio_devices_t out_device)
Eric Laurentb23d5282013-05-14 15:27:20 -07003193{
3194 struct platform_data *my_data = (struct platform_data *)platform;
3195 struct audio_device *adev = my_data->adev;
Eric Laurentd1b7a9b2018-11-15 12:24:31 -08003196 audio_mode_t mode = adev->mode;
Eric Laurentb23d5282013-05-14 15:27:20 -07003197 snd_device_t snd_device = SND_DEVICE_NONE;
Eric Laurentd1b7a9b2018-11-15 12:24:31 -08003198
3199 if (in == NULL) {
3200 in = adev_get_active_input(adev);
3201 }
3202
3203 audio_source_t source = (in == NULL) ? AUDIO_SOURCE_DEFAULT : in->source;
3204 audio_devices_t in_device =
3205 ((in == NULL) ? AUDIO_DEVICE_NONE : in->device) & ~AUDIO_DEVICE_BIT_IN;
3206 audio_channel_mask_t channel_mask = (in == NULL) ? AUDIO_CHANNEL_IN_MONO : in->channel_mask;
3207 int channel_count = audio_channel_count_from_in_mask(channel_mask);
Eric Laurentb23d5282013-05-14 15:27:20 -07003208
Prashant Malanic92c5962015-08-11 15:10:18 -07003209 ALOGV("%s: enter: out_device(%#x) in_device(%#x) channel_count (%d) channel_mask (0x%x)",
3210 __func__, out_device, in_device, channel_count, channel_mask);
Eric Laurentd1b7a9b2018-11-15 12:24:31 -08003211
Devin Kimd789e432016-10-26 15:07:27 -07003212 if ((out_device != AUDIO_DEVICE_NONE) && (voice_is_in_call(adev) ||
3213 audio_extn_hfp_is_active(adev))) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07003214 if (adev->voice.tty_mode != TTY_MODE_OFF) {
Eric Laurentb23d5282013-05-14 15:27:20 -07003215 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05003216 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
3217 out_device & AUDIO_DEVICE_OUT_LINE) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07003218 switch (adev->voice.tty_mode) {
vivek mehtaa6b79742017-03-09 15:40:43 -08003219 case TTY_MODE_FULL:
3220 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
3221 break;
3222 case TTY_MODE_VCO:
3223 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
3224 break;
3225 case TTY_MODE_HCO:
3226 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
3227 break;
3228 default:
3229 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
3230 }
3231 goto exit;
Eric Laurent99dab492017-06-17 15:19:08 -07003232 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
vivek mehtaa6b79742017-03-09 15:40:43 -08003233 switch (adev->voice.tty_mode) {
3234 case TTY_MODE_FULL:
3235 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC;
3236 break;
3237 case TTY_MODE_VCO:
3238 // since voice will be captured from handset mic, use existing device
3239 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
3240 break;
3241 case TTY_MODE_HCO:
3242 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC;
3243 break;
3244 default:
3245 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
Eric Laurentb23d5282013-05-14 15:27:20 -07003246 }
3247 goto exit;
3248 }
3249 }
Eric Laurentb991fb02014-08-29 15:23:17 -05003250 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07003251 if (my_data->fluence_in_voice_call == false) {
3252 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3253 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003254 if (is_operator_tmus())
3255 snd_device = SND_DEVICE_IN_VOICE_DMIC_TMUS;
Eric Laurentb23d5282013-05-14 15:27:20 -07003256 else
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003257 snd_device = SND_DEVICE_IN_VOICE_DMIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07003258 }
3259 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
3260 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
3261 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003262 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003263 if (adev->bluetooth_nrec)
3264 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
3265 else
3266 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003267 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003268 if (adev->bluetooth_nrec)
3269 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
3270 else
3271 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003272 }
Eric Laurentb991fb02014-08-29 15:23:17 -05003273 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Prashant Malanic92c5962015-08-11 15:10:18 -07003274 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
3275 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
3276 out_device & AUDIO_DEVICE_OUT_LINE) {
3277 if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
3278 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
3279 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
3280 } else {
3281 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
3282 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003283 }
vivek mehtafe121d52015-08-10 23:39:23 -07003284
3285 //select default
3286 if (snd_device == SND_DEVICE_NONE) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07003287 if (!adev->enable_hfp) {
3288 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
3289 } else {
3290 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP;
3291 platform_set_echo_reference(adev, true, out_device);
3292 }
vivek mehtafe121d52015-08-10 23:39:23 -07003293 }
Prashant Malanic92c5962015-08-11 15:10:18 -07003294 } else if (out_device & AUDIO_DEVICE_OUT_TELEPHONY_TX) {
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07003295 snd_device = SND_DEVICE_IN_VOICE_RX;
Eric Laurent99dab492017-06-17 15:19:08 -07003296 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
David Lin40b07892017-08-07 15:02:48 -07003297 if (audio_extn_usb_is_capture_supported()) {
3298 snd_device = SND_DEVICE_IN_VOICE_USB_HEADSET_MIC;
3299 } else if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
3300 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
3301 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
3302 } else {
3303 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
3304 }
3305 }
juyuchend194b432018-11-16 14:15:16 +08003306 } else if (out_device & AUDIO_DEVICE_OUT_HEARING_AID) {
3307 snd_device = SND_DEVICE_IN_VOICE_HEARING_AID;
Prashant Malanic92c5962015-08-11 15:10:18 -07003308 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003309 } else if (source == AUDIO_SOURCE_CAMCORDER) {
3310 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
3311 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Eric Laurent5f4ca952018-10-19 17:33:43 -07003312 switch (adev->camera_orientation) {
3313 case CAMERA_BACK_LANDSCAPE:
3314 snd_device = SND_DEVICE_IN_CAMCORDER_LANDSCAPE;
3315 break;
3316 case CAMERA_BACK_INVERT_LANDSCAPE:
3317 snd_device = SND_DEVICE_IN_CAMCORDER_INVERT_LANDSCAPE;
3318 break;
3319 case CAMERA_BACK_PORTRAIT:
3320 snd_device = SND_DEVICE_IN_CAMCORDER_PORTRAIT;
3321 break;
3322 case CAMERA_FRONT_LANDSCAPE:
3323 snd_device = SND_DEVICE_IN_CAMCORDER_SELFIE_LANDSCAPE;
3324 break;
3325 case CAMERA_FRONT_INVERT_LANDSCAPE:
3326 snd_device = SND_DEVICE_IN_CAMCORDER_SELFIE_INVERT_LANDSCAPE;
3327 break;
3328 case CAMERA_FRONT_PORTRAIT:
3329 snd_device = SND_DEVICE_IN_CAMCORDER_SELFIE_PORTRAIT;
3330 break;
3331 default:
3332 ALOGW("%s: invalid camera orientation %08x", __func__, adev->camera_orientation);
3333 snd_device = SND_DEVICE_IN_CAMCORDER_LANDSCAPE;
3334 break;
3335 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003336 }
3337 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
3338 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003339 if (my_data->fluence_in_voice_rec && channel_count == 1) {
3340 if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
3341 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
Eric Laurentd1b7a9b2018-11-15 12:24:31 -08003342 if (in->enable_aec)
vivek mehta733c1df2016-04-04 15:09:24 -07003343 snd_device = SND_DEVICE_IN_HANDSET_QMIC_AEC;
3344 else
3345 snd_device = SND_DEVICE_IN_HANDSET_QMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003346 } else if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
3347 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
Eric Laurentd1b7a9b2018-11-15 12:24:31 -08003348 if (in->enable_aec)
vivek mehta733c1df2016-04-04 15:09:24 -07003349 snd_device = SND_DEVICE_IN_HANDSET_TMIC_AEC;
3350 else
3351 snd_device = SND_DEVICE_IN_HANDSET_TMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003352 } else if (((my_data->fluence_type == FLUENCE_PRO_ENABLE) ||
3353 (my_data->fluence_type == FLUENCE_ENABLE)) &&
3354 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Eric Laurentd1b7a9b2018-11-15 12:24:31 -08003355 if (in->enable_aec)
vivek mehta733c1df2016-04-04 15:09:24 -07003356 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
3357 else
3358 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
Prashant Malanic92c5962015-08-11 15:10:18 -07003359 }
3360 platform_set_echo_reference(adev, true, out_device);
3361 } else if ((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) &&
3362 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
3363 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003364 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003365 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
3366 snd_device = SND_DEVICE_IN_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003367 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003368 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
3369 snd_device = SND_DEVICE_IN_QUAD_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07003370 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003371 if (snd_device == SND_DEVICE_NONE) {
Eric Laurentd1b7a9b2018-11-15 12:24:31 -08003372 if (in->enable_aec) {
3373 if (in->enable_ns) {
vivek mehtaf3440682016-05-11 14:24:37 -07003374 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS;
3375 } else {
3376 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC;
3377 }
vivek mehta733c1df2016-04-04 15:09:24 -07003378 platform_set_echo_reference(adev, true, out_device);
Eric Laurentd1b7a9b2018-11-15 12:24:31 -08003379 } else if (in->enable_ns) {
vivek mehtaf3440682016-05-11 14:24:37 -07003380 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
3381 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003382 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
vivek mehtaf3440682016-05-11 14:24:37 -07003383 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003384 }
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -07003385 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3386 snd_device = SND_DEVICE_IN_VOICE_REC_HEADSET_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07003387 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07003388 snd_device = SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07003389 }
rago90fb9612015-12-02 11:37:53 -08003390 } else if (source == AUDIO_SOURCE_UNPROCESSED) {
3391 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
vivek mehta4ed66e62016-04-15 23:33:34 -07003392 if (((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) ||
3393 (channel_mask == AUDIO_CHANNEL_IN_STEREO)) &&
3394 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
3395 snd_device = SND_DEVICE_IN_UNPROCESSED_STEREO_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003396 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07003397 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
3398 snd_device = SND_DEVICE_IN_UNPROCESSED_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003399 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07003400 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
3401 snd_device = SND_DEVICE_IN_UNPROCESSED_QUAD_MIC;
3402 } else {
3403 snd_device = SND_DEVICE_IN_UNPROCESSED_MIC;
3404 }
rago90fb9612015-12-02 11:37:53 -08003405 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3406 snd_device = SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07003407 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07003408 snd_device = SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC;
rago90fb9612015-12-02 11:37:53 -08003409 }
Eric Laurent50a38ed2015-10-14 18:48:06 -07003410 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION ||
rago90fb9612015-12-02 11:37:53 -08003411 mode == AUDIO_MODE_IN_COMMUNICATION) {
David Lin40b07892017-08-07 15:02:48 -07003412 if (out_device & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
3413 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
3414 (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE | AUDIO_DEVICE_OUT_USB_HEADSET) &&
3415 !audio_extn_usb_is_capture_supported())) {
Eric Laurentb23d5282013-05-14 15:27:20 -07003416 in_device = AUDIO_DEVICE_IN_BACK_MIC;
David Lin40b07892017-08-07 15:02:48 -07003417 }
Vignesh Kulothungan64698822018-01-23 11:25:18 -08003418
Eric Laurentd1b7a9b2018-11-15 12:24:31 -08003419 if (in) {
Vignesh Kulothungan64698822018-01-23 11:25:18 -08003420 snd_device = get_snd_device_for_voice_comm(my_data, in, out_device, in_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07003421 }
3422 } else if (source == AUDIO_SOURCE_DEFAULT) {
3423 goto exit;
3424 }
3425
3426
3427 if (snd_device != SND_DEVICE_NONE) {
3428 goto exit;
3429 }
3430
3431 if (in_device != AUDIO_DEVICE_NONE &&
3432 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
3433 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
3434 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003435 if ((my_data->source_mic_type & SOURCE_QUAD_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003436 channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003437 snd_device = SND_DEVICE_IN_QUAD_MIC;
3438 } else if ((my_data->source_mic_type & SOURCE_THREE_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003439 channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003440 snd_device = SND_DEVICE_IN_THREE_MIC;
3441 } else if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
3442 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003443 snd_device = SND_DEVICE_IN_HANDSET_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07003444 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
3445 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003446 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003447 } else {
3448 ALOGE("%s: something wrong (1): source type (%d) channel_count (%d) .."
3449 " channel mask (0x%x) no combination found .. setting to mono", __func__,
3450 my_data->source_mic_type, channel_count, channel_mask);
3451 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3452 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003453 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003454 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
3455 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003456 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07003457 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
3458 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003459 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003460 } else {
3461 ALOGE("%s: something wrong (2): source type (%d) channel_count (%d) .."
3462 " no combination found .. setting to mono", __func__,
3463 my_data->source_mic_type, channel_count);
3464 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
3465 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003466 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3467 snd_device = SND_DEVICE_IN_HEADSET_MIC;
3468 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003469 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003470 if (adev->bluetooth_nrec)
3471 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
3472 else
3473 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003474 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003475 if (adev->bluetooth_nrec)
3476 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
3477 else
3478 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003479 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003480 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
3481 snd_device = SND_DEVICE_IN_HDMI_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07003482 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
David Linee3fe402017-03-13 10:00:42 -07003483 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07003484 } else {
3485 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
3486 ALOGW("%s: Using default handset-mic", __func__);
3487 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3488 }
3489 } else {
3490 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
3491 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3492 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
3493 snd_device = SND_DEVICE_IN_HEADSET_MIC;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003494 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07003495 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003496 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05003497 out_device & AUDIO_DEVICE_OUT_LINE) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003498 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
3499 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003500 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07003501 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
3502 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003503 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003504 } else {
3505 ALOGE("%s: something wrong (3): source type (%d) channel_count (%d) .."
3506 " no combination found .. setting to mono", __func__,
3507 my_data->source_mic_type, channel_count);
3508 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
3509 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003510 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003511 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003512 if (adev->bluetooth_nrec)
3513 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
3514 else
3515 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003516 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003517 if (adev->bluetooth_nrec)
3518 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
3519 else
3520 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003521 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003522 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
3523 snd_device = SND_DEVICE_IN_HDMI_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07003524 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
David Linee3fe402017-03-13 10:00:42 -07003525 if (audio_extn_usb_is_capture_supported())
3526 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
3527 else
3528 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07003529 } else {
3530 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
3531 ALOGW("%s: Using default handset-mic", __func__);
3532 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3533 }
3534 }
3535exit:
3536 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
3537 return snd_device;
3538}
3539
3540int platform_set_hdmi_channels(void *platform, int channel_count)
3541{
3542 struct platform_data *my_data = (struct platform_data *)platform;
3543 struct audio_device *adev = my_data->adev;
3544 struct mixer_ctl *ctl;
3545 const char *channel_cnt_str = NULL;
3546 const char *mixer_ctl_name = "HDMI_RX Channels";
3547 switch (channel_count) {
3548 case 8:
3549 channel_cnt_str = "Eight"; break;
3550 case 7:
3551 channel_cnt_str = "Seven"; break;
3552 case 6:
3553 channel_cnt_str = "Six"; break;
3554 case 5:
3555 channel_cnt_str = "Five"; break;
3556 case 4:
3557 channel_cnt_str = "Four"; break;
3558 case 3:
3559 channel_cnt_str = "Three"; break;
3560 default:
3561 channel_cnt_str = "Two"; break;
3562 }
3563 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3564 if (!ctl) {
3565 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3566 __func__, mixer_ctl_name);
3567 return -EINVAL;
3568 }
3569 ALOGV("HDMI channel count: %s", channel_cnt_str);
3570 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
3571 return 0;
3572}
3573
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003574int platform_edid_get_max_channels(void *platform)
Eric Laurentb23d5282013-05-14 15:27:20 -07003575{
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003576 struct platform_data *my_data = (struct platform_data *)platform;
3577 struct audio_device *adev = my_data->adev;
Eric Laurentb23d5282013-05-14 15:27:20 -07003578 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
3579 char *sad = block;
3580 int num_audio_blocks;
3581 int channel_count;
3582 int max_channels = 0;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003583 int i, ret, count;
Eric Laurentb23d5282013-05-14 15:27:20 -07003584
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003585 struct mixer_ctl *ctl;
3586
3587 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
3588 if (!ctl) {
3589 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3590 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
Eric Laurentb23d5282013-05-14 15:27:20 -07003591 return 0;
3592 }
3593
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003594 mixer_ctl_update(ctl);
3595
3596 count = mixer_ctl_get_num_values(ctl);
Eric Laurentb23d5282013-05-14 15:27:20 -07003597
3598 /* Read SAD blocks, clamping the maximum size for safety */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003599 if (count > (int)sizeof(block))
3600 count = (int)sizeof(block);
Eric Laurentb23d5282013-05-14 15:27:20 -07003601
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003602 ret = mixer_ctl_get_array(ctl, block, count);
3603 if (ret != 0) {
3604 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
3605 return 0;
3606 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003607
3608 /* Calculate the number of SAD blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003609 num_audio_blocks = count / SAD_BLOCK_SIZE;
Eric Laurentb23d5282013-05-14 15:27:20 -07003610
3611 for (i = 0; i < num_audio_blocks; i++) {
3612 /* Only consider LPCM blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003613 if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
3614 sad += 3;
Eric Laurentb23d5282013-05-14 15:27:20 -07003615 continue;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003616 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003617
3618 channel_count = (sad[0] & 0x7) + 1;
3619 if (channel_count > max_channels)
3620 max_channels = channel_count;
3621
3622 /* Advance to next block */
3623 sad += 3;
3624 }
3625
3626 return max_channels;
3627}
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003628
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07003629int platform_set_incall_recording_session_id(void *platform,
3630 uint32_t session_id, int rec_mode)
3631{
3632 int ret = 0;
3633 struct platform_data *my_data = (struct platform_data *)platform;
3634 struct audio_device *adev = my_data->adev;
3635 struct mixer_ctl *ctl;
3636 const char *mixer_ctl_name = "Voc VSID";
3637 int num_ctl_values;
3638 int i;
3639
3640 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3641 if (!ctl) {
3642 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3643 __func__, mixer_ctl_name);
3644 ret = -EINVAL;
3645 } else {
3646 num_ctl_values = mixer_ctl_get_num_values(ctl);
3647 for (i = 0; i < num_ctl_values; i++) {
3648 if (mixer_ctl_set_value(ctl, i, session_id)) {
3649 ALOGV("Error: invalid session_id: %x", session_id);
3650 ret = -EINVAL;
3651 break;
3652 }
3653 }
3654 }
3655
3656 if (my_data->csd != NULL) {
3657 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
3658 if (ret < 0) {
3659 ALOGE("%s: csd_client_start_record failed, error %d",
3660 __func__, ret);
3661 }
3662 }
3663
3664 return ret;
3665}
3666
Arun Mirpuriba2749a2018-04-17 14:32:24 -07003667int platform_set_incall_recording_session_channels(void *platform,
3668 uint32_t channel_count)
3669{
3670 int ret = 0;
3671 struct platform_data *my_data = (struct platform_data *)platform;
3672 struct audio_device *adev = my_data->adev;
3673 const char *mixer_ctl_name = "Voc Rec Config";
3674 int num_ctl_values;
3675 int i;
3676 struct mixer_ctl *ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3677
3678 if (!ctl) {
3679 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3680 __func__, mixer_ctl_name);
3681 ret = -EINVAL;
3682 } else {
3683 num_ctl_values = mixer_ctl_get_num_values(ctl);
3684 for (i = 0; i < num_ctl_values; i++) {
3685 if (mixer_ctl_set_value(ctl, i, channel_count)) {
3686 ALOGE("Error: invalid channel count: %x", channel_count);
3687 ret = -EINVAL;
3688 break;
3689 }
3690 }
3691 }
3692
3693 return ret;
3694}
3695
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07003696int platform_stop_incall_recording_usecase(void *platform)
3697{
3698 int ret = 0;
3699 struct platform_data *my_data = (struct platform_data *)platform;
3700
3701 if (my_data->csd != NULL) {
3702 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
3703 if (ret < 0) {
3704 ALOGE("%s: csd_client_stop_record failed, error %d",
3705 __func__, ret);
3706 }
3707 }
3708
3709 return ret;
3710}
3711
3712int platform_start_incall_music_usecase(void *platform)
3713{
3714 int ret = 0;
3715 struct platform_data *my_data = (struct platform_data *)platform;
3716
3717 if (my_data->csd != NULL) {
3718 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
3719 if (ret < 0) {
3720 ALOGE("%s: csd_client_start_playback failed, error %d",
3721 __func__, ret);
3722 }
3723 }
3724
3725 return ret;
3726}
3727
3728int platform_stop_incall_music_usecase(void *platform)
3729{
3730 int ret = 0;
3731 struct platform_data *my_data = (struct platform_data *)platform;
3732
3733 if (my_data->csd != NULL) {
3734 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
3735 if (ret < 0) {
3736 ALOGE("%s: csd_client_stop_playback failed, error %d",
3737 __func__, ret);
3738 }
3739 }
3740
3741 return ret;
3742}
3743
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003744int platform_set_parameters(void *platform, struct str_parms *parms)
3745{
3746 struct platform_data *my_data = (struct platform_data *)platform;
jasmine chac89321b2018-04-10 21:37:01 +08003747 char *value = NULL;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003748 char *kv_pairs = str_parms_to_str(parms);
jasmine chac89321b2018-04-10 21:37:01 +08003749 int len;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003750 int ret = 0, err;
3751
3752 if (kv_pairs == NULL) {
3753 ret = -EINVAL;
Jasmine Chaa314e192018-05-09 17:46:28 +08003754 ALOGE("%s: key-value pair is NULL", __func__);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003755 goto done;
3756 }
3757
3758 ALOGV("%s: enter: %s", __func__, kv_pairs);
3759
jasmine chac89321b2018-04-10 21:37:01 +08003760 len = strlen(kv_pairs);
Jasmine Chaa314e192018-05-09 17:46:28 +08003761 value = (char*)calloc(len + 1, sizeof(char));
jasmine chac89321b2018-04-10 21:37:01 +08003762 if (value == NULL) {
3763 ret = -ENOMEM;
Jasmine Chaa314e192018-05-09 17:46:28 +08003764 ALOGE("[%s] failed to allocate memory", __func__);
jasmine chac89321b2018-04-10 21:37:01 +08003765 goto done;
3766 }
3767
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003768 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME,
jasmine chac89321b2018-04-10 21:37:01 +08003769 value, len);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003770 if (err >= 0) {
3771 str_parms_del(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME);
3772 my_data->snd_card_name = strdup(value);
3773 ALOGV("%s: sound card name %s", __func__, my_data->snd_card_name);
3774 }
3775
keunhui.park2f7306a2015-07-16 16:48:06 +09003776 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO,
jasmine chac89321b2018-04-10 21:37:01 +08003777 value, len);
keunhui.park2f7306a2015-07-16 16:48:06 +09003778 if (err >= 0) {
3779 struct operator_info *info;
3780 char *str = value;
3781 char *name;
3782
3783 str_parms_del(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO);
3784 info = (struct operator_info *)calloc(1, sizeof(struct operator_info));
3785 name = strtok(str, ";");
3786 info->name = strdup(name);
3787 info->mccmnc = strdup(str + strlen(name) + 1);
3788
3789 list_add_tail(&operator_info_list, &info->list);
Joe Onorato188b6222016-03-01 11:02:27 -08003790 ALOGV("%s: add operator[%s] mccmnc[%s]", __func__, info->name, info->mccmnc);
keunhui.park2f7306a2015-07-16 16:48:06 +09003791 }
Prashant Malanic92c5962015-08-11 15:10:18 -07003792
Jasmine Chaa314e192018-05-09 17:46:28 +08003793 memset(value, 0, len + 1);
Eric Laurentc6333382015-09-14 12:43:44 -07003794 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT,
jasmine chac89321b2018-04-10 21:37:01 +08003795 value, len);
Prashant Malanic92c5962015-08-11 15:10:18 -07003796 if (err >= 0) {
Eric Laurentc6333382015-09-14 12:43:44 -07003797 str_parms_del(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT);
Prashant Malanic92c5962015-08-11 15:10:18 -07003798 my_data->max_mic_count = atoi(value);
3799 ALOGV("%s: max_mic_count %s/%d", __func__, value, my_data->max_mic_count);
Prashant Malanic92c5962015-08-11 15:10:18 -07003800 }
3801
jasmine chac89321b2018-04-10 21:37:01 +08003802 /* handle audio calibration parameters */
3803 set_audiocal(platform, parms, value, len);
3804
vivek mehta90933872017-06-15 18:04:39 -07003805 // to-do: disable setting sidetone gain, will revist this later
3806 // audio_extn_usb_set_sidetone_gain(parms, value, len);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003807done:
3808 ALOGV("%s: exit with code(%d)", __func__, ret);
3809 if (kv_pairs != NULL)
3810 free(kv_pairs);
jasmine chac89321b2018-04-10 21:37:01 +08003811 if (value != NULL)
3812 free(value);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003813
3814 return ret;
3815}
3816
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003817/* Delay in Us */
3818int64_t platform_render_latency(audio_usecase_t usecase)
3819{
3820 switch (usecase) {
3821 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
3822 return DEEP_BUFFER_PLATFORM_DELAY;
3823 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
Vignesh Kulothungan019d19b2019-01-23 11:09:18 -08003824 case USECASE_AUDIO_PLAYBACK_WITH_HAPTICS:
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003825 return LOW_LATENCY_PLATFORM_DELAY;
Haynes Mathew George03c40102016-01-29 17:57:48 -08003826 case USECASE_AUDIO_PLAYBACK_ULL:
3827 return ULL_PLATFORM_DELAY;
Eric Laurent0e46adf2016-12-16 12:49:24 -08003828 case USECASE_AUDIO_PLAYBACK_MMAP:
3829 return MMAP_PLATFORM_DELAY;
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003830 default:
3831 return 0;
3832 }
3833}
Haynes Mathew George98c95622014-06-20 19:14:25 -07003834
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003835int platform_set_snd_device_backend(snd_device_t device, const char *backend_tag,
3836 const char * hw_interface)
Haynes Mathew George98c95622014-06-20 19:14:25 -07003837{
3838 int ret = 0;
3839
3840 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
3841 ALOGE("%s: Invalid snd_device = %d",
3842 __func__, device);
3843 ret = -EINVAL;
3844 goto done;
3845 }
3846
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003847 ALOGV("%s: backend_tag_table[%s]: old = %s new = %s", __func__,
3848 platform_get_snd_device_name(device),
3849 backend_tag_table[device] != NULL ? backend_tag_table[device]: "null", backend_tag);
3850 if (backend_tag_table[device]) {
3851 free(backend_tag_table[device]);
Haynes Mathew George98c95622014-06-20 19:14:25 -07003852 }
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003853 backend_tag_table[device] = strdup(backend_tag);
3854
3855 if (hw_interface != NULL) {
3856 if (hw_interface_table[device])
3857 free(hw_interface_table[device]);
3858 ALOGV("%s: hw_interface_table[%d] = %s", __func__, device, hw_interface);
3859 hw_interface_table[device] = strdup(hw_interface);
3860 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07003861done:
3862 return ret;
3863}
3864
3865int platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t pcm_id)
3866{
3867 int ret = 0;
3868 if ((usecase <= USECASE_INVALID) || (usecase >= AUDIO_USECASE_MAX)) {
3869 ALOGE("%s: invalid usecase case idx %d", __func__, usecase);
3870 ret = -EINVAL;
3871 goto done;
3872 }
3873
3874 if ((type != 0) && (type != 1)) {
3875 ALOGE("%s: invalid usecase type", __func__);
3876 ret = -EINVAL;
3877 }
vivek mehtaa68fea62017-06-08 19:04:02 -07003878 ALOGV("%s: pcm_device_table[%d %s][%d] = %d", __func__, usecase,
3879 use_case_table[usecase],
3880 type, pcm_id);
Haynes Mathew George98c95622014-06-20 19:14:25 -07003881 pcm_device_table[usecase][type] = pcm_id;
3882done:
3883 return ret;
3884}
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003885
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07003886#define DEFAULT_NOMINAL_SPEAKER_GAIN 20
3887int ramp_speaker_gain(struct audio_device *adev, bool ramp_up, int target_ramp_up_gain) {
3888 // backup_gain: gain to try to set in case of an error during ramp
3889 int start_gain, end_gain, step, backup_gain, i;
3890 bool error = false;
3891 const struct mixer_ctl *ctl;
3892 const char *mixer_ctl_name_gain_left = "Left Speaker Gain";
3893 const char *mixer_ctl_name_gain_right = "Right Speaker Gain";
3894 struct mixer_ctl *ctl_left = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_left);
3895 struct mixer_ctl *ctl_right = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_right);
3896 if (!ctl_left || !ctl_right) {
3897 ALOGE("%s: Could not get ctl for mixer cmd - %s or %s, not applying speaker gain ramp",
3898 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
3899 return -EINVAL;
3900 } else if ((mixer_ctl_get_num_values(ctl_left) != 1)
3901 || (mixer_ctl_get_num_values(ctl_right) != 1)) {
3902 ALOGE("%s: Unexpected num values for mixer cmd - %s or %s, not applying speaker gain ramp",
3903 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
3904 return -EINVAL;
3905 }
3906 if (ramp_up) {
3907 start_gain = 0;
3908 end_gain = target_ramp_up_gain > 0 ? target_ramp_up_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
3909 step = +1;
3910 backup_gain = end_gain;
3911 } else {
3912 // using same gain on left and right
3913 const int left_gain = mixer_ctl_get_value(ctl_left, 0);
3914 start_gain = left_gain > 0 ? left_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
3915 end_gain = 0;
3916 step = -1;
3917 backup_gain = start_gain;
3918 }
3919 for (i = start_gain ; i != (end_gain + step) ; i += step) {
3920 //ALOGV("setting speaker gain to %d", i);
3921 if (mixer_ctl_set_value(ctl_left, 0, i)) {
3922 ALOGE("%s: error setting %s to %d during gain ramp",
3923 __func__, mixer_ctl_name_gain_left, i);
3924 error = true;
3925 break;
3926 }
3927 if (mixer_ctl_set_value(ctl_right, 0, i)) {
3928 ALOGE("%s: error setting %s to %d during gain ramp",
3929 __func__, mixer_ctl_name_gain_right, i);
3930 error = true;
3931 break;
3932 }
3933 usleep(1000);
3934 }
3935 if (error) {
3936 // an error occured during the ramp, let's still try to go back to a safe volume
3937 if (mixer_ctl_set_value(ctl_left, 0, backup_gain)) {
3938 ALOGE("%s: error restoring left gain to %d", __func__, backup_gain);
3939 }
3940 if (mixer_ctl_set_value(ctl_right, 0, backup_gain)) {
3941 ALOGE("%s: error restoring right gain to %d", __func__, backup_gain);
3942 }
3943 }
3944 return start_gain;
3945}
3946
vivek mehtae59cfb22017-06-16 15:57:11 -07003947int platform_set_swap_mixer(struct audio_device *adev, bool swap_channels)
3948{
3949 const char *mixer_ctl_name = "Swap channel";
3950 struct mixer_ctl *ctl;
3951 const char *mixer_path;
3952 struct platform_data *my_data = (struct platform_data *)adev->platform;
3953
3954 // forced to set to swap, but device not rotated ... ignore set
3955 if (swap_channels && !my_data->speaker_lr_swap)
3956 return 0;
3957
3958 ALOGV("%s:", __func__);
3959
3960 if (swap_channels) {
3961 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER_REVERSE);
3962 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
3963 } else {
3964 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER);
3965 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
3966 }
3967
3968 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3969 if (!ctl) {
3970 ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name);
3971 return -EINVAL;
3972 }
3973
3974 if (mixer_ctl_set_value(ctl, 0, swap_channels) < 0) {
3975 ALOGE("%s: Could not set reverse cotrol %d",__func__, swap_channels);
3976 return -EINVAL;
3977 }
3978
3979 ALOGV("platfor_force_swap_channel :: Channel orientation ( %s ) ",
3980 swap_channels?"R --> L":"L --> R");
3981
3982 return 0;
3983}
3984
3985int platform_check_and_set_swap_lr_channels(struct audio_device *adev, bool swap_channels)
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003986{
3987 // only update if there is active pcm playback on speaker
3988 struct audio_usecase *usecase;
3989 struct listnode *node;
3990 struct platform_data *my_data = (struct platform_data *)adev->platform;
3991
vivek mehtae59cfb22017-06-16 15:57:11 -07003992 my_data->speaker_lr_swap = swap_channels;
Jean-Michel Trivif7148702016-09-16 18:23:05 -07003993
vivek mehtae59cfb22017-06-16 15:57:11 -07003994 return platform_set_swap_channels(adev, swap_channels);
3995}
Jean-Michel Trivif7148702016-09-16 18:23:05 -07003996
vivek mehtae59cfb22017-06-16 15:57:11 -07003997int platform_set_swap_channels(struct audio_device *adev, bool swap_channels)
3998{
3999 // only update if there is active pcm playback on speaker
4000 struct audio_usecase *usecase;
4001 struct listnode *node;
4002 struct platform_data *my_data = (struct platform_data *)adev->platform;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07004003
vivek mehtae59cfb22017-06-16 15:57:11 -07004004 // do not swap channels in audio modes with concurrent capture and playback
4005 // as this may break the echo reference
4006 if ((adev->mode == AUDIO_MODE_IN_COMMUNICATION) || (adev->mode == AUDIO_MODE_IN_CALL)) {
4007 ALOGV("%s: will not swap due to audio mode %d", __func__, adev->mode);
4008 return 0;
4009 }
4010
4011 list_for_each(node, &adev->usecase_list) {
4012 usecase = node_to_item(node, struct audio_usecase, list);
4013 if (usecase->type == PCM_PLAYBACK &&
4014 usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) {
4015 /*
4016 * If acdb tuning is different for SPEAKER_REVERSE, it is must
4017 * to perform device switch to disable the current backend to
4018 * enable it with new acdb data.
4019 */
4020 if (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
4021 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]) {
4022 const int initial_skpr_gain = ramp_speaker_gain(adev, false /*ramp_up*/, -1);
4023 select_devices(adev, usecase->id);
4024 if (initial_skpr_gain != -EINVAL)
4025 ramp_speaker_gain(adev, true /*ramp_up*/, initial_skpr_gain);
4026
4027 } else {
4028 platform_set_swap_mixer(adev, swap_channels);
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07004029 }
vivek mehtae59cfb22017-06-16 15:57:11 -07004030 break;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07004031 }
4032 }
vivek mehtae59cfb22017-06-16 15:57:11 -07004033
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07004034 return 0;
4035}
vivek mehtaa8d7c922016-05-25 14:40:44 -07004036
4037static struct amp_db_and_gain_table tbl_mapping[MAX_VOLUME_CAL_STEPS];
4038static int num_gain_tbl_entry = 0;
4039
4040bool platform_add_gain_level_mapping(struct amp_db_and_gain_table *tbl_entry) {
4041
4042 ALOGV("%s: enter .. add %f %f %d", __func__, tbl_entry->amp, tbl_entry->db, tbl_entry->level);
4043 if (num_gain_tbl_entry == -1) {
4044 ALOGE("%s: num entry beyond valid step levels or corrupted..rejecting custom mapping",
4045 __func__);
4046 return false;
4047 }
4048
4049 if (num_gain_tbl_entry >= MAX_VOLUME_CAL_STEPS) {
4050 ALOGE("%s: max entry reached max[%d] current index[%d] .. rejecting", __func__,
4051 MAX_VOLUME_CAL_STEPS, num_gain_tbl_entry);
4052 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
4053 return false;
4054 }
4055
4056 if (num_gain_tbl_entry > 0 && tbl_mapping[num_gain_tbl_entry - 1].amp >= tbl_entry->amp) {
4057 ALOGE("%s: value not in ascending order .. rejecting custom mapping", __func__);
4058 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
4059 return false;
4060 }
4061
4062 tbl_mapping[num_gain_tbl_entry] = *tbl_entry;
4063 ++num_gain_tbl_entry;
4064
4065 return true;
4066}
4067
4068int platform_get_gain_level_mapping(struct amp_db_and_gain_table *mapping_tbl,
4069 int table_size) {
4070 int itt = 0;
4071 ALOGV("platform_get_gain_level_mapping called ");
4072
4073 if (num_gain_tbl_entry <= 0 || num_gain_tbl_entry > MAX_VOLUME_CAL_STEPS) {
4074 ALOGD("%s: empty or currupted gain_mapping_table", __func__);
4075 return 0;
4076 }
4077
4078 for (; itt < num_gain_tbl_entry && itt <= table_size; itt++) {
4079 mapping_tbl[itt] = tbl_mapping[itt];
4080 ALOGV("%s: added amp[%f] db[%f] level[%d]", __func__,
4081 mapping_tbl[itt].amp, mapping_tbl[itt].db, mapping_tbl[itt].level);
4082 }
4083
4084 return num_gain_tbl_entry;
4085}
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07004086
4087int platform_snd_card_update(void *platform, card_status_t status)
4088{
4089 struct platform_data *my_data = (struct platform_data *)platform;
4090 struct audio_device *adev = my_data->adev;
4091
4092 if (status == CARD_STATUS_ONLINE) {
4093 if (my_data->acdb_send_custom_top)
4094 my_data->acdb_send_custom_top();
4095 }
4096 return 0;
4097}
David Linee3fe402017-03-13 10:00:42 -07004098
4099/*
4100 * configures afe with bit width and Sample Rate
4101 */
Haynes Mathew George65f6b432018-02-27 17:44:55 -08004102int platform_set_backend_cfg(const struct audio_device* adev,
4103 snd_device_t snd_device,
4104 const struct audio_backend_cfg *backend_cfg)
David Linee3fe402017-03-13 10:00:42 -07004105{
4106
4107 int ret = 0;
4108 const int backend_idx = platform_get_backend_index(snd_device);
4109 struct platform_data *my_data = (struct platform_data *)adev->platform;
4110 const unsigned int bit_width = backend_cfg->bit_width;
4111 const unsigned int sample_rate = backend_cfg->sample_rate;
4112 const unsigned int channels = backend_cfg->channels;
4113 const audio_format_t format = backend_cfg->format;
4114 const bool passthrough_enabled = backend_cfg->passthrough_enabled;
4115
4116
4117 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
4118 ", backend_idx %d device (%s)", __func__, bit_width,
4119 sample_rate, channels, backend_idx,
4120 platform_get_snd_device_name(snd_device));
4121
4122 if ((my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl) &&
4123 (bit_width != my_data->current_backend_cfg[backend_idx].bit_width)) {
4124
4125 struct mixer_ctl *ctl = NULL;
4126 ctl = mixer_get_ctl_by_name(adev->mixer,
4127 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
4128 if (!ctl) {
4129 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
4130 __func__,
4131 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
4132 return -EINVAL;
4133 }
4134
4135 if (bit_width == 24) {
4136 if (format == AUDIO_FORMAT_PCM_24_BIT_PACKED)
4137 ret = mixer_ctl_set_enum_by_string(ctl, "S24_3LE");
4138 else
4139 ret = mixer_ctl_set_enum_by_string(ctl, "S24_LE");
4140 } else if (bit_width == 32) {
4141 ret = mixer_ctl_set_enum_by_string(ctl, "S32_LE");
4142 } else {
4143 ret = mixer_ctl_set_enum_by_string(ctl, "S16_LE");
4144 }
4145 if ( ret < 0) {
4146 ALOGE("%s:becf: afe: fail for %s mixer set to %d bit for %x format", __func__,
4147 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
4148 } else {
4149 my_data->current_backend_cfg[backend_idx].bit_width = bit_width;
4150 ALOGD("%s:becf: afe: %s mixer set to %d bit for %x format", __func__,
4151 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
4152 }
4153 /* set the ret as 0 and not pass back to upper layer */
4154 ret = 0;
4155 }
4156
4157 if (passthrough_enabled || ((my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl) &&
4158 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate))) {
4159 char *rate_str = NULL;
4160 struct mixer_ctl *ctl = NULL;
4161
4162 switch (sample_rate) {
4163 case 32000:
4164 if (passthrough_enabled) {
4165 rate_str = "KHZ_32";
4166 break;
4167 }
4168 case 8000:
4169 case 11025:
4170 case 16000:
4171 case 22050:
4172 case 48000:
4173 rate_str = "KHZ_48";
4174 break;
4175 case 44100:
4176 rate_str = "KHZ_44P1";
4177 break;
4178 case 64000:
4179 case 96000:
4180 rate_str = "KHZ_96";
4181 break;
4182 case 88200:
4183 rate_str = "KHZ_88P2";
4184 break;
4185 case 176400:
4186 rate_str = "KHZ_176P4";
4187 break;
4188 case 192000:
4189 rate_str = "KHZ_192";
4190 break;
4191 case 352800:
4192 rate_str = "KHZ_352P8";
4193 break;
4194 case 384000:
4195 rate_str = "KHZ_384";
4196 break;
4197 case 144000:
4198 if (passthrough_enabled) {
4199 rate_str = "KHZ_144";
4200 break;
4201 }
4202 default:
4203 rate_str = "KHZ_48";
4204 break;
4205 }
4206
4207 ctl = mixer_get_ctl_by_name(adev->mixer,
4208 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
4209 if(!ctl) {
4210 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
4211 __func__,
4212 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
4213 return -EINVAL;
4214 }
4215
4216 ALOGD("%s:becf: afe: %s set to %s", __func__,
4217 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl, rate_str);
4218 mixer_ctl_set_enum_by_string(ctl, rate_str);
4219 my_data->current_backend_cfg[backend_idx].sample_rate = sample_rate;
4220 }
4221 if ((my_data->current_backend_cfg[backend_idx].channels_mixer_ctl) &&
4222 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
4223 struct mixer_ctl *ctl = NULL;
4224 char *channel_cnt_str = NULL;
4225
4226 switch (channels) {
4227 case 8:
4228 channel_cnt_str = "Eight"; break;
4229 case 7:
4230 channel_cnt_str = "Seven"; break;
4231 case 6:
4232 channel_cnt_str = "Six"; break;
4233 case 5:
4234 channel_cnt_str = "Five"; break;
4235 case 4:
4236 channel_cnt_str = "Four"; break;
4237 case 3:
4238 channel_cnt_str = "Three"; break;
4239 case 1:
4240 channel_cnt_str = "One"; break;
4241 case 2:
4242 default:
4243 channel_cnt_str = "Two"; break;
4244 }
4245
4246 ctl = mixer_get_ctl_by_name(adev->mixer,
4247 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
4248 if (!ctl) {
4249 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
4250 __func__,
4251 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
4252 return -EINVAL;
4253 }
4254 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
4255 my_data->current_backend_cfg[backend_idx].channels = channels;
4256
4257 // skip EDID configuration for HDMI backend
4258
4259 ALOGD("%s:becf: afe: %s set to %s", __func__,
4260 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl,
4261 channel_cnt_str);
4262 }
4263
4264 // skip set ext_display format mixer control
4265 return ret;
4266}
4267
4268static int platform_get_snd_device_bit_width(snd_device_t snd_device)
4269{
4270 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
4271 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
4272 return CODEC_BACKEND_DEFAULT_BIT_WIDTH;
4273 }
4274
4275 return backend_bit_width_table[snd_device];
4276}
4277
4278/*
4279 * return backend_idx on which voice call is active
4280 */
4281static int platform_get_voice_call_backend(struct audio_device* adev)
4282{
4283 struct audio_usecase *uc = NULL;
4284 struct listnode *node;
4285 snd_device_t out_snd_device = SND_DEVICE_NONE;
4286
4287 int backend_idx = -1;
4288
4289 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
4290 list_for_each(node, &adev->usecase_list) {
4291 uc = node_to_item(node, struct audio_usecase, list);
4292 if (uc && uc->type == VOICE_CALL && uc->stream.out) {
4293 out_snd_device = platform_get_output_snd_device(adev->platform,
4294 uc->stream.out->devices);
4295 backend_idx = platform_get_backend_index(out_snd_device);
4296 break;
4297 }
4298 }
4299 }
4300 return backend_idx;
4301}
4302
4303/*
4304 * goes through all the current usecases and picks the highest
4305 * bitwidth & samplerate
4306 */
4307static bool platform_check_capture_backend_cfg(struct audio_device* adev,
4308 int backend_idx,
4309 struct audio_backend_cfg *backend_cfg)
4310{
4311 bool backend_change = false;
4312 unsigned int bit_width;
4313 unsigned int sample_rate;
4314 unsigned int channels;
4315 struct platform_data *my_data = (struct platform_data *)adev->platform;
4316
4317 bit_width = backend_cfg->bit_width;
4318 sample_rate = backend_cfg->sample_rate;
4319 channels = backend_cfg->channels;
4320
4321 ALOGV("%s:txbecf: afe: Codec selected backend: %d current bit width: %d and "
4322 "sample rate: %d, channels %d",__func__,backend_idx, bit_width,
4323 sample_rate, channels);
4324
4325 // For voice calls use default configuration i.e. 16b/48K, only applicable to
4326 // default backend
4327 // force routing is not required here, caller will do it anyway
4328 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
4329 ALOGW("%s:txbecf: afe: Use default bw and sr for voice/voip calls and "
4330 "for unprocessed/camera source", __func__);
4331 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
4332 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4333 }
4334
4335 if (backend_idx == USB_AUDIO_TX_BACKEND) {
4336 audio_extn_usb_is_config_supported(&bit_width, &sample_rate, &channels, false);
4337 ALOGV("%s:txbecf: afe: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
4338 __func__, bit_width, sample_rate, channels);
4339 }
4340
4341 ALOGV("%s:txbecf: afe: Codec selected backend: %d updated bit width: %d and "
4342 "sample rate: %d", __func__, backend_idx, bit_width, sample_rate);
4343
4344 // Force routing if the expected bitwdith or samplerate
4345 // is not same as current backend comfiguration
4346 if ((bit_width != my_data->current_backend_cfg[backend_idx].bit_width) ||
4347 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate) ||
4348 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
4349 backend_cfg->bit_width = bit_width;
4350 backend_cfg->sample_rate= sample_rate;
4351 backend_cfg->channels = channels;
4352 backend_change = true;
4353 ALOGI("%s:txbecf: afe: Codec backend needs to be updated. new bit width: %d "
4354 "new sample rate: %d new channel: %d",
4355 __func__, backend_cfg->bit_width,
4356 backend_cfg->sample_rate, backend_cfg->channels);
4357 }
4358
4359 return backend_change;
4360}
4361
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004362static void pick_playback_cfg_for_uc(struct audio_device *adev,
4363 struct audio_usecase *usecase,
4364 snd_device_t snd_device,
4365 unsigned int *bit_width,
4366 unsigned int *sample_rate,
4367 unsigned int *channels)
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004368{
4369 int i =0;
4370 struct listnode *node;
4371 list_for_each(node, &adev->usecase_list) {
4372 struct audio_usecase *uc;
4373 uc = node_to_item(node, struct audio_usecase, list);
4374 struct stream_out *out = (struct stream_out*) uc->stream.out;
4375 if (uc->type == PCM_PLAYBACK && out && usecase != uc) {
4376 unsigned int out_channels = audio_channel_count_from_out_mask(out->channel_mask);
4377 ALOGV("%s:napb: (%d) - (%s)id (%d) sr %d bw "
4378 "(%d) ch (%d) device %s", __func__, i++, use_case_table[uc->id],
4379 uc->id, out->sample_rate,
4380 pcm_format_to_bits(out->config.format), out_channels,
4381 platform_get_snd_device_name(uc->out_snd_device));
4382
4383 if (platform_check_backends_match(snd_device, uc->out_snd_device)) {
4384 if (*bit_width < pcm_format_to_bits(out->config.format))
4385 *bit_width = pcm_format_to_bits(out->config.format);
4386 if (*sample_rate < out->sample_rate)
4387 *sample_rate = out->sample_rate;
4388 if (out->sample_rate < OUTPUT_SAMPLING_RATE_44100)
4389 *sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4390 if (*channels < out_channels)
4391 *channels = out_channels;
4392 }
4393 }
4394 }
4395 return;
4396}
4397
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004398static void headset_is_config_supported(unsigned int *bit_width,
4399 unsigned int *sample_rate,
4400 unsigned int *channels) {
4401 switch (*bit_width) {
4402 case 16:
4403 case 24:
4404 break;
4405 default:
4406 *bit_width = 16;
4407 break;
4408 }
4409
4410 if (*sample_rate > 192000) {
4411 *sample_rate = 192000;
4412 }
4413
4414 if (*channels > 2) {
4415 *channels = 2;
4416 }
4417}
4418
David Linee3fe402017-03-13 10:00:42 -07004419static bool platform_check_playback_backend_cfg(struct audio_device* adev,
4420 struct audio_usecase* usecase,
4421 snd_device_t snd_device,
4422 struct audio_backend_cfg *backend_cfg)
4423{
4424 bool backend_change = false;
David Linee3fe402017-03-13 10:00:42 -07004425 unsigned int bit_width;
4426 unsigned int sample_rate;
4427 unsigned int channels;
David Linee3fe402017-03-13 10:00:42 -07004428 int backend_idx = DEFAULT_CODEC_BACKEND;
Haynes Mathew George65f6b432018-02-27 17:44:55 -08004429 unsigned long service_interval = 0; // 0 is invalid
David Linee3fe402017-03-13 10:00:42 -07004430 struct platform_data *my_data = (struct platform_data *)adev->platform;
David Linee3fe402017-03-13 10:00:42 -07004431
4432 if (snd_device == SND_DEVICE_OUT_BT_SCO ||
4433 snd_device == SND_DEVICE_OUT_BT_SCO_WB) {
4434 backend_change = false;
4435 return backend_change;
4436 }
4437
4438 backend_idx = platform_get_backend_index(snd_device);
4439 bit_width = backend_cfg->bit_width;
4440 sample_rate = backend_cfg->sample_rate;
4441 channels = backend_cfg->channels;
4442
4443 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
4444 ", backend_idx %d usecase = %d device (%s)", __func__, bit_width,
4445 sample_rate, channels, backend_idx, usecase->id,
4446 platform_get_snd_device_name(snd_device));
4447
4448 if (backend_idx == platform_get_voice_call_backend(adev)) {
4449 ALOGW("%s:becf: afe:Use default bw and sr for voice/voip calls ",
4450 __func__);
4451 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
4452 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4453 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
4454 } else {
4455 /*
4456 * The backend should be configured at highest bit width and/or
4457 * sample rate amongst all playback usecases.
4458 * If the selected sample rate and/or bit width differ with
4459 * current backend sample rate and/or bit width, then, we set the
4460 * backend re-configuration flag.
4461 *
4462 * Exception: 16 bit playbacks is allowed through 16 bit/48/44.1 khz backend only
4463 */
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004464 pick_playback_cfg_for_uc(adev, usecase, snd_device,
4465 &bit_width,
4466 &sample_rate,
4467 &channels);
David Linee3fe402017-03-13 10:00:42 -07004468 }
4469
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004470 switch (backend_idx) {
4471 case USB_AUDIO_RX_BACKEND:
4472 audio_extn_usb_is_config_supported(&bit_width,
4473 &sample_rate, &channels, true);
Haynes Mathew George65f6b432018-02-27 17:44:55 -08004474 if (platform_get_usb_service_interval(adev->platform, true,
4475 &service_interval) == 0) {
4476 /* overwrite with best altset for this service interval */
4477 int ret =
4478 audio_extn_usb_altset_for_service_interval(true /*playback*/,
4479 service_interval,
4480 &bit_width,
4481 &sample_rate,
4482 &channels);
4483 if (ret < 0) {
4484 ALOGE("Failed to find altset for service interval %lu, skip reconfig",
4485 service_interval);
4486 return false;
4487 }
4488 }
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004489 ALOGV("%s: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
4490 __func__, bit_width, sample_rate, channels);
4491 break;
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004492 case HEADPHONE_BACKEND:
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004493 headset_is_config_supported(&bit_width, &sample_rate, &channels);
4494 break;
4495 case DEFAULT_CODEC_BACKEND:
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004496 default:
4497 bit_width = platform_get_snd_device_bit_width(snd_device);
4498 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4499 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
4500 break;
David Linee3fe402017-03-13 10:00:42 -07004501 }
4502
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004503 ALOGV("%s:becf: afe: Codec selected backend: %d updated bit width: %d and"
4504 "sample rate: %d",
David Linee3fe402017-03-13 10:00:42 -07004505 __func__, backend_idx , bit_width, sample_rate);
4506
4507 // Force routing if the expected bitwdith or samplerate
4508 // is not same as current backend comfiguration
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004509 if (bit_width != my_data->current_backend_cfg[backend_idx].bit_width ||
4510 sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate ||
4511 channels != my_data->current_backend_cfg[backend_idx].channels) {
David Linee3fe402017-03-13 10:00:42 -07004512 backend_cfg->bit_width = bit_width;
4513 backend_cfg->sample_rate = sample_rate;
4514 backend_cfg->channels = channels;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004515 backend_cfg->passthrough_enabled = false;
David Linee3fe402017-03-13 10:00:42 -07004516 backend_change = true;
4517 ALOGV("%s:becf: afe: Codec backend needs to be updated. new bit width: %d"
4518 "new sample rate: %d new channels: %d",
4519 __func__, backend_cfg->bit_width, backend_cfg->sample_rate, backend_cfg->channels);
4520 }
4521
4522 return backend_change;
4523}
4524
4525bool platform_check_and_set_playback_backend_cfg(struct audio_device* adev,
4526 struct audio_usecase *usecase, snd_device_t snd_device)
4527{
4528 int backend_idx = DEFAULT_CODEC_BACKEND;
4529 int new_snd_devices[SND_DEVICE_OUT_END];
4530 int i, num_devices = 1;
4531 bool ret = false;
4532 struct platform_data *my_data = (struct platform_data *)adev->platform;
4533 struct audio_backend_cfg backend_cfg;
4534
4535 backend_idx = platform_get_backend_index(snd_device);
4536
4537 backend_cfg.bit_width = pcm_format_to_bits(usecase->stream.out->config.format);
4538 backend_cfg.sample_rate = usecase->stream.out->sample_rate;
4539 backend_cfg.format = usecase->stream.out->format;
4540 backend_cfg.channels = audio_channel_count_from_out_mask(usecase->stream.out->channel_mask);
4541 /*this is populated by check_codec_backend_cfg hence set default value to false*/
4542 backend_cfg.passthrough_enabled = false;
4543
4544 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
4545 ", backend_idx %d usecase = %d device (%s)", __func__, backend_cfg.bit_width,
4546 backend_cfg.sample_rate, backend_cfg.channels, backend_idx, usecase->id,
4547 platform_get_snd_device_name(snd_device));
4548
4549 if (platform_can_split_snd_device(snd_device, &num_devices, new_snd_devices) < 0)
4550 new_snd_devices[0] = snd_device;
4551
4552 for (i = 0; i < num_devices; i++) {
4553 ALOGV("%s: new_snd_devices[%d] is %d", __func__, i, new_snd_devices[i]);
4554 if ((platform_check_playback_backend_cfg(adev, usecase, new_snd_devices[i],
4555 &backend_cfg))) {
4556 platform_set_backend_cfg(adev, new_snd_devices[i],
4557 &backend_cfg);
4558 ret = true;
4559 }
4560 }
4561 return ret;
4562}
4563
4564bool platform_check_and_set_capture_backend_cfg(struct audio_device* adev,
4565 struct audio_usecase *usecase, snd_device_t snd_device)
4566{
4567 int backend_idx = platform_get_backend_index(snd_device);
4568 int ret = 0;
4569 struct audio_backend_cfg backend_cfg;
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004570 memset(&backend_cfg, 0, sizeof(struct audio_backend_cfg));
David Linee3fe402017-03-13 10:00:42 -07004571
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004572 if (usecase->type == PCM_CAPTURE) {
4573 backend_cfg.format = usecase->stream.in->format;
David Linee3fe402017-03-13 10:00:42 -07004574 backend_cfg.channels = audio_channel_count_from_in_mask(usecase->stream.in->channel_mask);
4575 } else {
4576 backend_cfg.bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
4577 backend_cfg.sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4578 backend_cfg.format = AUDIO_FORMAT_PCM_16_BIT;
4579 backend_cfg.channels = 1;
4580 }
4581
4582 ALOGV("%s:txbecf: afe: bitwidth %d, samplerate %d, channel %d"
4583 ", backend_idx %d usecase = %d device (%s)", __func__,
4584 backend_cfg.bit_width,
4585 backend_cfg.sample_rate,
4586 backend_cfg.channels,
4587 backend_idx, usecase->id,
4588 platform_get_snd_device_name(snd_device));
4589
4590 if (platform_check_capture_backend_cfg(adev, backend_idx, &backend_cfg)) {
4591 ret = platform_set_backend_cfg(adev, snd_device,
4592 &backend_cfg);
4593 if(!ret)
4594 return true;
4595 }
4596
4597 return false;
4598}
4599
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004600static int max_be_dai_names = 0;
4601static const struct be_dai_name_struct *be_dai_name_table;
4602
4603/*
4604 * Retrieves the be_dai_name_table from kernel to enable a mapping
4605 * between sound device hw interfaces and backend IDs. This allows HAL to
4606 * specify the backend a specific calibration is needed for.
4607 */
4608static int init_be_dai_name_table(struct audio_device *adev)
4609{
4610 const char *mixer_ctl_name = "Backend DAI Name Table";
4611 struct mixer_ctl *ctl;
4612 int i, j, ret, size;
4613 bool valid_hw_interface;
4614
4615 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
4616 if (!ctl) {
4617 ALOGE("%s: Could not get ctl for mixer name %s\n",
4618 __func__, mixer_ctl_name);
4619 ret = -EINVAL;
4620 goto done;
4621 }
4622
4623 mixer_ctl_update(ctl);
4624
4625 size = mixer_ctl_get_num_values(ctl);
4626 if (size <= 0){
4627 ALOGE("%s: Failed to get %s size %d\n",
4628 __func__, mixer_ctl_name, size);
4629 ret = -EFAULT;
4630 goto done;
4631 }
4632
vivek mehtaa68fea62017-06-08 19:04:02 -07004633 be_dai_name_table =
4634 (const struct be_dai_name_struct *)calloc(1, size);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004635 if (be_dai_name_table == NULL) {
4636 ALOGE("%s: Failed to allocate memory for %s\n",
4637 __func__, mixer_ctl_name);
4638 ret = -ENOMEM;
4639 goto freeMem;
4640 }
4641
4642 ret = mixer_ctl_get_array(ctl, (void *)be_dai_name_table, size);
4643 if (ret) {
4644 ALOGE("%s: Failed to get %s, ret %d\n",
4645 __func__, mixer_ctl_name, ret);
4646 ret = -EFAULT;
4647 goto freeMem;
4648 }
4649
4650 if (be_dai_name_table != NULL) {
4651 max_be_dai_names = size / sizeof(struct be_dai_name_struct);
4652 ALOGV("%s: Successfully got %s, number of be dais is %d\n",
4653 __func__, mixer_ctl_name, max_be_dai_names);
4654 ret = 0;
4655 } else {
4656 ALOGE("%s: Failed to get %s\n", __func__, mixer_ctl_name);
4657 ret = -EFAULT;
4658 goto freeMem;
4659 }
4660
4661 /*
4662 * Validate all sound devices have a valid backend set to catch
4663 * errors for uncommon sound devices
4664 */
4665 for (i = 0; i < SND_DEVICE_MAX; i++) {
4666 valid_hw_interface = false;
4667
4668 if (hw_interface_table[i] == NULL) {
4669 ALOGW("%s: sound device %s has no hw interface set\n",
4670 __func__, platform_get_snd_device_name(i));
4671 continue;
4672 }
4673
4674 for (j = 0; j < max_be_dai_names; j++) {
4675 if (strcmp(hw_interface_table[i], be_dai_name_table[j].be_name)
4676 == 0) {
4677 valid_hw_interface = true;
4678 break;
4679 }
4680 }
4681 if (!valid_hw_interface)
4682 ALOGD("%s: sound device %s does not have a valid hw interface set "
4683 "(disregard for combo devices) %s\n",
4684 __func__, platform_get_snd_device_name(i),
4685 hw_interface_table[i]);
4686 }
4687
4688 goto done;
4689
4690freeMem:
4691 if (be_dai_name_table) {
4692 free((void *)be_dai_name_table);
4693 be_dai_name_table = NULL;
4694 }
4695
4696done:
4697 return ret;
4698}
4699
4700int platform_get_snd_device_backend_index(snd_device_t device)
4701{
4702 int i, be_dai_id;
4703 const char * hw_interface_name = NULL;
4704
4705 ALOGV("%s: enter with device %d\n", __func__, device);
4706
vivek mehtaa68fea62017-06-08 19:04:02 -07004707 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004708 ALOGE("%s: Invalid snd_device = %d",
4709 __func__, device);
4710 be_dai_id = -EINVAL;
4711 goto done;
4712 }
4713
4714 /* Get string value of necessary backend for device */
4715 hw_interface_name = hw_interface_table[device];
4716 if (hw_interface_name == NULL) {
4717 ALOGE("%s: no hw_interface set for device %d\n", __func__, device);
4718 be_dai_id = -EINVAL;
4719 goto done;
4720 }
4721
4722 /* Check if be dai name table was retrieved successfully */
4723 if (be_dai_name_table == NULL) {
4724 ALOGE("%s: BE DAI Name Table is not present\n", __func__);
4725 be_dai_id = -EFAULT;
4726 goto done;
4727 }
4728
4729 /* Get backend ID for device specified */
4730 for (i = 0; i < max_be_dai_names; i++) {
4731 if (strcmp(hw_interface_name, be_dai_name_table[i].be_name) == 0) {
4732 be_dai_id = be_dai_name_table[i].be_id;
4733 goto done;
4734 }
4735 }
4736 ALOGE("%s: no interface matching name %s\n", __func__, hw_interface_name);
4737 be_dai_id = -EINVAL;
4738 goto done;
4739
4740done:
4741 return be_dai_id;
4742}
4743
4744void platform_check_and_update_copp_sample_rate(void* platform, snd_device_t snd_device,
4745 unsigned int stream_sr, int* sample_rate)
4746{
4747 struct platform_data* my_data = (struct platform_data *)platform;
4748 int backend_idx = platform_get_backend_index(snd_device);
4749 int device_sr = my_data->current_backend_cfg[backend_idx].sample_rate;
4750 /*
4751 *Check if device SR is multiple of 8K or 11.025 Khz
4752 *check if the stream SR is multiple of same base, if yes
4753 *then have copp SR equal to stream SR, this ensures that
4754 *post processing happens at stream SR, else have
4755 *copp SR equal to device SR.
4756 */
4757 if (!(((sample_rate_multiple(device_sr, SAMPLE_RATE_8000)) &&
4758 (sample_rate_multiple(stream_sr, SAMPLE_RATE_8000))) ||
4759 ((sample_rate_multiple(device_sr, SAMPLE_RATE_11025)) &&
4760 (sample_rate_multiple(stream_sr, SAMPLE_RATE_11025))))) {
4761 *sample_rate = device_sr;
4762 } else
4763 *sample_rate = stream_sr;
4764
4765 ALOGI("sn_device %d device sr %d stream sr %d copp sr %d", snd_device, device_sr, stream_sr
4766 , *sample_rate);
4767
4768}
4769
4770// called from info parser
vivek mehtaa68fea62017-06-08 19:04:02 -07004771void platform_add_app_type(const char *uc_type,
4772 const char *mode,
4773 int bw,
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004774 int app_type, int max_rate) {
4775 struct app_type_entry *ap =
4776 (struct app_type_entry *)calloc(1, sizeof(struct app_type_entry));
4777
4778 if (!ap) {
4779 ALOGE("%s failed to allocate mem for app type", __func__);
4780 return;
4781 }
4782
4783 ap->uc_type = -1;
4784 for (int i=0; i<USECASE_TYPE_MAX; i++) {
4785 if (!strcmp(uc_type, usecase_type_index[i].name)) {
4786 ap->uc_type = usecase_type_index[i].index;
4787 break;
4788 }
4789 }
4790
4791 if (ap->uc_type == -1) {
4792 free(ap);
4793 return;
4794 }
4795
vivek mehtaa68fea62017-06-08 19:04:02 -07004796 ALOGI("%s uc %s mode %s bw %d app_type %d max_rate %d",
4797 __func__, uc_type, mode, bw, app_type, max_rate);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004798 ap->bit_width = bw;
4799 ap->app_type = app_type;
4800 ap->max_rate = max_rate;
vivek mehtaa68fea62017-06-08 19:04:02 -07004801 ap->mode = strdup(mode);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004802 list_add_tail(&app_type_entry_list, &ap->node);
4803}
4804
4805
4806int platform_get_default_app_type_v2(void *platform __unused,
4807 usecase_type_t type,
4808 int *app_type )
4809{
4810 if (type == PCM_PLAYBACK)
4811 *app_type = DEFAULT_APP_TYPE_RX_PATH;
4812 else
4813 *app_type = DEFAULT_APP_TYPE_TX_PATH;
4814 return 0;
4815}
4816
vivek mehtaa68fea62017-06-08 19:04:02 -07004817int platform_get_app_type_v2(void *platform,
4818 usecase_type_t uc_type,
4819 const char *mode,
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004820 int bw, int sr __unused,
4821 int *app_type)
4822{
4823 struct listnode *node;
4824 struct app_type_entry *entry;
4825 *app_type = -1;
vivek mehtaa68fea62017-06-08 19:04:02 -07004826
4827 ALOGV("%s find match for uc %d mode %s bw %d rate %d",
4828 __func__, uc_type, mode, bw, sr);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004829 list_for_each(node, &app_type_entry_list) {
4830 entry = node_to_item(node, struct app_type_entry, node);
vivek mehtaa68fea62017-06-08 19:04:02 -07004831 ALOGV("%s uc %d mode %s bw %d app_type %d max_rate %d",
4832 __func__, entry->uc_type, entry->mode, entry->bit_width,
4833 entry->app_type, entry->max_rate);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004834 if (entry->bit_width == bw &&
vivek mehtaa68fea62017-06-08 19:04:02 -07004835 entry->uc_type == uc_type &&
4836 sr <= entry->max_rate &&
4837 entry->mode && !strcmp(mode, entry->mode)) {
4838 ALOGV("%s found match %d", __func__, entry->app_type);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004839 *app_type = entry->app_type;
4840 break;
4841 }
4842 }
4843
4844 if (*app_type == -1) {
vivek mehtaa68fea62017-06-08 19:04:02 -07004845 ALOGV("%s no match found, return default", __func__);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004846 return platform_get_default_app_type_v2(platform, uc_type, app_type);
4847 }
4848 return 0;
4849}
vivek mehta90933872017-06-15 18:04:39 -07004850
4851int platform_set_sidetone(struct audio_device *adev,
4852 snd_device_t out_snd_device,
4853 bool enable, char *str)
4854{
4855 int ret;
4856 if (out_snd_device == SND_DEVICE_OUT_USB_HEADSET ||
4857 out_snd_device == SND_DEVICE_OUT_VOICE_USB_HEADSET) {
4858 ret = audio_extn_usb_enable_sidetone(out_snd_device, enable);
4859 if (ret)
4860 ALOGI("%s: usb device %d does not support device sidetone\n",
4861 __func__, out_snd_device);
4862 } else {
4863 ALOGV("%s: sidetone out device(%d) mixer cmd = %s\n",
4864 __func__, out_snd_device, str);
4865 if (enable)
4866 audio_route_apply_and_update_path(adev->audio_route, str);
4867 else
4868 audio_route_reset_and_update_path(adev->audio_route, str);
4869 }
4870 return 0;
4871}
Haynes Mathew George96483a22017-03-28 14:52:47 -07004872
4873int platform_get_mmap_data_fd(void *platform __unused, int fe_dev __unused, int dir __unused,
4874 int *fd __unused, uint32_t *size __unused)
4875{
Thierry Strudel07f96d12018-09-20 13:31:34 -07004876#if defined (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845) || (PLATFORM_SDM710) || (PLATFORM_SM8150)
Haynes Mathew George96483a22017-03-28 14:52:47 -07004877 struct platform_data *my_data = (struct platform_data *)platform;
4878 struct audio_device *adev = my_data->adev;
4879 int hw_fd = -1;
4880 char dev_name[128];
4881 struct snd_pcm_mmap_fd mmap_fd;
4882 memset(&mmap_fd, 0, sizeof(mmap_fd));
4883 mmap_fd.dir = dir;
4884 snprintf(dev_name, sizeof(dev_name), "/dev/snd/hwC%uD%u",
4885 adev->snd_card, HWDEP_FE_BASE+fe_dev);
4886 hw_fd = open(dev_name, O_RDONLY);
4887 if (hw_fd < 0) {
4888 ALOGE("fe hw dep node open %d/%d failed", adev->snd_card, fe_dev);
4889 return -1;
4890 }
4891 if (ioctl(hw_fd, SNDRV_PCM_IOCTL_MMAP_DATA_FD, &mmap_fd) < 0) {
4892 ALOGE("fe hw dep node ioctl failed");
4893 close(hw_fd);
4894 return -1;
4895 }
4896 *fd = mmap_fd.fd;
4897 *size = mmap_fd.size;
4898 close(hw_fd); // mmap_fd should still be valid
4899 return 0;
4900#else
4901 return -1;
4902#endif
4903}
Mikhail Naganov4ee6e3e2018-03-21 16:28:35 +00004904
4905bool platform_sound_trigger_usecase_needs_event(audio_usecase_t uc_id)
4906{
4907 bool needs_event = false;
4908
4909 switch (uc_id) {
4910 /* concurrent capture usecases which needs event */
4911 case USECASE_AUDIO_RECORD:
4912 case USECASE_AUDIO_RECORD_LOW_LATENCY:
4913 case USECASE_AUDIO_RECORD_MMAP:
4914 case USECASE_AUDIO_RECORD_HIFI:
4915 case USECASE_AUDIO_RECORD_VOIP:
4916 case USECASE_VOICEMMODE1_CALL:
4917 case USECASE_VOICEMMODE2_CALL:
4918 /* concurrent playback usecases that needs event */
4919 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
4920 case USECASE_AUDIO_PLAYBACK_OFFLOAD:
4921 needs_event = true;
4922 break;
4923 default:
4924 ALOGV("%s:usecase_id[%d] no need to raise event.", __func__, uc_id);
4925 }
4926 return needs_event;
4927}
4928
4929bool platform_snd_device_has_speaker(snd_device_t dev) {
4930 int num_devs = 2;
4931 snd_device_t split_devs[2] = {SND_DEVICE_NONE, SND_DEVICE_NONE};
4932 if (platform_can_split_snd_device(dev, &num_devs, split_devs) == 0) {
4933 return platform_snd_device_has_speaker(split_devs[0]) ||
4934 platform_snd_device_has_speaker(split_devs[1]);
4935 }
4936
4937 switch (dev) {
4938 case SND_DEVICE_OUT_SPEAKER:
4939 case SND_DEVICE_OUT_SPEAKER_SAFE:
4940 case SND_DEVICE_OUT_SPEAKER_REVERSE:
4941 case SND_DEVICE_OUT_SPEAKER_PROTECTED:
4942 case SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED:
4943 case SND_DEVICE_OUT_VOICE_SPEAKER_HFP:
4944 return true;
4945 default:
4946 break;
4947 }
4948 return false;
4949}
jiabin8962a4d2018-03-19 18:21:24 -07004950
4951bool platform_set_microphone_characteristic(void *platform,
4952 struct audio_microphone_characteristic_t mic) {
4953 struct platform_data *my_data = (struct platform_data *)platform;
4954 if (my_data->declared_mic_count >= AUDIO_MICROPHONE_MAX_COUNT) {
4955 ALOGE("mic number is more than maximum number");
4956 return false;
4957 }
4958 for (size_t ch = 0; ch < AUDIO_CHANNEL_COUNT_MAX; ch++) {
4959 mic.channel_mapping[ch] = AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED;
4960 }
4961 my_data->microphones[my_data->declared_mic_count++] = mic;
4962 return true;
4963}
4964
4965int platform_get_microphones(void *platform,
4966 struct audio_microphone_characteristic_t *mic_array,
4967 size_t *mic_count) {
4968 struct platform_data *my_data = (struct platform_data *)platform;
4969 if (mic_count == NULL) {
4970 return -EINVAL;
4971 }
4972 if (mic_array == NULL) {
4973 return -EINVAL;
4974 }
4975
4976 if (*mic_count == 0) {
4977 *mic_count = my_data->declared_mic_count;
4978 return 0;
4979 }
4980
4981 size_t max_mic_count = *mic_count;
4982 size_t actual_mic_count = 0;
4983 for (size_t i = 0; i < max_mic_count && i < my_data->declared_mic_count; i++) {
4984 mic_array[i] = my_data->microphones[i];
4985 actual_mic_count++;
4986 }
4987 *mic_count = actual_mic_count;
4988 return 0;
4989}
4990
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004991bool platform_set_microphone_map(void *platform, snd_device_t in_snd_device,
4992 const struct mic_info *info) {
4993 struct platform_data *my_data = (struct platform_data *)platform;
4994 if (in_snd_device < SND_DEVICE_IN_BEGIN || in_snd_device >= SND_DEVICE_IN_END) {
4995 ALOGE("%s: Sound device not valid", __func__);
4996 return false;
4997 }
4998 size_t m_count = my_data->mic_map[in_snd_device].mic_count++;
4999 if (m_count >= AUDIO_MICROPHONE_MAX_COUNT) {
5000 ALOGE("%s: Microphone count is greater than max allowed value", __func__);
5001 my_data->mic_map[in_snd_device].mic_count--;
5002 return false;
5003 }
5004 my_data->mic_map[in_snd_device].microphones[m_count] = *info;
5005 return true;
5006}
5007
5008int platform_get_active_microphones(void *platform, unsigned int channels,
5009 audio_usecase_t uc_id,
jiabin8962a4d2018-03-19 18:21:24 -07005010 struct audio_microphone_characteristic_t *mic_array,
5011 size_t *mic_count) {
5012 struct platform_data *my_data = (struct platform_data *)platform;
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07005013 struct audio_usecase *usecase = get_usecase_from_list(my_data->adev, uc_id);
5014 if (mic_count == NULL || mic_array == NULL || usecase == NULL) {
jiabin8962a4d2018-03-19 18:21:24 -07005015 return -EINVAL;
5016 }
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07005017 size_t max_mic_count = my_data->declared_mic_count;
jiabin8962a4d2018-03-19 18:21:24 -07005018 size_t actual_mic_count = 0;
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07005019
5020 snd_device_t active_input_snd_device =
Eric Laurentd1b7a9b2018-11-15 12:24:31 -08005021 platform_get_input_snd_device(platform, usecase->stream.in, AUDIO_DEVICE_NONE);
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07005022 if (active_input_snd_device == SND_DEVICE_NONE) {
5023 ALOGI("%s: No active microphones found", __func__);
5024 goto end;
5025 }
5026
5027 size_t active_mic_count = my_data->mic_map[active_input_snd_device].mic_count;
5028 struct mic_info *m_info = my_data->mic_map[active_input_snd_device].microphones;
5029
5030 for (size_t i = 0; i < active_mic_count; i++) {
5031 unsigned int channels_for_active_mic = channels;
5032 if (channels_for_active_mic > m_info[i].channel_count) {
5033 channels_for_active_mic = m_info[i].channel_count;
5034 }
5035 for (size_t j = 0; j < max_mic_count; j++) {
5036 if (strcmp(my_data->microphones[j].device_id,
5037 m_info[i].device_id) == 0) {
5038 mic_array[actual_mic_count] = my_data->microphones[j];
5039 for (size_t ch = 0; ch < channels_for_active_mic; ch++) {
5040 mic_array[actual_mic_count].channel_mapping[ch] =
5041 m_info[i].channel_mapping[ch];
5042 }
5043 actual_mic_count++;
5044 break;
jiabin8962a4d2018-03-19 18:21:24 -07005045 }
jiabin8962a4d2018-03-19 18:21:24 -07005046 }
5047 }
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07005048end:
jiabin8962a4d2018-03-19 18:21:24 -07005049 *mic_count = actual_mic_count;
5050 return 0;
5051}
Haynes Mathew George65f6b432018-02-27 17:44:55 -08005052
5053int platform_set_usb_service_interval(void *platform,
5054 bool playback,
5055 unsigned long service_interval,
5056 bool *reconfig)
5057{
5058#if defined (USB_SERVICE_INTERVAL_ENABLED)
5059 struct platform_data *_platform = (struct platform_data *)platform;
5060 *reconfig = false;
5061 if (!playback) {
5062 ALOGE("%s not valid for capture", __func__);
5063 return -1;
5064 }
5065 const char *ctl_name = "USB_AUDIO_RX service_interval";
5066 struct mixer_ctl *ctl = mixer_get_ctl_by_name(_platform->adev->mixer,
5067 ctl_name);
5068 if (!ctl) {
5069 ALOGV("%s: could not get mixer %s", __func__, ctl_name);
5070 return -1;
5071 }
5072 if (mixer_ctl_get_value(ctl, 0) != (int)service_interval) {
5073 mixer_ctl_set_value(ctl, 0, service_interval);
5074 *reconfig = true;
5075 }
5076 return 0;
5077#else
5078 *reconfig = false;
5079 (void)platform;
5080 (void)playback;
5081 (void)service_interval;
5082 return -1;
5083#endif
5084}
5085
5086int platform_get_usb_service_interval(void *platform,
5087 bool playback,
5088 unsigned long *service_interval)
5089{
5090#if defined (USB_SERVICE_INTERVAL_ENABLED)
5091 struct platform_data *_platform = (struct platform_data *)platform;
5092 if (!playback) {
5093 ALOGE("%s not valid for capture", __func__);
5094 return -1;
5095 }
5096 const char *ctl_name = "USB_AUDIO_RX service_interval";
5097 struct mixer_ctl *ctl = mixer_get_ctl_by_name(_platform->adev->mixer,
5098 ctl_name);
5099 if (!ctl) {
5100 ALOGV("%s: could not get mixer %s", __func__, ctl_name);
5101 return -1;
5102 }
5103 *service_interval = mixer_ctl_get_value(ctl, 0);
5104 return 0;
5105#else
5106 (void)platform;
5107 (void)playback;
5108 (void)service_interval;
5109 return -1;
5110#endif
5111}
Ashish Jain1c849702018-05-11 20:11:55 +05305112
5113int platform_set_acdb_metainfo_key(void *platform __unused,
5114 char *name __unused,
5115 int key __unused)
5116{
5117 return -ENOSYS;
5118}