blob: 941d39f60840f768ac9b8e8ec87ea8016332bd14 [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;
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +053083 bool ec_ref_enabled;
Eric Laurentb23d5282013-05-14 15:27:20 -070084
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -070085 /* Audio calibration related functions */
Eric Laurentb23d5282013-05-14 15:27:20 -070086 void *acdb_handle;
87 acdb_init_t acdb_init;
88 acdb_deallocate_t acdb_deallocate;
89 acdb_send_audio_cal_t acdb_send_audio_cal;
90 acdb_send_voice_cal_t acdb_send_voice_cal;
91
92 /* CSD Client related functions for voice call */
93 void *csd_client;
94 csd_client_init_t csd_client_init;
95 csd_client_deinit_t csd_client_deinit;
96 csd_disable_device_t csd_disable_device;
97 csd_enable_device_t csd_enable_device;
98 csd_volume_t csd_volume;
99 csd_mic_mute_t csd_mic_mute;
100 csd_start_voice_t csd_start_voice;
101 csd_stop_voice_t csd_stop_voice;
102};
103
104static const int pcm_device_table[AUDIO_USECASE_MAX][2] = {
105 [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = {0, 0},
106 [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = {14, 14},
107 [USECASE_AUDIO_PLAYBACK_MULTI_CH] = {1, 1},
108 [USECASE_AUDIO_RECORD] = {0, 0},
109 [USECASE_AUDIO_RECORD_LOW_LATENCY] = {14, 14},
110 [USECASE_VOICE_CALL] = {12, 12},
111};
112
113/* Array to store sound devices */
114static const char * const device_table[SND_DEVICE_MAX] = {
115 [SND_DEVICE_NONE] = "none",
116 /* Playback sound devices */
117 [SND_DEVICE_OUT_HANDSET] = "handset",
118 [SND_DEVICE_OUT_SPEAKER] = "speaker",
119 [SND_DEVICE_OUT_SPEAKER_REVERSE] = "speaker-reverse",
120 [SND_DEVICE_OUT_HEADPHONES] = "headphones",
121 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones",
122 [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker",
123 [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones",
124 [SND_DEVICE_OUT_HDMI] = "hdmi",
125 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi",
126 [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset",
Mingming Yin514a8bc2014-07-29 15:22:21 -0700127 [SND_DEVICE_OUT_BT_SCO_WB] = "bt-sco-headset-wb",
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",
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -0700131 [SND_DEVICE_OUT_USB_HEADSET] = "usb-headphones",
132 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = "speaker-and-usb-headphones",
Eric Laurentb23d5282013-05-14 15:27:20 -0700133
134 /* Capture sound devices */
135 [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
136 [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
137 [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
138 [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic",
139 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "voice-speaker-mic",
140 [SND_DEVICE_IN_HEADSET_MIC_AEC] = "headset-mic",
141 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
142 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
143 [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic",
144 [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
Mingming Yin514a8bc2014-07-29 15:22:21 -0700145 [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700146 [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic",
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700147 [SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef",
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700148 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = "voice-speaker-dmic-ef",
Eric Laurentb23d5282013-05-14 15:27:20 -0700149 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
150 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
151 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
152 [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700153 [SND_DEVICE_IN_VOICE_REC_DMIC] = "voice-rec-dmic-ef",
154 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence",
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -0700155 [SND_DEVICE_IN_USB_HEADSET_MIC] = "usb-headset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700156};
157
158/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
159static const int acdb_device_table[SND_DEVICE_MAX] = {
160 [SND_DEVICE_NONE] = -1,
161 [SND_DEVICE_OUT_HANDSET] = 7,
162 [SND_DEVICE_OUT_SPEAKER] = 14,
163 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 14,
164 [SND_DEVICE_OUT_HEADPHONES] = 10,
165 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
166 [SND_DEVICE_OUT_VOICE_SPEAKER] = 14,
167 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
168 [SND_DEVICE_OUT_HDMI] = 18,
169 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 14,
170 [SND_DEVICE_OUT_BT_SCO] = 22,
Mingming Yin514a8bc2014-07-29 15:22:21 -0700171 [SND_DEVICE_OUT_BT_SCO_WB] = 39,
Eric Laurentb23d5282013-05-14 15:27:20 -0700172 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
173 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
174 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -0700175 [SND_DEVICE_OUT_USB_HEADSET] = 45,
176 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = 14,
Eric Laurentb23d5282013-05-14 15:27:20 -0700177
178 [SND_DEVICE_IN_HANDSET_MIC] = 4,
179 [SND_DEVICE_IN_SPEAKER_MIC] = 4,
180 [SND_DEVICE_IN_HEADSET_MIC] = 8,
181 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 40,
182 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 42,
183 [SND_DEVICE_IN_HEADSET_MIC_AEC] = 47,
184 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
185 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = 8,
186 [SND_DEVICE_IN_HDMI_MIC] = 4,
187 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
Mingming Yin514a8bc2014-07-29 15:22:21 -0700188 [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38,
Eric Laurentb23d5282013-05-14 15:27:20 -0700189 [SND_DEVICE_IN_CAMCORDER_MIC] = 61,
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700190 [SND_DEVICE_IN_VOICE_DMIC] = 6,
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700191 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 13,
Eric Laurentb23d5282013-05-14 15:27:20 -0700192 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
193 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
194 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
195 [SND_DEVICE_IN_VOICE_REC_MIC] = 62,
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -0700196 [SND_DEVICE_IN_USB_HEADSET_MIC] = 44,
Eric Laurentb23d5282013-05-14 15:27:20 -0700197 /* TODO: Update with proper acdb ids */
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700198 [SND_DEVICE_IN_VOICE_REC_DMIC] = 62,
199 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 6,
Eric Laurentb23d5282013-05-14 15:27:20 -0700200};
201
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700202#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
203#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
204
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +0530205void platform_set_echo_reference(void *platform, bool enable)
Eric Laurentb23d5282013-05-14 15:27:20 -0700206{
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +0530207 struct platform_data *my_data = (struct platform_data *)platform;
208 struct audio_device *adev = my_data->adev;
209
210 if (enable) {
211 my_data->ec_ref_enabled = enable;
Anish Kumar4980fa12014-04-17 12:42:20 -0700212 audio_route_apply_and_update_path(adev->audio_route, "echo-reference");
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +0530213 } else {
214 if (my_data->ec_ref_enabled) {
215 audio_route_reset_and_update_path(adev->audio_route, "echo-reference");
216 my_data->ec_ref_enabled = enable;
217 } else {
218 ALOGV("EC Reference is already disabled: %d", my_data->ec_ref_enabled);
219 }
220 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700221
Anish Kumar4980fa12014-04-17 12:42:20 -0700222 ALOGV("Setting EC Reference: %d", enable);
Eric Laurentb23d5282013-05-14 15:27:20 -0700223}
224
225void *platform_init(struct audio_device *adev)
226{
227 char platform[PROPERTY_VALUE_MAX];
228 char baseband[PROPERTY_VALUE_MAX];
229 char value[PROPERTY_VALUE_MAX];
230 struct platform_data *my_data;
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -0700231 const char *snd_card_name;
Eric Laurentb23d5282013-05-14 15:27:20 -0700232
sangwoo1b9f4b32013-06-21 18:22:55 -0700233 adev->mixer = mixer_open(MIXER_CARD);
234
235 if (!adev->mixer) {
236 ALOGE("Unable to open the mixer, aborting.");
237 return NULL;
238 }
239
240 adev->audio_route = audio_route_init(MIXER_CARD, MIXER_XML_PATH);
241 if (!adev->audio_route) {
242 ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
243 return NULL;
244 }
245
Eric Laurentb23d5282013-05-14 15:27:20 -0700246 my_data = calloc(1, sizeof(struct platform_data));
247
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -0700248 snd_card_name = mixer_get_name(adev->mixer);
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -0700249
Eric Laurentb23d5282013-05-14 15:27:20 -0700250 my_data->adev = adev;
Eric Laurentb23d5282013-05-14 15:27:20 -0700251 my_data->fluence_in_spkr_mode = false;
252 my_data->fluence_in_voice_call = false;
253 my_data->fluence_in_voice_rec = false;
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700254 my_data->fluence_type = FLUENCE_NONE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700255
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700256 property_get("ro.qc.sdk.audio.fluencetype", value, "");
257 if (!strncmp("fluencepro", value, sizeof("fluencepro"))) {
258 my_data->fluence_type = FLUENCE_QUAD_MIC;
259 } else if (!strncmp("fluence", value, sizeof("fluence"))) {
260 my_data->fluence_type = FLUENCE_DUAL_MIC;
261 } else {
262 my_data->fluence_type = FLUENCE_NONE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700263 }
264
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700265 if (my_data->fluence_type != FLUENCE_NONE) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700266 property_get("persist.audio.fluence.voicecall",value,"");
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700267 if (!strncmp("true", value, sizeof("true"))) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700268 my_data->fluence_in_voice_call = true;
269 }
270
271 property_get("persist.audio.fluence.voicerec",value,"");
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700272 if (!strncmp("true", value, sizeof("true"))) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700273 my_data->fluence_in_voice_rec = true;
274 }
275
276 property_get("persist.audio.fluence.speaker",value,"");
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700277 if (!strncmp("true", value, sizeof("true"))) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700278 my_data->fluence_in_spkr_mode = true;
279 }
280 }
281
282 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
283 if (my_data->acdb_handle == NULL) {
284 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
285 } else {
286 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
287 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
288 "acdb_loader_deallocate_ACDB");
289 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
290 "acdb_loader_send_audio_cal");
291 if (!my_data->acdb_send_audio_cal)
292 ALOGW("%s: Could not find the symbol acdb_send_audio_cal from %s",
293 __func__, LIB_ACDB_LOADER);
294 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
295 "acdb_loader_send_voice_cal");
296 my_data->acdb_init = (acdb_init_t)dlsym(my_data->acdb_handle,
297 "acdb_loader_init_ACDB");
298 if (my_data->acdb_init == NULL)
299 ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__, dlerror());
300 else
301 my_data->acdb_init();
302 }
303
304 /* If platform is Fusion3, load CSD Client specific symbols
305 * Voice call is handled by MDM and apps processor talks to
306 * MDM through CSD Client
307 */
308 property_get("ro.board.platform", platform, "");
309 property_get("ro.baseband", baseband, "");
310 if (!strcmp("msm8960", platform) && !strcmp("mdm", baseband)) {
311 my_data->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
312 if (my_data->csd_client == NULL)
313 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
314 }
315
316 if (my_data->csd_client) {
317 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
318 my_data->csd_client_deinit = (csd_client_deinit_t)dlsym(my_data->csd_client,
319 "csd_client_deinit");
320 my_data->csd_disable_device = (csd_disable_device_t)dlsym(my_data->csd_client,
321 "csd_client_disable_device");
322 my_data->csd_enable_device = (csd_enable_device_t)dlsym(my_data->csd_client,
323 "csd_client_enable_device");
324 my_data->csd_start_voice = (csd_start_voice_t)dlsym(my_data->csd_client,
325 "csd_client_start_voice");
326 my_data->csd_stop_voice = (csd_stop_voice_t)dlsym(my_data->csd_client,
327 "csd_client_stop_voice");
328 my_data->csd_volume = (csd_volume_t)dlsym(my_data->csd_client,
329 "csd_client_volume");
330 my_data->csd_mic_mute = (csd_mic_mute_t)dlsym(my_data->csd_client,
331 "csd_client_mic_mute");
332 my_data->csd_client_init = (csd_client_init_t)dlsym(my_data->csd_client,
333 "csd_client_init");
334
335 if (my_data->csd_client_init == NULL) {
336 ALOGE("%s: dlsym error %s for csd_client_init", __func__, dlerror());
337 } else {
338 my_data->csd_client_init();
339 }
340 }
341
342 return my_data;
343}
344
345void platform_deinit(void *platform)
346{
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -0700347 struct platform_data *my_data = (struct platform_data *)platform;
348
Eric Laurentb23d5282013-05-14 15:27:20 -0700349 free(platform);
350}
351
352const char *platform_get_snd_device_name(snd_device_t snd_device)
353{
354 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX)
355 return device_table[snd_device];
356 else
357 return "";
358}
359
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -0700360int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
361 char *device_name)
362{
363 struct platform_data *my_data = (struct platform_data *)platform;
364
365 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
366 strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE);
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -0700367 } else {
368 strlcpy(device_name, "", DEVICE_NAME_MAX_SIZE);
369 return -EINVAL;
370 }
371
372 return 0;
373}
374
Eric Laurentb23d5282013-05-14 15:27:20 -0700375void platform_add_backend_name(char *mixer_path, snd_device_t snd_device)
376{
377 if (snd_device == SND_DEVICE_IN_BT_SCO_MIC)
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700378 strlcat(mixer_path, " bt-sco", MIXER_PATH_MAX_LENGTH);
379 else if (snd_device == SND_DEVICE_IN_BT_SCO_MIC_WB)
380 strlcat(mixer_path, " bt-sco-wb", MIXER_PATH_MAX_LENGTH);
Eric Laurentb23d5282013-05-14 15:27:20 -0700381 else if(snd_device == SND_DEVICE_OUT_BT_SCO)
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700382 strlcat(mixer_path, " bt-sco", MIXER_PATH_MAX_LENGTH);
383 else if(snd_device == SND_DEVICE_OUT_BT_SCO_WB)
384 strlcat(mixer_path, " bt-sco-wb", MIXER_PATH_MAX_LENGTH);
Eric Laurentb23d5282013-05-14 15:27:20 -0700385 else if (snd_device == SND_DEVICE_OUT_HDMI)
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700386 strlcat(mixer_path, " hdmi", MIXER_PATH_MAX_LENGTH);
Eric Laurentb23d5282013-05-14 15:27:20 -0700387 else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HDMI)
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700388 strlcat(mixer_path, " speaker-and-hdmi", MIXER_PATH_MAX_LENGTH);
Eric Laurentb23d5282013-05-14 15:27:20 -0700389}
390
391int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
392{
393 int device_id;
394 if (device_type == PCM_PLAYBACK)
395 device_id = pcm_device_table[usecase][0];
396 else
397 device_id = pcm_device_table[usecase][1];
398 return device_id;
399}
400
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -0700401int platform_get_snd_device_index(char *snd_device_index_name __unused)
Ben Romberger61764e32014-01-10 13:49:02 -0800402{
403 return -ENODEV;
404}
405
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -0700406int platform_set_snd_device_acdb_id(snd_device_t snd_device __unused,
407 unsigned int acdb_id __unused)
Ben Romberger55886882014-01-10 13:49:02 -0800408{
409 return -ENODEV;
410}
411
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -0700412uint32_t platform_get_compress_offload_buffer_size(audio_offload_info_t* info __unused)
413{
414 ALOGE("%s: Not implemented", __func__);
415 return -ENOSYS;
416}
417
418int platform_get_snd_device_acdb_id(snd_device_t snd_device __unused)
419{
420 ALOGE("%s: Not implemented", __func__);
421 return -ENOSYS;
422}
423
Amit Shekhar5a39c912014-10-14 15:39:30 -0700424int platform_set_snd_device_bit_width(snd_device_t snd_device, unsigned int bit_width)
425{
426 ALOGE("%s: Not implemented", __func__);
427 return -ENOSYS;
428}
429
430int platform_get_snd_device_bit_width(snd_device_t snd_device)
431{
432 ALOGE("%s: Not implemented", __func__);
433 return -ENOSYS;
434}
435
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -0700436int platform_switch_voice_call_enable_device_config(void *platform __unused,
437 snd_device_t out_snd_device __unused,
438 snd_device_t in_snd_device __unused)
439{
440 ALOGE("%s: Not implemented", __func__);
441 return -ENOSYS;
442}
443
444int platform_switch_voice_call_usecase_route_post(void *platform __unused,
445 snd_device_t out_snd_device __unused,
446 snd_device_t in_snd_device __unused)
447{
448 ALOGE("%s: Not implemented", __func__);
449 return -ENOSYS;
450}
451
452int platform_set_incall_recording_session_id(void *platform __unused,
453 uint32_t session_id __unused,
454 int rec_mode __unused)
455{
456 ALOGE("%s: Not implemented", __func__);
457 return -ENOSYS;
458}
459
460int platform_stop_incall_recording_usecase(void *platform __unused)
461{
462 ALOGE("%s: Not implemented", __func__);
463 return -ENOSYS;
464}
465
466int platform_get_sample_rate(void *platform __unused, uint32_t *rate __unused)
467{
468 ALOGE("%s: Not implemented", __func__);
469 return -ENOSYS;
470}
471
472int platform_get_default_app_type(void *platform __unused)
473{
474 ALOGE("%s: Not implemented", __func__);
475 return -ENOSYS;
476}
477
478int platform_send_audio_calibration(void *platform, snd_device_t snd_device,
479 int app_type __unused, int sample_rate __unused)
Eric Laurentb23d5282013-05-14 15:27:20 -0700480{
481 struct platform_data *my_data = (struct platform_data *)platform;
482 int acdb_dev_id, acdb_dev_type;
483
484 acdb_dev_id = acdb_device_table[snd_device];
485 if (acdb_dev_id < 0) {
486 ALOGE("%s: Could not find acdb id for device(%d)",
487 __func__, snd_device);
488 return -EINVAL;
489 }
490 if (my_data->acdb_send_audio_cal) {
Eric Laurent994a6932013-07-17 11:51:42 -0700491 ("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Eric Laurentb23d5282013-05-14 15:27:20 -0700492 __func__, snd_device, acdb_dev_id);
493 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
494 snd_device < SND_DEVICE_OUT_END)
495 acdb_dev_type = ACDB_DEV_TYPE_OUT;
496 else
497 acdb_dev_type = ACDB_DEV_TYPE_IN;
498 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
499 }
500 return 0;
501}
502
503int platform_switch_voice_call_device_pre(void *platform)
504{
505 struct platform_data *my_data = (struct platform_data *)platform;
506 int ret = 0;
507
Ravi Kumar Alamandabe149392014-10-20 17:07:43 -0700508 if (my_data->csd_client != NULL &&
509 voice_is_in_call(my_data->adev)) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700510 /* This must be called before disabling the mixer controls on APQ side */
511 if (my_data->csd_disable_device == NULL) {
512 ALOGE("%s: dlsym error for csd_disable_device", __func__);
513 } else {
514 ret = my_data->csd_disable_device();
515 if (ret < 0) {
516 ALOGE("%s: csd_client_disable_device, failed, error %d",
517 __func__, ret);
518 }
519 }
520 }
521 return ret;
522}
523
524int platform_switch_voice_call_device_post(void *platform,
525 snd_device_t out_snd_device,
526 snd_device_t in_snd_device)
527{
528 struct platform_data *my_data = (struct platform_data *)platform;
529 int acdb_rx_id, acdb_tx_id;
530 int ret = 0;
531
532 if (my_data->csd_client) {
533 if (my_data->csd_enable_device == NULL) {
534 ALOGE("%s: dlsym error for csd_enable_device",
535 __func__);
536 } else {
537 acdb_rx_id = acdb_device_table[out_snd_device];
538 acdb_tx_id = acdb_device_table[in_snd_device];
539
540 if (acdb_rx_id > 0 || acdb_tx_id > 0) {
541 ret = my_data->csd_enable_device(acdb_rx_id, acdb_tx_id,
542 my_data->adev->acdb_settings);
543 if (ret < 0) {
544 ALOGE("%s: csd_enable_device, failed, error %d",
545 __func__, ret);
546 }
547 } else {
548 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
549 acdb_rx_id, acdb_tx_id);
550 }
551 }
552 }
553
554 return ret;
555}
556
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -0700557int platform_start_voice_call(void *platform, uint32_t vsid __unused)
Eric Laurentb23d5282013-05-14 15:27:20 -0700558{
559 struct platform_data *my_data = (struct platform_data *)platform;
560 int ret = 0;
561
562 if (my_data->csd_client) {
563 if (my_data->csd_start_voice == NULL) {
564 ALOGE("dlsym error for csd_client_start_voice");
565 ret = -ENOSYS;
566 } else {
567 ret = my_data->csd_start_voice();
568 if (ret < 0) {
569 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
570 }
571 }
572 }
573
574 return ret;
575}
576
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -0700577int platform_stop_voice_call(void *platform, uint32_t vsid __unused)
Eric Laurentb23d5282013-05-14 15:27:20 -0700578{
579 struct platform_data *my_data = (struct platform_data *)platform;
580 int ret = 0;
581
582 if (my_data->csd_client) {
583 if (my_data->csd_stop_voice == NULL) {
584 ALOGE("dlsym error for csd_stop_voice");
585 } else {
586 ret = my_data->csd_stop_voice();
587 if (ret < 0) {
588 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
589 }
590 }
591 }
592
593 return ret;
594}
595
596int platform_set_voice_volume(void *platform, int volume)
597{
598 struct platform_data *my_data = (struct platform_data *)platform;
599 int ret = 0;
600
601 if (my_data->csd_client) {
602 if (my_data->csd_volume == NULL) {
603 ALOGE("%s: dlsym error for csd_volume", __func__);
604 } else {
605 ret = my_data->csd_volume(volume);
606 if (ret < 0) {
607 ALOGE("%s: csd_volume error %d", __func__, ret);
608 }
609 }
610 } else {
611 ALOGE("%s: No CSD Client present", __func__);
612 }
613
614 return ret;
615}
616
617int platform_set_mic_mute(void *platform, bool state)
618{
619 struct platform_data *my_data = (struct platform_data *)platform;
620 int ret = 0;
621
622 if (my_data->adev->mode == AUDIO_MODE_IN_CALL) {
623 if (my_data->csd_client) {
624 if (my_data->csd_mic_mute == NULL) {
625 ALOGE("%s: dlsym error for csd_mic_mute", __func__);
626 } else {
627 ret = my_data->csd_mic_mute(state);
628 if (ret < 0) {
629 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
630 }
631 }
632 } else {
633 ALOGE("%s: No CSD Client present", __func__);
634 }
635 }
636
637 return ret;
638}
639
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -0700640int platform_set_device_mute(void *platform __unused, bool state __unused, char *dir __unused)
Shiv Maliyappanahallic6fd8ee2014-03-07 15:31:55 -0800641{
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -0700642 ALOGE("%s: Not implemented", __func__);
Shiv Maliyappanahallic6fd8ee2014-03-07 15:31:55 -0800643 return -ENOSYS;
644}
645
Eric Laurentb23d5282013-05-14 15:27:20 -0700646snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
647{
648 struct platform_data *my_data = (struct platform_data *)platform;
649 struct audio_device *adev = my_data->adev;
650 audio_mode_t mode = adev->mode;
651 snd_device_t snd_device = SND_DEVICE_NONE;
652
653 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
654 if (devices == AUDIO_DEVICE_NONE ||
655 devices & AUDIO_DEVICE_BIT_IN) {
656 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
657 goto exit;
658 }
659
Ravi Kumar Alamandabe149392014-10-20 17:07:43 -0700660 if (voice_is_in_call(adev)) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700661 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
662 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -0700663 if (adev->voice.tty_mode == TTY_MODE_FULL)
Eric Laurentb23d5282013-05-14 15:27:20 -0700664 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -0700665 else if (adev->voice.tty_mode == TTY_MODE_VCO)
Eric Laurentb23d5282013-05-14 15:27:20 -0700666 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -0700667 else if (adev->voice.tty_mode == TTY_MODE_HCO)
Eric Laurentb23d5282013-05-14 15:27:20 -0700668 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
669 else
670 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
671 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Mingming Yin514a8bc2014-07-29 15:22:21 -0700672 if (adev->bt_wb_speech_enabled)
673 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
674 else
675 snd_device = SND_DEVICE_OUT_BT_SCO;
Eric Laurentb23d5282013-05-14 15:27:20 -0700676 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
677 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
678 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Ravi Kumar Alamandaceb40822013-11-06 11:01:47 -0800679 snd_device = SND_DEVICE_OUT_HANDSET;
Eric Laurentb23d5282013-05-14 15:27:20 -0700680 }
681 if (snd_device != SND_DEVICE_NONE) {
682 goto exit;
683 }
684 }
685
686 if (popcount(devices) == 2) {
687 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
688 AUDIO_DEVICE_OUT_SPEAKER)) {
689 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
690 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
691 AUDIO_DEVICE_OUT_SPEAKER)) {
692 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
693 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
694 AUDIO_DEVICE_OUT_SPEAKER)) {
695 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
696 } else {
697 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
698 goto exit;
699 }
700 if (snd_device != SND_DEVICE_NONE) {
701 goto exit;
702 }
703 }
704
705 if (popcount(devices) != 1) {
706 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
707 goto exit;
708 }
709
710 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
711 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
712 snd_device = SND_DEVICE_OUT_HEADPHONES;
713 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
714 if (adev->speaker_lr_swap)
715 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
716 else
717 snd_device = SND_DEVICE_OUT_SPEAKER;
718 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Mingming Yin514a8bc2014-07-29 15:22:21 -0700719 if (adev->bt_wb_speech_enabled)
720 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
721 else
722 snd_device = SND_DEVICE_OUT_BT_SCO;
Eric Laurentb23d5282013-05-14 15:27:20 -0700723 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
724 snd_device = SND_DEVICE_OUT_HDMI ;
725 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
726 snd_device = SND_DEVICE_OUT_HANDSET;
727 } else {
728 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
729 }
730exit:
731 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
732 return snd_device;
733}
734
735snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
736{
737 struct platform_data *my_data = (struct platform_data *)platform;
738 struct audio_device *adev = my_data->adev;
739 audio_source_t source = (adev->active_input == NULL) ?
740 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
741
742 audio_mode_t mode = adev->mode;
743 audio_devices_t in_device = ((adev->active_input == NULL) ?
744 AUDIO_DEVICE_NONE : adev->active_input->device)
745 & ~AUDIO_DEVICE_BIT_IN;
746 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
747 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
748 snd_device_t snd_device = SND_DEVICE_NONE;
749
750 ALOGV("%s: enter: out_device(%#x) in_device(%#x)",
751 __func__, out_device, in_device);
Ravi Kumar Alamandabe149392014-10-20 17:07:43 -0700752 if ((out_device != AUDIO_DEVICE_NONE) && voice_is_in_call(adev)) {
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -0700753 if (adev->voice.tty_mode != TTY_MODE_OFF) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700754 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
755 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -0700756 switch (adev->voice.tty_mode) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700757 case TTY_MODE_FULL:
758 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
759 break;
760 case TTY_MODE_VCO:
761 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
762 break;
763 case TTY_MODE_HCO:
764 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
765 break;
766 default:
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -0700767 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
Eric Laurentb23d5282013-05-14 15:27:20 -0700768 }
769 goto exit;
770 }
771 }
772 if (out_device & AUDIO_DEVICE_OUT_EARPIECE ||
773 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700774 if (my_data->fluence_type == FLUENCE_NONE ||
775 my_data->fluence_in_voice_call == false) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700776 snd_device = SND_DEVICE_IN_HANDSET_MIC;
777 } else {
Ravi Kumar Alamandaceb40822013-11-06 11:01:47 -0800778 snd_device = SND_DEVICE_IN_VOICE_DMIC;
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700779 adev->acdb_settings |= DMIC_FLAG;
Eric Laurentb23d5282013-05-14 15:27:20 -0700780 }
781 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
782 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
783 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Mingming Yin514a8bc2014-07-29 15:22:21 -0700784 if (adev->bt_wb_speech_enabled)
785 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
786 else
787 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -0700788 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700789 if (my_data->fluence_type != FLUENCE_NONE &&
790 my_data->fluence_in_voice_call &&
791 my_data->fluence_in_spkr_mode) {
792 if(my_data->fluence_type == FLUENCE_DUAL_MIC) {
793 adev->acdb_settings |= DMIC_FLAG;
794 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
795 } else {
796 adev->acdb_settings |= QMIC_FLAG;
797 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_QMIC;
798 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700799 } else {
800 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
801 }
802 }
803 } else if (source == AUDIO_SOURCE_CAMCORDER) {
804 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
805 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
806 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
807 }
808 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
809 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700810 if (channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK)
811 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC;
812 else if (my_data->fluence_in_voice_rec)
813 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700814
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700815 if (snd_device == SND_DEVICE_NONE)
Eric Laurentb23d5282013-05-14 15:27:20 -0700816 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700817 else
818 adev->acdb_settings |= DMIC_FLAG;
Eric Laurentb23d5282013-05-14 15:27:20 -0700819 }
820 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION) {
821 if (out_device & AUDIO_DEVICE_OUT_SPEAKER)
822 in_device = AUDIO_DEVICE_IN_BACK_MIC;
823 if (adev->active_input) {
824 if (adev->active_input->enable_aec) {
825 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
826 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
827 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
828 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
829 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
830 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
831 }
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +0530832 platform_set_echo_reference(adev->platform, true);
Eric Laurentb23d5282013-05-14 15:27:20 -0700833 } else
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +0530834 platform_set_echo_reference(adev->platform, false);
Eric Laurentb23d5282013-05-14 15:27:20 -0700835 }
836 } else if (source == AUDIO_SOURCE_DEFAULT) {
837 goto exit;
838 }
839
840
841 if (snd_device != SND_DEVICE_NONE) {
842 goto exit;
843 }
844
845 if (in_device != AUDIO_DEVICE_NONE &&
846 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
847 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
848 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
849 snd_device = SND_DEVICE_IN_HANDSET_MIC;
850 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
851 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
852 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
853 snd_device = SND_DEVICE_IN_HEADSET_MIC;
854 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Mingming Yin514a8bc2014-07-29 15:22:21 -0700855 if (adev->bt_wb_speech_enabled)
856 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
857 else
858 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -0700859 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
860 snd_device = SND_DEVICE_IN_HDMI_MIC;
861 } else {
862 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
863 ALOGW("%s: Using default handset-mic", __func__);
864 snd_device = SND_DEVICE_IN_HANDSET_MIC;
865 }
866 } else {
867 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
868 snd_device = SND_DEVICE_IN_HANDSET_MIC;
869 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
870 snd_device = SND_DEVICE_IN_HEADSET_MIC;
871 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
872 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
873 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
874 snd_device = SND_DEVICE_IN_HANDSET_MIC;
875 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Mingming Yin514a8bc2014-07-29 15:22:21 -0700876 if (adev->bt_wb_speech_enabled)
877 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
878 else
879 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -0700880 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
881 snd_device = SND_DEVICE_IN_HDMI_MIC;
882 } else {
883 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
884 ALOGW("%s: Using default handset-mic", __func__);
885 snd_device = SND_DEVICE_IN_HANDSET_MIC;
886 }
887 }
888exit:
889 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
890 return snd_device;
891}
892
893int platform_set_hdmi_channels(void *platform, int channel_count)
894{
895 struct platform_data *my_data = (struct platform_data *)platform;
896 struct audio_device *adev = my_data->adev;
897 struct mixer_ctl *ctl;
898 const char *channel_cnt_str = NULL;
899 const char *mixer_ctl_name = "HDMI_RX Channels";
900 switch (channel_count) {
901 case 8:
902 channel_cnt_str = "Eight"; break;
903 case 7:
904 channel_cnt_str = "Seven"; break;
905 case 6:
906 channel_cnt_str = "Six"; break;
907 case 5:
908 channel_cnt_str = "Five"; break;
909 case 4:
910 channel_cnt_str = "Four"; break;
911 case 3:
912 channel_cnt_str = "Three"; break;
913 default:
914 channel_cnt_str = "Two"; break;
915 }
916 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
917 if (!ctl) {
918 ALOGE("%s: Could not get ctl for mixer cmd - %s",
919 __func__, mixer_ctl_name);
920 return -EINVAL;
921 }
922 ALOGV("HDMI channel count: %s", channel_cnt_str);
923 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
924 return 0;
925}
926
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -0700927int platform_edid_get_max_channels(void *platform __unused)
Eric Laurentb23d5282013-05-14 15:27:20 -0700928{
929 FILE *file;
930 struct audio_block_header header;
931 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
932 char *sad = block;
933 int num_audio_blocks;
934 int channel_count;
935 int max_channels = 0;
936 int i;
937
938 file = fopen(AUDIO_DATA_BLOCK_PATH, "rb");
939 if (file == NULL) {
940 ALOGE("Unable to open '%s'", AUDIO_DATA_BLOCK_PATH);
941 return 0;
942 }
943
944 /* Read audio block header */
945 fread(&header, 1, sizeof(header), file);
946
947 /* Read SAD blocks, clamping the maximum size for safety */
948 if (header.length > (int)sizeof(block))
949 header.length = (int)sizeof(block);
950 fread(&block, header.length, 1, file);
951
952 fclose(file);
953
954 /* Calculate the number of SAD blocks */
955 num_audio_blocks = header.length / SAD_BLOCK_SIZE;
956
957 for (i = 0; i < num_audio_blocks; i++) {
958 /* Only consider LPCM blocks */
959 if ((sad[0] >> 3) != EDID_FORMAT_LPCM)
960 continue;
961
962 channel_count = (sad[0] & 0x7) + 1;
963 if (channel_count > max_channels)
964 max_channels = channel_count;
965
966 /* Advance to next block */
967 sad += 3;
968 }
969
970 return max_channels;
971}
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700972
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -0700973void platform_get_parameters(void *platform __unused,
974 struct str_parms *query __unused,
975 struct str_parms *reply __unused)
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700976{
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -0700977 ALOGE("%s: Not implemented", __func__);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700978}
979
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -0700980int platform_set_parameters(void *platform __unused, struct str_parms *parms __unused)
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700981{
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -0700982 ALOGE("%s: Not implemented", __func__);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700983 return -ENOSYS;
984}
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700985
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -0700986int platform_set_incall_recoding_session_id(void *platform __unused,
987 uint32_t session_id __unused)
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700988{
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -0700989 ALOGE("%s: Not implemented", __func__);
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700990 return -ENOSYS;
991}
Shruthi Krishnaace10852013-10-25 14:32:12 -0700992
Vidyakumar Athota21b3bb92014-04-25 11:08:08 -0700993int platform_update_lch(void *platform __unused,
994 struct voice_session *session __unused,
995 enum voice_lch_mode lch_mode __unused)
996{
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -0700997 ALOGE("%s: Not implemented", __func__);
998 return -ENOSYS;
999}
1000
1001int platform_start_incall_music_usecase(void *platform __unused)
1002{
1003 ALOGE("%s: Not implemented", __func__);
1004 return -ENOSYS;
1005}
1006
1007int platform_stop_incall_music_usecase(void *platform __unused)
1008{
1009 ALOGE("%s: Not implemented", __func__);
Vidyakumar Athota21b3bb92014-04-25 11:08:08 -07001010 return -ENOSYS;
1011}
1012
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07001013/* Delay in Us */
1014int64_t platform_render_latency(audio_usecase_t usecase)
1015{
1016 switch (usecase) {
1017 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
1018 return DEEP_BUFFER_PLATFORM_DELAY;
1019 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
1020 return LOW_LATENCY_PLATFORM_DELAY;
1021 default:
1022 return 0;
1023 }
1024}
Mingming Yine62d7842013-10-25 16:26:03 -07001025
1026int platform_update_usecase_from_source(int source, int usecase)
1027{
1028 ALOGV("%s: input source :%d", __func__, source);
1029 return usecase;
1030}
Kiran Kandide144c82013-11-20 15:58:32 -08001031
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07001032bool platform_listen_device_needs_event(snd_device_t snd_device __unused)
Kiran Kandide144c82013-11-20 15:58:32 -08001033{
Dhananjay Kumar45b71742014-05-29 21:47:27 +05301034 return false;
1035}
1036
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07001037bool platform_listen_usecase_needs_event(audio_usecase_t uc_id __unused)
Dhananjay Kumar45b71742014-05-29 21:47:27 +05301038{
1039 return false;
Kiran Kandide144c82013-11-20 15:58:32 -08001040}
Mingming Yin3ee55c62014-08-04 14:23:35 -07001041
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07001042bool platform_check_and_set_codec_backend_cfg(struct audio_device* adev __unused,
1043 struct audio_usecase *usecase __unused)
1044{
Mingming Yin3ee55c62014-08-04 14:23:35 -07001045 return false;
1046}
1047
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001048int platform_get_usecase_index(const char * usecase __unused)
1049{
1050 return -ENOSYS;
1051}
1052
1053int platform_set_usecase_pcm_id(audio_usecase_t usecase __unused, int32_t type __unused,
1054 int32_t pcm_id __unused)
1055{
1056 return -ENOSYS;
1057}
1058
1059int platform_set_snd_device_backend(snd_device_t snd_device __unused,
1060 const char * backend __unused)
1061{
1062 return -ENOSYS;
1063}
Ravi Kumar Alamanda8fa6b192014-09-09 16:06:42 -07001064
1065bool platform_sound_trigger_device_needs_event(snd_device_t snd_device __unused)
1066{
1067 return false;
1068}
1069
1070bool platform_sound_trigger_usecase_needs_event(audio_usecase_t uc_id __unused)
1071{
1072 return false;
1073}
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07001074
1075int platform_set_fluence_type(void *platform __unused, char *value __unused)
1076{
1077 return -ENOSYS;
1078}
1079
1080int platform_get_fluence_type(void *platform __unused, char *value __unused,
1081 uint32_t len __unused)
1082{
1083 return -ENOSYS;
1084}
1085
1086uint32_t platform_get_pcm_offload_buffer_size(audio_offload_info_t* info __unused)
1087{
1088 return 0;
1089}