blob: ff90c8d489a4facdbc017027fd4e9acfd211bb1a [file] [log] [blame]
Eric Laurentb23d5282013-05-14 15:27:20 -07001/*
vivek mehtaa51fd402016-02-04 19:49:33 -08002 * Copyright (C) 2013-2016 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>
22#include <cutils/log.h>
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -070023#include <cutils/str_parms.h>
Eric Laurentb23d5282013-05-14 15:27:20 -070024#include <cutils/properties.h>
25#include <audio_hw.h>
26#include <platform_api.h>
27#include "platform.h"
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -070028#include "audio_extn.h"
vivek mehta1a9b7c02015-06-25 11:49:38 -070029#include <linux/msm_audio.h>
Eric Laurentb23d5282013-05-14 15:27:20 -070030
Jaekyun Seokf62e17d2017-03-08 17:15:28 +090031#define MIXER_XML_DEFAULT_PATH "mixer_paths.xml"
32#define MIXER_XML_BASE_STRING "mixer_paths"
vivek mehta60ea4152016-02-18 17:10:26 -080033#define TOMTOM_8226_SND_CARD_NAME "msm8226-tomtom-snd-card"
34#define TOMTOM_MIXER_FILE_SUFFIX "wcd9330"
35
Eric Laurentb23d5282013-05-14 15:27:20 -070036#define LIB_ACDB_LOADER "libacdbloader.so"
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -070037#define AUDIO_DATA_BLOCK_MIXER_CTL "HDMI EDID"
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +090038#define CVD_VERSION_MIXER_CTL "CVD Version"
Eric Laurentb23d5282013-05-14 15:27:20 -070039
Eric Laurentf9583c32016-03-28 13:50:50 -070040#define min(a, b) ((a) < (b) ? (a) : (b))
Eric Laurentb23d5282013-05-14 15:27:20 -070041
42/*
Eric Laurentb23d5282013-05-14 15:27:20 -070043 * This file will have a maximum of 38 bytes:
44 *
45 * 4 bytes: number of audio blocks
46 * 4 bytes: total length of Short Audio Descriptor (SAD) blocks
47 * Maximum 10 * 3 bytes: SAD blocks
48 */
49#define MAX_SAD_BLOCKS 10
50#define SAD_BLOCK_SIZE 3
51
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +090052#define MAX_CVD_VERSION_STRING_SIZE 100
53
Eric Laurentb23d5282013-05-14 15:27:20 -070054/* EDID format ID for LPCM audio */
55#define EDID_FORMAT_LPCM 1
56
sangwoo1b9f4b32013-06-21 18:22:55 -070057/* Retry for delay in FW loading*/
58#define RETRY_NUMBER 10
59#define RETRY_US 500000
Vineeta Srivastava4b89e372014-06-19 14:21:42 -070060#define MAX_SND_CARD 8
sangwoo53b2cf02013-07-25 19:18:44 -070061
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -070062#define MAX_SND_CARD_NAME_LEN 31
63
vivek mehta1a9b7c02015-06-25 11:49:38 -070064#define DEFAULT_APP_TYPE_RX_PATH 0x11130
65
keunhui.parkc5aaa0e2015-07-13 10:57:37 +090066#define TOSTRING_(x) #x
67#define TOSTRING(x) TOSTRING_(x)
68
Eric Laurentb23d5282013-05-14 15:27:20 -070069struct audio_block_header
70{
71 int reserved;
72 int length;
73};
74
vivek mehta1a9b7c02015-06-25 11:49:38 -070075enum {
76 CAL_MODE_SEND = 0x1,
77 CAL_MODE_PERSIST = 0x2,
78 CAL_MODE_RTAC = 0x4
79};
80
keunhui.park2f7306a2015-07-16 16:48:06 +090081#define PLATFORM_CONFIG_KEY_OPERATOR_INFO "operator_info"
82
83struct operator_info {
84 struct listnode list;
85 char *name;
86 char *mccmnc;
87};
88
89struct operator_specific_device {
90 struct listnode list;
91 char *operator;
92 char *mixer_path;
93 int acdb_id;
94};
95
96static struct listnode operator_info_list;
97static struct listnode *operator_specific_device_table[SND_DEVICE_MAX];
98
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -070099/* Audio calibration related functions */
Eric Laurentb23d5282013-05-14 15:27:20 -0700100typedef void (*acdb_deallocate_t)();
vivek mehtac698f132016-02-25 18:50:35 -0800101typedef int (*acdb_init_v2_cvd_t)(char *, char *, int);
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +0900102typedef int (*acdb_init_v2_t)(char *);
Eric Laurentb23d5282013-05-14 15:27:20 -0700103typedef int (*acdb_init_t)();
104typedef void (*acdb_send_audio_cal_t)(int, int);
105typedef void (*acdb_send_voice_cal_t)(int, int);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700106typedef int (*acdb_reload_vocvoltable_t)(int);
vivek mehta1a9b7c02015-06-25 11:49:38 -0700107typedef int (*acdb_send_gain_dep_cal_t)(int, int, int, int, int);
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -0700108typedef int (*acdb_send_custom_top_t) (void);
Eric Laurentb23d5282013-05-14 15:27:20 -0700109
110/* Audio calibration related functions */
111struct 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;
Thierry Strudel92232b42017-01-26 10:51:48 -0800123#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998)
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;
132 acdb_send_voice_cal_t acdb_send_voice_cal;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700133 acdb_reload_vocvoltable_t acdb_reload_vocvoltable;
vivek mehta1a9b7c02015-06-25 11:49:38 -0700134 acdb_send_gain_dep_cal_t acdb_send_gain_dep_cal;
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -0700135 acdb_send_custom_top_t acdb_send_custom_top;
136 bool acdb_initialized;
137
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700138 struct csd_data *csd;
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800139 char ec_ref_mixer_path[64];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700140
141 char *snd_card_name;
keunhui.parkc5aaa0e2015-07-13 10:57:37 +0900142 int max_vol_index;
Prashant Malanic92c5962015-08-11 15:10:18 -0700143 int max_mic_count;
vivek mehtade4849c2016-03-03 17:23:38 -0800144
145 void *hw_info;
Eric Laurentb23d5282013-05-14 15:27:20 -0700146};
147
Haynes Mathew George98c95622014-06-20 19:14:25 -0700148static int pcm_device_table[AUDIO_USECASE_MAX][2] = {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700149 [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = {DEEP_BUFFER_PCM_DEVICE,
150 DEEP_BUFFER_PCM_DEVICE},
151 [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
152 LOWLATENCY_PCM_DEVICE},
153 [USECASE_AUDIO_PLAYBACK_MULTI_CH] = {MULTIMEDIA2_PCM_DEVICE,
154 MULTIMEDIA2_PCM_DEVICE},
155 [USECASE_AUDIO_PLAYBACK_OFFLOAD] = {PLAYBACK_OFFLOAD_DEVICE,
156 PLAYBACK_OFFLOAD_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700157 [USECASE_AUDIO_PLAYBACK_TTS] = {MULTIMEDIA2_PCM_DEVICE,
158 MULTIMEDIA2_PCM_DEVICE},
159 [USECASE_AUDIO_PLAYBACK_ULL] = {MULTIMEDIA3_PCM_DEVICE,
160 MULTIMEDIA3_PCM_DEVICE},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800161 [USECASE_AUDIO_PLAYBACK_MMAP] = {MMAP_PLAYBACK_PCM_DEVICE,
162 MMAP_PLAYBACK_PCM_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700163
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700164 [USECASE_AUDIO_RECORD] = {AUDIO_RECORD_PCM_DEVICE,
165 AUDIO_RECORD_PCM_DEVICE},
166 [USECASE_AUDIO_RECORD_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
167 LOWLATENCY_PCM_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700168
Eric Laurent0e46adf2016-12-16 12:49:24 -0800169 [USECASE_AUDIO_RECORD_MMAP] = {MMAP_RECORD_PCM_DEVICE,
170 MMAP_RECORD_PCM_DEVICE},
171
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700172 [USECASE_VOICE_CALL] = {VOICE_CALL_PCM_DEVICE,
173 VOICE_CALL_PCM_DEVICE},
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700174 [USECASE_VOICE2_CALL] = {VOICE2_CALL_PCM_DEVICE, VOICE2_CALL_PCM_DEVICE},
175 [USECASE_VOLTE_CALL] = {VOLTE_CALL_PCM_DEVICE, VOLTE_CALL_PCM_DEVICE},
176 [USECASE_QCHAT_CALL] = {QCHAT_CALL_PCM_DEVICE, QCHAT_CALL_PCM_DEVICE},
177 [USECASE_VOWLAN_CALL] = {VOWLAN_CALL_PCM_DEVICE, VOWLAN_CALL_PCM_DEVICE},
vivek mehtaa51fd402016-02-04 19:49:33 -0800178 [USECASE_VOICEMMODE1_CALL] = {VOICEMMODE1_CALL_PCM_DEVICE,
179 VOICEMMODE1_CALL_PCM_DEVICE},
180 [USECASE_VOICEMMODE2_CALL] = {VOICEMMODE2_CALL_PCM_DEVICE,
181 VOICEMMODE2_CALL_PCM_DEVICE},
182
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700183 [USECASE_INCALL_REC_UPLINK] = {AUDIO_RECORD_PCM_DEVICE,
184 AUDIO_RECORD_PCM_DEVICE},
185 [USECASE_INCALL_REC_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
186 AUDIO_RECORD_PCM_DEVICE},
187 [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
188 AUDIO_RECORD_PCM_DEVICE},
Ravi Kumar Alamanda8e6e98f2013-11-05 15:57:39 -0800189 [USECASE_AUDIO_HFP_SCO] = {HFP_PCM_RX, HFP_SCO_RX},
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700190
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700191 [USECASE_AUDIO_SPKR_CALIB_RX] = {SPKR_PROT_CALIB_RX_PCM_DEVICE, -1},
192 [USECASE_AUDIO_SPKR_CALIB_TX] = {-1, SPKR_PROT_CALIB_TX_PCM_DEVICE},
193
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700194 [USECASE_AUDIO_PLAYBACK_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
195 AFE_PROXY_RECORD_PCM_DEVICE},
196 [USECASE_AUDIO_RECORD_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
197 AFE_PROXY_RECORD_PCM_DEVICE},
zhaoyang yin4211fad2015-06-04 21:13:25 +0800198 [USECASE_AUDIO_DSM_FEEDBACK] = {QUAT_MI2S_PCM_DEVICE, QUAT_MI2S_PCM_DEVICE},
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700199
Eric Laurentb23d5282013-05-14 15:27:20 -0700200};
201
202/* Array to store sound devices */
203static const char * const device_table[SND_DEVICE_MAX] = {
204 [SND_DEVICE_NONE] = "none",
205 /* Playback sound devices */
206 [SND_DEVICE_OUT_HANDSET] = "handset",
207 [SND_DEVICE_OUT_SPEAKER] = "speaker",
208 [SND_DEVICE_OUT_SPEAKER_REVERSE] = "speaker-reverse",
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700209 [SND_DEVICE_OUT_SPEAKER_SAFE] = "speaker-safe",
Eric Laurentb23d5282013-05-14 15:27:20 -0700210 [SND_DEVICE_OUT_HEADPHONES] = "headphones",
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500211 [SND_DEVICE_OUT_LINE] = "line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700212 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones",
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700213 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = "speaker-safe-and-headphones",
Eric Laurent744996b2014-10-01 11:40:40 -0500214 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = "speaker-and-line",
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700215 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = "speaker-safe-and-line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700216 [SND_DEVICE_OUT_VOICE_HANDSET] = "voice-handset",
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500217 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = "voice-hac-handset",
Eric Laurentb23d5282013-05-14 15:27:20 -0700218 [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker",
219 [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones",
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500220 [SND_DEVICE_OUT_VOICE_LINE] = "voice-line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700221 [SND_DEVICE_OUT_HDMI] = "hdmi",
222 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi",
223 [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700224 [SND_DEVICE_OUT_BT_SCO_WB] = "bt-sco-headset-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700225 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = "voice-handset-tmus",
226 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones",
227 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones",
228 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700229 [SND_DEVICE_OUT_VOICE_TX] = "voice-tx",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700230 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = "speaker-protected",
231 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = "voice-speaker-protected",
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -0700232 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = "voice-speaker-hfp",
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -0800233 [SND_DEVICE_OUT_SPEAKER_AND_BT_SCO] = "speaker-and-bt-sco",
234 [SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB] = "speaker-and-bt-sco-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700235
236 /* Capture sound devices */
237 [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700238 [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700239 [SND_DEVICE_IN_HANDSET_MIC_NS] = "handset-mic",
240 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = "handset-mic",
241 [SND_DEVICE_IN_HANDSET_DMIC] = "dmic-endfire",
242 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = "dmic-endfire",
243 [SND_DEVICE_IN_HANDSET_DMIC_NS] = "dmic-endfire",
244 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = "dmic-endfire",
245 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = "dmic-endfire",
246
247 [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
248 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "speaker-mic",
249 [SND_DEVICE_IN_SPEAKER_MIC_NS] = "speaker-mic",
250 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = "speaker-mic",
251 [SND_DEVICE_IN_SPEAKER_DMIC] = "speaker-dmic-endfire",
252 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = "speaker-dmic-endfire",
253 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = "speaker-dmic-endfire",
254 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = "speaker-dmic-endfire",
255 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = "speaker-dmic-endfire",
256
257 [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
Eric Laurentcefbbac2014-09-04 13:54:10 -0500258 [SND_DEVICE_IN_HEADSET_MIC_AEC] = "headset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700259
Eric Laurentb23d5282013-05-14 15:27:20 -0700260 [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic",
261 [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700262 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = "bt-sco-mic",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700263 [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700264 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = "bt-sco-mic-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700265 [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700266
267 [SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef",
268 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = "voice-dmic-ef-tmus",
269 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
270 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = "voice-speaker-dmic-ef",
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -0700271 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = "voice-speaker-mic-hfp",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700272 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700273 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
274 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
275 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700276
Eric Laurentb23d5282013-05-14 15:27:20 -0700277 [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700278 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = "voice-rec-mic",
vivek mehta733c1df2016-04-04 15:09:24 -0700279 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = "voice-rec-mic",
vivek mehtaf3440682016-05-11 14:24:37 -0700280 [SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700281 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = "voice-rec-dmic-ef",
282 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence",
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700283 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = "headset-mic",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700284
Ricardo Garcia9034bc42016-04-04 07:11:46 -0700285 [SND_DEVICE_IN_UNPROCESSED_MIC] = "unprocessed-mic",
vivek mehta0125e782016-06-16 18:03:11 -0700286 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = "unprocessed-stereo-mic",
287 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = "unprocessed-three-mic",
288 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = "unprocessed-quad-mic",
289 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = "unprocessed-headset-mic",
rago90fb9612015-12-02 11:37:53 -0800290
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700291 [SND_DEVICE_IN_VOICE_RX] = "voice-rx",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700292
Prashant Malanic92c5962015-08-11 15:10:18 -0700293 [SND_DEVICE_IN_THREE_MIC] = "three-mic",
294 [SND_DEVICE_IN_QUAD_MIC] = "quad-mic",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700295 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = "vi-feedback",
Prashant Malanic92c5962015-08-11 15:10:18 -0700296 [SND_DEVICE_IN_HANDSET_TMIC] = "three-mic",
297 [SND_DEVICE_IN_HANDSET_QMIC] = "quad-mic",
vivek mehta733c1df2016-04-04 15:09:24 -0700298 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = "three-mic",
299 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = "quad-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700300};
301
302/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700303static int acdb_device_table[SND_DEVICE_MAX] = {
Eric Laurentb23d5282013-05-14 15:27:20 -0700304 [SND_DEVICE_NONE] = -1,
305 [SND_DEVICE_OUT_HANDSET] = 7,
306 [SND_DEVICE_OUT_SPEAKER] = 15,
307 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 15,
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700308 [SND_DEVICE_OUT_SPEAKER_SAFE] = 15,
Eric Laurentb23d5282013-05-14 15:27:20 -0700309 [SND_DEVICE_OUT_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500310 [SND_DEVICE_OUT_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700311 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700312 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500313 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = 77,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700314 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = 77,
Ravi Kumar Alamanda235c3482014-08-21 17:32:44 -0700315 [SND_DEVICE_OUT_VOICE_HANDSET] = ACDB_ID_VOICE_HANDSET,
316 [SND_DEVICE_OUT_VOICE_SPEAKER] = ACDB_ID_VOICE_SPEAKER,
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500317 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = 53,
Eric Laurentb23d5282013-05-14 15:27:20 -0700318 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500319 [SND_DEVICE_OUT_VOICE_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700320 [SND_DEVICE_OUT_HDMI] = 18,
321 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 15,
322 [SND_DEVICE_OUT_BT_SCO] = 22,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700323 [SND_DEVICE_OUT_BT_SCO_WB] = 39,
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700324 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = ACDB_ID_VOICE_HANDSET_TMUS,
Eric Laurentb23d5282013-05-14 15:27:20 -0700325 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
326 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
327 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700328 [SND_DEVICE_OUT_VOICE_TX] = 45,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700329 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = 124,
330 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = 101,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700331 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = ACDB_ID_VOICE_SPEAKER,
Eric Laurentb23d5282013-05-14 15:27:20 -0700332
333 [SND_DEVICE_IN_HANDSET_MIC] = 4,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700334 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 106,
335 [SND_DEVICE_IN_HANDSET_MIC_NS] = 107,
336 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = 108,
337 [SND_DEVICE_IN_HANDSET_DMIC] = 41,
338 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = 109,
339 [SND_DEVICE_IN_HANDSET_DMIC_NS] = 110,
340 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = 111,
341 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = 34,
342
343 [SND_DEVICE_IN_SPEAKER_MIC] = 11,
344 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 112,
345 [SND_DEVICE_IN_SPEAKER_MIC_NS] = 113,
346 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = 114,
347 [SND_DEVICE_IN_SPEAKER_DMIC] = 43,
348 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = 115,
349 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = 116,
350 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = 117,
351 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = 35,
352
rago90fb9612015-12-02 11:37:53 -0800353 [SND_DEVICE_IN_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentcefbbac2014-09-04 13:54:10 -0500354 [SND_DEVICE_IN_HEADSET_MIC_AEC] = ACDB_ID_HEADSET_MIC_AEC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700355
Eric Laurentb23d5282013-05-14 15:27:20 -0700356 [SND_DEVICE_IN_HDMI_MIC] = 4,
357 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700358 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = 21,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700359 [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700360 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = 38,
Eric Laurentb23d5282013-05-14 15:27:20 -0700361 [SND_DEVICE_IN_CAMCORDER_MIC] = 61,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700362
363 [SND_DEVICE_IN_VOICE_DMIC] = 41,
364 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = ACDB_ID_VOICE_DMIC_EF_TMUS,
365 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700366 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = 11,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700367 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 43,
rago90fb9612015-12-02 11:37:53 -0800368 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentb23d5282013-05-14 15:27:20 -0700369 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
370 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
371 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700372
rago90fb9612015-12-02 11:37:53 -0800373 [SND_DEVICE_IN_VOICE_REC_MIC] = ACDB_ID_VOICE_REC_MIC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700374 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = 113,
vivek mehta733c1df2016-04-04 15:09:24 -0700375 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = 112,
vivek mehtaf3440682016-05-11 14:24:37 -0700376 [SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = 114,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700377 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = 35,
378 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 43,
rago90fb9612015-12-02 11:37:53 -0800379 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
380
381 [SND_DEVICE_IN_UNPROCESSED_MIC] = ACDB_ID_VOICE_REC_MIC,
382 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
vivek mehta4ed66e62016-04-15 23:33:34 -0700383 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = 35,
384 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = 125,
385 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = 125,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700386
387 [SND_DEVICE_IN_VOICE_RX] = 44,
Mikhail Naganov9d677f42017-03-09 16:57:59 +0000388
Prashant Malanic92c5962015-08-11 15:10:18 -0700389 [SND_DEVICE_IN_THREE_MIC] = 46,
390 [SND_DEVICE_IN_QUAD_MIC] = 46,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700391 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = 102,
Prashant Malanic92c5962015-08-11 15:10:18 -0700392 [SND_DEVICE_IN_HANDSET_TMIC] = 125,
393 [SND_DEVICE_IN_HANDSET_QMIC] = 125,
vivek mehta733c1df2016-04-04 15:09:24 -0700394 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = 125, /* override this for new target to 140 */
395 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = 125, /* override this for new target to 140 */
Eric Laurentb23d5282013-05-14 15:27:20 -0700396};
397
Haynes Mathew George98c95622014-06-20 19:14:25 -0700398struct name_to_index {
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700399 char name[100];
400 unsigned int index;
401};
402
403#define TO_NAME_INDEX(X) #X, X
404
Haynes Mathew George98c95622014-06-20 19:14:25 -0700405/* Used to get index from parsed string */
406static const struct name_to_index snd_device_name_index[SND_DEVICE_MAX] = {
407 /* out */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700408 {TO_NAME_INDEX(SND_DEVICE_OUT_HANDSET)},
409 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER)},
410 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_REVERSE)},
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700411 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700412 {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500413 {TO_NAME_INDEX(SND_DEVICE_OUT_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700414 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700415 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES)},
Eric Laurent744996b2014-10-01 11:40:40 -0500416 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_LINE)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700417 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700418 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET)},
419 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700420 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_HFP)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700421 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500422 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700423 {TO_NAME_INDEX(SND_DEVICE_OUT_HDMI)},
424 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HDMI)},
425 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO)},
426 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO_WB)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700427 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET_TMUS)},
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500428 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HAC_HANDSET)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700429 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES)},
430 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES)},
431 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET)},
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -0800432 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_SCO)},
433 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700434
435 /* in */
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700436 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED)},
437 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700438 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700439 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700440 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_NS)},
441 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)},
442 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC)},
443 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC)},
444 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_NS)},
445 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)},
446 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_STEREO)},
447
448 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700449 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700450 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_NS)},
451 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)},
452 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC)},
453 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC)},
454 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS)},
455 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)},
456 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_STEREO)},
457
458 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC)},
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700459 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700460
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700461 {TO_NAME_INDEX(SND_DEVICE_IN_HDMI_MIC)},
462 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700463 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700464 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700465 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700466 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700467
468 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC)},
469 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC_TMUS)},
470 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700471 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700472 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC)},
473 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEADSET_MIC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700474 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC)},
475 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC)},
476 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700477
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700478 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700479 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_NS)},
vivek mehta733c1df2016-04-04 15:09:24 -0700480 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC)},
vivek mehtaf3440682016-05-11 14:24:37 -0700481 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700482 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_STEREO)},
483 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE)},
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700484 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_HEADSET_MIC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700485
rago90fb9612015-12-02 11:37:53 -0800486 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_MIC)},
487 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC)},
vivek mehta4ed66e62016-04-15 23:33:34 -0700488 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_STEREO_MIC)},
489 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_THREE_MIC)},
490 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_QUAD_MIC)},
rago90fb9612015-12-02 11:37:53 -0800491
Prashant Malanic92c5962015-08-11 15:10:18 -0700492 {TO_NAME_INDEX(SND_DEVICE_IN_THREE_MIC)},
493 {TO_NAME_INDEX(SND_DEVICE_IN_QUAD_MIC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700494 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_VI_FEEDBACK)},
Prashant Malanic92c5962015-08-11 15:10:18 -0700495 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC)},
496 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC)},
vivek mehta733c1df2016-04-04 15:09:24 -0700497 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC_AEC)},
498 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC_AEC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700499};
500
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700501static char * backend_tag_table[SND_DEVICE_MAX] = {0};
502static char * hw_interface_table[SND_DEVICE_MAX] = {0};
Haynes Mathew George98c95622014-06-20 19:14:25 -0700503
504static const struct name_to_index usecase_name_index[AUDIO_USECASE_MAX] = {
505 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_DEEP_BUFFER)},
506 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_LOW_LATENCY)},
507 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_MULTI_CH)},
508 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD)},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700509 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_TTS)},
510 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_ULL)},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800511 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_MMAP)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700512 {TO_NAME_INDEX(USECASE_AUDIO_RECORD)},
513 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_LOW_LATENCY)},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800514 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_MMAP)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700515 {TO_NAME_INDEX(USECASE_VOICE_CALL)},
516 {TO_NAME_INDEX(USECASE_VOICE2_CALL)},
517 {TO_NAME_INDEX(USECASE_VOLTE_CALL)},
518 {TO_NAME_INDEX(USECASE_QCHAT_CALL)},
519 {TO_NAME_INDEX(USECASE_VOWLAN_CALL)},
John Muirf1346ce2016-12-06 00:03:41 -0800520 {TO_NAME_INDEX(USECASE_VOICEMMODE1_CALL)},
521 {TO_NAME_INDEX(USECASE_VOICEMMODE2_CALL)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700522 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK)},
523 {TO_NAME_INDEX(USECASE_INCALL_REC_DOWNLINK)},
524 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK_AND_DOWNLINK)},
525 {TO_NAME_INDEX(USECASE_AUDIO_HFP_SCO)},
John Muirf1346ce2016-12-06 00:03:41 -0800526 {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_RX)},
527 {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_TX)},
528 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_AFE_PROXY)},
529 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_AFE_PROXY)},
530 {TO_NAME_INDEX(USECASE_AUDIO_DSM_FEEDBACK)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700531};
532
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700533#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
534#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
Eric Laurent0e46adf2016-12-16 12:49:24 -0800535#define ULL_PLATFORM_DELAY (3*1000LL)
536#define MMAP_PLATFORM_DELAY (3*1000LL)
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700537
Eric Laurentb23d5282013-05-14 15:27:20 -0700538static pthread_once_t check_op_once_ctl = PTHREAD_ONCE_INIT;
539static bool is_tmus = false;
540
541static void check_operator()
542{
543 char value[PROPERTY_VALUE_MAX];
544 int mccmnc;
545 property_get("gsm.sim.operator.numeric",value,"0");
546 mccmnc = atoi(value);
Eric Laurent2bafff12016-03-17 12:17:23 -0700547 ALOGD("%s: tmus mccmnc %d", __func__, mccmnc);
Eric Laurentb23d5282013-05-14 15:27:20 -0700548 switch(mccmnc) {
549 /* TMUS MCC(310), MNC(490, 260, 026) */
550 case 310490:
551 case 310260:
552 case 310026:
sangwon.jeonb891db52013-09-14 17:39:15 +0900553 /* Add new TMUS MNC(800, 660, 580, 310, 270, 250, 240, 230, 220, 210, 200, 160) */
554 case 310800:
555 case 310660:
556 case 310580:
557 case 310310:
558 case 310270:
559 case 310250:
560 case 310240:
561 case 310230:
562 case 310220:
563 case 310210:
564 case 310200:
565 case 310160:
Eric Laurentb23d5282013-05-14 15:27:20 -0700566 is_tmus = true;
567 break;
568 }
569}
570
571bool is_operator_tmus()
572{
573 pthread_once(&check_op_once_ctl, check_operator);
574 return is_tmus;
575}
576
keunhui.park2f7306a2015-07-16 16:48:06 +0900577static char *get_current_operator()
578{
579 struct listnode *node;
580 struct operator_info *info_item;
581 char mccmnc[PROPERTY_VALUE_MAX];
582 char *ret = NULL;
583
Tom Cherry7fea2042016-11-10 18:05:59 -0800584 property_get("gsm.sim.operator.numeric",mccmnc,"00000");
keunhui.park2f7306a2015-07-16 16:48:06 +0900585
586 list_for_each(node, &operator_info_list) {
587 info_item = node_to_item(node, struct operator_info, list);
588 if (strstr(info_item->mccmnc, mccmnc) != NULL) {
589 ret = info_item->name;
590 }
591 }
592
593 return ret;
594}
595
596static struct operator_specific_device *get_operator_specific_device(snd_device_t snd_device)
597{
598 struct listnode *node;
599 struct operator_specific_device *ret = NULL;
600 struct operator_specific_device *device_item;
601 char *operator_name;
602
603 operator_name = get_current_operator();
604 if (operator_name == NULL)
605 return ret;
606
607 list_for_each(node, operator_specific_device_table[snd_device]) {
608 device_item = node_to_item(node, struct operator_specific_device, list);
609 if (strcmp(operator_name, device_item->operator) == 0) {
610 ret = device_item;
611 }
612 }
613
614 return ret;
615}
616
617
618static int get_operator_specific_device_acdb_id(snd_device_t snd_device)
619{
620 struct operator_specific_device *device;
621 int ret = acdb_device_table[snd_device];
622
623 device = get_operator_specific_device(snd_device);
624 if (device != NULL)
625 ret = device->acdb_id;
626
627 return ret;
628}
629
630static const char *get_operator_specific_device_mixer_path(snd_device_t snd_device)
631{
632 struct operator_specific_device *device;
633 const char *ret = device_table[snd_device];
634
635 device = get_operator_specific_device(snd_device);
636 if (device != NULL)
637 ret = device->mixer_path;
638
639 return ret;
640}
641
vivek mehta1a9b7c02015-06-25 11:49:38 -0700642bool platform_send_gain_dep_cal(void *platform, int level)
643{
644 bool ret_val = false;
645 struct platform_data *my_data = (struct platform_data *)platform;
646 struct audio_device *adev = my_data->adev;
647 int acdb_dev_id, app_type;
648 int acdb_dev_type = MSM_SNDDEV_CAP_RX;
649 int mode = CAL_MODE_RTAC;
650 struct listnode *node;
651 struct audio_usecase *usecase;
vivek mehta1a9b7c02015-06-25 11:49:38 -0700652
653 if (my_data->acdb_send_gain_dep_cal == NULL) {
654 ALOGE("%s: dlsym error for acdb_send_gain_dep_cal", __func__);
655 return ret_val;
656 }
657
658 if (!voice_is_in_call(adev)) {
659 ALOGV("%s: Not Voice call usecase, apply new cal for level %d",
660 __func__, level);
661 app_type = DEFAULT_APP_TYPE_RX_PATH;
662
663 // find the current active sound device
664 list_for_each(node, &adev->usecase_list) {
665 usecase = node_to_item(node, struct audio_usecase, list);
666
667 if (usecase != NULL &&
668 usecase->type == PCM_PLAYBACK &&
669 (usecase->stream.out->devices == AUDIO_DEVICE_OUT_SPEAKER)) {
670
671 ALOGV("%s: out device is %d", __func__, usecase->out_snd_device);
vivek mehta4cb82982015-07-13 12:05:49 -0700672 if (audio_extn_spkr_prot_is_enabled()) {
673 acdb_dev_id = audio_extn_spkr_prot_get_acdb_id(usecase->out_snd_device);
674 } else {
675 acdb_dev_id = acdb_device_table[usecase->out_snd_device];
676 }
677
vivek mehta1a9b7c02015-06-25 11:49:38 -0700678 if (!my_data->acdb_send_gain_dep_cal(acdb_dev_id, app_type,
679 acdb_dev_type, mode, level)) {
680 // set ret_val true if at least one calibration is set successfully
681 ret_val = true;
682 } else {
683 ALOGE("%s: my_data->acdb_send_gain_dep_cal failed ", __func__);
684 }
685 } else {
686 ALOGW("%s: Usecase list is empty", __func__);
687 }
688 }
689 } else {
690 ALOGW("%s: Voice call in progress .. ignore setting new cal",
691 __func__);
692 }
693 return ret_val;
694}
695
Eric Laurentcefbbac2014-09-04 13:54:10 -0500696void platform_set_echo_reference(struct audio_device *adev, bool enable, audio_devices_t out_device)
Eric Laurentb23d5282013-05-14 15:27:20 -0700697{
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800698 struct platform_data *my_data = (struct platform_data *)adev->platform;
Eric Laurentcefbbac2014-09-04 13:54:10 -0500699 snd_device_t snd_device = SND_DEVICE_NONE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700700
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800701 if (strcmp(my_data->ec_ref_mixer_path, "")) {
702 ALOGV("%s: diabling %s", __func__, my_data->ec_ref_mixer_path);
703 audio_route_reset_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
Eric Laurentcefbbac2014-09-04 13:54:10 -0500704 }
705
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800706 if (enable) {
707 strcpy(my_data->ec_ref_mixer_path, "echo-reference");
708 if (out_device != AUDIO_DEVICE_NONE) {
709 snd_device = platform_get_output_snd_device(adev->platform, out_device);
710 platform_add_backend_name(adev->platform, my_data->ec_ref_mixer_path, snd_device);
711 }
Eric Laurentcefbbac2014-09-04 13:54:10 -0500712
Joe Onorato188b6222016-03-01 11:02:27 -0800713 ALOGV("%s: enabling %s", __func__, my_data->ec_ref_mixer_path);
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800714 audio_route_apply_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
715 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700716}
717
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700718static struct csd_data *open_csd_client(bool i2s_ext_modem)
719{
720 struct csd_data *csd = calloc(1, sizeof(struct csd_data));
721
722 csd->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
723 if (csd->csd_client == NULL) {
724 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
725 goto error;
726 } else {
727 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
728
729 csd->deinit = (deinit_t)dlsym(csd->csd_client,
730 "csd_client_deinit");
731 if (csd->deinit == NULL) {
732 ALOGE("%s: dlsym error %s for csd_client_deinit", __func__,
733 dlerror());
734 goto error;
735 }
736 csd->disable_device = (disable_device_t)dlsym(csd->csd_client,
737 "csd_client_disable_device");
738 if (csd->disable_device == NULL) {
739 ALOGE("%s: dlsym error %s for csd_client_disable_device",
740 __func__, dlerror());
741 goto error;
742 }
743 csd->enable_device_config = (enable_device_config_t)dlsym(csd->csd_client,
744 "csd_client_enable_device_config");
745 if (csd->enable_device_config == NULL) {
746 ALOGE("%s: dlsym error %s for csd_client_enable_device_config",
747 __func__, dlerror());
748 goto error;
749 }
750 csd->enable_device = (enable_device_t)dlsym(csd->csd_client,
751 "csd_client_enable_device");
752 if (csd->enable_device == NULL) {
753 ALOGE("%s: dlsym error %s for csd_client_enable_device",
754 __func__, dlerror());
755 goto error;
756 }
757 csd->start_voice = (start_voice_t)dlsym(csd->csd_client,
758 "csd_client_start_voice");
759 if (csd->start_voice == NULL) {
760 ALOGE("%s: dlsym error %s for csd_client_start_voice",
761 __func__, dlerror());
762 goto error;
763 }
764 csd->stop_voice = (stop_voice_t)dlsym(csd->csd_client,
765 "csd_client_stop_voice");
766 if (csd->stop_voice == NULL) {
767 ALOGE("%s: dlsym error %s for csd_client_stop_voice",
768 __func__, dlerror());
769 goto error;
770 }
771 csd->volume = (volume_t)dlsym(csd->csd_client,
772 "csd_client_volume");
773 if (csd->volume == NULL) {
774 ALOGE("%s: dlsym error %s for csd_client_volume",
775 __func__, dlerror());
776 goto error;
777 }
778 csd->mic_mute = (mic_mute_t)dlsym(csd->csd_client,
779 "csd_client_mic_mute");
780 if (csd->mic_mute == NULL) {
781 ALOGE("%s: dlsym error %s for csd_client_mic_mute",
782 __func__, dlerror());
783 goto error;
784 }
785 csd->slow_talk = (slow_talk_t)dlsym(csd->csd_client,
786 "csd_client_slow_talk");
787 if (csd->slow_talk == NULL) {
788 ALOGE("%s: dlsym error %s for csd_client_slow_talk",
789 __func__, dlerror());
790 goto error;
791 }
792 csd->start_playback = (start_playback_t)dlsym(csd->csd_client,
793 "csd_client_start_playback");
794 if (csd->start_playback == NULL) {
795 ALOGE("%s: dlsym error %s for csd_client_start_playback",
796 __func__, dlerror());
797 goto error;
798 }
799 csd->stop_playback = (stop_playback_t)dlsym(csd->csd_client,
800 "csd_client_stop_playback");
801 if (csd->stop_playback == NULL) {
802 ALOGE("%s: dlsym error %s for csd_client_stop_playback",
803 __func__, dlerror());
804 goto error;
805 }
806 csd->start_record = (start_record_t)dlsym(csd->csd_client,
807 "csd_client_start_record");
808 if (csd->start_record == NULL) {
809 ALOGE("%s: dlsym error %s for csd_client_start_record",
810 __func__, dlerror());
811 goto error;
812 }
813 csd->stop_record = (stop_record_t)dlsym(csd->csd_client,
814 "csd_client_stop_record");
815 if (csd->stop_record == NULL) {
816 ALOGE("%s: dlsym error %s for csd_client_stop_record",
817 __func__, dlerror());
818 goto error;
819 }
820
821 csd->get_sample_rate = (get_sample_rate_t)dlsym(csd->csd_client,
822 "csd_client_get_sample_rate");
823 if (csd->get_sample_rate == NULL) {
824 ALOGE("%s: dlsym error %s for csd_client_get_sample_rate",
825 __func__, dlerror());
826
827 goto error;
828 }
829
830 csd->init = (init_t)dlsym(csd->csd_client, "csd_client_init");
831
832 if (csd->init == NULL) {
833 ALOGE("%s: dlsym error %s for csd_client_init",
834 __func__, dlerror());
835 goto error;
836 } else {
837 csd->init(i2s_ext_modem);
838 }
839 }
840 return csd;
841
842error:
843 free(csd);
844 csd = NULL;
845 return csd;
846}
847
848void close_csd_client(struct csd_data *csd)
849{
850 if (csd != NULL) {
851 csd->deinit();
852 dlclose(csd->csd_client);
853 free(csd);
854 csd = NULL;
855 }
856}
857
858static void platform_csd_init(struct platform_data *my_data)
859{
860#ifdef PLATFORM_MSM8084
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700861 int32_t modems, (*count_modems)(void);
862 const char *name = "libdetectmodem.so";
863 const char *func = "count_modems";
864 const char *error;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700865
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700866 my_data->csd = NULL;
867
868 void *lib = dlopen(name, RTLD_NOW);
869 error = dlerror();
870 if (!lib) {
871 ALOGE("%s: could not find %s: %s", __func__, name, error);
872 return;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700873 }
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700874
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700875 count_modems = NULL;
876 *(void **)(&count_modems) = dlsym(lib, func);
877 error = dlerror();
878 if (!count_modems) {
879 ALOGE("%s: could not find symbol %s in %s: %s",
880 __func__, func, name, error);
881 goto done;
882 }
883
884 modems = count_modems();
885 if (modems < 0) {
886 ALOGE("%s: count_modems failed\n", __func__);
887 goto done;
888 }
889
Eric Laurent2bafff12016-03-17 12:17:23 -0700890 ALOGD("%s: num_modems %d\n", __func__, modems);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700891 if (modems > 0)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700892 my_data->csd = open_csd_client(false /*is_i2s_ext_modem*/);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700893
894done:
895 dlclose(lib);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700896#else
897 my_data->csd = NULL;
898#endif
899}
900
Eric Laurentc6333382015-09-14 12:43:44 -0700901static void set_platform_defaults(struct platform_data * my_data)
Haynes Mathew George98c95622014-06-20 19:14:25 -0700902{
903 int32_t dev;
904 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700905 backend_tag_table[dev] = NULL;
906 hw_interface_table[dev] = NULL;
keunhui.park2f7306a2015-07-16 16:48:06 +0900907 operator_specific_device_table[dev] = NULL;
Haynes Mathew George98c95622014-06-20 19:14:25 -0700908 }
909
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700910 // To overwrite these go to the audio_platform_info.xml file.
911 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("bt-sco");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700912 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("bt-sco");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700913 backend_tag_table[SND_DEVICE_OUT_BT_SCO] = strdup("bt-sco");
914 backend_tag_table[SND_DEVICE_OUT_HDMI] = strdup("hdmi");
915 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("speaker-and-hdmi");
916 backend_tag_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("bt-sco-wb");
917 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("bt-sco-wb");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700918 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("bt-sco-wb");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700919 backend_tag_table[SND_DEVICE_OUT_VOICE_TX] = strdup("afe-proxy");
920 backend_tag_table[SND_DEVICE_IN_VOICE_RX] = strdup("afe-proxy");
Haynes Mathew George98c95622014-06-20 19:14:25 -0700921
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700922 hw_interface_table[SND_DEVICE_OUT_HANDSET] = strdup("SLIMBUS_0_RX");
923 hw_interface_table[SND_DEVICE_OUT_SPEAKER] = strdup("SLIMBUS_0_RX");
924 hw_interface_table[SND_DEVICE_OUT_SPEAKER_REVERSE] = strdup("SLIMBUS_0_RX");
925 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE] = strdup("SLIMBUS_0_RX");
926 hw_interface_table[SND_DEVICE_OUT_HEADPHONES] = strdup("SLIMBUS_0_RX");
927 hw_interface_table[SND_DEVICE_OUT_LINE] = strdup("SLIMBUS_0_RX");
928 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700929 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700930 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700931 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700932 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET] = strdup("SLIMBUS_0_RX");
933 hw_interface_table[SND_DEVICE_OUT_VOICE_HAC_HANDSET] = strdup("SLIMBUS_0_RX");
934 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER] = strdup("SLIMBUS_0_RX");
935 hw_interface_table[SND_DEVICE_OUT_VOICE_HEADPHONES] = strdup("SLIMBUS_0_RX");
936 hw_interface_table[SND_DEVICE_OUT_VOICE_LINE] = strdup("SLIMBUS_0_RX");
937 hw_interface_table[SND_DEVICE_OUT_HDMI] = strdup("HDMI_RX");
938 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("SLIMBUS_0_RX-and-HDMI_RX");
939 hw_interface_table[SND_DEVICE_OUT_BT_SCO] = strdup("SEC_AUX_PCM_RX");
940 hw_interface_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("SEC_AUX_PCM_RX");
941 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = strdup("SLIMBUS_0_RX");
942 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = strdup("SLIMBUS_0_RX");
943 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = strdup("SLIMBUS_0_RX");
944 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = strdup("SLIMBUS_0_RX");
945 hw_interface_table[SND_DEVICE_OUT_VOICE_TX] = strdup("AFE_PCM_RX");
946 hw_interface_table[SND_DEVICE_OUT_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
947 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
Eric Laurentc6333382015-09-14 12:43:44 -0700948
949 my_data->max_mic_count = PLATFORM_DEFAULT_MIC_COUNT;
Haynes Mathew George98c95622014-06-20 19:14:25 -0700950}
951
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +0900952void get_cvd_version(char *cvd_version, struct audio_device *adev)
953{
954 struct mixer_ctl *ctl;
955 int count;
956 int ret = 0;
957
958 ctl = mixer_get_ctl_by_name(adev->mixer, CVD_VERSION_MIXER_CTL);
959 if (!ctl) {
960 ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__, CVD_VERSION_MIXER_CTL);
961 goto done;
962 }
963 mixer_ctl_update(ctl);
964
965 count = mixer_ctl_get_num_values(ctl);
966 if (count > MAX_CVD_VERSION_STRING_SIZE)
967 count = MAX_CVD_VERSION_STRING_SIZE - 1;
968
969 ret = mixer_ctl_get_array(ctl, cvd_version, count);
970 if (ret != 0) {
971 ALOGE("%s: ERROR! mixer_ctl_get_array() failed to get CVD Version", __func__);
972 goto done;
973 }
974
975done:
976 return;
977}
978
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -0700979static int platform_acdb_init(void *platform)
980{
981 struct platform_data *my_data = (struct platform_data *)platform;
982 struct audio_device *adev = my_data->adev;
983
984 if (!my_data->acdb_init) {
985 ALOGE("%s: no acdb_init fn provided", __func__);
986 return -1;
987 }
988
989 if (my_data->acdb_initialized) {
990 ALOGW("acdb is already initialized");
991 return 0;
992 }
993
Thierry Strudel92232b42017-01-26 10:51:48 -0800994#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -0700995 char *cvd_version = calloc(1, MAX_CVD_VERSION_STRING_SIZE);
996 if (!cvd_version)
997 ALOGE("failed to allocate cvd_version");
998 else {
999 get_cvd_version(cvd_version, adev);
1000 my_data->acdb_init((char *)my_data->snd_card_name, cvd_version, 0);
1001 free(cvd_version);
1002 }
1003#elif defined (PLATFORM_MSM8084)
1004 my_data->acdb_init((char *)my_data->snd_card_name);
1005#else
1006 my_data->acdb_init();
1007#endif
1008 my_data->acdb_initialized = true;
1009 return 0;
1010}
1011
Jaekyun Seokf62e17d2017-03-08 17:15:28 +09001012// Treblized config files will be located in /odm/etc or /vendor/etc.
1013static const char *kConfigLocationList[] =
1014 {"/odm/etc", "/vendor/etc", "/system/etc"};
1015static const int kConfigLocationListSize =
1016 (sizeof(kConfigLocationList) / sizeof(kConfigLocationList[0]));
1017
1018bool resolveConfigFile(char file_name[MIXER_PATH_MAX_LENGTH]) {
1019 char full_config_path[MIXER_PATH_MAX_LENGTH];
1020 for (int i = 0; i < kConfigLocationListSize; i++) {
1021 snprintf(full_config_path,
1022 MIXER_PATH_MAX_LENGTH,
1023 "%s/%s",
1024 kConfigLocationList[i],
1025 file_name);
1026 if (F_OK == access(full_config_path, 0)) {
1027 strcpy(file_name, full_config_path);
1028 return true;
1029 }
1030 }
1031 return false;
1032}
1033
Eric Laurentb23d5282013-05-14 15:27:20 -07001034void *platform_init(struct audio_device *adev)
1035{
1036 char value[PROPERTY_VALUE_MAX];
vivek mehta60ea4152016-02-18 17:10:26 -08001037 struct platform_data *my_data = NULL;
1038 int retry_num = 0, snd_card_num = 0, key = 0, ret = 0;
1039 bool dual_mic_config = false, use_default_mixer_path = true;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001040 const char *snd_card_name;
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001041 char *cvd_version = NULL;
vivek mehta60ea4152016-02-18 17:10:26 -08001042 char *snd_internal_name = NULL;
1043 char *tmp = NULL;
1044 char mixer_xml_file[MIXER_PATH_MAX_LENGTH]= {0};
vivek mehtade4849c2016-03-03 17:23:38 -08001045 char platform_info_file[MIXER_PATH_MAX_LENGTH]= {0};
1046 struct snd_card_split *snd_split_handle = NULL;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001047 my_data = calloc(1, sizeof(struct platform_data));
1048
1049 my_data->adev = adev;
1050
keunhui.park2f7306a2015-07-16 16:48:06 +09001051 list_init(&operator_info_list);
1052
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001053 set_platform_defaults(my_data);
vivek mehta2b0e5a62016-09-02 17:31:58 -07001054 bool card_verifed[MAX_SND_CARD] = {0};
1055 const int retry_limit = property_get_int32("audio.snd_card.open.retries", RETRY_NUMBER);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001056
vivek mehta2b0e5a62016-09-02 17:31:58 -07001057 for (;;) {
1058 if (snd_card_num >= MAX_SND_CARD) {
1059 if (retry_num++ >= retry_limit) {
1060 ALOGE("%s: Unable to find correct sound card, aborting.", __func__);
1061 goto init_failed;
1062 }
sangwoo1b9f4b32013-06-21 18:22:55 -07001063
vivek mehta2b0e5a62016-09-02 17:31:58 -07001064 snd_card_num = 0;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001065 usleep(RETRY_US);
vivek mehta2b0e5a62016-09-02 17:31:58 -07001066 continue;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001067 }
1068
vivek mehta2b0e5a62016-09-02 17:31:58 -07001069 if (card_verifed[snd_card_num]) {
1070 ++snd_card_num;
1071 continue;
1072 }
1073
1074 adev->mixer = mixer_open(snd_card_num);
1075
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001076 if (!adev->mixer) {
1077 ALOGE("%s: Unable to open the mixer card: %d", __func__,
vivek mehta2b0e5a62016-09-02 17:31:58 -07001078 snd_card_num);
1079 ++snd_card_num;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001080 continue;
1081 }
1082
vivek mehta2b0e5a62016-09-02 17:31:58 -07001083 card_verifed[snd_card_num] = true;
1084
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001085 snd_card_name = mixer_get_name(adev->mixer);
vivek mehtade4849c2016-03-03 17:23:38 -08001086 my_data->hw_info = hw_info_init(snd_card_name);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001087
vivek mehtade4849c2016-03-03 17:23:38 -08001088 audio_extn_set_snd_card_split(snd_card_name);
1089 snd_split_handle = audio_extn_get_snd_card_split();
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001090
vivek mehtade4849c2016-03-03 17:23:38 -08001091 /* Get the codec internal name from the sound card and/or form factor
1092 * name and form the mixer paths and platfor info file name dynamically.
1093 * This is generic way of picking any codec and forma factor name based
1094 * mixer and platform info files in future with no code change.
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001095
vivek mehtade4849c2016-03-03 17:23:38 -08001096 * current code extends and looks for any of the exteneded mixer path and
1097 * platform info file present based on codec and form factor.
vivek mehta60ea4152016-02-18 17:10:26 -08001098
vivek mehtade4849c2016-03-03 17:23:38 -08001099 * order of picking appropriate file is
1100 * <i> mixer_paths_<codec_name>_<form_factor>.xml, if file not present
1101 * <ii> mixer_paths_<codec_name>.xml, if file not present
1102 * <iii> mixer_paths.xml
1103
1104 * same order is followed for audio_platform_info.xml as well
1105 */
1106
1107 // need to carryforward old file name
1108 if (!strncmp(snd_card_name, TOMTOM_8226_SND_CARD_NAME,
Eric Laurentf9583c32016-03-28 13:50:50 -07001109 min(strlen(TOMTOM_8226_SND_CARD_NAME), strlen(snd_card_name)))) {
vivek mehtade4849c2016-03-03 17:23:38 -08001110 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
vivek mehta60ea4152016-02-18 17:10:26 -08001111 MIXER_XML_BASE_STRING, TOMTOM_MIXER_FILE_SUFFIX );
vivek mehtade4849c2016-03-03 17:23:38 -08001112 } else {
Ed Tamb0b0d572016-03-21 10:45:37 -07001113
vivek mehtade4849c2016-03-03 17:23:38 -08001114 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s_%s.xml",
1115 MIXER_XML_BASE_STRING, snd_split_handle->snd_card,
1116 snd_split_handle->form_factor);
Jaekyun Seokf62e17d2017-03-08 17:15:28 +09001117 if (!resolveConfigFile(mixer_xml_file)) {
vivek mehtade4849c2016-03-03 17:23:38 -08001118 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1119 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1120 MIXER_XML_BASE_STRING, snd_split_handle->snd_card);
1121
Jaekyun Seokf62e17d2017-03-08 17:15:28 +09001122 if (!resolveConfigFile(mixer_xml_file)) {
vivek mehtade4849c2016-03-03 17:23:38 -08001123 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1124 strlcpy(mixer_xml_file, MIXER_XML_DEFAULT_PATH, MIXER_PATH_MAX_LENGTH);
Jaekyun Seokf62e17d2017-03-08 17:15:28 +09001125 resolveConfigFile(mixer_xml_file);
vivek mehtade4849c2016-03-03 17:23:38 -08001126 }
1127 }
1128
1129 snprintf(platform_info_file, sizeof(platform_info_file), "%s_%s_%s.xml",
1130 PLATFORM_INFO_XML_BASE_STRING, snd_split_handle->snd_card,
1131 snd_split_handle->form_factor);
1132
Jaekyun Seokf62e17d2017-03-08 17:15:28 +09001133 if (!resolveConfigFile(platform_info_file)) {
vivek mehtade4849c2016-03-03 17:23:38 -08001134 memset(platform_info_file, 0, sizeof(platform_info_file));
1135 snprintf(platform_info_file, sizeof(platform_info_file), "%s_%s.xml",
1136 PLATFORM_INFO_XML_BASE_STRING, snd_split_handle->snd_card);
1137
Jaekyun Seokf62e17d2017-03-08 17:15:28 +09001138 if (!resolveConfigFile(platform_info_file)) {
vivek mehtade4849c2016-03-03 17:23:38 -08001139 memset(platform_info_file, 0, sizeof(platform_info_file));
1140 strlcpy(platform_info_file, PLATFORM_INFO_XML_PATH, MIXER_PATH_MAX_LENGTH);
Jaekyun Seokf62e17d2017-03-08 17:15:28 +09001141 resolveConfigFile(platform_info_file);
vivek mehta60ea4152016-02-18 17:10:26 -08001142 }
1143 }
Uday Kishore Pasupuleti11dd2232015-06-24 14:18:01 -07001144 }
1145
vivek mehtade4849c2016-03-03 17:23:38 -08001146 /* Initialize platform specific ids and/or backends*/
1147 platform_info_init(platform_info_file, my_data);
1148
1149 /* validate the sound card name
1150 * my_data->snd_card_name can contain
1151 * <a> complete sound card name, i.e. <device>-<codec>-<form_factor>-snd-card
1152 * example: msm8994-tomtom-mtp-snd-card
1153 * <b> or sub string of the card name, i.e. <device>-<codec>
1154 * example: msm8994-tomtom
Eric Laurentf9583c32016-03-28 13:50:50 -07001155 * snd_card_name is truncated to 32 charaters as per mixer_get_name() implementation
1156 * so use min of my_data->snd_card_name and snd_card_name length for comparison
vivek mehtade4849c2016-03-03 17:23:38 -08001157 */
1158
1159 if (my_data->snd_card_name != NULL &&
Eric Laurentf9583c32016-03-28 13:50:50 -07001160 strncmp(snd_card_name, my_data->snd_card_name,
1161 min(strlen(snd_card_name), strlen(my_data->snd_card_name))) != 0) {
vivek mehtade4849c2016-03-03 17:23:38 -08001162 ALOGI("%s: found valid sound card %s, but not primary sound card %s",
1163 __func__, snd_card_name, my_data->snd_card_name);
vivek mehta2b0e5a62016-09-02 17:31:58 -07001164 ++snd_card_num;
1165 mixer_close(adev->mixer);
1166 adev->mixer = NULL;
vivek mehtade4849c2016-03-03 17:23:38 -08001167 hw_info_deinit(my_data->hw_info);
1168 my_data->hw_info = NULL;
1169 continue;
Ed Tam70b5c142016-03-21 19:14:29 -07001170 }
vivek mehtade4849c2016-03-03 17:23:38 -08001171 ALOGI("%s: found sound card %s, primary sound card expeted is %s",
1172 __func__, snd_card_name, my_data->snd_card_name);
vivek mehta60ea4152016-02-18 17:10:26 -08001173
1174 ALOGD("%s: Loading mixer file: %s", __func__, mixer_xml_file);
1175 adev->audio_route = audio_route_init(snd_card_num, mixer_xml_file);
1176
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001177 if (!adev->audio_route) {
1178 ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
vivek mehta2b0e5a62016-09-02 17:31:58 -07001179 mixer_close(adev->mixer);
1180 adev->mixer = NULL;
1181 hw_info_deinit(my_data->hw_info);
1182 my_data->hw_info = NULL;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001183 goto init_failed;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001184 }
1185 adev->snd_card = snd_card_num;
Eric Laurent2bafff12016-03-17 12:17:23 -07001186 ALOGD("%s: Opened sound card:%d", __func__, snd_card_num);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001187 break;
sangwoo1b9f4b32013-06-21 18:22:55 -07001188 }
1189
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09001190 //set max volume step for voice call
1191 property_get("ro.config.vc_call_vol_steps", value, TOSTRING(MAX_VOL_INDEX));
1192 my_data->max_vol_index = atoi(value);
1193
vivek mehta65ad12d2015-08-13 18:32:48 -07001194 property_get("persist.audio.dualmic.config",value,"");
1195 if (!strcmp("endfire", value)) {
1196 dual_mic_config = true;
1197 }
1198
Prashant Malanic92c5962015-08-11 15:10:18 -07001199 my_data->source_mic_type = SOURCE_DUAL_MIC;
1200
Eric Laurentb23d5282013-05-14 15:27:20 -07001201 my_data->fluence_in_spkr_mode = false;
1202 my_data->fluence_in_voice_call = false;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001203 my_data->fluence_in_voice_comm = false;
Eric Laurentb23d5282013-05-14 15:27:20 -07001204 my_data->fluence_in_voice_rec = false;
1205
vivek mehta65ad12d2015-08-13 18:32:48 -07001206 property_get("ro.qc.sdk.audio.fluencetype", value, "none");
Prashant Malanic92c5962015-08-11 15:10:18 -07001207 if (!strcmp("fluencepro", value)) {
1208 my_data->fluence_type = FLUENCE_PRO_ENABLE;
vivek mehta65ad12d2015-08-13 18:32:48 -07001209 } else if (!strcmp("fluence", value) || (dual_mic_config)) {
Prashant Malanic92c5962015-08-11 15:10:18 -07001210 my_data->fluence_type = FLUENCE_ENABLE;
1211 } else if (!strcmp("none", value)) {
1212 my_data->fluence_type = FLUENCE_DISABLE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001213 }
1214
Prashant Malanic92c5962015-08-11 15:10:18 -07001215 if (my_data->fluence_type != FLUENCE_DISABLE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001216 property_get("persist.audio.fluence.voicecall",value,"");
1217 if (!strcmp("true", value)) {
1218 my_data->fluence_in_voice_call = true;
1219 }
1220
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001221 property_get("persist.audio.fluence.voicecomm",value,"");
1222 if (!strcmp("true", value)) {
1223 my_data->fluence_in_voice_comm = true;
1224 }
1225
Eric Laurentb23d5282013-05-14 15:27:20 -07001226 property_get("persist.audio.fluence.voicerec",value,"");
1227 if (!strcmp("true", value)) {
1228 my_data->fluence_in_voice_rec = true;
1229 }
1230
1231 property_get("persist.audio.fluence.speaker",value,"");
1232 if (!strcmp("true", value)) {
1233 my_data->fluence_in_spkr_mode = true;
1234 }
1235 }
1236
Prashant Malanic92c5962015-08-11 15:10:18 -07001237 // support max to mono, example if max count is 3, usecase supports Three, dual and mono mic
1238 switch (my_data->max_mic_count) {
1239 case 4:
1240 my_data->source_mic_type |= SOURCE_QUAD_MIC;
1241 case 3:
1242 my_data->source_mic_type |= SOURCE_THREE_MIC;
1243 case 2:
1244 my_data->source_mic_type |= SOURCE_DUAL_MIC;
1245 case 1:
1246 my_data->source_mic_type |= SOURCE_MONO_MIC;
1247 break;
1248 default:
1249 ALOGE("%s: max_mic_count (%d), is not supported, setting to default",
1250 __func__, my_data->max_mic_count);
1251 my_data->source_mic_type = SOURCE_MONO_MIC|SOURCE_DUAL_MIC;
1252 break;
1253 }
1254
1255 ALOGV("%s: Fluence_Type(%d) max_mic_count(%d) mic_type(0x%x) fluence_in_voice_call(%d)"
1256 " fluence_in_voice_comm(%d) fluence_in_voice_rec(%d) fluence_in_spkr_mode(%d) ",
1257 __func__, my_data->fluence_type, my_data->max_mic_count, my_data->source_mic_type,
1258 my_data->fluence_in_voice_call, my_data->fluence_in_voice_comm,
1259 my_data->fluence_in_voice_rec, my_data->fluence_in_spkr_mode);
1260
Eric Laurentb23d5282013-05-14 15:27:20 -07001261 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
1262 if (my_data->acdb_handle == NULL) {
1263 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
1264 } else {
1265 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
1266 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
1267 "acdb_loader_deallocate_ACDB");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001268 if (!my_data->acdb_deallocate)
1269 ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s",
1270 __func__, LIB_ACDB_LOADER);
1271
Eric Laurentb23d5282013-05-14 15:27:20 -07001272 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
1273 "acdb_loader_send_audio_cal");
1274 if (!my_data->acdb_send_audio_cal)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001275 ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s",
Eric Laurentb23d5282013-05-14 15:27:20 -07001276 __func__, LIB_ACDB_LOADER);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001277
Eric Laurentb23d5282013-05-14 15:27:20 -07001278 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
1279 "acdb_loader_send_voice_cal");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001280 if (!my_data->acdb_send_voice_cal)
1281 ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s",
1282 __func__, LIB_ACDB_LOADER);
1283
1284 my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle,
1285 "acdb_loader_reload_vocvoltable");
1286 if (!my_data->acdb_reload_vocvoltable)
1287 ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s",
1288 __func__, LIB_ACDB_LOADER);
vivek mehta1a9b7c02015-06-25 11:49:38 -07001289
1290 my_data->acdb_send_gain_dep_cal = (acdb_send_gain_dep_cal_t)dlsym(my_data->acdb_handle,
1291 "acdb_loader_send_gain_dep_cal");
1292 if (!my_data->acdb_send_gain_dep_cal)
1293 ALOGV("%s: Could not find the symbol acdb_loader_send_gain_dep_cal from %s",
1294 __func__, LIB_ACDB_LOADER);
1295
Thierry Strudel92232b42017-01-26 10:51:48 -08001296#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998)
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001297 acdb_init_v2_cvd_t acdb_init;
1298 acdb_init = (acdb_init_v2_cvd_t)dlsym(my_data->acdb_handle,
1299 "acdb_loader_init_v2");
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001300 if (acdb_init == NULL)
1301 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1302 dlerror());
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001303
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001304#elif defined (PLATFORM_MSM8084)
1305 acdb_init_v2_t acdb_init;
1306 acdb_init = (acdb_init_v2_t)dlsym(my_data->acdb_handle,
1307 "acdb_loader_init_v2");
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001308 if (acdb_init == NULL)
1309 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1310 dlerror());
1311
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001312#else
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001313 acdb_init_t acdb_init;
1314 acdb_init = (acdb_init_t)dlsym(my_data->acdb_handle,
Eric Laurentb23d5282013-05-14 15:27:20 -07001315 "acdb_loader_init_ACDB");
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001316 if (acdb_init == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001317 ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__,
1318 dlerror());
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001319#endif
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001320 my_data->acdb_init = acdb_init;
Eric Laurentb23d5282013-05-14 15:27:20 -07001321
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001322 my_data->acdb_send_custom_top = (acdb_send_custom_top_t)
1323 dlsym(my_data->acdb_handle,
1324 "acdb_loader_send_common_custom_topology");
1325
1326 if (!my_data->acdb_send_custom_top)
1327 ALOGE("%s: Could not find the symbol acdb_get_default_app_type from %s",
1328 __func__, LIB_ACDB_LOADER);
1329
1330 platform_acdb_init(my_data);
1331 }
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001332
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001333 audio_extn_spkr_prot_init(adev);
Haynes Mathew George98c95622014-06-20 19:14:25 -07001334
Ravi Kumar Alamanda76315572015-04-23 13:13:56 -07001335 audio_extn_hwdep_cal_send(adev->snd_card, my_data->acdb_handle);
1336
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001337 /* load csd client */
1338 platform_csd_init(my_data);
1339
Eric Laurentb23d5282013-05-14 15:27:20 -07001340 return my_data;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001341
1342init_failed:
1343 if (my_data)
1344 free(my_data);
1345 return NULL;
Eric Laurentb23d5282013-05-14 15:27:20 -07001346}
1347
1348void platform_deinit(void *platform)
1349{
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001350 int32_t dev;
keunhui.park2f7306a2015-07-16 16:48:06 +09001351 struct operator_info *info_item;
1352 struct operator_specific_device *device_item;
1353 struct listnode *node;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001354
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001355 struct platform_data *my_data = (struct platform_data *)platform;
1356 close_csd_client(my_data->csd);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001357
vivek mehtade4849c2016-03-03 17:23:38 -08001358 hw_info_deinit(my_data->hw_info);
1359
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001360 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1361 if (backend_tag_table[dev])
1362 free(backend_tag_table[dev]);
1363 if (hw_interface_table[dev])
1364 free(hw_interface_table[dev]);
keunhui.park2f7306a2015-07-16 16:48:06 +09001365 if (operator_specific_device_table[dev]) {
1366 while (!list_empty(operator_specific_device_table[dev])) {
1367 node = list_head(operator_specific_device_table[dev]);
1368 list_remove(node);
1369 device_item = node_to_item(node, struct operator_specific_device, list);
1370 free(device_item->operator);
1371 free(device_item->mixer_path);
1372 free(device_item);
1373 }
1374 free(operator_specific_device_table[dev]);
1375 }
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001376 }
1377
1378 if (my_data->snd_card_name)
1379 free(my_data->snd_card_name);
1380
keunhui.park2f7306a2015-07-16 16:48:06 +09001381 while (!list_empty(&operator_info_list)) {
1382 node = list_head(&operator_info_list);
1383 list_remove(node);
1384 info_item = node_to_item(node, struct operator_info, list);
1385 free(info_item->name);
1386 free(info_item->mccmnc);
1387 free(info_item);
1388 }
1389
Eric Laurentb23d5282013-05-14 15:27:20 -07001390 free(platform);
1391}
1392
1393const char *platform_get_snd_device_name(snd_device_t snd_device)
1394{
keunhui.park2f7306a2015-07-16 16:48:06 +09001395 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1396 if (operator_specific_device_table[snd_device] != NULL) {
1397 return get_operator_specific_device_mixer_path(snd_device);
1398 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001399 return device_table[snd_device];
keunhui.park2f7306a2015-07-16 16:48:06 +09001400 } else
Ravi Kumar Alamanda64026462014-09-15 00:08:58 -07001401 return "none";
Eric Laurentb23d5282013-05-14 15:27:20 -07001402}
1403
vivek mehtade4849c2016-03-03 17:23:38 -08001404int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
1405 char *device_name)
1406{
1407 struct platform_data *my_data = (struct platform_data *)platform;
1408
David Benjamin1565f992016-09-21 12:10:34 -04001409 if (platform == NULL) {
vivek mehtade4849c2016-03-03 17:23:38 -08001410 ALOGW("%s: something wrong, use legacy get_snd_device name", __func__);
David Benjamin1565f992016-09-21 12:10:34 -04001411 strlcpy(device_name, platform_get_snd_device_name(snd_device),
1412 DEVICE_NAME_MAX_SIZE);
vivek mehtade4849c2016-03-03 17:23:38 -08001413 } else if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1414 if (operator_specific_device_table[snd_device] != NULL) {
1415 strlcpy(device_name, get_operator_specific_device_mixer_path(snd_device),
1416 DEVICE_NAME_MAX_SIZE);
1417 } else {
1418 strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE);
1419 }
1420 hw_info_append_hw_type(my_data->hw_info, snd_device, device_name);
1421 } else {
1422 strlcpy(device_name, "none", DEVICE_NAME_MAX_SIZE);
1423 }
1424
1425 return 0;
1426}
1427
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001428void platform_add_backend_name(void *platform, char *mixer_path,
1429 snd_device_t snd_device)
Eric Laurentb23d5282013-05-14 15:27:20 -07001430{
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001431 struct platform_data *my_data = (struct platform_data *)platform;
1432
Haynes Mathew George98c95622014-06-20 19:14:25 -07001433 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1434 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1435 return;
Ravi Kumar Alamanda1de6e5a2014-06-19 21:55:39 -05001436 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001437
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001438 const char * suffix = backend_tag_table[snd_device];
Haynes Mathew George98c95622014-06-20 19:14:25 -07001439
1440 if (suffix != NULL) {
1441 strcat(mixer_path, " ");
1442 strcat(mixer_path, suffix);
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001443 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001444}
1445
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001446bool platform_check_backends_match(snd_device_t snd_device1, snd_device_t snd_device2)
1447{
1448 bool result = true;
1449
1450 ALOGV("%s: snd_device1 = %s, snd_device2 = %s", __func__,
1451 platform_get_snd_device_name(snd_device1),
1452 platform_get_snd_device_name(snd_device2));
1453
1454 if ((snd_device1 < SND_DEVICE_MIN) || (snd_device1 >= SND_DEVICE_MAX)) {
1455 ALOGE("%s: Invalid snd_device = %s", __func__,
1456 platform_get_snd_device_name(snd_device1));
1457 return false;
1458 }
1459 if ((snd_device2 < SND_DEVICE_MIN) || (snd_device2 >= SND_DEVICE_MAX)) {
1460 ALOGE("%s: Invalid snd_device = %s", __func__,
1461 platform_get_snd_device_name(snd_device2));
1462 return false;
1463 }
1464 const char * be_itf1 = hw_interface_table[snd_device1];
1465 const char * be_itf2 = hw_interface_table[snd_device2];
1466
1467 if (NULL != be_itf1 && NULL != be_itf2) {
Eric Laurente63e61d2015-09-10 12:19:33 -07001468 if ((NULL == strstr(be_itf2, be_itf1)) && (NULL == strstr(be_itf1, be_itf2)))
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001469 result = false;
1470 }
1471
1472 ALOGV("%s: be_itf1 = %s, be_itf2 = %s, match %d", __func__, be_itf1, be_itf2, result);
1473 return result;
1474}
1475
Eric Laurentb23d5282013-05-14 15:27:20 -07001476int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
1477{
1478 int device_id;
1479 if (device_type == PCM_PLAYBACK)
1480 device_id = pcm_device_table[usecase][0];
1481 else
1482 device_id = pcm_device_table[usecase][1];
1483 return device_id;
1484}
1485
Haynes Mathew George98c95622014-06-20 19:14:25 -07001486static int find_index(const struct name_to_index * table, int32_t len,
1487 const char * name)
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001488{
1489 int ret = 0;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001490 int32_t i;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001491
Haynes Mathew George98c95622014-06-20 19:14:25 -07001492 if (table == NULL) {
1493 ALOGE("%s: table is NULL", __func__);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001494 ret = -ENODEV;
1495 goto done;
1496 }
1497
Haynes Mathew George98c95622014-06-20 19:14:25 -07001498 if (name == NULL) {
1499 ALOGE("null key");
1500 ret = -ENODEV;
1501 goto done;
1502 }
1503
1504 for (i=0; i < len; i++) {
1505 if (!strcmp(table[i].name, name)) {
1506 ret = table[i].index;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001507 goto done;
1508 }
1509 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001510 ALOGE("%s: Could not find index for name = %s",
1511 __func__, name);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001512 ret = -ENODEV;
1513done:
1514 return ret;
1515}
1516
Haynes Mathew George98c95622014-06-20 19:14:25 -07001517int platform_get_snd_device_index(char *device_name)
1518{
1519 return find_index(snd_device_name_index, SND_DEVICE_MAX, device_name);
1520}
1521
1522int platform_get_usecase_index(const char *usecase_name)
1523{
1524 return find_index(usecase_name_index, AUDIO_USECASE_MAX, usecase_name);
1525}
1526
keunhui.park2f7306a2015-07-16 16:48:06 +09001527void platform_add_operator_specific_device(snd_device_t snd_device,
1528 const char *operator,
1529 const char *mixer_path,
1530 unsigned int acdb_id)
1531{
1532 struct operator_specific_device *device;
1533
1534 if (operator_specific_device_table[snd_device] == NULL) {
1535 operator_specific_device_table[snd_device] =
1536 (struct listnode *)calloc(1, sizeof(struct listnode));
1537 list_init(operator_specific_device_table[snd_device]);
1538 }
1539
1540 device = (struct operator_specific_device *)calloc(1, sizeof(struct operator_specific_device));
1541
1542 device->operator = strdup(operator);
1543 device->mixer_path = strdup(mixer_path);
1544 device->acdb_id = acdb_id;
1545
1546 list_add_tail(operator_specific_device_table[snd_device], &device->list);
1547
Eric Laurent2bafff12016-03-17 12:17:23 -07001548 ALOGD("%s: device[%s] -> operator[%s] mixer_path[%s] acdb_id[%d]", __func__,
keunhui.park2f7306a2015-07-16 16:48:06 +09001549 platform_get_snd_device_name(snd_device), operator, mixer_path, acdb_id);
1550
1551}
1552
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001553int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
1554{
1555 int ret = 0;
1556
1557 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1558 ALOGE("%s: Invalid snd_device = %d",
1559 __func__, snd_device);
1560 ret = -EINVAL;
1561 goto done;
1562 }
1563
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001564 ALOGV("%s: acdb_device_table[%s]: old = %d new = %d", __func__,
1565 platform_get_snd_device_name(snd_device), acdb_device_table[snd_device], acdb_id);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001566 acdb_device_table[snd_device] = acdb_id;
1567done:
1568 return ret;
1569}
1570
Glenn Kastencbe06ca2016-11-09 10:49:26 -08001571int platform_get_default_app_type_v2(void *platform __unused, usecase_type_t type __unused,
1572 int *app_type __unused)
Yamit Mehtae3b99562016-09-16 22:44:00 +05301573{
1574 ALOGE("%s: Not implemented", __func__);
1575 return -ENOSYS;
1576}
1577
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001578int platform_get_snd_device_acdb_id(snd_device_t snd_device)
1579{
1580 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1581 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1582 return -EINVAL;
1583 }
keunhui.park2f7306a2015-07-16 16:48:06 +09001584
1585 if (operator_specific_device_table[snd_device] != NULL)
1586 return get_operator_specific_device_acdb_id(snd_device);
1587 else
1588 return acdb_device_table[snd_device];
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001589}
1590
Eric Laurentb23d5282013-05-14 15:27:20 -07001591int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
1592{
1593 struct platform_data *my_data = (struct platform_data *)platform;
1594 int acdb_dev_id, acdb_dev_type;
1595
Ravi Kumar Alamandaadf0f3b2015-06-04 02:34:02 -07001596 acdb_dev_id = acdb_device_table[audio_extn_get_spkr_prot_snd_device(snd_device)];
Eric Laurentb23d5282013-05-14 15:27:20 -07001597 if (acdb_dev_id < 0) {
1598 ALOGE("%s: Could not find acdb id for device(%d)",
1599 __func__, snd_device);
1600 return -EINVAL;
1601 }
1602 if (my_data->acdb_send_audio_cal) {
Joe Onorato188b6222016-03-01 11:02:27 -08001603 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Eric Laurentb23d5282013-05-14 15:27:20 -07001604 __func__, snd_device, acdb_dev_id);
1605 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
1606 snd_device < SND_DEVICE_OUT_END)
1607 acdb_dev_type = ACDB_DEV_TYPE_OUT;
1608 else
1609 acdb_dev_type = ACDB_DEV_TYPE_IN;
1610 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
1611 }
1612 return 0;
1613}
1614
1615int platform_switch_voice_call_device_pre(void *platform)
1616{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001617 struct platform_data *my_data = (struct platform_data *)platform;
1618 int ret = 0;
1619
1620 if (my_data->csd != NULL &&
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001621 voice_is_in_call(my_data->adev)) {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001622 /* This must be called before disabling mixer controls on APQ side */
1623 ret = my_data->csd->disable_device();
1624 if (ret < 0) {
1625 ALOGE("%s: csd_client_disable_device, failed, error %d",
1626 __func__, ret);
1627 }
1628 }
1629 return ret;
1630}
1631
1632int platform_switch_voice_call_enable_device_config(void *platform,
1633 snd_device_t out_snd_device,
1634 snd_device_t in_snd_device)
1635{
1636 struct platform_data *my_data = (struct platform_data *)platform;
1637 int acdb_rx_id, acdb_tx_id;
1638 int ret = 0;
1639
1640 if (my_data->csd == NULL)
1641 return ret;
1642
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001643 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1644 audio_extn_spkr_prot_is_enabled())
keunhui.park2f7306a2015-07-16 16:48:06 +09001645 acdb_rx_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_SPEAKER_PROTECTED);
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001646 else
keunhui.park2f7306a2015-07-16 16:48:06 +09001647 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001648
keunhui.park2f7306a2015-07-16 16:48:06 +09001649 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001650
1651 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
1652 ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
1653 if (ret < 0) {
1654 ALOGE("%s: csd_enable_device_config, failed, error %d",
1655 __func__, ret);
1656 }
1657 } else {
1658 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1659 acdb_rx_id, acdb_tx_id);
1660 }
1661
1662 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001663}
1664
1665int platform_switch_voice_call_device_post(void *platform,
1666 snd_device_t out_snd_device,
1667 snd_device_t in_snd_device)
1668{
1669 struct platform_data *my_data = (struct platform_data *)platform;
1670 int acdb_rx_id, acdb_tx_id;
1671
1672 if (my_data->acdb_send_voice_cal == NULL) {
1673 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
1674 } else {
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001675 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1676 audio_extn_spkr_prot_is_enabled())
1677 out_snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED;
1678
keunhui.park2f7306a2015-07-16 16:48:06 +09001679 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
1680 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07001681
1682 if (acdb_rx_id > 0 && acdb_tx_id > 0)
1683 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
1684 else
1685 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1686 acdb_rx_id, acdb_tx_id);
1687 }
1688
1689 return 0;
1690}
1691
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001692int platform_switch_voice_call_usecase_route_post(void *platform,
1693 snd_device_t out_snd_device,
1694 snd_device_t in_snd_device)
1695{
1696 struct platform_data *my_data = (struct platform_data *)platform;
1697 int acdb_rx_id, acdb_tx_id;
1698 int ret = 0;
1699
1700 if (my_data->csd == NULL)
1701 return ret;
1702
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001703 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1704 audio_extn_spkr_prot_is_enabled())
keunhui.park2f7306a2015-07-16 16:48:06 +09001705 acdb_rx_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED);
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001706 else
keunhui.park2f7306a2015-07-16 16:48:06 +09001707 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001708
keunhui.park2f7306a2015-07-16 16:48:06 +09001709 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001710
1711 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
1712 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
1713 my_data->adev->acdb_settings);
1714 if (ret < 0) {
1715 ALOGE("%s: csd_enable_device, failed, error %d", __func__, ret);
1716 }
1717 } else {
1718 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1719 acdb_rx_id, acdb_tx_id);
1720 }
1721
1722 return ret;
1723}
1724
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001725int platform_start_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07001726{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001727 struct platform_data *my_data = (struct platform_data *)platform;
1728 int ret = 0;
1729
1730 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001731 ret = my_data->csd->start_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001732 if (ret < 0) {
1733 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
1734 }
1735 }
1736 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001737}
1738
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001739int platform_stop_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07001740{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001741 struct platform_data *my_data = (struct platform_data *)platform;
1742 int ret = 0;
1743
1744 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001745 ret = my_data->csd->stop_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001746 if (ret < 0) {
1747 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
1748 }
1749 }
1750 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001751}
1752
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001753int platform_get_sample_rate(void *platform, uint32_t *rate)
1754{
1755 struct platform_data *my_data = (struct platform_data *)platform;
1756 int ret = 0;
1757
1758 if (my_data->csd != NULL) {
1759 ret = my_data->csd->get_sample_rate(rate);
1760 if (ret < 0) {
1761 ALOGE("%s: csd_get_sample_rate error %d\n", __func__, ret);
1762 }
1763 }
1764 return ret;
1765}
1766
vivek mehtab6506412015-08-07 16:55:17 -07001767void platform_set_speaker_gain_in_combo(struct audio_device *adev,
1768 snd_device_t snd_device,
1769 bool enable)
1770{
1771 const char* name;
1772 switch (snd_device) {
1773 case SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES:
1774 if (enable)
1775 name = "spkr-gain-in-headphone-combo";
1776 else
1777 name = "speaker-gain-default";
1778 break;
1779 case SND_DEVICE_OUT_SPEAKER_AND_LINE:
1780 if (enable)
1781 name = "spkr-gain-in-line-combo";
1782 else
1783 name = "speaker-gain-default";
1784 break;
1785 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES:
1786 if (enable)
1787 name = "spkr-safe-gain-in-headphone-combo";
1788 else
1789 name = "speaker-safe-gain-default";
1790 break;
1791 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE:
1792 if (enable)
1793 name = "spkr-safe-gain-in-line-combo";
1794 else
1795 name = "speaker-safe-gain-default";
1796 break;
1797 default:
1798 return;
1799 }
1800
1801 audio_route_apply_and_update_path(adev->audio_route, name);
1802}
1803
Eric Laurentb23d5282013-05-14 15:27:20 -07001804int platform_set_voice_volume(void *platform, int volume)
1805{
1806 struct platform_data *my_data = (struct platform_data *)platform;
1807 struct audio_device *adev = my_data->adev;
1808 struct mixer_ctl *ctl;
sangwoo53b2cf02013-07-25 19:18:44 -07001809 const char *mixer_ctl_name = "Voice Rx Gain";
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001810 int vol_index = 0, ret = 0;
1811 uint32_t set_values[ ] = {0,
1812 ALL_SESSION_VSID,
1813 DEFAULT_VOLUME_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07001814
1815 // Voice volume levels are mapped to adsp volume levels as follows.
1816 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
1817 // But this values don't changed in kernel. So, below change is need.
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09001818 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, my_data->max_vol_index);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001819 set_values[0] = vol_index;
Eric Laurentb23d5282013-05-14 15:27:20 -07001820
1821 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1822 if (!ctl) {
1823 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1824 __func__, mixer_ctl_name);
1825 return -EINVAL;
1826 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001827 ALOGV("Setting voice volume index: %d", set_values[0]);
1828 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1829
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001830 if (my_data->csd != NULL) {
1831 ret = my_data->csd->volume(ALL_SESSION_VSID, volume,
1832 DEFAULT_VOLUME_RAMP_DURATION_MS);
1833 if (ret < 0) {
1834 ALOGE("%s: csd_volume error %d", __func__, ret);
1835 }
1836 }
1837 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001838}
1839
1840int platform_set_mic_mute(void *platform, bool state)
1841{
1842 struct platform_data *my_data = (struct platform_data *)platform;
1843 struct audio_device *adev = my_data->adev;
1844 struct mixer_ctl *ctl;
1845 const char *mixer_ctl_name = "Voice Tx Mute";
sangwoo53b2cf02013-07-25 19:18:44 -07001846 int ret = 0;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001847 uint32_t set_values[ ] = {0,
1848 ALL_SESSION_VSID,
1849 DEFAULT_MUTE_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07001850
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09001851 if (adev->mode != AUDIO_MODE_IN_CALL &&
1852 adev->mode != AUDIO_MODE_IN_COMMUNICATION)
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001853 return 0;
1854
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09001855 if (adev->enable_hfp)
1856 mixer_ctl_name = "HFP Tx Mute";
1857
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001858 set_values[0] = state;
1859 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1860 if (!ctl) {
1861 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1862 __func__, mixer_ctl_name);
1863 return -EINVAL;
1864 }
1865 ALOGV("Setting voice mute state: %d", state);
1866 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1867
1868 if (my_data->csd != NULL) {
1869 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state,
1870 DEFAULT_MUTE_RAMP_DURATION_MS);
sangwoo53b2cf02013-07-25 19:18:44 -07001871 if (ret < 0) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001872 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
sangwoo53b2cf02013-07-25 19:18:44 -07001873 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001874 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001875 return ret;
1876}
Eric Laurentb23d5282013-05-14 15:27:20 -07001877
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001878int platform_set_device_mute(void *platform, bool state, char *dir)
1879{
1880 struct platform_data *my_data = (struct platform_data *)platform;
1881 struct audio_device *adev = my_data->adev;
1882 struct mixer_ctl *ctl;
1883 char *mixer_ctl_name = NULL;
1884 int ret = 0;
1885 uint32_t set_values[ ] = {0,
1886 ALL_SESSION_VSID,
1887 0};
1888 if(dir == NULL) {
1889 ALOGE("%s: Invalid direction:%s", __func__, dir);
1890 return -EINVAL;
1891 }
1892
1893 if (!strncmp("rx", dir, sizeof("rx"))) {
1894 mixer_ctl_name = "Voice Rx Device Mute";
1895 } else if (!strncmp("tx", dir, sizeof("tx"))) {
1896 mixer_ctl_name = "Voice Tx Device Mute";
1897 } else {
1898 return -EINVAL;
1899 }
1900
1901 set_values[0] = state;
1902 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1903 if (!ctl) {
1904 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1905 __func__, mixer_ctl_name);
1906 return -EINVAL;
1907 }
1908
1909 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
1910 __func__,state, mixer_ctl_name);
1911 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1912
1913 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001914}
1915
Haynes Mathew George2d809e02016-09-22 17:38:16 -07001916int platform_can_split_snd_device(snd_device_t snd_device,
1917 int *num_devices,
1918 snd_device_t *new_snd_devices)
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001919{
Haynes Mathew George2d809e02016-09-22 17:38:16 -07001920 int ret = -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001921 if (NULL == num_devices || NULL == new_snd_devices) {
1922 ALOGE("%s: NULL pointer ..", __func__);
Haynes Mathew George2d809e02016-09-22 17:38:16 -07001923 return -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001924 }
1925
1926 /*
1927 * If wired headset/headphones/line devices share the same backend
Haynes Mathew George2d809e02016-09-22 17:38:16 -07001928 * with speaker/earpiece this routine returns -EINVAL.
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001929 */
1930 if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES &&
1931 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_HEADPHONES)) {
1932 *num_devices = 2;
1933 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
1934 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07001935 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001936 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_LINE &&
1937 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_LINE)) {
1938 *num_devices = 2;
1939 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
1940 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07001941 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001942 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES &&
1943 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_HEADPHONES)) {
1944 *num_devices = 2;
1945 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
1946 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07001947 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001948 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE &&
1949 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_LINE)) {
1950 *num_devices = 2;
1951 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
1952 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07001953 ret = 0;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08001954 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO &&
1955 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
1956 SND_DEVICE_OUT_BT_SCO)) {
1957 *num_devices = 2;
1958 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
1959 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO;
1960 ret = 0;
1961 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB &&
1962 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
1963 SND_DEVICE_OUT_BT_SCO_WB)) {
1964 *num_devices = 2;
1965 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
1966 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO_WB;
1967 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001968 }
Haynes Mathew George2d809e02016-09-22 17:38:16 -07001969 return ret;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001970}
1971
Eric Laurentb23d5282013-05-14 15:27:20 -07001972snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
1973{
1974 struct platform_data *my_data = (struct platform_data *)platform;
1975 struct audio_device *adev = my_data->adev;
1976 audio_mode_t mode = adev->mode;
1977 snd_device_t snd_device = SND_DEVICE_NONE;
1978
1979 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
1980 if (devices == AUDIO_DEVICE_NONE ||
1981 devices & AUDIO_DEVICE_BIT_IN) {
1982 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
1983 goto exit;
1984 }
1985
Eric Laurent1b491552015-09-15 17:52:41 -07001986 if (popcount(devices) == 2) {
1987 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
1988 AUDIO_DEVICE_OUT_SPEAKER) ||
1989 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
1990 AUDIO_DEVICE_OUT_SPEAKER)) {
1991 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
1992 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
1993 AUDIO_DEVICE_OUT_SPEAKER)) {
1994 snd_device = SND_DEVICE_OUT_SPEAKER_AND_LINE;
1995 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
1996 AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
1997 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
1998 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
1999 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES;
2000 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2001 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2002 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE;
2003 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
2004 AUDIO_DEVICE_OUT_SPEAKER)) {
2005 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002006 } else if ((devices & AUDIO_DEVICE_OUT_ALL_SCO) &&
2007 ((devices & ~AUDIO_DEVICE_OUT_ALL_SCO) == AUDIO_DEVICE_OUT_SPEAKER)) {
2008 snd_device = adev->bt_wb_speech_enabled ?
2009 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB :
2010 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO;
Eric Laurent1b491552015-09-15 17:52:41 -07002011 } else {
2012 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
2013 goto exit;
2014 }
2015 if (snd_device != SND_DEVICE_NONE) {
2016 goto exit;
2017 }
2018 }
2019
2020 if (popcount(devices) != 1) {
2021 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
2022 goto exit;
2023 }
2024
Madhuri Athota3f6051b2016-10-13 23:25:38 +05302025 if (voice_is_in_call(adev) || adev->enable_voicerx || audio_extn_hfp_is_active(adev)) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002026 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002027 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2028 devices & AUDIO_DEVICE_OUT_LINE) {
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002029 if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002030 (adev->voice.tty_mode == TTY_MODE_FULL))
Eric Laurentb23d5282013-05-14 15:27:20 -07002031 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002032 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002033 (adev->voice.tty_mode == TTY_MODE_VCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002034 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002035 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002036 (adev->voice.tty_mode == TTY_MODE_HCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002037 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002038 else {
2039 if (devices & AUDIO_DEVICE_OUT_LINE)
2040 snd_device = SND_DEVICE_OUT_VOICE_LINE;
2041 else
2042 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
2043 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002044 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002045 if (adev->bt_wb_speech_enabled) {
2046 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2047 } else {
2048 snd_device = SND_DEVICE_OUT_BT_SCO;
2049 }
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002050 } else if (devices & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002051 if (!adev->enable_hfp) {
2052 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
2053 } else {
2054 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_HFP;
2055 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002056 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002057 if(adev->voice.hac)
2058 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2059 else if (is_operator_tmus())
Eric Laurentb23d5282013-05-14 15:27:20 -07002060 snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS;
2061 else
Eric Laurentb4d368e2014-06-25 10:21:54 -05002062 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002063 } else if (devices & AUDIO_DEVICE_OUT_TELEPHONY_TX)
2064 snd_device = SND_DEVICE_OUT_VOICE_TX;
2065
Eric Laurentb23d5282013-05-14 15:27:20 -07002066 if (snd_device != SND_DEVICE_NONE) {
2067 goto exit;
2068 }
2069 }
2070
Eric Laurentb23d5282013-05-14 15:27:20 -07002071 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2072 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2073 snd_device = SND_DEVICE_OUT_HEADPHONES;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002074 } else if (devices & AUDIO_DEVICE_OUT_LINE) {
2075 snd_device = SND_DEVICE_OUT_LINE;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002076 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) {
2077 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE;
Eric Laurentb23d5282013-05-14 15:27:20 -07002078 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002079 if (my_data->speaker_lr_swap)
Eric Laurentb23d5282013-05-14 15:27:20 -07002080 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
2081 else
2082 snd_device = SND_DEVICE_OUT_SPEAKER;
2083 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002084 if (adev->bt_wb_speech_enabled) {
2085 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2086 } else {
2087 snd_device = SND_DEVICE_OUT_BT_SCO;
2088 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002089 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2090 snd_device = SND_DEVICE_OUT_HDMI ;
Mikhail Naganov9d677f42017-03-09 16:57:59 +00002091 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002092 /*HAC support for voice-ish audio (eg visual voicemail)*/
2093 if(adev->voice.hac)
2094 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2095 else
2096 snd_device = SND_DEVICE_OUT_HANDSET;
Eric Laurentb23d5282013-05-14 15:27:20 -07002097 } else {
2098 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
2099 }
2100exit:
2101 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
2102 return snd_device;
2103}
2104
2105snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
2106{
2107 struct platform_data *my_data = (struct platform_data *)platform;
2108 struct audio_device *adev = my_data->adev;
2109 audio_source_t source = (adev->active_input == NULL) ?
2110 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
2111
2112 audio_mode_t mode = adev->mode;
2113 audio_devices_t in_device = ((adev->active_input == NULL) ?
2114 AUDIO_DEVICE_NONE : adev->active_input->device)
2115 & ~AUDIO_DEVICE_BIT_IN;
2116 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
2117 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
2118 snd_device_t snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002119 int channel_count = popcount(channel_mask);
Eric Laurentb23d5282013-05-14 15:27:20 -07002120
Prashant Malanic92c5962015-08-11 15:10:18 -07002121 ALOGV("%s: enter: out_device(%#x) in_device(%#x) channel_count (%d) channel_mask (0x%x)",
2122 __func__, out_device, in_device, channel_count, channel_mask);
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002123 if ((out_device != AUDIO_DEVICE_NONE) && voice_is_in_call(adev)) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002124 if (adev->voice.tty_mode != TTY_MODE_OFF) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002125 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002126 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2127 out_device & AUDIO_DEVICE_OUT_LINE) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002128 switch (adev->voice.tty_mode) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002129 case TTY_MODE_FULL:
2130 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
2131 break;
2132 case TTY_MODE_VCO:
2133 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
2134 break;
2135 case TTY_MODE_HCO:
2136 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
2137 break;
2138 default:
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002139 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
Eric Laurentb23d5282013-05-14 15:27:20 -07002140 }
2141 goto exit;
2142 }
2143 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002144 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002145 if (my_data->fluence_in_voice_call == false) {
2146 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2147 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002148 if (is_operator_tmus())
2149 snd_device = SND_DEVICE_IN_VOICE_DMIC_TMUS;
Eric Laurentb23d5282013-05-14 15:27:20 -07002150 else
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002151 snd_device = SND_DEVICE_IN_VOICE_DMIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002152 }
2153 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2154 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
2155 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002156 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002157 if (adev->bluetooth_nrec)
2158 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2159 else
2160 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002161 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002162 if (adev->bluetooth_nrec)
2163 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2164 else
2165 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002166 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002167 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Prashant Malanic92c5962015-08-11 15:10:18 -07002168 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
2169 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2170 out_device & AUDIO_DEVICE_OUT_LINE) {
2171 if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
2172 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
2173 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
2174 } else {
2175 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2176 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002177 }
vivek mehtafe121d52015-08-10 23:39:23 -07002178
2179 //select default
2180 if (snd_device == SND_DEVICE_NONE) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002181 if (!adev->enable_hfp) {
2182 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2183 } else {
2184 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP;
2185 platform_set_echo_reference(adev, true, out_device);
2186 }
vivek mehtafe121d52015-08-10 23:39:23 -07002187 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002188 } else if (out_device & AUDIO_DEVICE_OUT_TELEPHONY_TX) {
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002189 snd_device = SND_DEVICE_IN_VOICE_RX;
Prashant Malanic92c5962015-08-11 15:10:18 -07002190 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002191 } else if (source == AUDIO_SOURCE_CAMCORDER) {
2192 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
2193 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2194 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
2195 }
2196 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
2197 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002198 if (my_data->fluence_in_voice_rec && channel_count == 1) {
2199 if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2200 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002201 if (adev->active_input->enable_aec)
2202 snd_device = SND_DEVICE_IN_HANDSET_QMIC_AEC;
2203 else
2204 snd_device = SND_DEVICE_IN_HANDSET_QMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002205 } else if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2206 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002207 if (adev->active_input->enable_aec)
2208 snd_device = SND_DEVICE_IN_HANDSET_TMIC_AEC;
2209 else
2210 snd_device = SND_DEVICE_IN_HANDSET_TMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002211 } else if (((my_data->fluence_type == FLUENCE_PRO_ENABLE) ||
2212 (my_data->fluence_type == FLUENCE_ENABLE)) &&
2213 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002214 if (adev->active_input->enable_aec)
2215 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
2216 else
2217 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
Prashant Malanic92c5962015-08-11 15:10:18 -07002218 }
2219 platform_set_echo_reference(adev, true, out_device);
2220 } else if ((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) &&
2221 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2222 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002223 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002224 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
2225 snd_device = SND_DEVICE_IN_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002226 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002227 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2228 snd_device = SND_DEVICE_IN_QUAD_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002229 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002230 if (snd_device == SND_DEVICE_NONE) {
vivek mehtaf3440682016-05-11 14:24:37 -07002231 if (adev->active_input->enable_aec) {
2232 if (adev->active_input->enable_ns) {
2233 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS;
2234 } else {
2235 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC;
2236 }
vivek mehta733c1df2016-04-04 15:09:24 -07002237 platform_set_echo_reference(adev, true, out_device);
vivek mehtaf3440682016-05-11 14:24:37 -07002238 } else if (adev->active_input->enable_ns) {
2239 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
2240 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002241 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
vivek mehtaf3440682016-05-11 14:24:37 -07002242 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002243 }
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -07002244 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2245 snd_device = SND_DEVICE_IN_VOICE_REC_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002246 }
rago90fb9612015-12-02 11:37:53 -08002247 } else if (source == AUDIO_SOURCE_UNPROCESSED) {
2248 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
vivek mehta4ed66e62016-04-15 23:33:34 -07002249 if (((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) ||
2250 (channel_mask == AUDIO_CHANNEL_IN_STEREO)) &&
2251 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2252 snd_device = SND_DEVICE_IN_UNPROCESSED_STEREO_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002253 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07002254 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
2255 snd_device = SND_DEVICE_IN_UNPROCESSED_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002256 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07002257 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2258 snd_device = SND_DEVICE_IN_UNPROCESSED_QUAD_MIC;
2259 } else {
2260 snd_device = SND_DEVICE_IN_UNPROCESSED_MIC;
2261 }
rago90fb9612015-12-02 11:37:53 -08002262 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2263 snd_device = SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC;
2264 }
Eric Laurent50a38ed2015-10-14 18:48:06 -07002265 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION ||
rago90fb9612015-12-02 11:37:53 -08002266 mode == AUDIO_MODE_IN_COMMUNICATION) {
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002267 if (out_device & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE))
Eric Laurentb23d5282013-05-14 15:27:20 -07002268 in_device = AUDIO_DEVICE_IN_BACK_MIC;
2269 if (adev->active_input) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002270 if (adev->active_input->enable_aec &&
2271 adev->active_input->enable_ns) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002272 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002273 if (my_data->fluence_in_spkr_mode &&
2274 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002275 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002276 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002277 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002278 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002279 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002280 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002281 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002282 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002283 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002284 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002285 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002286 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002287 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2288 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002289 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002290 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002291 } else if (adev->active_input->enable_aec) {
2292 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2293 if (my_data->fluence_in_spkr_mode &&
2294 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002295 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002296 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002297 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002298 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002299 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002300 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2301 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002302 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002303 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002304 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002305 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002306 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002307 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2308 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
2309 }
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08002310 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002311 } else if (adev->active_input->enable_ns) {
2312 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2313 if (my_data->fluence_in_spkr_mode &&
2314 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002315 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002316 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002317 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002318 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002319 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002320 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2321 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002322 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002323 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002324 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002325 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002326 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002327 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002328 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002329 }
2330 } else if (source == AUDIO_SOURCE_DEFAULT) {
2331 goto exit;
2332 }
2333
2334
2335 if (snd_device != SND_DEVICE_NONE) {
2336 goto exit;
2337 }
2338
2339 if (in_device != AUDIO_DEVICE_NONE &&
2340 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
2341 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
2342 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002343 if ((my_data->source_mic_type & SOURCE_QUAD_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002344 channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002345 snd_device = SND_DEVICE_IN_QUAD_MIC;
2346 } else if ((my_data->source_mic_type & SOURCE_THREE_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002347 channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002348 snd_device = SND_DEVICE_IN_THREE_MIC;
2349 } else if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2350 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002351 snd_device = SND_DEVICE_IN_HANDSET_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002352 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2353 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002354 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002355 } else {
2356 ALOGE("%s: something wrong (1): source type (%d) channel_count (%d) .."
2357 " channel mask (0x%x) no combination found .. setting to mono", __func__,
2358 my_data->source_mic_type, channel_count, channel_mask);
2359 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2360 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002361 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002362 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2363 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002364 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002365 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2366 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002367 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002368 } else {
2369 ALOGE("%s: something wrong (2): source type (%d) channel_count (%d) .."
2370 " no combination found .. setting to mono", __func__,
2371 my_data->source_mic_type, channel_count);
2372 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
2373 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002374 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2375 snd_device = SND_DEVICE_IN_HEADSET_MIC;
2376 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002377 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002378 if (adev->bluetooth_nrec)
2379 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2380 else
2381 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002382 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002383 if (adev->bluetooth_nrec)
2384 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2385 else
2386 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002387 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002388 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
2389 snd_device = SND_DEVICE_IN_HDMI_MIC;
2390 } else {
2391 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
2392 ALOGW("%s: Using default handset-mic", __func__);
2393 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2394 }
2395 } else {
2396 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
2397 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2398 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2399 snd_device = SND_DEVICE_IN_HEADSET_MIC;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002400 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002401 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002402 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002403 out_device & AUDIO_DEVICE_OUT_LINE) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002404 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2405 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002406 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002407 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2408 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002409 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002410 } else {
2411 ALOGE("%s: something wrong (3): source type (%d) channel_count (%d) .."
2412 " no combination found .. setting to mono", __func__,
2413 my_data->source_mic_type, channel_count);
2414 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
2415 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002416 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002417 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002418 if (adev->bluetooth_nrec)
2419 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2420 else
2421 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002422 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002423 if (adev->bluetooth_nrec)
2424 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2425 else
2426 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002427 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002428 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2429 snd_device = SND_DEVICE_IN_HDMI_MIC;
2430 } else {
2431 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
2432 ALOGW("%s: Using default handset-mic", __func__);
2433 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2434 }
2435 }
2436exit:
2437 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
2438 return snd_device;
2439}
2440
2441int platform_set_hdmi_channels(void *platform, int channel_count)
2442{
2443 struct platform_data *my_data = (struct platform_data *)platform;
2444 struct audio_device *adev = my_data->adev;
2445 struct mixer_ctl *ctl;
2446 const char *channel_cnt_str = NULL;
2447 const char *mixer_ctl_name = "HDMI_RX Channels";
2448 switch (channel_count) {
2449 case 8:
2450 channel_cnt_str = "Eight"; break;
2451 case 7:
2452 channel_cnt_str = "Seven"; break;
2453 case 6:
2454 channel_cnt_str = "Six"; break;
2455 case 5:
2456 channel_cnt_str = "Five"; break;
2457 case 4:
2458 channel_cnt_str = "Four"; break;
2459 case 3:
2460 channel_cnt_str = "Three"; break;
2461 default:
2462 channel_cnt_str = "Two"; break;
2463 }
2464 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2465 if (!ctl) {
2466 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2467 __func__, mixer_ctl_name);
2468 return -EINVAL;
2469 }
2470 ALOGV("HDMI channel count: %s", channel_cnt_str);
2471 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
2472 return 0;
2473}
2474
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002475int platform_edid_get_max_channels(void *platform)
Eric Laurentb23d5282013-05-14 15:27:20 -07002476{
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002477 struct platform_data *my_data = (struct platform_data *)platform;
2478 struct audio_device *adev = my_data->adev;
Eric Laurentb23d5282013-05-14 15:27:20 -07002479 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
2480 char *sad = block;
2481 int num_audio_blocks;
2482 int channel_count;
2483 int max_channels = 0;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002484 int i, ret, count;
Eric Laurentb23d5282013-05-14 15:27:20 -07002485
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002486 struct mixer_ctl *ctl;
2487
2488 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
2489 if (!ctl) {
2490 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2491 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
Eric Laurentb23d5282013-05-14 15:27:20 -07002492 return 0;
2493 }
2494
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002495 mixer_ctl_update(ctl);
2496
2497 count = mixer_ctl_get_num_values(ctl);
Eric Laurentb23d5282013-05-14 15:27:20 -07002498
2499 /* Read SAD blocks, clamping the maximum size for safety */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002500 if (count > (int)sizeof(block))
2501 count = (int)sizeof(block);
Eric Laurentb23d5282013-05-14 15:27:20 -07002502
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002503 ret = mixer_ctl_get_array(ctl, block, count);
2504 if (ret != 0) {
2505 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
2506 return 0;
2507 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002508
2509 /* Calculate the number of SAD blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002510 num_audio_blocks = count / SAD_BLOCK_SIZE;
Eric Laurentb23d5282013-05-14 15:27:20 -07002511
2512 for (i = 0; i < num_audio_blocks; i++) {
2513 /* Only consider LPCM blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002514 if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
2515 sad += 3;
Eric Laurentb23d5282013-05-14 15:27:20 -07002516 continue;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002517 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002518
2519 channel_count = (sad[0] & 0x7) + 1;
2520 if (channel_count > max_channels)
2521 max_channels = channel_count;
2522
2523 /* Advance to next block */
2524 sad += 3;
2525 }
2526
2527 return max_channels;
2528}
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07002529
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002530int platform_set_incall_recording_session_id(void *platform,
2531 uint32_t session_id, int rec_mode)
2532{
2533 int ret = 0;
2534 struct platform_data *my_data = (struct platform_data *)platform;
2535 struct audio_device *adev = my_data->adev;
2536 struct mixer_ctl *ctl;
2537 const char *mixer_ctl_name = "Voc VSID";
2538 int num_ctl_values;
2539 int i;
2540
2541 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2542 if (!ctl) {
2543 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2544 __func__, mixer_ctl_name);
2545 ret = -EINVAL;
2546 } else {
2547 num_ctl_values = mixer_ctl_get_num_values(ctl);
2548 for (i = 0; i < num_ctl_values; i++) {
2549 if (mixer_ctl_set_value(ctl, i, session_id)) {
2550 ALOGV("Error: invalid session_id: %x", session_id);
2551 ret = -EINVAL;
2552 break;
2553 }
2554 }
2555 }
2556
2557 if (my_data->csd != NULL) {
2558 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
2559 if (ret < 0) {
2560 ALOGE("%s: csd_client_start_record failed, error %d",
2561 __func__, ret);
2562 }
2563 }
2564
2565 return ret;
2566}
2567
2568int platform_stop_incall_recording_usecase(void *platform)
2569{
2570 int ret = 0;
2571 struct platform_data *my_data = (struct platform_data *)platform;
2572
2573 if (my_data->csd != NULL) {
2574 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
2575 if (ret < 0) {
2576 ALOGE("%s: csd_client_stop_record failed, error %d",
2577 __func__, ret);
2578 }
2579 }
2580
2581 return ret;
2582}
2583
2584int platform_start_incall_music_usecase(void *platform)
2585{
2586 int ret = 0;
2587 struct platform_data *my_data = (struct platform_data *)platform;
2588
2589 if (my_data->csd != NULL) {
2590 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
2591 if (ret < 0) {
2592 ALOGE("%s: csd_client_start_playback failed, error %d",
2593 __func__, ret);
2594 }
2595 }
2596
2597 return ret;
2598}
2599
2600int platform_stop_incall_music_usecase(void *platform)
2601{
2602 int ret = 0;
2603 struct platform_data *my_data = (struct platform_data *)platform;
2604
2605 if (my_data->csd != NULL) {
2606 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
2607 if (ret < 0) {
2608 ALOGE("%s: csd_client_stop_playback failed, error %d",
2609 __func__, ret);
2610 }
2611 }
2612
2613 return ret;
2614}
2615
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002616int platform_set_parameters(void *platform, struct str_parms *parms)
2617{
2618 struct platform_data *my_data = (struct platform_data *)platform;
keunhui.park2f7306a2015-07-16 16:48:06 +09002619 char value[128];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002620 char *kv_pairs = str_parms_to_str(parms);
2621 int ret = 0, err;
2622
2623 if (kv_pairs == NULL) {
2624 ret = -EINVAL;
2625 ALOGE("%s: key-value pair is NULL",__func__);
2626 goto done;
2627 }
2628
2629 ALOGV("%s: enter: %s", __func__, kv_pairs);
2630
2631 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME,
2632 value, sizeof(value));
2633 if (err >= 0) {
2634 str_parms_del(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME);
2635 my_data->snd_card_name = strdup(value);
2636 ALOGV("%s: sound card name %s", __func__, my_data->snd_card_name);
2637 }
2638
keunhui.park2f7306a2015-07-16 16:48:06 +09002639 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO,
2640 value, sizeof(value));
2641 if (err >= 0) {
2642 struct operator_info *info;
2643 char *str = value;
2644 char *name;
2645
2646 str_parms_del(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO);
2647 info = (struct operator_info *)calloc(1, sizeof(struct operator_info));
2648 name = strtok(str, ";");
2649 info->name = strdup(name);
2650 info->mccmnc = strdup(str + strlen(name) + 1);
2651
2652 list_add_tail(&operator_info_list, &info->list);
Joe Onorato188b6222016-03-01 11:02:27 -08002653 ALOGV("%s: add operator[%s] mccmnc[%s]", __func__, info->name, info->mccmnc);
keunhui.park2f7306a2015-07-16 16:48:06 +09002654 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002655
2656 memset(value, 0, sizeof(value));
Eric Laurentc6333382015-09-14 12:43:44 -07002657 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT,
Prashant Malanic92c5962015-08-11 15:10:18 -07002658 value, sizeof(value));
2659 if (err >= 0) {
Eric Laurentc6333382015-09-14 12:43:44 -07002660 str_parms_del(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT);
Prashant Malanic92c5962015-08-11 15:10:18 -07002661 my_data->max_mic_count = atoi(value);
2662 ALOGV("%s: max_mic_count %s/%d", __func__, value, my_data->max_mic_count);
Prashant Malanic92c5962015-08-11 15:10:18 -07002663 }
2664
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002665done:
2666 ALOGV("%s: exit with code(%d)", __func__, ret);
2667 if (kv_pairs != NULL)
2668 free(kv_pairs);
2669
2670 return ret;
2671}
2672
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07002673/* Delay in Us */
2674int64_t platform_render_latency(audio_usecase_t usecase)
2675{
2676 switch (usecase) {
2677 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
2678 return DEEP_BUFFER_PLATFORM_DELAY;
2679 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
2680 return LOW_LATENCY_PLATFORM_DELAY;
Haynes Mathew George03c40102016-01-29 17:57:48 -08002681 case USECASE_AUDIO_PLAYBACK_ULL:
2682 return ULL_PLATFORM_DELAY;
Eric Laurent0e46adf2016-12-16 12:49:24 -08002683 case USECASE_AUDIO_PLAYBACK_MMAP:
2684 return MMAP_PLATFORM_DELAY;
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07002685 default:
2686 return 0;
2687 }
2688}
Haynes Mathew George98c95622014-06-20 19:14:25 -07002689
Mikhail Naganov9d677f42017-03-09 16:57:59 +00002690bool platform_check_and_set_capture_backend_cfg(struct audio_device* adev,
2691 struct audio_usecase *usecase __unused,
2692 snd_device_t snd_device __unused)
2693{
2694 enum pcm_format in_pcm_format = PCM_FORMAT_S16_LE;
2695
2696 if (adev && adev->active_input)
2697 in_pcm_format = adev->active_input->config.format;
2698
2699 // allow 24 bit recording only if voice call is not active
2700 if (!voice_is_in_call(adev) &&
2701 adev->mode != AUDIO_MODE_IN_COMMUNICATION &&
2702 in_pcm_format == PCM_FORMAT_S24_LE) {
2703 audio_route_apply_and_update_path(adev->audio_route, "set-capture-format-24le");
2704 } else {
2705 audio_route_apply_and_update_path(adev->audio_route, "set-capture-format-default");
2706 }
2707
2708 return true;
2709}
2710
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002711int platform_set_snd_device_backend(snd_device_t device, const char *backend_tag,
2712 const char * hw_interface)
Haynes Mathew George98c95622014-06-20 19:14:25 -07002713{
2714 int ret = 0;
2715
2716 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
2717 ALOGE("%s: Invalid snd_device = %d",
2718 __func__, device);
2719 ret = -EINVAL;
2720 goto done;
2721 }
2722
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002723 ALOGV("%s: backend_tag_table[%s]: old = %s new = %s", __func__,
2724 platform_get_snd_device_name(device),
2725 backend_tag_table[device] != NULL ? backend_tag_table[device]: "null", backend_tag);
2726 if (backend_tag_table[device]) {
2727 free(backend_tag_table[device]);
Haynes Mathew George98c95622014-06-20 19:14:25 -07002728 }
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002729 backend_tag_table[device] = strdup(backend_tag);
2730
2731 if (hw_interface != NULL) {
2732 if (hw_interface_table[device])
2733 free(hw_interface_table[device]);
2734 ALOGV("%s: hw_interface_table[%d] = %s", __func__, device, hw_interface);
2735 hw_interface_table[device] = strdup(hw_interface);
2736 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07002737done:
2738 return ret;
2739}
2740
2741int platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t pcm_id)
2742{
2743 int ret = 0;
2744 if ((usecase <= USECASE_INVALID) || (usecase >= AUDIO_USECASE_MAX)) {
2745 ALOGE("%s: invalid usecase case idx %d", __func__, usecase);
2746 ret = -EINVAL;
2747 goto done;
2748 }
2749
2750 if ((type != 0) && (type != 1)) {
2751 ALOGE("%s: invalid usecase type", __func__);
2752 ret = -EINVAL;
2753 }
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002754 ALOGV("%s: pcm_device_table[%d][%d] = %d", __func__, usecase, type, pcm_id);
Haynes Mathew George98c95622014-06-20 19:14:25 -07002755 pcm_device_table[usecase][type] = pcm_id;
2756done:
2757 return ret;
2758}
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002759
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07002760#define DEFAULT_NOMINAL_SPEAKER_GAIN 20
2761int ramp_speaker_gain(struct audio_device *adev, bool ramp_up, int target_ramp_up_gain) {
2762 // backup_gain: gain to try to set in case of an error during ramp
2763 int start_gain, end_gain, step, backup_gain, i;
2764 bool error = false;
2765 const struct mixer_ctl *ctl;
2766 const char *mixer_ctl_name_gain_left = "Left Speaker Gain";
2767 const char *mixer_ctl_name_gain_right = "Right Speaker Gain";
2768 struct mixer_ctl *ctl_left = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_left);
2769 struct mixer_ctl *ctl_right = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_right);
2770 if (!ctl_left || !ctl_right) {
2771 ALOGE("%s: Could not get ctl for mixer cmd - %s or %s, not applying speaker gain ramp",
2772 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
2773 return -EINVAL;
2774 } else if ((mixer_ctl_get_num_values(ctl_left) != 1)
2775 || (mixer_ctl_get_num_values(ctl_right) != 1)) {
2776 ALOGE("%s: Unexpected num values for mixer cmd - %s or %s, not applying speaker gain ramp",
2777 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
2778 return -EINVAL;
2779 }
2780 if (ramp_up) {
2781 start_gain = 0;
2782 end_gain = target_ramp_up_gain > 0 ? target_ramp_up_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
2783 step = +1;
2784 backup_gain = end_gain;
2785 } else {
2786 // using same gain on left and right
2787 const int left_gain = mixer_ctl_get_value(ctl_left, 0);
2788 start_gain = left_gain > 0 ? left_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
2789 end_gain = 0;
2790 step = -1;
2791 backup_gain = start_gain;
2792 }
2793 for (i = start_gain ; i != (end_gain + step) ; i += step) {
2794 //ALOGV("setting speaker gain to %d", i);
2795 if (mixer_ctl_set_value(ctl_left, 0, i)) {
2796 ALOGE("%s: error setting %s to %d during gain ramp",
2797 __func__, mixer_ctl_name_gain_left, i);
2798 error = true;
2799 break;
2800 }
2801 if (mixer_ctl_set_value(ctl_right, 0, i)) {
2802 ALOGE("%s: error setting %s to %d during gain ramp",
2803 __func__, mixer_ctl_name_gain_right, i);
2804 error = true;
2805 break;
2806 }
2807 usleep(1000);
2808 }
2809 if (error) {
2810 // an error occured during the ramp, let's still try to go back to a safe volume
2811 if (mixer_ctl_set_value(ctl_left, 0, backup_gain)) {
2812 ALOGE("%s: error restoring left gain to %d", __func__, backup_gain);
2813 }
2814 if (mixer_ctl_set_value(ctl_right, 0, backup_gain)) {
2815 ALOGE("%s: error restoring right gain to %d", __func__, backup_gain);
2816 }
2817 }
2818 return start_gain;
2819}
2820
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002821int platform_swap_lr_channels(struct audio_device *adev, bool swap_channels)
2822{
2823 // only update if there is active pcm playback on speaker
2824 struct audio_usecase *usecase;
2825 struct listnode *node;
2826 struct platform_data *my_data = (struct platform_data *)adev->platform;
2827
2828 if (my_data->speaker_lr_swap != swap_channels) {
Jean-Michel Trivif7148702016-09-16 18:23:05 -07002829
2830 // do not swap channels in audio modes with concurrent capture and playback
2831 // as this may break the echo reference
2832 if ((adev->mode == AUDIO_MODE_IN_COMMUNICATION) || (adev->mode == AUDIO_MODE_IN_CALL)) {
2833 ALOGV("%s: will not swap due to audio mode %d", __func__, adev->mode);
2834 return 0;
2835 }
2836
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002837 my_data->speaker_lr_swap = swap_channels;
2838
2839 list_for_each(node, &adev->usecase_list) {
2840 usecase = node_to_item(node, struct audio_usecase, list);
2841 if (usecase->type == PCM_PLAYBACK &&
Ravi Kumar Alamanda425e1542015-09-22 09:11:18 -07002842 usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) {
2843 /*
2844 * If acdb tuning is different for SPEAKER_REVERSE, it is must
2845 * to perform device switch to disable the current backend to
2846 * enable it with new acdb data.
2847 */
2848 if (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
2849 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]) {
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07002850 const int initial_skpr_gain = ramp_speaker_gain(adev, false /*ramp_up*/, -1);
Ravi Kumar Alamanda425e1542015-09-22 09:11:18 -07002851 select_devices(adev, usecase->id);
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07002852 if (initial_skpr_gain != -EINVAL) {
2853 ramp_speaker_gain(adev, true /*ramp_up*/, initial_skpr_gain);
2854 }
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002855 } else {
Ravi Kumar Alamanda425e1542015-09-22 09:11:18 -07002856 const char *mixer_path;
2857 if (swap_channels) {
2858 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER_REVERSE);
2859 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
2860 } else {
2861 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER);
2862 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
2863 }
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002864 }
2865 break;
2866 }
2867 }
2868 }
2869 return 0;
2870}
vivek mehtaa8d7c922016-05-25 14:40:44 -07002871
2872static struct amp_db_and_gain_table tbl_mapping[MAX_VOLUME_CAL_STEPS];
2873static int num_gain_tbl_entry = 0;
2874
2875bool platform_add_gain_level_mapping(struct amp_db_and_gain_table *tbl_entry) {
2876
2877 ALOGV("%s: enter .. add %f %f %d", __func__, tbl_entry->amp, tbl_entry->db, tbl_entry->level);
2878 if (num_gain_tbl_entry == -1) {
2879 ALOGE("%s: num entry beyond valid step levels or corrupted..rejecting custom mapping",
2880 __func__);
2881 return false;
2882 }
2883
2884 if (num_gain_tbl_entry >= MAX_VOLUME_CAL_STEPS) {
2885 ALOGE("%s: max entry reached max[%d] current index[%d] .. rejecting", __func__,
2886 MAX_VOLUME_CAL_STEPS, num_gain_tbl_entry);
2887 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
2888 return false;
2889 }
2890
2891 if (num_gain_tbl_entry > 0 && tbl_mapping[num_gain_tbl_entry - 1].amp >= tbl_entry->amp) {
2892 ALOGE("%s: value not in ascending order .. rejecting custom mapping", __func__);
2893 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
2894 return false;
2895 }
2896
2897 tbl_mapping[num_gain_tbl_entry] = *tbl_entry;
2898 ++num_gain_tbl_entry;
2899
2900 return true;
2901}
2902
2903int platform_get_gain_level_mapping(struct amp_db_and_gain_table *mapping_tbl,
2904 int table_size) {
2905 int itt = 0;
2906 ALOGV("platform_get_gain_level_mapping called ");
2907
2908 if (num_gain_tbl_entry <= 0 || num_gain_tbl_entry > MAX_VOLUME_CAL_STEPS) {
2909 ALOGD("%s: empty or currupted gain_mapping_table", __func__);
2910 return 0;
2911 }
2912
2913 for (; itt < num_gain_tbl_entry && itt <= table_size; itt++) {
2914 mapping_tbl[itt] = tbl_mapping[itt];
2915 ALOGV("%s: added amp[%f] db[%f] level[%d]", __func__,
2916 mapping_tbl[itt].amp, mapping_tbl[itt].db, mapping_tbl[itt].level);
2917 }
2918
2919 return num_gain_tbl_entry;
2920}
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07002921
2922int platform_snd_card_update(void *platform, card_status_t status)
2923{
2924 struct platform_data *my_data = (struct platform_data *)platform;
2925 struct audio_device *adev = my_data->adev;
2926
2927 if (status == CARD_STATUS_ONLINE) {
2928 if (my_data->acdb_send_custom_top)
2929 my_data->acdb_send_custom_top();
2930 }
2931 return 0;
2932}