blob: fc9d322d1f7d80bf6654891135315d38dbf26844 [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>
Alexey Polyudove920d4b2017-09-15 17:09:07 -070033#if defined (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845)
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
keunhui.park2f7306a2015-07-16 16:48:06 +0900108static struct listnode operator_info_list;
109static struct listnode *operator_specific_device_table[SND_DEVICE_MAX];
110
jasmine chac89321b2018-04-10 21:37:01 +0800111#define AUDIO_PARAMETER_KEY_AUD_CALDATA "cal_data"
112
113typedef struct acdb_audio_cal_cfg {
114 uint32_t persist;
115 uint32_t snd_dev_id;
116 audio_devices_t dev_id;
117 int32_t acdb_dev_id;
118 uint32_t app_type;
119 uint32_t topo_id;
120 uint32_t sampling_rate;
121 uint32_t cal_type;
122 uint32_t module_id;
123 uint32_t param_id;
124} acdb_audio_cal_cfg_t;
125
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700126/* Audio calibration related functions */
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800127typedef void (*acdb_send_audio_cal_v3_t)(int, int, int, int, int);
Eric Laurentb23d5282013-05-14 15:27:20 -0700128
Eric Laurentb23d5282013-05-14 15:27:20 -0700129struct platform_data {
130 struct audio_device *adev;
131 bool fluence_in_spkr_mode;
132 bool fluence_in_voice_call;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700133 bool fluence_in_voice_comm;
Eric Laurentb23d5282013-05-14 15:27:20 -0700134 bool fluence_in_voice_rec;
Prashant Malanic92c5962015-08-11 15:10:18 -0700135 /* 0 = no fluence, 1 = fluence, 2 = fluence pro */
136 int fluence_type;
137 int source_mic_type;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -0700138 bool speaker_lr_swap;
139
Eric Laurentb23d5282013-05-14 15:27:20 -0700140 void *acdb_handle;
Alexey Polyudove920d4b2017-09-15 17:09:07 -0700141#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -0700142 acdb_init_v2_cvd_t acdb_init;
143#elif defined (PLATFORM_MSM8084)
144 acdb_init_v2_t acdb_init;
145#else
146 acdb_init_t acdb_init;
147#endif
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700148 acdb_deallocate_t acdb_deallocate;
149 acdb_send_audio_cal_t acdb_send_audio_cal;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800150 acdb_send_audio_cal_v3_t acdb_send_audio_cal_v3;
jasmine chac89321b2018-04-10 21:37:01 +0800151 acdb_set_audio_cal_t acdb_set_audio_cal;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700152 acdb_send_voice_cal_t acdb_send_voice_cal;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700153 acdb_reload_vocvoltable_t acdb_reload_vocvoltable;
vivek mehta1a9b7c02015-06-25 11:49:38 -0700154 acdb_send_gain_dep_cal_t acdb_send_gain_dep_cal;
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -0700155 acdb_send_custom_top_t acdb_send_custom_top;
156 bool acdb_initialized;
157
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700158 struct csd_data *csd;
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800159 char ec_ref_mixer_path[64];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700160
David Linee3fe402017-03-13 10:00:42 -0700161 codec_backend_cfg_t current_backend_cfg[MAX_CODEC_BACKENDS];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700162 char *snd_card_name;
keunhui.parkc5aaa0e2015-07-13 10:57:37 +0900163 int max_vol_index;
Prashant Malanic92c5962015-08-11 15:10:18 -0700164 int max_mic_count;
vivek mehtade4849c2016-03-03 17:23:38 -0800165
166 void *hw_info;
jiabin8962a4d2018-03-19 18:21:24 -0700167
168 uint32_t declared_mic_count;
169 struct audio_microphone_characteristic_t microphones[AUDIO_MICROPHONE_MAX_COUNT];
Eric Laurentb23d5282013-05-14 15:27:20 -0700170};
171
Haynes Mathew George98c95622014-06-20 19:14:25 -0700172static int pcm_device_table[AUDIO_USECASE_MAX][2] = {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700173 [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = {DEEP_BUFFER_PCM_DEVICE,
174 DEEP_BUFFER_PCM_DEVICE},
175 [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
176 LOWLATENCY_PCM_DEVICE},
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800177 [USECASE_AUDIO_PLAYBACK_HIFI] = {MULTIMEDIA2_PCM_DEVICE,
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700178 MULTIMEDIA2_PCM_DEVICE},
179 [USECASE_AUDIO_PLAYBACK_OFFLOAD] = {PLAYBACK_OFFLOAD_DEVICE,
180 PLAYBACK_OFFLOAD_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700181 [USECASE_AUDIO_PLAYBACK_TTS] = {MULTIMEDIA2_PCM_DEVICE,
182 MULTIMEDIA2_PCM_DEVICE},
183 [USECASE_AUDIO_PLAYBACK_ULL] = {MULTIMEDIA3_PCM_DEVICE,
184 MULTIMEDIA3_PCM_DEVICE},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800185 [USECASE_AUDIO_PLAYBACK_MMAP] = {MMAP_PLAYBACK_PCM_DEVICE,
186 MMAP_PLAYBACK_PCM_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700187
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700188 [USECASE_AUDIO_RECORD] = {AUDIO_RECORD_PCM_DEVICE,
189 AUDIO_RECORD_PCM_DEVICE},
190 [USECASE_AUDIO_RECORD_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
191 LOWLATENCY_PCM_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700192
Eric Laurent0e46adf2016-12-16 12:49:24 -0800193 [USECASE_AUDIO_RECORD_MMAP] = {MMAP_RECORD_PCM_DEVICE,
194 MMAP_RECORD_PCM_DEVICE},
Haynes Mathew George569b7482017-05-08 14:44:27 -0700195 [USECASE_AUDIO_RECORD_HIFI] = {MULTIMEDIA2_PCM_DEVICE,
196 MULTIMEDIA2_PCM_DEVICE},
197
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700198 [USECASE_VOICE_CALL] = {VOICE_CALL_PCM_DEVICE,
199 VOICE_CALL_PCM_DEVICE},
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700200 [USECASE_VOICE2_CALL] = {VOICE2_CALL_PCM_DEVICE, VOICE2_CALL_PCM_DEVICE},
201 [USECASE_VOLTE_CALL] = {VOLTE_CALL_PCM_DEVICE, VOLTE_CALL_PCM_DEVICE},
202 [USECASE_QCHAT_CALL] = {QCHAT_CALL_PCM_DEVICE, QCHAT_CALL_PCM_DEVICE},
203 [USECASE_VOWLAN_CALL] = {VOWLAN_CALL_PCM_DEVICE, VOWLAN_CALL_PCM_DEVICE},
vivek mehtaa51fd402016-02-04 19:49:33 -0800204 [USECASE_VOICEMMODE1_CALL] = {VOICEMMODE1_CALL_PCM_DEVICE,
205 VOICEMMODE1_CALL_PCM_DEVICE},
206 [USECASE_VOICEMMODE2_CALL] = {VOICEMMODE2_CALL_PCM_DEVICE,
207 VOICEMMODE2_CALL_PCM_DEVICE},
208
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700209 [USECASE_INCALL_REC_UPLINK] = {AUDIO_RECORD_PCM_DEVICE,
210 AUDIO_RECORD_PCM_DEVICE},
211 [USECASE_INCALL_REC_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
212 AUDIO_RECORD_PCM_DEVICE},
213 [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
214 AUDIO_RECORD_PCM_DEVICE},
Ravi Kumar Alamanda8e6e98f2013-11-05 15:57:39 -0800215 [USECASE_AUDIO_HFP_SCO] = {HFP_PCM_RX, HFP_SCO_RX},
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700216
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700217 [USECASE_AUDIO_SPKR_CALIB_RX] = {SPKR_PROT_CALIB_RX_PCM_DEVICE, -1},
218 [USECASE_AUDIO_SPKR_CALIB_TX] = {-1, SPKR_PROT_CALIB_TX_PCM_DEVICE},
219
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700220 [USECASE_AUDIO_PLAYBACK_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
221 AFE_PROXY_RECORD_PCM_DEVICE},
222 [USECASE_AUDIO_RECORD_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
223 AFE_PROXY_RECORD_PCM_DEVICE},
zhaoyang yin4211fad2015-06-04 21:13:25 +0800224 [USECASE_AUDIO_DSM_FEEDBACK] = {QUAT_MI2S_PCM_DEVICE, QUAT_MI2S_PCM_DEVICE},
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700225
vivek mehtaa68fea62017-06-08 19:04:02 -0700226 [USECASE_AUDIO_PLAYBACK_VOIP] = {AUDIO_PLAYBACK_VOIP_PCM_DEVICE,
227 AUDIO_PLAYBACK_VOIP_PCM_DEVICE},
228 [USECASE_AUDIO_RECORD_VOIP] = {AUDIO_RECORD_VOIP_PCM_DEVICE,
229 AUDIO_RECORD_VOIP_PCM_DEVICE},
Nadav Bar3d72cfc2018-01-07 12:19:24 +0200230
231 [USECASE_INCALL_MUSIC_UPLINK] = {INCALL_MUSIC_UPLINK_PCM_DEVICE,
232 INCALL_MUSIC_UPLINK_PCM_DEVICE},
Eric Laurentb23d5282013-05-14 15:27:20 -0700233};
234
235/* Array to store sound devices */
236static const char * const device_table[SND_DEVICE_MAX] = {
237 [SND_DEVICE_NONE] = "none",
238 /* Playback sound devices */
239 [SND_DEVICE_OUT_HANDSET] = "handset",
240 [SND_DEVICE_OUT_SPEAKER] = "speaker",
241 [SND_DEVICE_OUT_SPEAKER_REVERSE] = "speaker-reverse",
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700242 [SND_DEVICE_OUT_SPEAKER_SAFE] = "speaker-safe",
Eric Laurentb23d5282013-05-14 15:27:20 -0700243 [SND_DEVICE_OUT_HEADPHONES] = "headphones",
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500244 [SND_DEVICE_OUT_LINE] = "line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700245 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones",
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700246 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = "speaker-safe-and-headphones",
Eric Laurent744996b2014-10-01 11:40:40 -0500247 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = "speaker-and-line",
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700248 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = "speaker-safe-and-line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700249 [SND_DEVICE_OUT_VOICE_HANDSET] = "voice-handset",
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500250 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = "voice-hac-handset",
Eric Laurentb23d5282013-05-14 15:27:20 -0700251 [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker",
252 [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones",
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500253 [SND_DEVICE_OUT_VOICE_LINE] = "voice-line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700254 [SND_DEVICE_OUT_HDMI] = "hdmi",
255 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi",
256 [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700257 [SND_DEVICE_OUT_BT_SCO_WB] = "bt-sco-headset-wb",
Aniket Kumar Lata26483012018-01-31 20:21:42 -0800258 [SND_DEVICE_OUT_BT_A2DP] = "bt-a2dp",
259 [SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] = "speaker-and-bt-a2dp",
Eric Laurentb23d5282013-05-14 15:27:20 -0700260 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = "voice-handset-tmus",
261 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones",
262 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones",
263 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset",
vivek mehtaa6b79742017-03-09 15:40:43 -0800264 [SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = "voice-tty-full-usb",
265 [SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = "voice-tty-vco-usb",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700266 [SND_DEVICE_OUT_VOICE_TX] = "voice-tx",
David Linee3fe402017-03-13 10:00:42 -0700267 [SND_DEVICE_OUT_USB_HEADSET] = "usb-headset",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700268 [SND_DEVICE_OUT_VOICE_USB_HEADSET] = "usb-headset",
David Linee3fe402017-03-13 10:00:42 -0700269 [SND_DEVICE_OUT_USB_HEADPHONES] = "usb-headphones",
jasmine cha270b7762018-03-30 15:41:33 +0800270 [SND_DEVICE_OUT_USB_HEADSET_SPEC] = "usb-headset",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700271 [SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = "usb-headphones",
David Linee3fe402017-03-13 10:00:42 -0700272 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = "speaker-and-usb-headphones",
Haynes Mathew George9090bfb2017-05-31 11:44:50 -0700273 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] = "speaker-safe-and-usb-headphones",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700274 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = "speaker-protected",
275 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = "voice-speaker-protected",
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -0700276 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = "voice-speaker-hfp",
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -0800277 [SND_DEVICE_OUT_SPEAKER_AND_BT_SCO] = "speaker-and-bt-sco",
278 [SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB] = "speaker-and-bt-sco-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700279
280 /* Capture sound devices */
281 [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700282 [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700283 [SND_DEVICE_IN_HANDSET_MIC_NS] = "handset-mic",
284 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = "handset-mic",
285 [SND_DEVICE_IN_HANDSET_DMIC] = "dmic-endfire",
286 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = "dmic-endfire",
287 [SND_DEVICE_IN_HANDSET_DMIC_NS] = "dmic-endfire",
288 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = "dmic-endfire",
289 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = "dmic-endfire",
290
291 [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
292 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "speaker-mic",
293 [SND_DEVICE_IN_SPEAKER_MIC_NS] = "speaker-mic",
294 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = "speaker-mic",
295 [SND_DEVICE_IN_SPEAKER_DMIC] = "speaker-dmic-endfire",
296 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = "speaker-dmic-endfire",
297 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = "speaker-dmic-endfire",
298 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = "speaker-dmic-endfire",
299 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = "speaker-dmic-endfire",
300
301 [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
Eric Laurentcefbbac2014-09-04 13:54:10 -0500302 [SND_DEVICE_IN_HEADSET_MIC_AEC] = "headset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700303
Eric Laurentb23d5282013-05-14 15:27:20 -0700304 [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic",
305 [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700306 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = "bt-sco-mic",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700307 [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700308 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = "bt-sco-mic-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700309 [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700310
311 [SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef",
312 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = "voice-dmic-ef-tmus",
313 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
314 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = "voice-speaker-dmic-ef",
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -0700315 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = "voice-speaker-mic-hfp",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700316 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700317 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
318 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
319 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
vivek mehtaa6b79742017-03-09 15:40:43 -0800320 [SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = "voice-tty-full-usb-mic",
321 [SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = "voice-tty-hco-usb-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700322
Eric Laurentb23d5282013-05-14 15:27:20 -0700323 [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700324 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = "voice-rec-mic",
vivek mehta733c1df2016-04-04 15:09:24 -0700325 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = "voice-rec-mic",
vivek mehtaf3440682016-05-11 14:24:37 -0700326 [SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700327 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = "voice-rec-dmic-ef",
328 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence",
David Linee3fe402017-03-13 10:00:42 -0700329 [SND_DEVICE_IN_USB_HEADSET_MIC] = "usb-headset-mic",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700330 [SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] ="usb-headset-mic",
331 [SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = "usb-headset-mic",
332 [SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = "usb-headset-mic",
333 [SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = "usb-headset-mic",
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700334 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = "headset-mic",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700335
Ricardo Garcia9034bc42016-04-04 07:11:46 -0700336 [SND_DEVICE_IN_UNPROCESSED_MIC] = "unprocessed-mic",
vivek mehta0125e782016-06-16 18:03:11 -0700337 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = "unprocessed-stereo-mic",
338 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = "unprocessed-three-mic",
339 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = "unprocessed-quad-mic",
340 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = "unprocessed-headset-mic",
rago90fb9612015-12-02 11:37:53 -0800341
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700342 [SND_DEVICE_IN_VOICE_RX] = "voice-rx",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700343
Prashant Malanic92c5962015-08-11 15:10:18 -0700344 [SND_DEVICE_IN_THREE_MIC] = "three-mic",
345 [SND_DEVICE_IN_QUAD_MIC] = "quad-mic",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700346 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = "vi-feedback",
Prashant Malanic92c5962015-08-11 15:10:18 -0700347 [SND_DEVICE_IN_HANDSET_TMIC] = "three-mic",
348 [SND_DEVICE_IN_HANDSET_QMIC] = "quad-mic",
vivek mehta733c1df2016-04-04 15:09:24 -0700349 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = "three-mic",
350 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = "quad-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700351};
352
353/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700354static int acdb_device_table[SND_DEVICE_MAX] = {
Eric Laurentb23d5282013-05-14 15:27:20 -0700355 [SND_DEVICE_NONE] = -1,
356 [SND_DEVICE_OUT_HANDSET] = 7,
357 [SND_DEVICE_OUT_SPEAKER] = 15,
358 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 15,
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700359 [SND_DEVICE_OUT_SPEAKER_SAFE] = 15,
Eric Laurentb23d5282013-05-14 15:27:20 -0700360 [SND_DEVICE_OUT_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500361 [SND_DEVICE_OUT_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700362 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700363 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500364 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = 77,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700365 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = 77,
Ravi Kumar Alamanda235c3482014-08-21 17:32:44 -0700366 [SND_DEVICE_OUT_VOICE_HANDSET] = ACDB_ID_VOICE_HANDSET,
367 [SND_DEVICE_OUT_VOICE_SPEAKER] = ACDB_ID_VOICE_SPEAKER,
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500368 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = 53,
Eric Laurentb23d5282013-05-14 15:27:20 -0700369 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500370 [SND_DEVICE_OUT_VOICE_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700371 [SND_DEVICE_OUT_HDMI] = 18,
372 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 15,
373 [SND_DEVICE_OUT_BT_SCO] = 22,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700374 [SND_DEVICE_OUT_BT_SCO_WB] = 39,
Aniket Kumar Lata26483012018-01-31 20:21:42 -0800375 [SND_DEVICE_OUT_BT_A2DP] = 20,
376 [SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] = 14,
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700377 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = ACDB_ID_VOICE_HANDSET_TMUS,
Eric Laurentb23d5282013-05-14 15:27:20 -0700378 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
379 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
380 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
vivek mehtaa6b79742017-03-09 15:40:43 -0800381 [SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = 17,
382 [SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = 17,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700383 [SND_DEVICE_OUT_VOICE_TX] = 45,
David Linee3fe402017-03-13 10:00:42 -0700384 [SND_DEVICE_OUT_USB_HEADSET] = 45,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700385 [SND_DEVICE_OUT_VOICE_USB_HEADSET] = 45,
David Linee3fe402017-03-13 10:00:42 -0700386 [SND_DEVICE_OUT_USB_HEADPHONES] = 45,
jasmine cha270b7762018-03-30 15:41:33 +0800387 [SND_DEVICE_OUT_USB_HEADSET_SPEC] = 45,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700388 [SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = 45,
David Linee3fe402017-03-13 10:00:42 -0700389 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = 14,
Haynes Mathew George9090bfb2017-05-31 11:44:50 -0700390 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] = 14,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700391 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = 124,
392 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = 101,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700393 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = ACDB_ID_VOICE_SPEAKER,
Eric Laurentb23d5282013-05-14 15:27:20 -0700394
395 [SND_DEVICE_IN_HANDSET_MIC] = 4,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700396 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 106,
397 [SND_DEVICE_IN_HANDSET_MIC_NS] = 107,
398 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = 108,
399 [SND_DEVICE_IN_HANDSET_DMIC] = 41,
400 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = 109,
401 [SND_DEVICE_IN_HANDSET_DMIC_NS] = 110,
402 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = 111,
403 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = 34,
404
405 [SND_DEVICE_IN_SPEAKER_MIC] = 11,
406 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 112,
407 [SND_DEVICE_IN_SPEAKER_MIC_NS] = 113,
408 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = 114,
409 [SND_DEVICE_IN_SPEAKER_DMIC] = 43,
410 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = 115,
411 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = 116,
412 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = 117,
413 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = 35,
414
rago90fb9612015-12-02 11:37:53 -0800415 [SND_DEVICE_IN_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentcefbbac2014-09-04 13:54:10 -0500416 [SND_DEVICE_IN_HEADSET_MIC_AEC] = ACDB_ID_HEADSET_MIC_AEC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700417
Eric Laurentb23d5282013-05-14 15:27:20 -0700418 [SND_DEVICE_IN_HDMI_MIC] = 4,
419 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700420 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = 21,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700421 [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700422 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = 38,
Eric Laurentb23d5282013-05-14 15:27:20 -0700423 [SND_DEVICE_IN_CAMCORDER_MIC] = 61,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700424
425 [SND_DEVICE_IN_VOICE_DMIC] = 41,
426 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = ACDB_ID_VOICE_DMIC_EF_TMUS,
427 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700428 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = 11,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700429 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 43,
rago90fb9612015-12-02 11:37:53 -0800430 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentb23d5282013-05-14 15:27:20 -0700431 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
432 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
433 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
vivek mehtaa6b79742017-03-09 15:40:43 -0800434 [SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = 16,
435 [SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = 16,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700436
rago90fb9612015-12-02 11:37:53 -0800437 [SND_DEVICE_IN_VOICE_REC_MIC] = ACDB_ID_VOICE_REC_MIC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700438 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = 113,
vivek mehta733c1df2016-04-04 15:09:24 -0700439 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = 112,
vivek mehtaf3440682016-05-11 14:24:37 -0700440 [SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = 114,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700441 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = 35,
442 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 43,
rago90fb9612015-12-02 11:37:53 -0800443 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
444
445 [SND_DEVICE_IN_UNPROCESSED_MIC] = ACDB_ID_VOICE_REC_MIC,
446 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
vivek mehta4ed66e62016-04-15 23:33:34 -0700447 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = 35,
448 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = 125,
449 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = 125,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700450
451 [SND_DEVICE_IN_VOICE_RX] = 44,
David Linee3fe402017-03-13 10:00:42 -0700452 [SND_DEVICE_IN_USB_HEADSET_MIC] = 44,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700453 [SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = 44,
454 [SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = 44,
455 [SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = 44,
456 [SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = 44,
Prashant Malanic92c5962015-08-11 15:10:18 -0700457 [SND_DEVICE_IN_THREE_MIC] = 46,
458 [SND_DEVICE_IN_QUAD_MIC] = 46,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700459 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = 102,
Prashant Malanic92c5962015-08-11 15:10:18 -0700460 [SND_DEVICE_IN_HANDSET_TMIC] = 125,
461 [SND_DEVICE_IN_HANDSET_QMIC] = 125,
vivek mehta733c1df2016-04-04 15:09:24 -0700462 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = 125, /* override this for new target to 140 */
463 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = 125, /* override this for new target to 140 */
Eric Laurentb23d5282013-05-14 15:27:20 -0700464};
465
David Linee3fe402017-03-13 10:00:42 -0700466// Platform specific backend bit width table
467static int backend_bit_width_table[SND_DEVICE_MAX] = {0};
468
Haynes Mathew George98c95622014-06-20 19:14:25 -0700469struct name_to_index {
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700470 char name[100];
471 unsigned int index;
472};
473
474#define TO_NAME_INDEX(X) #X, X
475
Haynes Mathew George98c95622014-06-20 19:14:25 -0700476/* Used to get index from parsed string */
477static const struct name_to_index snd_device_name_index[SND_DEVICE_MAX] = {
478 /* out */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700479 {TO_NAME_INDEX(SND_DEVICE_OUT_HANDSET)},
480 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER)},
481 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_REVERSE)},
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700482 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700483 {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500484 {TO_NAME_INDEX(SND_DEVICE_OUT_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700485 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700486 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES)},
Eric Laurent744996b2014-10-01 11:40:40 -0500487 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_LINE)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700488 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700489 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET)},
490 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700491 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_HFP)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700492 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500493 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700494 {TO_NAME_INDEX(SND_DEVICE_OUT_HDMI)},
495 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HDMI)},
496 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO)},
497 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO_WB)},
Aniket Kumar Lata26483012018-01-31 20:21:42 -0800498 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_A2DP)},
499 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700500 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET_TMUS)},
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500501 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HAC_HANDSET)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700502 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES)},
503 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES)},
504 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET)},
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -0800505 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_SCO)},
506 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800507 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_USB)},
508 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_USB)},
David Linee3fe402017-03-13 10:00:42 -0700509 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADSET)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700510 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_USB_HEADSET)},
David Linee3fe402017-03-13 10:00:42 -0700511 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADPHONES)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700512 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_USB_HEADPHONES)},
David Linee3fe402017-03-13 10:00:42 -0700513 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET)},
Haynes Mathew George9090bfb2017-05-31 11:44:50 -0700514 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700515 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED)},
516 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED)},
jasmine cha270b7762018-03-30 15:41:33 +0800517 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADSET_SPEC)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800518
519 /* in */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700520 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700521 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700522 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_NS)},
523 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)},
524 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC)},
525 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC)},
526 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_NS)},
527 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)},
528 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_STEREO)},
529
530 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700531 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700532 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_NS)},
533 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)},
534 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC)},
535 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC)},
536 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS)},
537 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)},
538 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_STEREO)},
539
540 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC)},
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700541 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700542
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700543 {TO_NAME_INDEX(SND_DEVICE_IN_HDMI_MIC)},
544 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700545 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700546 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700547 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700548 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700549
550 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC)},
551 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC_TMUS)},
552 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700553 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700554 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC)},
555 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEADSET_MIC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700556 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC)},
557 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC)},
558 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800559 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC)},
560 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC)},
561
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700562
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700563 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700564 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_NS)},
vivek mehta733c1df2016-04-04 15:09:24 -0700565 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC)},
vivek mehtaf3440682016-05-11 14:24:37 -0700566 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700567 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_STEREO)},
568 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE)},
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700569 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_HEADSET_MIC)},
David Linee3fe402017-03-13 10:00:42 -0700570 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700571 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_USB_HEADSET_MIC)},
572 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC)},
573 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC)},
574 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC_AEC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700575
rago90fb9612015-12-02 11:37:53 -0800576 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_MIC)},
577 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC)},
vivek mehta4ed66e62016-04-15 23:33:34 -0700578 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_STEREO_MIC)},
579 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_THREE_MIC)},
580 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_QUAD_MIC)},
rago90fb9612015-12-02 11:37:53 -0800581
Prashant Malanic92c5962015-08-11 15:10:18 -0700582 {TO_NAME_INDEX(SND_DEVICE_IN_THREE_MIC)},
583 {TO_NAME_INDEX(SND_DEVICE_IN_QUAD_MIC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700584 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_VI_FEEDBACK)},
Prashant Malanic92c5962015-08-11 15:10:18 -0700585 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC)},
586 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC)},
vivek mehta733c1df2016-04-04 15:09:24 -0700587 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC_AEC)},
588 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC_AEC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700589};
590
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700591static char * backend_tag_table[SND_DEVICE_MAX] = {0};
592static char * hw_interface_table[SND_DEVICE_MAX] = {0};
Haynes Mathew George98c95622014-06-20 19:14:25 -0700593
594static const struct name_to_index usecase_name_index[AUDIO_USECASE_MAX] = {
595 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_DEEP_BUFFER)},
596 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_LOW_LATENCY)},
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800597 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_HIFI)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700598 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD)},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700599 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_TTS)},
600 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_ULL)},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800601 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_MMAP)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700602 {TO_NAME_INDEX(USECASE_AUDIO_RECORD)},
603 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_LOW_LATENCY)},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800604 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_MMAP)},
Haynes Mathew George569b7482017-05-08 14:44:27 -0700605 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_HIFI)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700606 {TO_NAME_INDEX(USECASE_VOICE_CALL)},
607 {TO_NAME_INDEX(USECASE_VOICE2_CALL)},
608 {TO_NAME_INDEX(USECASE_VOLTE_CALL)},
609 {TO_NAME_INDEX(USECASE_QCHAT_CALL)},
610 {TO_NAME_INDEX(USECASE_VOWLAN_CALL)},
John Muirf1346ce2016-12-06 00:03:41 -0800611 {TO_NAME_INDEX(USECASE_VOICEMMODE1_CALL)},
612 {TO_NAME_INDEX(USECASE_VOICEMMODE2_CALL)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700613 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK)},
614 {TO_NAME_INDEX(USECASE_INCALL_REC_DOWNLINK)},
615 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK_AND_DOWNLINK)},
616 {TO_NAME_INDEX(USECASE_AUDIO_HFP_SCO)},
John Muirf1346ce2016-12-06 00:03:41 -0800617 {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_RX)},
618 {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_TX)},
619 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_AFE_PROXY)},
620 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_AFE_PROXY)},
621 {TO_NAME_INDEX(USECASE_AUDIO_DSM_FEEDBACK)},
vivek mehtaa68fea62017-06-08 19:04:02 -0700622 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_VOIP)},
623 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_VOIP)},
Nadav Bar3d72cfc2018-01-07 12:19:24 +0200624 {TO_NAME_INDEX(USECASE_INCALL_MUSIC_UPLINK)},
Aniket Kumar Lata99546312018-03-19 21:38:38 -0700625 {TO_NAME_INDEX(USECASE_AUDIO_A2DP_ABR_FEEDBACK)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700626};
627
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800628static const struct name_to_index usecase_type_index[USECASE_TYPE_MAX] = {
629 {TO_NAME_INDEX(PCM_PLAYBACK)},
630 {TO_NAME_INDEX(PCM_CAPTURE)},
631 {TO_NAME_INDEX(VOICE_CALL)},
632 {TO_NAME_INDEX(PCM_HFP_CALL)},
633};
634
635struct app_type_entry {
636 int uc_type;
637 int bit_width;
638 int app_type;
639 int max_rate;
vivek mehtaa68fea62017-06-08 19:04:02 -0700640 char *mode;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800641 struct listnode node; // membership in app_type_entry_list;
642};
643
644static struct listnode app_type_entry_list;
645
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700646#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
647#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
Eric Laurent0e46adf2016-12-16 12:49:24 -0800648#define ULL_PLATFORM_DELAY (3*1000LL)
649#define MMAP_PLATFORM_DELAY (3*1000LL)
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700650
Eric Laurentb23d5282013-05-14 15:27:20 -0700651static pthread_once_t check_op_once_ctl = PTHREAD_ONCE_INIT;
652static bool is_tmus = false;
653
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800654static int init_be_dai_name_table(struct audio_device *adev);
655
Eric Laurentb23d5282013-05-14 15:27:20 -0700656static void check_operator()
657{
658 char value[PROPERTY_VALUE_MAX];
659 int mccmnc;
660 property_get("gsm.sim.operator.numeric",value,"0");
661 mccmnc = atoi(value);
Eric Laurent2bafff12016-03-17 12:17:23 -0700662 ALOGD("%s: tmus mccmnc %d", __func__, mccmnc);
Eric Laurentb23d5282013-05-14 15:27:20 -0700663 switch(mccmnc) {
664 /* TMUS MCC(310), MNC(490, 260, 026) */
665 case 310490:
666 case 310260:
667 case 310026:
sangwon.jeonb891db52013-09-14 17:39:15 +0900668 /* Add new TMUS MNC(800, 660, 580, 310, 270, 250, 240, 230, 220, 210, 200, 160) */
669 case 310800:
670 case 310660:
671 case 310580:
672 case 310310:
673 case 310270:
674 case 310250:
675 case 310240:
676 case 310230:
677 case 310220:
678 case 310210:
679 case 310200:
680 case 310160:
Eric Laurentb23d5282013-05-14 15:27:20 -0700681 is_tmus = true;
682 break;
683 }
684}
685
686bool is_operator_tmus()
687{
688 pthread_once(&check_op_once_ctl, check_operator);
689 return is_tmus;
690}
691
keunhui.park2f7306a2015-07-16 16:48:06 +0900692static char *get_current_operator()
693{
694 struct listnode *node;
695 struct operator_info *info_item;
696 char mccmnc[PROPERTY_VALUE_MAX];
697 char *ret = NULL;
698
Tom Cherry7fea2042016-11-10 18:05:59 -0800699 property_get("gsm.sim.operator.numeric",mccmnc,"00000");
keunhui.park2f7306a2015-07-16 16:48:06 +0900700
701 list_for_each(node, &operator_info_list) {
702 info_item = node_to_item(node, struct operator_info, list);
703 if (strstr(info_item->mccmnc, mccmnc) != NULL) {
704 ret = info_item->name;
705 }
706 }
707
708 return ret;
709}
710
711static struct operator_specific_device *get_operator_specific_device(snd_device_t snd_device)
712{
713 struct listnode *node;
714 struct operator_specific_device *ret = NULL;
715 struct operator_specific_device *device_item;
716 char *operator_name;
717
718 operator_name = get_current_operator();
719 if (operator_name == NULL)
720 return ret;
721
722 list_for_each(node, operator_specific_device_table[snd_device]) {
723 device_item = node_to_item(node, struct operator_specific_device, list);
724 if (strcmp(operator_name, device_item->operator) == 0) {
725 ret = device_item;
726 }
727 }
728
729 return ret;
730}
731
732
733static int get_operator_specific_device_acdb_id(snd_device_t snd_device)
734{
735 struct operator_specific_device *device;
736 int ret = acdb_device_table[snd_device];
737
738 device = get_operator_specific_device(snd_device);
739 if (device != NULL)
740 ret = device->acdb_id;
741
742 return ret;
743}
744
745static const char *get_operator_specific_device_mixer_path(snd_device_t snd_device)
746{
747 struct operator_specific_device *device;
748 const char *ret = device_table[snd_device];
749
750 device = get_operator_specific_device(snd_device);
751 if (device != NULL)
752 ret = device->mixer_path;
753
754 return ret;
755}
756
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800757inline bool platform_supports_app_type_cfg()
758{
Alexey Polyudove920d4b2017-09-15 17:09:07 -0700759#if defined (PLATFORM_MSM8998) || (PLATFORM_SDM845)
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800760 return true;
761#else
762 return false;
763#endif
764}
765
jasmine chac89321b2018-04-10 21:37:01 +0800766static int parse_audiocal_cfg(struct str_parms *parms, acdb_audio_cal_cfg_t *cal)
767{
768 int err;
769 char value[64];
770 int ret = 0;
771
772 if (parms == NULL || cal == NULL)
773 return ret;
774
775 err = str_parms_get_str(parms, "cal_persist", value, sizeof(value));
776 if (err >= 0) {
777 str_parms_del(parms, "cal_persist");
778 cal->persist = (uint32_t)strtoul(value, NULL, 0);
779 ret = ret | 0x1;
780 }
781 err = str_parms_get_str(parms, "cal_apptype", value, sizeof(value));
782 if (err >= 0) {
783 str_parms_del(parms, "cal_apptype");
784 cal->app_type = (uint32_t)strtoul(value, NULL, 0);
785 ret = ret | 0x2;
786 }
787 err = str_parms_get_str(parms, "cal_caltype", value, sizeof(value));
788 if (err >= 0) {
789 str_parms_del(parms, "cal_caltype");
790 cal->cal_type = (uint32_t)strtoul(value, NULL, 0);
791 ret = ret | 0x4;
792 }
793 err = str_parms_get_str(parms, "cal_samplerate", value, sizeof(value));
794 if (err >= 0) {
795 str_parms_del(parms, "cal_samplerate");
796 cal->sampling_rate = (uint32_t)strtoul(value, NULL, 0);
797 ret = ret | 0x8;
798 }
799 err = str_parms_get_str(parms, "cal_devid", value, sizeof(value));
800 if (err >= 0) {
801 str_parms_del(parms, "cal_devid");
802 cal->dev_id = (uint32_t)strtoul(value, NULL, 0);
803 ret = ret | 0x10;
804 }
805 err = str_parms_get_str(parms, "cal_snddevid", value, sizeof(value));
806 if (err >= 0) {
807 str_parms_del(parms, "cal_snddevid");
808 cal->snd_dev_id = (uint32_t)strtoul(value, NULL, 0);
809 ret = ret | 0x20;
810 }
811 err = str_parms_get_str(parms, "cal_topoid", value, sizeof(value));
812 if (err >= 0) {
813 str_parms_del(parms, "cal_topoid");
814 cal->topo_id = (uint32_t)strtoul(value, NULL, 0);
815 ret = ret | 0x40;
816 }
817 err = str_parms_get_str(parms, "cal_moduleid", value, sizeof(value));
818 if (err >= 0) {
819 str_parms_del(parms, "cal_moduleid");
820 cal->module_id = (uint32_t)strtoul(value, NULL, 0);
821 ret = ret | 0x80;
822 }
823 err = str_parms_get_str(parms, "cal_paramid", value, sizeof(value));
824 if (err >= 0) {
825 str_parms_del(parms, "cal_paramid");
826 cal->param_id = (uint32_t)strtoul(value, NULL, 0);
827 ret = ret | 0x100;
828 }
829 return ret;
830}
831
832static void set_audiocal(void *platform, struct str_parms *parms, char *value, int len)
833{
834 struct platform_data *my_data = (struct platform_data *)platform;
835 acdb_audio_cal_cfg_t cal;
836 uint8_t *dptr = NULL;
837 int32_t dlen = 0;
838 int err ,ret;
839
840 if (value == NULL || platform == NULL || parms == NULL) {
841 ALOGE("[%s] received null pointer, failed", __func__);
842 goto done_key_audcal;
843 }
844
845 memset(&cal, 0, sizeof(acdb_audio_cal_cfg_t));
846 /* parse audio calibration keys */
847 ret = parse_audiocal_cfg(parms, &cal);
848
849 /* handle audio calibration data now */
850 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_AUD_CALDATA, value, len);
851 if (err >= 0) {
852 str_parms_del(parms, AUDIO_PARAMETER_KEY_AUD_CALDATA);
853 dlen = strlen(value);
854 if (dlen <= 0) {
855 ALOGE("[%s] null data received", __func__);
856 goto done_key_audcal;
857 }
858 /*
859 The base64 encoded string is always larger than the binary data,
860 so b64_pton will always output less data than provided (around 1/3
861 less than the input data). That's why we can allocate input buffer
862 length and then get function work.
863 */
864 dptr = (uint8_t *)calloc(dlen, sizeof(uint8_t));
865 if (dptr == NULL) {
866 ALOGE("[%s] memory allocation failed for %d", __func__, dlen);
867 goto done_key_audcal;
868 }
869 dlen = b64_pton(value, dptr, dlen);
870 if (dlen <= 0) {
871 ALOGE("[%s] data decoding failed %d", __func__, dlen);
872 goto done_key_audcal;
873 }
874
875 if (cal.dev_id) {
876 if (audio_is_input_device(cal.dev_id)) {
877 cal.snd_dev_id = platform_get_input_snd_device(platform, cal.dev_id);
878 } else {
879 cal.snd_dev_id = platform_get_output_snd_device(platform, cal.dev_id);
880 }
881 }
882 cal.acdb_dev_id = platform_get_snd_device_acdb_id(cal.snd_dev_id);
883 ALOGD("Setting audio calibration for snd_device(%d) acdb_id(%d)",
884 cal.snd_dev_id, cal.acdb_dev_id);
885 if (cal.acdb_dev_id == -EINVAL) {
886 ALOGE("[%s] Invalid acdb_device id %d for snd device id %d",
887 __func__, cal.acdb_dev_id, cal.snd_dev_id);
888 goto done_key_audcal;
889 }
890 if (my_data->acdb_set_audio_cal) {
891 ret = my_data->acdb_set_audio_cal((void *)&cal, (void *)dptr, dlen);
892 }
893 }
894done_key_audcal:
895 if (dptr != NULL)
896 free(dptr);
897}
898
vivek mehta1a9b7c02015-06-25 11:49:38 -0700899bool platform_send_gain_dep_cal(void *platform, int level)
900{
901 bool ret_val = false;
902 struct platform_data *my_data = (struct platform_data *)platform;
903 struct audio_device *adev = my_data->adev;
904 int acdb_dev_id, app_type;
905 int acdb_dev_type = MSM_SNDDEV_CAP_RX;
906 int mode = CAL_MODE_RTAC;
907 struct listnode *node;
908 struct audio_usecase *usecase;
Haynes Mathew George67486e22017-06-26 12:58:38 -0700909 bool valid_uc_type;
910 bool valid_dev;
vivek mehta1a9b7c02015-06-25 11:49:38 -0700911
912 if (my_data->acdb_send_gain_dep_cal == NULL) {
913 ALOGE("%s: dlsym error for acdb_send_gain_dep_cal", __func__);
914 return ret_val;
915 }
916
917 if (!voice_is_in_call(adev)) {
918 ALOGV("%s: Not Voice call usecase, apply new cal for level %d",
919 __func__, level);
vivek mehta1a9b7c02015-06-25 11:49:38 -0700920
921 // find the current active sound device
922 list_for_each(node, &adev->usecase_list) {
923 usecase = node_to_item(node, struct audio_usecase, list);
Haynes Mathew George67486e22017-06-26 12:58:38 -0700924 LOG_ALWAYS_FATAL_IF(usecase == NULL,
925 "unxpected NULL usecase in usecase_list");
926 valid_uc_type = usecase->type == PCM_PLAYBACK;
927 valid_dev = false;
928 if (valid_uc_type) {
929 audio_devices_t dev = usecase->stream.out->devices;
930 valid_dev = (dev == AUDIO_DEVICE_OUT_SPEAKER ||
vivek mehta40125092017-08-21 18:48:51 -0700931 dev == AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Haynes Mathew George67486e22017-06-26 12:58:38 -0700932 dev == AUDIO_DEVICE_OUT_WIRED_HEADSET ||
933 dev == AUDIO_DEVICE_OUT_WIRED_HEADPHONE);
934 }
935 if (valid_dev) {
vivek mehta40125092017-08-21 18:48:51 -0700936 ALOGV("%s: out device is %d", __func__, usecase->out_snd_device);
937 if (platform_supports_app_type_cfg())
938 app_type = usecase->stream.out->app_type_cfg.app_type;
939 else
940 app_type = DEFAULT_APP_TYPE_RX_PATH;
vivek mehta4cb82982015-07-13 12:05:49 -0700941
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -0700942 acdb_dev_id = platform_get_snd_device_acdb_id(usecase->out_snd_device);
vivek mehta40125092017-08-21 18:48:51 -0700943
944 if (!my_data->acdb_send_gain_dep_cal(acdb_dev_id, app_type,
vivek mehta1a9b7c02015-06-25 11:49:38 -0700945 acdb_dev_type, mode, level)) {
946 // set ret_val true if at least one calibration is set successfully
947 ret_val = true;
948 } else {
949 ALOGE("%s: my_data->acdb_send_gain_dep_cal failed ", __func__);
950 }
951 } else {
952 ALOGW("%s: Usecase list is empty", __func__);
953 }
954 }
955 } else {
956 ALOGW("%s: Voice call in progress .. ignore setting new cal",
957 __func__);
958 }
959 return ret_val;
960}
961
Eric Laurentcefbbac2014-09-04 13:54:10 -0500962void platform_set_echo_reference(struct audio_device *adev, bool enable, audio_devices_t out_device)
Eric Laurentb23d5282013-05-14 15:27:20 -0700963{
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800964 struct platform_data *my_data = (struct platform_data *)adev->platform;
Eric Laurentcefbbac2014-09-04 13:54:10 -0500965 snd_device_t snd_device = SND_DEVICE_NONE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700966
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800967 if (strcmp(my_data->ec_ref_mixer_path, "")) {
968 ALOGV("%s: diabling %s", __func__, my_data->ec_ref_mixer_path);
969 audio_route_reset_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
Eric Laurentcefbbac2014-09-04 13:54:10 -0500970 }
971
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800972 if (enable) {
973 strcpy(my_data->ec_ref_mixer_path, "echo-reference");
974 if (out_device != AUDIO_DEVICE_NONE) {
975 snd_device = platform_get_output_snd_device(adev->platform, out_device);
976 platform_add_backend_name(adev->platform, my_data->ec_ref_mixer_path, snd_device);
977 }
Eric Laurentcefbbac2014-09-04 13:54:10 -0500978
Joe Onorato188b6222016-03-01 11:02:27 -0800979 ALOGV("%s: enabling %s", __func__, my_data->ec_ref_mixer_path);
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800980 audio_route_apply_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
981 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700982}
983
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700984static struct csd_data *open_csd_client(bool i2s_ext_modem)
985{
986 struct csd_data *csd = calloc(1, sizeof(struct csd_data));
987
988 csd->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
989 if (csd->csd_client == NULL) {
990 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
991 goto error;
992 } else {
993 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
994
995 csd->deinit = (deinit_t)dlsym(csd->csd_client,
996 "csd_client_deinit");
997 if (csd->deinit == NULL) {
998 ALOGE("%s: dlsym error %s for csd_client_deinit", __func__,
999 dlerror());
1000 goto error;
1001 }
1002 csd->disable_device = (disable_device_t)dlsym(csd->csd_client,
1003 "csd_client_disable_device");
1004 if (csd->disable_device == NULL) {
1005 ALOGE("%s: dlsym error %s for csd_client_disable_device",
1006 __func__, dlerror());
1007 goto error;
1008 }
1009 csd->enable_device_config = (enable_device_config_t)dlsym(csd->csd_client,
1010 "csd_client_enable_device_config");
1011 if (csd->enable_device_config == NULL) {
1012 ALOGE("%s: dlsym error %s for csd_client_enable_device_config",
1013 __func__, dlerror());
1014 goto error;
1015 }
1016 csd->enable_device = (enable_device_t)dlsym(csd->csd_client,
1017 "csd_client_enable_device");
1018 if (csd->enable_device == NULL) {
1019 ALOGE("%s: dlsym error %s for csd_client_enable_device",
1020 __func__, dlerror());
1021 goto error;
1022 }
1023 csd->start_voice = (start_voice_t)dlsym(csd->csd_client,
1024 "csd_client_start_voice");
1025 if (csd->start_voice == NULL) {
1026 ALOGE("%s: dlsym error %s for csd_client_start_voice",
1027 __func__, dlerror());
1028 goto error;
1029 }
1030 csd->stop_voice = (stop_voice_t)dlsym(csd->csd_client,
1031 "csd_client_stop_voice");
1032 if (csd->stop_voice == NULL) {
1033 ALOGE("%s: dlsym error %s for csd_client_stop_voice",
1034 __func__, dlerror());
1035 goto error;
1036 }
1037 csd->volume = (volume_t)dlsym(csd->csd_client,
1038 "csd_client_volume");
1039 if (csd->volume == NULL) {
1040 ALOGE("%s: dlsym error %s for csd_client_volume",
1041 __func__, dlerror());
1042 goto error;
1043 }
1044 csd->mic_mute = (mic_mute_t)dlsym(csd->csd_client,
1045 "csd_client_mic_mute");
1046 if (csd->mic_mute == NULL) {
1047 ALOGE("%s: dlsym error %s for csd_client_mic_mute",
1048 __func__, dlerror());
1049 goto error;
1050 }
1051 csd->slow_talk = (slow_talk_t)dlsym(csd->csd_client,
1052 "csd_client_slow_talk");
1053 if (csd->slow_talk == NULL) {
1054 ALOGE("%s: dlsym error %s for csd_client_slow_talk",
1055 __func__, dlerror());
1056 goto error;
1057 }
1058 csd->start_playback = (start_playback_t)dlsym(csd->csd_client,
1059 "csd_client_start_playback");
1060 if (csd->start_playback == NULL) {
1061 ALOGE("%s: dlsym error %s for csd_client_start_playback",
1062 __func__, dlerror());
1063 goto error;
1064 }
1065 csd->stop_playback = (stop_playback_t)dlsym(csd->csd_client,
1066 "csd_client_stop_playback");
1067 if (csd->stop_playback == NULL) {
1068 ALOGE("%s: dlsym error %s for csd_client_stop_playback",
1069 __func__, dlerror());
1070 goto error;
1071 }
1072 csd->start_record = (start_record_t)dlsym(csd->csd_client,
1073 "csd_client_start_record");
1074 if (csd->start_record == NULL) {
1075 ALOGE("%s: dlsym error %s for csd_client_start_record",
1076 __func__, dlerror());
1077 goto error;
1078 }
1079 csd->stop_record = (stop_record_t)dlsym(csd->csd_client,
1080 "csd_client_stop_record");
1081 if (csd->stop_record == NULL) {
1082 ALOGE("%s: dlsym error %s for csd_client_stop_record",
1083 __func__, dlerror());
1084 goto error;
1085 }
1086
1087 csd->get_sample_rate = (get_sample_rate_t)dlsym(csd->csd_client,
1088 "csd_client_get_sample_rate");
1089 if (csd->get_sample_rate == NULL) {
1090 ALOGE("%s: dlsym error %s for csd_client_get_sample_rate",
1091 __func__, dlerror());
1092
1093 goto error;
1094 }
1095
1096 csd->init = (init_t)dlsym(csd->csd_client, "csd_client_init");
1097
1098 if (csd->init == NULL) {
1099 ALOGE("%s: dlsym error %s for csd_client_init",
1100 __func__, dlerror());
1101 goto error;
1102 } else {
1103 csd->init(i2s_ext_modem);
1104 }
1105 }
1106 return csd;
1107
1108error:
1109 free(csd);
1110 csd = NULL;
1111 return csd;
1112}
1113
1114void close_csd_client(struct csd_data *csd)
1115{
1116 if (csd != NULL) {
1117 csd->deinit();
1118 dlclose(csd->csd_client);
1119 free(csd);
1120 csd = NULL;
1121 }
1122}
1123
1124static void platform_csd_init(struct platform_data *my_data)
1125{
1126#ifdef PLATFORM_MSM8084
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001127 int32_t modems, (*count_modems)(void);
1128 const char *name = "libdetectmodem.so";
1129 const char *func = "count_modems";
1130 const char *error;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001131
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001132 my_data->csd = NULL;
1133
1134 void *lib = dlopen(name, RTLD_NOW);
1135 error = dlerror();
1136 if (!lib) {
1137 ALOGE("%s: could not find %s: %s", __func__, name, error);
1138 return;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001139 }
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001140
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001141 count_modems = NULL;
1142 *(void **)(&count_modems) = dlsym(lib, func);
1143 error = dlerror();
1144 if (!count_modems) {
1145 ALOGE("%s: could not find symbol %s in %s: %s",
1146 __func__, func, name, error);
1147 goto done;
1148 }
1149
1150 modems = count_modems();
1151 if (modems < 0) {
1152 ALOGE("%s: count_modems failed\n", __func__);
1153 goto done;
1154 }
1155
Eric Laurent2bafff12016-03-17 12:17:23 -07001156 ALOGD("%s: num_modems %d\n", __func__, modems);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001157 if (modems > 0)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001158 my_data->csd = open_csd_client(false /*is_i2s_ext_modem*/);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001159
1160done:
1161 dlclose(lib);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001162#else
1163 my_data->csd = NULL;
1164#endif
1165}
1166
Eric Laurentc6333382015-09-14 12:43:44 -07001167static void set_platform_defaults(struct platform_data * my_data)
Haynes Mathew George98c95622014-06-20 19:14:25 -07001168{
1169 int32_t dev;
1170 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001171 backend_tag_table[dev] = NULL;
1172 hw_interface_table[dev] = NULL;
keunhui.park2f7306a2015-07-16 16:48:06 +09001173 operator_specific_device_table[dev] = NULL;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001174 }
1175
David Linee3fe402017-03-13 10:00:42 -07001176 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1177 backend_bit_width_table[dev] = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
1178 }
1179
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001180 // To overwrite these go to the audio_platform_info.xml file.
1181 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("bt-sco");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07001182 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("bt-sco");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001183 backend_tag_table[SND_DEVICE_OUT_BT_SCO] = strdup("bt-sco");
1184 backend_tag_table[SND_DEVICE_OUT_HDMI] = strdup("hdmi");
1185 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("speaker-and-hdmi");
1186 backend_tag_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("bt-sco-wb");
1187 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("bt-sco-wb");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07001188 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("bt-sco-wb");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001189 backend_tag_table[SND_DEVICE_OUT_VOICE_TX] = strdup("afe-proxy");
1190 backend_tag_table[SND_DEVICE_IN_VOICE_RX] = strdup("afe-proxy");
Haynes Mathew George98c95622014-06-20 19:14:25 -07001191
David Linee3fe402017-03-13 10:00:42 -07001192 backend_tag_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("usb-headset");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001193 backend_tag_table[SND_DEVICE_OUT_VOICE_USB_HEADSET] = strdup("usb-headset");
David Linee3fe402017-03-13 10:00:42 -07001194 backend_tag_table[SND_DEVICE_OUT_USB_HEADPHONES] = strdup("usb-headphones");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001195 backend_tag_table[SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = strdup("usb-headphones");
David Linee3fe402017-03-13 10:00:42 -07001196 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] =
1197 strdup("speaker-and-usb-headphones");
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07001198 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] =
1199 strdup("speaker-safe-and-usb-headphones");
David Linee3fe402017-03-13 10:00:42 -07001200 backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("usb-headset-mic");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001201 backend_tag_table[SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1202 backend_tag_table[SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1203 backend_tag_table[SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1204 backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = strdup("usb-headset-mic");
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001205 backend_tag_table[SND_DEVICE_OUT_BT_A2DP] = strdup("bt-a2dp");
1206 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] = strdup("speaker-and-bt-a2dp");
jasmine cha270b7762018-03-30 15:41:33 +08001207 backend_tag_table[SND_DEVICE_OUT_USB_HEADSET_SPEC] = strdup("usb-headset");
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001208
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001209 hw_interface_table[SND_DEVICE_OUT_HANDSET] = strdup("SLIMBUS_0_RX");
1210 hw_interface_table[SND_DEVICE_OUT_SPEAKER] = strdup("SLIMBUS_0_RX");
1211 hw_interface_table[SND_DEVICE_OUT_SPEAKER_REVERSE] = strdup("SLIMBUS_0_RX");
1212 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE] = strdup("SLIMBUS_0_RX");
1213 hw_interface_table[SND_DEVICE_OUT_HEADPHONES] = strdup("SLIMBUS_0_RX");
1214 hw_interface_table[SND_DEVICE_OUT_LINE] = strdup("SLIMBUS_0_RX");
1215 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001216 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001217 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001218 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001219 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET] = strdup("SLIMBUS_0_RX");
1220 hw_interface_table[SND_DEVICE_OUT_VOICE_HAC_HANDSET] = strdup("SLIMBUS_0_RX");
1221 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER] = strdup("SLIMBUS_0_RX");
1222 hw_interface_table[SND_DEVICE_OUT_VOICE_HEADPHONES] = strdup("SLIMBUS_0_RX");
1223 hw_interface_table[SND_DEVICE_OUT_VOICE_LINE] = strdup("SLIMBUS_0_RX");
1224 hw_interface_table[SND_DEVICE_OUT_HDMI] = strdup("HDMI_RX");
1225 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("SLIMBUS_0_RX-and-HDMI_RX");
1226 hw_interface_table[SND_DEVICE_OUT_BT_SCO] = strdup("SEC_AUX_PCM_RX");
1227 hw_interface_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("SEC_AUX_PCM_RX");
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001228 hw_interface_table[SND_DEVICE_OUT_BT_A2DP] = strdup("SLIMBUS_7_RX");
1229 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] =
1230 strdup("SLIMBUS_0_RX-and-SLIMBUS_7_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001231 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = strdup("SLIMBUS_0_RX");
1232 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = strdup("SLIMBUS_0_RX");
1233 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = strdup("SLIMBUS_0_RX");
1234 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = strdup("SLIMBUS_0_RX");
David Linee3fe402017-03-13 10:00:42 -07001235 hw_interface_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("USB_AUDIO_RX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001236 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = strdup("USB_AUDIO_RX");
1237 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = strdup("USB_AUDIO_RX");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001238 hw_interface_table[SND_DEVICE_OUT_VOICE_USB_HEADSET] = strdup("USB_AUDIO_RX");
David Linee3fe402017-03-13 10:00:42 -07001239 hw_interface_table[SND_DEVICE_OUT_USB_HEADPHONES] = strdup("USB_AUDIO_RX");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001240 hw_interface_table[SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = strdup("USB_AUDIO_RX");
jasmine cha270b7762018-03-30 15:41:33 +08001241 hw_interface_table[SND_DEVICE_OUT_USB_HEADSET_SPEC] = strdup("USB_AUDIO_RX");
David Linee3fe402017-03-13 10:00:42 -07001242 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 -07001243 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 -07001244 hw_interface_table[SND_DEVICE_OUT_VOICE_TX] = strdup("AFE_PCM_RX");
1245 hw_interface_table[SND_DEVICE_OUT_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
1246 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
jasmine cha52284622018-03-23 17:21:35 +08001247 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = strdup("SLIMBUS_0_RX");
1248 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_BT_SCO] = strdup("SLIMBUS_0_RX-and-SEC_AUX_PCM_RX");
1249 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB] = strdup("SLIMBUS_0_RX-and-SEC_AUX_PCM_RX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001250 hw_interface_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1251 hw_interface_table[SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1252 hw_interface_table[SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = strdup("USB_AUDIO_TX");
1253 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1254 hw_interface_table[SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1255 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = strdup("USB_AUDIO_TX");
1256 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = strdup("USB_AUDIO_TX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001257 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001258 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_AEC] = strdup("SLIMBUS_0_TX");
1259 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_NS] = strdup("SLIMBUS_0_TX");
1260 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1261 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC] = strdup("SLIMBUS_0_TX");
1262 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_AEC] = strdup("SLIMBUS_0_TX");
1263 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_NS] = strdup("SLIMBUS_0_TX");
1264 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1265 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001266 hw_interface_table[SND_DEVICE_IN_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001267 hw_interface_table[SND_DEVICE_IN_HEADSET_MIC_AEC] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001268 hw_interface_table[SND_DEVICE_IN_CAMCORDER_MIC] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001269 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC] = strdup("SLIMBUS_0_TX");
1270 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC_NS] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001271 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC_AEC] = strdup("SLIMBUS_0_TX");
1272 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001273 hw_interface_table[SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
1274 hw_interface_table[SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = strdup("SLIMBUS_0_TX");
David Lin93725722017-10-13 14:58:17 -07001275 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_MIC] = strdup("SLIMBUS_0_TX");
1276 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1277 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = strdup("SLIMBUS_0_TX");
1278 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = strdup("SLIMBUS_0_TX");
1279 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001280 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC] = strdup("SLIMBUS_0_TX");
1281 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_AEC] = strdup("SLIMBUS_0_TX");
1282 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_NS] = strdup("SLIMBUS_0_TX");
1283 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1284 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC] = strdup("SLIMBUS_0_TX");
1285 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_AEC] = strdup("SLIMBUS_0_TX");
1286 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_NS] = strdup("SLIMBUS_0_TX");
1287 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001288 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
1289 hw_interface_table[SND_DEVICE_IN_VOICE_DMIC] = strdup("SLIMBUS_0_TX");
1290 hw_interface_table[SND_DEVICE_IN_VOICE_DMIC_TMUS] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001291 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001292 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = strdup("SLIMBUS_0_TX");
1293 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001294 hw_interface_table[SND_DEVICE_IN_VOICE_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001295 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1296 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = strdup("SLIMBUS_0_TX");
1297 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1298 hw_interface_table[SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1299 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("SEC_AUX_PCM_TX");
1300 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("SEC_AUX_PCM_TX");
1301 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("SEC_AUX_PCM_TX");
1302 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("SEC_AUX_PCM_TX");
1303 hw_interface_table[SND_DEVICE_IN_VOICE_RX] = strdup("AFE_PCM_TX");
1304 hw_interface_table[SND_DEVICE_IN_THREE_MIC] = strdup("SLIMBUS_0_TX");
1305 hw_interface_table[SND_DEVICE_IN_QUAD_MIC] = strdup("SLIMBUS_0_TX");
1306 hw_interface_table[SND_DEVICE_IN_HANDSET_TMIC] = strdup("SLIMBUS_0_TX");
1307 hw_interface_table[SND_DEVICE_IN_HANDSET_QMIC] = strdup("SLIMBUS_0_TX");
1308 hw_interface_table[SND_DEVICE_IN_HANDSET_TMIC_AEC] = strdup("SLIMBUS_0_TX");
1309 hw_interface_table[SND_DEVICE_IN_HANDSET_QMIC_AEC] = strdup("SLIMBUS_0_TX");
Eric Laurentc6333382015-09-14 12:43:44 -07001310 my_data->max_mic_count = PLATFORM_DEFAULT_MIC_COUNT;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001311}
1312
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001313void get_cvd_version(char *cvd_version, struct audio_device *adev)
1314{
1315 struct mixer_ctl *ctl;
1316 int count;
1317 int ret = 0;
1318
1319 ctl = mixer_get_ctl_by_name(adev->mixer, CVD_VERSION_MIXER_CTL);
1320 if (!ctl) {
1321 ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__, CVD_VERSION_MIXER_CTL);
1322 goto done;
1323 }
1324 mixer_ctl_update(ctl);
1325
1326 count = mixer_ctl_get_num_values(ctl);
1327 if (count > MAX_CVD_VERSION_STRING_SIZE)
1328 count = MAX_CVD_VERSION_STRING_SIZE - 1;
1329
1330 ret = mixer_ctl_get_array(ctl, cvd_version, count);
1331 if (ret != 0) {
1332 ALOGE("%s: ERROR! mixer_ctl_get_array() failed to get CVD Version", __func__);
1333 goto done;
1334 }
1335
1336done:
1337 return;
1338}
1339
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001340static int platform_acdb_init(void *platform)
1341{
1342 struct platform_data *my_data = (struct platform_data *)platform;
1343 struct audio_device *adev = my_data->adev;
1344
1345 if (!my_data->acdb_init) {
1346 ALOGE("%s: no acdb_init fn provided", __func__);
1347 return -1;
1348 }
1349
1350 if (my_data->acdb_initialized) {
1351 ALOGW("acdb is already initialized");
1352 return 0;
1353 }
1354
Alexey Polyudove920d4b2017-09-15 17:09:07 -07001355#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001356 char *cvd_version = calloc(1, MAX_CVD_VERSION_STRING_SIZE);
1357 if (!cvd_version)
1358 ALOGE("failed to allocate cvd_version");
1359 else {
1360 get_cvd_version(cvd_version, adev);
1361 my_data->acdb_init((char *)my_data->snd_card_name, cvd_version, 0);
1362 free(cvd_version);
1363 }
1364#elif defined (PLATFORM_MSM8084)
1365 my_data->acdb_init((char *)my_data->snd_card_name);
1366#else
1367 my_data->acdb_init();
1368#endif
1369 my_data->acdb_initialized = true;
1370 return 0;
1371}
1372
David Linee3fe402017-03-13 10:00:42 -07001373static void
1374platform_backend_config_init(struct platform_data *pdata)
1375{
1376 int i;
1377
1378 /* initialize backend config */
1379 for (i = 0; i < MAX_CODEC_BACKENDS; i++) {
1380 pdata->current_backend_cfg[i].sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
1381 pdata->current_backend_cfg[i].bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
1382 pdata->current_backend_cfg[i].channels = CODEC_BACKEND_DEFAULT_CHANNELS;
1383
1384 if (i > MAX_RX_CODEC_BACKENDS)
1385 pdata->current_backend_cfg[i].channels = CODEC_BACKEND_DEFAULT_TX_CHANNELS;
1386
1387 pdata->current_backend_cfg[i].bitwidth_mixer_ctl = NULL;
1388 pdata->current_backend_cfg[i].samplerate_mixer_ctl = NULL;
1389 pdata->current_backend_cfg[i].channels_mixer_ctl = NULL;
1390 }
1391
1392 pdata->current_backend_cfg[DEFAULT_CODEC_BACKEND].bitwidth_mixer_ctl =
1393 strdup("SLIM_0_RX Format");
1394 pdata->current_backend_cfg[DEFAULT_CODEC_BACKEND].samplerate_mixer_ctl =
1395 strdup("SLIM_0_RX SampleRate");
1396
1397 pdata->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].bitwidth_mixer_ctl =
1398 strdup("SLIM_0_TX Format");
1399 pdata->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].samplerate_mixer_ctl =
1400 strdup("SLIM_0_TX SampleRate");
1401
1402 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].bitwidth_mixer_ctl =
1403 strdup("USB_AUDIO_TX Format");
1404 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].samplerate_mixer_ctl =
1405 strdup("USB_AUDIO_TX SampleRate");
1406 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].channels_mixer_ctl =
1407 strdup("USB_AUDIO_TX Channels");
1408
1409 pdata->current_backend_cfg[HEADPHONE_BACKEND].bitwidth_mixer_ctl =
1410 strdup("SLIM_6_RX Format");
1411 pdata->current_backend_cfg[HEADPHONE_BACKEND].samplerate_mixer_ctl =
1412 strdup("SLIM_6_RX SampleRate");
1413
1414 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].bitwidth_mixer_ctl =
1415 strdup("USB_AUDIO_RX Format");
1416 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].samplerate_mixer_ctl =
1417 strdup("USB_AUDIO_RX SampleRate");
1418
1419 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].channels = 1;
1420 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].channels_mixer_ctl =
1421 strdup("USB_AUDIO_RX Channels");
1422}
1423
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001424static int
1425platform_backend_app_type_cfg_init(struct platform_data *pdata,
1426 struct mixer *mixer)
1427{
1428 size_t app_type_cfg[128] = {0};
1429 int length, num_app_types = 0;
1430 struct mixer_ctl *ctl = NULL;
1431
1432 const char *mixer_ctl_name = "App Type Config";
1433 ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name);
1434 if (!ctl) {
1435 ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name);
1436 return -1;
1437 }
1438
1439 length = 1; // reserve index 0 for number of app types
1440
1441 struct listnode *node;
1442 struct app_type_entry *entry;
1443 list_for_each(node, &app_type_entry_list) {
1444 entry = node_to_item(node, struct app_type_entry, node);
1445 app_type_cfg[length++] = entry->app_type;
1446 app_type_cfg[length++] = entry->max_rate;
1447 app_type_cfg[length++] = entry->bit_width;
1448 ALOGI("%s add entry %d %d", __func__, entry->app_type, entry->bit_width);
1449 num_app_types += 1;
1450 }
1451
1452 // default for capture
1453 int t;
1454 platform_get_default_app_type_v2(pdata,
1455 PCM_CAPTURE,
1456 &t);
1457 app_type_cfg[length++] = t;
1458 app_type_cfg[length++] = 48000;
1459 app_type_cfg[length++] = 16;
1460 num_app_types += 1;
1461
1462 if (num_app_types) {
1463 app_type_cfg[0] = num_app_types;
1464 if (mixer_ctl_set_array(ctl, app_type_cfg, length) < 0) {
1465 ALOGE("Failed to set app type cfg");
1466 }
1467 }
1468 return 0;
1469}
1470
Xu Han1638fd12018-04-20 12:42:23 -07001471static void configure_flicker_sensor_input(struct mixer *mixer)
1472{
1473 struct mixer_ctl *ctl;
1474 const char* ctl1 = "AIF3_CAP Mixer SLIM TX2";
1475 int setting1 = 1;
1476 const char* ctl2 = "CDC_IF TX2 MUX";
1477 const char* setting2 = "DEC2";
1478 const char* ctl3 = "SLIM_1_TX Channels";
1479 const char* setting3 = "One";
1480 const char* ctl4 = "ADC MUX2";
1481 const char* setting4 = "AMIC";
1482 const char* ctl5 = "AMIC MUX2";
1483 const char* setting5 = "ADC1";
1484 const char* ctl6 = "DEC2 Volume";
1485 int setting6 = 84;
1486 const char* ctl7 = "MultiMedia2 Mixer SLIM_1_TX";
1487 int setting7 = 1;
1488 const char* ctl8 = "SLIM_1_TX SampleRate";
1489 const char* setting8 = "KHZ_8";
1490
1491 ctl = mixer_get_ctl_by_name(mixer, ctl1);
1492 mixer_ctl_set_value(ctl, 0, setting1);
1493 ctl = mixer_get_ctl_by_name(mixer, ctl2);
1494 mixer_ctl_set_enum_by_string(ctl, setting2);
1495 ctl = mixer_get_ctl_by_name(mixer, ctl3);
1496 mixer_ctl_set_enum_by_string(ctl, setting3);
1497 ctl = mixer_get_ctl_by_name(mixer, ctl4);
1498 mixer_ctl_set_enum_by_string(ctl, setting4);
1499 ctl = mixer_get_ctl_by_name(mixer, ctl5);
1500 mixer_ctl_set_enum_by_string(ctl, setting5);
1501 ctl = mixer_get_ctl_by_name(mixer, ctl6);
1502 mixer_ctl_set_value(ctl, 0, setting6);
1503 ctl = mixer_get_ctl_by_name(mixer, ctl7);
1504 mixer_ctl_set_value(ctl, 0, setting7);
1505 ctl = mixer_get_ctl_by_name(mixer, ctl8);
1506 mixer_ctl_set_enum_by_string(ctl, setting8);
1507}
1508
Eric Laurentb23d5282013-05-14 15:27:20 -07001509void *platform_init(struct audio_device *adev)
1510{
1511 char value[PROPERTY_VALUE_MAX];
vivek mehta60ea4152016-02-18 17:10:26 -08001512 struct platform_data *my_data = NULL;
1513 int retry_num = 0, snd_card_num = 0, key = 0, ret = 0;
1514 bool dual_mic_config = false, use_default_mixer_path = true;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001515 const char *snd_card_name;
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001516 char *cvd_version = NULL;
vivek mehta60ea4152016-02-18 17:10:26 -08001517 char *snd_internal_name = NULL;
1518 char *tmp = NULL;
1519 char mixer_xml_file[MIXER_PATH_MAX_LENGTH]= {0};
vivek mehtade4849c2016-03-03 17:23:38 -08001520 char platform_info_file[MIXER_PATH_MAX_LENGTH]= {0};
1521 struct snd_card_split *snd_split_handle = NULL;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001522 my_data = calloc(1, sizeof(struct platform_data));
1523
1524 my_data->adev = adev;
1525
keunhui.park2f7306a2015-07-16 16:48:06 +09001526 list_init(&operator_info_list);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001527 list_init(&app_type_entry_list);
keunhui.park2f7306a2015-07-16 16:48:06 +09001528
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001529 set_platform_defaults(my_data);
1530
vivek mehta0fb11312017-05-15 19:35:32 -07001531 // audio_extn_utils_get_snd_card_num does
1532 // - open mixer and get snd card name
1533 // - parse platform info xml file and check for valid snd card name
1534 // - on failure loop through all the active snd card
sangwoo1b9f4b32013-06-21 18:22:55 -07001535
vivek mehta0fb11312017-05-15 19:35:32 -07001536 snd_card_num = audio_extn_utils_get_snd_card_num();
1537 if (-1 == snd_card_num) {
1538 ALOGE("%s: invalid sound card number (-1), bailing out ", __func__);
1539 goto init_failed;
sangwoo1b9f4b32013-06-21 18:22:55 -07001540 }
1541
vivek mehta0fb11312017-05-15 19:35:32 -07001542 adev->mixer = mixer_open(snd_card_num);
1543 snd_card_name = mixer_get_name(adev->mixer);
1544 my_data->hw_info = hw_info_init(snd_card_name);
1545
1546 audio_extn_set_snd_card_split(snd_card_name);
1547 snd_split_handle = audio_extn_get_snd_card_split();
1548
1549 /* Get the codec internal name from the sound card and/or form factor
1550 * name and form the mixer paths and platfor info file name dynamically.
1551 * This is generic way of picking any codec and forma factor name based
1552 * mixer and platform info files in future with no code change.
1553
1554 * current code extends and looks for any of the exteneded mixer path and
1555 * platform info file present based on codec and form factor.
1556
1557 * order of picking appropriate file is
1558 * <i> mixer_paths_<codec_name>_<form_factor>.xml, if file not present
1559 * <ii> mixer_paths_<codec_name>.xml, if file not present
1560 * <iii> mixer_paths.xml
1561
1562 * same order is followed for audio_platform_info.xml as well
1563 */
1564
1565 // need to carryforward old file name
1566 if (!strncmp(snd_card_name, TOMTOM_8226_SND_CARD_NAME,
1567 min(strlen(TOMTOM_8226_SND_CARD_NAME), strlen(snd_card_name)))) {
1568 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1569 MIXER_XML_BASE_STRING, TOMTOM_MIXER_FILE_SUFFIX );
1570 } else {
1571
1572 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s_%s.xml",
1573 MIXER_XML_BASE_STRING, snd_split_handle->snd_card,
1574 snd_split_handle->form_factor);
1575 if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) {
1576 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1577 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1578 MIXER_XML_BASE_STRING, snd_split_handle->snd_card);
1579
1580 if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) {
1581 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1582 strlcpy(mixer_xml_file, MIXER_XML_DEFAULT_PATH, MIXER_PATH_MAX_LENGTH);
1583 audio_extn_utils_resolve_config_file(mixer_xml_file);
1584 }
1585 }
1586 }
1587
1588 audio_extn_utils_get_platform_info(snd_card_name, platform_info_file);
1589
jiabin8962a4d2018-03-19 18:21:24 -07001590 my_data->declared_mic_count = 0;
vivek mehta0fb11312017-05-15 19:35:32 -07001591 /* Initialize platform specific ids and/or backends*/
1592 platform_info_init(platform_info_file, my_data);
1593
1594 ALOGD("%s: Loading mixer file: %s", __func__, mixer_xml_file);
1595 adev->audio_route = audio_route_init(snd_card_num, mixer_xml_file);
1596
1597 if (!adev->audio_route) {
1598 ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
1599 mixer_close(adev->mixer);
1600 adev->mixer = NULL;
1601 hw_info_deinit(my_data->hw_info);
1602 my_data->hw_info = NULL;
1603 goto init_failed;
1604 }
1605 adev->snd_card = snd_card_num;
1606 ALOGD("%s: Opened sound card:%d", __func__, snd_card_num);
1607
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09001608 //set max volume step for voice call
1609 property_get("ro.config.vc_call_vol_steps", value, TOSTRING(MAX_VOL_INDEX));
1610 my_data->max_vol_index = atoi(value);
1611
vivek mehta65ad12d2015-08-13 18:32:48 -07001612 property_get("persist.audio.dualmic.config",value,"");
1613 if (!strcmp("endfire", value)) {
1614 dual_mic_config = true;
1615 }
1616
John Muir9e59a962018-01-10 13:30:00 -08001617 my_data->source_mic_type = 0;
Prashant Malanic92c5962015-08-11 15:10:18 -07001618
Eric Laurentb23d5282013-05-14 15:27:20 -07001619 my_data->fluence_in_spkr_mode = false;
1620 my_data->fluence_in_voice_call = false;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001621 my_data->fluence_in_voice_comm = false;
Eric Laurentb23d5282013-05-14 15:27:20 -07001622 my_data->fluence_in_voice_rec = false;
1623
vivek mehta65ad12d2015-08-13 18:32:48 -07001624 property_get("ro.qc.sdk.audio.fluencetype", value, "none");
Prashant Malanic92c5962015-08-11 15:10:18 -07001625 if (!strcmp("fluencepro", value)) {
1626 my_data->fluence_type = FLUENCE_PRO_ENABLE;
vivek mehta65ad12d2015-08-13 18:32:48 -07001627 } else if (!strcmp("fluence", value) || (dual_mic_config)) {
Prashant Malanic92c5962015-08-11 15:10:18 -07001628 my_data->fluence_type = FLUENCE_ENABLE;
1629 } else if (!strcmp("none", value)) {
1630 my_data->fluence_type = FLUENCE_DISABLE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001631 }
1632
Prashant Malanic92c5962015-08-11 15:10:18 -07001633 if (my_data->fluence_type != FLUENCE_DISABLE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001634 property_get("persist.audio.fluence.voicecall",value,"");
1635 if (!strcmp("true", value)) {
1636 my_data->fluence_in_voice_call = true;
1637 }
1638
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001639 property_get("persist.audio.fluence.voicecomm",value,"");
1640 if (!strcmp("true", value)) {
1641 my_data->fluence_in_voice_comm = true;
1642 }
1643
Eric Laurentb23d5282013-05-14 15:27:20 -07001644 property_get("persist.audio.fluence.voicerec",value,"");
1645 if (!strcmp("true", value)) {
1646 my_data->fluence_in_voice_rec = true;
1647 }
1648
1649 property_get("persist.audio.fluence.speaker",value,"");
1650 if (!strcmp("true", value)) {
1651 my_data->fluence_in_spkr_mode = true;
1652 }
1653 }
1654
Prashant Malanic92c5962015-08-11 15:10:18 -07001655 // support max to mono, example if max count is 3, usecase supports Three, dual and mono mic
1656 switch (my_data->max_mic_count) {
1657 case 4:
1658 my_data->source_mic_type |= SOURCE_QUAD_MIC;
1659 case 3:
1660 my_data->source_mic_type |= SOURCE_THREE_MIC;
1661 case 2:
1662 my_data->source_mic_type |= SOURCE_DUAL_MIC;
1663 case 1:
1664 my_data->source_mic_type |= SOURCE_MONO_MIC;
1665 break;
1666 default:
1667 ALOGE("%s: max_mic_count (%d), is not supported, setting to default",
1668 __func__, my_data->max_mic_count);
1669 my_data->source_mic_type = SOURCE_MONO_MIC|SOURCE_DUAL_MIC;
1670 break;
1671 }
1672
1673 ALOGV("%s: Fluence_Type(%d) max_mic_count(%d) mic_type(0x%x) fluence_in_voice_call(%d)"
1674 " fluence_in_voice_comm(%d) fluence_in_voice_rec(%d) fluence_in_spkr_mode(%d) ",
1675 __func__, my_data->fluence_type, my_data->max_mic_count, my_data->source_mic_type,
1676 my_data->fluence_in_voice_call, my_data->fluence_in_voice_comm,
1677 my_data->fluence_in_voice_rec, my_data->fluence_in_spkr_mode);
1678
Eric Laurentb23d5282013-05-14 15:27:20 -07001679 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
1680 if (my_data->acdb_handle == NULL) {
1681 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
1682 } else {
1683 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
1684 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
1685 "acdb_loader_deallocate_ACDB");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001686 if (!my_data->acdb_deallocate)
1687 ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s",
1688 __func__, LIB_ACDB_LOADER);
1689
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001690 my_data->acdb_send_audio_cal_v3 = (acdb_send_audio_cal_v3_t)dlsym(my_data->acdb_handle,
1691 "acdb_loader_send_audio_cal_v3");
1692 if (!my_data->acdb_send_audio_cal_v3)
1693 ALOGE("%s: Could not find the symbol acdb_send_audio_cal_v3 from %s",
1694 __func__, LIB_ACDB_LOADER);
1695
Eric Laurentb23d5282013-05-14 15:27:20 -07001696 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
1697 "acdb_loader_send_audio_cal");
1698 if (!my_data->acdb_send_audio_cal)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001699 ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s",
Eric Laurentb23d5282013-05-14 15:27:20 -07001700 __func__, LIB_ACDB_LOADER);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001701
Eric Laurentb23d5282013-05-14 15:27:20 -07001702 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
1703 "acdb_loader_send_voice_cal");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001704 if (!my_data->acdb_send_voice_cal)
1705 ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s",
1706 __func__, LIB_ACDB_LOADER);
1707
1708 my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle,
1709 "acdb_loader_reload_vocvoltable");
1710 if (!my_data->acdb_reload_vocvoltable)
1711 ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s",
1712 __func__, LIB_ACDB_LOADER);
vivek mehta1a9b7c02015-06-25 11:49:38 -07001713
1714 my_data->acdb_send_gain_dep_cal = (acdb_send_gain_dep_cal_t)dlsym(my_data->acdb_handle,
1715 "acdb_loader_send_gain_dep_cal");
1716 if (!my_data->acdb_send_gain_dep_cal)
1717 ALOGV("%s: Could not find the symbol acdb_loader_send_gain_dep_cal from %s",
1718 __func__, LIB_ACDB_LOADER);
1719
Xu Han1638fd12018-04-20 12:42:23 -07001720#if defined (FLICKER_SENSOR_INPUT)
1721 configure_flicker_sensor_input(adev->mixer);
1722#endif
1723
Alexey Polyudove920d4b2017-09-15 17:09:07 -07001724#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845)
vivek mehta0fb11312017-05-15 19:35:32 -07001725 acdb_init_v2_cvd_t acdb_init_local;
1726 acdb_init_local = (acdb_init_v2_cvd_t)dlsym(my_data->acdb_handle,
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001727 "acdb_loader_init_v2");
vivek mehta0fb11312017-05-15 19:35:32 -07001728 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001729 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1730 dlerror());
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001731
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001732#elif defined (PLATFORM_MSM8084)
vivek mehta0fb11312017-05-15 19:35:32 -07001733 acdb_init_v2_t acdb_init_local;
1734 acdb_init_local = (acdb_init_v2_t)dlsym(my_data->acdb_handle,
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001735 "acdb_loader_init_v2");
vivek mehta0fb11312017-05-15 19:35:32 -07001736 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001737 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1738 dlerror());
1739
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001740#else
vivek mehta0fb11312017-05-15 19:35:32 -07001741 acdb_init_t acdb_init_local;
1742 acdb_init_local = (acdb_init_t)dlsym(my_data->acdb_handle,
Eric Laurentb23d5282013-05-14 15:27:20 -07001743 "acdb_loader_init_ACDB");
vivek mehta0fb11312017-05-15 19:35:32 -07001744 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001745 ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__,
1746 dlerror());
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001747#endif
vivek mehta0fb11312017-05-15 19:35:32 -07001748 my_data->acdb_init = acdb_init_local;
Eric Laurentb23d5282013-05-14 15:27:20 -07001749
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001750 my_data->acdb_send_custom_top = (acdb_send_custom_top_t)
1751 dlsym(my_data->acdb_handle,
1752 "acdb_loader_send_common_custom_topology");
1753
1754 if (!my_data->acdb_send_custom_top)
1755 ALOGE("%s: Could not find the symbol acdb_get_default_app_type from %s",
1756 __func__, LIB_ACDB_LOADER);
1757
jasmine chac89321b2018-04-10 21:37:01 +08001758 my_data->acdb_set_audio_cal = (acdb_set_audio_cal_t)dlsym(my_data->acdb_handle,
1759 "acdb_loader_set_audio_cal_v2");
1760 if (!my_data->acdb_set_audio_cal)
1761 ALOGE("%s: Could not find the symbol acdb_set_audio_cal_v2 from %s",
1762 __func__, LIB_ACDB_LOADER);
1763
vivek mehta0fb11312017-05-15 19:35:32 -07001764 int result = acdb_init(adev->snd_card);
1765 if (!result) {
1766 my_data->acdb_initialized = true;
1767 ALOGD("ACDB initialized");
1768 } else {
1769 my_data->acdb_initialized = false;
1770 ALOGD("ACDB initialization failed");
1771 }
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001772 }
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001773
David Linee3fe402017-03-13 10:00:42 -07001774 /* init usb */
1775 audio_extn_usb_init(adev);
1776
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001777 /* init a2dp */
1778 audio_extn_a2dp_init(adev);
1779
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001780 audio_extn_spkr_prot_init(adev);
Haynes Mathew George98c95622014-06-20 19:14:25 -07001781
Ravi Kumar Alamanda76315572015-04-23 13:13:56 -07001782 audio_extn_hwdep_cal_send(adev->snd_card, my_data->acdb_handle);
1783
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001784 /* load csd client */
1785 platform_csd_init(my_data);
1786
David Linee3fe402017-03-13 10:00:42 -07001787 platform_backend_config_init(my_data);
1788
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001789 init_be_dai_name_table(adev);
1790
1791 if (platform_supports_app_type_cfg())
1792 platform_backend_app_type_cfg_init(my_data, adev->mixer);
1793
Eric Laurentb23d5282013-05-14 15:27:20 -07001794 return my_data;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001795
1796init_failed:
1797 if (my_data)
1798 free(my_data);
1799 return NULL;
Eric Laurentb23d5282013-05-14 15:27:20 -07001800}
1801
1802void platform_deinit(void *platform)
1803{
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001804 int32_t dev;
keunhui.park2f7306a2015-07-16 16:48:06 +09001805 struct operator_info *info_item;
1806 struct operator_specific_device *device_item;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001807 struct app_type_entry *ap;
keunhui.park2f7306a2015-07-16 16:48:06 +09001808 struct listnode *node;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001809
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001810 struct platform_data *my_data = (struct platform_data *)platform;
1811 close_csd_client(my_data->csd);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001812
vivek mehtade4849c2016-03-03 17:23:38 -08001813 hw_info_deinit(my_data->hw_info);
1814
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001815 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1816 if (backend_tag_table[dev])
1817 free(backend_tag_table[dev]);
1818 if (hw_interface_table[dev])
1819 free(hw_interface_table[dev]);
keunhui.park2f7306a2015-07-16 16:48:06 +09001820 if (operator_specific_device_table[dev]) {
1821 while (!list_empty(operator_specific_device_table[dev])) {
1822 node = list_head(operator_specific_device_table[dev]);
1823 list_remove(node);
1824 device_item = node_to_item(node, struct operator_specific_device, list);
1825 free(device_item->operator);
1826 free(device_item->mixer_path);
1827 free(device_item);
1828 }
1829 free(operator_specific_device_table[dev]);
1830 }
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001831 }
1832
1833 if (my_data->snd_card_name)
1834 free(my_data->snd_card_name);
1835
keunhui.park2f7306a2015-07-16 16:48:06 +09001836 while (!list_empty(&operator_info_list)) {
1837 node = list_head(&operator_info_list);
1838 list_remove(node);
1839 info_item = node_to_item(node, struct operator_info, list);
1840 free(info_item->name);
1841 free(info_item->mccmnc);
1842 free(info_item);
1843 }
1844
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001845 while (!list_empty(&app_type_entry_list)) {
1846 node = list_head(&app_type_entry_list);
1847 list_remove(node);
1848 ap = node_to_item(node, struct app_type_entry, node);
vivek mehtaa68fea62017-06-08 19:04:02 -07001849 if (ap->mode) free(ap->mode);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001850 free(ap);
1851 }
1852
Kevin Rocarde35d4af2017-05-02 16:55:28 -07001853 mixer_close(my_data->adev->mixer);
Eric Laurentb23d5282013-05-14 15:27:20 -07001854 free(platform);
David Linee3fe402017-03-13 10:00:42 -07001855
1856 /* deinit usb */
1857 audio_extn_usb_deinit();
Eric Laurentb23d5282013-05-14 15:27:20 -07001858}
1859
1860const char *platform_get_snd_device_name(snd_device_t snd_device)
1861{
keunhui.park2f7306a2015-07-16 16:48:06 +09001862 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1863 if (operator_specific_device_table[snd_device] != NULL) {
1864 return get_operator_specific_device_mixer_path(snd_device);
1865 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001866 return device_table[snd_device];
keunhui.park2f7306a2015-07-16 16:48:06 +09001867 } else
Ravi Kumar Alamanda64026462014-09-15 00:08:58 -07001868 return "none";
Eric Laurentb23d5282013-05-14 15:27:20 -07001869}
1870
vivek mehtade4849c2016-03-03 17:23:38 -08001871int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
1872 char *device_name)
1873{
1874 struct platform_data *my_data = (struct platform_data *)platform;
1875
David Benjamin1565f992016-09-21 12:10:34 -04001876 if (platform == NULL) {
vivek mehtade4849c2016-03-03 17:23:38 -08001877 ALOGW("%s: something wrong, use legacy get_snd_device name", __func__);
David Benjamin1565f992016-09-21 12:10:34 -04001878 strlcpy(device_name, platform_get_snd_device_name(snd_device),
1879 DEVICE_NAME_MAX_SIZE);
vivek mehtade4849c2016-03-03 17:23:38 -08001880 } else if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1881 if (operator_specific_device_table[snd_device] != NULL) {
1882 strlcpy(device_name, get_operator_specific_device_mixer_path(snd_device),
1883 DEVICE_NAME_MAX_SIZE);
1884 } else {
1885 strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE);
1886 }
1887 hw_info_append_hw_type(my_data->hw_info, snd_device, device_name);
1888 } else {
1889 strlcpy(device_name, "none", DEVICE_NAME_MAX_SIZE);
1890 }
1891
1892 return 0;
1893}
1894
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001895void platform_add_backend_name(void *platform, char *mixer_path,
1896 snd_device_t snd_device)
Eric Laurentb23d5282013-05-14 15:27:20 -07001897{
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001898 struct platform_data *my_data = (struct platform_data *)platform;
1899
Haynes Mathew George98c95622014-06-20 19:14:25 -07001900 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1901 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1902 return;
Ravi Kumar Alamanda1de6e5a2014-06-19 21:55:39 -05001903 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001904
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001905 const char * suffix = backend_tag_table[snd_device];
Haynes Mathew George98c95622014-06-20 19:14:25 -07001906
1907 if (suffix != NULL) {
1908 strcat(mixer_path, " ");
1909 strcat(mixer_path, suffix);
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001910 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001911}
1912
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001913bool platform_check_backends_match(snd_device_t snd_device1, snd_device_t snd_device2)
1914{
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001915 ALOGV("%s: snd_device1 = %s, snd_device2 = %s", __func__,
1916 platform_get_snd_device_name(snd_device1),
1917 platform_get_snd_device_name(snd_device2));
1918
1919 if ((snd_device1 < SND_DEVICE_MIN) || (snd_device1 >= SND_DEVICE_MAX)) {
1920 ALOGE("%s: Invalid snd_device = %s", __func__,
1921 platform_get_snd_device_name(snd_device1));
1922 return false;
1923 }
1924 if ((snd_device2 < SND_DEVICE_MIN) || (snd_device2 >= SND_DEVICE_MAX)) {
1925 ALOGE("%s: Invalid snd_device = %s", __func__,
1926 platform_get_snd_device_name(snd_device2));
1927 return false;
1928 }
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07001929
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001930 const char * be_itf1 = hw_interface_table[snd_device1];
1931 const char * be_itf2 = hw_interface_table[snd_device2];
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07001932 /*
1933 hw_interface_table has overrides for a snd_device.
1934 if there is no entry for a device, assume DEFAULT_RX_BACKEND
1935 */
1936 if (be_itf1 == NULL) {
1937 be_itf1 = DEFAULT_RX_BACKEND;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001938 }
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07001939 if (be_itf2 == NULL) {
1940 be_itf2 = DEFAULT_RX_BACKEND;
1941 }
1942 ALOGV("%s: be_itf1 = %s, be_itf2 = %s", __func__, be_itf1, be_itf2);
1943 /*
1944 this takes care of finding a device within a combo device pair as well
1945 */
1946 return strstr(be_itf1, be_itf2) != NULL || strstr(be_itf2, be_itf1) != NULL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001947}
1948
Eric Laurentb23d5282013-05-14 15:27:20 -07001949int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
1950{
1951 int device_id;
1952 if (device_type == PCM_PLAYBACK)
1953 device_id = pcm_device_table[usecase][0];
1954 else
1955 device_id = pcm_device_table[usecase][1];
1956 return device_id;
1957}
1958
Haynes Mathew George98c95622014-06-20 19:14:25 -07001959static int find_index(const struct name_to_index * table, int32_t len,
1960 const char * name)
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001961{
1962 int ret = 0;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001963 int32_t i;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001964
Haynes Mathew George98c95622014-06-20 19:14:25 -07001965 if (table == NULL) {
1966 ALOGE("%s: table is NULL", __func__);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001967 ret = -ENODEV;
1968 goto done;
1969 }
1970
Haynes Mathew George98c95622014-06-20 19:14:25 -07001971 if (name == NULL) {
1972 ALOGE("null key");
1973 ret = -ENODEV;
1974 goto done;
1975 }
1976
1977 for (i=0; i < len; i++) {
1978 if (!strcmp(table[i].name, name)) {
1979 ret = table[i].index;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001980 goto done;
1981 }
1982 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001983 ALOGE("%s: Could not find index for name = %s",
1984 __func__, name);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001985 ret = -ENODEV;
1986done:
1987 return ret;
1988}
1989
Haynes Mathew George98c95622014-06-20 19:14:25 -07001990int platform_get_snd_device_index(char *device_name)
1991{
1992 return find_index(snd_device_name_index, SND_DEVICE_MAX, device_name);
1993}
1994
1995int platform_get_usecase_index(const char *usecase_name)
1996{
1997 return find_index(usecase_name_index, AUDIO_USECASE_MAX, usecase_name);
1998}
1999
keunhui.park2f7306a2015-07-16 16:48:06 +09002000void platform_add_operator_specific_device(snd_device_t snd_device,
2001 const char *operator,
2002 const char *mixer_path,
2003 unsigned int acdb_id)
2004{
2005 struct operator_specific_device *device;
2006
2007 if (operator_specific_device_table[snd_device] == NULL) {
2008 operator_specific_device_table[snd_device] =
2009 (struct listnode *)calloc(1, sizeof(struct listnode));
2010 list_init(operator_specific_device_table[snd_device]);
2011 }
2012
2013 device = (struct operator_specific_device *)calloc(1, sizeof(struct operator_specific_device));
2014
2015 device->operator = strdup(operator);
2016 device->mixer_path = strdup(mixer_path);
2017 device->acdb_id = acdb_id;
2018
2019 list_add_tail(operator_specific_device_table[snd_device], &device->list);
2020
Eric Laurent2bafff12016-03-17 12:17:23 -07002021 ALOGD("%s: device[%s] -> operator[%s] mixer_path[%s] acdb_id[%d]", __func__,
keunhui.park2f7306a2015-07-16 16:48:06 +09002022 platform_get_snd_device_name(snd_device), operator, mixer_path, acdb_id);
2023
2024}
2025
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002026int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
2027{
2028 int ret = 0;
2029
2030 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
2031 ALOGE("%s: Invalid snd_device = %d",
2032 __func__, snd_device);
2033 ret = -EINVAL;
2034 goto done;
2035 }
2036
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002037 ALOGV("%s: acdb_device_table[%s]: old = %d new = %d", __func__,
2038 platform_get_snd_device_name(snd_device), acdb_device_table[snd_device], acdb_id);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002039 acdb_device_table[snd_device] = acdb_id;
2040done:
2041 return ret;
2042}
2043
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07002044int platform_get_snd_device_acdb_id(snd_device_t snd_device)
2045{
2046 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
2047 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
2048 return -EINVAL;
2049 }
keunhui.park2f7306a2015-07-16 16:48:06 +09002050
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002051 /*
2052 * If speaker protection is enabled, function returns supported
2053 * sound device for speaker. Else same sound device is returned.
2054 */
2055 snd_device = audio_extn_get_spkr_prot_snd_device(snd_device);
2056
keunhui.park2f7306a2015-07-16 16:48:06 +09002057 if (operator_specific_device_table[snd_device] != NULL)
2058 return get_operator_specific_device_acdb_id(snd_device);
2059 else
2060 return acdb_device_table[snd_device];
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07002061}
2062
David Linee3fe402017-03-13 10:00:42 -07002063static int platform_get_backend_index(snd_device_t snd_device)
2064{
2065 int32_t port = DEFAULT_CODEC_BACKEND;
2066
2067 if (snd_device >= SND_DEVICE_OUT_BEGIN && snd_device < SND_DEVICE_OUT_END) {
2068 if (backend_tag_table[snd_device] != NULL) {
2069 if (strncmp(backend_tag_table[snd_device], "headphones",
2070 sizeof("headphones")) == 0)
2071 port = HEADPHONE_BACKEND;
2072 else if (strcmp(backend_tag_table[snd_device], "hdmi") == 0)
2073 port = HDMI_RX_BACKEND;
2074 else if ((strcmp(backend_tag_table[snd_device], "usb-headphones") == 0) ||
2075 (strcmp(backend_tag_table[snd_device], "usb-headset") == 0))
2076 port = USB_AUDIO_RX_BACKEND;
2077 }
2078 } else if (snd_device >= SND_DEVICE_IN_BEGIN && snd_device < SND_DEVICE_IN_END) {
2079 port = DEFAULT_CODEC_TX_BACKEND;
2080 if (backend_tag_table[snd_device] != NULL) {
2081 if (strcmp(backend_tag_table[snd_device], "usb-headset-mic") == 0)
2082 port = USB_AUDIO_TX_BACKEND;
2083 else if (strstr(backend_tag_table[snd_device], "bt-sco") != NULL)
2084 port = BT_SCO_TX_BACKEND;
2085 }
2086 } else {
2087 ALOGW("%s:napb: Invalid device - %d ", __func__, snd_device);
2088 }
2089
2090 ALOGV("%s:napb: backend port - %d device - %d ", __func__, port, snd_device);
2091
2092 return port;
2093}
2094
Eric Laurentb23d5282013-05-14 15:27:20 -07002095int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
2096{
2097 struct platform_data *my_data = (struct platform_data *)platform;
2098 int acdb_dev_id, acdb_dev_type;
2099
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002100 if (platform_supports_app_type_cfg()) // use v2 instead
2101 return -ENOSYS;
2102
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002103 acdb_dev_id = platform_get_snd_device_acdb_id(snd_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07002104 if (acdb_dev_id < 0) {
2105 ALOGE("%s: Could not find acdb id for device(%d)",
2106 __func__, snd_device);
2107 return -EINVAL;
2108 }
2109 if (my_data->acdb_send_audio_cal) {
Joe Onorato188b6222016-03-01 11:02:27 -08002110 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Eric Laurentb23d5282013-05-14 15:27:20 -07002111 __func__, snd_device, acdb_dev_id);
2112 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
2113 snd_device < SND_DEVICE_OUT_END)
2114 acdb_dev_type = ACDB_DEV_TYPE_OUT;
2115 else
2116 acdb_dev_type = ACDB_DEV_TYPE_IN;
2117 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
2118 }
2119 return 0;
2120}
2121
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002122int platform_send_audio_calibration_v2(void *platform, struct audio_usecase *usecase,
2123 int app_type, int sample_rate)
2124{
2125 struct platform_data *my_data = (struct platform_data *)platform;
2126 int acdb_dev_id, acdb_dev_type;
vivek mehta7e573672018-03-13 17:41:41 -07002127 int snd_device = usecase->out_snd_device;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002128 int new_snd_device[SND_DEVICE_OUT_END] = {0};
2129 int i, num_devices = 1;
2130
2131 if (!platform_supports_app_type_cfg()) // use v1 instead
2132 return -ENOSYS;
2133
vivek mehta7e573672018-03-13 17:41:41 -07002134 if ((usecase->type == PCM_HFP_CALL) || (usecase->type == PCM_CAPTURE))
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002135 snd_device = usecase->in_snd_device;
2136
2137 // skipped over get_spkr_prot_device
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002138 acdb_dev_id = platform_get_snd_device_acdb_id(snd_device);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002139 if (acdb_dev_id < 0) {
2140 ALOGE("%s: Could not find acdb id for device(%d)",
2141 __func__, snd_device);
2142 return -EINVAL;
2143 }
2144
2145 if (platform_can_split_snd_device(snd_device,
2146 &num_devices, new_snd_device) < 0) {
2147 new_snd_device[0] = snd_device;
2148 }
2149
2150 for (i = 0; i < num_devices; i++) {
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002151 acdb_dev_id = platform_get_snd_device_acdb_id(new_snd_device[i]);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002152 if (acdb_dev_id < 0) {
2153 ALOGE("%s: Could not find acdb id for device(%d)",
2154 __func__, new_snd_device[i]);
2155 return -EINVAL;
2156 }
2157 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
2158 __func__, new_snd_device[i], acdb_dev_id);
2159 if (new_snd_device[i] >= SND_DEVICE_OUT_BEGIN &&
2160 new_snd_device[i] < SND_DEVICE_OUT_END)
2161 acdb_dev_type = ACDB_DEV_TYPE_OUT;
2162 else
2163 acdb_dev_type = ACDB_DEV_TYPE_IN;
2164
2165 if (my_data->acdb_send_audio_cal_v3) {
2166 my_data->acdb_send_audio_cal_v3(acdb_dev_id, acdb_dev_type,
2167 app_type, sample_rate, i);
2168 } else if (my_data->acdb_send_audio_cal) {
2169 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type); // this version differs from internal
2170 }
2171 }
2172
2173 return 0;
2174}
2175
2176
Eric Laurentb23d5282013-05-14 15:27:20 -07002177int platform_switch_voice_call_device_pre(void *platform)
2178{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002179 struct platform_data *my_data = (struct platform_data *)platform;
2180 int ret = 0;
2181
2182 if (my_data->csd != NULL &&
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002183 voice_is_in_call(my_data->adev)) {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002184 /* This must be called before disabling mixer controls on APQ side */
2185 ret = my_data->csd->disable_device();
2186 if (ret < 0) {
2187 ALOGE("%s: csd_client_disable_device, failed, error %d",
2188 __func__, ret);
2189 }
2190 }
2191 return ret;
2192}
2193
2194int platform_switch_voice_call_enable_device_config(void *platform,
2195 snd_device_t out_snd_device,
2196 snd_device_t in_snd_device)
2197{
2198 struct platform_data *my_data = (struct platform_data *)platform;
2199 int acdb_rx_id, acdb_tx_id;
2200 int ret = 0;
2201
2202 if (my_data->csd == NULL)
2203 return ret;
2204
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002205 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
keunhui.park2f7306a2015-07-16 16:48:06 +09002206 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002207
2208 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
2209 ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
2210 if (ret < 0) {
2211 ALOGE("%s: csd_enable_device_config, failed, error %d",
2212 __func__, ret);
2213 }
2214 } else {
2215 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2216 acdb_rx_id, acdb_tx_id);
2217 }
2218
2219 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002220}
2221
2222int platform_switch_voice_call_device_post(void *platform,
2223 snd_device_t out_snd_device,
2224 snd_device_t in_snd_device)
2225{
2226 struct platform_data *my_data = (struct platform_data *)platform;
2227 int acdb_rx_id, acdb_tx_id;
2228
2229 if (my_data->acdb_send_voice_cal == NULL) {
2230 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
2231 } else {
keunhui.park2f7306a2015-07-16 16:48:06 +09002232 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
2233 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07002234
2235 if (acdb_rx_id > 0 && acdb_tx_id > 0)
2236 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
2237 else
2238 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2239 acdb_rx_id, acdb_tx_id);
2240 }
2241
2242 return 0;
2243}
2244
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002245int platform_switch_voice_call_usecase_route_post(void *platform,
2246 snd_device_t out_snd_device,
2247 snd_device_t in_snd_device)
2248{
2249 struct platform_data *my_data = (struct platform_data *)platform;
2250 int acdb_rx_id, acdb_tx_id;
2251 int ret = 0;
2252
2253 if (my_data->csd == NULL)
2254 return ret;
2255
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002256 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
keunhui.park2f7306a2015-07-16 16:48:06 +09002257 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002258
2259 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
2260 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
2261 my_data->adev->acdb_settings);
2262 if (ret < 0) {
2263 ALOGE("%s: csd_enable_device, failed, error %d", __func__, ret);
2264 }
2265 } else {
2266 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2267 acdb_rx_id, acdb_tx_id);
2268 }
2269
2270 return ret;
2271}
2272
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002273int platform_start_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07002274{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002275 struct platform_data *my_data = (struct platform_data *)platform;
2276 int ret = 0;
2277
2278 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002279 ret = my_data->csd->start_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002280 if (ret < 0) {
2281 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
2282 }
2283 }
2284 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002285}
2286
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002287int platform_stop_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07002288{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002289 struct platform_data *my_data = (struct platform_data *)platform;
2290 int ret = 0;
2291
2292 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002293 ret = my_data->csd->stop_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002294 if (ret < 0) {
2295 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
2296 }
2297 }
2298 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002299}
2300
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002301int platform_get_sample_rate(void *platform, uint32_t *rate)
2302{
2303 struct platform_data *my_data = (struct platform_data *)platform;
2304 int ret = 0;
2305
2306 if (my_data->csd != NULL) {
2307 ret = my_data->csd->get_sample_rate(rate);
2308 if (ret < 0) {
2309 ALOGE("%s: csd_get_sample_rate error %d\n", __func__, ret);
2310 }
2311 }
2312 return ret;
2313}
2314
vivek mehtab6506412015-08-07 16:55:17 -07002315void platform_set_speaker_gain_in_combo(struct audio_device *adev,
2316 snd_device_t snd_device,
2317 bool enable)
2318{
2319 const char* name;
2320 switch (snd_device) {
2321 case SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES:
2322 if (enable)
2323 name = "spkr-gain-in-headphone-combo";
2324 else
2325 name = "speaker-gain-default";
2326 break;
2327 case SND_DEVICE_OUT_SPEAKER_AND_LINE:
2328 if (enable)
2329 name = "spkr-gain-in-line-combo";
2330 else
2331 name = "speaker-gain-default";
2332 break;
2333 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES:
2334 if (enable)
2335 name = "spkr-safe-gain-in-headphone-combo";
2336 else
2337 name = "speaker-safe-gain-default";
2338 break;
2339 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE:
2340 if (enable)
2341 name = "spkr-safe-gain-in-line-combo";
2342 else
2343 name = "speaker-safe-gain-default";
2344 break;
2345 default:
2346 return;
2347 }
2348
2349 audio_route_apply_and_update_path(adev->audio_route, name);
2350}
2351
Eric Laurentb23d5282013-05-14 15:27:20 -07002352int platform_set_voice_volume(void *platform, int volume)
2353{
2354 struct platform_data *my_data = (struct platform_data *)platform;
2355 struct audio_device *adev = my_data->adev;
2356 struct mixer_ctl *ctl;
sangwoo53b2cf02013-07-25 19:18:44 -07002357 const char *mixer_ctl_name = "Voice Rx Gain";
Nadav Barc46d0fa2017-12-24 14:50:37 +02002358 const char *mute_mixer_ctl_name = "Voice Rx Device Mute";
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002359 int vol_index = 0, ret = 0;
2360 uint32_t set_values[ ] = {0,
2361 ALL_SESSION_VSID,
2362 DEFAULT_VOLUME_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07002363
2364 // Voice volume levels are mapped to adsp volume levels as follows.
2365 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
2366 // But this values don't changed in kernel. So, below change is need.
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09002367 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, my_data->max_vol_index);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002368 set_values[0] = vol_index;
Eric Laurentb23d5282013-05-14 15:27:20 -07002369
2370 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 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002376 ALOGV("Setting voice volume index: %d", set_values[0]);
2377 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2378
Nadav Barc46d0fa2017-12-24 14:50:37 +02002379 // Send mute command in case volume index is max since indexes are inverted
2380 // for mixer controls.
2381 if (vol_index == my_data->max_vol_index) {
2382 set_values[0] = 1;
2383 }
2384 else {
2385 set_values[0] = 0;
2386 }
2387
2388 ctl = mixer_get_ctl_by_name(adev->mixer, mute_mixer_ctl_name);
2389 if (!ctl) {
2390 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2391 __func__, mute_mixer_ctl_name);
2392 return -EINVAL;
2393 }
2394 ALOGV("%s: Setting RX Device Mute to: %d", __func__, set_values[0]);
2395 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2396
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002397 if (my_data->csd != NULL) {
2398 ret = my_data->csd->volume(ALL_SESSION_VSID, volume,
2399 DEFAULT_VOLUME_RAMP_DURATION_MS);
2400 if (ret < 0) {
2401 ALOGE("%s: csd_volume error %d", __func__, ret);
2402 }
2403 }
2404 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002405}
2406
2407int platform_set_mic_mute(void *platform, bool state)
2408{
2409 struct platform_data *my_data = (struct platform_data *)platform;
2410 struct audio_device *adev = my_data->adev;
2411 struct mixer_ctl *ctl;
2412 const char *mixer_ctl_name = "Voice Tx Mute";
sangwoo53b2cf02013-07-25 19:18:44 -07002413 int ret = 0;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002414 uint32_t set_values[ ] = {0,
2415 ALL_SESSION_VSID,
2416 DEFAULT_MUTE_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07002417
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09002418 if (adev->mode != AUDIO_MODE_IN_CALL &&
2419 adev->mode != AUDIO_MODE_IN_COMMUNICATION)
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002420 return 0;
2421
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09002422 if (adev->enable_hfp)
2423 mixer_ctl_name = "HFP Tx Mute";
2424
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002425 set_values[0] = state;
2426 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2427 if (!ctl) {
2428 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2429 __func__, mixer_ctl_name);
2430 return -EINVAL;
2431 }
2432 ALOGV("Setting voice mute state: %d", state);
2433 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2434
2435 if (my_data->csd != NULL) {
2436 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state,
2437 DEFAULT_MUTE_RAMP_DURATION_MS);
sangwoo53b2cf02013-07-25 19:18:44 -07002438 if (ret < 0) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002439 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
sangwoo53b2cf02013-07-25 19:18:44 -07002440 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002441 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002442 return ret;
2443}
Eric Laurentb23d5282013-05-14 15:27:20 -07002444
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002445int platform_set_device_mute(void *platform, bool state, char *dir)
2446{
2447 struct platform_data *my_data = (struct platform_data *)platform;
2448 struct audio_device *adev = my_data->adev;
2449 struct mixer_ctl *ctl;
2450 char *mixer_ctl_name = NULL;
2451 int ret = 0;
2452 uint32_t set_values[ ] = {0,
2453 ALL_SESSION_VSID,
2454 0};
2455 if(dir == NULL) {
2456 ALOGE("%s: Invalid direction:%s", __func__, dir);
2457 return -EINVAL;
2458 }
2459
2460 if (!strncmp("rx", dir, sizeof("rx"))) {
2461 mixer_ctl_name = "Voice Rx Device Mute";
2462 } else if (!strncmp("tx", dir, sizeof("tx"))) {
2463 mixer_ctl_name = "Voice Tx Device Mute";
2464 } else {
2465 return -EINVAL;
2466 }
2467
2468 set_values[0] = state;
2469 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2470 if (!ctl) {
2471 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2472 __func__, mixer_ctl_name);
2473 return -EINVAL;
2474 }
2475
2476 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
2477 __func__,state, mixer_ctl_name);
2478 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2479
2480 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002481}
2482
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002483int platform_can_split_snd_device(snd_device_t snd_device,
2484 int *num_devices,
2485 snd_device_t *new_snd_devices)
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002486{
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002487 int ret = -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002488 if (NULL == num_devices || NULL == new_snd_devices) {
2489 ALOGE("%s: NULL pointer ..", __func__);
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002490 return -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002491 }
2492
2493 /*
2494 * If wired headset/headphones/line devices share the same backend
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002495 * with speaker/earpiece this routine returns -EINVAL.
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002496 */
2497 if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES &&
2498 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_HEADPHONES)) {
2499 *num_devices = 2;
2500 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2501 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002502 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002503 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_LINE &&
2504 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_LINE)) {
2505 *num_devices = 2;
2506 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2507 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002508 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002509 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES &&
2510 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_HEADPHONES)) {
2511 *num_devices = 2;
2512 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2513 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002514 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002515 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE &&
2516 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_LINE)) {
2517 *num_devices = 2;
2518 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2519 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002520 ret = 0;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002521 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO &&
2522 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2523 SND_DEVICE_OUT_BT_SCO)) {
2524 *num_devices = 2;
2525 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2526 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO;
2527 ret = 0;
2528 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB &&
2529 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2530 SND_DEVICE_OUT_BT_SCO_WB)) {
2531 *num_devices = 2;
2532 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2533 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO_WB;
2534 ret = 0;
David Linee3fe402017-03-13 10:00:42 -07002535 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET &&
2536 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_USB_HEADSET)) {
2537 *num_devices = 2;
2538 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2539 new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
2540 ret = 0;
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07002541 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET &&
2542 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_USB_HEADSET)) {
2543 *num_devices = 2;
2544 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2545 new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
2546 ret = 0;
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002547 } else if (SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP == snd_device &&
2548 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2549 SND_DEVICE_OUT_BT_A2DP)) {
2550 *num_devices = 2;
2551 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2552 new_snd_devices[1] = SND_DEVICE_OUT_BT_A2DP;
2553 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002554 }
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002555
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002556 return ret;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002557}
2558
Eric Laurentb23d5282013-05-14 15:27:20 -07002559snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
2560{
2561 struct platform_data *my_data = (struct platform_data *)platform;
2562 struct audio_device *adev = my_data->adev;
2563 audio_mode_t mode = adev->mode;
2564 snd_device_t snd_device = SND_DEVICE_NONE;
2565
2566 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
2567 if (devices == AUDIO_DEVICE_NONE ||
2568 devices & AUDIO_DEVICE_BIT_IN) {
2569 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
2570 goto exit;
2571 }
2572
Eric Laurent1b491552015-09-15 17:52:41 -07002573 if (popcount(devices) == 2) {
2574 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2575 AUDIO_DEVICE_OUT_SPEAKER) ||
2576 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2577 AUDIO_DEVICE_OUT_SPEAKER)) {
2578 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
2579 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2580 AUDIO_DEVICE_OUT_SPEAKER)) {
2581 snd_device = SND_DEVICE_OUT_SPEAKER_AND_LINE;
2582 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2583 AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
2584 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2585 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2586 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES;
2587 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2588 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2589 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE;
2590 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
2591 AUDIO_DEVICE_OUT_SPEAKER)) {
2592 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002593 } else if ((devices & AUDIO_DEVICE_OUT_ALL_SCO) &&
2594 ((devices & ~AUDIO_DEVICE_OUT_ALL_SCO) == AUDIO_DEVICE_OUT_SPEAKER)) {
2595 snd_device = adev->bt_wb_speech_enabled ?
2596 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB :
2597 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO;
Eric Laurent99dab492017-06-17 15:19:08 -07002598 } else if ((devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
2599 AUDIO_DEVICE_OUT_SPEAKER)) ||
2600 (devices == (AUDIO_DEVICE_OUT_USB_HEADSET |
2601 AUDIO_DEVICE_OUT_SPEAKER))) {
David Linee3fe402017-03-13 10:00:42 -07002602 snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET;
Eric Laurentd0f7c262017-07-05 09:09:12 -07002603 } else if ((devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
2604 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) ||
2605 (devices == (AUDIO_DEVICE_OUT_USB_HEADSET |
2606 AUDIO_DEVICE_OUT_SPEAKER_SAFE))) {
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07002607 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET;
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002608 } else if ((devices & AUDIO_DEVICE_OUT_SPEAKER) &&
2609 (devices & AUDIO_DEVICE_OUT_ALL_A2DP)) {
2610 snd_device = SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP;
Eric Laurent1b491552015-09-15 17:52:41 -07002611 } else {
2612 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
2613 goto exit;
2614 }
2615 if (snd_device != SND_DEVICE_NONE) {
2616 goto exit;
2617 }
2618 }
2619
2620 if (popcount(devices) != 1) {
2621 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
2622 goto exit;
2623 }
2624
Madhuri Athota3f6051b2016-10-13 23:25:38 +05302625 if (voice_is_in_call(adev) || adev->enable_voicerx || audio_extn_hfp_is_active(adev)) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002626 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002627 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2628 devices & AUDIO_DEVICE_OUT_LINE) {
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002629 if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002630 (adev->voice.tty_mode == TTY_MODE_FULL))
Eric Laurentb23d5282013-05-14 15:27:20 -07002631 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002632 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002633 (adev->voice.tty_mode == TTY_MODE_VCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002634 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002635 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002636 (adev->voice.tty_mode == TTY_MODE_HCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002637 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002638 else {
2639 if (devices & AUDIO_DEVICE_OUT_LINE)
2640 snd_device = SND_DEVICE_OUT_VOICE_LINE;
2641 else
2642 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
2643 }
Eric Laurent99dab492017-06-17 15:19:08 -07002644 } else if (audio_is_usb_out_device(devices)) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002645 if (voice_is_in_call(adev)) {
2646 switch (adev->voice.tty_mode) {
2647 case TTY_MODE_FULL:
2648 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_USB;
2649 break;
2650 case TTY_MODE_VCO:
2651 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_USB;
2652 break;
2653 case TTY_MODE_HCO:
2654 // since Hearing will be on handset\speaker, use existing device
2655 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
2656 break;
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002657 case TTY_MODE_OFF:
2658 break;
vivek mehtaa6b79742017-03-09 15:40:43 -08002659 default:
2660 ALOGE("%s: Invalid TTY mode (%#x)",
2661 __func__, adev->voice.tty_mode);
2662 }
2663 }
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002664 if (snd_device == SND_DEVICE_NONE) {
2665 snd_device = audio_extn_usb_is_capture_supported() ?
2666 SND_DEVICE_OUT_VOICE_USB_HEADSET :
2667 SND_DEVICE_OUT_VOICE_USB_HEADPHONES;
2668 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002669 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002670 if (adev->bt_wb_speech_enabled) {
2671 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2672 } else {
2673 snd_device = SND_DEVICE_OUT_BT_SCO;
2674 }
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002675 } else if (devices & AUDIO_DEVICE_OUT_ALL_A2DP) {
2676 snd_device = SND_DEVICE_OUT_BT_A2DP;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002677 } else if (devices & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002678 if (!adev->enable_hfp) {
2679 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
2680 } else {
2681 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_HFP;
2682 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002683 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002684 if(adev->voice.hac)
2685 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2686 else if (is_operator_tmus())
Eric Laurentb23d5282013-05-14 15:27:20 -07002687 snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS;
2688 else
Eric Laurentb4d368e2014-06-25 10:21:54 -05002689 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002690 } else if (devices & AUDIO_DEVICE_OUT_TELEPHONY_TX)
2691 snd_device = SND_DEVICE_OUT_VOICE_TX;
2692
Eric Laurentb23d5282013-05-14 15:27:20 -07002693 if (snd_device != SND_DEVICE_NONE) {
2694 goto exit;
2695 }
2696 }
2697
Eric Laurentb23d5282013-05-14 15:27:20 -07002698 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2699 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2700 snd_device = SND_DEVICE_OUT_HEADPHONES;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002701 } else if (devices & AUDIO_DEVICE_OUT_LINE) {
2702 snd_device = SND_DEVICE_OUT_LINE;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002703 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) {
2704 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE;
Eric Laurentb23d5282013-05-14 15:27:20 -07002705 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
andysu5b30b062018-04-20 16:34:06 +08002706 /*
2707 * Perform device switch only if acdb tuning is different between SPEAKER & SPEAKER_REVERSE,
2708 * Or there will be a small pause while performing device switch.
2709 */
2710 if (my_data->speaker_lr_swap &&
2711 (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
2712 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]))
Eric Laurentb23d5282013-05-14 15:27:20 -07002713 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
2714 else
2715 snd_device = SND_DEVICE_OUT_SPEAKER;
2716 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002717 if (adev->bt_wb_speech_enabled) {
2718 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2719 } else {
2720 snd_device = SND_DEVICE_OUT_BT_SCO;
2721 }
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002722 } else if (devices & AUDIO_DEVICE_OUT_ALL_A2DP) {
2723 snd_device = SND_DEVICE_OUT_BT_A2DP;
Eric Laurentb23d5282013-05-14 15:27:20 -07002724 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2725 snd_device = SND_DEVICE_OUT_HDMI ;
Eric Laurent99dab492017-06-17 15:19:08 -07002726 } else if (audio_is_usb_out_device(devices)) {
jasmine cha270b7762018-03-30 15:41:33 +08002727 if (audio_extn_ma_supported_usb())
2728 snd_device = SND_DEVICE_OUT_USB_HEADSET_SPEC;
2729 else if (audio_extn_usb_is_capture_supported())
David Linee3fe402017-03-13 10:00:42 -07002730 snd_device = SND_DEVICE_OUT_USB_HEADSET;
2731 else
2732 snd_device = SND_DEVICE_OUT_USB_HEADPHONES;
2733 }else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002734 /*HAC support for voice-ish audio (eg visual voicemail)*/
2735 if(adev->voice.hac)
2736 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2737 else
2738 snd_device = SND_DEVICE_OUT_HANDSET;
Eric Laurentb23d5282013-05-14 15:27:20 -07002739 } else {
2740 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
2741 }
2742exit:
2743 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
2744 return snd_device;
2745}
2746
2747snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
2748{
2749 struct platform_data *my_data = (struct platform_data *)platform;
2750 struct audio_device *adev = my_data->adev;
2751 audio_source_t source = (adev->active_input == NULL) ?
2752 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
2753
2754 audio_mode_t mode = adev->mode;
2755 audio_devices_t in_device = ((adev->active_input == NULL) ?
2756 AUDIO_DEVICE_NONE : adev->active_input->device)
2757 & ~AUDIO_DEVICE_BIT_IN;
2758 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
2759 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
2760 snd_device_t snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002761 int channel_count = popcount(channel_mask);
Eric Laurentb23d5282013-05-14 15:27:20 -07002762
Prashant Malanic92c5962015-08-11 15:10:18 -07002763 ALOGV("%s: enter: out_device(%#x) in_device(%#x) channel_count (%d) channel_mask (0x%x)",
2764 __func__, out_device, in_device, channel_count, channel_mask);
Devin Kimd789e432016-10-26 15:07:27 -07002765 if ((out_device != AUDIO_DEVICE_NONE) && (voice_is_in_call(adev) ||
2766 audio_extn_hfp_is_active(adev))) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002767 if (adev->voice.tty_mode != TTY_MODE_OFF) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002768 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002769 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2770 out_device & AUDIO_DEVICE_OUT_LINE) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002771 switch (adev->voice.tty_mode) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002772 case TTY_MODE_FULL:
2773 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
2774 break;
2775 case TTY_MODE_VCO:
2776 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
2777 break;
2778 case TTY_MODE_HCO:
2779 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
2780 break;
2781 default:
2782 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
2783 }
2784 goto exit;
Eric Laurent99dab492017-06-17 15:19:08 -07002785 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002786 switch (adev->voice.tty_mode) {
2787 case TTY_MODE_FULL:
2788 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC;
2789 break;
2790 case TTY_MODE_VCO:
2791 // since voice will be captured from handset mic, use existing device
2792 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
2793 break;
2794 case TTY_MODE_HCO:
2795 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC;
2796 break;
2797 default:
2798 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
Eric Laurentb23d5282013-05-14 15:27:20 -07002799 }
2800 goto exit;
2801 }
2802 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002803 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002804 if (my_data->fluence_in_voice_call == false) {
2805 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2806 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002807 if (is_operator_tmus())
2808 snd_device = SND_DEVICE_IN_VOICE_DMIC_TMUS;
Eric Laurentb23d5282013-05-14 15:27:20 -07002809 else
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002810 snd_device = SND_DEVICE_IN_VOICE_DMIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002811 }
2812 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2813 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
2814 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002815 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002816 if (adev->bluetooth_nrec)
2817 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2818 else
2819 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002820 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002821 if (adev->bluetooth_nrec)
2822 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2823 else
2824 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002825 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002826 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Prashant Malanic92c5962015-08-11 15:10:18 -07002827 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
2828 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2829 out_device & AUDIO_DEVICE_OUT_LINE) {
2830 if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
2831 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
2832 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
2833 } else {
2834 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2835 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002836 }
vivek mehtafe121d52015-08-10 23:39:23 -07002837
2838 //select default
2839 if (snd_device == SND_DEVICE_NONE) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002840 if (!adev->enable_hfp) {
2841 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2842 } else {
2843 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP;
2844 platform_set_echo_reference(adev, true, out_device);
2845 }
vivek mehtafe121d52015-08-10 23:39:23 -07002846 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002847 } else if (out_device & AUDIO_DEVICE_OUT_TELEPHONY_TX) {
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002848 snd_device = SND_DEVICE_IN_VOICE_RX;
Eric Laurent99dab492017-06-17 15:19:08 -07002849 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
David Lin40b07892017-08-07 15:02:48 -07002850 if (audio_extn_usb_is_capture_supported()) {
2851 snd_device = SND_DEVICE_IN_VOICE_USB_HEADSET_MIC;
2852 } else if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
2853 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
2854 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
2855 } else {
2856 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2857 }
2858 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002859 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002860 } else if (source == AUDIO_SOURCE_CAMCORDER) {
2861 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
2862 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2863 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
2864 }
2865 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
2866 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002867 if (my_data->fluence_in_voice_rec && channel_count == 1) {
2868 if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2869 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002870 if (adev->active_input->enable_aec)
2871 snd_device = SND_DEVICE_IN_HANDSET_QMIC_AEC;
2872 else
2873 snd_device = SND_DEVICE_IN_HANDSET_QMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002874 } else if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2875 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002876 if (adev->active_input->enable_aec)
2877 snd_device = SND_DEVICE_IN_HANDSET_TMIC_AEC;
2878 else
2879 snd_device = SND_DEVICE_IN_HANDSET_TMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002880 } else if (((my_data->fluence_type == FLUENCE_PRO_ENABLE) ||
2881 (my_data->fluence_type == FLUENCE_ENABLE)) &&
2882 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002883 if (adev->active_input->enable_aec)
2884 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
2885 else
2886 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
Prashant Malanic92c5962015-08-11 15:10:18 -07002887 }
2888 platform_set_echo_reference(adev, true, out_device);
2889 } else if ((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) &&
2890 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2891 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002892 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002893 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
2894 snd_device = SND_DEVICE_IN_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002895 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002896 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2897 snd_device = SND_DEVICE_IN_QUAD_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002898 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002899 if (snd_device == SND_DEVICE_NONE) {
vivek mehtaf3440682016-05-11 14:24:37 -07002900 if (adev->active_input->enable_aec) {
2901 if (adev->active_input->enable_ns) {
2902 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS;
2903 } else {
2904 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC;
2905 }
vivek mehta733c1df2016-04-04 15:09:24 -07002906 platform_set_echo_reference(adev, true, out_device);
vivek mehtaf3440682016-05-11 14:24:37 -07002907 } else if (adev->active_input->enable_ns) {
2908 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
2909 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002910 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
vivek mehtaf3440682016-05-11 14:24:37 -07002911 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002912 }
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -07002913 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2914 snd_device = SND_DEVICE_IN_VOICE_REC_HEADSET_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07002915 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002916 snd_device = SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002917 }
rago90fb9612015-12-02 11:37:53 -08002918 } else if (source == AUDIO_SOURCE_UNPROCESSED) {
2919 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
vivek mehta4ed66e62016-04-15 23:33:34 -07002920 if (((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) ||
2921 (channel_mask == AUDIO_CHANNEL_IN_STEREO)) &&
2922 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2923 snd_device = SND_DEVICE_IN_UNPROCESSED_STEREO_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002924 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07002925 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
2926 snd_device = SND_DEVICE_IN_UNPROCESSED_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002927 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07002928 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2929 snd_device = SND_DEVICE_IN_UNPROCESSED_QUAD_MIC;
2930 } else {
2931 snd_device = SND_DEVICE_IN_UNPROCESSED_MIC;
2932 }
rago90fb9612015-12-02 11:37:53 -08002933 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2934 snd_device = SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07002935 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002936 snd_device = SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC;
rago90fb9612015-12-02 11:37:53 -08002937 }
Eric Laurent50a38ed2015-10-14 18:48:06 -07002938 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION ||
rago90fb9612015-12-02 11:37:53 -08002939 mode == AUDIO_MODE_IN_COMMUNICATION) {
David Lin40b07892017-08-07 15:02:48 -07002940 if (out_device & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
2941 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2942 (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE | AUDIO_DEVICE_OUT_USB_HEADSET) &&
2943 !audio_extn_usb_is_capture_supported())) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002944 in_device = AUDIO_DEVICE_IN_BACK_MIC;
David Lin40b07892017-08-07 15:02:48 -07002945 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002946 if (adev->active_input) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002947 if (adev->active_input->enable_aec &&
2948 adev->active_input->enable_ns) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002949 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002950 if (my_data->fluence_in_spkr_mode &&
2951 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002952 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002953 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002954 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002955 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002956 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002957 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002958 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002959 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002960 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002961 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002962 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002963 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002964 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2965 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Eric Laurent99dab492017-06-17 15:19:08 -07002966 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002967 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002968 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002969 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002970 } else if (adev->active_input->enable_aec) {
2971 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2972 if (my_data->fluence_in_spkr_mode &&
2973 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002974 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002975 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002976 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002977 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002978 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002979 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2980 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002981 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002982 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002983 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002984 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002985 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002986 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2987 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Eric Laurent99dab492017-06-17 15:19:08 -07002988 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002989 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
Eric Laurentcefbbac2014-09-04 13:54:10 -05002990 }
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08002991 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002992 } else if (adev->active_input->enable_ns) {
2993 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2994 if (my_data->fluence_in_spkr_mode &&
2995 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002996 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002997 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002998 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002999 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003000 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003001 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
3002 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003003 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003004 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003005 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003006 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003007 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003008 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05003009 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003010 }
3011 } else if (source == AUDIO_SOURCE_DEFAULT) {
3012 goto exit;
3013 }
3014
3015
3016 if (snd_device != SND_DEVICE_NONE) {
3017 goto exit;
3018 }
3019
3020 if (in_device != AUDIO_DEVICE_NONE &&
3021 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
3022 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
3023 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003024 if ((my_data->source_mic_type & SOURCE_QUAD_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003025 channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003026 snd_device = SND_DEVICE_IN_QUAD_MIC;
3027 } else if ((my_data->source_mic_type & SOURCE_THREE_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003028 channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003029 snd_device = SND_DEVICE_IN_THREE_MIC;
3030 } else if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
3031 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003032 snd_device = SND_DEVICE_IN_HANDSET_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07003033 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
3034 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003035 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003036 } else {
3037 ALOGE("%s: something wrong (1): source type (%d) channel_count (%d) .."
3038 " channel mask (0x%x) no combination found .. setting to mono", __func__,
3039 my_data->source_mic_type, channel_count, channel_mask);
3040 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3041 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003042 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003043 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
3044 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003045 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07003046 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
3047 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003048 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003049 } else {
3050 ALOGE("%s: something wrong (2): source type (%d) channel_count (%d) .."
3051 " no combination found .. setting to mono", __func__,
3052 my_data->source_mic_type, channel_count);
3053 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
3054 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003055 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3056 snd_device = SND_DEVICE_IN_HEADSET_MIC;
3057 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003058 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003059 if (adev->bluetooth_nrec)
3060 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
3061 else
3062 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003063 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003064 if (adev->bluetooth_nrec)
3065 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
3066 else
3067 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003068 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003069 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
3070 snd_device = SND_DEVICE_IN_HDMI_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07003071 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
David Linee3fe402017-03-13 10:00:42 -07003072 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07003073 } else {
3074 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
3075 ALOGW("%s: Using default handset-mic", __func__);
3076 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3077 }
3078 } else {
3079 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
3080 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3081 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
3082 snd_device = SND_DEVICE_IN_HEADSET_MIC;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003083 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07003084 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003085 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05003086 out_device & AUDIO_DEVICE_OUT_LINE) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003087 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
3088 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003089 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07003090 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
3091 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003092 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003093 } else {
3094 ALOGE("%s: something wrong (3): source type (%d) channel_count (%d) .."
3095 " no combination found .. setting to mono", __func__,
3096 my_data->source_mic_type, channel_count);
3097 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
3098 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003099 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003100 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003101 if (adev->bluetooth_nrec)
3102 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
3103 else
3104 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003105 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003106 if (adev->bluetooth_nrec)
3107 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
3108 else
3109 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003110 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003111 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
3112 snd_device = SND_DEVICE_IN_HDMI_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07003113 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
David Linee3fe402017-03-13 10:00:42 -07003114 if (audio_extn_usb_is_capture_supported())
3115 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
3116 else
3117 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07003118 } else {
3119 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
3120 ALOGW("%s: Using default handset-mic", __func__);
3121 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3122 }
3123 }
3124exit:
3125 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
3126 return snd_device;
3127}
3128
3129int platform_set_hdmi_channels(void *platform, int channel_count)
3130{
3131 struct platform_data *my_data = (struct platform_data *)platform;
3132 struct audio_device *adev = my_data->adev;
3133 struct mixer_ctl *ctl;
3134 const char *channel_cnt_str = NULL;
3135 const char *mixer_ctl_name = "HDMI_RX Channels";
3136 switch (channel_count) {
3137 case 8:
3138 channel_cnt_str = "Eight"; break;
3139 case 7:
3140 channel_cnt_str = "Seven"; break;
3141 case 6:
3142 channel_cnt_str = "Six"; break;
3143 case 5:
3144 channel_cnt_str = "Five"; break;
3145 case 4:
3146 channel_cnt_str = "Four"; break;
3147 case 3:
3148 channel_cnt_str = "Three"; break;
3149 default:
3150 channel_cnt_str = "Two"; break;
3151 }
3152 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3153 if (!ctl) {
3154 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3155 __func__, mixer_ctl_name);
3156 return -EINVAL;
3157 }
3158 ALOGV("HDMI channel count: %s", channel_cnt_str);
3159 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
3160 return 0;
3161}
3162
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003163int platform_edid_get_max_channels(void *platform)
Eric Laurentb23d5282013-05-14 15:27:20 -07003164{
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003165 struct platform_data *my_data = (struct platform_data *)platform;
3166 struct audio_device *adev = my_data->adev;
Eric Laurentb23d5282013-05-14 15:27:20 -07003167 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
3168 char *sad = block;
3169 int num_audio_blocks;
3170 int channel_count;
3171 int max_channels = 0;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003172 int i, ret, count;
Eric Laurentb23d5282013-05-14 15:27:20 -07003173
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003174 struct mixer_ctl *ctl;
3175
3176 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
3177 if (!ctl) {
3178 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3179 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
Eric Laurentb23d5282013-05-14 15:27:20 -07003180 return 0;
3181 }
3182
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003183 mixer_ctl_update(ctl);
3184
3185 count = mixer_ctl_get_num_values(ctl);
Eric Laurentb23d5282013-05-14 15:27:20 -07003186
3187 /* Read SAD blocks, clamping the maximum size for safety */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003188 if (count > (int)sizeof(block))
3189 count = (int)sizeof(block);
Eric Laurentb23d5282013-05-14 15:27:20 -07003190
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003191 ret = mixer_ctl_get_array(ctl, block, count);
3192 if (ret != 0) {
3193 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
3194 return 0;
3195 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003196
3197 /* Calculate the number of SAD blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003198 num_audio_blocks = count / SAD_BLOCK_SIZE;
Eric Laurentb23d5282013-05-14 15:27:20 -07003199
3200 for (i = 0; i < num_audio_blocks; i++) {
3201 /* Only consider LPCM blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003202 if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
3203 sad += 3;
Eric Laurentb23d5282013-05-14 15:27:20 -07003204 continue;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003205 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003206
3207 channel_count = (sad[0] & 0x7) + 1;
3208 if (channel_count > max_channels)
3209 max_channels = channel_count;
3210
3211 /* Advance to next block */
3212 sad += 3;
3213 }
3214
3215 return max_channels;
3216}
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003217
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07003218int platform_set_incall_recording_session_id(void *platform,
3219 uint32_t session_id, int rec_mode)
3220{
3221 int ret = 0;
3222 struct platform_data *my_data = (struct platform_data *)platform;
3223 struct audio_device *adev = my_data->adev;
3224 struct mixer_ctl *ctl;
3225 const char *mixer_ctl_name = "Voc VSID";
3226 int num_ctl_values;
3227 int i;
3228
3229 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3230 if (!ctl) {
3231 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3232 __func__, mixer_ctl_name);
3233 ret = -EINVAL;
3234 } else {
3235 num_ctl_values = mixer_ctl_get_num_values(ctl);
3236 for (i = 0; i < num_ctl_values; i++) {
3237 if (mixer_ctl_set_value(ctl, i, session_id)) {
3238 ALOGV("Error: invalid session_id: %x", session_id);
3239 ret = -EINVAL;
3240 break;
3241 }
3242 }
3243 }
3244
3245 if (my_data->csd != NULL) {
3246 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
3247 if (ret < 0) {
3248 ALOGE("%s: csd_client_start_record failed, error %d",
3249 __func__, ret);
3250 }
3251 }
3252
3253 return ret;
3254}
3255
3256int platform_stop_incall_recording_usecase(void *platform)
3257{
3258 int ret = 0;
3259 struct platform_data *my_data = (struct platform_data *)platform;
3260
3261 if (my_data->csd != NULL) {
3262 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
3263 if (ret < 0) {
3264 ALOGE("%s: csd_client_stop_record failed, error %d",
3265 __func__, ret);
3266 }
3267 }
3268
3269 return ret;
3270}
3271
3272int platform_start_incall_music_usecase(void *platform)
3273{
3274 int ret = 0;
3275 struct platform_data *my_data = (struct platform_data *)platform;
3276
3277 if (my_data->csd != NULL) {
3278 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
3279 if (ret < 0) {
3280 ALOGE("%s: csd_client_start_playback failed, error %d",
3281 __func__, ret);
3282 }
3283 }
3284
3285 return ret;
3286}
3287
3288int platform_stop_incall_music_usecase(void *platform)
3289{
3290 int ret = 0;
3291 struct platform_data *my_data = (struct platform_data *)platform;
3292
3293 if (my_data->csd != NULL) {
3294 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
3295 if (ret < 0) {
3296 ALOGE("%s: csd_client_stop_playback failed, error %d",
3297 __func__, ret);
3298 }
3299 }
3300
3301 return ret;
3302}
3303
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003304int platform_set_parameters(void *platform, struct str_parms *parms)
3305{
3306 struct platform_data *my_data = (struct platform_data *)platform;
jasmine chac89321b2018-04-10 21:37:01 +08003307 char *value = NULL;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003308 char *kv_pairs = str_parms_to_str(parms);
jasmine chac89321b2018-04-10 21:37:01 +08003309 int len;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003310 int ret = 0, err;
3311
3312 if (kv_pairs == NULL) {
3313 ret = -EINVAL;
3314 ALOGE("%s: key-value pair is NULL",__func__);
3315 goto done;
3316 }
3317
3318 ALOGV("%s: enter: %s", __func__, kv_pairs);
3319
jasmine chac89321b2018-04-10 21:37:01 +08003320 len = strlen(kv_pairs);
3321 value = (char*)calloc(len+1, sizeof(char));
3322 if (value == NULL) {
3323 ret = -ENOMEM;
3324 ALOGE("[%s] failed to allocate memory",__func__);
3325 goto done;
3326 }
3327
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003328 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME,
jasmine chac89321b2018-04-10 21:37:01 +08003329 value, len);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003330 if (err >= 0) {
3331 str_parms_del(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME);
3332 my_data->snd_card_name = strdup(value);
3333 ALOGV("%s: sound card name %s", __func__, my_data->snd_card_name);
3334 }
3335
keunhui.park2f7306a2015-07-16 16:48:06 +09003336 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO,
jasmine chac89321b2018-04-10 21:37:01 +08003337 value, len);
keunhui.park2f7306a2015-07-16 16:48:06 +09003338 if (err >= 0) {
3339 struct operator_info *info;
3340 char *str = value;
3341 char *name;
3342
3343 str_parms_del(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO);
3344 info = (struct operator_info *)calloc(1, sizeof(struct operator_info));
3345 name = strtok(str, ";");
3346 info->name = strdup(name);
3347 info->mccmnc = strdup(str + strlen(name) + 1);
3348
3349 list_add_tail(&operator_info_list, &info->list);
Joe Onorato188b6222016-03-01 11:02:27 -08003350 ALOGV("%s: add operator[%s] mccmnc[%s]", __func__, info->name, info->mccmnc);
keunhui.park2f7306a2015-07-16 16:48:06 +09003351 }
Prashant Malanic92c5962015-08-11 15:10:18 -07003352
3353 memset(value, 0, sizeof(value));
Eric Laurentc6333382015-09-14 12:43:44 -07003354 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT,
jasmine chac89321b2018-04-10 21:37:01 +08003355 value, len);
Prashant Malanic92c5962015-08-11 15:10:18 -07003356 if (err >= 0) {
Eric Laurentc6333382015-09-14 12:43:44 -07003357 str_parms_del(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT);
Prashant Malanic92c5962015-08-11 15:10:18 -07003358 my_data->max_mic_count = atoi(value);
3359 ALOGV("%s: max_mic_count %s/%d", __func__, value, my_data->max_mic_count);
Prashant Malanic92c5962015-08-11 15:10:18 -07003360 }
3361
jasmine chac89321b2018-04-10 21:37:01 +08003362 /* handle audio calibration parameters */
3363 set_audiocal(platform, parms, value, len);
3364
vivek mehta90933872017-06-15 18:04:39 -07003365 // to-do: disable setting sidetone gain, will revist this later
3366 // audio_extn_usb_set_sidetone_gain(parms, value, len);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003367done:
3368 ALOGV("%s: exit with code(%d)", __func__, ret);
3369 if (kv_pairs != NULL)
3370 free(kv_pairs);
jasmine chac89321b2018-04-10 21:37:01 +08003371 if (value != NULL)
3372 free(value);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003373
3374 return ret;
3375}
3376
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003377/* Delay in Us */
3378int64_t platform_render_latency(audio_usecase_t usecase)
3379{
3380 switch (usecase) {
3381 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
3382 return DEEP_BUFFER_PLATFORM_DELAY;
3383 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
3384 return LOW_LATENCY_PLATFORM_DELAY;
Haynes Mathew George03c40102016-01-29 17:57:48 -08003385 case USECASE_AUDIO_PLAYBACK_ULL:
3386 return ULL_PLATFORM_DELAY;
Eric Laurent0e46adf2016-12-16 12:49:24 -08003387 case USECASE_AUDIO_PLAYBACK_MMAP:
3388 return MMAP_PLATFORM_DELAY;
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003389 default:
3390 return 0;
3391 }
3392}
Haynes Mathew George98c95622014-06-20 19:14:25 -07003393
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003394int platform_set_snd_device_backend(snd_device_t device, const char *backend_tag,
3395 const char * hw_interface)
Haynes Mathew George98c95622014-06-20 19:14:25 -07003396{
3397 int ret = 0;
3398
3399 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
3400 ALOGE("%s: Invalid snd_device = %d",
3401 __func__, device);
3402 ret = -EINVAL;
3403 goto done;
3404 }
3405
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003406 ALOGV("%s: backend_tag_table[%s]: old = %s new = %s", __func__,
3407 platform_get_snd_device_name(device),
3408 backend_tag_table[device] != NULL ? backend_tag_table[device]: "null", backend_tag);
3409 if (backend_tag_table[device]) {
3410 free(backend_tag_table[device]);
Haynes Mathew George98c95622014-06-20 19:14:25 -07003411 }
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003412 backend_tag_table[device] = strdup(backend_tag);
3413
3414 if (hw_interface != NULL) {
3415 if (hw_interface_table[device])
3416 free(hw_interface_table[device]);
3417 ALOGV("%s: hw_interface_table[%d] = %s", __func__, device, hw_interface);
3418 hw_interface_table[device] = strdup(hw_interface);
3419 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07003420done:
3421 return ret;
3422}
3423
3424int platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t pcm_id)
3425{
3426 int ret = 0;
3427 if ((usecase <= USECASE_INVALID) || (usecase >= AUDIO_USECASE_MAX)) {
3428 ALOGE("%s: invalid usecase case idx %d", __func__, usecase);
3429 ret = -EINVAL;
3430 goto done;
3431 }
3432
3433 if ((type != 0) && (type != 1)) {
3434 ALOGE("%s: invalid usecase type", __func__);
3435 ret = -EINVAL;
3436 }
vivek mehtaa68fea62017-06-08 19:04:02 -07003437 ALOGV("%s: pcm_device_table[%d %s][%d] = %d", __func__, usecase,
3438 use_case_table[usecase],
3439 type, pcm_id);
Haynes Mathew George98c95622014-06-20 19:14:25 -07003440 pcm_device_table[usecase][type] = pcm_id;
3441done:
3442 return ret;
3443}
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003444
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07003445#define DEFAULT_NOMINAL_SPEAKER_GAIN 20
3446int ramp_speaker_gain(struct audio_device *adev, bool ramp_up, int target_ramp_up_gain) {
3447 // backup_gain: gain to try to set in case of an error during ramp
3448 int start_gain, end_gain, step, backup_gain, i;
3449 bool error = false;
3450 const struct mixer_ctl *ctl;
3451 const char *mixer_ctl_name_gain_left = "Left Speaker Gain";
3452 const char *mixer_ctl_name_gain_right = "Right Speaker Gain";
3453 struct mixer_ctl *ctl_left = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_left);
3454 struct mixer_ctl *ctl_right = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_right);
3455 if (!ctl_left || !ctl_right) {
3456 ALOGE("%s: Could not get ctl for mixer cmd - %s or %s, not applying speaker gain ramp",
3457 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
3458 return -EINVAL;
3459 } else if ((mixer_ctl_get_num_values(ctl_left) != 1)
3460 || (mixer_ctl_get_num_values(ctl_right) != 1)) {
3461 ALOGE("%s: Unexpected num values for mixer cmd - %s or %s, not applying speaker gain ramp",
3462 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
3463 return -EINVAL;
3464 }
3465 if (ramp_up) {
3466 start_gain = 0;
3467 end_gain = target_ramp_up_gain > 0 ? target_ramp_up_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
3468 step = +1;
3469 backup_gain = end_gain;
3470 } else {
3471 // using same gain on left and right
3472 const int left_gain = mixer_ctl_get_value(ctl_left, 0);
3473 start_gain = left_gain > 0 ? left_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
3474 end_gain = 0;
3475 step = -1;
3476 backup_gain = start_gain;
3477 }
3478 for (i = start_gain ; i != (end_gain + step) ; i += step) {
3479 //ALOGV("setting speaker gain to %d", i);
3480 if (mixer_ctl_set_value(ctl_left, 0, i)) {
3481 ALOGE("%s: error setting %s to %d during gain ramp",
3482 __func__, mixer_ctl_name_gain_left, i);
3483 error = true;
3484 break;
3485 }
3486 if (mixer_ctl_set_value(ctl_right, 0, i)) {
3487 ALOGE("%s: error setting %s to %d during gain ramp",
3488 __func__, mixer_ctl_name_gain_right, i);
3489 error = true;
3490 break;
3491 }
3492 usleep(1000);
3493 }
3494 if (error) {
3495 // an error occured during the ramp, let's still try to go back to a safe volume
3496 if (mixer_ctl_set_value(ctl_left, 0, backup_gain)) {
3497 ALOGE("%s: error restoring left gain to %d", __func__, backup_gain);
3498 }
3499 if (mixer_ctl_set_value(ctl_right, 0, backup_gain)) {
3500 ALOGE("%s: error restoring right gain to %d", __func__, backup_gain);
3501 }
3502 }
3503 return start_gain;
3504}
3505
vivek mehtae59cfb22017-06-16 15:57:11 -07003506int platform_set_swap_mixer(struct audio_device *adev, bool swap_channels)
3507{
3508 const char *mixer_ctl_name = "Swap channel";
3509 struct mixer_ctl *ctl;
3510 const char *mixer_path;
3511 struct platform_data *my_data = (struct platform_data *)adev->platform;
3512
3513 // forced to set to swap, but device not rotated ... ignore set
3514 if (swap_channels && !my_data->speaker_lr_swap)
3515 return 0;
3516
3517 ALOGV("%s:", __func__);
3518
3519 if (swap_channels) {
3520 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER_REVERSE);
3521 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
3522 } else {
3523 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER);
3524 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
3525 }
3526
3527 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3528 if (!ctl) {
3529 ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name);
3530 return -EINVAL;
3531 }
3532
3533 if (mixer_ctl_set_value(ctl, 0, swap_channels) < 0) {
3534 ALOGE("%s: Could not set reverse cotrol %d",__func__, swap_channels);
3535 return -EINVAL;
3536 }
3537
3538 ALOGV("platfor_force_swap_channel :: Channel orientation ( %s ) ",
3539 swap_channels?"R --> L":"L --> R");
3540
3541 return 0;
3542}
3543
3544int platform_check_and_set_swap_lr_channels(struct audio_device *adev, bool swap_channels)
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003545{
3546 // only update if there is active pcm playback on speaker
3547 struct audio_usecase *usecase;
3548 struct listnode *node;
3549 struct platform_data *my_data = (struct platform_data *)adev->platform;
3550
vivek mehtae59cfb22017-06-16 15:57:11 -07003551 my_data->speaker_lr_swap = swap_channels;
Jean-Michel Trivif7148702016-09-16 18:23:05 -07003552
vivek mehtae59cfb22017-06-16 15:57:11 -07003553 return platform_set_swap_channels(adev, swap_channels);
3554}
Jean-Michel Trivif7148702016-09-16 18:23:05 -07003555
vivek mehtae59cfb22017-06-16 15:57:11 -07003556int platform_set_swap_channels(struct audio_device *adev, bool swap_channels)
3557{
3558 // only update if there is active pcm playback on speaker
3559 struct audio_usecase *usecase;
3560 struct listnode *node;
3561 struct platform_data *my_data = (struct platform_data *)adev->platform;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003562
vivek mehtae59cfb22017-06-16 15:57:11 -07003563 // do not swap channels in audio modes with concurrent capture and playback
3564 // as this may break the echo reference
3565 if ((adev->mode == AUDIO_MODE_IN_COMMUNICATION) || (adev->mode == AUDIO_MODE_IN_CALL)) {
3566 ALOGV("%s: will not swap due to audio mode %d", __func__, adev->mode);
3567 return 0;
3568 }
3569
3570 list_for_each(node, &adev->usecase_list) {
3571 usecase = node_to_item(node, struct audio_usecase, list);
3572 if (usecase->type == PCM_PLAYBACK &&
3573 usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) {
3574 /*
3575 * If acdb tuning is different for SPEAKER_REVERSE, it is must
3576 * to perform device switch to disable the current backend to
3577 * enable it with new acdb data.
3578 */
3579 if (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
3580 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]) {
3581 const int initial_skpr_gain = ramp_speaker_gain(adev, false /*ramp_up*/, -1);
3582 select_devices(adev, usecase->id);
3583 if (initial_skpr_gain != -EINVAL)
3584 ramp_speaker_gain(adev, true /*ramp_up*/, initial_skpr_gain);
3585
3586 } else {
3587 platform_set_swap_mixer(adev, swap_channels);
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003588 }
vivek mehtae59cfb22017-06-16 15:57:11 -07003589 break;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003590 }
3591 }
vivek mehtae59cfb22017-06-16 15:57:11 -07003592
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003593 return 0;
3594}
vivek mehtaa8d7c922016-05-25 14:40:44 -07003595
3596static struct amp_db_and_gain_table tbl_mapping[MAX_VOLUME_CAL_STEPS];
3597static int num_gain_tbl_entry = 0;
3598
3599bool platform_add_gain_level_mapping(struct amp_db_and_gain_table *tbl_entry) {
3600
3601 ALOGV("%s: enter .. add %f %f %d", __func__, tbl_entry->amp, tbl_entry->db, tbl_entry->level);
3602 if (num_gain_tbl_entry == -1) {
3603 ALOGE("%s: num entry beyond valid step levels or corrupted..rejecting custom mapping",
3604 __func__);
3605 return false;
3606 }
3607
3608 if (num_gain_tbl_entry >= MAX_VOLUME_CAL_STEPS) {
3609 ALOGE("%s: max entry reached max[%d] current index[%d] .. rejecting", __func__,
3610 MAX_VOLUME_CAL_STEPS, num_gain_tbl_entry);
3611 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
3612 return false;
3613 }
3614
3615 if (num_gain_tbl_entry > 0 && tbl_mapping[num_gain_tbl_entry - 1].amp >= tbl_entry->amp) {
3616 ALOGE("%s: value not in ascending order .. rejecting custom mapping", __func__);
3617 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
3618 return false;
3619 }
3620
3621 tbl_mapping[num_gain_tbl_entry] = *tbl_entry;
3622 ++num_gain_tbl_entry;
3623
3624 return true;
3625}
3626
3627int platform_get_gain_level_mapping(struct amp_db_and_gain_table *mapping_tbl,
3628 int table_size) {
3629 int itt = 0;
3630 ALOGV("platform_get_gain_level_mapping called ");
3631
3632 if (num_gain_tbl_entry <= 0 || num_gain_tbl_entry > MAX_VOLUME_CAL_STEPS) {
3633 ALOGD("%s: empty or currupted gain_mapping_table", __func__);
3634 return 0;
3635 }
3636
3637 for (; itt < num_gain_tbl_entry && itt <= table_size; itt++) {
3638 mapping_tbl[itt] = tbl_mapping[itt];
3639 ALOGV("%s: added amp[%f] db[%f] level[%d]", __func__,
3640 mapping_tbl[itt].amp, mapping_tbl[itt].db, mapping_tbl[itt].level);
3641 }
3642
3643 return num_gain_tbl_entry;
3644}
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07003645
3646int platform_snd_card_update(void *platform, card_status_t status)
3647{
3648 struct platform_data *my_data = (struct platform_data *)platform;
3649 struct audio_device *adev = my_data->adev;
3650
3651 if (status == CARD_STATUS_ONLINE) {
3652 if (my_data->acdb_send_custom_top)
3653 my_data->acdb_send_custom_top();
3654 }
3655 return 0;
3656}
David Linee3fe402017-03-13 10:00:42 -07003657
3658/*
3659 * configures afe with bit width and Sample Rate
3660 */
Haynes Mathew George65f6b432018-02-27 17:44:55 -08003661int platform_set_backend_cfg(const struct audio_device* adev,
3662 snd_device_t snd_device,
3663 const struct audio_backend_cfg *backend_cfg)
David Linee3fe402017-03-13 10:00:42 -07003664{
3665
3666 int ret = 0;
3667 const int backend_idx = platform_get_backend_index(snd_device);
3668 struct platform_data *my_data = (struct platform_data *)adev->platform;
3669 const unsigned int bit_width = backend_cfg->bit_width;
3670 const unsigned int sample_rate = backend_cfg->sample_rate;
3671 const unsigned int channels = backend_cfg->channels;
3672 const audio_format_t format = backend_cfg->format;
3673 const bool passthrough_enabled = backend_cfg->passthrough_enabled;
3674
3675
3676 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
3677 ", backend_idx %d device (%s)", __func__, bit_width,
3678 sample_rate, channels, backend_idx,
3679 platform_get_snd_device_name(snd_device));
3680
3681 if ((my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl) &&
3682 (bit_width != my_data->current_backend_cfg[backend_idx].bit_width)) {
3683
3684 struct mixer_ctl *ctl = NULL;
3685 ctl = mixer_get_ctl_by_name(adev->mixer,
3686 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
3687 if (!ctl) {
3688 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3689 __func__,
3690 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
3691 return -EINVAL;
3692 }
3693
3694 if (bit_width == 24) {
3695 if (format == AUDIO_FORMAT_PCM_24_BIT_PACKED)
3696 ret = mixer_ctl_set_enum_by_string(ctl, "S24_3LE");
3697 else
3698 ret = mixer_ctl_set_enum_by_string(ctl, "S24_LE");
3699 } else if (bit_width == 32) {
3700 ret = mixer_ctl_set_enum_by_string(ctl, "S32_LE");
3701 } else {
3702 ret = mixer_ctl_set_enum_by_string(ctl, "S16_LE");
3703 }
3704 if ( ret < 0) {
3705 ALOGE("%s:becf: afe: fail for %s mixer set to %d bit for %x format", __func__,
3706 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
3707 } else {
3708 my_data->current_backend_cfg[backend_idx].bit_width = bit_width;
3709 ALOGD("%s:becf: afe: %s mixer set to %d bit for %x format", __func__,
3710 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
3711 }
3712 /* set the ret as 0 and not pass back to upper layer */
3713 ret = 0;
3714 }
3715
3716 if (passthrough_enabled || ((my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl) &&
3717 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate))) {
3718 char *rate_str = NULL;
3719 struct mixer_ctl *ctl = NULL;
3720
3721 switch (sample_rate) {
3722 case 32000:
3723 if (passthrough_enabled) {
3724 rate_str = "KHZ_32";
3725 break;
3726 }
3727 case 8000:
3728 case 11025:
3729 case 16000:
3730 case 22050:
3731 case 48000:
3732 rate_str = "KHZ_48";
3733 break;
3734 case 44100:
3735 rate_str = "KHZ_44P1";
3736 break;
3737 case 64000:
3738 case 96000:
3739 rate_str = "KHZ_96";
3740 break;
3741 case 88200:
3742 rate_str = "KHZ_88P2";
3743 break;
3744 case 176400:
3745 rate_str = "KHZ_176P4";
3746 break;
3747 case 192000:
3748 rate_str = "KHZ_192";
3749 break;
3750 case 352800:
3751 rate_str = "KHZ_352P8";
3752 break;
3753 case 384000:
3754 rate_str = "KHZ_384";
3755 break;
3756 case 144000:
3757 if (passthrough_enabled) {
3758 rate_str = "KHZ_144";
3759 break;
3760 }
3761 default:
3762 rate_str = "KHZ_48";
3763 break;
3764 }
3765
3766 ctl = mixer_get_ctl_by_name(adev->mixer,
3767 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
3768 if(!ctl) {
3769 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3770 __func__,
3771 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
3772 return -EINVAL;
3773 }
3774
3775 ALOGD("%s:becf: afe: %s set to %s", __func__,
3776 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl, rate_str);
3777 mixer_ctl_set_enum_by_string(ctl, rate_str);
3778 my_data->current_backend_cfg[backend_idx].sample_rate = sample_rate;
3779 }
3780 if ((my_data->current_backend_cfg[backend_idx].channels_mixer_ctl) &&
3781 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
3782 struct mixer_ctl *ctl = NULL;
3783 char *channel_cnt_str = NULL;
3784
3785 switch (channels) {
3786 case 8:
3787 channel_cnt_str = "Eight"; break;
3788 case 7:
3789 channel_cnt_str = "Seven"; break;
3790 case 6:
3791 channel_cnt_str = "Six"; break;
3792 case 5:
3793 channel_cnt_str = "Five"; break;
3794 case 4:
3795 channel_cnt_str = "Four"; break;
3796 case 3:
3797 channel_cnt_str = "Three"; break;
3798 case 1:
3799 channel_cnt_str = "One"; break;
3800 case 2:
3801 default:
3802 channel_cnt_str = "Two"; break;
3803 }
3804
3805 ctl = mixer_get_ctl_by_name(adev->mixer,
3806 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
3807 if (!ctl) {
3808 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3809 __func__,
3810 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
3811 return -EINVAL;
3812 }
3813 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
3814 my_data->current_backend_cfg[backend_idx].channels = channels;
3815
3816 // skip EDID configuration for HDMI backend
3817
3818 ALOGD("%s:becf: afe: %s set to %s", __func__,
3819 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl,
3820 channel_cnt_str);
3821 }
3822
3823 // skip set ext_display format mixer control
3824 return ret;
3825}
3826
3827static int platform_get_snd_device_bit_width(snd_device_t snd_device)
3828{
3829 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
3830 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
3831 return CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3832 }
3833
3834 return backend_bit_width_table[snd_device];
3835}
3836
3837/*
3838 * return backend_idx on which voice call is active
3839 */
3840static int platform_get_voice_call_backend(struct audio_device* adev)
3841{
3842 struct audio_usecase *uc = NULL;
3843 struct listnode *node;
3844 snd_device_t out_snd_device = SND_DEVICE_NONE;
3845
3846 int backend_idx = -1;
3847
3848 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
3849 list_for_each(node, &adev->usecase_list) {
3850 uc = node_to_item(node, struct audio_usecase, list);
3851 if (uc && uc->type == VOICE_CALL && uc->stream.out) {
3852 out_snd_device = platform_get_output_snd_device(adev->platform,
3853 uc->stream.out->devices);
3854 backend_idx = platform_get_backend_index(out_snd_device);
3855 break;
3856 }
3857 }
3858 }
3859 return backend_idx;
3860}
3861
3862/*
3863 * goes through all the current usecases and picks the highest
3864 * bitwidth & samplerate
3865 */
3866static bool platform_check_capture_backend_cfg(struct audio_device* adev,
3867 int backend_idx,
3868 struct audio_backend_cfg *backend_cfg)
3869{
3870 bool backend_change = false;
3871 unsigned int bit_width;
3872 unsigned int sample_rate;
3873 unsigned int channels;
3874 struct platform_data *my_data = (struct platform_data *)adev->platform;
3875
3876 bit_width = backend_cfg->bit_width;
3877 sample_rate = backend_cfg->sample_rate;
3878 channels = backend_cfg->channels;
3879
3880 ALOGV("%s:txbecf: afe: Codec selected backend: %d current bit width: %d and "
3881 "sample rate: %d, channels %d",__func__,backend_idx, bit_width,
3882 sample_rate, channels);
3883
3884 // For voice calls use default configuration i.e. 16b/48K, only applicable to
3885 // default backend
3886 // force routing is not required here, caller will do it anyway
3887 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
3888 ALOGW("%s:txbecf: afe: Use default bw and sr for voice/voip calls and "
3889 "for unprocessed/camera source", __func__);
3890 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3891 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3892 }
3893
3894 if (backend_idx == USB_AUDIO_TX_BACKEND) {
3895 audio_extn_usb_is_config_supported(&bit_width, &sample_rate, &channels, false);
3896 ALOGV("%s:txbecf: afe: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
3897 __func__, bit_width, sample_rate, channels);
3898 }
3899
3900 ALOGV("%s:txbecf: afe: Codec selected backend: %d updated bit width: %d and "
3901 "sample rate: %d", __func__, backend_idx, bit_width, sample_rate);
3902
3903 // Force routing if the expected bitwdith or samplerate
3904 // is not same as current backend comfiguration
3905 if ((bit_width != my_data->current_backend_cfg[backend_idx].bit_width) ||
3906 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate) ||
3907 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
3908 backend_cfg->bit_width = bit_width;
3909 backend_cfg->sample_rate= sample_rate;
3910 backend_cfg->channels = channels;
3911 backend_change = true;
3912 ALOGI("%s:txbecf: afe: Codec backend needs to be updated. new bit width: %d "
3913 "new sample rate: %d new channel: %d",
3914 __func__, backend_cfg->bit_width,
3915 backend_cfg->sample_rate, backend_cfg->channels);
3916 }
3917
3918 return backend_change;
3919}
3920
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003921static void pick_playback_cfg_for_uc(struct audio_device *adev,
3922 struct audio_usecase *usecase,
3923 snd_device_t snd_device,
3924 unsigned int *bit_width,
3925 unsigned int *sample_rate,
3926 unsigned int *channels)
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003927{
3928 int i =0;
3929 struct listnode *node;
3930 list_for_each(node, &adev->usecase_list) {
3931 struct audio_usecase *uc;
3932 uc = node_to_item(node, struct audio_usecase, list);
3933 struct stream_out *out = (struct stream_out*) uc->stream.out;
3934 if (uc->type == PCM_PLAYBACK && out && usecase != uc) {
3935 unsigned int out_channels = audio_channel_count_from_out_mask(out->channel_mask);
3936 ALOGV("%s:napb: (%d) - (%s)id (%d) sr %d bw "
3937 "(%d) ch (%d) device %s", __func__, i++, use_case_table[uc->id],
3938 uc->id, out->sample_rate,
3939 pcm_format_to_bits(out->config.format), out_channels,
3940 platform_get_snd_device_name(uc->out_snd_device));
3941
3942 if (platform_check_backends_match(snd_device, uc->out_snd_device)) {
3943 if (*bit_width < pcm_format_to_bits(out->config.format))
3944 *bit_width = pcm_format_to_bits(out->config.format);
3945 if (*sample_rate < out->sample_rate)
3946 *sample_rate = out->sample_rate;
3947 if (out->sample_rate < OUTPUT_SAMPLING_RATE_44100)
3948 *sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3949 if (*channels < out_channels)
3950 *channels = out_channels;
3951 }
3952 }
3953 }
3954 return;
3955}
3956
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003957static void headset_is_config_supported(unsigned int *bit_width,
3958 unsigned int *sample_rate,
3959 unsigned int *channels) {
3960 switch (*bit_width) {
3961 case 16:
3962 case 24:
3963 break;
3964 default:
3965 *bit_width = 16;
3966 break;
3967 }
3968
3969 if (*sample_rate > 192000) {
3970 *sample_rate = 192000;
3971 }
3972
3973 if (*channels > 2) {
3974 *channels = 2;
3975 }
3976}
3977
David Linee3fe402017-03-13 10:00:42 -07003978static bool platform_check_playback_backend_cfg(struct audio_device* adev,
3979 struct audio_usecase* usecase,
3980 snd_device_t snd_device,
3981 struct audio_backend_cfg *backend_cfg)
3982{
3983 bool backend_change = false;
David Linee3fe402017-03-13 10:00:42 -07003984 unsigned int bit_width;
3985 unsigned int sample_rate;
3986 unsigned int channels;
David Linee3fe402017-03-13 10:00:42 -07003987 int backend_idx = DEFAULT_CODEC_BACKEND;
Haynes Mathew George65f6b432018-02-27 17:44:55 -08003988 unsigned long service_interval = 0; // 0 is invalid
David Linee3fe402017-03-13 10:00:42 -07003989 struct platform_data *my_data = (struct platform_data *)adev->platform;
David Linee3fe402017-03-13 10:00:42 -07003990
3991 if (snd_device == SND_DEVICE_OUT_BT_SCO ||
3992 snd_device == SND_DEVICE_OUT_BT_SCO_WB) {
3993 backend_change = false;
3994 return backend_change;
3995 }
3996
3997 backend_idx = platform_get_backend_index(snd_device);
3998 bit_width = backend_cfg->bit_width;
3999 sample_rate = backend_cfg->sample_rate;
4000 channels = backend_cfg->channels;
4001
4002 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
4003 ", backend_idx %d usecase = %d device (%s)", __func__, bit_width,
4004 sample_rate, channels, backend_idx, usecase->id,
4005 platform_get_snd_device_name(snd_device));
4006
4007 if (backend_idx == platform_get_voice_call_backend(adev)) {
4008 ALOGW("%s:becf: afe:Use default bw and sr for voice/voip calls ",
4009 __func__);
4010 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
4011 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4012 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
4013 } else {
4014 /*
4015 * The backend should be configured at highest bit width and/or
4016 * sample rate amongst all playback usecases.
4017 * If the selected sample rate and/or bit width differ with
4018 * current backend sample rate and/or bit width, then, we set the
4019 * backend re-configuration flag.
4020 *
4021 * Exception: 16 bit playbacks is allowed through 16 bit/48/44.1 khz backend only
4022 */
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004023 pick_playback_cfg_for_uc(adev, usecase, snd_device,
4024 &bit_width,
4025 &sample_rate,
4026 &channels);
David Linee3fe402017-03-13 10:00:42 -07004027 }
4028
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004029 switch (backend_idx) {
4030 case USB_AUDIO_RX_BACKEND:
4031 audio_extn_usb_is_config_supported(&bit_width,
4032 &sample_rate, &channels, true);
Haynes Mathew George65f6b432018-02-27 17:44:55 -08004033 if (platform_get_usb_service_interval(adev->platform, true,
4034 &service_interval) == 0) {
4035 /* overwrite with best altset for this service interval */
4036 int ret =
4037 audio_extn_usb_altset_for_service_interval(true /*playback*/,
4038 service_interval,
4039 &bit_width,
4040 &sample_rate,
4041 &channels);
4042 if (ret < 0) {
4043 ALOGE("Failed to find altset for service interval %lu, skip reconfig",
4044 service_interval);
4045 return false;
4046 }
4047 }
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004048 ALOGV("%s: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
4049 __func__, bit_width, sample_rate, channels);
4050 break;
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004051 case HEADPHONE_BACKEND:
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004052 headset_is_config_supported(&bit_width, &sample_rate, &channels);
4053 break;
4054 case DEFAULT_CODEC_BACKEND:
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004055 default:
4056 bit_width = platform_get_snd_device_bit_width(snd_device);
4057 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4058 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
4059 break;
David Linee3fe402017-03-13 10:00:42 -07004060 }
4061
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004062 ALOGV("%s:becf: afe: Codec selected backend: %d updated bit width: %d and"
4063 "sample rate: %d",
David Linee3fe402017-03-13 10:00:42 -07004064 __func__, backend_idx , bit_width, sample_rate);
4065
4066 // Force routing if the expected bitwdith or samplerate
4067 // is not same as current backend comfiguration
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004068 if (bit_width != my_data->current_backend_cfg[backend_idx].bit_width ||
4069 sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate ||
4070 channels != my_data->current_backend_cfg[backend_idx].channels) {
David Linee3fe402017-03-13 10:00:42 -07004071 backend_cfg->bit_width = bit_width;
4072 backend_cfg->sample_rate = sample_rate;
4073 backend_cfg->channels = channels;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004074 backend_cfg->passthrough_enabled = false;
David Linee3fe402017-03-13 10:00:42 -07004075 backend_change = true;
4076 ALOGV("%s:becf: afe: Codec backend needs to be updated. new bit width: %d"
4077 "new sample rate: %d new channels: %d",
4078 __func__, backend_cfg->bit_width, backend_cfg->sample_rate, backend_cfg->channels);
4079 }
4080
4081 return backend_change;
4082}
4083
4084bool platform_check_and_set_playback_backend_cfg(struct audio_device* adev,
4085 struct audio_usecase *usecase, snd_device_t snd_device)
4086{
4087 int backend_idx = DEFAULT_CODEC_BACKEND;
4088 int new_snd_devices[SND_DEVICE_OUT_END];
4089 int i, num_devices = 1;
4090 bool ret = false;
4091 struct platform_data *my_data = (struct platform_data *)adev->platform;
4092 struct audio_backend_cfg backend_cfg;
4093
4094 backend_idx = platform_get_backend_index(snd_device);
4095
4096 backend_cfg.bit_width = pcm_format_to_bits(usecase->stream.out->config.format);
4097 backend_cfg.sample_rate = usecase->stream.out->sample_rate;
4098 backend_cfg.format = usecase->stream.out->format;
4099 backend_cfg.channels = audio_channel_count_from_out_mask(usecase->stream.out->channel_mask);
4100 /*this is populated by check_codec_backend_cfg hence set default value to false*/
4101 backend_cfg.passthrough_enabled = false;
4102
4103 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
4104 ", backend_idx %d usecase = %d device (%s)", __func__, backend_cfg.bit_width,
4105 backend_cfg.sample_rate, backend_cfg.channels, backend_idx, usecase->id,
4106 platform_get_snd_device_name(snd_device));
4107
4108 if (platform_can_split_snd_device(snd_device, &num_devices, new_snd_devices) < 0)
4109 new_snd_devices[0] = snd_device;
4110
4111 for (i = 0; i < num_devices; i++) {
4112 ALOGV("%s: new_snd_devices[%d] is %d", __func__, i, new_snd_devices[i]);
4113 if ((platform_check_playback_backend_cfg(adev, usecase, new_snd_devices[i],
4114 &backend_cfg))) {
4115 platform_set_backend_cfg(adev, new_snd_devices[i],
4116 &backend_cfg);
4117 ret = true;
4118 }
4119 }
4120 return ret;
4121}
4122
4123bool platform_check_and_set_capture_backend_cfg(struct audio_device* adev,
4124 struct audio_usecase *usecase, snd_device_t snd_device)
4125{
4126 int backend_idx = platform_get_backend_index(snd_device);
4127 int ret = 0;
4128 struct audio_backend_cfg backend_cfg;
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004129 memset(&backend_cfg, 0, sizeof(struct audio_backend_cfg));
David Linee3fe402017-03-13 10:00:42 -07004130
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004131 if (usecase->type == PCM_CAPTURE) {
4132 backend_cfg.format = usecase->stream.in->format;
David Linee3fe402017-03-13 10:00:42 -07004133 backend_cfg.channels = audio_channel_count_from_in_mask(usecase->stream.in->channel_mask);
4134 } else {
4135 backend_cfg.bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
4136 backend_cfg.sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4137 backend_cfg.format = AUDIO_FORMAT_PCM_16_BIT;
4138 backend_cfg.channels = 1;
4139 }
4140
4141 ALOGV("%s:txbecf: afe: bitwidth %d, samplerate %d, channel %d"
4142 ", backend_idx %d usecase = %d device (%s)", __func__,
4143 backend_cfg.bit_width,
4144 backend_cfg.sample_rate,
4145 backend_cfg.channels,
4146 backend_idx, usecase->id,
4147 platform_get_snd_device_name(snd_device));
4148
4149 if (platform_check_capture_backend_cfg(adev, backend_idx, &backend_cfg)) {
4150 ret = platform_set_backend_cfg(adev, snd_device,
4151 &backend_cfg);
4152 if(!ret)
4153 return true;
4154 }
4155
4156 return false;
4157}
4158
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004159static int max_be_dai_names = 0;
4160static const struct be_dai_name_struct *be_dai_name_table;
4161
4162/*
4163 * Retrieves the be_dai_name_table from kernel to enable a mapping
4164 * between sound device hw interfaces and backend IDs. This allows HAL to
4165 * specify the backend a specific calibration is needed for.
4166 */
4167static int init_be_dai_name_table(struct audio_device *adev)
4168{
4169 const char *mixer_ctl_name = "Backend DAI Name Table";
4170 struct mixer_ctl *ctl;
4171 int i, j, ret, size;
4172 bool valid_hw_interface;
4173
4174 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
4175 if (!ctl) {
4176 ALOGE("%s: Could not get ctl for mixer name %s\n",
4177 __func__, mixer_ctl_name);
4178 ret = -EINVAL;
4179 goto done;
4180 }
4181
4182 mixer_ctl_update(ctl);
4183
4184 size = mixer_ctl_get_num_values(ctl);
4185 if (size <= 0){
4186 ALOGE("%s: Failed to get %s size %d\n",
4187 __func__, mixer_ctl_name, size);
4188 ret = -EFAULT;
4189 goto done;
4190 }
4191
vivek mehtaa68fea62017-06-08 19:04:02 -07004192 be_dai_name_table =
4193 (const struct be_dai_name_struct *)calloc(1, size);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004194 if (be_dai_name_table == NULL) {
4195 ALOGE("%s: Failed to allocate memory for %s\n",
4196 __func__, mixer_ctl_name);
4197 ret = -ENOMEM;
4198 goto freeMem;
4199 }
4200
4201 ret = mixer_ctl_get_array(ctl, (void *)be_dai_name_table, size);
4202 if (ret) {
4203 ALOGE("%s: Failed to get %s, ret %d\n",
4204 __func__, mixer_ctl_name, ret);
4205 ret = -EFAULT;
4206 goto freeMem;
4207 }
4208
4209 if (be_dai_name_table != NULL) {
4210 max_be_dai_names = size / sizeof(struct be_dai_name_struct);
4211 ALOGV("%s: Successfully got %s, number of be dais is %d\n",
4212 __func__, mixer_ctl_name, max_be_dai_names);
4213 ret = 0;
4214 } else {
4215 ALOGE("%s: Failed to get %s\n", __func__, mixer_ctl_name);
4216 ret = -EFAULT;
4217 goto freeMem;
4218 }
4219
4220 /*
4221 * Validate all sound devices have a valid backend set to catch
4222 * errors for uncommon sound devices
4223 */
4224 for (i = 0; i < SND_DEVICE_MAX; i++) {
4225 valid_hw_interface = false;
4226
4227 if (hw_interface_table[i] == NULL) {
4228 ALOGW("%s: sound device %s has no hw interface set\n",
4229 __func__, platform_get_snd_device_name(i));
4230 continue;
4231 }
4232
4233 for (j = 0; j < max_be_dai_names; j++) {
4234 if (strcmp(hw_interface_table[i], be_dai_name_table[j].be_name)
4235 == 0) {
4236 valid_hw_interface = true;
4237 break;
4238 }
4239 }
4240 if (!valid_hw_interface)
4241 ALOGD("%s: sound device %s does not have a valid hw interface set "
4242 "(disregard for combo devices) %s\n",
4243 __func__, platform_get_snd_device_name(i),
4244 hw_interface_table[i]);
4245 }
4246
4247 goto done;
4248
4249freeMem:
4250 if (be_dai_name_table) {
4251 free((void *)be_dai_name_table);
4252 be_dai_name_table = NULL;
4253 }
4254
4255done:
4256 return ret;
4257}
4258
4259int platform_get_snd_device_backend_index(snd_device_t device)
4260{
4261 int i, be_dai_id;
4262 const char * hw_interface_name = NULL;
4263
4264 ALOGV("%s: enter with device %d\n", __func__, device);
4265
vivek mehtaa68fea62017-06-08 19:04:02 -07004266 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004267 ALOGE("%s: Invalid snd_device = %d",
4268 __func__, device);
4269 be_dai_id = -EINVAL;
4270 goto done;
4271 }
4272
4273 /* Get string value of necessary backend for device */
4274 hw_interface_name = hw_interface_table[device];
4275 if (hw_interface_name == NULL) {
4276 ALOGE("%s: no hw_interface set for device %d\n", __func__, device);
4277 be_dai_id = -EINVAL;
4278 goto done;
4279 }
4280
4281 /* Check if be dai name table was retrieved successfully */
4282 if (be_dai_name_table == NULL) {
4283 ALOGE("%s: BE DAI Name Table is not present\n", __func__);
4284 be_dai_id = -EFAULT;
4285 goto done;
4286 }
4287
4288 /* Get backend ID for device specified */
4289 for (i = 0; i < max_be_dai_names; i++) {
4290 if (strcmp(hw_interface_name, be_dai_name_table[i].be_name) == 0) {
4291 be_dai_id = be_dai_name_table[i].be_id;
4292 goto done;
4293 }
4294 }
4295 ALOGE("%s: no interface matching name %s\n", __func__, hw_interface_name);
4296 be_dai_id = -EINVAL;
4297 goto done;
4298
4299done:
4300 return be_dai_id;
4301}
4302
4303void platform_check_and_update_copp_sample_rate(void* platform, snd_device_t snd_device,
4304 unsigned int stream_sr, int* sample_rate)
4305{
4306 struct platform_data* my_data = (struct platform_data *)platform;
4307 int backend_idx = platform_get_backend_index(snd_device);
4308 int device_sr = my_data->current_backend_cfg[backend_idx].sample_rate;
4309 /*
4310 *Check if device SR is multiple of 8K or 11.025 Khz
4311 *check if the stream SR is multiple of same base, if yes
4312 *then have copp SR equal to stream SR, this ensures that
4313 *post processing happens at stream SR, else have
4314 *copp SR equal to device SR.
4315 */
4316 if (!(((sample_rate_multiple(device_sr, SAMPLE_RATE_8000)) &&
4317 (sample_rate_multiple(stream_sr, SAMPLE_RATE_8000))) ||
4318 ((sample_rate_multiple(device_sr, SAMPLE_RATE_11025)) &&
4319 (sample_rate_multiple(stream_sr, SAMPLE_RATE_11025))))) {
4320 *sample_rate = device_sr;
4321 } else
4322 *sample_rate = stream_sr;
4323
4324 ALOGI("sn_device %d device sr %d stream sr %d copp sr %d", snd_device, device_sr, stream_sr
4325 , *sample_rate);
4326
4327}
4328
4329// called from info parser
vivek mehtaa68fea62017-06-08 19:04:02 -07004330void platform_add_app_type(const char *uc_type,
4331 const char *mode,
4332 int bw,
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004333 int app_type, int max_rate) {
4334 struct app_type_entry *ap =
4335 (struct app_type_entry *)calloc(1, sizeof(struct app_type_entry));
4336
4337 if (!ap) {
4338 ALOGE("%s failed to allocate mem for app type", __func__);
4339 return;
4340 }
4341
4342 ap->uc_type = -1;
4343 for (int i=0; i<USECASE_TYPE_MAX; i++) {
4344 if (!strcmp(uc_type, usecase_type_index[i].name)) {
4345 ap->uc_type = usecase_type_index[i].index;
4346 break;
4347 }
4348 }
4349
4350 if (ap->uc_type == -1) {
4351 free(ap);
4352 return;
4353 }
4354
vivek mehtaa68fea62017-06-08 19:04:02 -07004355 ALOGI("%s uc %s mode %s bw %d app_type %d max_rate %d",
4356 __func__, uc_type, mode, bw, app_type, max_rate);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004357 ap->bit_width = bw;
4358 ap->app_type = app_type;
4359 ap->max_rate = max_rate;
vivek mehtaa68fea62017-06-08 19:04:02 -07004360 ap->mode = strdup(mode);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004361 list_add_tail(&app_type_entry_list, &ap->node);
4362}
4363
4364
4365int platform_get_default_app_type_v2(void *platform __unused,
4366 usecase_type_t type,
4367 int *app_type )
4368{
4369 if (type == PCM_PLAYBACK)
4370 *app_type = DEFAULT_APP_TYPE_RX_PATH;
4371 else
4372 *app_type = DEFAULT_APP_TYPE_TX_PATH;
4373 return 0;
4374}
4375
vivek mehtaa68fea62017-06-08 19:04:02 -07004376int platform_get_app_type_v2(void *platform,
4377 usecase_type_t uc_type,
4378 const char *mode,
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004379 int bw, int sr __unused,
4380 int *app_type)
4381{
4382 struct listnode *node;
4383 struct app_type_entry *entry;
4384 *app_type = -1;
vivek mehtaa68fea62017-06-08 19:04:02 -07004385
4386 ALOGV("%s find match for uc %d mode %s bw %d rate %d",
4387 __func__, uc_type, mode, bw, sr);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004388 list_for_each(node, &app_type_entry_list) {
4389 entry = node_to_item(node, struct app_type_entry, node);
vivek mehtaa68fea62017-06-08 19:04:02 -07004390 ALOGV("%s uc %d mode %s bw %d app_type %d max_rate %d",
4391 __func__, entry->uc_type, entry->mode, entry->bit_width,
4392 entry->app_type, entry->max_rate);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004393 if (entry->bit_width == bw &&
vivek mehtaa68fea62017-06-08 19:04:02 -07004394 entry->uc_type == uc_type &&
4395 sr <= entry->max_rate &&
4396 entry->mode && !strcmp(mode, entry->mode)) {
4397 ALOGV("%s found match %d", __func__, entry->app_type);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004398 *app_type = entry->app_type;
4399 break;
4400 }
4401 }
4402
4403 if (*app_type == -1) {
vivek mehtaa68fea62017-06-08 19:04:02 -07004404 ALOGV("%s no match found, return default", __func__);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004405 return platform_get_default_app_type_v2(platform, uc_type, app_type);
4406 }
4407 return 0;
4408}
vivek mehta90933872017-06-15 18:04:39 -07004409
4410int platform_set_sidetone(struct audio_device *adev,
4411 snd_device_t out_snd_device,
4412 bool enable, char *str)
4413{
4414 int ret;
4415 if (out_snd_device == SND_DEVICE_OUT_USB_HEADSET ||
4416 out_snd_device == SND_DEVICE_OUT_VOICE_USB_HEADSET) {
4417 ret = audio_extn_usb_enable_sidetone(out_snd_device, enable);
4418 if (ret)
4419 ALOGI("%s: usb device %d does not support device sidetone\n",
4420 __func__, out_snd_device);
4421 } else {
4422 ALOGV("%s: sidetone out device(%d) mixer cmd = %s\n",
4423 __func__, out_snd_device, str);
4424 if (enable)
4425 audio_route_apply_and_update_path(adev->audio_route, str);
4426 else
4427 audio_route_reset_and_update_path(adev->audio_route, str);
4428 }
4429 return 0;
4430}
Haynes Mathew George96483a22017-03-28 14:52:47 -07004431
4432int platform_get_mmap_data_fd(void *platform __unused, int fe_dev __unused, int dir __unused,
4433 int *fd __unused, uint32_t *size __unused)
4434{
Alexey Polyudove920d4b2017-09-15 17:09:07 -07004435#if defined (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845)
Haynes Mathew George96483a22017-03-28 14:52:47 -07004436 struct platform_data *my_data = (struct platform_data *)platform;
4437 struct audio_device *adev = my_data->adev;
4438 int hw_fd = -1;
4439 char dev_name[128];
4440 struct snd_pcm_mmap_fd mmap_fd;
4441 memset(&mmap_fd, 0, sizeof(mmap_fd));
4442 mmap_fd.dir = dir;
4443 snprintf(dev_name, sizeof(dev_name), "/dev/snd/hwC%uD%u",
4444 adev->snd_card, HWDEP_FE_BASE+fe_dev);
4445 hw_fd = open(dev_name, O_RDONLY);
4446 if (hw_fd < 0) {
4447 ALOGE("fe hw dep node open %d/%d failed", adev->snd_card, fe_dev);
4448 return -1;
4449 }
4450 if (ioctl(hw_fd, SNDRV_PCM_IOCTL_MMAP_DATA_FD, &mmap_fd) < 0) {
4451 ALOGE("fe hw dep node ioctl failed");
4452 close(hw_fd);
4453 return -1;
4454 }
4455 *fd = mmap_fd.fd;
4456 *size = mmap_fd.size;
4457 close(hw_fd); // mmap_fd should still be valid
4458 return 0;
4459#else
4460 return -1;
4461#endif
4462}
Mikhail Naganov4ee6e3e2018-03-21 16:28:35 +00004463
4464bool platform_sound_trigger_usecase_needs_event(audio_usecase_t uc_id)
4465{
4466 bool needs_event = false;
4467
4468 switch (uc_id) {
4469 /* concurrent capture usecases which needs event */
4470 case USECASE_AUDIO_RECORD:
4471 case USECASE_AUDIO_RECORD_LOW_LATENCY:
4472 case USECASE_AUDIO_RECORD_MMAP:
4473 case USECASE_AUDIO_RECORD_HIFI:
4474 case USECASE_AUDIO_RECORD_VOIP:
4475 case USECASE_VOICEMMODE1_CALL:
4476 case USECASE_VOICEMMODE2_CALL:
4477 /* concurrent playback usecases that needs event */
4478 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
4479 case USECASE_AUDIO_PLAYBACK_OFFLOAD:
4480 needs_event = true;
4481 break;
4482 default:
4483 ALOGV("%s:usecase_id[%d] no need to raise event.", __func__, uc_id);
4484 }
4485 return needs_event;
4486}
4487
4488bool platform_snd_device_has_speaker(snd_device_t dev) {
4489 int num_devs = 2;
4490 snd_device_t split_devs[2] = {SND_DEVICE_NONE, SND_DEVICE_NONE};
4491 if (platform_can_split_snd_device(dev, &num_devs, split_devs) == 0) {
4492 return platform_snd_device_has_speaker(split_devs[0]) ||
4493 platform_snd_device_has_speaker(split_devs[1]);
4494 }
4495
4496 switch (dev) {
4497 case SND_DEVICE_OUT_SPEAKER:
4498 case SND_DEVICE_OUT_SPEAKER_SAFE:
4499 case SND_DEVICE_OUT_SPEAKER_REVERSE:
4500 case SND_DEVICE_OUT_SPEAKER_PROTECTED:
4501 case SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED:
4502 case SND_DEVICE_OUT_VOICE_SPEAKER_HFP:
4503 return true;
4504 default:
4505 break;
4506 }
4507 return false;
4508}
jiabin8962a4d2018-03-19 18:21:24 -07004509
4510bool platform_set_microphone_characteristic(void *platform,
4511 struct audio_microphone_characteristic_t mic) {
4512 struct platform_data *my_data = (struct platform_data *)platform;
4513 if (my_data->declared_mic_count >= AUDIO_MICROPHONE_MAX_COUNT) {
4514 ALOGE("mic number is more than maximum number");
4515 return false;
4516 }
4517 for (size_t ch = 0; ch < AUDIO_CHANNEL_COUNT_MAX; ch++) {
4518 mic.channel_mapping[ch] = AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED;
4519 }
4520 my_data->microphones[my_data->declared_mic_count++] = mic;
4521 return true;
4522}
4523
4524int platform_get_microphones(void *platform,
4525 struct audio_microphone_characteristic_t *mic_array,
4526 size_t *mic_count) {
4527 struct platform_data *my_data = (struct platform_data *)platform;
4528 if (mic_count == NULL) {
4529 return -EINVAL;
4530 }
4531 if (mic_array == NULL) {
4532 return -EINVAL;
4533 }
4534
4535 if (*mic_count == 0) {
4536 *mic_count = my_data->declared_mic_count;
4537 return 0;
4538 }
4539
4540 size_t max_mic_count = *mic_count;
4541 size_t actual_mic_count = 0;
4542 for (size_t i = 0; i < max_mic_count && i < my_data->declared_mic_count; i++) {
4543 mic_array[i] = my_data->microphones[i];
4544 actual_mic_count++;
4545 }
4546 *mic_count = actual_mic_count;
4547 return 0;
4548}
4549
4550int platform_get_active_microphones(void *platform, audio_devices_t device, unsigned int channels,
4551 int source __unused, audio_usecase_t usecase __unused,
4552 struct audio_microphone_characteristic_t *mic_array,
4553 size_t *mic_count) {
4554 struct platform_data *my_data = (struct platform_data *)platform;
4555 if (mic_count == NULL) {
4556 return -EINVAL;
4557 }
4558 if (mic_array == NULL) {
4559 return -EINVAL;
4560 }
4561
4562 if (*mic_count == 0) {
4563 // TODO: return declared mic count as a preliminary implementation, the final
4564 // implementation will derive mic count and channel mapping from use case, source and device
4565 *mic_count = my_data->declared_mic_count;
4566 return 0;
4567 }
4568
4569 size_t max_mic_count = *mic_count;
4570 size_t actual_mic_count = 0;
4571 for (size_t i = 0; i < max_mic_count && i < my_data->declared_mic_count; i++) {
4572 // TODO: get actual microphone and channel mapping type.
4573 if ((my_data->microphones[i].device & device) == device) {
4574 mic_array[actual_mic_count] = my_data->microphones[i];
4575 for (size_t ch = 0; ch < channels; ch++) {
4576 mic_array[actual_mic_count].channel_mapping[ch] =
4577 AUDIO_MICROPHONE_CHANNEL_MAPPING_DIRECT;
4578 }
4579 actual_mic_count++;
4580 }
4581 }
4582 *mic_count = actual_mic_count;
4583 return 0;
4584}
Haynes Mathew George65f6b432018-02-27 17:44:55 -08004585
4586int platform_set_usb_service_interval(void *platform,
4587 bool playback,
4588 unsigned long service_interval,
4589 bool *reconfig)
4590{
4591#if defined (USB_SERVICE_INTERVAL_ENABLED)
4592 struct platform_data *_platform = (struct platform_data *)platform;
4593 *reconfig = false;
4594 if (!playback) {
4595 ALOGE("%s not valid for capture", __func__);
4596 return -1;
4597 }
4598 const char *ctl_name = "USB_AUDIO_RX service_interval";
4599 struct mixer_ctl *ctl = mixer_get_ctl_by_name(_platform->adev->mixer,
4600 ctl_name);
4601 if (!ctl) {
4602 ALOGV("%s: could not get mixer %s", __func__, ctl_name);
4603 return -1;
4604 }
4605 if (mixer_ctl_get_value(ctl, 0) != (int)service_interval) {
4606 mixer_ctl_set_value(ctl, 0, service_interval);
4607 *reconfig = true;
4608 }
4609 return 0;
4610#else
4611 *reconfig = false;
4612 (void)platform;
4613 (void)playback;
4614 (void)service_interval;
4615 return -1;
4616#endif
4617}
4618
4619int platform_get_usb_service_interval(void *platform,
4620 bool playback,
4621 unsigned long *service_interval)
4622{
4623#if defined (USB_SERVICE_INTERVAL_ENABLED)
4624 struct platform_data *_platform = (struct platform_data *)platform;
4625 if (!playback) {
4626 ALOGE("%s not valid for capture", __func__);
4627 return -1;
4628 }
4629 const char *ctl_name = "USB_AUDIO_RX service_interval";
4630 struct mixer_ctl *ctl = mixer_get_ctl_by_name(_platform->adev->mixer,
4631 ctl_name);
4632 if (!ctl) {
4633 ALOGV("%s: could not get mixer %s", __func__, ctl_name);
4634 return -1;
4635 }
4636 *service_interval = mixer_ctl_get_value(ctl, 0);
4637 return 0;
4638#else
4639 (void)platform;
4640 (void)playback;
4641 (void)service_interval;
4642 return -1;
4643#endif
4644}