blob: ed1a7818c08d7f96f50aeb5d3a7fbcc1646bd06c [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 Romberger61764e32014-01-10 13:49:02 -0800394int platform_get_snd_device_index(char *snd_device_index_name)
395{
396 return -ENODEV;
397}
398
Ben Romberger55886882014-01-10 13:49:02 -0800399int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
400{
401 return -ENODEV;
402}
403
Eric Laurentb23d5282013-05-14 15:27:20 -0700404int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
405{
406 struct platform_data *my_data = (struct platform_data *)platform;
407 int acdb_dev_id, acdb_dev_type;
408
409 acdb_dev_id = acdb_device_table[snd_device];
410 if (acdb_dev_id < 0) {
411 ALOGE("%s: Could not find acdb id for device(%d)",
412 __func__, snd_device);
413 return -EINVAL;
414 }
415 if (my_data->acdb_send_audio_cal) {
Eric Laurent994a6932013-07-17 11:51:42 -0700416 ("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Eric Laurentb23d5282013-05-14 15:27:20 -0700417 __func__, snd_device, acdb_dev_id);
418 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
419 snd_device < SND_DEVICE_OUT_END)
420 acdb_dev_type = ACDB_DEV_TYPE_OUT;
421 else
422 acdb_dev_type = ACDB_DEV_TYPE_IN;
423 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
424 }
425 return 0;
426}
427
428int platform_switch_voice_call_device_pre(void *platform)
429{
430 struct platform_data *my_data = (struct platform_data *)platform;
431 int ret = 0;
432
433 if (my_data->csd_client != NULL) {
434 /* This must be called before disabling the mixer controls on APQ side */
435 if (my_data->csd_disable_device == NULL) {
436 ALOGE("%s: dlsym error for csd_disable_device", __func__);
437 } else {
438 ret = my_data->csd_disable_device();
439 if (ret < 0) {
440 ALOGE("%s: csd_client_disable_device, failed, error %d",
441 __func__, ret);
442 }
443 }
444 }
445 return ret;
446}
447
448int platform_switch_voice_call_device_post(void *platform,
449 snd_device_t out_snd_device,
450 snd_device_t in_snd_device)
451{
452 struct platform_data *my_data = (struct platform_data *)platform;
453 int acdb_rx_id, acdb_tx_id;
454 int ret = 0;
455
456 if (my_data->csd_client) {
457 if (my_data->csd_enable_device == NULL) {
458 ALOGE("%s: dlsym error for csd_enable_device",
459 __func__);
460 } else {
461 acdb_rx_id = acdb_device_table[out_snd_device];
462 acdb_tx_id = acdb_device_table[in_snd_device];
463
464 if (acdb_rx_id > 0 || acdb_tx_id > 0) {
465 ret = my_data->csd_enable_device(acdb_rx_id, acdb_tx_id,
466 my_data->adev->acdb_settings);
467 if (ret < 0) {
468 ALOGE("%s: csd_enable_device, failed, error %d",
469 __func__, ret);
470 }
471 } else {
472 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
473 acdb_rx_id, acdb_tx_id);
474 }
475 }
476 }
477
478 return ret;
479}
480
481int platform_start_voice_call(void *platform)
482{
483 struct platform_data *my_data = (struct platform_data *)platform;
484 int ret = 0;
485
486 if (my_data->csd_client) {
487 if (my_data->csd_start_voice == NULL) {
488 ALOGE("dlsym error for csd_client_start_voice");
489 ret = -ENOSYS;
490 } else {
491 ret = my_data->csd_start_voice();
492 if (ret < 0) {
493 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
494 }
495 }
496 }
497
498 return ret;
499}
500
501int platform_stop_voice_call(void *platform)
502{
503 struct platform_data *my_data = (struct platform_data *)platform;
504 int ret = 0;
505
506 if (my_data->csd_client) {
507 if (my_data->csd_stop_voice == NULL) {
508 ALOGE("dlsym error for csd_stop_voice");
509 } else {
510 ret = my_data->csd_stop_voice();
511 if (ret < 0) {
512 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
513 }
514 }
515 }
516
517 return ret;
518}
519
520int platform_set_voice_volume(void *platform, int volume)
521{
522 struct platform_data *my_data = (struct platform_data *)platform;
523 int ret = 0;
524
525 if (my_data->csd_client) {
526 if (my_data->csd_volume == NULL) {
527 ALOGE("%s: dlsym error for csd_volume", __func__);
528 } else {
529 ret = my_data->csd_volume(volume);
530 if (ret < 0) {
531 ALOGE("%s: csd_volume error %d", __func__, ret);
532 }
533 }
534 } else {
535 ALOGE("%s: No CSD Client present", __func__);
536 }
537
538 return ret;
539}
540
541int platform_set_mic_mute(void *platform, bool state)
542{
543 struct platform_data *my_data = (struct platform_data *)platform;
544 int ret = 0;
545
546 if (my_data->adev->mode == AUDIO_MODE_IN_CALL) {
547 if (my_data->csd_client) {
548 if (my_data->csd_mic_mute == NULL) {
549 ALOGE("%s: dlsym error for csd_mic_mute", __func__);
550 } else {
551 ret = my_data->csd_mic_mute(state);
552 if (ret < 0) {
553 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
554 }
555 }
556 } else {
557 ALOGE("%s: No CSD Client present", __func__);
558 }
559 }
560
561 return ret;
562}
563
Shiv Maliyappanahallic6fd8ee2014-03-07 15:31:55 -0800564int platform_set_device_mute(void *platform, bool state, char *dir)
565{
566 LOGE("%s: Not implemented", __func__);
567 return -ENOSYS;
568}
569
Eric Laurentb23d5282013-05-14 15:27:20 -0700570snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
571{
572 struct platform_data *my_data = (struct platform_data *)platform;
573 struct audio_device *adev = my_data->adev;
574 audio_mode_t mode = adev->mode;
575 snd_device_t snd_device = SND_DEVICE_NONE;
576
577 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
578 if (devices == AUDIO_DEVICE_NONE ||
579 devices & AUDIO_DEVICE_BIT_IN) {
580 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
581 goto exit;
582 }
583
584 if (mode == AUDIO_MODE_IN_CALL) {
585 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
586 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
587 if (adev->tty_mode == TTY_MODE_FULL)
588 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
589 else if (adev->tty_mode == TTY_MODE_VCO)
590 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
591 else if (adev->tty_mode == TTY_MODE_HCO)
592 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
593 else
594 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
595 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
596 snd_device = SND_DEVICE_OUT_BT_SCO;
597 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
598 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
599 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Ravi Kumar Alamandaceb40822013-11-06 11:01:47 -0800600 snd_device = SND_DEVICE_OUT_HANDSET;
Eric Laurentb23d5282013-05-14 15:27:20 -0700601 }
602 if (snd_device != SND_DEVICE_NONE) {
603 goto exit;
604 }
605 }
606
607 if (popcount(devices) == 2) {
608 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
609 AUDIO_DEVICE_OUT_SPEAKER)) {
610 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
611 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
612 AUDIO_DEVICE_OUT_SPEAKER)) {
613 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
614 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
615 AUDIO_DEVICE_OUT_SPEAKER)) {
616 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
617 } else {
618 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
619 goto exit;
620 }
621 if (snd_device != SND_DEVICE_NONE) {
622 goto exit;
623 }
624 }
625
626 if (popcount(devices) != 1) {
627 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
628 goto exit;
629 }
630
631 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
632 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
633 snd_device = SND_DEVICE_OUT_HEADPHONES;
634 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
635 if (adev->speaker_lr_swap)
636 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
637 else
638 snd_device = SND_DEVICE_OUT_SPEAKER;
639 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
640 snd_device = SND_DEVICE_OUT_BT_SCO;
641 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
642 snd_device = SND_DEVICE_OUT_HDMI ;
643 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
644 snd_device = SND_DEVICE_OUT_HANDSET;
645 } else {
646 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
647 }
648exit:
649 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
650 return snd_device;
651}
652
653snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
654{
655 struct platform_data *my_data = (struct platform_data *)platform;
656 struct audio_device *adev = my_data->adev;
657 audio_source_t source = (adev->active_input == NULL) ?
658 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
659
660 audio_mode_t mode = adev->mode;
661 audio_devices_t in_device = ((adev->active_input == NULL) ?
662 AUDIO_DEVICE_NONE : adev->active_input->device)
663 & ~AUDIO_DEVICE_BIT_IN;
664 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
665 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
666 snd_device_t snd_device = SND_DEVICE_NONE;
667
668 ALOGV("%s: enter: out_device(%#x) in_device(%#x)",
669 __func__, out_device, in_device);
670 if (mode == AUDIO_MODE_IN_CALL) {
671 if (out_device == AUDIO_DEVICE_NONE) {
672 ALOGE("%s: No output device set for voice call", __func__);
673 goto exit;
674 }
675 if (adev->tty_mode != TTY_MODE_OFF) {
676 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
677 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
678 switch (adev->tty_mode) {
679 case TTY_MODE_FULL:
680 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
681 break;
682 case TTY_MODE_VCO:
683 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
684 break;
685 case TTY_MODE_HCO:
686 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
687 break;
688 default:
689 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->tty_mode);
690 }
691 goto exit;
692 }
693 }
694 if (out_device & AUDIO_DEVICE_OUT_EARPIECE ||
695 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700696 if (my_data->fluence_type == FLUENCE_NONE ||
697 my_data->fluence_in_voice_call == false) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700698 snd_device = SND_DEVICE_IN_HANDSET_MIC;
699 } else {
Ravi Kumar Alamandaceb40822013-11-06 11:01:47 -0800700 snd_device = SND_DEVICE_IN_VOICE_DMIC;
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700701 adev->acdb_settings |= DMIC_FLAG;
Eric Laurentb23d5282013-05-14 15:27:20 -0700702 }
703 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
704 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
705 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
706 snd_device = SND_DEVICE_IN_BT_SCO_MIC ;
707 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700708 if (my_data->fluence_type != FLUENCE_NONE &&
709 my_data->fluence_in_voice_call &&
710 my_data->fluence_in_spkr_mode) {
711 if(my_data->fluence_type == FLUENCE_DUAL_MIC) {
712 adev->acdb_settings |= DMIC_FLAG;
713 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
714 } else {
715 adev->acdb_settings |= QMIC_FLAG;
716 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_QMIC;
717 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700718 } else {
719 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
720 }
721 }
722 } else if (source == AUDIO_SOURCE_CAMCORDER) {
723 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
724 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
725 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
726 }
727 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
728 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700729 if (channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK)
730 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC;
731 else if (my_data->fluence_in_voice_rec)
732 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700733
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700734 if (snd_device == SND_DEVICE_NONE)
Eric Laurentb23d5282013-05-14 15:27:20 -0700735 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700736 else
737 adev->acdb_settings |= DMIC_FLAG;
Eric Laurentb23d5282013-05-14 15:27:20 -0700738 }
739 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION) {
740 if (out_device & AUDIO_DEVICE_OUT_SPEAKER)
741 in_device = AUDIO_DEVICE_IN_BACK_MIC;
742 if (adev->active_input) {
743 if (adev->active_input->enable_aec) {
744 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
745 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
746 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
747 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
748 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
749 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
750 }
751 set_echo_reference(adev->mixer, "SLIM_RX");
752 } else
753 set_echo_reference(adev->mixer, "NONE");
754 }
755 } else if (source == AUDIO_SOURCE_DEFAULT) {
756 goto exit;
757 }
758
759
760 if (snd_device != SND_DEVICE_NONE) {
761 goto exit;
762 }
763
764 if (in_device != AUDIO_DEVICE_NONE &&
765 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
766 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
767 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
768 snd_device = SND_DEVICE_IN_HANDSET_MIC;
769 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
770 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
771 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
772 snd_device = SND_DEVICE_IN_HEADSET_MIC;
773 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
774 snd_device = SND_DEVICE_IN_BT_SCO_MIC ;
775 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
776 snd_device = SND_DEVICE_IN_HDMI_MIC;
777 } else {
778 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
779 ALOGW("%s: Using default handset-mic", __func__);
780 snd_device = SND_DEVICE_IN_HANDSET_MIC;
781 }
782 } else {
783 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
784 snd_device = SND_DEVICE_IN_HANDSET_MIC;
785 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
786 snd_device = SND_DEVICE_IN_HEADSET_MIC;
787 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
788 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
789 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
790 snd_device = SND_DEVICE_IN_HANDSET_MIC;
791 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
792 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
793 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
794 snd_device = SND_DEVICE_IN_HDMI_MIC;
795 } else {
796 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
797 ALOGW("%s: Using default handset-mic", __func__);
798 snd_device = SND_DEVICE_IN_HANDSET_MIC;
799 }
800 }
801exit:
802 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
803 return snd_device;
804}
805
806int platform_set_hdmi_channels(void *platform, int channel_count)
807{
808 struct platform_data *my_data = (struct platform_data *)platform;
809 struct audio_device *adev = my_data->adev;
810 struct mixer_ctl *ctl;
811 const char *channel_cnt_str = NULL;
812 const char *mixer_ctl_name = "HDMI_RX Channels";
813 switch (channel_count) {
814 case 8:
815 channel_cnt_str = "Eight"; break;
816 case 7:
817 channel_cnt_str = "Seven"; break;
818 case 6:
819 channel_cnt_str = "Six"; break;
820 case 5:
821 channel_cnt_str = "Five"; break;
822 case 4:
823 channel_cnt_str = "Four"; break;
824 case 3:
825 channel_cnt_str = "Three"; break;
826 default:
827 channel_cnt_str = "Two"; break;
828 }
829 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
830 if (!ctl) {
831 ALOGE("%s: Could not get ctl for mixer cmd - %s",
832 __func__, mixer_ctl_name);
833 return -EINVAL;
834 }
835 ALOGV("HDMI channel count: %s", channel_cnt_str);
836 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
837 return 0;
838}
839
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -0700840int platform_edid_get_max_channels(void *platform)
Eric Laurentb23d5282013-05-14 15:27:20 -0700841{
842 FILE *file;
843 struct audio_block_header header;
844 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
845 char *sad = block;
846 int num_audio_blocks;
847 int channel_count;
848 int max_channels = 0;
849 int i;
850
851 file = fopen(AUDIO_DATA_BLOCK_PATH, "rb");
852 if (file == NULL) {
853 ALOGE("Unable to open '%s'", AUDIO_DATA_BLOCK_PATH);
854 return 0;
855 }
856
857 /* Read audio block header */
858 fread(&header, 1, sizeof(header), file);
859
860 /* Read SAD blocks, clamping the maximum size for safety */
861 if (header.length > (int)sizeof(block))
862 header.length = (int)sizeof(block);
863 fread(&block, header.length, 1, file);
864
865 fclose(file);
866
867 /* Calculate the number of SAD blocks */
868 num_audio_blocks = header.length / SAD_BLOCK_SIZE;
869
870 for (i = 0; i < num_audio_blocks; i++) {
871 /* Only consider LPCM blocks */
872 if ((sad[0] >> 3) != EDID_FORMAT_LPCM)
873 continue;
874
875 channel_count = (sad[0] & 0x7) + 1;
876 if (channel_count > max_channels)
877 max_channels = channel_count;
878
879 /* Advance to next block */
880 sad += 3;
881 }
882
883 return max_channels;
884}
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700885
886void platform_get_parameters(void *platform, struct str_parms *query,
887 struct str_parms *reply)
888{
889 LOGE("%s: Not implemented", __func__);
890}
891
892int platform_set_parameters(void *platform, struct str_parms *parms)
893{
894 LOGE("%s: Not implemented", __func__);
895 return -ENOSYS;
896}
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700897
898int platform_set_incall_recoding_session_id(void *platform, uint32_t session_id)
899{
900 LOGE("%s: Not implemented", __func__);
901 return -ENOSYS;
902}
Shruthi Krishnaace10852013-10-25 14:32:12 -0700903
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700904/* Delay in Us */
905int64_t platform_render_latency(audio_usecase_t usecase)
906{
907 switch (usecase) {
908 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
909 return DEEP_BUFFER_PLATFORM_DELAY;
910 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
911 return LOW_LATENCY_PLATFORM_DELAY;
912 default:
913 return 0;
914 }
915}
Mingming Yine62d7842013-10-25 16:26:03 -0700916
917int platform_update_usecase_from_source(int source, int usecase)
918{
919 ALOGV("%s: input source :%d", __func__, source);
920 return usecase;
921}
Kiran Kandide144c82013-11-20 15:58:32 -0800922
923bool platform_listen_update_status(snd_device_t snd_device)
924{
925 return false;
926}