blob: 43bef8146b7f28df868bfd53653b55aec5eaca14 [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
Eric Laurentb23d5282013-05-14 15:27:20 -070076struct platform_data {
77 struct audio_device *adev;
78 bool fluence_in_spkr_mode;
79 bool fluence_in_voice_call;
80 bool fluence_in_voice_rec;
Mingming Yin8e5a4f62013-10-07 15:23:41 -070081 int fluence_type;
Eric Laurentb23d5282013-05-14 15:27:20 -070082 int dualmic_config;
83
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -070084 void *hw_info;
85
86 /* Audio calibration related functions */
Eric Laurentb23d5282013-05-14 15:27:20 -070087 void *acdb_handle;
88 acdb_init_t acdb_init;
89 acdb_deallocate_t acdb_deallocate;
90 acdb_send_audio_cal_t acdb_send_audio_cal;
91 acdb_send_voice_cal_t acdb_send_voice_cal;
92
93 /* CSD Client related functions for voice call */
94 void *csd_client;
95 csd_client_init_t csd_client_init;
96 csd_client_deinit_t csd_client_deinit;
97 csd_disable_device_t csd_disable_device;
98 csd_enable_device_t csd_enable_device;
99 csd_volume_t csd_volume;
100 csd_mic_mute_t csd_mic_mute;
101 csd_start_voice_t csd_start_voice;
102 csd_stop_voice_t csd_stop_voice;
103};
104
105static const int pcm_device_table[AUDIO_USECASE_MAX][2] = {
106 [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = {0, 0},
107 [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = {14, 14},
108 [USECASE_AUDIO_PLAYBACK_MULTI_CH] = {1, 1},
109 [USECASE_AUDIO_RECORD] = {0, 0},
110 [USECASE_AUDIO_RECORD_LOW_LATENCY] = {14, 14},
111 [USECASE_VOICE_CALL] = {12, 12},
112};
113
114/* Array to store sound devices */
115static const char * const device_table[SND_DEVICE_MAX] = {
116 [SND_DEVICE_NONE] = "none",
117 /* Playback sound devices */
118 [SND_DEVICE_OUT_HANDSET] = "handset",
119 [SND_DEVICE_OUT_SPEAKER] = "speaker",
120 [SND_DEVICE_OUT_SPEAKER_REVERSE] = "speaker-reverse",
121 [SND_DEVICE_OUT_HEADPHONES] = "headphones",
122 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones",
123 [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker",
124 [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones",
125 [SND_DEVICE_OUT_HDMI] = "hdmi",
126 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi",
127 [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset",
Eric Laurentb23d5282013-05-14 15:27:20 -0700128 [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",
143 [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic",
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700144 [SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef",
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700145 [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,
Eric Laurentb23d5282013-05-14 15:27:20 -0700167 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
168 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
169 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
170
171 [SND_DEVICE_IN_HANDSET_MIC] = 4,
172 [SND_DEVICE_IN_SPEAKER_MIC] = 4,
173 [SND_DEVICE_IN_HEADSET_MIC] = 8,
174 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 40,
175 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 42,
176 [SND_DEVICE_IN_HEADSET_MIC_AEC] = 47,
177 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
178 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = 8,
179 [SND_DEVICE_IN_HDMI_MIC] = 4,
180 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
181 [SND_DEVICE_IN_CAMCORDER_MIC] = 61,
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700182 [SND_DEVICE_IN_VOICE_DMIC] = 6,
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700183 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 13,
Eric Laurentb23d5282013-05-14 15:27:20 -0700184 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
185 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
186 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
187 [SND_DEVICE_IN_VOICE_REC_MIC] = 62,
188 /* TODO: Update with proper acdb ids */
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700189 [SND_DEVICE_IN_VOICE_REC_DMIC] = 62,
190 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 6,
Eric Laurentb23d5282013-05-14 15:27:20 -0700191};
192
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700193#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
194#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
195
Eric Laurentb23d5282013-05-14 15:27:20 -0700196static int set_echo_reference(struct mixer *mixer, const char* ec_ref)
197{
198 struct mixer_ctl *ctl;
199 const char *mixer_ctl_name = "EC_REF_RX";
200
201 ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name);
202 if (!ctl) {
203 ALOGE("%s: Could not get ctl for mixer cmd - %s",
204 __func__, mixer_ctl_name);
205 return -EINVAL;
206 }
207 ALOGV("Setting EC Reference: %s", ec_ref);
208 mixer_ctl_set_enum_by_string(ctl, ec_ref);
209 return 0;
210}
211
212void *platform_init(struct audio_device *adev)
213{
214 char platform[PROPERTY_VALUE_MAX];
215 char baseband[PROPERTY_VALUE_MAX];
216 char value[PROPERTY_VALUE_MAX];
217 struct platform_data *my_data;
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -0700218 const char *snd_card_name;
Eric Laurentb23d5282013-05-14 15:27:20 -0700219
sangwoo1b9f4b32013-06-21 18:22:55 -0700220 adev->mixer = mixer_open(MIXER_CARD);
221
222 if (!adev->mixer) {
223 ALOGE("Unable to open the mixer, aborting.");
224 return NULL;
225 }
226
227 adev->audio_route = audio_route_init(MIXER_CARD, MIXER_XML_PATH);
228 if (!adev->audio_route) {
229 ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
230 return NULL;
231 }
232
Eric Laurentb23d5282013-05-14 15:27:20 -0700233 my_data = calloc(1, sizeof(struct platform_data));
234
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -0700235 snd_card_name = mixer_get_name(adev->mixer);
236 my_data->hw_info = hw_info_init(snd_card_name);
237 if (!my_data->hw_info) {
238 ALOGE("%s: Failed to init hardware info", __func__);
239 }
240
Eric Laurentb23d5282013-05-14 15:27:20 -0700241 my_data->adev = adev;
Eric Laurentb23d5282013-05-14 15:27:20 -0700242 my_data->fluence_in_spkr_mode = false;
243 my_data->fluence_in_voice_call = false;
244 my_data->fluence_in_voice_rec = false;
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700245 my_data->fluence_type = FLUENCE_NONE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700246
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700247 property_get("ro.qc.sdk.audio.fluencetype", value, "");
248 if (!strncmp("fluencepro", value, sizeof("fluencepro"))) {
249 my_data->fluence_type = FLUENCE_QUAD_MIC;
250 } else if (!strncmp("fluence", value, sizeof("fluence"))) {
251 my_data->fluence_type = FLUENCE_DUAL_MIC;
252 } else {
253 my_data->fluence_type = FLUENCE_NONE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700254 }
255
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700256 if (my_data->fluence_type != FLUENCE_NONE) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700257 property_get("persist.audio.fluence.voicecall",value,"");
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700258 if (!strncmp("true", value, sizeof("true"))) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700259 my_data->fluence_in_voice_call = true;
260 }
261
262 property_get("persist.audio.fluence.voicerec",value,"");
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700263 if (!strncmp("true", value, sizeof("true"))) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700264 my_data->fluence_in_voice_rec = true;
265 }
266
267 property_get("persist.audio.fluence.speaker",value,"");
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700268 if (!strncmp("true", value, sizeof("true"))) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700269 my_data->fluence_in_spkr_mode = true;
270 }
271 }
272
273 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
274 if (my_data->acdb_handle == NULL) {
275 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
276 } else {
277 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
278 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
279 "acdb_loader_deallocate_ACDB");
280 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
281 "acdb_loader_send_audio_cal");
282 if (!my_data->acdb_send_audio_cal)
283 ALOGW("%s: Could not find the symbol acdb_send_audio_cal from %s",
284 __func__, LIB_ACDB_LOADER);
285 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
286 "acdb_loader_send_voice_cal");
287 my_data->acdb_init = (acdb_init_t)dlsym(my_data->acdb_handle,
288 "acdb_loader_init_ACDB");
289 if (my_data->acdb_init == NULL)
290 ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__, dlerror());
291 else
292 my_data->acdb_init();
293 }
294
295 /* If platform is Fusion3, load CSD Client specific symbols
296 * Voice call is handled by MDM and apps processor talks to
297 * MDM through CSD Client
298 */
299 property_get("ro.board.platform", platform, "");
300 property_get("ro.baseband", baseband, "");
301 if (!strcmp("msm8960", platform) && !strcmp("mdm", baseband)) {
302 my_data->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
303 if (my_data->csd_client == NULL)
304 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
305 }
306
307 if (my_data->csd_client) {
308 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
309 my_data->csd_client_deinit = (csd_client_deinit_t)dlsym(my_data->csd_client,
310 "csd_client_deinit");
311 my_data->csd_disable_device = (csd_disable_device_t)dlsym(my_data->csd_client,
312 "csd_client_disable_device");
313 my_data->csd_enable_device = (csd_enable_device_t)dlsym(my_data->csd_client,
314 "csd_client_enable_device");
315 my_data->csd_start_voice = (csd_start_voice_t)dlsym(my_data->csd_client,
316 "csd_client_start_voice");
317 my_data->csd_stop_voice = (csd_stop_voice_t)dlsym(my_data->csd_client,
318 "csd_client_stop_voice");
319 my_data->csd_volume = (csd_volume_t)dlsym(my_data->csd_client,
320 "csd_client_volume");
321 my_data->csd_mic_mute = (csd_mic_mute_t)dlsym(my_data->csd_client,
322 "csd_client_mic_mute");
323 my_data->csd_client_init = (csd_client_init_t)dlsym(my_data->csd_client,
324 "csd_client_init");
325
326 if (my_data->csd_client_init == NULL) {
327 ALOGE("%s: dlsym error %s for csd_client_init", __func__, dlerror());
328 } else {
329 my_data->csd_client_init();
330 }
331 }
332
333 return my_data;
334}
335
336void platform_deinit(void *platform)
337{
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -0700338 struct platform_data *my_data = (struct platform_data *)platform;
339
340 hw_info_deinit(my_data->hw_info);
Eric Laurentb23d5282013-05-14 15:27:20 -0700341 free(platform);
342}
343
344const char *platform_get_snd_device_name(snd_device_t snd_device)
345{
346 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX)
347 return device_table[snd_device];
348 else
349 return "";
350}
351
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -0700352int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
353 char *device_name)
354{
355 struct platform_data *my_data = (struct platform_data *)platform;
356
357 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
358 strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE);
359 hw_info_append_hw_type(my_data->hw_info, snd_device, device_name);
360 } else {
361 strlcpy(device_name, "", DEVICE_NAME_MAX_SIZE);
362 return -EINVAL;
363 }
364
365 return 0;
366}
367
Eric Laurentb23d5282013-05-14 15:27:20 -0700368void platform_add_backend_name(char *mixer_path, snd_device_t snd_device)
369{
370 if (snd_device == SND_DEVICE_IN_BT_SCO_MIC)
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700371 strlcat(mixer_path, " bt-sco", MIXER_PATH_MAX_LENGTH);
372 else if (snd_device == SND_DEVICE_IN_BT_SCO_MIC_WB)
373 strlcat(mixer_path, " bt-sco-wb", MIXER_PATH_MAX_LENGTH);
Eric Laurentb23d5282013-05-14 15:27:20 -0700374 else if(snd_device == SND_DEVICE_OUT_BT_SCO)
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700375 strlcat(mixer_path, " bt-sco", MIXER_PATH_MAX_LENGTH);
376 else if(snd_device == SND_DEVICE_OUT_BT_SCO_WB)
377 strlcat(mixer_path, " bt-sco-wb", MIXER_PATH_MAX_LENGTH);
Eric Laurentb23d5282013-05-14 15:27:20 -0700378 else if (snd_device == SND_DEVICE_OUT_HDMI)
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700379 strlcat(mixer_path, " hdmi", MIXER_PATH_MAX_LENGTH);
Eric Laurentb23d5282013-05-14 15:27:20 -0700380 else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HDMI)
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700381 strlcat(mixer_path, " speaker-and-hdmi", MIXER_PATH_MAX_LENGTH);
Eric Laurentb23d5282013-05-14 15:27:20 -0700382}
383
384int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
385{
386 int device_id;
387 if (device_type == PCM_PLAYBACK)
388 device_id = pcm_device_table[usecase][0];
389 else
390 device_id = pcm_device_table[usecase][1];
391 return device_id;
392}
393
394int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
395{
396 struct platform_data *my_data = (struct platform_data *)platform;
397 int acdb_dev_id, acdb_dev_type;
398
399 acdb_dev_id = acdb_device_table[snd_device];
400 if (acdb_dev_id < 0) {
401 ALOGE("%s: Could not find acdb id for device(%d)",
402 __func__, snd_device);
403 return -EINVAL;
404 }
405 if (my_data->acdb_send_audio_cal) {
Eric Laurent994a6932013-07-17 11:51:42 -0700406 ("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Eric Laurentb23d5282013-05-14 15:27:20 -0700407 __func__, snd_device, acdb_dev_id);
408 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
409 snd_device < SND_DEVICE_OUT_END)
410 acdb_dev_type = ACDB_DEV_TYPE_OUT;
411 else
412 acdb_dev_type = ACDB_DEV_TYPE_IN;
413 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
414 }
415 return 0;
416}
417
418int platform_switch_voice_call_device_pre(void *platform)
419{
420 struct platform_data *my_data = (struct platform_data *)platform;
421 int ret = 0;
422
423 if (my_data->csd_client != NULL) {
424 /* This must be called before disabling the mixer controls on APQ side */
425 if (my_data->csd_disable_device == NULL) {
426 ALOGE("%s: dlsym error for csd_disable_device", __func__);
427 } else {
428 ret = my_data->csd_disable_device();
429 if (ret < 0) {
430 ALOGE("%s: csd_client_disable_device, failed, error %d",
431 __func__, ret);
432 }
433 }
434 }
435 return ret;
436}
437
438int platform_switch_voice_call_device_post(void *platform,
439 snd_device_t out_snd_device,
440 snd_device_t in_snd_device)
441{
442 struct platform_data *my_data = (struct platform_data *)platform;
443 int acdb_rx_id, acdb_tx_id;
444 int ret = 0;
445
446 if (my_data->csd_client) {
447 if (my_data->csd_enable_device == NULL) {
448 ALOGE("%s: dlsym error for csd_enable_device",
449 __func__);
450 } else {
451 acdb_rx_id = acdb_device_table[out_snd_device];
452 acdb_tx_id = acdb_device_table[in_snd_device];
453
454 if (acdb_rx_id > 0 || acdb_tx_id > 0) {
455 ret = my_data->csd_enable_device(acdb_rx_id, acdb_tx_id,
456 my_data->adev->acdb_settings);
457 if (ret < 0) {
458 ALOGE("%s: csd_enable_device, failed, error %d",
459 __func__, ret);
460 }
461 } else {
462 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
463 acdb_rx_id, acdb_tx_id);
464 }
465 }
466 }
467
468 return ret;
469}
470
471int platform_start_voice_call(void *platform)
472{
473 struct platform_data *my_data = (struct platform_data *)platform;
474 int ret = 0;
475
476 if (my_data->csd_client) {
477 if (my_data->csd_start_voice == NULL) {
478 ALOGE("dlsym error for csd_client_start_voice");
479 ret = -ENOSYS;
480 } else {
481 ret = my_data->csd_start_voice();
482 if (ret < 0) {
483 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
484 }
485 }
486 }
487
488 return ret;
489}
490
491int platform_stop_voice_call(void *platform)
492{
493 struct platform_data *my_data = (struct platform_data *)platform;
494 int ret = 0;
495
496 if (my_data->csd_client) {
497 if (my_data->csd_stop_voice == NULL) {
498 ALOGE("dlsym error for csd_stop_voice");
499 } else {
500 ret = my_data->csd_stop_voice();
501 if (ret < 0) {
502 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
503 }
504 }
505 }
506
507 return ret;
508}
509
510int platform_set_voice_volume(void *platform, int volume)
511{
512 struct platform_data *my_data = (struct platform_data *)platform;
513 int ret = 0;
514
515 if (my_data->csd_client) {
516 if (my_data->csd_volume == NULL) {
517 ALOGE("%s: dlsym error for csd_volume", __func__);
518 } else {
519 ret = my_data->csd_volume(volume);
520 if (ret < 0) {
521 ALOGE("%s: csd_volume error %d", __func__, ret);
522 }
523 }
524 } else {
525 ALOGE("%s: No CSD Client present", __func__);
526 }
527
528 return ret;
529}
530
531int platform_set_mic_mute(void *platform, bool state)
532{
533 struct platform_data *my_data = (struct platform_data *)platform;
534 int ret = 0;
535
536 if (my_data->adev->mode == AUDIO_MODE_IN_CALL) {
537 if (my_data->csd_client) {
538 if (my_data->csd_mic_mute == NULL) {
539 ALOGE("%s: dlsym error for csd_mic_mute", __func__);
540 } else {
541 ret = my_data->csd_mic_mute(state);
542 if (ret < 0) {
543 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
544 }
545 }
546 } else {
547 ALOGE("%s: No CSD Client present", __func__);
548 }
549 }
550
551 return ret;
552}
553
554snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
555{
556 struct platform_data *my_data = (struct platform_data *)platform;
557 struct audio_device *adev = my_data->adev;
558 audio_mode_t mode = adev->mode;
559 snd_device_t snd_device = SND_DEVICE_NONE;
560
561 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
562 if (devices == AUDIO_DEVICE_NONE ||
563 devices & AUDIO_DEVICE_BIT_IN) {
564 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
565 goto exit;
566 }
567
568 if (mode == AUDIO_MODE_IN_CALL) {
569 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
570 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
571 if (adev->tty_mode == TTY_MODE_FULL)
572 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
573 else if (adev->tty_mode == TTY_MODE_VCO)
574 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
575 else if (adev->tty_mode == TTY_MODE_HCO)
576 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
577 else
578 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
579 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
580 snd_device = SND_DEVICE_OUT_BT_SCO;
581 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
582 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
583 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Ravi Kumar Alamandaceb40822013-11-06 11:01:47 -0800584 snd_device = SND_DEVICE_OUT_HANDSET;
Eric Laurentb23d5282013-05-14 15:27:20 -0700585 }
586 if (snd_device != SND_DEVICE_NONE) {
587 goto exit;
588 }
589 }
590
591 if (popcount(devices) == 2) {
592 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
593 AUDIO_DEVICE_OUT_SPEAKER)) {
594 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
595 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
596 AUDIO_DEVICE_OUT_SPEAKER)) {
597 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
598 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
599 AUDIO_DEVICE_OUT_SPEAKER)) {
600 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
601 } else {
602 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
603 goto exit;
604 }
605 if (snd_device != SND_DEVICE_NONE) {
606 goto exit;
607 }
608 }
609
610 if (popcount(devices) != 1) {
611 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
612 goto exit;
613 }
614
615 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
616 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
617 snd_device = SND_DEVICE_OUT_HEADPHONES;
618 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
619 if (adev->speaker_lr_swap)
620 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
621 else
622 snd_device = SND_DEVICE_OUT_SPEAKER;
623 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
624 snd_device = SND_DEVICE_OUT_BT_SCO;
625 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
626 snd_device = SND_DEVICE_OUT_HDMI ;
627 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
628 snd_device = SND_DEVICE_OUT_HANDSET;
629 } else {
630 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
631 }
632exit:
633 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
634 return snd_device;
635}
636
637snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
638{
639 struct platform_data *my_data = (struct platform_data *)platform;
640 struct audio_device *adev = my_data->adev;
641 audio_source_t source = (adev->active_input == NULL) ?
642 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
643
644 audio_mode_t mode = adev->mode;
645 audio_devices_t in_device = ((adev->active_input == NULL) ?
646 AUDIO_DEVICE_NONE : adev->active_input->device)
647 & ~AUDIO_DEVICE_BIT_IN;
648 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
649 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
650 snd_device_t snd_device = SND_DEVICE_NONE;
651
652 ALOGV("%s: enter: out_device(%#x) in_device(%#x)",
653 __func__, out_device, in_device);
654 if (mode == AUDIO_MODE_IN_CALL) {
655 if (out_device == AUDIO_DEVICE_NONE) {
656 ALOGE("%s: No output device set for voice call", __func__);
657 goto exit;
658 }
659 if (adev->tty_mode != TTY_MODE_OFF) {
660 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
661 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
662 switch (adev->tty_mode) {
663 case TTY_MODE_FULL:
664 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
665 break;
666 case TTY_MODE_VCO:
667 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
668 break;
669 case TTY_MODE_HCO:
670 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
671 break;
672 default:
673 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->tty_mode);
674 }
675 goto exit;
676 }
677 }
678 if (out_device & AUDIO_DEVICE_OUT_EARPIECE ||
679 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700680 if (my_data->fluence_type == FLUENCE_NONE ||
681 my_data->fluence_in_voice_call == false) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700682 snd_device = SND_DEVICE_IN_HANDSET_MIC;
683 } else {
Ravi Kumar Alamandaceb40822013-11-06 11:01:47 -0800684 snd_device = SND_DEVICE_IN_VOICE_DMIC;
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700685 adev->acdb_settings |= DMIC_FLAG;
Eric Laurentb23d5282013-05-14 15:27:20 -0700686 }
687 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
688 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
689 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
690 snd_device = SND_DEVICE_IN_BT_SCO_MIC ;
691 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700692 if (my_data->fluence_type != FLUENCE_NONE &&
693 my_data->fluence_in_voice_call &&
694 my_data->fluence_in_spkr_mode) {
695 if(my_data->fluence_type == FLUENCE_DUAL_MIC) {
696 adev->acdb_settings |= DMIC_FLAG;
697 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
698 } else {
699 adev->acdb_settings |= QMIC_FLAG;
700 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_QMIC;
701 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700702 } else {
703 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
704 }
705 }
706 } else if (source == AUDIO_SOURCE_CAMCORDER) {
707 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
708 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
709 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
710 }
711 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
712 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700713 if (channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK)
714 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC;
715 else if (my_data->fluence_in_voice_rec)
716 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700717
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700718 if (snd_device == SND_DEVICE_NONE)
Eric Laurentb23d5282013-05-14 15:27:20 -0700719 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700720 else
721 adev->acdb_settings |= DMIC_FLAG;
Eric Laurentb23d5282013-05-14 15:27:20 -0700722 }
723 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION) {
724 if (out_device & AUDIO_DEVICE_OUT_SPEAKER)
725 in_device = AUDIO_DEVICE_IN_BACK_MIC;
726 if (adev->active_input) {
727 if (adev->active_input->enable_aec) {
728 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
729 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
730 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
731 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
732 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
733 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
734 }
735 set_echo_reference(adev->mixer, "SLIM_RX");
736 } else
737 set_echo_reference(adev->mixer, "NONE");
738 }
739 } else if (source == AUDIO_SOURCE_DEFAULT) {
740 goto exit;
741 }
742
743
744 if (snd_device != SND_DEVICE_NONE) {
745 goto exit;
746 }
747
748 if (in_device != AUDIO_DEVICE_NONE &&
749 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
750 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
751 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
752 snd_device = SND_DEVICE_IN_HANDSET_MIC;
753 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
754 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
755 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
756 snd_device = SND_DEVICE_IN_HEADSET_MIC;
757 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
758 snd_device = SND_DEVICE_IN_BT_SCO_MIC ;
759 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
760 snd_device = SND_DEVICE_IN_HDMI_MIC;
761 } else {
762 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
763 ALOGW("%s: Using default handset-mic", __func__);
764 snd_device = SND_DEVICE_IN_HANDSET_MIC;
765 }
766 } else {
767 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
768 snd_device = SND_DEVICE_IN_HANDSET_MIC;
769 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
770 snd_device = SND_DEVICE_IN_HEADSET_MIC;
771 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
772 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
773 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
774 snd_device = SND_DEVICE_IN_HANDSET_MIC;
775 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
776 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
777 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
778 snd_device = SND_DEVICE_IN_HDMI_MIC;
779 } else {
780 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
781 ALOGW("%s: Using default handset-mic", __func__);
782 snd_device = SND_DEVICE_IN_HANDSET_MIC;
783 }
784 }
785exit:
786 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
787 return snd_device;
788}
789
790int platform_set_hdmi_channels(void *platform, int channel_count)
791{
792 struct platform_data *my_data = (struct platform_data *)platform;
793 struct audio_device *adev = my_data->adev;
794 struct mixer_ctl *ctl;
795 const char *channel_cnt_str = NULL;
796 const char *mixer_ctl_name = "HDMI_RX Channels";
797 switch (channel_count) {
798 case 8:
799 channel_cnt_str = "Eight"; break;
800 case 7:
801 channel_cnt_str = "Seven"; break;
802 case 6:
803 channel_cnt_str = "Six"; break;
804 case 5:
805 channel_cnt_str = "Five"; break;
806 case 4:
807 channel_cnt_str = "Four"; break;
808 case 3:
809 channel_cnt_str = "Three"; break;
810 default:
811 channel_cnt_str = "Two"; break;
812 }
813 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
814 if (!ctl) {
815 ALOGE("%s: Could not get ctl for mixer cmd - %s",
816 __func__, mixer_ctl_name);
817 return -EINVAL;
818 }
819 ALOGV("HDMI channel count: %s", channel_cnt_str);
820 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
821 return 0;
822}
823
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -0700824int platform_edid_get_max_channels(void *platform)
Eric Laurentb23d5282013-05-14 15:27:20 -0700825{
826 FILE *file;
827 struct audio_block_header header;
828 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
829 char *sad = block;
830 int num_audio_blocks;
831 int channel_count;
832 int max_channels = 0;
833 int i;
834
835 file = fopen(AUDIO_DATA_BLOCK_PATH, "rb");
836 if (file == NULL) {
837 ALOGE("Unable to open '%s'", AUDIO_DATA_BLOCK_PATH);
838 return 0;
839 }
840
841 /* Read audio block header */
842 fread(&header, 1, sizeof(header), file);
843
844 /* Read SAD blocks, clamping the maximum size for safety */
845 if (header.length > (int)sizeof(block))
846 header.length = (int)sizeof(block);
847 fread(&block, header.length, 1, file);
848
849 fclose(file);
850
851 /* Calculate the number of SAD blocks */
852 num_audio_blocks = header.length / SAD_BLOCK_SIZE;
853
854 for (i = 0; i < num_audio_blocks; i++) {
855 /* Only consider LPCM blocks */
856 if ((sad[0] >> 3) != EDID_FORMAT_LPCM)
857 continue;
858
859 channel_count = (sad[0] & 0x7) + 1;
860 if (channel_count > max_channels)
861 max_channels = channel_count;
862
863 /* Advance to next block */
864 sad += 3;
865 }
866
867 return max_channels;
868}
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700869
870void platform_get_parameters(void *platform, struct str_parms *query,
871 struct str_parms *reply)
872{
873 LOGE("%s: Not implemented", __func__);
874}
875
876int platform_set_parameters(void *platform, struct str_parms *parms)
877{
878 LOGE("%s: Not implemented", __func__);
879 return -ENOSYS;
880}
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700881
882int platform_set_incall_recoding_session_id(void *platform, uint32_t session_id)
883{
884 LOGE("%s: Not implemented", __func__);
885 return -ENOSYS;
886}
Shruthi Krishnaace10852013-10-25 14:32:12 -0700887
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700888/* Delay in Us */
889int64_t platform_render_latency(audio_usecase_t usecase)
890{
891 switch (usecase) {
892 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
893 return DEEP_BUFFER_PLATFORM_DELAY;
894 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
895 return LOW_LATENCY_PLATFORM_DELAY;
896 default:
897 return 0;
898 }
899}
Mingming Yine62d7842013-10-25 16:26:03 -0700900
901int platform_update_usecase_from_source(int source, int usecase)
902{
903 ALOGV("%s: input source :%d", __func__, source);
904 return usecase;
905}