blob: 5a36f0c5f2e2b5dfe9ee7e35303637c55d80a937 [file] [log] [blame]
Eric Laurentb23d5282013-05-14 15:27:20 -07001/*
vivek mehtaa6b79742017-03-09 15:40:43 -08002 * Copyright (C) 2013-2017 The Android Open Source Project
Eric Laurentb23d5282013-05-14 15:27:20 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Eric Laurentb23d5282013-05-14 15:27:20 -070016#define LOG_TAG "msm8974_platform"
17/*#define LOG_NDEBUG 0*/
18#define LOG_NDDEBUG 0
19
20#include <stdlib.h>
21#include <dlfcn.h>
Jiyong Park6431fe62017-06-29 15:15:58 +090022#include <pthread.h>
23#include <unistd.h>
Haynes Mathew Georgee6e2d442018-02-22 18:51:56 -080024#include <log/log.h>
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -070025#include <cutils/str_parms.h>
Eric Laurentb23d5282013-05-14 15:27:20 -070026#include <cutils/properties.h>
27#include <audio_hw.h>
28#include <platform_api.h>
vivek mehta0fb11312017-05-15 19:35:32 -070029#include "acdb.h"
Eric Laurentb23d5282013-05-14 15:27:20 -070030#include "platform.h"
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -070031#include "audio_extn.h"
vivek mehta1a9b7c02015-06-25 11:49:38 -070032#include <linux/msm_audio.h>
Thierry Strudel07f96d12018-09-20 13:31:34 -070033#if defined (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845) || (PLATFORM_SDM710) || (PLATFORM_SM8150)
Haynes Mathew George96483a22017-03-28 14:52:47 -070034#include <sound/devdep_params.h>
35#endif
Eric Laurentb23d5282013-05-14 15:27:20 -070036
jasmine cha270b7762018-03-30 15:41:33 +080037#include "maxxaudio.h"
jasmine chac89321b2018-04-10 21:37:01 +080038#include <resolv.h>
39
Jaekyun Seokf62e17d2017-03-08 17:15:28 +090040#define MIXER_XML_DEFAULT_PATH "mixer_paths.xml"
41#define MIXER_XML_BASE_STRING "mixer_paths"
vivek mehta60ea4152016-02-18 17:10:26 -080042#define TOMTOM_8226_SND_CARD_NAME "msm8226-tomtom-snd-card"
43#define TOMTOM_MIXER_FILE_SUFFIX "wcd9330"
44
Eric Laurentb23d5282013-05-14 15:27:20 -070045#define LIB_ACDB_LOADER "libacdbloader.so"
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -070046#define AUDIO_DATA_BLOCK_MIXER_CTL "HDMI EDID"
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +090047#define CVD_VERSION_MIXER_CTL "CVD Version"
Eric Laurentb23d5282013-05-14 15:27:20 -070048
Eric Laurentf9583c32016-03-28 13:50:50 -070049#define min(a, b) ((a) < (b) ? (a) : (b))
Eric Laurentb23d5282013-05-14 15:27:20 -070050
51/*
Eric Laurentb23d5282013-05-14 15:27:20 -070052 * This file will have a maximum of 38 bytes:
53 *
54 * 4 bytes: number of audio blocks
55 * 4 bytes: total length of Short Audio Descriptor (SAD) blocks
56 * Maximum 10 * 3 bytes: SAD blocks
57 */
58#define MAX_SAD_BLOCKS 10
59#define SAD_BLOCK_SIZE 3
60
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +090061#define MAX_CVD_VERSION_STRING_SIZE 100
62
Eric Laurentb23d5282013-05-14 15:27:20 -070063/* EDID format ID for LPCM audio */
64#define EDID_FORMAT_LPCM 1
65
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -070066#define MAX_SND_CARD_NAME_LEN 31
67
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -080068#define DEFAULT_APP_TYPE_RX_PATH 69936
69#define DEFAULT_APP_TYPE_TX_PATH 69938
Haynes Mathew George39c55dc2017-07-11 19:31:23 -070070#define DEFAULT_RX_BACKEND "SLIMBUS_0_RX"
vivek mehta1a9b7c02015-06-25 11:49:38 -070071
keunhui.parkc5aaa0e2015-07-13 10:57:37 +090072#define TOSTRING_(x) #x
73#define TOSTRING(x) TOSTRING_(x)
74
Eric Laurentb23d5282013-05-14 15:27:20 -070075struct audio_block_header
76{
77 int reserved;
78 int length;
79};
80
vivek mehta1a9b7c02015-06-25 11:49:38 -070081enum {
82 CAL_MODE_SEND = 0x1,
83 CAL_MODE_PERSIST = 0x2,
84 CAL_MODE_RTAC = 0x4
85};
86
keunhui.park2f7306a2015-07-16 16:48:06 +090087#define PLATFORM_CONFIG_KEY_OPERATOR_INFO "operator_info"
88
89struct operator_info {
90 struct listnode list;
91 char *name;
92 char *mccmnc;
93};
94
95struct operator_specific_device {
96 struct listnode list;
97 char *operator;
98 char *mixer_path;
99 int acdb_id;
100};
101
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800102#define BE_DAI_NAME_MAX_LENGTH 24
103struct be_dai_name_struct {
104 unsigned int be_id;
105 char be_name[BE_DAI_NAME_MAX_LENGTH];
106};
107
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -0700108struct snd_device_to_mic_map {
109 struct mic_info microphones[AUDIO_MICROPHONE_MAX_COUNT];
110 size_t mic_count;
111};
112
keunhui.park2f7306a2015-07-16 16:48:06 +0900113static struct listnode operator_info_list;
114static struct listnode *operator_specific_device_table[SND_DEVICE_MAX];
115
jasmine chac89321b2018-04-10 21:37:01 +0800116#define AUDIO_PARAMETER_KEY_AUD_CALDATA "cal_data"
117
118typedef struct acdb_audio_cal_cfg {
119 uint32_t persist;
120 uint32_t snd_dev_id;
121 audio_devices_t dev_id;
122 int32_t acdb_dev_id;
123 uint32_t app_type;
124 uint32_t topo_id;
125 uint32_t sampling_rate;
126 uint32_t cal_type;
127 uint32_t module_id;
128 uint32_t param_id;
129} acdb_audio_cal_cfg_t;
130
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700131/* Audio calibration related functions */
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800132typedef void (*acdb_send_audio_cal_v3_t)(int, int, int, int, int);
Eric Laurentb23d5282013-05-14 15:27:20 -0700133
Eric Laurentb23d5282013-05-14 15:27:20 -0700134struct platform_data {
135 struct audio_device *adev;
136 bool fluence_in_spkr_mode;
137 bool fluence_in_voice_call;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700138 bool fluence_in_voice_comm;
Eric Laurentb23d5282013-05-14 15:27:20 -0700139 bool fluence_in_voice_rec;
Prashant Malanic92c5962015-08-11 15:10:18 -0700140 /* 0 = no fluence, 1 = fluence, 2 = fluence pro */
141 int fluence_type;
142 int source_mic_type;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -0700143 bool speaker_lr_swap;
144
Eric Laurentb23d5282013-05-14 15:27:20 -0700145 void *acdb_handle;
Thierry Strudel07f96d12018-09-20 13:31:34 -0700146#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845) || (PLATFORM_SDM710) || (PLATFORM_SM8150)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -0700147 acdb_init_v2_cvd_t acdb_init;
148#elif defined (PLATFORM_MSM8084)
149 acdb_init_v2_t acdb_init;
150#else
151 acdb_init_t acdb_init;
152#endif
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700153 acdb_deallocate_t acdb_deallocate;
154 acdb_send_audio_cal_t acdb_send_audio_cal;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800155 acdb_send_audio_cal_v3_t acdb_send_audio_cal_v3;
jasmine chac89321b2018-04-10 21:37:01 +0800156 acdb_set_audio_cal_t acdb_set_audio_cal;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700157 acdb_send_voice_cal_t acdb_send_voice_cal;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700158 acdb_reload_vocvoltable_t acdb_reload_vocvoltable;
vivek mehta1a9b7c02015-06-25 11:49:38 -0700159 acdb_send_gain_dep_cal_t acdb_send_gain_dep_cal;
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -0700160 acdb_send_custom_top_t acdb_send_custom_top;
161 bool acdb_initialized;
162
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700163 struct csd_data *csd;
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800164 char ec_ref_mixer_path[64];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700165
David Linee3fe402017-03-13 10:00:42 -0700166 codec_backend_cfg_t current_backend_cfg[MAX_CODEC_BACKENDS];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700167 char *snd_card_name;
keunhui.parkc5aaa0e2015-07-13 10:57:37 +0900168 int max_vol_index;
Prashant Malanic92c5962015-08-11 15:10:18 -0700169 int max_mic_count;
vivek mehtade4849c2016-03-03 17:23:38 -0800170
171 void *hw_info;
jiabin8962a4d2018-03-19 18:21:24 -0700172
173 uint32_t declared_mic_count;
174 struct audio_microphone_characteristic_t microphones[AUDIO_MICROPHONE_MAX_COUNT];
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -0700175 struct snd_device_to_mic_map mic_map[SND_DEVICE_MAX];
Eric Laurentb23d5282013-05-14 15:27:20 -0700176};
177
Haynes Mathew George98c95622014-06-20 19:14:25 -0700178static int pcm_device_table[AUDIO_USECASE_MAX][2] = {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700179 [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = {DEEP_BUFFER_PCM_DEVICE,
180 DEEP_BUFFER_PCM_DEVICE},
181 [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
182 LOWLATENCY_PCM_DEVICE},
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800183 [USECASE_AUDIO_PLAYBACK_HIFI] = {MULTIMEDIA2_PCM_DEVICE,
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700184 MULTIMEDIA2_PCM_DEVICE},
185 [USECASE_AUDIO_PLAYBACK_OFFLOAD] = {PLAYBACK_OFFLOAD_DEVICE,
186 PLAYBACK_OFFLOAD_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700187 [USECASE_AUDIO_PLAYBACK_TTS] = {MULTIMEDIA2_PCM_DEVICE,
188 MULTIMEDIA2_PCM_DEVICE},
189 [USECASE_AUDIO_PLAYBACK_ULL] = {MULTIMEDIA3_PCM_DEVICE,
190 MULTIMEDIA3_PCM_DEVICE},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800191 [USECASE_AUDIO_PLAYBACK_MMAP] = {MMAP_PLAYBACK_PCM_DEVICE,
192 MMAP_PLAYBACK_PCM_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700193
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700194 [USECASE_AUDIO_RECORD] = {AUDIO_RECORD_PCM_DEVICE,
195 AUDIO_RECORD_PCM_DEVICE},
196 [USECASE_AUDIO_RECORD_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
197 LOWLATENCY_PCM_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700198
Eric Laurent0e46adf2016-12-16 12:49:24 -0800199 [USECASE_AUDIO_RECORD_MMAP] = {MMAP_RECORD_PCM_DEVICE,
200 MMAP_RECORD_PCM_DEVICE},
Haynes Mathew George569b7482017-05-08 14:44:27 -0700201 [USECASE_AUDIO_RECORD_HIFI] = {MULTIMEDIA2_PCM_DEVICE,
202 MULTIMEDIA2_PCM_DEVICE},
203
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700204 [USECASE_VOICE_CALL] = {VOICE_CALL_PCM_DEVICE,
205 VOICE_CALL_PCM_DEVICE},
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700206 [USECASE_VOICE2_CALL] = {VOICE2_CALL_PCM_DEVICE, VOICE2_CALL_PCM_DEVICE},
207 [USECASE_VOLTE_CALL] = {VOLTE_CALL_PCM_DEVICE, VOLTE_CALL_PCM_DEVICE},
208 [USECASE_QCHAT_CALL] = {QCHAT_CALL_PCM_DEVICE, QCHAT_CALL_PCM_DEVICE},
209 [USECASE_VOWLAN_CALL] = {VOWLAN_CALL_PCM_DEVICE, VOWLAN_CALL_PCM_DEVICE},
vivek mehtaa51fd402016-02-04 19:49:33 -0800210 [USECASE_VOICEMMODE1_CALL] = {VOICEMMODE1_CALL_PCM_DEVICE,
211 VOICEMMODE1_CALL_PCM_DEVICE},
212 [USECASE_VOICEMMODE2_CALL] = {VOICEMMODE2_CALL_PCM_DEVICE,
213 VOICEMMODE2_CALL_PCM_DEVICE},
214
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700215 [USECASE_INCALL_REC_UPLINK] = {AUDIO_RECORD_PCM_DEVICE,
216 AUDIO_RECORD_PCM_DEVICE},
217 [USECASE_INCALL_REC_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
218 AUDIO_RECORD_PCM_DEVICE},
219 [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
220 AUDIO_RECORD_PCM_DEVICE},
Ravi Kumar Alamanda8e6e98f2013-11-05 15:57:39 -0800221 [USECASE_AUDIO_HFP_SCO] = {HFP_PCM_RX, HFP_SCO_RX},
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700222
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700223 [USECASE_AUDIO_SPKR_CALIB_RX] = {SPKR_PROT_CALIB_RX_PCM_DEVICE, -1},
224 [USECASE_AUDIO_SPKR_CALIB_TX] = {-1, SPKR_PROT_CALIB_TX_PCM_DEVICE},
225
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700226 [USECASE_AUDIO_PLAYBACK_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
227 AFE_PROXY_RECORD_PCM_DEVICE},
228 [USECASE_AUDIO_RECORD_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
229 AFE_PROXY_RECORD_PCM_DEVICE},
zhaoyang yin4211fad2015-06-04 21:13:25 +0800230 [USECASE_AUDIO_DSM_FEEDBACK] = {QUAT_MI2S_PCM_DEVICE, QUAT_MI2S_PCM_DEVICE},
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700231
vivek mehtaa68fea62017-06-08 19:04:02 -0700232 [USECASE_AUDIO_PLAYBACK_VOIP] = {AUDIO_PLAYBACK_VOIP_PCM_DEVICE,
233 AUDIO_PLAYBACK_VOIP_PCM_DEVICE},
234 [USECASE_AUDIO_RECORD_VOIP] = {AUDIO_RECORD_VOIP_PCM_DEVICE,
235 AUDIO_RECORD_VOIP_PCM_DEVICE},
Nadav Bar3d72cfc2018-01-07 12:19:24 +0200236
237 [USECASE_INCALL_MUSIC_UPLINK] = {INCALL_MUSIC_UPLINK_PCM_DEVICE,
238 INCALL_MUSIC_UPLINK_PCM_DEVICE},
Eric Laurentb23d5282013-05-14 15:27:20 -0700239};
240
241/* Array to store sound devices */
242static const char * const device_table[SND_DEVICE_MAX] = {
243 [SND_DEVICE_NONE] = "none",
244 /* Playback sound devices */
245 [SND_DEVICE_OUT_HANDSET] = "handset",
246 [SND_DEVICE_OUT_SPEAKER] = "speaker",
247 [SND_DEVICE_OUT_SPEAKER_REVERSE] = "speaker-reverse",
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700248 [SND_DEVICE_OUT_SPEAKER_SAFE] = "speaker-safe",
Eric Laurentb23d5282013-05-14 15:27:20 -0700249 [SND_DEVICE_OUT_HEADPHONES] = "headphones",
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500250 [SND_DEVICE_OUT_LINE] = "line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700251 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones",
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700252 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = "speaker-safe-and-headphones",
Eric Laurent744996b2014-10-01 11:40:40 -0500253 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = "speaker-and-line",
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700254 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = "speaker-safe-and-line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700255 [SND_DEVICE_OUT_VOICE_HANDSET] = "voice-handset",
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500256 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = "voice-hac-handset",
Eric Laurentb23d5282013-05-14 15:27:20 -0700257 [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker",
258 [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones",
yixuanjiang9536e672018-09-06 18:43:36 +0800259 [SND_DEVICE_OUT_VOICE_HEADSET] = "voice-headphones",
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500260 [SND_DEVICE_OUT_VOICE_LINE] = "voice-line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700261 [SND_DEVICE_OUT_HDMI] = "hdmi",
262 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi",
263 [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700264 [SND_DEVICE_OUT_BT_SCO_WB] = "bt-sco-headset-wb",
Aniket Kumar Lata26483012018-01-31 20:21:42 -0800265 [SND_DEVICE_OUT_BT_A2DP] = "bt-a2dp",
266 [SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] = "speaker-and-bt-a2dp",
Aniket Kumar Lata9723a962018-05-16 17:41:55 -0700267 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP] = "speaker-safe-and-bt-a2dp",
Eric Laurentb23d5282013-05-14 15:27:20 -0700268 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = "voice-handset-tmus",
269 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones",
270 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones",
271 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset",
vivek mehtaa6b79742017-03-09 15:40:43 -0800272 [SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = "voice-tty-full-usb",
273 [SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = "voice-tty-vco-usb",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700274 [SND_DEVICE_OUT_VOICE_TX] = "voice-tx",
juyuchen66c4ecf2018-08-06 15:39:34 +0800275 [SND_DEVICE_OUT_VOICE_MUSIC_TX] = "voice-music-tx",
David Linee3fe402017-03-13 10:00:42 -0700276 [SND_DEVICE_OUT_USB_HEADSET] = "usb-headset",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700277 [SND_DEVICE_OUT_VOICE_USB_HEADSET] = "usb-headset",
David Linee3fe402017-03-13 10:00:42 -0700278 [SND_DEVICE_OUT_USB_HEADPHONES] = "usb-headphones",
jasmine cha270b7762018-03-30 15:41:33 +0800279 [SND_DEVICE_OUT_USB_HEADSET_SPEC] = "usb-headset",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700280 [SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = "usb-headphones",
David Linee3fe402017-03-13 10:00:42 -0700281 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = "speaker-and-usb-headphones",
Haynes Mathew George9090bfb2017-05-31 11:44:50 -0700282 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] = "speaker-safe-and-usb-headphones",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700283 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = "speaker-protected",
284 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = "voice-speaker-protected",
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -0700285 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = "voice-speaker-hfp",
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -0800286 [SND_DEVICE_OUT_SPEAKER_AND_BT_SCO] = "speaker-and-bt-sco",
juyuchen5351ea62018-05-16 10:54:37 +0800287 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO] = "speaker-safe-and-bt-sco",
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -0800288 [SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB] = "speaker-and-bt-sco-wb",
juyuchen5351ea62018-05-16 10:54:37 +0800289 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB] = "speaker-safe-and-bt-sco-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700290
291 /* Capture sound devices */
292 [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700293 [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700294 [SND_DEVICE_IN_HANDSET_MIC_NS] = "handset-mic",
295 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = "handset-mic",
296 [SND_DEVICE_IN_HANDSET_DMIC] = "dmic-endfire",
297 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = "dmic-endfire",
298 [SND_DEVICE_IN_HANDSET_DMIC_NS] = "dmic-endfire",
299 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = "dmic-endfire",
300 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = "dmic-endfire",
301
302 [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
303 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "speaker-mic",
304 [SND_DEVICE_IN_SPEAKER_MIC_NS] = "speaker-mic",
305 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = "speaker-mic",
306 [SND_DEVICE_IN_SPEAKER_DMIC] = "speaker-dmic-endfire",
307 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = "speaker-dmic-endfire",
308 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = "speaker-dmic-endfire",
309 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = "speaker-dmic-endfire",
310 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = "speaker-dmic-endfire",
311
312 [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
Eric Laurentcefbbac2014-09-04 13:54:10 -0500313 [SND_DEVICE_IN_HEADSET_MIC_AEC] = "headset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700314
Eric Laurentb23d5282013-05-14 15:27:20 -0700315 [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic",
316 [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700317 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = "bt-sco-mic",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700318 [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700319 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = "bt-sco-mic-wb",
Eric Laurent5f4ca952018-10-19 17:33:43 -0700320 [SND_DEVICE_IN_CAMCORDER_LANDSCAPE] = "camcorder-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700321
322 [SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef",
323 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = "voice-dmic-ef-tmus",
324 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
325 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = "voice-speaker-dmic-ef",
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -0700326 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = "voice-speaker-mic-hfp",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700327 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700328 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
329 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
330 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
vivek mehtaa6b79742017-03-09 15:40:43 -0800331 [SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = "voice-tty-full-usb-mic",
332 [SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = "voice-tty-hco-usb-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700333
Eric Laurentb23d5282013-05-14 15:27:20 -0700334 [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700335 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = "voice-rec-mic",
vivek mehta733c1df2016-04-04 15:09:24 -0700336 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = "voice-rec-mic",
vivek mehtaf3440682016-05-11 14:24:37 -0700337 [SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700338 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = "voice-rec-dmic-ef",
339 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence",
David Linee3fe402017-03-13 10:00:42 -0700340 [SND_DEVICE_IN_USB_HEADSET_MIC] = "usb-headset-mic",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700341 [SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] ="usb-headset-mic",
342 [SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = "usb-headset-mic",
343 [SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = "usb-headset-mic",
344 [SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = "usb-headset-mic",
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700345 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = "headset-mic",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700346
Ricardo Garcia9034bc42016-04-04 07:11:46 -0700347 [SND_DEVICE_IN_UNPROCESSED_MIC] = "unprocessed-mic",
vivek mehta0125e782016-06-16 18:03:11 -0700348 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = "unprocessed-stereo-mic",
349 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = "unprocessed-three-mic",
350 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = "unprocessed-quad-mic",
351 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = "unprocessed-headset-mic",
rago90fb9612015-12-02 11:37:53 -0800352
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700353 [SND_DEVICE_IN_VOICE_RX] = "voice-rx",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700354
Prashant Malanic92c5962015-08-11 15:10:18 -0700355 [SND_DEVICE_IN_THREE_MIC] = "three-mic",
356 [SND_DEVICE_IN_QUAD_MIC] = "quad-mic",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700357 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = "vi-feedback",
Prashant Malanic92c5962015-08-11 15:10:18 -0700358 [SND_DEVICE_IN_HANDSET_TMIC] = "three-mic",
359 [SND_DEVICE_IN_HANDSET_QMIC] = "quad-mic",
vivek mehta733c1df2016-04-04 15:09:24 -0700360 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = "three-mic",
361 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = "quad-mic",
Eric Laurent5f4ca952018-10-19 17:33:43 -0700362 [SND_DEVICE_IN_CAMCORDER_INVERT_LANDSCAPE] = "camcorder-mic",
363 [SND_DEVICE_IN_CAMCORDER_PORTRAIT] = "camcorder-mic",
364 [SND_DEVICE_IN_CAMCORDER_SELFIE_LANDSCAPE] = "camcorder-mic",
365 [SND_DEVICE_IN_CAMCORDER_SELFIE_INVERT_LANDSCAPE] = "camcorder-mic",
366 [SND_DEVICE_IN_CAMCORDER_SELFIE_PORTRAIT] = "camcorder-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700367};
368
369/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700370static int acdb_device_table[SND_DEVICE_MAX] = {
Eric Laurentb23d5282013-05-14 15:27:20 -0700371 [SND_DEVICE_NONE] = -1,
372 [SND_DEVICE_OUT_HANDSET] = 7,
373 [SND_DEVICE_OUT_SPEAKER] = 15,
374 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 15,
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700375 [SND_DEVICE_OUT_SPEAKER_SAFE] = 15,
Eric Laurentb23d5282013-05-14 15:27:20 -0700376 [SND_DEVICE_OUT_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500377 [SND_DEVICE_OUT_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700378 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700379 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500380 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = 77,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700381 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = 77,
Ravi Kumar Alamanda235c3482014-08-21 17:32:44 -0700382 [SND_DEVICE_OUT_VOICE_HANDSET] = ACDB_ID_VOICE_HANDSET,
383 [SND_DEVICE_OUT_VOICE_SPEAKER] = ACDB_ID_VOICE_SPEAKER,
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500384 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = 53,
Eric Laurentb23d5282013-05-14 15:27:20 -0700385 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
yixuanjiang9536e672018-09-06 18:43:36 +0800386 [SND_DEVICE_OUT_VOICE_HEADSET] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500387 [SND_DEVICE_OUT_VOICE_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700388 [SND_DEVICE_OUT_HDMI] = 18,
389 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 15,
390 [SND_DEVICE_OUT_BT_SCO] = 22,
juyuchen5351ea62018-05-16 10:54:37 +0800391 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO] = 14,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700392 [SND_DEVICE_OUT_BT_SCO_WB] = 39,
juyuchen5351ea62018-05-16 10:54:37 +0800393 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB] = 14,
Aniket Kumar Lata26483012018-01-31 20:21:42 -0800394 [SND_DEVICE_OUT_BT_A2DP] = 20,
395 [SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] = 14,
Aniket Kumar Lata9723a962018-05-16 17:41:55 -0700396 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP] = 14,
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700397 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = ACDB_ID_VOICE_HANDSET_TMUS,
Eric Laurentb23d5282013-05-14 15:27:20 -0700398 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
399 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
400 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
vivek mehtaa6b79742017-03-09 15:40:43 -0800401 [SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = 17,
402 [SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = 17,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700403 [SND_DEVICE_OUT_VOICE_TX] = 45,
juyuchen66c4ecf2018-08-06 15:39:34 +0800404 [SND_DEVICE_OUT_VOICE_MUSIC_TX] = 3,
David Linee3fe402017-03-13 10:00:42 -0700405 [SND_DEVICE_OUT_USB_HEADSET] = 45,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700406 [SND_DEVICE_OUT_VOICE_USB_HEADSET] = 45,
David Linee3fe402017-03-13 10:00:42 -0700407 [SND_DEVICE_OUT_USB_HEADPHONES] = 45,
jasmine cha270b7762018-03-30 15:41:33 +0800408 [SND_DEVICE_OUT_USB_HEADSET_SPEC] = 45,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700409 [SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = 45,
David Linee3fe402017-03-13 10:00:42 -0700410 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = 14,
Haynes Mathew George9090bfb2017-05-31 11:44:50 -0700411 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] = 14,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700412 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = 124,
413 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = 101,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700414 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = ACDB_ID_VOICE_SPEAKER,
Eric Laurentb23d5282013-05-14 15:27:20 -0700415
416 [SND_DEVICE_IN_HANDSET_MIC] = 4,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700417 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 106,
418 [SND_DEVICE_IN_HANDSET_MIC_NS] = 107,
419 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = 108,
420 [SND_DEVICE_IN_HANDSET_DMIC] = 41,
421 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = 109,
422 [SND_DEVICE_IN_HANDSET_DMIC_NS] = 110,
423 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = 111,
424 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = 34,
425
426 [SND_DEVICE_IN_SPEAKER_MIC] = 11,
427 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 112,
428 [SND_DEVICE_IN_SPEAKER_MIC_NS] = 113,
429 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = 114,
430 [SND_DEVICE_IN_SPEAKER_DMIC] = 43,
431 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = 115,
432 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = 116,
433 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = 117,
434 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = 35,
435
rago90fb9612015-12-02 11:37:53 -0800436 [SND_DEVICE_IN_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentcefbbac2014-09-04 13:54:10 -0500437 [SND_DEVICE_IN_HEADSET_MIC_AEC] = ACDB_ID_HEADSET_MIC_AEC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700438
Eric Laurentb23d5282013-05-14 15:27:20 -0700439 [SND_DEVICE_IN_HDMI_MIC] = 4,
440 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700441 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = 21,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700442 [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700443 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = 38,
Eric Laurent5f4ca952018-10-19 17:33:43 -0700444 [SND_DEVICE_IN_CAMCORDER_LANDSCAPE] = 61,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700445
446 [SND_DEVICE_IN_VOICE_DMIC] = 41,
447 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = ACDB_ID_VOICE_DMIC_EF_TMUS,
448 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700449 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = 11,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700450 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 43,
rago90fb9612015-12-02 11:37:53 -0800451 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentb23d5282013-05-14 15:27:20 -0700452 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
453 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
454 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
vivek mehtaa6b79742017-03-09 15:40:43 -0800455 [SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = 16,
456 [SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = 16,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700457
rago90fb9612015-12-02 11:37:53 -0800458 [SND_DEVICE_IN_VOICE_REC_MIC] = ACDB_ID_VOICE_REC_MIC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700459 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = 113,
vivek mehta733c1df2016-04-04 15:09:24 -0700460 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = 112,
vivek mehtaf3440682016-05-11 14:24:37 -0700461 [SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = 114,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700462 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = 35,
463 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 43,
rago90fb9612015-12-02 11:37:53 -0800464 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
465
466 [SND_DEVICE_IN_UNPROCESSED_MIC] = ACDB_ID_VOICE_REC_MIC,
467 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
vivek mehta4ed66e62016-04-15 23:33:34 -0700468 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = 35,
469 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = 125,
470 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = 125,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700471
472 [SND_DEVICE_IN_VOICE_RX] = 44,
David Linee3fe402017-03-13 10:00:42 -0700473 [SND_DEVICE_IN_USB_HEADSET_MIC] = 44,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700474 [SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = 44,
475 [SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = 44,
476 [SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = 44,
477 [SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = 44,
Prashant Malanic92c5962015-08-11 15:10:18 -0700478 [SND_DEVICE_IN_THREE_MIC] = 46,
479 [SND_DEVICE_IN_QUAD_MIC] = 46,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700480 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = 102,
Prashant Malanic92c5962015-08-11 15:10:18 -0700481 [SND_DEVICE_IN_HANDSET_TMIC] = 125,
482 [SND_DEVICE_IN_HANDSET_QMIC] = 125,
vivek mehta733c1df2016-04-04 15:09:24 -0700483 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = 125, /* override this for new target to 140 */
484 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = 125, /* override this for new target to 140 */
Eric Laurent5f4ca952018-10-19 17:33:43 -0700485 [SND_DEVICE_IN_CAMCORDER_INVERT_LANDSCAPE] = 61,
486 [SND_DEVICE_IN_CAMCORDER_PORTRAIT] = 61,
487 [SND_DEVICE_IN_CAMCORDER_SELFIE_LANDSCAPE] = 61,
488 [SND_DEVICE_IN_CAMCORDER_SELFIE_INVERT_LANDSCAPE] = 61,
489 [SND_DEVICE_IN_CAMCORDER_SELFIE_PORTRAIT] = 61,
Eric Laurentb23d5282013-05-14 15:27:20 -0700490};
491
David Linee3fe402017-03-13 10:00:42 -0700492// Platform specific backend bit width table
493static int backend_bit_width_table[SND_DEVICE_MAX] = {0};
494
Haynes Mathew George98c95622014-06-20 19:14:25 -0700495struct name_to_index {
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700496 char name[100];
497 unsigned int index;
498};
499
500#define TO_NAME_INDEX(X) #X, X
501
Haynes Mathew George98c95622014-06-20 19:14:25 -0700502/* Used to get index from parsed string */
503static const struct name_to_index snd_device_name_index[SND_DEVICE_MAX] = {
504 /* out */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700505 {TO_NAME_INDEX(SND_DEVICE_OUT_HANDSET)},
506 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER)},
507 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_REVERSE)},
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700508 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700509 {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500510 {TO_NAME_INDEX(SND_DEVICE_OUT_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700511 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700512 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES)},
Eric Laurent744996b2014-10-01 11:40:40 -0500513 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_LINE)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700514 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700515 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET)},
516 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700517 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_HFP)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700518 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADPHONES)},
yixuanjiang9536e672018-09-06 18:43:36 +0800519 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADSET)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500520 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700521 {TO_NAME_INDEX(SND_DEVICE_OUT_HDMI)},
522 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HDMI)},
523 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO)},
juyuchen5351ea62018-05-16 10:54:37 +0800524 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700525 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO_WB)},
juyuchen5351ea62018-05-16 10:54:37 +0800526 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB)},
Aniket Kumar Lata26483012018-01-31 20:21:42 -0800527 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_A2DP)},
528 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP)},
Aniket Kumar Lata9723a962018-05-16 17:41:55 -0700529 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700530 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET_TMUS)},
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500531 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HAC_HANDSET)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700532 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES)},
533 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES)},
534 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET)},
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -0800535 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_SCO)},
536 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800537 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_USB)},
538 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_USB)},
David Linee3fe402017-03-13 10:00:42 -0700539 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADSET)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700540 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_USB_HEADSET)},
David Linee3fe402017-03-13 10:00:42 -0700541 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADPHONES)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700542 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_USB_HEADPHONES)},
David Linee3fe402017-03-13 10:00:42 -0700543 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET)},
Haynes Mathew George9090bfb2017-05-31 11:44:50 -0700544 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700545 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED)},
546 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED)},
jasmine cha270b7762018-03-30 15:41:33 +0800547 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADSET_SPEC)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800548
549 /* in */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700550 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700551 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700552 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_NS)},
553 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)},
554 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC)},
555 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC)},
556 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_NS)},
557 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)},
558 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_STEREO)},
559
560 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700561 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700562 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_NS)},
563 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)},
564 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC)},
565 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC)},
566 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS)},
567 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)},
568 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_STEREO)},
569
570 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC)},
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700571 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700572
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700573 {TO_NAME_INDEX(SND_DEVICE_IN_HDMI_MIC)},
574 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700575 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700576 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700577 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB_NREC)},
Eric Laurent5f4ca952018-10-19 17:33:43 -0700578 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_LANDSCAPE)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700579
580 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC)},
581 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC_TMUS)},
582 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700583 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700584 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC)},
585 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEADSET_MIC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700586 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC)},
587 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC)},
588 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800589 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC)},
590 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC)},
591
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700592
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700593 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700594 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_NS)},
vivek mehta733c1df2016-04-04 15:09:24 -0700595 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC)},
vivek mehtaf3440682016-05-11 14:24:37 -0700596 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700597 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_STEREO)},
598 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE)},
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700599 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_HEADSET_MIC)},
David Linee3fe402017-03-13 10:00:42 -0700600 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700601 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_USB_HEADSET_MIC)},
602 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC)},
603 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC)},
604 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC_AEC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700605
rago90fb9612015-12-02 11:37:53 -0800606 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_MIC)},
607 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC)},
vivek mehta4ed66e62016-04-15 23:33:34 -0700608 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_STEREO_MIC)},
609 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_THREE_MIC)},
610 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_QUAD_MIC)},
rago90fb9612015-12-02 11:37:53 -0800611
Prashant Malanic92c5962015-08-11 15:10:18 -0700612 {TO_NAME_INDEX(SND_DEVICE_IN_THREE_MIC)},
613 {TO_NAME_INDEX(SND_DEVICE_IN_QUAD_MIC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700614 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_VI_FEEDBACK)},
Prashant Malanic92c5962015-08-11 15:10:18 -0700615 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC)},
616 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC)},
vivek mehta733c1df2016-04-04 15:09:24 -0700617 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC_AEC)},
618 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC_AEC)},
Eric Laurent5f4ca952018-10-19 17:33:43 -0700619 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_INVERT_LANDSCAPE)},
620 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_PORTRAIT)},
621 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_SELFIE_LANDSCAPE)},
622 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_SELFIE_INVERT_LANDSCAPE)},
623 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_SELFIE_PORTRAIT)},
624 /* For legacy xml file parsing */
625 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700626};
627
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700628static char * backend_tag_table[SND_DEVICE_MAX] = {0};
629static char * hw_interface_table[SND_DEVICE_MAX] = {0};
Haynes Mathew George98c95622014-06-20 19:14:25 -0700630
631static const struct name_to_index usecase_name_index[AUDIO_USECASE_MAX] = {
632 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_DEEP_BUFFER)},
633 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_LOW_LATENCY)},
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800634 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_HIFI)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700635 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD)},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700636 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_TTS)},
637 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_ULL)},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800638 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_MMAP)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700639 {TO_NAME_INDEX(USECASE_AUDIO_RECORD)},
640 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_LOW_LATENCY)},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800641 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_MMAP)},
Haynes Mathew George569b7482017-05-08 14:44:27 -0700642 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_HIFI)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700643 {TO_NAME_INDEX(USECASE_VOICE_CALL)},
644 {TO_NAME_INDEX(USECASE_VOICE2_CALL)},
645 {TO_NAME_INDEX(USECASE_VOLTE_CALL)},
646 {TO_NAME_INDEX(USECASE_QCHAT_CALL)},
647 {TO_NAME_INDEX(USECASE_VOWLAN_CALL)},
John Muirf1346ce2016-12-06 00:03:41 -0800648 {TO_NAME_INDEX(USECASE_VOICEMMODE1_CALL)},
649 {TO_NAME_INDEX(USECASE_VOICEMMODE2_CALL)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700650 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK)},
651 {TO_NAME_INDEX(USECASE_INCALL_REC_DOWNLINK)},
652 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK_AND_DOWNLINK)},
653 {TO_NAME_INDEX(USECASE_AUDIO_HFP_SCO)},
John Muirf1346ce2016-12-06 00:03:41 -0800654 {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_RX)},
655 {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_TX)},
656 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_AFE_PROXY)},
657 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_AFE_PROXY)},
658 {TO_NAME_INDEX(USECASE_AUDIO_DSM_FEEDBACK)},
vivek mehtaa68fea62017-06-08 19:04:02 -0700659 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_VOIP)},
660 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_VOIP)},
Nadav Bar3d72cfc2018-01-07 12:19:24 +0200661 {TO_NAME_INDEX(USECASE_INCALL_MUSIC_UPLINK)},
Aniket Kumar Lata99546312018-03-19 21:38:38 -0700662 {TO_NAME_INDEX(USECASE_AUDIO_A2DP_ABR_FEEDBACK)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700663};
664
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800665static const struct name_to_index usecase_type_index[USECASE_TYPE_MAX] = {
666 {TO_NAME_INDEX(PCM_PLAYBACK)},
667 {TO_NAME_INDEX(PCM_CAPTURE)},
668 {TO_NAME_INDEX(VOICE_CALL)},
669 {TO_NAME_INDEX(PCM_HFP_CALL)},
670};
671
672struct app_type_entry {
673 int uc_type;
674 int bit_width;
675 int app_type;
676 int max_rate;
vivek mehtaa68fea62017-06-08 19:04:02 -0700677 char *mode;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800678 struct listnode node; // membership in app_type_entry_list;
679};
680
681static struct listnode app_type_entry_list;
682
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700683#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
684#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
Eric Laurent0e46adf2016-12-16 12:49:24 -0800685#define ULL_PLATFORM_DELAY (3*1000LL)
686#define MMAP_PLATFORM_DELAY (3*1000LL)
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700687
Eric Laurentb23d5282013-05-14 15:27:20 -0700688static pthread_once_t check_op_once_ctl = PTHREAD_ONCE_INIT;
689static bool is_tmus = false;
690
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800691static int init_be_dai_name_table(struct audio_device *adev);
692
Eric Laurentb23d5282013-05-14 15:27:20 -0700693static void check_operator()
694{
695 char value[PROPERTY_VALUE_MAX];
696 int mccmnc;
697 property_get("gsm.sim.operator.numeric",value,"0");
698 mccmnc = atoi(value);
Eric Laurent2bafff12016-03-17 12:17:23 -0700699 ALOGD("%s: tmus mccmnc %d", __func__, mccmnc);
Eric Laurentb23d5282013-05-14 15:27:20 -0700700 switch(mccmnc) {
701 /* TMUS MCC(310), MNC(490, 260, 026) */
702 case 310490:
703 case 310260:
704 case 310026:
sangwon.jeonb891db52013-09-14 17:39:15 +0900705 /* Add new TMUS MNC(800, 660, 580, 310, 270, 250, 240, 230, 220, 210, 200, 160) */
706 case 310800:
707 case 310660:
708 case 310580:
709 case 310310:
710 case 310270:
711 case 310250:
712 case 310240:
713 case 310230:
714 case 310220:
715 case 310210:
716 case 310200:
717 case 310160:
Eric Laurentb23d5282013-05-14 15:27:20 -0700718 is_tmus = true;
719 break;
720 }
721}
722
723bool is_operator_tmus()
724{
725 pthread_once(&check_op_once_ctl, check_operator);
726 return is_tmus;
727}
728
keunhui.park2f7306a2015-07-16 16:48:06 +0900729static char *get_current_operator()
730{
731 struct listnode *node;
732 struct operator_info *info_item;
733 char mccmnc[PROPERTY_VALUE_MAX];
734 char *ret = NULL;
735
Tom Cherry7fea2042016-11-10 18:05:59 -0800736 property_get("gsm.sim.operator.numeric",mccmnc,"00000");
keunhui.park2f7306a2015-07-16 16:48:06 +0900737
738 list_for_each(node, &operator_info_list) {
739 info_item = node_to_item(node, struct operator_info, list);
740 if (strstr(info_item->mccmnc, mccmnc) != NULL) {
741 ret = info_item->name;
742 }
743 }
744
745 return ret;
746}
747
748static struct operator_specific_device *get_operator_specific_device(snd_device_t snd_device)
749{
750 struct listnode *node;
751 struct operator_specific_device *ret = NULL;
752 struct operator_specific_device *device_item;
753 char *operator_name;
754
755 operator_name = get_current_operator();
756 if (operator_name == NULL)
757 return ret;
758
759 list_for_each(node, operator_specific_device_table[snd_device]) {
760 device_item = node_to_item(node, struct operator_specific_device, list);
761 if (strcmp(operator_name, device_item->operator) == 0) {
762 ret = device_item;
763 }
764 }
765
766 return ret;
767}
768
769
770static int get_operator_specific_device_acdb_id(snd_device_t snd_device)
771{
772 struct operator_specific_device *device;
773 int ret = acdb_device_table[snd_device];
774
775 device = get_operator_specific_device(snd_device);
776 if (device != NULL)
777 ret = device->acdb_id;
778
779 return ret;
780}
781
782static const char *get_operator_specific_device_mixer_path(snd_device_t snd_device)
783{
784 struct operator_specific_device *device;
785 const char *ret = device_table[snd_device];
786
787 device = get_operator_specific_device(snd_device);
788 if (device != NULL)
789 ret = device->mixer_path;
790
791 return ret;
792}
793
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800794inline bool platform_supports_app_type_cfg()
795{
Thierry Strudel07f96d12018-09-20 13:31:34 -0700796#if defined (PLATFORM_MSM8998) || (PLATFORM_SDM845) || (PLATFORM_SDM710) || (PLATFORM_SM8150)
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800797 return true;
798#else
799 return false;
800#endif
801}
802
jasmine chac89321b2018-04-10 21:37:01 +0800803static int parse_audiocal_cfg(struct str_parms *parms, acdb_audio_cal_cfg_t *cal)
804{
805 int err;
806 char value[64];
807 int ret = 0;
808
809 if (parms == NULL || cal == NULL)
810 return ret;
811
812 err = str_parms_get_str(parms, "cal_persist", value, sizeof(value));
813 if (err >= 0) {
814 str_parms_del(parms, "cal_persist");
815 cal->persist = (uint32_t)strtoul(value, NULL, 0);
816 ret = ret | 0x1;
817 }
818 err = str_parms_get_str(parms, "cal_apptype", value, sizeof(value));
819 if (err >= 0) {
820 str_parms_del(parms, "cal_apptype");
821 cal->app_type = (uint32_t)strtoul(value, NULL, 0);
822 ret = ret | 0x2;
823 }
824 err = str_parms_get_str(parms, "cal_caltype", value, sizeof(value));
825 if (err >= 0) {
826 str_parms_del(parms, "cal_caltype");
827 cal->cal_type = (uint32_t)strtoul(value, NULL, 0);
828 ret = ret | 0x4;
829 }
830 err = str_parms_get_str(parms, "cal_samplerate", value, sizeof(value));
831 if (err >= 0) {
832 str_parms_del(parms, "cal_samplerate");
833 cal->sampling_rate = (uint32_t)strtoul(value, NULL, 0);
834 ret = ret | 0x8;
835 }
836 err = str_parms_get_str(parms, "cal_devid", value, sizeof(value));
837 if (err >= 0) {
838 str_parms_del(parms, "cal_devid");
839 cal->dev_id = (uint32_t)strtoul(value, NULL, 0);
840 ret = ret | 0x10;
841 }
842 err = str_parms_get_str(parms, "cal_snddevid", value, sizeof(value));
843 if (err >= 0) {
844 str_parms_del(parms, "cal_snddevid");
845 cal->snd_dev_id = (uint32_t)strtoul(value, NULL, 0);
846 ret = ret | 0x20;
847 }
848 err = str_parms_get_str(parms, "cal_topoid", value, sizeof(value));
849 if (err >= 0) {
850 str_parms_del(parms, "cal_topoid");
851 cal->topo_id = (uint32_t)strtoul(value, NULL, 0);
852 ret = ret | 0x40;
853 }
854 err = str_parms_get_str(parms, "cal_moduleid", value, sizeof(value));
855 if (err >= 0) {
856 str_parms_del(parms, "cal_moduleid");
857 cal->module_id = (uint32_t)strtoul(value, NULL, 0);
858 ret = ret | 0x80;
859 }
860 err = str_parms_get_str(parms, "cal_paramid", value, sizeof(value));
861 if (err >= 0) {
862 str_parms_del(parms, "cal_paramid");
863 cal->param_id = (uint32_t)strtoul(value, NULL, 0);
864 ret = ret | 0x100;
865 }
866 return ret;
867}
868
869static void set_audiocal(void *platform, struct str_parms *parms, char *value, int len)
870{
871 struct platform_data *my_data = (struct platform_data *)platform;
872 acdb_audio_cal_cfg_t cal;
873 uint8_t *dptr = NULL;
874 int32_t dlen = 0;
875 int err ,ret;
876
877 if (value == NULL || platform == NULL || parms == NULL) {
878 ALOGE("[%s] received null pointer, failed", __func__);
879 goto done_key_audcal;
880 }
881
882 memset(&cal, 0, sizeof(acdb_audio_cal_cfg_t));
883 /* parse audio calibration keys */
884 ret = parse_audiocal_cfg(parms, &cal);
885
886 /* handle audio calibration data now */
887 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_AUD_CALDATA, value, len);
888 if (err >= 0) {
889 str_parms_del(parms, AUDIO_PARAMETER_KEY_AUD_CALDATA);
890 dlen = strlen(value);
891 if (dlen <= 0) {
892 ALOGE("[%s] null data received", __func__);
893 goto done_key_audcal;
894 }
895 /*
896 The base64 encoded string is always larger than the binary data,
897 so b64_pton will always output less data than provided (around 1/3
898 less than the input data). That's why we can allocate input buffer
899 length and then get function work.
900 */
901 dptr = (uint8_t *)calloc(dlen, sizeof(uint8_t));
902 if (dptr == NULL) {
903 ALOGE("[%s] memory allocation failed for %d", __func__, dlen);
904 goto done_key_audcal;
905 }
906 dlen = b64_pton(value, dptr, dlen);
907 if (dlen <= 0) {
908 ALOGE("[%s] data decoding failed %d", __func__, dlen);
909 goto done_key_audcal;
910 }
911
912 if (cal.dev_id) {
913 if (audio_is_input_device(cal.dev_id)) {
914 cal.snd_dev_id = platform_get_input_snd_device(platform, cal.dev_id);
915 } else {
916 cal.snd_dev_id = platform_get_output_snd_device(platform, cal.dev_id);
917 }
918 }
919 cal.acdb_dev_id = platform_get_snd_device_acdb_id(cal.snd_dev_id);
920 ALOGD("Setting audio calibration for snd_device(%d) acdb_id(%d)",
921 cal.snd_dev_id, cal.acdb_dev_id);
922 if (cal.acdb_dev_id == -EINVAL) {
923 ALOGE("[%s] Invalid acdb_device id %d for snd device id %d",
924 __func__, cal.acdb_dev_id, cal.snd_dev_id);
925 goto done_key_audcal;
926 }
927 if (my_data->acdb_set_audio_cal) {
928 ret = my_data->acdb_set_audio_cal((void *)&cal, (void *)dptr, dlen);
929 }
930 }
931done_key_audcal:
932 if (dptr != NULL)
933 free(dptr);
934}
935
vivek mehta1a9b7c02015-06-25 11:49:38 -0700936bool platform_send_gain_dep_cal(void *platform, int level)
937{
938 bool ret_val = false;
939 struct platform_data *my_data = (struct platform_data *)platform;
940 struct audio_device *adev = my_data->adev;
941 int acdb_dev_id, app_type;
942 int acdb_dev_type = MSM_SNDDEV_CAP_RX;
943 int mode = CAL_MODE_RTAC;
944 struct listnode *node;
945 struct audio_usecase *usecase;
Haynes Mathew George67486e22017-06-26 12:58:38 -0700946 bool valid_uc_type;
947 bool valid_dev;
vivek mehta1a9b7c02015-06-25 11:49:38 -0700948
949 if (my_data->acdb_send_gain_dep_cal == NULL) {
950 ALOGE("%s: dlsym error for acdb_send_gain_dep_cal", __func__);
951 return ret_val;
952 }
953
954 if (!voice_is_in_call(adev)) {
955 ALOGV("%s: Not Voice call usecase, apply new cal for level %d",
956 __func__, level);
vivek mehta1a9b7c02015-06-25 11:49:38 -0700957
958 // find the current active sound device
959 list_for_each(node, &adev->usecase_list) {
960 usecase = node_to_item(node, struct audio_usecase, list);
Haynes Mathew George67486e22017-06-26 12:58:38 -0700961 LOG_ALWAYS_FATAL_IF(usecase == NULL,
962 "unxpected NULL usecase in usecase_list");
963 valid_uc_type = usecase->type == PCM_PLAYBACK;
964 valid_dev = false;
965 if (valid_uc_type) {
966 audio_devices_t dev = usecase->stream.out->devices;
967 valid_dev = (dev == AUDIO_DEVICE_OUT_SPEAKER ||
vivek mehta40125092017-08-21 18:48:51 -0700968 dev == AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Haynes Mathew George67486e22017-06-26 12:58:38 -0700969 dev == AUDIO_DEVICE_OUT_WIRED_HEADSET ||
970 dev == AUDIO_DEVICE_OUT_WIRED_HEADPHONE);
971 }
972 if (valid_dev) {
vivek mehta40125092017-08-21 18:48:51 -0700973 ALOGV("%s: out device is %d", __func__, usecase->out_snd_device);
974 if (platform_supports_app_type_cfg())
975 app_type = usecase->stream.out->app_type_cfg.app_type;
976 else
977 app_type = DEFAULT_APP_TYPE_RX_PATH;
vivek mehta4cb82982015-07-13 12:05:49 -0700978
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -0700979 acdb_dev_id = platform_get_snd_device_acdb_id(usecase->out_snd_device);
vivek mehta40125092017-08-21 18:48:51 -0700980
981 if (!my_data->acdb_send_gain_dep_cal(acdb_dev_id, app_type,
vivek mehta1a9b7c02015-06-25 11:49:38 -0700982 acdb_dev_type, mode, level)) {
983 // set ret_val true if at least one calibration is set successfully
984 ret_val = true;
985 } else {
986 ALOGE("%s: my_data->acdb_send_gain_dep_cal failed ", __func__);
987 }
988 } else {
989 ALOGW("%s: Usecase list is empty", __func__);
990 }
991 }
992 } else {
993 ALOGW("%s: Voice call in progress .. ignore setting new cal",
994 __func__);
995 }
996 return ret_val;
997}
998
Eric Laurentcefbbac2014-09-04 13:54:10 -0500999void platform_set_echo_reference(struct audio_device *adev, bool enable, audio_devices_t out_device)
Eric Laurentb23d5282013-05-14 15:27:20 -07001000{
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08001001 struct platform_data *my_data = (struct platform_data *)adev->platform;
Eric Laurentcefbbac2014-09-04 13:54:10 -05001002 snd_device_t snd_device = SND_DEVICE_NONE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001003
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08001004 if (strcmp(my_data->ec_ref_mixer_path, "")) {
1005 ALOGV("%s: diabling %s", __func__, my_data->ec_ref_mixer_path);
1006 audio_route_reset_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
Eric Laurentcefbbac2014-09-04 13:54:10 -05001007 }
1008
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08001009 if (enable) {
1010 strcpy(my_data->ec_ref_mixer_path, "echo-reference");
1011 if (out_device != AUDIO_DEVICE_NONE) {
1012 snd_device = platform_get_output_snd_device(adev->platform, out_device);
1013 platform_add_backend_name(adev->platform, my_data->ec_ref_mixer_path, snd_device);
1014 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05001015
Joe Onorato188b6222016-03-01 11:02:27 -08001016 ALOGV("%s: enabling %s", __func__, my_data->ec_ref_mixer_path);
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08001017 audio_route_apply_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
1018 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001019}
1020
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001021static struct csd_data *open_csd_client(bool i2s_ext_modem)
1022{
1023 struct csd_data *csd = calloc(1, sizeof(struct csd_data));
1024
1025 csd->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
1026 if (csd->csd_client == NULL) {
1027 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
1028 goto error;
1029 } else {
1030 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
1031
1032 csd->deinit = (deinit_t)dlsym(csd->csd_client,
1033 "csd_client_deinit");
1034 if (csd->deinit == NULL) {
1035 ALOGE("%s: dlsym error %s for csd_client_deinit", __func__,
1036 dlerror());
1037 goto error;
1038 }
1039 csd->disable_device = (disable_device_t)dlsym(csd->csd_client,
1040 "csd_client_disable_device");
1041 if (csd->disable_device == NULL) {
1042 ALOGE("%s: dlsym error %s for csd_client_disable_device",
1043 __func__, dlerror());
1044 goto error;
1045 }
1046 csd->enable_device_config = (enable_device_config_t)dlsym(csd->csd_client,
1047 "csd_client_enable_device_config");
1048 if (csd->enable_device_config == NULL) {
1049 ALOGE("%s: dlsym error %s for csd_client_enable_device_config",
1050 __func__, dlerror());
1051 goto error;
1052 }
1053 csd->enable_device = (enable_device_t)dlsym(csd->csd_client,
1054 "csd_client_enable_device");
1055 if (csd->enable_device == NULL) {
1056 ALOGE("%s: dlsym error %s for csd_client_enable_device",
1057 __func__, dlerror());
1058 goto error;
1059 }
1060 csd->start_voice = (start_voice_t)dlsym(csd->csd_client,
1061 "csd_client_start_voice");
1062 if (csd->start_voice == NULL) {
1063 ALOGE("%s: dlsym error %s for csd_client_start_voice",
1064 __func__, dlerror());
1065 goto error;
1066 }
1067 csd->stop_voice = (stop_voice_t)dlsym(csd->csd_client,
1068 "csd_client_stop_voice");
1069 if (csd->stop_voice == NULL) {
1070 ALOGE("%s: dlsym error %s for csd_client_stop_voice",
1071 __func__, dlerror());
1072 goto error;
1073 }
1074 csd->volume = (volume_t)dlsym(csd->csd_client,
1075 "csd_client_volume");
1076 if (csd->volume == NULL) {
1077 ALOGE("%s: dlsym error %s for csd_client_volume",
1078 __func__, dlerror());
1079 goto error;
1080 }
1081 csd->mic_mute = (mic_mute_t)dlsym(csd->csd_client,
1082 "csd_client_mic_mute");
1083 if (csd->mic_mute == NULL) {
1084 ALOGE("%s: dlsym error %s for csd_client_mic_mute",
1085 __func__, dlerror());
1086 goto error;
1087 }
1088 csd->slow_talk = (slow_talk_t)dlsym(csd->csd_client,
1089 "csd_client_slow_talk");
1090 if (csd->slow_talk == NULL) {
1091 ALOGE("%s: dlsym error %s for csd_client_slow_talk",
1092 __func__, dlerror());
1093 goto error;
1094 }
1095 csd->start_playback = (start_playback_t)dlsym(csd->csd_client,
1096 "csd_client_start_playback");
1097 if (csd->start_playback == NULL) {
1098 ALOGE("%s: dlsym error %s for csd_client_start_playback",
1099 __func__, dlerror());
1100 goto error;
1101 }
1102 csd->stop_playback = (stop_playback_t)dlsym(csd->csd_client,
1103 "csd_client_stop_playback");
1104 if (csd->stop_playback == NULL) {
1105 ALOGE("%s: dlsym error %s for csd_client_stop_playback",
1106 __func__, dlerror());
1107 goto error;
1108 }
1109 csd->start_record = (start_record_t)dlsym(csd->csd_client,
1110 "csd_client_start_record");
1111 if (csd->start_record == NULL) {
1112 ALOGE("%s: dlsym error %s for csd_client_start_record",
1113 __func__, dlerror());
1114 goto error;
1115 }
1116 csd->stop_record = (stop_record_t)dlsym(csd->csd_client,
1117 "csd_client_stop_record");
1118 if (csd->stop_record == NULL) {
1119 ALOGE("%s: dlsym error %s for csd_client_stop_record",
1120 __func__, dlerror());
1121 goto error;
1122 }
1123
1124 csd->get_sample_rate = (get_sample_rate_t)dlsym(csd->csd_client,
1125 "csd_client_get_sample_rate");
1126 if (csd->get_sample_rate == NULL) {
1127 ALOGE("%s: dlsym error %s for csd_client_get_sample_rate",
1128 __func__, dlerror());
1129
1130 goto error;
1131 }
1132
1133 csd->init = (init_t)dlsym(csd->csd_client, "csd_client_init");
1134
1135 if (csd->init == NULL) {
1136 ALOGE("%s: dlsym error %s for csd_client_init",
1137 __func__, dlerror());
1138 goto error;
1139 } else {
1140 csd->init(i2s_ext_modem);
1141 }
1142 }
1143 return csd;
1144
1145error:
1146 free(csd);
1147 csd = NULL;
1148 return csd;
1149}
1150
1151void close_csd_client(struct csd_data *csd)
1152{
1153 if (csd != NULL) {
1154 csd->deinit();
1155 dlclose(csd->csd_client);
1156 free(csd);
1157 csd = NULL;
1158 }
1159}
1160
1161static void platform_csd_init(struct platform_data *my_data)
1162{
1163#ifdef PLATFORM_MSM8084
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001164 int32_t modems, (*count_modems)(void);
1165 const char *name = "libdetectmodem.so";
1166 const char *func = "count_modems";
1167 const char *error;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001168
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001169 my_data->csd = NULL;
1170
1171 void *lib = dlopen(name, RTLD_NOW);
1172 error = dlerror();
1173 if (!lib) {
1174 ALOGE("%s: could not find %s: %s", __func__, name, error);
1175 return;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001176 }
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001177
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001178 count_modems = NULL;
1179 *(void **)(&count_modems) = dlsym(lib, func);
1180 error = dlerror();
1181 if (!count_modems) {
1182 ALOGE("%s: could not find symbol %s in %s: %s",
1183 __func__, func, name, error);
1184 goto done;
1185 }
1186
1187 modems = count_modems();
1188 if (modems < 0) {
1189 ALOGE("%s: count_modems failed\n", __func__);
1190 goto done;
1191 }
1192
Eric Laurent2bafff12016-03-17 12:17:23 -07001193 ALOGD("%s: num_modems %d\n", __func__, modems);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001194 if (modems > 0)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001195 my_data->csd = open_csd_client(false /*is_i2s_ext_modem*/);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001196
1197done:
1198 dlclose(lib);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001199#else
1200 my_data->csd = NULL;
1201#endif
1202}
1203
Eric Laurentc6333382015-09-14 12:43:44 -07001204static void set_platform_defaults(struct platform_data * my_data)
Haynes Mathew George98c95622014-06-20 19:14:25 -07001205{
1206 int32_t dev;
1207 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001208 backend_tag_table[dev] = NULL;
1209 hw_interface_table[dev] = NULL;
keunhui.park2f7306a2015-07-16 16:48:06 +09001210 operator_specific_device_table[dev] = NULL;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001211 }
1212
David Linee3fe402017-03-13 10:00:42 -07001213 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1214 backend_bit_width_table[dev] = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
1215 }
1216
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001217 // To overwrite these go to the audio_platform_info.xml file.
1218 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("bt-sco");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07001219 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("bt-sco");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001220 backend_tag_table[SND_DEVICE_OUT_BT_SCO] = strdup("bt-sco");
1221 backend_tag_table[SND_DEVICE_OUT_HDMI] = strdup("hdmi");
1222 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("speaker-and-hdmi");
1223 backend_tag_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("bt-sco-wb");
1224 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("bt-sco-wb");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07001225 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("bt-sco-wb");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001226 backend_tag_table[SND_DEVICE_OUT_VOICE_TX] = strdup("afe-proxy");
1227 backend_tag_table[SND_DEVICE_IN_VOICE_RX] = strdup("afe-proxy");
Haynes Mathew George98c95622014-06-20 19:14:25 -07001228
David Linee3fe402017-03-13 10:00:42 -07001229 backend_tag_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("usb-headset");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001230 backend_tag_table[SND_DEVICE_OUT_VOICE_USB_HEADSET] = strdup("usb-headset");
David Linee3fe402017-03-13 10:00:42 -07001231 backend_tag_table[SND_DEVICE_OUT_USB_HEADPHONES] = strdup("usb-headphones");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001232 backend_tag_table[SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = strdup("usb-headphones");
David Linee3fe402017-03-13 10:00:42 -07001233 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] =
1234 strdup("speaker-and-usb-headphones");
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07001235 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] =
1236 strdup("speaker-safe-and-usb-headphones");
juyuchen5351ea62018-05-16 10:54:37 +08001237 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO] =
1238 strdup("speaker-safe-and-bt-sco"),
1239 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB] =
1240 strdup("speaker-safe-and-bt-sco-wb"),
David Linee3fe402017-03-13 10:00:42 -07001241 backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("usb-headset-mic");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001242 backend_tag_table[SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1243 backend_tag_table[SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1244 backend_tag_table[SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1245 backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = strdup("usb-headset-mic");
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001246 backend_tag_table[SND_DEVICE_OUT_BT_A2DP] = strdup("bt-a2dp");
1247 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] = strdup("speaker-and-bt-a2dp");
Aniket Kumar Lata9723a962018-05-16 17:41:55 -07001248 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP] = strdup("speaker-safe-and-bt-a2dp");
jasmine cha270b7762018-03-30 15:41:33 +08001249 backend_tag_table[SND_DEVICE_OUT_USB_HEADSET_SPEC] = strdup("usb-headset");
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001250
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001251 hw_interface_table[SND_DEVICE_OUT_HANDSET] = strdup("SLIMBUS_0_RX");
1252 hw_interface_table[SND_DEVICE_OUT_SPEAKER] = strdup("SLIMBUS_0_RX");
1253 hw_interface_table[SND_DEVICE_OUT_SPEAKER_REVERSE] = strdup("SLIMBUS_0_RX");
1254 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE] = strdup("SLIMBUS_0_RX");
1255 hw_interface_table[SND_DEVICE_OUT_HEADPHONES] = strdup("SLIMBUS_0_RX");
1256 hw_interface_table[SND_DEVICE_OUT_LINE] = strdup("SLIMBUS_0_RX");
1257 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001258 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001259 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001260 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001261 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET] = strdup("SLIMBUS_0_RX");
1262 hw_interface_table[SND_DEVICE_OUT_VOICE_HAC_HANDSET] = strdup("SLIMBUS_0_RX");
1263 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER] = strdup("SLIMBUS_0_RX");
1264 hw_interface_table[SND_DEVICE_OUT_VOICE_HEADPHONES] = strdup("SLIMBUS_0_RX");
yixuanjiang9536e672018-09-06 18:43:36 +08001265 hw_interface_table[SND_DEVICE_OUT_VOICE_HEADSET] = strdup("SLIMBUS_0_RX");
juyuchen66c4ecf2018-08-06 15:39:34 +08001266 hw_interface_table[SND_DEVICE_OUT_VOICE_MUSIC_TX] = strdup("VOICE_PLAYBACK_TX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001267 hw_interface_table[SND_DEVICE_OUT_VOICE_LINE] = strdup("SLIMBUS_0_RX");
1268 hw_interface_table[SND_DEVICE_OUT_HDMI] = strdup("HDMI_RX");
1269 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("SLIMBUS_0_RX-and-HDMI_RX");
1270 hw_interface_table[SND_DEVICE_OUT_BT_SCO] = strdup("SEC_AUX_PCM_RX");
1271 hw_interface_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("SEC_AUX_PCM_RX");
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001272 hw_interface_table[SND_DEVICE_OUT_BT_A2DP] = strdup("SLIMBUS_7_RX");
1273 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] =
1274 strdup("SLIMBUS_0_RX-and-SLIMBUS_7_RX");
Aniket Kumar Lata9723a962018-05-16 17:41:55 -07001275 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP] =
1276 strdup("SLIMBUS_0_RX-and-SLIMBUS_7_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001277 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = strdup("SLIMBUS_0_RX");
1278 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = strdup("SLIMBUS_0_RX");
1279 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = strdup("SLIMBUS_0_RX");
1280 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = strdup("SLIMBUS_0_RX");
David Linee3fe402017-03-13 10:00:42 -07001281 hw_interface_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("USB_AUDIO_RX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001282 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = strdup("USB_AUDIO_RX");
1283 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = strdup("USB_AUDIO_RX");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001284 hw_interface_table[SND_DEVICE_OUT_VOICE_USB_HEADSET] = strdup("USB_AUDIO_RX");
David Linee3fe402017-03-13 10:00:42 -07001285 hw_interface_table[SND_DEVICE_OUT_USB_HEADPHONES] = strdup("USB_AUDIO_RX");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001286 hw_interface_table[SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = strdup("USB_AUDIO_RX");
jasmine cha270b7762018-03-30 15:41:33 +08001287 hw_interface_table[SND_DEVICE_OUT_USB_HEADSET_SPEC] = strdup("USB_AUDIO_RX");
David Linee3fe402017-03-13 10:00:42 -07001288 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 -07001289 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 -07001290 hw_interface_table[SND_DEVICE_OUT_VOICE_TX] = strdup("AFE_PCM_RX");
1291 hw_interface_table[SND_DEVICE_OUT_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
1292 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
jasmine cha52284622018-03-23 17:21:35 +08001293 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = strdup("SLIMBUS_0_RX");
1294 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_BT_SCO] = strdup("SLIMBUS_0_RX-and-SEC_AUX_PCM_RX");
1295 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 +08001296 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO] = strdup("QUAT_TDM_RX_0-and-SLIMBUS_7_RX"),
1297 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB] = strdup("QUAT_TDM_RX_0-and-SLIMBUS_7_RX"),
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001298 hw_interface_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1299 hw_interface_table[SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1300 hw_interface_table[SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = strdup("USB_AUDIO_TX");
1301 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1302 hw_interface_table[SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1303 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = strdup("USB_AUDIO_TX");
1304 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = strdup("USB_AUDIO_TX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001305 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001306 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_AEC] = strdup("SLIMBUS_0_TX");
1307 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_NS] = strdup("SLIMBUS_0_TX");
1308 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1309 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC] = strdup("SLIMBUS_0_TX");
1310 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_AEC] = strdup("SLIMBUS_0_TX");
1311 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_NS] = strdup("SLIMBUS_0_TX");
1312 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1313 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001314 hw_interface_table[SND_DEVICE_IN_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001315 hw_interface_table[SND_DEVICE_IN_HEADSET_MIC_AEC] = strdup("SLIMBUS_0_TX");
Eric Laurent5f4ca952018-10-19 17:33:43 -07001316 hw_interface_table[SND_DEVICE_IN_CAMCORDER_LANDSCAPE] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001317 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC] = strdup("SLIMBUS_0_TX");
1318 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC_NS] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001319 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC_AEC] = strdup("SLIMBUS_0_TX");
1320 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001321 hw_interface_table[SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
1322 hw_interface_table[SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = strdup("SLIMBUS_0_TX");
David Lin93725722017-10-13 14:58:17 -07001323 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_MIC] = strdup("SLIMBUS_0_TX");
1324 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1325 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = strdup("SLIMBUS_0_TX");
1326 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = strdup("SLIMBUS_0_TX");
1327 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001328 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC] = strdup("SLIMBUS_0_TX");
1329 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_AEC] = strdup("SLIMBUS_0_TX");
1330 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_NS] = strdup("SLIMBUS_0_TX");
1331 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1332 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC] = strdup("SLIMBUS_0_TX");
1333 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_AEC] = strdup("SLIMBUS_0_TX");
1334 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_NS] = strdup("SLIMBUS_0_TX");
1335 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001336 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
1337 hw_interface_table[SND_DEVICE_IN_VOICE_DMIC] = strdup("SLIMBUS_0_TX");
1338 hw_interface_table[SND_DEVICE_IN_VOICE_DMIC_TMUS] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001339 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001340 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = strdup("SLIMBUS_0_TX");
1341 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001342 hw_interface_table[SND_DEVICE_IN_VOICE_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001343 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1344 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = strdup("SLIMBUS_0_TX");
1345 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1346 hw_interface_table[SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1347 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("SEC_AUX_PCM_TX");
1348 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("SEC_AUX_PCM_TX");
1349 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("SEC_AUX_PCM_TX");
1350 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("SEC_AUX_PCM_TX");
1351 hw_interface_table[SND_DEVICE_IN_VOICE_RX] = strdup("AFE_PCM_TX");
1352 hw_interface_table[SND_DEVICE_IN_THREE_MIC] = strdup("SLIMBUS_0_TX");
1353 hw_interface_table[SND_DEVICE_IN_QUAD_MIC] = strdup("SLIMBUS_0_TX");
1354 hw_interface_table[SND_DEVICE_IN_HANDSET_TMIC] = strdup("SLIMBUS_0_TX");
1355 hw_interface_table[SND_DEVICE_IN_HANDSET_QMIC] = strdup("SLIMBUS_0_TX");
1356 hw_interface_table[SND_DEVICE_IN_HANDSET_TMIC_AEC] = strdup("SLIMBUS_0_TX");
1357 hw_interface_table[SND_DEVICE_IN_HANDSET_QMIC_AEC] = strdup("SLIMBUS_0_TX");
Eric Laurent5f4ca952018-10-19 17:33:43 -07001358 hw_interface_table[SND_DEVICE_IN_CAMCORDER_INVERT_LANDSCAPE] = strdup("SLIMBUS_0_TX");
1359 hw_interface_table[SND_DEVICE_IN_CAMCORDER_PORTRAIT] = strdup("SLIMBUS_0_TX");
1360 hw_interface_table[SND_DEVICE_IN_CAMCORDER_SELFIE_LANDSCAPE] = strdup("SLIMBUS_0_TX");
1361 hw_interface_table[SND_DEVICE_IN_CAMCORDER_SELFIE_INVERT_LANDSCAPE] = strdup("SLIMBUS_0_TX");
1362 hw_interface_table[SND_DEVICE_IN_CAMCORDER_SELFIE_PORTRAIT] = strdup("SLIMBUS_0_TX");
Eric Laurentc6333382015-09-14 12:43:44 -07001363 my_data->max_mic_count = PLATFORM_DEFAULT_MIC_COUNT;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001364}
1365
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001366void get_cvd_version(char *cvd_version, struct audio_device *adev)
1367{
1368 struct mixer_ctl *ctl;
1369 int count;
1370 int ret = 0;
1371
1372 ctl = mixer_get_ctl_by_name(adev->mixer, CVD_VERSION_MIXER_CTL);
1373 if (!ctl) {
1374 ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__, CVD_VERSION_MIXER_CTL);
1375 goto done;
1376 }
1377 mixer_ctl_update(ctl);
1378
1379 count = mixer_ctl_get_num_values(ctl);
1380 if (count > MAX_CVD_VERSION_STRING_SIZE)
1381 count = MAX_CVD_VERSION_STRING_SIZE - 1;
1382
1383 ret = mixer_ctl_get_array(ctl, cvd_version, count);
1384 if (ret != 0) {
1385 ALOGE("%s: ERROR! mixer_ctl_get_array() failed to get CVD Version", __func__);
1386 goto done;
1387 }
1388
1389done:
1390 return;
1391}
1392
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001393static int platform_acdb_init(void *platform)
1394{
1395 struct platform_data *my_data = (struct platform_data *)platform;
1396 struct audio_device *adev = my_data->adev;
1397
1398 if (!my_data->acdb_init) {
1399 ALOGE("%s: no acdb_init fn provided", __func__);
1400 return -1;
1401 }
1402
1403 if (my_data->acdb_initialized) {
1404 ALOGW("acdb is already initialized");
1405 return 0;
1406 }
1407
Thierry Strudel07f96d12018-09-20 13:31:34 -07001408#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845) || (PLATFORM_SDM710) || (PLATFORM_SM8150)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001409 char *cvd_version = calloc(1, MAX_CVD_VERSION_STRING_SIZE);
1410 if (!cvd_version)
1411 ALOGE("failed to allocate cvd_version");
1412 else {
1413 get_cvd_version(cvd_version, adev);
1414 my_data->acdb_init((char *)my_data->snd_card_name, cvd_version, 0);
1415 free(cvd_version);
1416 }
1417#elif defined (PLATFORM_MSM8084)
1418 my_data->acdb_init((char *)my_data->snd_card_name);
1419#else
1420 my_data->acdb_init();
1421#endif
1422 my_data->acdb_initialized = true;
1423 return 0;
1424}
1425
David Linee3fe402017-03-13 10:00:42 -07001426static void
1427platform_backend_config_init(struct platform_data *pdata)
1428{
1429 int i;
1430
1431 /* initialize backend config */
1432 for (i = 0; i < MAX_CODEC_BACKENDS; i++) {
1433 pdata->current_backend_cfg[i].sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
1434 pdata->current_backend_cfg[i].bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
1435 pdata->current_backend_cfg[i].channels = CODEC_BACKEND_DEFAULT_CHANNELS;
1436
1437 if (i > MAX_RX_CODEC_BACKENDS)
1438 pdata->current_backend_cfg[i].channels = CODEC_BACKEND_DEFAULT_TX_CHANNELS;
1439
1440 pdata->current_backend_cfg[i].bitwidth_mixer_ctl = NULL;
1441 pdata->current_backend_cfg[i].samplerate_mixer_ctl = NULL;
1442 pdata->current_backend_cfg[i].channels_mixer_ctl = NULL;
1443 }
1444
1445 pdata->current_backend_cfg[DEFAULT_CODEC_BACKEND].bitwidth_mixer_ctl =
1446 strdup("SLIM_0_RX Format");
1447 pdata->current_backend_cfg[DEFAULT_CODEC_BACKEND].samplerate_mixer_ctl =
1448 strdup("SLIM_0_RX SampleRate");
1449
1450 pdata->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].bitwidth_mixer_ctl =
1451 strdup("SLIM_0_TX Format");
1452 pdata->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].samplerate_mixer_ctl =
1453 strdup("SLIM_0_TX SampleRate");
1454
1455 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].bitwidth_mixer_ctl =
1456 strdup("USB_AUDIO_TX Format");
1457 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].samplerate_mixer_ctl =
1458 strdup("USB_AUDIO_TX SampleRate");
1459 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].channels_mixer_ctl =
1460 strdup("USB_AUDIO_TX Channels");
1461
Yung Ti Su39a2b8a2018-10-05 15:43:40 +08001462 if (strstr(pdata->snd_card_name, "intcodec")) {
1463 pdata->current_backend_cfg[HEADPHONE_BACKEND].bitwidth_mixer_ctl =
1464 strdup("INT0_MI2S_RX Format");
1465 pdata->current_backend_cfg[HEADPHONE_BACKEND].samplerate_mixer_ctl =
1466 strdup("INT0_MI2S_RX SampleRate");
1467 } else {
1468 pdata->current_backend_cfg[HEADPHONE_BACKEND].bitwidth_mixer_ctl =
1469 strdup("SLIM_6_RX Format");
1470 pdata->current_backend_cfg[HEADPHONE_BACKEND].samplerate_mixer_ctl =
1471 strdup("SLIM_6_RX SampleRate");
1472 }
David Linee3fe402017-03-13 10:00:42 -07001473
1474 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].bitwidth_mixer_ctl =
1475 strdup("USB_AUDIO_RX Format");
1476 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].samplerate_mixer_ctl =
1477 strdup("USB_AUDIO_RX SampleRate");
1478
1479 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].channels = 1;
1480 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].channels_mixer_ctl =
1481 strdup("USB_AUDIO_RX Channels");
1482}
1483
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001484static int
1485platform_backend_app_type_cfg_init(struct platform_data *pdata,
1486 struct mixer *mixer)
1487{
1488 size_t app_type_cfg[128] = {0};
1489 int length, num_app_types = 0;
1490 struct mixer_ctl *ctl = NULL;
1491
1492 const char *mixer_ctl_name = "App Type Config";
1493 ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name);
1494 if (!ctl) {
1495 ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name);
1496 return -1;
1497 }
1498
1499 length = 1; // reserve index 0 for number of app types
1500
1501 struct listnode *node;
1502 struct app_type_entry *entry;
1503 list_for_each(node, &app_type_entry_list) {
1504 entry = node_to_item(node, struct app_type_entry, node);
1505 app_type_cfg[length++] = entry->app_type;
1506 app_type_cfg[length++] = entry->max_rate;
1507 app_type_cfg[length++] = entry->bit_width;
1508 ALOGI("%s add entry %d %d", __func__, entry->app_type, entry->bit_width);
1509 num_app_types += 1;
1510 }
1511
1512 // default for capture
1513 int t;
1514 platform_get_default_app_type_v2(pdata,
1515 PCM_CAPTURE,
1516 &t);
1517 app_type_cfg[length++] = t;
1518 app_type_cfg[length++] = 48000;
1519 app_type_cfg[length++] = 16;
1520 num_app_types += 1;
1521
1522 if (num_app_types) {
1523 app_type_cfg[0] = num_app_types;
1524 if (mixer_ctl_set_array(ctl, app_type_cfg, length) < 0) {
1525 ALOGE("Failed to set app type cfg");
1526 }
1527 }
1528 return 0;
1529}
1530
Xu Han1638fd12018-04-20 12:42:23 -07001531static void configure_flicker_sensor_input(struct mixer *mixer)
1532{
1533 struct mixer_ctl *ctl;
1534 const char* ctl1 = "AIF3_CAP Mixer SLIM TX2";
1535 int setting1 = 1;
1536 const char* ctl2 = "CDC_IF TX2 MUX";
1537 const char* setting2 = "DEC2";
1538 const char* ctl3 = "SLIM_1_TX Channels";
1539 const char* setting3 = "One";
1540 const char* ctl4 = "ADC MUX2";
1541 const char* setting4 = "AMIC";
1542 const char* ctl5 = "AMIC MUX2";
1543 const char* setting5 = "ADC1";
1544 const char* ctl6 = "DEC2 Volume";
1545 int setting6 = 84;
Xu Han07e07402018-05-15 14:19:25 -07001546 const char* ctl7 = "MultiMedia9 Mixer SLIM_1_TX";
Xu Han1638fd12018-04-20 12:42:23 -07001547 int setting7 = 1;
1548 const char* ctl8 = "SLIM_1_TX SampleRate";
1549 const char* setting8 = "KHZ_8";
1550
1551 ctl = mixer_get_ctl_by_name(mixer, ctl1);
1552 mixer_ctl_set_value(ctl, 0, setting1);
1553 ctl = mixer_get_ctl_by_name(mixer, ctl2);
1554 mixer_ctl_set_enum_by_string(ctl, setting2);
1555 ctl = mixer_get_ctl_by_name(mixer, ctl3);
1556 mixer_ctl_set_enum_by_string(ctl, setting3);
1557 ctl = mixer_get_ctl_by_name(mixer, ctl4);
1558 mixer_ctl_set_enum_by_string(ctl, setting4);
1559 ctl = mixer_get_ctl_by_name(mixer, ctl5);
1560 mixer_ctl_set_enum_by_string(ctl, setting5);
1561 ctl = mixer_get_ctl_by_name(mixer, ctl6);
1562 mixer_ctl_set_value(ctl, 0, setting6);
1563 ctl = mixer_get_ctl_by_name(mixer, ctl7);
1564 mixer_ctl_set_value(ctl, 0, setting7);
1565 ctl = mixer_get_ctl_by_name(mixer, ctl8);
1566 mixer_ctl_set_enum_by_string(ctl, setting8);
1567}
1568
Eric Laurentb23d5282013-05-14 15:27:20 -07001569void *platform_init(struct audio_device *adev)
1570{
1571 char value[PROPERTY_VALUE_MAX];
vivek mehta60ea4152016-02-18 17:10:26 -08001572 struct platform_data *my_data = NULL;
1573 int retry_num = 0, snd_card_num = 0, key = 0, ret = 0;
1574 bool dual_mic_config = false, use_default_mixer_path = true;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001575 const char *snd_card_name;
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001576 char *cvd_version = NULL;
vivek mehta60ea4152016-02-18 17:10:26 -08001577 char *snd_internal_name = NULL;
1578 char *tmp = NULL;
1579 char mixer_xml_file[MIXER_PATH_MAX_LENGTH]= {0};
vivek mehtade4849c2016-03-03 17:23:38 -08001580 char platform_info_file[MIXER_PATH_MAX_LENGTH]= {0};
1581 struct snd_card_split *snd_split_handle = NULL;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001582 my_data = calloc(1, sizeof(struct platform_data));
1583
1584 my_data->adev = adev;
1585
keunhui.park2f7306a2015-07-16 16:48:06 +09001586 list_init(&operator_info_list);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001587 list_init(&app_type_entry_list);
keunhui.park2f7306a2015-07-16 16:48:06 +09001588
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001589 set_platform_defaults(my_data);
1590
vivek mehta0fb11312017-05-15 19:35:32 -07001591 // audio_extn_utils_get_snd_card_num does
1592 // - open mixer and get snd card name
1593 // - parse platform info xml file and check for valid snd card name
1594 // - on failure loop through all the active snd card
sangwoo1b9f4b32013-06-21 18:22:55 -07001595
vivek mehta0fb11312017-05-15 19:35:32 -07001596 snd_card_num = audio_extn_utils_get_snd_card_num();
1597 if (-1 == snd_card_num) {
1598 ALOGE("%s: invalid sound card number (-1), bailing out ", __func__);
1599 goto init_failed;
sangwoo1b9f4b32013-06-21 18:22:55 -07001600 }
1601
vivek mehta0fb11312017-05-15 19:35:32 -07001602 adev->mixer = mixer_open(snd_card_num);
1603 snd_card_name = mixer_get_name(adev->mixer);
1604 my_data->hw_info = hw_info_init(snd_card_name);
1605
1606 audio_extn_set_snd_card_split(snd_card_name);
1607 snd_split_handle = audio_extn_get_snd_card_split();
1608
1609 /* Get the codec internal name from the sound card and/or form factor
1610 * name and form the mixer paths and platfor info file name dynamically.
1611 * This is generic way of picking any codec and forma factor name based
1612 * mixer and platform info files in future with no code change.
1613
1614 * current code extends and looks for any of the exteneded mixer path and
1615 * platform info file present based on codec and form factor.
1616
1617 * order of picking appropriate file is
1618 * <i> mixer_paths_<codec_name>_<form_factor>.xml, if file not present
1619 * <ii> mixer_paths_<codec_name>.xml, if file not present
1620 * <iii> mixer_paths.xml
1621
1622 * same order is followed for audio_platform_info.xml as well
1623 */
1624
1625 // need to carryforward old file name
1626 if (!strncmp(snd_card_name, TOMTOM_8226_SND_CARD_NAME,
1627 min(strlen(TOMTOM_8226_SND_CARD_NAME), strlen(snd_card_name)))) {
1628 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1629 MIXER_XML_BASE_STRING, TOMTOM_MIXER_FILE_SUFFIX );
1630 } else {
1631
1632 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s_%s.xml",
1633 MIXER_XML_BASE_STRING, snd_split_handle->snd_card,
1634 snd_split_handle->form_factor);
1635 if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) {
1636 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1637 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1638 MIXER_XML_BASE_STRING, snd_split_handle->snd_card);
1639
1640 if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) {
1641 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1642 strlcpy(mixer_xml_file, MIXER_XML_DEFAULT_PATH, MIXER_PATH_MAX_LENGTH);
1643 audio_extn_utils_resolve_config_file(mixer_xml_file);
1644 }
1645 }
1646 }
1647
1648 audio_extn_utils_get_platform_info(snd_card_name, platform_info_file);
1649
jiabin8962a4d2018-03-19 18:21:24 -07001650 my_data->declared_mic_count = 0;
vivek mehta0fb11312017-05-15 19:35:32 -07001651 /* Initialize platform specific ids and/or backends*/
1652 platform_info_init(platform_info_file, my_data);
1653
1654 ALOGD("%s: Loading mixer file: %s", __func__, mixer_xml_file);
1655 adev->audio_route = audio_route_init(snd_card_num, mixer_xml_file);
1656
1657 if (!adev->audio_route) {
1658 ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
1659 mixer_close(adev->mixer);
1660 adev->mixer = NULL;
1661 hw_info_deinit(my_data->hw_info);
1662 my_data->hw_info = NULL;
1663 goto init_failed;
1664 }
1665 adev->snd_card = snd_card_num;
1666 ALOGD("%s: Opened sound card:%d", __func__, snd_card_num);
1667
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09001668 //set max volume step for voice call
1669 property_get("ro.config.vc_call_vol_steps", value, TOSTRING(MAX_VOL_INDEX));
1670 my_data->max_vol_index = atoi(value);
1671
vivek mehta65ad12d2015-08-13 18:32:48 -07001672 property_get("persist.audio.dualmic.config",value,"");
1673 if (!strcmp("endfire", value)) {
1674 dual_mic_config = true;
1675 }
1676
John Muir9e59a962018-01-10 13:30:00 -08001677 my_data->source_mic_type = 0;
Prashant Malanic92c5962015-08-11 15:10:18 -07001678
Eric Laurentb23d5282013-05-14 15:27:20 -07001679 my_data->fluence_in_spkr_mode = false;
1680 my_data->fluence_in_voice_call = false;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001681 my_data->fluence_in_voice_comm = false;
Eric Laurentb23d5282013-05-14 15:27:20 -07001682 my_data->fluence_in_voice_rec = false;
1683
vivek mehta65ad12d2015-08-13 18:32:48 -07001684 property_get("ro.qc.sdk.audio.fluencetype", value, "none");
Prashant Malanic92c5962015-08-11 15:10:18 -07001685 if (!strcmp("fluencepro", value)) {
1686 my_data->fluence_type = FLUENCE_PRO_ENABLE;
vivek mehta65ad12d2015-08-13 18:32:48 -07001687 } else if (!strcmp("fluence", value) || (dual_mic_config)) {
Prashant Malanic92c5962015-08-11 15:10:18 -07001688 my_data->fluence_type = FLUENCE_ENABLE;
1689 } else if (!strcmp("none", value)) {
1690 my_data->fluence_type = FLUENCE_DISABLE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001691 }
1692
Prashant Malanic92c5962015-08-11 15:10:18 -07001693 if (my_data->fluence_type != FLUENCE_DISABLE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001694 property_get("persist.audio.fluence.voicecall",value,"");
1695 if (!strcmp("true", value)) {
1696 my_data->fluence_in_voice_call = true;
1697 }
1698
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001699 property_get("persist.audio.fluence.voicecomm",value,"");
1700 if (!strcmp("true", value)) {
1701 my_data->fluence_in_voice_comm = true;
1702 }
1703
Eric Laurentb23d5282013-05-14 15:27:20 -07001704 property_get("persist.audio.fluence.voicerec",value,"");
1705 if (!strcmp("true", value)) {
1706 my_data->fluence_in_voice_rec = true;
1707 }
1708
1709 property_get("persist.audio.fluence.speaker",value,"");
1710 if (!strcmp("true", value)) {
1711 my_data->fluence_in_spkr_mode = true;
1712 }
1713 }
1714
Prashant Malanic92c5962015-08-11 15:10:18 -07001715 // support max to mono, example if max count is 3, usecase supports Three, dual and mono mic
1716 switch (my_data->max_mic_count) {
1717 case 4:
1718 my_data->source_mic_type |= SOURCE_QUAD_MIC;
1719 case 3:
1720 my_data->source_mic_type |= SOURCE_THREE_MIC;
1721 case 2:
1722 my_data->source_mic_type |= SOURCE_DUAL_MIC;
1723 case 1:
1724 my_data->source_mic_type |= SOURCE_MONO_MIC;
1725 break;
1726 default:
1727 ALOGE("%s: max_mic_count (%d), is not supported, setting to default",
1728 __func__, my_data->max_mic_count);
1729 my_data->source_mic_type = SOURCE_MONO_MIC|SOURCE_DUAL_MIC;
1730 break;
1731 }
1732
1733 ALOGV("%s: Fluence_Type(%d) max_mic_count(%d) mic_type(0x%x) fluence_in_voice_call(%d)"
1734 " fluence_in_voice_comm(%d) fluence_in_voice_rec(%d) fluence_in_spkr_mode(%d) ",
1735 __func__, my_data->fluence_type, my_data->max_mic_count, my_data->source_mic_type,
1736 my_data->fluence_in_voice_call, my_data->fluence_in_voice_comm,
1737 my_data->fluence_in_voice_rec, my_data->fluence_in_spkr_mode);
1738
Eric Laurentb23d5282013-05-14 15:27:20 -07001739 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
1740 if (my_data->acdb_handle == NULL) {
1741 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
1742 } else {
1743 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
1744 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
1745 "acdb_loader_deallocate_ACDB");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001746 if (!my_data->acdb_deallocate)
1747 ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s",
1748 __func__, LIB_ACDB_LOADER);
1749
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001750 my_data->acdb_send_audio_cal_v3 = (acdb_send_audio_cal_v3_t)dlsym(my_data->acdb_handle,
1751 "acdb_loader_send_audio_cal_v3");
1752 if (!my_data->acdb_send_audio_cal_v3)
1753 ALOGE("%s: Could not find the symbol acdb_send_audio_cal_v3 from %s",
1754 __func__, LIB_ACDB_LOADER);
1755
Eric Laurentb23d5282013-05-14 15:27:20 -07001756 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
1757 "acdb_loader_send_audio_cal");
1758 if (!my_data->acdb_send_audio_cal)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001759 ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s",
Eric Laurentb23d5282013-05-14 15:27:20 -07001760 __func__, LIB_ACDB_LOADER);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001761
Eric Laurentb23d5282013-05-14 15:27:20 -07001762 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
1763 "acdb_loader_send_voice_cal");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001764 if (!my_data->acdb_send_voice_cal)
1765 ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s",
1766 __func__, LIB_ACDB_LOADER);
1767
1768 my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle,
1769 "acdb_loader_reload_vocvoltable");
1770 if (!my_data->acdb_reload_vocvoltable)
1771 ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s",
1772 __func__, LIB_ACDB_LOADER);
vivek mehta1a9b7c02015-06-25 11:49:38 -07001773
1774 my_data->acdb_send_gain_dep_cal = (acdb_send_gain_dep_cal_t)dlsym(my_data->acdb_handle,
1775 "acdb_loader_send_gain_dep_cal");
1776 if (!my_data->acdb_send_gain_dep_cal)
1777 ALOGV("%s: Could not find the symbol acdb_loader_send_gain_dep_cal from %s",
1778 __func__, LIB_ACDB_LOADER);
1779
Xu Han1638fd12018-04-20 12:42:23 -07001780#if defined (FLICKER_SENSOR_INPUT)
1781 configure_flicker_sensor_input(adev->mixer);
1782#endif
1783
Thierry Strudel07f96d12018-09-20 13:31:34 -07001784#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845) || (PLATFORM_SDM710) || (PLATFORM_SM8150)
vivek mehta0fb11312017-05-15 19:35:32 -07001785 acdb_init_v2_cvd_t acdb_init_local;
1786 acdb_init_local = (acdb_init_v2_cvd_t)dlsym(my_data->acdb_handle,
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001787 "acdb_loader_init_v2");
vivek mehta0fb11312017-05-15 19:35:32 -07001788 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001789 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1790 dlerror());
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001791
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001792#elif defined (PLATFORM_MSM8084)
vivek mehta0fb11312017-05-15 19:35:32 -07001793 acdb_init_v2_t acdb_init_local;
1794 acdb_init_local = (acdb_init_v2_t)dlsym(my_data->acdb_handle,
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001795 "acdb_loader_init_v2");
vivek mehta0fb11312017-05-15 19:35:32 -07001796 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001797 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1798 dlerror());
1799
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001800#else
vivek mehta0fb11312017-05-15 19:35:32 -07001801 acdb_init_t acdb_init_local;
1802 acdb_init_local = (acdb_init_t)dlsym(my_data->acdb_handle,
Eric Laurentb23d5282013-05-14 15:27:20 -07001803 "acdb_loader_init_ACDB");
vivek mehta0fb11312017-05-15 19:35:32 -07001804 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001805 ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__,
1806 dlerror());
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001807#endif
vivek mehta0fb11312017-05-15 19:35:32 -07001808 my_data->acdb_init = acdb_init_local;
Eric Laurentb23d5282013-05-14 15:27:20 -07001809
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001810 my_data->acdb_send_custom_top = (acdb_send_custom_top_t)
1811 dlsym(my_data->acdb_handle,
1812 "acdb_loader_send_common_custom_topology");
1813
1814 if (!my_data->acdb_send_custom_top)
1815 ALOGE("%s: Could not find the symbol acdb_get_default_app_type from %s",
1816 __func__, LIB_ACDB_LOADER);
1817
jasmine chac89321b2018-04-10 21:37:01 +08001818 my_data->acdb_set_audio_cal = (acdb_set_audio_cal_t)dlsym(my_data->acdb_handle,
1819 "acdb_loader_set_audio_cal_v2");
1820 if (!my_data->acdb_set_audio_cal)
1821 ALOGE("%s: Could not find the symbol acdb_set_audio_cal_v2 from %s",
1822 __func__, LIB_ACDB_LOADER);
1823
vivek mehta0fb11312017-05-15 19:35:32 -07001824 int result = acdb_init(adev->snd_card);
1825 if (!result) {
1826 my_data->acdb_initialized = true;
1827 ALOGD("ACDB initialized");
1828 } else {
1829 my_data->acdb_initialized = false;
1830 ALOGD("ACDB initialization failed");
1831 }
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001832 }
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001833
David Linee3fe402017-03-13 10:00:42 -07001834 /* init usb */
1835 audio_extn_usb_init(adev);
1836
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001837 /* init a2dp */
1838 audio_extn_a2dp_init(adev);
1839
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001840 audio_extn_spkr_prot_init(adev);
Haynes Mathew George98c95622014-06-20 19:14:25 -07001841
Ravi Kumar Alamanda76315572015-04-23 13:13:56 -07001842 audio_extn_hwdep_cal_send(adev->snd_card, my_data->acdb_handle);
1843
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001844 /* load csd client */
1845 platform_csd_init(my_data);
1846
David Linee3fe402017-03-13 10:00:42 -07001847 platform_backend_config_init(my_data);
1848
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001849 init_be_dai_name_table(adev);
1850
1851 if (platform_supports_app_type_cfg())
1852 platform_backend_app_type_cfg_init(my_data, adev->mixer);
1853
Eric Laurentb23d5282013-05-14 15:27:20 -07001854 return my_data;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001855
1856init_failed:
1857 if (my_data)
1858 free(my_data);
1859 return NULL;
Eric Laurentb23d5282013-05-14 15:27:20 -07001860}
1861
1862void platform_deinit(void *platform)
1863{
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001864 int32_t dev;
keunhui.park2f7306a2015-07-16 16:48:06 +09001865 struct operator_info *info_item;
1866 struct operator_specific_device *device_item;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001867 struct app_type_entry *ap;
keunhui.park2f7306a2015-07-16 16:48:06 +09001868 struct listnode *node;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001869
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001870 struct platform_data *my_data = (struct platform_data *)platform;
1871 close_csd_client(my_data->csd);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001872
David Lin41b4fe42018-07-08 16:14:24 -07001873 audio_extn_spkr_prot_deinit(my_data->adev);
1874
vivek mehtade4849c2016-03-03 17:23:38 -08001875 hw_info_deinit(my_data->hw_info);
1876
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001877 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1878 if (backend_tag_table[dev])
1879 free(backend_tag_table[dev]);
1880 if (hw_interface_table[dev])
1881 free(hw_interface_table[dev]);
keunhui.park2f7306a2015-07-16 16:48:06 +09001882 if (operator_specific_device_table[dev]) {
1883 while (!list_empty(operator_specific_device_table[dev])) {
1884 node = list_head(operator_specific_device_table[dev]);
1885 list_remove(node);
1886 device_item = node_to_item(node, struct operator_specific_device, list);
1887 free(device_item->operator);
1888 free(device_item->mixer_path);
1889 free(device_item);
1890 }
1891 free(operator_specific_device_table[dev]);
1892 }
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001893 }
1894
1895 if (my_data->snd_card_name)
1896 free(my_data->snd_card_name);
1897
keunhui.park2f7306a2015-07-16 16:48:06 +09001898 while (!list_empty(&operator_info_list)) {
1899 node = list_head(&operator_info_list);
1900 list_remove(node);
1901 info_item = node_to_item(node, struct operator_info, list);
1902 free(info_item->name);
1903 free(info_item->mccmnc);
1904 free(info_item);
1905 }
1906
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001907 while (!list_empty(&app_type_entry_list)) {
1908 node = list_head(&app_type_entry_list);
1909 list_remove(node);
1910 ap = node_to_item(node, struct app_type_entry, node);
vivek mehtaa68fea62017-06-08 19:04:02 -07001911 if (ap->mode) free(ap->mode);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001912 free(ap);
1913 }
1914
Kevin Rocarde35d4af2017-05-02 16:55:28 -07001915 mixer_close(my_data->adev->mixer);
Eric Laurentb23d5282013-05-14 15:27:20 -07001916 free(platform);
David Linee3fe402017-03-13 10:00:42 -07001917
1918 /* deinit usb */
1919 audio_extn_usb_deinit();
Eric Laurentb23d5282013-05-14 15:27:20 -07001920}
1921
1922const char *platform_get_snd_device_name(snd_device_t snd_device)
1923{
keunhui.park2f7306a2015-07-16 16:48:06 +09001924 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1925 if (operator_specific_device_table[snd_device] != NULL) {
1926 return get_operator_specific_device_mixer_path(snd_device);
1927 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001928 return device_table[snd_device];
keunhui.park2f7306a2015-07-16 16:48:06 +09001929 } else
Ravi Kumar Alamanda64026462014-09-15 00:08:58 -07001930 return "none";
Eric Laurentb23d5282013-05-14 15:27:20 -07001931}
1932
vivek mehtade4849c2016-03-03 17:23:38 -08001933int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
1934 char *device_name)
1935{
1936 struct platform_data *my_data = (struct platform_data *)platform;
1937
David Benjamin1565f992016-09-21 12:10:34 -04001938 if (platform == NULL) {
vivek mehtade4849c2016-03-03 17:23:38 -08001939 ALOGW("%s: something wrong, use legacy get_snd_device name", __func__);
David Benjamin1565f992016-09-21 12:10:34 -04001940 strlcpy(device_name, platform_get_snd_device_name(snd_device),
1941 DEVICE_NAME_MAX_SIZE);
vivek mehtade4849c2016-03-03 17:23:38 -08001942 } else if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1943 if (operator_specific_device_table[snd_device] != NULL) {
1944 strlcpy(device_name, get_operator_specific_device_mixer_path(snd_device),
1945 DEVICE_NAME_MAX_SIZE);
1946 } else {
1947 strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE);
1948 }
1949 hw_info_append_hw_type(my_data->hw_info, snd_device, device_name);
1950 } else {
1951 strlcpy(device_name, "none", DEVICE_NAME_MAX_SIZE);
Aniket Kumar Lataa158e862018-05-11 17:28:40 -07001952 return -EINVAL;
vivek mehtade4849c2016-03-03 17:23:38 -08001953 }
1954
1955 return 0;
1956}
1957
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001958void platform_add_backend_name(void *platform, char *mixer_path,
1959 snd_device_t snd_device)
Eric Laurentb23d5282013-05-14 15:27:20 -07001960{
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001961 struct platform_data *my_data = (struct platform_data *)platform;
1962
Haynes Mathew George98c95622014-06-20 19:14:25 -07001963 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1964 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1965 return;
Ravi Kumar Alamanda1de6e5a2014-06-19 21:55:39 -05001966 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001967
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001968 const char * suffix = backend_tag_table[snd_device];
Haynes Mathew George98c95622014-06-20 19:14:25 -07001969
1970 if (suffix != NULL) {
1971 strcat(mixer_path, " ");
1972 strcat(mixer_path, suffix);
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001973 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001974}
1975
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001976bool platform_check_backends_match(snd_device_t snd_device1, snd_device_t snd_device2)
1977{
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001978 ALOGV("%s: snd_device1 = %s, snd_device2 = %s", __func__,
1979 platform_get_snd_device_name(snd_device1),
1980 platform_get_snd_device_name(snd_device2));
1981
1982 if ((snd_device1 < SND_DEVICE_MIN) || (snd_device1 >= SND_DEVICE_MAX)) {
1983 ALOGE("%s: Invalid snd_device = %s", __func__,
1984 platform_get_snd_device_name(snd_device1));
1985 return false;
1986 }
1987 if ((snd_device2 < SND_DEVICE_MIN) || (snd_device2 >= SND_DEVICE_MAX)) {
1988 ALOGE("%s: Invalid snd_device = %s", __func__,
1989 platform_get_snd_device_name(snd_device2));
1990 return false;
1991 }
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07001992
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001993 const char * be_itf1 = hw_interface_table[snd_device1];
1994 const char * be_itf2 = hw_interface_table[snd_device2];
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07001995 /*
1996 hw_interface_table has overrides for a snd_device.
1997 if there is no entry for a device, assume DEFAULT_RX_BACKEND
1998 */
1999 if (be_itf1 == NULL) {
2000 be_itf1 = DEFAULT_RX_BACKEND;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002001 }
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07002002 if (be_itf2 == NULL) {
2003 be_itf2 = DEFAULT_RX_BACKEND;
2004 }
2005 ALOGV("%s: be_itf1 = %s, be_itf2 = %s", __func__, be_itf1, be_itf2);
2006 /*
2007 this takes care of finding a device within a combo device pair as well
2008 */
2009 return strstr(be_itf1, be_itf2) != NULL || strstr(be_itf2, be_itf1) != NULL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002010}
2011
Eric Laurentb23d5282013-05-14 15:27:20 -07002012int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
2013{
2014 int device_id;
2015 if (device_type == PCM_PLAYBACK)
2016 device_id = pcm_device_table[usecase][0];
2017 else
2018 device_id = pcm_device_table[usecase][1];
2019 return device_id;
2020}
2021
Haynes Mathew George98c95622014-06-20 19:14:25 -07002022static int find_index(const struct name_to_index * table, int32_t len,
2023 const char * name)
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002024{
2025 int ret = 0;
Haynes Mathew George98c95622014-06-20 19:14:25 -07002026 int32_t i;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002027
Haynes Mathew George98c95622014-06-20 19:14:25 -07002028 if (table == NULL) {
2029 ALOGE("%s: table is NULL", __func__);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002030 ret = -ENODEV;
2031 goto done;
2032 }
2033
Haynes Mathew George98c95622014-06-20 19:14:25 -07002034 if (name == NULL) {
2035 ALOGE("null key");
2036 ret = -ENODEV;
2037 goto done;
2038 }
2039
2040 for (i=0; i < len; i++) {
2041 if (!strcmp(table[i].name, name)) {
2042 ret = table[i].index;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002043 goto done;
2044 }
2045 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07002046 ALOGE("%s: Could not find index for name = %s",
2047 __func__, name);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002048 ret = -ENODEV;
2049done:
2050 return ret;
2051}
2052
Haynes Mathew George98c95622014-06-20 19:14:25 -07002053int platform_get_snd_device_index(char *device_name)
2054{
2055 return find_index(snd_device_name_index, SND_DEVICE_MAX, device_name);
2056}
2057
2058int platform_get_usecase_index(const char *usecase_name)
2059{
2060 return find_index(usecase_name_index, AUDIO_USECASE_MAX, usecase_name);
2061}
2062
keunhui.park2f7306a2015-07-16 16:48:06 +09002063void platform_add_operator_specific_device(snd_device_t snd_device,
2064 const char *operator,
2065 const char *mixer_path,
2066 unsigned int acdb_id)
2067{
2068 struct operator_specific_device *device;
2069
2070 if (operator_specific_device_table[snd_device] == NULL) {
2071 operator_specific_device_table[snd_device] =
2072 (struct listnode *)calloc(1, sizeof(struct listnode));
2073 list_init(operator_specific_device_table[snd_device]);
2074 }
2075
2076 device = (struct operator_specific_device *)calloc(1, sizeof(struct operator_specific_device));
2077
2078 device->operator = strdup(operator);
2079 device->mixer_path = strdup(mixer_path);
2080 device->acdb_id = acdb_id;
2081
2082 list_add_tail(operator_specific_device_table[snd_device], &device->list);
2083
Eric Laurent2bafff12016-03-17 12:17:23 -07002084 ALOGD("%s: device[%s] -> operator[%s] mixer_path[%s] acdb_id[%d]", __func__,
keunhui.park2f7306a2015-07-16 16:48:06 +09002085 platform_get_snd_device_name(snd_device), operator, mixer_path, acdb_id);
2086
2087}
2088
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002089int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
2090{
2091 int ret = 0;
2092
2093 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
2094 ALOGE("%s: Invalid snd_device = %d",
2095 __func__, snd_device);
2096 ret = -EINVAL;
2097 goto done;
2098 }
2099
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002100 ALOGV("%s: acdb_device_table[%s]: old = %d new = %d", __func__,
2101 platform_get_snd_device_name(snd_device), acdb_device_table[snd_device], acdb_id);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002102 acdb_device_table[snd_device] = acdb_id;
2103done:
2104 return ret;
2105}
2106
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07002107int platform_get_snd_device_acdb_id(snd_device_t snd_device)
2108{
2109 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
2110 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
2111 return -EINVAL;
2112 }
keunhui.park2f7306a2015-07-16 16:48:06 +09002113
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002114 /*
2115 * If speaker protection is enabled, function returns supported
2116 * sound device for speaker. Else same sound device is returned.
2117 */
2118 snd_device = audio_extn_get_spkr_prot_snd_device(snd_device);
2119
keunhui.park2f7306a2015-07-16 16:48:06 +09002120 if (operator_specific_device_table[snd_device] != NULL)
2121 return get_operator_specific_device_acdb_id(snd_device);
2122 else
2123 return acdb_device_table[snd_device];
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07002124}
2125
David Linee3fe402017-03-13 10:00:42 -07002126static int platform_get_backend_index(snd_device_t snd_device)
2127{
2128 int32_t port = DEFAULT_CODEC_BACKEND;
2129
2130 if (snd_device >= SND_DEVICE_OUT_BEGIN && snd_device < SND_DEVICE_OUT_END) {
2131 if (backend_tag_table[snd_device] != NULL) {
2132 if (strncmp(backend_tag_table[snd_device], "headphones",
2133 sizeof("headphones")) == 0)
2134 port = HEADPHONE_BACKEND;
2135 else if (strcmp(backend_tag_table[snd_device], "hdmi") == 0)
2136 port = HDMI_RX_BACKEND;
2137 else if ((strcmp(backend_tag_table[snd_device], "usb-headphones") == 0) ||
2138 (strcmp(backend_tag_table[snd_device], "usb-headset") == 0))
2139 port = USB_AUDIO_RX_BACKEND;
2140 }
2141 } else if (snd_device >= SND_DEVICE_IN_BEGIN && snd_device < SND_DEVICE_IN_END) {
2142 port = DEFAULT_CODEC_TX_BACKEND;
2143 if (backend_tag_table[snd_device] != NULL) {
2144 if (strcmp(backend_tag_table[snd_device], "usb-headset-mic") == 0)
2145 port = USB_AUDIO_TX_BACKEND;
2146 else if (strstr(backend_tag_table[snd_device], "bt-sco") != NULL)
2147 port = BT_SCO_TX_BACKEND;
2148 }
2149 } else {
2150 ALOGW("%s:napb: Invalid device - %d ", __func__, snd_device);
2151 }
2152
2153 ALOGV("%s:napb: backend port - %d device - %d ", __func__, port, snd_device);
2154
2155 return port;
2156}
2157
Eric Laurentb23d5282013-05-14 15:27:20 -07002158int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
2159{
2160 struct platform_data *my_data = (struct platform_data *)platform;
2161 int acdb_dev_id, acdb_dev_type;
2162
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002163 if (platform_supports_app_type_cfg()) // use v2 instead
2164 return -ENOSYS;
2165
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002166 acdb_dev_id = platform_get_snd_device_acdb_id(snd_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07002167 if (acdb_dev_id < 0) {
2168 ALOGE("%s: Could not find acdb id for device(%d)",
2169 __func__, snd_device);
2170 return -EINVAL;
2171 }
2172 if (my_data->acdb_send_audio_cal) {
Joe Onorato188b6222016-03-01 11:02:27 -08002173 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Eric Laurentb23d5282013-05-14 15:27:20 -07002174 __func__, snd_device, acdb_dev_id);
2175 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
2176 snd_device < SND_DEVICE_OUT_END)
2177 acdb_dev_type = ACDB_DEV_TYPE_OUT;
2178 else
2179 acdb_dev_type = ACDB_DEV_TYPE_IN;
2180 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
2181 }
2182 return 0;
2183}
2184
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002185int platform_send_audio_calibration_v2(void *platform, struct audio_usecase *usecase,
2186 int app_type, int sample_rate)
2187{
2188 struct platform_data *my_data = (struct platform_data *)platform;
2189 int acdb_dev_id, acdb_dev_type;
vivek mehta7e573672018-03-13 17:41:41 -07002190 int snd_device = usecase->out_snd_device;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002191 int new_snd_device[SND_DEVICE_OUT_END] = {0};
2192 int i, num_devices = 1;
2193
2194 if (!platform_supports_app_type_cfg()) // use v1 instead
2195 return -ENOSYS;
2196
vivek mehta7e573672018-03-13 17:41:41 -07002197 if ((usecase->type == PCM_HFP_CALL) || (usecase->type == PCM_CAPTURE))
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002198 snd_device = usecase->in_snd_device;
2199
2200 // skipped over get_spkr_prot_device
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002201 acdb_dev_id = platform_get_snd_device_acdb_id(snd_device);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002202 if (acdb_dev_id < 0) {
2203 ALOGE("%s: Could not find acdb id for device(%d)",
2204 __func__, snd_device);
2205 return -EINVAL;
2206 }
2207
2208 if (platform_can_split_snd_device(snd_device,
2209 &num_devices, new_snd_device) < 0) {
2210 new_snd_device[0] = snd_device;
2211 }
2212
2213 for (i = 0; i < num_devices; i++) {
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002214 acdb_dev_id = platform_get_snd_device_acdb_id(new_snd_device[i]);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002215 if (acdb_dev_id < 0) {
2216 ALOGE("%s: Could not find acdb id for device(%d)",
2217 __func__, new_snd_device[i]);
2218 return -EINVAL;
2219 }
2220 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
2221 __func__, new_snd_device[i], acdb_dev_id);
2222 if (new_snd_device[i] >= SND_DEVICE_OUT_BEGIN &&
2223 new_snd_device[i] < SND_DEVICE_OUT_END)
2224 acdb_dev_type = ACDB_DEV_TYPE_OUT;
2225 else
2226 acdb_dev_type = ACDB_DEV_TYPE_IN;
2227
2228 if (my_data->acdb_send_audio_cal_v3) {
2229 my_data->acdb_send_audio_cal_v3(acdb_dev_id, acdb_dev_type,
2230 app_type, sample_rate, i);
2231 } else if (my_data->acdb_send_audio_cal) {
2232 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type); // this version differs from internal
2233 }
2234 }
2235
2236 return 0;
2237}
2238
2239
Eric Laurentb23d5282013-05-14 15:27:20 -07002240int platform_switch_voice_call_device_pre(void *platform)
2241{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002242 struct platform_data *my_data = (struct platform_data *)platform;
2243 int ret = 0;
2244
2245 if (my_data->csd != NULL &&
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002246 voice_is_in_call(my_data->adev)) {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002247 /* This must be called before disabling mixer controls on APQ side */
2248 ret = my_data->csd->disable_device();
2249 if (ret < 0) {
2250 ALOGE("%s: csd_client_disable_device, failed, error %d",
2251 __func__, ret);
2252 }
2253 }
2254 return ret;
2255}
2256
2257int platform_switch_voice_call_enable_device_config(void *platform,
2258 snd_device_t out_snd_device,
2259 snd_device_t in_snd_device)
2260{
2261 struct platform_data *my_data = (struct platform_data *)platform;
2262 int acdb_rx_id, acdb_tx_id;
2263 int ret = 0;
2264
2265 if (my_data->csd == NULL)
2266 return ret;
2267
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002268 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
keunhui.park2f7306a2015-07-16 16:48:06 +09002269 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002270
2271 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
2272 ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
2273 if (ret < 0) {
2274 ALOGE("%s: csd_enable_device_config, failed, error %d",
2275 __func__, ret);
2276 }
2277 } else {
2278 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2279 acdb_rx_id, acdb_tx_id);
2280 }
2281
2282 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002283}
2284
2285int platform_switch_voice_call_device_post(void *platform,
2286 snd_device_t out_snd_device,
2287 snd_device_t in_snd_device)
2288{
2289 struct platform_data *my_data = (struct platform_data *)platform;
2290 int acdb_rx_id, acdb_tx_id;
2291
2292 if (my_data->acdb_send_voice_cal == NULL) {
2293 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
2294 } else {
keunhui.park2f7306a2015-07-16 16:48:06 +09002295 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
2296 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07002297
2298 if (acdb_rx_id > 0 && acdb_tx_id > 0)
2299 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
2300 else
2301 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2302 acdb_rx_id, acdb_tx_id);
2303 }
2304
2305 return 0;
2306}
2307
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002308int platform_switch_voice_call_usecase_route_post(void *platform,
2309 snd_device_t out_snd_device,
2310 snd_device_t in_snd_device)
2311{
2312 struct platform_data *my_data = (struct platform_data *)platform;
2313 int acdb_rx_id, acdb_tx_id;
2314 int ret = 0;
2315
2316 if (my_data->csd == NULL)
2317 return ret;
2318
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002319 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
keunhui.park2f7306a2015-07-16 16:48:06 +09002320 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002321
2322 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
2323 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
2324 my_data->adev->acdb_settings);
2325 if (ret < 0) {
2326 ALOGE("%s: csd_enable_device, failed, error %d", __func__, ret);
2327 }
2328 } else {
2329 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2330 acdb_rx_id, acdb_tx_id);
2331 }
2332
2333 return ret;
2334}
2335
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002336int platform_start_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07002337{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002338 struct platform_data *my_data = (struct platform_data *)platform;
2339 int ret = 0;
2340
2341 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002342 ret = my_data->csd->start_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002343 if (ret < 0) {
2344 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
2345 }
2346 }
2347 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002348}
2349
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002350int platform_stop_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07002351{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002352 struct platform_data *my_data = (struct platform_data *)platform;
2353 int ret = 0;
2354
2355 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002356 ret = my_data->csd->stop_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002357 if (ret < 0) {
2358 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
2359 }
2360 }
2361 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002362}
2363
Vignesh Kulothunganb6f0a9c2018-03-22 13:50:22 -07002364int platform_set_mic_break_det(void *platform, bool enable)
2365{
2366 int ret = 0;
2367 struct platform_data *my_data = (struct platform_data *)platform;
2368 struct audio_device *adev = my_data->adev;
2369 const char *mixer_ctl_name = "Voice Mic Break Enable";
2370 struct mixer_ctl *ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2371 if (!ctl) {
2372 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2373 __func__, mixer_ctl_name);
2374 return -EINVAL;
2375 }
2376
2377 ret = mixer_ctl_set_value(ctl, 0, enable);
2378 if(ret)
2379 ALOGE("%s: Failed to set mixer ctl: %s", __func__, mixer_ctl_name);
2380
2381 return ret;
2382}
2383
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002384int platform_get_sample_rate(void *platform, uint32_t *rate)
2385{
2386 struct platform_data *my_data = (struct platform_data *)platform;
2387 int ret = 0;
2388
2389 if (my_data->csd != NULL) {
2390 ret = my_data->csd->get_sample_rate(rate);
2391 if (ret < 0) {
2392 ALOGE("%s: csd_get_sample_rate error %d\n", __func__, ret);
2393 }
2394 }
2395 return ret;
2396}
2397
vivek mehtab6506412015-08-07 16:55:17 -07002398void platform_set_speaker_gain_in_combo(struct audio_device *adev,
2399 snd_device_t snd_device,
2400 bool enable)
2401{
2402 const char* name;
2403 switch (snd_device) {
2404 case SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES:
2405 if (enable)
2406 name = "spkr-gain-in-headphone-combo";
2407 else
2408 name = "speaker-gain-default";
2409 break;
2410 case SND_DEVICE_OUT_SPEAKER_AND_LINE:
2411 if (enable)
2412 name = "spkr-gain-in-line-combo";
2413 else
2414 name = "speaker-gain-default";
2415 break;
2416 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES:
2417 if (enable)
2418 name = "spkr-safe-gain-in-headphone-combo";
2419 else
2420 name = "speaker-safe-gain-default";
2421 break;
2422 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE:
2423 if (enable)
2424 name = "spkr-safe-gain-in-line-combo";
2425 else
2426 name = "speaker-safe-gain-default";
2427 break;
2428 default:
2429 return;
2430 }
2431
2432 audio_route_apply_and_update_path(adev->audio_route, name);
2433}
2434
Eric Laurentb23d5282013-05-14 15:27:20 -07002435int platform_set_voice_volume(void *platform, int volume)
2436{
2437 struct platform_data *my_data = (struct platform_data *)platform;
2438 struct audio_device *adev = my_data->adev;
2439 struct mixer_ctl *ctl;
sangwoo53b2cf02013-07-25 19:18:44 -07002440 const char *mixer_ctl_name = "Voice Rx Gain";
Nadav Barc46d0fa2017-12-24 14:50:37 +02002441 const char *mute_mixer_ctl_name = "Voice Rx Device Mute";
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002442 int vol_index = 0, ret = 0;
2443 uint32_t set_values[ ] = {0,
2444 ALL_SESSION_VSID,
2445 DEFAULT_VOLUME_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07002446
2447 // Voice volume levels are mapped to adsp volume levels as follows.
2448 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
2449 // But this values don't changed in kernel. So, below change is need.
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09002450 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, my_data->max_vol_index);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002451 set_values[0] = vol_index;
Eric Laurentb23d5282013-05-14 15:27:20 -07002452
2453 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2454 if (!ctl) {
2455 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2456 __func__, mixer_ctl_name);
2457 return -EINVAL;
2458 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002459 ALOGV("Setting voice volume index: %d", set_values[0]);
2460 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2461
Nadav Barc46d0fa2017-12-24 14:50:37 +02002462 // Send mute command in case volume index is max since indexes are inverted
2463 // for mixer controls.
2464 if (vol_index == my_data->max_vol_index) {
2465 set_values[0] = 1;
2466 }
2467 else {
2468 set_values[0] = 0;
2469 }
2470
2471 ctl = mixer_get_ctl_by_name(adev->mixer, mute_mixer_ctl_name);
2472 if (!ctl) {
2473 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2474 __func__, mute_mixer_ctl_name);
2475 return -EINVAL;
2476 }
2477 ALOGV("%s: Setting RX Device Mute to: %d", __func__, set_values[0]);
2478 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2479
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002480 if (my_data->csd != NULL) {
2481 ret = my_data->csd->volume(ALL_SESSION_VSID, volume,
2482 DEFAULT_VOLUME_RAMP_DURATION_MS);
2483 if (ret < 0) {
2484 ALOGE("%s: csd_volume error %d", __func__, ret);
2485 }
2486 }
2487 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002488}
2489
2490int platform_set_mic_mute(void *platform, bool state)
2491{
2492 struct platform_data *my_data = (struct platform_data *)platform;
2493 struct audio_device *adev = my_data->adev;
2494 struct mixer_ctl *ctl;
2495 const char *mixer_ctl_name = "Voice Tx Mute";
sangwoo53b2cf02013-07-25 19:18:44 -07002496 int ret = 0;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002497 uint32_t set_values[ ] = {0,
2498 ALL_SESSION_VSID,
2499 DEFAULT_MUTE_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07002500
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09002501 if (adev->mode != AUDIO_MODE_IN_CALL &&
2502 adev->mode != AUDIO_MODE_IN_COMMUNICATION)
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002503 return 0;
2504
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09002505 if (adev->enable_hfp)
2506 mixer_ctl_name = "HFP Tx Mute";
2507
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002508 set_values[0] = state;
2509 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2510 if (!ctl) {
2511 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2512 __func__, mixer_ctl_name);
2513 return -EINVAL;
2514 }
2515 ALOGV("Setting voice mute state: %d", state);
2516 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2517
2518 if (my_data->csd != NULL) {
2519 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state,
2520 DEFAULT_MUTE_RAMP_DURATION_MS);
sangwoo53b2cf02013-07-25 19:18:44 -07002521 if (ret < 0) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002522 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
sangwoo53b2cf02013-07-25 19:18:44 -07002523 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002524 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002525 return ret;
2526}
Eric Laurentb23d5282013-05-14 15:27:20 -07002527
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002528int platform_set_device_mute(void *platform, bool state, char *dir)
2529{
2530 struct platform_data *my_data = (struct platform_data *)platform;
2531 struct audio_device *adev = my_data->adev;
2532 struct mixer_ctl *ctl;
2533 char *mixer_ctl_name = NULL;
2534 int ret = 0;
2535 uint32_t set_values[ ] = {0,
2536 ALL_SESSION_VSID,
2537 0};
2538 if(dir == NULL) {
2539 ALOGE("%s: Invalid direction:%s", __func__, dir);
2540 return -EINVAL;
2541 }
2542
2543 if (!strncmp("rx", dir, sizeof("rx"))) {
2544 mixer_ctl_name = "Voice Rx Device Mute";
2545 } else if (!strncmp("tx", dir, sizeof("tx"))) {
2546 mixer_ctl_name = "Voice Tx Device Mute";
2547 } else {
2548 return -EINVAL;
2549 }
2550
2551 set_values[0] = state;
2552 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2553 if (!ctl) {
2554 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2555 __func__, mixer_ctl_name);
2556 return -EINVAL;
2557 }
2558
2559 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
2560 __func__,state, mixer_ctl_name);
2561 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2562
2563 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002564}
2565
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002566int platform_can_split_snd_device(snd_device_t snd_device,
2567 int *num_devices,
2568 snd_device_t *new_snd_devices)
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002569{
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002570 int ret = -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002571 if (NULL == num_devices || NULL == new_snd_devices) {
2572 ALOGE("%s: NULL pointer ..", __func__);
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002573 return -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002574 }
2575
2576 /*
2577 * If wired headset/headphones/line devices share the same backend
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002578 * with speaker/earpiece this routine returns -EINVAL.
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002579 */
2580 if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES &&
2581 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_HEADPHONES)) {
2582 *num_devices = 2;
2583 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2584 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002585 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002586 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_LINE &&
2587 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_LINE)) {
2588 *num_devices = 2;
2589 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2590 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002591 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002592 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES &&
2593 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_HEADPHONES)) {
2594 *num_devices = 2;
2595 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2596 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002597 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002598 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE &&
2599 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_LINE)) {
2600 *num_devices = 2;
2601 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2602 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002603 ret = 0;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002604 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO &&
2605 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2606 SND_DEVICE_OUT_BT_SCO)) {
2607 *num_devices = 2;
2608 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2609 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO;
2610 ret = 0;
juyuchen5351ea62018-05-16 10:54:37 +08002611 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO &&
2612 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE,
2613 SND_DEVICE_OUT_BT_SCO)) {
2614 *num_devices = 2;
2615 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2616 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO;
2617 ret = 0;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002618 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB &&
2619 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2620 SND_DEVICE_OUT_BT_SCO_WB)) {
2621 *num_devices = 2;
2622 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2623 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO_WB;
2624 ret = 0;
juyuchen5351ea62018-05-16 10:54:37 +08002625 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB &&
2626 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE,
2627 SND_DEVICE_OUT_BT_SCO_WB)) {
2628 *num_devices = 2;
2629 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2630 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO_WB;
2631 ret = 0;
David Linee3fe402017-03-13 10:00:42 -07002632 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET &&
2633 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_USB_HEADSET)) {
2634 *num_devices = 2;
2635 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2636 new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
2637 ret = 0;
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07002638 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET &&
2639 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_USB_HEADSET)) {
2640 *num_devices = 2;
2641 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2642 new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
2643 ret = 0;
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002644 } else if (SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP == snd_device &&
2645 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2646 SND_DEVICE_OUT_BT_A2DP)) {
2647 *num_devices = 2;
2648 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2649 new_snd_devices[1] = SND_DEVICE_OUT_BT_A2DP;
2650 ret = 0;
Aniket Kumar Lata9723a962018-05-16 17:41:55 -07002651 } else if (SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP == snd_device &&
2652 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE,
2653 SND_DEVICE_OUT_BT_A2DP)) {
2654 *num_devices = 2;
2655 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2656 new_snd_devices[1] = SND_DEVICE_OUT_BT_A2DP;
2657 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002658 }
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002659
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002660 return ret;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002661}
2662
Eric Laurentb23d5282013-05-14 15:27:20 -07002663snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
2664{
2665 struct platform_data *my_data = (struct platform_data *)platform;
2666 struct audio_device *adev = my_data->adev;
2667 audio_mode_t mode = adev->mode;
2668 snd_device_t snd_device = SND_DEVICE_NONE;
2669
2670 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
2671 if (devices == AUDIO_DEVICE_NONE ||
2672 devices & AUDIO_DEVICE_BIT_IN) {
2673 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
2674 goto exit;
2675 }
2676
Eric Laurent1b491552015-09-15 17:52:41 -07002677 if (popcount(devices) == 2) {
2678 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2679 AUDIO_DEVICE_OUT_SPEAKER) ||
2680 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2681 AUDIO_DEVICE_OUT_SPEAKER)) {
2682 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
2683 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2684 AUDIO_DEVICE_OUT_SPEAKER)) {
2685 snd_device = SND_DEVICE_OUT_SPEAKER_AND_LINE;
2686 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2687 AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
2688 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2689 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2690 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES;
2691 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2692 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2693 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE;
2694 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
2695 AUDIO_DEVICE_OUT_SPEAKER)) {
2696 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002697 } else if ((devices & AUDIO_DEVICE_OUT_ALL_SCO) &&
2698 ((devices & ~AUDIO_DEVICE_OUT_ALL_SCO) == AUDIO_DEVICE_OUT_SPEAKER)) {
2699 snd_device = adev->bt_wb_speech_enabled ?
2700 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB :
2701 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO;
juyuchen5351ea62018-05-16 10:54:37 +08002702 } else if ((devices & AUDIO_DEVICE_OUT_ALL_SCO) &&
2703 ((devices & ~AUDIO_DEVICE_OUT_ALL_SCO) == AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2704 snd_device = adev->bt_wb_speech_enabled ?
2705 SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB :
2706 SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO;
Eric Laurent99dab492017-06-17 15:19:08 -07002707 } else if ((devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
2708 AUDIO_DEVICE_OUT_SPEAKER)) ||
2709 (devices == (AUDIO_DEVICE_OUT_USB_HEADSET |
2710 AUDIO_DEVICE_OUT_SPEAKER))) {
David Linee3fe402017-03-13 10:00:42 -07002711 snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET;
Eric Laurentd0f7c262017-07-05 09:09:12 -07002712 } else if ((devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
2713 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) ||
2714 (devices == (AUDIO_DEVICE_OUT_USB_HEADSET |
2715 AUDIO_DEVICE_OUT_SPEAKER_SAFE))) {
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07002716 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET;
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002717 } else if ((devices & AUDIO_DEVICE_OUT_SPEAKER) &&
2718 (devices & AUDIO_DEVICE_OUT_ALL_A2DP)) {
2719 snd_device = SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP;
Aniket Kumar Lata9723a962018-05-16 17:41:55 -07002720 } else if ((devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) &&
2721 (devices & AUDIO_DEVICE_OUT_ALL_A2DP)) {
2722 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP;
Eric Laurent1b491552015-09-15 17:52:41 -07002723 } else {
2724 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
2725 goto exit;
2726 }
2727 if (snd_device != SND_DEVICE_NONE) {
2728 goto exit;
2729 }
2730 }
2731
2732 if (popcount(devices) != 1) {
2733 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
2734 goto exit;
2735 }
2736
Madhuri Athota3f6051b2016-10-13 23:25:38 +05302737 if (voice_is_in_call(adev) || adev->enable_voicerx || audio_extn_hfp_is_active(adev)) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002738 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002739 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2740 devices & AUDIO_DEVICE_OUT_LINE) {
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002741 if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002742 (adev->voice.tty_mode == TTY_MODE_FULL))
Eric Laurentb23d5282013-05-14 15:27:20 -07002743 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002744 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002745 (adev->voice.tty_mode == TTY_MODE_VCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002746 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002747 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002748 (adev->voice.tty_mode == TTY_MODE_HCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002749 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002750 else {
2751 if (devices & AUDIO_DEVICE_OUT_LINE)
2752 snd_device = SND_DEVICE_OUT_VOICE_LINE;
yixuanjiang9536e672018-09-06 18:43:36 +08002753 else if (devices & AUDIO_DEVICE_OUT_WIRED_HEADSET)
2754 snd_device = SND_DEVICE_OUT_VOICE_HEADSET;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002755 else
2756 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
2757 }
Eric Laurent99dab492017-06-17 15:19:08 -07002758 } else if (audio_is_usb_out_device(devices)) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002759 if (voice_is_in_call(adev)) {
2760 switch (adev->voice.tty_mode) {
2761 case TTY_MODE_FULL:
2762 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_USB;
2763 break;
2764 case TTY_MODE_VCO:
2765 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_USB;
2766 break;
2767 case TTY_MODE_HCO:
2768 // since Hearing will be on handset\speaker, use existing device
2769 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
2770 break;
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002771 case TTY_MODE_OFF:
2772 break;
vivek mehtaa6b79742017-03-09 15:40:43 -08002773 default:
2774 ALOGE("%s: Invalid TTY mode (%#x)",
2775 __func__, adev->voice.tty_mode);
2776 }
2777 }
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002778 if (snd_device == SND_DEVICE_NONE) {
2779 snd_device = audio_extn_usb_is_capture_supported() ?
2780 SND_DEVICE_OUT_VOICE_USB_HEADSET :
2781 SND_DEVICE_OUT_VOICE_USB_HEADPHONES;
2782 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002783 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002784 if (adev->bt_wb_speech_enabled) {
2785 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2786 } else {
2787 snd_device = SND_DEVICE_OUT_BT_SCO;
2788 }
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002789 } else if (devices & AUDIO_DEVICE_OUT_ALL_A2DP) {
2790 snd_device = SND_DEVICE_OUT_BT_A2DP;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002791 } else if (devices & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002792 if (!adev->enable_hfp) {
2793 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
2794 } else {
2795 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_HFP;
2796 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002797 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002798 if(adev->voice.hac)
2799 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2800 else if (is_operator_tmus())
Eric Laurentb23d5282013-05-14 15:27:20 -07002801 snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS;
2802 else
Eric Laurentb4d368e2014-06-25 10:21:54 -05002803 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002804 } else if (devices & AUDIO_DEVICE_OUT_TELEPHONY_TX)
2805 snd_device = SND_DEVICE_OUT_VOICE_TX;
2806
Eric Laurentb23d5282013-05-14 15:27:20 -07002807 if (snd_device != SND_DEVICE_NONE) {
2808 goto exit;
2809 }
2810 }
2811
Eric Laurentb23d5282013-05-14 15:27:20 -07002812 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2813 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2814 snd_device = SND_DEVICE_OUT_HEADPHONES;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002815 } else if (devices & AUDIO_DEVICE_OUT_LINE) {
2816 snd_device = SND_DEVICE_OUT_LINE;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002817 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) {
2818 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE;
Eric Laurentb23d5282013-05-14 15:27:20 -07002819 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
andysu5b30b062018-04-20 16:34:06 +08002820 /*
2821 * Perform device switch only if acdb tuning is different between SPEAKER & SPEAKER_REVERSE,
2822 * Or there will be a small pause while performing device switch.
2823 */
2824 if (my_data->speaker_lr_swap &&
2825 (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
2826 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]))
Eric Laurentb23d5282013-05-14 15:27:20 -07002827 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
2828 else
2829 snd_device = SND_DEVICE_OUT_SPEAKER;
2830 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002831 if (adev->bt_wb_speech_enabled) {
2832 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2833 } else {
2834 snd_device = SND_DEVICE_OUT_BT_SCO;
2835 }
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002836 } else if (devices & AUDIO_DEVICE_OUT_ALL_A2DP) {
2837 snd_device = SND_DEVICE_OUT_BT_A2DP;
Eric Laurentb23d5282013-05-14 15:27:20 -07002838 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2839 snd_device = SND_DEVICE_OUT_HDMI ;
Eric Laurent99dab492017-06-17 15:19:08 -07002840 } else if (audio_is_usb_out_device(devices)) {
jasmine cha270b7762018-03-30 15:41:33 +08002841 if (audio_extn_ma_supported_usb())
2842 snd_device = SND_DEVICE_OUT_USB_HEADSET_SPEC;
2843 else if (audio_extn_usb_is_capture_supported())
David Linee3fe402017-03-13 10:00:42 -07002844 snd_device = SND_DEVICE_OUT_USB_HEADSET;
2845 else
2846 snd_device = SND_DEVICE_OUT_USB_HEADPHONES;
2847 }else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002848 /*HAC support for voice-ish audio (eg visual voicemail)*/
2849 if(adev->voice.hac)
2850 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2851 else
2852 snd_device = SND_DEVICE_OUT_HANDSET;
Eric Laurentb23d5282013-05-14 15:27:20 -07002853 } else {
2854 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
2855 }
2856exit:
2857 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
2858 return snd_device;
2859}
2860
2861snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
2862{
2863 struct platform_data *my_data = (struct platform_data *)platform;
2864 struct audio_device *adev = my_data->adev;
2865 audio_source_t source = (adev->active_input == NULL) ?
2866 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
2867
2868 audio_mode_t mode = adev->mode;
2869 audio_devices_t in_device = ((adev->active_input == NULL) ?
2870 AUDIO_DEVICE_NONE : adev->active_input->device)
2871 & ~AUDIO_DEVICE_BIT_IN;
2872 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
2873 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
2874 snd_device_t snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002875 int channel_count = popcount(channel_mask);
Eric Laurentb23d5282013-05-14 15:27:20 -07002876
Prashant Malanic92c5962015-08-11 15:10:18 -07002877 ALOGV("%s: enter: out_device(%#x) in_device(%#x) channel_count (%d) channel_mask (0x%x)",
2878 __func__, out_device, in_device, channel_count, channel_mask);
Devin Kimd789e432016-10-26 15:07:27 -07002879 if ((out_device != AUDIO_DEVICE_NONE) && (voice_is_in_call(adev) ||
2880 audio_extn_hfp_is_active(adev))) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002881 if (adev->voice.tty_mode != TTY_MODE_OFF) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002882 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002883 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2884 out_device & AUDIO_DEVICE_OUT_LINE) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002885 switch (adev->voice.tty_mode) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002886 case TTY_MODE_FULL:
2887 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
2888 break;
2889 case TTY_MODE_VCO:
2890 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
2891 break;
2892 case TTY_MODE_HCO:
2893 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
2894 break;
2895 default:
2896 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
2897 }
2898 goto exit;
Eric Laurent99dab492017-06-17 15:19:08 -07002899 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002900 switch (adev->voice.tty_mode) {
2901 case TTY_MODE_FULL:
2902 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC;
2903 break;
2904 case TTY_MODE_VCO:
2905 // since voice will be captured from handset mic, use existing device
2906 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
2907 break;
2908 case TTY_MODE_HCO:
2909 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC;
2910 break;
2911 default:
2912 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
Eric Laurentb23d5282013-05-14 15:27:20 -07002913 }
2914 goto exit;
2915 }
2916 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002917 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002918 if (my_data->fluence_in_voice_call == false) {
2919 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2920 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002921 if (is_operator_tmus())
2922 snd_device = SND_DEVICE_IN_VOICE_DMIC_TMUS;
Eric Laurentb23d5282013-05-14 15:27:20 -07002923 else
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002924 snd_device = SND_DEVICE_IN_VOICE_DMIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002925 }
2926 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2927 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
2928 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002929 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002930 if (adev->bluetooth_nrec)
2931 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2932 else
2933 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002934 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002935 if (adev->bluetooth_nrec)
2936 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2937 else
2938 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002939 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002940 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Prashant Malanic92c5962015-08-11 15:10:18 -07002941 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
2942 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2943 out_device & AUDIO_DEVICE_OUT_LINE) {
2944 if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
2945 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
2946 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
2947 } else {
2948 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2949 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002950 }
vivek mehtafe121d52015-08-10 23:39:23 -07002951
2952 //select default
2953 if (snd_device == SND_DEVICE_NONE) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002954 if (!adev->enable_hfp) {
2955 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2956 } else {
2957 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP;
2958 platform_set_echo_reference(adev, true, out_device);
2959 }
vivek mehtafe121d52015-08-10 23:39:23 -07002960 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002961 } else if (out_device & AUDIO_DEVICE_OUT_TELEPHONY_TX) {
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002962 snd_device = SND_DEVICE_IN_VOICE_RX;
Eric Laurent99dab492017-06-17 15:19:08 -07002963 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
David Lin40b07892017-08-07 15:02:48 -07002964 if (audio_extn_usb_is_capture_supported()) {
2965 snd_device = SND_DEVICE_IN_VOICE_USB_HEADSET_MIC;
2966 } else if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
2967 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
2968 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
2969 } else {
2970 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2971 }
2972 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002973 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002974 } else if (source == AUDIO_SOURCE_CAMCORDER) {
2975 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
2976 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Eric Laurent5f4ca952018-10-19 17:33:43 -07002977 switch (adev->camera_orientation) {
2978 case CAMERA_BACK_LANDSCAPE:
2979 snd_device = SND_DEVICE_IN_CAMCORDER_LANDSCAPE;
2980 break;
2981 case CAMERA_BACK_INVERT_LANDSCAPE:
2982 snd_device = SND_DEVICE_IN_CAMCORDER_INVERT_LANDSCAPE;
2983 break;
2984 case CAMERA_BACK_PORTRAIT:
2985 snd_device = SND_DEVICE_IN_CAMCORDER_PORTRAIT;
2986 break;
2987 case CAMERA_FRONT_LANDSCAPE:
2988 snd_device = SND_DEVICE_IN_CAMCORDER_SELFIE_LANDSCAPE;
2989 break;
2990 case CAMERA_FRONT_INVERT_LANDSCAPE:
2991 snd_device = SND_DEVICE_IN_CAMCORDER_SELFIE_INVERT_LANDSCAPE;
2992 break;
2993 case CAMERA_FRONT_PORTRAIT:
2994 snd_device = SND_DEVICE_IN_CAMCORDER_SELFIE_PORTRAIT;
2995 break;
2996 default:
2997 ALOGW("%s: invalid camera orientation %08x", __func__, adev->camera_orientation);
2998 snd_device = SND_DEVICE_IN_CAMCORDER_LANDSCAPE;
2999 break;
3000 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003001 }
3002 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
3003 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003004 if (my_data->fluence_in_voice_rec && channel_count == 1) {
3005 if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
3006 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07003007 if (adev->active_input->enable_aec)
3008 snd_device = SND_DEVICE_IN_HANDSET_QMIC_AEC;
3009 else
3010 snd_device = SND_DEVICE_IN_HANDSET_QMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003011 } else if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
3012 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07003013 if (adev->active_input->enable_aec)
3014 snd_device = SND_DEVICE_IN_HANDSET_TMIC_AEC;
3015 else
3016 snd_device = SND_DEVICE_IN_HANDSET_TMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003017 } else if (((my_data->fluence_type == FLUENCE_PRO_ENABLE) ||
3018 (my_data->fluence_type == FLUENCE_ENABLE)) &&
3019 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07003020 if (adev->active_input->enable_aec)
3021 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
3022 else
3023 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
Prashant Malanic92c5962015-08-11 15:10:18 -07003024 }
3025 platform_set_echo_reference(adev, true, out_device);
3026 } else if ((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) &&
3027 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
3028 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003029 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003030 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
3031 snd_device = SND_DEVICE_IN_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003032 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003033 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
3034 snd_device = SND_DEVICE_IN_QUAD_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07003035 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003036 if (snd_device == SND_DEVICE_NONE) {
vivek mehtaf3440682016-05-11 14:24:37 -07003037 if (adev->active_input->enable_aec) {
3038 if (adev->active_input->enable_ns) {
3039 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS;
3040 } else {
3041 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC;
3042 }
vivek mehta733c1df2016-04-04 15:09:24 -07003043 platform_set_echo_reference(adev, true, out_device);
vivek mehtaf3440682016-05-11 14:24:37 -07003044 } else if (adev->active_input->enable_ns) {
3045 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
3046 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003047 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
vivek mehtaf3440682016-05-11 14:24:37 -07003048 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003049 }
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -07003050 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3051 snd_device = SND_DEVICE_IN_VOICE_REC_HEADSET_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07003052 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07003053 snd_device = SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07003054 }
rago90fb9612015-12-02 11:37:53 -08003055 } else if (source == AUDIO_SOURCE_UNPROCESSED) {
3056 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
vivek mehta4ed66e62016-04-15 23:33:34 -07003057 if (((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) ||
3058 (channel_mask == AUDIO_CHANNEL_IN_STEREO)) &&
3059 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
3060 snd_device = SND_DEVICE_IN_UNPROCESSED_STEREO_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003061 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07003062 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
3063 snd_device = SND_DEVICE_IN_UNPROCESSED_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003064 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07003065 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
3066 snd_device = SND_DEVICE_IN_UNPROCESSED_QUAD_MIC;
3067 } else {
3068 snd_device = SND_DEVICE_IN_UNPROCESSED_MIC;
3069 }
rago90fb9612015-12-02 11:37:53 -08003070 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3071 snd_device = SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07003072 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07003073 snd_device = SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC;
rago90fb9612015-12-02 11:37:53 -08003074 }
Eric Laurent50a38ed2015-10-14 18:48:06 -07003075 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION ||
rago90fb9612015-12-02 11:37:53 -08003076 mode == AUDIO_MODE_IN_COMMUNICATION) {
David Lin40b07892017-08-07 15:02:48 -07003077 if (out_device & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
3078 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
3079 (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE | AUDIO_DEVICE_OUT_USB_HEADSET) &&
3080 !audio_extn_usb_is_capture_supported())) {
Eric Laurentb23d5282013-05-14 15:27:20 -07003081 in_device = AUDIO_DEVICE_IN_BACK_MIC;
David Lin40b07892017-08-07 15:02:48 -07003082 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003083 if (adev->active_input) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003084 if (adev->active_input->enable_aec &&
3085 adev->active_input->enable_ns) {
Eric Laurentb23d5282013-05-14 15:27:20 -07003086 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003087 if (my_data->fluence_in_spkr_mode &&
3088 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003089 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003090 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003091 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003092 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003093 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003094 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003095 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003096 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003097 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003098 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003099 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003100 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05003101 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3102 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Eric Laurent99dab492017-06-17 15:19:08 -07003103 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07003104 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
Eric Laurentb23d5282013-05-14 15:27:20 -07003105 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05003106 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003107 } else if (adev->active_input->enable_aec) {
3108 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
3109 if (my_data->fluence_in_spkr_mode &&
3110 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003111 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003112 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003113 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003114 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003115 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003116 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
3117 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003118 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003119 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003120 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003121 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003122 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05003123 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3124 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Eric Laurent99dab492017-06-17 15:19:08 -07003125 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07003126 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
Eric Laurentcefbbac2014-09-04 13:54:10 -05003127 }
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08003128 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003129 } else if (adev->active_input->enable_ns) {
3130 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
3131 if (my_data->fluence_in_spkr_mode &&
3132 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003133 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003134 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003135 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003136 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003137 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003138 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
3139 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003140 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003141 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003142 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003143 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003144 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003145 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05003146 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003147 }
3148 } else if (source == AUDIO_SOURCE_DEFAULT) {
3149 goto exit;
3150 }
3151
3152
3153 if (snd_device != SND_DEVICE_NONE) {
3154 goto exit;
3155 }
3156
3157 if (in_device != AUDIO_DEVICE_NONE &&
3158 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
3159 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
3160 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003161 if ((my_data->source_mic_type & SOURCE_QUAD_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003162 channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003163 snd_device = SND_DEVICE_IN_QUAD_MIC;
3164 } else if ((my_data->source_mic_type & SOURCE_THREE_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003165 channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003166 snd_device = SND_DEVICE_IN_THREE_MIC;
3167 } else if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
3168 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003169 snd_device = SND_DEVICE_IN_HANDSET_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07003170 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
3171 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003172 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003173 } else {
3174 ALOGE("%s: something wrong (1): source type (%d) channel_count (%d) .."
3175 " channel mask (0x%x) no combination found .. setting to mono", __func__,
3176 my_data->source_mic_type, channel_count, channel_mask);
3177 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3178 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003179 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003180 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
3181 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003182 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07003183 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
3184 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003185 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003186 } else {
3187 ALOGE("%s: something wrong (2): source type (%d) channel_count (%d) .."
3188 " no combination found .. setting to mono", __func__,
3189 my_data->source_mic_type, channel_count);
3190 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
3191 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003192 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3193 snd_device = SND_DEVICE_IN_HEADSET_MIC;
3194 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003195 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003196 if (adev->bluetooth_nrec)
3197 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
3198 else
3199 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003200 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003201 if (adev->bluetooth_nrec)
3202 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
3203 else
3204 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003205 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003206 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
3207 snd_device = SND_DEVICE_IN_HDMI_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07003208 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
David Linee3fe402017-03-13 10:00:42 -07003209 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07003210 } else {
3211 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
3212 ALOGW("%s: Using default handset-mic", __func__);
3213 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3214 }
3215 } else {
3216 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
3217 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3218 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
3219 snd_device = SND_DEVICE_IN_HEADSET_MIC;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003220 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07003221 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003222 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05003223 out_device & AUDIO_DEVICE_OUT_LINE) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003224 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
3225 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003226 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07003227 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
3228 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003229 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003230 } else {
3231 ALOGE("%s: something wrong (3): source type (%d) channel_count (%d) .."
3232 " no combination found .. setting to mono", __func__,
3233 my_data->source_mic_type, channel_count);
3234 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
3235 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003236 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003237 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003238 if (adev->bluetooth_nrec)
3239 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
3240 else
3241 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003242 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003243 if (adev->bluetooth_nrec)
3244 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
3245 else
3246 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003247 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003248 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
3249 snd_device = SND_DEVICE_IN_HDMI_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07003250 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
David Linee3fe402017-03-13 10:00:42 -07003251 if (audio_extn_usb_is_capture_supported())
3252 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
3253 else
3254 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07003255 } else {
3256 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
3257 ALOGW("%s: Using default handset-mic", __func__);
3258 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3259 }
3260 }
3261exit:
3262 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
3263 return snd_device;
3264}
3265
3266int platform_set_hdmi_channels(void *platform, int channel_count)
3267{
3268 struct platform_data *my_data = (struct platform_data *)platform;
3269 struct audio_device *adev = my_data->adev;
3270 struct mixer_ctl *ctl;
3271 const char *channel_cnt_str = NULL;
3272 const char *mixer_ctl_name = "HDMI_RX Channels";
3273 switch (channel_count) {
3274 case 8:
3275 channel_cnt_str = "Eight"; break;
3276 case 7:
3277 channel_cnt_str = "Seven"; break;
3278 case 6:
3279 channel_cnt_str = "Six"; break;
3280 case 5:
3281 channel_cnt_str = "Five"; break;
3282 case 4:
3283 channel_cnt_str = "Four"; break;
3284 case 3:
3285 channel_cnt_str = "Three"; break;
3286 default:
3287 channel_cnt_str = "Two"; break;
3288 }
3289 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3290 if (!ctl) {
3291 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3292 __func__, mixer_ctl_name);
3293 return -EINVAL;
3294 }
3295 ALOGV("HDMI channel count: %s", channel_cnt_str);
3296 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
3297 return 0;
3298}
3299
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003300int platform_edid_get_max_channels(void *platform)
Eric Laurentb23d5282013-05-14 15:27:20 -07003301{
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003302 struct platform_data *my_data = (struct platform_data *)platform;
3303 struct audio_device *adev = my_data->adev;
Eric Laurentb23d5282013-05-14 15:27:20 -07003304 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
3305 char *sad = block;
3306 int num_audio_blocks;
3307 int channel_count;
3308 int max_channels = 0;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003309 int i, ret, count;
Eric Laurentb23d5282013-05-14 15:27:20 -07003310
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003311 struct mixer_ctl *ctl;
3312
3313 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
3314 if (!ctl) {
3315 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3316 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
Eric Laurentb23d5282013-05-14 15:27:20 -07003317 return 0;
3318 }
3319
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003320 mixer_ctl_update(ctl);
3321
3322 count = mixer_ctl_get_num_values(ctl);
Eric Laurentb23d5282013-05-14 15:27:20 -07003323
3324 /* Read SAD blocks, clamping the maximum size for safety */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003325 if (count > (int)sizeof(block))
3326 count = (int)sizeof(block);
Eric Laurentb23d5282013-05-14 15:27:20 -07003327
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003328 ret = mixer_ctl_get_array(ctl, block, count);
3329 if (ret != 0) {
3330 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
3331 return 0;
3332 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003333
3334 /* Calculate the number of SAD blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003335 num_audio_blocks = count / SAD_BLOCK_SIZE;
Eric Laurentb23d5282013-05-14 15:27:20 -07003336
3337 for (i = 0; i < num_audio_blocks; i++) {
3338 /* Only consider LPCM blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003339 if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
3340 sad += 3;
Eric Laurentb23d5282013-05-14 15:27:20 -07003341 continue;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003342 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003343
3344 channel_count = (sad[0] & 0x7) + 1;
3345 if (channel_count > max_channels)
3346 max_channels = channel_count;
3347
3348 /* Advance to next block */
3349 sad += 3;
3350 }
3351
3352 return max_channels;
3353}
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003354
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07003355int platform_set_incall_recording_session_id(void *platform,
3356 uint32_t session_id, int rec_mode)
3357{
3358 int ret = 0;
3359 struct platform_data *my_data = (struct platform_data *)platform;
3360 struct audio_device *adev = my_data->adev;
3361 struct mixer_ctl *ctl;
3362 const char *mixer_ctl_name = "Voc VSID";
3363 int num_ctl_values;
3364 int i;
3365
3366 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3367 if (!ctl) {
3368 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3369 __func__, mixer_ctl_name);
3370 ret = -EINVAL;
3371 } else {
3372 num_ctl_values = mixer_ctl_get_num_values(ctl);
3373 for (i = 0; i < num_ctl_values; i++) {
3374 if (mixer_ctl_set_value(ctl, i, session_id)) {
3375 ALOGV("Error: invalid session_id: %x", session_id);
3376 ret = -EINVAL;
3377 break;
3378 }
3379 }
3380 }
3381
3382 if (my_data->csd != NULL) {
3383 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
3384 if (ret < 0) {
3385 ALOGE("%s: csd_client_start_record failed, error %d",
3386 __func__, ret);
3387 }
3388 }
3389
3390 return ret;
3391}
3392
Arun Mirpuriba2749a2018-04-17 14:32:24 -07003393int platform_set_incall_recording_session_channels(void *platform,
3394 uint32_t channel_count)
3395{
3396 int ret = 0;
3397 struct platform_data *my_data = (struct platform_data *)platform;
3398 struct audio_device *adev = my_data->adev;
3399 const char *mixer_ctl_name = "Voc Rec Config";
3400 int num_ctl_values;
3401 int i;
3402 struct mixer_ctl *ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3403
3404 if (!ctl) {
3405 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3406 __func__, mixer_ctl_name);
3407 ret = -EINVAL;
3408 } else {
3409 num_ctl_values = mixer_ctl_get_num_values(ctl);
3410 for (i = 0; i < num_ctl_values; i++) {
3411 if (mixer_ctl_set_value(ctl, i, channel_count)) {
3412 ALOGE("Error: invalid channel count: %x", channel_count);
3413 ret = -EINVAL;
3414 break;
3415 }
3416 }
3417 }
3418
3419 return ret;
3420}
3421
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07003422int platform_stop_incall_recording_usecase(void *platform)
3423{
3424 int ret = 0;
3425 struct platform_data *my_data = (struct platform_data *)platform;
3426
3427 if (my_data->csd != NULL) {
3428 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
3429 if (ret < 0) {
3430 ALOGE("%s: csd_client_stop_record failed, error %d",
3431 __func__, ret);
3432 }
3433 }
3434
3435 return ret;
3436}
3437
3438int platform_start_incall_music_usecase(void *platform)
3439{
3440 int ret = 0;
3441 struct platform_data *my_data = (struct platform_data *)platform;
3442
3443 if (my_data->csd != NULL) {
3444 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
3445 if (ret < 0) {
3446 ALOGE("%s: csd_client_start_playback failed, error %d",
3447 __func__, ret);
3448 }
3449 }
3450
3451 return ret;
3452}
3453
3454int platform_stop_incall_music_usecase(void *platform)
3455{
3456 int ret = 0;
3457 struct platform_data *my_data = (struct platform_data *)platform;
3458
3459 if (my_data->csd != NULL) {
3460 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
3461 if (ret < 0) {
3462 ALOGE("%s: csd_client_stop_playback failed, error %d",
3463 __func__, ret);
3464 }
3465 }
3466
3467 return ret;
3468}
3469
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003470int platform_set_parameters(void *platform, struct str_parms *parms)
3471{
3472 struct platform_data *my_data = (struct platform_data *)platform;
jasmine chac89321b2018-04-10 21:37:01 +08003473 char *value = NULL;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003474 char *kv_pairs = str_parms_to_str(parms);
jasmine chac89321b2018-04-10 21:37:01 +08003475 int len;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003476 int ret = 0, err;
3477
3478 if (kv_pairs == NULL) {
3479 ret = -EINVAL;
Jasmine Chaa314e192018-05-09 17:46:28 +08003480 ALOGE("%s: key-value pair is NULL", __func__);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003481 goto done;
3482 }
3483
3484 ALOGV("%s: enter: %s", __func__, kv_pairs);
3485
jasmine chac89321b2018-04-10 21:37:01 +08003486 len = strlen(kv_pairs);
Jasmine Chaa314e192018-05-09 17:46:28 +08003487 value = (char*)calloc(len + 1, sizeof(char));
jasmine chac89321b2018-04-10 21:37:01 +08003488 if (value == NULL) {
3489 ret = -ENOMEM;
Jasmine Chaa314e192018-05-09 17:46:28 +08003490 ALOGE("[%s] failed to allocate memory", __func__);
jasmine chac89321b2018-04-10 21:37:01 +08003491 goto done;
3492 }
3493
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003494 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME,
jasmine chac89321b2018-04-10 21:37:01 +08003495 value, len);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003496 if (err >= 0) {
3497 str_parms_del(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME);
3498 my_data->snd_card_name = strdup(value);
3499 ALOGV("%s: sound card name %s", __func__, my_data->snd_card_name);
3500 }
3501
keunhui.park2f7306a2015-07-16 16:48:06 +09003502 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO,
jasmine chac89321b2018-04-10 21:37:01 +08003503 value, len);
keunhui.park2f7306a2015-07-16 16:48:06 +09003504 if (err >= 0) {
3505 struct operator_info *info;
3506 char *str = value;
3507 char *name;
3508
3509 str_parms_del(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO);
3510 info = (struct operator_info *)calloc(1, sizeof(struct operator_info));
3511 name = strtok(str, ";");
3512 info->name = strdup(name);
3513 info->mccmnc = strdup(str + strlen(name) + 1);
3514
3515 list_add_tail(&operator_info_list, &info->list);
Joe Onorato188b6222016-03-01 11:02:27 -08003516 ALOGV("%s: add operator[%s] mccmnc[%s]", __func__, info->name, info->mccmnc);
keunhui.park2f7306a2015-07-16 16:48:06 +09003517 }
Prashant Malanic92c5962015-08-11 15:10:18 -07003518
Jasmine Chaa314e192018-05-09 17:46:28 +08003519 memset(value, 0, len + 1);
Eric Laurentc6333382015-09-14 12:43:44 -07003520 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT,
jasmine chac89321b2018-04-10 21:37:01 +08003521 value, len);
Prashant Malanic92c5962015-08-11 15:10:18 -07003522 if (err >= 0) {
Eric Laurentc6333382015-09-14 12:43:44 -07003523 str_parms_del(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT);
Prashant Malanic92c5962015-08-11 15:10:18 -07003524 my_data->max_mic_count = atoi(value);
3525 ALOGV("%s: max_mic_count %s/%d", __func__, value, my_data->max_mic_count);
Prashant Malanic92c5962015-08-11 15:10:18 -07003526 }
3527
jasmine chac89321b2018-04-10 21:37:01 +08003528 /* handle audio calibration parameters */
3529 set_audiocal(platform, parms, value, len);
3530
vivek mehta90933872017-06-15 18:04:39 -07003531 // to-do: disable setting sidetone gain, will revist this later
3532 // audio_extn_usb_set_sidetone_gain(parms, value, len);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003533done:
3534 ALOGV("%s: exit with code(%d)", __func__, ret);
3535 if (kv_pairs != NULL)
3536 free(kv_pairs);
jasmine chac89321b2018-04-10 21:37:01 +08003537 if (value != NULL)
3538 free(value);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003539
3540 return ret;
3541}
3542
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003543/* Delay in Us */
3544int64_t platform_render_latency(audio_usecase_t usecase)
3545{
3546 switch (usecase) {
3547 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
3548 return DEEP_BUFFER_PLATFORM_DELAY;
3549 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
3550 return LOW_LATENCY_PLATFORM_DELAY;
Haynes Mathew George03c40102016-01-29 17:57:48 -08003551 case USECASE_AUDIO_PLAYBACK_ULL:
3552 return ULL_PLATFORM_DELAY;
Eric Laurent0e46adf2016-12-16 12:49:24 -08003553 case USECASE_AUDIO_PLAYBACK_MMAP:
3554 return MMAP_PLATFORM_DELAY;
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003555 default:
3556 return 0;
3557 }
3558}
Haynes Mathew George98c95622014-06-20 19:14:25 -07003559
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003560int platform_set_snd_device_backend(snd_device_t device, const char *backend_tag,
3561 const char * hw_interface)
Haynes Mathew George98c95622014-06-20 19:14:25 -07003562{
3563 int ret = 0;
3564
3565 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
3566 ALOGE("%s: Invalid snd_device = %d",
3567 __func__, device);
3568 ret = -EINVAL;
3569 goto done;
3570 }
3571
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003572 ALOGV("%s: backend_tag_table[%s]: old = %s new = %s", __func__,
3573 platform_get_snd_device_name(device),
3574 backend_tag_table[device] != NULL ? backend_tag_table[device]: "null", backend_tag);
3575 if (backend_tag_table[device]) {
3576 free(backend_tag_table[device]);
Haynes Mathew George98c95622014-06-20 19:14:25 -07003577 }
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003578 backend_tag_table[device] = strdup(backend_tag);
3579
3580 if (hw_interface != NULL) {
3581 if (hw_interface_table[device])
3582 free(hw_interface_table[device]);
3583 ALOGV("%s: hw_interface_table[%d] = %s", __func__, device, hw_interface);
3584 hw_interface_table[device] = strdup(hw_interface);
3585 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07003586done:
3587 return ret;
3588}
3589
3590int platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t pcm_id)
3591{
3592 int ret = 0;
3593 if ((usecase <= USECASE_INVALID) || (usecase >= AUDIO_USECASE_MAX)) {
3594 ALOGE("%s: invalid usecase case idx %d", __func__, usecase);
3595 ret = -EINVAL;
3596 goto done;
3597 }
3598
3599 if ((type != 0) && (type != 1)) {
3600 ALOGE("%s: invalid usecase type", __func__);
3601 ret = -EINVAL;
3602 }
vivek mehtaa68fea62017-06-08 19:04:02 -07003603 ALOGV("%s: pcm_device_table[%d %s][%d] = %d", __func__, usecase,
3604 use_case_table[usecase],
3605 type, pcm_id);
Haynes Mathew George98c95622014-06-20 19:14:25 -07003606 pcm_device_table[usecase][type] = pcm_id;
3607done:
3608 return ret;
3609}
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003610
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07003611#define DEFAULT_NOMINAL_SPEAKER_GAIN 20
3612int ramp_speaker_gain(struct audio_device *adev, bool ramp_up, int target_ramp_up_gain) {
3613 // backup_gain: gain to try to set in case of an error during ramp
3614 int start_gain, end_gain, step, backup_gain, i;
3615 bool error = false;
3616 const struct mixer_ctl *ctl;
3617 const char *mixer_ctl_name_gain_left = "Left Speaker Gain";
3618 const char *mixer_ctl_name_gain_right = "Right Speaker Gain";
3619 struct mixer_ctl *ctl_left = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_left);
3620 struct mixer_ctl *ctl_right = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_right);
3621 if (!ctl_left || !ctl_right) {
3622 ALOGE("%s: Could not get ctl for mixer cmd - %s or %s, not applying speaker gain ramp",
3623 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
3624 return -EINVAL;
3625 } else if ((mixer_ctl_get_num_values(ctl_left) != 1)
3626 || (mixer_ctl_get_num_values(ctl_right) != 1)) {
3627 ALOGE("%s: Unexpected num values for mixer cmd - %s or %s, not applying speaker gain ramp",
3628 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
3629 return -EINVAL;
3630 }
3631 if (ramp_up) {
3632 start_gain = 0;
3633 end_gain = target_ramp_up_gain > 0 ? target_ramp_up_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
3634 step = +1;
3635 backup_gain = end_gain;
3636 } else {
3637 // using same gain on left and right
3638 const int left_gain = mixer_ctl_get_value(ctl_left, 0);
3639 start_gain = left_gain > 0 ? left_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
3640 end_gain = 0;
3641 step = -1;
3642 backup_gain = start_gain;
3643 }
3644 for (i = start_gain ; i != (end_gain + step) ; i += step) {
3645 //ALOGV("setting speaker gain to %d", i);
3646 if (mixer_ctl_set_value(ctl_left, 0, i)) {
3647 ALOGE("%s: error setting %s to %d during gain ramp",
3648 __func__, mixer_ctl_name_gain_left, i);
3649 error = true;
3650 break;
3651 }
3652 if (mixer_ctl_set_value(ctl_right, 0, i)) {
3653 ALOGE("%s: error setting %s to %d during gain ramp",
3654 __func__, mixer_ctl_name_gain_right, i);
3655 error = true;
3656 break;
3657 }
3658 usleep(1000);
3659 }
3660 if (error) {
3661 // an error occured during the ramp, let's still try to go back to a safe volume
3662 if (mixer_ctl_set_value(ctl_left, 0, backup_gain)) {
3663 ALOGE("%s: error restoring left gain to %d", __func__, backup_gain);
3664 }
3665 if (mixer_ctl_set_value(ctl_right, 0, backup_gain)) {
3666 ALOGE("%s: error restoring right gain to %d", __func__, backup_gain);
3667 }
3668 }
3669 return start_gain;
3670}
3671
vivek mehtae59cfb22017-06-16 15:57:11 -07003672int platform_set_swap_mixer(struct audio_device *adev, bool swap_channels)
3673{
3674 const char *mixer_ctl_name = "Swap channel";
3675 struct mixer_ctl *ctl;
3676 const char *mixer_path;
3677 struct platform_data *my_data = (struct platform_data *)adev->platform;
3678
3679 // forced to set to swap, but device not rotated ... ignore set
3680 if (swap_channels && !my_data->speaker_lr_swap)
3681 return 0;
3682
3683 ALOGV("%s:", __func__);
3684
3685 if (swap_channels) {
3686 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER_REVERSE);
3687 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
3688 } else {
3689 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER);
3690 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
3691 }
3692
3693 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3694 if (!ctl) {
3695 ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name);
3696 return -EINVAL;
3697 }
3698
3699 if (mixer_ctl_set_value(ctl, 0, swap_channels) < 0) {
3700 ALOGE("%s: Could not set reverse cotrol %d",__func__, swap_channels);
3701 return -EINVAL;
3702 }
3703
3704 ALOGV("platfor_force_swap_channel :: Channel orientation ( %s ) ",
3705 swap_channels?"R --> L":"L --> R");
3706
3707 return 0;
3708}
3709
3710int platform_check_and_set_swap_lr_channels(struct audio_device *adev, bool swap_channels)
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003711{
3712 // only update if there is active pcm playback on speaker
3713 struct audio_usecase *usecase;
3714 struct listnode *node;
3715 struct platform_data *my_data = (struct platform_data *)adev->platform;
3716
vivek mehtae59cfb22017-06-16 15:57:11 -07003717 my_data->speaker_lr_swap = swap_channels;
Jean-Michel Trivif7148702016-09-16 18:23:05 -07003718
vivek mehtae59cfb22017-06-16 15:57:11 -07003719 return platform_set_swap_channels(adev, swap_channels);
3720}
Jean-Michel Trivif7148702016-09-16 18:23:05 -07003721
vivek mehtae59cfb22017-06-16 15:57:11 -07003722int platform_set_swap_channels(struct audio_device *adev, bool swap_channels)
3723{
3724 // only update if there is active pcm playback on speaker
3725 struct audio_usecase *usecase;
3726 struct listnode *node;
3727 struct platform_data *my_data = (struct platform_data *)adev->platform;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003728
vivek mehtae59cfb22017-06-16 15:57:11 -07003729 // do not swap channels in audio modes with concurrent capture and playback
3730 // as this may break the echo reference
3731 if ((adev->mode == AUDIO_MODE_IN_COMMUNICATION) || (adev->mode == AUDIO_MODE_IN_CALL)) {
3732 ALOGV("%s: will not swap due to audio mode %d", __func__, adev->mode);
3733 return 0;
3734 }
3735
3736 list_for_each(node, &adev->usecase_list) {
3737 usecase = node_to_item(node, struct audio_usecase, list);
3738 if (usecase->type == PCM_PLAYBACK &&
3739 usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) {
3740 /*
3741 * If acdb tuning is different for SPEAKER_REVERSE, it is must
3742 * to perform device switch to disable the current backend to
3743 * enable it with new acdb data.
3744 */
3745 if (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
3746 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]) {
3747 const int initial_skpr_gain = ramp_speaker_gain(adev, false /*ramp_up*/, -1);
3748 select_devices(adev, usecase->id);
3749 if (initial_skpr_gain != -EINVAL)
3750 ramp_speaker_gain(adev, true /*ramp_up*/, initial_skpr_gain);
3751
3752 } else {
3753 platform_set_swap_mixer(adev, swap_channels);
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003754 }
vivek mehtae59cfb22017-06-16 15:57:11 -07003755 break;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003756 }
3757 }
vivek mehtae59cfb22017-06-16 15:57:11 -07003758
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003759 return 0;
3760}
vivek mehtaa8d7c922016-05-25 14:40:44 -07003761
3762static struct amp_db_and_gain_table tbl_mapping[MAX_VOLUME_CAL_STEPS];
3763static int num_gain_tbl_entry = 0;
3764
3765bool platform_add_gain_level_mapping(struct amp_db_and_gain_table *tbl_entry) {
3766
3767 ALOGV("%s: enter .. add %f %f %d", __func__, tbl_entry->amp, tbl_entry->db, tbl_entry->level);
3768 if (num_gain_tbl_entry == -1) {
3769 ALOGE("%s: num entry beyond valid step levels or corrupted..rejecting custom mapping",
3770 __func__);
3771 return false;
3772 }
3773
3774 if (num_gain_tbl_entry >= MAX_VOLUME_CAL_STEPS) {
3775 ALOGE("%s: max entry reached max[%d] current index[%d] .. rejecting", __func__,
3776 MAX_VOLUME_CAL_STEPS, num_gain_tbl_entry);
3777 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
3778 return false;
3779 }
3780
3781 if (num_gain_tbl_entry > 0 && tbl_mapping[num_gain_tbl_entry - 1].amp >= tbl_entry->amp) {
3782 ALOGE("%s: value not in ascending order .. rejecting custom mapping", __func__);
3783 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
3784 return false;
3785 }
3786
3787 tbl_mapping[num_gain_tbl_entry] = *tbl_entry;
3788 ++num_gain_tbl_entry;
3789
3790 return true;
3791}
3792
3793int platform_get_gain_level_mapping(struct amp_db_and_gain_table *mapping_tbl,
3794 int table_size) {
3795 int itt = 0;
3796 ALOGV("platform_get_gain_level_mapping called ");
3797
3798 if (num_gain_tbl_entry <= 0 || num_gain_tbl_entry > MAX_VOLUME_CAL_STEPS) {
3799 ALOGD("%s: empty or currupted gain_mapping_table", __func__);
3800 return 0;
3801 }
3802
3803 for (; itt < num_gain_tbl_entry && itt <= table_size; itt++) {
3804 mapping_tbl[itt] = tbl_mapping[itt];
3805 ALOGV("%s: added amp[%f] db[%f] level[%d]", __func__,
3806 mapping_tbl[itt].amp, mapping_tbl[itt].db, mapping_tbl[itt].level);
3807 }
3808
3809 return num_gain_tbl_entry;
3810}
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07003811
3812int platform_snd_card_update(void *platform, card_status_t status)
3813{
3814 struct platform_data *my_data = (struct platform_data *)platform;
3815 struct audio_device *adev = my_data->adev;
3816
3817 if (status == CARD_STATUS_ONLINE) {
3818 if (my_data->acdb_send_custom_top)
3819 my_data->acdb_send_custom_top();
3820 }
3821 return 0;
3822}
David Linee3fe402017-03-13 10:00:42 -07003823
3824/*
3825 * configures afe with bit width and Sample Rate
3826 */
Haynes Mathew George65f6b432018-02-27 17:44:55 -08003827int platform_set_backend_cfg(const struct audio_device* adev,
3828 snd_device_t snd_device,
3829 const struct audio_backend_cfg *backend_cfg)
David Linee3fe402017-03-13 10:00:42 -07003830{
3831
3832 int ret = 0;
3833 const int backend_idx = platform_get_backend_index(snd_device);
3834 struct platform_data *my_data = (struct platform_data *)adev->platform;
3835 const unsigned int bit_width = backend_cfg->bit_width;
3836 const unsigned int sample_rate = backend_cfg->sample_rate;
3837 const unsigned int channels = backend_cfg->channels;
3838 const audio_format_t format = backend_cfg->format;
3839 const bool passthrough_enabled = backend_cfg->passthrough_enabled;
3840
3841
3842 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
3843 ", backend_idx %d device (%s)", __func__, bit_width,
3844 sample_rate, channels, backend_idx,
3845 platform_get_snd_device_name(snd_device));
3846
3847 if ((my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl) &&
3848 (bit_width != my_data->current_backend_cfg[backend_idx].bit_width)) {
3849
3850 struct mixer_ctl *ctl = NULL;
3851 ctl = mixer_get_ctl_by_name(adev->mixer,
3852 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
3853 if (!ctl) {
3854 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3855 __func__,
3856 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
3857 return -EINVAL;
3858 }
3859
3860 if (bit_width == 24) {
3861 if (format == AUDIO_FORMAT_PCM_24_BIT_PACKED)
3862 ret = mixer_ctl_set_enum_by_string(ctl, "S24_3LE");
3863 else
3864 ret = mixer_ctl_set_enum_by_string(ctl, "S24_LE");
3865 } else if (bit_width == 32) {
3866 ret = mixer_ctl_set_enum_by_string(ctl, "S32_LE");
3867 } else {
3868 ret = mixer_ctl_set_enum_by_string(ctl, "S16_LE");
3869 }
3870 if ( ret < 0) {
3871 ALOGE("%s:becf: afe: fail for %s mixer set to %d bit for %x format", __func__,
3872 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
3873 } else {
3874 my_data->current_backend_cfg[backend_idx].bit_width = bit_width;
3875 ALOGD("%s:becf: afe: %s mixer set to %d bit for %x format", __func__,
3876 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
3877 }
3878 /* set the ret as 0 and not pass back to upper layer */
3879 ret = 0;
3880 }
3881
3882 if (passthrough_enabled || ((my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl) &&
3883 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate))) {
3884 char *rate_str = NULL;
3885 struct mixer_ctl *ctl = NULL;
3886
3887 switch (sample_rate) {
3888 case 32000:
3889 if (passthrough_enabled) {
3890 rate_str = "KHZ_32";
3891 break;
3892 }
3893 case 8000:
3894 case 11025:
3895 case 16000:
3896 case 22050:
3897 case 48000:
3898 rate_str = "KHZ_48";
3899 break;
3900 case 44100:
3901 rate_str = "KHZ_44P1";
3902 break;
3903 case 64000:
3904 case 96000:
3905 rate_str = "KHZ_96";
3906 break;
3907 case 88200:
3908 rate_str = "KHZ_88P2";
3909 break;
3910 case 176400:
3911 rate_str = "KHZ_176P4";
3912 break;
3913 case 192000:
3914 rate_str = "KHZ_192";
3915 break;
3916 case 352800:
3917 rate_str = "KHZ_352P8";
3918 break;
3919 case 384000:
3920 rate_str = "KHZ_384";
3921 break;
3922 case 144000:
3923 if (passthrough_enabled) {
3924 rate_str = "KHZ_144";
3925 break;
3926 }
3927 default:
3928 rate_str = "KHZ_48";
3929 break;
3930 }
3931
3932 ctl = mixer_get_ctl_by_name(adev->mixer,
3933 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
3934 if(!ctl) {
3935 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3936 __func__,
3937 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
3938 return -EINVAL;
3939 }
3940
3941 ALOGD("%s:becf: afe: %s set to %s", __func__,
3942 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl, rate_str);
3943 mixer_ctl_set_enum_by_string(ctl, rate_str);
3944 my_data->current_backend_cfg[backend_idx].sample_rate = sample_rate;
3945 }
3946 if ((my_data->current_backend_cfg[backend_idx].channels_mixer_ctl) &&
3947 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
3948 struct mixer_ctl *ctl = NULL;
3949 char *channel_cnt_str = NULL;
3950
3951 switch (channels) {
3952 case 8:
3953 channel_cnt_str = "Eight"; break;
3954 case 7:
3955 channel_cnt_str = "Seven"; break;
3956 case 6:
3957 channel_cnt_str = "Six"; break;
3958 case 5:
3959 channel_cnt_str = "Five"; break;
3960 case 4:
3961 channel_cnt_str = "Four"; break;
3962 case 3:
3963 channel_cnt_str = "Three"; break;
3964 case 1:
3965 channel_cnt_str = "One"; break;
3966 case 2:
3967 default:
3968 channel_cnt_str = "Two"; break;
3969 }
3970
3971 ctl = mixer_get_ctl_by_name(adev->mixer,
3972 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
3973 if (!ctl) {
3974 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3975 __func__,
3976 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
3977 return -EINVAL;
3978 }
3979 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
3980 my_data->current_backend_cfg[backend_idx].channels = channels;
3981
3982 // skip EDID configuration for HDMI backend
3983
3984 ALOGD("%s:becf: afe: %s set to %s", __func__,
3985 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl,
3986 channel_cnt_str);
3987 }
3988
3989 // skip set ext_display format mixer control
3990 return ret;
3991}
3992
3993static int platform_get_snd_device_bit_width(snd_device_t snd_device)
3994{
3995 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
3996 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
3997 return CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3998 }
3999
4000 return backend_bit_width_table[snd_device];
4001}
4002
4003/*
4004 * return backend_idx on which voice call is active
4005 */
4006static int platform_get_voice_call_backend(struct audio_device* adev)
4007{
4008 struct audio_usecase *uc = NULL;
4009 struct listnode *node;
4010 snd_device_t out_snd_device = SND_DEVICE_NONE;
4011
4012 int backend_idx = -1;
4013
4014 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
4015 list_for_each(node, &adev->usecase_list) {
4016 uc = node_to_item(node, struct audio_usecase, list);
4017 if (uc && uc->type == VOICE_CALL && uc->stream.out) {
4018 out_snd_device = platform_get_output_snd_device(adev->platform,
4019 uc->stream.out->devices);
4020 backend_idx = platform_get_backend_index(out_snd_device);
4021 break;
4022 }
4023 }
4024 }
4025 return backend_idx;
4026}
4027
4028/*
4029 * goes through all the current usecases and picks the highest
4030 * bitwidth & samplerate
4031 */
4032static bool platform_check_capture_backend_cfg(struct audio_device* adev,
4033 int backend_idx,
4034 struct audio_backend_cfg *backend_cfg)
4035{
4036 bool backend_change = false;
4037 unsigned int bit_width;
4038 unsigned int sample_rate;
4039 unsigned int channels;
4040 struct platform_data *my_data = (struct platform_data *)adev->platform;
4041
4042 bit_width = backend_cfg->bit_width;
4043 sample_rate = backend_cfg->sample_rate;
4044 channels = backend_cfg->channels;
4045
4046 ALOGV("%s:txbecf: afe: Codec selected backend: %d current bit width: %d and "
4047 "sample rate: %d, channels %d",__func__,backend_idx, bit_width,
4048 sample_rate, channels);
4049
4050 // For voice calls use default configuration i.e. 16b/48K, only applicable to
4051 // default backend
4052 // force routing is not required here, caller will do it anyway
4053 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
4054 ALOGW("%s:txbecf: afe: Use default bw and sr for voice/voip calls and "
4055 "for unprocessed/camera source", __func__);
4056 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
4057 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4058 }
4059
4060 if (backend_idx == USB_AUDIO_TX_BACKEND) {
4061 audio_extn_usb_is_config_supported(&bit_width, &sample_rate, &channels, false);
4062 ALOGV("%s:txbecf: afe: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
4063 __func__, bit_width, sample_rate, channels);
4064 }
4065
4066 ALOGV("%s:txbecf: afe: Codec selected backend: %d updated bit width: %d and "
4067 "sample rate: %d", __func__, backend_idx, bit_width, sample_rate);
4068
4069 // Force routing if the expected bitwdith or samplerate
4070 // is not same as current backend comfiguration
4071 if ((bit_width != my_data->current_backend_cfg[backend_idx].bit_width) ||
4072 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate) ||
4073 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
4074 backend_cfg->bit_width = bit_width;
4075 backend_cfg->sample_rate= sample_rate;
4076 backend_cfg->channels = channels;
4077 backend_change = true;
4078 ALOGI("%s:txbecf: afe: Codec backend needs to be updated. new bit width: %d "
4079 "new sample rate: %d new channel: %d",
4080 __func__, backend_cfg->bit_width,
4081 backend_cfg->sample_rate, backend_cfg->channels);
4082 }
4083
4084 return backend_change;
4085}
4086
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004087static void pick_playback_cfg_for_uc(struct audio_device *adev,
4088 struct audio_usecase *usecase,
4089 snd_device_t snd_device,
4090 unsigned int *bit_width,
4091 unsigned int *sample_rate,
4092 unsigned int *channels)
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004093{
4094 int i =0;
4095 struct listnode *node;
4096 list_for_each(node, &adev->usecase_list) {
4097 struct audio_usecase *uc;
4098 uc = node_to_item(node, struct audio_usecase, list);
4099 struct stream_out *out = (struct stream_out*) uc->stream.out;
4100 if (uc->type == PCM_PLAYBACK && out && usecase != uc) {
4101 unsigned int out_channels = audio_channel_count_from_out_mask(out->channel_mask);
4102 ALOGV("%s:napb: (%d) - (%s)id (%d) sr %d bw "
4103 "(%d) ch (%d) device %s", __func__, i++, use_case_table[uc->id],
4104 uc->id, out->sample_rate,
4105 pcm_format_to_bits(out->config.format), out_channels,
4106 platform_get_snd_device_name(uc->out_snd_device));
4107
4108 if (platform_check_backends_match(snd_device, uc->out_snd_device)) {
4109 if (*bit_width < pcm_format_to_bits(out->config.format))
4110 *bit_width = pcm_format_to_bits(out->config.format);
4111 if (*sample_rate < out->sample_rate)
4112 *sample_rate = out->sample_rate;
4113 if (out->sample_rate < OUTPUT_SAMPLING_RATE_44100)
4114 *sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4115 if (*channels < out_channels)
4116 *channels = out_channels;
4117 }
4118 }
4119 }
4120 return;
4121}
4122
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004123static void headset_is_config_supported(unsigned int *bit_width,
4124 unsigned int *sample_rate,
4125 unsigned int *channels) {
4126 switch (*bit_width) {
4127 case 16:
4128 case 24:
4129 break;
4130 default:
4131 *bit_width = 16;
4132 break;
4133 }
4134
4135 if (*sample_rate > 192000) {
4136 *sample_rate = 192000;
4137 }
4138
4139 if (*channels > 2) {
4140 *channels = 2;
4141 }
4142}
4143
David Linee3fe402017-03-13 10:00:42 -07004144static bool platform_check_playback_backend_cfg(struct audio_device* adev,
4145 struct audio_usecase* usecase,
4146 snd_device_t snd_device,
4147 struct audio_backend_cfg *backend_cfg)
4148{
4149 bool backend_change = false;
David Linee3fe402017-03-13 10:00:42 -07004150 unsigned int bit_width;
4151 unsigned int sample_rate;
4152 unsigned int channels;
David Linee3fe402017-03-13 10:00:42 -07004153 int backend_idx = DEFAULT_CODEC_BACKEND;
Haynes Mathew George65f6b432018-02-27 17:44:55 -08004154 unsigned long service_interval = 0; // 0 is invalid
David Linee3fe402017-03-13 10:00:42 -07004155 struct platform_data *my_data = (struct platform_data *)adev->platform;
David Linee3fe402017-03-13 10:00:42 -07004156
4157 if (snd_device == SND_DEVICE_OUT_BT_SCO ||
4158 snd_device == SND_DEVICE_OUT_BT_SCO_WB) {
4159 backend_change = false;
4160 return backend_change;
4161 }
4162
4163 backend_idx = platform_get_backend_index(snd_device);
4164 bit_width = backend_cfg->bit_width;
4165 sample_rate = backend_cfg->sample_rate;
4166 channels = backend_cfg->channels;
4167
4168 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
4169 ", backend_idx %d usecase = %d device (%s)", __func__, bit_width,
4170 sample_rate, channels, backend_idx, usecase->id,
4171 platform_get_snd_device_name(snd_device));
4172
4173 if (backend_idx == platform_get_voice_call_backend(adev)) {
4174 ALOGW("%s:becf: afe:Use default bw and sr for voice/voip calls ",
4175 __func__);
4176 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
4177 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4178 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
4179 } else {
4180 /*
4181 * The backend should be configured at highest bit width and/or
4182 * sample rate amongst all playback usecases.
4183 * If the selected sample rate and/or bit width differ with
4184 * current backend sample rate and/or bit width, then, we set the
4185 * backend re-configuration flag.
4186 *
4187 * Exception: 16 bit playbacks is allowed through 16 bit/48/44.1 khz backend only
4188 */
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004189 pick_playback_cfg_for_uc(adev, usecase, snd_device,
4190 &bit_width,
4191 &sample_rate,
4192 &channels);
David Linee3fe402017-03-13 10:00:42 -07004193 }
4194
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004195 switch (backend_idx) {
4196 case USB_AUDIO_RX_BACKEND:
4197 audio_extn_usb_is_config_supported(&bit_width,
4198 &sample_rate, &channels, true);
Haynes Mathew George65f6b432018-02-27 17:44:55 -08004199 if (platform_get_usb_service_interval(adev->platform, true,
4200 &service_interval) == 0) {
4201 /* overwrite with best altset for this service interval */
4202 int ret =
4203 audio_extn_usb_altset_for_service_interval(true /*playback*/,
4204 service_interval,
4205 &bit_width,
4206 &sample_rate,
4207 &channels);
4208 if (ret < 0) {
4209 ALOGE("Failed to find altset for service interval %lu, skip reconfig",
4210 service_interval);
4211 return false;
4212 }
4213 }
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004214 ALOGV("%s: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
4215 __func__, bit_width, sample_rate, channels);
4216 break;
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004217 case HEADPHONE_BACKEND:
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004218 headset_is_config_supported(&bit_width, &sample_rate, &channels);
4219 break;
4220 case DEFAULT_CODEC_BACKEND:
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004221 default:
4222 bit_width = platform_get_snd_device_bit_width(snd_device);
4223 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4224 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
4225 break;
David Linee3fe402017-03-13 10:00:42 -07004226 }
4227
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004228 ALOGV("%s:becf: afe: Codec selected backend: %d updated bit width: %d and"
4229 "sample rate: %d",
David Linee3fe402017-03-13 10:00:42 -07004230 __func__, backend_idx , bit_width, sample_rate);
4231
4232 // Force routing if the expected bitwdith or samplerate
4233 // is not same as current backend comfiguration
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004234 if (bit_width != my_data->current_backend_cfg[backend_idx].bit_width ||
4235 sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate ||
4236 channels != my_data->current_backend_cfg[backend_idx].channels) {
David Linee3fe402017-03-13 10:00:42 -07004237 backend_cfg->bit_width = bit_width;
4238 backend_cfg->sample_rate = sample_rate;
4239 backend_cfg->channels = channels;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004240 backend_cfg->passthrough_enabled = false;
David Linee3fe402017-03-13 10:00:42 -07004241 backend_change = true;
4242 ALOGV("%s:becf: afe: Codec backend needs to be updated. new bit width: %d"
4243 "new sample rate: %d new channels: %d",
4244 __func__, backend_cfg->bit_width, backend_cfg->sample_rate, backend_cfg->channels);
4245 }
4246
4247 return backend_change;
4248}
4249
4250bool platform_check_and_set_playback_backend_cfg(struct audio_device* adev,
4251 struct audio_usecase *usecase, snd_device_t snd_device)
4252{
4253 int backend_idx = DEFAULT_CODEC_BACKEND;
4254 int new_snd_devices[SND_DEVICE_OUT_END];
4255 int i, num_devices = 1;
4256 bool ret = false;
4257 struct platform_data *my_data = (struct platform_data *)adev->platform;
4258 struct audio_backend_cfg backend_cfg;
4259
4260 backend_idx = platform_get_backend_index(snd_device);
4261
4262 backend_cfg.bit_width = pcm_format_to_bits(usecase->stream.out->config.format);
4263 backend_cfg.sample_rate = usecase->stream.out->sample_rate;
4264 backend_cfg.format = usecase->stream.out->format;
4265 backend_cfg.channels = audio_channel_count_from_out_mask(usecase->stream.out->channel_mask);
4266 /*this is populated by check_codec_backend_cfg hence set default value to false*/
4267 backend_cfg.passthrough_enabled = false;
4268
4269 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
4270 ", backend_idx %d usecase = %d device (%s)", __func__, backend_cfg.bit_width,
4271 backend_cfg.sample_rate, backend_cfg.channels, backend_idx, usecase->id,
4272 platform_get_snd_device_name(snd_device));
4273
4274 if (platform_can_split_snd_device(snd_device, &num_devices, new_snd_devices) < 0)
4275 new_snd_devices[0] = snd_device;
4276
4277 for (i = 0; i < num_devices; i++) {
4278 ALOGV("%s: new_snd_devices[%d] is %d", __func__, i, new_snd_devices[i]);
4279 if ((platform_check_playback_backend_cfg(adev, usecase, new_snd_devices[i],
4280 &backend_cfg))) {
4281 platform_set_backend_cfg(adev, new_snd_devices[i],
4282 &backend_cfg);
4283 ret = true;
4284 }
4285 }
4286 return ret;
4287}
4288
4289bool platform_check_and_set_capture_backend_cfg(struct audio_device* adev,
4290 struct audio_usecase *usecase, snd_device_t snd_device)
4291{
4292 int backend_idx = platform_get_backend_index(snd_device);
4293 int ret = 0;
4294 struct audio_backend_cfg backend_cfg;
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004295 memset(&backend_cfg, 0, sizeof(struct audio_backend_cfg));
David Linee3fe402017-03-13 10:00:42 -07004296
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004297 if (usecase->type == PCM_CAPTURE) {
4298 backend_cfg.format = usecase->stream.in->format;
David Linee3fe402017-03-13 10:00:42 -07004299 backend_cfg.channels = audio_channel_count_from_in_mask(usecase->stream.in->channel_mask);
4300 } else {
4301 backend_cfg.bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
4302 backend_cfg.sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4303 backend_cfg.format = AUDIO_FORMAT_PCM_16_BIT;
4304 backend_cfg.channels = 1;
4305 }
4306
4307 ALOGV("%s:txbecf: afe: bitwidth %d, samplerate %d, channel %d"
4308 ", backend_idx %d usecase = %d device (%s)", __func__,
4309 backend_cfg.bit_width,
4310 backend_cfg.sample_rate,
4311 backend_cfg.channels,
4312 backend_idx, usecase->id,
4313 platform_get_snd_device_name(snd_device));
4314
4315 if (platform_check_capture_backend_cfg(adev, backend_idx, &backend_cfg)) {
4316 ret = platform_set_backend_cfg(adev, snd_device,
4317 &backend_cfg);
4318 if(!ret)
4319 return true;
4320 }
4321
4322 return false;
4323}
4324
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004325static int max_be_dai_names = 0;
4326static const struct be_dai_name_struct *be_dai_name_table;
4327
4328/*
4329 * Retrieves the be_dai_name_table from kernel to enable a mapping
4330 * between sound device hw interfaces and backend IDs. This allows HAL to
4331 * specify the backend a specific calibration is needed for.
4332 */
4333static int init_be_dai_name_table(struct audio_device *adev)
4334{
4335 const char *mixer_ctl_name = "Backend DAI Name Table";
4336 struct mixer_ctl *ctl;
4337 int i, j, ret, size;
4338 bool valid_hw_interface;
4339
4340 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
4341 if (!ctl) {
4342 ALOGE("%s: Could not get ctl for mixer name %s\n",
4343 __func__, mixer_ctl_name);
4344 ret = -EINVAL;
4345 goto done;
4346 }
4347
4348 mixer_ctl_update(ctl);
4349
4350 size = mixer_ctl_get_num_values(ctl);
4351 if (size <= 0){
4352 ALOGE("%s: Failed to get %s size %d\n",
4353 __func__, mixer_ctl_name, size);
4354 ret = -EFAULT;
4355 goto done;
4356 }
4357
vivek mehtaa68fea62017-06-08 19:04:02 -07004358 be_dai_name_table =
4359 (const struct be_dai_name_struct *)calloc(1, size);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004360 if (be_dai_name_table == NULL) {
4361 ALOGE("%s: Failed to allocate memory for %s\n",
4362 __func__, mixer_ctl_name);
4363 ret = -ENOMEM;
4364 goto freeMem;
4365 }
4366
4367 ret = mixer_ctl_get_array(ctl, (void *)be_dai_name_table, size);
4368 if (ret) {
4369 ALOGE("%s: Failed to get %s, ret %d\n",
4370 __func__, mixer_ctl_name, ret);
4371 ret = -EFAULT;
4372 goto freeMem;
4373 }
4374
4375 if (be_dai_name_table != NULL) {
4376 max_be_dai_names = size / sizeof(struct be_dai_name_struct);
4377 ALOGV("%s: Successfully got %s, number of be dais is %d\n",
4378 __func__, mixer_ctl_name, max_be_dai_names);
4379 ret = 0;
4380 } else {
4381 ALOGE("%s: Failed to get %s\n", __func__, mixer_ctl_name);
4382 ret = -EFAULT;
4383 goto freeMem;
4384 }
4385
4386 /*
4387 * Validate all sound devices have a valid backend set to catch
4388 * errors for uncommon sound devices
4389 */
4390 for (i = 0; i < SND_DEVICE_MAX; i++) {
4391 valid_hw_interface = false;
4392
4393 if (hw_interface_table[i] == NULL) {
4394 ALOGW("%s: sound device %s has no hw interface set\n",
4395 __func__, platform_get_snd_device_name(i));
4396 continue;
4397 }
4398
4399 for (j = 0; j < max_be_dai_names; j++) {
4400 if (strcmp(hw_interface_table[i], be_dai_name_table[j].be_name)
4401 == 0) {
4402 valid_hw_interface = true;
4403 break;
4404 }
4405 }
4406 if (!valid_hw_interface)
4407 ALOGD("%s: sound device %s does not have a valid hw interface set "
4408 "(disregard for combo devices) %s\n",
4409 __func__, platform_get_snd_device_name(i),
4410 hw_interface_table[i]);
4411 }
4412
4413 goto done;
4414
4415freeMem:
4416 if (be_dai_name_table) {
4417 free((void *)be_dai_name_table);
4418 be_dai_name_table = NULL;
4419 }
4420
4421done:
4422 return ret;
4423}
4424
4425int platform_get_snd_device_backend_index(snd_device_t device)
4426{
4427 int i, be_dai_id;
4428 const char * hw_interface_name = NULL;
4429
4430 ALOGV("%s: enter with device %d\n", __func__, device);
4431
vivek mehtaa68fea62017-06-08 19:04:02 -07004432 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004433 ALOGE("%s: Invalid snd_device = %d",
4434 __func__, device);
4435 be_dai_id = -EINVAL;
4436 goto done;
4437 }
4438
4439 /* Get string value of necessary backend for device */
4440 hw_interface_name = hw_interface_table[device];
4441 if (hw_interface_name == NULL) {
4442 ALOGE("%s: no hw_interface set for device %d\n", __func__, device);
4443 be_dai_id = -EINVAL;
4444 goto done;
4445 }
4446
4447 /* Check if be dai name table was retrieved successfully */
4448 if (be_dai_name_table == NULL) {
4449 ALOGE("%s: BE DAI Name Table is not present\n", __func__);
4450 be_dai_id = -EFAULT;
4451 goto done;
4452 }
4453
4454 /* Get backend ID for device specified */
4455 for (i = 0; i < max_be_dai_names; i++) {
4456 if (strcmp(hw_interface_name, be_dai_name_table[i].be_name) == 0) {
4457 be_dai_id = be_dai_name_table[i].be_id;
4458 goto done;
4459 }
4460 }
4461 ALOGE("%s: no interface matching name %s\n", __func__, hw_interface_name);
4462 be_dai_id = -EINVAL;
4463 goto done;
4464
4465done:
4466 return be_dai_id;
4467}
4468
4469void platform_check_and_update_copp_sample_rate(void* platform, snd_device_t snd_device,
4470 unsigned int stream_sr, int* sample_rate)
4471{
4472 struct platform_data* my_data = (struct platform_data *)platform;
4473 int backend_idx = platform_get_backend_index(snd_device);
4474 int device_sr = my_data->current_backend_cfg[backend_idx].sample_rate;
4475 /*
4476 *Check if device SR is multiple of 8K or 11.025 Khz
4477 *check if the stream SR is multiple of same base, if yes
4478 *then have copp SR equal to stream SR, this ensures that
4479 *post processing happens at stream SR, else have
4480 *copp SR equal to device SR.
4481 */
4482 if (!(((sample_rate_multiple(device_sr, SAMPLE_RATE_8000)) &&
4483 (sample_rate_multiple(stream_sr, SAMPLE_RATE_8000))) ||
4484 ((sample_rate_multiple(device_sr, SAMPLE_RATE_11025)) &&
4485 (sample_rate_multiple(stream_sr, SAMPLE_RATE_11025))))) {
4486 *sample_rate = device_sr;
4487 } else
4488 *sample_rate = stream_sr;
4489
4490 ALOGI("sn_device %d device sr %d stream sr %d copp sr %d", snd_device, device_sr, stream_sr
4491 , *sample_rate);
4492
4493}
4494
4495// called from info parser
vivek mehtaa68fea62017-06-08 19:04:02 -07004496void platform_add_app_type(const char *uc_type,
4497 const char *mode,
4498 int bw,
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004499 int app_type, int max_rate) {
4500 struct app_type_entry *ap =
4501 (struct app_type_entry *)calloc(1, sizeof(struct app_type_entry));
4502
4503 if (!ap) {
4504 ALOGE("%s failed to allocate mem for app type", __func__);
4505 return;
4506 }
4507
4508 ap->uc_type = -1;
4509 for (int i=0; i<USECASE_TYPE_MAX; i++) {
4510 if (!strcmp(uc_type, usecase_type_index[i].name)) {
4511 ap->uc_type = usecase_type_index[i].index;
4512 break;
4513 }
4514 }
4515
4516 if (ap->uc_type == -1) {
4517 free(ap);
4518 return;
4519 }
4520
vivek mehtaa68fea62017-06-08 19:04:02 -07004521 ALOGI("%s uc %s mode %s bw %d app_type %d max_rate %d",
4522 __func__, uc_type, mode, bw, app_type, max_rate);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004523 ap->bit_width = bw;
4524 ap->app_type = app_type;
4525 ap->max_rate = max_rate;
vivek mehtaa68fea62017-06-08 19:04:02 -07004526 ap->mode = strdup(mode);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004527 list_add_tail(&app_type_entry_list, &ap->node);
4528}
4529
4530
4531int platform_get_default_app_type_v2(void *platform __unused,
4532 usecase_type_t type,
4533 int *app_type )
4534{
4535 if (type == PCM_PLAYBACK)
4536 *app_type = DEFAULT_APP_TYPE_RX_PATH;
4537 else
4538 *app_type = DEFAULT_APP_TYPE_TX_PATH;
4539 return 0;
4540}
4541
vivek mehtaa68fea62017-06-08 19:04:02 -07004542int platform_get_app_type_v2(void *platform,
4543 usecase_type_t uc_type,
4544 const char *mode,
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004545 int bw, int sr __unused,
4546 int *app_type)
4547{
4548 struct listnode *node;
4549 struct app_type_entry *entry;
4550 *app_type = -1;
vivek mehtaa68fea62017-06-08 19:04:02 -07004551
4552 ALOGV("%s find match for uc %d mode %s bw %d rate %d",
4553 __func__, uc_type, mode, bw, sr);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004554 list_for_each(node, &app_type_entry_list) {
4555 entry = node_to_item(node, struct app_type_entry, node);
vivek mehtaa68fea62017-06-08 19:04:02 -07004556 ALOGV("%s uc %d mode %s bw %d app_type %d max_rate %d",
4557 __func__, entry->uc_type, entry->mode, entry->bit_width,
4558 entry->app_type, entry->max_rate);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004559 if (entry->bit_width == bw &&
vivek mehtaa68fea62017-06-08 19:04:02 -07004560 entry->uc_type == uc_type &&
4561 sr <= entry->max_rate &&
4562 entry->mode && !strcmp(mode, entry->mode)) {
4563 ALOGV("%s found match %d", __func__, entry->app_type);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004564 *app_type = entry->app_type;
4565 break;
4566 }
4567 }
4568
4569 if (*app_type == -1) {
vivek mehtaa68fea62017-06-08 19:04:02 -07004570 ALOGV("%s no match found, return default", __func__);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004571 return platform_get_default_app_type_v2(platform, uc_type, app_type);
4572 }
4573 return 0;
4574}
vivek mehta90933872017-06-15 18:04:39 -07004575
4576int platform_set_sidetone(struct audio_device *adev,
4577 snd_device_t out_snd_device,
4578 bool enable, char *str)
4579{
4580 int ret;
4581 if (out_snd_device == SND_DEVICE_OUT_USB_HEADSET ||
4582 out_snd_device == SND_DEVICE_OUT_VOICE_USB_HEADSET) {
4583 ret = audio_extn_usb_enable_sidetone(out_snd_device, enable);
4584 if (ret)
4585 ALOGI("%s: usb device %d does not support device sidetone\n",
4586 __func__, out_snd_device);
4587 } else {
4588 ALOGV("%s: sidetone out device(%d) mixer cmd = %s\n",
4589 __func__, out_snd_device, str);
4590 if (enable)
4591 audio_route_apply_and_update_path(adev->audio_route, str);
4592 else
4593 audio_route_reset_and_update_path(adev->audio_route, str);
4594 }
4595 return 0;
4596}
Haynes Mathew George96483a22017-03-28 14:52:47 -07004597
4598int platform_get_mmap_data_fd(void *platform __unused, int fe_dev __unused, int dir __unused,
4599 int *fd __unused, uint32_t *size __unused)
4600{
Thierry Strudel07f96d12018-09-20 13:31:34 -07004601#if defined (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845) || (PLATFORM_SDM710) || (PLATFORM_SM8150)
Haynes Mathew George96483a22017-03-28 14:52:47 -07004602 struct platform_data *my_data = (struct platform_data *)platform;
4603 struct audio_device *adev = my_data->adev;
4604 int hw_fd = -1;
4605 char dev_name[128];
4606 struct snd_pcm_mmap_fd mmap_fd;
4607 memset(&mmap_fd, 0, sizeof(mmap_fd));
4608 mmap_fd.dir = dir;
4609 snprintf(dev_name, sizeof(dev_name), "/dev/snd/hwC%uD%u",
4610 adev->snd_card, HWDEP_FE_BASE+fe_dev);
4611 hw_fd = open(dev_name, O_RDONLY);
4612 if (hw_fd < 0) {
4613 ALOGE("fe hw dep node open %d/%d failed", adev->snd_card, fe_dev);
4614 return -1;
4615 }
4616 if (ioctl(hw_fd, SNDRV_PCM_IOCTL_MMAP_DATA_FD, &mmap_fd) < 0) {
4617 ALOGE("fe hw dep node ioctl failed");
4618 close(hw_fd);
4619 return -1;
4620 }
4621 *fd = mmap_fd.fd;
4622 *size = mmap_fd.size;
4623 close(hw_fd); // mmap_fd should still be valid
4624 return 0;
4625#else
4626 return -1;
4627#endif
4628}
Mikhail Naganov4ee6e3e2018-03-21 16:28:35 +00004629
4630bool platform_sound_trigger_usecase_needs_event(audio_usecase_t uc_id)
4631{
4632 bool needs_event = false;
4633
4634 switch (uc_id) {
4635 /* concurrent capture usecases which needs event */
4636 case USECASE_AUDIO_RECORD:
4637 case USECASE_AUDIO_RECORD_LOW_LATENCY:
4638 case USECASE_AUDIO_RECORD_MMAP:
4639 case USECASE_AUDIO_RECORD_HIFI:
4640 case USECASE_AUDIO_RECORD_VOIP:
4641 case USECASE_VOICEMMODE1_CALL:
4642 case USECASE_VOICEMMODE2_CALL:
4643 /* concurrent playback usecases that needs event */
4644 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
4645 case USECASE_AUDIO_PLAYBACK_OFFLOAD:
4646 needs_event = true;
4647 break;
4648 default:
4649 ALOGV("%s:usecase_id[%d] no need to raise event.", __func__, uc_id);
4650 }
4651 return needs_event;
4652}
4653
4654bool platform_snd_device_has_speaker(snd_device_t dev) {
4655 int num_devs = 2;
4656 snd_device_t split_devs[2] = {SND_DEVICE_NONE, SND_DEVICE_NONE};
4657 if (platform_can_split_snd_device(dev, &num_devs, split_devs) == 0) {
4658 return platform_snd_device_has_speaker(split_devs[0]) ||
4659 platform_snd_device_has_speaker(split_devs[1]);
4660 }
4661
4662 switch (dev) {
4663 case SND_DEVICE_OUT_SPEAKER:
4664 case SND_DEVICE_OUT_SPEAKER_SAFE:
4665 case SND_DEVICE_OUT_SPEAKER_REVERSE:
4666 case SND_DEVICE_OUT_SPEAKER_PROTECTED:
4667 case SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED:
4668 case SND_DEVICE_OUT_VOICE_SPEAKER_HFP:
4669 return true;
4670 default:
4671 break;
4672 }
4673 return false;
4674}
jiabin8962a4d2018-03-19 18:21:24 -07004675
4676bool platform_set_microphone_characteristic(void *platform,
4677 struct audio_microphone_characteristic_t mic) {
4678 struct platform_data *my_data = (struct platform_data *)platform;
4679 if (my_data->declared_mic_count >= AUDIO_MICROPHONE_MAX_COUNT) {
4680 ALOGE("mic number is more than maximum number");
4681 return false;
4682 }
4683 for (size_t ch = 0; ch < AUDIO_CHANNEL_COUNT_MAX; ch++) {
4684 mic.channel_mapping[ch] = AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED;
4685 }
4686 my_data->microphones[my_data->declared_mic_count++] = mic;
4687 return true;
4688}
4689
4690int platform_get_microphones(void *platform,
4691 struct audio_microphone_characteristic_t *mic_array,
4692 size_t *mic_count) {
4693 struct platform_data *my_data = (struct platform_data *)platform;
4694 if (mic_count == NULL) {
4695 return -EINVAL;
4696 }
4697 if (mic_array == NULL) {
4698 return -EINVAL;
4699 }
4700
4701 if (*mic_count == 0) {
4702 *mic_count = my_data->declared_mic_count;
4703 return 0;
4704 }
4705
4706 size_t max_mic_count = *mic_count;
4707 size_t actual_mic_count = 0;
4708 for (size_t i = 0; i < max_mic_count && i < my_data->declared_mic_count; i++) {
4709 mic_array[i] = my_data->microphones[i];
4710 actual_mic_count++;
4711 }
4712 *mic_count = actual_mic_count;
4713 return 0;
4714}
4715
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004716bool platform_set_microphone_map(void *platform, snd_device_t in_snd_device,
4717 const struct mic_info *info) {
4718 struct platform_data *my_data = (struct platform_data *)platform;
4719 if (in_snd_device < SND_DEVICE_IN_BEGIN || in_snd_device >= SND_DEVICE_IN_END) {
4720 ALOGE("%s: Sound device not valid", __func__);
4721 return false;
4722 }
4723 size_t m_count = my_data->mic_map[in_snd_device].mic_count++;
4724 if (m_count >= AUDIO_MICROPHONE_MAX_COUNT) {
4725 ALOGE("%s: Microphone count is greater than max allowed value", __func__);
4726 my_data->mic_map[in_snd_device].mic_count--;
4727 return false;
4728 }
4729 my_data->mic_map[in_snd_device].microphones[m_count] = *info;
4730 return true;
4731}
4732
4733int platform_get_active_microphones(void *platform, unsigned int channels,
4734 audio_usecase_t uc_id,
jiabin8962a4d2018-03-19 18:21:24 -07004735 struct audio_microphone_characteristic_t *mic_array,
4736 size_t *mic_count) {
4737 struct platform_data *my_data = (struct platform_data *)platform;
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004738 struct audio_usecase *usecase = get_usecase_from_list(my_data->adev, uc_id);
4739 if (mic_count == NULL || mic_array == NULL || usecase == NULL) {
jiabin8962a4d2018-03-19 18:21:24 -07004740 return -EINVAL;
4741 }
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004742 size_t max_mic_count = my_data->declared_mic_count;
jiabin8962a4d2018-03-19 18:21:24 -07004743 size_t actual_mic_count = 0;
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004744
4745 snd_device_t active_input_snd_device =
4746 platform_get_input_snd_device(platform, usecase->stream.in->device);
4747 if (active_input_snd_device == SND_DEVICE_NONE) {
4748 ALOGI("%s: No active microphones found", __func__);
4749 goto end;
4750 }
4751
4752 size_t active_mic_count = my_data->mic_map[active_input_snd_device].mic_count;
4753 struct mic_info *m_info = my_data->mic_map[active_input_snd_device].microphones;
4754
4755 for (size_t i = 0; i < active_mic_count; i++) {
4756 unsigned int channels_for_active_mic = channels;
4757 if (channels_for_active_mic > m_info[i].channel_count) {
4758 channels_for_active_mic = m_info[i].channel_count;
4759 }
4760 for (size_t j = 0; j < max_mic_count; j++) {
4761 if (strcmp(my_data->microphones[j].device_id,
4762 m_info[i].device_id) == 0) {
4763 mic_array[actual_mic_count] = my_data->microphones[j];
4764 for (size_t ch = 0; ch < channels_for_active_mic; ch++) {
4765 mic_array[actual_mic_count].channel_mapping[ch] =
4766 m_info[i].channel_mapping[ch];
4767 }
4768 actual_mic_count++;
4769 break;
jiabin8962a4d2018-03-19 18:21:24 -07004770 }
jiabin8962a4d2018-03-19 18:21:24 -07004771 }
4772 }
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004773end:
jiabin8962a4d2018-03-19 18:21:24 -07004774 *mic_count = actual_mic_count;
4775 return 0;
4776}
Haynes Mathew George65f6b432018-02-27 17:44:55 -08004777
4778int platform_set_usb_service_interval(void *platform,
4779 bool playback,
4780 unsigned long service_interval,
4781 bool *reconfig)
4782{
4783#if defined (USB_SERVICE_INTERVAL_ENABLED)
4784 struct platform_data *_platform = (struct platform_data *)platform;
4785 *reconfig = false;
4786 if (!playback) {
4787 ALOGE("%s not valid for capture", __func__);
4788 return -1;
4789 }
4790 const char *ctl_name = "USB_AUDIO_RX service_interval";
4791 struct mixer_ctl *ctl = mixer_get_ctl_by_name(_platform->adev->mixer,
4792 ctl_name);
4793 if (!ctl) {
4794 ALOGV("%s: could not get mixer %s", __func__, ctl_name);
4795 return -1;
4796 }
4797 if (mixer_ctl_get_value(ctl, 0) != (int)service_interval) {
4798 mixer_ctl_set_value(ctl, 0, service_interval);
4799 *reconfig = true;
4800 }
4801 return 0;
4802#else
4803 *reconfig = false;
4804 (void)platform;
4805 (void)playback;
4806 (void)service_interval;
4807 return -1;
4808#endif
4809}
4810
4811int platform_get_usb_service_interval(void *platform,
4812 bool playback,
4813 unsigned long *service_interval)
4814{
4815#if defined (USB_SERVICE_INTERVAL_ENABLED)
4816 struct platform_data *_platform = (struct platform_data *)platform;
4817 if (!playback) {
4818 ALOGE("%s not valid for capture", __func__);
4819 return -1;
4820 }
4821 const char *ctl_name = "USB_AUDIO_RX service_interval";
4822 struct mixer_ctl *ctl = mixer_get_ctl_by_name(_platform->adev->mixer,
4823 ctl_name);
4824 if (!ctl) {
4825 ALOGV("%s: could not get mixer %s", __func__, ctl_name);
4826 return -1;
4827 }
4828 *service_interval = mixer_ctl_get_value(ctl, 0);
4829 return 0;
4830#else
4831 (void)platform;
4832 (void)playback;
4833 (void)service_interval;
4834 return -1;
4835#endif
4836}
Ashish Jain1c849702018-05-11 20:11:55 +05304837
4838int platform_set_acdb_metainfo_key(void *platform __unused,
4839 char *name __unused,
4840 int key __unused)
4841{
4842 return -ENOSYS;
4843}