blob: cb07986b944280a70d778412ff5f9530877fabbc [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)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700603};
604
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800605static const struct name_to_index usecase_type_index[USECASE_TYPE_MAX] = {
606 {TO_NAME_INDEX(PCM_PLAYBACK)},
607 {TO_NAME_INDEX(PCM_CAPTURE)},
608 {TO_NAME_INDEX(VOICE_CALL)},
609 {TO_NAME_INDEX(PCM_HFP_CALL)},
610};
611
612struct app_type_entry {
613 int uc_type;
614 int bit_width;
615 int app_type;
616 int max_rate;
vivek mehtaa68fea62017-06-08 19:04:02 -0700617 char *mode;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800618 struct listnode node; // membership in app_type_entry_list;
619};
620
621static struct listnode app_type_entry_list;
622
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700623#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
624#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
Eric Laurent0e46adf2016-12-16 12:49:24 -0800625#define ULL_PLATFORM_DELAY (3*1000LL)
626#define MMAP_PLATFORM_DELAY (3*1000LL)
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700627
Eric Laurentb23d5282013-05-14 15:27:20 -0700628static pthread_once_t check_op_once_ctl = PTHREAD_ONCE_INIT;
629static bool is_tmus = false;
630
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800631static int init_be_dai_name_table(struct audio_device *adev);
632
Eric Laurentb23d5282013-05-14 15:27:20 -0700633static void check_operator()
634{
635 char value[PROPERTY_VALUE_MAX];
636 int mccmnc;
637 property_get("gsm.sim.operator.numeric",value,"0");
638 mccmnc = atoi(value);
Eric Laurent2bafff12016-03-17 12:17:23 -0700639 ALOGD("%s: tmus mccmnc %d", __func__, mccmnc);
Eric Laurentb23d5282013-05-14 15:27:20 -0700640 switch(mccmnc) {
641 /* TMUS MCC(310), MNC(490, 260, 026) */
642 case 310490:
643 case 310260:
644 case 310026:
sangwon.jeonb891db52013-09-14 17:39:15 +0900645 /* Add new TMUS MNC(800, 660, 580, 310, 270, 250, 240, 230, 220, 210, 200, 160) */
646 case 310800:
647 case 310660:
648 case 310580:
649 case 310310:
650 case 310270:
651 case 310250:
652 case 310240:
653 case 310230:
654 case 310220:
655 case 310210:
656 case 310200:
657 case 310160:
Eric Laurentb23d5282013-05-14 15:27:20 -0700658 is_tmus = true;
659 break;
660 }
661}
662
663bool is_operator_tmus()
664{
665 pthread_once(&check_op_once_ctl, check_operator);
666 return is_tmus;
667}
668
keunhui.park2f7306a2015-07-16 16:48:06 +0900669static char *get_current_operator()
670{
671 struct listnode *node;
672 struct operator_info *info_item;
673 char mccmnc[PROPERTY_VALUE_MAX];
674 char *ret = NULL;
675
Tom Cherry7fea2042016-11-10 18:05:59 -0800676 property_get("gsm.sim.operator.numeric",mccmnc,"00000");
keunhui.park2f7306a2015-07-16 16:48:06 +0900677
678 list_for_each(node, &operator_info_list) {
679 info_item = node_to_item(node, struct operator_info, list);
680 if (strstr(info_item->mccmnc, mccmnc) != NULL) {
681 ret = info_item->name;
682 }
683 }
684
685 return ret;
686}
687
688static struct operator_specific_device *get_operator_specific_device(snd_device_t snd_device)
689{
690 struct listnode *node;
691 struct operator_specific_device *ret = NULL;
692 struct operator_specific_device *device_item;
693 char *operator_name;
694
695 operator_name = get_current_operator();
696 if (operator_name == NULL)
697 return ret;
698
699 list_for_each(node, operator_specific_device_table[snd_device]) {
700 device_item = node_to_item(node, struct operator_specific_device, list);
701 if (strcmp(operator_name, device_item->operator) == 0) {
702 ret = device_item;
703 }
704 }
705
706 return ret;
707}
708
709
710static int get_operator_specific_device_acdb_id(snd_device_t snd_device)
711{
712 struct operator_specific_device *device;
713 int ret = acdb_device_table[snd_device];
714
715 device = get_operator_specific_device(snd_device);
716 if (device != NULL)
717 ret = device->acdb_id;
718
719 return ret;
720}
721
722static const char *get_operator_specific_device_mixer_path(snd_device_t snd_device)
723{
724 struct operator_specific_device *device;
725 const char *ret = device_table[snd_device];
726
727 device = get_operator_specific_device(snd_device);
728 if (device != NULL)
729 ret = device->mixer_path;
730
731 return ret;
732}
733
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800734inline bool platform_supports_app_type_cfg()
735{
Alexey Polyudove920d4b2017-09-15 17:09:07 -0700736#if defined (PLATFORM_MSM8998) || (PLATFORM_SDM845)
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800737 return true;
738#else
739 return false;
740#endif
741}
742
vivek mehta1a9b7c02015-06-25 11:49:38 -0700743bool platform_send_gain_dep_cal(void *platform, int level)
744{
745 bool ret_val = false;
746 struct platform_data *my_data = (struct platform_data *)platform;
747 struct audio_device *adev = my_data->adev;
748 int acdb_dev_id, app_type;
749 int acdb_dev_type = MSM_SNDDEV_CAP_RX;
750 int mode = CAL_MODE_RTAC;
751 struct listnode *node;
752 struct audio_usecase *usecase;
Haynes Mathew George67486e22017-06-26 12:58:38 -0700753 bool valid_uc_type;
754 bool valid_dev;
vivek mehta1a9b7c02015-06-25 11:49:38 -0700755
756 if (my_data->acdb_send_gain_dep_cal == NULL) {
757 ALOGE("%s: dlsym error for acdb_send_gain_dep_cal", __func__);
758 return ret_val;
759 }
760
761 if (!voice_is_in_call(adev)) {
762 ALOGV("%s: Not Voice call usecase, apply new cal for level %d",
763 __func__, level);
vivek mehta1a9b7c02015-06-25 11:49:38 -0700764
765 // find the current active sound device
766 list_for_each(node, &adev->usecase_list) {
767 usecase = node_to_item(node, struct audio_usecase, list);
Haynes Mathew George67486e22017-06-26 12:58:38 -0700768 LOG_ALWAYS_FATAL_IF(usecase == NULL,
769 "unxpected NULL usecase in usecase_list");
770 valid_uc_type = usecase->type == PCM_PLAYBACK;
771 valid_dev = false;
772 if (valid_uc_type) {
773 audio_devices_t dev = usecase->stream.out->devices;
774 valid_dev = (dev == AUDIO_DEVICE_OUT_SPEAKER ||
vivek mehta40125092017-08-21 18:48:51 -0700775 dev == AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Haynes Mathew George67486e22017-06-26 12:58:38 -0700776 dev == AUDIO_DEVICE_OUT_WIRED_HEADSET ||
777 dev == AUDIO_DEVICE_OUT_WIRED_HEADPHONE);
778 }
779 if (valid_dev) {
vivek mehta40125092017-08-21 18:48:51 -0700780 ALOGV("%s: out device is %d", __func__, usecase->out_snd_device);
781 if (platform_supports_app_type_cfg())
782 app_type = usecase->stream.out->app_type_cfg.app_type;
783 else
784 app_type = DEFAULT_APP_TYPE_RX_PATH;
vivek mehta4cb82982015-07-13 12:05:49 -0700785
vivek mehta7e573672018-03-13 17:41:41 -0700786 acdb_dev_id =
787 acdb_device_table[audio_extn_get_spkr_prot_snd_device(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
Eric Laurentb23d5282013-05-14 15:27:20 -07001314void *platform_init(struct audio_device *adev)
1315{
1316 char value[PROPERTY_VALUE_MAX];
vivek mehta60ea4152016-02-18 17:10:26 -08001317 struct platform_data *my_data = NULL;
1318 int retry_num = 0, snd_card_num = 0, key = 0, ret = 0;
1319 bool dual_mic_config = false, use_default_mixer_path = true;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001320 const char *snd_card_name;
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001321 char *cvd_version = NULL;
vivek mehta60ea4152016-02-18 17:10:26 -08001322 char *snd_internal_name = NULL;
1323 char *tmp = NULL;
1324 char mixer_xml_file[MIXER_PATH_MAX_LENGTH]= {0};
vivek mehtade4849c2016-03-03 17:23:38 -08001325 char platform_info_file[MIXER_PATH_MAX_LENGTH]= {0};
1326 struct snd_card_split *snd_split_handle = NULL;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001327 my_data = calloc(1, sizeof(struct platform_data));
1328
1329 my_data->adev = adev;
1330
keunhui.park2f7306a2015-07-16 16:48:06 +09001331 list_init(&operator_info_list);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001332 list_init(&app_type_entry_list);
keunhui.park2f7306a2015-07-16 16:48:06 +09001333
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001334 set_platform_defaults(my_data);
1335
vivek mehta0fb11312017-05-15 19:35:32 -07001336 // audio_extn_utils_get_snd_card_num does
1337 // - open mixer and get snd card name
1338 // - parse platform info xml file and check for valid snd card name
1339 // - on failure loop through all the active snd card
sangwoo1b9f4b32013-06-21 18:22:55 -07001340
vivek mehta0fb11312017-05-15 19:35:32 -07001341 snd_card_num = audio_extn_utils_get_snd_card_num();
1342 if (-1 == snd_card_num) {
1343 ALOGE("%s: invalid sound card number (-1), bailing out ", __func__);
1344 goto init_failed;
sangwoo1b9f4b32013-06-21 18:22:55 -07001345 }
1346
vivek mehta0fb11312017-05-15 19:35:32 -07001347 adev->mixer = mixer_open(snd_card_num);
1348 snd_card_name = mixer_get_name(adev->mixer);
1349 my_data->hw_info = hw_info_init(snd_card_name);
1350
1351 audio_extn_set_snd_card_split(snd_card_name);
1352 snd_split_handle = audio_extn_get_snd_card_split();
1353
1354 /* Get the codec internal name from the sound card and/or form factor
1355 * name and form the mixer paths and platfor info file name dynamically.
1356 * This is generic way of picking any codec and forma factor name based
1357 * mixer and platform info files in future with no code change.
1358
1359 * current code extends and looks for any of the exteneded mixer path and
1360 * platform info file present based on codec and form factor.
1361
1362 * order of picking appropriate file is
1363 * <i> mixer_paths_<codec_name>_<form_factor>.xml, if file not present
1364 * <ii> mixer_paths_<codec_name>.xml, if file not present
1365 * <iii> mixer_paths.xml
1366
1367 * same order is followed for audio_platform_info.xml as well
1368 */
1369
1370 // need to carryforward old file name
1371 if (!strncmp(snd_card_name, TOMTOM_8226_SND_CARD_NAME,
1372 min(strlen(TOMTOM_8226_SND_CARD_NAME), strlen(snd_card_name)))) {
1373 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1374 MIXER_XML_BASE_STRING, TOMTOM_MIXER_FILE_SUFFIX );
1375 } else {
1376
1377 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s_%s.xml",
1378 MIXER_XML_BASE_STRING, snd_split_handle->snd_card,
1379 snd_split_handle->form_factor);
1380 if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) {
1381 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1382 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1383 MIXER_XML_BASE_STRING, snd_split_handle->snd_card);
1384
1385 if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) {
1386 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1387 strlcpy(mixer_xml_file, MIXER_XML_DEFAULT_PATH, MIXER_PATH_MAX_LENGTH);
1388 audio_extn_utils_resolve_config_file(mixer_xml_file);
1389 }
1390 }
1391 }
1392
1393 audio_extn_utils_get_platform_info(snd_card_name, platform_info_file);
1394
jiabin8962a4d2018-03-19 18:21:24 -07001395 my_data->declared_mic_count = 0;
vivek mehta0fb11312017-05-15 19:35:32 -07001396 /* Initialize platform specific ids and/or backends*/
1397 platform_info_init(platform_info_file, my_data);
1398
1399 ALOGD("%s: Loading mixer file: %s", __func__, mixer_xml_file);
1400 adev->audio_route = audio_route_init(snd_card_num, mixer_xml_file);
1401
1402 if (!adev->audio_route) {
1403 ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
1404 mixer_close(adev->mixer);
1405 adev->mixer = NULL;
1406 hw_info_deinit(my_data->hw_info);
1407 my_data->hw_info = NULL;
1408 goto init_failed;
1409 }
1410 adev->snd_card = snd_card_num;
1411 ALOGD("%s: Opened sound card:%d", __func__, snd_card_num);
1412
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09001413 //set max volume step for voice call
1414 property_get("ro.config.vc_call_vol_steps", value, TOSTRING(MAX_VOL_INDEX));
1415 my_data->max_vol_index = atoi(value);
1416
vivek mehta65ad12d2015-08-13 18:32:48 -07001417 property_get("persist.audio.dualmic.config",value,"");
1418 if (!strcmp("endfire", value)) {
1419 dual_mic_config = true;
1420 }
1421
John Muir9e59a962018-01-10 13:30:00 -08001422 my_data->source_mic_type = 0;
Prashant Malanic92c5962015-08-11 15:10:18 -07001423
Eric Laurentb23d5282013-05-14 15:27:20 -07001424 my_data->fluence_in_spkr_mode = false;
1425 my_data->fluence_in_voice_call = false;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001426 my_data->fluence_in_voice_comm = false;
Eric Laurentb23d5282013-05-14 15:27:20 -07001427 my_data->fluence_in_voice_rec = false;
1428
vivek mehta65ad12d2015-08-13 18:32:48 -07001429 property_get("ro.qc.sdk.audio.fluencetype", value, "none");
Prashant Malanic92c5962015-08-11 15:10:18 -07001430 if (!strcmp("fluencepro", value)) {
1431 my_data->fluence_type = FLUENCE_PRO_ENABLE;
vivek mehta65ad12d2015-08-13 18:32:48 -07001432 } else if (!strcmp("fluence", value) || (dual_mic_config)) {
Prashant Malanic92c5962015-08-11 15:10:18 -07001433 my_data->fluence_type = FLUENCE_ENABLE;
1434 } else if (!strcmp("none", value)) {
1435 my_data->fluence_type = FLUENCE_DISABLE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001436 }
1437
Prashant Malanic92c5962015-08-11 15:10:18 -07001438 if (my_data->fluence_type != FLUENCE_DISABLE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001439 property_get("persist.audio.fluence.voicecall",value,"");
1440 if (!strcmp("true", value)) {
1441 my_data->fluence_in_voice_call = true;
1442 }
1443
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001444 property_get("persist.audio.fluence.voicecomm",value,"");
1445 if (!strcmp("true", value)) {
1446 my_data->fluence_in_voice_comm = true;
1447 }
1448
Eric Laurentb23d5282013-05-14 15:27:20 -07001449 property_get("persist.audio.fluence.voicerec",value,"");
1450 if (!strcmp("true", value)) {
1451 my_data->fluence_in_voice_rec = true;
1452 }
1453
1454 property_get("persist.audio.fluence.speaker",value,"");
1455 if (!strcmp("true", value)) {
1456 my_data->fluence_in_spkr_mode = true;
1457 }
1458 }
1459
Prashant Malanic92c5962015-08-11 15:10:18 -07001460 // support max to mono, example if max count is 3, usecase supports Three, dual and mono mic
1461 switch (my_data->max_mic_count) {
1462 case 4:
1463 my_data->source_mic_type |= SOURCE_QUAD_MIC;
1464 case 3:
1465 my_data->source_mic_type |= SOURCE_THREE_MIC;
1466 case 2:
1467 my_data->source_mic_type |= SOURCE_DUAL_MIC;
1468 case 1:
1469 my_data->source_mic_type |= SOURCE_MONO_MIC;
1470 break;
1471 default:
1472 ALOGE("%s: max_mic_count (%d), is not supported, setting to default",
1473 __func__, my_data->max_mic_count);
1474 my_data->source_mic_type = SOURCE_MONO_MIC|SOURCE_DUAL_MIC;
1475 break;
1476 }
1477
1478 ALOGV("%s: Fluence_Type(%d) max_mic_count(%d) mic_type(0x%x) fluence_in_voice_call(%d)"
1479 " fluence_in_voice_comm(%d) fluence_in_voice_rec(%d) fluence_in_spkr_mode(%d) ",
1480 __func__, my_data->fluence_type, my_data->max_mic_count, my_data->source_mic_type,
1481 my_data->fluence_in_voice_call, my_data->fluence_in_voice_comm,
1482 my_data->fluence_in_voice_rec, my_data->fluence_in_spkr_mode);
1483
Eric Laurentb23d5282013-05-14 15:27:20 -07001484 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
1485 if (my_data->acdb_handle == NULL) {
1486 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
1487 } else {
1488 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
1489 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
1490 "acdb_loader_deallocate_ACDB");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001491 if (!my_data->acdb_deallocate)
1492 ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s",
1493 __func__, LIB_ACDB_LOADER);
1494
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001495 my_data->acdb_send_audio_cal_v3 = (acdb_send_audio_cal_v3_t)dlsym(my_data->acdb_handle,
1496 "acdb_loader_send_audio_cal_v3");
1497 if (!my_data->acdb_send_audio_cal_v3)
1498 ALOGE("%s: Could not find the symbol acdb_send_audio_cal_v3 from %s",
1499 __func__, LIB_ACDB_LOADER);
1500
Eric Laurentb23d5282013-05-14 15:27:20 -07001501 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
1502 "acdb_loader_send_audio_cal");
1503 if (!my_data->acdb_send_audio_cal)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001504 ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s",
Eric Laurentb23d5282013-05-14 15:27:20 -07001505 __func__, LIB_ACDB_LOADER);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001506
Eric Laurentb23d5282013-05-14 15:27:20 -07001507 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
1508 "acdb_loader_send_voice_cal");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001509 if (!my_data->acdb_send_voice_cal)
1510 ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s",
1511 __func__, LIB_ACDB_LOADER);
1512
1513 my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle,
1514 "acdb_loader_reload_vocvoltable");
1515 if (!my_data->acdb_reload_vocvoltable)
1516 ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s",
1517 __func__, LIB_ACDB_LOADER);
vivek mehta1a9b7c02015-06-25 11:49:38 -07001518
1519 my_data->acdb_send_gain_dep_cal = (acdb_send_gain_dep_cal_t)dlsym(my_data->acdb_handle,
1520 "acdb_loader_send_gain_dep_cal");
1521 if (!my_data->acdb_send_gain_dep_cal)
1522 ALOGV("%s: Could not find the symbol acdb_loader_send_gain_dep_cal from %s",
1523 __func__, LIB_ACDB_LOADER);
1524
Alexey Polyudove920d4b2017-09-15 17:09:07 -07001525#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845)
vivek mehta0fb11312017-05-15 19:35:32 -07001526 acdb_init_v2_cvd_t acdb_init_local;
1527 acdb_init_local = (acdb_init_v2_cvd_t)dlsym(my_data->acdb_handle,
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001528 "acdb_loader_init_v2");
vivek mehta0fb11312017-05-15 19:35:32 -07001529 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001530 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1531 dlerror());
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001532
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001533#elif defined (PLATFORM_MSM8084)
vivek mehta0fb11312017-05-15 19:35:32 -07001534 acdb_init_v2_t acdb_init_local;
1535 acdb_init_local = (acdb_init_v2_t)dlsym(my_data->acdb_handle,
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001536 "acdb_loader_init_v2");
vivek mehta0fb11312017-05-15 19:35:32 -07001537 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001538 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1539 dlerror());
1540
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001541#else
vivek mehta0fb11312017-05-15 19:35:32 -07001542 acdb_init_t acdb_init_local;
1543 acdb_init_local = (acdb_init_t)dlsym(my_data->acdb_handle,
Eric Laurentb23d5282013-05-14 15:27:20 -07001544 "acdb_loader_init_ACDB");
vivek mehta0fb11312017-05-15 19:35:32 -07001545 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001546 ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__,
1547 dlerror());
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001548#endif
vivek mehta0fb11312017-05-15 19:35:32 -07001549 my_data->acdb_init = acdb_init_local;
Eric Laurentb23d5282013-05-14 15:27:20 -07001550
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001551 my_data->acdb_send_custom_top = (acdb_send_custom_top_t)
1552 dlsym(my_data->acdb_handle,
1553 "acdb_loader_send_common_custom_topology");
1554
1555 if (!my_data->acdb_send_custom_top)
1556 ALOGE("%s: Could not find the symbol acdb_get_default_app_type from %s",
1557 __func__, LIB_ACDB_LOADER);
1558
vivek mehta0fb11312017-05-15 19:35:32 -07001559 int result = acdb_init(adev->snd_card);
1560 if (!result) {
1561 my_data->acdb_initialized = true;
1562 ALOGD("ACDB initialized");
1563 } else {
1564 my_data->acdb_initialized = false;
1565 ALOGD("ACDB initialization failed");
1566 }
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001567 }
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001568
David Linee3fe402017-03-13 10:00:42 -07001569 /* init usb */
1570 audio_extn_usb_init(adev);
1571
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001572 /* init a2dp */
1573 audio_extn_a2dp_init(adev);
1574
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001575 audio_extn_spkr_prot_init(adev);
Haynes Mathew George98c95622014-06-20 19:14:25 -07001576
Ravi Kumar Alamanda76315572015-04-23 13:13:56 -07001577 audio_extn_hwdep_cal_send(adev->snd_card, my_data->acdb_handle);
1578
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001579 /* load csd client */
1580 platform_csd_init(my_data);
1581
David Linee3fe402017-03-13 10:00:42 -07001582 platform_backend_config_init(my_data);
1583
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001584 init_be_dai_name_table(adev);
1585
1586 if (platform_supports_app_type_cfg())
1587 platform_backend_app_type_cfg_init(my_data, adev->mixer);
1588
Eric Laurentb23d5282013-05-14 15:27:20 -07001589 return my_data;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001590
1591init_failed:
1592 if (my_data)
1593 free(my_data);
1594 return NULL;
Eric Laurentb23d5282013-05-14 15:27:20 -07001595}
1596
1597void platform_deinit(void *platform)
1598{
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001599 int32_t dev;
keunhui.park2f7306a2015-07-16 16:48:06 +09001600 struct operator_info *info_item;
1601 struct operator_specific_device *device_item;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001602 struct app_type_entry *ap;
keunhui.park2f7306a2015-07-16 16:48:06 +09001603 struct listnode *node;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001604
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001605 struct platform_data *my_data = (struct platform_data *)platform;
1606 close_csd_client(my_data->csd);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001607
vivek mehtade4849c2016-03-03 17:23:38 -08001608 hw_info_deinit(my_data->hw_info);
1609
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001610 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1611 if (backend_tag_table[dev])
1612 free(backend_tag_table[dev]);
1613 if (hw_interface_table[dev])
1614 free(hw_interface_table[dev]);
keunhui.park2f7306a2015-07-16 16:48:06 +09001615 if (operator_specific_device_table[dev]) {
1616 while (!list_empty(operator_specific_device_table[dev])) {
1617 node = list_head(operator_specific_device_table[dev]);
1618 list_remove(node);
1619 device_item = node_to_item(node, struct operator_specific_device, list);
1620 free(device_item->operator);
1621 free(device_item->mixer_path);
1622 free(device_item);
1623 }
1624 free(operator_specific_device_table[dev]);
1625 }
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001626 }
1627
1628 if (my_data->snd_card_name)
1629 free(my_data->snd_card_name);
1630
keunhui.park2f7306a2015-07-16 16:48:06 +09001631 while (!list_empty(&operator_info_list)) {
1632 node = list_head(&operator_info_list);
1633 list_remove(node);
1634 info_item = node_to_item(node, struct operator_info, list);
1635 free(info_item->name);
1636 free(info_item->mccmnc);
1637 free(info_item);
1638 }
1639
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001640 while (!list_empty(&app_type_entry_list)) {
1641 node = list_head(&app_type_entry_list);
1642 list_remove(node);
1643 ap = node_to_item(node, struct app_type_entry, node);
vivek mehtaa68fea62017-06-08 19:04:02 -07001644 if (ap->mode) free(ap->mode);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001645 free(ap);
1646 }
1647
Kevin Rocarde35d4af2017-05-02 16:55:28 -07001648 mixer_close(my_data->adev->mixer);
Eric Laurentb23d5282013-05-14 15:27:20 -07001649 free(platform);
David Linee3fe402017-03-13 10:00:42 -07001650
1651 /* deinit usb */
1652 audio_extn_usb_deinit();
Eric Laurentb23d5282013-05-14 15:27:20 -07001653}
1654
1655const char *platform_get_snd_device_name(snd_device_t snd_device)
1656{
keunhui.park2f7306a2015-07-16 16:48:06 +09001657 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1658 if (operator_specific_device_table[snd_device] != NULL) {
1659 return get_operator_specific_device_mixer_path(snd_device);
1660 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001661 return device_table[snd_device];
keunhui.park2f7306a2015-07-16 16:48:06 +09001662 } else
Ravi Kumar Alamanda64026462014-09-15 00:08:58 -07001663 return "none";
Eric Laurentb23d5282013-05-14 15:27:20 -07001664}
1665
vivek mehtade4849c2016-03-03 17:23:38 -08001666int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
1667 char *device_name)
1668{
1669 struct platform_data *my_data = (struct platform_data *)platform;
1670
David Benjamin1565f992016-09-21 12:10:34 -04001671 if (platform == NULL) {
vivek mehtade4849c2016-03-03 17:23:38 -08001672 ALOGW("%s: something wrong, use legacy get_snd_device name", __func__);
David Benjamin1565f992016-09-21 12:10:34 -04001673 strlcpy(device_name, platform_get_snd_device_name(snd_device),
1674 DEVICE_NAME_MAX_SIZE);
vivek mehtade4849c2016-03-03 17:23:38 -08001675 } else if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1676 if (operator_specific_device_table[snd_device] != NULL) {
1677 strlcpy(device_name, get_operator_specific_device_mixer_path(snd_device),
1678 DEVICE_NAME_MAX_SIZE);
1679 } else {
1680 strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE);
1681 }
1682 hw_info_append_hw_type(my_data->hw_info, snd_device, device_name);
1683 } else {
1684 strlcpy(device_name, "none", DEVICE_NAME_MAX_SIZE);
1685 }
1686
1687 return 0;
1688}
1689
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001690void platform_add_backend_name(void *platform, char *mixer_path,
1691 snd_device_t snd_device)
Eric Laurentb23d5282013-05-14 15:27:20 -07001692{
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001693 struct platform_data *my_data = (struct platform_data *)platform;
1694
Haynes Mathew George98c95622014-06-20 19:14:25 -07001695 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1696 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1697 return;
Ravi Kumar Alamanda1de6e5a2014-06-19 21:55:39 -05001698 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001699
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001700 const char * suffix = backend_tag_table[snd_device];
Haynes Mathew George98c95622014-06-20 19:14:25 -07001701
1702 if (suffix != NULL) {
1703 strcat(mixer_path, " ");
1704 strcat(mixer_path, suffix);
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001705 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001706}
1707
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001708bool platform_check_backends_match(snd_device_t snd_device1, snd_device_t snd_device2)
1709{
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001710 ALOGV("%s: snd_device1 = %s, snd_device2 = %s", __func__,
1711 platform_get_snd_device_name(snd_device1),
1712 platform_get_snd_device_name(snd_device2));
1713
1714 if ((snd_device1 < SND_DEVICE_MIN) || (snd_device1 >= SND_DEVICE_MAX)) {
1715 ALOGE("%s: Invalid snd_device = %s", __func__,
1716 platform_get_snd_device_name(snd_device1));
1717 return false;
1718 }
1719 if ((snd_device2 < SND_DEVICE_MIN) || (snd_device2 >= SND_DEVICE_MAX)) {
1720 ALOGE("%s: Invalid snd_device = %s", __func__,
1721 platform_get_snd_device_name(snd_device2));
1722 return false;
1723 }
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07001724
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001725 const char * be_itf1 = hw_interface_table[snd_device1];
1726 const char * be_itf2 = hw_interface_table[snd_device2];
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07001727 /*
1728 hw_interface_table has overrides for a snd_device.
1729 if there is no entry for a device, assume DEFAULT_RX_BACKEND
1730 */
1731 if (be_itf1 == NULL) {
1732 be_itf1 = DEFAULT_RX_BACKEND;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001733 }
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07001734 if (be_itf2 == NULL) {
1735 be_itf2 = DEFAULT_RX_BACKEND;
1736 }
1737 ALOGV("%s: be_itf1 = %s, be_itf2 = %s", __func__, be_itf1, be_itf2);
1738 /*
1739 this takes care of finding a device within a combo device pair as well
1740 */
1741 return strstr(be_itf1, be_itf2) != NULL || strstr(be_itf2, be_itf1) != NULL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001742}
1743
Eric Laurentb23d5282013-05-14 15:27:20 -07001744int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
1745{
1746 int device_id;
1747 if (device_type == PCM_PLAYBACK)
1748 device_id = pcm_device_table[usecase][0];
1749 else
1750 device_id = pcm_device_table[usecase][1];
1751 return device_id;
1752}
1753
Haynes Mathew George98c95622014-06-20 19:14:25 -07001754static int find_index(const struct name_to_index * table, int32_t len,
1755 const char * name)
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001756{
1757 int ret = 0;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001758 int32_t i;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001759
Haynes Mathew George98c95622014-06-20 19:14:25 -07001760 if (table == NULL) {
1761 ALOGE("%s: table is NULL", __func__);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001762 ret = -ENODEV;
1763 goto done;
1764 }
1765
Haynes Mathew George98c95622014-06-20 19:14:25 -07001766 if (name == NULL) {
1767 ALOGE("null key");
1768 ret = -ENODEV;
1769 goto done;
1770 }
1771
1772 for (i=0; i < len; i++) {
1773 if (!strcmp(table[i].name, name)) {
1774 ret = table[i].index;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001775 goto done;
1776 }
1777 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001778 ALOGE("%s: Could not find index for name = %s",
1779 __func__, name);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001780 ret = -ENODEV;
1781done:
1782 return ret;
1783}
1784
Haynes Mathew George98c95622014-06-20 19:14:25 -07001785int platform_get_snd_device_index(char *device_name)
1786{
1787 return find_index(snd_device_name_index, SND_DEVICE_MAX, device_name);
1788}
1789
1790int platform_get_usecase_index(const char *usecase_name)
1791{
1792 return find_index(usecase_name_index, AUDIO_USECASE_MAX, usecase_name);
1793}
1794
keunhui.park2f7306a2015-07-16 16:48:06 +09001795void platform_add_operator_specific_device(snd_device_t snd_device,
1796 const char *operator,
1797 const char *mixer_path,
1798 unsigned int acdb_id)
1799{
1800 struct operator_specific_device *device;
1801
1802 if (operator_specific_device_table[snd_device] == NULL) {
1803 operator_specific_device_table[snd_device] =
1804 (struct listnode *)calloc(1, sizeof(struct listnode));
1805 list_init(operator_specific_device_table[snd_device]);
1806 }
1807
1808 device = (struct operator_specific_device *)calloc(1, sizeof(struct operator_specific_device));
1809
1810 device->operator = strdup(operator);
1811 device->mixer_path = strdup(mixer_path);
1812 device->acdb_id = acdb_id;
1813
1814 list_add_tail(operator_specific_device_table[snd_device], &device->list);
1815
Eric Laurent2bafff12016-03-17 12:17:23 -07001816 ALOGD("%s: device[%s] -> operator[%s] mixer_path[%s] acdb_id[%d]", __func__,
keunhui.park2f7306a2015-07-16 16:48:06 +09001817 platform_get_snd_device_name(snd_device), operator, mixer_path, acdb_id);
1818
1819}
1820
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001821int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
1822{
1823 int ret = 0;
1824
1825 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1826 ALOGE("%s: Invalid snd_device = %d",
1827 __func__, snd_device);
1828 ret = -EINVAL;
1829 goto done;
1830 }
1831
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001832 ALOGV("%s: acdb_device_table[%s]: old = %d new = %d", __func__,
1833 platform_get_snd_device_name(snd_device), acdb_device_table[snd_device], acdb_id);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001834 acdb_device_table[snd_device] = acdb_id;
1835done:
1836 return ret;
1837}
1838
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001839int platform_get_snd_device_acdb_id(snd_device_t snd_device)
1840{
1841 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1842 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1843 return -EINVAL;
1844 }
keunhui.park2f7306a2015-07-16 16:48:06 +09001845
1846 if (operator_specific_device_table[snd_device] != NULL)
1847 return get_operator_specific_device_acdb_id(snd_device);
1848 else
1849 return acdb_device_table[snd_device];
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001850}
1851
David Linee3fe402017-03-13 10:00:42 -07001852static int platform_get_backend_index(snd_device_t snd_device)
1853{
1854 int32_t port = DEFAULT_CODEC_BACKEND;
1855
1856 if (snd_device >= SND_DEVICE_OUT_BEGIN && snd_device < SND_DEVICE_OUT_END) {
1857 if (backend_tag_table[snd_device] != NULL) {
1858 if (strncmp(backend_tag_table[snd_device], "headphones",
1859 sizeof("headphones")) == 0)
1860 port = HEADPHONE_BACKEND;
1861 else if (strcmp(backend_tag_table[snd_device], "hdmi") == 0)
1862 port = HDMI_RX_BACKEND;
1863 else if ((strcmp(backend_tag_table[snd_device], "usb-headphones") == 0) ||
1864 (strcmp(backend_tag_table[snd_device], "usb-headset") == 0))
1865 port = USB_AUDIO_RX_BACKEND;
1866 }
1867 } else if (snd_device >= SND_DEVICE_IN_BEGIN && snd_device < SND_DEVICE_IN_END) {
1868 port = DEFAULT_CODEC_TX_BACKEND;
1869 if (backend_tag_table[snd_device] != NULL) {
1870 if (strcmp(backend_tag_table[snd_device], "usb-headset-mic") == 0)
1871 port = USB_AUDIO_TX_BACKEND;
1872 else if (strstr(backend_tag_table[snd_device], "bt-sco") != NULL)
1873 port = BT_SCO_TX_BACKEND;
1874 }
1875 } else {
1876 ALOGW("%s:napb: Invalid device - %d ", __func__, snd_device);
1877 }
1878
1879 ALOGV("%s:napb: backend port - %d device - %d ", __func__, port, snd_device);
1880
1881 return port;
1882}
1883
Eric Laurentb23d5282013-05-14 15:27:20 -07001884int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
1885{
1886 struct platform_data *my_data = (struct platform_data *)platform;
1887 int acdb_dev_id, acdb_dev_type;
1888
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001889 if (platform_supports_app_type_cfg()) // use v2 instead
1890 return -ENOSYS;
1891
Ravi Kumar Alamandaadf0f3b2015-06-04 02:34:02 -07001892 acdb_dev_id = acdb_device_table[audio_extn_get_spkr_prot_snd_device(snd_device)];
Eric Laurentb23d5282013-05-14 15:27:20 -07001893 if (acdb_dev_id < 0) {
1894 ALOGE("%s: Could not find acdb id for device(%d)",
1895 __func__, snd_device);
1896 return -EINVAL;
1897 }
1898 if (my_data->acdb_send_audio_cal) {
Joe Onorato188b6222016-03-01 11:02:27 -08001899 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Eric Laurentb23d5282013-05-14 15:27:20 -07001900 __func__, snd_device, acdb_dev_id);
1901 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
1902 snd_device < SND_DEVICE_OUT_END)
1903 acdb_dev_type = ACDB_DEV_TYPE_OUT;
1904 else
1905 acdb_dev_type = ACDB_DEV_TYPE_IN;
1906 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
1907 }
1908 return 0;
1909}
1910
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001911int platform_send_audio_calibration_v2(void *platform, struct audio_usecase *usecase,
1912 int app_type, int sample_rate)
1913{
1914 struct platform_data *my_data = (struct platform_data *)platform;
1915 int acdb_dev_id, acdb_dev_type;
vivek mehta7e573672018-03-13 17:41:41 -07001916 int snd_device = usecase->out_snd_device;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001917 int new_snd_device[SND_DEVICE_OUT_END] = {0};
1918 int i, num_devices = 1;
1919
1920 if (!platform_supports_app_type_cfg()) // use v1 instead
1921 return -ENOSYS;
1922
vivek mehta7e573672018-03-13 17:41:41 -07001923 if ((usecase->type == PCM_HFP_CALL) || (usecase->type == PCM_CAPTURE))
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001924 snd_device = usecase->in_snd_device;
1925
1926 // skipped over get_spkr_prot_device
vivek mehta7e573672018-03-13 17:41:41 -07001927 acdb_dev_id = acdb_device_table[audio_extn_get_spkr_prot_snd_device(snd_device)];
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001928 if (acdb_dev_id < 0) {
1929 ALOGE("%s: Could not find acdb id for device(%d)",
1930 __func__, snd_device);
1931 return -EINVAL;
1932 }
1933
1934 if (platform_can_split_snd_device(snd_device,
1935 &num_devices, new_snd_device) < 0) {
1936 new_snd_device[0] = snd_device;
1937 }
1938
1939 for (i = 0; i < num_devices; i++) {
vivek mehta7e573672018-03-13 17:41:41 -07001940 acdb_dev_id = acdb_device_table[audio_extn_get_spkr_prot_snd_device(new_snd_device[i])];
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001941 if (acdb_dev_id < 0) {
1942 ALOGE("%s: Could not find acdb id for device(%d)",
1943 __func__, new_snd_device[i]);
1944 return -EINVAL;
1945 }
1946 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
1947 __func__, new_snd_device[i], acdb_dev_id);
1948 if (new_snd_device[i] >= SND_DEVICE_OUT_BEGIN &&
1949 new_snd_device[i] < SND_DEVICE_OUT_END)
1950 acdb_dev_type = ACDB_DEV_TYPE_OUT;
1951 else
1952 acdb_dev_type = ACDB_DEV_TYPE_IN;
1953
1954 if (my_data->acdb_send_audio_cal_v3) {
1955 my_data->acdb_send_audio_cal_v3(acdb_dev_id, acdb_dev_type,
1956 app_type, sample_rate, i);
1957 } else if (my_data->acdb_send_audio_cal) {
1958 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type); // this version differs from internal
1959 }
1960 }
1961
1962 return 0;
1963}
1964
1965
Eric Laurentb23d5282013-05-14 15:27:20 -07001966int platform_switch_voice_call_device_pre(void *platform)
1967{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001968 struct platform_data *my_data = (struct platform_data *)platform;
1969 int ret = 0;
1970
1971 if (my_data->csd != NULL &&
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001972 voice_is_in_call(my_data->adev)) {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001973 /* This must be called before disabling mixer controls on APQ side */
1974 ret = my_data->csd->disable_device();
1975 if (ret < 0) {
1976 ALOGE("%s: csd_client_disable_device, failed, error %d",
1977 __func__, ret);
1978 }
1979 }
1980 return ret;
1981}
1982
1983int platform_switch_voice_call_enable_device_config(void *platform,
1984 snd_device_t out_snd_device,
1985 snd_device_t in_snd_device)
1986{
1987 struct platform_data *my_data = (struct platform_data *)platform;
1988 int acdb_rx_id, acdb_tx_id;
1989 int ret = 0;
1990
1991 if (my_data->csd == NULL)
1992 return ret;
1993
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001994 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1995 audio_extn_spkr_prot_is_enabled())
keunhui.park2f7306a2015-07-16 16:48:06 +09001996 acdb_rx_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_SPEAKER_PROTECTED);
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001997 else
keunhui.park2f7306a2015-07-16 16:48:06 +09001998 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001999
keunhui.park2f7306a2015-07-16 16:48:06 +09002000 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002001
2002 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
2003 ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
2004 if (ret < 0) {
2005 ALOGE("%s: csd_enable_device_config, failed, error %d",
2006 __func__, ret);
2007 }
2008 } else {
2009 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2010 acdb_rx_id, acdb_tx_id);
2011 }
2012
2013 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002014}
2015
2016int platform_switch_voice_call_device_post(void *platform,
2017 snd_device_t out_snd_device,
2018 snd_device_t in_snd_device)
2019{
2020 struct platform_data *my_data = (struct platform_data *)platform;
2021 int acdb_rx_id, acdb_tx_id;
2022
2023 if (my_data->acdb_send_voice_cal == NULL) {
2024 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
2025 } else {
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07002026 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
2027 audio_extn_spkr_prot_is_enabled())
2028 out_snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED;
2029
keunhui.park2f7306a2015-07-16 16:48:06 +09002030 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
2031 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07002032
2033 if (acdb_rx_id > 0 && acdb_tx_id > 0)
2034 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
2035 else
2036 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2037 acdb_rx_id, acdb_tx_id);
2038 }
2039
2040 return 0;
2041}
2042
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002043int platform_switch_voice_call_usecase_route_post(void *platform,
2044 snd_device_t out_snd_device,
2045 snd_device_t in_snd_device)
2046{
2047 struct platform_data *my_data = (struct platform_data *)platform;
2048 int acdb_rx_id, acdb_tx_id;
2049 int ret = 0;
2050
2051 if (my_data->csd == NULL)
2052 return ret;
2053
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07002054 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
2055 audio_extn_spkr_prot_is_enabled())
keunhui.park2f7306a2015-07-16 16:48:06 +09002056 acdb_rx_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED);
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07002057 else
keunhui.park2f7306a2015-07-16 16:48:06 +09002058 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002059
keunhui.park2f7306a2015-07-16 16:48:06 +09002060 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002061
2062 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
2063 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
2064 my_data->adev->acdb_settings);
2065 if (ret < 0) {
2066 ALOGE("%s: csd_enable_device, failed, error %d", __func__, ret);
2067 }
2068 } else {
2069 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2070 acdb_rx_id, acdb_tx_id);
2071 }
2072
2073 return ret;
2074}
2075
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002076int platform_start_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07002077{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002078 struct platform_data *my_data = (struct platform_data *)platform;
2079 int ret = 0;
2080
2081 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002082 ret = my_data->csd->start_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002083 if (ret < 0) {
2084 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
2085 }
2086 }
2087 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002088}
2089
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002090int platform_stop_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07002091{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002092 struct platform_data *my_data = (struct platform_data *)platform;
2093 int ret = 0;
2094
2095 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002096 ret = my_data->csd->stop_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002097 if (ret < 0) {
2098 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
2099 }
2100 }
2101 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002102}
2103
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002104int platform_get_sample_rate(void *platform, uint32_t *rate)
2105{
2106 struct platform_data *my_data = (struct platform_data *)platform;
2107 int ret = 0;
2108
2109 if (my_data->csd != NULL) {
2110 ret = my_data->csd->get_sample_rate(rate);
2111 if (ret < 0) {
2112 ALOGE("%s: csd_get_sample_rate error %d\n", __func__, ret);
2113 }
2114 }
2115 return ret;
2116}
2117
vivek mehtab6506412015-08-07 16:55:17 -07002118void platform_set_speaker_gain_in_combo(struct audio_device *adev,
2119 snd_device_t snd_device,
2120 bool enable)
2121{
2122 const char* name;
2123 switch (snd_device) {
2124 case SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES:
2125 if (enable)
2126 name = "spkr-gain-in-headphone-combo";
2127 else
2128 name = "speaker-gain-default";
2129 break;
2130 case SND_DEVICE_OUT_SPEAKER_AND_LINE:
2131 if (enable)
2132 name = "spkr-gain-in-line-combo";
2133 else
2134 name = "speaker-gain-default";
2135 break;
2136 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES:
2137 if (enable)
2138 name = "spkr-safe-gain-in-headphone-combo";
2139 else
2140 name = "speaker-safe-gain-default";
2141 break;
2142 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE:
2143 if (enable)
2144 name = "spkr-safe-gain-in-line-combo";
2145 else
2146 name = "speaker-safe-gain-default";
2147 break;
2148 default:
2149 return;
2150 }
2151
2152 audio_route_apply_and_update_path(adev->audio_route, name);
2153}
2154
Eric Laurentb23d5282013-05-14 15:27:20 -07002155int platform_set_voice_volume(void *platform, int volume)
2156{
2157 struct platform_data *my_data = (struct platform_data *)platform;
2158 struct audio_device *adev = my_data->adev;
2159 struct mixer_ctl *ctl;
sangwoo53b2cf02013-07-25 19:18:44 -07002160 const char *mixer_ctl_name = "Voice Rx Gain";
Nadav Barc46d0fa2017-12-24 14:50:37 +02002161 const char *mute_mixer_ctl_name = "Voice Rx Device Mute";
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002162 int vol_index = 0, ret = 0;
2163 uint32_t set_values[ ] = {0,
2164 ALL_SESSION_VSID,
2165 DEFAULT_VOLUME_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07002166
2167 // Voice volume levels are mapped to adsp volume levels as follows.
2168 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
2169 // But this values don't changed in kernel. So, below change is need.
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09002170 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, my_data->max_vol_index);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002171 set_values[0] = vol_index;
Eric Laurentb23d5282013-05-14 15:27:20 -07002172
2173 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2174 if (!ctl) {
2175 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2176 __func__, mixer_ctl_name);
2177 return -EINVAL;
2178 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002179 ALOGV("Setting voice volume index: %d", set_values[0]);
2180 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2181
Nadav Barc46d0fa2017-12-24 14:50:37 +02002182 // Send mute command in case volume index is max since indexes are inverted
2183 // for mixer controls.
2184 if (vol_index == my_data->max_vol_index) {
2185 set_values[0] = 1;
2186 }
2187 else {
2188 set_values[0] = 0;
2189 }
2190
2191 ctl = mixer_get_ctl_by_name(adev->mixer, mute_mixer_ctl_name);
2192 if (!ctl) {
2193 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2194 __func__, mute_mixer_ctl_name);
2195 return -EINVAL;
2196 }
2197 ALOGV("%s: Setting RX Device Mute to: %d", __func__, set_values[0]);
2198 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2199
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002200 if (my_data->csd != NULL) {
2201 ret = my_data->csd->volume(ALL_SESSION_VSID, volume,
2202 DEFAULT_VOLUME_RAMP_DURATION_MS);
2203 if (ret < 0) {
2204 ALOGE("%s: csd_volume error %d", __func__, ret);
2205 }
2206 }
2207 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002208}
2209
2210int platform_set_mic_mute(void *platform, bool state)
2211{
2212 struct platform_data *my_data = (struct platform_data *)platform;
2213 struct audio_device *adev = my_data->adev;
2214 struct mixer_ctl *ctl;
2215 const char *mixer_ctl_name = "Voice Tx Mute";
sangwoo53b2cf02013-07-25 19:18:44 -07002216 int ret = 0;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002217 uint32_t set_values[ ] = {0,
2218 ALL_SESSION_VSID,
2219 DEFAULT_MUTE_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07002220
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09002221 if (adev->mode != AUDIO_MODE_IN_CALL &&
2222 adev->mode != AUDIO_MODE_IN_COMMUNICATION)
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002223 return 0;
2224
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09002225 if (adev->enable_hfp)
2226 mixer_ctl_name = "HFP Tx Mute";
2227
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002228 set_values[0] = state;
2229 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2230 if (!ctl) {
2231 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2232 __func__, mixer_ctl_name);
2233 return -EINVAL;
2234 }
2235 ALOGV("Setting voice mute state: %d", state);
2236 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2237
2238 if (my_data->csd != NULL) {
2239 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state,
2240 DEFAULT_MUTE_RAMP_DURATION_MS);
sangwoo53b2cf02013-07-25 19:18:44 -07002241 if (ret < 0) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002242 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
sangwoo53b2cf02013-07-25 19:18:44 -07002243 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002244 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002245 return ret;
2246}
Eric Laurentb23d5282013-05-14 15:27:20 -07002247
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002248int platform_set_device_mute(void *platform, bool state, char *dir)
2249{
2250 struct platform_data *my_data = (struct platform_data *)platform;
2251 struct audio_device *adev = my_data->adev;
2252 struct mixer_ctl *ctl;
2253 char *mixer_ctl_name = NULL;
2254 int ret = 0;
2255 uint32_t set_values[ ] = {0,
2256 ALL_SESSION_VSID,
2257 0};
2258 if(dir == NULL) {
2259 ALOGE("%s: Invalid direction:%s", __func__, dir);
2260 return -EINVAL;
2261 }
2262
2263 if (!strncmp("rx", dir, sizeof("rx"))) {
2264 mixer_ctl_name = "Voice Rx Device Mute";
2265 } else if (!strncmp("tx", dir, sizeof("tx"))) {
2266 mixer_ctl_name = "Voice Tx Device Mute";
2267 } else {
2268 return -EINVAL;
2269 }
2270
2271 set_values[0] = state;
2272 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2273 if (!ctl) {
2274 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2275 __func__, mixer_ctl_name);
2276 return -EINVAL;
2277 }
2278
2279 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
2280 __func__,state, mixer_ctl_name);
2281 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2282
2283 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002284}
2285
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002286int platform_can_split_snd_device(snd_device_t snd_device,
2287 int *num_devices,
2288 snd_device_t *new_snd_devices)
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002289{
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002290 int ret = -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002291 if (NULL == num_devices || NULL == new_snd_devices) {
2292 ALOGE("%s: NULL pointer ..", __func__);
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002293 return -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002294 }
2295
2296 /*
2297 * If wired headset/headphones/line devices share the same backend
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002298 * with speaker/earpiece this routine returns -EINVAL.
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002299 */
2300 if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES &&
2301 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_HEADPHONES)) {
2302 *num_devices = 2;
2303 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2304 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002305 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002306 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_LINE &&
2307 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_LINE)) {
2308 *num_devices = 2;
2309 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2310 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002311 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002312 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES &&
2313 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_HEADPHONES)) {
2314 *num_devices = 2;
2315 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2316 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002317 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002318 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE &&
2319 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_LINE)) {
2320 *num_devices = 2;
2321 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2322 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002323 ret = 0;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002324 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO &&
2325 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2326 SND_DEVICE_OUT_BT_SCO)) {
2327 *num_devices = 2;
2328 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2329 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO;
2330 ret = 0;
2331 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB &&
2332 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2333 SND_DEVICE_OUT_BT_SCO_WB)) {
2334 *num_devices = 2;
2335 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2336 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO_WB;
2337 ret = 0;
David Linee3fe402017-03-13 10:00:42 -07002338 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET &&
2339 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_USB_HEADSET)) {
2340 *num_devices = 2;
2341 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2342 new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
2343 ret = 0;
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07002344 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET &&
2345 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_USB_HEADSET)) {
2346 *num_devices = 2;
2347 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2348 new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
2349 ret = 0;
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002350 } else if (SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP == snd_device &&
2351 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2352 SND_DEVICE_OUT_BT_A2DP)) {
2353 *num_devices = 2;
2354 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2355 new_snd_devices[1] = SND_DEVICE_OUT_BT_A2DP;
2356 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002357 }
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002358
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002359 return ret;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002360}
2361
Eric Laurentb23d5282013-05-14 15:27:20 -07002362snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
2363{
2364 struct platform_data *my_data = (struct platform_data *)platform;
2365 struct audio_device *adev = my_data->adev;
2366 audio_mode_t mode = adev->mode;
2367 snd_device_t snd_device = SND_DEVICE_NONE;
2368
2369 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
2370 if (devices == AUDIO_DEVICE_NONE ||
2371 devices & AUDIO_DEVICE_BIT_IN) {
2372 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
2373 goto exit;
2374 }
2375
Eric Laurent1b491552015-09-15 17:52:41 -07002376 if (popcount(devices) == 2) {
2377 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2378 AUDIO_DEVICE_OUT_SPEAKER) ||
2379 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2380 AUDIO_DEVICE_OUT_SPEAKER)) {
2381 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
2382 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2383 AUDIO_DEVICE_OUT_SPEAKER)) {
2384 snd_device = SND_DEVICE_OUT_SPEAKER_AND_LINE;
2385 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2386 AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
2387 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2388 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2389 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES;
2390 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2391 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2392 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE;
2393 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
2394 AUDIO_DEVICE_OUT_SPEAKER)) {
2395 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002396 } else if ((devices & AUDIO_DEVICE_OUT_ALL_SCO) &&
2397 ((devices & ~AUDIO_DEVICE_OUT_ALL_SCO) == AUDIO_DEVICE_OUT_SPEAKER)) {
2398 snd_device = adev->bt_wb_speech_enabled ?
2399 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB :
2400 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO;
Eric Laurent99dab492017-06-17 15:19:08 -07002401 } else if ((devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
2402 AUDIO_DEVICE_OUT_SPEAKER)) ||
2403 (devices == (AUDIO_DEVICE_OUT_USB_HEADSET |
2404 AUDIO_DEVICE_OUT_SPEAKER))) {
David Linee3fe402017-03-13 10:00:42 -07002405 snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET;
Eric Laurentd0f7c262017-07-05 09:09:12 -07002406 } else if ((devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
2407 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) ||
2408 (devices == (AUDIO_DEVICE_OUT_USB_HEADSET |
2409 AUDIO_DEVICE_OUT_SPEAKER_SAFE))) {
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07002410 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET;
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002411 } else if ((devices & AUDIO_DEVICE_OUT_SPEAKER) &&
2412 (devices & AUDIO_DEVICE_OUT_ALL_A2DP)) {
2413 snd_device = SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP;
Eric Laurent1b491552015-09-15 17:52:41 -07002414 } else {
2415 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
2416 goto exit;
2417 }
2418 if (snd_device != SND_DEVICE_NONE) {
2419 goto exit;
2420 }
2421 }
2422
2423 if (popcount(devices) != 1) {
2424 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
2425 goto exit;
2426 }
2427
Madhuri Athota3f6051b2016-10-13 23:25:38 +05302428 if (voice_is_in_call(adev) || adev->enable_voicerx || audio_extn_hfp_is_active(adev)) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002429 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002430 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2431 devices & AUDIO_DEVICE_OUT_LINE) {
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002432 if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002433 (adev->voice.tty_mode == TTY_MODE_FULL))
Eric Laurentb23d5282013-05-14 15:27:20 -07002434 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002435 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002436 (adev->voice.tty_mode == TTY_MODE_VCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002437 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002438 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002439 (adev->voice.tty_mode == TTY_MODE_HCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002440 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002441 else {
2442 if (devices & AUDIO_DEVICE_OUT_LINE)
2443 snd_device = SND_DEVICE_OUT_VOICE_LINE;
2444 else
2445 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
2446 }
Eric Laurent99dab492017-06-17 15:19:08 -07002447 } else if (audio_is_usb_out_device(devices)) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002448 if (voice_is_in_call(adev)) {
2449 switch (adev->voice.tty_mode) {
2450 case TTY_MODE_FULL:
2451 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_USB;
2452 break;
2453 case TTY_MODE_VCO:
2454 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_USB;
2455 break;
2456 case TTY_MODE_HCO:
2457 // since Hearing will be on handset\speaker, use existing device
2458 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
2459 break;
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002460 case TTY_MODE_OFF:
2461 break;
vivek mehtaa6b79742017-03-09 15:40:43 -08002462 default:
2463 ALOGE("%s: Invalid TTY mode (%#x)",
2464 __func__, adev->voice.tty_mode);
2465 }
2466 }
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002467 if (snd_device == SND_DEVICE_NONE) {
2468 snd_device = audio_extn_usb_is_capture_supported() ?
2469 SND_DEVICE_OUT_VOICE_USB_HEADSET :
2470 SND_DEVICE_OUT_VOICE_USB_HEADPHONES;
2471 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002472 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002473 if (adev->bt_wb_speech_enabled) {
2474 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2475 } else {
2476 snd_device = SND_DEVICE_OUT_BT_SCO;
2477 }
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002478 } else if (devices & AUDIO_DEVICE_OUT_ALL_A2DP) {
2479 snd_device = SND_DEVICE_OUT_BT_A2DP;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002480 } else if (devices & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002481 if (!adev->enable_hfp) {
2482 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
2483 } else {
2484 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_HFP;
2485 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002486 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002487 if(adev->voice.hac)
2488 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2489 else if (is_operator_tmus())
Eric Laurentb23d5282013-05-14 15:27:20 -07002490 snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS;
2491 else
Eric Laurentb4d368e2014-06-25 10:21:54 -05002492 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002493 } else if (devices & AUDIO_DEVICE_OUT_TELEPHONY_TX)
2494 snd_device = SND_DEVICE_OUT_VOICE_TX;
2495
Eric Laurentb23d5282013-05-14 15:27:20 -07002496 if (snd_device != SND_DEVICE_NONE) {
2497 goto exit;
2498 }
2499 }
2500
Eric Laurentb23d5282013-05-14 15:27:20 -07002501 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2502 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2503 snd_device = SND_DEVICE_OUT_HEADPHONES;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002504 } else if (devices & AUDIO_DEVICE_OUT_LINE) {
2505 snd_device = SND_DEVICE_OUT_LINE;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002506 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) {
2507 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE;
Eric Laurentb23d5282013-05-14 15:27:20 -07002508 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002509 if (my_data->speaker_lr_swap)
Eric Laurentb23d5282013-05-14 15:27:20 -07002510 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
2511 else
2512 snd_device = SND_DEVICE_OUT_SPEAKER;
2513 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002514 if (adev->bt_wb_speech_enabled) {
2515 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2516 } else {
2517 snd_device = SND_DEVICE_OUT_BT_SCO;
2518 }
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002519 } else if (devices & AUDIO_DEVICE_OUT_ALL_A2DP) {
2520 snd_device = SND_DEVICE_OUT_BT_A2DP;
Eric Laurentb23d5282013-05-14 15:27:20 -07002521 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2522 snd_device = SND_DEVICE_OUT_HDMI ;
Eric Laurent99dab492017-06-17 15:19:08 -07002523 } else if (audio_is_usb_out_device(devices)) {
David Linee3fe402017-03-13 10:00:42 -07002524 if (audio_extn_usb_is_capture_supported())
2525 snd_device = SND_DEVICE_OUT_USB_HEADSET;
2526 else
2527 snd_device = SND_DEVICE_OUT_USB_HEADPHONES;
2528 }else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002529 /*HAC support for voice-ish audio (eg visual voicemail)*/
2530 if(adev->voice.hac)
2531 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2532 else
2533 snd_device = SND_DEVICE_OUT_HANDSET;
Eric Laurentb23d5282013-05-14 15:27:20 -07002534 } else {
2535 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
2536 }
2537exit:
2538 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
2539 return snd_device;
2540}
2541
2542snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
2543{
2544 struct platform_data *my_data = (struct platform_data *)platform;
2545 struct audio_device *adev = my_data->adev;
2546 audio_source_t source = (adev->active_input == NULL) ?
2547 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
2548
2549 audio_mode_t mode = adev->mode;
2550 audio_devices_t in_device = ((adev->active_input == NULL) ?
2551 AUDIO_DEVICE_NONE : adev->active_input->device)
2552 & ~AUDIO_DEVICE_BIT_IN;
2553 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
2554 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
2555 snd_device_t snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002556 int channel_count = popcount(channel_mask);
Eric Laurentb23d5282013-05-14 15:27:20 -07002557
Prashant Malanic92c5962015-08-11 15:10:18 -07002558 ALOGV("%s: enter: out_device(%#x) in_device(%#x) channel_count (%d) channel_mask (0x%x)",
2559 __func__, out_device, in_device, channel_count, channel_mask);
Devin Kimd789e432016-10-26 15:07:27 -07002560 if ((out_device != AUDIO_DEVICE_NONE) && (voice_is_in_call(adev) ||
2561 audio_extn_hfp_is_active(adev))) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002562 if (adev->voice.tty_mode != TTY_MODE_OFF) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002563 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002564 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2565 out_device & AUDIO_DEVICE_OUT_LINE) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002566 switch (adev->voice.tty_mode) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002567 case TTY_MODE_FULL:
2568 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
2569 break;
2570 case TTY_MODE_VCO:
2571 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
2572 break;
2573 case TTY_MODE_HCO:
2574 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
2575 break;
2576 default:
2577 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
2578 }
2579 goto exit;
Eric Laurent99dab492017-06-17 15:19:08 -07002580 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002581 switch (adev->voice.tty_mode) {
2582 case TTY_MODE_FULL:
2583 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC;
2584 break;
2585 case TTY_MODE_VCO:
2586 // since voice will be captured from handset mic, use existing device
2587 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
2588 break;
2589 case TTY_MODE_HCO:
2590 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC;
2591 break;
2592 default:
2593 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
Eric Laurentb23d5282013-05-14 15:27:20 -07002594 }
2595 goto exit;
2596 }
2597 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002598 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002599 if (my_data->fluence_in_voice_call == false) {
2600 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2601 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002602 if (is_operator_tmus())
2603 snd_device = SND_DEVICE_IN_VOICE_DMIC_TMUS;
Eric Laurentb23d5282013-05-14 15:27:20 -07002604 else
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002605 snd_device = SND_DEVICE_IN_VOICE_DMIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002606 }
2607 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2608 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
2609 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002610 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002611 if (adev->bluetooth_nrec)
2612 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2613 else
2614 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002615 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002616 if (adev->bluetooth_nrec)
2617 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2618 else
2619 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002620 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002621 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Prashant Malanic92c5962015-08-11 15:10:18 -07002622 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
2623 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2624 out_device & AUDIO_DEVICE_OUT_LINE) {
2625 if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
2626 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
2627 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
2628 } else {
2629 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2630 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002631 }
vivek mehtafe121d52015-08-10 23:39:23 -07002632
2633 //select default
2634 if (snd_device == SND_DEVICE_NONE) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002635 if (!adev->enable_hfp) {
2636 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2637 } else {
2638 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP;
2639 platform_set_echo_reference(adev, true, out_device);
2640 }
vivek mehtafe121d52015-08-10 23:39:23 -07002641 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002642 } else if (out_device & AUDIO_DEVICE_OUT_TELEPHONY_TX) {
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002643 snd_device = SND_DEVICE_IN_VOICE_RX;
Eric Laurent99dab492017-06-17 15:19:08 -07002644 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
David Lin40b07892017-08-07 15:02:48 -07002645 if (audio_extn_usb_is_capture_supported()) {
2646 snd_device = SND_DEVICE_IN_VOICE_USB_HEADSET_MIC;
2647 } else if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
2648 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
2649 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
2650 } else {
2651 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2652 }
2653 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002654 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002655 } else if (source == AUDIO_SOURCE_CAMCORDER) {
2656 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
2657 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2658 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
2659 }
2660 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
2661 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002662 if (my_data->fluence_in_voice_rec && channel_count == 1) {
2663 if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2664 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002665 if (adev->active_input->enable_aec)
2666 snd_device = SND_DEVICE_IN_HANDSET_QMIC_AEC;
2667 else
2668 snd_device = SND_DEVICE_IN_HANDSET_QMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002669 } else if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2670 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002671 if (adev->active_input->enable_aec)
2672 snd_device = SND_DEVICE_IN_HANDSET_TMIC_AEC;
2673 else
2674 snd_device = SND_DEVICE_IN_HANDSET_TMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002675 } else if (((my_data->fluence_type == FLUENCE_PRO_ENABLE) ||
2676 (my_data->fluence_type == FLUENCE_ENABLE)) &&
2677 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002678 if (adev->active_input->enable_aec)
2679 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
2680 else
2681 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
Prashant Malanic92c5962015-08-11 15:10:18 -07002682 }
2683 platform_set_echo_reference(adev, true, out_device);
2684 } else if ((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) &&
2685 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2686 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002687 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002688 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
2689 snd_device = SND_DEVICE_IN_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002690 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002691 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2692 snd_device = SND_DEVICE_IN_QUAD_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002693 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002694 if (snd_device == SND_DEVICE_NONE) {
vivek mehtaf3440682016-05-11 14:24:37 -07002695 if (adev->active_input->enable_aec) {
2696 if (adev->active_input->enable_ns) {
2697 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS;
2698 } else {
2699 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC;
2700 }
vivek mehta733c1df2016-04-04 15:09:24 -07002701 platform_set_echo_reference(adev, true, out_device);
vivek mehtaf3440682016-05-11 14:24:37 -07002702 } else if (adev->active_input->enable_ns) {
2703 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
2704 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002705 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
vivek mehtaf3440682016-05-11 14:24:37 -07002706 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002707 }
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -07002708 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2709 snd_device = SND_DEVICE_IN_VOICE_REC_HEADSET_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07002710 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002711 snd_device = SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002712 }
rago90fb9612015-12-02 11:37:53 -08002713 } else if (source == AUDIO_SOURCE_UNPROCESSED) {
2714 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
vivek mehta4ed66e62016-04-15 23:33:34 -07002715 if (((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) ||
2716 (channel_mask == AUDIO_CHANNEL_IN_STEREO)) &&
2717 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2718 snd_device = SND_DEVICE_IN_UNPROCESSED_STEREO_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002719 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07002720 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
2721 snd_device = SND_DEVICE_IN_UNPROCESSED_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002722 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07002723 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2724 snd_device = SND_DEVICE_IN_UNPROCESSED_QUAD_MIC;
2725 } else {
2726 snd_device = SND_DEVICE_IN_UNPROCESSED_MIC;
2727 }
rago90fb9612015-12-02 11:37:53 -08002728 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2729 snd_device = SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07002730 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002731 snd_device = SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC;
rago90fb9612015-12-02 11:37:53 -08002732 }
Eric Laurent50a38ed2015-10-14 18:48:06 -07002733 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION ||
rago90fb9612015-12-02 11:37:53 -08002734 mode == AUDIO_MODE_IN_COMMUNICATION) {
David Lin40b07892017-08-07 15:02:48 -07002735 if (out_device & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
2736 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2737 (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE | AUDIO_DEVICE_OUT_USB_HEADSET) &&
2738 !audio_extn_usb_is_capture_supported())) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002739 in_device = AUDIO_DEVICE_IN_BACK_MIC;
David Lin40b07892017-08-07 15:02:48 -07002740 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002741 if (adev->active_input) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002742 if (adev->active_input->enable_aec &&
2743 adev->active_input->enable_ns) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002744 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002745 if (my_data->fluence_in_spkr_mode &&
2746 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002747 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002748 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002749 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002750 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002751 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002752 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002753 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002754 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002755 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002756 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002757 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002758 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002759 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2760 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Eric Laurent99dab492017-06-17 15:19:08 -07002761 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002762 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002763 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002764 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002765 } else if (adev->active_input->enable_aec) {
2766 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2767 if (my_data->fluence_in_spkr_mode &&
2768 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002769 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002770 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002771 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002772 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002773 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002774 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2775 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002776 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002777 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002778 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002779 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002780 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002781 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2782 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Eric Laurent99dab492017-06-17 15:19:08 -07002783 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002784 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
Eric Laurentcefbbac2014-09-04 13:54:10 -05002785 }
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08002786 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002787 } else if (adev->active_input->enable_ns) {
2788 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2789 if (my_data->fluence_in_spkr_mode &&
2790 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002791 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002792 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002793 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002794 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002795 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002796 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2797 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002798 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002799 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002800 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002801 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002802 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002803 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002804 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002805 }
2806 } else if (source == AUDIO_SOURCE_DEFAULT) {
2807 goto exit;
2808 }
2809
2810
2811 if (snd_device != SND_DEVICE_NONE) {
2812 goto exit;
2813 }
2814
2815 if (in_device != AUDIO_DEVICE_NONE &&
2816 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
2817 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
2818 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002819 if ((my_data->source_mic_type & SOURCE_QUAD_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002820 channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002821 snd_device = SND_DEVICE_IN_QUAD_MIC;
2822 } else if ((my_data->source_mic_type & SOURCE_THREE_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002823 channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002824 snd_device = SND_DEVICE_IN_THREE_MIC;
2825 } else if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2826 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002827 snd_device = SND_DEVICE_IN_HANDSET_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002828 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2829 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002830 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002831 } else {
2832 ALOGE("%s: something wrong (1): source type (%d) channel_count (%d) .."
2833 " channel mask (0x%x) no combination found .. setting to mono", __func__,
2834 my_data->source_mic_type, channel_count, channel_mask);
2835 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2836 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002837 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002838 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2839 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002840 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002841 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2842 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002843 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002844 } else {
2845 ALOGE("%s: something wrong (2): source type (%d) channel_count (%d) .."
2846 " no combination found .. setting to mono", __func__,
2847 my_data->source_mic_type, channel_count);
2848 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
2849 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002850 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2851 snd_device = SND_DEVICE_IN_HEADSET_MIC;
2852 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002853 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002854 if (adev->bluetooth_nrec)
2855 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2856 else
2857 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002858 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002859 if (adev->bluetooth_nrec)
2860 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2861 else
2862 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002863 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002864 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
2865 snd_device = SND_DEVICE_IN_HDMI_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07002866 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
David Linee3fe402017-03-13 10:00:42 -07002867 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002868 } else {
2869 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
2870 ALOGW("%s: Using default handset-mic", __func__);
2871 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2872 }
2873 } else {
2874 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
2875 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2876 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2877 snd_device = SND_DEVICE_IN_HEADSET_MIC;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002878 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002879 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002880 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002881 out_device & AUDIO_DEVICE_OUT_LINE) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002882 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2883 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002884 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002885 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2886 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002887 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002888 } else {
2889 ALOGE("%s: something wrong (3): source type (%d) channel_count (%d) .."
2890 " no combination found .. setting to mono", __func__,
2891 my_data->source_mic_type, channel_count);
2892 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
2893 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002894 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002895 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002896 if (adev->bluetooth_nrec)
2897 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2898 else
2899 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002900 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002901 if (adev->bluetooth_nrec)
2902 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2903 else
2904 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002905 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002906 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2907 snd_device = SND_DEVICE_IN_HDMI_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07002908 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
David Linee3fe402017-03-13 10:00:42 -07002909 if (audio_extn_usb_is_capture_supported())
2910 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
2911 else
2912 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002913 } else {
2914 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
2915 ALOGW("%s: Using default handset-mic", __func__);
2916 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2917 }
2918 }
2919exit:
2920 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
2921 return snd_device;
2922}
2923
2924int platform_set_hdmi_channels(void *platform, int channel_count)
2925{
2926 struct platform_data *my_data = (struct platform_data *)platform;
2927 struct audio_device *adev = my_data->adev;
2928 struct mixer_ctl *ctl;
2929 const char *channel_cnt_str = NULL;
2930 const char *mixer_ctl_name = "HDMI_RX Channels";
2931 switch (channel_count) {
2932 case 8:
2933 channel_cnt_str = "Eight"; break;
2934 case 7:
2935 channel_cnt_str = "Seven"; break;
2936 case 6:
2937 channel_cnt_str = "Six"; break;
2938 case 5:
2939 channel_cnt_str = "Five"; break;
2940 case 4:
2941 channel_cnt_str = "Four"; break;
2942 case 3:
2943 channel_cnt_str = "Three"; break;
2944 default:
2945 channel_cnt_str = "Two"; break;
2946 }
2947 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2948 if (!ctl) {
2949 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2950 __func__, mixer_ctl_name);
2951 return -EINVAL;
2952 }
2953 ALOGV("HDMI channel count: %s", channel_cnt_str);
2954 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
2955 return 0;
2956}
2957
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002958int platform_edid_get_max_channels(void *platform)
Eric Laurentb23d5282013-05-14 15:27:20 -07002959{
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002960 struct platform_data *my_data = (struct platform_data *)platform;
2961 struct audio_device *adev = my_data->adev;
Eric Laurentb23d5282013-05-14 15:27:20 -07002962 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
2963 char *sad = block;
2964 int num_audio_blocks;
2965 int channel_count;
2966 int max_channels = 0;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002967 int i, ret, count;
Eric Laurentb23d5282013-05-14 15:27:20 -07002968
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002969 struct mixer_ctl *ctl;
2970
2971 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
2972 if (!ctl) {
2973 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2974 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
Eric Laurentb23d5282013-05-14 15:27:20 -07002975 return 0;
2976 }
2977
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002978 mixer_ctl_update(ctl);
2979
2980 count = mixer_ctl_get_num_values(ctl);
Eric Laurentb23d5282013-05-14 15:27:20 -07002981
2982 /* Read SAD blocks, clamping the maximum size for safety */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002983 if (count > (int)sizeof(block))
2984 count = (int)sizeof(block);
Eric Laurentb23d5282013-05-14 15:27:20 -07002985
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002986 ret = mixer_ctl_get_array(ctl, block, count);
2987 if (ret != 0) {
2988 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
2989 return 0;
2990 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002991
2992 /* Calculate the number of SAD blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002993 num_audio_blocks = count / SAD_BLOCK_SIZE;
Eric Laurentb23d5282013-05-14 15:27:20 -07002994
2995 for (i = 0; i < num_audio_blocks; i++) {
2996 /* Only consider LPCM blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002997 if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
2998 sad += 3;
Eric Laurentb23d5282013-05-14 15:27:20 -07002999 continue;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003000 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003001
3002 channel_count = (sad[0] & 0x7) + 1;
3003 if (channel_count > max_channels)
3004 max_channels = channel_count;
3005
3006 /* Advance to next block */
3007 sad += 3;
3008 }
3009
3010 return max_channels;
3011}
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003012
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07003013int platform_set_incall_recording_session_id(void *platform,
3014 uint32_t session_id, int rec_mode)
3015{
3016 int ret = 0;
3017 struct platform_data *my_data = (struct platform_data *)platform;
3018 struct audio_device *adev = my_data->adev;
3019 struct mixer_ctl *ctl;
3020 const char *mixer_ctl_name = "Voc VSID";
3021 int num_ctl_values;
3022 int i;
3023
3024 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3025 if (!ctl) {
3026 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3027 __func__, mixer_ctl_name);
3028 ret = -EINVAL;
3029 } else {
3030 num_ctl_values = mixer_ctl_get_num_values(ctl);
3031 for (i = 0; i < num_ctl_values; i++) {
3032 if (mixer_ctl_set_value(ctl, i, session_id)) {
3033 ALOGV("Error: invalid session_id: %x", session_id);
3034 ret = -EINVAL;
3035 break;
3036 }
3037 }
3038 }
3039
3040 if (my_data->csd != NULL) {
3041 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
3042 if (ret < 0) {
3043 ALOGE("%s: csd_client_start_record failed, error %d",
3044 __func__, ret);
3045 }
3046 }
3047
3048 return ret;
3049}
3050
3051int platform_stop_incall_recording_usecase(void *platform)
3052{
3053 int ret = 0;
3054 struct platform_data *my_data = (struct platform_data *)platform;
3055
3056 if (my_data->csd != NULL) {
3057 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
3058 if (ret < 0) {
3059 ALOGE("%s: csd_client_stop_record failed, error %d",
3060 __func__, ret);
3061 }
3062 }
3063
3064 return ret;
3065}
3066
3067int platform_start_incall_music_usecase(void *platform)
3068{
3069 int ret = 0;
3070 struct platform_data *my_data = (struct platform_data *)platform;
3071
3072 if (my_data->csd != NULL) {
3073 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
3074 if (ret < 0) {
3075 ALOGE("%s: csd_client_start_playback failed, error %d",
3076 __func__, ret);
3077 }
3078 }
3079
3080 return ret;
3081}
3082
3083int platform_stop_incall_music_usecase(void *platform)
3084{
3085 int ret = 0;
3086 struct platform_data *my_data = (struct platform_data *)platform;
3087
3088 if (my_data->csd != NULL) {
3089 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
3090 if (ret < 0) {
3091 ALOGE("%s: csd_client_stop_playback failed, error %d",
3092 __func__, ret);
3093 }
3094 }
3095
3096 return ret;
3097}
3098
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003099int platform_set_parameters(void *platform, struct str_parms *parms)
3100{
3101 struct platform_data *my_data = (struct platform_data *)platform;
keunhui.park2f7306a2015-07-16 16:48:06 +09003102 char value[128];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003103 char *kv_pairs = str_parms_to_str(parms);
3104 int ret = 0, err;
3105
3106 if (kv_pairs == NULL) {
3107 ret = -EINVAL;
3108 ALOGE("%s: key-value pair is NULL",__func__);
3109 goto done;
3110 }
3111
3112 ALOGV("%s: enter: %s", __func__, kv_pairs);
3113
3114 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME,
3115 value, sizeof(value));
3116 if (err >= 0) {
3117 str_parms_del(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME);
3118 my_data->snd_card_name = strdup(value);
3119 ALOGV("%s: sound card name %s", __func__, my_data->snd_card_name);
3120 }
3121
keunhui.park2f7306a2015-07-16 16:48:06 +09003122 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO,
3123 value, sizeof(value));
3124 if (err >= 0) {
3125 struct operator_info *info;
3126 char *str = value;
3127 char *name;
3128
3129 str_parms_del(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO);
3130 info = (struct operator_info *)calloc(1, sizeof(struct operator_info));
3131 name = strtok(str, ";");
3132 info->name = strdup(name);
3133 info->mccmnc = strdup(str + strlen(name) + 1);
3134
3135 list_add_tail(&operator_info_list, &info->list);
Joe Onorato188b6222016-03-01 11:02:27 -08003136 ALOGV("%s: add operator[%s] mccmnc[%s]", __func__, info->name, info->mccmnc);
keunhui.park2f7306a2015-07-16 16:48:06 +09003137 }
Prashant Malanic92c5962015-08-11 15:10:18 -07003138
3139 memset(value, 0, sizeof(value));
Eric Laurentc6333382015-09-14 12:43:44 -07003140 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT,
Prashant Malanic92c5962015-08-11 15:10:18 -07003141 value, sizeof(value));
3142 if (err >= 0) {
Eric Laurentc6333382015-09-14 12:43:44 -07003143 str_parms_del(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT);
Prashant Malanic92c5962015-08-11 15:10:18 -07003144 my_data->max_mic_count = atoi(value);
3145 ALOGV("%s: max_mic_count %s/%d", __func__, value, my_data->max_mic_count);
Prashant Malanic92c5962015-08-11 15:10:18 -07003146 }
3147
vivek mehta90933872017-06-15 18:04:39 -07003148 // to-do: disable setting sidetone gain, will revist this later
3149 // audio_extn_usb_set_sidetone_gain(parms, value, len);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003150done:
3151 ALOGV("%s: exit with code(%d)", __func__, ret);
3152 if (kv_pairs != NULL)
3153 free(kv_pairs);
3154
3155 return ret;
3156}
3157
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003158/* Delay in Us */
3159int64_t platform_render_latency(audio_usecase_t usecase)
3160{
3161 switch (usecase) {
3162 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
3163 return DEEP_BUFFER_PLATFORM_DELAY;
3164 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
3165 return LOW_LATENCY_PLATFORM_DELAY;
Haynes Mathew George03c40102016-01-29 17:57:48 -08003166 case USECASE_AUDIO_PLAYBACK_ULL:
3167 return ULL_PLATFORM_DELAY;
Eric Laurent0e46adf2016-12-16 12:49:24 -08003168 case USECASE_AUDIO_PLAYBACK_MMAP:
3169 return MMAP_PLATFORM_DELAY;
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003170 default:
3171 return 0;
3172 }
3173}
Haynes Mathew George98c95622014-06-20 19:14:25 -07003174
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003175int platform_set_snd_device_backend(snd_device_t device, const char *backend_tag,
3176 const char * hw_interface)
Haynes Mathew George98c95622014-06-20 19:14:25 -07003177{
3178 int ret = 0;
3179
3180 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
3181 ALOGE("%s: Invalid snd_device = %d",
3182 __func__, device);
3183 ret = -EINVAL;
3184 goto done;
3185 }
3186
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003187 ALOGV("%s: backend_tag_table[%s]: old = %s new = %s", __func__,
3188 platform_get_snd_device_name(device),
3189 backend_tag_table[device] != NULL ? backend_tag_table[device]: "null", backend_tag);
3190 if (backend_tag_table[device]) {
3191 free(backend_tag_table[device]);
Haynes Mathew George98c95622014-06-20 19:14:25 -07003192 }
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003193 backend_tag_table[device] = strdup(backend_tag);
3194
3195 if (hw_interface != NULL) {
3196 if (hw_interface_table[device])
3197 free(hw_interface_table[device]);
3198 ALOGV("%s: hw_interface_table[%d] = %s", __func__, device, hw_interface);
3199 hw_interface_table[device] = strdup(hw_interface);
3200 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07003201done:
3202 return ret;
3203}
3204
3205int platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t pcm_id)
3206{
3207 int ret = 0;
3208 if ((usecase <= USECASE_INVALID) || (usecase >= AUDIO_USECASE_MAX)) {
3209 ALOGE("%s: invalid usecase case idx %d", __func__, usecase);
3210 ret = -EINVAL;
3211 goto done;
3212 }
3213
3214 if ((type != 0) && (type != 1)) {
3215 ALOGE("%s: invalid usecase type", __func__);
3216 ret = -EINVAL;
3217 }
vivek mehtaa68fea62017-06-08 19:04:02 -07003218 ALOGV("%s: pcm_device_table[%d %s][%d] = %d", __func__, usecase,
3219 use_case_table[usecase],
3220 type, pcm_id);
Haynes Mathew George98c95622014-06-20 19:14:25 -07003221 pcm_device_table[usecase][type] = pcm_id;
3222done:
3223 return ret;
3224}
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003225
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07003226#define DEFAULT_NOMINAL_SPEAKER_GAIN 20
3227int ramp_speaker_gain(struct audio_device *adev, bool ramp_up, int target_ramp_up_gain) {
3228 // backup_gain: gain to try to set in case of an error during ramp
3229 int start_gain, end_gain, step, backup_gain, i;
3230 bool error = false;
3231 const struct mixer_ctl *ctl;
3232 const char *mixer_ctl_name_gain_left = "Left Speaker Gain";
3233 const char *mixer_ctl_name_gain_right = "Right Speaker Gain";
3234 struct mixer_ctl *ctl_left = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_left);
3235 struct mixer_ctl *ctl_right = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_right);
3236 if (!ctl_left || !ctl_right) {
3237 ALOGE("%s: Could not get ctl for mixer cmd - %s or %s, not applying speaker gain ramp",
3238 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
3239 return -EINVAL;
3240 } else if ((mixer_ctl_get_num_values(ctl_left) != 1)
3241 || (mixer_ctl_get_num_values(ctl_right) != 1)) {
3242 ALOGE("%s: Unexpected num values for mixer cmd - %s or %s, not applying speaker gain ramp",
3243 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
3244 return -EINVAL;
3245 }
3246 if (ramp_up) {
3247 start_gain = 0;
3248 end_gain = target_ramp_up_gain > 0 ? target_ramp_up_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
3249 step = +1;
3250 backup_gain = end_gain;
3251 } else {
3252 // using same gain on left and right
3253 const int left_gain = mixer_ctl_get_value(ctl_left, 0);
3254 start_gain = left_gain > 0 ? left_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
3255 end_gain = 0;
3256 step = -1;
3257 backup_gain = start_gain;
3258 }
3259 for (i = start_gain ; i != (end_gain + step) ; i += step) {
3260 //ALOGV("setting speaker gain to %d", i);
3261 if (mixer_ctl_set_value(ctl_left, 0, i)) {
3262 ALOGE("%s: error setting %s to %d during gain ramp",
3263 __func__, mixer_ctl_name_gain_left, i);
3264 error = true;
3265 break;
3266 }
3267 if (mixer_ctl_set_value(ctl_right, 0, i)) {
3268 ALOGE("%s: error setting %s to %d during gain ramp",
3269 __func__, mixer_ctl_name_gain_right, i);
3270 error = true;
3271 break;
3272 }
3273 usleep(1000);
3274 }
3275 if (error) {
3276 // an error occured during the ramp, let's still try to go back to a safe volume
3277 if (mixer_ctl_set_value(ctl_left, 0, backup_gain)) {
3278 ALOGE("%s: error restoring left gain to %d", __func__, backup_gain);
3279 }
3280 if (mixer_ctl_set_value(ctl_right, 0, backup_gain)) {
3281 ALOGE("%s: error restoring right gain to %d", __func__, backup_gain);
3282 }
3283 }
3284 return start_gain;
3285}
3286
vivek mehtae59cfb22017-06-16 15:57:11 -07003287int platform_set_swap_mixer(struct audio_device *adev, bool swap_channels)
3288{
3289 const char *mixer_ctl_name = "Swap channel";
3290 struct mixer_ctl *ctl;
3291 const char *mixer_path;
3292 struct platform_data *my_data = (struct platform_data *)adev->platform;
3293
3294 // forced to set to swap, but device not rotated ... ignore set
3295 if (swap_channels && !my_data->speaker_lr_swap)
3296 return 0;
3297
3298 ALOGV("%s:", __func__);
3299
3300 if (swap_channels) {
3301 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER_REVERSE);
3302 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
3303 } else {
3304 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER);
3305 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
3306 }
3307
3308 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3309 if (!ctl) {
3310 ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name);
3311 return -EINVAL;
3312 }
3313
3314 if (mixer_ctl_set_value(ctl, 0, swap_channels) < 0) {
3315 ALOGE("%s: Could not set reverse cotrol %d",__func__, swap_channels);
3316 return -EINVAL;
3317 }
3318
3319 ALOGV("platfor_force_swap_channel :: Channel orientation ( %s ) ",
3320 swap_channels?"R --> L":"L --> R");
3321
3322 return 0;
3323}
3324
3325int platform_check_and_set_swap_lr_channels(struct audio_device *adev, bool swap_channels)
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003326{
3327 // only update if there is active pcm playback on speaker
3328 struct audio_usecase *usecase;
3329 struct listnode *node;
3330 struct platform_data *my_data = (struct platform_data *)adev->platform;
3331
vivek mehtae59cfb22017-06-16 15:57:11 -07003332 my_data->speaker_lr_swap = swap_channels;
Jean-Michel Trivif7148702016-09-16 18:23:05 -07003333
vivek mehtae59cfb22017-06-16 15:57:11 -07003334 return platform_set_swap_channels(adev, swap_channels);
3335}
Jean-Michel Trivif7148702016-09-16 18:23:05 -07003336
vivek mehtae59cfb22017-06-16 15:57:11 -07003337int platform_set_swap_channels(struct audio_device *adev, bool swap_channels)
3338{
3339 // only update if there is active pcm playback on speaker
3340 struct audio_usecase *usecase;
3341 struct listnode *node;
3342 struct platform_data *my_data = (struct platform_data *)adev->platform;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003343
vivek mehtae59cfb22017-06-16 15:57:11 -07003344 // do not swap channels in audio modes with concurrent capture and playback
3345 // as this may break the echo reference
3346 if ((adev->mode == AUDIO_MODE_IN_COMMUNICATION) || (adev->mode == AUDIO_MODE_IN_CALL)) {
3347 ALOGV("%s: will not swap due to audio mode %d", __func__, adev->mode);
3348 return 0;
3349 }
3350
3351 list_for_each(node, &adev->usecase_list) {
3352 usecase = node_to_item(node, struct audio_usecase, list);
3353 if (usecase->type == PCM_PLAYBACK &&
3354 usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) {
3355 /*
3356 * If acdb tuning is different for SPEAKER_REVERSE, it is must
3357 * to perform device switch to disable the current backend to
3358 * enable it with new acdb data.
3359 */
3360 if (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
3361 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]) {
3362 const int initial_skpr_gain = ramp_speaker_gain(adev, false /*ramp_up*/, -1);
3363 select_devices(adev, usecase->id);
3364 if (initial_skpr_gain != -EINVAL)
3365 ramp_speaker_gain(adev, true /*ramp_up*/, initial_skpr_gain);
3366
3367 } else {
3368 platform_set_swap_mixer(adev, swap_channels);
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003369 }
vivek mehtae59cfb22017-06-16 15:57:11 -07003370 break;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003371 }
3372 }
vivek mehtae59cfb22017-06-16 15:57:11 -07003373
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003374 return 0;
3375}
vivek mehtaa8d7c922016-05-25 14:40:44 -07003376
3377static struct amp_db_and_gain_table tbl_mapping[MAX_VOLUME_CAL_STEPS];
3378static int num_gain_tbl_entry = 0;
3379
3380bool platform_add_gain_level_mapping(struct amp_db_and_gain_table *tbl_entry) {
3381
3382 ALOGV("%s: enter .. add %f %f %d", __func__, tbl_entry->amp, tbl_entry->db, tbl_entry->level);
3383 if (num_gain_tbl_entry == -1) {
3384 ALOGE("%s: num entry beyond valid step levels or corrupted..rejecting custom mapping",
3385 __func__);
3386 return false;
3387 }
3388
3389 if (num_gain_tbl_entry >= MAX_VOLUME_CAL_STEPS) {
3390 ALOGE("%s: max entry reached max[%d] current index[%d] .. rejecting", __func__,
3391 MAX_VOLUME_CAL_STEPS, num_gain_tbl_entry);
3392 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
3393 return false;
3394 }
3395
3396 if (num_gain_tbl_entry > 0 && tbl_mapping[num_gain_tbl_entry - 1].amp >= tbl_entry->amp) {
3397 ALOGE("%s: value not in ascending order .. rejecting custom mapping", __func__);
3398 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
3399 return false;
3400 }
3401
3402 tbl_mapping[num_gain_tbl_entry] = *tbl_entry;
3403 ++num_gain_tbl_entry;
3404
3405 return true;
3406}
3407
3408int platform_get_gain_level_mapping(struct amp_db_and_gain_table *mapping_tbl,
3409 int table_size) {
3410 int itt = 0;
3411 ALOGV("platform_get_gain_level_mapping called ");
3412
3413 if (num_gain_tbl_entry <= 0 || num_gain_tbl_entry > MAX_VOLUME_CAL_STEPS) {
3414 ALOGD("%s: empty or currupted gain_mapping_table", __func__);
3415 return 0;
3416 }
3417
3418 for (; itt < num_gain_tbl_entry && itt <= table_size; itt++) {
3419 mapping_tbl[itt] = tbl_mapping[itt];
3420 ALOGV("%s: added amp[%f] db[%f] level[%d]", __func__,
3421 mapping_tbl[itt].amp, mapping_tbl[itt].db, mapping_tbl[itt].level);
3422 }
3423
3424 return num_gain_tbl_entry;
3425}
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07003426
3427int platform_snd_card_update(void *platform, card_status_t status)
3428{
3429 struct platform_data *my_data = (struct platform_data *)platform;
3430 struct audio_device *adev = my_data->adev;
3431
3432 if (status == CARD_STATUS_ONLINE) {
3433 if (my_data->acdb_send_custom_top)
3434 my_data->acdb_send_custom_top();
3435 }
3436 return 0;
3437}
David Linee3fe402017-03-13 10:00:42 -07003438
3439/*
3440 * configures afe with bit width and Sample Rate
3441 */
3442static int platform_set_backend_cfg(const struct audio_device* adev,
3443 snd_device_t snd_device,
3444 const struct audio_backend_cfg *backend_cfg)
3445{
3446
3447 int ret = 0;
3448 const int backend_idx = platform_get_backend_index(snd_device);
3449 struct platform_data *my_data = (struct platform_data *)adev->platform;
3450 const unsigned int bit_width = backend_cfg->bit_width;
3451 const unsigned int sample_rate = backend_cfg->sample_rate;
3452 const unsigned int channels = backend_cfg->channels;
3453 const audio_format_t format = backend_cfg->format;
3454 const bool passthrough_enabled = backend_cfg->passthrough_enabled;
3455
3456
3457 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
3458 ", backend_idx %d device (%s)", __func__, bit_width,
3459 sample_rate, channels, backend_idx,
3460 platform_get_snd_device_name(snd_device));
3461
3462 if ((my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl) &&
3463 (bit_width != my_data->current_backend_cfg[backend_idx].bit_width)) {
3464
3465 struct mixer_ctl *ctl = NULL;
3466 ctl = mixer_get_ctl_by_name(adev->mixer,
3467 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
3468 if (!ctl) {
3469 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3470 __func__,
3471 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
3472 return -EINVAL;
3473 }
3474
3475 if (bit_width == 24) {
3476 if (format == AUDIO_FORMAT_PCM_24_BIT_PACKED)
3477 ret = mixer_ctl_set_enum_by_string(ctl, "S24_3LE");
3478 else
3479 ret = mixer_ctl_set_enum_by_string(ctl, "S24_LE");
3480 } else if (bit_width == 32) {
3481 ret = mixer_ctl_set_enum_by_string(ctl, "S32_LE");
3482 } else {
3483 ret = mixer_ctl_set_enum_by_string(ctl, "S16_LE");
3484 }
3485 if ( ret < 0) {
3486 ALOGE("%s:becf: afe: fail for %s mixer set to %d bit for %x format", __func__,
3487 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
3488 } else {
3489 my_data->current_backend_cfg[backend_idx].bit_width = bit_width;
3490 ALOGD("%s:becf: afe: %s mixer set to %d bit for %x format", __func__,
3491 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
3492 }
3493 /* set the ret as 0 and not pass back to upper layer */
3494 ret = 0;
3495 }
3496
3497 if (passthrough_enabled || ((my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl) &&
3498 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate))) {
3499 char *rate_str = NULL;
3500 struct mixer_ctl *ctl = NULL;
3501
3502 switch (sample_rate) {
3503 case 32000:
3504 if (passthrough_enabled) {
3505 rate_str = "KHZ_32";
3506 break;
3507 }
3508 case 8000:
3509 case 11025:
3510 case 16000:
3511 case 22050:
3512 case 48000:
3513 rate_str = "KHZ_48";
3514 break;
3515 case 44100:
3516 rate_str = "KHZ_44P1";
3517 break;
3518 case 64000:
3519 case 96000:
3520 rate_str = "KHZ_96";
3521 break;
3522 case 88200:
3523 rate_str = "KHZ_88P2";
3524 break;
3525 case 176400:
3526 rate_str = "KHZ_176P4";
3527 break;
3528 case 192000:
3529 rate_str = "KHZ_192";
3530 break;
3531 case 352800:
3532 rate_str = "KHZ_352P8";
3533 break;
3534 case 384000:
3535 rate_str = "KHZ_384";
3536 break;
3537 case 144000:
3538 if (passthrough_enabled) {
3539 rate_str = "KHZ_144";
3540 break;
3541 }
3542 default:
3543 rate_str = "KHZ_48";
3544 break;
3545 }
3546
3547 ctl = mixer_get_ctl_by_name(adev->mixer,
3548 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
3549 if(!ctl) {
3550 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3551 __func__,
3552 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
3553 return -EINVAL;
3554 }
3555
3556 ALOGD("%s:becf: afe: %s set to %s", __func__,
3557 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl, rate_str);
3558 mixer_ctl_set_enum_by_string(ctl, rate_str);
3559 my_data->current_backend_cfg[backend_idx].sample_rate = sample_rate;
3560 }
3561 if ((my_data->current_backend_cfg[backend_idx].channels_mixer_ctl) &&
3562 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
3563 struct mixer_ctl *ctl = NULL;
3564 char *channel_cnt_str = NULL;
3565
3566 switch (channels) {
3567 case 8:
3568 channel_cnt_str = "Eight"; break;
3569 case 7:
3570 channel_cnt_str = "Seven"; break;
3571 case 6:
3572 channel_cnt_str = "Six"; break;
3573 case 5:
3574 channel_cnt_str = "Five"; break;
3575 case 4:
3576 channel_cnt_str = "Four"; break;
3577 case 3:
3578 channel_cnt_str = "Three"; break;
3579 case 1:
3580 channel_cnt_str = "One"; break;
3581 case 2:
3582 default:
3583 channel_cnt_str = "Two"; break;
3584 }
3585
3586 ctl = mixer_get_ctl_by_name(adev->mixer,
3587 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
3588 if (!ctl) {
3589 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3590 __func__,
3591 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
3592 return -EINVAL;
3593 }
3594 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
3595 my_data->current_backend_cfg[backend_idx].channels = channels;
3596
3597 // skip EDID configuration for HDMI backend
3598
3599 ALOGD("%s:becf: afe: %s set to %s", __func__,
3600 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl,
3601 channel_cnt_str);
3602 }
3603
3604 // skip set ext_display format mixer control
3605 return ret;
3606}
3607
3608static int platform_get_snd_device_bit_width(snd_device_t snd_device)
3609{
3610 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
3611 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
3612 return CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3613 }
3614
3615 return backend_bit_width_table[snd_device];
3616}
3617
3618/*
3619 * return backend_idx on which voice call is active
3620 */
3621static int platform_get_voice_call_backend(struct audio_device* adev)
3622{
3623 struct audio_usecase *uc = NULL;
3624 struct listnode *node;
3625 snd_device_t out_snd_device = SND_DEVICE_NONE;
3626
3627 int backend_idx = -1;
3628
3629 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
3630 list_for_each(node, &adev->usecase_list) {
3631 uc = node_to_item(node, struct audio_usecase, list);
3632 if (uc && uc->type == VOICE_CALL && uc->stream.out) {
3633 out_snd_device = platform_get_output_snd_device(adev->platform,
3634 uc->stream.out->devices);
3635 backend_idx = platform_get_backend_index(out_snd_device);
3636 break;
3637 }
3638 }
3639 }
3640 return backend_idx;
3641}
3642
3643/*
3644 * goes through all the current usecases and picks the highest
3645 * bitwidth & samplerate
3646 */
3647static bool platform_check_capture_backend_cfg(struct audio_device* adev,
3648 int backend_idx,
3649 struct audio_backend_cfg *backend_cfg)
3650{
3651 bool backend_change = false;
3652 unsigned int bit_width;
3653 unsigned int sample_rate;
3654 unsigned int channels;
3655 struct platform_data *my_data = (struct platform_data *)adev->platform;
3656
3657 bit_width = backend_cfg->bit_width;
3658 sample_rate = backend_cfg->sample_rate;
3659 channels = backend_cfg->channels;
3660
3661 ALOGV("%s:txbecf: afe: Codec selected backend: %d current bit width: %d and "
3662 "sample rate: %d, channels %d",__func__,backend_idx, bit_width,
3663 sample_rate, channels);
3664
3665 // For voice calls use default configuration i.e. 16b/48K, only applicable to
3666 // default backend
3667 // force routing is not required here, caller will do it anyway
3668 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
3669 ALOGW("%s:txbecf: afe: Use default bw and sr for voice/voip calls and "
3670 "for unprocessed/camera source", __func__);
3671 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3672 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3673 }
3674
3675 if (backend_idx == USB_AUDIO_TX_BACKEND) {
3676 audio_extn_usb_is_config_supported(&bit_width, &sample_rate, &channels, false);
3677 ALOGV("%s:txbecf: afe: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
3678 __func__, bit_width, sample_rate, channels);
3679 }
3680
3681 ALOGV("%s:txbecf: afe: Codec selected backend: %d updated bit width: %d and "
3682 "sample rate: %d", __func__, backend_idx, bit_width, sample_rate);
3683
3684 // Force routing if the expected bitwdith or samplerate
3685 // is not same as current backend comfiguration
3686 if ((bit_width != my_data->current_backend_cfg[backend_idx].bit_width) ||
3687 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate) ||
3688 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
3689 backend_cfg->bit_width = bit_width;
3690 backend_cfg->sample_rate= sample_rate;
3691 backend_cfg->channels = channels;
3692 backend_change = true;
3693 ALOGI("%s:txbecf: afe: Codec backend needs to be updated. new bit width: %d "
3694 "new sample rate: %d new channel: %d",
3695 __func__, backend_cfg->bit_width,
3696 backend_cfg->sample_rate, backend_cfg->channels);
3697 }
3698
3699 return backend_change;
3700}
3701
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003702static void pick_playback_cfg_for_uc(struct audio_device *adev,
3703 struct audio_usecase *usecase,
3704 snd_device_t snd_device,
3705 unsigned int *bit_width,
3706 unsigned int *sample_rate,
3707 unsigned int *channels)
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003708{
3709 int i =0;
3710 struct listnode *node;
3711 list_for_each(node, &adev->usecase_list) {
3712 struct audio_usecase *uc;
3713 uc = node_to_item(node, struct audio_usecase, list);
3714 struct stream_out *out = (struct stream_out*) uc->stream.out;
3715 if (uc->type == PCM_PLAYBACK && out && usecase != uc) {
3716 unsigned int out_channels = audio_channel_count_from_out_mask(out->channel_mask);
3717 ALOGV("%s:napb: (%d) - (%s)id (%d) sr %d bw "
3718 "(%d) ch (%d) device %s", __func__, i++, use_case_table[uc->id],
3719 uc->id, out->sample_rate,
3720 pcm_format_to_bits(out->config.format), out_channels,
3721 platform_get_snd_device_name(uc->out_snd_device));
3722
3723 if (platform_check_backends_match(snd_device, uc->out_snd_device)) {
3724 if (*bit_width < pcm_format_to_bits(out->config.format))
3725 *bit_width = pcm_format_to_bits(out->config.format);
3726 if (*sample_rate < out->sample_rate)
3727 *sample_rate = out->sample_rate;
3728 if (out->sample_rate < OUTPUT_SAMPLING_RATE_44100)
3729 *sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3730 if (*channels < out_channels)
3731 *channels = out_channels;
3732 }
3733 }
3734 }
3735 return;
3736}
3737
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003738static void headset_is_config_supported(unsigned int *bit_width,
3739 unsigned int *sample_rate,
3740 unsigned int *channels) {
3741 switch (*bit_width) {
3742 case 16:
3743 case 24:
3744 break;
3745 default:
3746 *bit_width = 16;
3747 break;
3748 }
3749
3750 if (*sample_rate > 192000) {
3751 *sample_rate = 192000;
3752 }
3753
3754 if (*channels > 2) {
3755 *channels = 2;
3756 }
3757}
3758
David Linee3fe402017-03-13 10:00:42 -07003759static bool platform_check_playback_backend_cfg(struct audio_device* adev,
3760 struct audio_usecase* usecase,
3761 snd_device_t snd_device,
3762 struct audio_backend_cfg *backend_cfg)
3763{
3764 bool backend_change = false;
David Linee3fe402017-03-13 10:00:42 -07003765 unsigned int bit_width;
3766 unsigned int sample_rate;
3767 unsigned int channels;
David Linee3fe402017-03-13 10:00:42 -07003768 int backend_idx = DEFAULT_CODEC_BACKEND;
3769 struct platform_data *my_data = (struct platform_data *)adev->platform;
David Linee3fe402017-03-13 10:00:42 -07003770
3771 if (snd_device == SND_DEVICE_OUT_BT_SCO ||
3772 snd_device == SND_DEVICE_OUT_BT_SCO_WB) {
3773 backend_change = false;
3774 return backend_change;
3775 }
3776
3777 backend_idx = platform_get_backend_index(snd_device);
3778 bit_width = backend_cfg->bit_width;
3779 sample_rate = backend_cfg->sample_rate;
3780 channels = backend_cfg->channels;
3781
3782 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
3783 ", backend_idx %d usecase = %d device (%s)", __func__, bit_width,
3784 sample_rate, channels, backend_idx, usecase->id,
3785 platform_get_snd_device_name(snd_device));
3786
3787 if (backend_idx == platform_get_voice_call_backend(adev)) {
3788 ALOGW("%s:becf: afe:Use default bw and sr for voice/voip calls ",
3789 __func__);
3790 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3791 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3792 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
3793 } else {
3794 /*
3795 * The backend should be configured at highest bit width and/or
3796 * sample rate amongst all playback usecases.
3797 * If the selected sample rate and/or bit width differ with
3798 * current backend sample rate and/or bit width, then, we set the
3799 * backend re-configuration flag.
3800 *
3801 * Exception: 16 bit playbacks is allowed through 16 bit/48/44.1 khz backend only
3802 */
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003803 pick_playback_cfg_for_uc(adev, usecase, snd_device,
3804 &bit_width,
3805 &sample_rate,
3806 &channels);
David Linee3fe402017-03-13 10:00:42 -07003807 }
3808
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003809 switch (backend_idx) {
3810 case USB_AUDIO_RX_BACKEND:
3811 audio_extn_usb_is_config_supported(&bit_width,
3812 &sample_rate, &channels, true);
3813 ALOGV("%s: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
3814 __func__, bit_width, sample_rate, channels);
3815 break;
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003816 case HEADPHONE_BACKEND:
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003817 headset_is_config_supported(&bit_width, &sample_rate, &channels);
3818 break;
3819 case DEFAULT_CODEC_BACKEND:
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003820 default:
3821 bit_width = platform_get_snd_device_bit_width(snd_device);
3822 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3823 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
3824 break;
David Linee3fe402017-03-13 10:00:42 -07003825 }
3826
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003827 ALOGV("%s:becf: afe: Codec selected backend: %d updated bit width: %d and"
3828 "sample rate: %d",
David Linee3fe402017-03-13 10:00:42 -07003829 __func__, backend_idx , bit_width, sample_rate);
3830
3831 // Force routing if the expected bitwdith or samplerate
3832 // is not same as current backend comfiguration
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003833 if (bit_width != my_data->current_backend_cfg[backend_idx].bit_width ||
3834 sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate ||
3835 channels != my_data->current_backend_cfg[backend_idx].channels) {
David Linee3fe402017-03-13 10:00:42 -07003836 backend_cfg->bit_width = bit_width;
3837 backend_cfg->sample_rate = sample_rate;
3838 backend_cfg->channels = channels;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003839 backend_cfg->passthrough_enabled = false;
David Linee3fe402017-03-13 10:00:42 -07003840 backend_change = true;
3841 ALOGV("%s:becf: afe: Codec backend needs to be updated. new bit width: %d"
3842 "new sample rate: %d new channels: %d",
3843 __func__, backend_cfg->bit_width, backend_cfg->sample_rate, backend_cfg->channels);
3844 }
3845
3846 return backend_change;
3847}
3848
3849bool platform_check_and_set_playback_backend_cfg(struct audio_device* adev,
3850 struct audio_usecase *usecase, snd_device_t snd_device)
3851{
3852 int backend_idx = DEFAULT_CODEC_BACKEND;
3853 int new_snd_devices[SND_DEVICE_OUT_END];
3854 int i, num_devices = 1;
3855 bool ret = false;
3856 struct platform_data *my_data = (struct platform_data *)adev->platform;
3857 struct audio_backend_cfg backend_cfg;
3858
3859 backend_idx = platform_get_backend_index(snd_device);
3860
3861 backend_cfg.bit_width = pcm_format_to_bits(usecase->stream.out->config.format);
3862 backend_cfg.sample_rate = usecase->stream.out->sample_rate;
3863 backend_cfg.format = usecase->stream.out->format;
3864 backend_cfg.channels = audio_channel_count_from_out_mask(usecase->stream.out->channel_mask);
3865 /*this is populated by check_codec_backend_cfg hence set default value to false*/
3866 backend_cfg.passthrough_enabled = false;
3867
3868 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
3869 ", backend_idx %d usecase = %d device (%s)", __func__, backend_cfg.bit_width,
3870 backend_cfg.sample_rate, backend_cfg.channels, backend_idx, usecase->id,
3871 platform_get_snd_device_name(snd_device));
3872
3873 if (platform_can_split_snd_device(snd_device, &num_devices, new_snd_devices) < 0)
3874 new_snd_devices[0] = snd_device;
3875
3876 for (i = 0; i < num_devices; i++) {
3877 ALOGV("%s: new_snd_devices[%d] is %d", __func__, i, new_snd_devices[i]);
3878 if ((platform_check_playback_backend_cfg(adev, usecase, new_snd_devices[i],
3879 &backend_cfg))) {
3880 platform_set_backend_cfg(adev, new_snd_devices[i],
3881 &backend_cfg);
3882 ret = true;
3883 }
3884 }
3885 return ret;
3886}
3887
3888bool platform_check_and_set_capture_backend_cfg(struct audio_device* adev,
3889 struct audio_usecase *usecase, snd_device_t snd_device)
3890{
3891 int backend_idx = platform_get_backend_index(snd_device);
3892 int ret = 0;
3893 struct audio_backend_cfg backend_cfg;
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003894 memset(&backend_cfg, 0, sizeof(struct audio_backend_cfg));
David Linee3fe402017-03-13 10:00:42 -07003895
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003896 if (usecase->type == PCM_CAPTURE) {
3897 backend_cfg.format = usecase->stream.in->format;
David Linee3fe402017-03-13 10:00:42 -07003898 backend_cfg.channels = audio_channel_count_from_in_mask(usecase->stream.in->channel_mask);
3899 } else {
3900 backend_cfg.bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3901 backend_cfg.sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3902 backend_cfg.format = AUDIO_FORMAT_PCM_16_BIT;
3903 backend_cfg.channels = 1;
3904 }
3905
3906 ALOGV("%s:txbecf: afe: bitwidth %d, samplerate %d, channel %d"
3907 ", backend_idx %d usecase = %d device (%s)", __func__,
3908 backend_cfg.bit_width,
3909 backend_cfg.sample_rate,
3910 backend_cfg.channels,
3911 backend_idx, usecase->id,
3912 platform_get_snd_device_name(snd_device));
3913
3914 if (platform_check_capture_backend_cfg(adev, backend_idx, &backend_cfg)) {
3915 ret = platform_set_backend_cfg(adev, snd_device,
3916 &backend_cfg);
3917 if(!ret)
3918 return true;
3919 }
3920
3921 return false;
3922}
3923
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003924static int max_be_dai_names = 0;
3925static const struct be_dai_name_struct *be_dai_name_table;
3926
3927/*
3928 * Retrieves the be_dai_name_table from kernel to enable a mapping
3929 * between sound device hw interfaces and backend IDs. This allows HAL to
3930 * specify the backend a specific calibration is needed for.
3931 */
3932static int init_be_dai_name_table(struct audio_device *adev)
3933{
3934 const char *mixer_ctl_name = "Backend DAI Name Table";
3935 struct mixer_ctl *ctl;
3936 int i, j, ret, size;
3937 bool valid_hw_interface;
3938
3939 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3940 if (!ctl) {
3941 ALOGE("%s: Could not get ctl for mixer name %s\n",
3942 __func__, mixer_ctl_name);
3943 ret = -EINVAL;
3944 goto done;
3945 }
3946
3947 mixer_ctl_update(ctl);
3948
3949 size = mixer_ctl_get_num_values(ctl);
3950 if (size <= 0){
3951 ALOGE("%s: Failed to get %s size %d\n",
3952 __func__, mixer_ctl_name, size);
3953 ret = -EFAULT;
3954 goto done;
3955 }
3956
vivek mehtaa68fea62017-06-08 19:04:02 -07003957 be_dai_name_table =
3958 (const struct be_dai_name_struct *)calloc(1, size);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003959 if (be_dai_name_table == NULL) {
3960 ALOGE("%s: Failed to allocate memory for %s\n",
3961 __func__, mixer_ctl_name);
3962 ret = -ENOMEM;
3963 goto freeMem;
3964 }
3965
3966 ret = mixer_ctl_get_array(ctl, (void *)be_dai_name_table, size);
3967 if (ret) {
3968 ALOGE("%s: Failed to get %s, ret %d\n",
3969 __func__, mixer_ctl_name, ret);
3970 ret = -EFAULT;
3971 goto freeMem;
3972 }
3973
3974 if (be_dai_name_table != NULL) {
3975 max_be_dai_names = size / sizeof(struct be_dai_name_struct);
3976 ALOGV("%s: Successfully got %s, number of be dais is %d\n",
3977 __func__, mixer_ctl_name, max_be_dai_names);
3978 ret = 0;
3979 } else {
3980 ALOGE("%s: Failed to get %s\n", __func__, mixer_ctl_name);
3981 ret = -EFAULT;
3982 goto freeMem;
3983 }
3984
3985 /*
3986 * Validate all sound devices have a valid backend set to catch
3987 * errors for uncommon sound devices
3988 */
3989 for (i = 0; i < SND_DEVICE_MAX; i++) {
3990 valid_hw_interface = false;
3991
3992 if (hw_interface_table[i] == NULL) {
3993 ALOGW("%s: sound device %s has no hw interface set\n",
3994 __func__, platform_get_snd_device_name(i));
3995 continue;
3996 }
3997
3998 for (j = 0; j < max_be_dai_names; j++) {
3999 if (strcmp(hw_interface_table[i], be_dai_name_table[j].be_name)
4000 == 0) {
4001 valid_hw_interface = true;
4002 break;
4003 }
4004 }
4005 if (!valid_hw_interface)
4006 ALOGD("%s: sound device %s does not have a valid hw interface set "
4007 "(disregard for combo devices) %s\n",
4008 __func__, platform_get_snd_device_name(i),
4009 hw_interface_table[i]);
4010 }
4011
4012 goto done;
4013
4014freeMem:
4015 if (be_dai_name_table) {
4016 free((void *)be_dai_name_table);
4017 be_dai_name_table = NULL;
4018 }
4019
4020done:
4021 return ret;
4022}
4023
4024int platform_get_snd_device_backend_index(snd_device_t device)
4025{
4026 int i, be_dai_id;
4027 const char * hw_interface_name = NULL;
4028
4029 ALOGV("%s: enter with device %d\n", __func__, device);
4030
vivek mehtaa68fea62017-06-08 19:04:02 -07004031 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004032 ALOGE("%s: Invalid snd_device = %d",
4033 __func__, device);
4034 be_dai_id = -EINVAL;
4035 goto done;
4036 }
4037
4038 /* Get string value of necessary backend for device */
4039 hw_interface_name = hw_interface_table[device];
4040 if (hw_interface_name == NULL) {
4041 ALOGE("%s: no hw_interface set for device %d\n", __func__, device);
4042 be_dai_id = -EINVAL;
4043 goto done;
4044 }
4045
4046 /* Check if be dai name table was retrieved successfully */
4047 if (be_dai_name_table == NULL) {
4048 ALOGE("%s: BE DAI Name Table is not present\n", __func__);
4049 be_dai_id = -EFAULT;
4050 goto done;
4051 }
4052
4053 /* Get backend ID for device specified */
4054 for (i = 0; i < max_be_dai_names; i++) {
4055 if (strcmp(hw_interface_name, be_dai_name_table[i].be_name) == 0) {
4056 be_dai_id = be_dai_name_table[i].be_id;
4057 goto done;
4058 }
4059 }
4060 ALOGE("%s: no interface matching name %s\n", __func__, hw_interface_name);
4061 be_dai_id = -EINVAL;
4062 goto done;
4063
4064done:
4065 return be_dai_id;
4066}
4067
4068void platform_check_and_update_copp_sample_rate(void* platform, snd_device_t snd_device,
4069 unsigned int stream_sr, int* sample_rate)
4070{
4071 struct platform_data* my_data = (struct platform_data *)platform;
4072 int backend_idx = platform_get_backend_index(snd_device);
4073 int device_sr = my_data->current_backend_cfg[backend_idx].sample_rate;
4074 /*
4075 *Check if device SR is multiple of 8K or 11.025 Khz
4076 *check if the stream SR is multiple of same base, if yes
4077 *then have copp SR equal to stream SR, this ensures that
4078 *post processing happens at stream SR, else have
4079 *copp SR equal to device SR.
4080 */
4081 if (!(((sample_rate_multiple(device_sr, SAMPLE_RATE_8000)) &&
4082 (sample_rate_multiple(stream_sr, SAMPLE_RATE_8000))) ||
4083 ((sample_rate_multiple(device_sr, SAMPLE_RATE_11025)) &&
4084 (sample_rate_multiple(stream_sr, SAMPLE_RATE_11025))))) {
4085 *sample_rate = device_sr;
4086 } else
4087 *sample_rate = stream_sr;
4088
4089 ALOGI("sn_device %d device sr %d stream sr %d copp sr %d", snd_device, device_sr, stream_sr
4090 , *sample_rate);
4091
4092}
4093
4094// called from info parser
vivek mehtaa68fea62017-06-08 19:04:02 -07004095void platform_add_app_type(const char *uc_type,
4096 const char *mode,
4097 int bw,
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004098 int app_type, int max_rate) {
4099 struct app_type_entry *ap =
4100 (struct app_type_entry *)calloc(1, sizeof(struct app_type_entry));
4101
4102 if (!ap) {
4103 ALOGE("%s failed to allocate mem for app type", __func__);
4104 return;
4105 }
4106
4107 ap->uc_type = -1;
4108 for (int i=0; i<USECASE_TYPE_MAX; i++) {
4109 if (!strcmp(uc_type, usecase_type_index[i].name)) {
4110 ap->uc_type = usecase_type_index[i].index;
4111 break;
4112 }
4113 }
4114
4115 if (ap->uc_type == -1) {
4116 free(ap);
4117 return;
4118 }
4119
vivek mehtaa68fea62017-06-08 19:04:02 -07004120 ALOGI("%s uc %s mode %s bw %d app_type %d max_rate %d",
4121 __func__, uc_type, mode, bw, app_type, max_rate);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004122 ap->bit_width = bw;
4123 ap->app_type = app_type;
4124 ap->max_rate = max_rate;
vivek mehtaa68fea62017-06-08 19:04:02 -07004125 ap->mode = strdup(mode);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004126 list_add_tail(&app_type_entry_list, &ap->node);
4127}
4128
4129
4130int platform_get_default_app_type_v2(void *platform __unused,
4131 usecase_type_t type,
4132 int *app_type )
4133{
4134 if (type == PCM_PLAYBACK)
4135 *app_type = DEFAULT_APP_TYPE_RX_PATH;
4136 else
4137 *app_type = DEFAULT_APP_TYPE_TX_PATH;
4138 return 0;
4139}
4140
vivek mehtaa68fea62017-06-08 19:04:02 -07004141int platform_get_app_type_v2(void *platform,
4142 usecase_type_t uc_type,
4143 const char *mode,
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004144 int bw, int sr __unused,
4145 int *app_type)
4146{
4147 struct listnode *node;
4148 struct app_type_entry *entry;
4149 *app_type = -1;
vivek mehtaa68fea62017-06-08 19:04:02 -07004150
4151 ALOGV("%s find match for uc %d mode %s bw %d rate %d",
4152 __func__, uc_type, mode, bw, sr);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004153 list_for_each(node, &app_type_entry_list) {
4154 entry = node_to_item(node, struct app_type_entry, node);
vivek mehtaa68fea62017-06-08 19:04:02 -07004155 ALOGV("%s uc %d mode %s bw %d app_type %d max_rate %d",
4156 __func__, entry->uc_type, entry->mode, entry->bit_width,
4157 entry->app_type, entry->max_rate);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004158 if (entry->bit_width == bw &&
vivek mehtaa68fea62017-06-08 19:04:02 -07004159 entry->uc_type == uc_type &&
4160 sr <= entry->max_rate &&
4161 entry->mode && !strcmp(mode, entry->mode)) {
4162 ALOGV("%s found match %d", __func__, entry->app_type);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004163 *app_type = entry->app_type;
4164 break;
4165 }
4166 }
4167
4168 if (*app_type == -1) {
vivek mehtaa68fea62017-06-08 19:04:02 -07004169 ALOGV("%s no match found, return default", __func__);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004170 return platform_get_default_app_type_v2(platform, uc_type, app_type);
4171 }
4172 return 0;
4173}
vivek mehta90933872017-06-15 18:04:39 -07004174
4175int platform_set_sidetone(struct audio_device *adev,
4176 snd_device_t out_snd_device,
4177 bool enable, char *str)
4178{
4179 int ret;
4180 if (out_snd_device == SND_DEVICE_OUT_USB_HEADSET ||
4181 out_snd_device == SND_DEVICE_OUT_VOICE_USB_HEADSET) {
4182 ret = audio_extn_usb_enable_sidetone(out_snd_device, enable);
4183 if (ret)
4184 ALOGI("%s: usb device %d does not support device sidetone\n",
4185 __func__, out_snd_device);
4186 } else {
4187 ALOGV("%s: sidetone out device(%d) mixer cmd = %s\n",
4188 __func__, out_snd_device, str);
4189 if (enable)
4190 audio_route_apply_and_update_path(adev->audio_route, str);
4191 else
4192 audio_route_reset_and_update_path(adev->audio_route, str);
4193 }
4194 return 0;
4195}
Haynes Mathew George96483a22017-03-28 14:52:47 -07004196
4197int platform_get_mmap_data_fd(void *platform __unused, int fe_dev __unused, int dir __unused,
4198 int *fd __unused, uint32_t *size __unused)
4199{
Alexey Polyudove920d4b2017-09-15 17:09:07 -07004200#if defined (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845)
Haynes Mathew George96483a22017-03-28 14:52:47 -07004201 struct platform_data *my_data = (struct platform_data *)platform;
4202 struct audio_device *adev = my_data->adev;
4203 int hw_fd = -1;
4204 char dev_name[128];
4205 struct snd_pcm_mmap_fd mmap_fd;
4206 memset(&mmap_fd, 0, sizeof(mmap_fd));
4207 mmap_fd.dir = dir;
4208 snprintf(dev_name, sizeof(dev_name), "/dev/snd/hwC%uD%u",
4209 adev->snd_card, HWDEP_FE_BASE+fe_dev);
4210 hw_fd = open(dev_name, O_RDONLY);
4211 if (hw_fd < 0) {
4212 ALOGE("fe hw dep node open %d/%d failed", adev->snd_card, fe_dev);
4213 return -1;
4214 }
4215 if (ioctl(hw_fd, SNDRV_PCM_IOCTL_MMAP_DATA_FD, &mmap_fd) < 0) {
4216 ALOGE("fe hw dep node ioctl failed");
4217 close(hw_fd);
4218 return -1;
4219 }
4220 *fd = mmap_fd.fd;
4221 *size = mmap_fd.size;
4222 close(hw_fd); // mmap_fd should still be valid
4223 return 0;
4224#else
4225 return -1;
4226#endif
4227}
Mikhail Naganov4ee6e3e2018-03-21 16:28:35 +00004228
4229bool platform_sound_trigger_usecase_needs_event(audio_usecase_t uc_id)
4230{
4231 bool needs_event = false;
4232
4233 switch (uc_id) {
4234 /* concurrent capture usecases which needs event */
4235 case USECASE_AUDIO_RECORD:
4236 case USECASE_AUDIO_RECORD_LOW_LATENCY:
4237 case USECASE_AUDIO_RECORD_MMAP:
4238 case USECASE_AUDIO_RECORD_HIFI:
4239 case USECASE_AUDIO_RECORD_VOIP:
4240 case USECASE_VOICEMMODE1_CALL:
4241 case USECASE_VOICEMMODE2_CALL:
4242 /* concurrent playback usecases that needs event */
4243 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
4244 case USECASE_AUDIO_PLAYBACK_OFFLOAD:
4245 needs_event = true;
4246 break;
4247 default:
4248 ALOGV("%s:usecase_id[%d] no need to raise event.", __func__, uc_id);
4249 }
4250 return needs_event;
4251}
4252
4253bool platform_snd_device_has_speaker(snd_device_t dev) {
4254 int num_devs = 2;
4255 snd_device_t split_devs[2] = {SND_DEVICE_NONE, SND_DEVICE_NONE};
4256 if (platform_can_split_snd_device(dev, &num_devs, split_devs) == 0) {
4257 return platform_snd_device_has_speaker(split_devs[0]) ||
4258 platform_snd_device_has_speaker(split_devs[1]);
4259 }
4260
4261 switch (dev) {
4262 case SND_DEVICE_OUT_SPEAKER:
4263 case SND_DEVICE_OUT_SPEAKER_SAFE:
4264 case SND_DEVICE_OUT_SPEAKER_REVERSE:
4265 case SND_DEVICE_OUT_SPEAKER_PROTECTED:
4266 case SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED:
4267 case SND_DEVICE_OUT_VOICE_SPEAKER_HFP:
4268 return true;
4269 default:
4270 break;
4271 }
4272 return false;
4273}
jiabin8962a4d2018-03-19 18:21:24 -07004274
4275bool platform_set_microphone_characteristic(void *platform,
4276 struct audio_microphone_characteristic_t mic) {
4277 struct platform_data *my_data = (struct platform_data *)platform;
4278 if (my_data->declared_mic_count >= AUDIO_MICROPHONE_MAX_COUNT) {
4279 ALOGE("mic number is more than maximum number");
4280 return false;
4281 }
4282 for (size_t ch = 0; ch < AUDIO_CHANNEL_COUNT_MAX; ch++) {
4283 mic.channel_mapping[ch] = AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED;
4284 }
4285 my_data->microphones[my_data->declared_mic_count++] = mic;
4286 return true;
4287}
4288
4289int platform_get_microphones(void *platform,
4290 struct audio_microphone_characteristic_t *mic_array,
4291 size_t *mic_count) {
4292 struct platform_data *my_data = (struct platform_data *)platform;
4293 if (mic_count == NULL) {
4294 return -EINVAL;
4295 }
4296 if (mic_array == NULL) {
4297 return -EINVAL;
4298 }
4299
4300 if (*mic_count == 0) {
4301 *mic_count = my_data->declared_mic_count;
4302 return 0;
4303 }
4304
4305 size_t max_mic_count = *mic_count;
4306 size_t actual_mic_count = 0;
4307 for (size_t i = 0; i < max_mic_count && i < my_data->declared_mic_count; i++) {
4308 mic_array[i] = my_data->microphones[i];
4309 actual_mic_count++;
4310 }
4311 *mic_count = actual_mic_count;
4312 return 0;
4313}
4314
4315int platform_get_active_microphones(void *platform, audio_devices_t device, unsigned int channels,
4316 int source __unused, audio_usecase_t usecase __unused,
4317 struct audio_microphone_characteristic_t *mic_array,
4318 size_t *mic_count) {
4319 struct platform_data *my_data = (struct platform_data *)platform;
4320 if (mic_count == NULL) {
4321 return -EINVAL;
4322 }
4323 if (mic_array == NULL) {
4324 return -EINVAL;
4325 }
4326
4327 if (*mic_count == 0) {
4328 // TODO: return declared mic count as a preliminary implementation, the final
4329 // implementation will derive mic count and channel mapping from use case, source and device
4330 *mic_count = my_data->declared_mic_count;
4331 return 0;
4332 }
4333
4334 size_t max_mic_count = *mic_count;
4335 size_t actual_mic_count = 0;
4336 for (size_t i = 0; i < max_mic_count && i < my_data->declared_mic_count; i++) {
4337 // TODO: get actual microphone and channel mapping type.
4338 if ((my_data->microphones[i].device & device) == device) {
4339 mic_array[actual_mic_count] = my_data->microphones[i];
4340 for (size_t ch = 0; ch < channels; ch++) {
4341 mic_array[actual_mic_count].channel_mapping[ch] =
4342 AUDIO_MICROPHONE_CHANNEL_MAPPING_DIRECT;
4343 }
4344 actual_mic_count++;
4345 }
4346 }
4347 *mic_count = actual_mic_count;
4348 return 0;
4349}