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