blob: 54bda5a7f3bd781a575c6ca4a910559930296a13 [file] [log] [blame]
Eric Laurentb23d5282013-05-14 15:27:20 -07001/*
Ben Romberger55886882014-01-10 13:49:02 -08002 * Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07003 * 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
Ben Romberger55886882014-01-10 13:49:02 -0800394int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
395{
396 return -ENODEV;
397}
398
Eric Laurentb23d5282013-05-14 15:27:20 -0700399int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
400{
401 struct platform_data *my_data = (struct platform_data *)platform;
402 int acdb_dev_id, acdb_dev_type;
403
404 acdb_dev_id = acdb_device_table[snd_device];
405 if (acdb_dev_id < 0) {
406 ALOGE("%s: Could not find acdb id for device(%d)",
407 __func__, snd_device);
408 return -EINVAL;
409 }
410 if (my_data->acdb_send_audio_cal) {
Eric Laurent994a6932013-07-17 11:51:42 -0700411 ("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Eric Laurentb23d5282013-05-14 15:27:20 -0700412 __func__, snd_device, acdb_dev_id);
413 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
414 snd_device < SND_DEVICE_OUT_END)
415 acdb_dev_type = ACDB_DEV_TYPE_OUT;
416 else
417 acdb_dev_type = ACDB_DEV_TYPE_IN;
418 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
419 }
420 return 0;
421}
422
423int platform_switch_voice_call_device_pre(void *platform)
424{
425 struct platform_data *my_data = (struct platform_data *)platform;
426 int ret = 0;
427
428 if (my_data->csd_client != NULL) {
429 /* This must be called before disabling the mixer controls on APQ side */
430 if (my_data->csd_disable_device == NULL) {
431 ALOGE("%s: dlsym error for csd_disable_device", __func__);
432 } else {
433 ret = my_data->csd_disable_device();
434 if (ret < 0) {
435 ALOGE("%s: csd_client_disable_device, failed, error %d",
436 __func__, ret);
437 }
438 }
439 }
440 return ret;
441}
442
443int platform_switch_voice_call_device_post(void *platform,
444 snd_device_t out_snd_device,
445 snd_device_t in_snd_device)
446{
447 struct platform_data *my_data = (struct platform_data *)platform;
448 int acdb_rx_id, acdb_tx_id;
449 int ret = 0;
450
451 if (my_data->csd_client) {
452 if (my_data->csd_enable_device == NULL) {
453 ALOGE("%s: dlsym error for csd_enable_device",
454 __func__);
455 } else {
456 acdb_rx_id = acdb_device_table[out_snd_device];
457 acdb_tx_id = acdb_device_table[in_snd_device];
458
459 if (acdb_rx_id > 0 || acdb_tx_id > 0) {
460 ret = my_data->csd_enable_device(acdb_rx_id, acdb_tx_id,
461 my_data->adev->acdb_settings);
462 if (ret < 0) {
463 ALOGE("%s: csd_enable_device, failed, error %d",
464 __func__, ret);
465 }
466 } else {
467 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
468 acdb_rx_id, acdb_tx_id);
469 }
470 }
471 }
472
473 return ret;
474}
475
476int platform_start_voice_call(void *platform)
477{
478 struct platform_data *my_data = (struct platform_data *)platform;
479 int ret = 0;
480
481 if (my_data->csd_client) {
482 if (my_data->csd_start_voice == NULL) {
483 ALOGE("dlsym error for csd_client_start_voice");
484 ret = -ENOSYS;
485 } else {
486 ret = my_data->csd_start_voice();
487 if (ret < 0) {
488 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
489 }
490 }
491 }
492
493 return ret;
494}
495
496int platform_stop_voice_call(void *platform)
497{
498 struct platform_data *my_data = (struct platform_data *)platform;
499 int ret = 0;
500
501 if (my_data->csd_client) {
502 if (my_data->csd_stop_voice == NULL) {
503 ALOGE("dlsym error for csd_stop_voice");
504 } else {
505 ret = my_data->csd_stop_voice();
506 if (ret < 0) {
507 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
508 }
509 }
510 }
511
512 return ret;
513}
514
515int platform_set_voice_volume(void *platform, int volume)
516{
517 struct platform_data *my_data = (struct platform_data *)platform;
518 int ret = 0;
519
520 if (my_data->csd_client) {
521 if (my_data->csd_volume == NULL) {
522 ALOGE("%s: dlsym error for csd_volume", __func__);
523 } else {
524 ret = my_data->csd_volume(volume);
525 if (ret < 0) {
526 ALOGE("%s: csd_volume error %d", __func__, ret);
527 }
528 }
529 } else {
530 ALOGE("%s: No CSD Client present", __func__);
531 }
532
533 return ret;
534}
535
536int platform_set_mic_mute(void *platform, bool state)
537{
538 struct platform_data *my_data = (struct platform_data *)platform;
539 int ret = 0;
540
541 if (my_data->adev->mode == AUDIO_MODE_IN_CALL) {
542 if (my_data->csd_client) {
543 if (my_data->csd_mic_mute == NULL) {
544 ALOGE("%s: dlsym error for csd_mic_mute", __func__);
545 } else {
546 ret = my_data->csd_mic_mute(state);
547 if (ret < 0) {
548 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
549 }
550 }
551 } else {
552 ALOGE("%s: No CSD Client present", __func__);
553 }
554 }
555
556 return ret;
557}
558
559snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
560{
561 struct platform_data *my_data = (struct platform_data *)platform;
562 struct audio_device *adev = my_data->adev;
563 audio_mode_t mode = adev->mode;
564 snd_device_t snd_device = SND_DEVICE_NONE;
565
566 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
567 if (devices == AUDIO_DEVICE_NONE ||
568 devices & AUDIO_DEVICE_BIT_IN) {
569 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
570 goto exit;
571 }
572
573 if (mode == AUDIO_MODE_IN_CALL) {
574 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
575 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
576 if (adev->tty_mode == TTY_MODE_FULL)
577 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
578 else if (adev->tty_mode == TTY_MODE_VCO)
579 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
580 else if (adev->tty_mode == TTY_MODE_HCO)
581 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
582 else
583 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
584 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
585 snd_device = SND_DEVICE_OUT_BT_SCO;
586 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
587 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
588 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Ravi Kumar Alamandaceb40822013-11-06 11:01:47 -0800589 snd_device = SND_DEVICE_OUT_HANDSET;
Eric Laurentb23d5282013-05-14 15:27:20 -0700590 }
591 if (snd_device != SND_DEVICE_NONE) {
592 goto exit;
593 }
594 }
595
596 if (popcount(devices) == 2) {
597 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
598 AUDIO_DEVICE_OUT_SPEAKER)) {
599 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
600 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
601 AUDIO_DEVICE_OUT_SPEAKER)) {
602 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
603 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
604 AUDIO_DEVICE_OUT_SPEAKER)) {
605 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
606 } else {
607 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
608 goto exit;
609 }
610 if (snd_device != SND_DEVICE_NONE) {
611 goto exit;
612 }
613 }
614
615 if (popcount(devices) != 1) {
616 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
617 goto exit;
618 }
619
620 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
621 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
622 snd_device = SND_DEVICE_OUT_HEADPHONES;
623 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
624 if (adev->speaker_lr_swap)
625 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
626 else
627 snd_device = SND_DEVICE_OUT_SPEAKER;
628 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
629 snd_device = SND_DEVICE_OUT_BT_SCO;
630 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
631 snd_device = SND_DEVICE_OUT_HDMI ;
632 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
633 snd_device = SND_DEVICE_OUT_HANDSET;
634 } else {
635 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
636 }
637exit:
638 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
639 return snd_device;
640}
641
642snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
643{
644 struct platform_data *my_data = (struct platform_data *)platform;
645 struct audio_device *adev = my_data->adev;
646 audio_source_t source = (adev->active_input == NULL) ?
647 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
648
649 audio_mode_t mode = adev->mode;
650 audio_devices_t in_device = ((adev->active_input == NULL) ?
651 AUDIO_DEVICE_NONE : adev->active_input->device)
652 & ~AUDIO_DEVICE_BIT_IN;
653 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
654 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
655 snd_device_t snd_device = SND_DEVICE_NONE;
656
657 ALOGV("%s: enter: out_device(%#x) in_device(%#x)",
658 __func__, out_device, in_device);
659 if (mode == AUDIO_MODE_IN_CALL) {
660 if (out_device == AUDIO_DEVICE_NONE) {
661 ALOGE("%s: No output device set for voice call", __func__);
662 goto exit;
663 }
664 if (adev->tty_mode != TTY_MODE_OFF) {
665 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
666 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
667 switch (adev->tty_mode) {
668 case TTY_MODE_FULL:
669 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
670 break;
671 case TTY_MODE_VCO:
672 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
673 break;
674 case TTY_MODE_HCO:
675 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
676 break;
677 default:
678 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->tty_mode);
679 }
680 goto exit;
681 }
682 }
683 if (out_device & AUDIO_DEVICE_OUT_EARPIECE ||
684 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700685 if (my_data->fluence_type == FLUENCE_NONE ||
686 my_data->fluence_in_voice_call == false) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700687 snd_device = SND_DEVICE_IN_HANDSET_MIC;
688 } else {
Ravi Kumar Alamandaceb40822013-11-06 11:01:47 -0800689 snd_device = SND_DEVICE_IN_VOICE_DMIC;
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700690 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}
Shruthi Krishnaace10852013-10-25 14:32:12 -0700892
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700893/* Delay in Us */
894int64_t platform_render_latency(audio_usecase_t usecase)
895{
896 switch (usecase) {
897 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
898 return DEEP_BUFFER_PLATFORM_DELAY;
899 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
900 return LOW_LATENCY_PLATFORM_DELAY;
901 default:
902 return 0;
903 }
904}
Mingming Yine62d7842013-10-25 16:26:03 -0700905
906int platform_update_usecase_from_source(int source, int usecase)
907{
908 ALOGV("%s: input source :%d", __func__, source);
909 return usecase;
910}
Kiran Kandide144c82013-11-20 15:58:32 -0800911
912bool platform_listen_update_status(snd_device_t snd_device)
913{
914 return false;
915}