blob: c80f9949177a4ee8d288a187919392c43f8fb287 [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
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -0700787 acdb_dev_id = platform_get_snd_device_acdb_id(usecase->out_snd_device);
vivek mehta40125092017-08-21 18:48:51 -0700788
789 if (!my_data->acdb_send_gain_dep_cal(acdb_dev_id, app_type,
vivek mehta1a9b7c02015-06-25 11:49:38 -0700790 acdb_dev_type, mode, level)) {
791 // set ret_val true if at least one calibration is set successfully
792 ret_val = true;
793 } else {
794 ALOGE("%s: my_data->acdb_send_gain_dep_cal failed ", __func__);
795 }
796 } else {
797 ALOGW("%s: Usecase list is empty", __func__);
798 }
799 }
800 } else {
801 ALOGW("%s: Voice call in progress .. ignore setting new cal",
802 __func__);
803 }
804 return ret_val;
805}
806
Eric Laurentcefbbac2014-09-04 13:54:10 -0500807void platform_set_echo_reference(struct audio_device *adev, bool enable, audio_devices_t out_device)
Eric Laurentb23d5282013-05-14 15:27:20 -0700808{
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800809 struct platform_data *my_data = (struct platform_data *)adev->platform;
Eric Laurentcefbbac2014-09-04 13:54:10 -0500810 snd_device_t snd_device = SND_DEVICE_NONE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700811
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800812 if (strcmp(my_data->ec_ref_mixer_path, "")) {
813 ALOGV("%s: diabling %s", __func__, my_data->ec_ref_mixer_path);
814 audio_route_reset_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
Eric Laurentcefbbac2014-09-04 13:54:10 -0500815 }
816
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800817 if (enable) {
818 strcpy(my_data->ec_ref_mixer_path, "echo-reference");
819 if (out_device != AUDIO_DEVICE_NONE) {
820 snd_device = platform_get_output_snd_device(adev->platform, out_device);
821 platform_add_backend_name(adev->platform, my_data->ec_ref_mixer_path, snd_device);
822 }
Eric Laurentcefbbac2014-09-04 13:54:10 -0500823
Joe Onorato188b6222016-03-01 11:02:27 -0800824 ALOGV("%s: enabling %s", __func__, my_data->ec_ref_mixer_path);
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800825 audio_route_apply_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
826 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700827}
828
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700829static struct csd_data *open_csd_client(bool i2s_ext_modem)
830{
831 struct csd_data *csd = calloc(1, sizeof(struct csd_data));
832
833 csd->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
834 if (csd->csd_client == NULL) {
835 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
836 goto error;
837 } else {
838 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
839
840 csd->deinit = (deinit_t)dlsym(csd->csd_client,
841 "csd_client_deinit");
842 if (csd->deinit == NULL) {
843 ALOGE("%s: dlsym error %s for csd_client_deinit", __func__,
844 dlerror());
845 goto error;
846 }
847 csd->disable_device = (disable_device_t)dlsym(csd->csd_client,
848 "csd_client_disable_device");
849 if (csd->disable_device == NULL) {
850 ALOGE("%s: dlsym error %s for csd_client_disable_device",
851 __func__, dlerror());
852 goto error;
853 }
854 csd->enable_device_config = (enable_device_config_t)dlsym(csd->csd_client,
855 "csd_client_enable_device_config");
856 if (csd->enable_device_config == NULL) {
857 ALOGE("%s: dlsym error %s for csd_client_enable_device_config",
858 __func__, dlerror());
859 goto error;
860 }
861 csd->enable_device = (enable_device_t)dlsym(csd->csd_client,
862 "csd_client_enable_device");
863 if (csd->enable_device == NULL) {
864 ALOGE("%s: dlsym error %s for csd_client_enable_device",
865 __func__, dlerror());
866 goto error;
867 }
868 csd->start_voice = (start_voice_t)dlsym(csd->csd_client,
869 "csd_client_start_voice");
870 if (csd->start_voice == NULL) {
871 ALOGE("%s: dlsym error %s for csd_client_start_voice",
872 __func__, dlerror());
873 goto error;
874 }
875 csd->stop_voice = (stop_voice_t)dlsym(csd->csd_client,
876 "csd_client_stop_voice");
877 if (csd->stop_voice == NULL) {
878 ALOGE("%s: dlsym error %s for csd_client_stop_voice",
879 __func__, dlerror());
880 goto error;
881 }
882 csd->volume = (volume_t)dlsym(csd->csd_client,
883 "csd_client_volume");
884 if (csd->volume == NULL) {
885 ALOGE("%s: dlsym error %s for csd_client_volume",
886 __func__, dlerror());
887 goto error;
888 }
889 csd->mic_mute = (mic_mute_t)dlsym(csd->csd_client,
890 "csd_client_mic_mute");
891 if (csd->mic_mute == NULL) {
892 ALOGE("%s: dlsym error %s for csd_client_mic_mute",
893 __func__, dlerror());
894 goto error;
895 }
896 csd->slow_talk = (slow_talk_t)dlsym(csd->csd_client,
897 "csd_client_slow_talk");
898 if (csd->slow_talk == NULL) {
899 ALOGE("%s: dlsym error %s for csd_client_slow_talk",
900 __func__, dlerror());
901 goto error;
902 }
903 csd->start_playback = (start_playback_t)dlsym(csd->csd_client,
904 "csd_client_start_playback");
905 if (csd->start_playback == NULL) {
906 ALOGE("%s: dlsym error %s for csd_client_start_playback",
907 __func__, dlerror());
908 goto error;
909 }
910 csd->stop_playback = (stop_playback_t)dlsym(csd->csd_client,
911 "csd_client_stop_playback");
912 if (csd->stop_playback == NULL) {
913 ALOGE("%s: dlsym error %s for csd_client_stop_playback",
914 __func__, dlerror());
915 goto error;
916 }
917 csd->start_record = (start_record_t)dlsym(csd->csd_client,
918 "csd_client_start_record");
919 if (csd->start_record == NULL) {
920 ALOGE("%s: dlsym error %s for csd_client_start_record",
921 __func__, dlerror());
922 goto error;
923 }
924 csd->stop_record = (stop_record_t)dlsym(csd->csd_client,
925 "csd_client_stop_record");
926 if (csd->stop_record == NULL) {
927 ALOGE("%s: dlsym error %s for csd_client_stop_record",
928 __func__, dlerror());
929 goto error;
930 }
931
932 csd->get_sample_rate = (get_sample_rate_t)dlsym(csd->csd_client,
933 "csd_client_get_sample_rate");
934 if (csd->get_sample_rate == NULL) {
935 ALOGE("%s: dlsym error %s for csd_client_get_sample_rate",
936 __func__, dlerror());
937
938 goto error;
939 }
940
941 csd->init = (init_t)dlsym(csd->csd_client, "csd_client_init");
942
943 if (csd->init == NULL) {
944 ALOGE("%s: dlsym error %s for csd_client_init",
945 __func__, dlerror());
946 goto error;
947 } else {
948 csd->init(i2s_ext_modem);
949 }
950 }
951 return csd;
952
953error:
954 free(csd);
955 csd = NULL;
956 return csd;
957}
958
959void close_csd_client(struct csd_data *csd)
960{
961 if (csd != NULL) {
962 csd->deinit();
963 dlclose(csd->csd_client);
964 free(csd);
965 csd = NULL;
966 }
967}
968
969static void platform_csd_init(struct platform_data *my_data)
970{
971#ifdef PLATFORM_MSM8084
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700972 int32_t modems, (*count_modems)(void);
973 const char *name = "libdetectmodem.so";
974 const char *func = "count_modems";
975 const char *error;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700976
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700977 my_data->csd = NULL;
978
979 void *lib = dlopen(name, RTLD_NOW);
980 error = dlerror();
981 if (!lib) {
982 ALOGE("%s: could not find %s: %s", __func__, name, error);
983 return;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700984 }
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700985
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700986 count_modems = NULL;
987 *(void **)(&count_modems) = dlsym(lib, func);
988 error = dlerror();
989 if (!count_modems) {
990 ALOGE("%s: could not find symbol %s in %s: %s",
991 __func__, func, name, error);
992 goto done;
993 }
994
995 modems = count_modems();
996 if (modems < 0) {
997 ALOGE("%s: count_modems failed\n", __func__);
998 goto done;
999 }
1000
Eric Laurent2bafff12016-03-17 12:17:23 -07001001 ALOGD("%s: num_modems %d\n", __func__, modems);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001002 if (modems > 0)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001003 my_data->csd = open_csd_client(false /*is_i2s_ext_modem*/);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001004
1005done:
1006 dlclose(lib);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001007#else
1008 my_data->csd = NULL;
1009#endif
1010}
1011
Eric Laurentc6333382015-09-14 12:43:44 -07001012static void set_platform_defaults(struct platform_data * my_data)
Haynes Mathew George98c95622014-06-20 19:14:25 -07001013{
1014 int32_t dev;
1015 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001016 backend_tag_table[dev] = NULL;
1017 hw_interface_table[dev] = NULL;
keunhui.park2f7306a2015-07-16 16:48:06 +09001018 operator_specific_device_table[dev] = NULL;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001019 }
1020
David Linee3fe402017-03-13 10:00:42 -07001021 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1022 backend_bit_width_table[dev] = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
1023 }
1024
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001025 // To overwrite these go to the audio_platform_info.xml file.
1026 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("bt-sco");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07001027 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("bt-sco");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001028 backend_tag_table[SND_DEVICE_OUT_BT_SCO] = strdup("bt-sco");
1029 backend_tag_table[SND_DEVICE_OUT_HDMI] = strdup("hdmi");
1030 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("speaker-and-hdmi");
1031 backend_tag_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("bt-sco-wb");
1032 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("bt-sco-wb");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07001033 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("bt-sco-wb");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001034 backend_tag_table[SND_DEVICE_OUT_VOICE_TX] = strdup("afe-proxy");
1035 backend_tag_table[SND_DEVICE_IN_VOICE_RX] = strdup("afe-proxy");
Haynes Mathew George98c95622014-06-20 19:14:25 -07001036
David Linee3fe402017-03-13 10:00:42 -07001037 backend_tag_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("usb-headset");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001038 backend_tag_table[SND_DEVICE_OUT_VOICE_USB_HEADSET] = strdup("usb-headset");
David Linee3fe402017-03-13 10:00:42 -07001039 backend_tag_table[SND_DEVICE_OUT_USB_HEADPHONES] = strdup("usb-headphones");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001040 backend_tag_table[SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = strdup("usb-headphones");
David Linee3fe402017-03-13 10:00:42 -07001041 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] =
1042 strdup("speaker-and-usb-headphones");
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07001043 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] =
1044 strdup("speaker-safe-and-usb-headphones");
David Linee3fe402017-03-13 10:00:42 -07001045 backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("usb-headset-mic");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001046 backend_tag_table[SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1047 backend_tag_table[SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1048 backend_tag_table[SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1049 backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = strdup("usb-headset-mic");
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001050 backend_tag_table[SND_DEVICE_OUT_BT_A2DP] = strdup("bt-a2dp");
1051 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] = strdup("speaker-and-bt-a2dp");
1052
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001053 hw_interface_table[SND_DEVICE_OUT_HANDSET] = strdup("SLIMBUS_0_RX");
1054 hw_interface_table[SND_DEVICE_OUT_SPEAKER] = strdup("SLIMBUS_0_RX");
1055 hw_interface_table[SND_DEVICE_OUT_SPEAKER_REVERSE] = strdup("SLIMBUS_0_RX");
1056 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE] = strdup("SLIMBUS_0_RX");
1057 hw_interface_table[SND_DEVICE_OUT_HEADPHONES] = strdup("SLIMBUS_0_RX");
1058 hw_interface_table[SND_DEVICE_OUT_LINE] = strdup("SLIMBUS_0_RX");
1059 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001060 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001061 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001062 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001063 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET] = strdup("SLIMBUS_0_RX");
1064 hw_interface_table[SND_DEVICE_OUT_VOICE_HAC_HANDSET] = strdup("SLIMBUS_0_RX");
1065 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER] = strdup("SLIMBUS_0_RX");
1066 hw_interface_table[SND_DEVICE_OUT_VOICE_HEADPHONES] = strdup("SLIMBUS_0_RX");
1067 hw_interface_table[SND_DEVICE_OUT_VOICE_LINE] = strdup("SLIMBUS_0_RX");
1068 hw_interface_table[SND_DEVICE_OUT_HDMI] = strdup("HDMI_RX");
1069 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("SLIMBUS_0_RX-and-HDMI_RX");
1070 hw_interface_table[SND_DEVICE_OUT_BT_SCO] = strdup("SEC_AUX_PCM_RX");
1071 hw_interface_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("SEC_AUX_PCM_RX");
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001072 hw_interface_table[SND_DEVICE_OUT_BT_A2DP] = strdup("SLIMBUS_7_RX");
1073 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] =
1074 strdup("SLIMBUS_0_RX-and-SLIMBUS_7_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001075 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = strdup("SLIMBUS_0_RX");
1076 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = strdup("SLIMBUS_0_RX");
1077 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = strdup("SLIMBUS_0_RX");
1078 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = strdup("SLIMBUS_0_RX");
David Linee3fe402017-03-13 10:00:42 -07001079 hw_interface_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("USB_AUDIO_RX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001080 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = strdup("USB_AUDIO_RX");
1081 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = strdup("USB_AUDIO_RX");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001082 hw_interface_table[SND_DEVICE_OUT_VOICE_USB_HEADSET] = strdup("USB_AUDIO_RX");
David Linee3fe402017-03-13 10:00:42 -07001083 hw_interface_table[SND_DEVICE_OUT_USB_HEADPHONES] = strdup("USB_AUDIO_RX");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001084 hw_interface_table[SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = strdup("USB_AUDIO_RX");
David Linee3fe402017-03-13 10:00:42 -07001085 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 -07001086 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 -07001087 hw_interface_table[SND_DEVICE_OUT_VOICE_TX] = strdup("AFE_PCM_RX");
1088 hw_interface_table[SND_DEVICE_OUT_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
1089 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
jasmine cha52284622018-03-23 17:21:35 +08001090 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = strdup("SLIMBUS_0_RX");
1091 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_BT_SCO] = strdup("SLIMBUS_0_RX-and-SEC_AUX_PCM_RX");
1092 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 -07001093 hw_interface_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1094 hw_interface_table[SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1095 hw_interface_table[SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = strdup("USB_AUDIO_TX");
1096 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1097 hw_interface_table[SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1098 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = strdup("USB_AUDIO_TX");
1099 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = strdup("USB_AUDIO_TX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001100 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001101 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_AEC] = strdup("SLIMBUS_0_TX");
1102 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_NS] = strdup("SLIMBUS_0_TX");
1103 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1104 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC] = strdup("SLIMBUS_0_TX");
1105 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_AEC] = strdup("SLIMBUS_0_TX");
1106 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_NS] = strdup("SLIMBUS_0_TX");
1107 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1108 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001109 hw_interface_table[SND_DEVICE_IN_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001110 hw_interface_table[SND_DEVICE_IN_HEADSET_MIC_AEC] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001111 hw_interface_table[SND_DEVICE_IN_CAMCORDER_MIC] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001112 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC] = strdup("SLIMBUS_0_TX");
1113 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC_NS] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001114 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC_AEC] = strdup("SLIMBUS_0_TX");
1115 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001116 hw_interface_table[SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
1117 hw_interface_table[SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = strdup("SLIMBUS_0_TX");
David Lin93725722017-10-13 14:58:17 -07001118 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_MIC] = strdup("SLIMBUS_0_TX");
1119 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1120 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = strdup("SLIMBUS_0_TX");
1121 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = strdup("SLIMBUS_0_TX");
1122 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001123 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC] = strdup("SLIMBUS_0_TX");
1124 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_AEC] = strdup("SLIMBUS_0_TX");
1125 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_NS] = strdup("SLIMBUS_0_TX");
1126 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1127 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC] = strdup("SLIMBUS_0_TX");
1128 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_AEC] = strdup("SLIMBUS_0_TX");
1129 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_NS] = strdup("SLIMBUS_0_TX");
1130 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001131 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
1132 hw_interface_table[SND_DEVICE_IN_VOICE_DMIC] = strdup("SLIMBUS_0_TX");
1133 hw_interface_table[SND_DEVICE_IN_VOICE_DMIC_TMUS] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001134 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001135 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = strdup("SLIMBUS_0_TX");
1136 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001137 hw_interface_table[SND_DEVICE_IN_VOICE_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001138 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1139 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = strdup("SLIMBUS_0_TX");
1140 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1141 hw_interface_table[SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1142 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("SEC_AUX_PCM_TX");
1143 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("SEC_AUX_PCM_TX");
1144 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("SEC_AUX_PCM_TX");
1145 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("SEC_AUX_PCM_TX");
1146 hw_interface_table[SND_DEVICE_IN_VOICE_RX] = strdup("AFE_PCM_TX");
1147 hw_interface_table[SND_DEVICE_IN_THREE_MIC] = strdup("SLIMBUS_0_TX");
1148 hw_interface_table[SND_DEVICE_IN_QUAD_MIC] = strdup("SLIMBUS_0_TX");
1149 hw_interface_table[SND_DEVICE_IN_HANDSET_TMIC] = strdup("SLIMBUS_0_TX");
1150 hw_interface_table[SND_DEVICE_IN_HANDSET_QMIC] = strdup("SLIMBUS_0_TX");
1151 hw_interface_table[SND_DEVICE_IN_HANDSET_TMIC_AEC] = strdup("SLIMBUS_0_TX");
1152 hw_interface_table[SND_DEVICE_IN_HANDSET_QMIC_AEC] = strdup("SLIMBUS_0_TX");
Eric Laurentc6333382015-09-14 12:43:44 -07001153 my_data->max_mic_count = PLATFORM_DEFAULT_MIC_COUNT;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001154}
1155
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001156void get_cvd_version(char *cvd_version, struct audio_device *adev)
1157{
1158 struct mixer_ctl *ctl;
1159 int count;
1160 int ret = 0;
1161
1162 ctl = mixer_get_ctl_by_name(adev->mixer, CVD_VERSION_MIXER_CTL);
1163 if (!ctl) {
1164 ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__, CVD_VERSION_MIXER_CTL);
1165 goto done;
1166 }
1167 mixer_ctl_update(ctl);
1168
1169 count = mixer_ctl_get_num_values(ctl);
1170 if (count > MAX_CVD_VERSION_STRING_SIZE)
1171 count = MAX_CVD_VERSION_STRING_SIZE - 1;
1172
1173 ret = mixer_ctl_get_array(ctl, cvd_version, count);
1174 if (ret != 0) {
1175 ALOGE("%s: ERROR! mixer_ctl_get_array() failed to get CVD Version", __func__);
1176 goto done;
1177 }
1178
1179done:
1180 return;
1181}
1182
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001183static int platform_acdb_init(void *platform)
1184{
1185 struct platform_data *my_data = (struct platform_data *)platform;
1186 struct audio_device *adev = my_data->adev;
1187
1188 if (!my_data->acdb_init) {
1189 ALOGE("%s: no acdb_init fn provided", __func__);
1190 return -1;
1191 }
1192
1193 if (my_data->acdb_initialized) {
1194 ALOGW("acdb is already initialized");
1195 return 0;
1196 }
1197
Alexey Polyudove920d4b2017-09-15 17:09:07 -07001198#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001199 char *cvd_version = calloc(1, MAX_CVD_VERSION_STRING_SIZE);
1200 if (!cvd_version)
1201 ALOGE("failed to allocate cvd_version");
1202 else {
1203 get_cvd_version(cvd_version, adev);
1204 my_data->acdb_init((char *)my_data->snd_card_name, cvd_version, 0);
1205 free(cvd_version);
1206 }
1207#elif defined (PLATFORM_MSM8084)
1208 my_data->acdb_init((char *)my_data->snd_card_name);
1209#else
1210 my_data->acdb_init();
1211#endif
1212 my_data->acdb_initialized = true;
1213 return 0;
1214}
1215
David Linee3fe402017-03-13 10:00:42 -07001216static void
1217platform_backend_config_init(struct platform_data *pdata)
1218{
1219 int i;
1220
1221 /* initialize backend config */
1222 for (i = 0; i < MAX_CODEC_BACKENDS; i++) {
1223 pdata->current_backend_cfg[i].sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
1224 pdata->current_backend_cfg[i].bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
1225 pdata->current_backend_cfg[i].channels = CODEC_BACKEND_DEFAULT_CHANNELS;
1226
1227 if (i > MAX_RX_CODEC_BACKENDS)
1228 pdata->current_backend_cfg[i].channels = CODEC_BACKEND_DEFAULT_TX_CHANNELS;
1229
1230 pdata->current_backend_cfg[i].bitwidth_mixer_ctl = NULL;
1231 pdata->current_backend_cfg[i].samplerate_mixer_ctl = NULL;
1232 pdata->current_backend_cfg[i].channels_mixer_ctl = NULL;
1233 }
1234
1235 pdata->current_backend_cfg[DEFAULT_CODEC_BACKEND].bitwidth_mixer_ctl =
1236 strdup("SLIM_0_RX Format");
1237 pdata->current_backend_cfg[DEFAULT_CODEC_BACKEND].samplerate_mixer_ctl =
1238 strdup("SLIM_0_RX SampleRate");
1239
1240 pdata->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].bitwidth_mixer_ctl =
1241 strdup("SLIM_0_TX Format");
1242 pdata->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].samplerate_mixer_ctl =
1243 strdup("SLIM_0_TX SampleRate");
1244
1245 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].bitwidth_mixer_ctl =
1246 strdup("USB_AUDIO_TX Format");
1247 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].samplerate_mixer_ctl =
1248 strdup("USB_AUDIO_TX SampleRate");
1249 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].channels_mixer_ctl =
1250 strdup("USB_AUDIO_TX Channels");
1251
1252 pdata->current_backend_cfg[HEADPHONE_BACKEND].bitwidth_mixer_ctl =
1253 strdup("SLIM_6_RX Format");
1254 pdata->current_backend_cfg[HEADPHONE_BACKEND].samplerate_mixer_ctl =
1255 strdup("SLIM_6_RX SampleRate");
1256
1257 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].bitwidth_mixer_ctl =
1258 strdup("USB_AUDIO_RX Format");
1259 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].samplerate_mixer_ctl =
1260 strdup("USB_AUDIO_RX SampleRate");
1261
1262 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].channels = 1;
1263 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].channels_mixer_ctl =
1264 strdup("USB_AUDIO_RX Channels");
1265}
1266
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001267static int
1268platform_backend_app_type_cfg_init(struct platform_data *pdata,
1269 struct mixer *mixer)
1270{
1271 size_t app_type_cfg[128] = {0};
1272 int length, num_app_types = 0;
1273 struct mixer_ctl *ctl = NULL;
1274
1275 const char *mixer_ctl_name = "App Type Config";
1276 ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name);
1277 if (!ctl) {
1278 ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name);
1279 return -1;
1280 }
1281
1282 length = 1; // reserve index 0 for number of app types
1283
1284 struct listnode *node;
1285 struct app_type_entry *entry;
1286 list_for_each(node, &app_type_entry_list) {
1287 entry = node_to_item(node, struct app_type_entry, node);
1288 app_type_cfg[length++] = entry->app_type;
1289 app_type_cfg[length++] = entry->max_rate;
1290 app_type_cfg[length++] = entry->bit_width;
1291 ALOGI("%s add entry %d %d", __func__, entry->app_type, entry->bit_width);
1292 num_app_types += 1;
1293 }
1294
1295 // default for capture
1296 int t;
1297 platform_get_default_app_type_v2(pdata,
1298 PCM_CAPTURE,
1299 &t);
1300 app_type_cfg[length++] = t;
1301 app_type_cfg[length++] = 48000;
1302 app_type_cfg[length++] = 16;
1303 num_app_types += 1;
1304
1305 if (num_app_types) {
1306 app_type_cfg[0] = num_app_types;
1307 if (mixer_ctl_set_array(ctl, app_type_cfg, length) < 0) {
1308 ALOGE("Failed to set app type cfg");
1309 }
1310 }
1311 return 0;
1312}
1313
Xu Han1638fd12018-04-20 12:42:23 -07001314static void configure_flicker_sensor_input(struct mixer *mixer)
1315{
1316 struct mixer_ctl *ctl;
1317 const char* ctl1 = "AIF3_CAP Mixer SLIM TX2";
1318 int setting1 = 1;
1319 const char* ctl2 = "CDC_IF TX2 MUX";
1320 const char* setting2 = "DEC2";
1321 const char* ctl3 = "SLIM_1_TX Channels";
1322 const char* setting3 = "One";
1323 const char* ctl4 = "ADC MUX2";
1324 const char* setting4 = "AMIC";
1325 const char* ctl5 = "AMIC MUX2";
1326 const char* setting5 = "ADC1";
1327 const char* ctl6 = "DEC2 Volume";
1328 int setting6 = 84;
1329 const char* ctl7 = "MultiMedia2 Mixer SLIM_1_TX";
1330 int setting7 = 1;
1331 const char* ctl8 = "SLIM_1_TX SampleRate";
1332 const char* setting8 = "KHZ_8";
1333
1334 ctl = mixer_get_ctl_by_name(mixer, ctl1);
1335 mixer_ctl_set_value(ctl, 0, setting1);
1336 ctl = mixer_get_ctl_by_name(mixer, ctl2);
1337 mixer_ctl_set_enum_by_string(ctl, setting2);
1338 ctl = mixer_get_ctl_by_name(mixer, ctl3);
1339 mixer_ctl_set_enum_by_string(ctl, setting3);
1340 ctl = mixer_get_ctl_by_name(mixer, ctl4);
1341 mixer_ctl_set_enum_by_string(ctl, setting4);
1342 ctl = mixer_get_ctl_by_name(mixer, ctl5);
1343 mixer_ctl_set_enum_by_string(ctl, setting5);
1344 ctl = mixer_get_ctl_by_name(mixer, ctl6);
1345 mixer_ctl_set_value(ctl, 0, setting6);
1346 ctl = mixer_get_ctl_by_name(mixer, ctl7);
1347 mixer_ctl_set_value(ctl, 0, setting7);
1348 ctl = mixer_get_ctl_by_name(mixer, ctl8);
1349 mixer_ctl_set_enum_by_string(ctl, setting8);
1350}
1351
Eric Laurentb23d5282013-05-14 15:27:20 -07001352void *platform_init(struct audio_device *adev)
1353{
1354 char value[PROPERTY_VALUE_MAX];
vivek mehta60ea4152016-02-18 17:10:26 -08001355 struct platform_data *my_data = NULL;
1356 int retry_num = 0, snd_card_num = 0, key = 0, ret = 0;
1357 bool dual_mic_config = false, use_default_mixer_path = true;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001358 const char *snd_card_name;
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001359 char *cvd_version = NULL;
vivek mehta60ea4152016-02-18 17:10:26 -08001360 char *snd_internal_name = NULL;
1361 char *tmp = NULL;
1362 char mixer_xml_file[MIXER_PATH_MAX_LENGTH]= {0};
vivek mehtade4849c2016-03-03 17:23:38 -08001363 char platform_info_file[MIXER_PATH_MAX_LENGTH]= {0};
1364 struct snd_card_split *snd_split_handle = NULL;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001365 my_data = calloc(1, sizeof(struct platform_data));
1366
1367 my_data->adev = adev;
1368
keunhui.park2f7306a2015-07-16 16:48:06 +09001369 list_init(&operator_info_list);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001370 list_init(&app_type_entry_list);
keunhui.park2f7306a2015-07-16 16:48:06 +09001371
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001372 set_platform_defaults(my_data);
1373
vivek mehta0fb11312017-05-15 19:35:32 -07001374 // audio_extn_utils_get_snd_card_num does
1375 // - open mixer and get snd card name
1376 // - parse platform info xml file and check for valid snd card name
1377 // - on failure loop through all the active snd card
sangwoo1b9f4b32013-06-21 18:22:55 -07001378
vivek mehta0fb11312017-05-15 19:35:32 -07001379 snd_card_num = audio_extn_utils_get_snd_card_num();
1380 if (-1 == snd_card_num) {
1381 ALOGE("%s: invalid sound card number (-1), bailing out ", __func__);
1382 goto init_failed;
sangwoo1b9f4b32013-06-21 18:22:55 -07001383 }
1384
vivek mehta0fb11312017-05-15 19:35:32 -07001385 adev->mixer = mixer_open(snd_card_num);
1386 snd_card_name = mixer_get_name(adev->mixer);
1387 my_data->hw_info = hw_info_init(snd_card_name);
1388
1389 audio_extn_set_snd_card_split(snd_card_name);
1390 snd_split_handle = audio_extn_get_snd_card_split();
1391
1392 /* Get the codec internal name from the sound card and/or form factor
1393 * name and form the mixer paths and platfor info file name dynamically.
1394 * This is generic way of picking any codec and forma factor name based
1395 * mixer and platform info files in future with no code change.
1396
1397 * current code extends and looks for any of the exteneded mixer path and
1398 * platform info file present based on codec and form factor.
1399
1400 * order of picking appropriate file is
1401 * <i> mixer_paths_<codec_name>_<form_factor>.xml, if file not present
1402 * <ii> mixer_paths_<codec_name>.xml, if file not present
1403 * <iii> mixer_paths.xml
1404
1405 * same order is followed for audio_platform_info.xml as well
1406 */
1407
1408 // need to carryforward old file name
1409 if (!strncmp(snd_card_name, TOMTOM_8226_SND_CARD_NAME,
1410 min(strlen(TOMTOM_8226_SND_CARD_NAME), strlen(snd_card_name)))) {
1411 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1412 MIXER_XML_BASE_STRING, TOMTOM_MIXER_FILE_SUFFIX );
1413 } else {
1414
1415 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s_%s.xml",
1416 MIXER_XML_BASE_STRING, snd_split_handle->snd_card,
1417 snd_split_handle->form_factor);
1418 if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) {
1419 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1420 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1421 MIXER_XML_BASE_STRING, snd_split_handle->snd_card);
1422
1423 if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) {
1424 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1425 strlcpy(mixer_xml_file, MIXER_XML_DEFAULT_PATH, MIXER_PATH_MAX_LENGTH);
1426 audio_extn_utils_resolve_config_file(mixer_xml_file);
1427 }
1428 }
1429 }
1430
1431 audio_extn_utils_get_platform_info(snd_card_name, platform_info_file);
1432
jiabin8962a4d2018-03-19 18:21:24 -07001433 my_data->declared_mic_count = 0;
vivek mehta0fb11312017-05-15 19:35:32 -07001434 /* Initialize platform specific ids and/or backends*/
1435 platform_info_init(platform_info_file, my_data);
1436
1437 ALOGD("%s: Loading mixer file: %s", __func__, mixer_xml_file);
1438 adev->audio_route = audio_route_init(snd_card_num, mixer_xml_file);
1439
1440 if (!adev->audio_route) {
1441 ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
1442 mixer_close(adev->mixer);
1443 adev->mixer = NULL;
1444 hw_info_deinit(my_data->hw_info);
1445 my_data->hw_info = NULL;
1446 goto init_failed;
1447 }
1448 adev->snd_card = snd_card_num;
1449 ALOGD("%s: Opened sound card:%d", __func__, snd_card_num);
1450
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09001451 //set max volume step for voice call
1452 property_get("ro.config.vc_call_vol_steps", value, TOSTRING(MAX_VOL_INDEX));
1453 my_data->max_vol_index = atoi(value);
1454
vivek mehta65ad12d2015-08-13 18:32:48 -07001455 property_get("persist.audio.dualmic.config",value,"");
1456 if (!strcmp("endfire", value)) {
1457 dual_mic_config = true;
1458 }
1459
John Muir9e59a962018-01-10 13:30:00 -08001460 my_data->source_mic_type = 0;
Prashant Malanic92c5962015-08-11 15:10:18 -07001461
Eric Laurentb23d5282013-05-14 15:27:20 -07001462 my_data->fluence_in_spkr_mode = false;
1463 my_data->fluence_in_voice_call = false;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001464 my_data->fluence_in_voice_comm = false;
Eric Laurentb23d5282013-05-14 15:27:20 -07001465 my_data->fluence_in_voice_rec = false;
1466
vivek mehta65ad12d2015-08-13 18:32:48 -07001467 property_get("ro.qc.sdk.audio.fluencetype", value, "none");
Prashant Malanic92c5962015-08-11 15:10:18 -07001468 if (!strcmp("fluencepro", value)) {
1469 my_data->fluence_type = FLUENCE_PRO_ENABLE;
vivek mehta65ad12d2015-08-13 18:32:48 -07001470 } else if (!strcmp("fluence", value) || (dual_mic_config)) {
Prashant Malanic92c5962015-08-11 15:10:18 -07001471 my_data->fluence_type = FLUENCE_ENABLE;
1472 } else if (!strcmp("none", value)) {
1473 my_data->fluence_type = FLUENCE_DISABLE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001474 }
1475
Prashant Malanic92c5962015-08-11 15:10:18 -07001476 if (my_data->fluence_type != FLUENCE_DISABLE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001477 property_get("persist.audio.fluence.voicecall",value,"");
1478 if (!strcmp("true", value)) {
1479 my_data->fluence_in_voice_call = true;
1480 }
1481
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001482 property_get("persist.audio.fluence.voicecomm",value,"");
1483 if (!strcmp("true", value)) {
1484 my_data->fluence_in_voice_comm = true;
1485 }
1486
Eric Laurentb23d5282013-05-14 15:27:20 -07001487 property_get("persist.audio.fluence.voicerec",value,"");
1488 if (!strcmp("true", value)) {
1489 my_data->fluence_in_voice_rec = true;
1490 }
1491
1492 property_get("persist.audio.fluence.speaker",value,"");
1493 if (!strcmp("true", value)) {
1494 my_data->fluence_in_spkr_mode = true;
1495 }
1496 }
1497
Prashant Malanic92c5962015-08-11 15:10:18 -07001498 // support max to mono, example if max count is 3, usecase supports Three, dual and mono mic
1499 switch (my_data->max_mic_count) {
1500 case 4:
1501 my_data->source_mic_type |= SOURCE_QUAD_MIC;
1502 case 3:
1503 my_data->source_mic_type |= SOURCE_THREE_MIC;
1504 case 2:
1505 my_data->source_mic_type |= SOURCE_DUAL_MIC;
1506 case 1:
1507 my_data->source_mic_type |= SOURCE_MONO_MIC;
1508 break;
1509 default:
1510 ALOGE("%s: max_mic_count (%d), is not supported, setting to default",
1511 __func__, my_data->max_mic_count);
1512 my_data->source_mic_type = SOURCE_MONO_MIC|SOURCE_DUAL_MIC;
1513 break;
1514 }
1515
1516 ALOGV("%s: Fluence_Type(%d) max_mic_count(%d) mic_type(0x%x) fluence_in_voice_call(%d)"
1517 " fluence_in_voice_comm(%d) fluence_in_voice_rec(%d) fluence_in_spkr_mode(%d) ",
1518 __func__, my_data->fluence_type, my_data->max_mic_count, my_data->source_mic_type,
1519 my_data->fluence_in_voice_call, my_data->fluence_in_voice_comm,
1520 my_data->fluence_in_voice_rec, my_data->fluence_in_spkr_mode);
1521
Eric Laurentb23d5282013-05-14 15:27:20 -07001522 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
1523 if (my_data->acdb_handle == NULL) {
1524 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
1525 } else {
1526 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
1527 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
1528 "acdb_loader_deallocate_ACDB");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001529 if (!my_data->acdb_deallocate)
1530 ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s",
1531 __func__, LIB_ACDB_LOADER);
1532
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001533 my_data->acdb_send_audio_cal_v3 = (acdb_send_audio_cal_v3_t)dlsym(my_data->acdb_handle,
1534 "acdb_loader_send_audio_cal_v3");
1535 if (!my_data->acdb_send_audio_cal_v3)
1536 ALOGE("%s: Could not find the symbol acdb_send_audio_cal_v3 from %s",
1537 __func__, LIB_ACDB_LOADER);
1538
Eric Laurentb23d5282013-05-14 15:27:20 -07001539 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
1540 "acdb_loader_send_audio_cal");
1541 if (!my_data->acdb_send_audio_cal)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001542 ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s",
Eric Laurentb23d5282013-05-14 15:27:20 -07001543 __func__, LIB_ACDB_LOADER);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001544
Eric Laurentb23d5282013-05-14 15:27:20 -07001545 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
1546 "acdb_loader_send_voice_cal");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001547 if (!my_data->acdb_send_voice_cal)
1548 ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s",
1549 __func__, LIB_ACDB_LOADER);
1550
1551 my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle,
1552 "acdb_loader_reload_vocvoltable");
1553 if (!my_data->acdb_reload_vocvoltable)
1554 ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s",
1555 __func__, LIB_ACDB_LOADER);
vivek mehta1a9b7c02015-06-25 11:49:38 -07001556
1557 my_data->acdb_send_gain_dep_cal = (acdb_send_gain_dep_cal_t)dlsym(my_data->acdb_handle,
1558 "acdb_loader_send_gain_dep_cal");
1559 if (!my_data->acdb_send_gain_dep_cal)
1560 ALOGV("%s: Could not find the symbol acdb_loader_send_gain_dep_cal from %s",
1561 __func__, LIB_ACDB_LOADER);
1562
Xu Han1638fd12018-04-20 12:42:23 -07001563#if defined (FLICKER_SENSOR_INPUT)
1564 configure_flicker_sensor_input(adev->mixer);
1565#endif
1566
Alexey Polyudove920d4b2017-09-15 17:09:07 -07001567#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845)
vivek mehta0fb11312017-05-15 19:35:32 -07001568 acdb_init_v2_cvd_t acdb_init_local;
1569 acdb_init_local = (acdb_init_v2_cvd_t)dlsym(my_data->acdb_handle,
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001570 "acdb_loader_init_v2");
vivek mehta0fb11312017-05-15 19:35:32 -07001571 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001572 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1573 dlerror());
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001574
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001575#elif defined (PLATFORM_MSM8084)
vivek mehta0fb11312017-05-15 19:35:32 -07001576 acdb_init_v2_t acdb_init_local;
1577 acdb_init_local = (acdb_init_v2_t)dlsym(my_data->acdb_handle,
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001578 "acdb_loader_init_v2");
vivek mehta0fb11312017-05-15 19:35:32 -07001579 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001580 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1581 dlerror());
1582
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001583#else
vivek mehta0fb11312017-05-15 19:35:32 -07001584 acdb_init_t acdb_init_local;
1585 acdb_init_local = (acdb_init_t)dlsym(my_data->acdb_handle,
Eric Laurentb23d5282013-05-14 15:27:20 -07001586 "acdb_loader_init_ACDB");
vivek mehta0fb11312017-05-15 19:35:32 -07001587 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001588 ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__,
1589 dlerror());
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001590#endif
vivek mehta0fb11312017-05-15 19:35:32 -07001591 my_data->acdb_init = acdb_init_local;
Eric Laurentb23d5282013-05-14 15:27:20 -07001592
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001593 my_data->acdb_send_custom_top = (acdb_send_custom_top_t)
1594 dlsym(my_data->acdb_handle,
1595 "acdb_loader_send_common_custom_topology");
1596
1597 if (!my_data->acdb_send_custom_top)
1598 ALOGE("%s: Could not find the symbol acdb_get_default_app_type from %s",
1599 __func__, LIB_ACDB_LOADER);
1600
vivek mehta0fb11312017-05-15 19:35:32 -07001601 int result = acdb_init(adev->snd_card);
1602 if (!result) {
1603 my_data->acdb_initialized = true;
1604 ALOGD("ACDB initialized");
1605 } else {
1606 my_data->acdb_initialized = false;
1607 ALOGD("ACDB initialization failed");
1608 }
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001609 }
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001610
David Linee3fe402017-03-13 10:00:42 -07001611 /* init usb */
1612 audio_extn_usb_init(adev);
1613
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001614 /* init a2dp */
1615 audio_extn_a2dp_init(adev);
1616
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001617 audio_extn_spkr_prot_init(adev);
Haynes Mathew George98c95622014-06-20 19:14:25 -07001618
Ravi Kumar Alamanda76315572015-04-23 13:13:56 -07001619 audio_extn_hwdep_cal_send(adev->snd_card, my_data->acdb_handle);
1620
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001621 /* load csd client */
1622 platform_csd_init(my_data);
1623
David Linee3fe402017-03-13 10:00:42 -07001624 platform_backend_config_init(my_data);
1625
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001626 init_be_dai_name_table(adev);
1627
1628 if (platform_supports_app_type_cfg())
1629 platform_backend_app_type_cfg_init(my_data, adev->mixer);
1630
Eric Laurentb23d5282013-05-14 15:27:20 -07001631 return my_data;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001632
1633init_failed:
1634 if (my_data)
1635 free(my_data);
1636 return NULL;
Eric Laurentb23d5282013-05-14 15:27:20 -07001637}
1638
1639void platform_deinit(void *platform)
1640{
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001641 int32_t dev;
keunhui.park2f7306a2015-07-16 16:48:06 +09001642 struct operator_info *info_item;
1643 struct operator_specific_device *device_item;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001644 struct app_type_entry *ap;
keunhui.park2f7306a2015-07-16 16:48:06 +09001645 struct listnode *node;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001646
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001647 struct platform_data *my_data = (struct platform_data *)platform;
1648 close_csd_client(my_data->csd);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001649
vivek mehtade4849c2016-03-03 17:23:38 -08001650 hw_info_deinit(my_data->hw_info);
1651
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001652 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1653 if (backend_tag_table[dev])
1654 free(backend_tag_table[dev]);
1655 if (hw_interface_table[dev])
1656 free(hw_interface_table[dev]);
keunhui.park2f7306a2015-07-16 16:48:06 +09001657 if (operator_specific_device_table[dev]) {
1658 while (!list_empty(operator_specific_device_table[dev])) {
1659 node = list_head(operator_specific_device_table[dev]);
1660 list_remove(node);
1661 device_item = node_to_item(node, struct operator_specific_device, list);
1662 free(device_item->operator);
1663 free(device_item->mixer_path);
1664 free(device_item);
1665 }
1666 free(operator_specific_device_table[dev]);
1667 }
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001668 }
1669
1670 if (my_data->snd_card_name)
1671 free(my_data->snd_card_name);
1672
keunhui.park2f7306a2015-07-16 16:48:06 +09001673 while (!list_empty(&operator_info_list)) {
1674 node = list_head(&operator_info_list);
1675 list_remove(node);
1676 info_item = node_to_item(node, struct operator_info, list);
1677 free(info_item->name);
1678 free(info_item->mccmnc);
1679 free(info_item);
1680 }
1681
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001682 while (!list_empty(&app_type_entry_list)) {
1683 node = list_head(&app_type_entry_list);
1684 list_remove(node);
1685 ap = node_to_item(node, struct app_type_entry, node);
vivek mehtaa68fea62017-06-08 19:04:02 -07001686 if (ap->mode) free(ap->mode);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001687 free(ap);
1688 }
1689
Kevin Rocarde35d4af2017-05-02 16:55:28 -07001690 mixer_close(my_data->adev->mixer);
Eric Laurentb23d5282013-05-14 15:27:20 -07001691 free(platform);
David Linee3fe402017-03-13 10:00:42 -07001692
1693 /* deinit usb */
1694 audio_extn_usb_deinit();
Eric Laurentb23d5282013-05-14 15:27:20 -07001695}
1696
1697const char *platform_get_snd_device_name(snd_device_t snd_device)
1698{
keunhui.park2f7306a2015-07-16 16:48:06 +09001699 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1700 if (operator_specific_device_table[snd_device] != NULL) {
1701 return get_operator_specific_device_mixer_path(snd_device);
1702 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001703 return device_table[snd_device];
keunhui.park2f7306a2015-07-16 16:48:06 +09001704 } else
Ravi Kumar Alamanda64026462014-09-15 00:08:58 -07001705 return "none";
Eric Laurentb23d5282013-05-14 15:27:20 -07001706}
1707
vivek mehtade4849c2016-03-03 17:23:38 -08001708int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
1709 char *device_name)
1710{
1711 struct platform_data *my_data = (struct platform_data *)platform;
1712
David Benjamin1565f992016-09-21 12:10:34 -04001713 if (platform == NULL) {
vivek mehtade4849c2016-03-03 17:23:38 -08001714 ALOGW("%s: something wrong, use legacy get_snd_device name", __func__);
David Benjamin1565f992016-09-21 12:10:34 -04001715 strlcpy(device_name, platform_get_snd_device_name(snd_device),
1716 DEVICE_NAME_MAX_SIZE);
vivek mehtade4849c2016-03-03 17:23:38 -08001717 } else if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1718 if (operator_specific_device_table[snd_device] != NULL) {
1719 strlcpy(device_name, get_operator_specific_device_mixer_path(snd_device),
1720 DEVICE_NAME_MAX_SIZE);
1721 } else {
1722 strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE);
1723 }
1724 hw_info_append_hw_type(my_data->hw_info, snd_device, device_name);
1725 } else {
1726 strlcpy(device_name, "none", DEVICE_NAME_MAX_SIZE);
1727 }
1728
1729 return 0;
1730}
1731
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001732void platform_add_backend_name(void *platform, char *mixer_path,
1733 snd_device_t snd_device)
Eric Laurentb23d5282013-05-14 15:27:20 -07001734{
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001735 struct platform_data *my_data = (struct platform_data *)platform;
1736
Haynes Mathew George98c95622014-06-20 19:14:25 -07001737 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1738 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1739 return;
Ravi Kumar Alamanda1de6e5a2014-06-19 21:55:39 -05001740 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001741
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001742 const char * suffix = backend_tag_table[snd_device];
Haynes Mathew George98c95622014-06-20 19:14:25 -07001743
1744 if (suffix != NULL) {
1745 strcat(mixer_path, " ");
1746 strcat(mixer_path, suffix);
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001747 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001748}
1749
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001750bool platform_check_backends_match(snd_device_t snd_device1, snd_device_t snd_device2)
1751{
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001752 ALOGV("%s: snd_device1 = %s, snd_device2 = %s", __func__,
1753 platform_get_snd_device_name(snd_device1),
1754 platform_get_snd_device_name(snd_device2));
1755
1756 if ((snd_device1 < SND_DEVICE_MIN) || (snd_device1 >= SND_DEVICE_MAX)) {
1757 ALOGE("%s: Invalid snd_device = %s", __func__,
1758 platform_get_snd_device_name(snd_device1));
1759 return false;
1760 }
1761 if ((snd_device2 < SND_DEVICE_MIN) || (snd_device2 >= SND_DEVICE_MAX)) {
1762 ALOGE("%s: Invalid snd_device = %s", __func__,
1763 platform_get_snd_device_name(snd_device2));
1764 return false;
1765 }
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07001766
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001767 const char * be_itf1 = hw_interface_table[snd_device1];
1768 const char * be_itf2 = hw_interface_table[snd_device2];
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07001769 /*
1770 hw_interface_table has overrides for a snd_device.
1771 if there is no entry for a device, assume DEFAULT_RX_BACKEND
1772 */
1773 if (be_itf1 == NULL) {
1774 be_itf1 = DEFAULT_RX_BACKEND;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001775 }
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07001776 if (be_itf2 == NULL) {
1777 be_itf2 = DEFAULT_RX_BACKEND;
1778 }
1779 ALOGV("%s: be_itf1 = %s, be_itf2 = %s", __func__, be_itf1, be_itf2);
1780 /*
1781 this takes care of finding a device within a combo device pair as well
1782 */
1783 return strstr(be_itf1, be_itf2) != NULL || strstr(be_itf2, be_itf1) != NULL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001784}
1785
Eric Laurentb23d5282013-05-14 15:27:20 -07001786int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
1787{
1788 int device_id;
1789 if (device_type == PCM_PLAYBACK)
1790 device_id = pcm_device_table[usecase][0];
1791 else
1792 device_id = pcm_device_table[usecase][1];
1793 return device_id;
1794}
1795
Haynes Mathew George98c95622014-06-20 19:14:25 -07001796static int find_index(const struct name_to_index * table, int32_t len,
1797 const char * name)
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001798{
1799 int ret = 0;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001800 int32_t i;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001801
Haynes Mathew George98c95622014-06-20 19:14:25 -07001802 if (table == NULL) {
1803 ALOGE("%s: table is NULL", __func__);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001804 ret = -ENODEV;
1805 goto done;
1806 }
1807
Haynes Mathew George98c95622014-06-20 19:14:25 -07001808 if (name == NULL) {
1809 ALOGE("null key");
1810 ret = -ENODEV;
1811 goto done;
1812 }
1813
1814 for (i=0; i < len; i++) {
1815 if (!strcmp(table[i].name, name)) {
1816 ret = table[i].index;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001817 goto done;
1818 }
1819 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001820 ALOGE("%s: Could not find index for name = %s",
1821 __func__, name);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001822 ret = -ENODEV;
1823done:
1824 return ret;
1825}
1826
Haynes Mathew George98c95622014-06-20 19:14:25 -07001827int platform_get_snd_device_index(char *device_name)
1828{
1829 return find_index(snd_device_name_index, SND_DEVICE_MAX, device_name);
1830}
1831
1832int platform_get_usecase_index(const char *usecase_name)
1833{
1834 return find_index(usecase_name_index, AUDIO_USECASE_MAX, usecase_name);
1835}
1836
keunhui.park2f7306a2015-07-16 16:48:06 +09001837void platform_add_operator_specific_device(snd_device_t snd_device,
1838 const char *operator,
1839 const char *mixer_path,
1840 unsigned int acdb_id)
1841{
1842 struct operator_specific_device *device;
1843
1844 if (operator_specific_device_table[snd_device] == NULL) {
1845 operator_specific_device_table[snd_device] =
1846 (struct listnode *)calloc(1, sizeof(struct listnode));
1847 list_init(operator_specific_device_table[snd_device]);
1848 }
1849
1850 device = (struct operator_specific_device *)calloc(1, sizeof(struct operator_specific_device));
1851
1852 device->operator = strdup(operator);
1853 device->mixer_path = strdup(mixer_path);
1854 device->acdb_id = acdb_id;
1855
1856 list_add_tail(operator_specific_device_table[snd_device], &device->list);
1857
Eric Laurent2bafff12016-03-17 12:17:23 -07001858 ALOGD("%s: device[%s] -> operator[%s] mixer_path[%s] acdb_id[%d]", __func__,
keunhui.park2f7306a2015-07-16 16:48:06 +09001859 platform_get_snd_device_name(snd_device), operator, mixer_path, acdb_id);
1860
1861}
1862
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001863int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
1864{
1865 int ret = 0;
1866
1867 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1868 ALOGE("%s: Invalid snd_device = %d",
1869 __func__, snd_device);
1870 ret = -EINVAL;
1871 goto done;
1872 }
1873
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001874 ALOGV("%s: acdb_device_table[%s]: old = %d new = %d", __func__,
1875 platform_get_snd_device_name(snd_device), acdb_device_table[snd_device], acdb_id);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001876 acdb_device_table[snd_device] = acdb_id;
1877done:
1878 return ret;
1879}
1880
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001881int platform_get_snd_device_acdb_id(snd_device_t snd_device)
1882{
1883 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1884 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1885 return -EINVAL;
1886 }
keunhui.park2f7306a2015-07-16 16:48:06 +09001887
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07001888 /*
1889 * If speaker protection is enabled, function returns supported
1890 * sound device for speaker. Else same sound device is returned.
1891 */
1892 snd_device = audio_extn_get_spkr_prot_snd_device(snd_device);
1893
keunhui.park2f7306a2015-07-16 16:48:06 +09001894 if (operator_specific_device_table[snd_device] != NULL)
1895 return get_operator_specific_device_acdb_id(snd_device);
1896 else
1897 return acdb_device_table[snd_device];
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001898}
1899
David Linee3fe402017-03-13 10:00:42 -07001900static int platform_get_backend_index(snd_device_t snd_device)
1901{
1902 int32_t port = DEFAULT_CODEC_BACKEND;
1903
1904 if (snd_device >= SND_DEVICE_OUT_BEGIN && snd_device < SND_DEVICE_OUT_END) {
1905 if (backend_tag_table[snd_device] != NULL) {
1906 if (strncmp(backend_tag_table[snd_device], "headphones",
1907 sizeof("headphones")) == 0)
1908 port = HEADPHONE_BACKEND;
1909 else if (strcmp(backend_tag_table[snd_device], "hdmi") == 0)
1910 port = HDMI_RX_BACKEND;
1911 else if ((strcmp(backend_tag_table[snd_device], "usb-headphones") == 0) ||
1912 (strcmp(backend_tag_table[snd_device], "usb-headset") == 0))
1913 port = USB_AUDIO_RX_BACKEND;
1914 }
1915 } else if (snd_device >= SND_DEVICE_IN_BEGIN && snd_device < SND_DEVICE_IN_END) {
1916 port = DEFAULT_CODEC_TX_BACKEND;
1917 if (backend_tag_table[snd_device] != NULL) {
1918 if (strcmp(backend_tag_table[snd_device], "usb-headset-mic") == 0)
1919 port = USB_AUDIO_TX_BACKEND;
1920 else if (strstr(backend_tag_table[snd_device], "bt-sco") != NULL)
1921 port = BT_SCO_TX_BACKEND;
1922 }
1923 } else {
1924 ALOGW("%s:napb: Invalid device - %d ", __func__, snd_device);
1925 }
1926
1927 ALOGV("%s:napb: backend port - %d device - %d ", __func__, port, snd_device);
1928
1929 return port;
1930}
1931
Eric Laurentb23d5282013-05-14 15:27:20 -07001932int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
1933{
1934 struct platform_data *my_data = (struct platform_data *)platform;
1935 int acdb_dev_id, acdb_dev_type;
1936
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001937 if (platform_supports_app_type_cfg()) // use v2 instead
1938 return -ENOSYS;
1939
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07001940 acdb_dev_id = platform_get_snd_device_acdb_id(snd_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07001941 if (acdb_dev_id < 0) {
1942 ALOGE("%s: Could not find acdb id for device(%d)",
1943 __func__, snd_device);
1944 return -EINVAL;
1945 }
1946 if (my_data->acdb_send_audio_cal) {
Joe Onorato188b6222016-03-01 11:02:27 -08001947 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Eric Laurentb23d5282013-05-14 15:27:20 -07001948 __func__, snd_device, acdb_dev_id);
1949 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
1950 snd_device < SND_DEVICE_OUT_END)
1951 acdb_dev_type = ACDB_DEV_TYPE_OUT;
1952 else
1953 acdb_dev_type = ACDB_DEV_TYPE_IN;
1954 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
1955 }
1956 return 0;
1957}
1958
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001959int platform_send_audio_calibration_v2(void *platform, struct audio_usecase *usecase,
1960 int app_type, int sample_rate)
1961{
1962 struct platform_data *my_data = (struct platform_data *)platform;
1963 int acdb_dev_id, acdb_dev_type;
vivek mehta7e573672018-03-13 17:41:41 -07001964 int snd_device = usecase->out_snd_device;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001965 int new_snd_device[SND_DEVICE_OUT_END] = {0};
1966 int i, num_devices = 1;
1967
1968 if (!platform_supports_app_type_cfg()) // use v1 instead
1969 return -ENOSYS;
1970
vivek mehta7e573672018-03-13 17:41:41 -07001971 if ((usecase->type == PCM_HFP_CALL) || (usecase->type == PCM_CAPTURE))
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001972 snd_device = usecase->in_snd_device;
1973
1974 // skipped over get_spkr_prot_device
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07001975 acdb_dev_id = platform_get_snd_device_acdb_id(snd_device);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001976 if (acdb_dev_id < 0) {
1977 ALOGE("%s: Could not find acdb id for device(%d)",
1978 __func__, snd_device);
1979 return -EINVAL;
1980 }
1981
1982 if (platform_can_split_snd_device(snd_device,
1983 &num_devices, new_snd_device) < 0) {
1984 new_snd_device[0] = snd_device;
1985 }
1986
1987 for (i = 0; i < num_devices; i++) {
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07001988 acdb_dev_id = platform_get_snd_device_acdb_id(new_snd_device[i]);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001989 if (acdb_dev_id < 0) {
1990 ALOGE("%s: Could not find acdb id for device(%d)",
1991 __func__, new_snd_device[i]);
1992 return -EINVAL;
1993 }
1994 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
1995 __func__, new_snd_device[i], acdb_dev_id);
1996 if (new_snd_device[i] >= SND_DEVICE_OUT_BEGIN &&
1997 new_snd_device[i] < SND_DEVICE_OUT_END)
1998 acdb_dev_type = ACDB_DEV_TYPE_OUT;
1999 else
2000 acdb_dev_type = ACDB_DEV_TYPE_IN;
2001
2002 if (my_data->acdb_send_audio_cal_v3) {
2003 my_data->acdb_send_audio_cal_v3(acdb_dev_id, acdb_dev_type,
2004 app_type, sample_rate, i);
2005 } else if (my_data->acdb_send_audio_cal) {
2006 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type); // this version differs from internal
2007 }
2008 }
2009
2010 return 0;
2011}
2012
2013
Eric Laurentb23d5282013-05-14 15:27:20 -07002014int platform_switch_voice_call_device_pre(void *platform)
2015{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002016 struct platform_data *my_data = (struct platform_data *)platform;
2017 int ret = 0;
2018
2019 if (my_data->csd != NULL &&
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002020 voice_is_in_call(my_data->adev)) {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002021 /* This must be called before disabling mixer controls on APQ side */
2022 ret = my_data->csd->disable_device();
2023 if (ret < 0) {
2024 ALOGE("%s: csd_client_disable_device, failed, error %d",
2025 __func__, ret);
2026 }
2027 }
2028 return ret;
2029}
2030
2031int platform_switch_voice_call_enable_device_config(void *platform,
2032 snd_device_t out_snd_device,
2033 snd_device_t in_snd_device)
2034{
2035 struct platform_data *my_data = (struct platform_data *)platform;
2036 int acdb_rx_id, acdb_tx_id;
2037 int ret = 0;
2038
2039 if (my_data->csd == NULL)
2040 return ret;
2041
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002042 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
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 {
keunhui.park2f7306a2015-07-16 16:48:06 +09002069 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
2070 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07002071
2072 if (acdb_rx_id > 0 && acdb_tx_id > 0)
2073 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
2074 else
2075 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2076 acdb_rx_id, acdb_tx_id);
2077 }
2078
2079 return 0;
2080}
2081
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002082int platform_switch_voice_call_usecase_route_post(void *platform,
2083 snd_device_t out_snd_device,
2084 snd_device_t in_snd_device)
2085{
2086 struct platform_data *my_data = (struct platform_data *)platform;
2087 int acdb_rx_id, acdb_tx_id;
2088 int ret = 0;
2089
2090 if (my_data->csd == NULL)
2091 return ret;
2092
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002093 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
keunhui.park2f7306a2015-07-16 16:48:06 +09002094 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002095
2096 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
2097 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
2098 my_data->adev->acdb_settings);
2099 if (ret < 0) {
2100 ALOGE("%s: csd_enable_device, failed, error %d", __func__, ret);
2101 }
2102 } else {
2103 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2104 acdb_rx_id, acdb_tx_id);
2105 }
2106
2107 return ret;
2108}
2109
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002110int platform_start_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07002111{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002112 struct platform_data *my_data = (struct platform_data *)platform;
2113 int ret = 0;
2114
2115 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002116 ret = my_data->csd->start_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002117 if (ret < 0) {
2118 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
2119 }
2120 }
2121 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002122}
2123
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002124int platform_stop_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07002125{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002126 struct platform_data *my_data = (struct platform_data *)platform;
2127 int ret = 0;
2128
2129 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002130 ret = my_data->csd->stop_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002131 if (ret < 0) {
2132 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
2133 }
2134 }
2135 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002136}
2137
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002138int platform_get_sample_rate(void *platform, uint32_t *rate)
2139{
2140 struct platform_data *my_data = (struct platform_data *)platform;
2141 int ret = 0;
2142
2143 if (my_data->csd != NULL) {
2144 ret = my_data->csd->get_sample_rate(rate);
2145 if (ret < 0) {
2146 ALOGE("%s: csd_get_sample_rate error %d\n", __func__, ret);
2147 }
2148 }
2149 return ret;
2150}
2151
vivek mehtab6506412015-08-07 16:55:17 -07002152void platform_set_speaker_gain_in_combo(struct audio_device *adev,
2153 snd_device_t snd_device,
2154 bool enable)
2155{
2156 const char* name;
2157 switch (snd_device) {
2158 case SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES:
2159 if (enable)
2160 name = "spkr-gain-in-headphone-combo";
2161 else
2162 name = "speaker-gain-default";
2163 break;
2164 case SND_DEVICE_OUT_SPEAKER_AND_LINE:
2165 if (enable)
2166 name = "spkr-gain-in-line-combo";
2167 else
2168 name = "speaker-gain-default";
2169 break;
2170 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES:
2171 if (enable)
2172 name = "spkr-safe-gain-in-headphone-combo";
2173 else
2174 name = "speaker-safe-gain-default";
2175 break;
2176 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE:
2177 if (enable)
2178 name = "spkr-safe-gain-in-line-combo";
2179 else
2180 name = "speaker-safe-gain-default";
2181 break;
2182 default:
2183 return;
2184 }
2185
2186 audio_route_apply_and_update_path(adev->audio_route, name);
2187}
2188
Eric Laurentb23d5282013-05-14 15:27:20 -07002189int platform_set_voice_volume(void *platform, int volume)
2190{
2191 struct platform_data *my_data = (struct platform_data *)platform;
2192 struct audio_device *adev = my_data->adev;
2193 struct mixer_ctl *ctl;
sangwoo53b2cf02013-07-25 19:18:44 -07002194 const char *mixer_ctl_name = "Voice Rx Gain";
Nadav Barc46d0fa2017-12-24 14:50:37 +02002195 const char *mute_mixer_ctl_name = "Voice Rx Device Mute";
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002196 int vol_index = 0, ret = 0;
2197 uint32_t set_values[ ] = {0,
2198 ALL_SESSION_VSID,
2199 DEFAULT_VOLUME_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07002200
2201 // Voice volume levels are mapped to adsp volume levels as follows.
2202 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
2203 // But this values don't changed in kernel. So, below change is need.
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09002204 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, my_data->max_vol_index);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002205 set_values[0] = vol_index;
Eric Laurentb23d5282013-05-14 15:27:20 -07002206
2207 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2208 if (!ctl) {
2209 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2210 __func__, mixer_ctl_name);
2211 return -EINVAL;
2212 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002213 ALOGV("Setting voice volume index: %d", set_values[0]);
2214 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2215
Nadav Barc46d0fa2017-12-24 14:50:37 +02002216 // Send mute command in case volume index is max since indexes are inverted
2217 // for mixer controls.
2218 if (vol_index == my_data->max_vol_index) {
2219 set_values[0] = 1;
2220 }
2221 else {
2222 set_values[0] = 0;
2223 }
2224
2225 ctl = mixer_get_ctl_by_name(adev->mixer, mute_mixer_ctl_name);
2226 if (!ctl) {
2227 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2228 __func__, mute_mixer_ctl_name);
2229 return -EINVAL;
2230 }
2231 ALOGV("%s: Setting RX Device Mute to: %d", __func__, set_values[0]);
2232 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2233
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002234 if (my_data->csd != NULL) {
2235 ret = my_data->csd->volume(ALL_SESSION_VSID, volume,
2236 DEFAULT_VOLUME_RAMP_DURATION_MS);
2237 if (ret < 0) {
2238 ALOGE("%s: csd_volume error %d", __func__, ret);
2239 }
2240 }
2241 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002242}
2243
2244int platform_set_mic_mute(void *platform, bool state)
2245{
2246 struct platform_data *my_data = (struct platform_data *)platform;
2247 struct audio_device *adev = my_data->adev;
2248 struct mixer_ctl *ctl;
2249 const char *mixer_ctl_name = "Voice Tx Mute";
sangwoo53b2cf02013-07-25 19:18:44 -07002250 int ret = 0;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002251 uint32_t set_values[ ] = {0,
2252 ALL_SESSION_VSID,
2253 DEFAULT_MUTE_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07002254
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09002255 if (adev->mode != AUDIO_MODE_IN_CALL &&
2256 adev->mode != AUDIO_MODE_IN_COMMUNICATION)
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002257 return 0;
2258
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09002259 if (adev->enable_hfp)
2260 mixer_ctl_name = "HFP Tx Mute";
2261
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002262 set_values[0] = state;
2263 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2264 if (!ctl) {
2265 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2266 __func__, mixer_ctl_name);
2267 return -EINVAL;
2268 }
2269 ALOGV("Setting voice mute state: %d", state);
2270 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2271
2272 if (my_data->csd != NULL) {
2273 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state,
2274 DEFAULT_MUTE_RAMP_DURATION_MS);
sangwoo53b2cf02013-07-25 19:18:44 -07002275 if (ret < 0) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002276 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
sangwoo53b2cf02013-07-25 19:18:44 -07002277 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002278 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002279 return ret;
2280}
Eric Laurentb23d5282013-05-14 15:27:20 -07002281
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002282int platform_set_device_mute(void *platform, bool state, char *dir)
2283{
2284 struct platform_data *my_data = (struct platform_data *)platform;
2285 struct audio_device *adev = my_data->adev;
2286 struct mixer_ctl *ctl;
2287 char *mixer_ctl_name = NULL;
2288 int ret = 0;
2289 uint32_t set_values[ ] = {0,
2290 ALL_SESSION_VSID,
2291 0};
2292 if(dir == NULL) {
2293 ALOGE("%s: Invalid direction:%s", __func__, dir);
2294 return -EINVAL;
2295 }
2296
2297 if (!strncmp("rx", dir, sizeof("rx"))) {
2298 mixer_ctl_name = "Voice Rx Device Mute";
2299 } else if (!strncmp("tx", dir, sizeof("tx"))) {
2300 mixer_ctl_name = "Voice Tx Device Mute";
2301 } else {
2302 return -EINVAL;
2303 }
2304
2305 set_values[0] = state;
2306 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2307 if (!ctl) {
2308 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2309 __func__, mixer_ctl_name);
2310 return -EINVAL;
2311 }
2312
2313 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
2314 __func__,state, mixer_ctl_name);
2315 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2316
2317 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002318}
2319
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002320int platform_can_split_snd_device(snd_device_t snd_device,
2321 int *num_devices,
2322 snd_device_t *new_snd_devices)
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002323{
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002324 int ret = -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002325 if (NULL == num_devices || NULL == new_snd_devices) {
2326 ALOGE("%s: NULL pointer ..", __func__);
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002327 return -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002328 }
2329
2330 /*
2331 * If wired headset/headphones/line devices share the same backend
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002332 * with speaker/earpiece this routine returns -EINVAL.
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002333 */
2334 if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES &&
2335 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_HEADPHONES)) {
2336 *num_devices = 2;
2337 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2338 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002339 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002340 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_LINE &&
2341 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_LINE)) {
2342 *num_devices = 2;
2343 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2344 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002345 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002346 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES &&
2347 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_HEADPHONES)) {
2348 *num_devices = 2;
2349 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2350 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002351 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002352 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE &&
2353 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_LINE)) {
2354 *num_devices = 2;
2355 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2356 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002357 ret = 0;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002358 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO &&
2359 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2360 SND_DEVICE_OUT_BT_SCO)) {
2361 *num_devices = 2;
2362 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2363 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO;
2364 ret = 0;
2365 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB &&
2366 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2367 SND_DEVICE_OUT_BT_SCO_WB)) {
2368 *num_devices = 2;
2369 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2370 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO_WB;
2371 ret = 0;
David Linee3fe402017-03-13 10:00:42 -07002372 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET &&
2373 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_USB_HEADSET)) {
2374 *num_devices = 2;
2375 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2376 new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
2377 ret = 0;
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07002378 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET &&
2379 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_USB_HEADSET)) {
2380 *num_devices = 2;
2381 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2382 new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
2383 ret = 0;
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002384 } else if (SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP == snd_device &&
2385 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2386 SND_DEVICE_OUT_BT_A2DP)) {
2387 *num_devices = 2;
2388 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2389 new_snd_devices[1] = SND_DEVICE_OUT_BT_A2DP;
2390 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002391 }
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002392
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002393 return ret;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002394}
2395
Eric Laurentb23d5282013-05-14 15:27:20 -07002396snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
2397{
2398 struct platform_data *my_data = (struct platform_data *)platform;
2399 struct audio_device *adev = my_data->adev;
2400 audio_mode_t mode = adev->mode;
2401 snd_device_t snd_device = SND_DEVICE_NONE;
2402
2403 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
2404 if (devices == AUDIO_DEVICE_NONE ||
2405 devices & AUDIO_DEVICE_BIT_IN) {
2406 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
2407 goto exit;
2408 }
2409
Eric Laurent1b491552015-09-15 17:52:41 -07002410 if (popcount(devices) == 2) {
2411 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2412 AUDIO_DEVICE_OUT_SPEAKER) ||
2413 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2414 AUDIO_DEVICE_OUT_SPEAKER)) {
2415 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
2416 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2417 AUDIO_DEVICE_OUT_SPEAKER)) {
2418 snd_device = SND_DEVICE_OUT_SPEAKER_AND_LINE;
2419 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2420 AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
2421 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2422 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2423 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES;
2424 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2425 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2426 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE;
2427 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
2428 AUDIO_DEVICE_OUT_SPEAKER)) {
2429 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002430 } else if ((devices & AUDIO_DEVICE_OUT_ALL_SCO) &&
2431 ((devices & ~AUDIO_DEVICE_OUT_ALL_SCO) == AUDIO_DEVICE_OUT_SPEAKER)) {
2432 snd_device = adev->bt_wb_speech_enabled ?
2433 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB :
2434 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO;
Eric Laurent99dab492017-06-17 15:19:08 -07002435 } else if ((devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
2436 AUDIO_DEVICE_OUT_SPEAKER)) ||
2437 (devices == (AUDIO_DEVICE_OUT_USB_HEADSET |
2438 AUDIO_DEVICE_OUT_SPEAKER))) {
David Linee3fe402017-03-13 10:00:42 -07002439 snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET;
Eric Laurentd0f7c262017-07-05 09:09:12 -07002440 } else if ((devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
2441 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) ||
2442 (devices == (AUDIO_DEVICE_OUT_USB_HEADSET |
2443 AUDIO_DEVICE_OUT_SPEAKER_SAFE))) {
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07002444 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET;
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002445 } else if ((devices & AUDIO_DEVICE_OUT_SPEAKER) &&
2446 (devices & AUDIO_DEVICE_OUT_ALL_A2DP)) {
2447 snd_device = SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP;
Eric Laurent1b491552015-09-15 17:52:41 -07002448 } else {
2449 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
2450 goto exit;
2451 }
2452 if (snd_device != SND_DEVICE_NONE) {
2453 goto exit;
2454 }
2455 }
2456
2457 if (popcount(devices) != 1) {
2458 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
2459 goto exit;
2460 }
2461
Madhuri Athota3f6051b2016-10-13 23:25:38 +05302462 if (voice_is_in_call(adev) || adev->enable_voicerx || audio_extn_hfp_is_active(adev)) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002463 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002464 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2465 devices & AUDIO_DEVICE_OUT_LINE) {
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002466 if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002467 (adev->voice.tty_mode == TTY_MODE_FULL))
Eric Laurentb23d5282013-05-14 15:27:20 -07002468 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002469 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002470 (adev->voice.tty_mode == TTY_MODE_VCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002471 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002472 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002473 (adev->voice.tty_mode == TTY_MODE_HCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002474 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002475 else {
2476 if (devices & AUDIO_DEVICE_OUT_LINE)
2477 snd_device = SND_DEVICE_OUT_VOICE_LINE;
2478 else
2479 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
2480 }
Eric Laurent99dab492017-06-17 15:19:08 -07002481 } else if (audio_is_usb_out_device(devices)) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002482 if (voice_is_in_call(adev)) {
2483 switch (adev->voice.tty_mode) {
2484 case TTY_MODE_FULL:
2485 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_USB;
2486 break;
2487 case TTY_MODE_VCO:
2488 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_USB;
2489 break;
2490 case TTY_MODE_HCO:
2491 // since Hearing will be on handset\speaker, use existing device
2492 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
2493 break;
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002494 case TTY_MODE_OFF:
2495 break;
vivek mehtaa6b79742017-03-09 15:40:43 -08002496 default:
2497 ALOGE("%s: Invalid TTY mode (%#x)",
2498 __func__, adev->voice.tty_mode);
2499 }
2500 }
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002501 if (snd_device == SND_DEVICE_NONE) {
2502 snd_device = audio_extn_usb_is_capture_supported() ?
2503 SND_DEVICE_OUT_VOICE_USB_HEADSET :
2504 SND_DEVICE_OUT_VOICE_USB_HEADPHONES;
2505 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002506 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002507 if (adev->bt_wb_speech_enabled) {
2508 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2509 } else {
2510 snd_device = SND_DEVICE_OUT_BT_SCO;
2511 }
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002512 } else if (devices & AUDIO_DEVICE_OUT_ALL_A2DP) {
2513 snd_device = SND_DEVICE_OUT_BT_A2DP;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002514 } else if (devices & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002515 if (!adev->enable_hfp) {
2516 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
2517 } else {
2518 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_HFP;
2519 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002520 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002521 if(adev->voice.hac)
2522 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2523 else if (is_operator_tmus())
Eric Laurentb23d5282013-05-14 15:27:20 -07002524 snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS;
2525 else
Eric Laurentb4d368e2014-06-25 10:21:54 -05002526 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002527 } else if (devices & AUDIO_DEVICE_OUT_TELEPHONY_TX)
2528 snd_device = SND_DEVICE_OUT_VOICE_TX;
2529
Eric Laurentb23d5282013-05-14 15:27:20 -07002530 if (snd_device != SND_DEVICE_NONE) {
2531 goto exit;
2532 }
2533 }
2534
Eric Laurentb23d5282013-05-14 15:27:20 -07002535 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2536 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2537 snd_device = SND_DEVICE_OUT_HEADPHONES;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002538 } else if (devices & AUDIO_DEVICE_OUT_LINE) {
2539 snd_device = SND_DEVICE_OUT_LINE;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002540 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) {
2541 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE;
Eric Laurentb23d5282013-05-14 15:27:20 -07002542 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
andysu5b30b062018-04-20 16:34:06 +08002543 /*
2544 * Perform device switch only if acdb tuning is different between SPEAKER & SPEAKER_REVERSE,
2545 * Or there will be a small pause while performing device switch.
2546 */
2547 if (my_data->speaker_lr_swap &&
2548 (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
2549 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]))
Eric Laurentb23d5282013-05-14 15:27:20 -07002550 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
2551 else
2552 snd_device = SND_DEVICE_OUT_SPEAKER;
2553 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002554 if (adev->bt_wb_speech_enabled) {
2555 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2556 } else {
2557 snd_device = SND_DEVICE_OUT_BT_SCO;
2558 }
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002559 } else if (devices & AUDIO_DEVICE_OUT_ALL_A2DP) {
2560 snd_device = SND_DEVICE_OUT_BT_A2DP;
Eric Laurentb23d5282013-05-14 15:27:20 -07002561 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2562 snd_device = SND_DEVICE_OUT_HDMI ;
Eric Laurent99dab492017-06-17 15:19:08 -07002563 } else if (audio_is_usb_out_device(devices)) {
David Linee3fe402017-03-13 10:00:42 -07002564 if (audio_extn_usb_is_capture_supported())
2565 snd_device = SND_DEVICE_OUT_USB_HEADSET;
2566 else
2567 snd_device = SND_DEVICE_OUT_USB_HEADPHONES;
2568 }else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002569 /*HAC support for voice-ish audio (eg visual voicemail)*/
2570 if(adev->voice.hac)
2571 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2572 else
2573 snd_device = SND_DEVICE_OUT_HANDSET;
Eric Laurentb23d5282013-05-14 15:27:20 -07002574 } else {
2575 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
2576 }
2577exit:
2578 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
2579 return snd_device;
2580}
2581
2582snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
2583{
2584 struct platform_data *my_data = (struct platform_data *)platform;
2585 struct audio_device *adev = my_data->adev;
2586 audio_source_t source = (adev->active_input == NULL) ?
2587 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
2588
2589 audio_mode_t mode = adev->mode;
2590 audio_devices_t in_device = ((adev->active_input == NULL) ?
2591 AUDIO_DEVICE_NONE : adev->active_input->device)
2592 & ~AUDIO_DEVICE_BIT_IN;
2593 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
2594 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
2595 snd_device_t snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002596 int channel_count = popcount(channel_mask);
Eric Laurentb23d5282013-05-14 15:27:20 -07002597
Prashant Malanic92c5962015-08-11 15:10:18 -07002598 ALOGV("%s: enter: out_device(%#x) in_device(%#x) channel_count (%d) channel_mask (0x%x)",
2599 __func__, out_device, in_device, channel_count, channel_mask);
Devin Kimd789e432016-10-26 15:07:27 -07002600 if ((out_device != AUDIO_DEVICE_NONE) && (voice_is_in_call(adev) ||
2601 audio_extn_hfp_is_active(adev))) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002602 if (adev->voice.tty_mode != TTY_MODE_OFF) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002603 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002604 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2605 out_device & AUDIO_DEVICE_OUT_LINE) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002606 switch (adev->voice.tty_mode) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002607 case TTY_MODE_FULL:
2608 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
2609 break;
2610 case TTY_MODE_VCO:
2611 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
2612 break;
2613 case TTY_MODE_HCO:
2614 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
2615 break;
2616 default:
2617 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
2618 }
2619 goto exit;
Eric Laurent99dab492017-06-17 15:19:08 -07002620 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002621 switch (adev->voice.tty_mode) {
2622 case TTY_MODE_FULL:
2623 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC;
2624 break;
2625 case TTY_MODE_VCO:
2626 // since voice will be captured from handset mic, use existing device
2627 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
2628 break;
2629 case TTY_MODE_HCO:
2630 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC;
2631 break;
2632 default:
2633 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
Eric Laurentb23d5282013-05-14 15:27:20 -07002634 }
2635 goto exit;
2636 }
2637 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002638 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002639 if (my_data->fluence_in_voice_call == false) {
2640 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2641 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002642 if (is_operator_tmus())
2643 snd_device = SND_DEVICE_IN_VOICE_DMIC_TMUS;
Eric Laurentb23d5282013-05-14 15:27:20 -07002644 else
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002645 snd_device = SND_DEVICE_IN_VOICE_DMIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002646 }
2647 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2648 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
2649 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002650 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002651 if (adev->bluetooth_nrec)
2652 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2653 else
2654 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002655 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002656 if (adev->bluetooth_nrec)
2657 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2658 else
2659 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002660 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002661 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Prashant Malanic92c5962015-08-11 15:10:18 -07002662 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
2663 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2664 out_device & AUDIO_DEVICE_OUT_LINE) {
2665 if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
2666 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
2667 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
2668 } else {
2669 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2670 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002671 }
vivek mehtafe121d52015-08-10 23:39:23 -07002672
2673 //select default
2674 if (snd_device == SND_DEVICE_NONE) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002675 if (!adev->enable_hfp) {
2676 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2677 } else {
2678 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP;
2679 platform_set_echo_reference(adev, true, out_device);
2680 }
vivek mehtafe121d52015-08-10 23:39:23 -07002681 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002682 } else if (out_device & AUDIO_DEVICE_OUT_TELEPHONY_TX) {
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002683 snd_device = SND_DEVICE_IN_VOICE_RX;
Eric Laurent99dab492017-06-17 15:19:08 -07002684 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
David Lin40b07892017-08-07 15:02:48 -07002685 if (audio_extn_usb_is_capture_supported()) {
2686 snd_device = SND_DEVICE_IN_VOICE_USB_HEADSET_MIC;
2687 } else if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
2688 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
2689 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
2690 } else {
2691 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2692 }
2693 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002694 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002695 } else if (source == AUDIO_SOURCE_CAMCORDER) {
2696 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
2697 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2698 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
2699 }
2700 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
2701 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002702 if (my_data->fluence_in_voice_rec && channel_count == 1) {
2703 if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2704 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002705 if (adev->active_input->enable_aec)
2706 snd_device = SND_DEVICE_IN_HANDSET_QMIC_AEC;
2707 else
2708 snd_device = SND_DEVICE_IN_HANDSET_QMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002709 } else if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2710 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002711 if (adev->active_input->enable_aec)
2712 snd_device = SND_DEVICE_IN_HANDSET_TMIC_AEC;
2713 else
2714 snd_device = SND_DEVICE_IN_HANDSET_TMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002715 } else if (((my_data->fluence_type == FLUENCE_PRO_ENABLE) ||
2716 (my_data->fluence_type == FLUENCE_ENABLE)) &&
2717 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002718 if (adev->active_input->enable_aec)
2719 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
2720 else
2721 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
Prashant Malanic92c5962015-08-11 15:10:18 -07002722 }
2723 platform_set_echo_reference(adev, true, out_device);
2724 } else if ((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) &&
2725 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2726 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002727 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002728 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
2729 snd_device = SND_DEVICE_IN_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002730 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002731 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2732 snd_device = SND_DEVICE_IN_QUAD_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002733 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002734 if (snd_device == SND_DEVICE_NONE) {
vivek mehtaf3440682016-05-11 14:24:37 -07002735 if (adev->active_input->enable_aec) {
2736 if (adev->active_input->enable_ns) {
2737 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS;
2738 } else {
2739 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC;
2740 }
vivek mehta733c1df2016-04-04 15:09:24 -07002741 platform_set_echo_reference(adev, true, out_device);
vivek mehtaf3440682016-05-11 14:24:37 -07002742 } else if (adev->active_input->enable_ns) {
2743 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
2744 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002745 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
vivek mehtaf3440682016-05-11 14:24:37 -07002746 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002747 }
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -07002748 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2749 snd_device = SND_DEVICE_IN_VOICE_REC_HEADSET_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07002750 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002751 snd_device = SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002752 }
rago90fb9612015-12-02 11:37:53 -08002753 } else if (source == AUDIO_SOURCE_UNPROCESSED) {
2754 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
vivek mehta4ed66e62016-04-15 23:33:34 -07002755 if (((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) ||
2756 (channel_mask == AUDIO_CHANNEL_IN_STEREO)) &&
2757 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2758 snd_device = SND_DEVICE_IN_UNPROCESSED_STEREO_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002759 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07002760 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
2761 snd_device = SND_DEVICE_IN_UNPROCESSED_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002762 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07002763 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2764 snd_device = SND_DEVICE_IN_UNPROCESSED_QUAD_MIC;
2765 } else {
2766 snd_device = SND_DEVICE_IN_UNPROCESSED_MIC;
2767 }
rago90fb9612015-12-02 11:37:53 -08002768 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2769 snd_device = SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07002770 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002771 snd_device = SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC;
rago90fb9612015-12-02 11:37:53 -08002772 }
Eric Laurent50a38ed2015-10-14 18:48:06 -07002773 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION ||
rago90fb9612015-12-02 11:37:53 -08002774 mode == AUDIO_MODE_IN_COMMUNICATION) {
David Lin40b07892017-08-07 15:02:48 -07002775 if (out_device & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
2776 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2777 (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE | AUDIO_DEVICE_OUT_USB_HEADSET) &&
2778 !audio_extn_usb_is_capture_supported())) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002779 in_device = AUDIO_DEVICE_IN_BACK_MIC;
David Lin40b07892017-08-07 15:02:48 -07002780 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002781 if (adev->active_input) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002782 if (adev->active_input->enable_aec &&
2783 adev->active_input->enable_ns) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002784 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002785 if (my_data->fluence_in_spkr_mode &&
2786 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002787 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002788 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002789 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002790 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002791 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002792 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002793 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002794 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002795 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002796 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002797 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002798 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002799 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2800 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Eric Laurent99dab492017-06-17 15:19:08 -07002801 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002802 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002803 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002804 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002805 } else if (adev->active_input->enable_aec) {
2806 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2807 if (my_data->fluence_in_spkr_mode &&
2808 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002809 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002810 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002811 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002812 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002813 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002814 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2815 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002816 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002817 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002818 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002819 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002820 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002821 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2822 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Eric Laurent99dab492017-06-17 15:19:08 -07002823 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002824 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
Eric Laurentcefbbac2014-09-04 13:54:10 -05002825 }
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08002826 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002827 } else if (adev->active_input->enable_ns) {
2828 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2829 if (my_data->fluence_in_spkr_mode &&
2830 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002831 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002832 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002833 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002834 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002835 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002836 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2837 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002838 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002839 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002840 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002841 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002842 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002843 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002844 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002845 }
2846 } else if (source == AUDIO_SOURCE_DEFAULT) {
2847 goto exit;
2848 }
2849
2850
2851 if (snd_device != SND_DEVICE_NONE) {
2852 goto exit;
2853 }
2854
2855 if (in_device != AUDIO_DEVICE_NONE &&
2856 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
2857 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
2858 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002859 if ((my_data->source_mic_type & SOURCE_QUAD_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002860 channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002861 snd_device = SND_DEVICE_IN_QUAD_MIC;
2862 } else if ((my_data->source_mic_type & SOURCE_THREE_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002863 channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002864 snd_device = SND_DEVICE_IN_THREE_MIC;
2865 } else if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2866 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002867 snd_device = SND_DEVICE_IN_HANDSET_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002868 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2869 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002870 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002871 } else {
2872 ALOGE("%s: something wrong (1): source type (%d) channel_count (%d) .."
2873 " channel mask (0x%x) no combination found .. setting to mono", __func__,
2874 my_data->source_mic_type, channel_count, channel_mask);
2875 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2876 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002877 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002878 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2879 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002880 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002881 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2882 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002883 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002884 } else {
2885 ALOGE("%s: something wrong (2): source type (%d) channel_count (%d) .."
2886 " no combination found .. setting to mono", __func__,
2887 my_data->source_mic_type, channel_count);
2888 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
2889 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002890 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2891 snd_device = SND_DEVICE_IN_HEADSET_MIC;
2892 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002893 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002894 if (adev->bluetooth_nrec)
2895 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2896 else
2897 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002898 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002899 if (adev->bluetooth_nrec)
2900 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2901 else
2902 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002903 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002904 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
2905 snd_device = SND_DEVICE_IN_HDMI_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07002906 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
David Linee3fe402017-03-13 10:00:42 -07002907 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002908 } else {
2909 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
2910 ALOGW("%s: Using default handset-mic", __func__);
2911 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2912 }
2913 } else {
2914 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
2915 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2916 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2917 snd_device = SND_DEVICE_IN_HEADSET_MIC;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002918 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002919 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002920 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002921 out_device & AUDIO_DEVICE_OUT_LINE) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002922 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2923 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002924 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002925 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2926 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002927 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002928 } else {
2929 ALOGE("%s: something wrong (3): source type (%d) channel_count (%d) .."
2930 " no combination found .. setting to mono", __func__,
2931 my_data->source_mic_type, channel_count);
2932 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
2933 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002934 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002935 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002936 if (adev->bluetooth_nrec)
2937 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2938 else
2939 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002940 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002941 if (adev->bluetooth_nrec)
2942 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2943 else
2944 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002945 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002946 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2947 snd_device = SND_DEVICE_IN_HDMI_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07002948 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
David Linee3fe402017-03-13 10:00:42 -07002949 if (audio_extn_usb_is_capture_supported())
2950 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
2951 else
2952 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002953 } else {
2954 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
2955 ALOGW("%s: Using default handset-mic", __func__);
2956 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2957 }
2958 }
2959exit:
2960 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
2961 return snd_device;
2962}
2963
2964int platform_set_hdmi_channels(void *platform, int channel_count)
2965{
2966 struct platform_data *my_data = (struct platform_data *)platform;
2967 struct audio_device *adev = my_data->adev;
2968 struct mixer_ctl *ctl;
2969 const char *channel_cnt_str = NULL;
2970 const char *mixer_ctl_name = "HDMI_RX Channels";
2971 switch (channel_count) {
2972 case 8:
2973 channel_cnt_str = "Eight"; break;
2974 case 7:
2975 channel_cnt_str = "Seven"; break;
2976 case 6:
2977 channel_cnt_str = "Six"; break;
2978 case 5:
2979 channel_cnt_str = "Five"; break;
2980 case 4:
2981 channel_cnt_str = "Four"; break;
2982 case 3:
2983 channel_cnt_str = "Three"; break;
2984 default:
2985 channel_cnt_str = "Two"; break;
2986 }
2987 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2988 if (!ctl) {
2989 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2990 __func__, mixer_ctl_name);
2991 return -EINVAL;
2992 }
2993 ALOGV("HDMI channel count: %s", channel_cnt_str);
2994 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
2995 return 0;
2996}
2997
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002998int platform_edid_get_max_channels(void *platform)
Eric Laurentb23d5282013-05-14 15:27:20 -07002999{
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003000 struct platform_data *my_data = (struct platform_data *)platform;
3001 struct audio_device *adev = my_data->adev;
Eric Laurentb23d5282013-05-14 15:27:20 -07003002 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
3003 char *sad = block;
3004 int num_audio_blocks;
3005 int channel_count;
3006 int max_channels = 0;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003007 int i, ret, count;
Eric Laurentb23d5282013-05-14 15:27:20 -07003008
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003009 struct mixer_ctl *ctl;
3010
3011 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
3012 if (!ctl) {
3013 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3014 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
Eric Laurentb23d5282013-05-14 15:27:20 -07003015 return 0;
3016 }
3017
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003018 mixer_ctl_update(ctl);
3019
3020 count = mixer_ctl_get_num_values(ctl);
Eric Laurentb23d5282013-05-14 15:27:20 -07003021
3022 /* Read SAD blocks, clamping the maximum size for safety */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003023 if (count > (int)sizeof(block))
3024 count = (int)sizeof(block);
Eric Laurentb23d5282013-05-14 15:27:20 -07003025
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003026 ret = mixer_ctl_get_array(ctl, block, count);
3027 if (ret != 0) {
3028 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
3029 return 0;
3030 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003031
3032 /* Calculate the number of SAD blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003033 num_audio_blocks = count / SAD_BLOCK_SIZE;
Eric Laurentb23d5282013-05-14 15:27:20 -07003034
3035 for (i = 0; i < num_audio_blocks; i++) {
3036 /* Only consider LPCM blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003037 if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
3038 sad += 3;
Eric Laurentb23d5282013-05-14 15:27:20 -07003039 continue;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003040 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003041
3042 channel_count = (sad[0] & 0x7) + 1;
3043 if (channel_count > max_channels)
3044 max_channels = channel_count;
3045
3046 /* Advance to next block */
3047 sad += 3;
3048 }
3049
3050 return max_channels;
3051}
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003052
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07003053int platform_set_incall_recording_session_id(void *platform,
3054 uint32_t session_id, int rec_mode)
3055{
3056 int ret = 0;
3057 struct platform_data *my_data = (struct platform_data *)platform;
3058 struct audio_device *adev = my_data->adev;
3059 struct mixer_ctl *ctl;
3060 const char *mixer_ctl_name = "Voc VSID";
3061 int num_ctl_values;
3062 int i;
3063
3064 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3065 if (!ctl) {
3066 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3067 __func__, mixer_ctl_name);
3068 ret = -EINVAL;
3069 } else {
3070 num_ctl_values = mixer_ctl_get_num_values(ctl);
3071 for (i = 0; i < num_ctl_values; i++) {
3072 if (mixer_ctl_set_value(ctl, i, session_id)) {
3073 ALOGV("Error: invalid session_id: %x", session_id);
3074 ret = -EINVAL;
3075 break;
3076 }
3077 }
3078 }
3079
3080 if (my_data->csd != NULL) {
3081 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
3082 if (ret < 0) {
3083 ALOGE("%s: csd_client_start_record failed, error %d",
3084 __func__, ret);
3085 }
3086 }
3087
3088 return ret;
3089}
3090
3091int platform_stop_incall_recording_usecase(void *platform)
3092{
3093 int ret = 0;
3094 struct platform_data *my_data = (struct platform_data *)platform;
3095
3096 if (my_data->csd != NULL) {
3097 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
3098 if (ret < 0) {
3099 ALOGE("%s: csd_client_stop_record failed, error %d",
3100 __func__, ret);
3101 }
3102 }
3103
3104 return ret;
3105}
3106
3107int platform_start_incall_music_usecase(void *platform)
3108{
3109 int ret = 0;
3110 struct platform_data *my_data = (struct platform_data *)platform;
3111
3112 if (my_data->csd != NULL) {
3113 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
3114 if (ret < 0) {
3115 ALOGE("%s: csd_client_start_playback failed, error %d",
3116 __func__, ret);
3117 }
3118 }
3119
3120 return ret;
3121}
3122
3123int platform_stop_incall_music_usecase(void *platform)
3124{
3125 int ret = 0;
3126 struct platform_data *my_data = (struct platform_data *)platform;
3127
3128 if (my_data->csd != NULL) {
3129 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
3130 if (ret < 0) {
3131 ALOGE("%s: csd_client_stop_playback failed, error %d",
3132 __func__, ret);
3133 }
3134 }
3135
3136 return ret;
3137}
3138
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003139int platform_set_parameters(void *platform, struct str_parms *parms)
3140{
3141 struct platform_data *my_data = (struct platform_data *)platform;
keunhui.park2f7306a2015-07-16 16:48:06 +09003142 char value[128];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003143 char *kv_pairs = str_parms_to_str(parms);
3144 int ret = 0, err;
3145
3146 if (kv_pairs == NULL) {
3147 ret = -EINVAL;
3148 ALOGE("%s: key-value pair is NULL",__func__);
3149 goto done;
3150 }
3151
3152 ALOGV("%s: enter: %s", __func__, kv_pairs);
3153
3154 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME,
3155 value, sizeof(value));
3156 if (err >= 0) {
3157 str_parms_del(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME);
3158 my_data->snd_card_name = strdup(value);
3159 ALOGV("%s: sound card name %s", __func__, my_data->snd_card_name);
3160 }
3161
keunhui.park2f7306a2015-07-16 16:48:06 +09003162 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO,
3163 value, sizeof(value));
3164 if (err >= 0) {
3165 struct operator_info *info;
3166 char *str = value;
3167 char *name;
3168
3169 str_parms_del(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO);
3170 info = (struct operator_info *)calloc(1, sizeof(struct operator_info));
3171 name = strtok(str, ";");
3172 info->name = strdup(name);
3173 info->mccmnc = strdup(str + strlen(name) + 1);
3174
3175 list_add_tail(&operator_info_list, &info->list);
Joe Onorato188b6222016-03-01 11:02:27 -08003176 ALOGV("%s: add operator[%s] mccmnc[%s]", __func__, info->name, info->mccmnc);
keunhui.park2f7306a2015-07-16 16:48:06 +09003177 }
Prashant Malanic92c5962015-08-11 15:10:18 -07003178
3179 memset(value, 0, sizeof(value));
Eric Laurentc6333382015-09-14 12:43:44 -07003180 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT,
Prashant Malanic92c5962015-08-11 15:10:18 -07003181 value, sizeof(value));
3182 if (err >= 0) {
Eric Laurentc6333382015-09-14 12:43:44 -07003183 str_parms_del(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT);
Prashant Malanic92c5962015-08-11 15:10:18 -07003184 my_data->max_mic_count = atoi(value);
3185 ALOGV("%s: max_mic_count %s/%d", __func__, value, my_data->max_mic_count);
Prashant Malanic92c5962015-08-11 15:10:18 -07003186 }
3187
vivek mehta90933872017-06-15 18:04:39 -07003188 // to-do: disable setting sidetone gain, will revist this later
3189 // audio_extn_usb_set_sidetone_gain(parms, value, len);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003190done:
3191 ALOGV("%s: exit with code(%d)", __func__, ret);
3192 if (kv_pairs != NULL)
3193 free(kv_pairs);
3194
3195 return ret;
3196}
3197
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003198/* Delay in Us */
3199int64_t platform_render_latency(audio_usecase_t usecase)
3200{
3201 switch (usecase) {
3202 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
3203 return DEEP_BUFFER_PLATFORM_DELAY;
3204 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
3205 return LOW_LATENCY_PLATFORM_DELAY;
Haynes Mathew George03c40102016-01-29 17:57:48 -08003206 case USECASE_AUDIO_PLAYBACK_ULL:
3207 return ULL_PLATFORM_DELAY;
Eric Laurent0e46adf2016-12-16 12:49:24 -08003208 case USECASE_AUDIO_PLAYBACK_MMAP:
3209 return MMAP_PLATFORM_DELAY;
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003210 default:
3211 return 0;
3212 }
3213}
Haynes Mathew George98c95622014-06-20 19:14:25 -07003214
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003215int platform_set_snd_device_backend(snd_device_t device, const char *backend_tag,
3216 const char * hw_interface)
Haynes Mathew George98c95622014-06-20 19:14:25 -07003217{
3218 int ret = 0;
3219
3220 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
3221 ALOGE("%s: Invalid snd_device = %d",
3222 __func__, device);
3223 ret = -EINVAL;
3224 goto done;
3225 }
3226
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003227 ALOGV("%s: backend_tag_table[%s]: old = %s new = %s", __func__,
3228 platform_get_snd_device_name(device),
3229 backend_tag_table[device] != NULL ? backend_tag_table[device]: "null", backend_tag);
3230 if (backend_tag_table[device]) {
3231 free(backend_tag_table[device]);
Haynes Mathew George98c95622014-06-20 19:14:25 -07003232 }
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003233 backend_tag_table[device] = strdup(backend_tag);
3234
3235 if (hw_interface != NULL) {
3236 if (hw_interface_table[device])
3237 free(hw_interface_table[device]);
3238 ALOGV("%s: hw_interface_table[%d] = %s", __func__, device, hw_interface);
3239 hw_interface_table[device] = strdup(hw_interface);
3240 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07003241done:
3242 return ret;
3243}
3244
3245int platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t pcm_id)
3246{
3247 int ret = 0;
3248 if ((usecase <= USECASE_INVALID) || (usecase >= AUDIO_USECASE_MAX)) {
3249 ALOGE("%s: invalid usecase case idx %d", __func__, usecase);
3250 ret = -EINVAL;
3251 goto done;
3252 }
3253
3254 if ((type != 0) && (type != 1)) {
3255 ALOGE("%s: invalid usecase type", __func__);
3256 ret = -EINVAL;
3257 }
vivek mehtaa68fea62017-06-08 19:04:02 -07003258 ALOGV("%s: pcm_device_table[%d %s][%d] = %d", __func__, usecase,
3259 use_case_table[usecase],
3260 type, pcm_id);
Haynes Mathew George98c95622014-06-20 19:14:25 -07003261 pcm_device_table[usecase][type] = pcm_id;
3262done:
3263 return ret;
3264}
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003265
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07003266#define DEFAULT_NOMINAL_SPEAKER_GAIN 20
3267int ramp_speaker_gain(struct audio_device *adev, bool ramp_up, int target_ramp_up_gain) {
3268 // backup_gain: gain to try to set in case of an error during ramp
3269 int start_gain, end_gain, step, backup_gain, i;
3270 bool error = false;
3271 const struct mixer_ctl *ctl;
3272 const char *mixer_ctl_name_gain_left = "Left Speaker Gain";
3273 const char *mixer_ctl_name_gain_right = "Right Speaker Gain";
3274 struct mixer_ctl *ctl_left = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_left);
3275 struct mixer_ctl *ctl_right = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_right);
3276 if (!ctl_left || !ctl_right) {
3277 ALOGE("%s: Could not get ctl for mixer cmd - %s or %s, not applying speaker gain ramp",
3278 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
3279 return -EINVAL;
3280 } else if ((mixer_ctl_get_num_values(ctl_left) != 1)
3281 || (mixer_ctl_get_num_values(ctl_right) != 1)) {
3282 ALOGE("%s: Unexpected num values for mixer cmd - %s or %s, not applying speaker gain ramp",
3283 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
3284 return -EINVAL;
3285 }
3286 if (ramp_up) {
3287 start_gain = 0;
3288 end_gain = target_ramp_up_gain > 0 ? target_ramp_up_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
3289 step = +1;
3290 backup_gain = end_gain;
3291 } else {
3292 // using same gain on left and right
3293 const int left_gain = mixer_ctl_get_value(ctl_left, 0);
3294 start_gain = left_gain > 0 ? left_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
3295 end_gain = 0;
3296 step = -1;
3297 backup_gain = start_gain;
3298 }
3299 for (i = start_gain ; i != (end_gain + step) ; i += step) {
3300 //ALOGV("setting speaker gain to %d", i);
3301 if (mixer_ctl_set_value(ctl_left, 0, i)) {
3302 ALOGE("%s: error setting %s to %d during gain ramp",
3303 __func__, mixer_ctl_name_gain_left, i);
3304 error = true;
3305 break;
3306 }
3307 if (mixer_ctl_set_value(ctl_right, 0, i)) {
3308 ALOGE("%s: error setting %s to %d during gain ramp",
3309 __func__, mixer_ctl_name_gain_right, i);
3310 error = true;
3311 break;
3312 }
3313 usleep(1000);
3314 }
3315 if (error) {
3316 // an error occured during the ramp, let's still try to go back to a safe volume
3317 if (mixer_ctl_set_value(ctl_left, 0, backup_gain)) {
3318 ALOGE("%s: error restoring left gain to %d", __func__, backup_gain);
3319 }
3320 if (mixer_ctl_set_value(ctl_right, 0, backup_gain)) {
3321 ALOGE("%s: error restoring right gain to %d", __func__, backup_gain);
3322 }
3323 }
3324 return start_gain;
3325}
3326
vivek mehtae59cfb22017-06-16 15:57:11 -07003327int platform_set_swap_mixer(struct audio_device *adev, bool swap_channels)
3328{
3329 const char *mixer_ctl_name = "Swap channel";
3330 struct mixer_ctl *ctl;
3331 const char *mixer_path;
3332 struct platform_data *my_data = (struct platform_data *)adev->platform;
3333
3334 // forced to set to swap, but device not rotated ... ignore set
3335 if (swap_channels && !my_data->speaker_lr_swap)
3336 return 0;
3337
3338 ALOGV("%s:", __func__);
3339
3340 if (swap_channels) {
3341 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER_REVERSE);
3342 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
3343 } else {
3344 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER);
3345 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
3346 }
3347
3348 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3349 if (!ctl) {
3350 ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name);
3351 return -EINVAL;
3352 }
3353
3354 if (mixer_ctl_set_value(ctl, 0, swap_channels) < 0) {
3355 ALOGE("%s: Could not set reverse cotrol %d",__func__, swap_channels);
3356 return -EINVAL;
3357 }
3358
3359 ALOGV("platfor_force_swap_channel :: Channel orientation ( %s ) ",
3360 swap_channels?"R --> L":"L --> R");
3361
3362 return 0;
3363}
3364
3365int platform_check_and_set_swap_lr_channels(struct audio_device *adev, bool swap_channels)
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003366{
3367 // only update if there is active pcm playback on speaker
3368 struct audio_usecase *usecase;
3369 struct listnode *node;
3370 struct platform_data *my_data = (struct platform_data *)adev->platform;
3371
vivek mehtae59cfb22017-06-16 15:57:11 -07003372 my_data->speaker_lr_swap = swap_channels;
Jean-Michel Trivif7148702016-09-16 18:23:05 -07003373
vivek mehtae59cfb22017-06-16 15:57:11 -07003374 return platform_set_swap_channels(adev, swap_channels);
3375}
Jean-Michel Trivif7148702016-09-16 18:23:05 -07003376
vivek mehtae59cfb22017-06-16 15:57:11 -07003377int platform_set_swap_channels(struct audio_device *adev, bool swap_channels)
3378{
3379 // only update if there is active pcm playback on speaker
3380 struct audio_usecase *usecase;
3381 struct listnode *node;
3382 struct platform_data *my_data = (struct platform_data *)adev->platform;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003383
vivek mehtae59cfb22017-06-16 15:57:11 -07003384 // do not swap channels in audio modes with concurrent capture and playback
3385 // as this may break the echo reference
3386 if ((adev->mode == AUDIO_MODE_IN_COMMUNICATION) || (adev->mode == AUDIO_MODE_IN_CALL)) {
3387 ALOGV("%s: will not swap due to audio mode %d", __func__, adev->mode);
3388 return 0;
3389 }
3390
3391 list_for_each(node, &adev->usecase_list) {
3392 usecase = node_to_item(node, struct audio_usecase, list);
3393 if (usecase->type == PCM_PLAYBACK &&
3394 usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) {
3395 /*
3396 * If acdb tuning is different for SPEAKER_REVERSE, it is must
3397 * to perform device switch to disable the current backend to
3398 * enable it with new acdb data.
3399 */
3400 if (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
3401 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]) {
3402 const int initial_skpr_gain = ramp_speaker_gain(adev, false /*ramp_up*/, -1);
3403 select_devices(adev, usecase->id);
3404 if (initial_skpr_gain != -EINVAL)
3405 ramp_speaker_gain(adev, true /*ramp_up*/, initial_skpr_gain);
3406
3407 } else {
3408 platform_set_swap_mixer(adev, swap_channels);
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003409 }
vivek mehtae59cfb22017-06-16 15:57:11 -07003410 break;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003411 }
3412 }
vivek mehtae59cfb22017-06-16 15:57:11 -07003413
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003414 return 0;
3415}
vivek mehtaa8d7c922016-05-25 14:40:44 -07003416
3417static struct amp_db_and_gain_table tbl_mapping[MAX_VOLUME_CAL_STEPS];
3418static int num_gain_tbl_entry = 0;
3419
3420bool platform_add_gain_level_mapping(struct amp_db_and_gain_table *tbl_entry) {
3421
3422 ALOGV("%s: enter .. add %f %f %d", __func__, tbl_entry->amp, tbl_entry->db, tbl_entry->level);
3423 if (num_gain_tbl_entry == -1) {
3424 ALOGE("%s: num entry beyond valid step levels or corrupted..rejecting custom mapping",
3425 __func__);
3426 return false;
3427 }
3428
3429 if (num_gain_tbl_entry >= MAX_VOLUME_CAL_STEPS) {
3430 ALOGE("%s: max entry reached max[%d] current index[%d] .. rejecting", __func__,
3431 MAX_VOLUME_CAL_STEPS, num_gain_tbl_entry);
3432 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
3433 return false;
3434 }
3435
3436 if (num_gain_tbl_entry > 0 && tbl_mapping[num_gain_tbl_entry - 1].amp >= tbl_entry->amp) {
3437 ALOGE("%s: value not in ascending order .. rejecting custom mapping", __func__);
3438 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
3439 return false;
3440 }
3441
3442 tbl_mapping[num_gain_tbl_entry] = *tbl_entry;
3443 ++num_gain_tbl_entry;
3444
3445 return true;
3446}
3447
3448int platform_get_gain_level_mapping(struct amp_db_and_gain_table *mapping_tbl,
3449 int table_size) {
3450 int itt = 0;
3451 ALOGV("platform_get_gain_level_mapping called ");
3452
3453 if (num_gain_tbl_entry <= 0 || num_gain_tbl_entry > MAX_VOLUME_CAL_STEPS) {
3454 ALOGD("%s: empty or currupted gain_mapping_table", __func__);
3455 return 0;
3456 }
3457
3458 for (; itt < num_gain_tbl_entry && itt <= table_size; itt++) {
3459 mapping_tbl[itt] = tbl_mapping[itt];
3460 ALOGV("%s: added amp[%f] db[%f] level[%d]", __func__,
3461 mapping_tbl[itt].amp, mapping_tbl[itt].db, mapping_tbl[itt].level);
3462 }
3463
3464 return num_gain_tbl_entry;
3465}
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07003466
3467int platform_snd_card_update(void *platform, card_status_t status)
3468{
3469 struct platform_data *my_data = (struct platform_data *)platform;
3470 struct audio_device *adev = my_data->adev;
3471
3472 if (status == CARD_STATUS_ONLINE) {
3473 if (my_data->acdb_send_custom_top)
3474 my_data->acdb_send_custom_top();
3475 }
3476 return 0;
3477}
David Linee3fe402017-03-13 10:00:42 -07003478
3479/*
3480 * configures afe with bit width and Sample Rate
3481 */
Haynes Mathew George65f6b432018-02-27 17:44:55 -08003482int platform_set_backend_cfg(const struct audio_device* adev,
3483 snd_device_t snd_device,
3484 const struct audio_backend_cfg *backend_cfg)
David Linee3fe402017-03-13 10:00:42 -07003485{
3486
3487 int ret = 0;
3488 const int backend_idx = platform_get_backend_index(snd_device);
3489 struct platform_data *my_data = (struct platform_data *)adev->platform;
3490 const unsigned int bit_width = backend_cfg->bit_width;
3491 const unsigned int sample_rate = backend_cfg->sample_rate;
3492 const unsigned int channels = backend_cfg->channels;
3493 const audio_format_t format = backend_cfg->format;
3494 const bool passthrough_enabled = backend_cfg->passthrough_enabled;
3495
3496
3497 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
3498 ", backend_idx %d device (%s)", __func__, bit_width,
3499 sample_rate, channels, backend_idx,
3500 platform_get_snd_device_name(snd_device));
3501
3502 if ((my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl) &&
3503 (bit_width != my_data->current_backend_cfg[backend_idx].bit_width)) {
3504
3505 struct mixer_ctl *ctl = NULL;
3506 ctl = mixer_get_ctl_by_name(adev->mixer,
3507 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
3508 if (!ctl) {
3509 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3510 __func__,
3511 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
3512 return -EINVAL;
3513 }
3514
3515 if (bit_width == 24) {
3516 if (format == AUDIO_FORMAT_PCM_24_BIT_PACKED)
3517 ret = mixer_ctl_set_enum_by_string(ctl, "S24_3LE");
3518 else
3519 ret = mixer_ctl_set_enum_by_string(ctl, "S24_LE");
3520 } else if (bit_width == 32) {
3521 ret = mixer_ctl_set_enum_by_string(ctl, "S32_LE");
3522 } else {
3523 ret = mixer_ctl_set_enum_by_string(ctl, "S16_LE");
3524 }
3525 if ( ret < 0) {
3526 ALOGE("%s:becf: afe: fail for %s mixer set to %d bit for %x format", __func__,
3527 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
3528 } else {
3529 my_data->current_backend_cfg[backend_idx].bit_width = bit_width;
3530 ALOGD("%s:becf: afe: %s mixer set to %d bit for %x format", __func__,
3531 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
3532 }
3533 /* set the ret as 0 and not pass back to upper layer */
3534 ret = 0;
3535 }
3536
3537 if (passthrough_enabled || ((my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl) &&
3538 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate))) {
3539 char *rate_str = NULL;
3540 struct mixer_ctl *ctl = NULL;
3541
3542 switch (sample_rate) {
3543 case 32000:
3544 if (passthrough_enabled) {
3545 rate_str = "KHZ_32";
3546 break;
3547 }
3548 case 8000:
3549 case 11025:
3550 case 16000:
3551 case 22050:
3552 case 48000:
3553 rate_str = "KHZ_48";
3554 break;
3555 case 44100:
3556 rate_str = "KHZ_44P1";
3557 break;
3558 case 64000:
3559 case 96000:
3560 rate_str = "KHZ_96";
3561 break;
3562 case 88200:
3563 rate_str = "KHZ_88P2";
3564 break;
3565 case 176400:
3566 rate_str = "KHZ_176P4";
3567 break;
3568 case 192000:
3569 rate_str = "KHZ_192";
3570 break;
3571 case 352800:
3572 rate_str = "KHZ_352P8";
3573 break;
3574 case 384000:
3575 rate_str = "KHZ_384";
3576 break;
3577 case 144000:
3578 if (passthrough_enabled) {
3579 rate_str = "KHZ_144";
3580 break;
3581 }
3582 default:
3583 rate_str = "KHZ_48";
3584 break;
3585 }
3586
3587 ctl = mixer_get_ctl_by_name(adev->mixer,
3588 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
3589 if(!ctl) {
3590 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3591 __func__,
3592 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
3593 return -EINVAL;
3594 }
3595
3596 ALOGD("%s:becf: afe: %s set to %s", __func__,
3597 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl, rate_str);
3598 mixer_ctl_set_enum_by_string(ctl, rate_str);
3599 my_data->current_backend_cfg[backend_idx].sample_rate = sample_rate;
3600 }
3601 if ((my_data->current_backend_cfg[backend_idx].channels_mixer_ctl) &&
3602 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
3603 struct mixer_ctl *ctl = NULL;
3604 char *channel_cnt_str = NULL;
3605
3606 switch (channels) {
3607 case 8:
3608 channel_cnt_str = "Eight"; break;
3609 case 7:
3610 channel_cnt_str = "Seven"; break;
3611 case 6:
3612 channel_cnt_str = "Six"; break;
3613 case 5:
3614 channel_cnt_str = "Five"; break;
3615 case 4:
3616 channel_cnt_str = "Four"; break;
3617 case 3:
3618 channel_cnt_str = "Three"; break;
3619 case 1:
3620 channel_cnt_str = "One"; break;
3621 case 2:
3622 default:
3623 channel_cnt_str = "Two"; break;
3624 }
3625
3626 ctl = mixer_get_ctl_by_name(adev->mixer,
3627 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
3628 if (!ctl) {
3629 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3630 __func__,
3631 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
3632 return -EINVAL;
3633 }
3634 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
3635 my_data->current_backend_cfg[backend_idx].channels = channels;
3636
3637 // skip EDID configuration for HDMI backend
3638
3639 ALOGD("%s:becf: afe: %s set to %s", __func__,
3640 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl,
3641 channel_cnt_str);
3642 }
3643
3644 // skip set ext_display format mixer control
3645 return ret;
3646}
3647
3648static int platform_get_snd_device_bit_width(snd_device_t snd_device)
3649{
3650 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
3651 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
3652 return CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3653 }
3654
3655 return backend_bit_width_table[snd_device];
3656}
3657
3658/*
3659 * return backend_idx on which voice call is active
3660 */
3661static int platform_get_voice_call_backend(struct audio_device* adev)
3662{
3663 struct audio_usecase *uc = NULL;
3664 struct listnode *node;
3665 snd_device_t out_snd_device = SND_DEVICE_NONE;
3666
3667 int backend_idx = -1;
3668
3669 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
3670 list_for_each(node, &adev->usecase_list) {
3671 uc = node_to_item(node, struct audio_usecase, list);
3672 if (uc && uc->type == VOICE_CALL && uc->stream.out) {
3673 out_snd_device = platform_get_output_snd_device(adev->platform,
3674 uc->stream.out->devices);
3675 backend_idx = platform_get_backend_index(out_snd_device);
3676 break;
3677 }
3678 }
3679 }
3680 return backend_idx;
3681}
3682
3683/*
3684 * goes through all the current usecases and picks the highest
3685 * bitwidth & samplerate
3686 */
3687static bool platform_check_capture_backend_cfg(struct audio_device* adev,
3688 int backend_idx,
3689 struct audio_backend_cfg *backend_cfg)
3690{
3691 bool backend_change = false;
3692 unsigned int bit_width;
3693 unsigned int sample_rate;
3694 unsigned int channels;
3695 struct platform_data *my_data = (struct platform_data *)adev->platform;
3696
3697 bit_width = backend_cfg->bit_width;
3698 sample_rate = backend_cfg->sample_rate;
3699 channels = backend_cfg->channels;
3700
3701 ALOGV("%s:txbecf: afe: Codec selected backend: %d current bit width: %d and "
3702 "sample rate: %d, channels %d",__func__,backend_idx, bit_width,
3703 sample_rate, channels);
3704
3705 // For voice calls use default configuration i.e. 16b/48K, only applicable to
3706 // default backend
3707 // force routing is not required here, caller will do it anyway
3708 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
3709 ALOGW("%s:txbecf: afe: Use default bw and sr for voice/voip calls and "
3710 "for unprocessed/camera source", __func__);
3711 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3712 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3713 }
3714
3715 if (backend_idx == USB_AUDIO_TX_BACKEND) {
3716 audio_extn_usb_is_config_supported(&bit_width, &sample_rate, &channels, false);
3717 ALOGV("%s:txbecf: afe: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
3718 __func__, bit_width, sample_rate, channels);
3719 }
3720
3721 ALOGV("%s:txbecf: afe: Codec selected backend: %d updated bit width: %d and "
3722 "sample rate: %d", __func__, backend_idx, bit_width, sample_rate);
3723
3724 // Force routing if the expected bitwdith or samplerate
3725 // is not same as current backend comfiguration
3726 if ((bit_width != my_data->current_backend_cfg[backend_idx].bit_width) ||
3727 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate) ||
3728 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
3729 backend_cfg->bit_width = bit_width;
3730 backend_cfg->sample_rate= sample_rate;
3731 backend_cfg->channels = channels;
3732 backend_change = true;
3733 ALOGI("%s:txbecf: afe: Codec backend needs to be updated. new bit width: %d "
3734 "new sample rate: %d new channel: %d",
3735 __func__, backend_cfg->bit_width,
3736 backend_cfg->sample_rate, backend_cfg->channels);
3737 }
3738
3739 return backend_change;
3740}
3741
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003742static void pick_playback_cfg_for_uc(struct audio_device *adev,
3743 struct audio_usecase *usecase,
3744 snd_device_t snd_device,
3745 unsigned int *bit_width,
3746 unsigned int *sample_rate,
3747 unsigned int *channels)
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003748{
3749 int i =0;
3750 struct listnode *node;
3751 list_for_each(node, &adev->usecase_list) {
3752 struct audio_usecase *uc;
3753 uc = node_to_item(node, struct audio_usecase, list);
3754 struct stream_out *out = (struct stream_out*) uc->stream.out;
3755 if (uc->type == PCM_PLAYBACK && out && usecase != uc) {
3756 unsigned int out_channels = audio_channel_count_from_out_mask(out->channel_mask);
3757 ALOGV("%s:napb: (%d) - (%s)id (%d) sr %d bw "
3758 "(%d) ch (%d) device %s", __func__, i++, use_case_table[uc->id],
3759 uc->id, out->sample_rate,
3760 pcm_format_to_bits(out->config.format), out_channels,
3761 platform_get_snd_device_name(uc->out_snd_device));
3762
3763 if (platform_check_backends_match(snd_device, uc->out_snd_device)) {
3764 if (*bit_width < pcm_format_to_bits(out->config.format))
3765 *bit_width = pcm_format_to_bits(out->config.format);
3766 if (*sample_rate < out->sample_rate)
3767 *sample_rate = out->sample_rate;
3768 if (out->sample_rate < OUTPUT_SAMPLING_RATE_44100)
3769 *sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3770 if (*channels < out_channels)
3771 *channels = out_channels;
3772 }
3773 }
3774 }
3775 return;
3776}
3777
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003778static void headset_is_config_supported(unsigned int *bit_width,
3779 unsigned int *sample_rate,
3780 unsigned int *channels) {
3781 switch (*bit_width) {
3782 case 16:
3783 case 24:
3784 break;
3785 default:
3786 *bit_width = 16;
3787 break;
3788 }
3789
3790 if (*sample_rate > 192000) {
3791 *sample_rate = 192000;
3792 }
3793
3794 if (*channels > 2) {
3795 *channels = 2;
3796 }
3797}
3798
David Linee3fe402017-03-13 10:00:42 -07003799static bool platform_check_playback_backend_cfg(struct audio_device* adev,
3800 struct audio_usecase* usecase,
3801 snd_device_t snd_device,
3802 struct audio_backend_cfg *backend_cfg)
3803{
3804 bool backend_change = false;
David Linee3fe402017-03-13 10:00:42 -07003805 unsigned int bit_width;
3806 unsigned int sample_rate;
3807 unsigned int channels;
David Linee3fe402017-03-13 10:00:42 -07003808 int backend_idx = DEFAULT_CODEC_BACKEND;
Haynes Mathew George65f6b432018-02-27 17:44:55 -08003809 unsigned long service_interval = 0; // 0 is invalid
David Linee3fe402017-03-13 10:00:42 -07003810 struct platform_data *my_data = (struct platform_data *)adev->platform;
David Linee3fe402017-03-13 10:00:42 -07003811
3812 if (snd_device == SND_DEVICE_OUT_BT_SCO ||
3813 snd_device == SND_DEVICE_OUT_BT_SCO_WB) {
3814 backend_change = false;
3815 return backend_change;
3816 }
3817
3818 backend_idx = platform_get_backend_index(snd_device);
3819 bit_width = backend_cfg->bit_width;
3820 sample_rate = backend_cfg->sample_rate;
3821 channels = backend_cfg->channels;
3822
3823 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
3824 ", backend_idx %d usecase = %d device (%s)", __func__, bit_width,
3825 sample_rate, channels, backend_idx, usecase->id,
3826 platform_get_snd_device_name(snd_device));
3827
3828 if (backend_idx == platform_get_voice_call_backend(adev)) {
3829 ALOGW("%s:becf: afe:Use default bw and sr for voice/voip calls ",
3830 __func__);
3831 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3832 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3833 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
3834 } else {
3835 /*
3836 * The backend should be configured at highest bit width and/or
3837 * sample rate amongst all playback usecases.
3838 * If the selected sample rate and/or bit width differ with
3839 * current backend sample rate and/or bit width, then, we set the
3840 * backend re-configuration flag.
3841 *
3842 * Exception: 16 bit playbacks is allowed through 16 bit/48/44.1 khz backend only
3843 */
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003844 pick_playback_cfg_for_uc(adev, usecase, snd_device,
3845 &bit_width,
3846 &sample_rate,
3847 &channels);
David Linee3fe402017-03-13 10:00:42 -07003848 }
3849
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003850 switch (backend_idx) {
3851 case USB_AUDIO_RX_BACKEND:
3852 audio_extn_usb_is_config_supported(&bit_width,
3853 &sample_rate, &channels, true);
Haynes Mathew George65f6b432018-02-27 17:44:55 -08003854 if (platform_get_usb_service_interval(adev->platform, true,
3855 &service_interval) == 0) {
3856 /* overwrite with best altset for this service interval */
3857 int ret =
3858 audio_extn_usb_altset_for_service_interval(true /*playback*/,
3859 service_interval,
3860 &bit_width,
3861 &sample_rate,
3862 &channels);
3863 if (ret < 0) {
3864 ALOGE("Failed to find altset for service interval %lu, skip reconfig",
3865 service_interval);
3866 return false;
3867 }
3868 }
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003869 ALOGV("%s: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
3870 __func__, bit_width, sample_rate, channels);
3871 break;
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003872 case HEADPHONE_BACKEND:
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003873 headset_is_config_supported(&bit_width, &sample_rate, &channels);
3874 break;
3875 case DEFAULT_CODEC_BACKEND:
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003876 default:
3877 bit_width = platform_get_snd_device_bit_width(snd_device);
3878 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3879 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
3880 break;
David Linee3fe402017-03-13 10:00:42 -07003881 }
3882
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003883 ALOGV("%s:becf: afe: Codec selected backend: %d updated bit width: %d and"
3884 "sample rate: %d",
David Linee3fe402017-03-13 10:00:42 -07003885 __func__, backend_idx , bit_width, sample_rate);
3886
3887 // Force routing if the expected bitwdith or samplerate
3888 // is not same as current backend comfiguration
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003889 if (bit_width != my_data->current_backend_cfg[backend_idx].bit_width ||
3890 sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate ||
3891 channels != my_data->current_backend_cfg[backend_idx].channels) {
David Linee3fe402017-03-13 10:00:42 -07003892 backend_cfg->bit_width = bit_width;
3893 backend_cfg->sample_rate = sample_rate;
3894 backend_cfg->channels = channels;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003895 backend_cfg->passthrough_enabled = false;
David Linee3fe402017-03-13 10:00:42 -07003896 backend_change = true;
3897 ALOGV("%s:becf: afe: Codec backend needs to be updated. new bit width: %d"
3898 "new sample rate: %d new channels: %d",
3899 __func__, backend_cfg->bit_width, backend_cfg->sample_rate, backend_cfg->channels);
3900 }
3901
3902 return backend_change;
3903}
3904
3905bool platform_check_and_set_playback_backend_cfg(struct audio_device* adev,
3906 struct audio_usecase *usecase, snd_device_t snd_device)
3907{
3908 int backend_idx = DEFAULT_CODEC_BACKEND;
3909 int new_snd_devices[SND_DEVICE_OUT_END];
3910 int i, num_devices = 1;
3911 bool ret = false;
3912 struct platform_data *my_data = (struct platform_data *)adev->platform;
3913 struct audio_backend_cfg backend_cfg;
3914
3915 backend_idx = platform_get_backend_index(snd_device);
3916
3917 backend_cfg.bit_width = pcm_format_to_bits(usecase->stream.out->config.format);
3918 backend_cfg.sample_rate = usecase->stream.out->sample_rate;
3919 backend_cfg.format = usecase->stream.out->format;
3920 backend_cfg.channels = audio_channel_count_from_out_mask(usecase->stream.out->channel_mask);
3921 /*this is populated by check_codec_backend_cfg hence set default value to false*/
3922 backend_cfg.passthrough_enabled = false;
3923
3924 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
3925 ", backend_idx %d usecase = %d device (%s)", __func__, backend_cfg.bit_width,
3926 backend_cfg.sample_rate, backend_cfg.channels, backend_idx, usecase->id,
3927 platform_get_snd_device_name(snd_device));
3928
3929 if (platform_can_split_snd_device(snd_device, &num_devices, new_snd_devices) < 0)
3930 new_snd_devices[0] = snd_device;
3931
3932 for (i = 0; i < num_devices; i++) {
3933 ALOGV("%s: new_snd_devices[%d] is %d", __func__, i, new_snd_devices[i]);
3934 if ((platform_check_playback_backend_cfg(adev, usecase, new_snd_devices[i],
3935 &backend_cfg))) {
3936 platform_set_backend_cfg(adev, new_snd_devices[i],
3937 &backend_cfg);
3938 ret = true;
3939 }
3940 }
3941 return ret;
3942}
3943
3944bool platform_check_and_set_capture_backend_cfg(struct audio_device* adev,
3945 struct audio_usecase *usecase, snd_device_t snd_device)
3946{
3947 int backend_idx = platform_get_backend_index(snd_device);
3948 int ret = 0;
3949 struct audio_backend_cfg backend_cfg;
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003950 memset(&backend_cfg, 0, sizeof(struct audio_backend_cfg));
David Linee3fe402017-03-13 10:00:42 -07003951
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003952 if (usecase->type == PCM_CAPTURE) {
3953 backend_cfg.format = usecase->stream.in->format;
David Linee3fe402017-03-13 10:00:42 -07003954 backend_cfg.channels = audio_channel_count_from_in_mask(usecase->stream.in->channel_mask);
3955 } else {
3956 backend_cfg.bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3957 backend_cfg.sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3958 backend_cfg.format = AUDIO_FORMAT_PCM_16_BIT;
3959 backend_cfg.channels = 1;
3960 }
3961
3962 ALOGV("%s:txbecf: afe: bitwidth %d, samplerate %d, channel %d"
3963 ", backend_idx %d usecase = %d device (%s)", __func__,
3964 backend_cfg.bit_width,
3965 backend_cfg.sample_rate,
3966 backend_cfg.channels,
3967 backend_idx, usecase->id,
3968 platform_get_snd_device_name(snd_device));
3969
3970 if (platform_check_capture_backend_cfg(adev, backend_idx, &backend_cfg)) {
3971 ret = platform_set_backend_cfg(adev, snd_device,
3972 &backend_cfg);
3973 if(!ret)
3974 return true;
3975 }
3976
3977 return false;
3978}
3979
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003980static int max_be_dai_names = 0;
3981static const struct be_dai_name_struct *be_dai_name_table;
3982
3983/*
3984 * Retrieves the be_dai_name_table from kernel to enable a mapping
3985 * between sound device hw interfaces and backend IDs. This allows HAL to
3986 * specify the backend a specific calibration is needed for.
3987 */
3988static int init_be_dai_name_table(struct audio_device *adev)
3989{
3990 const char *mixer_ctl_name = "Backend DAI Name Table";
3991 struct mixer_ctl *ctl;
3992 int i, j, ret, size;
3993 bool valid_hw_interface;
3994
3995 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3996 if (!ctl) {
3997 ALOGE("%s: Could not get ctl for mixer name %s\n",
3998 __func__, mixer_ctl_name);
3999 ret = -EINVAL;
4000 goto done;
4001 }
4002
4003 mixer_ctl_update(ctl);
4004
4005 size = mixer_ctl_get_num_values(ctl);
4006 if (size <= 0){
4007 ALOGE("%s: Failed to get %s size %d\n",
4008 __func__, mixer_ctl_name, size);
4009 ret = -EFAULT;
4010 goto done;
4011 }
4012
vivek mehtaa68fea62017-06-08 19:04:02 -07004013 be_dai_name_table =
4014 (const struct be_dai_name_struct *)calloc(1, size);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004015 if (be_dai_name_table == NULL) {
4016 ALOGE("%s: Failed to allocate memory for %s\n",
4017 __func__, mixer_ctl_name);
4018 ret = -ENOMEM;
4019 goto freeMem;
4020 }
4021
4022 ret = mixer_ctl_get_array(ctl, (void *)be_dai_name_table, size);
4023 if (ret) {
4024 ALOGE("%s: Failed to get %s, ret %d\n",
4025 __func__, mixer_ctl_name, ret);
4026 ret = -EFAULT;
4027 goto freeMem;
4028 }
4029
4030 if (be_dai_name_table != NULL) {
4031 max_be_dai_names = size / sizeof(struct be_dai_name_struct);
4032 ALOGV("%s: Successfully got %s, number of be dais is %d\n",
4033 __func__, mixer_ctl_name, max_be_dai_names);
4034 ret = 0;
4035 } else {
4036 ALOGE("%s: Failed to get %s\n", __func__, mixer_ctl_name);
4037 ret = -EFAULT;
4038 goto freeMem;
4039 }
4040
4041 /*
4042 * Validate all sound devices have a valid backend set to catch
4043 * errors for uncommon sound devices
4044 */
4045 for (i = 0; i < SND_DEVICE_MAX; i++) {
4046 valid_hw_interface = false;
4047
4048 if (hw_interface_table[i] == NULL) {
4049 ALOGW("%s: sound device %s has no hw interface set\n",
4050 __func__, platform_get_snd_device_name(i));
4051 continue;
4052 }
4053
4054 for (j = 0; j < max_be_dai_names; j++) {
4055 if (strcmp(hw_interface_table[i], be_dai_name_table[j].be_name)
4056 == 0) {
4057 valid_hw_interface = true;
4058 break;
4059 }
4060 }
4061 if (!valid_hw_interface)
4062 ALOGD("%s: sound device %s does not have a valid hw interface set "
4063 "(disregard for combo devices) %s\n",
4064 __func__, platform_get_snd_device_name(i),
4065 hw_interface_table[i]);
4066 }
4067
4068 goto done;
4069
4070freeMem:
4071 if (be_dai_name_table) {
4072 free((void *)be_dai_name_table);
4073 be_dai_name_table = NULL;
4074 }
4075
4076done:
4077 return ret;
4078}
4079
4080int platform_get_snd_device_backend_index(snd_device_t device)
4081{
4082 int i, be_dai_id;
4083 const char * hw_interface_name = NULL;
4084
4085 ALOGV("%s: enter with device %d\n", __func__, device);
4086
vivek mehtaa68fea62017-06-08 19:04:02 -07004087 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004088 ALOGE("%s: Invalid snd_device = %d",
4089 __func__, device);
4090 be_dai_id = -EINVAL;
4091 goto done;
4092 }
4093
4094 /* Get string value of necessary backend for device */
4095 hw_interface_name = hw_interface_table[device];
4096 if (hw_interface_name == NULL) {
4097 ALOGE("%s: no hw_interface set for device %d\n", __func__, device);
4098 be_dai_id = -EINVAL;
4099 goto done;
4100 }
4101
4102 /* Check if be dai name table was retrieved successfully */
4103 if (be_dai_name_table == NULL) {
4104 ALOGE("%s: BE DAI Name Table is not present\n", __func__);
4105 be_dai_id = -EFAULT;
4106 goto done;
4107 }
4108
4109 /* Get backend ID for device specified */
4110 for (i = 0; i < max_be_dai_names; i++) {
4111 if (strcmp(hw_interface_name, be_dai_name_table[i].be_name) == 0) {
4112 be_dai_id = be_dai_name_table[i].be_id;
4113 goto done;
4114 }
4115 }
4116 ALOGE("%s: no interface matching name %s\n", __func__, hw_interface_name);
4117 be_dai_id = -EINVAL;
4118 goto done;
4119
4120done:
4121 return be_dai_id;
4122}
4123
4124void platform_check_and_update_copp_sample_rate(void* platform, snd_device_t snd_device,
4125 unsigned int stream_sr, int* sample_rate)
4126{
4127 struct platform_data* my_data = (struct platform_data *)platform;
4128 int backend_idx = platform_get_backend_index(snd_device);
4129 int device_sr = my_data->current_backend_cfg[backend_idx].sample_rate;
4130 /*
4131 *Check if device SR is multiple of 8K or 11.025 Khz
4132 *check if the stream SR is multiple of same base, if yes
4133 *then have copp SR equal to stream SR, this ensures that
4134 *post processing happens at stream SR, else have
4135 *copp SR equal to device SR.
4136 */
4137 if (!(((sample_rate_multiple(device_sr, SAMPLE_RATE_8000)) &&
4138 (sample_rate_multiple(stream_sr, SAMPLE_RATE_8000))) ||
4139 ((sample_rate_multiple(device_sr, SAMPLE_RATE_11025)) &&
4140 (sample_rate_multiple(stream_sr, SAMPLE_RATE_11025))))) {
4141 *sample_rate = device_sr;
4142 } else
4143 *sample_rate = stream_sr;
4144
4145 ALOGI("sn_device %d device sr %d stream sr %d copp sr %d", snd_device, device_sr, stream_sr
4146 , *sample_rate);
4147
4148}
4149
4150// called from info parser
vivek mehtaa68fea62017-06-08 19:04:02 -07004151void platform_add_app_type(const char *uc_type,
4152 const char *mode,
4153 int bw,
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004154 int app_type, int max_rate) {
4155 struct app_type_entry *ap =
4156 (struct app_type_entry *)calloc(1, sizeof(struct app_type_entry));
4157
4158 if (!ap) {
4159 ALOGE("%s failed to allocate mem for app type", __func__);
4160 return;
4161 }
4162
4163 ap->uc_type = -1;
4164 for (int i=0; i<USECASE_TYPE_MAX; i++) {
4165 if (!strcmp(uc_type, usecase_type_index[i].name)) {
4166 ap->uc_type = usecase_type_index[i].index;
4167 break;
4168 }
4169 }
4170
4171 if (ap->uc_type == -1) {
4172 free(ap);
4173 return;
4174 }
4175
vivek mehtaa68fea62017-06-08 19:04:02 -07004176 ALOGI("%s uc %s mode %s bw %d app_type %d max_rate %d",
4177 __func__, uc_type, mode, bw, app_type, max_rate);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004178 ap->bit_width = bw;
4179 ap->app_type = app_type;
4180 ap->max_rate = max_rate;
vivek mehtaa68fea62017-06-08 19:04:02 -07004181 ap->mode = strdup(mode);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004182 list_add_tail(&app_type_entry_list, &ap->node);
4183}
4184
4185
4186int platform_get_default_app_type_v2(void *platform __unused,
4187 usecase_type_t type,
4188 int *app_type )
4189{
4190 if (type == PCM_PLAYBACK)
4191 *app_type = DEFAULT_APP_TYPE_RX_PATH;
4192 else
4193 *app_type = DEFAULT_APP_TYPE_TX_PATH;
4194 return 0;
4195}
4196
vivek mehtaa68fea62017-06-08 19:04:02 -07004197int platform_get_app_type_v2(void *platform,
4198 usecase_type_t uc_type,
4199 const char *mode,
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004200 int bw, int sr __unused,
4201 int *app_type)
4202{
4203 struct listnode *node;
4204 struct app_type_entry *entry;
4205 *app_type = -1;
vivek mehtaa68fea62017-06-08 19:04:02 -07004206
4207 ALOGV("%s find match for uc %d mode %s bw %d rate %d",
4208 __func__, uc_type, mode, bw, sr);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004209 list_for_each(node, &app_type_entry_list) {
4210 entry = node_to_item(node, struct app_type_entry, node);
vivek mehtaa68fea62017-06-08 19:04:02 -07004211 ALOGV("%s uc %d mode %s bw %d app_type %d max_rate %d",
4212 __func__, entry->uc_type, entry->mode, entry->bit_width,
4213 entry->app_type, entry->max_rate);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004214 if (entry->bit_width == bw &&
vivek mehtaa68fea62017-06-08 19:04:02 -07004215 entry->uc_type == uc_type &&
4216 sr <= entry->max_rate &&
4217 entry->mode && !strcmp(mode, entry->mode)) {
4218 ALOGV("%s found match %d", __func__, entry->app_type);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004219 *app_type = entry->app_type;
4220 break;
4221 }
4222 }
4223
4224 if (*app_type == -1) {
vivek mehtaa68fea62017-06-08 19:04:02 -07004225 ALOGV("%s no match found, return default", __func__);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004226 return platform_get_default_app_type_v2(platform, uc_type, app_type);
4227 }
4228 return 0;
4229}
vivek mehta90933872017-06-15 18:04:39 -07004230
4231int platform_set_sidetone(struct audio_device *adev,
4232 snd_device_t out_snd_device,
4233 bool enable, char *str)
4234{
4235 int ret;
4236 if (out_snd_device == SND_DEVICE_OUT_USB_HEADSET ||
4237 out_snd_device == SND_DEVICE_OUT_VOICE_USB_HEADSET) {
4238 ret = audio_extn_usb_enable_sidetone(out_snd_device, enable);
4239 if (ret)
4240 ALOGI("%s: usb device %d does not support device sidetone\n",
4241 __func__, out_snd_device);
4242 } else {
4243 ALOGV("%s: sidetone out device(%d) mixer cmd = %s\n",
4244 __func__, out_snd_device, str);
4245 if (enable)
4246 audio_route_apply_and_update_path(adev->audio_route, str);
4247 else
4248 audio_route_reset_and_update_path(adev->audio_route, str);
4249 }
4250 return 0;
4251}
Haynes Mathew George96483a22017-03-28 14:52:47 -07004252
4253int platform_get_mmap_data_fd(void *platform __unused, int fe_dev __unused, int dir __unused,
4254 int *fd __unused, uint32_t *size __unused)
4255{
Alexey Polyudove920d4b2017-09-15 17:09:07 -07004256#if defined (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845)
Haynes Mathew George96483a22017-03-28 14:52:47 -07004257 struct platform_data *my_data = (struct platform_data *)platform;
4258 struct audio_device *adev = my_data->adev;
4259 int hw_fd = -1;
4260 char dev_name[128];
4261 struct snd_pcm_mmap_fd mmap_fd;
4262 memset(&mmap_fd, 0, sizeof(mmap_fd));
4263 mmap_fd.dir = dir;
4264 snprintf(dev_name, sizeof(dev_name), "/dev/snd/hwC%uD%u",
4265 adev->snd_card, HWDEP_FE_BASE+fe_dev);
4266 hw_fd = open(dev_name, O_RDONLY);
4267 if (hw_fd < 0) {
4268 ALOGE("fe hw dep node open %d/%d failed", adev->snd_card, fe_dev);
4269 return -1;
4270 }
4271 if (ioctl(hw_fd, SNDRV_PCM_IOCTL_MMAP_DATA_FD, &mmap_fd) < 0) {
4272 ALOGE("fe hw dep node ioctl failed");
4273 close(hw_fd);
4274 return -1;
4275 }
4276 *fd = mmap_fd.fd;
4277 *size = mmap_fd.size;
4278 close(hw_fd); // mmap_fd should still be valid
4279 return 0;
4280#else
4281 return -1;
4282#endif
4283}
Mikhail Naganov4ee6e3e2018-03-21 16:28:35 +00004284
4285bool platform_sound_trigger_usecase_needs_event(audio_usecase_t uc_id)
4286{
4287 bool needs_event = false;
4288
4289 switch (uc_id) {
4290 /* concurrent capture usecases which needs event */
4291 case USECASE_AUDIO_RECORD:
4292 case USECASE_AUDIO_RECORD_LOW_LATENCY:
4293 case USECASE_AUDIO_RECORD_MMAP:
4294 case USECASE_AUDIO_RECORD_HIFI:
4295 case USECASE_AUDIO_RECORD_VOIP:
4296 case USECASE_VOICEMMODE1_CALL:
4297 case USECASE_VOICEMMODE2_CALL:
4298 /* concurrent playback usecases that needs event */
4299 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
4300 case USECASE_AUDIO_PLAYBACK_OFFLOAD:
4301 needs_event = true;
4302 break;
4303 default:
4304 ALOGV("%s:usecase_id[%d] no need to raise event.", __func__, uc_id);
4305 }
4306 return needs_event;
4307}
4308
4309bool platform_snd_device_has_speaker(snd_device_t dev) {
4310 int num_devs = 2;
4311 snd_device_t split_devs[2] = {SND_DEVICE_NONE, SND_DEVICE_NONE};
4312 if (platform_can_split_snd_device(dev, &num_devs, split_devs) == 0) {
4313 return platform_snd_device_has_speaker(split_devs[0]) ||
4314 platform_snd_device_has_speaker(split_devs[1]);
4315 }
4316
4317 switch (dev) {
4318 case SND_DEVICE_OUT_SPEAKER:
4319 case SND_DEVICE_OUT_SPEAKER_SAFE:
4320 case SND_DEVICE_OUT_SPEAKER_REVERSE:
4321 case SND_DEVICE_OUT_SPEAKER_PROTECTED:
4322 case SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED:
4323 case SND_DEVICE_OUT_VOICE_SPEAKER_HFP:
4324 return true;
4325 default:
4326 break;
4327 }
4328 return false;
4329}
jiabin8962a4d2018-03-19 18:21:24 -07004330
4331bool platform_set_microphone_characteristic(void *platform,
4332 struct audio_microphone_characteristic_t mic) {
4333 struct platform_data *my_data = (struct platform_data *)platform;
4334 if (my_data->declared_mic_count >= AUDIO_MICROPHONE_MAX_COUNT) {
4335 ALOGE("mic number is more than maximum number");
4336 return false;
4337 }
4338 for (size_t ch = 0; ch < AUDIO_CHANNEL_COUNT_MAX; ch++) {
4339 mic.channel_mapping[ch] = AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED;
4340 }
4341 my_data->microphones[my_data->declared_mic_count++] = mic;
4342 return true;
4343}
4344
4345int platform_get_microphones(void *platform,
4346 struct audio_microphone_characteristic_t *mic_array,
4347 size_t *mic_count) {
4348 struct platform_data *my_data = (struct platform_data *)platform;
4349 if (mic_count == NULL) {
4350 return -EINVAL;
4351 }
4352 if (mic_array == NULL) {
4353 return -EINVAL;
4354 }
4355
4356 if (*mic_count == 0) {
4357 *mic_count = my_data->declared_mic_count;
4358 return 0;
4359 }
4360
4361 size_t max_mic_count = *mic_count;
4362 size_t actual_mic_count = 0;
4363 for (size_t i = 0; i < max_mic_count && i < my_data->declared_mic_count; i++) {
4364 mic_array[i] = my_data->microphones[i];
4365 actual_mic_count++;
4366 }
4367 *mic_count = actual_mic_count;
4368 return 0;
4369}
4370
4371int platform_get_active_microphones(void *platform, audio_devices_t device, unsigned int channels,
4372 int source __unused, audio_usecase_t usecase __unused,
4373 struct audio_microphone_characteristic_t *mic_array,
4374 size_t *mic_count) {
4375 struct platform_data *my_data = (struct platform_data *)platform;
4376 if (mic_count == NULL) {
4377 return -EINVAL;
4378 }
4379 if (mic_array == NULL) {
4380 return -EINVAL;
4381 }
4382
4383 if (*mic_count == 0) {
4384 // TODO: return declared mic count as a preliminary implementation, the final
4385 // implementation will derive mic count and channel mapping from use case, source and device
4386 *mic_count = my_data->declared_mic_count;
4387 return 0;
4388 }
4389
4390 size_t max_mic_count = *mic_count;
4391 size_t actual_mic_count = 0;
4392 for (size_t i = 0; i < max_mic_count && i < my_data->declared_mic_count; i++) {
4393 // TODO: get actual microphone and channel mapping type.
4394 if ((my_data->microphones[i].device & device) == device) {
4395 mic_array[actual_mic_count] = my_data->microphones[i];
4396 for (size_t ch = 0; ch < channels; ch++) {
4397 mic_array[actual_mic_count].channel_mapping[ch] =
4398 AUDIO_MICROPHONE_CHANNEL_MAPPING_DIRECT;
4399 }
4400 actual_mic_count++;
4401 }
4402 }
4403 *mic_count = actual_mic_count;
4404 return 0;
4405}
Haynes Mathew George65f6b432018-02-27 17:44:55 -08004406
4407int platform_set_usb_service_interval(void *platform,
4408 bool playback,
4409 unsigned long service_interval,
4410 bool *reconfig)
4411{
4412#if defined (USB_SERVICE_INTERVAL_ENABLED)
4413 struct platform_data *_platform = (struct platform_data *)platform;
4414 *reconfig = false;
4415 if (!playback) {
4416 ALOGE("%s not valid for capture", __func__);
4417 return -1;
4418 }
4419 const char *ctl_name = "USB_AUDIO_RX service_interval";
4420 struct mixer_ctl *ctl = mixer_get_ctl_by_name(_platform->adev->mixer,
4421 ctl_name);
4422 if (!ctl) {
4423 ALOGV("%s: could not get mixer %s", __func__, ctl_name);
4424 return -1;
4425 }
4426 if (mixer_ctl_get_value(ctl, 0) != (int)service_interval) {
4427 mixer_ctl_set_value(ctl, 0, service_interval);
4428 *reconfig = true;
4429 }
4430 return 0;
4431#else
4432 *reconfig = false;
4433 (void)platform;
4434 (void)playback;
4435 (void)service_interval;
4436 return -1;
4437#endif
4438}
4439
4440int platform_get_usb_service_interval(void *platform,
4441 bool playback,
4442 unsigned long *service_interval)
4443{
4444#if defined (USB_SERVICE_INTERVAL_ENABLED)
4445 struct platform_data *_platform = (struct platform_data *)platform;
4446 if (!playback) {
4447 ALOGE("%s not valid for capture", __func__);
4448 return -1;
4449 }
4450 const char *ctl_name = "USB_AUDIO_RX service_interval";
4451 struct mixer_ctl *ctl = mixer_get_ctl_by_name(_platform->adev->mixer,
4452 ctl_name);
4453 if (!ctl) {
4454 ALOGV("%s: could not get mixer %s", __func__, ctl_name);
4455 return -1;
4456 }
4457 *service_interval = mixer_ctl_get_value(ctl, 0);
4458 return 0;
4459#else
4460 (void)platform;
4461 (void)playback;
4462 (void)service_interval;
4463 return -1;
4464#endif
4465}