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