blob: 70e0b9e72c55ca9498f123d204209a807709f5d6 [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
Anish Kumar4980fa12014-04-17 12:42:20 -0700196static void set_echo_reference(struct audio_device *adev, bool enable)
Eric Laurentb23d5282013-05-14 15:27:20 -0700197{
Anish Kumar4980fa12014-04-17 12:42:20 -0700198 if (enable)
199 audio_route_apply_and_update_path(adev->audio_route, "echo-reference");
200 else
201 audio_route_reset_and_update_path(adev->audio_route, "echo-reference");
Eric Laurentb23d5282013-05-14 15:27:20 -0700202
Anish Kumar4980fa12014-04-17 12:42:20 -0700203 ALOGV("Setting EC Reference: %d", enable);
Eric Laurentb23d5282013-05-14 15:27:20 -0700204}
205
206void *platform_init(struct audio_device *adev)
207{
208 char platform[PROPERTY_VALUE_MAX];
209 char baseband[PROPERTY_VALUE_MAX];
210 char value[PROPERTY_VALUE_MAX];
211 struct platform_data *my_data;
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -0700212 const char *snd_card_name;
Eric Laurentb23d5282013-05-14 15:27:20 -0700213
sangwoo1b9f4b32013-06-21 18:22:55 -0700214 adev->mixer = mixer_open(MIXER_CARD);
215
216 if (!adev->mixer) {
217 ALOGE("Unable to open the mixer, aborting.");
218 return NULL;
219 }
220
221 adev->audio_route = audio_route_init(MIXER_CARD, MIXER_XML_PATH);
222 if (!adev->audio_route) {
223 ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
224 return NULL;
225 }
226
Eric Laurentb23d5282013-05-14 15:27:20 -0700227 my_data = calloc(1, sizeof(struct platform_data));
228
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -0700229 snd_card_name = mixer_get_name(adev->mixer);
230 my_data->hw_info = hw_info_init(snd_card_name);
231 if (!my_data->hw_info) {
232 ALOGE("%s: Failed to init hardware info", __func__);
233 }
234
Eric Laurentb23d5282013-05-14 15:27:20 -0700235 my_data->adev = adev;
Eric Laurentb23d5282013-05-14 15:27:20 -0700236 my_data->fluence_in_spkr_mode = false;
237 my_data->fluence_in_voice_call = false;
238 my_data->fluence_in_voice_rec = false;
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700239 my_data->fluence_type = FLUENCE_NONE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700240
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700241 property_get("ro.qc.sdk.audio.fluencetype", value, "");
242 if (!strncmp("fluencepro", value, sizeof("fluencepro"))) {
243 my_data->fluence_type = FLUENCE_QUAD_MIC;
244 } else if (!strncmp("fluence", value, sizeof("fluence"))) {
245 my_data->fluence_type = FLUENCE_DUAL_MIC;
246 } else {
247 my_data->fluence_type = FLUENCE_NONE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700248 }
249
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700250 if (my_data->fluence_type != FLUENCE_NONE) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700251 property_get("persist.audio.fluence.voicecall",value,"");
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700252 if (!strncmp("true", value, sizeof("true"))) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700253 my_data->fluence_in_voice_call = true;
254 }
255
256 property_get("persist.audio.fluence.voicerec",value,"");
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700257 if (!strncmp("true", value, sizeof("true"))) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700258 my_data->fluence_in_voice_rec = true;
259 }
260
261 property_get("persist.audio.fluence.speaker",value,"");
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700262 if (!strncmp("true", value, sizeof("true"))) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700263 my_data->fluence_in_spkr_mode = true;
264 }
265 }
266
267 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
268 if (my_data->acdb_handle == NULL) {
269 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
270 } else {
271 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
272 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
273 "acdb_loader_deallocate_ACDB");
274 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
275 "acdb_loader_send_audio_cal");
276 if (!my_data->acdb_send_audio_cal)
277 ALOGW("%s: Could not find the symbol acdb_send_audio_cal from %s",
278 __func__, LIB_ACDB_LOADER);
279 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
280 "acdb_loader_send_voice_cal");
281 my_data->acdb_init = (acdb_init_t)dlsym(my_data->acdb_handle,
282 "acdb_loader_init_ACDB");
283 if (my_data->acdb_init == NULL)
284 ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__, dlerror());
285 else
286 my_data->acdb_init();
287 }
288
289 /* If platform is Fusion3, load CSD Client specific symbols
290 * Voice call is handled by MDM and apps processor talks to
291 * MDM through CSD Client
292 */
293 property_get("ro.board.platform", platform, "");
294 property_get("ro.baseband", baseband, "");
295 if (!strcmp("msm8960", platform) && !strcmp("mdm", baseband)) {
296 my_data->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
297 if (my_data->csd_client == NULL)
298 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
299 }
300
301 if (my_data->csd_client) {
302 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
303 my_data->csd_client_deinit = (csd_client_deinit_t)dlsym(my_data->csd_client,
304 "csd_client_deinit");
305 my_data->csd_disable_device = (csd_disable_device_t)dlsym(my_data->csd_client,
306 "csd_client_disable_device");
307 my_data->csd_enable_device = (csd_enable_device_t)dlsym(my_data->csd_client,
308 "csd_client_enable_device");
309 my_data->csd_start_voice = (csd_start_voice_t)dlsym(my_data->csd_client,
310 "csd_client_start_voice");
311 my_data->csd_stop_voice = (csd_stop_voice_t)dlsym(my_data->csd_client,
312 "csd_client_stop_voice");
313 my_data->csd_volume = (csd_volume_t)dlsym(my_data->csd_client,
314 "csd_client_volume");
315 my_data->csd_mic_mute = (csd_mic_mute_t)dlsym(my_data->csd_client,
316 "csd_client_mic_mute");
317 my_data->csd_client_init = (csd_client_init_t)dlsym(my_data->csd_client,
318 "csd_client_init");
319
320 if (my_data->csd_client_init == NULL) {
321 ALOGE("%s: dlsym error %s for csd_client_init", __func__, dlerror());
322 } else {
323 my_data->csd_client_init();
324 }
325 }
326
327 return my_data;
328}
329
330void platform_deinit(void *platform)
331{
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -0700332 struct platform_data *my_data = (struct platform_data *)platform;
333
334 hw_info_deinit(my_data->hw_info);
Eric Laurentb23d5282013-05-14 15:27:20 -0700335 free(platform);
336}
337
338const char *platform_get_snd_device_name(snd_device_t snd_device)
339{
340 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX)
341 return device_table[snd_device];
342 else
343 return "";
344}
345
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -0700346int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
347 char *device_name)
348{
349 struct platform_data *my_data = (struct platform_data *)platform;
350
351 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
352 strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE);
353 hw_info_append_hw_type(my_data->hw_info, snd_device, device_name);
354 } else {
355 strlcpy(device_name, "", DEVICE_NAME_MAX_SIZE);
356 return -EINVAL;
357 }
358
359 return 0;
360}
361
Eric Laurentb23d5282013-05-14 15:27:20 -0700362void platform_add_backend_name(char *mixer_path, snd_device_t snd_device)
363{
364 if (snd_device == SND_DEVICE_IN_BT_SCO_MIC)
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700365 strlcat(mixer_path, " bt-sco", MIXER_PATH_MAX_LENGTH);
366 else if (snd_device == SND_DEVICE_IN_BT_SCO_MIC_WB)
367 strlcat(mixer_path, " bt-sco-wb", MIXER_PATH_MAX_LENGTH);
Eric Laurentb23d5282013-05-14 15:27:20 -0700368 else if(snd_device == SND_DEVICE_OUT_BT_SCO)
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700369 strlcat(mixer_path, " bt-sco", MIXER_PATH_MAX_LENGTH);
370 else if(snd_device == SND_DEVICE_OUT_BT_SCO_WB)
371 strlcat(mixer_path, " bt-sco-wb", MIXER_PATH_MAX_LENGTH);
Eric Laurentb23d5282013-05-14 15:27:20 -0700372 else if (snd_device == SND_DEVICE_OUT_HDMI)
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700373 strlcat(mixer_path, " hdmi", MIXER_PATH_MAX_LENGTH);
Eric Laurentb23d5282013-05-14 15:27:20 -0700374 else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HDMI)
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700375 strlcat(mixer_path, " speaker-and-hdmi", MIXER_PATH_MAX_LENGTH);
Eric Laurentb23d5282013-05-14 15:27:20 -0700376}
377
378int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
379{
380 int device_id;
381 if (device_type == PCM_PLAYBACK)
382 device_id = pcm_device_table[usecase][0];
383 else
384 device_id = pcm_device_table[usecase][1];
385 return device_id;
386}
387
Ben Romberger61764e32014-01-10 13:49:02 -0800388int platform_get_snd_device_index(char *snd_device_index_name)
389{
390 return -ENODEV;
391}
392
Ben Romberger55886882014-01-10 13:49:02 -0800393int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
394{
395 return -ENODEV;
396}
397
Eric Laurentb23d5282013-05-14 15:27:20 -0700398int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
399{
400 struct platform_data *my_data = (struct platform_data *)platform;
401 int acdb_dev_id, acdb_dev_type;
402
403 acdb_dev_id = acdb_device_table[snd_device];
404 if (acdb_dev_id < 0) {
405 ALOGE("%s: Could not find acdb id for device(%d)",
406 __func__, snd_device);
407 return -EINVAL;
408 }
409 if (my_data->acdb_send_audio_cal) {
Eric Laurent994a6932013-07-17 11:51:42 -0700410 ("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Eric Laurentb23d5282013-05-14 15:27:20 -0700411 __func__, snd_device, acdb_dev_id);
412 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
413 snd_device < SND_DEVICE_OUT_END)
414 acdb_dev_type = ACDB_DEV_TYPE_OUT;
415 else
416 acdb_dev_type = ACDB_DEV_TYPE_IN;
417 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
418 }
419 return 0;
420}
421
422int platform_switch_voice_call_device_pre(void *platform)
423{
424 struct platform_data *my_data = (struct platform_data *)platform;
425 int ret = 0;
426
427 if (my_data->csd_client != NULL) {
428 /* This must be called before disabling the mixer controls on APQ side */
429 if (my_data->csd_disable_device == NULL) {
430 ALOGE("%s: dlsym error for csd_disable_device", __func__);
431 } else {
432 ret = my_data->csd_disable_device();
433 if (ret < 0) {
434 ALOGE("%s: csd_client_disable_device, failed, error %d",
435 __func__, ret);
436 }
437 }
438 }
439 return ret;
440}
441
442int platform_switch_voice_call_device_post(void *platform,
443 snd_device_t out_snd_device,
444 snd_device_t in_snd_device)
445{
446 struct platform_data *my_data = (struct platform_data *)platform;
447 int acdb_rx_id, acdb_tx_id;
448 int ret = 0;
449
450 if (my_data->csd_client) {
451 if (my_data->csd_enable_device == NULL) {
452 ALOGE("%s: dlsym error for csd_enable_device",
453 __func__);
454 } else {
455 acdb_rx_id = acdb_device_table[out_snd_device];
456 acdb_tx_id = acdb_device_table[in_snd_device];
457
458 if (acdb_rx_id > 0 || acdb_tx_id > 0) {
459 ret = my_data->csd_enable_device(acdb_rx_id, acdb_tx_id,
460 my_data->adev->acdb_settings);
461 if (ret < 0) {
462 ALOGE("%s: csd_enable_device, failed, error %d",
463 __func__, ret);
464 }
465 } else {
466 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
467 acdb_rx_id, acdb_tx_id);
468 }
469 }
470 }
471
472 return ret;
473}
474
475int platform_start_voice_call(void *platform)
476{
477 struct platform_data *my_data = (struct platform_data *)platform;
478 int ret = 0;
479
480 if (my_data->csd_client) {
481 if (my_data->csd_start_voice == NULL) {
482 ALOGE("dlsym error for csd_client_start_voice");
483 ret = -ENOSYS;
484 } else {
485 ret = my_data->csd_start_voice();
486 if (ret < 0) {
487 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
488 }
489 }
490 }
491
492 return ret;
493}
494
495int platform_stop_voice_call(void *platform)
496{
497 struct platform_data *my_data = (struct platform_data *)platform;
498 int ret = 0;
499
500 if (my_data->csd_client) {
501 if (my_data->csd_stop_voice == NULL) {
502 ALOGE("dlsym error for csd_stop_voice");
503 } else {
504 ret = my_data->csd_stop_voice();
505 if (ret < 0) {
506 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
507 }
508 }
509 }
510
511 return ret;
512}
513
514int platform_set_voice_volume(void *platform, int volume)
515{
516 struct platform_data *my_data = (struct platform_data *)platform;
517 int ret = 0;
518
519 if (my_data->csd_client) {
520 if (my_data->csd_volume == NULL) {
521 ALOGE("%s: dlsym error for csd_volume", __func__);
522 } else {
523 ret = my_data->csd_volume(volume);
524 if (ret < 0) {
525 ALOGE("%s: csd_volume error %d", __func__, ret);
526 }
527 }
528 } else {
529 ALOGE("%s: No CSD Client present", __func__);
530 }
531
532 return ret;
533}
534
535int platform_set_mic_mute(void *platform, bool state)
536{
537 struct platform_data *my_data = (struct platform_data *)platform;
538 int ret = 0;
539
540 if (my_data->adev->mode == AUDIO_MODE_IN_CALL) {
541 if (my_data->csd_client) {
542 if (my_data->csd_mic_mute == NULL) {
543 ALOGE("%s: dlsym error for csd_mic_mute", __func__);
544 } else {
545 ret = my_data->csd_mic_mute(state);
546 if (ret < 0) {
547 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
548 }
549 }
550 } else {
551 ALOGE("%s: No CSD Client present", __func__);
552 }
553 }
554
555 return ret;
556}
557
Shiv Maliyappanahallic6fd8ee2014-03-07 15:31:55 -0800558int platform_set_device_mute(void *platform, bool state, char *dir)
559{
560 LOGE("%s: Not implemented", __func__);
561 return -ENOSYS;
562}
563
Eric Laurentb23d5282013-05-14 15:27:20 -0700564snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
565{
566 struct platform_data *my_data = (struct platform_data *)platform;
567 struct audio_device *adev = my_data->adev;
568 audio_mode_t mode = adev->mode;
569 snd_device_t snd_device = SND_DEVICE_NONE;
570
571 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
572 if (devices == AUDIO_DEVICE_NONE ||
573 devices & AUDIO_DEVICE_BIT_IN) {
574 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
575 goto exit;
576 }
577
578 if (mode == AUDIO_MODE_IN_CALL) {
579 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
580 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
581 if (adev->tty_mode == TTY_MODE_FULL)
582 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
583 else if (adev->tty_mode == TTY_MODE_VCO)
584 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
585 else if (adev->tty_mode == TTY_MODE_HCO)
586 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
587 else
588 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
589 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
590 snd_device = SND_DEVICE_OUT_BT_SCO;
591 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
592 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
593 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Ravi Kumar Alamandaceb40822013-11-06 11:01:47 -0800594 snd_device = SND_DEVICE_OUT_HANDSET;
Eric Laurentb23d5282013-05-14 15:27:20 -0700595 }
596 if (snd_device != SND_DEVICE_NONE) {
597 goto exit;
598 }
599 }
600
601 if (popcount(devices) == 2) {
602 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
603 AUDIO_DEVICE_OUT_SPEAKER)) {
604 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
605 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
606 AUDIO_DEVICE_OUT_SPEAKER)) {
607 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
608 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
609 AUDIO_DEVICE_OUT_SPEAKER)) {
610 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
611 } else {
612 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
613 goto exit;
614 }
615 if (snd_device != SND_DEVICE_NONE) {
616 goto exit;
617 }
618 }
619
620 if (popcount(devices) != 1) {
621 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
622 goto exit;
623 }
624
625 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
626 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
627 snd_device = SND_DEVICE_OUT_HEADPHONES;
628 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
629 if (adev->speaker_lr_swap)
630 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
631 else
632 snd_device = SND_DEVICE_OUT_SPEAKER;
633 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
634 snd_device = SND_DEVICE_OUT_BT_SCO;
635 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
636 snd_device = SND_DEVICE_OUT_HDMI ;
637 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
638 snd_device = SND_DEVICE_OUT_HANDSET;
639 } else {
640 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
641 }
642exit:
643 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
644 return snd_device;
645}
646
647snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
648{
649 struct platform_data *my_data = (struct platform_data *)platform;
650 struct audio_device *adev = my_data->adev;
651 audio_source_t source = (adev->active_input == NULL) ?
652 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
653
654 audio_mode_t mode = adev->mode;
655 audio_devices_t in_device = ((adev->active_input == NULL) ?
656 AUDIO_DEVICE_NONE : adev->active_input->device)
657 & ~AUDIO_DEVICE_BIT_IN;
658 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
659 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
660 snd_device_t snd_device = SND_DEVICE_NONE;
661
662 ALOGV("%s: enter: out_device(%#x) in_device(%#x)",
663 __func__, out_device, in_device);
664 if (mode == AUDIO_MODE_IN_CALL) {
665 if (out_device == AUDIO_DEVICE_NONE) {
666 ALOGE("%s: No output device set for voice call", __func__);
667 goto exit;
668 }
669 if (adev->tty_mode != TTY_MODE_OFF) {
670 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
671 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
672 switch (adev->tty_mode) {
673 case TTY_MODE_FULL:
674 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
675 break;
676 case TTY_MODE_VCO:
677 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
678 break;
679 case TTY_MODE_HCO:
680 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
681 break;
682 default:
683 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->tty_mode);
684 }
685 goto exit;
686 }
687 }
688 if (out_device & AUDIO_DEVICE_OUT_EARPIECE ||
689 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700690 if (my_data->fluence_type == FLUENCE_NONE ||
691 my_data->fluence_in_voice_call == false) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700692 snd_device = SND_DEVICE_IN_HANDSET_MIC;
693 } else {
Ravi Kumar Alamandaceb40822013-11-06 11:01:47 -0800694 snd_device = SND_DEVICE_IN_VOICE_DMIC;
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700695 adev->acdb_settings |= DMIC_FLAG;
Eric Laurentb23d5282013-05-14 15:27:20 -0700696 }
697 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
698 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
699 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
700 snd_device = SND_DEVICE_IN_BT_SCO_MIC ;
701 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700702 if (my_data->fluence_type != FLUENCE_NONE &&
703 my_data->fluence_in_voice_call &&
704 my_data->fluence_in_spkr_mode) {
705 if(my_data->fluence_type == FLUENCE_DUAL_MIC) {
706 adev->acdb_settings |= DMIC_FLAG;
707 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
708 } else {
709 adev->acdb_settings |= QMIC_FLAG;
710 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_QMIC;
711 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700712 } else {
713 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
714 }
715 }
716 } else if (source == AUDIO_SOURCE_CAMCORDER) {
717 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
718 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
719 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
720 }
721 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
722 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700723 if (channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK)
724 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC;
725 else if (my_data->fluence_in_voice_rec)
726 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700727
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700728 if (snd_device == SND_DEVICE_NONE)
Eric Laurentb23d5282013-05-14 15:27:20 -0700729 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700730 else
731 adev->acdb_settings |= DMIC_FLAG;
Eric Laurentb23d5282013-05-14 15:27:20 -0700732 }
733 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION) {
734 if (out_device & AUDIO_DEVICE_OUT_SPEAKER)
735 in_device = AUDIO_DEVICE_IN_BACK_MIC;
736 if (adev->active_input) {
737 if (adev->active_input->enable_aec) {
738 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
739 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
740 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
741 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
742 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
743 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
744 }
Anish Kumar4980fa12014-04-17 12:42:20 -0700745 set_echo_reference(adev, true);
Eric Laurentb23d5282013-05-14 15:27:20 -0700746 } else
Anish Kumar4980fa12014-04-17 12:42:20 -0700747 set_echo_reference(adev, false);
Eric Laurentb23d5282013-05-14 15:27:20 -0700748 }
749 } else if (source == AUDIO_SOURCE_DEFAULT) {
750 goto exit;
751 }
752
753
754 if (snd_device != SND_DEVICE_NONE) {
755 goto exit;
756 }
757
758 if (in_device != AUDIO_DEVICE_NONE &&
759 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
760 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
761 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
762 snd_device = SND_DEVICE_IN_HANDSET_MIC;
763 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
764 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
765 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
766 snd_device = SND_DEVICE_IN_HEADSET_MIC;
767 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
768 snd_device = SND_DEVICE_IN_BT_SCO_MIC ;
769 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
770 snd_device = SND_DEVICE_IN_HDMI_MIC;
771 } else {
772 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
773 ALOGW("%s: Using default handset-mic", __func__);
774 snd_device = SND_DEVICE_IN_HANDSET_MIC;
775 }
776 } else {
777 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
778 snd_device = SND_DEVICE_IN_HANDSET_MIC;
779 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
780 snd_device = SND_DEVICE_IN_HEADSET_MIC;
781 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
782 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
783 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
784 snd_device = SND_DEVICE_IN_HANDSET_MIC;
785 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
786 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
787 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
788 snd_device = SND_DEVICE_IN_HDMI_MIC;
789 } else {
790 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
791 ALOGW("%s: Using default handset-mic", __func__);
792 snd_device = SND_DEVICE_IN_HANDSET_MIC;
793 }
794 }
795exit:
796 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
797 return snd_device;
798}
799
800int platform_set_hdmi_channels(void *platform, int channel_count)
801{
802 struct platform_data *my_data = (struct platform_data *)platform;
803 struct audio_device *adev = my_data->adev;
804 struct mixer_ctl *ctl;
805 const char *channel_cnt_str = NULL;
806 const char *mixer_ctl_name = "HDMI_RX Channels";
807 switch (channel_count) {
808 case 8:
809 channel_cnt_str = "Eight"; break;
810 case 7:
811 channel_cnt_str = "Seven"; break;
812 case 6:
813 channel_cnt_str = "Six"; break;
814 case 5:
815 channel_cnt_str = "Five"; break;
816 case 4:
817 channel_cnt_str = "Four"; break;
818 case 3:
819 channel_cnt_str = "Three"; break;
820 default:
821 channel_cnt_str = "Two"; break;
822 }
823 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
824 if (!ctl) {
825 ALOGE("%s: Could not get ctl for mixer cmd - %s",
826 __func__, mixer_ctl_name);
827 return -EINVAL;
828 }
829 ALOGV("HDMI channel count: %s", channel_cnt_str);
830 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
831 return 0;
832}
833
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -0700834int platform_edid_get_max_channels(void *platform)
Eric Laurentb23d5282013-05-14 15:27:20 -0700835{
836 FILE *file;
837 struct audio_block_header header;
838 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
839 char *sad = block;
840 int num_audio_blocks;
841 int channel_count;
842 int max_channels = 0;
843 int i;
844
845 file = fopen(AUDIO_DATA_BLOCK_PATH, "rb");
846 if (file == NULL) {
847 ALOGE("Unable to open '%s'", AUDIO_DATA_BLOCK_PATH);
848 return 0;
849 }
850
851 /* Read audio block header */
852 fread(&header, 1, sizeof(header), file);
853
854 /* Read SAD blocks, clamping the maximum size for safety */
855 if (header.length > (int)sizeof(block))
856 header.length = (int)sizeof(block);
857 fread(&block, header.length, 1, file);
858
859 fclose(file);
860
861 /* Calculate the number of SAD blocks */
862 num_audio_blocks = header.length / SAD_BLOCK_SIZE;
863
864 for (i = 0; i < num_audio_blocks; i++) {
865 /* Only consider LPCM blocks */
866 if ((sad[0] >> 3) != EDID_FORMAT_LPCM)
867 continue;
868
869 channel_count = (sad[0] & 0x7) + 1;
870 if (channel_count > max_channels)
871 max_channels = channel_count;
872
873 /* Advance to next block */
874 sad += 3;
875 }
876
877 return max_channels;
878}
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700879
880void platform_get_parameters(void *platform, struct str_parms *query,
881 struct str_parms *reply)
882{
883 LOGE("%s: Not implemented", __func__);
884}
885
886int platform_set_parameters(void *platform, struct str_parms *parms)
887{
888 LOGE("%s: Not implemented", __func__);
889 return -ENOSYS;
890}
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700891
892int platform_set_incall_recoding_session_id(void *platform, uint32_t session_id)
893{
894 LOGE("%s: Not implemented", __func__);
895 return -ENOSYS;
896}
Shruthi Krishnaace10852013-10-25 14:32:12 -0700897
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700898/* Delay in Us */
899int64_t platform_render_latency(audio_usecase_t usecase)
900{
901 switch (usecase) {
902 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
903 return DEEP_BUFFER_PLATFORM_DELAY;
904 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
905 return LOW_LATENCY_PLATFORM_DELAY;
906 default:
907 return 0;
908 }
909}
Mingming Yine62d7842013-10-25 16:26:03 -0700910
911int platform_update_usecase_from_source(int source, int usecase)
912{
913 ALOGV("%s: input source :%d", __func__, source);
914 return usecase;
915}
Kiran Kandide144c82013-11-20 15:58:32 -0800916
917bool platform_listen_update_status(snd_device_t snd_device)
918{
919 return false;
920}