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