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