1 /*
2 * Copyright (C) 2013-2014 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 "msm8960_platform"
18 /*#define LOG_NDEBUG 0*/
19 #define LOG_NDDEBUG 0
20
21 #include <stdlib.h>
22 #include <dlfcn.h>
23 #include <cutils/log.h>
24 #include <cutils/properties.h>
25 #include <audio_hw.h>
26 #include <platform_api.h>
27 #include "platform.h"
28 #include "audio_extn.h"
29
30 #define LIB_ACDB_LOADER "libacdbloader.so"
31 #define LIB_CSD_CLIENT "libcsd-client.so"
32
33 #define DUALMIC_CONFIG_NONE 0 /* Target does not contain 2 mics */
34 #define DUALMIC_CONFIG_ENDFIRE 1
35 #define DUALMIC_CONFIG_BROADSIDE 2
36
37 /*
38 * This is the sysfs path for the HDMI audio data block
39 */
40 #define AUDIO_DATA_BLOCK_PATH "/sys/class/graphics/fb1/audio_data_block"
41 #define MIXER_XML_PATH "/system/etc/mixer_paths.xml"
42
43 /*
44 * This file will have a maximum of 38 bytes:
45 *
46 * 4 bytes: number of audio blocks
47 * 4 bytes: total length of Short Audio Descriptor (SAD) blocks
48 * Maximum 10 * 3 bytes: SAD blocks
49 */
50 #define MAX_SAD_BLOCKS 10
51 #define SAD_BLOCK_SIZE 3
52
53 /* EDID format ID for LPCM audio */
54 #define EDID_FORMAT_LPCM 1
55
56 struct audio_block_header
57 {
58 int reserved;
59 int length;
60 };
61
62
63 typedef void (*acdb_deallocate_t)();
64 typedef int (*acdb_init_t)();
65 typedef void (*acdb_send_audio_cal_t)(int, int);
66 typedef void (*acdb_send_voice_cal_t)(int, int);
67
68 typedef int (*csd_client_init_t)();
69 typedef int (*csd_client_deinit_t)();
70 typedef int (*csd_disable_device_t)();
71 typedef int (*csd_enable_device_t)(int, int, uint32_t);
72 typedef int (*csd_volume_t)(int);
73 typedef int (*csd_mic_mute_t)(int);
74 typedef int (*csd_start_voice_t)();
75 typedef int (*csd_stop_voice_t)();
76
77
78 /* Audio calibration related functions */
79 struct platform_data {
80 struct audio_device *adev;
81 bool fluence_in_spkr_mode;
82 bool fluence_in_voice_call;
83 bool fluence_in_voice_rec;
84 int dualmic_config;
85 bool speaker_lr_swap;
86
87 void *acdb_handle;
88 acdb_init_t acdb_init;
89 acdb_deallocate_t acdb_deallocate;
90 acdb_send_audio_cal_t acdb_send_audio_cal;
91 acdb_send_voice_cal_t acdb_send_voice_cal;
92
93 /* CSD Client related functions for voice call */
94 void *csd_client;
95 csd_client_init_t csd_client_init;
96 csd_client_deinit_t csd_client_deinit;
97 csd_disable_device_t csd_disable_device;
98 csd_enable_device_t csd_enable_device;
99 csd_volume_t csd_volume;
100 csd_mic_mute_t csd_mic_mute;
101 csd_start_voice_t csd_start_voice;
102 csd_stop_voice_t csd_stop_voice;
103 };
104
105 static const int pcm_device_table[AUDIO_USECASE_MAX][2] = {
106 [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = {0, 0},
107 [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = {14, 14},
108 [USECASE_AUDIO_PLAYBACK_HIFI] = {1, 1},
109 [USECASE_AUDIO_RECORD] = {0, 0},
110 [USECASE_AUDIO_RECORD_LOW_LATENCY] = {14, 14},
111 [USECASE_VOICE_CALL] = {12, 12},
112 };
113
114 /* Array to store sound devices */
115 static const char * const device_table[SND_DEVICE_MAX] = {
116 [SND_DEVICE_NONE] = "none",
117 /* Playback sound devices */
118 [SND_DEVICE_OUT_HANDSET] = "handset",
119 [SND_DEVICE_OUT_SPEAKER] = "speaker",
120 [SND_DEVICE_OUT_SPEAKER_REVERSE] = "speaker-reverse",
121 [SND_DEVICE_OUT_HEADPHONES] = "headphones",
122 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones",
123 [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker",
124 [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones",
125 [SND_DEVICE_OUT_HDMI] = "hdmi",
126 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi",
127 [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset",
128 [SND_DEVICE_OUT_BT_SCO_WB] = "bt-sco-headset-wb",
129 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = "voice-handset-tmus",
130 [SND_DEVICE_OUT_VOICE_HANDSET] = "voice-handset-tmus",
131 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = "voice-handset-tmus",
132 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones",
133 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones",
134 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset",
135 [SND_DEVICE_OUT_USB_HEADSET] = "usb-headset",
136 [SND_DEVICE_OUT_USB_HEADPHONES] = "usb-headphones",
137 [SND_DEVICE_OUT_VOICE_USB_HEADSET] = "usb-headset",
138 [SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = "usb-headphones",
139
140
141 /* Capture sound devices */
142 [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
143 [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
144 [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
145 [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic",
146 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "voice-speaker-mic",
147 [SND_DEVICE_IN_HEADSET_MIC_AEC] = "headset-mic",
148 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
149 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
150 [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic",
151 [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
152 [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb",
153 [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic",
154 [SND_DEVICE_IN_VOICE_DMIC_EF] = "voice-dmic-ef",
155 [SND_DEVICE_IN_VOICE_DMIC_BS] = "voice-dmic-bs",
156 [SND_DEVICE_IN_VOICE_DMIC_EF_TMUS] = "voice-dmic-ef-tmus",
157 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_EF] = "voice-speaker-dmic-ef",
158 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BS] = "voice-speaker-dmic-bs",
159 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
160 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
161 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
162 [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
163 [SND_DEVICE_IN_VOICE_REC_DMIC_EF] = "voice-rec-dmic-ef",
164 [SND_DEVICE_IN_VOICE_REC_DMIC_BS] = "voice-rec-dmic-bs",
165 [SND_DEVICE_IN_VOICE_REC_DMIC_EF_FLUENCE] = "voice-rec-dmic-ef-fluence",
166 [SND_DEVICE_IN_VOICE_REC_DMIC_BS_FLUENCE] = "voice-rec-dmic-bs-fluence",
167 };
168
169 /* ACDB IDs (audio DSP path configuration IDs) for each sound device */
170 static const int acdb_device_table[SND_DEVICE_MAX] = {
171 [SND_DEVICE_NONE] = -1,
172 [SND_DEVICE_OUT_HANDSET] = 7,
173 [SND_DEVICE_OUT_SPEAKER] = 14,
174 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 14,
175 [SND_DEVICE_OUT_HEADPHONES] = 10,
176 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
177 [SND_DEVICE_OUT_VOICE_SPEAKER] = 14,
178 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
179 [SND_DEVICE_OUT_HDMI] = 18,
180 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 14,
181 [SND_DEVICE_OUT_BT_SCO] = 22,
182 [SND_DEVICE_OUT_BT_SCO_WB] = 39,
183 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = 81,
184 [SND_DEVICE_OUT_VOICE_HANDSET] = 81,
185 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = 81,
186 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
187 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
188 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
189 [SND_DEVICE_OUT_USB_HEADSET] = 45,
190 [SND_DEVICE_OUT_USB_HEADPHONES] = 45,
191 [SND_DEVICE_OUT_VOICE_USB_HEADSET] = 45,
192 [SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = 45,
193
194 [SND_DEVICE_IN_HANDSET_MIC] = 4,
195 [SND_DEVICE_IN_SPEAKER_MIC] = 4,
196 [SND_DEVICE_IN_HEADSET_MIC] = 8,
197 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 40,
198 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 42,
199 [SND_DEVICE_IN_HEADSET_MIC_AEC] = 47,
200 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
201 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = 8,
202 [SND_DEVICE_IN_HDMI_MIC] = 4,
203 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
204 [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38,
205 [SND_DEVICE_IN_CAMCORDER_MIC] = 61,
206 [SND_DEVICE_IN_VOICE_DMIC_EF] = 6,
207 [SND_DEVICE_IN_VOICE_DMIC_BS] = 5,
208 [SND_DEVICE_IN_VOICE_DMIC_EF_TMUS] = 91,
209 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_EF] = 13,
210 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BS] = 12,
211 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
212 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
213 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
214 [SND_DEVICE_IN_VOICE_REC_MIC] = 62,
215 /* TODO: Update with proper acdb ids */
216 [SND_DEVICE_IN_VOICE_REC_DMIC_EF] = 62,
217 [SND_DEVICE_IN_VOICE_REC_DMIC_BS] = 62,
218 [SND_DEVICE_IN_VOICE_REC_DMIC_EF_FLUENCE] = 6,
219 [SND_DEVICE_IN_VOICE_REC_DMIC_BS_FLUENCE] = 5,
220 };
221
222 #define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
223 #define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
224
225 static pthread_once_t check_op_once_ctl = PTHREAD_ONCE_INIT;
226 static bool is_tmus = false;
227
check_operator()228 static void check_operator()
229 {
230 char value[PROPERTY_VALUE_MAX];
231 int mccmnc;
232 property_get("gsm.sim.operator.numeric",value,"0");
233 mccmnc = atoi(value);
234 ALOGD("%s: tmus mccmnc %d", __func__, mccmnc);
235 switch(mccmnc) {
236 /* TMUS MCC(310), MNC(490, 260, 026) */
237 case 310490:
238 case 310260:
239 case 310026:
240 is_tmus = true;
241 break;
242 }
243 }
244
is_operator_tmus()245 bool is_operator_tmus()
246 {
247 pthread_once(&check_op_once_ctl, check_operator);
248 return is_tmus;
249 }
250
set_echo_reference(struct mixer * mixer,const char * ec_ref)251 static int set_echo_reference(struct mixer *mixer, const char* ec_ref)
252 {
253 struct mixer_ctl *ctl;
254 const char *mixer_ctl_name = "EC_REF_RX";
255
256 ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name);
257 if (!ctl) {
258 ALOGE("%s: Could not get ctl for mixer cmd - %s",
259 __func__, mixer_ctl_name);
260 return -EINVAL;
261 }
262 ALOGV("Setting EC Reference: %s", ec_ref);
263 mixer_ctl_set_enum_by_string(ctl, ec_ref);
264 return 0;
265 }
266
platform_init(struct audio_device * adev)267 void *platform_init(struct audio_device *adev)
268 {
269 char platform[PROPERTY_VALUE_MAX];
270 char baseband[PROPERTY_VALUE_MAX];
271 char value[PROPERTY_VALUE_MAX];
272 struct platform_data *my_data;
273
274 adev->mixer = mixer_open(MIXER_CARD);
275
276 if (!adev->mixer) {
277 ALOGE("Unable to open the mixer, aborting.");
278 return NULL;
279 }
280
281 adev->audio_route = audio_route_init(MIXER_CARD, MIXER_XML_PATH);
282 if (!adev->audio_route) {
283 ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
284 return NULL;
285 }
286
287 my_data = calloc(1, sizeof(struct platform_data));
288
289 my_data->adev = adev;
290 my_data->dualmic_config = DUALMIC_CONFIG_NONE;
291 my_data->fluence_in_spkr_mode = false;
292 my_data->fluence_in_voice_call = false;
293 my_data->fluence_in_voice_rec = false;
294
295 property_get("persist.audio.dualmic.config",value,"");
296 if (!strcmp("broadside", value)) {
297 my_data->dualmic_config = DUALMIC_CONFIG_BROADSIDE;
298 adev->acdb_settings |= DMIC_FLAG;
299 } else if (!strcmp("endfire", value)) {
300 my_data->dualmic_config = DUALMIC_CONFIG_ENDFIRE;
301 adev->acdb_settings |= DMIC_FLAG;
302 }
303
304 if (my_data->dualmic_config != DUALMIC_CONFIG_NONE) {
305 property_get("persist.audio.fluence.voicecall",value,"");
306 if (!strcmp("true", value)) {
307 my_data->fluence_in_voice_call = true;
308 }
309
310 property_get("persist.audio.fluence.voicerec",value,"");
311 if (!strcmp("true", value)) {
312 my_data->fluence_in_voice_rec = true;
313 }
314
315 property_get("persist.audio.fluence.speaker",value,"");
316 if (!strcmp("true", value)) {
317 my_data->fluence_in_spkr_mode = true;
318 }
319 }
320
321 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
322 if (my_data->acdb_handle == NULL) {
323 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
324 } else {
325 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
326 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
327 "acdb_loader_deallocate_ACDB");
328 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
329 "acdb_loader_send_audio_cal");
330 if (!my_data->acdb_send_audio_cal)
331 ALOGW("%s: Could not find the symbol acdb_send_audio_cal from %s",
332 __func__, LIB_ACDB_LOADER);
333 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
334 "acdb_loader_send_voice_cal");
335 my_data->acdb_init = (acdb_init_t)dlsym(my_data->acdb_handle,
336 "acdb_loader_init_ACDB");
337 if (my_data->acdb_init == NULL)
338 ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__, dlerror());
339 else
340 my_data->acdb_init();
341 }
342
343 /* If platform is Fusion3, load CSD Client specific symbols
344 * Voice call is handled by MDM and apps processor talks to
345 * MDM through CSD Client
346 */
347 property_get("ro.board.platform", platform, "");
348 property_get("ro.baseband", baseband, "");
349 if (!strcmp("msm8960", platform) && !strcmp("mdm", baseband)) {
350 my_data->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
351 if (my_data->csd_client == NULL)
352 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
353 }
354
355 if (my_data->csd_client) {
356 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
357 my_data->csd_client_deinit = (csd_client_deinit_t)dlsym(my_data->csd_client,
358 "csd_client_deinit");
359 my_data->csd_disable_device = (csd_disable_device_t)dlsym(my_data->csd_client,
360 "csd_client_disable_device");
361 my_data->csd_enable_device = (csd_enable_device_t)dlsym(my_data->csd_client,
362 "csd_client_enable_device");
363 my_data->csd_start_voice = (csd_start_voice_t)dlsym(my_data->csd_client,
364 "csd_client_start_voice");
365 my_data->csd_stop_voice = (csd_stop_voice_t)dlsym(my_data->csd_client,
366 "csd_client_stop_voice");
367 my_data->csd_volume = (csd_volume_t)dlsym(my_data->csd_client,
368 "csd_client_volume");
369 my_data->csd_mic_mute = (csd_mic_mute_t)dlsym(my_data->csd_client,
370 "csd_client_mic_mute");
371 my_data->csd_client_init = (csd_client_init_t)dlsym(my_data->csd_client,
372 "csd_client_init");
373
374 if (my_data->csd_client_init == NULL) {
375 ALOGE("%s: dlsym error %s for csd_client_init", __func__, dlerror());
376 } else {
377 my_data->csd_client_init();
378 }
379 }
380
381 return my_data;
382 }
383
platform_deinit(void * platform)384 void platform_deinit(void *platform)
385 {
386 free(platform);
387 }
388
platform_get_snd_device_name(snd_device_t snd_device)389 const char *platform_get_snd_device_name(snd_device_t snd_device)
390 {
391 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX)
392 return device_table[snd_device];
393 else
394 return "none";
395 }
396
platform_add_backend_name(void * platform __unused,char * mixer_path,snd_device_t snd_device)397 void platform_add_backend_name(void *platform __unused, char *mixer_path,
398 snd_device_t snd_device)
399 {
400 if (snd_device == SND_DEVICE_IN_BT_SCO_MIC)
401 strcat(mixer_path, " bt-sco");
402 else if(snd_device == SND_DEVICE_OUT_BT_SCO)
403 strcat(mixer_path, " bt-sco");
404 else if (snd_device == SND_DEVICE_OUT_HDMI)
405 strcat(mixer_path, " hdmi");
406 else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HDMI)
407 strcat(mixer_path, " speaker-and-hdmi");
408 else if (snd_device == SND_DEVICE_OUT_BT_SCO_WB ||
409 snd_device == SND_DEVICE_IN_BT_SCO_MIC_WB)
410 strcat(mixer_path, " bt-sco-wb");
411 }
412
platform_get_pcm_device_id(audio_usecase_t usecase,int device_type)413 int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
414 {
415 int device_id;
416 if (device_type == PCM_PLAYBACK)
417 device_id = pcm_device_table[usecase][0];
418 else
419 device_id = pcm_device_table[usecase][1];
420 return device_id;
421 }
422
platform_get_snd_device_index(char * snd_device_index_name __unused)423 int platform_get_snd_device_index(char *snd_device_index_name __unused)
424 {
425 return -ENODEV;
426 }
427
platform_set_snd_device_acdb_id(snd_device_t snd_device __unused,unsigned int acdb_id __unused)428 int platform_set_snd_device_acdb_id(snd_device_t snd_device __unused,
429 unsigned int acdb_id __unused)
430 {
431 return -ENODEV;
432 }
433
platform_get_default_app_type_v2(void * platform __unused,usecase_type_t type __unused,int * app_type __unused)434 int platform_get_default_app_type_v2(void *platform __unused, usecase_type_t type __unused,
435 int *app_type __unused)
436 {
437 ALOGE("%s: Not implemented", __func__);
438 return -ENOSYS;
439 }
440
platform_get_snd_device_acdb_id(snd_device_t snd_device __unused)441 int platform_get_snd_device_acdb_id(snd_device_t snd_device __unused)
442 {
443 ALOGE("%s: Not implemented", __func__);
444 return -ENOSYS;
445 }
446
platform_add_operator_specific_device(snd_device_t snd_device __unused,const char * operator __unused,const char * mixer_path __unused,unsigned int acdb_id __unused)447 void platform_add_operator_specific_device(snd_device_t snd_device __unused,
448 const char *operator __unused,
449 const char *mixer_path __unused,
450 unsigned int acdb_id __unused)
451 {
452 }
453
platform_send_audio_calibration(void * platform,snd_device_t snd_device)454 int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
455 {
456 struct platform_data *my_data = (struct platform_data *)platform;
457 int acdb_dev_id, acdb_dev_type;
458
459 acdb_dev_id = acdb_device_table[snd_device];
460 if (acdb_dev_id < 0) {
461 ALOGE("%s: Could not find acdb id for device(%d)",
462 __func__, snd_device);
463 return -EINVAL;
464 }
465 if (my_data->acdb_send_audio_cal) {
466 ("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
467 __func__, snd_device, acdb_dev_id);
468 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
469 snd_device < SND_DEVICE_OUT_END)
470 acdb_dev_type = ACDB_DEV_TYPE_OUT;
471 else
472 acdb_dev_type = ACDB_DEV_TYPE_IN;
473 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
474 }
475 return 0;
476 }
477
platform_switch_voice_call_device_pre(void * platform)478 int platform_switch_voice_call_device_pre(void *platform)
479 {
480 struct platform_data *my_data = (struct platform_data *)platform;
481 int ret = 0;
482
483 if (my_data->csd_client != NULL &&
484 voice_is_in_call(my_data->adev)) {
485 /* This must be called before disabling the mixer controls on APQ side */
486 if (my_data->csd_disable_device == NULL) {
487 ALOGE("%s: dlsym error for csd_disable_device", __func__);
488 } else {
489 ret = my_data->csd_disable_device();
490 if (ret < 0) {
491 ALOGE("%s: csd_client_disable_device, failed, error %d",
492 __func__, ret);
493 }
494 }
495 }
496 return ret;
497 }
498
platform_switch_voice_call_device_post(void * platform,snd_device_t out_snd_device,snd_device_t in_snd_device)499 int platform_switch_voice_call_device_post(void *platform,
500 snd_device_t out_snd_device,
501 snd_device_t in_snd_device)
502 {
503 struct platform_data *my_data = (struct platform_data *)platform;
504 int acdb_rx_id, acdb_tx_id;
505 int ret = 0;
506
507 if (my_data->csd_client) {
508 if (my_data->csd_enable_device == NULL) {
509 ALOGE("%s: dlsym error for csd_enable_device",
510 __func__);
511 } else {
512 acdb_rx_id = acdb_device_table[out_snd_device];
513 acdb_tx_id = acdb_device_table[in_snd_device];
514
515 if (acdb_rx_id > 0 || acdb_tx_id > 0) {
516 ret = my_data->csd_enable_device(acdb_rx_id, acdb_tx_id,
517 my_data->adev->acdb_settings);
518 if (ret < 0) {
519 ALOGE("%s: csd_enable_device, failed, error %d",
520 __func__, ret);
521 }
522 } else {
523 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
524 acdb_rx_id, acdb_tx_id);
525 }
526 }
527 }
528
529 return ret;
530 }
531
platform_start_voice_call(void * platform,uint32_t vsid __unused)532 int platform_start_voice_call(void *platform, uint32_t vsid __unused)
533 {
534 struct platform_data *my_data = (struct platform_data *)platform;
535 int ret = 0;
536
537 if (my_data->csd_client) {
538 if (my_data->csd_start_voice == NULL) {
539 ALOGE("dlsym error for csd_client_start_voice");
540 ret = -ENOSYS;
541 } else {
542 ret = my_data->csd_start_voice();
543 if (ret < 0) {
544 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
545 }
546 }
547 }
548
549 return ret;
550 }
551
platform_stop_voice_call(void * platform,uint32_t vsid __unused)552 int platform_stop_voice_call(void *platform, uint32_t vsid __unused)
553 {
554 struct platform_data *my_data = (struct platform_data *)platform;
555 int ret = 0;
556
557 if (my_data->csd_client) {
558 if (my_data->csd_stop_voice == NULL) {
559 ALOGE("dlsym error for csd_stop_voice");
560 } else {
561 ret = my_data->csd_stop_voice();
562 if (ret < 0) {
563 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
564 }
565 }
566 }
567
568 return ret;
569 }
570
platform_set_speaker_gain_in_combo(struct audio_device * adev __unused,snd_device_t snd_device __unused,bool enable __unused)571 void platform_set_speaker_gain_in_combo(struct audio_device *adev __unused,
572 snd_device_t snd_device __unused,
573 bool enable __unused) {
574 }
575
platform_set_voice_volume(void * platform,int volume)576 int platform_set_voice_volume(void *platform, int volume)
577 {
578 struct platform_data *my_data = (struct platform_data *)platform;
579 int ret = 0;
580
581 if (my_data->csd_client) {
582 if (my_data->csd_volume == NULL) {
583 ALOGE("%s: dlsym error for csd_volume", __func__);
584 } else {
585 ret = my_data->csd_volume(volume);
586 if (ret < 0) {
587 ALOGE("%s: csd_volume error %d", __func__, ret);
588 }
589 }
590 } else {
591 ALOGE("%s: No CSD Client present", __func__);
592 }
593
594 return ret;
595 }
596
platform_set_mic_mute(void * platform,bool state)597 int platform_set_mic_mute(void *platform, bool state)
598 {
599 struct platform_data *my_data = (struct platform_data *)platform;
600 int ret = 0;
601
602 if (my_data->adev->mode == AUDIO_MODE_IN_CALL) {
603 if (my_data->csd_client) {
604 if (my_data->csd_mic_mute == NULL) {
605 ALOGE("%s: dlsym error for csd_mic_mute", __func__);
606 } else {
607 ret = my_data->csd_mic_mute(state);
608 if (ret < 0) {
609 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
610 }
611 }
612 } else {
613 ALOGE("%s: No CSD Client present", __func__);
614 }
615 }
616
617 return ret;
618 }
619
platform_set_device_mute(void * platform __unused,bool state __unused,char * dir __unused)620 int platform_set_device_mute(void *platform __unused, bool state __unused, char *dir __unused)
621 {
622 ALOGE("%s: Not implemented", __func__);
623 return -ENOSYS;
624 }
625
platform_get_output_snd_device(void * platform,audio_devices_t devices)626 snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
627 {
628 struct platform_data *my_data = (struct platform_data *)platform;
629 struct audio_device *adev = my_data->adev;
630 audio_mode_t mode = adev->mode;
631 snd_device_t snd_device = SND_DEVICE_NONE;
632
633 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
634 if (devices == AUDIO_DEVICE_NONE ||
635 devices & AUDIO_DEVICE_BIT_IN) {
636 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
637 goto exit;
638 }
639
640 if (voice_is_in_call(adev)) {
641 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
642 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
643 if (adev->voice.tty_mode == TTY_MODE_FULL)
644 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
645 else if (adev->voice.tty_mode == TTY_MODE_VCO)
646 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
647 else if (adev->voice.tty_mode == TTY_MODE_HCO)
648 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
649 else
650 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
651 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
652 if (adev->bt_wb_speech_enabled) {
653 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
654 } else {
655 snd_device = SND_DEVICE_OUT_BT_SCO;
656 }
657 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
658 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
659 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
660 if (is_operator_tmus())
661 snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS;
662 else
663 snd_device = SND_DEVICE_OUT_HANDSET;
664 }
665 if (snd_device != SND_DEVICE_NONE) {
666 goto exit;
667 }
668 }
669
670 if (popcount(devices) == 2) {
671 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
672 AUDIO_DEVICE_OUT_SPEAKER)) {
673 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
674 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
675 AUDIO_DEVICE_OUT_SPEAKER)) {
676 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
677 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
678 AUDIO_DEVICE_OUT_SPEAKER)) {
679 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
680 } else {
681 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
682 goto exit;
683 }
684 if (snd_device != SND_DEVICE_NONE) {
685 goto exit;
686 }
687 }
688
689 if (popcount(devices) != 1) {
690 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
691 goto exit;
692 }
693
694 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
695 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
696 snd_device = SND_DEVICE_OUT_HEADPHONES;
697 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
698 if (my_data->speaker_lr_swap)
699 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
700 else
701 snd_device = SND_DEVICE_OUT_SPEAKER;
702 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
703 if (adev->bt_wb_speech_enabled) {
704 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
705 } else {
706 snd_device = SND_DEVICE_OUT_BT_SCO;
707 }
708 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
709 snd_device = SND_DEVICE_OUT_HDMI ;
710 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
711 snd_device = SND_DEVICE_OUT_HANDSET;
712 } else {
713 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
714 }
715 exit:
716 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
717 return snd_device;
718 }
719
platform_get_input_snd_device(void * platform,audio_devices_t out_device)720 snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
721 {
722 struct platform_data *my_data = (struct platform_data *)platform;
723 struct audio_device *adev = my_data->adev;
724 audio_source_t source = (adev->active_input == NULL) ?
725 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
726
727 audio_mode_t mode = adev->mode;
728 audio_devices_t in_device = ((adev->active_input == NULL) ?
729 AUDIO_DEVICE_NONE : adev->active_input->device)
730 & ~AUDIO_DEVICE_BIT_IN;
731 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
732 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
733 snd_device_t snd_device = SND_DEVICE_NONE;
734
735 ALOGV("%s: enter: out_device(%#x) in_device(%#x)",
736 __func__, out_device, in_device);
737 if ((out_device != AUDIO_DEVICE_NONE) && voice_is_in_call(adev)) {
738 if (adev->voice.tty_mode != TTY_MODE_OFF) {
739 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
740 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
741 switch (adev->voice.tty_mode) {
742 case TTY_MODE_FULL:
743 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
744 break;
745 case TTY_MODE_VCO:
746 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
747 break;
748 case TTY_MODE_HCO:
749 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
750 break;
751 default:
752 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
753 }
754 goto exit;
755 }
756 }
757 if (out_device & AUDIO_DEVICE_OUT_EARPIECE ||
758 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
759 if (my_data->fluence_in_voice_call == false) {
760 snd_device = SND_DEVICE_IN_HANDSET_MIC;
761 } else {
762 if (my_data->dualmic_config == DUALMIC_CONFIG_ENDFIRE) {
763 if (is_operator_tmus())
764 snd_device = SND_DEVICE_IN_VOICE_DMIC_EF_TMUS;
765 else
766 snd_device = SND_DEVICE_IN_VOICE_DMIC_EF;
767 } else if(my_data->dualmic_config == DUALMIC_CONFIG_BROADSIDE)
768 snd_device = SND_DEVICE_IN_VOICE_DMIC_BS;
769 else
770 snd_device = SND_DEVICE_IN_HANDSET_MIC;
771 }
772 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
773 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
774 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
775 if (adev->bt_wb_speech_enabled) {
776 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
777 } else {
778 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
779 }
780 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
781 if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode &&
782 my_data->dualmic_config == DUALMIC_CONFIG_ENDFIRE) {
783 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC_EF;
784 } else if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode &&
785 my_data->dualmic_config == DUALMIC_CONFIG_BROADSIDE) {
786 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BS;
787 } else {
788 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
789 }
790 }
791 } else if (source == AUDIO_SOURCE_CAMCORDER) {
792 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
793 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
794 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
795 }
796 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
797 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
798 if (my_data->dualmic_config == DUALMIC_CONFIG_ENDFIRE) {
799 if (channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK)
800 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_EF;
801 else if (my_data->fluence_in_voice_rec)
802 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_EF_FLUENCE;
803 } else if (my_data->dualmic_config == DUALMIC_CONFIG_BROADSIDE) {
804 if (channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK)
805 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_BS;
806 else if (my_data->fluence_in_voice_rec)
807 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_BS_FLUENCE;
808 }
809
810 if (snd_device == SND_DEVICE_NONE) {
811 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
812 }
813 }
814 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION ||
815 mode == AUDIO_MODE_IN_COMMUNICATION) {
816 if (out_device & AUDIO_DEVICE_OUT_SPEAKER)
817 in_device = AUDIO_DEVICE_IN_BACK_MIC;
818 if (adev->active_input) {
819 if (adev->active_input->enable_aec) {
820 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
821 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
822 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
823 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
824 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
825 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
826 }
827 set_echo_reference(adev->mixer, "SLIM_RX");
828 } else
829 set_echo_reference(adev->mixer, "NONE");
830 }
831 } else if (source == AUDIO_SOURCE_DEFAULT) {
832 goto exit;
833 }
834
835
836 if (snd_device != SND_DEVICE_NONE) {
837 goto exit;
838 }
839
840 if (in_device != AUDIO_DEVICE_NONE &&
841 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
842 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
843 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
844 snd_device = SND_DEVICE_IN_HANDSET_MIC;
845 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
846 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
847 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
848 snd_device = SND_DEVICE_IN_HEADSET_MIC;
849 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
850 if (adev->bt_wb_speech_enabled) {
851 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
852 } else {
853 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
854 }
855 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
856 snd_device = SND_DEVICE_IN_HDMI_MIC;
857 } else {
858 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
859 ALOGW("%s: Using default handset-mic", __func__);
860 snd_device = SND_DEVICE_IN_HANDSET_MIC;
861 }
862 } else {
863 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
864 snd_device = SND_DEVICE_IN_HANDSET_MIC;
865 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
866 snd_device = SND_DEVICE_IN_HEADSET_MIC;
867 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
868 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
869 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
870 snd_device = SND_DEVICE_IN_HANDSET_MIC;
871 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
872 if (adev->bt_wb_speech_enabled) {
873 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
874 } else {
875 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
876 }
877 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
878 snd_device = SND_DEVICE_IN_HDMI_MIC;
879 } else {
880 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
881 ALOGW("%s: Using default handset-mic", __func__);
882 snd_device = SND_DEVICE_IN_HANDSET_MIC;
883 }
884 }
885 exit:
886 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
887 return snd_device;
888 }
889
platform_set_hdmi_channels(void * platform,int channel_count)890 int platform_set_hdmi_channels(void *platform, int channel_count)
891 {
892 struct platform_data *my_data = (struct platform_data *)platform;
893 struct audio_device *adev = my_data->adev;
894 struct mixer_ctl *ctl;
895 const char *channel_cnt_str = NULL;
896 const char *mixer_ctl_name = "HDMI_RX Channels";
897 switch (channel_count) {
898 case 8:
899 channel_cnt_str = "Eight"; break;
900 case 7:
901 channel_cnt_str = "Seven"; break;
902 case 6:
903 channel_cnt_str = "Six"; break;
904 case 5:
905 channel_cnt_str = "Five"; break;
906 case 4:
907 channel_cnt_str = "Four"; break;
908 case 3:
909 channel_cnt_str = "Three"; break;
910 default:
911 channel_cnt_str = "Two"; break;
912 }
913 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
914 if (!ctl) {
915 ALOGE("%s: Could not get ctl for mixer cmd - %s",
916 __func__, mixer_ctl_name);
917 return -EINVAL;
918 }
919 ALOGV("HDMI channel count: %s", channel_cnt_str);
920 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
921 return 0;
922 }
923
platform_edid_get_max_channels(void * platform __unused)924 int platform_edid_get_max_channels(void *platform __unused)
925 {
926 FILE *file;
927 struct audio_block_header header;
928 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
929 char *sad = block;
930 int num_audio_blocks;
931 int channel_count;
932 int max_channels = 0;
933 int i;
934
935 file = fopen(AUDIO_DATA_BLOCK_PATH, "rb");
936 if (file == NULL) {
937 ALOGE("Unable to open '%s'", AUDIO_DATA_BLOCK_PATH);
938 return 0;
939 }
940
941 /* Read audio block header */
942 fread(&header, 1, sizeof(header), file);
943
944 /* Read SAD blocks, clamping the maximum size for safety */
945 if (header.length > (int)sizeof(block))
946 header.length = (int)sizeof(block);
947 fread(&block, header.length, 1, file);
948
949 fclose(file);
950
951 /* Calculate the number of SAD blocks */
952 num_audio_blocks = header.length / SAD_BLOCK_SIZE;
953
954 for (i = 0; i < num_audio_blocks; i++) {
955 /* Only consider LPCM blocks */
956 if ((sad[0] >> 3) != EDID_FORMAT_LPCM)
957 continue;
958
959 channel_count = (sad[0] & 0x7) + 1;
960 if (channel_count > max_channels)
961 max_channels = channel_count;
962
963 /* Advance to next block */
964 sad += 3;
965 }
966
967 return max_channels;
968 }
969
platform_set_incall_recording_session_id(void * platform __unused,uint32_t session_id __unused,int rec_mode __unused)970 int platform_set_incall_recording_session_id(void *platform __unused,
971 uint32_t session_id __unused, int rec_mode __unused)
972 {
973 ALOGE("%s: Not implemented", __func__);
974 return -ENOSYS;
975 }
976
platform_stop_incall_recording_usecase(void * platform __unused)977 int platform_stop_incall_recording_usecase(void *platform __unused)
978 {
979 ALOGE("%s: Not implemented", __func__);
980 return -ENOSYS;
981 }
982
platform_start_incall_music_usecase(void * platform __unused)983 int platform_start_incall_music_usecase(void *platform __unused)
984 {
985 ALOGE("%s: Not implemented", __func__);
986 return -ENOSYS;
987 }
988
platform_stop_incall_music_usecase(void * platform __unused)989 int platform_stop_incall_music_usecase(void *platform __unused)
990 {
991 ALOGE("%s: Not implemented", __func__);
992 return -ENOSYS;
993 }
994
platform_set_parameters(void * platform __unused,struct str_parms * parms __unused)995 int platform_set_parameters(void *platform __unused,
996 struct str_parms *parms __unused)
997 {
998 ALOGE("%s: Not implemented", __func__);
999 return -ENOSYS;
1000 }
1001
1002 /* Delay in Us */
platform_render_latency(audio_usecase_t usecase)1003 int64_t platform_render_latency(audio_usecase_t usecase)
1004 {
1005 switch (usecase) {
1006 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
1007 return DEEP_BUFFER_PLATFORM_DELAY;
1008 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
1009 return LOW_LATENCY_PLATFORM_DELAY;
1010 default:
1011 return 0;
1012 }
1013 }
1014
platform_switch_voice_call_enable_device_config(void * platform __unused,snd_device_t out_snd_device __unused,snd_device_t in_snd_device __unused)1015 int platform_switch_voice_call_enable_device_config(void *platform __unused,
1016 snd_device_t out_snd_device __unused,
1017 snd_device_t in_snd_device __unused)
1018 {
1019 return 0;
1020 }
1021
platform_switch_voice_call_usecase_route_post(void * platform __unused,snd_device_t out_snd_device __unused,snd_device_t in_snd_device __unused)1022 int platform_switch_voice_call_usecase_route_post(void *platform __unused,
1023 snd_device_t out_snd_device __unused,
1024 snd_device_t in_snd_device __unused)
1025 {
1026 return 0;
1027 }
1028
platform_get_sample_rate(void * platform __unused,uint32_t * rate __unused)1029 int platform_get_sample_rate(void *platform __unused, uint32_t *rate __unused)
1030 {
1031 return -ENOSYS;
1032 }
1033
platform_get_usecase_index(const char * usecase __unused)1034 int platform_get_usecase_index(const char * usecase __unused)
1035 {
1036 return -ENOSYS;
1037 }
1038
platform_set_usecase_pcm_id(audio_usecase_t usecase __unused,int32_t type __unused,int32_t pcm_id __unused)1039 int platform_set_usecase_pcm_id(audio_usecase_t usecase __unused, int32_t type __unused,
1040 int32_t pcm_id __unused)
1041 {
1042 return -ENOSYS;
1043 }
1044
platform_set_snd_device_backend(snd_device_t device __unused,const char * backend __unused,const char * hw_interface __unused)1045 int platform_set_snd_device_backend(snd_device_t device __unused,
1046 const char *backend __unused,
1047 const char *hw_interface __unused)
1048 {
1049 return -ENOSYS;
1050 }
1051
platform_set_echo_reference(struct audio_device * adev __unused,bool enable __unused,audio_devices_t out_device __unused)1052 void platform_set_echo_reference(struct audio_device *adev __unused,
1053 bool enable __unused,
1054 audio_devices_t out_device __unused)
1055 {
1056 return;
1057 }
1058
1059 #define DEFAULT_NOMINAL_SPEAKER_GAIN 20
ramp_speaker_gain(struct audio_device * adev,bool ramp_up,int target_ramp_up_gain)1060 int ramp_speaker_gain(struct audio_device *adev, bool ramp_up, int target_ramp_up_gain) {
1061 // backup_gain: gain to try to set in case of an error during ramp
1062 int start_gain, end_gain, step, backup_gain, i;
1063 bool error = false;
1064 const struct mixer_ctl *ctl;
1065 const char *mixer_ctl_name_gain_left = "Left Speaker Gain";
1066 const char *mixer_ctl_name_gain_right = "Right Speaker Gain";
1067 struct mixer_ctl *ctl_left = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_left);
1068 struct mixer_ctl *ctl_right = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_right);
1069 if (!ctl_left || !ctl_right) {
1070 ALOGE("%s: Could not get ctl for mixer cmd - %s or %s, not applying speaker gain ramp",
1071 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
1072 return -EINVAL;
1073 } else if ((mixer_ctl_get_num_values(ctl_left) != 1)
1074 || (mixer_ctl_get_num_values(ctl_right) != 1)) {
1075 ALOGE("%s: Unexpected num values for mixer cmd - %s or %s, not applying speaker gain ramp",
1076 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
1077 return -EINVAL;
1078 }
1079 if (ramp_up) {
1080 start_gain = 0;
1081 end_gain = target_ramp_up_gain > 0 ? target_ramp_up_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
1082 step = +1;
1083 backup_gain = end_gain;
1084 } else {
1085 // using same gain on left and right
1086 const int left_gain = mixer_ctl_get_value(ctl_left, 0);
1087 start_gain = left_gain > 0 ? left_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
1088 end_gain = 0;
1089 step = -1;
1090 backup_gain = start_gain;
1091 }
1092 for (i = start_gain ; i != (end_gain + step) ; i += step) {
1093 //ALOGV("setting speaker gain to %d", i);
1094 if (mixer_ctl_set_value(ctl_left, 0, i)) {
1095 ALOGE("%s: error setting %s to %d during gain ramp",
1096 __func__, mixer_ctl_name_gain_left, i);
1097 error = true;
1098 break;
1099 }
1100 if (mixer_ctl_set_value(ctl_right, 0, i)) {
1101 ALOGE("%s: error setting %s to %d during gain ramp",
1102 __func__, mixer_ctl_name_gain_right, i);
1103 error = true;
1104 break;
1105 }
1106 usleep(1000);
1107 }
1108 if (error) {
1109 // an error occured during the ramp, let's still try to go back to a safe volume
1110 if (mixer_ctl_set_value(ctl_left, 0, backup_gain)) {
1111 ALOGE("%s: error restoring left gain to %d", __func__, backup_gain);
1112 }
1113 if (mixer_ctl_set_value(ctl_right, 0, backup_gain)) {
1114 ALOGE("%s: error restoring right gain to %d", __func__, backup_gain);
1115 }
1116 }
1117 return start_gain;
1118 }
1119
platform_set_swap_mixer(struct audio_device * adev,bool swap_channels)1120 int platform_set_swap_mixer(struct audio_device *adev, bool swap_channels)
1121 {
1122 const char *mixer_ctl_name = "Swap channel";
1123 struct mixer_ctl *ctl;
1124 const char *mixer_path;
1125 struct platform_data *my_data = (struct platform_data *)adev->platform;
1126
1127 // forced to set to swap, but device not rotated ... ignore set
1128 if (swap_channels && !my_data->speaker_lr_swap)
1129 return 0;
1130
1131 ALOGV("%s:", __func__);
1132
1133 if (swap_channels) {
1134 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER_REVERSE);
1135 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
1136 } else {
1137 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER);
1138 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
1139 }
1140
1141 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1142 if (!ctl) {
1143 ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name);
1144 return -EINVAL;
1145 }
1146
1147 if (mixer_ctl_set_value(ctl, 0, swap_channels) < 0) {
1148 ALOGE("%s: Could not set reverse cotrol %d",__func__, swap_channels);
1149 return -EINVAL;
1150 }
1151
1152 ALOGV("platfor_force_swap_channel :: Channel orientation ( %s ) ",
1153 swap_channels?"R --> L":"L --> R");
1154
1155 return 0;
1156 }
1157
platform_check_and_set_swap_lr_channels(struct audio_device * adev,bool swap_channels)1158 int platform_check_and_set_swap_lr_channels(struct audio_device *adev, bool swap_channels)
1159 {
1160 // only update if there is active pcm playback on speaker
1161 struct audio_usecase *usecase;
1162 struct listnode *node;
1163 struct platform_data *my_data = (struct platform_data *)adev->platform;
1164
1165 my_data->speaker_lr_swap = swap_channels;
1166
1167 return platform_set_swap_channels(adev, swap_channels);
1168 }
1169
platform_set_swap_channels(struct audio_device * adev,bool swap_channels)1170 int platform_set_swap_channels(struct audio_device *adev, bool swap_channels)
1171 {
1172 // only update if there is active pcm playback on speaker
1173 struct audio_usecase *usecase;
1174 struct listnode *node;
1175 struct platform_data *my_data = (struct platform_data *)adev->platform;
1176
1177 // do not swap channels in audio modes with concurrent capture and playback
1178 // as this may break the echo reference
1179 if ((adev->mode == AUDIO_MODE_IN_COMMUNICATION) || (adev->mode == AUDIO_MODE_IN_CALL)) {
1180 ALOGV("%s: will not swap due to audio mode %d", __func__, adev->mode);
1181 return 0;
1182 }
1183
1184 list_for_each(node, &adev->usecase_list) {
1185 usecase = node_to_item(node, struct audio_usecase, list);
1186 if (usecase->type == PCM_PLAYBACK &&
1187 usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) {
1188 /*
1189 * If acdb tuning is different for SPEAKER_REVERSE, it is must
1190 * to perform device switch to disable the current backend to
1191 * enable it with new acdb data.
1192 */
1193 if (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
1194 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]) {
1195 const int initial_skpr_gain = ramp_speaker_gain(adev, false /*ramp_up*/, -1);
1196 select_devices(adev, usecase->id);
1197 if (initial_skpr_gain != -EINVAL)
1198 ramp_speaker_gain(adev, true /*ramp_up*/, initial_skpr_gain);
1199
1200 } else {
1201 platform_set_swap_mixer(adev, swap_channels);
1202 }
1203 break;
1204 }
1205 }
1206
1207 return 0;
1208 }
1209
platform_send_gain_dep_cal(void * platform __unused,int level __unused)1210 bool platform_send_gain_dep_cal(void *platform __unused,
1211 int level __unused)
1212 {
1213 return true;
1214 }
1215
platform_can_split_snd_device(snd_device_t in_snd_device __unused,int * num_devices __unused,snd_device_t * out_snd_devices __unused)1216 int platform_can_split_snd_device(snd_device_t in_snd_device __unused,
1217 int *num_devices __unused,
1218 snd_device_t *out_snd_devices __unused)
1219 {
1220 return -ENOSYS;
1221 }
1222
platform_check_backends_match(snd_device_t snd_device1 __unused,snd_device_t snd_device2 __unused)1223 bool platform_check_backends_match(snd_device_t snd_device1 __unused,
1224 snd_device_t snd_device2 __unused)
1225 {
1226 return true;
1227 }
1228
platform_get_snd_device_name_extn(void * platform __unused,snd_device_t snd_device,char * device_name)1229 int platform_get_snd_device_name_extn(void *platform __unused,
1230 snd_device_t snd_device,
1231 char *device_name)
1232 {
1233 strlcpy(device_name, platform_get_snd_device_name(snd_device),
1234 DEVICE_NAME_MAX_SIZE);
1235 return 0;
1236 }
1237
platform_check_and_set_playback_backend_cfg(struct audio_device * adev __unused,struct audio_usecase * usecase __unused,snd_device_t snd_device __unused)1238 bool platform_check_and_set_playback_backend_cfg(struct audio_device* adev __unused,
1239 struct audio_usecase *usecase __unused,
1240 snd_device_t snd_device __unused)
1241 {
1242 return false;
1243 }
1244
platform_check_and_set_capture_backend_cfg(struct audio_device * adev __unused,struct audio_usecase * usecase __unused,snd_device_t snd_device __unused)1245 bool platform_check_and_set_capture_backend_cfg(struct audio_device* adev __unused,
1246 struct audio_usecase *usecase __unused, snd_device_t snd_device __unused)
1247 {
1248 return false;
1249 }
1250
platform_add_gain_level_mapping(struct amp_db_and_gain_table * tbl_entry __unused)1251 bool platform_add_gain_level_mapping(struct amp_db_and_gain_table *tbl_entry __unused)
1252 {
1253 return false;
1254 }
1255
platform_get_gain_level_mapping(struct amp_db_and_gain_table * mapping_tbl __unused,int table_size __unused)1256 int platform_get_gain_level_mapping(struct amp_db_and_gain_table *mapping_tbl __unused,
1257 int table_size __unused)
1258 {
1259 return 0;
1260 }
1261
platform_snd_card_update(void * platform __unused,card_status_t status __unused)1262 int platform_snd_card_update(void *platform __unused,
1263 card_status_t status __unused)
1264 {
1265 return -1;
1266 }
1267
platform_get_snd_device_backend_index(snd_device_t snd_device __unused)1268 int platform_get_snd_device_backend_index(snd_device_t snd_device __unused)
1269 {
1270 return -ENOSYS;
1271 }
1272
platform_check_and_update_copp_sample_rate(void * platform __unused,snd_device_t snd_device __unused,unsigned int stream_sr __unused,int * sample_rate __unused)1273 void platform_check_and_update_copp_sample_rate(void* platform __unused, snd_device_t snd_device __unused,
1274 unsigned int stream_sr __unused, int* sample_rate __unused)
1275 {
1276
1277 }
1278
platform_send_audio_calibration_v2(void * platform __unused,struct audio_usecase * usecase __unused,int app_type __unused,int sample_rate __unused)1279 int platform_send_audio_calibration_v2(void *platform __unused, struct audio_usecase *usecase __unused,
1280 int app_type __unused, int sample_rate __unused)
1281 {
1282 return -ENOSYS;
1283 }
1284
platform_supports_app_type_cfg()1285 bool platform_supports_app_type_cfg() { return false; }
1286
platform_add_app_type(const char * uc_type __unused,const char * mode __unused,int bw __unused,int app_type __unused,int max_sr __unused)1287 void platform_add_app_type(const char *uc_type __unused,
1288 const char *mode __unused,
1289 int bw __unused, int app_type __unused,
1290 int max_sr __unused) {}
1291
platform_get_app_type_v2(void * platform __unused,enum usecase_type_t type __unused,const char * mode __unused,int bw __unused,int sr __unused,int * app_type __unused)1292 int platform_get_app_type_v2(void *platform __unused,
1293 enum usecase_type_t type __unused,
1294 const char *mode __unused,
1295 int bw __unused, int sr __unused,
1296 int *app_type __unused) {
1297 return -ENOSYS;
1298 }
1299
platform_set_sidetone(struct audio_device * adev,snd_device_t out_snd_device,bool enable,char * str)1300 int platform_set_sidetone(struct audio_device *adev,
1301 snd_device_t out_snd_device,
1302 bool enable, char *str)
1303 {
1304 int ret;
1305 if (out_snd_device == SND_DEVICE_OUT_USB_HEADSET ||
1306 out_snd_device == SND_DEVICE_OUT_VOICE_USB_HEADSET) {
1307 ret = audio_extn_usb_enable_sidetone(out_snd_device, enable);
1308 if (ret)
1309 ALOGI("%s: usb device %d does not support device sidetone\n",
1310 __func__, out_snd_device);
1311 } else {
1312 ALOGV("%s: sidetone out device(%d) mixer cmd = %s\n",
1313 __func__, out_snd_device, str);
1314 if (enable)
1315 audio_route_apply_and_update_path(adev->audio_route, str);
1316 else
1317 audio_route_reset_and_update_path(adev->audio_route, str);
1318 }
1319 return 0;
1320 }
1321
platform_get_mmap_data_fd(void * platform __unused,int fe_dev __unused,int dir __unused,int * fd __unused,uint32_t * size __unused)1322 int platform_get_mmap_data_fd(void *platform __unused, int fe_dev __unused, int dir __unused,
1323 int *fd __unused, uint32_t *size __unused)
1324 {
1325 return -ENOSYS;
1326 }
1327