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
29 #define LIB_ACDB_LOADER "libacdbloader.so"
30 #define LIB_CSD_CLIENT "libcsd-client.so"
31
32 #define DUALMIC_CONFIG_NONE 0 /* Target does not contain 2 mics */
33 #define DUALMIC_CONFIG_ENDFIRE 1
34 #define DUALMIC_CONFIG_BROADSIDE 2
35
36 /*
37 * This is the sysfs path for the HDMI audio data block
38 */
39 #define AUDIO_DATA_BLOCK_PATH "/sys/class/graphics/fb1/audio_data_block"
40 #define MIXER_XML_PATH "/system/etc/mixer_paths.xml"
41
42 /*
43 * This file will have a maximum of 38 bytes:
44 *
45 * 4 bytes: number of audio blocks
46 * 4 bytes: total length of Short Audio Descriptor (SAD) blocks
47 * Maximum 10 * 3 bytes: SAD blocks
48 */
49 #define MAX_SAD_BLOCKS 10
50 #define SAD_BLOCK_SIZE 3
51
52 /* EDID format ID for LPCM audio */
53 #define EDID_FORMAT_LPCM 1
54
55 struct audio_block_header
56 {
57 int reserved;
58 int length;
59 };
60
61
62 typedef void (*acdb_deallocate_t)();
63 typedef int (*acdb_init_t)();
64 typedef void (*acdb_send_audio_cal_t)(int, int);
65 typedef void (*acdb_send_voice_cal_t)(int, int);
66
67 typedef int (*csd_client_init_t)();
68 typedef int (*csd_client_deinit_t)();
69 typedef int (*csd_disable_device_t)();
70 typedef int (*csd_enable_device_t)(int, int, uint32_t);
71 typedef int (*csd_volume_t)(int);
72 typedef int (*csd_mic_mute_t)(int);
73 typedef int (*csd_start_voice_t)();
74 typedef int (*csd_stop_voice_t)();
75
76
77 /* Audio calibration related functions */
78 struct platform_data {
79 struct audio_device *adev;
80 bool fluence_in_spkr_mode;
81 bool fluence_in_voice_call;
82 bool fluence_in_voice_rec;
83 int dualmic_config;
84
85 void *acdb_handle;
86 acdb_init_t acdb_init;
87 acdb_deallocate_t acdb_deallocate;
88 acdb_send_audio_cal_t acdb_send_audio_cal;
89 acdb_send_voice_cal_t acdb_send_voice_cal;
90
91 /* CSD Client related functions for voice call */
92 void *csd_client;
93 csd_client_init_t csd_client_init;
94 csd_client_deinit_t csd_client_deinit;
95 csd_disable_device_t csd_disable_device;
96 csd_enable_device_t csd_enable_device;
97 csd_volume_t csd_volume;
98 csd_mic_mute_t csd_mic_mute;
99 csd_start_voice_t csd_start_voice;
100 csd_stop_voice_t csd_stop_voice;
101 };
102
103 static const int pcm_device_table[AUDIO_USECASE_MAX][2] = {
104 [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = {0, 0},
105 [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = {14, 14},
106 [USECASE_AUDIO_PLAYBACK_MULTI_CH] = {1, 1},
107 [USECASE_AUDIO_RECORD] = {0, 0},
108 [USECASE_AUDIO_RECORD_LOW_LATENCY] = {14, 14},
109 [USECASE_VOICE_CALL] = {12, 12},
110 };
111
112 /* Array to store sound devices */
113 static const char * const device_table[SND_DEVICE_MAX] = {
114 [SND_DEVICE_NONE] = "none",
115 /* Playback sound devices */
116 [SND_DEVICE_OUT_HANDSET] = "handset",
117 [SND_DEVICE_OUT_SPEAKER] = "speaker",
118 [SND_DEVICE_OUT_SPEAKER_REVERSE] = "speaker-reverse",
119 [SND_DEVICE_OUT_HEADPHONES] = "headphones",
120 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones",
121 [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker",
122 [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones",
123 [SND_DEVICE_OUT_HDMI] = "hdmi",
124 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi",
125 [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset",
126 [SND_DEVICE_OUT_BT_SCO_WB] = "bt-sco-headset-wb",
127 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = "voice-handset-tmus",
128 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones",
129 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones",
130 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset",
131
132 /* Capture sound devices */
133 [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
134 [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
135 [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
136 [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic",
137 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "voice-speaker-mic",
138 [SND_DEVICE_IN_HEADSET_MIC_AEC] = "headset-mic",
139 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
140 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
141 [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic",
142 [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
143 [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb",
144 [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic",
145 [SND_DEVICE_IN_VOICE_DMIC_EF] = "voice-dmic-ef",
146 [SND_DEVICE_IN_VOICE_DMIC_BS] = "voice-dmic-bs",
147 [SND_DEVICE_IN_VOICE_DMIC_EF_TMUS] = "voice-dmic-ef-tmus",
148 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_EF] = "voice-speaker-dmic-ef",
149 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BS] = "voice-speaker-dmic-bs",
150 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
151 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
152 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
153 [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
154 [SND_DEVICE_IN_VOICE_REC_DMIC_EF] = "voice-rec-dmic-ef",
155 [SND_DEVICE_IN_VOICE_REC_DMIC_BS] = "voice-rec-dmic-bs",
156 [SND_DEVICE_IN_VOICE_REC_DMIC_EF_FLUENCE] = "voice-rec-dmic-ef-fluence",
157 [SND_DEVICE_IN_VOICE_REC_DMIC_BS_FLUENCE] = "voice-rec-dmic-bs-fluence",
158 };
159
160 /* ACDB IDs (audio DSP path configuration IDs) for each sound device */
161 static const int acdb_device_table[SND_DEVICE_MAX] = {
162 [SND_DEVICE_NONE] = -1,
163 [SND_DEVICE_OUT_HANDSET] = 7,
164 [SND_DEVICE_OUT_SPEAKER] = 14,
165 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 14,
166 [SND_DEVICE_OUT_HEADPHONES] = 10,
167 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
168 [SND_DEVICE_OUT_VOICE_SPEAKER] = 14,
169 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
170 [SND_DEVICE_OUT_HDMI] = 18,
171 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 14,
172 [SND_DEVICE_OUT_BT_SCO] = 22,
173 [SND_DEVICE_OUT_BT_SCO_WB] = 39,
174 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = 81,
175 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
176 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
177 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
178
179 [SND_DEVICE_IN_HANDSET_MIC] = 4,
180 [SND_DEVICE_IN_SPEAKER_MIC] = 4,
181 [SND_DEVICE_IN_HEADSET_MIC] = 8,
182 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 40,
183 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 42,
184 [SND_DEVICE_IN_HEADSET_MIC_AEC] = 47,
185 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
186 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = 8,
187 [SND_DEVICE_IN_HDMI_MIC] = 4,
188 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
189 [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38,
190 [SND_DEVICE_IN_CAMCORDER_MIC] = 61,
191 [SND_DEVICE_IN_VOICE_DMIC_EF] = 6,
192 [SND_DEVICE_IN_VOICE_DMIC_BS] = 5,
193 [SND_DEVICE_IN_VOICE_DMIC_EF_TMUS] = 91,
194 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_EF] = 13,
195 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BS] = 12,
196 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
197 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
198 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
199 [SND_DEVICE_IN_VOICE_REC_MIC] = 62,
200 /* TODO: Update with proper acdb ids */
201 [SND_DEVICE_IN_VOICE_REC_DMIC_EF] = 62,
202 [SND_DEVICE_IN_VOICE_REC_DMIC_BS] = 62,
203 [SND_DEVICE_IN_VOICE_REC_DMIC_EF_FLUENCE] = 6,
204 [SND_DEVICE_IN_VOICE_REC_DMIC_BS_FLUENCE] = 5,
205 };
206
207 #define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
208 #define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
209
210 static pthread_once_t check_op_once_ctl = PTHREAD_ONCE_INIT;
211 static bool is_tmus = false;
212
check_operator()213 static void check_operator()
214 {
215 char value[PROPERTY_VALUE_MAX];
216 int mccmnc;
217 property_get("gsm.sim.operator.numeric",value,"0");
218 mccmnc = atoi(value);
219 ALOGD("%s: tmus mccmnc %d", __func__, mccmnc);
220 switch(mccmnc) {
221 /* TMUS MCC(310), MNC(490, 260, 026) */
222 case 310490:
223 case 310260:
224 case 310026:
225 is_tmus = true;
226 break;
227 }
228 }
229
is_operator_tmus()230 bool is_operator_tmus()
231 {
232 pthread_once(&check_op_once_ctl, check_operator);
233 return is_tmus;
234 }
235
set_echo_reference(struct mixer * mixer,const char * ec_ref)236 static int set_echo_reference(struct mixer *mixer, const char* ec_ref)
237 {
238 struct mixer_ctl *ctl;
239 const char *mixer_ctl_name = "EC_REF_RX";
240
241 ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name);
242 if (!ctl) {
243 ALOGE("%s: Could not get ctl for mixer cmd - %s",
244 __func__, mixer_ctl_name);
245 return -EINVAL;
246 }
247 ALOGV("Setting EC Reference: %s", ec_ref);
248 mixer_ctl_set_enum_by_string(ctl, ec_ref);
249 return 0;
250 }
251
platform_init(struct audio_device * adev)252 void *platform_init(struct audio_device *adev)
253 {
254 char platform[PROPERTY_VALUE_MAX];
255 char baseband[PROPERTY_VALUE_MAX];
256 char value[PROPERTY_VALUE_MAX];
257 struct platform_data *my_data;
258
259 adev->mixer = mixer_open(MIXER_CARD);
260
261 if (!adev->mixer) {
262 ALOGE("Unable to open the mixer, aborting.");
263 return NULL;
264 }
265
266 adev->audio_route = audio_route_init(MIXER_CARD, MIXER_XML_PATH);
267 if (!adev->audio_route) {
268 ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
269 return NULL;
270 }
271
272 my_data = calloc(1, sizeof(struct platform_data));
273
274 my_data->adev = adev;
275 my_data->dualmic_config = DUALMIC_CONFIG_NONE;
276 my_data->fluence_in_spkr_mode = false;
277 my_data->fluence_in_voice_call = false;
278 my_data->fluence_in_voice_rec = false;
279
280 property_get("persist.audio.dualmic.config",value,"");
281 if (!strcmp("broadside", value)) {
282 my_data->dualmic_config = DUALMIC_CONFIG_BROADSIDE;
283 adev->acdb_settings |= DMIC_FLAG;
284 } else if (!strcmp("endfire", value)) {
285 my_data->dualmic_config = DUALMIC_CONFIG_ENDFIRE;
286 adev->acdb_settings |= DMIC_FLAG;
287 }
288
289 if (my_data->dualmic_config != DUALMIC_CONFIG_NONE) {
290 property_get("persist.audio.fluence.voicecall",value,"");
291 if (!strcmp("true", value)) {
292 my_data->fluence_in_voice_call = true;
293 }
294
295 property_get("persist.audio.fluence.voicerec",value,"");
296 if (!strcmp("true", value)) {
297 my_data->fluence_in_voice_rec = true;
298 }
299
300 property_get("persist.audio.fluence.speaker",value,"");
301 if (!strcmp("true", value)) {
302 my_data->fluence_in_spkr_mode = true;
303 }
304 }
305
306 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
307 if (my_data->acdb_handle == NULL) {
308 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
309 } else {
310 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
311 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
312 "acdb_loader_deallocate_ACDB");
313 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
314 "acdb_loader_send_audio_cal");
315 if (!my_data->acdb_send_audio_cal)
316 ALOGW("%s: Could not find the symbol acdb_send_audio_cal from %s",
317 __func__, LIB_ACDB_LOADER);
318 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
319 "acdb_loader_send_voice_cal");
320 my_data->acdb_init = (acdb_init_t)dlsym(my_data->acdb_handle,
321 "acdb_loader_init_ACDB");
322 if (my_data->acdb_init == NULL)
323 ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__, dlerror());
324 else
325 my_data->acdb_init();
326 }
327
328 /* If platform is Fusion3, load CSD Client specific symbols
329 * Voice call is handled by MDM and apps processor talks to
330 * MDM through CSD Client
331 */
332 property_get("ro.board.platform", platform, "");
333 property_get("ro.baseband", baseband, "");
334 if (!strcmp("msm8960", platform) && !strcmp("mdm", baseband)) {
335 my_data->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
336 if (my_data->csd_client == NULL)
337 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
338 }
339
340 if (my_data->csd_client) {
341 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
342 my_data->csd_client_deinit = (csd_client_deinit_t)dlsym(my_data->csd_client,
343 "csd_client_deinit");
344 my_data->csd_disable_device = (csd_disable_device_t)dlsym(my_data->csd_client,
345 "csd_client_disable_device");
346 my_data->csd_enable_device = (csd_enable_device_t)dlsym(my_data->csd_client,
347 "csd_client_enable_device");
348 my_data->csd_start_voice = (csd_start_voice_t)dlsym(my_data->csd_client,
349 "csd_client_start_voice");
350 my_data->csd_stop_voice = (csd_stop_voice_t)dlsym(my_data->csd_client,
351 "csd_client_stop_voice");
352 my_data->csd_volume = (csd_volume_t)dlsym(my_data->csd_client,
353 "csd_client_volume");
354 my_data->csd_mic_mute = (csd_mic_mute_t)dlsym(my_data->csd_client,
355 "csd_client_mic_mute");
356 my_data->csd_client_init = (csd_client_init_t)dlsym(my_data->csd_client,
357 "csd_client_init");
358
359 if (my_data->csd_client_init == NULL) {
360 ALOGE("%s: dlsym error %s for csd_client_init", __func__, dlerror());
361 } else {
362 my_data->csd_client_init();
363 }
364 }
365
366 return my_data;
367 }
368
platform_deinit(void * platform)369 void platform_deinit(void *platform)
370 {
371 free(platform);
372 }
373
platform_get_snd_device_name(snd_device_t snd_device)374 const char *platform_get_snd_device_name(snd_device_t snd_device)
375 {
376 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX)
377 return device_table[snd_device];
378 else
379 return "none";
380 }
381
platform_add_backend_name(void * platform __unused,char * mixer_path,snd_device_t snd_device)382 void platform_add_backend_name(void *platform __unused, char *mixer_path,
383 snd_device_t snd_device)
384 {
385 if (snd_device == SND_DEVICE_IN_BT_SCO_MIC)
386 strcat(mixer_path, " bt-sco");
387 else if(snd_device == SND_DEVICE_OUT_BT_SCO)
388 strcat(mixer_path, " bt-sco");
389 else if (snd_device == SND_DEVICE_OUT_HDMI)
390 strcat(mixer_path, " hdmi");
391 else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HDMI)
392 strcat(mixer_path, " speaker-and-hdmi");
393 else if (snd_device == SND_DEVICE_OUT_BT_SCO_WB ||
394 snd_device == SND_DEVICE_IN_BT_SCO_MIC_WB)
395 strcat(mixer_path, " bt-sco-wb");
396 }
397
platform_get_pcm_device_id(audio_usecase_t usecase,int device_type)398 int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
399 {
400 int device_id;
401 if (device_type == PCM_PLAYBACK)
402 device_id = pcm_device_table[usecase][0];
403 else
404 device_id = pcm_device_table[usecase][1];
405 return device_id;
406 }
407
platform_get_snd_device_index(char * snd_device_index_name __unused)408 int platform_get_snd_device_index(char *snd_device_index_name __unused)
409 {
410 return -ENODEV;
411 }
412
platform_set_snd_device_acdb_id(snd_device_t snd_device __unused,unsigned int acdb_id __unused)413 int platform_set_snd_device_acdb_id(snd_device_t snd_device __unused,
414 unsigned int acdb_id __unused)
415 {
416 return -ENODEV;
417 }
418
platform_send_audio_calibration(void * platform,snd_device_t snd_device)419 int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
420 {
421 struct platform_data *my_data = (struct platform_data *)platform;
422 int acdb_dev_id, acdb_dev_type;
423
424 acdb_dev_id = acdb_device_table[snd_device];
425 if (acdb_dev_id < 0) {
426 ALOGE("%s: Could not find acdb id for device(%d)",
427 __func__, snd_device);
428 return -EINVAL;
429 }
430 if (my_data->acdb_send_audio_cal) {
431 ("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
432 __func__, snd_device, acdb_dev_id);
433 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
434 snd_device < SND_DEVICE_OUT_END)
435 acdb_dev_type = ACDB_DEV_TYPE_OUT;
436 else
437 acdb_dev_type = ACDB_DEV_TYPE_IN;
438 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
439 }
440 return 0;
441 }
442
platform_switch_voice_call_device_pre(void * platform)443 int platform_switch_voice_call_device_pre(void *platform)
444 {
445 struct platform_data *my_data = (struct platform_data *)platform;
446 int ret = 0;
447
448 if (my_data->csd_client != NULL &&
449 voice_is_in_call(my_data->adev)) {
450 /* This must be called before disabling the mixer controls on APQ side */
451 if (my_data->csd_disable_device == NULL) {
452 ALOGE("%s: dlsym error for csd_disable_device", __func__);
453 } else {
454 ret = my_data->csd_disable_device();
455 if (ret < 0) {
456 ALOGE("%s: csd_client_disable_device, failed, error %d",
457 __func__, ret);
458 }
459 }
460 }
461 return ret;
462 }
463
platform_switch_voice_call_device_post(void * platform,snd_device_t out_snd_device,snd_device_t in_snd_device)464 int platform_switch_voice_call_device_post(void *platform,
465 snd_device_t out_snd_device,
466 snd_device_t in_snd_device)
467 {
468 struct platform_data *my_data = (struct platform_data *)platform;
469 int acdb_rx_id, acdb_tx_id;
470 int ret = 0;
471
472 if (my_data->csd_client) {
473 if (my_data->csd_enable_device == NULL) {
474 ALOGE("%s: dlsym error for csd_enable_device",
475 __func__);
476 } else {
477 acdb_rx_id = acdb_device_table[out_snd_device];
478 acdb_tx_id = acdb_device_table[in_snd_device];
479
480 if (acdb_rx_id > 0 || acdb_tx_id > 0) {
481 ret = my_data->csd_enable_device(acdb_rx_id, acdb_tx_id,
482 my_data->adev->acdb_settings);
483 if (ret < 0) {
484 ALOGE("%s: csd_enable_device, failed, error %d",
485 __func__, ret);
486 }
487 } else {
488 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
489 acdb_rx_id, acdb_tx_id);
490 }
491 }
492 }
493
494 return ret;
495 }
496
platform_start_voice_call(void * platform,uint32_t vsid __unused)497 int platform_start_voice_call(void *platform, uint32_t vsid __unused)
498 {
499 struct platform_data *my_data = (struct platform_data *)platform;
500 int ret = 0;
501
502 if (my_data->csd_client) {
503 if (my_data->csd_start_voice == NULL) {
504 ALOGE("dlsym error for csd_client_start_voice");
505 ret = -ENOSYS;
506 } else {
507 ret = my_data->csd_start_voice();
508 if (ret < 0) {
509 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
510 }
511 }
512 }
513
514 return ret;
515 }
516
platform_stop_voice_call(void * platform,uint32_t vsid __unused)517 int platform_stop_voice_call(void *platform, uint32_t vsid __unused)
518 {
519 struct platform_data *my_data = (struct platform_data *)platform;
520 int ret = 0;
521
522 if (my_data->csd_client) {
523 if (my_data->csd_stop_voice == NULL) {
524 ALOGE("dlsym error for csd_stop_voice");
525 } else {
526 ret = my_data->csd_stop_voice();
527 if (ret < 0) {
528 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
529 }
530 }
531 }
532
533 return ret;
534 }
535
platform_set_voice_volume(void * platform,int volume)536 int platform_set_voice_volume(void *platform, int volume)
537 {
538 struct platform_data *my_data = (struct platform_data *)platform;
539 int ret = 0;
540
541 if (my_data->csd_client) {
542 if (my_data->csd_volume == NULL) {
543 ALOGE("%s: dlsym error for csd_volume", __func__);
544 } else {
545 ret = my_data->csd_volume(volume);
546 if (ret < 0) {
547 ALOGE("%s: csd_volume error %d", __func__, ret);
548 }
549 }
550 } else {
551 ALOGE("%s: No CSD Client present", __func__);
552 }
553
554 return ret;
555 }
556
platform_set_mic_mute(void * platform,bool state)557 int platform_set_mic_mute(void *platform, bool state)
558 {
559 struct platform_data *my_data = (struct platform_data *)platform;
560 int ret = 0;
561
562 if (my_data->adev->mode == AUDIO_MODE_IN_CALL) {
563 if (my_data->csd_client) {
564 if (my_data->csd_mic_mute == NULL) {
565 ALOGE("%s: dlsym error for csd_mic_mute", __func__);
566 } else {
567 ret = my_data->csd_mic_mute(state);
568 if (ret < 0) {
569 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
570 }
571 }
572 } else {
573 ALOGE("%s: No CSD Client present", __func__);
574 }
575 }
576
577 return ret;
578 }
579
platform_set_device_mute(void * platform __unused,bool state __unused,char * dir __unused)580 int platform_set_device_mute(void *platform __unused, bool state __unused, char *dir __unused)
581 {
582 ALOGE("%s: Not implemented", __func__);
583 return -ENOSYS;
584 }
585
platform_get_output_snd_device(void * platform,audio_devices_t devices)586 snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
587 {
588 struct platform_data *my_data = (struct platform_data *)platform;
589 struct audio_device *adev = my_data->adev;
590 audio_mode_t mode = adev->mode;
591 snd_device_t snd_device = SND_DEVICE_NONE;
592
593 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
594 if (devices == AUDIO_DEVICE_NONE ||
595 devices & AUDIO_DEVICE_BIT_IN) {
596 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
597 goto exit;
598 }
599
600 if (voice_is_in_call(adev)) {
601 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
602 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
603 if (adev->voice.tty_mode == TTY_MODE_FULL)
604 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
605 else if (adev->voice.tty_mode == TTY_MODE_VCO)
606 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
607 else if (adev->voice.tty_mode == TTY_MODE_HCO)
608 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
609 else
610 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
611 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
612 if (adev->bt_wb_speech_enabled) {
613 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
614 } else {
615 snd_device = SND_DEVICE_OUT_BT_SCO;
616 }
617 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
618 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
619 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
620 if (is_operator_tmus())
621 snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS;
622 else
623 snd_device = SND_DEVICE_OUT_HANDSET;
624 }
625 if (snd_device != SND_DEVICE_NONE) {
626 goto exit;
627 }
628 }
629
630 if (popcount(devices) == 2) {
631 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
632 AUDIO_DEVICE_OUT_SPEAKER)) {
633 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
634 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
635 AUDIO_DEVICE_OUT_SPEAKER)) {
636 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
637 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
638 AUDIO_DEVICE_OUT_SPEAKER)) {
639 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
640 } else {
641 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
642 goto exit;
643 }
644 if (snd_device != SND_DEVICE_NONE) {
645 goto exit;
646 }
647 }
648
649 if (popcount(devices) != 1) {
650 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
651 goto exit;
652 }
653
654 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
655 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
656 snd_device = SND_DEVICE_OUT_HEADPHONES;
657 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
658 if (adev->speaker_lr_swap)
659 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
660 else
661 snd_device = SND_DEVICE_OUT_SPEAKER;
662 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
663 if (adev->bt_wb_speech_enabled) {
664 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
665 } else {
666 snd_device = SND_DEVICE_OUT_BT_SCO;
667 }
668 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
669 snd_device = SND_DEVICE_OUT_HDMI ;
670 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
671 snd_device = SND_DEVICE_OUT_HANDSET;
672 } else {
673 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
674 }
675 exit:
676 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
677 return snd_device;
678 }
679
platform_get_input_snd_device(void * platform,audio_devices_t out_device)680 snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
681 {
682 struct platform_data *my_data = (struct platform_data *)platform;
683 struct audio_device *adev = my_data->adev;
684 audio_source_t source = (adev->active_input == NULL) ?
685 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
686
687 audio_mode_t mode = adev->mode;
688 audio_devices_t in_device = ((adev->active_input == NULL) ?
689 AUDIO_DEVICE_NONE : adev->active_input->device)
690 & ~AUDIO_DEVICE_BIT_IN;
691 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
692 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
693 snd_device_t snd_device = SND_DEVICE_NONE;
694
695 ALOGV("%s: enter: out_device(%#x) in_device(%#x)",
696 __func__, out_device, in_device);
697 if ((out_device != AUDIO_DEVICE_NONE) && voice_is_in_call(adev)) {
698 if (adev->voice.tty_mode != TTY_MODE_OFF) {
699 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
700 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
701 switch (adev->voice.tty_mode) {
702 case TTY_MODE_FULL:
703 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
704 break;
705 case TTY_MODE_VCO:
706 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
707 break;
708 case TTY_MODE_HCO:
709 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
710 break;
711 default:
712 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
713 }
714 goto exit;
715 }
716 }
717 if (out_device & AUDIO_DEVICE_OUT_EARPIECE ||
718 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
719 if (my_data->fluence_in_voice_call == false) {
720 snd_device = SND_DEVICE_IN_HANDSET_MIC;
721 } else {
722 if (my_data->dualmic_config == DUALMIC_CONFIG_ENDFIRE) {
723 if (is_operator_tmus())
724 snd_device = SND_DEVICE_IN_VOICE_DMIC_EF_TMUS;
725 else
726 snd_device = SND_DEVICE_IN_VOICE_DMIC_EF;
727 } else if(my_data->dualmic_config == DUALMIC_CONFIG_BROADSIDE)
728 snd_device = SND_DEVICE_IN_VOICE_DMIC_BS;
729 else
730 snd_device = SND_DEVICE_IN_HANDSET_MIC;
731 }
732 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
733 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
734 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
735 if (adev->bt_wb_speech_enabled) {
736 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
737 } else {
738 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
739 }
740 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
741 if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode &&
742 my_data->dualmic_config == DUALMIC_CONFIG_ENDFIRE) {
743 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC_EF;
744 } else if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode &&
745 my_data->dualmic_config == DUALMIC_CONFIG_BROADSIDE) {
746 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BS;
747 } else {
748 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
749 }
750 }
751 } else if (source == AUDIO_SOURCE_CAMCORDER) {
752 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
753 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
754 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
755 }
756 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
757 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
758 if (my_data->dualmic_config == DUALMIC_CONFIG_ENDFIRE) {
759 if (channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK)
760 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_EF;
761 else if (my_data->fluence_in_voice_rec)
762 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_EF_FLUENCE;
763 } else if (my_data->dualmic_config == DUALMIC_CONFIG_BROADSIDE) {
764 if (channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK)
765 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_BS;
766 else if (my_data->fluence_in_voice_rec)
767 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_BS_FLUENCE;
768 }
769
770 if (snd_device == SND_DEVICE_NONE) {
771 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
772 }
773 }
774 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION) {
775 if (out_device & AUDIO_DEVICE_OUT_SPEAKER)
776 in_device = AUDIO_DEVICE_IN_BACK_MIC;
777 if (adev->active_input) {
778 if (adev->active_input->enable_aec) {
779 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
780 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
781 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
782 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
783 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
784 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
785 }
786 set_echo_reference(adev->mixer, "SLIM_RX");
787 } else
788 set_echo_reference(adev->mixer, "NONE");
789 }
790 } else if (source == AUDIO_SOURCE_DEFAULT) {
791 goto exit;
792 }
793
794
795 if (snd_device != SND_DEVICE_NONE) {
796 goto exit;
797 }
798
799 if (in_device != AUDIO_DEVICE_NONE &&
800 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
801 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
802 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
803 snd_device = SND_DEVICE_IN_HANDSET_MIC;
804 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
805 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
806 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
807 snd_device = SND_DEVICE_IN_HEADSET_MIC;
808 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
809 if (adev->bt_wb_speech_enabled) {
810 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
811 } else {
812 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
813 }
814 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
815 snd_device = SND_DEVICE_IN_HDMI_MIC;
816 } else {
817 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
818 ALOGW("%s: Using default handset-mic", __func__);
819 snd_device = SND_DEVICE_IN_HANDSET_MIC;
820 }
821 } else {
822 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
823 snd_device = SND_DEVICE_IN_HANDSET_MIC;
824 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
825 snd_device = SND_DEVICE_IN_HEADSET_MIC;
826 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
827 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
828 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
829 snd_device = SND_DEVICE_IN_HANDSET_MIC;
830 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
831 if (adev->bt_wb_speech_enabled) {
832 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
833 } else {
834 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
835 }
836 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
837 snd_device = SND_DEVICE_IN_HDMI_MIC;
838 } else {
839 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
840 ALOGW("%s: Using default handset-mic", __func__);
841 snd_device = SND_DEVICE_IN_HANDSET_MIC;
842 }
843 }
844 exit:
845 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
846 return snd_device;
847 }
848
platform_set_hdmi_channels(void * platform,int channel_count)849 int platform_set_hdmi_channels(void *platform, int channel_count)
850 {
851 struct platform_data *my_data = (struct platform_data *)platform;
852 struct audio_device *adev = my_data->adev;
853 struct mixer_ctl *ctl;
854 const char *channel_cnt_str = NULL;
855 const char *mixer_ctl_name = "HDMI_RX Channels";
856 switch (channel_count) {
857 case 8:
858 channel_cnt_str = "Eight"; break;
859 case 7:
860 channel_cnt_str = "Seven"; break;
861 case 6:
862 channel_cnt_str = "Six"; break;
863 case 5:
864 channel_cnt_str = "Five"; break;
865 case 4:
866 channel_cnt_str = "Four"; break;
867 case 3:
868 channel_cnt_str = "Three"; break;
869 default:
870 channel_cnt_str = "Two"; break;
871 }
872 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
873 if (!ctl) {
874 ALOGE("%s: Could not get ctl for mixer cmd - %s",
875 __func__, mixer_ctl_name);
876 return -EINVAL;
877 }
878 ALOGV("HDMI channel count: %s", channel_cnt_str);
879 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
880 return 0;
881 }
882
platform_edid_get_max_channels(void * platform __unused)883 int platform_edid_get_max_channels(void *platform __unused)
884 {
885 FILE *file;
886 struct audio_block_header header;
887 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
888 char *sad = block;
889 int num_audio_blocks;
890 int channel_count;
891 int max_channels = 0;
892 int i;
893
894 file = fopen(AUDIO_DATA_BLOCK_PATH, "rb");
895 if (file == NULL) {
896 ALOGE("Unable to open '%s'", AUDIO_DATA_BLOCK_PATH);
897 return 0;
898 }
899
900 /* Read audio block header */
901 fread(&header, 1, sizeof(header), file);
902
903 /* Read SAD blocks, clamping the maximum size for safety */
904 if (header.length > (int)sizeof(block))
905 header.length = (int)sizeof(block);
906 fread(&block, header.length, 1, file);
907
908 fclose(file);
909
910 /* Calculate the number of SAD blocks */
911 num_audio_blocks = header.length / SAD_BLOCK_SIZE;
912
913 for (i = 0; i < num_audio_blocks; i++) {
914 /* Only consider LPCM blocks */
915 if ((sad[0] >> 3) != EDID_FORMAT_LPCM)
916 continue;
917
918 channel_count = (sad[0] & 0x7) + 1;
919 if (channel_count > max_channels)
920 max_channels = channel_count;
921
922 /* Advance to next block */
923 sad += 3;
924 }
925
926 return max_channels;
927 }
928
platform_set_incall_recording_session_id(void * platform __unused,uint32_t session_id __unused,int rec_mode __unused)929 int platform_set_incall_recording_session_id(void *platform __unused,
930 uint32_t session_id __unused, int rec_mode __unused)
931 {
932 ALOGE("%s: Not implemented", __func__);
933 return -ENOSYS;
934 }
935
platform_stop_incall_recording_usecase(void * platform __unused)936 int platform_stop_incall_recording_usecase(void *platform __unused)
937 {
938 ALOGE("%s: Not implemented", __func__);
939 return -ENOSYS;
940 }
941
platform_start_incall_music_usecase(void * platform __unused)942 int platform_start_incall_music_usecase(void *platform __unused)
943 {
944 ALOGE("%s: Not implemented", __func__);
945 return -ENOSYS;
946 }
947
platform_stop_incall_music_usecase(void * platform __unused)948 int platform_stop_incall_music_usecase(void *platform __unused)
949 {
950 ALOGE("%s: Not implemented", __func__);
951 return -ENOSYS;
952 }
953
954 /* Delay in Us */
platform_render_latency(audio_usecase_t usecase)955 int64_t platform_render_latency(audio_usecase_t usecase)
956 {
957 switch (usecase) {
958 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
959 return DEEP_BUFFER_PLATFORM_DELAY;
960 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
961 return LOW_LATENCY_PLATFORM_DELAY;
962 default:
963 return 0;
964 }
965 }
966
platform_switch_voice_call_enable_device_config(void * platform __unused,snd_device_t out_snd_device __unused,snd_device_t in_snd_device __unused)967 int platform_switch_voice_call_enable_device_config(void *platform __unused,
968 snd_device_t out_snd_device __unused,
969 snd_device_t in_snd_device __unused)
970 {
971 return 0;
972 }
973
platform_switch_voice_call_usecase_route_post(void * platform __unused,snd_device_t out_snd_device __unused,snd_device_t in_snd_device __unused)974 int platform_switch_voice_call_usecase_route_post(void *platform __unused,
975 snd_device_t out_snd_device __unused,
976 snd_device_t in_snd_device __unused)
977 {
978 return 0;
979 }
980
platform_get_sample_rate(void * platform __unused,uint32_t * rate __unused)981 int platform_get_sample_rate(void *platform __unused, uint32_t *rate __unused)
982 {
983 return -ENOSYS;
984 }
985
platform_get_usecase_index(const char * usecase __unused)986 int platform_get_usecase_index(const char * usecase __unused)
987 {
988 return -ENOSYS;
989 }
990
platform_set_usecase_pcm_id(audio_usecase_t usecase __unused,int32_t type __unused,int32_t pcm_id __unused)991 int platform_set_usecase_pcm_id(audio_usecase_t usecase __unused, int32_t type __unused,
992 int32_t pcm_id __unused)
993 {
994 return -ENOSYS;
995 }
996
platform_set_snd_device_backend(snd_device_t device __unused,const char * backend __unused)997 int platform_set_snd_device_backend(snd_device_t device __unused,
998 const char *backend __unused)
999 {
1000 return -ENOSYS;
1001 }
1002
platform_set_echo_reference(struct audio_device * adev,bool enable,audio_devices_t out_device)1003 void platform_set_echo_reference(struct audio_device *adev, bool enable, audio_devices_t out_device)
1004 {
1005 return;
1006 }
1007