blob: e7d6920a98316654740115cae833ebfafb58bbc0 [file] [log] [blame]
Eric Laurentb23d5282013-05-14 15:27:20 -07001/*
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -08002 * Copyright (c) 2013-2015, 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"
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -070031#include "audio_extn.h"
Eric Laurentb23d5282013-05-14 15:27:20 -070032
33#define LIB_ACDB_LOADER "libacdbloader.so"
34#define LIB_CSD_CLIENT "libcsd-client.so"
35
Eric Laurentb23d5282013-05-14 15:27:20 -070036/*
37 * This is the sysfs path for the HDMI audio data block
38 */
39#define AUDIO_DATA_BLOCK_PATH "/sys/class/graphics/fb1/audio_data_block"
sangwoo1b9f4b32013-06-21 18:22:55 -070040#define MIXER_XML_PATH "/system/etc/mixer_paths.xml"
Eric Laurentb23d5282013-05-14 15:27:20 -070041
42/*
43 * This file will have a maximum of 38 bytes:
44 *
45 * 4 bytes: number of audio blocks
46 * 4 bytes: total length of Short Audio Descriptor (SAD) blocks
47 * Maximum 10 * 3 bytes: SAD blocks
48 */
49#define MAX_SAD_BLOCKS 10
50#define SAD_BLOCK_SIZE 3
51
52/* EDID format ID for LPCM audio */
53#define EDID_FORMAT_LPCM 1
54
55struct audio_block_header
56{
57 int reserved;
58 int length;
59};
60
61
62typedef void (*acdb_deallocate_t)();
63typedef int (*acdb_init_t)();
64typedef void (*acdb_send_audio_cal_t)(int, int);
65typedef void (*acdb_send_voice_cal_t)(int, int);
66
67typedef int (*csd_client_init_t)();
68typedef int (*csd_client_deinit_t)();
69typedef int (*csd_disable_device_t)();
70typedef int (*csd_enable_device_t)(int, int, uint32_t);
71typedef int (*csd_volume_t)(int);
72typedef int (*csd_mic_mute_t)(int);
73typedef int (*csd_start_voice_t)();
74typedef int (*csd_stop_voice_t)();
75
76
Eric Laurentb23d5282013-05-14 15:27:20 -070077struct platform_data {
78 struct audio_device *adev;
79 bool fluence_in_spkr_mode;
80 bool fluence_in_voice_call;
81 bool fluence_in_voice_rec;
Mingming Yin8e5a4f62013-10-07 15:23:41 -070082 int fluence_type;
Eric Laurentb23d5282013-05-14 15:27:20 -070083 int dualmic_config;
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +053084 bool ec_ref_enabled;
Eric Laurentb23d5282013-05-14 15:27:20 -070085
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -070086 /* 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",
Mingming Yin514a8bc2014-07-29 15:22:21 -0700128 [SND_DEVICE_OUT_BT_SCO_WB] = "bt-sco-headset-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700129 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones",
130 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones",
131 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset",
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -0700132 [SND_DEVICE_OUT_USB_HEADSET] = "usb-headphones",
133 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = "speaker-and-usb-headphones",
Eric Laurentb23d5282013-05-14 15:27:20 -0700134
135 /* Capture sound devices */
136 [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
137 [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
138 [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
139 [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic",
140 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "voice-speaker-mic",
141 [SND_DEVICE_IN_HEADSET_MIC_AEC] = "headset-mic",
142 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
143 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
144 [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic",
145 [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
Mingming Yin514a8bc2014-07-29 15:22:21 -0700146 [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700147 [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic",
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700148 [SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef",
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700149 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = "voice-speaker-dmic-ef",
Eric Laurentb23d5282013-05-14 15:27:20 -0700150 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
151 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
152 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
153 [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700154 [SND_DEVICE_IN_VOICE_REC_DMIC] = "voice-rec-dmic-ef",
155 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence",
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -0700156 [SND_DEVICE_IN_USB_HEADSET_MIC] = "usb-headset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700157};
158
159/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
160static const int acdb_device_table[SND_DEVICE_MAX] = {
161 [SND_DEVICE_NONE] = -1,
162 [SND_DEVICE_OUT_HANDSET] = 7,
163 [SND_DEVICE_OUT_SPEAKER] = 14,
164 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 14,
165 [SND_DEVICE_OUT_HEADPHONES] = 10,
166 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
167 [SND_DEVICE_OUT_VOICE_SPEAKER] = 14,
168 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
169 [SND_DEVICE_OUT_HDMI] = 18,
170 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 14,
171 [SND_DEVICE_OUT_BT_SCO] = 22,
Mingming Yin514a8bc2014-07-29 15:22:21 -0700172 [SND_DEVICE_OUT_BT_SCO_WB] = 39,
Eric Laurentb23d5282013-05-14 15:27:20 -0700173 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
174 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
175 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -0700176 [SND_DEVICE_OUT_USB_HEADSET] = 45,
177 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = 14,
Eric Laurentb23d5282013-05-14 15:27:20 -0700178
179 [SND_DEVICE_IN_HANDSET_MIC] = 4,
180 [SND_DEVICE_IN_SPEAKER_MIC] = 4,
181 [SND_DEVICE_IN_HEADSET_MIC] = 8,
182 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 40,
183 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 42,
184 [SND_DEVICE_IN_HEADSET_MIC_AEC] = 47,
185 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
186 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = 8,
187 [SND_DEVICE_IN_HDMI_MIC] = 4,
188 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
Mingming Yin514a8bc2014-07-29 15:22:21 -0700189 [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38,
Eric Laurentb23d5282013-05-14 15:27:20 -0700190 [SND_DEVICE_IN_CAMCORDER_MIC] = 61,
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700191 [SND_DEVICE_IN_VOICE_DMIC] = 6,
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700192 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 13,
Eric Laurentb23d5282013-05-14 15:27:20 -0700193 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
194 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
195 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
196 [SND_DEVICE_IN_VOICE_REC_MIC] = 62,
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -0700197 [SND_DEVICE_IN_USB_HEADSET_MIC] = 44,
Eric Laurentb23d5282013-05-14 15:27:20 -0700198 /* TODO: Update with proper acdb ids */
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700199 [SND_DEVICE_IN_VOICE_REC_DMIC] = 62,
200 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 6,
Eric Laurentb23d5282013-05-14 15:27:20 -0700201};
202
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700203#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
204#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
205
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +0530206void platform_set_echo_reference(void *platform, bool enable)
Eric Laurentb23d5282013-05-14 15:27:20 -0700207{
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +0530208 struct platform_data *my_data = (struct platform_data *)platform;
209 struct audio_device *adev = my_data->adev;
210
211 if (enable) {
212 my_data->ec_ref_enabled = enable;
Anish Kumar4980fa12014-04-17 12:42:20 -0700213 audio_route_apply_and_update_path(adev->audio_route, "echo-reference");
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +0530214 } else {
215 if (my_data->ec_ref_enabled) {
216 audio_route_reset_and_update_path(adev->audio_route, "echo-reference");
217 my_data->ec_ref_enabled = enable;
218 } else {
219 ALOGV("EC Reference is already disabled: %d", my_data->ec_ref_enabled);
220 }
221 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700222
Anish Kumar4980fa12014-04-17 12:42:20 -0700223 ALOGV("Setting EC Reference: %d", enable);
Eric Laurentb23d5282013-05-14 15:27:20 -0700224}
225
226void *platform_init(struct audio_device *adev)
227{
228 char platform[PROPERTY_VALUE_MAX];
229 char baseband[PROPERTY_VALUE_MAX];
230 char value[PROPERTY_VALUE_MAX];
231 struct platform_data *my_data;
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -0700232 const char *snd_card_name;
Satish Babu Patakokilabbd4e9d2015-05-13 22:08:06 +0530233 const char *mixer_ctl_name = "Set HPX ActiveBe";
234 struct mixer_ctl *ctl = NULL;
Eric Laurentb23d5282013-05-14 15:27:20 -0700235
sangwoo1b9f4b32013-06-21 18:22:55 -0700236 adev->mixer = mixer_open(MIXER_CARD);
237
238 if (!adev->mixer) {
239 ALOGE("Unable to open the mixer, aborting.");
240 return NULL;
241 }
242
243 adev->audio_route = audio_route_init(MIXER_CARD, MIXER_XML_PATH);
244 if (!adev->audio_route) {
245 ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
246 return NULL;
247 }
248
Eric Laurentb23d5282013-05-14 15:27:20 -0700249 my_data = calloc(1, sizeof(struct platform_data));
250
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -0700251 snd_card_name = mixer_get_name(adev->mixer);
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -0700252
Eric Laurentb23d5282013-05-14 15:27:20 -0700253 my_data->adev = adev;
Eric Laurentb23d5282013-05-14 15:27:20 -0700254 my_data->fluence_in_spkr_mode = false;
255 my_data->fluence_in_voice_call = false;
256 my_data->fluence_in_voice_rec = false;
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700257 my_data->fluence_type = FLUENCE_NONE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700258
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700259 property_get("ro.qc.sdk.audio.fluencetype", value, "");
260 if (!strncmp("fluencepro", value, sizeof("fluencepro"))) {
261 my_data->fluence_type = FLUENCE_QUAD_MIC;
262 } else if (!strncmp("fluence", value, sizeof("fluence"))) {
263 my_data->fluence_type = FLUENCE_DUAL_MIC;
264 } else {
265 my_data->fluence_type = FLUENCE_NONE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700266 }
267
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700268 if (my_data->fluence_type != FLUENCE_NONE) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700269 property_get("persist.audio.fluence.voicecall",value,"");
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700270 if (!strncmp("true", value, sizeof("true"))) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700271 my_data->fluence_in_voice_call = true;
272 }
273
274 property_get("persist.audio.fluence.voicerec",value,"");
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700275 if (!strncmp("true", value, sizeof("true"))) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700276 my_data->fluence_in_voice_rec = true;
277 }
278
279 property_get("persist.audio.fluence.speaker",value,"");
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700280 if (!strncmp("true", value, sizeof("true"))) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700281 my_data->fluence_in_spkr_mode = true;
282 }
283 }
284
285 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
286 if (my_data->acdb_handle == NULL) {
287 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
288 } else {
289 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
290 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
291 "acdb_loader_deallocate_ACDB");
292 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
293 "acdb_loader_send_audio_cal");
294 if (!my_data->acdb_send_audio_cal)
295 ALOGW("%s: Could not find the symbol acdb_send_audio_cal from %s",
296 __func__, LIB_ACDB_LOADER);
297 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
298 "acdb_loader_send_voice_cal");
299 my_data->acdb_init = (acdb_init_t)dlsym(my_data->acdb_handle,
300 "acdb_loader_init_ACDB");
301 if (my_data->acdb_init == NULL)
302 ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__, dlerror());
303 else
304 my_data->acdb_init();
305 }
306
307 /* If platform is Fusion3, load CSD Client specific symbols
308 * Voice call is handled by MDM and apps processor talks to
309 * MDM through CSD Client
310 */
311 property_get("ro.board.platform", platform, "");
312 property_get("ro.baseband", baseband, "");
313 if (!strcmp("msm8960", platform) && !strcmp("mdm", baseband)) {
314 my_data->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
315 if (my_data->csd_client == NULL)
316 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
317 }
318
319 if (my_data->csd_client) {
320 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
321 my_data->csd_client_deinit = (csd_client_deinit_t)dlsym(my_data->csd_client,
322 "csd_client_deinit");
323 my_data->csd_disable_device = (csd_disable_device_t)dlsym(my_data->csd_client,
324 "csd_client_disable_device");
325 my_data->csd_enable_device = (csd_enable_device_t)dlsym(my_data->csd_client,
326 "csd_client_enable_device");
327 my_data->csd_start_voice = (csd_start_voice_t)dlsym(my_data->csd_client,
328 "csd_client_start_voice");
329 my_data->csd_stop_voice = (csd_stop_voice_t)dlsym(my_data->csd_client,
330 "csd_client_stop_voice");
331 my_data->csd_volume = (csd_volume_t)dlsym(my_data->csd_client,
332 "csd_client_volume");
333 my_data->csd_mic_mute = (csd_mic_mute_t)dlsym(my_data->csd_client,
334 "csd_client_mic_mute");
335 my_data->csd_client_init = (csd_client_init_t)dlsym(my_data->csd_client,
336 "csd_client_init");
337
338 if (my_data->csd_client_init == NULL) {
339 ALOGE("%s: dlsym error %s for csd_client_init", __func__, dlerror());
340 } else {
341 my_data->csd_client_init();
342 }
343 }
344
Satish Babu Patakokilabbd4e9d2015-05-13 22:08:06 +0530345 /* Configure active back end for HPX*/
346 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
347 if (ctl) {
348 ALOGI(" sending HPX Active BE information ");
349 mixer_ctl_set_value(ctl, 0, false);
350 }
351
Eric Laurentb23d5282013-05-14 15:27:20 -0700352 return my_data;
353}
354
355void platform_deinit(void *platform)
356{
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -0700357 struct platform_data *my_data = (struct platform_data *)platform;
358
Eric Laurentb23d5282013-05-14 15:27:20 -0700359 free(platform);
360}
361
362const char *platform_get_snd_device_name(snd_device_t snd_device)
363{
364 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX)
365 return device_table[snd_device];
366 else
367 return "";
368}
369
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -0700370int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
371 char *device_name)
372{
373 struct platform_data *my_data = (struct platform_data *)platform;
374
375 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
376 strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE);
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -0700377 } else {
378 strlcpy(device_name, "", DEVICE_NAME_MAX_SIZE);
379 return -EINVAL;
380 }
381
382 return 0;
383}
384
Banajit Goswami20cdd212015-09-11 01:11:30 -0700385void platform_add_backend_name(char *mixer_path, snd_device_t snd_device,
Banajit Goswami4dc87fb2015-10-11 21:46:07 -0700386 struct audio_usecase *usecase __unused)
Eric Laurentb23d5282013-05-14 15:27:20 -0700387{
388 if (snd_device == SND_DEVICE_IN_BT_SCO_MIC)
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700389 strlcat(mixer_path, " bt-sco", MIXER_PATH_MAX_LENGTH);
390 else if (snd_device == SND_DEVICE_IN_BT_SCO_MIC_WB)
391 strlcat(mixer_path, " bt-sco-wb", MIXER_PATH_MAX_LENGTH);
Eric Laurentb23d5282013-05-14 15:27:20 -0700392 else if(snd_device == SND_DEVICE_OUT_BT_SCO)
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700393 strlcat(mixer_path, " bt-sco", MIXER_PATH_MAX_LENGTH);
394 else if(snd_device == SND_DEVICE_OUT_BT_SCO_WB)
395 strlcat(mixer_path, " bt-sco-wb", MIXER_PATH_MAX_LENGTH);
Eric Laurentb23d5282013-05-14 15:27:20 -0700396 else if (snd_device == SND_DEVICE_OUT_HDMI)
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700397 strlcat(mixer_path, " hdmi", MIXER_PATH_MAX_LENGTH);
Eric Laurentb23d5282013-05-14 15:27:20 -0700398 else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HDMI)
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700399 strlcat(mixer_path, " speaker-and-hdmi", MIXER_PATH_MAX_LENGTH);
Eric Laurentb23d5282013-05-14 15:27:20 -0700400}
401
402int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
403{
404 int device_id;
405 if (device_type == PCM_PLAYBACK)
406 device_id = pcm_device_table[usecase][0];
407 else
408 device_id = pcm_device_table[usecase][1];
409 return device_id;
410}
411
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -0700412int platform_get_snd_device_index(char *snd_device_index_name __unused)
Ben Romberger61764e32014-01-10 13:49:02 -0800413{
414 return -ENODEV;
415}
416
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -0700417int platform_set_snd_device_acdb_id(snd_device_t snd_device __unused,
418 unsigned int acdb_id __unused)
Ben Romberger55886882014-01-10 13:49:02 -0800419{
420 return -ENODEV;
421}
422
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -0700423uint32_t platform_get_compress_offload_buffer_size(audio_offload_info_t* info __unused)
424{
425 ALOGE("%s: Not implemented", __func__);
426 return -ENOSYS;
427}
428
429int platform_get_snd_device_acdb_id(snd_device_t snd_device __unused)
430{
431 ALOGE("%s: Not implemented", __func__);
432 return -ENOSYS;
433}
434
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -0700435int platform_set_snd_device_bit_width(snd_device_t snd_device __unused,
436 unsigned int bit_width __unused)
Amit Shekhar5a39c912014-10-14 15:39:30 -0700437{
438 ALOGE("%s: Not implemented", __func__);
439 return -ENOSYS;
440}
441
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -0700442int platform_get_snd_device_bit_width(snd_device_t snd_device __unused)
Amit Shekhar5a39c912014-10-14 15:39:30 -0700443{
444 ALOGE("%s: Not implemented", __func__);
445 return -ENOSYS;
446}
447
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -0700448int platform_switch_voice_call_enable_device_config(void *platform __unused,
449 snd_device_t out_snd_device __unused,
450 snd_device_t in_snd_device __unused)
451{
452 ALOGE("%s: Not implemented", __func__);
453 return -ENOSYS;
454}
455
456int platform_switch_voice_call_usecase_route_post(void *platform __unused,
457 snd_device_t out_snd_device __unused,
458 snd_device_t in_snd_device __unused)
459{
460 ALOGE("%s: Not implemented", __func__);
461 return -ENOSYS;
462}
463
464int platform_set_incall_recording_session_id(void *platform __unused,
465 uint32_t session_id __unused,
466 int rec_mode __unused)
467{
468 ALOGE("%s: Not implemented", __func__);
469 return -ENOSYS;
470}
471
472int platform_stop_incall_recording_usecase(void *platform __unused)
473{
474 ALOGE("%s: Not implemented", __func__);
475 return -ENOSYS;
476}
477
478int platform_get_sample_rate(void *platform __unused, uint32_t *rate __unused)
479{
480 ALOGE("%s: Not implemented", __func__);
481 return -ENOSYS;
482}
483
484int platform_get_default_app_type(void *platform __unused)
485{
486 ALOGE("%s: Not implemented", __func__);
487 return -ENOSYS;
488}
489
Preetam Singh Ranawat2d0e4632015-02-02 12:40:59 +0530490int platform_send_audio_calibration(void *platform, struct audio_usecase *usecase,
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -0700491 int app_type __unused, int sample_rate __unused)
Eric Laurentb23d5282013-05-14 15:27:20 -0700492{
493 struct platform_data *my_data = (struct platform_data *)platform;
494 int acdb_dev_id, acdb_dev_type;
Preetam Singh Ranawat2d0e4632015-02-02 12:40:59 +0530495 struct audio_device *adev = my_data->adev;
496 int snd_device = SND_DEVICE_OUT_SPEAKER;
Eric Laurentb23d5282013-05-14 15:27:20 -0700497
Preetam Singh Ranawat2d0e4632015-02-02 12:40:59 +0530498 if (usecase->type == PCM_PLAYBACK)
499 snd_device = platform_get_output_snd_device(adev->platform,
500 usecase->stream.out->devices);
Karthik Reddy Katta81c42612015-11-13 17:49:07 +0530501 else if ((usecase->type == PCM_CAPTURE) &&
502 voice_is_in_call_rec_stream(usecase->stream.in))
503 snd_device = voice_get_incall_rec_snd_device(usecase->in_snd_device);
Preetam Singh Ranawat2d0e4632015-02-02 12:40:59 +0530504 else if ((usecase->type == PCM_HFP_CALL) || (usecase->type == PCM_CAPTURE))
505 snd_device = platform_get_input_snd_device(adev->platform,
506 adev->primary_output->devices);
Eric Laurentb23d5282013-05-14 15:27:20 -0700507 acdb_dev_id = acdb_device_table[snd_device];
508 if (acdb_dev_id < 0) {
509 ALOGE("%s: Could not find acdb id for device(%d)",
510 __func__, snd_device);
511 return -EINVAL;
512 }
513 if (my_data->acdb_send_audio_cal) {
Eric Laurent994a6932013-07-17 11:51:42 -0700514 ("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Eric Laurentb23d5282013-05-14 15:27:20 -0700515 __func__, snd_device, acdb_dev_id);
516 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
517 snd_device < SND_DEVICE_OUT_END)
518 acdb_dev_type = ACDB_DEV_TYPE_OUT;
519 else
520 acdb_dev_type = ACDB_DEV_TYPE_IN;
521 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
522 }
523 return 0;
524}
525
526int platform_switch_voice_call_device_pre(void *platform)
527{
528 struct platform_data *my_data = (struct platform_data *)platform;
529 int ret = 0;
530
Ravi Kumar Alamandabe149392014-10-20 17:07:43 -0700531 if (my_data->csd_client != NULL &&
532 voice_is_in_call(my_data->adev)) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700533 /* This must be called before disabling the mixer controls on APQ side */
534 if (my_data->csd_disable_device == NULL) {
535 ALOGE("%s: dlsym error for csd_disable_device", __func__);
536 } else {
537 ret = my_data->csd_disable_device();
538 if (ret < 0) {
539 ALOGE("%s: csd_client_disable_device, failed, error %d",
540 __func__, ret);
541 }
542 }
543 }
544 return ret;
545}
546
547int platform_switch_voice_call_device_post(void *platform,
548 snd_device_t out_snd_device,
549 snd_device_t in_snd_device)
550{
551 struct platform_data *my_data = (struct platform_data *)platform;
552 int acdb_rx_id, acdb_tx_id;
553 int ret = 0;
554
555 if (my_data->csd_client) {
556 if (my_data->csd_enable_device == NULL) {
557 ALOGE("%s: dlsym error for csd_enable_device",
558 __func__);
559 } else {
560 acdb_rx_id = acdb_device_table[out_snd_device];
561 acdb_tx_id = acdb_device_table[in_snd_device];
562
563 if (acdb_rx_id > 0 || acdb_tx_id > 0) {
564 ret = my_data->csd_enable_device(acdb_rx_id, acdb_tx_id,
565 my_data->adev->acdb_settings);
566 if (ret < 0) {
567 ALOGE("%s: csd_enable_device, failed, error %d",
568 __func__, ret);
569 }
570 } else {
571 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
572 acdb_rx_id, acdb_tx_id);
573 }
574 }
575 }
576
577 return ret;
578}
579
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -0700580int platform_start_voice_call(void *platform, uint32_t vsid __unused)
Eric Laurentb23d5282013-05-14 15:27:20 -0700581{
582 struct platform_data *my_data = (struct platform_data *)platform;
583 int ret = 0;
584
585 if (my_data->csd_client) {
586 if (my_data->csd_start_voice == NULL) {
587 ALOGE("dlsym error for csd_client_start_voice");
588 ret = -ENOSYS;
589 } else {
590 ret = my_data->csd_start_voice();
591 if (ret < 0) {
592 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
593 }
594 }
595 }
596
597 return ret;
598}
599
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -0700600int platform_stop_voice_call(void *platform, uint32_t vsid __unused)
Eric Laurentb23d5282013-05-14 15:27:20 -0700601{
602 struct platform_data *my_data = (struct platform_data *)platform;
603 int ret = 0;
604
605 if (my_data->csd_client) {
606 if (my_data->csd_stop_voice == NULL) {
607 ALOGE("dlsym error for csd_stop_voice");
608 } else {
609 ret = my_data->csd_stop_voice();
610 if (ret < 0) {
611 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
612 }
613 }
614 }
615
616 return ret;
617}
618
619int platform_set_voice_volume(void *platform, int volume)
620{
621 struct platform_data *my_data = (struct platform_data *)platform;
622 int ret = 0;
623
624 if (my_data->csd_client) {
625 if (my_data->csd_volume == NULL) {
626 ALOGE("%s: dlsym error for csd_volume", __func__);
627 } else {
628 ret = my_data->csd_volume(volume);
629 if (ret < 0) {
630 ALOGE("%s: csd_volume error %d", __func__, ret);
631 }
632 }
633 } else {
634 ALOGE("%s: No CSD Client present", __func__);
635 }
636
637 return ret;
638}
639
640int platform_set_mic_mute(void *platform, bool state)
641{
642 struct platform_data *my_data = (struct platform_data *)platform;
643 int ret = 0;
644
645 if (my_data->adev->mode == AUDIO_MODE_IN_CALL) {
646 if (my_data->csd_client) {
647 if (my_data->csd_mic_mute == NULL) {
648 ALOGE("%s: dlsym error for csd_mic_mute", __func__);
649 } else {
650 ret = my_data->csd_mic_mute(state);
651 if (ret < 0) {
652 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
653 }
654 }
655 } else {
656 ALOGE("%s: No CSD Client present", __func__);
657 }
658 }
659
660 return ret;
661}
662
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -0700663int platform_set_device_mute(void *platform __unused, bool state __unused, char *dir __unused)
Shiv Maliyappanahallic6fd8ee2014-03-07 15:31:55 -0800664{
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -0700665 ALOGE("%s: Not implemented", __func__);
Shiv Maliyappanahallic6fd8ee2014-03-07 15:31:55 -0800666 return -ENOSYS;
667}
668
Eric Laurentb23d5282013-05-14 15:27:20 -0700669snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
670{
671 struct platform_data *my_data = (struct platform_data *)platform;
672 struct audio_device *adev = my_data->adev;
673 audio_mode_t mode = adev->mode;
674 snd_device_t snd_device = SND_DEVICE_NONE;
675
676 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
677 if (devices == AUDIO_DEVICE_NONE ||
678 devices & AUDIO_DEVICE_BIT_IN) {
679 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
680 goto exit;
681 }
682
Venkata Narendra Kumar Guttabfdfa152015-06-22 14:25:35 +0530683 if (mode == AUDIO_MODE_IN_CALL) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700684 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
685 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -0700686 if (adev->voice.tty_mode == TTY_MODE_FULL)
Eric Laurentb23d5282013-05-14 15:27:20 -0700687 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -0700688 else if (adev->voice.tty_mode == TTY_MODE_VCO)
Eric Laurentb23d5282013-05-14 15:27:20 -0700689 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -0700690 else if (adev->voice.tty_mode == TTY_MODE_HCO)
Eric Laurentb23d5282013-05-14 15:27:20 -0700691 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
692 else
693 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
694 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Mingming Yin514a8bc2014-07-29 15:22:21 -0700695 if (adev->bt_wb_speech_enabled)
696 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
697 else
698 snd_device = SND_DEVICE_OUT_BT_SCO;
Eric Laurentb23d5282013-05-14 15:27:20 -0700699 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
700 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
701 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Ravi Kumar Alamandaceb40822013-11-06 11:01:47 -0800702 snd_device = SND_DEVICE_OUT_HANDSET;
Eric Laurentb23d5282013-05-14 15:27:20 -0700703 }
704 if (snd_device != SND_DEVICE_NONE) {
705 goto exit;
706 }
707 }
708
709 if (popcount(devices) == 2) {
710 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
711 AUDIO_DEVICE_OUT_SPEAKER)) {
712 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
713 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
714 AUDIO_DEVICE_OUT_SPEAKER)) {
715 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
716 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
717 AUDIO_DEVICE_OUT_SPEAKER)) {
718 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
719 } else {
720 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
721 goto exit;
722 }
723 if (snd_device != SND_DEVICE_NONE) {
724 goto exit;
725 }
726 }
727
728 if (popcount(devices) != 1) {
729 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
730 goto exit;
731 }
732
733 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
734 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
735 snd_device = SND_DEVICE_OUT_HEADPHONES;
736 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
737 if (adev->speaker_lr_swap)
738 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
739 else
740 snd_device = SND_DEVICE_OUT_SPEAKER;
741 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Mingming Yin514a8bc2014-07-29 15:22:21 -0700742 if (adev->bt_wb_speech_enabled)
743 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
744 else
745 snd_device = SND_DEVICE_OUT_BT_SCO;
Eric Laurentb23d5282013-05-14 15:27:20 -0700746 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
747 snd_device = SND_DEVICE_OUT_HDMI ;
748 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
749 snd_device = SND_DEVICE_OUT_HANDSET;
750 } else {
751 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
752 }
753exit:
754 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
755 return snd_device;
756}
757
758snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
759{
760 struct platform_data *my_data = (struct platform_data *)platform;
761 struct audio_device *adev = my_data->adev;
762 audio_source_t source = (adev->active_input == NULL) ?
763 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
764
765 audio_mode_t mode = adev->mode;
766 audio_devices_t in_device = ((adev->active_input == NULL) ?
767 AUDIO_DEVICE_NONE : adev->active_input->device)
768 & ~AUDIO_DEVICE_BIT_IN;
769 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
770 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
771 snd_device_t snd_device = SND_DEVICE_NONE;
772
773 ALOGV("%s: enter: out_device(%#x) in_device(%#x)",
774 __func__, out_device, in_device);
Venkata Narendra Kumar Guttabfdfa152015-06-22 14:25:35 +0530775 if ((out_device != AUDIO_DEVICE_NONE) && (mode == AUDIO_MODE_IN_CALL)) {
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -0700776 if (adev->voice.tty_mode != TTY_MODE_OFF) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700777 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
778 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -0700779 switch (adev->voice.tty_mode) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700780 case TTY_MODE_FULL:
781 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
782 break;
783 case TTY_MODE_VCO:
784 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
785 break;
786 case TTY_MODE_HCO:
787 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
788 break;
789 default:
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -0700790 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
Eric Laurentb23d5282013-05-14 15:27:20 -0700791 }
792 goto exit;
793 }
794 }
795 if (out_device & AUDIO_DEVICE_OUT_EARPIECE ||
796 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700797 if (my_data->fluence_type == FLUENCE_NONE ||
798 my_data->fluence_in_voice_call == false) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700799 snd_device = SND_DEVICE_IN_HANDSET_MIC;
800 } else {
Ravi Kumar Alamandaceb40822013-11-06 11:01:47 -0800801 snd_device = SND_DEVICE_IN_VOICE_DMIC;
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700802 adev->acdb_settings |= DMIC_FLAG;
Eric Laurentb23d5282013-05-14 15:27:20 -0700803 }
804 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
805 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
806 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Mingming Yin514a8bc2014-07-29 15:22:21 -0700807 if (adev->bt_wb_speech_enabled)
808 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
809 else
810 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -0700811 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700812 if (my_data->fluence_type != FLUENCE_NONE &&
813 my_data->fluence_in_voice_call &&
814 my_data->fluence_in_spkr_mode) {
815 if(my_data->fluence_type == FLUENCE_DUAL_MIC) {
816 adev->acdb_settings |= DMIC_FLAG;
817 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
818 } else {
819 adev->acdb_settings |= QMIC_FLAG;
820 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_QMIC;
821 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700822 } else {
823 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
824 }
825 }
826 } else if (source == AUDIO_SOURCE_CAMCORDER) {
827 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
828 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
829 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
830 }
831 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
832 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700833 if (channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK)
834 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC;
835 else if (my_data->fluence_in_voice_rec)
836 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700837
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700838 if (snd_device == SND_DEVICE_NONE)
Eric Laurentb23d5282013-05-14 15:27:20 -0700839 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700840 else
841 adev->acdb_settings |= DMIC_FLAG;
Eric Laurentb23d5282013-05-14 15:27:20 -0700842 }
843 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION) {
844 if (out_device & AUDIO_DEVICE_OUT_SPEAKER)
845 in_device = AUDIO_DEVICE_IN_BACK_MIC;
846 if (adev->active_input) {
847 if (adev->active_input->enable_aec) {
848 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
849 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
850 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
851 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
852 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
853 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
854 }
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +0530855 platform_set_echo_reference(adev->platform, true);
Eric Laurentb23d5282013-05-14 15:27:20 -0700856 } else
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +0530857 platform_set_echo_reference(adev->platform, false);
Eric Laurentb23d5282013-05-14 15:27:20 -0700858 }
859 } else if (source == AUDIO_SOURCE_DEFAULT) {
860 goto exit;
861 }
862
863
864 if (snd_device != SND_DEVICE_NONE) {
865 goto exit;
866 }
867
868 if (in_device != AUDIO_DEVICE_NONE &&
869 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
870 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
871 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
872 snd_device = SND_DEVICE_IN_HANDSET_MIC;
873 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
874 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
875 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
876 snd_device = SND_DEVICE_IN_HEADSET_MIC;
877 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Mingming Yin514a8bc2014-07-29 15:22:21 -0700878 if (adev->bt_wb_speech_enabled)
879 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
880 else
881 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -0700882 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
883 snd_device = SND_DEVICE_IN_HDMI_MIC;
884 } else {
885 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
886 ALOGW("%s: Using default handset-mic", __func__);
887 snd_device = SND_DEVICE_IN_HANDSET_MIC;
888 }
889 } else {
890 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
891 snd_device = SND_DEVICE_IN_HANDSET_MIC;
892 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
893 snd_device = SND_DEVICE_IN_HEADSET_MIC;
894 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
895 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
896 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
897 snd_device = SND_DEVICE_IN_HANDSET_MIC;
898 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Mingming Yin514a8bc2014-07-29 15:22:21 -0700899 if (adev->bt_wb_speech_enabled)
900 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
901 else
902 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -0700903 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
904 snd_device = SND_DEVICE_IN_HDMI_MIC;
905 } else {
906 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
907 ALOGW("%s: Using default handset-mic", __func__);
908 snd_device = SND_DEVICE_IN_HANDSET_MIC;
909 }
910 }
911exit:
912 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
913 return snd_device;
914}
915
916int platform_set_hdmi_channels(void *platform, int channel_count)
917{
918 struct platform_data *my_data = (struct platform_data *)platform;
919 struct audio_device *adev = my_data->adev;
920 struct mixer_ctl *ctl;
921 const char *channel_cnt_str = NULL;
922 const char *mixer_ctl_name = "HDMI_RX Channels";
923 switch (channel_count) {
924 case 8:
925 channel_cnt_str = "Eight"; break;
926 case 7:
927 channel_cnt_str = "Seven"; break;
928 case 6:
929 channel_cnt_str = "Six"; break;
930 case 5:
931 channel_cnt_str = "Five"; break;
932 case 4:
933 channel_cnt_str = "Four"; break;
934 case 3:
935 channel_cnt_str = "Three"; break;
936 default:
937 channel_cnt_str = "Two"; break;
938 }
939 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
940 if (!ctl) {
941 ALOGE("%s: Could not get ctl for mixer cmd - %s",
942 __func__, mixer_ctl_name);
943 return -EINVAL;
944 }
945 ALOGV("HDMI channel count: %s", channel_cnt_str);
946 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
947 return 0;
948}
949
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -0700950int platform_edid_get_max_channels(void *platform __unused)
Eric Laurentb23d5282013-05-14 15:27:20 -0700951{
952 FILE *file;
953 struct audio_block_header header;
954 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
955 char *sad = block;
956 int num_audio_blocks;
957 int channel_count;
958 int max_channels = 0;
959 int i;
960
961 file = fopen(AUDIO_DATA_BLOCK_PATH, "rb");
962 if (file == NULL) {
963 ALOGE("Unable to open '%s'", AUDIO_DATA_BLOCK_PATH);
964 return 0;
965 }
966
967 /* Read audio block header */
968 fread(&header, 1, sizeof(header), file);
969
970 /* Read SAD blocks, clamping the maximum size for safety */
971 if (header.length > (int)sizeof(block))
972 header.length = (int)sizeof(block);
973 fread(&block, header.length, 1, file);
974
975 fclose(file);
976
977 /* Calculate the number of SAD blocks */
978 num_audio_blocks = header.length / SAD_BLOCK_SIZE;
979
980 for (i = 0; i < num_audio_blocks; i++) {
981 /* Only consider LPCM blocks */
982 if ((sad[0] >> 3) != EDID_FORMAT_LPCM)
983 continue;
984
985 channel_count = (sad[0] & 0x7) + 1;
986 if (channel_count > max_channels)
987 max_channels = channel_count;
988
989 /* Advance to next block */
990 sad += 3;
991 }
992
993 return max_channels;
994}
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700995
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -0700996void platform_get_parameters(void *platform __unused,
997 struct str_parms *query __unused,
998 struct str_parms *reply __unused)
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700999{
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07001000 ALOGE("%s: Not implemented", __func__);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07001001}
1002
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07001003int platform_set_parameters(void *platform __unused, struct str_parms *parms __unused)
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07001004{
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07001005 ALOGE("%s: Not implemented", __func__);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07001006 return -ENOSYS;
1007}
Shiv Maliyappanahallida107642013-10-17 11:16:13 -07001008
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07001009int platform_set_incall_recoding_session_id(void *platform __unused,
1010 uint32_t session_id __unused)
Shiv Maliyappanahallida107642013-10-17 11:16:13 -07001011{
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07001012 ALOGE("%s: Not implemented", __func__);
Shiv Maliyappanahallida107642013-10-17 11:16:13 -07001013 return -ENOSYS;
1014}
Shruthi Krishnaace10852013-10-25 14:32:12 -07001015
Vidyakumar Athota21b3bb92014-04-25 11:08:08 -07001016int platform_update_lch(void *platform __unused,
1017 struct voice_session *session __unused,
1018 enum voice_lch_mode lch_mode __unused)
1019{
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07001020 ALOGE("%s: Not implemented", __func__);
1021 return -ENOSYS;
1022}
1023
1024int platform_start_incall_music_usecase(void *platform __unused)
1025{
1026 ALOGE("%s: Not implemented", __func__);
1027 return -ENOSYS;
1028}
1029
1030int platform_stop_incall_music_usecase(void *platform __unused)
1031{
1032 ALOGE("%s: Not implemented", __func__);
Vidyakumar Athota21b3bb92014-04-25 11:08:08 -07001033 return -ENOSYS;
1034}
1035
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07001036/* Delay in Us */
1037int64_t platform_render_latency(audio_usecase_t usecase)
1038{
1039 switch (usecase) {
1040 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
1041 return DEEP_BUFFER_PLATFORM_DELAY;
1042 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
1043 return LOW_LATENCY_PLATFORM_DELAY;
1044 default:
1045 return 0;
1046 }
1047}
Mingming Yine62d7842013-10-25 16:26:03 -07001048
1049int platform_update_usecase_from_source(int source, int usecase)
1050{
1051 ALOGV("%s: input source :%d", __func__, source);
1052 return usecase;
1053}
Kiran Kandide144c82013-11-20 15:58:32 -08001054
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07001055bool platform_listen_device_needs_event(snd_device_t snd_device __unused)
Kiran Kandide144c82013-11-20 15:58:32 -08001056{
Dhananjay Kumar45b71742014-05-29 21:47:27 +05301057 return false;
1058}
1059
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07001060bool platform_listen_usecase_needs_event(audio_usecase_t uc_id __unused)
Dhananjay Kumar45b71742014-05-29 21:47:27 +05301061{
1062 return false;
Kiran Kandide144c82013-11-20 15:58:32 -08001063}
Mingming Yin3ee55c62014-08-04 14:23:35 -07001064
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07001065bool platform_check_and_set_codec_backend_cfg(struct audio_device* adev __unused,
1066 struct audio_usecase *usecase __unused)
1067{
Mingming Yin3ee55c62014-08-04 14:23:35 -07001068 return false;
1069}
1070
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001071int platform_get_usecase_index(const char * usecase __unused)
1072{
1073 return -ENOSYS;
1074}
1075
1076int platform_set_usecase_pcm_id(audio_usecase_t usecase __unused, int32_t type __unused,
1077 int32_t pcm_id __unused)
1078{
1079 return -ENOSYS;
1080}
1081
1082int platform_set_snd_device_backend(snd_device_t snd_device __unused,
1083 const char * backend __unused)
1084{
1085 return -ENOSYS;
1086}
Ravi Kumar Alamanda8fa6b192014-09-09 16:06:42 -07001087
1088bool platform_sound_trigger_device_needs_event(snd_device_t snd_device __unused)
1089{
1090 return false;
1091}
1092
1093bool platform_sound_trigger_usecase_needs_event(audio_usecase_t uc_id __unused)
1094{
1095 return false;
1096}
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07001097
1098int platform_set_fluence_type(void *platform __unused, char *value __unused)
1099{
1100 return -ENOSYS;
1101}
1102
1103int platform_get_fluence_type(void *platform __unused, char *value __unused,
1104 uint32_t len __unused)
1105{
1106 return -ENOSYS;
1107}
1108
1109uint32_t platform_get_pcm_offload_buffer_size(audio_offload_info_t* info __unused)
1110{
1111 return 0;
1112}
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07001113
Mingming Yin497419f2015-07-01 16:57:32 -07001114bool platform_use_small_buffer(audio_offload_info_t* info)
1115{
1116 return false;
1117}
1118
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07001119int platform_get_edid_info(void *platform __unused)
1120{
1121 return -ENOSYS;
1122}
1123
1124int platform_set_channel_map(void *platform __unused, int ch_count __unused,
1125 char *ch_map __unused, int snd_id __unused)
1126{
1127 return -ENOSYS;
1128}
1129
1130int platform_set_stream_channel_map(void *platform __unused,
1131 audio_channel_mask_t channel_mask __unused,
1132 int snd_id __unused)
1133{
1134 return -ENOSYS;
1135}
1136
1137int platform_set_edid_channels_configuration(void *platform __unused,
Pradnya Chaphekar80a8cfb2014-10-20 16:17:01 -07001138 int channels __unused)
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07001139{
1140 return 0;
1141}
1142
1143unsigned char platform_map_to_edid_format(int format __unused)
1144{
1145 return 0;
1146}
Pradnya Chaphekar80a8cfb2014-10-20 16:17:01 -07001147
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07001148bool platform_is_edid_supported_format(void *platform __unused,
1149 int format __unused)
1150{
1151 return false;
1152}
1153
1154void platform_cache_edid(void * platform __unused)
1155{
1156
1157}
1158
1159void platform_invalidate_edid(void * platform __unused)
1160{
1161
1162}
Pradnya Chaphekar80a8cfb2014-10-20 16:17:01 -07001163
1164int platform_set_hdmi_config(struct stream_out *out __unused)
1165{
1166 return 0;
1167}
1168
1169int platform_set_device_params(struct stream_out *out __unused,
1170 int param __unused, int value __unused)
1171{
1172 return 0;
1173}
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -08001174
1175int platform_set_audio_device_interface(const char * device_name __unused,
Karthik Reddy Katta508eca42015-05-11 13:43:18 +05301176 const char *intf_name __unused,
1177 const char *codec_type __unused)
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -08001178{
1179 return -ENOSYS;
1180}
Laxminath Kasam82252432015-05-29 18:37:11 +05301181
vivek mehtaa76401a2015-04-24 14:12:15 -07001182bool platform_send_gain_dep_cal(void *platform __unused,
1183 int level __unused)
1184{
1185 return 0;
1186}
Banajit Goswami4dc87fb2015-10-11 21:46:07 -07001187
1188void platform_set_gsm_mode(void *platform __unused, bool enable __unused)
1189{
1190 ALOGE("%s: Not implemented", __func__);
1191}
Xiaojun Sang040cc9f2015-08-03 19:38:28 +08001192
1193bool platform_can_enable_spkr_prot_on_device(snd_device_t snd_device __unused)
1194{
1195 /* speaker protection not implemented for this platform*/
1196 return false;
1197}
1198
1199int platform_get_spkr_prot_acdb_id(snd_device_t snd_device __unused)
1200{
1201 return -ENOSYS;
1202}
1203
1204int platform_get_spkr_prot_snd_device(snd_device_t snd_device __unused)
1205{
1206 return -ENOSYS;
1207}