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