blob: af48c032ec26c6944f8a4ec4571e385d3e5a62fd [file] [log] [blame]
Yamit Mehta1d2e4742016-05-18 15:25:12 +05301/*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
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 */
16
17#define LOG_TAG "msm8916_platform"
18/*#define LOG_NDEBUG 0*/
19#define LOG_NDDEBUG 0
20
21#include <stdlib.h>
22#include <dlfcn.h>
23#include <fcntl.h>
24#include <sys/ioctl.h>
Haynes Mathew Georgee6e2d442018-02-22 18:51:56 -080025#include <log/log.h>
Yamit Mehta1d2e4742016-05-18 15:25:12 +053026#include <cutils/properties.h>
27#include <cutils/str_parms.h>
28#include <audio_hw.h>
29#include <platform_api.h>
30#include "platform.h"
31#include "audio_extn.h"
32#include "voice_extn.h"
33#include "sound/msmcal-hwdep.h"
Zheng Zhang858c3c62016-12-08 09:29:30 +080034#include "audio_extn/tfa_98xx.h"
Yamit Mehta1d2e4742016-05-18 15:25:12 +053035#include <dirent.h>
36#define MAX_MIXER_XML_PATH 100
Julius D'souza1a2531c2017-10-03 11:08:41 -070037#define MIXER_XML_PATH "mixer_paths.xml"
38#define MIXER_XML_PATH_MTP "mixer_paths_mtp.xml"
39#define MIXER_XML_PATH_MSM8909_PM8916 "mixer_paths_msm8909_pm8916.xml"
40#define MIXER_XML_PATH_L9300 "mixer_paths_l9300.xml"
Yamit Mehta1d2e4742016-05-18 15:25:12 +053041
42#define LIB_ACDB_LOADER "libacdbloader.so"
43#define AUDIO_DATA_BLOCK_MIXER_CTL "HDMI EDID"
44#define CVD_VERSION_MIXER_CTL "CVD Version"
45
46/*
47 * This file will have a maximum of 38 bytes:
48 *
49 * 4 bytes: number of audio blocks
50 * 4 bytes: total length of Short Audio Descriptor (SAD) blocks
51 * Maximum 10 * 3 bytes: SAD blocks
52 */
53#define MAX_SAD_BLOCKS 10
54#define SAD_BLOCK_SIZE 3
55#define MAX_CVD_VERSION_STRING_SIZE 100
56
57/* EDID format ID for LPCM audio */
58#define EDID_FORMAT_LPCM 1
59
Yamit Mehtae3b99562016-09-16 22:44:00 +053060/* fallback app type if the default app type from acdb loader fails */
61#define DEFAULT_APP_TYPE_RX_PATH 0x11130
62#define DEFAULT_APP_TYPE_TX_PATH 0x11132
Haynes Mathew George39c55dc2017-07-11 19:31:23 -070063#define DEFAULT_RX_BACKEND "SLIMBUS_0_RX"
Yamit Mehtae3b99562016-09-16 22:44:00 +053064
Yamit Mehta1d2e4742016-05-18 15:25:12 +053065/* Retry for delay in FW loading*/
66#define RETRY_NUMBER 20
67#define RETRY_US 500000
68#define MAX_SND_CARD 8
69
70#define SAMPLE_RATE_8KHZ 8000
71#define SAMPLE_RATE_16KHZ 16000
72
73#define MAX_SET_CAL_BYTE_SIZE 65536
74
75#define MAX_CAL_NAME 20
76
77#define QMIC_FLAG 0x00000004
78
Tom Cherry6ebefdd2016-07-01 13:09:35 -070079#define TOSTRING_(x) #x
80#define TOSTRING(x) TOSTRING_(x)
81
Yamit Mehta1d2e4742016-05-18 15:25:12 +053082char cal_name_info[WCD9XXX_MAX_CAL][MAX_CAL_NAME] = {
83 [WCD9XXX_MBHC_CAL] = "mbhc_cal",
84};
85
86struct audio_block_header
87{
88 int reserved;
89 int length;
90};
91
92enum {
93 CAL_MODE_SEND = 0x1,
94 CAL_MODE_PERSIST = 0x2,
95 CAL_MODE_RTAC = 0x4
96};
97
Yamit Mehtae3b99562016-09-16 22:44:00 +053098enum {
99 BUFF_IDX_0 = 0,
100 BUFF_IDX_1 = 1,
101};
102
Yamit Mehta1d2e4742016-05-18 15:25:12 +0530103#define PLATFORM_CONFIG_KEY_OPERATOR_INFO "operator_info"
104
105struct operator_info {
106 struct listnode list;
107 char *name;
108 char *mccmnc;
109};
110
111struct operator_specific_device {
112 struct listnode list;
113 char *operator;
114 char *mixer_path;
115 int acdb_id;
116};
117
118static struct listnode operator_info_list;
119static struct listnode *operator_specific_device_table[SND_DEVICE_MAX];
120
121/* Audio calibration related functions */
122typedef void (*acdb_deallocate_t)();
123typedef int (*acdb_init_v2_cvd_t)(const char *, char *, int);
124typedef void (*acdb_send_audio_cal_t)(int, int);
Yamit Mehtae3b99562016-09-16 22:44:00 +0530125typedef void (*acdb_send_audio_cal_v3_t)(int, int, int , int, int);
Yamit Mehta1d2e4742016-05-18 15:25:12 +0530126typedef void (*acdb_send_voice_cal_t)(int, int);
127typedef int (*acdb_reload_vocvoltable_t)(int);
128typedef int (*acdb_loader_get_calibration_t)(char *attr, int size, void *data);
129acdb_loader_get_calibration_t acdb_loader_get_calibration;
130
131struct platform_data {
132 struct audio_device *adev;
133 bool fluence_in_spkr_mode;
134 bool fluence_in_voice_call;
135 bool fluence_in_voice_rec;
136 int fluence_type;
137 char fluence_cap[PROPERTY_VALUE_MAX];
138 int fluence_mode;
139 bool ec_ref_enabled;
140 bool gsm_mode_enabled;
141 /* Audio calibration related functions */
142 void *acdb_handle;
143 acdb_init_v2_cvd_t acdb_init;
144 acdb_deallocate_t acdb_deallocate;
145 acdb_send_audio_cal_t acdb_send_audio_cal;
Yamit Mehtae3b99562016-09-16 22:44:00 +0530146 acdb_send_audio_cal_v3_t acdb_send_audio_cal_v3;
Yamit Mehta1d2e4742016-05-18 15:25:12 +0530147 acdb_send_voice_cal_t acdb_send_voice_cal;
148 acdb_reload_vocvoltable_t acdb_reload_vocvoltable;
149 void *hw_info;
150 char ec_ref_mixer_path[64];
151 bool speaker_lr_swap;
Tom Cherry6ebefdd2016-07-01 13:09:35 -0700152
153 int max_vol_index;
Yamit Mehta1d2e4742016-05-18 15:25:12 +0530154};
155
156int pcm_device_table[AUDIO_USECASE_MAX][2] = {
157 [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = {DEEP_BUFFER_PCM_DEVICE,
158 DEEP_BUFFER_PCM_DEVICE},
159 [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
160 LOWLATENCY_PCM_DEVICE},
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800161 [USECASE_AUDIO_PLAYBACK_HIFI] = {MULTIMEDIA2_PCM_DEVICE,
Yamit Mehta1d2e4742016-05-18 15:25:12 +0530162 MULTIMEDIA2_PCM_DEVICE},
163 [USECASE_AUDIO_PLAYBACK_OFFLOAD] =
164 {PLAYBACK_OFFLOAD_DEVICE, PLAYBACK_OFFLOAD_DEVICE},
165 [USECASE_AUDIO_PLAYBACK_ULL] = {MULTIMEDIA3_PCM_DEVICE, MULTIMEDIA3_PCM_DEVICE},
166 [USECASE_AUDIO_RECORD] = {AUDIO_RECORD_PCM_DEVICE, AUDIO_RECORD_PCM_DEVICE},
167 [USECASE_AUDIO_RECORD_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
168 LOWLATENCY_PCM_DEVICE},
169 [USECASE_AUDIO_HFP_SCO] = {HFP_PCM_RX, HFP_SCO_RX},
170 [USECASE_AUDIO_HFP_SCO_WB] = {HFP_PCM_RX, HFP_SCO_RX},
171 [USECASE_VOICE_CALL] = {VOICE_CALL_PCM_DEVICE, VOICE_CALL_PCM_DEVICE},
172 [USECASE_VOICE2_CALL] = {VOICE2_CALL_PCM_DEVICE, VOICE2_CALL_PCM_DEVICE},
173 [USECASE_VOLTE_CALL] = {VOLTE_CALL_PCM_DEVICE, VOLTE_CALL_PCM_DEVICE},
174 [USECASE_QCHAT_CALL] = {QCHAT_CALL_PCM_DEVICE, QCHAT_CALL_PCM_DEVICE},
175 [USECASE_VOWLAN_CALL] = {VOWLAN_CALL_PCM_DEVICE, VOWLAN_CALL_PCM_DEVICE},
176 [USECASE_VOICEMMODE1_CALL] = {-1, -1}, /* pcm ids updated from platform info file */
177 [USECASE_VOICEMMODE2_CALL] = {-1, -1}, /* pcm ids updated from platform info file */
178 [USECASE_INCALL_REC_UPLINK] = {AUDIO_RECORD_PCM_DEVICE,
179 AUDIO_RECORD_PCM_DEVICE},
180 [USECASE_INCALL_REC_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
181 AUDIO_RECORD_PCM_DEVICE},
182 [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
183 AUDIO_RECORD_PCM_DEVICE},
184 [USECASE_AUDIO_SPKR_CALIB_RX] = {SPKR_PROT_CALIB_RX_PCM_DEVICE, -1},
185 [USECASE_AUDIO_SPKR_CALIB_TX] = {-1, SPKR_PROT_CALIB_TX_PCM_DEVICE},
186 [USECASE_AUDIO_PLAYBACK_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
187 AFE_PROXY_RECORD_PCM_DEVICE},
188 [USECASE_AUDIO_RECORD_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
189 AFE_PROXY_RECORD_PCM_DEVICE},
190};
191
192/* Array to store sound devices */
193static const char * const device_table[SND_DEVICE_MAX] = {
194 [SND_DEVICE_NONE] = "none",
195 /* Playback sound devices */
196 [SND_DEVICE_OUT_HANDSET] = "handset",
197 [SND_DEVICE_OUT_SPEAKER] = "speaker",
198 [SND_DEVICE_OUT_SPEAKER_REVERSE] = "speaker-reverse",
David Linfb3c9952018-01-19 14:57:43 -0800199 [SND_DEVICE_OUT_SPEAKER_SAFE] = "speaker-safe",
Yamit Mehta1d2e4742016-05-18 15:25:12 +0530200 [SND_DEVICE_OUT_HEADPHONES] = "headphones",
201 [SND_DEVICE_OUT_LINE] = "line",
202 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones",
203 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = "speaker-and-line",
204 [SND_DEVICE_OUT_VOICE_HANDSET] = "voice-handset",
205 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = "voice-hac-handset",
206 [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker",
Devin Kim152b09a2016-06-23 13:53:04 -0700207 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = "voice-speaker-hfp",
Yamit Mehta1d2e4742016-05-18 15:25:12 +0530208 [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones",
209 [SND_DEVICE_OUT_VOICE_LINE] = "voice-line",
210 [SND_DEVICE_OUT_HDMI] = "hdmi",
211 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi",
212 [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset",
213 [SND_DEVICE_OUT_BT_SCO_WB] = "bt-sco-headset-wb",
214 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones",
215 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones",
216 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset",
217 [SND_DEVICE_OUT_VOICE_TX] = "voice-tx",
218 [SND_DEVICE_OUT_AFE_PROXY] = "afe-proxy",
219 [SND_DEVICE_OUT_USB_HEADSET] = "usb-headphones",
Eric Laurent36e692d2017-05-18 17:48:59 -0700220 [SND_DEVICE_OUT_USB_HEADPHONES] = "usb-headphones",
Eric Laurentb1b07992017-06-29 09:20:02 -0700221 [SND_DEVICE_OUT_VOICE_USB_HEADSET] = "usb-headphones",
222 [SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = "usb-headphones",
Yamit Mehta1d2e4742016-05-18 15:25:12 +0530223 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = "speaker-and-usb-headphones",
224 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = "speaker-protected",
225 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = "voice-speaker-protected",
226
227 /* Capture sound devices */
228 [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
229 [SND_DEVICE_IN_HANDSET_MIC_EXTERNAL] = "handset-mic-ext",
230 [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic",
231 [SND_DEVICE_IN_HANDSET_MIC_NS] = "handset-mic",
232 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = "handset-mic",
233 [SND_DEVICE_IN_HANDSET_DMIC] = "dmic-endfire",
234 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = "dmic-endfire",
235 [SND_DEVICE_IN_HANDSET_DMIC_NS] = "dmic-endfire",
236 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = "dmic-endfire",
237 [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
238 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "speaker-mic",
239 [SND_DEVICE_IN_SPEAKER_MIC_NS] = "speaker-mic",
240 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = "speaker-mic",
241 [SND_DEVICE_IN_SPEAKER_DMIC] = "speaker-dmic-endfire",
242 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = "speaker-dmic-endfire",
243 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = "speaker-dmic-endfire",
244 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = "speaker-dmic-endfire",
245 [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
246 [SND_DEVICE_IN_HEADSET_MIC_FLUENCE] = "headset-mic",
247 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
Devin Kim152b09a2016-06-23 13:53:04 -0700248 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = "voice-speaker-mic-hfp",
Yamit Mehta1d2e4742016-05-18 15:25:12 +0530249 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
250 [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic",
251 [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
252 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = "bt-sco-mic",
253 [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb",
254 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = "bt-sco-mic-wb",
255 [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic",
256 [SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef",
257 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = "voice-speaker-dmic-ef",
258 [SND_DEVICE_IN_VOICE_SPEAKER_QMIC] = "voice-speaker-qmic",
259 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
260 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
261 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
262 [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
263 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = "voice-rec-mic",
264 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = "voice-rec-dmic-ef",
265 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence",
266 [SND_DEVICE_IN_VOICE_RX] = "voice-rx",
267 [SND_DEVICE_IN_USB_HEADSET_MIC] = "usb-headset-mic",
268 [SND_DEVICE_IN_CAPTURE_FM] = "capture-fm",
269 [SND_DEVICE_IN_AANC_HANDSET_MIC] = "aanc-handset-mic",
270 [SND_DEVICE_IN_QUAD_MIC] = "quad-mic",
271 [SND_DEVICE_IN_HANDSET_STEREO_DMIC] = "handset-stereo-dmic-ef",
272 [SND_DEVICE_IN_SPEAKER_STEREO_DMIC] = "speaker-stereo-dmic-ef",
273 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = "vi-feedback",
274 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BROADSIDE] = "voice-speaker-dmic-broadside",
275 [SND_DEVICE_IN_SPEAKER_DMIC_BROADSIDE] = "speaker-dmic-broadside",
276 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_BROADSIDE] = "speaker-dmic-broadside",
277 [SND_DEVICE_IN_SPEAKER_DMIC_NS_BROADSIDE] = "speaker-dmic-broadside",
278 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_BROADSIDE] = "speaker-dmic-broadside",
279 [SND_DEVICE_IN_HANDSET_QMIC] = "quad-mic",
280 [SND_DEVICE_IN_SPEAKER_QMIC_AEC] = "quad-mic",
281 [SND_DEVICE_IN_SPEAKER_QMIC_NS] = "quad-mic",
282 [SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS] = "quad-mic",
283};
284
285/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
286static int acdb_device_table[SND_DEVICE_MAX] = {
287 [SND_DEVICE_NONE] = -1,
288 [SND_DEVICE_OUT_HANDSET] = 7,
289 [SND_DEVICE_OUT_SPEAKER] = 14,
290 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 14,
David Linfb3c9952018-01-19 14:57:43 -0800291 [SND_DEVICE_OUT_SPEAKER_SAFE] = 14,
Yamit Mehta1d2e4742016-05-18 15:25:12 +0530292 [SND_DEVICE_OUT_LINE] = 10,
293 [SND_DEVICE_OUT_HEADPHONES] = 10,
294 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
295 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = 10,
296 [SND_DEVICE_OUT_VOICE_HANDSET] = 7,
297 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = 53,
298 [SND_DEVICE_OUT_VOICE_LINE] = 10,
299 [SND_DEVICE_OUT_VOICE_SPEAKER] = 14,
300 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
301 [SND_DEVICE_OUT_HDMI] = 18,
302 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 14,
303 [SND_DEVICE_OUT_BT_SCO] = 22,
304 [SND_DEVICE_OUT_BT_SCO_WB] = 39,
305 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
306 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
307 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
308 [SND_DEVICE_OUT_VOICE_TX] = 45,
309 [SND_DEVICE_OUT_AFE_PROXY] = 0,
310 [SND_DEVICE_OUT_USB_HEADSET] = 45,
Eric Laurentb1b07992017-06-29 09:20:02 -0700311 [SND_DEVICE_OUT_VOICE_USB_HEADSET] = 45,
312 [SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = 45,
Eric Laurent36e692d2017-05-18 17:48:59 -0700313 [SND_DEVICE_OUT_USB_HEADPHONES] = 45,
Yamit Mehta1d2e4742016-05-18 15:25:12 +0530314 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = 14,
315 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = 124,
316 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = 101,
Yamit Mehta9c50bd82016-08-17 15:24:35 +0530317 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = 140,
Yamit Mehta1d2e4742016-05-18 15:25:12 +0530318
319 [SND_DEVICE_IN_HANDSET_MIC] = 4,
320 [SND_DEVICE_IN_HANDSET_MIC_EXTERNAL] = 4,
321 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 106,
322 [SND_DEVICE_IN_HANDSET_MIC_NS] = 107,
323 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = 108,
324 [SND_DEVICE_IN_HANDSET_DMIC] = 41,
325 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = 109,
326 [SND_DEVICE_IN_HANDSET_DMIC_NS] = 110,
327 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = 111,
328 [SND_DEVICE_IN_SPEAKER_MIC] = 11,
329 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 112,
330 [SND_DEVICE_IN_SPEAKER_MIC_NS] = 113,
331 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = 114,
332 [SND_DEVICE_IN_SPEAKER_DMIC] = 43,
333 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = 115,
334 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = 116,
335 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = 117,
336 [SND_DEVICE_IN_HEADSET_MIC] = 8,
337 [SND_DEVICE_IN_HEADSET_MIC_FLUENCE] = 47,
338 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
339 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = 8,
340 [SND_DEVICE_IN_HDMI_MIC] = 4,
341 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
342 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = 122,
343 [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38,
344 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = 123,
345 [SND_DEVICE_IN_CAMCORDER_MIC] = 4,
346 [SND_DEVICE_IN_VOICE_DMIC] = 41,
Yamit Mehta9c50bd82016-08-17 15:24:35 +0530347 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = 141,
Yamit Mehta1d2e4742016-05-18 15:25:12 +0530348 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 43,
349 [SND_DEVICE_IN_VOICE_SPEAKER_QMIC] = 19,
350 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
351 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
352 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
353 [SND_DEVICE_IN_VOICE_REC_MIC] = 4,
354 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = 107,
355 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = 34,
356 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 41,
357 [SND_DEVICE_IN_VOICE_RX] = 44,
358 [SND_DEVICE_IN_USB_HEADSET_MIC] = 44,
359 [SND_DEVICE_IN_CAPTURE_FM] = 0,
360 [SND_DEVICE_IN_AANC_HANDSET_MIC] = 104,
361 [SND_DEVICE_IN_QUAD_MIC] = 46,
362 [SND_DEVICE_IN_HANDSET_STEREO_DMIC] = 34,
363 [SND_DEVICE_IN_SPEAKER_STEREO_DMIC] = 35,
364 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = 102,
365 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BROADSIDE] = 12,
366 [SND_DEVICE_IN_SPEAKER_DMIC_BROADSIDE] = 12,
367 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_BROADSIDE] = 119,
368 [SND_DEVICE_IN_SPEAKER_DMIC_NS_BROADSIDE] = 121,
369 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_BROADSIDE] = 120,
370 [SND_DEVICE_IN_HANDSET_QMIC] = 125,
371 [SND_DEVICE_IN_SPEAKER_QMIC_AEC] = 126,
372 [SND_DEVICE_IN_SPEAKER_QMIC_NS] = 127,
373 [SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS] = 129,
374};
375
376struct name_to_index {
377 char name[100];
378 unsigned int index;
379};
380
381#define TO_NAME_INDEX(X) #X, X
382
383/* Used to get index from parsed sting */
384static struct name_to_index snd_device_name_index[SND_DEVICE_MAX] = {
385 {TO_NAME_INDEX(SND_DEVICE_OUT_HANDSET)},
386 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER)},
387 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_REVERSE)},
David Linfb3c9952018-01-19 14:57:43 -0800388 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE)},
Yamit Mehta1d2e4742016-05-18 15:25:12 +0530389 {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES)},
390 {TO_NAME_INDEX(SND_DEVICE_OUT_LINE)},
391 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES)},
392 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_LINE)},
393 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET)},
394 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HAC_HANDSET)},
395 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER)},
Devin Kim152b09a2016-06-23 13:53:04 -0700396 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_HFP)},
Yamit Mehta1d2e4742016-05-18 15:25:12 +0530397 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADPHONES)},
398 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_LINE)},
399 {TO_NAME_INDEX(SND_DEVICE_OUT_HDMI)},
400 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HDMI)},
401 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO)},
402 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO_WB)},
403 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES)},
404 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES)},
405 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET)},
406 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TX)},
407 {TO_NAME_INDEX(SND_DEVICE_OUT_AFE_PROXY)},
408 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADSET)},
Eric Laurentb1b07992017-06-29 09:20:02 -0700409 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_USB_HEADSET)},
410 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_USB_HEADPHONES)},
Eric Laurent36e692d2017-05-18 17:48:59 -0700411 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADPHONES)},
Yamit Mehta1d2e4742016-05-18 15:25:12 +0530412 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET)},
413 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED)},
414 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED)},
415 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC)},
416 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_EXTERNAL)},
417 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC)},
418 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_NS)},
419 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)},
420 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC)},
421 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC)},
422 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_NS)},
423 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)},
424 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC)},
425 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC)},
426 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_NS)},
427 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)},
428 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC)},
429 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC)},
430 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS)},
431 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)},
432 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC)},
433 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC_FLUENCE)},
434 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC)},
Devin Kim152b09a2016-06-23 13:53:04 -0700435 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP)},
Yamit Mehta1d2e4742016-05-18 15:25:12 +0530436 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEADSET_MIC)},
437 {TO_NAME_INDEX(SND_DEVICE_IN_HDMI_MIC)},
438 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC)},
439 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_NREC)},
440 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB)},
441 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB_NREC)},
442 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_MIC)},
443 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC)},
444 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC)},
445 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_QMIC)},
446 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC)},
447 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC)},
448 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC)},
449 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC)},
450 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_NS)},
451 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_STEREO)},
452 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE)},
453 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_RX)},
454 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC)},
455 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_FM)},
456 {TO_NAME_INDEX(SND_DEVICE_IN_AANC_HANDSET_MIC)},
457 {TO_NAME_INDEX(SND_DEVICE_IN_QUAD_MIC)},
458 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_STEREO_DMIC)},
459 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_STEREO_DMIC)},
460 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_VI_FEEDBACK)},
461 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BROADSIDE)},
462 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_BROADSIDE)},
463 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_BROADSIDE)},
464 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS_BROADSIDE)},
465 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_BROADSIDE)},
466 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC)},
467 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_QMIC_AEC)},
468 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_QMIC_NS)},
469 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS)},
470};
471
472static char * backend_table[SND_DEVICE_MAX] = {0};
473static char * hw_interface_table[SND_DEVICE_MAX] = {0};
474
475static struct name_to_index usecase_name_index[AUDIO_USECASE_MAX] = {
476 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_DEEP_BUFFER)},
477 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_LOW_LATENCY)},
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800478 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_HIFI)},
Yamit Mehta1d2e4742016-05-18 15:25:12 +0530479 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD)},
480 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_ULL)},
481 {TO_NAME_INDEX(USECASE_AUDIO_RECORD)},
482 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_LOW_LATENCY)},
483 {TO_NAME_INDEX(USECASE_VOICE_CALL)},
484 {TO_NAME_INDEX(USECASE_VOICE2_CALL)},
485 {TO_NAME_INDEX(USECASE_VOLTE_CALL)},
486 {TO_NAME_INDEX(USECASE_QCHAT_CALL)},
487 {TO_NAME_INDEX(USECASE_VOWLAN_CALL)},
488 {TO_NAME_INDEX(USECASE_VOICEMMODE1_CALL)},
489 {TO_NAME_INDEX(USECASE_VOICEMMODE2_CALL)},
490 {TO_NAME_INDEX(USECASE_AUDIO_HFP_SCO)},
Devin Kim95630292017-09-08 14:49:14 -0700491 {TO_NAME_INDEX(USECASE_AUDIO_HFP_SCO_WB)},
Yamit Mehta1d2e4742016-05-18 15:25:12 +0530492 {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_TX)},
493};
494
495#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
496#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
497
498static void query_platform(const char *snd_card_name,
499 char *mixer_xml_path)
500{
501 if (!strncmp(snd_card_name, "msm8x16-snd-card-mtp",
502 sizeof("msm8x16-snd-card-mtp"))) {
503 strlcpy(mixer_xml_path, MIXER_XML_PATH_MTP,
504 sizeof(MIXER_XML_PATH_MTP));
505 } else if (!strncmp(snd_card_name, "msm8909-pm8916-snd-card",
506 sizeof("msm8909-pm8916-snd-card"))) {
507 strlcpy(mixer_xml_path, MIXER_XML_PATH_MSM8909_PM8916,
508 sizeof(MIXER_XML_PATH_MSM8909_PM8916));
509 } else if (!strncmp(snd_card_name, "msm8952-snd-card-mtp",
510 sizeof("msm8952-snd-card-mtp"))) {
511 strlcpy(mixer_xml_path, MIXER_XML_PATH_MTP,
512 sizeof(MIXER_XML_PATH_MTP));
513 } else if (!strncmp(snd_card_name, "msm8952-l9300-snd-card",
514 sizeof("msm8952-l9300-snd-card"))) {
515 strlcpy(mixer_xml_path, MIXER_XML_PATH_L9300,
516 sizeof(MIXER_XML_PATH_L9300));
517 } else {
518 strlcpy(mixer_xml_path, MIXER_XML_PATH,
519 sizeof(MIXER_XML_PATH));
520 }
521}
522
523static pthread_once_t check_op_once_ctl = PTHREAD_ONCE_INIT;
524static bool is_tmus = false;
525
526static void check_operator()
527{
528 char value[PROPERTY_VALUE_MAX];
529 int mccmnc;
530 property_get("gsm.sim.operator.numeric",value,"0");
531 mccmnc = atoi(value);
532 ALOGD("%s: tmus mccmnc %d", __func__, mccmnc);
533 switch(mccmnc) {
534 /* TMUS MCC(310), MNC(490, 260, 026) */
535 case 310490:
536 case 310260:
537 case 310026:
538 /* Add new TMUS MNC(800, 660, 580, 310, 270, 250, 240, 230, 220, 210, 200, 160) */
539 case 310800:
540 case 310660:
541 case 310580:
542 case 310310:
543 case 310270:
544 case 310250:
545 case 310240:
546 case 310230:
547 case 310220:
548 case 310210:
549 case 310200:
550 case 310160:
551 is_tmus = true;
552 break;
553 }
554}
555
556bool is_operator_tmus()
557{
558 pthread_once(&check_op_once_ctl, check_operator);
559 return is_tmus;
560}
561
562static char *get_current_operator()
563{
564 struct listnode *node;
565 struct operator_info *info_item;
566 char mccmnc[PROPERTY_VALUE_MAX];
567 char *ret = NULL;
568
Tom Cherry7fea2042016-11-10 18:05:59 -0800569 property_get("gsm.sim.operator.numeric",mccmnc,"00000");
Yamit Mehta1d2e4742016-05-18 15:25:12 +0530570
571 list_for_each(node, &operator_info_list) {
572 info_item = node_to_item(node, struct operator_info, list);
573 if (strstr(info_item->mccmnc, mccmnc) != NULL) {
574 ret = info_item->name;
575 }
576 }
577
578 return ret;
579}
580
581static struct operator_specific_device *get_operator_specific_device(snd_device_t snd_device)
582{
583 struct listnode *node;
584 struct operator_specific_device *ret = NULL;
585 struct operator_specific_device *device_item;
586 char *operator_name;
587
588 operator_name = get_current_operator();
589 if (operator_name == NULL)
590 return ret;
591
592 list_for_each(node, operator_specific_device_table[snd_device]) {
593 device_item = node_to_item(node, struct operator_specific_device, list);
594 if (strcmp(operator_name, device_item->operator) == 0) {
595 ret = device_item;
596 }
597 }
598
599 return ret;
600}
601
602static int get_operator_specific_device_acdb_id(snd_device_t snd_device)
603{
604 struct operator_specific_device *device;
605 int ret = acdb_device_table[snd_device];
606
607 device = get_operator_specific_device(snd_device);
608 if (device != NULL)
609 ret = device->acdb_id;
610
611 return ret;
612}
613
614static const char *get_operator_specific_device_mixer_path(snd_device_t snd_device)
615{
616 struct operator_specific_device *device;
617 const char *ret = device_table[snd_device];
618
619 device = get_operator_specific_device(snd_device);
620 if (device != NULL)
621 ret = device->mixer_path;
622
623 return ret;
624}
625
626bool platform_send_gain_dep_cal(void *platform __unused, int level __unused)
627{
vivek mehtafb4d7bd2016-04-29 03:16:47 -0700628 return true;
Yamit Mehta1d2e4742016-05-18 15:25:12 +0530629}
630
631void platform_set_echo_reference(struct audio_device *adev, bool enable,
632 audio_devices_t out_device)
633{
634 struct platform_data *my_data = (struct platform_data *)adev->platform;
635 snd_device_t snd_device = SND_DEVICE_NONE;
636
637 if (strcmp(my_data->ec_ref_mixer_path, "")) {
638 ALOGV("%s: disabling %s", __func__, my_data->ec_ref_mixer_path);
639 audio_route_reset_and_update_path(adev->audio_route,
640 my_data->ec_ref_mixer_path);
641 }
642
643 if (enable) {
644 if (out_device != AUDIO_DEVICE_NONE) {
645 snd_device = platform_get_output_snd_device(adev->platform, out_device);
646 platform_add_backend_name(adev->platform, my_data->ec_ref_mixer_path, snd_device);
647 }
648
649 strlcpy(my_data->ec_ref_mixer_path, "echo-reference",
650 sizeof(my_data->ec_ref_mixer_path));
651
652 ALOGD("%s: enabling %s", __func__, my_data->ec_ref_mixer_path);
653 audio_route_apply_and_update_path(adev->audio_route,
654 my_data->ec_ref_mixer_path);
655 }
656}
657
658static void set_platform_defaults()
659{
660 int32_t dev;
661 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
662 backend_table[dev] = NULL;
663 hw_interface_table[dev] = NULL;
664 }
665
666 // TBD - do these go to the platform-info.xml file.
667 // will help in avoiding strdups here
668 backend_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("bt-sco");
669 backend_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("bt-sco-wb");
670 backend_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("bt-sco");
671 backend_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("bt-sco-wb");
672 backend_table[SND_DEVICE_OUT_BT_SCO] = strdup("bt-sco");
673 backend_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("bt-sco-wb");
674 backend_table[SND_DEVICE_OUT_HDMI] = strdup("hdmi");
675 backend_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("speaker-and-hdmi");
676 backend_table[SND_DEVICE_OUT_VOICE_TX] = strdup("afe-proxy");
677 backend_table[SND_DEVICE_IN_VOICE_RX] = strdup("afe-proxy");
678 backend_table[SND_DEVICE_OUT_AFE_PROXY] = strdup("afe-proxy");
679 backend_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("usb-headphones");
Eric Laurentb1b07992017-06-29 09:20:02 -0700680 backend_table[SND_DEVICE_OUT_VOICE_USB_HEADSET] = strdup("usb-headphones");
Eric Laurent36e692d2017-05-18 17:48:59 -0700681 backend_table[SND_DEVICE_OUT_USB_HEADPHONES] = strdup("usb-headphones");
Eric Laurentb1b07992017-06-29 09:20:02 -0700682 backend_table[SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = strdup("usb-headphones");
Yamit Mehta1d2e4742016-05-18 15:25:12 +0530683 backend_table[SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] =
684 strdup("speaker-and-usb-headphones");
685 backend_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("usb-headset-mic");
686 backend_table[SND_DEVICE_IN_CAPTURE_FM] = strdup("capture-fm");
687}
688
689void get_cvd_version(char *cvd_version, struct audio_device *adev)
690{
691 struct mixer_ctl *ctl;
692 int count;
693 int ret = 0;
694
695 ctl = mixer_get_ctl_by_name(adev->mixer, CVD_VERSION_MIXER_CTL);
696 if (!ctl) {
697 ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__, CVD_VERSION_MIXER_CTL);
698 goto done;
699 }
700 mixer_ctl_update(ctl);
701
702 count = mixer_ctl_get_num_values(ctl);
703 if (count > MAX_CVD_VERSION_STRING_SIZE)
704 count = MAX_CVD_VERSION_STRING_SIZE -1;
705
706 ret = mixer_ctl_get_array(ctl, cvd_version, count);
707 if (ret != 0) {
708 ALOGE("%s: ERROR! mixer_ctl_get_array() failed to get CVD Version", __func__);
709 goto done;
710 }
711
712done:
713 return;
714}
715
716static int hw_util_open(int card_no)
717{
718 int fd = -1;
719 char dev_name[256];
720
721 snprintf(dev_name, sizeof(dev_name), "/dev/snd/hwC%uD%u",
722 card_no, WCD9XXX_CODEC_HWDEP_NODE);
723 ALOGD("%s Opening device %s\n", __func__, dev_name);
724 fd = open(dev_name, O_WRONLY);
725 if (fd < 0) {
726 ALOGE("%s: cannot open device '%s'\n", __func__, dev_name);
727 return fd;
728 }
729 ALOGD("%s success", __func__);
730 return fd;
731}
732
733struct param_data {
734 int use_case;
735 int acdb_id;
736 int get_size;
737 int buff_size;
738 int data_size;
739 void *buff;
740};
741
742static int send_codec_cal(acdb_loader_get_calibration_t acdb_loader_get_calibration,
743 struct platform_data *plat_data __unused, int fd)
744{
745 int ret = 0, type;
746
747 for (type = WCD9XXX_ANC_CAL; type < WCD9XXX_MAX_CAL; type++) {
748 struct wcdcal_ioctl_buffer codec_buffer;
749 struct param_data calib;
750
751 if (type != WCD9XXX_MBHC_CAL)
752 continue;
753
754 calib.get_size = 1;
755 ret = acdb_loader_get_calibration(cal_name_info[type], sizeof(struct param_data),
756 &calib);
757 if (ret < 0) {
758 ALOGE("%s get_calibration failed\n", __func__);
759 return ret;
760 }
761 calib.get_size = 0;
762 calib.buff = malloc(calib.buff_size);
763 if(calib.buff == NULL) {
764 ALOGE("%s mem allocation for %d bytes for %s failed\n"
765 , __func__, calib.buff_size, cal_name_info[type]);
766 return -1;
767 }
768 ret = acdb_loader_get_calibration(cal_name_info[type],
769 sizeof(struct param_data), &calib);
770 if (ret < 0) {
771 ALOGE("%s get_calibration failed type=%s calib.size=%d\n"
772 , __func__, cal_name_info[type], codec_buffer.size);
773 free(calib.buff);
774 return ret;
775 }
776 codec_buffer.buffer = calib.buff;
777 codec_buffer.size = calib.data_size;
778 codec_buffer.cal_type = type;
779 if (ioctl(fd, SNDRV_CTL_IOCTL_HWDEP_CAL_TYPE, &codec_buffer) < 0)
780 ALOGE("Failed to call ioctl for %s err=%d calib.size=%d",
781 cal_name_info[type], errno, codec_buffer.size);
782 ALOGD("%s cal sent for %s calib.size=%d"
783 , __func__, cal_name_info[type], codec_buffer.size);
784 free(calib.buff);
785 }
786 return ret;
787}
788
789static void audio_hwdep_send_cal(struct platform_data *plat_data)
790{
791 int fd;
792
793 fd = hw_util_open(plat_data->adev->snd_card);
794 if (fd == -1) {
795 ALOGE("%s error open\n", __func__);
796 return;
797 }
798
799 acdb_loader_get_calibration = (acdb_loader_get_calibration_t)
800 dlsym(plat_data->acdb_handle, "acdb_loader_get_calibration");
801
802 if (acdb_loader_get_calibration == NULL) {
803 ALOGE("%s: ERROR. dlsym Error:%s acdb_loader_get_calibration", __func__,
804 dlerror());
805 return;
806 }
807 if (send_codec_cal(acdb_loader_get_calibration, plat_data, fd) < 0)
808 ALOGE("%s: Could not send anc cal", __FUNCTION__);
809}
810
811
812int platform_acdb_init(void *platform)
813{
814 struct platform_data *my_data = (struct platform_data *)platform;
815 char *cvd_version = NULL;
816 int key = 0;
817 const char *snd_card_name;
818 int result;
819 char value[PROPERTY_VALUE_MAX];
820 cvd_version = calloc(1, MAX_CVD_VERSION_STRING_SIZE);
821 if (!cvd_version)
822 ALOGE("Failed to allocate cvd version");
823 else
824 get_cvd_version(cvd_version, my_data->adev);
825
826 property_get("audio.ds1.metainfo.key",value,"0");
827 key = atoi(value);
828 snd_card_name = mixer_get_name(my_data->adev->mixer);
829
830 result = my_data->acdb_init(snd_card_name, cvd_version, key);
831
832 if (cvd_version)
833 free(cvd_version);
834 if (!result) {
835 ALOGD("ACDB initialized");
836 audio_hwdep_send_cal(my_data);
837 } else {
838 ALOGD("ACDB initialization failed");
839 }
840 return result;
841}
842
Julius D'souza1a2531c2017-10-03 11:08:41 -0700843// Treblized config files will be located in /odm/etc or /vendor/etc.
844static const char *kConfigLocationList[] =
845 {"/odm/etc", "/vendor/etc", "/system/etc"};
846static const int kConfigLocationListSize =
847 (sizeof(kConfigLocationList) / sizeof(kConfigLocationList[0]));
848
849bool resolve_config_file(char file_name[MIXER_PATH_MAX_LENGTH]) {
850 char full_config_path[MIXER_PATH_MAX_LENGTH];
851 for (int i = 0; i < kConfigLocationListSize; i++) {
852 snprintf(full_config_path,
853 MIXER_PATH_MAX_LENGTH,
854 "%s/%s",
855 kConfigLocationList[i],
856 file_name);
857 if (F_OK == access(full_config_path, 0)) {
858 strcpy(file_name, full_config_path);
859 return true;
860 }
861 }
862 return false;
863}
864
Yamit Mehta1d2e4742016-05-18 15:25:12 +0530865void *platform_init(struct audio_device *adev)
866{
867 char platform[PROPERTY_VALUE_MAX] = {0};
868 char baseband[PROPERTY_VALUE_MAX] = {0};
869 char value[PROPERTY_VALUE_MAX] = {0};
870 struct platform_data *my_data = NULL;
871 int retry_num = 0, snd_card_num = 0, key = 0;
872 const char *snd_card_name;
873 char mixer_xml_path[MAX_MIXER_XML_PATH] = {0};
Julius D'souza1a2531c2017-10-03 11:08:41 -0700874 char platform_info_path[MAX_MIXER_XML_PATH] = {0};
Yamit Mehta1d2e4742016-05-18 15:25:12 +0530875 char ffspEnable[PROPERTY_VALUE_MAX] = {0};
876 char *cvd_version = NULL;
877 int idx;
878
879 my_data = calloc(1, sizeof(struct platform_data));
880 if (!my_data) {
881 ALOGE("failed to allocate platform data");
882 return NULL;
883 }
884
885 list_init(&operator_info_list);
vivek mehtad135c312016-09-14 18:37:49 -0700886 bool card_verifed[MAX_SND_CARD] = {0};
887 const int retry_limit = property_get_int32("audio.snd_card.open.retries", RETRY_NUMBER);
Yamit Mehta1d2e4742016-05-18 15:25:12 +0530888
vivek mehtad135c312016-09-14 18:37:49 -0700889 for (;;) {
890 if (snd_card_num >= MAX_SND_CARD) {
891 if (retry_num++ >= retry_limit) {
892 ALOGE("%s: Unable to find correct sound card, aborting.", __func__);
893 free(my_data);
894 my_data = NULL;
895 return NULL;
896 }
Yamit Mehta1d2e4742016-05-18 15:25:12 +0530897
vivek mehtad135c312016-09-14 18:37:49 -0700898 snd_card_num = 0;
Yamit Mehta1d2e4742016-05-18 15:25:12 +0530899 usleep(RETRY_US);
vivek mehtad135c312016-09-14 18:37:49 -0700900 continue;
Yamit Mehta1d2e4742016-05-18 15:25:12 +0530901 }
902
vivek mehtad135c312016-09-14 18:37:49 -0700903 if (card_verifed[snd_card_num]) {
904 ++snd_card_num;
905 continue;
906 }
907
908 adev->mixer = mixer_open(snd_card_num);
909
Yamit Mehta1d2e4742016-05-18 15:25:12 +0530910 if (!adev->mixer) {
911 ALOGE("%s: Unable to open the mixer card: %d", __func__,
vivek mehtad135c312016-09-14 18:37:49 -0700912 snd_card_num);
913 ++snd_card_num;
Yamit Mehta1d2e4742016-05-18 15:25:12 +0530914 continue;
915 }
916
vivek mehtad135c312016-09-14 18:37:49 -0700917 card_verifed[snd_card_num] = true;
918
Yamit Mehta1d2e4742016-05-18 15:25:12 +0530919 snd_card_name = mixer_get_name(adev->mixer);
920 ALOGV("%s: snd_card_name: %s", __func__, snd_card_name);
921
922 my_data->hw_info = hw_info_init(snd_card_name);
923 if (!my_data->hw_info) {
924 ALOGE("%s: Failed to init hardware info", __func__);
925 } else {
926 query_platform(snd_card_name, mixer_xml_path);
Julius D'souza1a2531c2017-10-03 11:08:41 -0700927 if (!resolve_config_file(mixer_xml_path)) {
928 memset(mixer_xml_path, 0, sizeof(mixer_xml_path));
929 strlcpy(mixer_xml_path, MIXER_XML_PATH, MAX_MIXER_XML_PATH);
930 resolve_config_file(mixer_xml_path);
931 }
Yamit Mehta1d2e4742016-05-18 15:25:12 +0530932 ALOGD("%s: mixer path file is %s", __func__,
933 mixer_xml_path);
934 adev->audio_route = audio_route_init(snd_card_num,
935 mixer_xml_path);
936 if (!adev->audio_route) {
937 ALOGE("%s: Failed to init audio route controls, aborting.",
938 __func__);
vivek mehtad135c312016-09-14 18:37:49 -0700939 hw_info_deinit(my_data->hw_info);
940 my_data->hw_info = NULL;
Yamit Mehta1d2e4742016-05-18 15:25:12 +0530941 free(my_data);
vivek mehtad135c312016-09-14 18:37:49 -0700942 my_data = NULL;
943 mixer_close(adev->mixer);
944 adev->mixer = NULL;
Yamit Mehta1d2e4742016-05-18 15:25:12 +0530945 return NULL;
946 }
947 adev->snd_card = snd_card_num;
948 ALOGD("%s: Opened sound card:%d", __func__, snd_card_num);
949 break;
950 }
vivek mehtad135c312016-09-14 18:37:49 -0700951 ++snd_card_num;
952 mixer_close(adev->mixer);
953 adev->mixer = NULL;
Yamit Mehta1d2e4742016-05-18 15:25:12 +0530954 }
955
Tom Cherry6ebefdd2016-07-01 13:09:35 -0700956 //set max volume step for voice call
957 property_get("ro.config.vc_call_vol_steps", value, TOSTRING(MAX_VOL_INDEX));
958 my_data->max_vol_index = atoi(value);
959
Yamit Mehta1d2e4742016-05-18 15:25:12 +0530960 my_data->adev = adev;
961 my_data->fluence_in_spkr_mode = false;
962 my_data->fluence_in_voice_call = false;
963 my_data->fluence_in_voice_rec = false;
964 my_data->fluence_type = FLUENCE_NONE;
965 my_data->fluence_mode = FLUENCE_ENDFIRE;
966
967 property_get("ro.qc.sdk.audio.fluencetype", my_data->fluence_cap, "");
968 if (!strncmp("fluencepro", my_data->fluence_cap, sizeof("fluencepro"))) {
969 my_data->fluence_type = FLUENCE_QUAD_MIC | FLUENCE_DUAL_MIC;
970 } else if (!strncmp("fluence", my_data->fluence_cap, sizeof("fluence"))) {
971 my_data->fluence_type = FLUENCE_DUAL_MIC;
972 } else {
973 my_data->fluence_type = FLUENCE_NONE;
974 }
975
976 if (my_data->fluence_type != FLUENCE_NONE) {
977 property_get("persist.audio.fluence.voicecall",value,"");
978 if (!strncmp("true", value, sizeof("true"))) {
979 my_data->fluence_in_voice_call = true;
980 }
981
982 property_get("persist.audio.fluence.voicerec",value,"");
983 if (!strncmp("true", value, sizeof("true"))) {
984 my_data->fluence_in_voice_rec = true;
985 }
986
987 property_get("persist.audio.fluence.speaker",value,"");
988 if (!strncmp("true", value, sizeof("true"))) {
989 my_data->fluence_in_spkr_mode = true;
990 }
991
992 property_get("persist.audio.fluence.mode",value,"");
993 if (!strncmp("broadside", value, sizeof("broadside"))) {
994 my_data->fluence_mode = FLUENCE_BROADSIDE;
995 }
996 }
997
998 property_get("persist.audio.FFSP.enable", ffspEnable, "");
999 if (!strncmp("true", ffspEnable, sizeof("true"))) {
1000 acdb_device_table[SND_DEVICE_OUT_SPEAKER] = 131;
1001 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE] = 131;
1002 acdb_device_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 131;
1003 acdb_device_table[SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = 131;
1004 }
1005
1006 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
1007 if (my_data->acdb_handle == NULL) {
1008 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
1009 } else {
1010 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
1011 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
1012 "acdb_loader_deallocate_ACDB");
1013 if (!my_data->acdb_deallocate)
1014 ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s",
1015 __func__, LIB_ACDB_LOADER);
1016
Ariel Gertzensteinc2c11742016-11-14 18:08:28 -05001017 my_data->acdb_send_audio_cal_v3 = (acdb_send_audio_cal_v3_t)dlsym(my_data->acdb_handle,
Yamit Mehtae3b99562016-09-16 22:44:00 +05301018 "acdb_loader_send_audio_cal_v3");
1019 if (!my_data->acdb_send_audio_cal_v3)
1020 ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s",
1021 __func__, LIB_ACDB_LOADER);
1022
Yamit Mehta1d2e4742016-05-18 15:25:12 +05301023 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
1024 "acdb_loader_send_audio_cal");
1025 if (!my_data->acdb_send_audio_cal)
1026 ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s",
1027 __func__, LIB_ACDB_LOADER);
1028
1029 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
1030 "acdb_loader_send_voice_cal");
1031 if (!my_data->acdb_send_voice_cal)
1032 ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s",
1033 __func__, LIB_ACDB_LOADER);
1034
1035 my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle,
1036 "acdb_loader_reload_vocvoltable");
1037 if (!my_data->acdb_reload_vocvoltable)
1038 ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s",
1039 __func__, LIB_ACDB_LOADER);
1040
1041 my_data->acdb_init = (acdb_init_v2_cvd_t)dlsym(my_data->acdb_handle,
1042 "acdb_loader_init_v2");
1043 if (my_data->acdb_init == NULL) {
1044 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__, dlerror());
1045 goto acdb_init_fail;
1046 }
1047 platform_acdb_init(my_data);
1048 }
1049
1050acdb_init_fail:
1051
1052 set_platform_defaults();
1053
1054 /* Initialize ACDB and PCM ID's */
Julius D'souza1a2531c2017-10-03 11:08:41 -07001055 strlcpy(platform_info_path, PLATFORM_INFO_XML_PATH, MAX_MIXER_XML_PATH);
1056 resolve_config_file(platform_info_path);
1057 platform_info_init(platform_info_path, my_data);
Yamit Mehta1d2e4742016-05-18 15:25:12 +05301058
1059
1060 /* Read one time ssr property */
1061 audio_extn_spkr_prot_init(adev);
1062
1063 return my_data;
1064}
1065
1066void platform_deinit(void *platform)
1067{
1068 struct platform_data *my_data = (struct platform_data *)platform;
1069
1070 int32_t dev;
1071 struct operator_info *info_item;
1072 struct operator_specific_device *device_item;
1073 struct listnode *node;
1074
1075 hw_info_deinit(my_data->hw_info);
1076
1077 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1078 if (backend_table[dev]) {
1079 free(backend_table[dev]);
1080 backend_table[dev]= NULL;
1081 }
1082 if (operator_specific_device_table[dev]) {
1083 while (!list_empty(operator_specific_device_table[dev])) {
1084 node = list_head(operator_specific_device_table[dev]);
1085 list_remove(node);
1086 device_item = node_to_item(node, struct operator_specific_device, list);
1087 free(device_item->operator);
1088 free(device_item->mixer_path);
1089 free(device_item);
1090 }
1091 free(operator_specific_device_table[dev]);
1092 }
1093 }
1094
1095 while (!list_empty(&operator_info_list)) {
1096 node = list_head(&operator_info_list);
1097 list_remove(node);
1098 info_item = node_to_item(node, struct operator_info, list);
1099 free(info_item->name);
1100 free(info_item->mccmnc);
1101 free(info_item);
1102 }
1103
Kevin Rocarde35d4af2017-05-02 16:55:28 -07001104 mixer_close(my_data->adev->mixer);
Yamit Mehta1d2e4742016-05-18 15:25:12 +05301105 free(platform);
1106}
1107
1108const char *platform_get_snd_device_name(snd_device_t snd_device)
1109{
1110 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1111 if (operator_specific_device_table[snd_device] != NULL) {
1112 return get_operator_specific_device_mixer_path(snd_device);
1113 }
1114 return device_table[snd_device];
1115 } else
1116 return "none";
1117}
1118
1119int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
1120 char *device_name)
1121{
1122 struct platform_data *my_data = (struct platform_data *)platform;
1123
David Benjamin1565f992016-09-21 12:10:34 -04001124 if (platform == NULL) {
Yamit Mehta1d2e4742016-05-18 15:25:12 +05301125 ALOGW("%s: something wrong, use legacy get_snd_device name", __func__);
1126 strlcpy(device_name, platform_get_snd_device_name(snd_device),
1127 DEVICE_NAME_MAX_SIZE);
1128 } else if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1129 if (operator_specific_device_table[snd_device] != NULL) {
1130 strlcpy(device_name, get_operator_specific_device_mixer_path(snd_device),
1131 DEVICE_NAME_MAX_SIZE);
1132 } else {
1133 strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE);
1134 }
1135 hw_info_append_hw_type(my_data->hw_info, snd_device, device_name);
1136 } else {
1137 strlcpy(device_name, "none", DEVICE_NAME_MAX_SIZE);
1138 return -EINVAL;
1139 }
1140
1141 return 0;
1142}
1143
David Linee3fe402017-03-13 10:00:42 -07001144bool platform_check_and_set_playback_backend_cfg(struct audio_device* adev __unused,
1145 struct audio_usecase *usecase __unused,
1146 snd_device_t snd_device __unused)
1147{
1148 return false;
1149}
1150
Yamit Mehta6b4b1272016-06-10 15:12:50 +05301151bool platform_check_and_set_capture_backend_cfg(struct audio_device* adev __unused,
1152 struct audio_usecase *usecase __unused,
Ariel Gertzensteinc2c11742016-11-14 18:08:28 -05001153 snd_device_t snd_device __unused)
Yamit Mehta6b4b1272016-06-10 15:12:50 +05301154{
1155 return false;
1156}
1157
1158bool platform_add_gain_level_mapping(struct amp_db_and_gain_table *tbl_entry __unused)
1159{
1160 return false;
1161}
1162
1163int platform_get_gain_level_mapping(struct amp_db_and_gain_table *mapping_tbl __unused,
1164 int table_size __unused)
1165{
1166 return 0;
1167}
1168
Yamit Mehta1d2e4742016-05-18 15:25:12 +05301169void platform_add_backend_name(void *platform, char *mixer_path,
1170 snd_device_t snd_device)
1171{
1172
1173 struct platform_data *my_data = (struct platform_data *)platform;
1174
1175 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1176 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1177 return;
1178 }
1179
1180 const char * suffix = backend_table[snd_device];
1181
1182 if (suffix != NULL) {
1183 strlcat(mixer_path, " ", MIXER_PATH_MAX_LENGTH);
1184 strlcat(mixer_path, suffix, MIXER_PATH_MAX_LENGTH);
1185 }
1186}
1187
1188bool platform_check_backends_match(snd_device_t snd_device1, snd_device_t snd_device2)
1189{
1190 bool result = true;
1191
1192 ALOGV("%s: snd_device1 = %s, snd_device2 = %s", __func__,
1193 platform_get_snd_device_name(snd_device1),
1194 platform_get_snd_device_name(snd_device2));
1195
1196 if ((snd_device1 < SND_DEVICE_MIN) || (snd_device1 >= SND_DEVICE_MAX)) {
1197 ALOGE("%s: Invalid snd_device = %s", __func__,
1198 platform_get_snd_device_name(snd_device1));
1199 return false;
1200 }
1201 if ((snd_device2 < SND_DEVICE_MIN) || (snd_device2 >= SND_DEVICE_MAX)) {
1202 ALOGE("%s: Invalid snd_device = %s", __func__,
1203 platform_get_snd_device_name(snd_device2));
1204 return false;
1205 }
1206 const char * be_itf1 = hw_interface_table[snd_device1];
1207 const char * be_itf2 = hw_interface_table[snd_device2];
1208
1209 if (NULL != be_itf1 && NULL != be_itf2) {
1210 if ((NULL == strstr(be_itf2, be_itf1)) && (NULL == strstr(be_itf1, be_itf2)))
1211 result = false;
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07001212 } else if (NULL != be_itf2 && (NULL == strstr(be_itf2, DEFAULT_RX_BACKEND))) {
1213 result = false;
1214 } else if (NULL != be_itf1 && (NULL == strstr(be_itf1, DEFAULT_RX_BACKEND))) {
1215 result = false;
Yamit Mehta1d2e4742016-05-18 15:25:12 +05301216 }
1217
1218 ALOGV("%s: be_itf1 = %s, be_itf2 = %s, match %d", __func__, be_itf1, be_itf2, result);
1219 return result;
1220}
1221
1222int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
1223{
1224 int device_id = -1;
1225
1226 if (device_type == PCM_PLAYBACK)
1227 device_id = pcm_device_table[usecase][0];
1228 else
1229 device_id = pcm_device_table[usecase][1];
1230 return device_id;
1231}
1232
1233static int find_index(struct name_to_index * table, int32_t len, const char * name)
1234{
1235 int ret = 0;
1236 int32_t i;
1237
1238 if (table == NULL) {
1239 ALOGE("%s: table is NULL", __func__);
1240 ret = -ENODEV;
1241 goto done;
1242 }
1243
1244 if (name == NULL) {
1245 ALOGE("null key");
1246 ret = -ENODEV;
1247 goto done;
1248 }
1249
1250 for (i=0; i < len; i++) {
1251 const char* tn = table[i].name;
1252 size_t len = strlen(tn);
1253 if (strncmp(tn, name, len) == 0) {
1254 if (strlen(name) != len) {
1255 continue; // substring
1256 }
1257 ret = table[i].index;
1258 goto done;
1259 }
1260 }
1261 ALOGE("%s: Could not find index for name = %s",
1262 __func__, name);
1263 ret = -ENODEV;
1264done:
1265 return ret;
1266}
1267
1268int platform_get_snd_device_index(char *device_name)
1269{
1270 return find_index(snd_device_name_index, SND_DEVICE_MAX, device_name);
1271}
1272
1273int platform_get_usecase_index(const char *usecase_name)
1274{
1275 return find_index(usecase_name_index, AUDIO_USECASE_MAX, usecase_name);
1276}
1277
1278void platform_add_operator_specific_device(snd_device_t snd_device,
1279 const char *operator,
1280 const char *mixer_path,
1281 unsigned int acdb_id)
1282{
1283 struct operator_specific_device *device;
1284
1285 if (operator_specific_device_table[snd_device] == NULL) {
1286 operator_specific_device_table[snd_device] =
1287 (struct listnode *)calloc(1, sizeof(struct listnode));
1288 list_init(operator_specific_device_table[snd_device]);
1289 }
1290
1291 device = (struct operator_specific_device *)calloc(1, sizeof(struct operator_specific_device));
1292
1293 device->operator = strdup(operator);
1294 device->mixer_path = strdup(mixer_path);
1295 device->acdb_id = acdb_id;
1296
1297 list_add_tail(operator_specific_device_table[snd_device], &device->list);
1298
1299 ALOGD("%s: device[%s] -> operator[%s] mixer_path[%s] acdb_id[%d]", __func__,
1300 platform_get_snd_device_name(snd_device), operator, mixer_path, acdb_id);
1301
1302}
1303
1304int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
1305{
1306 int ret = 0;
1307
1308 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1309 ALOGE("%s: Invalid snd_device = %d",
1310 __func__, snd_device);
1311 ret = -EINVAL;
1312 goto done;
1313 }
1314 ALOGV("%s: acdb_device_table[%s]: old = %d new = %d", __func__,
1315 platform_get_snd_device_name(snd_device), acdb_device_table[snd_device], acdb_id);
1316 acdb_device_table[snd_device] = acdb_id;
1317done:
1318 return ret;
1319}
1320
Yamit Mehtae3b99562016-09-16 22:44:00 +05301321int platform_get_default_app_type_v2(void *platform, usecase_type_t type, int *app_type)
1322{
1323 ALOGV("%s: platform: %p, type: %d", __func__, platform, type);
1324 int rc = 0;
1325 if (type == PCM_CAPTURE) {
1326 *app_type = DEFAULT_APP_TYPE_TX_PATH;
1327 } else if (type == PCM_PLAYBACK) {
1328 *app_type = DEFAULT_APP_TYPE_RX_PATH;
1329 } else {
1330 rc = -EINVAL;
1331 }
1332 return rc;
1333}
1334
Yamit Mehta1d2e4742016-05-18 15:25:12 +05301335int platform_get_snd_device_acdb_id(snd_device_t snd_device)
1336{
1337 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1338 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1339 return -EINVAL;
1340 }
1341
1342 if (operator_specific_device_table[snd_device] != NULL)
1343 return get_operator_specific_device_acdb_id(snd_device);
1344 else
1345 return acdb_device_table[snd_device];
1346}
1347
1348int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
1349{
1350 struct platform_data *my_data = (struct platform_data *)platform;
1351 int acdb_dev_id, acdb_dev_type;
Yamit Mehtae3b99562016-09-16 22:44:00 +05301352 int sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
Yamit Mehta1d2e4742016-05-18 15:25:12 +05301353
1354 acdb_dev_id = acdb_device_table[audio_extn_get_spkr_prot_snd_device(snd_device)];
1355 if (acdb_dev_id < 0) {
1356 ALOGE("%s: Could not find acdb id for device(%d)",
1357 __func__, snd_device);
1358 return -EINVAL;
1359 }
Yamit Mehta1d2e4742016-05-18 15:25:12 +05301360 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
1361 __func__, snd_device, acdb_dev_id);
Yamit Mehtae3b99562016-09-16 22:44:00 +05301362 if (snd_device >= SND_DEVICE_OUT_BEGIN && snd_device < SND_DEVICE_OUT_END)
1363 acdb_dev_type = ACDB_DEV_TYPE_OUT;
1364 else
1365 acdb_dev_type = ACDB_DEV_TYPE_IN;
1366
Zheng Zhang858c3c62016-12-08 09:29:30 +08001367 if ((my_data->acdb_send_audio_cal_v3) &&
1368 (snd_device == SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP) &&
1369 !audio_extn_tfa_98xx_is_supported() ) {
Yamit Mehtae3b99562016-09-16 22:44:00 +05301370 /* TX path calibration */
1371 my_data->acdb_send_audio_cal_v3(acdb_dev_id, ACDB_DEV_TYPE_IN,
1372 DEFAULT_APP_TYPE_TX_PATH, sample_rate, BUFF_IDX_0);
1373 my_data->acdb_send_audio_cal_v3(acdb_dev_id, ACDB_DEV_TYPE_OUT,
1374 DEFAULT_APP_TYPE_RX_PATH, sample_rate, BUFF_IDX_0);
Zheng Zhang858c3c62016-12-08 09:29:30 +08001375 } else if ((my_data->acdb_send_audio_cal_v3) &&
1376 (snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_HFP) &&
1377 !audio_extn_tfa_98xx_is_supported()) {
Yamit Mehtae3b99562016-09-16 22:44:00 +05301378 /* RX path calibration */
1379 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
1380 __func__, snd_device, acdb_dev_id);
1381 my_data->acdb_send_audio_cal_v3(acdb_dev_id, ACDB_DEV_TYPE_IN,
1382 DEFAULT_APP_TYPE_TX_PATH, sample_rate, BUFF_IDX_1);
1383 my_data->acdb_send_audio_cal_v3(acdb_dev_id, ACDB_DEV_TYPE_OUT,
1384 DEFAULT_APP_TYPE_RX_PATH, sample_rate, BUFF_IDX_1);
1385 } else if (my_data->acdb_send_audio_cal) {
Yamit Mehta1d2e4742016-05-18 15:25:12 +05301386 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
1387 }
1388 return 0;
1389}
1390
1391int platform_switch_voice_call_device_pre(void *platform __unused)
1392{
1393 return 0;
1394}
1395
1396int platform_switch_voice_call_enable_device_config(void *platform __unused,
1397 snd_device_t out_snd_device __unused,
1398 snd_device_t in_snd_device __unused)
1399{
1400 return 0;
1401}
1402
1403int platform_switch_voice_call_device_post(void *platform,
1404 snd_device_t out_snd_device,
1405 snd_device_t in_snd_device)
1406{
1407 struct platform_data *my_data = (struct platform_data *)platform;
1408 int acdb_rx_id, acdb_tx_id;
1409
1410 if (my_data->acdb_send_voice_cal == NULL) {
1411 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
1412 } else {
1413 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1414 audio_extn_spkr_prot_is_enabled())
1415 out_snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED;
1416
1417 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
1418 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
1419
1420 if (acdb_rx_id > 0 && acdb_tx_id > 0)
1421 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
1422 else
1423 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1424 acdb_rx_id, acdb_tx_id);
1425 }
1426
1427 return 0;
1428}
1429
1430int platform_switch_voice_call_usecase_route_post(void *platform __unused,
1431 snd_device_t out_snd_device __unused,
1432 snd_device_t in_snd_device __unused)
1433{
1434 return 0;
1435}
1436
1437int platform_start_voice_call(void *platform __unused, uint32_t vsid __unused)
1438{
1439 return 0;
1440}
1441
1442int platform_stop_voice_call(void *platform __unused, uint32_t vsid __unused)
1443{
1444 return 0;
1445}
1446
1447int platform_get_sample_rate(void *platform __unused, uint32_t *rate __unused)
1448{
1449 return 0;
1450}
1451
1452void platform_set_speaker_gain_in_combo(struct audio_device *adev __unused,
1453 snd_device_t snd_device __unused,
1454 bool enable __unused)
1455{
1456 return;
1457}
1458
1459int platform_set_voice_volume(void *platform, int volume)
1460{
1461 struct platform_data *my_data = (struct platform_data *)platform;
1462 struct audio_device *adev = my_data->adev;
1463 struct mixer_ctl *ctl;
1464 const char *mixer_ctl_name = "Voice Rx Gain";
1465 int vol_index = 0, ret = 0;
1466 uint32_t set_values[ ] = {0,
1467 ALL_SESSION_VSID,
1468 DEFAULT_VOLUME_RAMP_DURATION_MS};
1469
1470 // Voice volume levels are mapped to adsp volume levels as follows.
1471 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
1472 // But this values don't changed in kernel. So, below change is need.
Tom Cherry6ebefdd2016-07-01 13:09:35 -07001473 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, my_data->max_vol_index);
Yamit Mehta1d2e4742016-05-18 15:25:12 +05301474 set_values[0] = vol_index;
1475
1476 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1477 if (!ctl) {
1478 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1479 __func__, mixer_ctl_name);
1480 return -EINVAL;
1481 }
1482 ALOGV("Setting voice volume index: %d", set_values[0]);
1483 ret = mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1484
1485 return ret;
1486}
1487
1488int platform_set_mic_mute(void *platform, bool state)
1489{
1490 struct platform_data *my_data = (struct platform_data *)platform;
1491 struct audio_device *adev = my_data->adev;
1492 struct mixer_ctl *ctl;
1493 const char *mixer_ctl_name = "Voice Tx Mute";
1494 int ret = 0;
Yamit Mehtaa2bdf6e2016-11-02 12:01:02 +05301495 uint32_t set_values[ ] = {0,
1496 ALL_SESSION_VSID,
1497 DEFAULT_MUTE_RAMP_DURATION_MS};
Yamit Mehta1d2e4742016-05-18 15:25:12 +05301498
Devin Kim152b09a2016-06-23 13:53:04 -07001499 if (audio_extn_hfp_is_active(adev))
Yamit Mehtabb15d172016-08-08 20:19:03 +05301500 mixer_ctl_name = "HFP TX Mute";
Devin Kim152b09a2016-06-23 13:53:04 -07001501
Yamit Mehta1d2e4742016-05-18 15:25:12 +05301502 set_values[0] = state;
1503 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1504 if (!ctl) {
1505 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1506 __func__, mixer_ctl_name);
1507 return -EINVAL;
1508 }
1509 ALOGV("Setting voice mute state: %d", state);
Yamit Mehtaa2bdf6e2016-11-02 12:01:02 +05301510 // "HFP TX mute" mixer control has xcount of 1.
1511 if (audio_extn_hfp_is_active(adev))
1512 ret = mixer_ctl_set_array(ctl, set_values, 1 /*count*/);
1513 else
1514 ret = mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
Yamit Mehta1d2e4742016-05-18 15:25:12 +05301515 return ret;
1516}
1517
1518int platform_set_device_mute(void *platform, bool state, char *dir)
1519{
1520 struct platform_data *my_data = (struct platform_data *)platform;
1521 struct audio_device *adev = my_data->adev;
1522 struct mixer_ctl *ctl;
1523 char *mixer_ctl_name = NULL;
1524 int ret = 0;
1525 uint32_t set_values[ ] = {0,
1526 ALL_SESSION_VSID,
1527 0};
1528 if(dir == NULL) {
1529 ALOGE("%s: Invalid direction:%s", __func__, dir);
1530 return -EINVAL;
1531 }
1532
1533 if (!strncmp("rx", dir, sizeof("rx"))) {
1534 mixer_ctl_name = "Voice Rx Device Mute";
1535 } else if (!strncmp("tx", dir, sizeof("tx"))) {
1536 mixer_ctl_name = "Voice Tx Device Mute";
1537 } else {
1538 return -EINVAL;
1539 }
1540
1541 set_values[0] = state;
1542 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1543 if (!ctl) {
1544 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1545 __func__, mixer_ctl_name);
1546 return -EINVAL;
1547 }
1548
1549 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
1550 __func__,state, mixer_ctl_name);
1551 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1552
1553 return ret;
1554}
1555
Haynes Mathew George2d809e02016-09-22 17:38:16 -07001556int platform_can_split_snd_device(snd_device_t snd_device,
Yamit Mehta1d2e4742016-05-18 15:25:12 +05301557 int *num_devices,
1558 snd_device_t *new_snd_devices)
1559{
Haynes Mathew George2d809e02016-09-22 17:38:16 -07001560 int ret = -EINVAL;
Yamit Mehta1d2e4742016-05-18 15:25:12 +05301561
1562 if (NULL == num_devices || NULL == new_snd_devices) {
1563 ALOGE("%s: NULL pointer ..", __func__);
Haynes Mathew George2d809e02016-09-22 17:38:16 -07001564 return -EINVAL;
Yamit Mehta1d2e4742016-05-18 15:25:12 +05301565 }
1566
1567 /*
1568 * If wired headset/headphones/line devices share the same backend
Haynes Mathew George2d809e02016-09-22 17:38:16 -07001569 * with speaker/earpiece this routine -EINVAL.
Yamit Mehta1d2e4742016-05-18 15:25:12 +05301570 */
1571 if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES &&
1572 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_HEADPHONES)) {
1573 *num_devices = 2;
1574 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
1575 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07001576 ret = 0;
Yamit Mehta1d2e4742016-05-18 15:25:12 +05301577 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_LINE &&
1578 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_LINE)) {
1579 *num_devices = 2;
1580 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
1581 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07001582 ret = 0;
Yamit Mehta1d2e4742016-05-18 15:25:12 +05301583 }
Haynes Mathew George2d809e02016-09-22 17:38:16 -07001584 return ret;
Yamit Mehta1d2e4742016-05-18 15:25:12 +05301585}
1586
1587snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
1588{
1589 struct platform_data *my_data = (struct platform_data *)platform;
1590 struct audio_device *adev = my_data->adev;
1591 audio_mode_t mode = adev->mode;
1592 snd_device_t snd_device = SND_DEVICE_NONE;
1593
1594 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
1595 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
1596 int channel_count = popcount(channel_mask);
1597
1598 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
1599 if (devices == AUDIO_DEVICE_NONE ||
1600 devices & AUDIO_DEVICE_BIT_IN) {
1601 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
1602 goto exit;
1603 }
1604
1605 if (popcount(devices) == 2) {
1606 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
1607 AUDIO_DEVICE_OUT_SPEAKER)) {
1608 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
1609 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
1610 AUDIO_DEVICE_OUT_SPEAKER)) {
1611 snd_device = SND_DEVICE_OUT_SPEAKER_AND_LINE;
1612 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
1613 AUDIO_DEVICE_OUT_SPEAKER)) {
1614 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
1615 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
1616 AUDIO_DEVICE_OUT_SPEAKER)) {
1617 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
1618 } else if (devices == (AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET |
1619 AUDIO_DEVICE_OUT_SPEAKER)) {
1620 snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET;
1621 } else {
1622 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
1623 goto exit;
1624 }
1625 if (snd_device != SND_DEVICE_NONE) {
1626 goto exit;
1627 }
1628 }
1629
1630 if (popcount(devices) != 1) {
1631 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
1632 goto exit;
1633 }
1634
Madhuri Athota3f6051b2016-10-13 23:25:38 +05301635 if (mode == AUDIO_MODE_IN_CALL || audio_extn_hfp_is_active(adev)) {
Yamit Mehta1d2e4742016-05-18 15:25:12 +05301636 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1637 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
1638 devices & AUDIO_DEVICE_OUT_LINE) {
1639 if (adev->voice.tty_mode != TTY_MODE_OFF) {
1640 switch (adev->voice.tty_mode) {
1641 case TTY_MODE_FULL:
1642 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
1643 break;
1644 case TTY_MODE_VCO:
1645 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
1646 break;
1647 case TTY_MODE_HCO:
1648 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
1649 break;
1650 default:
1651 ALOGE("%s: Invalid TTY mode (%#x)",
1652 __func__, adev->voice.tty_mode);
1653 }
1654 } else if (devices & AUDIO_DEVICE_OUT_LINE) {
1655 snd_device = SND_DEVICE_OUT_VOICE_LINE;
1656 } else {
1657 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
1658 }
1659 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
1660 if (adev->bt_wb_speech_enabled)
1661 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
1662 else
1663 snd_device = SND_DEVICE_OUT_BT_SCO;
1664 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
Devin Kim152b09a2016-06-23 13:53:04 -07001665 if (audio_extn_hfp_is_active(adev))
1666 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_HFP;
1667 else
1668 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
Yamit Mehta1d2e4742016-05-18 15:25:12 +05301669 } else if (devices & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
1670 devices & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
1671 snd_device = SND_DEVICE_OUT_USB_HEADSET;
1672 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
1673 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
1674 } else if (devices & AUDIO_DEVICE_OUT_TELEPHONY_TX)
1675 snd_device = SND_DEVICE_OUT_VOICE_TX;
1676
1677 if (snd_device != SND_DEVICE_NONE) {
1678 goto exit;
1679 }
1680 }
1681
1682 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1683 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
1684 snd_device = SND_DEVICE_OUT_HEADPHONES;
1685 } else if (devices & AUDIO_DEVICE_OUT_LINE) {
1686 snd_device = SND_DEVICE_OUT_LINE;
1687 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
1688 if (my_data->speaker_lr_swap)
1689 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
1690 else
1691 snd_device = SND_DEVICE_OUT_SPEAKER;
1692 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
1693 if (adev->bt_wb_speech_enabled)
1694 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
1695 else
1696 snd_device = SND_DEVICE_OUT_BT_SCO;
1697 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
1698 snd_device = SND_DEVICE_OUT_HDMI ;
1699 } else if (devices & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
1700 devices & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
1701 snd_device = SND_DEVICE_OUT_USB_HEADSET;
1702 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
1703 snd_device = SND_DEVICE_OUT_HANDSET;
Yamit Mehta1d2e4742016-05-18 15:25:12 +05301704 } else {
1705 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
1706 }
1707exit:
1708 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
1709 return snd_device;
1710}
1711
1712snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
1713{
1714 struct platform_data *my_data = (struct platform_data *)platform;
1715 struct audio_device *adev = my_data->adev;
1716 audio_source_t source = (adev->active_input == NULL) ?
1717 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
1718
1719 audio_mode_t mode = adev->mode;
1720 audio_devices_t in_device = ((adev->active_input == NULL) ?
1721 AUDIO_DEVICE_NONE : adev->active_input->device)
1722 & ~AUDIO_DEVICE_BIT_IN;
1723 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
1724 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
1725 snd_device_t snd_device = SND_DEVICE_NONE;
1726 int channel_count = popcount(channel_mask);
1727
1728 ALOGV("%s: enter: out_device(%#x) in_device(%#x)",
1729 __func__, out_device, in_device);
1730
1731 if ((out_device != AUDIO_DEVICE_NONE) && ((mode == AUDIO_MODE_IN_CALL) ||
1732 audio_extn_hfp_is_active(adev))) {
1733 if (adev->voice.tty_mode != TTY_MODE_OFF) {
1734 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1735 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
1736 out_device & AUDIO_DEVICE_OUT_LINE) {
1737 switch (adev->voice.tty_mode) {
1738 case TTY_MODE_FULL:
1739 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
1740 break;
1741 case TTY_MODE_VCO:
1742 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
1743 break;
1744 case TTY_MODE_HCO:
1745 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
1746 break;
1747 default:
1748 ALOGE("%s: Invalid TTY mode (%#x)",
1749 __func__, adev->voice.tty_mode);
1750 }
1751 goto exit;
1752 }
1753 }
1754 if (out_device & AUDIO_DEVICE_OUT_EARPIECE ||
1755 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1756 out_device & AUDIO_DEVICE_OUT_LINE) {
1757 if (my_data->fluence_type == FLUENCE_NONE ||
1758 my_data->fluence_in_voice_call == false) {
1759 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1760 if (audio_extn_hfp_is_active(adev))
1761 platform_set_echo_reference(adev, true, out_device);
1762 } else {
1763 snd_device = SND_DEVICE_IN_VOICE_DMIC;
1764 adev->acdb_settings |= DMIC_FLAG;
1765 }
1766 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
1767 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
1768 if (audio_extn_hfp_is_active(adev))
1769 platform_set_echo_reference(adev, true, out_device);
1770 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
1771 if (adev->bt_wb_speech_enabled) {
1772 if (adev->bluetooth_nrec)
1773 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
1774 else
1775 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
1776 } else {
1777 if (adev->bluetooth_nrec)
1778 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
1779 else
1780 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
1781 }
1782 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
1783 if (my_data->fluence_type != FLUENCE_NONE &&
1784 my_data->fluence_in_voice_call &&
1785 my_data->fluence_in_spkr_mode) {
1786 if(my_data->fluence_type & FLUENCE_QUAD_MIC) {
1787 adev->acdb_settings |= QMIC_FLAG;
1788 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_QMIC;
1789 } else {
1790 adev->acdb_settings |= DMIC_FLAG;
1791 if (my_data->fluence_mode == FLUENCE_BROADSIDE)
1792 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BROADSIDE;
1793 else
1794 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
1795 }
1796 } else {
1797 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
Devin Kim152b09a2016-06-23 13:53:04 -07001798 if (audio_extn_hfp_is_active(adev)) {
1799 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP;
Yamit Mehta1d2e4742016-05-18 15:25:12 +05301800 platform_set_echo_reference(adev, true, out_device);
Devin Kim152b09a2016-06-23 13:53:04 -07001801 } else {
1802 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
1803 }
Yamit Mehta1d2e4742016-05-18 15:25:12 +05301804 }
1805 } else if (out_device & AUDIO_DEVICE_OUT_TELEPHONY_TX)
1806 snd_device = SND_DEVICE_IN_VOICE_RX;
1807 } else if (source == AUDIO_SOURCE_CAMCORDER) {
1808 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
1809 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
1810 if (my_data->fluence_type & FLUENCE_DUAL_MIC &&
1811 channel_count == 2)
1812 snd_device = SND_DEVICE_IN_HANDSET_STEREO_DMIC;
1813 else
1814 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
1815 }
1816 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
1817 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
1818 if (channel_count == 2) {
1819 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
1820 adev->acdb_settings |= DMIC_FLAG;
1821 } else if (adev->active_input->enable_ns)
1822 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
1823 else if (my_data->fluence_type != FLUENCE_NONE &&
1824 my_data->fluence_in_voice_rec) {
1825 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
1826 adev->acdb_settings |= DMIC_FLAG;
1827 } else {
1828 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
1829 }
1830 }
1831 } else if ((source == AUDIO_SOURCE_VOICE_COMMUNICATION) ||
1832 (mode == AUDIO_MODE_IN_COMMUNICATION)) {
1833 if (out_device & AUDIO_DEVICE_OUT_SPEAKER)
1834 in_device = AUDIO_DEVICE_IN_BACK_MIC;
1835 if (adev->active_input) {
1836 if (my_data->fluence_type != FLUENCE_NONE &&
1837 adev->active_input->enable_aec &&
1838 adev->active_input->enable_ns) {
1839 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
1840 if (my_data->fluence_in_spkr_mode) {
1841 if (my_data->fluence_type & FLUENCE_QUAD_MIC) {
1842 snd_device = SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS;
1843 } else if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1844 if (my_data->fluence_mode == FLUENCE_BROADSIDE)
1845 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_BROADSIDE;
1846 else
1847 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
1848 }
1849 adev->acdb_settings |= DMIC_FLAG;
1850 } else
1851 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
1852 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
1853 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1854 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
1855 adev->acdb_settings |= DMIC_FLAG;
1856 } else
1857 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
1858 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
1859 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
1860 }
1861 platform_set_echo_reference(adev, true, out_device);
1862 } else if (my_data->fluence_type != FLUENCE_NONE &&
1863 adev->active_input->enable_aec) {
1864 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
1865 if (my_data->fluence_in_spkr_mode) {
1866 if (my_data->fluence_type & FLUENCE_QUAD_MIC) {
1867 snd_device = SND_DEVICE_IN_SPEAKER_QMIC_AEC;
1868 } else if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1869 if (my_data->fluence_mode == FLUENCE_BROADSIDE)
1870 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_BROADSIDE;
1871 else
1872 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
1873 }
1874 adev->acdb_settings |= DMIC_FLAG;
1875 } else
1876 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
1877 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
1878 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1879 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
1880 adev->acdb_settings |= DMIC_FLAG;
1881 } else
1882 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
1883 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
1884 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
1885 }
1886 platform_set_echo_reference(adev, true, out_device);
1887 } else if (my_data->fluence_type != FLUENCE_NONE &&
1888 adev->active_input->enable_ns) {
1889 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
1890 if (my_data->fluence_in_spkr_mode) {
1891 if (my_data->fluence_type & FLUENCE_QUAD_MIC) {
1892 snd_device = SND_DEVICE_IN_SPEAKER_QMIC_NS;
1893 } else if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1894 if (my_data->fluence_mode == FLUENCE_BROADSIDE)
1895 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS_BROADSIDE;
1896 else
1897 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
1898 }
1899 adev->acdb_settings |= DMIC_FLAG;
1900 } else
1901 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
1902 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
1903 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1904 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
1905 adev->acdb_settings |= DMIC_FLAG;
1906 } else
1907 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
1908 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
1909 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
1910 }
1911 platform_set_echo_reference(adev, false, out_device);
1912 } else
1913 platform_set_echo_reference(adev, false, out_device);
1914 }
1915 } else if (source == AUDIO_SOURCE_FM_TUNER) {
1916 snd_device = SND_DEVICE_IN_CAPTURE_FM;
1917 } else if (source == AUDIO_SOURCE_DEFAULT) {
1918 goto exit;
1919 }
1920
1921
1922 if (snd_device != SND_DEVICE_NONE) {
1923 goto exit;
1924 }
1925
1926 if (in_device != AUDIO_DEVICE_NONE &&
1927 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
1928 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
1929 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
1930 if (my_data->fluence_type & (FLUENCE_DUAL_MIC | FLUENCE_QUAD_MIC) &&
1931 channel_count == 2)
1932 snd_device = SND_DEVICE_IN_HANDSET_STEREO_DMIC;
1933 else
1934 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1935 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
1936 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
1937 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
1938 snd_device = SND_DEVICE_IN_HEADSET_MIC;
1939 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
1940 if (adev->bt_wb_speech_enabled) {
1941 if (adev->bluetooth_nrec)
1942 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
1943 else
1944 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
1945 } else {
1946 if (adev->bluetooth_nrec)
1947 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
1948 else
1949 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
1950 }
1951 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
1952 snd_device = SND_DEVICE_IN_HDMI_MIC;
1953 } else if (in_device & AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET ||
1954 in_device & AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET) {
1955 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
1956 } else if (in_device & AUDIO_DEVICE_IN_FM_TUNER) {
1957 snd_device = SND_DEVICE_IN_CAPTURE_FM;
1958 } else {
1959 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
1960 ALOGW("%s: Using default handset-mic", __func__);
1961 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1962 }
1963 } else {
1964 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
1965 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1966 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
1967 snd_device = SND_DEVICE_IN_HEADSET_MIC;
1968 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
1969 if (channel_count > 1)
1970 snd_device = SND_DEVICE_IN_SPEAKER_STEREO_DMIC;
1971 else
1972 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
1973 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1974 out_device & AUDIO_DEVICE_OUT_LINE) {
1975 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1976 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
1977 if (adev->bt_wb_speech_enabled) {
1978 if (adev->bluetooth_nrec)
1979 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
1980 else
1981 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
1982 } else {
1983 if (adev->bluetooth_nrec)
1984 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
1985 else
1986 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
1987 }
1988 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
1989 snd_device = SND_DEVICE_IN_HDMI_MIC;
1990 } else if (out_device & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
1991 out_device & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
1992 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
1993 } else {
1994 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
1995 ALOGW("%s: Using default handset-mic", __func__);
1996 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1997 }
1998 }
1999exit:
2000 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
2001 return snd_device;
2002}
2003
2004int platform_set_hdmi_channels(void *platform, int channel_count)
2005{
2006 struct platform_data *my_data = (struct platform_data *)platform;
2007 struct audio_device *adev = my_data->adev;
2008 struct mixer_ctl *ctl;
2009 const char *channel_cnt_str = NULL;
2010 const char *mixer_ctl_name = "HDMI_RX Channels";
2011 switch (channel_count) {
2012 case 8:
2013 channel_cnt_str = "Eight"; break;
2014 case 7:
2015 channel_cnt_str = "Seven"; break;
2016 case 6:
2017 channel_cnt_str = "Six"; break;
2018 case 5:
2019 channel_cnt_str = "Five"; break;
2020 case 4:
2021 channel_cnt_str = "Four"; break;
2022 case 3:
2023 channel_cnt_str = "Three"; break;
2024 default:
2025 channel_cnt_str = "Two"; break;
2026 }
2027 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2028 if (!ctl) {
2029 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2030 __func__, mixer_ctl_name);
2031 return -EINVAL;
2032 }
2033 ALOGV("HDMI channel count: %s", channel_cnt_str);
2034 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
2035 return 0;
2036}
2037
2038int platform_edid_get_max_channels(void *platform)
2039{
2040 struct platform_data *my_data = (struct platform_data *)platform;
2041 struct audio_device *adev = my_data->adev;
2042 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
2043 char *sad = block;
2044 int num_audio_blocks;
2045 int channel_count;
2046 int max_channels = 0;
2047 int i, ret, count;
2048
2049 struct mixer_ctl *ctl;
2050
2051 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
2052 if (!ctl) {
2053 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2054 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
2055 return 0;
2056 }
2057
2058 mixer_ctl_update(ctl);
2059
2060 count = mixer_ctl_get_num_values(ctl);
2061
2062 /* Read SAD blocks, clamping the maximum size for safety */
2063 if (count > (int)sizeof(block))
2064 count = (int)sizeof(block);
2065
2066 ret = mixer_ctl_get_array(ctl, block, count);
2067 if (ret != 0) {
2068 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
2069 return 0;
2070 }
2071
2072 /* Calculate the number of SAD blocks */
2073 num_audio_blocks = count / SAD_BLOCK_SIZE;
2074
2075 for (i = 0; i < num_audio_blocks; i++) {
2076 /* Only consider LPCM blocks */
2077 if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
2078 sad += 3;
2079 continue;
2080 }
2081
2082 channel_count = (sad[0] & 0x7) + 1;
2083 if (channel_count > max_channels)
2084 max_channels = channel_count;
2085
2086 /* Advance to next block */
2087 sad += 3;
2088 }
2089
2090 return max_channels;
2091}
2092
2093int platform_set_incall_recording_session_id(void *platform,
2094 uint32_t session_id,
2095 int rec_mode __unused)
2096{
2097 int ret = 0;
2098 struct platform_data *my_data = (struct platform_data *)platform;
2099 struct audio_device *adev = my_data->adev;
2100 struct mixer_ctl *ctl;
2101 const char *mixer_ctl_name = "Voc VSID";
2102 int num_ctl_values;
2103 int i;
2104
2105 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2106 if (!ctl) {
2107 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2108 __func__, mixer_ctl_name);
2109 ret = -EINVAL;
2110 } else {
2111 num_ctl_values = mixer_ctl_get_num_values(ctl);
2112 for (i = 0; i < num_ctl_values; i++) {
2113 if (mixer_ctl_set_value(ctl, i, session_id)) {
2114 ALOGV("Error: invalid session_id: %x", session_id);
2115 ret = -EINVAL;
2116 break;
2117 }
2118 }
2119 }
2120 return ret;
2121}
2122
2123int platform_stop_incall_recording_usecase(void *platform __unused)
2124{
2125 return 0;
2126}
2127
2128int platform_start_incall_music_usecase(void *platform __unused)
2129{
2130 return 0;
2131}
2132
2133int platform_stop_incall_music_usecase(void *platform __unused)
2134{
2135 return 0;
2136}
2137
2138int platform_set_parameters(void *platform, struct str_parms *parms)
2139{
2140 struct platform_data *my_data = (struct platform_data *)platform;
2141 char value[128];
2142 char *kv_pairs = str_parms_to_str(parms);
2143 int ret = 0, err;
2144
2145 if (kv_pairs == NULL) {
2146 ret = -EINVAL;
2147 ALOGE("%s: key-value pair is NULL",__func__);
2148 goto done;
2149 }
2150
2151 ALOGV("%s: enter: %s", __func__, kv_pairs);
2152
2153 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO,
2154 value, sizeof(value));
2155 if (err >= 0) {
2156 struct operator_info *info;
2157 char *str = value;
2158 char *name;
2159
2160 str_parms_del(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO);
2161 info = (struct operator_info *)calloc(1, sizeof(struct operator_info));
2162 name = strtok(str, ";");
2163 info->name = strdup(name);
2164 info->mccmnc = strdup(str + strlen(name) + 1);
2165
2166 list_add_tail(&operator_info_list, &info->list);
2167 ALOGV("%s: add operator[%s] mccmnc[%s]", __func__, info->name, info->mccmnc);
2168 }
Surendar karka56631b52016-07-13 15:08:39 -07002169
2170 audio_extn_hfp_set_parameters(my_data->adev, parms);
Yamit Mehta1d2e4742016-05-18 15:25:12 +05302171done:
2172 ALOGV("%s: exit with code(%d)", __func__, ret);
2173 if (kv_pairs != NULL)
2174 free(kv_pairs);
2175
2176 return ret;
2177}
2178
2179/* Delay in Us */
2180int64_t platform_render_latency(audio_usecase_t usecase)
2181{
2182 switch (usecase) {
2183 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
2184 return DEEP_BUFFER_PLATFORM_DELAY;
2185 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
2186 return LOW_LATENCY_PLATFORM_DELAY;
2187 default:
2188 return 0;
2189 }
2190}
2191
2192int platform_set_snd_device_backend(snd_device_t device, const char *backend, const char * hw_interface)
2193{
2194 int ret = 0;
2195
2196 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
2197 ALOGE("%s: Invalid snd_device = %d",
2198 __func__, device);
2199 ret = -EINVAL;
2200 goto done;
2201 }
2202
2203 ALOGV("%s: backend_tag_table[%s]: old = %s new = %s", __func__,
2204 platform_get_snd_device_name(device),
2205 backend_table[device] != NULL ? backend_table[device]: "null", backend);
2206 if (backend_table[device]) {
2207 free(backend_table[device]);
2208 }
2209 backend_table[device] = strdup(backend);
2210
2211 if (hw_interface != NULL) {
2212 if (hw_interface_table[device])
2213 free(hw_interface_table[device]);
2214 ALOGV("%s: hw_interface_table[%d] = %s", __func__, device, hw_interface);
2215 hw_interface_table[device] = strdup(hw_interface);
2216 }
2217done:
2218 return ret;
2219}
2220
2221int platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t pcm_id)
2222{
2223 int ret = 0;
2224 if ((usecase <= USECASE_INVALID) || (usecase >= AUDIO_USECASE_MAX)) {
2225 ALOGE("%s: invalid usecase case idx %d", __func__, usecase);
2226 ret = -EINVAL;
2227 goto done;
2228 }
2229
2230 if ((type != 0) && (type != 1)) {
2231 ALOGE("%s: invalid usecase type", __func__);
2232 ret = -EINVAL;
2233 }
2234 pcm_device_table[usecase][type] = pcm_id;
2235done:
2236 return ret;
2237}
2238
2239#define DEFAULT_NOMINAL_SPEAKER_GAIN 20
2240int ramp_speaker_gain(struct audio_device *adev, bool ramp_up, int target_ramp_up_gain) {
2241 // backup_gain: gain to try to set in case of an error during ramp
2242 int start_gain, end_gain, step, backup_gain, i;
2243 bool error = false;
2244 const struct mixer_ctl *ctl;
2245 const char *mixer_ctl_name_gain_left = "Left Speaker Gain";
2246 const char *mixer_ctl_name_gain_right = "Right Speaker Gain";
2247 struct mixer_ctl *ctl_left = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_left);
2248 struct mixer_ctl *ctl_right = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_right);
2249 if (!ctl_left || !ctl_right) {
2250 ALOGE("%s: Could not get ctl for mixer cmd - %s or %s, not applying speaker gain ramp",
2251 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
2252 return -EINVAL;
2253 } else if ((mixer_ctl_get_num_values(ctl_left) != 1)
2254 || (mixer_ctl_get_num_values(ctl_right) != 1)) {
2255 ALOGE("%s: Unexpected num values for mixer cmd - %s or %s, not applying speaker gain ramp",
2256 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
2257 return -EINVAL;
2258 }
2259 if (ramp_up) {
2260 start_gain = 0;
2261 end_gain = target_ramp_up_gain > 0 ? target_ramp_up_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
2262 step = +1;
2263 backup_gain = end_gain;
2264 } else {
2265 // using same gain on left and right
2266 const int left_gain = mixer_ctl_get_value(ctl_left, 0);
2267 start_gain = left_gain > 0 ? left_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
2268 end_gain = 0;
2269 step = -1;
2270 backup_gain = start_gain;
2271 }
2272 for (i = start_gain ; i != (end_gain + step) ; i += step) {
2273 //ALOGV("setting speaker gain to %d", i);
2274 if (mixer_ctl_set_value(ctl_left, 0, i)) {
2275 ALOGE("%s: error setting %s to %d during gain ramp",
2276 __func__, mixer_ctl_name_gain_left, i);
2277 error = true;
2278 break;
2279 }
2280 if (mixer_ctl_set_value(ctl_right, 0, i)) {
2281 ALOGE("%s: error setting %s to %d during gain ramp",
2282 __func__, mixer_ctl_name_gain_right, i);
2283 error = true;
2284 break;
2285 }
2286 usleep(1000);
2287 }
2288 if (error) {
2289 // an error occured during the ramp, let's still try to go back to a safe volume
2290 if (mixer_ctl_set_value(ctl_left, 0, backup_gain)) {
2291 ALOGE("%s: error restoring left gain to %d", __func__, backup_gain);
2292 }
2293 if (mixer_ctl_set_value(ctl_right, 0, backup_gain)) {
2294 ALOGE("%s: error restoring right gain to %d", __func__, backup_gain);
2295 }
2296 }
2297 return start_gain;
2298}
2299
vivek mehtae59cfb22017-06-16 15:57:11 -07002300int platform_set_swap_mixer(struct audio_device *adev, bool swap_channels)
2301{
2302 const char *mixer_ctl_name = "Swap channel";
2303 struct mixer_ctl *ctl;
2304 const char *mixer_path;
2305 struct platform_data *my_data = (struct platform_data *)adev->platform;
2306
2307 // forced to set to swap, but device not rotated ... ignore set
2308 if (swap_channels && !my_data->speaker_lr_swap)
2309 return 0;
2310
2311 ALOGV("%s:", __func__);
2312
2313 if (swap_channels) {
2314 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER_REVERSE);
2315 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
2316 } else {
2317 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER);
2318 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
2319 }
2320
2321 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2322 if (!ctl) {
2323 ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name);
2324 return -EINVAL;
2325 }
2326
2327 if (mixer_ctl_set_value(ctl, 0, swap_channels) < 0) {
2328 ALOGE("%s: Could not set reverse cotrol %d",__func__, swap_channels);
2329 return -EINVAL;
2330 }
2331
2332 ALOGV("platfor_force_swap_channel :: Channel orientation ( %s ) ",
2333 swap_channels?"R --> L":"L --> R");
2334
2335 return 0;
2336}
2337
2338int platform_check_and_set_swap_lr_channels(struct audio_device *adev, bool swap_channels)
Yamit Mehta1d2e4742016-05-18 15:25:12 +05302339{
2340 // only update if there is active pcm playback on speaker
2341 struct audio_usecase *usecase;
2342 struct listnode *node;
2343 struct platform_data *my_data = (struct platform_data *)adev->platform;
2344
vivek mehtae59cfb22017-06-16 15:57:11 -07002345 my_data->speaker_lr_swap = swap_channels;
Yamit Mehta1d2e4742016-05-18 15:25:12 +05302346
vivek mehtae59cfb22017-06-16 15:57:11 -07002347 return platform_set_swap_channels(adev, swap_channels);
2348}
2349
2350int platform_set_swap_channels(struct audio_device *adev, bool swap_channels)
2351{
2352 // only update if there is active pcm playback on speaker
2353 struct audio_usecase *usecase;
2354 struct listnode *node;
2355 struct platform_data *my_data = (struct platform_data *)adev->platform;
2356
2357 // do not swap channels in audio modes with concurrent capture and playback
2358 // as this may break the echo reference
2359 if ((adev->mode == AUDIO_MODE_IN_COMMUNICATION) || (adev->mode == AUDIO_MODE_IN_CALL)) {
2360 ALOGV("%s: will not swap due to audio mode %d", __func__, adev->mode);
2361 return 0;
2362 }
2363
2364 list_for_each(node, &adev->usecase_list) {
2365 usecase = node_to_item(node, struct audio_usecase, list);
2366 if (usecase->type == PCM_PLAYBACK &&
2367 usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) {
2368 /*
2369 * If acdb tuning is different for SPEAKER_REVERSE, it is must
2370 * to perform device switch to disable the current backend to
2371 * enable it with new acdb data.
2372 */
2373 if (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
2374 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]) {
2375 const int initial_skpr_gain = ramp_speaker_gain(adev, false /*ramp_up*/, -1);
2376 select_devices(adev, usecase->id);
2377 if (initial_skpr_gain != -EINVAL)
2378 ramp_speaker_gain(adev, true /*ramp_up*/, initial_skpr_gain);
2379
2380 } else {
2381 platform_set_swap_mixer(adev, swap_channels);
Yamit Mehta1d2e4742016-05-18 15:25:12 +05302382 }
vivek mehtae59cfb22017-06-16 15:57:11 -07002383 break;
Yamit Mehta1d2e4742016-05-18 15:25:12 +05302384 }
2385 }
vivek mehtae59cfb22017-06-16 15:57:11 -07002386
Yamit Mehta1d2e4742016-05-18 15:25:12 +05302387 return 0;
2388}
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07002389
Tom Cherry8721b4d2016-07-14 16:12:23 -07002390int platform_snd_card_update(void *platform __unused,
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07002391 card_status_t status __unused)
2392{
2393 return -1;
2394}
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002395
Chris Phoenix25df5e32017-05-18 18:37:56 -07002396int platform_send_audio_calibration_v2(void *platform __unused,
2397 struct audio_usecase *usecase __unused,
2398 int app_type __unused,
2399 int sample_rate __unused)
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002400{
2401 return -ENOSYS;
2402}
2403
Chris Phoenix25df5e32017-05-18 18:37:56 -07002404void platform_check_and_update_copp_sample_rate(void* platform __unused,
2405 snd_device_t snd_device __unused,
2406 unsigned int stream_sr __unused,
2407 int* sample_rate __unused)
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002408{
2409
2410}
2411
Chris Phoenix25df5e32017-05-18 18:37:56 -07002412int platform_get_snd_device_backend_index(snd_device_t snd_device __unused)
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002413{
2414 return -ENOSYS;
2415}
2416
2417bool platform_supports_app_type_cfg() { return false; }
2418
vivek mehtaa68fea62017-06-08 19:04:02 -07002419void platform_add_app_type(const char *uc_type __unused,
2420 const char *mode __unused,
2421 int bw __unused, int app_type __unused,
2422 int max_sr __unused) {}
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002423
Chris Phoenix25df5e32017-05-18 18:37:56 -07002424int platform_get_app_type_v2(void *platform __unused,
2425 enum usecase_type_t type __unused,
vivek mehtaa68fea62017-06-08 19:04:02 -07002426 const char *mode __unused,
Chris Phoenix25df5e32017-05-18 18:37:56 -07002427 int bw __unused, int sr __unused,
2428 int *app_type __unused) {
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002429 return -ENOSYS;
2430}
vivek mehtaa68fea62017-06-08 19:04:02 -07002431
vivek mehta90933872017-06-15 18:04:39 -07002432int platform_set_sidetone(struct audio_device *adev,
2433 snd_device_t out_snd_device,
2434 bool enable, char *str)
2435{
2436 int ret;
2437 if (out_snd_device == SND_DEVICE_OUT_USB_HEADSET ||
2438 out_snd_device == SND_DEVICE_OUT_VOICE_USB_HEADSET) {
2439 ret = audio_extn_usb_enable_sidetone(out_snd_device, enable);
2440 if (ret)
2441 ALOGI("%s: usb device %d does not support device sidetone\n",
2442 __func__, out_snd_device);
2443 } else {
2444 ALOGV("%s: sidetone out device(%d) mixer cmd = %s\n",
2445 __func__, out_snd_device, str);
2446
2447 if (enable)
2448 audio_route_apply_and_update_path(adev->audio_route, str);
2449 else
2450 audio_route_reset_and_update_path(adev->audio_route, str);
2451 }
2452 return 0;
2453}
Haynes Mathew George96483a22017-03-28 14:52:47 -07002454
2455int platform_get_mmap_data_fd(void *platform __unused, int fe_dev __unused, int dir __unused,
2456 int *fd __unused, uint32_t *size __unused)
2457{
2458 return -ENOSYS;
2459}