blob: ac36f8758e15e3d7f86e4d313c164042bb34c135 [file] [log] [blame]
Eric Laurentb23d5282013-05-14 15:27:20 -07001/*
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07002 * Copyright (c) 2013, The Linux Foundation. All rights reserved.
3 * Not a contribution.
4 *
Eric Laurentb23d5282013-05-14 15:27:20 -07005 * Copyright (C) 2013 The Android Open Source Project
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19
20#define LOG_TAG "msm8960_platform"
21/*#define LOG_NDEBUG 0*/
22#define LOG_NDDEBUG 0
23
24#include <stdlib.h>
25#include <dlfcn.h>
26#include <cutils/log.h>
27#include <cutils/properties.h>
28#include <audio_hw.h>
29#include <platform_api.h>
30#include "platform.h"
31
32#define LIB_ACDB_LOADER "libacdbloader.so"
33#define LIB_CSD_CLIENT "libcsd-client.so"
34
Eric Laurentb23d5282013-05-14 15:27:20 -070035/*
36 * This is the sysfs path for the HDMI audio data block
37 */
38#define AUDIO_DATA_BLOCK_PATH "/sys/class/graphics/fb1/audio_data_block"
sangwoo1b9f4b32013-06-21 18:22:55 -070039#define MIXER_XML_PATH "/system/etc/mixer_paths.xml"
Eric Laurentb23d5282013-05-14 15:27:20 -070040
41/*
42 * This file will have a maximum of 38 bytes:
43 *
44 * 4 bytes: number of audio blocks
45 * 4 bytes: total length of Short Audio Descriptor (SAD) blocks
46 * Maximum 10 * 3 bytes: SAD blocks
47 */
48#define MAX_SAD_BLOCKS 10
49#define SAD_BLOCK_SIZE 3
50
51/* EDID format ID for LPCM audio */
52#define EDID_FORMAT_LPCM 1
53
54struct audio_block_header
55{
56 int reserved;
57 int length;
58};
59
60
61typedef void (*acdb_deallocate_t)();
62typedef int (*acdb_init_t)();
63typedef void (*acdb_send_audio_cal_t)(int, int);
64typedef void (*acdb_send_voice_cal_t)(int, int);
65
66typedef int (*csd_client_init_t)();
67typedef int (*csd_client_deinit_t)();
68typedef int (*csd_disable_device_t)();
69typedef int (*csd_enable_device_t)(int, int, uint32_t);
70typedef int (*csd_volume_t)(int);
71typedef int (*csd_mic_mute_t)(int);
72typedef int (*csd_start_voice_t)();
73typedef int (*csd_stop_voice_t)();
74
75
76/* Audio calibration related functions */
77struct platform_data {
78 struct audio_device *adev;
79 bool fluence_in_spkr_mode;
80 bool fluence_in_voice_call;
81 bool fluence_in_voice_rec;
Mingming Yin8e5a4f62013-10-07 15:23:41 -070082 int fluence_type;
Eric Laurentb23d5282013-05-14 15:27:20 -070083 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",
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700143 [SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef",
144 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = "voice-dmic-ef-tmus",
145 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = "voice-speaker-dmic-ef",
Eric Laurentb23d5282013-05-14 15:27:20 -0700146 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
147 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
148 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
149 [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700150 [SND_DEVICE_IN_VOICE_REC_DMIC] = "voice-rec-dmic-ef",
151 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence",
Eric Laurentb23d5282013-05-14 15:27:20 -0700152};
153
154/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
155static const int acdb_device_table[SND_DEVICE_MAX] = {
156 [SND_DEVICE_NONE] = -1,
157 [SND_DEVICE_OUT_HANDSET] = 7,
158 [SND_DEVICE_OUT_SPEAKER] = 14,
159 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 14,
160 [SND_DEVICE_OUT_HEADPHONES] = 10,
161 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
162 [SND_DEVICE_OUT_VOICE_SPEAKER] = 14,
163 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
164 [SND_DEVICE_OUT_HDMI] = 18,
165 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 14,
166 [SND_DEVICE_OUT_BT_SCO] = 22,
167 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = 81,
168 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
169 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
170 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
171
172 [SND_DEVICE_IN_HANDSET_MIC] = 4,
173 [SND_DEVICE_IN_SPEAKER_MIC] = 4,
174 [SND_DEVICE_IN_HEADSET_MIC] = 8,
175 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 40,
176 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 42,
177 [SND_DEVICE_IN_HEADSET_MIC_AEC] = 47,
178 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
179 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = 8,
180 [SND_DEVICE_IN_HDMI_MIC] = 4,
181 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
182 [SND_DEVICE_IN_CAMCORDER_MIC] = 61,
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700183 [SND_DEVICE_IN_VOICE_DMIC] = 6,
184 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = 91,
185 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 13,
Eric Laurentb23d5282013-05-14 15:27:20 -0700186 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
187 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
188 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
189 [SND_DEVICE_IN_VOICE_REC_MIC] = 62,
190 /* TODO: Update with proper acdb ids */
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700191 [SND_DEVICE_IN_VOICE_REC_DMIC] = 62,
192 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 6,
Eric Laurentb23d5282013-05-14 15:27:20 -0700193};
194
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700195#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
196#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
197
Eric Laurentb23d5282013-05-14 15:27:20 -0700198static pthread_once_t check_op_once_ctl = PTHREAD_ONCE_INIT;
199static bool is_tmus = false;
200
201static void check_operator()
202{
203 char value[PROPERTY_VALUE_MAX];
204 int mccmnc;
205 property_get("gsm.sim.operator.numeric",value,"0");
206 mccmnc = atoi(value);
207 ALOGD("%s: tmus mccmnc %d", __func__, mccmnc);
208 switch(mccmnc) {
209 /* TMUS MCC(310), MNC(490, 260, 026) */
210 case 310490:
211 case 310260:
212 case 310026:
213 is_tmus = true;
214 break;
215 }
216}
217
218bool is_operator_tmus()
219{
220 pthread_once(&check_op_once_ctl, check_operator);
221 return is_tmus;
222}
223
224static int set_echo_reference(struct mixer *mixer, const char* ec_ref)
225{
226 struct mixer_ctl *ctl;
227 const char *mixer_ctl_name = "EC_REF_RX";
228
229 ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name);
230 if (!ctl) {
231 ALOGE("%s: Could not get ctl for mixer cmd - %s",
232 __func__, mixer_ctl_name);
233 return -EINVAL;
234 }
235 ALOGV("Setting EC Reference: %s", ec_ref);
236 mixer_ctl_set_enum_by_string(ctl, ec_ref);
237 return 0;
238}
239
240void *platform_init(struct audio_device *adev)
241{
242 char platform[PROPERTY_VALUE_MAX];
243 char baseband[PROPERTY_VALUE_MAX];
244 char value[PROPERTY_VALUE_MAX];
245 struct platform_data *my_data;
246
sangwoo1b9f4b32013-06-21 18:22:55 -0700247 adev->mixer = mixer_open(MIXER_CARD);
248
249 if (!adev->mixer) {
250 ALOGE("Unable to open the mixer, aborting.");
251 return NULL;
252 }
253
254 adev->audio_route = audio_route_init(MIXER_CARD, MIXER_XML_PATH);
255 if (!adev->audio_route) {
256 ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
257 return NULL;
258 }
259
Eric Laurentb23d5282013-05-14 15:27:20 -0700260 my_data = calloc(1, sizeof(struct platform_data));
261
262 my_data->adev = adev;
Eric Laurentb23d5282013-05-14 15:27:20 -0700263 my_data->fluence_in_spkr_mode = false;
264 my_data->fluence_in_voice_call = false;
265 my_data->fluence_in_voice_rec = false;
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700266 my_data->fluence_type = FLUENCE_NONE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700267
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700268 property_get("ro.qc.sdk.audio.fluencetype", value, "");
269 if (!strncmp("fluencepro", value, sizeof("fluencepro"))) {
270 my_data->fluence_type = FLUENCE_QUAD_MIC;
271 } else if (!strncmp("fluence", value, sizeof("fluence"))) {
272 my_data->fluence_type = FLUENCE_DUAL_MIC;
273 } else {
274 my_data->fluence_type = FLUENCE_NONE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700275 }
276
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700277 if (my_data->fluence_type != FLUENCE_NONE) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700278 property_get("persist.audio.fluence.voicecall",value,"");
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700279 if (!strncmp("true", value, sizeof("true"))) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700280 my_data->fluence_in_voice_call = true;
281 }
282
283 property_get("persist.audio.fluence.voicerec",value,"");
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700284 if (!strncmp("true", value, sizeof("true"))) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700285 my_data->fluence_in_voice_rec = true;
286 }
287
288 property_get("persist.audio.fluence.speaker",value,"");
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700289 if (!strncmp("true", value, sizeof("true"))) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700290 my_data->fluence_in_spkr_mode = true;
291 }
292 }
293
294 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
295 if (my_data->acdb_handle == NULL) {
296 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
297 } else {
298 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
299 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
300 "acdb_loader_deallocate_ACDB");
301 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
302 "acdb_loader_send_audio_cal");
303 if (!my_data->acdb_send_audio_cal)
304 ALOGW("%s: Could not find the symbol acdb_send_audio_cal from %s",
305 __func__, LIB_ACDB_LOADER);
306 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
307 "acdb_loader_send_voice_cal");
308 my_data->acdb_init = (acdb_init_t)dlsym(my_data->acdb_handle,
309 "acdb_loader_init_ACDB");
310 if (my_data->acdb_init == NULL)
311 ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__, dlerror());
312 else
313 my_data->acdb_init();
314 }
315
316 /* If platform is Fusion3, load CSD Client specific symbols
317 * Voice call is handled by MDM and apps processor talks to
318 * MDM through CSD Client
319 */
320 property_get("ro.board.platform", platform, "");
321 property_get("ro.baseband", baseband, "");
322 if (!strcmp("msm8960", platform) && !strcmp("mdm", baseband)) {
323 my_data->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
324 if (my_data->csd_client == NULL)
325 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
326 }
327
328 if (my_data->csd_client) {
329 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
330 my_data->csd_client_deinit = (csd_client_deinit_t)dlsym(my_data->csd_client,
331 "csd_client_deinit");
332 my_data->csd_disable_device = (csd_disable_device_t)dlsym(my_data->csd_client,
333 "csd_client_disable_device");
334 my_data->csd_enable_device = (csd_enable_device_t)dlsym(my_data->csd_client,
335 "csd_client_enable_device");
336 my_data->csd_start_voice = (csd_start_voice_t)dlsym(my_data->csd_client,
337 "csd_client_start_voice");
338 my_data->csd_stop_voice = (csd_stop_voice_t)dlsym(my_data->csd_client,
339 "csd_client_stop_voice");
340 my_data->csd_volume = (csd_volume_t)dlsym(my_data->csd_client,
341 "csd_client_volume");
342 my_data->csd_mic_mute = (csd_mic_mute_t)dlsym(my_data->csd_client,
343 "csd_client_mic_mute");
344 my_data->csd_client_init = (csd_client_init_t)dlsym(my_data->csd_client,
345 "csd_client_init");
346
347 if (my_data->csd_client_init == NULL) {
348 ALOGE("%s: dlsym error %s for csd_client_init", __func__, dlerror());
349 } else {
350 my_data->csd_client_init();
351 }
352 }
353
354 return my_data;
355}
356
357void platform_deinit(void *platform)
358{
359 free(platform);
360}
361
362const char *platform_get_snd_device_name(snd_device_t snd_device)
363{
364 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX)
365 return device_table[snd_device];
366 else
367 return "";
368}
369
370void platform_add_backend_name(char *mixer_path, snd_device_t snd_device)
371{
372 if (snd_device == SND_DEVICE_IN_BT_SCO_MIC)
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700373 strlcat(mixer_path, " bt-sco", MIXER_PATH_MAX_LENGTH);
374 else if (snd_device == SND_DEVICE_IN_BT_SCO_MIC_WB)
375 strlcat(mixer_path, " bt-sco-wb", MIXER_PATH_MAX_LENGTH);
Eric Laurentb23d5282013-05-14 15:27:20 -0700376 else if(snd_device == SND_DEVICE_OUT_BT_SCO)
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700377 strlcat(mixer_path, " bt-sco", MIXER_PATH_MAX_LENGTH);
378 else if(snd_device == SND_DEVICE_OUT_BT_SCO_WB)
379 strlcat(mixer_path, " bt-sco-wb", MIXER_PATH_MAX_LENGTH);
Eric Laurentb23d5282013-05-14 15:27:20 -0700380 else if (snd_device == SND_DEVICE_OUT_HDMI)
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700381 strlcat(mixer_path, " hdmi", MIXER_PATH_MAX_LENGTH);
Eric Laurentb23d5282013-05-14 15:27:20 -0700382 else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HDMI)
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700383 strlcat(mixer_path, " speaker-and-hdmi", MIXER_PATH_MAX_LENGTH);
Eric Laurentb23d5282013-05-14 15:27:20 -0700384}
385
386int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
387{
388 int device_id;
389 if (device_type == PCM_PLAYBACK)
390 device_id = pcm_device_table[usecase][0];
391 else
392 device_id = pcm_device_table[usecase][1];
393 return device_id;
394}
395
396int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
397{
398 struct platform_data *my_data = (struct platform_data *)platform;
399 int acdb_dev_id, acdb_dev_type;
400
401 acdb_dev_id = acdb_device_table[snd_device];
402 if (acdb_dev_id < 0) {
403 ALOGE("%s: Could not find acdb id for device(%d)",
404 __func__, snd_device);
405 return -EINVAL;
406 }
407 if (my_data->acdb_send_audio_cal) {
Eric Laurent994a6932013-07-17 11:51:42 -0700408 ("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Eric Laurentb23d5282013-05-14 15:27:20 -0700409 __func__, snd_device, acdb_dev_id);
410 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
411 snd_device < SND_DEVICE_OUT_END)
412 acdb_dev_type = ACDB_DEV_TYPE_OUT;
413 else
414 acdb_dev_type = ACDB_DEV_TYPE_IN;
415 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
416 }
417 return 0;
418}
419
420int platform_switch_voice_call_device_pre(void *platform)
421{
422 struct platform_data *my_data = (struct platform_data *)platform;
423 int ret = 0;
424
425 if (my_data->csd_client != NULL) {
426 /* This must be called before disabling the mixer controls on APQ side */
427 if (my_data->csd_disable_device == NULL) {
428 ALOGE("%s: dlsym error for csd_disable_device", __func__);
429 } else {
430 ret = my_data->csd_disable_device();
431 if (ret < 0) {
432 ALOGE("%s: csd_client_disable_device, failed, error %d",
433 __func__, ret);
434 }
435 }
436 }
437 return ret;
438}
439
440int platform_switch_voice_call_device_post(void *platform,
441 snd_device_t out_snd_device,
442 snd_device_t in_snd_device)
443{
444 struct platform_data *my_data = (struct platform_data *)platform;
445 int acdb_rx_id, acdb_tx_id;
446 int ret = 0;
447
448 if (my_data->csd_client) {
449 if (my_data->csd_enable_device == NULL) {
450 ALOGE("%s: dlsym error for csd_enable_device",
451 __func__);
452 } else {
453 acdb_rx_id = acdb_device_table[out_snd_device];
454 acdb_tx_id = acdb_device_table[in_snd_device];
455
456 if (acdb_rx_id > 0 || acdb_tx_id > 0) {
457 ret = my_data->csd_enable_device(acdb_rx_id, acdb_tx_id,
458 my_data->adev->acdb_settings);
459 if (ret < 0) {
460 ALOGE("%s: csd_enable_device, failed, error %d",
461 __func__, ret);
462 }
463 } else {
464 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
465 acdb_rx_id, acdb_tx_id);
466 }
467 }
468 }
469
470 return ret;
471}
472
473int platform_start_voice_call(void *platform)
474{
475 struct platform_data *my_data = (struct platform_data *)platform;
476 int ret = 0;
477
478 if (my_data->csd_client) {
479 if (my_data->csd_start_voice == NULL) {
480 ALOGE("dlsym error for csd_client_start_voice");
481 ret = -ENOSYS;
482 } else {
483 ret = my_data->csd_start_voice();
484 if (ret < 0) {
485 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
486 }
487 }
488 }
489
490 return ret;
491}
492
493int platform_stop_voice_call(void *platform)
494{
495 struct platform_data *my_data = (struct platform_data *)platform;
496 int ret = 0;
497
498 if (my_data->csd_client) {
499 if (my_data->csd_stop_voice == NULL) {
500 ALOGE("dlsym error for csd_stop_voice");
501 } else {
502 ret = my_data->csd_stop_voice();
503 if (ret < 0) {
504 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
505 }
506 }
507 }
508
509 return ret;
510}
511
512int platform_set_voice_volume(void *platform, int volume)
513{
514 struct platform_data *my_data = (struct platform_data *)platform;
515 int ret = 0;
516
517 if (my_data->csd_client) {
518 if (my_data->csd_volume == NULL) {
519 ALOGE("%s: dlsym error for csd_volume", __func__);
520 } else {
521 ret = my_data->csd_volume(volume);
522 if (ret < 0) {
523 ALOGE("%s: csd_volume error %d", __func__, ret);
524 }
525 }
526 } else {
527 ALOGE("%s: No CSD Client present", __func__);
528 }
529
530 return ret;
531}
532
533int platform_set_mic_mute(void *platform, bool state)
534{
535 struct platform_data *my_data = (struct platform_data *)platform;
536 int ret = 0;
537
538 if (my_data->adev->mode == AUDIO_MODE_IN_CALL) {
539 if (my_data->csd_client) {
540 if (my_data->csd_mic_mute == NULL) {
541 ALOGE("%s: dlsym error for csd_mic_mute", __func__);
542 } else {
543 ret = my_data->csd_mic_mute(state);
544 if (ret < 0) {
545 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
546 }
547 }
548 } else {
549 ALOGE("%s: No CSD Client present", __func__);
550 }
551 }
552
553 return ret;
554}
555
556snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
557{
558 struct platform_data *my_data = (struct platform_data *)platform;
559 struct audio_device *adev = my_data->adev;
560 audio_mode_t mode = adev->mode;
561 snd_device_t snd_device = SND_DEVICE_NONE;
562
563 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
564 if (devices == AUDIO_DEVICE_NONE ||
565 devices & AUDIO_DEVICE_BIT_IN) {
566 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
567 goto exit;
568 }
569
570 if (mode == AUDIO_MODE_IN_CALL) {
571 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
572 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
573 if (adev->tty_mode == TTY_MODE_FULL)
574 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
575 else if (adev->tty_mode == TTY_MODE_VCO)
576 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
577 else if (adev->tty_mode == TTY_MODE_HCO)
578 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
579 else
580 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
581 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
582 snd_device = SND_DEVICE_OUT_BT_SCO;
583 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
584 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
585 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
586 if (is_operator_tmus())
587 snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS;
588 else
589 snd_device = SND_DEVICE_OUT_HANDSET;
590 }
591 if (snd_device != SND_DEVICE_NONE) {
592 goto exit;
593 }
594 }
595
596 if (popcount(devices) == 2) {
597 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
598 AUDIO_DEVICE_OUT_SPEAKER)) {
599 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
600 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
601 AUDIO_DEVICE_OUT_SPEAKER)) {
602 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
603 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
604 AUDIO_DEVICE_OUT_SPEAKER)) {
605 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
606 } else {
607 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
608 goto exit;
609 }
610 if (snd_device != SND_DEVICE_NONE) {
611 goto exit;
612 }
613 }
614
615 if (popcount(devices) != 1) {
616 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
617 goto exit;
618 }
619
620 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
621 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
622 snd_device = SND_DEVICE_OUT_HEADPHONES;
623 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
624 if (adev->speaker_lr_swap)
625 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
626 else
627 snd_device = SND_DEVICE_OUT_SPEAKER;
628 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
629 snd_device = SND_DEVICE_OUT_BT_SCO;
630 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
631 snd_device = SND_DEVICE_OUT_HDMI ;
632 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
633 snd_device = SND_DEVICE_OUT_HANDSET;
634 } else {
635 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
636 }
637exit:
638 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
639 return snd_device;
640}
641
642snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
643{
644 struct platform_data *my_data = (struct platform_data *)platform;
645 struct audio_device *adev = my_data->adev;
646 audio_source_t source = (adev->active_input == NULL) ?
647 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
648
649 audio_mode_t mode = adev->mode;
650 audio_devices_t in_device = ((adev->active_input == NULL) ?
651 AUDIO_DEVICE_NONE : adev->active_input->device)
652 & ~AUDIO_DEVICE_BIT_IN;
653 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
654 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
655 snd_device_t snd_device = SND_DEVICE_NONE;
656
657 ALOGV("%s: enter: out_device(%#x) in_device(%#x)",
658 __func__, out_device, in_device);
659 if (mode == AUDIO_MODE_IN_CALL) {
660 if (out_device == AUDIO_DEVICE_NONE) {
661 ALOGE("%s: No output device set for voice call", __func__);
662 goto exit;
663 }
664 if (adev->tty_mode != TTY_MODE_OFF) {
665 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
666 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
667 switch (adev->tty_mode) {
668 case TTY_MODE_FULL:
669 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
670 break;
671 case TTY_MODE_VCO:
672 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
673 break;
674 case TTY_MODE_HCO:
675 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
676 break;
677 default:
678 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->tty_mode);
679 }
680 goto exit;
681 }
682 }
683 if (out_device & AUDIO_DEVICE_OUT_EARPIECE ||
684 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700685 if (my_data->fluence_type == FLUENCE_NONE ||
686 my_data->fluence_in_voice_call == false) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700687 snd_device = SND_DEVICE_IN_HANDSET_MIC;
688 } else {
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700689 if (is_operator_tmus())
690 snd_device = SND_DEVICE_IN_VOICE_DMIC_TMUS;
Eric Laurentb23d5282013-05-14 15:27:20 -0700691 else
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700692 snd_device = SND_DEVICE_IN_VOICE_DMIC;
693 adev->acdb_settings |= DMIC_FLAG;
Eric Laurentb23d5282013-05-14 15:27:20 -0700694 }
695 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
696 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
697 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
698 snd_device = SND_DEVICE_IN_BT_SCO_MIC ;
699 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700700 if (my_data->fluence_type != FLUENCE_NONE &&
701 my_data->fluence_in_voice_call &&
702 my_data->fluence_in_spkr_mode) {
703 if(my_data->fluence_type == FLUENCE_DUAL_MIC) {
704 adev->acdb_settings |= DMIC_FLAG;
705 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
706 } else {
707 adev->acdb_settings |= QMIC_FLAG;
708 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_QMIC;
709 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700710 } 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) {
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700721 if (channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK)
722 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC;
723 else if (my_data->fluence_in_voice_rec)
724 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700725
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700726 if (snd_device == SND_DEVICE_NONE)
Eric Laurentb23d5282013-05-14 15:27:20 -0700727 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700728 else
729 adev->acdb_settings |= DMIC_FLAG;
Eric Laurentb23d5282013-05-14 15:27:20 -0700730 }
731 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION) {
732 if (out_device & AUDIO_DEVICE_OUT_SPEAKER)
733 in_device = AUDIO_DEVICE_IN_BACK_MIC;
734 if (adev->active_input) {
735 if (adev->active_input->enable_aec) {
736 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
737 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
738 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
739 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
740 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
741 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
742 }
743 set_echo_reference(adev->mixer, "SLIM_RX");
744 } else
745 set_echo_reference(adev->mixer, "NONE");
746 }
747 } else if (source == AUDIO_SOURCE_DEFAULT) {
748 goto exit;
749 }
750
751
752 if (snd_device != SND_DEVICE_NONE) {
753 goto exit;
754 }
755
756 if (in_device != AUDIO_DEVICE_NONE &&
757 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
758 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
759 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
760 snd_device = SND_DEVICE_IN_HANDSET_MIC;
761 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
762 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
763 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
764 snd_device = SND_DEVICE_IN_HEADSET_MIC;
765 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
766 snd_device = SND_DEVICE_IN_BT_SCO_MIC ;
767 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
768 snd_device = SND_DEVICE_IN_HDMI_MIC;
769 } else {
770 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
771 ALOGW("%s: Using default handset-mic", __func__);
772 snd_device = SND_DEVICE_IN_HANDSET_MIC;
773 }
774 } else {
775 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
776 snd_device = SND_DEVICE_IN_HANDSET_MIC;
777 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
778 snd_device = SND_DEVICE_IN_HEADSET_MIC;
779 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
780 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
781 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
782 snd_device = SND_DEVICE_IN_HANDSET_MIC;
783 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
784 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
785 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
786 snd_device = SND_DEVICE_IN_HDMI_MIC;
787 } else {
788 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
789 ALOGW("%s: Using default handset-mic", __func__);
790 snd_device = SND_DEVICE_IN_HANDSET_MIC;
791 }
792 }
793exit:
794 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
795 return snd_device;
796}
797
798int platform_set_hdmi_channels(void *platform, int channel_count)
799{
800 struct platform_data *my_data = (struct platform_data *)platform;
801 struct audio_device *adev = my_data->adev;
802 struct mixer_ctl *ctl;
803 const char *channel_cnt_str = NULL;
804 const char *mixer_ctl_name = "HDMI_RX Channels";
805 switch (channel_count) {
806 case 8:
807 channel_cnt_str = "Eight"; break;
808 case 7:
809 channel_cnt_str = "Seven"; break;
810 case 6:
811 channel_cnt_str = "Six"; break;
812 case 5:
813 channel_cnt_str = "Five"; break;
814 case 4:
815 channel_cnt_str = "Four"; break;
816 case 3:
817 channel_cnt_str = "Three"; break;
818 default:
819 channel_cnt_str = "Two"; break;
820 }
821 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
822 if (!ctl) {
823 ALOGE("%s: Could not get ctl for mixer cmd - %s",
824 __func__, mixer_ctl_name);
825 return -EINVAL;
826 }
827 ALOGV("HDMI channel count: %s", channel_cnt_str);
828 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
829 return 0;
830}
831
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -0700832int platform_edid_get_max_channels(void *platform)
Eric Laurentb23d5282013-05-14 15:27:20 -0700833{
834 FILE *file;
835 struct audio_block_header header;
836 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
837 char *sad = block;
838 int num_audio_blocks;
839 int channel_count;
840 int max_channels = 0;
841 int i;
842
843 file = fopen(AUDIO_DATA_BLOCK_PATH, "rb");
844 if (file == NULL) {
845 ALOGE("Unable to open '%s'", AUDIO_DATA_BLOCK_PATH);
846 return 0;
847 }
848
849 /* Read audio block header */
850 fread(&header, 1, sizeof(header), file);
851
852 /* Read SAD blocks, clamping the maximum size for safety */
853 if (header.length > (int)sizeof(block))
854 header.length = (int)sizeof(block);
855 fread(&block, header.length, 1, file);
856
857 fclose(file);
858
859 /* Calculate the number of SAD blocks */
860 num_audio_blocks = header.length / SAD_BLOCK_SIZE;
861
862 for (i = 0; i < num_audio_blocks; i++) {
863 /* Only consider LPCM blocks */
864 if ((sad[0] >> 3) != EDID_FORMAT_LPCM)
865 continue;
866
867 channel_count = (sad[0] & 0x7) + 1;
868 if (channel_count > max_channels)
869 max_channels = channel_count;
870
871 /* Advance to next block */
872 sad += 3;
873 }
874
875 return max_channels;
876}
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700877
878void platform_get_parameters(void *platform, struct str_parms *query,
879 struct str_parms *reply)
880{
881 LOGE("%s: Not implemented", __func__);
882}
883
884int platform_set_parameters(void *platform, struct str_parms *parms)
885{
886 LOGE("%s: Not implemented", __func__);
887 return -ENOSYS;
888}
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700889
890int platform_set_incall_recoding_session_id(void *platform, uint32_t session_id)
891{
892 LOGE("%s: Not implemented", __func__);
893 return -ENOSYS;
894}
Shruthi Krishnaace10852013-10-25 14:32:12 -0700895
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700896/* Delay in Us */
897int64_t platform_render_latency(audio_usecase_t usecase)
898{
899 switch (usecase) {
900 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
901 return DEEP_BUFFER_PLATFORM_DELAY;
902 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
903 return LOW_LATENCY_PLATFORM_DELAY;
904 default:
905 return 0;
906 }
907}