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