blob: c07dd907e69d84907dbb9c0fc2af13d855c81bdb [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
Jaekyun Seokf62e17d2017-03-08 17:15:28 +090037#define MIXER_XML_DEFAULT_PATH "mixer_paths.xml"
38#define MIXER_XML_BASE_STRING "mixer_paths"
vivek mehta60ea4152016-02-18 17:10:26 -080039#define TOMTOM_8226_SND_CARD_NAME "msm8226-tomtom-snd-card"
40#define TOMTOM_MIXER_FILE_SUFFIX "wcd9330"
41
Eric Laurentb23d5282013-05-14 15:27:20 -070042#define LIB_ACDB_LOADER "libacdbloader.so"
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -070043#define AUDIO_DATA_BLOCK_MIXER_CTL "HDMI EDID"
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +090044#define CVD_VERSION_MIXER_CTL "CVD Version"
Eric Laurentb23d5282013-05-14 15:27:20 -070045
Eric Laurentf9583c32016-03-28 13:50:50 -070046#define min(a, b) ((a) < (b) ? (a) : (b))
Eric Laurentb23d5282013-05-14 15:27:20 -070047
48/*
Eric Laurentb23d5282013-05-14 15:27:20 -070049 * This file will have a maximum of 38 bytes:
50 *
51 * 4 bytes: number of audio blocks
52 * 4 bytes: total length of Short Audio Descriptor (SAD) blocks
53 * Maximum 10 * 3 bytes: SAD blocks
54 */
55#define MAX_SAD_BLOCKS 10
56#define SAD_BLOCK_SIZE 3
57
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +090058#define MAX_CVD_VERSION_STRING_SIZE 100
59
Eric Laurentb23d5282013-05-14 15:27:20 -070060/* EDID format ID for LPCM audio */
61#define EDID_FORMAT_LPCM 1
62
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -070063#define MAX_SND_CARD_NAME_LEN 31
64
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -080065#define DEFAULT_APP_TYPE_RX_PATH 69936
66#define DEFAULT_APP_TYPE_TX_PATH 69938
Haynes Mathew George39c55dc2017-07-11 19:31:23 -070067#define DEFAULT_RX_BACKEND "SLIMBUS_0_RX"
vivek mehta1a9b7c02015-06-25 11:49:38 -070068
keunhui.parkc5aaa0e2015-07-13 10:57:37 +090069#define TOSTRING_(x) #x
70#define TOSTRING(x) TOSTRING_(x)
71
Eric Laurentb23d5282013-05-14 15:27:20 -070072struct audio_block_header
73{
74 int reserved;
75 int length;
76};
77
vivek mehta1a9b7c02015-06-25 11:49:38 -070078enum {
79 CAL_MODE_SEND = 0x1,
80 CAL_MODE_PERSIST = 0x2,
81 CAL_MODE_RTAC = 0x4
82};
83
keunhui.park2f7306a2015-07-16 16:48:06 +090084#define PLATFORM_CONFIG_KEY_OPERATOR_INFO "operator_info"
85
86struct operator_info {
87 struct listnode list;
88 char *name;
89 char *mccmnc;
90};
91
92struct operator_specific_device {
93 struct listnode list;
94 char *operator;
95 char *mixer_path;
96 int acdb_id;
97};
98
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -080099#define BE_DAI_NAME_MAX_LENGTH 24
100struct be_dai_name_struct {
101 unsigned int be_id;
102 char be_name[BE_DAI_NAME_MAX_LENGTH];
103};
104
keunhui.park2f7306a2015-07-16 16:48:06 +0900105static struct listnode operator_info_list;
106static struct listnode *operator_specific_device_table[SND_DEVICE_MAX];
107
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700108/* Audio calibration related functions */
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800109typedef void (*acdb_send_audio_cal_v3_t)(int, int, int, int, int);
Eric Laurentb23d5282013-05-14 15:27:20 -0700110
Eric Laurentb23d5282013-05-14 15:27:20 -0700111struct platform_data {
112 struct audio_device *adev;
113 bool fluence_in_spkr_mode;
114 bool fluence_in_voice_call;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700115 bool fluence_in_voice_comm;
Eric Laurentb23d5282013-05-14 15:27:20 -0700116 bool fluence_in_voice_rec;
Prashant Malanic92c5962015-08-11 15:10:18 -0700117 /* 0 = no fluence, 1 = fluence, 2 = fluence pro */
118 int fluence_type;
119 int source_mic_type;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -0700120 bool speaker_lr_swap;
121
Eric Laurentb23d5282013-05-14 15:27:20 -0700122 void *acdb_handle;
Alexey Polyudove920d4b2017-09-15 17:09:07 -0700123#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -0700124 acdb_init_v2_cvd_t acdb_init;
125#elif defined (PLATFORM_MSM8084)
126 acdb_init_v2_t acdb_init;
127#else
128 acdb_init_t acdb_init;
129#endif
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700130 acdb_deallocate_t acdb_deallocate;
131 acdb_send_audio_cal_t acdb_send_audio_cal;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800132 acdb_send_audio_cal_v3_t acdb_send_audio_cal_v3;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700133 acdb_send_voice_cal_t acdb_send_voice_cal;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700134 acdb_reload_vocvoltable_t acdb_reload_vocvoltable;
vivek mehta1a9b7c02015-06-25 11:49:38 -0700135 acdb_send_gain_dep_cal_t acdb_send_gain_dep_cal;
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -0700136 acdb_send_custom_top_t acdb_send_custom_top;
137 bool acdb_initialized;
138
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700139 struct csd_data *csd;
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800140 char ec_ref_mixer_path[64];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700141
David Linee3fe402017-03-13 10:00:42 -0700142 codec_backend_cfg_t current_backend_cfg[MAX_CODEC_BACKENDS];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700143 char *snd_card_name;
keunhui.parkc5aaa0e2015-07-13 10:57:37 +0900144 int max_vol_index;
Prashant Malanic92c5962015-08-11 15:10:18 -0700145 int max_mic_count;
vivek mehtade4849c2016-03-03 17:23:38 -0800146
147 void *hw_info;
jiabin8962a4d2018-03-19 18:21:24 -0700148
149 uint32_t declared_mic_count;
150 struct audio_microphone_characteristic_t microphones[AUDIO_MICROPHONE_MAX_COUNT];
Eric Laurentb23d5282013-05-14 15:27:20 -0700151};
152
Haynes Mathew George98c95622014-06-20 19:14:25 -0700153static int pcm_device_table[AUDIO_USECASE_MAX][2] = {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700154 [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = {DEEP_BUFFER_PCM_DEVICE,
155 DEEP_BUFFER_PCM_DEVICE},
156 [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
157 LOWLATENCY_PCM_DEVICE},
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800158 [USECASE_AUDIO_PLAYBACK_HIFI] = {MULTIMEDIA2_PCM_DEVICE,
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700159 MULTIMEDIA2_PCM_DEVICE},
160 [USECASE_AUDIO_PLAYBACK_OFFLOAD] = {PLAYBACK_OFFLOAD_DEVICE,
161 PLAYBACK_OFFLOAD_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700162 [USECASE_AUDIO_PLAYBACK_TTS] = {MULTIMEDIA2_PCM_DEVICE,
163 MULTIMEDIA2_PCM_DEVICE},
164 [USECASE_AUDIO_PLAYBACK_ULL] = {MULTIMEDIA3_PCM_DEVICE,
165 MULTIMEDIA3_PCM_DEVICE},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800166 [USECASE_AUDIO_PLAYBACK_MMAP] = {MMAP_PLAYBACK_PCM_DEVICE,
167 MMAP_PLAYBACK_PCM_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700168
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700169 [USECASE_AUDIO_RECORD] = {AUDIO_RECORD_PCM_DEVICE,
170 AUDIO_RECORD_PCM_DEVICE},
171 [USECASE_AUDIO_RECORD_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
172 LOWLATENCY_PCM_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700173
Eric Laurent0e46adf2016-12-16 12:49:24 -0800174 [USECASE_AUDIO_RECORD_MMAP] = {MMAP_RECORD_PCM_DEVICE,
175 MMAP_RECORD_PCM_DEVICE},
Haynes Mathew George569b7482017-05-08 14:44:27 -0700176 [USECASE_AUDIO_RECORD_HIFI] = {MULTIMEDIA2_PCM_DEVICE,
177 MULTIMEDIA2_PCM_DEVICE},
178
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700179 [USECASE_VOICE_CALL] = {VOICE_CALL_PCM_DEVICE,
180 VOICE_CALL_PCM_DEVICE},
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700181 [USECASE_VOICE2_CALL] = {VOICE2_CALL_PCM_DEVICE, VOICE2_CALL_PCM_DEVICE},
182 [USECASE_VOLTE_CALL] = {VOLTE_CALL_PCM_DEVICE, VOLTE_CALL_PCM_DEVICE},
183 [USECASE_QCHAT_CALL] = {QCHAT_CALL_PCM_DEVICE, QCHAT_CALL_PCM_DEVICE},
184 [USECASE_VOWLAN_CALL] = {VOWLAN_CALL_PCM_DEVICE, VOWLAN_CALL_PCM_DEVICE},
vivek mehtaa51fd402016-02-04 19:49:33 -0800185 [USECASE_VOICEMMODE1_CALL] = {VOICEMMODE1_CALL_PCM_DEVICE,
186 VOICEMMODE1_CALL_PCM_DEVICE},
187 [USECASE_VOICEMMODE2_CALL] = {VOICEMMODE2_CALL_PCM_DEVICE,
188 VOICEMMODE2_CALL_PCM_DEVICE},
189
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700190 [USECASE_INCALL_REC_UPLINK] = {AUDIO_RECORD_PCM_DEVICE,
191 AUDIO_RECORD_PCM_DEVICE},
192 [USECASE_INCALL_REC_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
193 AUDIO_RECORD_PCM_DEVICE},
194 [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
195 AUDIO_RECORD_PCM_DEVICE},
Ravi Kumar Alamanda8e6e98f2013-11-05 15:57:39 -0800196 [USECASE_AUDIO_HFP_SCO] = {HFP_PCM_RX, HFP_SCO_RX},
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700197
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700198 [USECASE_AUDIO_SPKR_CALIB_RX] = {SPKR_PROT_CALIB_RX_PCM_DEVICE, -1},
199 [USECASE_AUDIO_SPKR_CALIB_TX] = {-1, SPKR_PROT_CALIB_TX_PCM_DEVICE},
200
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700201 [USECASE_AUDIO_PLAYBACK_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
202 AFE_PROXY_RECORD_PCM_DEVICE},
203 [USECASE_AUDIO_RECORD_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
204 AFE_PROXY_RECORD_PCM_DEVICE},
zhaoyang yin4211fad2015-06-04 21:13:25 +0800205 [USECASE_AUDIO_DSM_FEEDBACK] = {QUAT_MI2S_PCM_DEVICE, QUAT_MI2S_PCM_DEVICE},
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700206
vivek mehtaa68fea62017-06-08 19:04:02 -0700207 [USECASE_AUDIO_PLAYBACK_VOIP] = {AUDIO_PLAYBACK_VOIP_PCM_DEVICE,
208 AUDIO_PLAYBACK_VOIP_PCM_DEVICE},
209 [USECASE_AUDIO_RECORD_VOIP] = {AUDIO_RECORD_VOIP_PCM_DEVICE,
210 AUDIO_RECORD_VOIP_PCM_DEVICE},
Nadav Bar3d72cfc2018-01-07 12:19:24 +0200211
212 [USECASE_INCALL_MUSIC_UPLINK] = {INCALL_MUSIC_UPLINK_PCM_DEVICE,
213 INCALL_MUSIC_UPLINK_PCM_DEVICE},
Eric Laurentb23d5282013-05-14 15:27:20 -0700214};
215
216/* Array to store sound devices */
217static const char * const device_table[SND_DEVICE_MAX] = {
218 [SND_DEVICE_NONE] = "none",
219 /* Playback sound devices */
220 [SND_DEVICE_OUT_HANDSET] = "handset",
221 [SND_DEVICE_OUT_SPEAKER] = "speaker",
222 [SND_DEVICE_OUT_SPEAKER_REVERSE] = "speaker-reverse",
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700223 [SND_DEVICE_OUT_SPEAKER_SAFE] = "speaker-safe",
Eric Laurentb23d5282013-05-14 15:27:20 -0700224 [SND_DEVICE_OUT_HEADPHONES] = "headphones",
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500225 [SND_DEVICE_OUT_LINE] = "line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700226 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones",
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700227 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = "speaker-safe-and-headphones",
Eric Laurent744996b2014-10-01 11:40:40 -0500228 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = "speaker-and-line",
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700229 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = "speaker-safe-and-line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700230 [SND_DEVICE_OUT_VOICE_HANDSET] = "voice-handset",
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500231 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = "voice-hac-handset",
Eric Laurentb23d5282013-05-14 15:27:20 -0700232 [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker",
233 [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones",
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500234 [SND_DEVICE_OUT_VOICE_LINE] = "voice-line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700235 [SND_DEVICE_OUT_HDMI] = "hdmi",
236 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi",
237 [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700238 [SND_DEVICE_OUT_BT_SCO_WB] = "bt-sco-headset-wb",
Aniket Kumar Lata26483012018-01-31 20:21:42 -0800239 [SND_DEVICE_OUT_BT_A2DP] = "bt-a2dp",
240 [SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] = "speaker-and-bt-a2dp",
Eric Laurentb23d5282013-05-14 15:27:20 -0700241 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = "voice-handset-tmus",
242 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones",
243 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones",
244 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset",
vivek mehtaa6b79742017-03-09 15:40:43 -0800245 [SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = "voice-tty-full-usb",
246 [SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = "voice-tty-vco-usb",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700247 [SND_DEVICE_OUT_VOICE_TX] = "voice-tx",
David Linee3fe402017-03-13 10:00:42 -0700248 [SND_DEVICE_OUT_USB_HEADSET] = "usb-headset",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700249 [SND_DEVICE_OUT_VOICE_USB_HEADSET] = "usb-headset",
David Linee3fe402017-03-13 10:00:42 -0700250 [SND_DEVICE_OUT_USB_HEADPHONES] = "usb-headphones",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700251 [SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = "usb-headphones",
David Linee3fe402017-03-13 10:00:42 -0700252 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = "speaker-and-usb-headphones",
Haynes Mathew George9090bfb2017-05-31 11:44:50 -0700253 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] = "speaker-safe-and-usb-headphones",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700254 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = "speaker-protected",
255 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = "voice-speaker-protected",
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -0700256 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = "voice-speaker-hfp",
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -0800257 [SND_DEVICE_OUT_SPEAKER_AND_BT_SCO] = "speaker-and-bt-sco",
258 [SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB] = "speaker-and-bt-sco-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700259
260 /* Capture sound devices */
261 [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700262 [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700263 [SND_DEVICE_IN_HANDSET_MIC_NS] = "handset-mic",
264 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = "handset-mic",
265 [SND_DEVICE_IN_HANDSET_DMIC] = "dmic-endfire",
266 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = "dmic-endfire",
267 [SND_DEVICE_IN_HANDSET_DMIC_NS] = "dmic-endfire",
268 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = "dmic-endfire",
269 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = "dmic-endfire",
270
271 [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
272 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "speaker-mic",
273 [SND_DEVICE_IN_SPEAKER_MIC_NS] = "speaker-mic",
274 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = "speaker-mic",
275 [SND_DEVICE_IN_SPEAKER_DMIC] = "speaker-dmic-endfire",
276 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = "speaker-dmic-endfire",
277 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = "speaker-dmic-endfire",
278 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = "speaker-dmic-endfire",
279 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = "speaker-dmic-endfire",
280
281 [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
Eric Laurentcefbbac2014-09-04 13:54:10 -0500282 [SND_DEVICE_IN_HEADSET_MIC_AEC] = "headset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700283
Eric Laurentb23d5282013-05-14 15:27:20 -0700284 [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic",
285 [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700286 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = "bt-sco-mic",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700287 [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700288 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = "bt-sco-mic-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700289 [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700290
291 [SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef",
292 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = "voice-dmic-ef-tmus",
293 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
294 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = "voice-speaker-dmic-ef",
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -0700295 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = "voice-speaker-mic-hfp",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700296 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700297 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
298 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
299 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
vivek mehtaa6b79742017-03-09 15:40:43 -0800300 [SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = "voice-tty-full-usb-mic",
301 [SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = "voice-tty-hco-usb-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700302
Eric Laurentb23d5282013-05-14 15:27:20 -0700303 [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700304 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = "voice-rec-mic",
vivek mehta733c1df2016-04-04 15:09:24 -0700305 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = "voice-rec-mic",
vivek mehtaf3440682016-05-11 14:24:37 -0700306 [SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700307 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = "voice-rec-dmic-ef",
308 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence",
David Linee3fe402017-03-13 10:00:42 -0700309 [SND_DEVICE_IN_USB_HEADSET_MIC] = "usb-headset-mic",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700310 [SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] ="usb-headset-mic",
311 [SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = "usb-headset-mic",
312 [SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = "usb-headset-mic",
313 [SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = "usb-headset-mic",
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700314 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = "headset-mic",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700315
Ricardo Garcia9034bc42016-04-04 07:11:46 -0700316 [SND_DEVICE_IN_UNPROCESSED_MIC] = "unprocessed-mic",
vivek mehta0125e782016-06-16 18:03:11 -0700317 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = "unprocessed-stereo-mic",
318 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = "unprocessed-three-mic",
319 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = "unprocessed-quad-mic",
320 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = "unprocessed-headset-mic",
rago90fb9612015-12-02 11:37:53 -0800321
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700322 [SND_DEVICE_IN_VOICE_RX] = "voice-rx",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700323
Prashant Malanic92c5962015-08-11 15:10:18 -0700324 [SND_DEVICE_IN_THREE_MIC] = "three-mic",
325 [SND_DEVICE_IN_QUAD_MIC] = "quad-mic",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700326 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = "vi-feedback",
Prashant Malanic92c5962015-08-11 15:10:18 -0700327 [SND_DEVICE_IN_HANDSET_TMIC] = "three-mic",
328 [SND_DEVICE_IN_HANDSET_QMIC] = "quad-mic",
vivek mehta733c1df2016-04-04 15:09:24 -0700329 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = "three-mic",
330 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = "quad-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700331};
332
333/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700334static int acdb_device_table[SND_DEVICE_MAX] = {
Eric Laurentb23d5282013-05-14 15:27:20 -0700335 [SND_DEVICE_NONE] = -1,
336 [SND_DEVICE_OUT_HANDSET] = 7,
337 [SND_DEVICE_OUT_SPEAKER] = 15,
338 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 15,
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700339 [SND_DEVICE_OUT_SPEAKER_SAFE] = 15,
Eric Laurentb23d5282013-05-14 15:27:20 -0700340 [SND_DEVICE_OUT_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500341 [SND_DEVICE_OUT_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700342 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700343 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500344 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = 77,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700345 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = 77,
Ravi Kumar Alamanda235c3482014-08-21 17:32:44 -0700346 [SND_DEVICE_OUT_VOICE_HANDSET] = ACDB_ID_VOICE_HANDSET,
347 [SND_DEVICE_OUT_VOICE_SPEAKER] = ACDB_ID_VOICE_SPEAKER,
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500348 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = 53,
Eric Laurentb23d5282013-05-14 15:27:20 -0700349 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500350 [SND_DEVICE_OUT_VOICE_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700351 [SND_DEVICE_OUT_HDMI] = 18,
352 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 15,
353 [SND_DEVICE_OUT_BT_SCO] = 22,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700354 [SND_DEVICE_OUT_BT_SCO_WB] = 39,
Aniket Kumar Lata26483012018-01-31 20:21:42 -0800355 [SND_DEVICE_OUT_BT_A2DP] = 20,
356 [SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] = 14,
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700357 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = ACDB_ID_VOICE_HANDSET_TMUS,
Eric Laurentb23d5282013-05-14 15:27:20 -0700358 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
359 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
360 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
vivek mehtaa6b79742017-03-09 15:40:43 -0800361 [SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = 17,
362 [SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = 17,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700363 [SND_DEVICE_OUT_VOICE_TX] = 45,
David Linee3fe402017-03-13 10:00:42 -0700364 [SND_DEVICE_OUT_USB_HEADSET] = 45,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700365 [SND_DEVICE_OUT_VOICE_USB_HEADSET] = 45,
David Linee3fe402017-03-13 10:00:42 -0700366 [SND_DEVICE_OUT_USB_HEADPHONES] = 45,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700367 [SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = 45,
David Linee3fe402017-03-13 10:00:42 -0700368 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = 14,
Haynes Mathew George9090bfb2017-05-31 11:44:50 -0700369 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] = 14,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700370 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = 124,
371 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = 101,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700372 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = ACDB_ID_VOICE_SPEAKER,
Eric Laurentb23d5282013-05-14 15:27:20 -0700373
374 [SND_DEVICE_IN_HANDSET_MIC] = 4,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700375 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 106,
376 [SND_DEVICE_IN_HANDSET_MIC_NS] = 107,
377 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = 108,
378 [SND_DEVICE_IN_HANDSET_DMIC] = 41,
379 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = 109,
380 [SND_DEVICE_IN_HANDSET_DMIC_NS] = 110,
381 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = 111,
382 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = 34,
383
384 [SND_DEVICE_IN_SPEAKER_MIC] = 11,
385 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 112,
386 [SND_DEVICE_IN_SPEAKER_MIC_NS] = 113,
387 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = 114,
388 [SND_DEVICE_IN_SPEAKER_DMIC] = 43,
389 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = 115,
390 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = 116,
391 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = 117,
392 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = 35,
393
rago90fb9612015-12-02 11:37:53 -0800394 [SND_DEVICE_IN_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentcefbbac2014-09-04 13:54:10 -0500395 [SND_DEVICE_IN_HEADSET_MIC_AEC] = ACDB_ID_HEADSET_MIC_AEC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700396
Eric Laurentb23d5282013-05-14 15:27:20 -0700397 [SND_DEVICE_IN_HDMI_MIC] = 4,
398 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700399 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = 21,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700400 [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700401 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = 38,
Eric Laurentb23d5282013-05-14 15:27:20 -0700402 [SND_DEVICE_IN_CAMCORDER_MIC] = 61,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700403
404 [SND_DEVICE_IN_VOICE_DMIC] = 41,
405 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = ACDB_ID_VOICE_DMIC_EF_TMUS,
406 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700407 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = 11,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700408 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 43,
rago90fb9612015-12-02 11:37:53 -0800409 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentb23d5282013-05-14 15:27:20 -0700410 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
411 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
412 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
vivek mehtaa6b79742017-03-09 15:40:43 -0800413 [SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = 16,
414 [SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = 16,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700415
rago90fb9612015-12-02 11:37:53 -0800416 [SND_DEVICE_IN_VOICE_REC_MIC] = ACDB_ID_VOICE_REC_MIC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700417 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = 113,
vivek mehta733c1df2016-04-04 15:09:24 -0700418 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = 112,
vivek mehtaf3440682016-05-11 14:24:37 -0700419 [SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = 114,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700420 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = 35,
421 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 43,
rago90fb9612015-12-02 11:37:53 -0800422 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
423
424 [SND_DEVICE_IN_UNPROCESSED_MIC] = ACDB_ID_VOICE_REC_MIC,
425 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
vivek mehta4ed66e62016-04-15 23:33:34 -0700426 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = 35,
427 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = 125,
428 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = 125,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700429
430 [SND_DEVICE_IN_VOICE_RX] = 44,
David Linee3fe402017-03-13 10:00:42 -0700431 [SND_DEVICE_IN_USB_HEADSET_MIC] = 44,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700432 [SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = 44,
433 [SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = 44,
434 [SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = 44,
435 [SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = 44,
Prashant Malanic92c5962015-08-11 15:10:18 -0700436 [SND_DEVICE_IN_THREE_MIC] = 46,
437 [SND_DEVICE_IN_QUAD_MIC] = 46,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700438 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = 102,
Prashant Malanic92c5962015-08-11 15:10:18 -0700439 [SND_DEVICE_IN_HANDSET_TMIC] = 125,
440 [SND_DEVICE_IN_HANDSET_QMIC] = 125,
vivek mehta733c1df2016-04-04 15:09:24 -0700441 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = 125, /* override this for new target to 140 */
442 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = 125, /* override this for new target to 140 */
Eric Laurentb23d5282013-05-14 15:27:20 -0700443};
444
David Linee3fe402017-03-13 10:00:42 -0700445// Platform specific backend bit width table
446static int backend_bit_width_table[SND_DEVICE_MAX] = {0};
447
Haynes Mathew George98c95622014-06-20 19:14:25 -0700448struct name_to_index {
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700449 char name[100];
450 unsigned int index;
451};
452
453#define TO_NAME_INDEX(X) #X, X
454
Haynes Mathew George98c95622014-06-20 19:14:25 -0700455/* Used to get index from parsed string */
456static const struct name_to_index snd_device_name_index[SND_DEVICE_MAX] = {
457 /* out */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700458 {TO_NAME_INDEX(SND_DEVICE_OUT_HANDSET)},
459 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER)},
460 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_REVERSE)},
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700461 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700462 {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500463 {TO_NAME_INDEX(SND_DEVICE_OUT_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700464 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700465 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES)},
Eric Laurent744996b2014-10-01 11:40:40 -0500466 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_LINE)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700467 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700468 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET)},
469 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700470 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_HFP)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700471 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500472 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700473 {TO_NAME_INDEX(SND_DEVICE_OUT_HDMI)},
474 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HDMI)},
475 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO)},
476 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO_WB)},
Aniket Kumar Lata26483012018-01-31 20:21:42 -0800477 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_A2DP)},
478 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700479 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET_TMUS)},
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500480 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HAC_HANDSET)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700481 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES)},
482 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES)},
483 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET)},
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -0800484 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_SCO)},
485 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800486 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_USB)},
487 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_USB)},
David Linee3fe402017-03-13 10:00:42 -0700488 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADSET)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700489 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_USB_HEADSET)},
David Linee3fe402017-03-13 10:00:42 -0700490 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADPHONES)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700491 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_USB_HEADPHONES)},
David Linee3fe402017-03-13 10:00:42 -0700492 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET)},
Haynes Mathew George9090bfb2017-05-31 11:44:50 -0700493 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700494 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED)},
495 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800496
497 /* in */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700498 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700499 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700500 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_NS)},
501 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)},
502 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC)},
503 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC)},
504 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_NS)},
505 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)},
506 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_STEREO)},
507
508 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700509 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700510 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_NS)},
511 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)},
512 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC)},
513 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC)},
514 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS)},
515 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)},
516 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_STEREO)},
517
518 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC)},
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700519 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700520
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700521 {TO_NAME_INDEX(SND_DEVICE_IN_HDMI_MIC)},
522 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700523 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700524 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700525 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700526 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700527
528 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC)},
529 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC_TMUS)},
530 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700531 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700532 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC)},
533 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEADSET_MIC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700534 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC)},
535 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC)},
536 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800537 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC)},
538 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC)},
539
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700540
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700541 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700542 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_NS)},
vivek mehta733c1df2016-04-04 15:09:24 -0700543 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC)},
vivek mehtaf3440682016-05-11 14:24:37 -0700544 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700545 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_STEREO)},
546 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE)},
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700547 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_HEADSET_MIC)},
David Linee3fe402017-03-13 10:00:42 -0700548 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700549 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_USB_HEADSET_MIC)},
550 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC)},
551 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC)},
552 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC_AEC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700553
rago90fb9612015-12-02 11:37:53 -0800554 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_MIC)},
555 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC)},
vivek mehta4ed66e62016-04-15 23:33:34 -0700556 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_STEREO_MIC)},
557 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_THREE_MIC)},
558 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_QUAD_MIC)},
rago90fb9612015-12-02 11:37:53 -0800559
Prashant Malanic92c5962015-08-11 15:10:18 -0700560 {TO_NAME_INDEX(SND_DEVICE_IN_THREE_MIC)},
561 {TO_NAME_INDEX(SND_DEVICE_IN_QUAD_MIC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700562 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_VI_FEEDBACK)},
Prashant Malanic92c5962015-08-11 15:10:18 -0700563 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC)},
564 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC)},
vivek mehta733c1df2016-04-04 15:09:24 -0700565 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC_AEC)},
566 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC_AEC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700567};
568
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700569static char * backend_tag_table[SND_DEVICE_MAX] = {0};
570static char * hw_interface_table[SND_DEVICE_MAX] = {0};
Haynes Mathew George98c95622014-06-20 19:14:25 -0700571
572static const struct name_to_index usecase_name_index[AUDIO_USECASE_MAX] = {
573 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_DEEP_BUFFER)},
574 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_LOW_LATENCY)},
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800575 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_HIFI)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700576 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD)},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700577 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_TTS)},
578 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_ULL)},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800579 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_MMAP)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700580 {TO_NAME_INDEX(USECASE_AUDIO_RECORD)},
581 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_LOW_LATENCY)},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800582 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_MMAP)},
Haynes Mathew George569b7482017-05-08 14:44:27 -0700583 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_HIFI)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700584 {TO_NAME_INDEX(USECASE_VOICE_CALL)},
585 {TO_NAME_INDEX(USECASE_VOICE2_CALL)},
586 {TO_NAME_INDEX(USECASE_VOLTE_CALL)},
587 {TO_NAME_INDEX(USECASE_QCHAT_CALL)},
588 {TO_NAME_INDEX(USECASE_VOWLAN_CALL)},
John Muirf1346ce2016-12-06 00:03:41 -0800589 {TO_NAME_INDEX(USECASE_VOICEMMODE1_CALL)},
590 {TO_NAME_INDEX(USECASE_VOICEMMODE2_CALL)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700591 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK)},
592 {TO_NAME_INDEX(USECASE_INCALL_REC_DOWNLINK)},
593 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK_AND_DOWNLINK)},
594 {TO_NAME_INDEX(USECASE_AUDIO_HFP_SCO)},
John Muirf1346ce2016-12-06 00:03:41 -0800595 {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_RX)},
596 {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_TX)},
597 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_AFE_PROXY)},
598 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_AFE_PROXY)},
599 {TO_NAME_INDEX(USECASE_AUDIO_DSM_FEEDBACK)},
vivek mehtaa68fea62017-06-08 19:04:02 -0700600 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_VOIP)},
601 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_VOIP)},
Nadav Bar3d72cfc2018-01-07 12:19:24 +0200602 {TO_NAME_INDEX(USECASE_INCALL_MUSIC_UPLINK)},
Aniket Kumar Lata99546312018-03-19 21:38:38 -0700603 {TO_NAME_INDEX(USECASE_AUDIO_A2DP_ABR_FEEDBACK)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700604};
605
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800606static const struct name_to_index usecase_type_index[USECASE_TYPE_MAX] = {
607 {TO_NAME_INDEX(PCM_PLAYBACK)},
608 {TO_NAME_INDEX(PCM_CAPTURE)},
609 {TO_NAME_INDEX(VOICE_CALL)},
610 {TO_NAME_INDEX(PCM_HFP_CALL)},
611};
612
613struct app_type_entry {
614 int uc_type;
615 int bit_width;
616 int app_type;
617 int max_rate;
vivek mehtaa68fea62017-06-08 19:04:02 -0700618 char *mode;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800619 struct listnode node; // membership in app_type_entry_list;
620};
621
622static struct listnode app_type_entry_list;
623
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700624#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
625#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
Eric Laurent0e46adf2016-12-16 12:49:24 -0800626#define ULL_PLATFORM_DELAY (3*1000LL)
627#define MMAP_PLATFORM_DELAY (3*1000LL)
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700628
Eric Laurentb23d5282013-05-14 15:27:20 -0700629static pthread_once_t check_op_once_ctl = PTHREAD_ONCE_INIT;
630static bool is_tmus = false;
631
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800632static int init_be_dai_name_table(struct audio_device *adev);
633
Eric Laurentb23d5282013-05-14 15:27:20 -0700634static void check_operator()
635{
636 char value[PROPERTY_VALUE_MAX];
637 int mccmnc;
638 property_get("gsm.sim.operator.numeric",value,"0");
639 mccmnc = atoi(value);
Eric Laurent2bafff12016-03-17 12:17:23 -0700640 ALOGD("%s: tmus mccmnc %d", __func__, mccmnc);
Eric Laurentb23d5282013-05-14 15:27:20 -0700641 switch(mccmnc) {
642 /* TMUS MCC(310), MNC(490, 260, 026) */
643 case 310490:
644 case 310260:
645 case 310026:
sangwon.jeonb891db52013-09-14 17:39:15 +0900646 /* Add new TMUS MNC(800, 660, 580, 310, 270, 250, 240, 230, 220, 210, 200, 160) */
647 case 310800:
648 case 310660:
649 case 310580:
650 case 310310:
651 case 310270:
652 case 310250:
653 case 310240:
654 case 310230:
655 case 310220:
656 case 310210:
657 case 310200:
658 case 310160:
Eric Laurentb23d5282013-05-14 15:27:20 -0700659 is_tmus = true;
660 break;
661 }
662}
663
664bool is_operator_tmus()
665{
666 pthread_once(&check_op_once_ctl, check_operator);
667 return is_tmus;
668}
669
keunhui.park2f7306a2015-07-16 16:48:06 +0900670static char *get_current_operator()
671{
672 struct listnode *node;
673 struct operator_info *info_item;
674 char mccmnc[PROPERTY_VALUE_MAX];
675 char *ret = NULL;
676
Tom Cherry7fea2042016-11-10 18:05:59 -0800677 property_get("gsm.sim.operator.numeric",mccmnc,"00000");
keunhui.park2f7306a2015-07-16 16:48:06 +0900678
679 list_for_each(node, &operator_info_list) {
680 info_item = node_to_item(node, struct operator_info, list);
681 if (strstr(info_item->mccmnc, mccmnc) != NULL) {
682 ret = info_item->name;
683 }
684 }
685
686 return ret;
687}
688
689static struct operator_specific_device *get_operator_specific_device(snd_device_t snd_device)
690{
691 struct listnode *node;
692 struct operator_specific_device *ret = NULL;
693 struct operator_specific_device *device_item;
694 char *operator_name;
695
696 operator_name = get_current_operator();
697 if (operator_name == NULL)
698 return ret;
699
700 list_for_each(node, operator_specific_device_table[snd_device]) {
701 device_item = node_to_item(node, struct operator_specific_device, list);
702 if (strcmp(operator_name, device_item->operator) == 0) {
703 ret = device_item;
704 }
705 }
706
707 return ret;
708}
709
710
711static int get_operator_specific_device_acdb_id(snd_device_t snd_device)
712{
713 struct operator_specific_device *device;
714 int ret = acdb_device_table[snd_device];
715
716 device = get_operator_specific_device(snd_device);
717 if (device != NULL)
718 ret = device->acdb_id;
719
720 return ret;
721}
722
723static const char *get_operator_specific_device_mixer_path(snd_device_t snd_device)
724{
725 struct operator_specific_device *device;
726 const char *ret = device_table[snd_device];
727
728 device = get_operator_specific_device(snd_device);
729 if (device != NULL)
730 ret = device->mixer_path;
731
732 return ret;
733}
734
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800735inline bool platform_supports_app_type_cfg()
736{
Alexey Polyudove920d4b2017-09-15 17:09:07 -0700737#if defined (PLATFORM_MSM8998) || (PLATFORM_SDM845)
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800738 return true;
739#else
740 return false;
741#endif
742}
743
vivek mehta1a9b7c02015-06-25 11:49:38 -0700744bool platform_send_gain_dep_cal(void *platform, int level)
745{
746 bool ret_val = false;
747 struct platform_data *my_data = (struct platform_data *)platform;
748 struct audio_device *adev = my_data->adev;
749 int acdb_dev_id, app_type;
750 int acdb_dev_type = MSM_SNDDEV_CAP_RX;
751 int mode = CAL_MODE_RTAC;
752 struct listnode *node;
753 struct audio_usecase *usecase;
Haynes Mathew George67486e22017-06-26 12:58:38 -0700754 bool valid_uc_type;
755 bool valid_dev;
vivek mehta1a9b7c02015-06-25 11:49:38 -0700756
757 if (my_data->acdb_send_gain_dep_cal == NULL) {
758 ALOGE("%s: dlsym error for acdb_send_gain_dep_cal", __func__);
759 return ret_val;
760 }
761
762 if (!voice_is_in_call(adev)) {
763 ALOGV("%s: Not Voice call usecase, apply new cal for level %d",
764 __func__, level);
vivek mehta1a9b7c02015-06-25 11:49:38 -0700765
766 // find the current active sound device
767 list_for_each(node, &adev->usecase_list) {
768 usecase = node_to_item(node, struct audio_usecase, list);
Haynes Mathew George67486e22017-06-26 12:58:38 -0700769 LOG_ALWAYS_FATAL_IF(usecase == NULL,
770 "unxpected NULL usecase in usecase_list");
771 valid_uc_type = usecase->type == PCM_PLAYBACK;
772 valid_dev = false;
773 if (valid_uc_type) {
774 audio_devices_t dev = usecase->stream.out->devices;
775 valid_dev = (dev == AUDIO_DEVICE_OUT_SPEAKER ||
vivek mehta40125092017-08-21 18:48:51 -0700776 dev == AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Haynes Mathew George67486e22017-06-26 12:58:38 -0700777 dev == AUDIO_DEVICE_OUT_WIRED_HEADSET ||
778 dev == AUDIO_DEVICE_OUT_WIRED_HEADPHONE);
779 }
780 if (valid_dev) {
vivek mehta40125092017-08-21 18:48:51 -0700781 ALOGV("%s: out device is %d", __func__, usecase->out_snd_device);
782 if (platform_supports_app_type_cfg())
783 app_type = usecase->stream.out->app_type_cfg.app_type;
784 else
785 app_type = DEFAULT_APP_TYPE_RX_PATH;
vivek mehta4cb82982015-07-13 12:05:49 -0700786
vivek mehta7e573672018-03-13 17:41:41 -0700787 acdb_dev_id =
788 acdb_device_table[audio_extn_get_spkr_prot_snd_device(usecase->out_snd_device)];
vivek mehta40125092017-08-21 18:48:51 -0700789
790 if (!my_data->acdb_send_gain_dep_cal(acdb_dev_id, app_type,
vivek mehta1a9b7c02015-06-25 11:49:38 -0700791 acdb_dev_type, mode, level)) {
792 // set ret_val true if at least one calibration is set successfully
793 ret_val = true;
794 } else {
795 ALOGE("%s: my_data->acdb_send_gain_dep_cal failed ", __func__);
796 }
797 } else {
798 ALOGW("%s: Usecase list is empty", __func__);
799 }
800 }
801 } else {
802 ALOGW("%s: Voice call in progress .. ignore setting new cal",
803 __func__);
804 }
805 return ret_val;
806}
807
Eric Laurentcefbbac2014-09-04 13:54:10 -0500808void platform_set_echo_reference(struct audio_device *adev, bool enable, audio_devices_t out_device)
Eric Laurentb23d5282013-05-14 15:27:20 -0700809{
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800810 struct platform_data *my_data = (struct platform_data *)adev->platform;
Eric Laurentcefbbac2014-09-04 13:54:10 -0500811 snd_device_t snd_device = SND_DEVICE_NONE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700812
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800813 if (strcmp(my_data->ec_ref_mixer_path, "")) {
814 ALOGV("%s: diabling %s", __func__, my_data->ec_ref_mixer_path);
815 audio_route_reset_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
Eric Laurentcefbbac2014-09-04 13:54:10 -0500816 }
817
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800818 if (enable) {
819 strcpy(my_data->ec_ref_mixer_path, "echo-reference");
820 if (out_device != AUDIO_DEVICE_NONE) {
821 snd_device = platform_get_output_snd_device(adev->platform, out_device);
822 platform_add_backend_name(adev->platform, my_data->ec_ref_mixer_path, snd_device);
823 }
Eric Laurentcefbbac2014-09-04 13:54:10 -0500824
Joe Onorato188b6222016-03-01 11:02:27 -0800825 ALOGV("%s: enabling %s", __func__, my_data->ec_ref_mixer_path);
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800826 audio_route_apply_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
827 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700828}
829
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700830static struct csd_data *open_csd_client(bool i2s_ext_modem)
831{
832 struct csd_data *csd = calloc(1, sizeof(struct csd_data));
833
834 csd->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
835 if (csd->csd_client == NULL) {
836 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
837 goto error;
838 } else {
839 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
840
841 csd->deinit = (deinit_t)dlsym(csd->csd_client,
842 "csd_client_deinit");
843 if (csd->deinit == NULL) {
844 ALOGE("%s: dlsym error %s for csd_client_deinit", __func__,
845 dlerror());
846 goto error;
847 }
848 csd->disable_device = (disable_device_t)dlsym(csd->csd_client,
849 "csd_client_disable_device");
850 if (csd->disable_device == NULL) {
851 ALOGE("%s: dlsym error %s for csd_client_disable_device",
852 __func__, dlerror());
853 goto error;
854 }
855 csd->enable_device_config = (enable_device_config_t)dlsym(csd->csd_client,
856 "csd_client_enable_device_config");
857 if (csd->enable_device_config == NULL) {
858 ALOGE("%s: dlsym error %s for csd_client_enable_device_config",
859 __func__, dlerror());
860 goto error;
861 }
862 csd->enable_device = (enable_device_t)dlsym(csd->csd_client,
863 "csd_client_enable_device");
864 if (csd->enable_device == NULL) {
865 ALOGE("%s: dlsym error %s for csd_client_enable_device",
866 __func__, dlerror());
867 goto error;
868 }
869 csd->start_voice = (start_voice_t)dlsym(csd->csd_client,
870 "csd_client_start_voice");
871 if (csd->start_voice == NULL) {
872 ALOGE("%s: dlsym error %s for csd_client_start_voice",
873 __func__, dlerror());
874 goto error;
875 }
876 csd->stop_voice = (stop_voice_t)dlsym(csd->csd_client,
877 "csd_client_stop_voice");
878 if (csd->stop_voice == NULL) {
879 ALOGE("%s: dlsym error %s for csd_client_stop_voice",
880 __func__, dlerror());
881 goto error;
882 }
883 csd->volume = (volume_t)dlsym(csd->csd_client,
884 "csd_client_volume");
885 if (csd->volume == NULL) {
886 ALOGE("%s: dlsym error %s for csd_client_volume",
887 __func__, dlerror());
888 goto error;
889 }
890 csd->mic_mute = (mic_mute_t)dlsym(csd->csd_client,
891 "csd_client_mic_mute");
892 if (csd->mic_mute == NULL) {
893 ALOGE("%s: dlsym error %s for csd_client_mic_mute",
894 __func__, dlerror());
895 goto error;
896 }
897 csd->slow_talk = (slow_talk_t)dlsym(csd->csd_client,
898 "csd_client_slow_talk");
899 if (csd->slow_talk == NULL) {
900 ALOGE("%s: dlsym error %s for csd_client_slow_talk",
901 __func__, dlerror());
902 goto error;
903 }
904 csd->start_playback = (start_playback_t)dlsym(csd->csd_client,
905 "csd_client_start_playback");
906 if (csd->start_playback == NULL) {
907 ALOGE("%s: dlsym error %s for csd_client_start_playback",
908 __func__, dlerror());
909 goto error;
910 }
911 csd->stop_playback = (stop_playback_t)dlsym(csd->csd_client,
912 "csd_client_stop_playback");
913 if (csd->stop_playback == NULL) {
914 ALOGE("%s: dlsym error %s for csd_client_stop_playback",
915 __func__, dlerror());
916 goto error;
917 }
918 csd->start_record = (start_record_t)dlsym(csd->csd_client,
919 "csd_client_start_record");
920 if (csd->start_record == NULL) {
921 ALOGE("%s: dlsym error %s for csd_client_start_record",
922 __func__, dlerror());
923 goto error;
924 }
925 csd->stop_record = (stop_record_t)dlsym(csd->csd_client,
926 "csd_client_stop_record");
927 if (csd->stop_record == NULL) {
928 ALOGE("%s: dlsym error %s for csd_client_stop_record",
929 __func__, dlerror());
930 goto error;
931 }
932
933 csd->get_sample_rate = (get_sample_rate_t)dlsym(csd->csd_client,
934 "csd_client_get_sample_rate");
935 if (csd->get_sample_rate == NULL) {
936 ALOGE("%s: dlsym error %s for csd_client_get_sample_rate",
937 __func__, dlerror());
938
939 goto error;
940 }
941
942 csd->init = (init_t)dlsym(csd->csd_client, "csd_client_init");
943
944 if (csd->init == NULL) {
945 ALOGE("%s: dlsym error %s for csd_client_init",
946 __func__, dlerror());
947 goto error;
948 } else {
949 csd->init(i2s_ext_modem);
950 }
951 }
952 return csd;
953
954error:
955 free(csd);
956 csd = NULL;
957 return csd;
958}
959
960void close_csd_client(struct csd_data *csd)
961{
962 if (csd != NULL) {
963 csd->deinit();
964 dlclose(csd->csd_client);
965 free(csd);
966 csd = NULL;
967 }
968}
969
970static void platform_csd_init(struct platform_data *my_data)
971{
972#ifdef PLATFORM_MSM8084
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700973 int32_t modems, (*count_modems)(void);
974 const char *name = "libdetectmodem.so";
975 const char *func = "count_modems";
976 const char *error;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700977
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700978 my_data->csd = NULL;
979
980 void *lib = dlopen(name, RTLD_NOW);
981 error = dlerror();
982 if (!lib) {
983 ALOGE("%s: could not find %s: %s", __func__, name, error);
984 return;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700985 }
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700986
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700987 count_modems = NULL;
988 *(void **)(&count_modems) = dlsym(lib, func);
989 error = dlerror();
990 if (!count_modems) {
991 ALOGE("%s: could not find symbol %s in %s: %s",
992 __func__, func, name, error);
993 goto done;
994 }
995
996 modems = count_modems();
997 if (modems < 0) {
998 ALOGE("%s: count_modems failed\n", __func__);
999 goto done;
1000 }
1001
Eric Laurent2bafff12016-03-17 12:17:23 -07001002 ALOGD("%s: num_modems %d\n", __func__, modems);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001003 if (modems > 0)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001004 my_data->csd = open_csd_client(false /*is_i2s_ext_modem*/);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001005
1006done:
1007 dlclose(lib);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001008#else
1009 my_data->csd = NULL;
1010#endif
1011}
1012
Eric Laurentc6333382015-09-14 12:43:44 -07001013static void set_platform_defaults(struct platform_data * my_data)
Haynes Mathew George98c95622014-06-20 19:14:25 -07001014{
1015 int32_t dev;
1016 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001017 backend_tag_table[dev] = NULL;
1018 hw_interface_table[dev] = NULL;
keunhui.park2f7306a2015-07-16 16:48:06 +09001019 operator_specific_device_table[dev] = NULL;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001020 }
1021
David Linee3fe402017-03-13 10:00:42 -07001022 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1023 backend_bit_width_table[dev] = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
1024 }
1025
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001026 // To overwrite these go to the audio_platform_info.xml file.
1027 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("bt-sco");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07001028 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("bt-sco");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001029 backend_tag_table[SND_DEVICE_OUT_BT_SCO] = strdup("bt-sco");
1030 backend_tag_table[SND_DEVICE_OUT_HDMI] = strdup("hdmi");
1031 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("speaker-and-hdmi");
1032 backend_tag_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("bt-sco-wb");
1033 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("bt-sco-wb");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07001034 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("bt-sco-wb");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001035 backend_tag_table[SND_DEVICE_OUT_VOICE_TX] = strdup("afe-proxy");
1036 backend_tag_table[SND_DEVICE_IN_VOICE_RX] = strdup("afe-proxy");
Haynes Mathew George98c95622014-06-20 19:14:25 -07001037
David Linee3fe402017-03-13 10:00:42 -07001038 backend_tag_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("usb-headset");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001039 backend_tag_table[SND_DEVICE_OUT_VOICE_USB_HEADSET] = strdup("usb-headset");
David Linee3fe402017-03-13 10:00:42 -07001040 backend_tag_table[SND_DEVICE_OUT_USB_HEADPHONES] = strdup("usb-headphones");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001041 backend_tag_table[SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = strdup("usb-headphones");
David Linee3fe402017-03-13 10:00:42 -07001042 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] =
1043 strdup("speaker-and-usb-headphones");
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07001044 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] =
1045 strdup("speaker-safe-and-usb-headphones");
David Linee3fe402017-03-13 10:00:42 -07001046 backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("usb-headset-mic");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001047 backend_tag_table[SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1048 backend_tag_table[SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1049 backend_tag_table[SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1050 backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = strdup("usb-headset-mic");
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001051 backend_tag_table[SND_DEVICE_OUT_BT_A2DP] = strdup("bt-a2dp");
1052 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] = strdup("speaker-and-bt-a2dp");
1053
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001054 hw_interface_table[SND_DEVICE_OUT_HANDSET] = strdup("SLIMBUS_0_RX");
1055 hw_interface_table[SND_DEVICE_OUT_SPEAKER] = strdup("SLIMBUS_0_RX");
1056 hw_interface_table[SND_DEVICE_OUT_SPEAKER_REVERSE] = strdup("SLIMBUS_0_RX");
1057 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE] = strdup("SLIMBUS_0_RX");
1058 hw_interface_table[SND_DEVICE_OUT_HEADPHONES] = strdup("SLIMBUS_0_RX");
1059 hw_interface_table[SND_DEVICE_OUT_LINE] = strdup("SLIMBUS_0_RX");
1060 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001061 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001062 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001063 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001064 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET] = strdup("SLIMBUS_0_RX");
1065 hw_interface_table[SND_DEVICE_OUT_VOICE_HAC_HANDSET] = strdup("SLIMBUS_0_RX");
1066 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER] = strdup("SLIMBUS_0_RX");
1067 hw_interface_table[SND_DEVICE_OUT_VOICE_HEADPHONES] = strdup("SLIMBUS_0_RX");
1068 hw_interface_table[SND_DEVICE_OUT_VOICE_LINE] = strdup("SLIMBUS_0_RX");
1069 hw_interface_table[SND_DEVICE_OUT_HDMI] = strdup("HDMI_RX");
1070 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("SLIMBUS_0_RX-and-HDMI_RX");
1071 hw_interface_table[SND_DEVICE_OUT_BT_SCO] = strdup("SEC_AUX_PCM_RX");
1072 hw_interface_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("SEC_AUX_PCM_RX");
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001073 hw_interface_table[SND_DEVICE_OUT_BT_A2DP] = strdup("SLIMBUS_7_RX");
1074 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] =
1075 strdup("SLIMBUS_0_RX-and-SLIMBUS_7_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001076 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = strdup("SLIMBUS_0_RX");
1077 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = strdup("SLIMBUS_0_RX");
1078 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = strdup("SLIMBUS_0_RX");
1079 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = strdup("SLIMBUS_0_RX");
David Linee3fe402017-03-13 10:00:42 -07001080 hw_interface_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("USB_AUDIO_RX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001081 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = strdup("USB_AUDIO_RX");
1082 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = strdup("USB_AUDIO_RX");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001083 hw_interface_table[SND_DEVICE_OUT_VOICE_USB_HEADSET] = strdup("USB_AUDIO_RX");
David Linee3fe402017-03-13 10:00:42 -07001084 hw_interface_table[SND_DEVICE_OUT_USB_HEADPHONES] = strdup("USB_AUDIO_RX");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001085 hw_interface_table[SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = strdup("USB_AUDIO_RX");
David Linee3fe402017-03-13 10:00:42 -07001086 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 -07001087 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 -07001088 hw_interface_table[SND_DEVICE_OUT_VOICE_TX] = strdup("AFE_PCM_RX");
1089 hw_interface_table[SND_DEVICE_OUT_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
1090 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
jasmine cha52284622018-03-23 17:21:35 +08001091 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = strdup("SLIMBUS_0_RX");
1092 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_BT_SCO] = strdup("SLIMBUS_0_RX-and-SEC_AUX_PCM_RX");
1093 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 -07001094 hw_interface_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1095 hw_interface_table[SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1096 hw_interface_table[SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = strdup("USB_AUDIO_TX");
1097 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1098 hw_interface_table[SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1099 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = strdup("USB_AUDIO_TX");
1100 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = strdup("USB_AUDIO_TX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001101 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001102 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_AEC] = strdup("SLIMBUS_0_TX");
1103 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_NS] = strdup("SLIMBUS_0_TX");
1104 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1105 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC] = strdup("SLIMBUS_0_TX");
1106 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_AEC] = strdup("SLIMBUS_0_TX");
1107 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_NS] = strdup("SLIMBUS_0_TX");
1108 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1109 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001110 hw_interface_table[SND_DEVICE_IN_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001111 hw_interface_table[SND_DEVICE_IN_HEADSET_MIC_AEC] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001112 hw_interface_table[SND_DEVICE_IN_CAMCORDER_MIC] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001113 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC] = strdup("SLIMBUS_0_TX");
1114 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC_NS] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001115 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC_AEC] = strdup("SLIMBUS_0_TX");
1116 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001117 hw_interface_table[SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
1118 hw_interface_table[SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = strdup("SLIMBUS_0_TX");
David Lin93725722017-10-13 14:58:17 -07001119 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_MIC] = strdup("SLIMBUS_0_TX");
1120 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1121 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = strdup("SLIMBUS_0_TX");
1122 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = strdup("SLIMBUS_0_TX");
1123 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001124 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC] = strdup("SLIMBUS_0_TX");
1125 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_AEC] = strdup("SLIMBUS_0_TX");
1126 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_NS] = strdup("SLIMBUS_0_TX");
1127 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1128 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC] = strdup("SLIMBUS_0_TX");
1129 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_AEC] = strdup("SLIMBUS_0_TX");
1130 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_NS] = strdup("SLIMBUS_0_TX");
1131 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001132 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
1133 hw_interface_table[SND_DEVICE_IN_VOICE_DMIC] = strdup("SLIMBUS_0_TX");
1134 hw_interface_table[SND_DEVICE_IN_VOICE_DMIC_TMUS] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001135 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001136 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = strdup("SLIMBUS_0_TX");
1137 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001138 hw_interface_table[SND_DEVICE_IN_VOICE_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001139 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1140 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = strdup("SLIMBUS_0_TX");
1141 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1142 hw_interface_table[SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1143 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("SEC_AUX_PCM_TX");
1144 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("SEC_AUX_PCM_TX");
1145 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("SEC_AUX_PCM_TX");
1146 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("SEC_AUX_PCM_TX");
1147 hw_interface_table[SND_DEVICE_IN_VOICE_RX] = strdup("AFE_PCM_TX");
1148 hw_interface_table[SND_DEVICE_IN_THREE_MIC] = strdup("SLIMBUS_0_TX");
1149 hw_interface_table[SND_DEVICE_IN_QUAD_MIC] = strdup("SLIMBUS_0_TX");
1150 hw_interface_table[SND_DEVICE_IN_HANDSET_TMIC] = strdup("SLIMBUS_0_TX");
1151 hw_interface_table[SND_DEVICE_IN_HANDSET_QMIC] = strdup("SLIMBUS_0_TX");
1152 hw_interface_table[SND_DEVICE_IN_HANDSET_TMIC_AEC] = strdup("SLIMBUS_0_TX");
1153 hw_interface_table[SND_DEVICE_IN_HANDSET_QMIC_AEC] = strdup("SLIMBUS_0_TX");
Eric Laurentc6333382015-09-14 12:43:44 -07001154 my_data->max_mic_count = PLATFORM_DEFAULT_MIC_COUNT;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001155}
1156
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001157void get_cvd_version(char *cvd_version, struct audio_device *adev)
1158{
1159 struct mixer_ctl *ctl;
1160 int count;
1161 int ret = 0;
1162
1163 ctl = mixer_get_ctl_by_name(adev->mixer, CVD_VERSION_MIXER_CTL);
1164 if (!ctl) {
1165 ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__, CVD_VERSION_MIXER_CTL);
1166 goto done;
1167 }
1168 mixer_ctl_update(ctl);
1169
1170 count = mixer_ctl_get_num_values(ctl);
1171 if (count > MAX_CVD_VERSION_STRING_SIZE)
1172 count = MAX_CVD_VERSION_STRING_SIZE - 1;
1173
1174 ret = mixer_ctl_get_array(ctl, cvd_version, count);
1175 if (ret != 0) {
1176 ALOGE("%s: ERROR! mixer_ctl_get_array() failed to get CVD Version", __func__);
1177 goto done;
1178 }
1179
1180done:
1181 return;
1182}
1183
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001184static int platform_acdb_init(void *platform)
1185{
1186 struct platform_data *my_data = (struct platform_data *)platform;
1187 struct audio_device *adev = my_data->adev;
1188
1189 if (!my_data->acdb_init) {
1190 ALOGE("%s: no acdb_init fn provided", __func__);
1191 return -1;
1192 }
1193
1194 if (my_data->acdb_initialized) {
1195 ALOGW("acdb is already initialized");
1196 return 0;
1197 }
1198
Alexey Polyudove920d4b2017-09-15 17:09:07 -07001199#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001200 char *cvd_version = calloc(1, MAX_CVD_VERSION_STRING_SIZE);
1201 if (!cvd_version)
1202 ALOGE("failed to allocate cvd_version");
1203 else {
1204 get_cvd_version(cvd_version, adev);
1205 my_data->acdb_init((char *)my_data->snd_card_name, cvd_version, 0);
1206 free(cvd_version);
1207 }
1208#elif defined (PLATFORM_MSM8084)
1209 my_data->acdb_init((char *)my_data->snd_card_name);
1210#else
1211 my_data->acdb_init();
1212#endif
1213 my_data->acdb_initialized = true;
1214 return 0;
1215}
1216
David Linee3fe402017-03-13 10:00:42 -07001217static void
1218platform_backend_config_init(struct platform_data *pdata)
1219{
1220 int i;
1221
1222 /* initialize backend config */
1223 for (i = 0; i < MAX_CODEC_BACKENDS; i++) {
1224 pdata->current_backend_cfg[i].sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
1225 pdata->current_backend_cfg[i].bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
1226 pdata->current_backend_cfg[i].channels = CODEC_BACKEND_DEFAULT_CHANNELS;
1227
1228 if (i > MAX_RX_CODEC_BACKENDS)
1229 pdata->current_backend_cfg[i].channels = CODEC_BACKEND_DEFAULT_TX_CHANNELS;
1230
1231 pdata->current_backend_cfg[i].bitwidth_mixer_ctl = NULL;
1232 pdata->current_backend_cfg[i].samplerate_mixer_ctl = NULL;
1233 pdata->current_backend_cfg[i].channels_mixer_ctl = NULL;
1234 }
1235
1236 pdata->current_backend_cfg[DEFAULT_CODEC_BACKEND].bitwidth_mixer_ctl =
1237 strdup("SLIM_0_RX Format");
1238 pdata->current_backend_cfg[DEFAULT_CODEC_BACKEND].samplerate_mixer_ctl =
1239 strdup("SLIM_0_RX SampleRate");
1240
1241 pdata->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].bitwidth_mixer_ctl =
1242 strdup("SLIM_0_TX Format");
1243 pdata->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].samplerate_mixer_ctl =
1244 strdup("SLIM_0_TX SampleRate");
1245
1246 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].bitwidth_mixer_ctl =
1247 strdup("USB_AUDIO_TX Format");
1248 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].samplerate_mixer_ctl =
1249 strdup("USB_AUDIO_TX SampleRate");
1250 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].channels_mixer_ctl =
1251 strdup("USB_AUDIO_TX Channels");
1252
1253 pdata->current_backend_cfg[HEADPHONE_BACKEND].bitwidth_mixer_ctl =
1254 strdup("SLIM_6_RX Format");
1255 pdata->current_backend_cfg[HEADPHONE_BACKEND].samplerate_mixer_ctl =
1256 strdup("SLIM_6_RX SampleRate");
1257
1258 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].bitwidth_mixer_ctl =
1259 strdup("USB_AUDIO_RX Format");
1260 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].samplerate_mixer_ctl =
1261 strdup("USB_AUDIO_RX SampleRate");
1262
1263 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].channels = 1;
1264 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].channels_mixer_ctl =
1265 strdup("USB_AUDIO_RX Channels");
1266}
1267
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001268static int
1269platform_backend_app_type_cfg_init(struct platform_data *pdata,
1270 struct mixer *mixer)
1271{
1272 size_t app_type_cfg[128] = {0};
1273 int length, num_app_types = 0;
1274 struct mixer_ctl *ctl = NULL;
1275
1276 const char *mixer_ctl_name = "App Type Config";
1277 ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name);
1278 if (!ctl) {
1279 ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name);
1280 return -1;
1281 }
1282
1283 length = 1; // reserve index 0 for number of app types
1284
1285 struct listnode *node;
1286 struct app_type_entry *entry;
1287 list_for_each(node, &app_type_entry_list) {
1288 entry = node_to_item(node, struct app_type_entry, node);
1289 app_type_cfg[length++] = entry->app_type;
1290 app_type_cfg[length++] = entry->max_rate;
1291 app_type_cfg[length++] = entry->bit_width;
1292 ALOGI("%s add entry %d %d", __func__, entry->app_type, entry->bit_width);
1293 num_app_types += 1;
1294 }
1295
1296 // default for capture
1297 int t;
1298 platform_get_default_app_type_v2(pdata,
1299 PCM_CAPTURE,
1300 &t);
1301 app_type_cfg[length++] = t;
1302 app_type_cfg[length++] = 48000;
1303 app_type_cfg[length++] = 16;
1304 num_app_types += 1;
1305
1306 if (num_app_types) {
1307 app_type_cfg[0] = num_app_types;
1308 if (mixer_ctl_set_array(ctl, app_type_cfg, length) < 0) {
1309 ALOGE("Failed to set app type cfg");
1310 }
1311 }
1312 return 0;
1313}
1314
Xu Han1638fd12018-04-20 12:42:23 -07001315static void configure_flicker_sensor_input(struct mixer *mixer)
1316{
1317 struct mixer_ctl *ctl;
1318 const char* ctl1 = "AIF3_CAP Mixer SLIM TX2";
1319 int setting1 = 1;
1320 const char* ctl2 = "CDC_IF TX2 MUX";
1321 const char* setting2 = "DEC2";
1322 const char* ctl3 = "SLIM_1_TX Channels";
1323 const char* setting3 = "One";
1324 const char* ctl4 = "ADC MUX2";
1325 const char* setting4 = "AMIC";
1326 const char* ctl5 = "AMIC MUX2";
1327 const char* setting5 = "ADC1";
1328 const char* ctl6 = "DEC2 Volume";
1329 int setting6 = 84;
1330 const char* ctl7 = "MultiMedia2 Mixer SLIM_1_TX";
1331 int setting7 = 1;
1332 const char* ctl8 = "SLIM_1_TX SampleRate";
1333 const char* setting8 = "KHZ_8";
1334
1335 ctl = mixer_get_ctl_by_name(mixer, ctl1);
1336 mixer_ctl_set_value(ctl, 0, setting1);
1337 ctl = mixer_get_ctl_by_name(mixer, ctl2);
1338 mixer_ctl_set_enum_by_string(ctl, setting2);
1339 ctl = mixer_get_ctl_by_name(mixer, ctl3);
1340 mixer_ctl_set_enum_by_string(ctl, setting3);
1341 ctl = mixer_get_ctl_by_name(mixer, ctl4);
1342 mixer_ctl_set_enum_by_string(ctl, setting4);
1343 ctl = mixer_get_ctl_by_name(mixer, ctl5);
1344 mixer_ctl_set_enum_by_string(ctl, setting5);
1345 ctl = mixer_get_ctl_by_name(mixer, ctl6);
1346 mixer_ctl_set_value(ctl, 0, setting6);
1347 ctl = mixer_get_ctl_by_name(mixer, ctl7);
1348 mixer_ctl_set_value(ctl, 0, setting7);
1349 ctl = mixer_get_ctl_by_name(mixer, ctl8);
1350 mixer_ctl_set_enum_by_string(ctl, setting8);
1351}
1352
Eric Laurentb23d5282013-05-14 15:27:20 -07001353void *platform_init(struct audio_device *adev)
1354{
1355 char value[PROPERTY_VALUE_MAX];
vivek mehta60ea4152016-02-18 17:10:26 -08001356 struct platform_data *my_data = NULL;
1357 int retry_num = 0, snd_card_num = 0, key = 0, ret = 0;
1358 bool dual_mic_config = false, use_default_mixer_path = true;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001359 const char *snd_card_name;
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001360 char *cvd_version = NULL;
vivek mehta60ea4152016-02-18 17:10:26 -08001361 char *snd_internal_name = NULL;
1362 char *tmp = NULL;
1363 char mixer_xml_file[MIXER_PATH_MAX_LENGTH]= {0};
vivek mehtade4849c2016-03-03 17:23:38 -08001364 char platform_info_file[MIXER_PATH_MAX_LENGTH]= {0};
1365 struct snd_card_split *snd_split_handle = NULL;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001366 my_data = calloc(1, sizeof(struct platform_data));
1367
1368 my_data->adev = adev;
1369
keunhui.park2f7306a2015-07-16 16:48:06 +09001370 list_init(&operator_info_list);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001371 list_init(&app_type_entry_list);
keunhui.park2f7306a2015-07-16 16:48:06 +09001372
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001373 set_platform_defaults(my_data);
1374
vivek mehta0fb11312017-05-15 19:35:32 -07001375 // audio_extn_utils_get_snd_card_num does
1376 // - open mixer and get snd card name
1377 // - parse platform info xml file and check for valid snd card name
1378 // - on failure loop through all the active snd card
sangwoo1b9f4b32013-06-21 18:22:55 -07001379
vivek mehta0fb11312017-05-15 19:35:32 -07001380 snd_card_num = audio_extn_utils_get_snd_card_num();
1381 if (-1 == snd_card_num) {
1382 ALOGE("%s: invalid sound card number (-1), bailing out ", __func__);
1383 goto init_failed;
sangwoo1b9f4b32013-06-21 18:22:55 -07001384 }
1385
vivek mehta0fb11312017-05-15 19:35:32 -07001386 adev->mixer = mixer_open(snd_card_num);
1387 snd_card_name = mixer_get_name(adev->mixer);
1388 my_data->hw_info = hw_info_init(snd_card_name);
1389
1390 audio_extn_set_snd_card_split(snd_card_name);
1391 snd_split_handle = audio_extn_get_snd_card_split();
1392
1393 /* Get the codec internal name from the sound card and/or form factor
1394 * name and form the mixer paths and platfor info file name dynamically.
1395 * This is generic way of picking any codec and forma factor name based
1396 * mixer and platform info files in future with no code change.
1397
1398 * current code extends and looks for any of the exteneded mixer path and
1399 * platform info file present based on codec and form factor.
1400
1401 * order of picking appropriate file is
1402 * <i> mixer_paths_<codec_name>_<form_factor>.xml, if file not present
1403 * <ii> mixer_paths_<codec_name>.xml, if file not present
1404 * <iii> mixer_paths.xml
1405
1406 * same order is followed for audio_platform_info.xml as well
1407 */
1408
1409 // need to carryforward old file name
1410 if (!strncmp(snd_card_name, TOMTOM_8226_SND_CARD_NAME,
1411 min(strlen(TOMTOM_8226_SND_CARD_NAME), strlen(snd_card_name)))) {
1412 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1413 MIXER_XML_BASE_STRING, TOMTOM_MIXER_FILE_SUFFIX );
1414 } else {
1415
1416 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s_%s.xml",
1417 MIXER_XML_BASE_STRING, snd_split_handle->snd_card,
1418 snd_split_handle->form_factor);
1419 if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) {
1420 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1421 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1422 MIXER_XML_BASE_STRING, snd_split_handle->snd_card);
1423
1424 if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) {
1425 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1426 strlcpy(mixer_xml_file, MIXER_XML_DEFAULT_PATH, MIXER_PATH_MAX_LENGTH);
1427 audio_extn_utils_resolve_config_file(mixer_xml_file);
1428 }
1429 }
1430 }
1431
1432 audio_extn_utils_get_platform_info(snd_card_name, platform_info_file);
1433
jiabin8962a4d2018-03-19 18:21:24 -07001434 my_data->declared_mic_count = 0;
vivek mehta0fb11312017-05-15 19:35:32 -07001435 /* Initialize platform specific ids and/or backends*/
1436 platform_info_init(platform_info_file, my_data);
1437
1438 ALOGD("%s: Loading mixer file: %s", __func__, mixer_xml_file);
1439 adev->audio_route = audio_route_init(snd_card_num, mixer_xml_file);
1440
1441 if (!adev->audio_route) {
1442 ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
1443 mixer_close(adev->mixer);
1444 adev->mixer = NULL;
1445 hw_info_deinit(my_data->hw_info);
1446 my_data->hw_info = NULL;
1447 goto init_failed;
1448 }
1449 adev->snd_card = snd_card_num;
1450 ALOGD("%s: Opened sound card:%d", __func__, snd_card_num);
1451
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09001452 //set max volume step for voice call
1453 property_get("ro.config.vc_call_vol_steps", value, TOSTRING(MAX_VOL_INDEX));
1454 my_data->max_vol_index = atoi(value);
1455
vivek mehta65ad12d2015-08-13 18:32:48 -07001456 property_get("persist.audio.dualmic.config",value,"");
1457 if (!strcmp("endfire", value)) {
1458 dual_mic_config = true;
1459 }
1460
John Muir9e59a962018-01-10 13:30:00 -08001461 my_data->source_mic_type = 0;
Prashant Malanic92c5962015-08-11 15:10:18 -07001462
Eric Laurentb23d5282013-05-14 15:27:20 -07001463 my_data->fluence_in_spkr_mode = false;
1464 my_data->fluence_in_voice_call = false;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001465 my_data->fluence_in_voice_comm = false;
Eric Laurentb23d5282013-05-14 15:27:20 -07001466 my_data->fluence_in_voice_rec = false;
1467
vivek mehta65ad12d2015-08-13 18:32:48 -07001468 property_get("ro.qc.sdk.audio.fluencetype", value, "none");
Prashant Malanic92c5962015-08-11 15:10:18 -07001469 if (!strcmp("fluencepro", value)) {
1470 my_data->fluence_type = FLUENCE_PRO_ENABLE;
vivek mehta65ad12d2015-08-13 18:32:48 -07001471 } else if (!strcmp("fluence", value) || (dual_mic_config)) {
Prashant Malanic92c5962015-08-11 15:10:18 -07001472 my_data->fluence_type = FLUENCE_ENABLE;
1473 } else if (!strcmp("none", value)) {
1474 my_data->fluence_type = FLUENCE_DISABLE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001475 }
1476
Prashant Malanic92c5962015-08-11 15:10:18 -07001477 if (my_data->fluence_type != FLUENCE_DISABLE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001478 property_get("persist.audio.fluence.voicecall",value,"");
1479 if (!strcmp("true", value)) {
1480 my_data->fluence_in_voice_call = true;
1481 }
1482
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001483 property_get("persist.audio.fluence.voicecomm",value,"");
1484 if (!strcmp("true", value)) {
1485 my_data->fluence_in_voice_comm = true;
1486 }
1487
Eric Laurentb23d5282013-05-14 15:27:20 -07001488 property_get("persist.audio.fluence.voicerec",value,"");
1489 if (!strcmp("true", value)) {
1490 my_data->fluence_in_voice_rec = true;
1491 }
1492
1493 property_get("persist.audio.fluence.speaker",value,"");
1494 if (!strcmp("true", value)) {
1495 my_data->fluence_in_spkr_mode = true;
1496 }
1497 }
1498
Prashant Malanic92c5962015-08-11 15:10:18 -07001499 // support max to mono, example if max count is 3, usecase supports Three, dual and mono mic
1500 switch (my_data->max_mic_count) {
1501 case 4:
1502 my_data->source_mic_type |= SOURCE_QUAD_MIC;
1503 case 3:
1504 my_data->source_mic_type |= SOURCE_THREE_MIC;
1505 case 2:
1506 my_data->source_mic_type |= SOURCE_DUAL_MIC;
1507 case 1:
1508 my_data->source_mic_type |= SOURCE_MONO_MIC;
1509 break;
1510 default:
1511 ALOGE("%s: max_mic_count (%d), is not supported, setting to default",
1512 __func__, my_data->max_mic_count);
1513 my_data->source_mic_type = SOURCE_MONO_MIC|SOURCE_DUAL_MIC;
1514 break;
1515 }
1516
1517 ALOGV("%s: Fluence_Type(%d) max_mic_count(%d) mic_type(0x%x) fluence_in_voice_call(%d)"
1518 " fluence_in_voice_comm(%d) fluence_in_voice_rec(%d) fluence_in_spkr_mode(%d) ",
1519 __func__, my_data->fluence_type, my_data->max_mic_count, my_data->source_mic_type,
1520 my_data->fluence_in_voice_call, my_data->fluence_in_voice_comm,
1521 my_data->fluence_in_voice_rec, my_data->fluence_in_spkr_mode);
1522
Eric Laurentb23d5282013-05-14 15:27:20 -07001523 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
1524 if (my_data->acdb_handle == NULL) {
1525 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
1526 } else {
1527 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
1528 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
1529 "acdb_loader_deallocate_ACDB");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001530 if (!my_data->acdb_deallocate)
1531 ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s",
1532 __func__, LIB_ACDB_LOADER);
1533
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001534 my_data->acdb_send_audio_cal_v3 = (acdb_send_audio_cal_v3_t)dlsym(my_data->acdb_handle,
1535 "acdb_loader_send_audio_cal_v3");
1536 if (!my_data->acdb_send_audio_cal_v3)
1537 ALOGE("%s: Could not find the symbol acdb_send_audio_cal_v3 from %s",
1538 __func__, LIB_ACDB_LOADER);
1539
Eric Laurentb23d5282013-05-14 15:27:20 -07001540 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
1541 "acdb_loader_send_audio_cal");
1542 if (!my_data->acdb_send_audio_cal)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001543 ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s",
Eric Laurentb23d5282013-05-14 15:27:20 -07001544 __func__, LIB_ACDB_LOADER);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001545
Eric Laurentb23d5282013-05-14 15:27:20 -07001546 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
1547 "acdb_loader_send_voice_cal");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001548 if (!my_data->acdb_send_voice_cal)
1549 ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s",
1550 __func__, LIB_ACDB_LOADER);
1551
1552 my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle,
1553 "acdb_loader_reload_vocvoltable");
1554 if (!my_data->acdb_reload_vocvoltable)
1555 ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s",
1556 __func__, LIB_ACDB_LOADER);
vivek mehta1a9b7c02015-06-25 11:49:38 -07001557
1558 my_data->acdb_send_gain_dep_cal = (acdb_send_gain_dep_cal_t)dlsym(my_data->acdb_handle,
1559 "acdb_loader_send_gain_dep_cal");
1560 if (!my_data->acdb_send_gain_dep_cal)
1561 ALOGV("%s: Could not find the symbol acdb_loader_send_gain_dep_cal from %s",
1562 __func__, LIB_ACDB_LOADER);
1563
Xu Han1638fd12018-04-20 12:42:23 -07001564#if defined (FLICKER_SENSOR_INPUT)
1565 configure_flicker_sensor_input(adev->mixer);
1566#endif
1567
Alexey Polyudove920d4b2017-09-15 17:09:07 -07001568#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845)
vivek mehta0fb11312017-05-15 19:35:32 -07001569 acdb_init_v2_cvd_t acdb_init_local;
1570 acdb_init_local = (acdb_init_v2_cvd_t)dlsym(my_data->acdb_handle,
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001571 "acdb_loader_init_v2");
vivek mehta0fb11312017-05-15 19:35:32 -07001572 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001573 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1574 dlerror());
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001575
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001576#elif defined (PLATFORM_MSM8084)
vivek mehta0fb11312017-05-15 19:35:32 -07001577 acdb_init_v2_t acdb_init_local;
1578 acdb_init_local = (acdb_init_v2_t)dlsym(my_data->acdb_handle,
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001579 "acdb_loader_init_v2");
vivek mehta0fb11312017-05-15 19:35:32 -07001580 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001581 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1582 dlerror());
1583
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001584#else
vivek mehta0fb11312017-05-15 19:35:32 -07001585 acdb_init_t acdb_init_local;
1586 acdb_init_local = (acdb_init_t)dlsym(my_data->acdb_handle,
Eric Laurentb23d5282013-05-14 15:27:20 -07001587 "acdb_loader_init_ACDB");
vivek mehta0fb11312017-05-15 19:35:32 -07001588 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001589 ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__,
1590 dlerror());
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001591#endif
vivek mehta0fb11312017-05-15 19:35:32 -07001592 my_data->acdb_init = acdb_init_local;
Eric Laurentb23d5282013-05-14 15:27:20 -07001593
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001594 my_data->acdb_send_custom_top = (acdb_send_custom_top_t)
1595 dlsym(my_data->acdb_handle,
1596 "acdb_loader_send_common_custom_topology");
1597
1598 if (!my_data->acdb_send_custom_top)
1599 ALOGE("%s: Could not find the symbol acdb_get_default_app_type from %s",
1600 __func__, LIB_ACDB_LOADER);
1601
vivek mehta0fb11312017-05-15 19:35:32 -07001602 int result = acdb_init(adev->snd_card);
1603 if (!result) {
1604 my_data->acdb_initialized = true;
1605 ALOGD("ACDB initialized");
1606 } else {
1607 my_data->acdb_initialized = false;
1608 ALOGD("ACDB initialization failed");
1609 }
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001610 }
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001611
David Linee3fe402017-03-13 10:00:42 -07001612 /* init usb */
1613 audio_extn_usb_init(adev);
1614
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001615 /* init a2dp */
1616 audio_extn_a2dp_init(adev);
1617
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001618 audio_extn_spkr_prot_init(adev);
Haynes Mathew George98c95622014-06-20 19:14:25 -07001619
Ravi Kumar Alamanda76315572015-04-23 13:13:56 -07001620 audio_extn_hwdep_cal_send(adev->snd_card, my_data->acdb_handle);
1621
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001622 /* load csd client */
1623 platform_csd_init(my_data);
1624
David Linee3fe402017-03-13 10:00:42 -07001625 platform_backend_config_init(my_data);
1626
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001627 init_be_dai_name_table(adev);
1628
1629 if (platform_supports_app_type_cfg())
1630 platform_backend_app_type_cfg_init(my_data, adev->mixer);
1631
Eric Laurentb23d5282013-05-14 15:27:20 -07001632 return my_data;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001633
1634init_failed:
1635 if (my_data)
1636 free(my_data);
1637 return NULL;
Eric Laurentb23d5282013-05-14 15:27:20 -07001638}
1639
1640void platform_deinit(void *platform)
1641{
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001642 int32_t dev;
keunhui.park2f7306a2015-07-16 16:48:06 +09001643 struct operator_info *info_item;
1644 struct operator_specific_device *device_item;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001645 struct app_type_entry *ap;
keunhui.park2f7306a2015-07-16 16:48:06 +09001646 struct listnode *node;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001647
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001648 struct platform_data *my_data = (struct platform_data *)platform;
1649 close_csd_client(my_data->csd);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001650
vivek mehtade4849c2016-03-03 17:23:38 -08001651 hw_info_deinit(my_data->hw_info);
1652
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001653 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1654 if (backend_tag_table[dev])
1655 free(backend_tag_table[dev]);
1656 if (hw_interface_table[dev])
1657 free(hw_interface_table[dev]);
keunhui.park2f7306a2015-07-16 16:48:06 +09001658 if (operator_specific_device_table[dev]) {
1659 while (!list_empty(operator_specific_device_table[dev])) {
1660 node = list_head(operator_specific_device_table[dev]);
1661 list_remove(node);
1662 device_item = node_to_item(node, struct operator_specific_device, list);
1663 free(device_item->operator);
1664 free(device_item->mixer_path);
1665 free(device_item);
1666 }
1667 free(operator_specific_device_table[dev]);
1668 }
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001669 }
1670
1671 if (my_data->snd_card_name)
1672 free(my_data->snd_card_name);
1673
keunhui.park2f7306a2015-07-16 16:48:06 +09001674 while (!list_empty(&operator_info_list)) {
1675 node = list_head(&operator_info_list);
1676 list_remove(node);
1677 info_item = node_to_item(node, struct operator_info, list);
1678 free(info_item->name);
1679 free(info_item->mccmnc);
1680 free(info_item);
1681 }
1682
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001683 while (!list_empty(&app_type_entry_list)) {
1684 node = list_head(&app_type_entry_list);
1685 list_remove(node);
1686 ap = node_to_item(node, struct app_type_entry, node);
vivek mehtaa68fea62017-06-08 19:04:02 -07001687 if (ap->mode) free(ap->mode);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001688 free(ap);
1689 }
1690
Kevin Rocarde35d4af2017-05-02 16:55:28 -07001691 mixer_close(my_data->adev->mixer);
Eric Laurentb23d5282013-05-14 15:27:20 -07001692 free(platform);
David Linee3fe402017-03-13 10:00:42 -07001693
1694 /* deinit usb */
1695 audio_extn_usb_deinit();
Eric Laurentb23d5282013-05-14 15:27:20 -07001696}
1697
1698const char *platform_get_snd_device_name(snd_device_t snd_device)
1699{
keunhui.park2f7306a2015-07-16 16:48:06 +09001700 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1701 if (operator_specific_device_table[snd_device] != NULL) {
1702 return get_operator_specific_device_mixer_path(snd_device);
1703 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001704 return device_table[snd_device];
keunhui.park2f7306a2015-07-16 16:48:06 +09001705 } else
Ravi Kumar Alamanda64026462014-09-15 00:08:58 -07001706 return "none";
Eric Laurentb23d5282013-05-14 15:27:20 -07001707}
1708
vivek mehtade4849c2016-03-03 17:23:38 -08001709int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
1710 char *device_name)
1711{
1712 struct platform_data *my_data = (struct platform_data *)platform;
1713
David Benjamin1565f992016-09-21 12:10:34 -04001714 if (platform == NULL) {
vivek mehtade4849c2016-03-03 17:23:38 -08001715 ALOGW("%s: something wrong, use legacy get_snd_device name", __func__);
David Benjamin1565f992016-09-21 12:10:34 -04001716 strlcpy(device_name, platform_get_snd_device_name(snd_device),
1717 DEVICE_NAME_MAX_SIZE);
vivek mehtade4849c2016-03-03 17:23:38 -08001718 } else if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1719 if (operator_specific_device_table[snd_device] != NULL) {
1720 strlcpy(device_name, get_operator_specific_device_mixer_path(snd_device),
1721 DEVICE_NAME_MAX_SIZE);
1722 } else {
1723 strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE);
1724 }
1725 hw_info_append_hw_type(my_data->hw_info, snd_device, device_name);
1726 } else {
1727 strlcpy(device_name, "none", DEVICE_NAME_MAX_SIZE);
1728 }
1729
1730 return 0;
1731}
1732
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001733void platform_add_backend_name(void *platform, char *mixer_path,
1734 snd_device_t snd_device)
Eric Laurentb23d5282013-05-14 15:27:20 -07001735{
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001736 struct platform_data *my_data = (struct platform_data *)platform;
1737
Haynes Mathew George98c95622014-06-20 19:14:25 -07001738 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1739 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1740 return;
Ravi Kumar Alamanda1de6e5a2014-06-19 21:55:39 -05001741 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001742
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001743 const char * suffix = backend_tag_table[snd_device];
Haynes Mathew George98c95622014-06-20 19:14:25 -07001744
1745 if (suffix != NULL) {
1746 strcat(mixer_path, " ");
1747 strcat(mixer_path, suffix);
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001748 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001749}
1750
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001751bool platform_check_backends_match(snd_device_t snd_device1, snd_device_t snd_device2)
1752{
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001753 ALOGV("%s: snd_device1 = %s, snd_device2 = %s", __func__,
1754 platform_get_snd_device_name(snd_device1),
1755 platform_get_snd_device_name(snd_device2));
1756
1757 if ((snd_device1 < SND_DEVICE_MIN) || (snd_device1 >= SND_DEVICE_MAX)) {
1758 ALOGE("%s: Invalid snd_device = %s", __func__,
1759 platform_get_snd_device_name(snd_device1));
1760 return false;
1761 }
1762 if ((snd_device2 < SND_DEVICE_MIN) || (snd_device2 >= SND_DEVICE_MAX)) {
1763 ALOGE("%s: Invalid snd_device = %s", __func__,
1764 platform_get_snd_device_name(snd_device2));
1765 return false;
1766 }
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07001767
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001768 const char * be_itf1 = hw_interface_table[snd_device1];
1769 const char * be_itf2 = hw_interface_table[snd_device2];
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07001770 /*
1771 hw_interface_table has overrides for a snd_device.
1772 if there is no entry for a device, assume DEFAULT_RX_BACKEND
1773 */
1774 if (be_itf1 == NULL) {
1775 be_itf1 = DEFAULT_RX_BACKEND;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001776 }
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07001777 if (be_itf2 == NULL) {
1778 be_itf2 = DEFAULT_RX_BACKEND;
1779 }
1780 ALOGV("%s: be_itf1 = %s, be_itf2 = %s", __func__, be_itf1, be_itf2);
1781 /*
1782 this takes care of finding a device within a combo device pair as well
1783 */
1784 return strstr(be_itf1, be_itf2) != NULL || strstr(be_itf2, be_itf1) != NULL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001785}
1786
Eric Laurentb23d5282013-05-14 15:27:20 -07001787int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
1788{
1789 int device_id;
1790 if (device_type == PCM_PLAYBACK)
1791 device_id = pcm_device_table[usecase][0];
1792 else
1793 device_id = pcm_device_table[usecase][1];
1794 return device_id;
1795}
1796
Haynes Mathew George98c95622014-06-20 19:14:25 -07001797static int find_index(const struct name_to_index * table, int32_t len,
1798 const char * name)
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001799{
1800 int ret = 0;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001801 int32_t i;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001802
Haynes Mathew George98c95622014-06-20 19:14:25 -07001803 if (table == NULL) {
1804 ALOGE("%s: table is NULL", __func__);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001805 ret = -ENODEV;
1806 goto done;
1807 }
1808
Haynes Mathew George98c95622014-06-20 19:14:25 -07001809 if (name == NULL) {
1810 ALOGE("null key");
1811 ret = -ENODEV;
1812 goto done;
1813 }
1814
1815 for (i=0; i < len; i++) {
1816 if (!strcmp(table[i].name, name)) {
1817 ret = table[i].index;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001818 goto done;
1819 }
1820 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001821 ALOGE("%s: Could not find index for name = %s",
1822 __func__, name);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001823 ret = -ENODEV;
1824done:
1825 return ret;
1826}
1827
Haynes Mathew George98c95622014-06-20 19:14:25 -07001828int platform_get_snd_device_index(char *device_name)
1829{
1830 return find_index(snd_device_name_index, SND_DEVICE_MAX, device_name);
1831}
1832
1833int platform_get_usecase_index(const char *usecase_name)
1834{
1835 return find_index(usecase_name_index, AUDIO_USECASE_MAX, usecase_name);
1836}
1837
keunhui.park2f7306a2015-07-16 16:48:06 +09001838void platform_add_operator_specific_device(snd_device_t snd_device,
1839 const char *operator,
1840 const char *mixer_path,
1841 unsigned int acdb_id)
1842{
1843 struct operator_specific_device *device;
1844
1845 if (operator_specific_device_table[snd_device] == NULL) {
1846 operator_specific_device_table[snd_device] =
1847 (struct listnode *)calloc(1, sizeof(struct listnode));
1848 list_init(operator_specific_device_table[snd_device]);
1849 }
1850
1851 device = (struct operator_specific_device *)calloc(1, sizeof(struct operator_specific_device));
1852
1853 device->operator = strdup(operator);
1854 device->mixer_path = strdup(mixer_path);
1855 device->acdb_id = acdb_id;
1856
1857 list_add_tail(operator_specific_device_table[snd_device], &device->list);
1858
Eric Laurent2bafff12016-03-17 12:17:23 -07001859 ALOGD("%s: device[%s] -> operator[%s] mixer_path[%s] acdb_id[%d]", __func__,
keunhui.park2f7306a2015-07-16 16:48:06 +09001860 platform_get_snd_device_name(snd_device), operator, mixer_path, acdb_id);
1861
1862}
1863
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001864int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
1865{
1866 int ret = 0;
1867
1868 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1869 ALOGE("%s: Invalid snd_device = %d",
1870 __func__, snd_device);
1871 ret = -EINVAL;
1872 goto done;
1873 }
1874
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001875 ALOGV("%s: acdb_device_table[%s]: old = %d new = %d", __func__,
1876 platform_get_snd_device_name(snd_device), acdb_device_table[snd_device], acdb_id);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001877 acdb_device_table[snd_device] = acdb_id;
1878done:
1879 return ret;
1880}
1881
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001882int platform_get_snd_device_acdb_id(snd_device_t snd_device)
1883{
1884 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1885 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1886 return -EINVAL;
1887 }
keunhui.park2f7306a2015-07-16 16:48:06 +09001888
1889 if (operator_specific_device_table[snd_device] != NULL)
1890 return get_operator_specific_device_acdb_id(snd_device);
1891 else
1892 return acdb_device_table[snd_device];
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001893}
1894
David Linee3fe402017-03-13 10:00:42 -07001895static int platform_get_backend_index(snd_device_t snd_device)
1896{
1897 int32_t port = DEFAULT_CODEC_BACKEND;
1898
1899 if (snd_device >= SND_DEVICE_OUT_BEGIN && snd_device < SND_DEVICE_OUT_END) {
1900 if (backend_tag_table[snd_device] != NULL) {
1901 if (strncmp(backend_tag_table[snd_device], "headphones",
1902 sizeof("headphones")) == 0)
1903 port = HEADPHONE_BACKEND;
1904 else if (strcmp(backend_tag_table[snd_device], "hdmi") == 0)
1905 port = HDMI_RX_BACKEND;
1906 else if ((strcmp(backend_tag_table[snd_device], "usb-headphones") == 0) ||
1907 (strcmp(backend_tag_table[snd_device], "usb-headset") == 0))
1908 port = USB_AUDIO_RX_BACKEND;
1909 }
1910 } else if (snd_device >= SND_DEVICE_IN_BEGIN && snd_device < SND_DEVICE_IN_END) {
1911 port = DEFAULT_CODEC_TX_BACKEND;
1912 if (backend_tag_table[snd_device] != NULL) {
1913 if (strcmp(backend_tag_table[snd_device], "usb-headset-mic") == 0)
1914 port = USB_AUDIO_TX_BACKEND;
1915 else if (strstr(backend_tag_table[snd_device], "bt-sco") != NULL)
1916 port = BT_SCO_TX_BACKEND;
1917 }
1918 } else {
1919 ALOGW("%s:napb: Invalid device - %d ", __func__, snd_device);
1920 }
1921
1922 ALOGV("%s:napb: backend port - %d device - %d ", __func__, port, snd_device);
1923
1924 return port;
1925}
1926
Eric Laurentb23d5282013-05-14 15:27:20 -07001927int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
1928{
1929 struct platform_data *my_data = (struct platform_data *)platform;
1930 int acdb_dev_id, acdb_dev_type;
1931
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001932 if (platform_supports_app_type_cfg()) // use v2 instead
1933 return -ENOSYS;
1934
Ravi Kumar Alamandaadf0f3b2015-06-04 02:34:02 -07001935 acdb_dev_id = acdb_device_table[audio_extn_get_spkr_prot_snd_device(snd_device)];
Eric Laurentb23d5282013-05-14 15:27:20 -07001936 if (acdb_dev_id < 0) {
1937 ALOGE("%s: Could not find acdb id for device(%d)",
1938 __func__, snd_device);
1939 return -EINVAL;
1940 }
1941 if (my_data->acdb_send_audio_cal) {
Joe Onorato188b6222016-03-01 11:02:27 -08001942 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Eric Laurentb23d5282013-05-14 15:27:20 -07001943 __func__, snd_device, acdb_dev_id);
1944 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
1945 snd_device < SND_DEVICE_OUT_END)
1946 acdb_dev_type = ACDB_DEV_TYPE_OUT;
1947 else
1948 acdb_dev_type = ACDB_DEV_TYPE_IN;
1949 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
1950 }
1951 return 0;
1952}
1953
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001954int platform_send_audio_calibration_v2(void *platform, struct audio_usecase *usecase,
1955 int app_type, int sample_rate)
1956{
1957 struct platform_data *my_data = (struct platform_data *)platform;
1958 int acdb_dev_id, acdb_dev_type;
vivek mehta7e573672018-03-13 17:41:41 -07001959 int snd_device = usecase->out_snd_device;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001960 int new_snd_device[SND_DEVICE_OUT_END] = {0};
1961 int i, num_devices = 1;
1962
1963 if (!platform_supports_app_type_cfg()) // use v1 instead
1964 return -ENOSYS;
1965
vivek mehta7e573672018-03-13 17:41:41 -07001966 if ((usecase->type == PCM_HFP_CALL) || (usecase->type == PCM_CAPTURE))
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001967 snd_device = usecase->in_snd_device;
1968
1969 // skipped over get_spkr_prot_device
vivek mehta7e573672018-03-13 17:41:41 -07001970 acdb_dev_id = acdb_device_table[audio_extn_get_spkr_prot_snd_device(snd_device)];
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001971 if (acdb_dev_id < 0) {
1972 ALOGE("%s: Could not find acdb id for device(%d)",
1973 __func__, snd_device);
1974 return -EINVAL;
1975 }
1976
1977 if (platform_can_split_snd_device(snd_device,
1978 &num_devices, new_snd_device) < 0) {
1979 new_snd_device[0] = snd_device;
1980 }
1981
1982 for (i = 0; i < num_devices; i++) {
vivek mehta7e573672018-03-13 17:41:41 -07001983 acdb_dev_id = acdb_device_table[audio_extn_get_spkr_prot_snd_device(new_snd_device[i])];
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001984 if (acdb_dev_id < 0) {
1985 ALOGE("%s: Could not find acdb id for device(%d)",
1986 __func__, new_snd_device[i]);
1987 return -EINVAL;
1988 }
1989 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
1990 __func__, new_snd_device[i], acdb_dev_id);
1991 if (new_snd_device[i] >= SND_DEVICE_OUT_BEGIN &&
1992 new_snd_device[i] < SND_DEVICE_OUT_END)
1993 acdb_dev_type = ACDB_DEV_TYPE_OUT;
1994 else
1995 acdb_dev_type = ACDB_DEV_TYPE_IN;
1996
1997 if (my_data->acdb_send_audio_cal_v3) {
1998 my_data->acdb_send_audio_cal_v3(acdb_dev_id, acdb_dev_type,
1999 app_type, sample_rate, i);
2000 } else if (my_data->acdb_send_audio_cal) {
2001 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type); // this version differs from internal
2002 }
2003 }
2004
2005 return 0;
2006}
2007
2008
Eric Laurentb23d5282013-05-14 15:27:20 -07002009int platform_switch_voice_call_device_pre(void *platform)
2010{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002011 struct platform_data *my_data = (struct platform_data *)platform;
2012 int ret = 0;
2013
2014 if (my_data->csd != NULL &&
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002015 voice_is_in_call(my_data->adev)) {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002016 /* This must be called before disabling mixer controls on APQ side */
2017 ret = my_data->csd->disable_device();
2018 if (ret < 0) {
2019 ALOGE("%s: csd_client_disable_device, failed, error %d",
2020 __func__, ret);
2021 }
2022 }
2023 return ret;
2024}
2025
2026int platform_switch_voice_call_enable_device_config(void *platform,
2027 snd_device_t out_snd_device,
2028 snd_device_t in_snd_device)
2029{
2030 struct platform_data *my_data = (struct platform_data *)platform;
2031 int acdb_rx_id, acdb_tx_id;
2032 int ret = 0;
2033
2034 if (my_data->csd == NULL)
2035 return ret;
2036
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07002037 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
2038 audio_extn_spkr_prot_is_enabled())
keunhui.park2f7306a2015-07-16 16:48:06 +09002039 acdb_rx_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_SPEAKER_PROTECTED);
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07002040 else
keunhui.park2f7306a2015-07-16 16:48:06 +09002041 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002042
keunhui.park2f7306a2015-07-16 16:48:06 +09002043 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002044
2045 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
2046 ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
2047 if (ret < 0) {
2048 ALOGE("%s: csd_enable_device_config, failed, error %d",
2049 __func__, ret);
2050 }
2051 } else {
2052 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2053 acdb_rx_id, acdb_tx_id);
2054 }
2055
2056 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002057}
2058
2059int platform_switch_voice_call_device_post(void *platform,
2060 snd_device_t out_snd_device,
2061 snd_device_t in_snd_device)
2062{
2063 struct platform_data *my_data = (struct platform_data *)platform;
2064 int acdb_rx_id, acdb_tx_id;
2065
2066 if (my_data->acdb_send_voice_cal == NULL) {
2067 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
2068 } else {
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07002069 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
2070 audio_extn_spkr_prot_is_enabled())
2071 out_snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED;
2072
keunhui.park2f7306a2015-07-16 16:48:06 +09002073 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
2074 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07002075
2076 if (acdb_rx_id > 0 && acdb_tx_id > 0)
2077 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
2078 else
2079 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2080 acdb_rx_id, acdb_tx_id);
2081 }
2082
2083 return 0;
2084}
2085
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002086int platform_switch_voice_call_usecase_route_post(void *platform,
2087 snd_device_t out_snd_device,
2088 snd_device_t in_snd_device)
2089{
2090 struct platform_data *my_data = (struct platform_data *)platform;
2091 int acdb_rx_id, acdb_tx_id;
2092 int ret = 0;
2093
2094 if (my_data->csd == NULL)
2095 return ret;
2096
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07002097 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
2098 audio_extn_spkr_prot_is_enabled())
keunhui.park2f7306a2015-07-16 16:48:06 +09002099 acdb_rx_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED);
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07002100 else
keunhui.park2f7306a2015-07-16 16:48:06 +09002101 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002102
keunhui.park2f7306a2015-07-16 16:48:06 +09002103 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002104
2105 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
2106 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
2107 my_data->adev->acdb_settings);
2108 if (ret < 0) {
2109 ALOGE("%s: csd_enable_device, failed, error %d", __func__, ret);
2110 }
2111 } else {
2112 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2113 acdb_rx_id, acdb_tx_id);
2114 }
2115
2116 return ret;
2117}
2118
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002119int platform_start_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07002120{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002121 struct platform_data *my_data = (struct platform_data *)platform;
2122 int ret = 0;
2123
2124 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002125 ret = my_data->csd->start_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002126 if (ret < 0) {
2127 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
2128 }
2129 }
2130 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002131}
2132
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002133int platform_stop_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07002134{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002135 struct platform_data *my_data = (struct platform_data *)platform;
2136 int ret = 0;
2137
2138 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002139 ret = my_data->csd->stop_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002140 if (ret < 0) {
2141 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
2142 }
2143 }
2144 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002145}
2146
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002147int platform_get_sample_rate(void *platform, uint32_t *rate)
2148{
2149 struct platform_data *my_data = (struct platform_data *)platform;
2150 int ret = 0;
2151
2152 if (my_data->csd != NULL) {
2153 ret = my_data->csd->get_sample_rate(rate);
2154 if (ret < 0) {
2155 ALOGE("%s: csd_get_sample_rate error %d\n", __func__, ret);
2156 }
2157 }
2158 return ret;
2159}
2160
vivek mehtab6506412015-08-07 16:55:17 -07002161void platform_set_speaker_gain_in_combo(struct audio_device *adev,
2162 snd_device_t snd_device,
2163 bool enable)
2164{
2165 const char* name;
2166 switch (snd_device) {
2167 case SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES:
2168 if (enable)
2169 name = "spkr-gain-in-headphone-combo";
2170 else
2171 name = "speaker-gain-default";
2172 break;
2173 case SND_DEVICE_OUT_SPEAKER_AND_LINE:
2174 if (enable)
2175 name = "spkr-gain-in-line-combo";
2176 else
2177 name = "speaker-gain-default";
2178 break;
2179 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES:
2180 if (enable)
2181 name = "spkr-safe-gain-in-headphone-combo";
2182 else
2183 name = "speaker-safe-gain-default";
2184 break;
2185 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE:
2186 if (enable)
2187 name = "spkr-safe-gain-in-line-combo";
2188 else
2189 name = "speaker-safe-gain-default";
2190 break;
2191 default:
2192 return;
2193 }
2194
2195 audio_route_apply_and_update_path(adev->audio_route, name);
2196}
2197
Eric Laurentb23d5282013-05-14 15:27:20 -07002198int platform_set_voice_volume(void *platform, int volume)
2199{
2200 struct platform_data *my_data = (struct platform_data *)platform;
2201 struct audio_device *adev = my_data->adev;
2202 struct mixer_ctl *ctl;
sangwoo53b2cf02013-07-25 19:18:44 -07002203 const char *mixer_ctl_name = "Voice Rx Gain";
Nadav Barc46d0fa2017-12-24 14:50:37 +02002204 const char *mute_mixer_ctl_name = "Voice Rx Device Mute";
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002205 int vol_index = 0, ret = 0;
2206 uint32_t set_values[ ] = {0,
2207 ALL_SESSION_VSID,
2208 DEFAULT_VOLUME_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07002209
2210 // Voice volume levels are mapped to adsp volume levels as follows.
2211 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
2212 // But this values don't changed in kernel. So, below change is need.
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09002213 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, my_data->max_vol_index);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002214 set_values[0] = vol_index;
Eric Laurentb23d5282013-05-14 15:27:20 -07002215
2216 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2217 if (!ctl) {
2218 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2219 __func__, mixer_ctl_name);
2220 return -EINVAL;
2221 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002222 ALOGV("Setting voice volume index: %d", set_values[0]);
2223 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2224
Nadav Barc46d0fa2017-12-24 14:50:37 +02002225 // Send mute command in case volume index is max since indexes are inverted
2226 // for mixer controls.
2227 if (vol_index == my_data->max_vol_index) {
2228 set_values[0] = 1;
2229 }
2230 else {
2231 set_values[0] = 0;
2232 }
2233
2234 ctl = mixer_get_ctl_by_name(adev->mixer, mute_mixer_ctl_name);
2235 if (!ctl) {
2236 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2237 __func__, mute_mixer_ctl_name);
2238 return -EINVAL;
2239 }
2240 ALOGV("%s: Setting RX Device Mute to: %d", __func__, set_values[0]);
2241 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2242
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002243 if (my_data->csd != NULL) {
2244 ret = my_data->csd->volume(ALL_SESSION_VSID, volume,
2245 DEFAULT_VOLUME_RAMP_DURATION_MS);
2246 if (ret < 0) {
2247 ALOGE("%s: csd_volume error %d", __func__, ret);
2248 }
2249 }
2250 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002251}
2252
2253int platform_set_mic_mute(void *platform, bool state)
2254{
2255 struct platform_data *my_data = (struct platform_data *)platform;
2256 struct audio_device *adev = my_data->adev;
2257 struct mixer_ctl *ctl;
2258 const char *mixer_ctl_name = "Voice Tx Mute";
sangwoo53b2cf02013-07-25 19:18:44 -07002259 int ret = 0;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002260 uint32_t set_values[ ] = {0,
2261 ALL_SESSION_VSID,
2262 DEFAULT_MUTE_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07002263
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09002264 if (adev->mode != AUDIO_MODE_IN_CALL &&
2265 adev->mode != AUDIO_MODE_IN_COMMUNICATION)
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002266 return 0;
2267
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09002268 if (adev->enable_hfp)
2269 mixer_ctl_name = "HFP Tx Mute";
2270
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002271 set_values[0] = state;
2272 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2273 if (!ctl) {
2274 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2275 __func__, mixer_ctl_name);
2276 return -EINVAL;
2277 }
2278 ALOGV("Setting voice mute state: %d", state);
2279 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2280
2281 if (my_data->csd != NULL) {
2282 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state,
2283 DEFAULT_MUTE_RAMP_DURATION_MS);
sangwoo53b2cf02013-07-25 19:18:44 -07002284 if (ret < 0) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002285 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
sangwoo53b2cf02013-07-25 19:18:44 -07002286 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002287 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002288 return ret;
2289}
Eric Laurentb23d5282013-05-14 15:27:20 -07002290
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002291int platform_set_device_mute(void *platform, bool state, char *dir)
2292{
2293 struct platform_data *my_data = (struct platform_data *)platform;
2294 struct audio_device *adev = my_data->adev;
2295 struct mixer_ctl *ctl;
2296 char *mixer_ctl_name = NULL;
2297 int ret = 0;
2298 uint32_t set_values[ ] = {0,
2299 ALL_SESSION_VSID,
2300 0};
2301 if(dir == NULL) {
2302 ALOGE("%s: Invalid direction:%s", __func__, dir);
2303 return -EINVAL;
2304 }
2305
2306 if (!strncmp("rx", dir, sizeof("rx"))) {
2307 mixer_ctl_name = "Voice Rx Device Mute";
2308 } else if (!strncmp("tx", dir, sizeof("tx"))) {
2309 mixer_ctl_name = "Voice Tx Device Mute";
2310 } else {
2311 return -EINVAL;
2312 }
2313
2314 set_values[0] = state;
2315 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2316 if (!ctl) {
2317 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2318 __func__, mixer_ctl_name);
2319 return -EINVAL;
2320 }
2321
2322 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
2323 __func__,state, mixer_ctl_name);
2324 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2325
2326 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002327}
2328
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002329int platform_can_split_snd_device(snd_device_t snd_device,
2330 int *num_devices,
2331 snd_device_t *new_snd_devices)
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002332{
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002333 int ret = -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002334 if (NULL == num_devices || NULL == new_snd_devices) {
2335 ALOGE("%s: NULL pointer ..", __func__);
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002336 return -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002337 }
2338
2339 /*
2340 * If wired headset/headphones/line devices share the same backend
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002341 * with speaker/earpiece this routine returns -EINVAL.
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002342 */
2343 if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES &&
2344 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_HEADPHONES)) {
2345 *num_devices = 2;
2346 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2347 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002348 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002349 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_LINE &&
2350 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_LINE)) {
2351 *num_devices = 2;
2352 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2353 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002354 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002355 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES &&
2356 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_HEADPHONES)) {
2357 *num_devices = 2;
2358 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2359 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002360 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002361 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE &&
2362 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_LINE)) {
2363 *num_devices = 2;
2364 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2365 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002366 ret = 0;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002367 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO &&
2368 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2369 SND_DEVICE_OUT_BT_SCO)) {
2370 *num_devices = 2;
2371 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2372 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO;
2373 ret = 0;
2374 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB &&
2375 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2376 SND_DEVICE_OUT_BT_SCO_WB)) {
2377 *num_devices = 2;
2378 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2379 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO_WB;
2380 ret = 0;
David Linee3fe402017-03-13 10:00:42 -07002381 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET &&
2382 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_USB_HEADSET)) {
2383 *num_devices = 2;
2384 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2385 new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
2386 ret = 0;
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07002387 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET &&
2388 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_USB_HEADSET)) {
2389 *num_devices = 2;
2390 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2391 new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
2392 ret = 0;
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002393 } else if (SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP == snd_device &&
2394 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2395 SND_DEVICE_OUT_BT_A2DP)) {
2396 *num_devices = 2;
2397 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2398 new_snd_devices[1] = SND_DEVICE_OUT_BT_A2DP;
2399 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002400 }
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002401
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002402 return ret;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002403}
2404
Eric Laurentb23d5282013-05-14 15:27:20 -07002405snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
2406{
2407 struct platform_data *my_data = (struct platform_data *)platform;
2408 struct audio_device *adev = my_data->adev;
2409 audio_mode_t mode = adev->mode;
2410 snd_device_t snd_device = SND_DEVICE_NONE;
2411
2412 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
2413 if (devices == AUDIO_DEVICE_NONE ||
2414 devices & AUDIO_DEVICE_BIT_IN) {
2415 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
2416 goto exit;
2417 }
2418
Eric Laurent1b491552015-09-15 17:52:41 -07002419 if (popcount(devices) == 2) {
2420 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2421 AUDIO_DEVICE_OUT_SPEAKER) ||
2422 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2423 AUDIO_DEVICE_OUT_SPEAKER)) {
2424 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
2425 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2426 AUDIO_DEVICE_OUT_SPEAKER)) {
2427 snd_device = SND_DEVICE_OUT_SPEAKER_AND_LINE;
2428 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2429 AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
2430 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2431 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2432 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES;
2433 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2434 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2435 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE;
2436 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
2437 AUDIO_DEVICE_OUT_SPEAKER)) {
2438 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002439 } else if ((devices & AUDIO_DEVICE_OUT_ALL_SCO) &&
2440 ((devices & ~AUDIO_DEVICE_OUT_ALL_SCO) == AUDIO_DEVICE_OUT_SPEAKER)) {
2441 snd_device = adev->bt_wb_speech_enabled ?
2442 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB :
2443 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO;
Eric Laurent99dab492017-06-17 15:19:08 -07002444 } else if ((devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
2445 AUDIO_DEVICE_OUT_SPEAKER)) ||
2446 (devices == (AUDIO_DEVICE_OUT_USB_HEADSET |
2447 AUDIO_DEVICE_OUT_SPEAKER))) {
David Linee3fe402017-03-13 10:00:42 -07002448 snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET;
Eric Laurentd0f7c262017-07-05 09:09:12 -07002449 } else if ((devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
2450 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) ||
2451 (devices == (AUDIO_DEVICE_OUT_USB_HEADSET |
2452 AUDIO_DEVICE_OUT_SPEAKER_SAFE))) {
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07002453 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET;
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002454 } else if ((devices & AUDIO_DEVICE_OUT_SPEAKER) &&
2455 (devices & AUDIO_DEVICE_OUT_ALL_A2DP)) {
2456 snd_device = SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP;
Eric Laurent1b491552015-09-15 17:52:41 -07002457 } else {
2458 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
2459 goto exit;
2460 }
2461 if (snd_device != SND_DEVICE_NONE) {
2462 goto exit;
2463 }
2464 }
2465
2466 if (popcount(devices) != 1) {
2467 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
2468 goto exit;
2469 }
2470
Madhuri Athota3f6051b2016-10-13 23:25:38 +05302471 if (voice_is_in_call(adev) || adev->enable_voicerx || audio_extn_hfp_is_active(adev)) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002472 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002473 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2474 devices & AUDIO_DEVICE_OUT_LINE) {
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002475 if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002476 (adev->voice.tty_mode == TTY_MODE_FULL))
Eric Laurentb23d5282013-05-14 15:27:20 -07002477 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002478 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002479 (adev->voice.tty_mode == TTY_MODE_VCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002480 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002481 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002482 (adev->voice.tty_mode == TTY_MODE_HCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002483 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002484 else {
2485 if (devices & AUDIO_DEVICE_OUT_LINE)
2486 snd_device = SND_DEVICE_OUT_VOICE_LINE;
2487 else
2488 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
2489 }
Eric Laurent99dab492017-06-17 15:19:08 -07002490 } else if (audio_is_usb_out_device(devices)) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002491 if (voice_is_in_call(adev)) {
2492 switch (adev->voice.tty_mode) {
2493 case TTY_MODE_FULL:
2494 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_USB;
2495 break;
2496 case TTY_MODE_VCO:
2497 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_USB;
2498 break;
2499 case TTY_MODE_HCO:
2500 // since Hearing will be on handset\speaker, use existing device
2501 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
2502 break;
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002503 case TTY_MODE_OFF:
2504 break;
vivek mehtaa6b79742017-03-09 15:40:43 -08002505 default:
2506 ALOGE("%s: Invalid TTY mode (%#x)",
2507 __func__, adev->voice.tty_mode);
2508 }
2509 }
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002510 if (snd_device == SND_DEVICE_NONE) {
2511 snd_device = audio_extn_usb_is_capture_supported() ?
2512 SND_DEVICE_OUT_VOICE_USB_HEADSET :
2513 SND_DEVICE_OUT_VOICE_USB_HEADPHONES;
2514 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002515 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002516 if (adev->bt_wb_speech_enabled) {
2517 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2518 } else {
2519 snd_device = SND_DEVICE_OUT_BT_SCO;
2520 }
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002521 } else if (devices & AUDIO_DEVICE_OUT_ALL_A2DP) {
2522 snd_device = SND_DEVICE_OUT_BT_A2DP;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002523 } else if (devices & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002524 if (!adev->enable_hfp) {
2525 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
2526 } else {
2527 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_HFP;
2528 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002529 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002530 if(adev->voice.hac)
2531 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2532 else if (is_operator_tmus())
Eric Laurentb23d5282013-05-14 15:27:20 -07002533 snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS;
2534 else
Eric Laurentb4d368e2014-06-25 10:21:54 -05002535 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002536 } else if (devices & AUDIO_DEVICE_OUT_TELEPHONY_TX)
2537 snd_device = SND_DEVICE_OUT_VOICE_TX;
2538
Eric Laurentb23d5282013-05-14 15:27:20 -07002539 if (snd_device != SND_DEVICE_NONE) {
2540 goto exit;
2541 }
2542 }
2543
Eric Laurentb23d5282013-05-14 15:27:20 -07002544 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2545 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2546 snd_device = SND_DEVICE_OUT_HEADPHONES;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002547 } else if (devices & AUDIO_DEVICE_OUT_LINE) {
2548 snd_device = SND_DEVICE_OUT_LINE;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002549 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) {
2550 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE;
Eric Laurentb23d5282013-05-14 15:27:20 -07002551 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
andysu5b30b062018-04-20 16:34:06 +08002552 /*
2553 * Perform device switch only if acdb tuning is different between SPEAKER & SPEAKER_REVERSE,
2554 * Or there will be a small pause while performing device switch.
2555 */
2556 if (my_data->speaker_lr_swap &&
2557 (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
2558 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]))
Eric Laurentb23d5282013-05-14 15:27:20 -07002559 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
2560 else
2561 snd_device = SND_DEVICE_OUT_SPEAKER;
2562 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002563 if (adev->bt_wb_speech_enabled) {
2564 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2565 } else {
2566 snd_device = SND_DEVICE_OUT_BT_SCO;
2567 }
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002568 } else if (devices & AUDIO_DEVICE_OUT_ALL_A2DP) {
2569 snd_device = SND_DEVICE_OUT_BT_A2DP;
Eric Laurentb23d5282013-05-14 15:27:20 -07002570 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2571 snd_device = SND_DEVICE_OUT_HDMI ;
Eric Laurent99dab492017-06-17 15:19:08 -07002572 } else if (audio_is_usb_out_device(devices)) {
David Linee3fe402017-03-13 10:00:42 -07002573 if (audio_extn_usb_is_capture_supported())
2574 snd_device = SND_DEVICE_OUT_USB_HEADSET;
2575 else
2576 snd_device = SND_DEVICE_OUT_USB_HEADPHONES;
2577 }else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002578 /*HAC support for voice-ish audio (eg visual voicemail)*/
2579 if(adev->voice.hac)
2580 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2581 else
2582 snd_device = SND_DEVICE_OUT_HANDSET;
Eric Laurentb23d5282013-05-14 15:27:20 -07002583 } else {
2584 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
2585 }
2586exit:
2587 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
2588 return snd_device;
2589}
2590
2591snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
2592{
2593 struct platform_data *my_data = (struct platform_data *)platform;
2594 struct audio_device *adev = my_data->adev;
2595 audio_source_t source = (adev->active_input == NULL) ?
2596 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
2597
2598 audio_mode_t mode = adev->mode;
2599 audio_devices_t in_device = ((adev->active_input == NULL) ?
2600 AUDIO_DEVICE_NONE : adev->active_input->device)
2601 & ~AUDIO_DEVICE_BIT_IN;
2602 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
2603 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
2604 snd_device_t snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002605 int channel_count = popcount(channel_mask);
Eric Laurentb23d5282013-05-14 15:27:20 -07002606
Prashant Malanic92c5962015-08-11 15:10:18 -07002607 ALOGV("%s: enter: out_device(%#x) in_device(%#x) channel_count (%d) channel_mask (0x%x)",
2608 __func__, out_device, in_device, channel_count, channel_mask);
Devin Kimd789e432016-10-26 15:07:27 -07002609 if ((out_device != AUDIO_DEVICE_NONE) && (voice_is_in_call(adev) ||
2610 audio_extn_hfp_is_active(adev))) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002611 if (adev->voice.tty_mode != TTY_MODE_OFF) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002612 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002613 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2614 out_device & AUDIO_DEVICE_OUT_LINE) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002615 switch (adev->voice.tty_mode) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002616 case TTY_MODE_FULL:
2617 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
2618 break;
2619 case TTY_MODE_VCO:
2620 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
2621 break;
2622 case TTY_MODE_HCO:
2623 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
2624 break;
2625 default:
2626 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
2627 }
2628 goto exit;
Eric Laurent99dab492017-06-17 15:19:08 -07002629 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002630 switch (adev->voice.tty_mode) {
2631 case TTY_MODE_FULL:
2632 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC;
2633 break;
2634 case TTY_MODE_VCO:
2635 // since voice will be captured from handset mic, use existing device
2636 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
2637 break;
2638 case TTY_MODE_HCO:
2639 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC;
2640 break;
2641 default:
2642 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
Eric Laurentb23d5282013-05-14 15:27:20 -07002643 }
2644 goto exit;
2645 }
2646 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002647 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002648 if (my_data->fluence_in_voice_call == false) {
2649 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2650 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002651 if (is_operator_tmus())
2652 snd_device = SND_DEVICE_IN_VOICE_DMIC_TMUS;
Eric Laurentb23d5282013-05-14 15:27:20 -07002653 else
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002654 snd_device = SND_DEVICE_IN_VOICE_DMIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002655 }
2656 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2657 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
2658 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002659 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002660 if (adev->bluetooth_nrec)
2661 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2662 else
2663 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002664 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002665 if (adev->bluetooth_nrec)
2666 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2667 else
2668 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002669 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002670 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Prashant Malanic92c5962015-08-11 15:10:18 -07002671 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
2672 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2673 out_device & AUDIO_DEVICE_OUT_LINE) {
2674 if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
2675 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
2676 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
2677 } else {
2678 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2679 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002680 }
vivek mehtafe121d52015-08-10 23:39:23 -07002681
2682 //select default
2683 if (snd_device == SND_DEVICE_NONE) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002684 if (!adev->enable_hfp) {
2685 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2686 } else {
2687 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP;
2688 platform_set_echo_reference(adev, true, out_device);
2689 }
vivek mehtafe121d52015-08-10 23:39:23 -07002690 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002691 } else if (out_device & AUDIO_DEVICE_OUT_TELEPHONY_TX) {
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002692 snd_device = SND_DEVICE_IN_VOICE_RX;
Eric Laurent99dab492017-06-17 15:19:08 -07002693 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
David Lin40b07892017-08-07 15:02:48 -07002694 if (audio_extn_usb_is_capture_supported()) {
2695 snd_device = SND_DEVICE_IN_VOICE_USB_HEADSET_MIC;
2696 } else if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
2697 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
2698 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
2699 } else {
2700 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2701 }
2702 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002703 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002704 } else if (source == AUDIO_SOURCE_CAMCORDER) {
2705 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
2706 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2707 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
2708 }
2709 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
2710 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002711 if (my_data->fluence_in_voice_rec && channel_count == 1) {
2712 if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2713 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002714 if (adev->active_input->enable_aec)
2715 snd_device = SND_DEVICE_IN_HANDSET_QMIC_AEC;
2716 else
2717 snd_device = SND_DEVICE_IN_HANDSET_QMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002718 } else if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2719 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002720 if (adev->active_input->enable_aec)
2721 snd_device = SND_DEVICE_IN_HANDSET_TMIC_AEC;
2722 else
2723 snd_device = SND_DEVICE_IN_HANDSET_TMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002724 } else if (((my_data->fluence_type == FLUENCE_PRO_ENABLE) ||
2725 (my_data->fluence_type == FLUENCE_ENABLE)) &&
2726 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002727 if (adev->active_input->enable_aec)
2728 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
2729 else
2730 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
Prashant Malanic92c5962015-08-11 15:10:18 -07002731 }
2732 platform_set_echo_reference(adev, true, out_device);
2733 } else if ((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) &&
2734 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2735 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002736 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002737 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
2738 snd_device = SND_DEVICE_IN_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002739 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002740 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2741 snd_device = SND_DEVICE_IN_QUAD_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002742 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002743 if (snd_device == SND_DEVICE_NONE) {
vivek mehtaf3440682016-05-11 14:24:37 -07002744 if (adev->active_input->enable_aec) {
2745 if (adev->active_input->enable_ns) {
2746 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS;
2747 } else {
2748 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC;
2749 }
vivek mehta733c1df2016-04-04 15:09:24 -07002750 platform_set_echo_reference(adev, true, out_device);
vivek mehtaf3440682016-05-11 14:24:37 -07002751 } else if (adev->active_input->enable_ns) {
2752 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
2753 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002754 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
vivek mehtaf3440682016-05-11 14:24:37 -07002755 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002756 }
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -07002757 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2758 snd_device = SND_DEVICE_IN_VOICE_REC_HEADSET_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07002759 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002760 snd_device = SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002761 }
rago90fb9612015-12-02 11:37:53 -08002762 } else if (source == AUDIO_SOURCE_UNPROCESSED) {
2763 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
vivek mehta4ed66e62016-04-15 23:33:34 -07002764 if (((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) ||
2765 (channel_mask == AUDIO_CHANNEL_IN_STEREO)) &&
2766 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2767 snd_device = SND_DEVICE_IN_UNPROCESSED_STEREO_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002768 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07002769 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
2770 snd_device = SND_DEVICE_IN_UNPROCESSED_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002771 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07002772 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2773 snd_device = SND_DEVICE_IN_UNPROCESSED_QUAD_MIC;
2774 } else {
2775 snd_device = SND_DEVICE_IN_UNPROCESSED_MIC;
2776 }
rago90fb9612015-12-02 11:37:53 -08002777 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2778 snd_device = SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07002779 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002780 snd_device = SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC;
rago90fb9612015-12-02 11:37:53 -08002781 }
Eric Laurent50a38ed2015-10-14 18:48:06 -07002782 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION ||
rago90fb9612015-12-02 11:37:53 -08002783 mode == AUDIO_MODE_IN_COMMUNICATION) {
David Lin40b07892017-08-07 15:02:48 -07002784 if (out_device & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
2785 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2786 (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE | AUDIO_DEVICE_OUT_USB_HEADSET) &&
2787 !audio_extn_usb_is_capture_supported())) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002788 in_device = AUDIO_DEVICE_IN_BACK_MIC;
David Lin40b07892017-08-07 15:02:48 -07002789 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002790 if (adev->active_input) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002791 if (adev->active_input->enable_aec &&
2792 adev->active_input->enable_ns) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002793 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002794 if (my_data->fluence_in_spkr_mode &&
2795 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002796 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002797 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002798 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002799 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002800 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002801 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002802 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002803 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002804 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002805 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002806 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002807 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002808 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2809 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Eric Laurent99dab492017-06-17 15:19:08 -07002810 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002811 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002812 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002813 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002814 } else if (adev->active_input->enable_aec) {
2815 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2816 if (my_data->fluence_in_spkr_mode &&
2817 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002818 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002819 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002820 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002821 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002822 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002823 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2824 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002825 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002826 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002827 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002828 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002829 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002830 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2831 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Eric Laurent99dab492017-06-17 15:19:08 -07002832 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002833 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
Eric Laurentcefbbac2014-09-04 13:54:10 -05002834 }
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08002835 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002836 } else if (adev->active_input->enable_ns) {
2837 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2838 if (my_data->fluence_in_spkr_mode &&
2839 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002840 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002841 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002842 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002843 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002844 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002845 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2846 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002847 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002848 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002849 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002850 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002851 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002852 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002853 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002854 }
2855 } else if (source == AUDIO_SOURCE_DEFAULT) {
2856 goto exit;
2857 }
2858
2859
2860 if (snd_device != SND_DEVICE_NONE) {
2861 goto exit;
2862 }
2863
2864 if (in_device != AUDIO_DEVICE_NONE &&
2865 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
2866 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
2867 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002868 if ((my_data->source_mic_type & SOURCE_QUAD_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002869 channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002870 snd_device = SND_DEVICE_IN_QUAD_MIC;
2871 } else if ((my_data->source_mic_type & SOURCE_THREE_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002872 channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002873 snd_device = SND_DEVICE_IN_THREE_MIC;
2874 } else if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2875 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002876 snd_device = SND_DEVICE_IN_HANDSET_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002877 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2878 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002879 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002880 } else {
2881 ALOGE("%s: something wrong (1): source type (%d) channel_count (%d) .."
2882 " channel mask (0x%x) no combination found .. setting to mono", __func__,
2883 my_data->source_mic_type, channel_count, channel_mask);
2884 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2885 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002886 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002887 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2888 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002889 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002890 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2891 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002892 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002893 } else {
2894 ALOGE("%s: something wrong (2): source type (%d) channel_count (%d) .."
2895 " no combination found .. setting to mono", __func__,
2896 my_data->source_mic_type, channel_count);
2897 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
2898 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002899 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2900 snd_device = SND_DEVICE_IN_HEADSET_MIC;
2901 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002902 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002903 if (adev->bluetooth_nrec)
2904 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2905 else
2906 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002907 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002908 if (adev->bluetooth_nrec)
2909 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2910 else
2911 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002912 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002913 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
2914 snd_device = SND_DEVICE_IN_HDMI_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07002915 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
David Linee3fe402017-03-13 10:00:42 -07002916 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002917 } else {
2918 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
2919 ALOGW("%s: Using default handset-mic", __func__);
2920 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2921 }
2922 } else {
2923 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
2924 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2925 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2926 snd_device = SND_DEVICE_IN_HEADSET_MIC;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002927 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002928 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002929 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002930 out_device & AUDIO_DEVICE_OUT_LINE) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002931 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2932 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002933 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002934 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2935 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002936 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002937 } else {
2938 ALOGE("%s: something wrong (3): source type (%d) channel_count (%d) .."
2939 " no combination found .. setting to mono", __func__,
2940 my_data->source_mic_type, channel_count);
2941 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
2942 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002943 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002944 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002945 if (adev->bluetooth_nrec)
2946 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2947 else
2948 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002949 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002950 if (adev->bluetooth_nrec)
2951 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2952 else
2953 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002954 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002955 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2956 snd_device = SND_DEVICE_IN_HDMI_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07002957 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
David Linee3fe402017-03-13 10:00:42 -07002958 if (audio_extn_usb_is_capture_supported())
2959 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
2960 else
2961 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002962 } else {
2963 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
2964 ALOGW("%s: Using default handset-mic", __func__);
2965 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2966 }
2967 }
2968exit:
2969 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
2970 return snd_device;
2971}
2972
2973int platform_set_hdmi_channels(void *platform, int channel_count)
2974{
2975 struct platform_data *my_data = (struct platform_data *)platform;
2976 struct audio_device *adev = my_data->adev;
2977 struct mixer_ctl *ctl;
2978 const char *channel_cnt_str = NULL;
2979 const char *mixer_ctl_name = "HDMI_RX Channels";
2980 switch (channel_count) {
2981 case 8:
2982 channel_cnt_str = "Eight"; break;
2983 case 7:
2984 channel_cnt_str = "Seven"; break;
2985 case 6:
2986 channel_cnt_str = "Six"; break;
2987 case 5:
2988 channel_cnt_str = "Five"; break;
2989 case 4:
2990 channel_cnt_str = "Four"; break;
2991 case 3:
2992 channel_cnt_str = "Three"; break;
2993 default:
2994 channel_cnt_str = "Two"; break;
2995 }
2996 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2997 if (!ctl) {
2998 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2999 __func__, mixer_ctl_name);
3000 return -EINVAL;
3001 }
3002 ALOGV("HDMI channel count: %s", channel_cnt_str);
3003 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
3004 return 0;
3005}
3006
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003007int platform_edid_get_max_channels(void *platform)
Eric Laurentb23d5282013-05-14 15:27:20 -07003008{
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003009 struct platform_data *my_data = (struct platform_data *)platform;
3010 struct audio_device *adev = my_data->adev;
Eric Laurentb23d5282013-05-14 15:27:20 -07003011 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
3012 char *sad = block;
3013 int num_audio_blocks;
3014 int channel_count;
3015 int max_channels = 0;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003016 int i, ret, count;
Eric Laurentb23d5282013-05-14 15:27:20 -07003017
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003018 struct mixer_ctl *ctl;
3019
3020 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
3021 if (!ctl) {
3022 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3023 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
Eric Laurentb23d5282013-05-14 15:27:20 -07003024 return 0;
3025 }
3026
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003027 mixer_ctl_update(ctl);
3028
3029 count = mixer_ctl_get_num_values(ctl);
Eric Laurentb23d5282013-05-14 15:27:20 -07003030
3031 /* Read SAD blocks, clamping the maximum size for safety */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003032 if (count > (int)sizeof(block))
3033 count = (int)sizeof(block);
Eric Laurentb23d5282013-05-14 15:27:20 -07003034
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003035 ret = mixer_ctl_get_array(ctl, block, count);
3036 if (ret != 0) {
3037 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
3038 return 0;
3039 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003040
3041 /* Calculate the number of SAD blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003042 num_audio_blocks = count / SAD_BLOCK_SIZE;
Eric Laurentb23d5282013-05-14 15:27:20 -07003043
3044 for (i = 0; i < num_audio_blocks; i++) {
3045 /* Only consider LPCM blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003046 if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
3047 sad += 3;
Eric Laurentb23d5282013-05-14 15:27:20 -07003048 continue;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003049 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003050
3051 channel_count = (sad[0] & 0x7) + 1;
3052 if (channel_count > max_channels)
3053 max_channels = channel_count;
3054
3055 /* Advance to next block */
3056 sad += 3;
3057 }
3058
3059 return max_channels;
3060}
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003061
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07003062int platform_set_incall_recording_session_id(void *platform,
3063 uint32_t session_id, int rec_mode)
3064{
3065 int ret = 0;
3066 struct platform_data *my_data = (struct platform_data *)platform;
3067 struct audio_device *adev = my_data->adev;
3068 struct mixer_ctl *ctl;
3069 const char *mixer_ctl_name = "Voc VSID";
3070 int num_ctl_values;
3071 int i;
3072
3073 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3074 if (!ctl) {
3075 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3076 __func__, mixer_ctl_name);
3077 ret = -EINVAL;
3078 } else {
3079 num_ctl_values = mixer_ctl_get_num_values(ctl);
3080 for (i = 0; i < num_ctl_values; i++) {
3081 if (mixer_ctl_set_value(ctl, i, session_id)) {
3082 ALOGV("Error: invalid session_id: %x", session_id);
3083 ret = -EINVAL;
3084 break;
3085 }
3086 }
3087 }
3088
3089 if (my_data->csd != NULL) {
3090 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
3091 if (ret < 0) {
3092 ALOGE("%s: csd_client_start_record failed, error %d",
3093 __func__, ret);
3094 }
3095 }
3096
3097 return ret;
3098}
3099
3100int platform_stop_incall_recording_usecase(void *platform)
3101{
3102 int ret = 0;
3103 struct platform_data *my_data = (struct platform_data *)platform;
3104
3105 if (my_data->csd != NULL) {
3106 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
3107 if (ret < 0) {
3108 ALOGE("%s: csd_client_stop_record failed, error %d",
3109 __func__, ret);
3110 }
3111 }
3112
3113 return ret;
3114}
3115
3116int platform_start_incall_music_usecase(void *platform)
3117{
3118 int ret = 0;
3119 struct platform_data *my_data = (struct platform_data *)platform;
3120
3121 if (my_data->csd != NULL) {
3122 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
3123 if (ret < 0) {
3124 ALOGE("%s: csd_client_start_playback failed, error %d",
3125 __func__, ret);
3126 }
3127 }
3128
3129 return ret;
3130}
3131
3132int platform_stop_incall_music_usecase(void *platform)
3133{
3134 int ret = 0;
3135 struct platform_data *my_data = (struct platform_data *)platform;
3136
3137 if (my_data->csd != NULL) {
3138 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
3139 if (ret < 0) {
3140 ALOGE("%s: csd_client_stop_playback failed, error %d",
3141 __func__, ret);
3142 }
3143 }
3144
3145 return ret;
3146}
3147
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003148int platform_set_parameters(void *platform, struct str_parms *parms)
3149{
3150 struct platform_data *my_data = (struct platform_data *)platform;
keunhui.park2f7306a2015-07-16 16:48:06 +09003151 char value[128];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003152 char *kv_pairs = str_parms_to_str(parms);
3153 int ret = 0, err;
3154
3155 if (kv_pairs == NULL) {
3156 ret = -EINVAL;
3157 ALOGE("%s: key-value pair is NULL",__func__);
3158 goto done;
3159 }
3160
3161 ALOGV("%s: enter: %s", __func__, kv_pairs);
3162
3163 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME,
3164 value, sizeof(value));
3165 if (err >= 0) {
3166 str_parms_del(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME);
3167 my_data->snd_card_name = strdup(value);
3168 ALOGV("%s: sound card name %s", __func__, my_data->snd_card_name);
3169 }
3170
keunhui.park2f7306a2015-07-16 16:48:06 +09003171 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO,
3172 value, sizeof(value));
3173 if (err >= 0) {
3174 struct operator_info *info;
3175 char *str = value;
3176 char *name;
3177
3178 str_parms_del(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO);
3179 info = (struct operator_info *)calloc(1, sizeof(struct operator_info));
3180 name = strtok(str, ";");
3181 info->name = strdup(name);
3182 info->mccmnc = strdup(str + strlen(name) + 1);
3183
3184 list_add_tail(&operator_info_list, &info->list);
Joe Onorato188b6222016-03-01 11:02:27 -08003185 ALOGV("%s: add operator[%s] mccmnc[%s]", __func__, info->name, info->mccmnc);
keunhui.park2f7306a2015-07-16 16:48:06 +09003186 }
Prashant Malanic92c5962015-08-11 15:10:18 -07003187
3188 memset(value, 0, sizeof(value));
Eric Laurentc6333382015-09-14 12:43:44 -07003189 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT,
Prashant Malanic92c5962015-08-11 15:10:18 -07003190 value, sizeof(value));
3191 if (err >= 0) {
Eric Laurentc6333382015-09-14 12:43:44 -07003192 str_parms_del(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT);
Prashant Malanic92c5962015-08-11 15:10:18 -07003193 my_data->max_mic_count = atoi(value);
3194 ALOGV("%s: max_mic_count %s/%d", __func__, value, my_data->max_mic_count);
Prashant Malanic92c5962015-08-11 15:10:18 -07003195 }
3196
vivek mehta90933872017-06-15 18:04:39 -07003197 // to-do: disable setting sidetone gain, will revist this later
3198 // audio_extn_usb_set_sidetone_gain(parms, value, len);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003199done:
3200 ALOGV("%s: exit with code(%d)", __func__, ret);
3201 if (kv_pairs != NULL)
3202 free(kv_pairs);
3203
3204 return ret;
3205}
3206
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003207/* Delay in Us */
3208int64_t platform_render_latency(audio_usecase_t usecase)
3209{
3210 switch (usecase) {
3211 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
3212 return DEEP_BUFFER_PLATFORM_DELAY;
3213 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
3214 return LOW_LATENCY_PLATFORM_DELAY;
Haynes Mathew George03c40102016-01-29 17:57:48 -08003215 case USECASE_AUDIO_PLAYBACK_ULL:
3216 return ULL_PLATFORM_DELAY;
Eric Laurent0e46adf2016-12-16 12:49:24 -08003217 case USECASE_AUDIO_PLAYBACK_MMAP:
3218 return MMAP_PLATFORM_DELAY;
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003219 default:
3220 return 0;
3221 }
3222}
Haynes Mathew George98c95622014-06-20 19:14:25 -07003223
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003224int platform_set_snd_device_backend(snd_device_t device, const char *backend_tag,
3225 const char * hw_interface)
Haynes Mathew George98c95622014-06-20 19:14:25 -07003226{
3227 int ret = 0;
3228
3229 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
3230 ALOGE("%s: Invalid snd_device = %d",
3231 __func__, device);
3232 ret = -EINVAL;
3233 goto done;
3234 }
3235
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003236 ALOGV("%s: backend_tag_table[%s]: old = %s new = %s", __func__,
3237 platform_get_snd_device_name(device),
3238 backend_tag_table[device] != NULL ? backend_tag_table[device]: "null", backend_tag);
3239 if (backend_tag_table[device]) {
3240 free(backend_tag_table[device]);
Haynes Mathew George98c95622014-06-20 19:14:25 -07003241 }
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003242 backend_tag_table[device] = strdup(backend_tag);
3243
3244 if (hw_interface != NULL) {
3245 if (hw_interface_table[device])
3246 free(hw_interface_table[device]);
3247 ALOGV("%s: hw_interface_table[%d] = %s", __func__, device, hw_interface);
3248 hw_interface_table[device] = strdup(hw_interface);
3249 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07003250done:
3251 return ret;
3252}
3253
3254int platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t pcm_id)
3255{
3256 int ret = 0;
3257 if ((usecase <= USECASE_INVALID) || (usecase >= AUDIO_USECASE_MAX)) {
3258 ALOGE("%s: invalid usecase case idx %d", __func__, usecase);
3259 ret = -EINVAL;
3260 goto done;
3261 }
3262
3263 if ((type != 0) && (type != 1)) {
3264 ALOGE("%s: invalid usecase type", __func__);
3265 ret = -EINVAL;
3266 }
vivek mehtaa68fea62017-06-08 19:04:02 -07003267 ALOGV("%s: pcm_device_table[%d %s][%d] = %d", __func__, usecase,
3268 use_case_table[usecase],
3269 type, pcm_id);
Haynes Mathew George98c95622014-06-20 19:14:25 -07003270 pcm_device_table[usecase][type] = pcm_id;
3271done:
3272 return ret;
3273}
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003274
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07003275#define DEFAULT_NOMINAL_SPEAKER_GAIN 20
3276int ramp_speaker_gain(struct audio_device *adev, bool ramp_up, int target_ramp_up_gain) {
3277 // backup_gain: gain to try to set in case of an error during ramp
3278 int start_gain, end_gain, step, backup_gain, i;
3279 bool error = false;
3280 const struct mixer_ctl *ctl;
3281 const char *mixer_ctl_name_gain_left = "Left Speaker Gain";
3282 const char *mixer_ctl_name_gain_right = "Right Speaker Gain";
3283 struct mixer_ctl *ctl_left = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_left);
3284 struct mixer_ctl *ctl_right = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_right);
3285 if (!ctl_left || !ctl_right) {
3286 ALOGE("%s: Could not get ctl for mixer cmd - %s or %s, not applying speaker gain ramp",
3287 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
3288 return -EINVAL;
3289 } else if ((mixer_ctl_get_num_values(ctl_left) != 1)
3290 || (mixer_ctl_get_num_values(ctl_right) != 1)) {
3291 ALOGE("%s: Unexpected num values for mixer cmd - %s or %s, not applying speaker gain ramp",
3292 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
3293 return -EINVAL;
3294 }
3295 if (ramp_up) {
3296 start_gain = 0;
3297 end_gain = target_ramp_up_gain > 0 ? target_ramp_up_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
3298 step = +1;
3299 backup_gain = end_gain;
3300 } else {
3301 // using same gain on left and right
3302 const int left_gain = mixer_ctl_get_value(ctl_left, 0);
3303 start_gain = left_gain > 0 ? left_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
3304 end_gain = 0;
3305 step = -1;
3306 backup_gain = start_gain;
3307 }
3308 for (i = start_gain ; i != (end_gain + step) ; i += step) {
3309 //ALOGV("setting speaker gain to %d", i);
3310 if (mixer_ctl_set_value(ctl_left, 0, i)) {
3311 ALOGE("%s: error setting %s to %d during gain ramp",
3312 __func__, mixer_ctl_name_gain_left, i);
3313 error = true;
3314 break;
3315 }
3316 if (mixer_ctl_set_value(ctl_right, 0, i)) {
3317 ALOGE("%s: error setting %s to %d during gain ramp",
3318 __func__, mixer_ctl_name_gain_right, i);
3319 error = true;
3320 break;
3321 }
3322 usleep(1000);
3323 }
3324 if (error) {
3325 // an error occured during the ramp, let's still try to go back to a safe volume
3326 if (mixer_ctl_set_value(ctl_left, 0, backup_gain)) {
3327 ALOGE("%s: error restoring left gain to %d", __func__, backup_gain);
3328 }
3329 if (mixer_ctl_set_value(ctl_right, 0, backup_gain)) {
3330 ALOGE("%s: error restoring right gain to %d", __func__, backup_gain);
3331 }
3332 }
3333 return start_gain;
3334}
3335
vivek mehtae59cfb22017-06-16 15:57:11 -07003336int platform_set_swap_mixer(struct audio_device *adev, bool swap_channels)
3337{
3338 const char *mixer_ctl_name = "Swap channel";
3339 struct mixer_ctl *ctl;
3340 const char *mixer_path;
3341 struct platform_data *my_data = (struct platform_data *)adev->platform;
3342
3343 // forced to set to swap, but device not rotated ... ignore set
3344 if (swap_channels && !my_data->speaker_lr_swap)
3345 return 0;
3346
3347 ALOGV("%s:", __func__);
3348
3349 if (swap_channels) {
3350 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER_REVERSE);
3351 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
3352 } else {
3353 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER);
3354 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
3355 }
3356
3357 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3358 if (!ctl) {
3359 ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name);
3360 return -EINVAL;
3361 }
3362
3363 if (mixer_ctl_set_value(ctl, 0, swap_channels) < 0) {
3364 ALOGE("%s: Could not set reverse cotrol %d",__func__, swap_channels);
3365 return -EINVAL;
3366 }
3367
3368 ALOGV("platfor_force_swap_channel :: Channel orientation ( %s ) ",
3369 swap_channels?"R --> L":"L --> R");
3370
3371 return 0;
3372}
3373
3374int platform_check_and_set_swap_lr_channels(struct audio_device *adev, bool swap_channels)
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003375{
3376 // only update if there is active pcm playback on speaker
3377 struct audio_usecase *usecase;
3378 struct listnode *node;
3379 struct platform_data *my_data = (struct platform_data *)adev->platform;
3380
vivek mehtae59cfb22017-06-16 15:57:11 -07003381 my_data->speaker_lr_swap = swap_channels;
Jean-Michel Trivif7148702016-09-16 18:23:05 -07003382
vivek mehtae59cfb22017-06-16 15:57:11 -07003383 return platform_set_swap_channels(adev, swap_channels);
3384}
Jean-Michel Trivif7148702016-09-16 18:23:05 -07003385
vivek mehtae59cfb22017-06-16 15:57:11 -07003386int platform_set_swap_channels(struct audio_device *adev, bool swap_channels)
3387{
3388 // only update if there is active pcm playback on speaker
3389 struct audio_usecase *usecase;
3390 struct listnode *node;
3391 struct platform_data *my_data = (struct platform_data *)adev->platform;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003392
vivek mehtae59cfb22017-06-16 15:57:11 -07003393 // do not swap channels in audio modes with concurrent capture and playback
3394 // as this may break the echo reference
3395 if ((adev->mode == AUDIO_MODE_IN_COMMUNICATION) || (adev->mode == AUDIO_MODE_IN_CALL)) {
3396 ALOGV("%s: will not swap due to audio mode %d", __func__, adev->mode);
3397 return 0;
3398 }
3399
3400 list_for_each(node, &adev->usecase_list) {
3401 usecase = node_to_item(node, struct audio_usecase, list);
3402 if (usecase->type == PCM_PLAYBACK &&
3403 usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) {
3404 /*
3405 * If acdb tuning is different for SPEAKER_REVERSE, it is must
3406 * to perform device switch to disable the current backend to
3407 * enable it with new acdb data.
3408 */
3409 if (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
3410 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]) {
3411 const int initial_skpr_gain = ramp_speaker_gain(adev, false /*ramp_up*/, -1);
3412 select_devices(adev, usecase->id);
3413 if (initial_skpr_gain != -EINVAL)
3414 ramp_speaker_gain(adev, true /*ramp_up*/, initial_skpr_gain);
3415
3416 } else {
3417 platform_set_swap_mixer(adev, swap_channels);
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003418 }
vivek mehtae59cfb22017-06-16 15:57:11 -07003419 break;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003420 }
3421 }
vivek mehtae59cfb22017-06-16 15:57:11 -07003422
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003423 return 0;
3424}
vivek mehtaa8d7c922016-05-25 14:40:44 -07003425
3426static struct amp_db_and_gain_table tbl_mapping[MAX_VOLUME_CAL_STEPS];
3427static int num_gain_tbl_entry = 0;
3428
3429bool platform_add_gain_level_mapping(struct amp_db_and_gain_table *tbl_entry) {
3430
3431 ALOGV("%s: enter .. add %f %f %d", __func__, tbl_entry->amp, tbl_entry->db, tbl_entry->level);
3432 if (num_gain_tbl_entry == -1) {
3433 ALOGE("%s: num entry beyond valid step levels or corrupted..rejecting custom mapping",
3434 __func__);
3435 return false;
3436 }
3437
3438 if (num_gain_tbl_entry >= MAX_VOLUME_CAL_STEPS) {
3439 ALOGE("%s: max entry reached max[%d] current index[%d] .. rejecting", __func__,
3440 MAX_VOLUME_CAL_STEPS, num_gain_tbl_entry);
3441 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
3442 return false;
3443 }
3444
3445 if (num_gain_tbl_entry > 0 && tbl_mapping[num_gain_tbl_entry - 1].amp >= tbl_entry->amp) {
3446 ALOGE("%s: value not in ascending order .. rejecting custom mapping", __func__);
3447 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
3448 return false;
3449 }
3450
3451 tbl_mapping[num_gain_tbl_entry] = *tbl_entry;
3452 ++num_gain_tbl_entry;
3453
3454 return true;
3455}
3456
3457int platform_get_gain_level_mapping(struct amp_db_and_gain_table *mapping_tbl,
3458 int table_size) {
3459 int itt = 0;
3460 ALOGV("platform_get_gain_level_mapping called ");
3461
3462 if (num_gain_tbl_entry <= 0 || num_gain_tbl_entry > MAX_VOLUME_CAL_STEPS) {
3463 ALOGD("%s: empty or currupted gain_mapping_table", __func__);
3464 return 0;
3465 }
3466
3467 for (; itt < num_gain_tbl_entry && itt <= table_size; itt++) {
3468 mapping_tbl[itt] = tbl_mapping[itt];
3469 ALOGV("%s: added amp[%f] db[%f] level[%d]", __func__,
3470 mapping_tbl[itt].amp, mapping_tbl[itt].db, mapping_tbl[itt].level);
3471 }
3472
3473 return num_gain_tbl_entry;
3474}
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07003475
3476int platform_snd_card_update(void *platform, card_status_t status)
3477{
3478 struct platform_data *my_data = (struct platform_data *)platform;
3479 struct audio_device *adev = my_data->adev;
3480
3481 if (status == CARD_STATUS_ONLINE) {
3482 if (my_data->acdb_send_custom_top)
3483 my_data->acdb_send_custom_top();
3484 }
3485 return 0;
3486}
David Linee3fe402017-03-13 10:00:42 -07003487
3488/*
3489 * configures afe with bit width and Sample Rate
3490 */
3491static int platform_set_backend_cfg(const struct audio_device* adev,
3492 snd_device_t snd_device,
3493 const struct audio_backend_cfg *backend_cfg)
3494{
3495
3496 int ret = 0;
3497 const int backend_idx = platform_get_backend_index(snd_device);
3498 struct platform_data *my_data = (struct platform_data *)adev->platform;
3499 const unsigned int bit_width = backend_cfg->bit_width;
3500 const unsigned int sample_rate = backend_cfg->sample_rate;
3501 const unsigned int channels = backend_cfg->channels;
3502 const audio_format_t format = backend_cfg->format;
3503 const bool passthrough_enabled = backend_cfg->passthrough_enabled;
3504
3505
3506 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
3507 ", backend_idx %d device (%s)", __func__, bit_width,
3508 sample_rate, channels, backend_idx,
3509 platform_get_snd_device_name(snd_device));
3510
3511 if ((my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl) &&
3512 (bit_width != my_data->current_backend_cfg[backend_idx].bit_width)) {
3513
3514 struct mixer_ctl *ctl = NULL;
3515 ctl = mixer_get_ctl_by_name(adev->mixer,
3516 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
3517 if (!ctl) {
3518 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3519 __func__,
3520 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
3521 return -EINVAL;
3522 }
3523
3524 if (bit_width == 24) {
3525 if (format == AUDIO_FORMAT_PCM_24_BIT_PACKED)
3526 ret = mixer_ctl_set_enum_by_string(ctl, "S24_3LE");
3527 else
3528 ret = mixer_ctl_set_enum_by_string(ctl, "S24_LE");
3529 } else if (bit_width == 32) {
3530 ret = mixer_ctl_set_enum_by_string(ctl, "S32_LE");
3531 } else {
3532 ret = mixer_ctl_set_enum_by_string(ctl, "S16_LE");
3533 }
3534 if ( ret < 0) {
3535 ALOGE("%s:becf: afe: fail for %s mixer set to %d bit for %x format", __func__,
3536 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
3537 } else {
3538 my_data->current_backend_cfg[backend_idx].bit_width = bit_width;
3539 ALOGD("%s:becf: afe: %s mixer set to %d bit for %x format", __func__,
3540 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
3541 }
3542 /* set the ret as 0 and not pass back to upper layer */
3543 ret = 0;
3544 }
3545
3546 if (passthrough_enabled || ((my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl) &&
3547 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate))) {
3548 char *rate_str = NULL;
3549 struct mixer_ctl *ctl = NULL;
3550
3551 switch (sample_rate) {
3552 case 32000:
3553 if (passthrough_enabled) {
3554 rate_str = "KHZ_32";
3555 break;
3556 }
3557 case 8000:
3558 case 11025:
3559 case 16000:
3560 case 22050:
3561 case 48000:
3562 rate_str = "KHZ_48";
3563 break;
3564 case 44100:
3565 rate_str = "KHZ_44P1";
3566 break;
3567 case 64000:
3568 case 96000:
3569 rate_str = "KHZ_96";
3570 break;
3571 case 88200:
3572 rate_str = "KHZ_88P2";
3573 break;
3574 case 176400:
3575 rate_str = "KHZ_176P4";
3576 break;
3577 case 192000:
3578 rate_str = "KHZ_192";
3579 break;
3580 case 352800:
3581 rate_str = "KHZ_352P8";
3582 break;
3583 case 384000:
3584 rate_str = "KHZ_384";
3585 break;
3586 case 144000:
3587 if (passthrough_enabled) {
3588 rate_str = "KHZ_144";
3589 break;
3590 }
3591 default:
3592 rate_str = "KHZ_48";
3593 break;
3594 }
3595
3596 ctl = mixer_get_ctl_by_name(adev->mixer,
3597 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
3598 if(!ctl) {
3599 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3600 __func__,
3601 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
3602 return -EINVAL;
3603 }
3604
3605 ALOGD("%s:becf: afe: %s set to %s", __func__,
3606 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl, rate_str);
3607 mixer_ctl_set_enum_by_string(ctl, rate_str);
3608 my_data->current_backend_cfg[backend_idx].sample_rate = sample_rate;
3609 }
3610 if ((my_data->current_backend_cfg[backend_idx].channels_mixer_ctl) &&
3611 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
3612 struct mixer_ctl *ctl = NULL;
3613 char *channel_cnt_str = NULL;
3614
3615 switch (channels) {
3616 case 8:
3617 channel_cnt_str = "Eight"; break;
3618 case 7:
3619 channel_cnt_str = "Seven"; break;
3620 case 6:
3621 channel_cnt_str = "Six"; break;
3622 case 5:
3623 channel_cnt_str = "Five"; break;
3624 case 4:
3625 channel_cnt_str = "Four"; break;
3626 case 3:
3627 channel_cnt_str = "Three"; break;
3628 case 1:
3629 channel_cnt_str = "One"; break;
3630 case 2:
3631 default:
3632 channel_cnt_str = "Two"; break;
3633 }
3634
3635 ctl = mixer_get_ctl_by_name(adev->mixer,
3636 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
3637 if (!ctl) {
3638 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3639 __func__,
3640 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
3641 return -EINVAL;
3642 }
3643 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
3644 my_data->current_backend_cfg[backend_idx].channels = channels;
3645
3646 // skip EDID configuration for HDMI backend
3647
3648 ALOGD("%s:becf: afe: %s set to %s", __func__,
3649 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl,
3650 channel_cnt_str);
3651 }
3652
3653 // skip set ext_display format mixer control
3654 return ret;
3655}
3656
3657static int platform_get_snd_device_bit_width(snd_device_t snd_device)
3658{
3659 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
3660 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
3661 return CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3662 }
3663
3664 return backend_bit_width_table[snd_device];
3665}
3666
3667/*
3668 * return backend_idx on which voice call is active
3669 */
3670static int platform_get_voice_call_backend(struct audio_device* adev)
3671{
3672 struct audio_usecase *uc = NULL;
3673 struct listnode *node;
3674 snd_device_t out_snd_device = SND_DEVICE_NONE;
3675
3676 int backend_idx = -1;
3677
3678 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
3679 list_for_each(node, &adev->usecase_list) {
3680 uc = node_to_item(node, struct audio_usecase, list);
3681 if (uc && uc->type == VOICE_CALL && uc->stream.out) {
3682 out_snd_device = platform_get_output_snd_device(adev->platform,
3683 uc->stream.out->devices);
3684 backend_idx = platform_get_backend_index(out_snd_device);
3685 break;
3686 }
3687 }
3688 }
3689 return backend_idx;
3690}
3691
3692/*
3693 * goes through all the current usecases and picks the highest
3694 * bitwidth & samplerate
3695 */
3696static bool platform_check_capture_backend_cfg(struct audio_device* adev,
3697 int backend_idx,
3698 struct audio_backend_cfg *backend_cfg)
3699{
3700 bool backend_change = false;
3701 unsigned int bit_width;
3702 unsigned int sample_rate;
3703 unsigned int channels;
3704 struct platform_data *my_data = (struct platform_data *)adev->platform;
3705
3706 bit_width = backend_cfg->bit_width;
3707 sample_rate = backend_cfg->sample_rate;
3708 channels = backend_cfg->channels;
3709
3710 ALOGV("%s:txbecf: afe: Codec selected backend: %d current bit width: %d and "
3711 "sample rate: %d, channels %d",__func__,backend_idx, bit_width,
3712 sample_rate, channels);
3713
3714 // For voice calls use default configuration i.e. 16b/48K, only applicable to
3715 // default backend
3716 // force routing is not required here, caller will do it anyway
3717 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
3718 ALOGW("%s:txbecf: afe: Use default bw and sr for voice/voip calls and "
3719 "for unprocessed/camera source", __func__);
3720 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3721 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3722 }
3723
3724 if (backend_idx == USB_AUDIO_TX_BACKEND) {
3725 audio_extn_usb_is_config_supported(&bit_width, &sample_rate, &channels, false);
3726 ALOGV("%s:txbecf: afe: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
3727 __func__, bit_width, sample_rate, channels);
3728 }
3729
3730 ALOGV("%s:txbecf: afe: Codec selected backend: %d updated bit width: %d and "
3731 "sample rate: %d", __func__, backend_idx, bit_width, sample_rate);
3732
3733 // Force routing if the expected bitwdith or samplerate
3734 // is not same as current backend comfiguration
3735 if ((bit_width != my_data->current_backend_cfg[backend_idx].bit_width) ||
3736 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate) ||
3737 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
3738 backend_cfg->bit_width = bit_width;
3739 backend_cfg->sample_rate= sample_rate;
3740 backend_cfg->channels = channels;
3741 backend_change = true;
3742 ALOGI("%s:txbecf: afe: Codec backend needs to be updated. new bit width: %d "
3743 "new sample rate: %d new channel: %d",
3744 __func__, backend_cfg->bit_width,
3745 backend_cfg->sample_rate, backend_cfg->channels);
3746 }
3747
3748 return backend_change;
3749}
3750
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003751static void pick_playback_cfg_for_uc(struct audio_device *adev,
3752 struct audio_usecase *usecase,
3753 snd_device_t snd_device,
3754 unsigned int *bit_width,
3755 unsigned int *sample_rate,
3756 unsigned int *channels)
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003757{
3758 int i =0;
3759 struct listnode *node;
3760 list_for_each(node, &adev->usecase_list) {
3761 struct audio_usecase *uc;
3762 uc = node_to_item(node, struct audio_usecase, list);
3763 struct stream_out *out = (struct stream_out*) uc->stream.out;
3764 if (uc->type == PCM_PLAYBACK && out && usecase != uc) {
3765 unsigned int out_channels = audio_channel_count_from_out_mask(out->channel_mask);
3766 ALOGV("%s:napb: (%d) - (%s)id (%d) sr %d bw "
3767 "(%d) ch (%d) device %s", __func__, i++, use_case_table[uc->id],
3768 uc->id, out->sample_rate,
3769 pcm_format_to_bits(out->config.format), out_channels,
3770 platform_get_snd_device_name(uc->out_snd_device));
3771
3772 if (platform_check_backends_match(snd_device, uc->out_snd_device)) {
3773 if (*bit_width < pcm_format_to_bits(out->config.format))
3774 *bit_width = pcm_format_to_bits(out->config.format);
3775 if (*sample_rate < out->sample_rate)
3776 *sample_rate = out->sample_rate;
3777 if (out->sample_rate < OUTPUT_SAMPLING_RATE_44100)
3778 *sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3779 if (*channels < out_channels)
3780 *channels = out_channels;
3781 }
3782 }
3783 }
3784 return;
3785}
3786
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003787static void headset_is_config_supported(unsigned int *bit_width,
3788 unsigned int *sample_rate,
3789 unsigned int *channels) {
3790 switch (*bit_width) {
3791 case 16:
3792 case 24:
3793 break;
3794 default:
3795 *bit_width = 16;
3796 break;
3797 }
3798
3799 if (*sample_rate > 192000) {
3800 *sample_rate = 192000;
3801 }
3802
3803 if (*channels > 2) {
3804 *channels = 2;
3805 }
3806}
3807
David Linee3fe402017-03-13 10:00:42 -07003808static bool platform_check_playback_backend_cfg(struct audio_device* adev,
3809 struct audio_usecase* usecase,
3810 snd_device_t snd_device,
3811 struct audio_backend_cfg *backend_cfg)
3812{
3813 bool backend_change = false;
David Linee3fe402017-03-13 10:00:42 -07003814 unsigned int bit_width;
3815 unsigned int sample_rate;
3816 unsigned int channels;
David Linee3fe402017-03-13 10:00:42 -07003817 int backend_idx = DEFAULT_CODEC_BACKEND;
3818 struct platform_data *my_data = (struct platform_data *)adev->platform;
David Linee3fe402017-03-13 10:00:42 -07003819
3820 if (snd_device == SND_DEVICE_OUT_BT_SCO ||
3821 snd_device == SND_DEVICE_OUT_BT_SCO_WB) {
3822 backend_change = false;
3823 return backend_change;
3824 }
3825
3826 backend_idx = platform_get_backend_index(snd_device);
3827 bit_width = backend_cfg->bit_width;
3828 sample_rate = backend_cfg->sample_rate;
3829 channels = backend_cfg->channels;
3830
3831 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
3832 ", backend_idx %d usecase = %d device (%s)", __func__, bit_width,
3833 sample_rate, channels, backend_idx, usecase->id,
3834 platform_get_snd_device_name(snd_device));
3835
3836 if (backend_idx == platform_get_voice_call_backend(adev)) {
3837 ALOGW("%s:becf: afe:Use default bw and sr for voice/voip calls ",
3838 __func__);
3839 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3840 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3841 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
3842 } else {
3843 /*
3844 * The backend should be configured at highest bit width and/or
3845 * sample rate amongst all playback usecases.
3846 * If the selected sample rate and/or bit width differ with
3847 * current backend sample rate and/or bit width, then, we set the
3848 * backend re-configuration flag.
3849 *
3850 * Exception: 16 bit playbacks is allowed through 16 bit/48/44.1 khz backend only
3851 */
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003852 pick_playback_cfg_for_uc(adev, usecase, snd_device,
3853 &bit_width,
3854 &sample_rate,
3855 &channels);
David Linee3fe402017-03-13 10:00:42 -07003856 }
3857
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003858 switch (backend_idx) {
3859 case USB_AUDIO_RX_BACKEND:
3860 audio_extn_usb_is_config_supported(&bit_width,
3861 &sample_rate, &channels, true);
3862 ALOGV("%s: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
3863 __func__, bit_width, sample_rate, channels);
3864 break;
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003865 case HEADPHONE_BACKEND:
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003866 headset_is_config_supported(&bit_width, &sample_rate, &channels);
3867 break;
3868 case DEFAULT_CODEC_BACKEND:
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003869 default:
3870 bit_width = platform_get_snd_device_bit_width(snd_device);
3871 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3872 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
3873 break;
David Linee3fe402017-03-13 10:00:42 -07003874 }
3875
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003876 ALOGV("%s:becf: afe: Codec selected backend: %d updated bit width: %d and"
3877 "sample rate: %d",
David Linee3fe402017-03-13 10:00:42 -07003878 __func__, backend_idx , bit_width, sample_rate);
3879
3880 // Force routing if the expected bitwdith or samplerate
3881 // is not same as current backend comfiguration
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003882 if (bit_width != my_data->current_backend_cfg[backend_idx].bit_width ||
3883 sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate ||
3884 channels != my_data->current_backend_cfg[backend_idx].channels) {
David Linee3fe402017-03-13 10:00:42 -07003885 backend_cfg->bit_width = bit_width;
3886 backend_cfg->sample_rate = sample_rate;
3887 backend_cfg->channels = channels;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003888 backend_cfg->passthrough_enabled = false;
David Linee3fe402017-03-13 10:00:42 -07003889 backend_change = true;
3890 ALOGV("%s:becf: afe: Codec backend needs to be updated. new bit width: %d"
3891 "new sample rate: %d new channels: %d",
3892 __func__, backend_cfg->bit_width, backend_cfg->sample_rate, backend_cfg->channels);
3893 }
3894
3895 return backend_change;
3896}
3897
3898bool platform_check_and_set_playback_backend_cfg(struct audio_device* adev,
3899 struct audio_usecase *usecase, snd_device_t snd_device)
3900{
3901 int backend_idx = DEFAULT_CODEC_BACKEND;
3902 int new_snd_devices[SND_DEVICE_OUT_END];
3903 int i, num_devices = 1;
3904 bool ret = false;
3905 struct platform_data *my_data = (struct platform_data *)adev->platform;
3906 struct audio_backend_cfg backend_cfg;
3907
3908 backend_idx = platform_get_backend_index(snd_device);
3909
3910 backend_cfg.bit_width = pcm_format_to_bits(usecase->stream.out->config.format);
3911 backend_cfg.sample_rate = usecase->stream.out->sample_rate;
3912 backend_cfg.format = usecase->stream.out->format;
3913 backend_cfg.channels = audio_channel_count_from_out_mask(usecase->stream.out->channel_mask);
3914 /*this is populated by check_codec_backend_cfg hence set default value to false*/
3915 backend_cfg.passthrough_enabled = false;
3916
3917 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
3918 ", backend_idx %d usecase = %d device (%s)", __func__, backend_cfg.bit_width,
3919 backend_cfg.sample_rate, backend_cfg.channels, backend_idx, usecase->id,
3920 platform_get_snd_device_name(snd_device));
3921
3922 if (platform_can_split_snd_device(snd_device, &num_devices, new_snd_devices) < 0)
3923 new_snd_devices[0] = snd_device;
3924
3925 for (i = 0; i < num_devices; i++) {
3926 ALOGV("%s: new_snd_devices[%d] is %d", __func__, i, new_snd_devices[i]);
3927 if ((platform_check_playback_backend_cfg(adev, usecase, new_snd_devices[i],
3928 &backend_cfg))) {
3929 platform_set_backend_cfg(adev, new_snd_devices[i],
3930 &backend_cfg);
3931 ret = true;
3932 }
3933 }
3934 return ret;
3935}
3936
3937bool platform_check_and_set_capture_backend_cfg(struct audio_device* adev,
3938 struct audio_usecase *usecase, snd_device_t snd_device)
3939{
3940 int backend_idx = platform_get_backend_index(snd_device);
3941 int ret = 0;
3942 struct audio_backend_cfg backend_cfg;
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003943 memset(&backend_cfg, 0, sizeof(struct audio_backend_cfg));
David Linee3fe402017-03-13 10:00:42 -07003944
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003945 if (usecase->type == PCM_CAPTURE) {
3946 backend_cfg.format = usecase->stream.in->format;
David Linee3fe402017-03-13 10:00:42 -07003947 backend_cfg.channels = audio_channel_count_from_in_mask(usecase->stream.in->channel_mask);
3948 } else {
3949 backend_cfg.bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3950 backend_cfg.sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3951 backend_cfg.format = AUDIO_FORMAT_PCM_16_BIT;
3952 backend_cfg.channels = 1;
3953 }
3954
3955 ALOGV("%s:txbecf: afe: bitwidth %d, samplerate %d, channel %d"
3956 ", backend_idx %d usecase = %d device (%s)", __func__,
3957 backend_cfg.bit_width,
3958 backend_cfg.sample_rate,
3959 backend_cfg.channels,
3960 backend_idx, usecase->id,
3961 platform_get_snd_device_name(snd_device));
3962
3963 if (platform_check_capture_backend_cfg(adev, backend_idx, &backend_cfg)) {
3964 ret = platform_set_backend_cfg(adev, snd_device,
3965 &backend_cfg);
3966 if(!ret)
3967 return true;
3968 }
3969
3970 return false;
3971}
3972
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003973static int max_be_dai_names = 0;
3974static const struct be_dai_name_struct *be_dai_name_table;
3975
3976/*
3977 * Retrieves the be_dai_name_table from kernel to enable a mapping
3978 * between sound device hw interfaces and backend IDs. This allows HAL to
3979 * specify the backend a specific calibration is needed for.
3980 */
3981static int init_be_dai_name_table(struct audio_device *adev)
3982{
3983 const char *mixer_ctl_name = "Backend DAI Name Table";
3984 struct mixer_ctl *ctl;
3985 int i, j, ret, size;
3986 bool valid_hw_interface;
3987
3988 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3989 if (!ctl) {
3990 ALOGE("%s: Could not get ctl for mixer name %s\n",
3991 __func__, mixer_ctl_name);
3992 ret = -EINVAL;
3993 goto done;
3994 }
3995
3996 mixer_ctl_update(ctl);
3997
3998 size = mixer_ctl_get_num_values(ctl);
3999 if (size <= 0){
4000 ALOGE("%s: Failed to get %s size %d\n",
4001 __func__, mixer_ctl_name, size);
4002 ret = -EFAULT;
4003 goto done;
4004 }
4005
vivek mehtaa68fea62017-06-08 19:04:02 -07004006 be_dai_name_table =
4007 (const struct be_dai_name_struct *)calloc(1, size);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004008 if (be_dai_name_table == NULL) {
4009 ALOGE("%s: Failed to allocate memory for %s\n",
4010 __func__, mixer_ctl_name);
4011 ret = -ENOMEM;
4012 goto freeMem;
4013 }
4014
4015 ret = mixer_ctl_get_array(ctl, (void *)be_dai_name_table, size);
4016 if (ret) {
4017 ALOGE("%s: Failed to get %s, ret %d\n",
4018 __func__, mixer_ctl_name, ret);
4019 ret = -EFAULT;
4020 goto freeMem;
4021 }
4022
4023 if (be_dai_name_table != NULL) {
4024 max_be_dai_names = size / sizeof(struct be_dai_name_struct);
4025 ALOGV("%s: Successfully got %s, number of be dais is %d\n",
4026 __func__, mixer_ctl_name, max_be_dai_names);
4027 ret = 0;
4028 } else {
4029 ALOGE("%s: Failed to get %s\n", __func__, mixer_ctl_name);
4030 ret = -EFAULT;
4031 goto freeMem;
4032 }
4033
4034 /*
4035 * Validate all sound devices have a valid backend set to catch
4036 * errors for uncommon sound devices
4037 */
4038 for (i = 0; i < SND_DEVICE_MAX; i++) {
4039 valid_hw_interface = false;
4040
4041 if (hw_interface_table[i] == NULL) {
4042 ALOGW("%s: sound device %s has no hw interface set\n",
4043 __func__, platform_get_snd_device_name(i));
4044 continue;
4045 }
4046
4047 for (j = 0; j < max_be_dai_names; j++) {
4048 if (strcmp(hw_interface_table[i], be_dai_name_table[j].be_name)
4049 == 0) {
4050 valid_hw_interface = true;
4051 break;
4052 }
4053 }
4054 if (!valid_hw_interface)
4055 ALOGD("%s: sound device %s does not have a valid hw interface set "
4056 "(disregard for combo devices) %s\n",
4057 __func__, platform_get_snd_device_name(i),
4058 hw_interface_table[i]);
4059 }
4060
4061 goto done;
4062
4063freeMem:
4064 if (be_dai_name_table) {
4065 free((void *)be_dai_name_table);
4066 be_dai_name_table = NULL;
4067 }
4068
4069done:
4070 return ret;
4071}
4072
4073int platform_get_snd_device_backend_index(snd_device_t device)
4074{
4075 int i, be_dai_id;
4076 const char * hw_interface_name = NULL;
4077
4078 ALOGV("%s: enter with device %d\n", __func__, device);
4079
vivek mehtaa68fea62017-06-08 19:04:02 -07004080 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004081 ALOGE("%s: Invalid snd_device = %d",
4082 __func__, device);
4083 be_dai_id = -EINVAL;
4084 goto done;
4085 }
4086
4087 /* Get string value of necessary backend for device */
4088 hw_interface_name = hw_interface_table[device];
4089 if (hw_interface_name == NULL) {
4090 ALOGE("%s: no hw_interface set for device %d\n", __func__, device);
4091 be_dai_id = -EINVAL;
4092 goto done;
4093 }
4094
4095 /* Check if be dai name table was retrieved successfully */
4096 if (be_dai_name_table == NULL) {
4097 ALOGE("%s: BE DAI Name Table is not present\n", __func__);
4098 be_dai_id = -EFAULT;
4099 goto done;
4100 }
4101
4102 /* Get backend ID for device specified */
4103 for (i = 0; i < max_be_dai_names; i++) {
4104 if (strcmp(hw_interface_name, be_dai_name_table[i].be_name) == 0) {
4105 be_dai_id = be_dai_name_table[i].be_id;
4106 goto done;
4107 }
4108 }
4109 ALOGE("%s: no interface matching name %s\n", __func__, hw_interface_name);
4110 be_dai_id = -EINVAL;
4111 goto done;
4112
4113done:
4114 return be_dai_id;
4115}
4116
4117void platform_check_and_update_copp_sample_rate(void* platform, snd_device_t snd_device,
4118 unsigned int stream_sr, int* sample_rate)
4119{
4120 struct platform_data* my_data = (struct platform_data *)platform;
4121 int backend_idx = platform_get_backend_index(snd_device);
4122 int device_sr = my_data->current_backend_cfg[backend_idx].sample_rate;
4123 /*
4124 *Check if device SR is multiple of 8K or 11.025 Khz
4125 *check if the stream SR is multiple of same base, if yes
4126 *then have copp SR equal to stream SR, this ensures that
4127 *post processing happens at stream SR, else have
4128 *copp SR equal to device SR.
4129 */
4130 if (!(((sample_rate_multiple(device_sr, SAMPLE_RATE_8000)) &&
4131 (sample_rate_multiple(stream_sr, SAMPLE_RATE_8000))) ||
4132 ((sample_rate_multiple(device_sr, SAMPLE_RATE_11025)) &&
4133 (sample_rate_multiple(stream_sr, SAMPLE_RATE_11025))))) {
4134 *sample_rate = device_sr;
4135 } else
4136 *sample_rate = stream_sr;
4137
4138 ALOGI("sn_device %d device sr %d stream sr %d copp sr %d", snd_device, device_sr, stream_sr
4139 , *sample_rate);
4140
4141}
4142
4143// called from info parser
vivek mehtaa68fea62017-06-08 19:04:02 -07004144void platform_add_app_type(const char *uc_type,
4145 const char *mode,
4146 int bw,
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004147 int app_type, int max_rate) {
4148 struct app_type_entry *ap =
4149 (struct app_type_entry *)calloc(1, sizeof(struct app_type_entry));
4150
4151 if (!ap) {
4152 ALOGE("%s failed to allocate mem for app type", __func__);
4153 return;
4154 }
4155
4156 ap->uc_type = -1;
4157 for (int i=0; i<USECASE_TYPE_MAX; i++) {
4158 if (!strcmp(uc_type, usecase_type_index[i].name)) {
4159 ap->uc_type = usecase_type_index[i].index;
4160 break;
4161 }
4162 }
4163
4164 if (ap->uc_type == -1) {
4165 free(ap);
4166 return;
4167 }
4168
vivek mehtaa68fea62017-06-08 19:04:02 -07004169 ALOGI("%s uc %s mode %s bw %d app_type %d max_rate %d",
4170 __func__, uc_type, mode, bw, app_type, max_rate);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004171 ap->bit_width = bw;
4172 ap->app_type = app_type;
4173 ap->max_rate = max_rate;
vivek mehtaa68fea62017-06-08 19:04:02 -07004174 ap->mode = strdup(mode);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004175 list_add_tail(&app_type_entry_list, &ap->node);
4176}
4177
4178
4179int platform_get_default_app_type_v2(void *platform __unused,
4180 usecase_type_t type,
4181 int *app_type )
4182{
4183 if (type == PCM_PLAYBACK)
4184 *app_type = DEFAULT_APP_TYPE_RX_PATH;
4185 else
4186 *app_type = DEFAULT_APP_TYPE_TX_PATH;
4187 return 0;
4188}
4189
vivek mehtaa68fea62017-06-08 19:04:02 -07004190int platform_get_app_type_v2(void *platform,
4191 usecase_type_t uc_type,
4192 const char *mode,
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004193 int bw, int sr __unused,
4194 int *app_type)
4195{
4196 struct listnode *node;
4197 struct app_type_entry *entry;
4198 *app_type = -1;
vivek mehtaa68fea62017-06-08 19:04:02 -07004199
4200 ALOGV("%s find match for uc %d mode %s bw %d rate %d",
4201 __func__, uc_type, mode, bw, sr);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004202 list_for_each(node, &app_type_entry_list) {
4203 entry = node_to_item(node, struct app_type_entry, node);
vivek mehtaa68fea62017-06-08 19:04:02 -07004204 ALOGV("%s uc %d mode %s bw %d app_type %d max_rate %d",
4205 __func__, entry->uc_type, entry->mode, entry->bit_width,
4206 entry->app_type, entry->max_rate);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004207 if (entry->bit_width == bw &&
vivek mehtaa68fea62017-06-08 19:04:02 -07004208 entry->uc_type == uc_type &&
4209 sr <= entry->max_rate &&
4210 entry->mode && !strcmp(mode, entry->mode)) {
4211 ALOGV("%s found match %d", __func__, entry->app_type);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004212 *app_type = entry->app_type;
4213 break;
4214 }
4215 }
4216
4217 if (*app_type == -1) {
vivek mehtaa68fea62017-06-08 19:04:02 -07004218 ALOGV("%s no match found, return default", __func__);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004219 return platform_get_default_app_type_v2(platform, uc_type, app_type);
4220 }
4221 return 0;
4222}
vivek mehta90933872017-06-15 18:04:39 -07004223
4224int platform_set_sidetone(struct audio_device *adev,
4225 snd_device_t out_snd_device,
4226 bool enable, char *str)
4227{
4228 int ret;
4229 if (out_snd_device == SND_DEVICE_OUT_USB_HEADSET ||
4230 out_snd_device == SND_DEVICE_OUT_VOICE_USB_HEADSET) {
4231 ret = audio_extn_usb_enable_sidetone(out_snd_device, enable);
4232 if (ret)
4233 ALOGI("%s: usb device %d does not support device sidetone\n",
4234 __func__, out_snd_device);
4235 } else {
4236 ALOGV("%s: sidetone out device(%d) mixer cmd = %s\n",
4237 __func__, out_snd_device, str);
4238 if (enable)
4239 audio_route_apply_and_update_path(adev->audio_route, str);
4240 else
4241 audio_route_reset_and_update_path(adev->audio_route, str);
4242 }
4243 return 0;
4244}
Haynes Mathew George96483a22017-03-28 14:52:47 -07004245
4246int platform_get_mmap_data_fd(void *platform __unused, int fe_dev __unused, int dir __unused,
4247 int *fd __unused, uint32_t *size __unused)
4248{
Alexey Polyudove920d4b2017-09-15 17:09:07 -07004249#if defined (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845)
Haynes Mathew George96483a22017-03-28 14:52:47 -07004250 struct platform_data *my_data = (struct platform_data *)platform;
4251 struct audio_device *adev = my_data->adev;
4252 int hw_fd = -1;
4253 char dev_name[128];
4254 struct snd_pcm_mmap_fd mmap_fd;
4255 memset(&mmap_fd, 0, sizeof(mmap_fd));
4256 mmap_fd.dir = dir;
4257 snprintf(dev_name, sizeof(dev_name), "/dev/snd/hwC%uD%u",
4258 adev->snd_card, HWDEP_FE_BASE+fe_dev);
4259 hw_fd = open(dev_name, O_RDONLY);
4260 if (hw_fd < 0) {
4261 ALOGE("fe hw dep node open %d/%d failed", adev->snd_card, fe_dev);
4262 return -1;
4263 }
4264 if (ioctl(hw_fd, SNDRV_PCM_IOCTL_MMAP_DATA_FD, &mmap_fd) < 0) {
4265 ALOGE("fe hw dep node ioctl failed");
4266 close(hw_fd);
4267 return -1;
4268 }
4269 *fd = mmap_fd.fd;
4270 *size = mmap_fd.size;
4271 close(hw_fd); // mmap_fd should still be valid
4272 return 0;
4273#else
4274 return -1;
4275#endif
4276}
Mikhail Naganov4ee6e3e2018-03-21 16:28:35 +00004277
4278bool platform_sound_trigger_usecase_needs_event(audio_usecase_t uc_id)
4279{
4280 bool needs_event = false;
4281
4282 switch (uc_id) {
4283 /* concurrent capture usecases which needs event */
4284 case USECASE_AUDIO_RECORD:
4285 case USECASE_AUDIO_RECORD_LOW_LATENCY:
4286 case USECASE_AUDIO_RECORD_MMAP:
4287 case USECASE_AUDIO_RECORD_HIFI:
4288 case USECASE_AUDIO_RECORD_VOIP:
4289 case USECASE_VOICEMMODE1_CALL:
4290 case USECASE_VOICEMMODE2_CALL:
4291 /* concurrent playback usecases that needs event */
4292 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
4293 case USECASE_AUDIO_PLAYBACK_OFFLOAD:
4294 needs_event = true;
4295 break;
4296 default:
4297 ALOGV("%s:usecase_id[%d] no need to raise event.", __func__, uc_id);
4298 }
4299 return needs_event;
4300}
4301
4302bool platform_snd_device_has_speaker(snd_device_t dev) {
4303 int num_devs = 2;
4304 snd_device_t split_devs[2] = {SND_DEVICE_NONE, SND_DEVICE_NONE};
4305 if (platform_can_split_snd_device(dev, &num_devs, split_devs) == 0) {
4306 return platform_snd_device_has_speaker(split_devs[0]) ||
4307 platform_snd_device_has_speaker(split_devs[1]);
4308 }
4309
4310 switch (dev) {
4311 case SND_DEVICE_OUT_SPEAKER:
4312 case SND_DEVICE_OUT_SPEAKER_SAFE:
4313 case SND_DEVICE_OUT_SPEAKER_REVERSE:
4314 case SND_DEVICE_OUT_SPEAKER_PROTECTED:
4315 case SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED:
4316 case SND_DEVICE_OUT_VOICE_SPEAKER_HFP:
4317 return true;
4318 default:
4319 break;
4320 }
4321 return false;
4322}
jiabin8962a4d2018-03-19 18:21:24 -07004323
4324bool platform_set_microphone_characteristic(void *platform,
4325 struct audio_microphone_characteristic_t mic) {
4326 struct platform_data *my_data = (struct platform_data *)platform;
4327 if (my_data->declared_mic_count >= AUDIO_MICROPHONE_MAX_COUNT) {
4328 ALOGE("mic number is more than maximum number");
4329 return false;
4330 }
4331 for (size_t ch = 0; ch < AUDIO_CHANNEL_COUNT_MAX; ch++) {
4332 mic.channel_mapping[ch] = AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED;
4333 }
4334 my_data->microphones[my_data->declared_mic_count++] = mic;
4335 return true;
4336}
4337
4338int platform_get_microphones(void *platform,
4339 struct audio_microphone_characteristic_t *mic_array,
4340 size_t *mic_count) {
4341 struct platform_data *my_data = (struct platform_data *)platform;
4342 if (mic_count == NULL) {
4343 return -EINVAL;
4344 }
4345 if (mic_array == NULL) {
4346 return -EINVAL;
4347 }
4348
4349 if (*mic_count == 0) {
4350 *mic_count = my_data->declared_mic_count;
4351 return 0;
4352 }
4353
4354 size_t max_mic_count = *mic_count;
4355 size_t actual_mic_count = 0;
4356 for (size_t i = 0; i < max_mic_count && i < my_data->declared_mic_count; i++) {
4357 mic_array[i] = my_data->microphones[i];
4358 actual_mic_count++;
4359 }
4360 *mic_count = actual_mic_count;
4361 return 0;
4362}
4363
4364int platform_get_active_microphones(void *platform, audio_devices_t device, unsigned int channels,
4365 int source __unused, audio_usecase_t usecase __unused,
4366 struct audio_microphone_characteristic_t *mic_array,
4367 size_t *mic_count) {
4368 struct platform_data *my_data = (struct platform_data *)platform;
4369 if (mic_count == NULL) {
4370 return -EINVAL;
4371 }
4372 if (mic_array == NULL) {
4373 return -EINVAL;
4374 }
4375
4376 if (*mic_count == 0) {
4377 // TODO: return declared mic count as a preliminary implementation, the final
4378 // implementation will derive mic count and channel mapping from use case, source and device
4379 *mic_count = my_data->declared_mic_count;
4380 return 0;
4381 }
4382
4383 size_t max_mic_count = *mic_count;
4384 size_t actual_mic_count = 0;
4385 for (size_t i = 0; i < max_mic_count && i < my_data->declared_mic_count; i++) {
4386 // TODO: get actual microphone and channel mapping type.
4387 if ((my_data->microphones[i].device & device) == device) {
4388 mic_array[actual_mic_count] = my_data->microphones[i];
4389 for (size_t ch = 0; ch < channels; ch++) {
4390 mic_array[actual_mic_count].channel_mapping[ch] =
4391 AUDIO_MICROPHONE_CHANNEL_MAPPING_DIRECT;
4392 }
4393 actual_mic_count++;
4394 }
4395 }
4396 *mic_count = actual_mic_count;
4397 return 0;
4398}