blob: 78d06c538b93743db60551a1648a740043fe2941 [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
195static pthread_once_t check_op_once_ctl = PTHREAD_ONCE_INIT;
196static bool is_tmus = false;
197
198static void check_operator()
199{
200 char value[PROPERTY_VALUE_MAX];
201 int mccmnc;
202 property_get("gsm.sim.operator.numeric",value,"0");
203 mccmnc = atoi(value);
204 ALOGD("%s: tmus mccmnc %d", __func__, mccmnc);
205 switch(mccmnc) {
206 /* TMUS MCC(310), MNC(490, 260, 026) */
207 case 310490:
208 case 310260:
209 case 310026:
210 is_tmus = true;
211 break;
212 }
213}
214
215bool is_operator_tmus()
216{
217 pthread_once(&check_op_once_ctl, check_operator);
218 return is_tmus;
219}
220
221static int set_echo_reference(struct mixer *mixer, const char* ec_ref)
222{
223 struct mixer_ctl *ctl;
224 const char *mixer_ctl_name = "EC_REF_RX";
225
226 ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name);
227 if (!ctl) {
228 ALOGE("%s: Could not get ctl for mixer cmd - %s",
229 __func__, mixer_ctl_name);
230 return -EINVAL;
231 }
232 ALOGV("Setting EC Reference: %s", ec_ref);
233 mixer_ctl_set_enum_by_string(ctl, ec_ref);
234 return 0;
235}
236
237void *platform_init(struct audio_device *adev)
238{
239 char platform[PROPERTY_VALUE_MAX];
240 char baseband[PROPERTY_VALUE_MAX];
241 char value[PROPERTY_VALUE_MAX];
242 struct platform_data *my_data;
243
sangwoo1b9f4b32013-06-21 18:22:55 -0700244 adev->mixer = mixer_open(MIXER_CARD);
245
246 if (!adev->mixer) {
247 ALOGE("Unable to open the mixer, aborting.");
248 return NULL;
249 }
250
251 adev->audio_route = audio_route_init(MIXER_CARD, MIXER_XML_PATH);
252 if (!adev->audio_route) {
253 ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
254 return NULL;
255 }
256
Eric Laurentb23d5282013-05-14 15:27:20 -0700257 my_data = calloc(1, sizeof(struct platform_data));
258
259 my_data->adev = adev;
Eric Laurentb23d5282013-05-14 15:27:20 -0700260 my_data->fluence_in_spkr_mode = false;
261 my_data->fluence_in_voice_call = false;
262 my_data->fluence_in_voice_rec = false;
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700263 my_data->fluence_type = FLUENCE_NONE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700264
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700265 property_get("ro.qc.sdk.audio.fluencetype", value, "");
266 if (!strncmp("fluencepro", value, sizeof("fluencepro"))) {
267 my_data->fluence_type = FLUENCE_QUAD_MIC;
268 } else if (!strncmp("fluence", value, sizeof("fluence"))) {
269 my_data->fluence_type = FLUENCE_DUAL_MIC;
270 } else {
271 my_data->fluence_type = FLUENCE_NONE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700272 }
273
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700274 if (my_data->fluence_type != FLUENCE_NONE) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700275 property_get("persist.audio.fluence.voicecall",value,"");
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700276 if (!strncmp("true", value, sizeof("true"))) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700277 my_data->fluence_in_voice_call = true;
278 }
279
280 property_get("persist.audio.fluence.voicerec",value,"");
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700281 if (!strncmp("true", value, sizeof("true"))) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700282 my_data->fluence_in_voice_rec = true;
283 }
284
285 property_get("persist.audio.fluence.speaker",value,"");
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700286 if (!strncmp("true", value, sizeof("true"))) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700287 my_data->fluence_in_spkr_mode = true;
288 }
289 }
290
291 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
292 if (my_data->acdb_handle == NULL) {
293 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
294 } else {
295 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
296 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
297 "acdb_loader_deallocate_ACDB");
298 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
299 "acdb_loader_send_audio_cal");
300 if (!my_data->acdb_send_audio_cal)
301 ALOGW("%s: Could not find the symbol acdb_send_audio_cal from %s",
302 __func__, LIB_ACDB_LOADER);
303 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
304 "acdb_loader_send_voice_cal");
305 my_data->acdb_init = (acdb_init_t)dlsym(my_data->acdb_handle,
306 "acdb_loader_init_ACDB");
307 if (my_data->acdb_init == NULL)
308 ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__, dlerror());
309 else
310 my_data->acdb_init();
311 }
312
313 /* If platform is Fusion3, load CSD Client specific symbols
314 * Voice call is handled by MDM and apps processor talks to
315 * MDM through CSD Client
316 */
317 property_get("ro.board.platform", platform, "");
318 property_get("ro.baseband", baseband, "");
319 if (!strcmp("msm8960", platform) && !strcmp("mdm", baseband)) {
320 my_data->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
321 if (my_data->csd_client == NULL)
322 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
323 }
324
325 if (my_data->csd_client) {
326 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
327 my_data->csd_client_deinit = (csd_client_deinit_t)dlsym(my_data->csd_client,
328 "csd_client_deinit");
329 my_data->csd_disable_device = (csd_disable_device_t)dlsym(my_data->csd_client,
330 "csd_client_disable_device");
331 my_data->csd_enable_device = (csd_enable_device_t)dlsym(my_data->csd_client,
332 "csd_client_enable_device");
333 my_data->csd_start_voice = (csd_start_voice_t)dlsym(my_data->csd_client,
334 "csd_client_start_voice");
335 my_data->csd_stop_voice = (csd_stop_voice_t)dlsym(my_data->csd_client,
336 "csd_client_stop_voice");
337 my_data->csd_volume = (csd_volume_t)dlsym(my_data->csd_client,
338 "csd_client_volume");
339 my_data->csd_mic_mute = (csd_mic_mute_t)dlsym(my_data->csd_client,
340 "csd_client_mic_mute");
341 my_data->csd_client_init = (csd_client_init_t)dlsym(my_data->csd_client,
342 "csd_client_init");
343
344 if (my_data->csd_client_init == NULL) {
345 ALOGE("%s: dlsym error %s for csd_client_init", __func__, dlerror());
346 } else {
347 my_data->csd_client_init();
348 }
349 }
350
351 return my_data;
352}
353
354void platform_deinit(void *platform)
355{
356 free(platform);
357}
358
359const char *platform_get_snd_device_name(snd_device_t snd_device)
360{
361 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX)
362 return device_table[snd_device];
363 else
364 return "";
365}
366
367void platform_add_backend_name(char *mixer_path, snd_device_t snd_device)
368{
369 if (snd_device == SND_DEVICE_IN_BT_SCO_MIC)
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700370 strlcat(mixer_path, " bt-sco", MIXER_PATH_MAX_LENGTH);
371 else if (snd_device == SND_DEVICE_IN_BT_SCO_MIC_WB)
372 strlcat(mixer_path, " bt-sco-wb", MIXER_PATH_MAX_LENGTH);
Eric Laurentb23d5282013-05-14 15:27:20 -0700373 else if(snd_device == SND_DEVICE_OUT_BT_SCO)
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700374 strlcat(mixer_path, " bt-sco", MIXER_PATH_MAX_LENGTH);
375 else if(snd_device == SND_DEVICE_OUT_BT_SCO_WB)
376 strlcat(mixer_path, " bt-sco-wb", MIXER_PATH_MAX_LENGTH);
Eric Laurentb23d5282013-05-14 15:27:20 -0700377 else if (snd_device == SND_DEVICE_OUT_HDMI)
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700378 strlcat(mixer_path, " hdmi", MIXER_PATH_MAX_LENGTH);
Eric Laurentb23d5282013-05-14 15:27:20 -0700379 else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HDMI)
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700380 strlcat(mixer_path, " speaker-and-hdmi", MIXER_PATH_MAX_LENGTH);
Eric Laurentb23d5282013-05-14 15:27:20 -0700381}
382
383int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
384{
385 int device_id;
386 if (device_type == PCM_PLAYBACK)
387 device_id = pcm_device_table[usecase][0];
388 else
389 device_id = pcm_device_table[usecase][1];
390 return device_id;
391}
392
393int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
394{
395 struct platform_data *my_data = (struct platform_data *)platform;
396 int acdb_dev_id, acdb_dev_type;
397
398 acdb_dev_id = acdb_device_table[snd_device];
399 if (acdb_dev_id < 0) {
400 ALOGE("%s: Could not find acdb id for device(%d)",
401 __func__, snd_device);
402 return -EINVAL;
403 }
404 if (my_data->acdb_send_audio_cal) {
Eric Laurent994a6932013-07-17 11:51:42 -0700405 ("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Eric Laurentb23d5282013-05-14 15:27:20 -0700406 __func__, snd_device, acdb_dev_id);
407 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
408 snd_device < SND_DEVICE_OUT_END)
409 acdb_dev_type = ACDB_DEV_TYPE_OUT;
410 else
411 acdb_dev_type = ACDB_DEV_TYPE_IN;
412 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
413 }
414 return 0;
415}
416
417int platform_switch_voice_call_device_pre(void *platform)
418{
419 struct platform_data *my_data = (struct platform_data *)platform;
420 int ret = 0;
421
422 if (my_data->csd_client != NULL) {
423 /* This must be called before disabling the mixer controls on APQ side */
424 if (my_data->csd_disable_device == NULL) {
425 ALOGE("%s: dlsym error for csd_disable_device", __func__);
426 } else {
427 ret = my_data->csd_disable_device();
428 if (ret < 0) {
429 ALOGE("%s: csd_client_disable_device, failed, error %d",
430 __func__, ret);
431 }
432 }
433 }
434 return ret;
435}
436
437int platform_switch_voice_call_device_post(void *platform,
438 snd_device_t out_snd_device,
439 snd_device_t in_snd_device)
440{
441 struct platform_data *my_data = (struct platform_data *)platform;
442 int acdb_rx_id, acdb_tx_id;
443 int ret = 0;
444
445 if (my_data->csd_client) {
446 if (my_data->csd_enable_device == NULL) {
447 ALOGE("%s: dlsym error for csd_enable_device",
448 __func__);
449 } else {
450 acdb_rx_id = acdb_device_table[out_snd_device];
451 acdb_tx_id = acdb_device_table[in_snd_device];
452
453 if (acdb_rx_id > 0 || acdb_tx_id > 0) {
454 ret = my_data->csd_enable_device(acdb_rx_id, acdb_tx_id,
455 my_data->adev->acdb_settings);
456 if (ret < 0) {
457 ALOGE("%s: csd_enable_device, failed, error %d",
458 __func__, ret);
459 }
460 } else {
461 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
462 acdb_rx_id, acdb_tx_id);
463 }
464 }
465 }
466
467 return ret;
468}
469
470int platform_start_voice_call(void *platform)
471{
472 struct platform_data *my_data = (struct platform_data *)platform;
473 int ret = 0;
474
475 if (my_data->csd_client) {
476 if (my_data->csd_start_voice == NULL) {
477 ALOGE("dlsym error for csd_client_start_voice");
478 ret = -ENOSYS;
479 } else {
480 ret = my_data->csd_start_voice();
481 if (ret < 0) {
482 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
483 }
484 }
485 }
486
487 return ret;
488}
489
490int platform_stop_voice_call(void *platform)
491{
492 struct platform_data *my_data = (struct platform_data *)platform;
493 int ret = 0;
494
495 if (my_data->csd_client) {
496 if (my_data->csd_stop_voice == NULL) {
497 ALOGE("dlsym error for csd_stop_voice");
498 } else {
499 ret = my_data->csd_stop_voice();
500 if (ret < 0) {
501 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
502 }
503 }
504 }
505
506 return ret;
507}
508
509int platform_set_voice_volume(void *platform, int volume)
510{
511 struct platform_data *my_data = (struct platform_data *)platform;
512 int ret = 0;
513
514 if (my_data->csd_client) {
515 if (my_data->csd_volume == NULL) {
516 ALOGE("%s: dlsym error for csd_volume", __func__);
517 } else {
518 ret = my_data->csd_volume(volume);
519 if (ret < 0) {
520 ALOGE("%s: csd_volume error %d", __func__, ret);
521 }
522 }
523 } else {
524 ALOGE("%s: No CSD Client present", __func__);
525 }
526
527 return ret;
528}
529
530int platform_set_mic_mute(void *platform, bool state)
531{
532 struct platform_data *my_data = (struct platform_data *)platform;
533 int ret = 0;
534
535 if (my_data->adev->mode == AUDIO_MODE_IN_CALL) {
536 if (my_data->csd_client) {
537 if (my_data->csd_mic_mute == NULL) {
538 ALOGE("%s: dlsym error for csd_mic_mute", __func__);
539 } else {
540 ret = my_data->csd_mic_mute(state);
541 if (ret < 0) {
542 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
543 }
544 }
545 } else {
546 ALOGE("%s: No CSD Client present", __func__);
547 }
548 }
549
550 return ret;
551}
552
553snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
554{
555 struct platform_data *my_data = (struct platform_data *)platform;
556 struct audio_device *adev = my_data->adev;
557 audio_mode_t mode = adev->mode;
558 snd_device_t snd_device = SND_DEVICE_NONE;
559
560 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
561 if (devices == AUDIO_DEVICE_NONE ||
562 devices & AUDIO_DEVICE_BIT_IN) {
563 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
564 goto exit;
565 }
566
567 if (mode == AUDIO_MODE_IN_CALL) {
568 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
569 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
570 if (adev->tty_mode == TTY_MODE_FULL)
571 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
572 else if (adev->tty_mode == TTY_MODE_VCO)
573 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
574 else if (adev->tty_mode == TTY_MODE_HCO)
575 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
576 else
577 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
578 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
579 snd_device = SND_DEVICE_OUT_BT_SCO;
580 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
581 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
582 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
583 if (is_operator_tmus())
584 snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS;
585 else
586 snd_device = SND_DEVICE_OUT_HANDSET;
587 }
588 if (snd_device != SND_DEVICE_NONE) {
589 goto exit;
590 }
591 }
592
593 if (popcount(devices) == 2) {
594 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
595 AUDIO_DEVICE_OUT_SPEAKER)) {
596 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
597 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
598 AUDIO_DEVICE_OUT_SPEAKER)) {
599 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
600 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
601 AUDIO_DEVICE_OUT_SPEAKER)) {
602 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
603 } else {
604 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
605 goto exit;
606 }
607 if (snd_device != SND_DEVICE_NONE) {
608 goto exit;
609 }
610 }
611
612 if (popcount(devices) != 1) {
613 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
614 goto exit;
615 }
616
617 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
618 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
619 snd_device = SND_DEVICE_OUT_HEADPHONES;
620 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
621 if (adev->speaker_lr_swap)
622 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
623 else
624 snd_device = SND_DEVICE_OUT_SPEAKER;
625 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
626 snd_device = SND_DEVICE_OUT_BT_SCO;
627 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
628 snd_device = SND_DEVICE_OUT_HDMI ;
629 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
630 snd_device = SND_DEVICE_OUT_HANDSET;
631 } else {
632 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
633 }
634exit:
635 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
636 return snd_device;
637}
638
639snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
640{
641 struct platform_data *my_data = (struct platform_data *)platform;
642 struct audio_device *adev = my_data->adev;
643 audio_source_t source = (adev->active_input == NULL) ?
644 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
645
646 audio_mode_t mode = adev->mode;
647 audio_devices_t in_device = ((adev->active_input == NULL) ?
648 AUDIO_DEVICE_NONE : adev->active_input->device)
649 & ~AUDIO_DEVICE_BIT_IN;
650 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
651 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
652 snd_device_t snd_device = SND_DEVICE_NONE;
653
654 ALOGV("%s: enter: out_device(%#x) in_device(%#x)",
655 __func__, out_device, in_device);
656 if (mode == AUDIO_MODE_IN_CALL) {
657 if (out_device == AUDIO_DEVICE_NONE) {
658 ALOGE("%s: No output device set for voice call", __func__);
659 goto exit;
660 }
661 if (adev->tty_mode != TTY_MODE_OFF) {
662 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
663 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
664 switch (adev->tty_mode) {
665 case TTY_MODE_FULL:
666 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
667 break;
668 case TTY_MODE_VCO:
669 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
670 break;
671 case TTY_MODE_HCO:
672 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
673 break;
674 default:
675 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->tty_mode);
676 }
677 goto exit;
678 }
679 }
680 if (out_device & AUDIO_DEVICE_OUT_EARPIECE ||
681 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700682 if (my_data->fluence_type == FLUENCE_NONE ||
683 my_data->fluence_in_voice_call == false) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700684 snd_device = SND_DEVICE_IN_HANDSET_MIC;
685 } else {
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700686 if (is_operator_tmus())
687 snd_device = SND_DEVICE_IN_VOICE_DMIC_TMUS;
Eric Laurentb23d5282013-05-14 15:27:20 -0700688 else
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700689 snd_device = SND_DEVICE_IN_VOICE_DMIC;
690 adev->acdb_settings |= DMIC_FLAG;
Eric Laurentb23d5282013-05-14 15:27:20 -0700691 }
692 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
693 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
694 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
695 snd_device = SND_DEVICE_IN_BT_SCO_MIC ;
696 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700697 if (my_data->fluence_type != FLUENCE_NONE &&
698 my_data->fluence_in_voice_call &&
699 my_data->fluence_in_spkr_mode) {
700 if(my_data->fluence_type == FLUENCE_DUAL_MIC) {
701 adev->acdb_settings |= DMIC_FLAG;
702 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
703 } else {
704 adev->acdb_settings |= QMIC_FLAG;
705 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_QMIC;
706 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700707 } else {
708 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
709 }
710 }
711 } else if (source == AUDIO_SOURCE_CAMCORDER) {
712 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
713 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
714 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
715 }
716 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
717 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700718 if (channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK)
719 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC;
720 else if (my_data->fluence_in_voice_rec)
721 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700722
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700723 if (snd_device == SND_DEVICE_NONE)
Eric Laurentb23d5282013-05-14 15:27:20 -0700724 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700725 else
726 adev->acdb_settings |= DMIC_FLAG;
Eric Laurentb23d5282013-05-14 15:27:20 -0700727 }
728 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION) {
729 if (out_device & AUDIO_DEVICE_OUT_SPEAKER)
730 in_device = AUDIO_DEVICE_IN_BACK_MIC;
731 if (adev->active_input) {
732 if (adev->active_input->enable_aec) {
733 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
734 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
735 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
736 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
737 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
738 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
739 }
740 set_echo_reference(adev->mixer, "SLIM_RX");
741 } else
742 set_echo_reference(adev->mixer, "NONE");
743 }
744 } else if (source == AUDIO_SOURCE_DEFAULT) {
745 goto exit;
746 }
747
748
749 if (snd_device != SND_DEVICE_NONE) {
750 goto exit;
751 }
752
753 if (in_device != AUDIO_DEVICE_NONE &&
754 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
755 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
756 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
757 snd_device = SND_DEVICE_IN_HANDSET_MIC;
758 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
759 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
760 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
761 snd_device = SND_DEVICE_IN_HEADSET_MIC;
762 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
763 snd_device = SND_DEVICE_IN_BT_SCO_MIC ;
764 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
765 snd_device = SND_DEVICE_IN_HDMI_MIC;
766 } else {
767 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
768 ALOGW("%s: Using default handset-mic", __func__);
769 snd_device = SND_DEVICE_IN_HANDSET_MIC;
770 }
771 } else {
772 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
773 snd_device = SND_DEVICE_IN_HANDSET_MIC;
774 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
775 snd_device = SND_DEVICE_IN_HEADSET_MIC;
776 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
777 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
778 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
779 snd_device = SND_DEVICE_IN_HANDSET_MIC;
780 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
781 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
782 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
783 snd_device = SND_DEVICE_IN_HDMI_MIC;
784 } else {
785 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
786 ALOGW("%s: Using default handset-mic", __func__);
787 snd_device = SND_DEVICE_IN_HANDSET_MIC;
788 }
789 }
790exit:
791 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
792 return snd_device;
793}
794
795int platform_set_hdmi_channels(void *platform, int channel_count)
796{
797 struct platform_data *my_data = (struct platform_data *)platform;
798 struct audio_device *adev = my_data->adev;
799 struct mixer_ctl *ctl;
800 const char *channel_cnt_str = NULL;
801 const char *mixer_ctl_name = "HDMI_RX Channels";
802 switch (channel_count) {
803 case 8:
804 channel_cnt_str = "Eight"; break;
805 case 7:
806 channel_cnt_str = "Seven"; break;
807 case 6:
808 channel_cnt_str = "Six"; break;
809 case 5:
810 channel_cnt_str = "Five"; break;
811 case 4:
812 channel_cnt_str = "Four"; break;
813 case 3:
814 channel_cnt_str = "Three"; break;
815 default:
816 channel_cnt_str = "Two"; break;
817 }
818 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
819 if (!ctl) {
820 ALOGE("%s: Could not get ctl for mixer cmd - %s",
821 __func__, mixer_ctl_name);
822 return -EINVAL;
823 }
824 ALOGV("HDMI channel count: %s", channel_cnt_str);
825 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
826 return 0;
827}
828
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -0700829int platform_edid_get_max_channels(void *platform)
Eric Laurentb23d5282013-05-14 15:27:20 -0700830{
831 FILE *file;
832 struct audio_block_header header;
833 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
834 char *sad = block;
835 int num_audio_blocks;
836 int channel_count;
837 int max_channels = 0;
838 int i;
839
840 file = fopen(AUDIO_DATA_BLOCK_PATH, "rb");
841 if (file == NULL) {
842 ALOGE("Unable to open '%s'", AUDIO_DATA_BLOCK_PATH);
843 return 0;
844 }
845
846 /* Read audio block header */
847 fread(&header, 1, sizeof(header), file);
848
849 /* Read SAD blocks, clamping the maximum size for safety */
850 if (header.length > (int)sizeof(block))
851 header.length = (int)sizeof(block);
852 fread(&block, header.length, 1, file);
853
854 fclose(file);
855
856 /* Calculate the number of SAD blocks */
857 num_audio_blocks = header.length / SAD_BLOCK_SIZE;
858
859 for (i = 0; i < num_audio_blocks; i++) {
860 /* Only consider LPCM blocks */
861 if ((sad[0] >> 3) != EDID_FORMAT_LPCM)
862 continue;
863
864 channel_count = (sad[0] & 0x7) + 1;
865 if (channel_count > max_channels)
866 max_channels = channel_count;
867
868 /* Advance to next block */
869 sad += 3;
870 }
871
872 return max_channels;
873}
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700874
875void platform_get_parameters(void *platform, struct str_parms *query,
876 struct str_parms *reply)
877{
878 LOGE("%s: Not implemented", __func__);
879}
880
881int platform_set_parameters(void *platform, struct str_parms *parms)
882{
883 LOGE("%s: Not implemented", __func__);
884 return -ENOSYS;
885}
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700886
887int platform_set_incall_recoding_session_id(void *platform, uint32_t session_id)
888{
889 LOGE("%s: Not implemented", __func__);
890 return -ENOSYS;
891}