blob: c75efbe6e783401a2b3b80f06583238536cc269b [file] [log] [blame]
Eric Laurentb23d5282013-05-14 15:27:20 -07001/*
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002 * Copyright (C) 2013-2014 The Android Open Source Project
Eric Laurentb23d5282013-05-14 15:27:20 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#define LOG_TAG "msm8960_platform"
18/*#define LOG_NDEBUG 0*/
19#define LOG_NDDEBUG 0
20
21#include <stdlib.h>
22#include <dlfcn.h>
23#include <cutils/log.h>
24#include <cutils/properties.h>
25#include <audio_hw.h>
26#include <platform_api.h>
27#include "platform.h"
28
29#define LIB_ACDB_LOADER "libacdbloader.so"
30#define LIB_CSD_CLIENT "libcsd-client.so"
31
32#define DUALMIC_CONFIG_NONE 0 /* Target does not contain 2 mics */
33#define DUALMIC_CONFIG_ENDFIRE 1
34#define DUALMIC_CONFIG_BROADSIDE 2
35
36/*
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
77/* Audio calibration related functions */
78struct platform_data {
79 struct audio_device *adev;
80 bool fluence_in_spkr_mode;
81 bool fluence_in_voice_call;
82 bool fluence_in_voice_rec;
83 int dualmic_config;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -070084 bool speaker_lr_swap;
Eric Laurentb23d5282013-05-14 15:27:20 -070085
86 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",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700127 [SND_DEVICE_OUT_BT_SCO_WB] = "bt-sco-headset-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700128 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = "voice-handset-tmus",
129 [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",
132
133 /* Capture sound devices */
134 [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
135 [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
136 [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
137 [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic",
138 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "voice-speaker-mic",
139 [SND_DEVICE_IN_HEADSET_MIC_AEC] = "headset-mic",
140 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
141 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
142 [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic",
143 [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700144 [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700145 [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic",
146 [SND_DEVICE_IN_VOICE_DMIC_EF] = "voice-dmic-ef",
147 [SND_DEVICE_IN_VOICE_DMIC_BS] = "voice-dmic-bs",
148 [SND_DEVICE_IN_VOICE_DMIC_EF_TMUS] = "voice-dmic-ef-tmus",
149 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_EF] = "voice-speaker-dmic-ef",
150 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BS] = "voice-speaker-dmic-bs",
151 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
152 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
153 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
154 [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
155 [SND_DEVICE_IN_VOICE_REC_DMIC_EF] = "voice-rec-dmic-ef",
156 [SND_DEVICE_IN_VOICE_REC_DMIC_BS] = "voice-rec-dmic-bs",
157 [SND_DEVICE_IN_VOICE_REC_DMIC_EF_FLUENCE] = "voice-rec-dmic-ef-fluence",
158 [SND_DEVICE_IN_VOICE_REC_DMIC_BS_FLUENCE] = "voice-rec-dmic-bs-fluence",
159};
160
161/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
162static const int acdb_device_table[SND_DEVICE_MAX] = {
163 [SND_DEVICE_NONE] = -1,
164 [SND_DEVICE_OUT_HANDSET] = 7,
165 [SND_DEVICE_OUT_SPEAKER] = 14,
166 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 14,
167 [SND_DEVICE_OUT_HEADPHONES] = 10,
168 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
169 [SND_DEVICE_OUT_VOICE_SPEAKER] = 14,
170 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
171 [SND_DEVICE_OUT_HDMI] = 18,
172 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 14,
173 [SND_DEVICE_OUT_BT_SCO] = 22,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700174 [SND_DEVICE_OUT_BT_SCO_WB] = 39,
Eric Laurentb23d5282013-05-14 15:27:20 -0700175 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = 81,
176 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
177 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
178 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
179
180 [SND_DEVICE_IN_HANDSET_MIC] = 4,
181 [SND_DEVICE_IN_SPEAKER_MIC] = 4,
182 [SND_DEVICE_IN_HEADSET_MIC] = 8,
183 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 40,
184 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 42,
185 [SND_DEVICE_IN_HEADSET_MIC_AEC] = 47,
186 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
187 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = 8,
188 [SND_DEVICE_IN_HDMI_MIC] = 4,
189 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700190 [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38,
Eric Laurentb23d5282013-05-14 15:27:20 -0700191 [SND_DEVICE_IN_CAMCORDER_MIC] = 61,
192 [SND_DEVICE_IN_VOICE_DMIC_EF] = 6,
193 [SND_DEVICE_IN_VOICE_DMIC_BS] = 5,
194 [SND_DEVICE_IN_VOICE_DMIC_EF_TMUS] = 91,
195 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_EF] = 13,
196 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BS] = 12,
197 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
198 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
199 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
200 [SND_DEVICE_IN_VOICE_REC_MIC] = 62,
201 /* TODO: Update with proper acdb ids */
202 [SND_DEVICE_IN_VOICE_REC_DMIC_EF] = 62,
203 [SND_DEVICE_IN_VOICE_REC_DMIC_BS] = 62,
204 [SND_DEVICE_IN_VOICE_REC_DMIC_EF_FLUENCE] = 6,
205 [SND_DEVICE_IN_VOICE_REC_DMIC_BS_FLUENCE] = 5,
206};
207
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700208#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
209#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
210
Eric Laurentb23d5282013-05-14 15:27:20 -0700211static pthread_once_t check_op_once_ctl = PTHREAD_ONCE_INIT;
212static bool is_tmus = false;
213
214static void check_operator()
215{
216 char value[PROPERTY_VALUE_MAX];
217 int mccmnc;
218 property_get("gsm.sim.operator.numeric",value,"0");
219 mccmnc = atoi(value);
220 ALOGD("%s: tmus mccmnc %d", __func__, mccmnc);
221 switch(mccmnc) {
222 /* TMUS MCC(310), MNC(490, 260, 026) */
223 case 310490:
224 case 310260:
225 case 310026:
226 is_tmus = true;
227 break;
228 }
229}
230
231bool is_operator_tmus()
232{
233 pthread_once(&check_op_once_ctl, check_operator);
234 return is_tmus;
235}
236
237static int set_echo_reference(struct mixer *mixer, const char* ec_ref)
238{
239 struct mixer_ctl *ctl;
240 const char *mixer_ctl_name = "EC_REF_RX";
241
242 ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name);
243 if (!ctl) {
244 ALOGE("%s: Could not get ctl for mixer cmd - %s",
245 __func__, mixer_ctl_name);
246 return -EINVAL;
247 }
248 ALOGV("Setting EC Reference: %s", ec_ref);
249 mixer_ctl_set_enum_by_string(ctl, ec_ref);
250 return 0;
251}
252
253void *platform_init(struct audio_device *adev)
254{
255 char platform[PROPERTY_VALUE_MAX];
256 char baseband[PROPERTY_VALUE_MAX];
257 char value[PROPERTY_VALUE_MAX];
258 struct platform_data *my_data;
259
sangwoo1b9f4b32013-06-21 18:22:55 -0700260 adev->mixer = mixer_open(MIXER_CARD);
261
262 if (!adev->mixer) {
263 ALOGE("Unable to open the mixer, aborting.");
264 return NULL;
265 }
266
267 adev->audio_route = audio_route_init(MIXER_CARD, MIXER_XML_PATH);
268 if (!adev->audio_route) {
269 ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
270 return NULL;
271 }
272
Eric Laurentb23d5282013-05-14 15:27:20 -0700273 my_data = calloc(1, sizeof(struct platform_data));
274
275 my_data->adev = adev;
276 my_data->dualmic_config = DUALMIC_CONFIG_NONE;
277 my_data->fluence_in_spkr_mode = false;
278 my_data->fluence_in_voice_call = false;
279 my_data->fluence_in_voice_rec = false;
280
281 property_get("persist.audio.dualmic.config",value,"");
282 if (!strcmp("broadside", value)) {
283 my_data->dualmic_config = DUALMIC_CONFIG_BROADSIDE;
284 adev->acdb_settings |= DMIC_FLAG;
285 } else if (!strcmp("endfire", value)) {
286 my_data->dualmic_config = DUALMIC_CONFIG_ENDFIRE;
287 adev->acdb_settings |= DMIC_FLAG;
288 }
289
290 if (my_data->dualmic_config != DUALMIC_CONFIG_NONE) {
291 property_get("persist.audio.fluence.voicecall",value,"");
292 if (!strcmp("true", value)) {
293 my_data->fluence_in_voice_call = true;
294 }
295
296 property_get("persist.audio.fluence.voicerec",value,"");
297 if (!strcmp("true", value)) {
298 my_data->fluence_in_voice_rec = true;
299 }
300
301 property_get("persist.audio.fluence.speaker",value,"");
302 if (!strcmp("true", value)) {
303 my_data->fluence_in_spkr_mode = true;
304 }
305 }
306
307 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
308 if (my_data->acdb_handle == NULL) {
309 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
310 } else {
311 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
312 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
313 "acdb_loader_deallocate_ACDB");
314 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
315 "acdb_loader_send_audio_cal");
316 if (!my_data->acdb_send_audio_cal)
317 ALOGW("%s: Could not find the symbol acdb_send_audio_cal from %s",
318 __func__, LIB_ACDB_LOADER);
319 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
320 "acdb_loader_send_voice_cal");
321 my_data->acdb_init = (acdb_init_t)dlsym(my_data->acdb_handle,
322 "acdb_loader_init_ACDB");
323 if (my_data->acdb_init == NULL)
324 ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__, dlerror());
325 else
326 my_data->acdb_init();
327 }
328
329 /* If platform is Fusion3, load CSD Client specific symbols
330 * Voice call is handled by MDM and apps processor talks to
331 * MDM through CSD Client
332 */
333 property_get("ro.board.platform", platform, "");
334 property_get("ro.baseband", baseband, "");
335 if (!strcmp("msm8960", platform) && !strcmp("mdm", baseband)) {
336 my_data->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
337 if (my_data->csd_client == NULL)
338 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
339 }
340
341 if (my_data->csd_client) {
342 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
343 my_data->csd_client_deinit = (csd_client_deinit_t)dlsym(my_data->csd_client,
344 "csd_client_deinit");
345 my_data->csd_disable_device = (csd_disable_device_t)dlsym(my_data->csd_client,
346 "csd_client_disable_device");
347 my_data->csd_enable_device = (csd_enable_device_t)dlsym(my_data->csd_client,
348 "csd_client_enable_device");
349 my_data->csd_start_voice = (csd_start_voice_t)dlsym(my_data->csd_client,
350 "csd_client_start_voice");
351 my_data->csd_stop_voice = (csd_stop_voice_t)dlsym(my_data->csd_client,
352 "csd_client_stop_voice");
353 my_data->csd_volume = (csd_volume_t)dlsym(my_data->csd_client,
354 "csd_client_volume");
355 my_data->csd_mic_mute = (csd_mic_mute_t)dlsym(my_data->csd_client,
356 "csd_client_mic_mute");
357 my_data->csd_client_init = (csd_client_init_t)dlsym(my_data->csd_client,
358 "csd_client_init");
359
360 if (my_data->csd_client_init == NULL) {
361 ALOGE("%s: dlsym error %s for csd_client_init", __func__, dlerror());
362 } else {
363 my_data->csd_client_init();
364 }
365 }
366
367 return my_data;
368}
369
370void platform_deinit(void *platform)
371{
372 free(platform);
373}
374
375const char *platform_get_snd_device_name(snd_device_t snd_device)
376{
377 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX)
378 return device_table[snd_device];
379 else
Ravi Kumar Alamanda64026462014-09-15 00:08:58 -0700380 return "none";
Eric Laurentb23d5282013-05-14 15:27:20 -0700381}
382
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -0500383void platform_add_backend_name(void *platform __unused, char *mixer_path,
384 snd_device_t snd_device)
Eric Laurentb23d5282013-05-14 15:27:20 -0700385{
386 if (snd_device == SND_DEVICE_IN_BT_SCO_MIC)
387 strcat(mixer_path, " bt-sco");
388 else if(snd_device == SND_DEVICE_OUT_BT_SCO)
389 strcat(mixer_path, " bt-sco");
390 else if (snd_device == SND_DEVICE_OUT_HDMI)
391 strcat(mixer_path, " hdmi");
392 else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HDMI)
393 strcat(mixer_path, " speaker-and-hdmi");
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700394 else if (snd_device == SND_DEVICE_OUT_BT_SCO_WB ||
395 snd_device == SND_DEVICE_IN_BT_SCO_MIC_WB)
396 strcat(mixer_path, " bt-sco-wb");
Eric Laurentb23d5282013-05-14 15:27:20 -0700397}
398
399int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
400{
401 int device_id;
402 if (device_type == PCM_PLAYBACK)
403 device_id = pcm_device_table[usecase][0];
404 else
405 device_id = pcm_device_table[usecase][1];
406 return device_id;
407}
408
Haynes Mathew George98c95622014-06-20 19:14:25 -0700409int platform_get_snd_device_index(char *snd_device_index_name __unused)
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700410{
411 return -ENODEV;
412}
413
Haynes Mathew George98c95622014-06-20 19:14:25 -0700414int platform_set_snd_device_acdb_id(snd_device_t snd_device __unused,
415 unsigned int acdb_id __unused)
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700416{
417 return -ENODEV;
418}
419
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700420int platform_get_snd_device_acdb_id(snd_device_t snd_device __unused)
421{
422 ALOGE("%s: Not implemented", __func__);
423 return -ENOSYS;
424}
425
keunhui.park2f7306a2015-07-16 16:48:06 +0900426void platform_add_operator_specific_device(snd_device_t snd_device,
427 const char *operator,
428 const char *mixer_path,
429 unsigned int acdb_id)
430{
431}
432
Eric Laurentb23d5282013-05-14 15:27:20 -0700433int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
434{
435 struct platform_data *my_data = (struct platform_data *)platform;
436 int acdb_dev_id, acdb_dev_type;
437
438 acdb_dev_id = acdb_device_table[snd_device];
439 if (acdb_dev_id < 0) {
440 ALOGE("%s: Could not find acdb id for device(%d)",
441 __func__, snd_device);
442 return -EINVAL;
443 }
444 if (my_data->acdb_send_audio_cal) {
Eric Laurent994a6932013-07-17 11:51:42 -0700445 ("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Eric Laurentb23d5282013-05-14 15:27:20 -0700446 __func__, snd_device, acdb_dev_id);
447 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
448 snd_device < SND_DEVICE_OUT_END)
449 acdb_dev_type = ACDB_DEV_TYPE_OUT;
450 else
451 acdb_dev_type = ACDB_DEV_TYPE_IN;
452 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
453 }
454 return 0;
455}
456
457int platform_switch_voice_call_device_pre(void *platform)
458{
459 struct platform_data *my_data = (struct platform_data *)platform;
460 int ret = 0;
461
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -0700462 if (my_data->csd_client != NULL &&
463 voice_is_in_call(my_data->adev)) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700464 /* This must be called before disabling the mixer controls on APQ side */
465 if (my_data->csd_disable_device == NULL) {
466 ALOGE("%s: dlsym error for csd_disable_device", __func__);
467 } else {
468 ret = my_data->csd_disable_device();
469 if (ret < 0) {
470 ALOGE("%s: csd_client_disable_device, failed, error %d",
471 __func__, ret);
472 }
473 }
474 }
475 return ret;
476}
477
478int platform_switch_voice_call_device_post(void *platform,
479 snd_device_t out_snd_device,
480 snd_device_t in_snd_device)
481{
482 struct platform_data *my_data = (struct platform_data *)platform;
483 int acdb_rx_id, acdb_tx_id;
484 int ret = 0;
485
486 if (my_data->csd_client) {
487 if (my_data->csd_enable_device == NULL) {
488 ALOGE("%s: dlsym error for csd_enable_device",
489 __func__);
490 } else {
491 acdb_rx_id = acdb_device_table[out_snd_device];
492 acdb_tx_id = acdb_device_table[in_snd_device];
493
494 if (acdb_rx_id > 0 || acdb_tx_id > 0) {
495 ret = my_data->csd_enable_device(acdb_rx_id, acdb_tx_id,
496 my_data->adev->acdb_settings);
497 if (ret < 0) {
498 ALOGE("%s: csd_enable_device, failed, error %d",
499 __func__, ret);
500 }
501 } else {
502 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
503 acdb_rx_id, acdb_tx_id);
504 }
505 }
506 }
507
508 return ret;
509}
510
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700511int platform_start_voice_call(void *platform, uint32_t vsid __unused)
Eric Laurentb23d5282013-05-14 15:27:20 -0700512{
513 struct platform_data *my_data = (struct platform_data *)platform;
514 int ret = 0;
515
516 if (my_data->csd_client) {
517 if (my_data->csd_start_voice == NULL) {
518 ALOGE("dlsym error for csd_client_start_voice");
519 ret = -ENOSYS;
520 } else {
521 ret = my_data->csd_start_voice();
522 if (ret < 0) {
523 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
524 }
525 }
526 }
527
528 return ret;
529}
530
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700531int platform_stop_voice_call(void *platform, uint32_t vsid __unused)
Eric Laurentb23d5282013-05-14 15:27:20 -0700532{
533 struct platform_data *my_data = (struct platform_data *)platform;
534 int ret = 0;
535
536 if (my_data->csd_client) {
537 if (my_data->csd_stop_voice == NULL) {
538 ALOGE("dlsym error for csd_stop_voice");
539 } else {
540 ret = my_data->csd_stop_voice();
541 if (ret < 0) {
542 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
543 }
544 }
545 }
546
547 return ret;
548}
549
vivek mehtab6506412015-08-07 16:55:17 -0700550void platform_set_speaker_gain_in_combo(struct audio_device *adev __unused,
551 snd_device_t snd_device,
552 bool enable __unused) {
553}
554
Eric Laurentb23d5282013-05-14 15:27:20 -0700555int platform_set_voice_volume(void *platform, int volume)
556{
557 struct platform_data *my_data = (struct platform_data *)platform;
558 int ret = 0;
559
560 if (my_data->csd_client) {
561 if (my_data->csd_volume == NULL) {
562 ALOGE("%s: dlsym error for csd_volume", __func__);
563 } else {
564 ret = my_data->csd_volume(volume);
565 if (ret < 0) {
566 ALOGE("%s: csd_volume error %d", __func__, ret);
567 }
568 }
569 } else {
570 ALOGE("%s: No CSD Client present", __func__);
571 }
572
573 return ret;
574}
575
576int platform_set_mic_mute(void *platform, bool state)
577{
578 struct platform_data *my_data = (struct platform_data *)platform;
579 int ret = 0;
580
581 if (my_data->adev->mode == AUDIO_MODE_IN_CALL) {
582 if (my_data->csd_client) {
583 if (my_data->csd_mic_mute == NULL) {
584 ALOGE("%s: dlsym error for csd_mic_mute", __func__);
585 } else {
586 ret = my_data->csd_mic_mute(state);
587 if (ret < 0) {
588 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
589 }
590 }
591 } else {
592 ALOGE("%s: No CSD Client present", __func__);
593 }
594 }
595
596 return ret;
597}
598
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700599int platform_set_device_mute(void *platform __unused, bool state __unused, char *dir __unused)
600{
Haynes Mathew George24ca9ad2014-06-18 15:14:18 -0700601 ALOGE("%s: Not implemented", __func__);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700602 return -ENOSYS;
603}
604
Eric Laurentb23d5282013-05-14 15:27:20 -0700605snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
606{
607 struct platform_data *my_data = (struct platform_data *)platform;
608 struct audio_device *adev = my_data->adev;
609 audio_mode_t mode = adev->mode;
610 snd_device_t snd_device = SND_DEVICE_NONE;
611
612 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
613 if (devices == AUDIO_DEVICE_NONE ||
614 devices & AUDIO_DEVICE_BIT_IN) {
615 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
616 goto exit;
617 }
618
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -0700619 if (voice_is_in_call(adev)) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700620 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
621 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
Haynes Mathew George24ca9ad2014-06-18 15:14:18 -0700622 if (adev->voice.tty_mode == TTY_MODE_FULL)
Eric Laurentb23d5282013-05-14 15:27:20 -0700623 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
Haynes Mathew George24ca9ad2014-06-18 15:14:18 -0700624 else if (adev->voice.tty_mode == TTY_MODE_VCO)
Eric Laurentb23d5282013-05-14 15:27:20 -0700625 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
Haynes Mathew George24ca9ad2014-06-18 15:14:18 -0700626 else if (adev->voice.tty_mode == TTY_MODE_HCO)
Eric Laurentb23d5282013-05-14 15:27:20 -0700627 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
628 else
629 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
630 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700631 if (adev->bt_wb_speech_enabled) {
632 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
633 } else {
634 snd_device = SND_DEVICE_OUT_BT_SCO;
635 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700636 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
637 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
638 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
639 if (is_operator_tmus())
640 snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS;
641 else
642 snd_device = SND_DEVICE_OUT_HANDSET;
643 }
644 if (snd_device != SND_DEVICE_NONE) {
645 goto exit;
646 }
647 }
648
649 if (popcount(devices) == 2) {
650 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
651 AUDIO_DEVICE_OUT_SPEAKER)) {
652 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
653 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
654 AUDIO_DEVICE_OUT_SPEAKER)) {
655 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
656 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
657 AUDIO_DEVICE_OUT_SPEAKER)) {
658 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
659 } else {
660 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
661 goto exit;
662 }
663 if (snd_device != SND_DEVICE_NONE) {
664 goto exit;
665 }
666 }
667
668 if (popcount(devices) != 1) {
669 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
670 goto exit;
671 }
672
673 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
674 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
675 snd_device = SND_DEVICE_OUT_HEADPHONES;
676 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -0700677 if (my_data->speaker_lr_swap)
Eric Laurentb23d5282013-05-14 15:27:20 -0700678 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
679 else
680 snd_device = SND_DEVICE_OUT_SPEAKER;
681 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700682 if (adev->bt_wb_speech_enabled) {
683 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
684 } else {
685 snd_device = SND_DEVICE_OUT_BT_SCO;
686 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700687 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
688 snd_device = SND_DEVICE_OUT_HDMI ;
689 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
690 snd_device = SND_DEVICE_OUT_HANDSET;
691 } else {
692 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
693 }
694exit:
695 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
696 return snd_device;
697}
698
699snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
700{
701 struct platform_data *my_data = (struct platform_data *)platform;
702 struct audio_device *adev = my_data->adev;
703 audio_source_t source = (adev->active_input == NULL) ?
704 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
705
706 audio_mode_t mode = adev->mode;
707 audio_devices_t in_device = ((adev->active_input == NULL) ?
708 AUDIO_DEVICE_NONE : adev->active_input->device)
709 & ~AUDIO_DEVICE_BIT_IN;
710 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
711 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
712 snd_device_t snd_device = SND_DEVICE_NONE;
713
714 ALOGV("%s: enter: out_device(%#x) in_device(%#x)",
715 __func__, out_device, in_device);
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -0700716 if ((out_device != AUDIO_DEVICE_NONE) && voice_is_in_call(adev)) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700717 if (adev->voice.tty_mode != TTY_MODE_OFF) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700718 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
719 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700720 switch (adev->voice.tty_mode) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700721 case TTY_MODE_FULL:
722 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
723 break;
724 case TTY_MODE_VCO:
725 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
726 break;
727 case TTY_MODE_HCO:
728 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
729 break;
730 default:
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700731 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
Eric Laurentb23d5282013-05-14 15:27:20 -0700732 }
733 goto exit;
734 }
735 }
736 if (out_device & AUDIO_DEVICE_OUT_EARPIECE ||
737 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
738 if (my_data->fluence_in_voice_call == false) {
739 snd_device = SND_DEVICE_IN_HANDSET_MIC;
740 } else {
741 if (my_data->dualmic_config == DUALMIC_CONFIG_ENDFIRE) {
742 if (is_operator_tmus())
743 snd_device = SND_DEVICE_IN_VOICE_DMIC_EF_TMUS;
744 else
745 snd_device = SND_DEVICE_IN_VOICE_DMIC_EF;
746 } else if(my_data->dualmic_config == DUALMIC_CONFIG_BROADSIDE)
747 snd_device = SND_DEVICE_IN_VOICE_DMIC_BS;
748 else
749 snd_device = SND_DEVICE_IN_HANDSET_MIC;
750 }
751 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
752 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
753 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700754 if (adev->bt_wb_speech_enabled) {
755 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
756 } else {
757 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
758 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700759 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
760 if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode &&
761 my_data->dualmic_config == DUALMIC_CONFIG_ENDFIRE) {
762 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC_EF;
763 } else if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode &&
764 my_data->dualmic_config == DUALMIC_CONFIG_BROADSIDE) {
765 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BS;
766 } else {
767 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
768 }
769 }
770 } else if (source == AUDIO_SOURCE_CAMCORDER) {
771 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
772 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
773 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
774 }
775 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
776 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
777 if (my_data->dualmic_config == DUALMIC_CONFIG_ENDFIRE) {
778 if (channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK)
779 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_EF;
780 else if (my_data->fluence_in_voice_rec)
781 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_EF_FLUENCE;
782 } else if (my_data->dualmic_config == DUALMIC_CONFIG_BROADSIDE) {
783 if (channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK)
784 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_BS;
785 else if (my_data->fluence_in_voice_rec)
786 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_BS_FLUENCE;
787 }
788
789 if (snd_device == SND_DEVICE_NONE) {
790 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
791 }
792 }
793 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION) {
794 if (out_device & AUDIO_DEVICE_OUT_SPEAKER)
795 in_device = AUDIO_DEVICE_IN_BACK_MIC;
796 if (adev->active_input) {
797 if (adev->active_input->enable_aec) {
798 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
799 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
800 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
801 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
802 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
803 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
804 }
805 set_echo_reference(adev->mixer, "SLIM_RX");
806 } else
807 set_echo_reference(adev->mixer, "NONE");
808 }
809 } else if (source == AUDIO_SOURCE_DEFAULT) {
810 goto exit;
811 }
812
813
814 if (snd_device != SND_DEVICE_NONE) {
815 goto exit;
816 }
817
818 if (in_device != AUDIO_DEVICE_NONE &&
819 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
820 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
821 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
822 snd_device = SND_DEVICE_IN_HANDSET_MIC;
823 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
824 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
825 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
826 snd_device = SND_DEVICE_IN_HEADSET_MIC;
827 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700828 if (adev->bt_wb_speech_enabled) {
829 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
830 } else {
831 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
832 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700833 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
834 snd_device = SND_DEVICE_IN_HDMI_MIC;
835 } else {
836 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
837 ALOGW("%s: Using default handset-mic", __func__);
838 snd_device = SND_DEVICE_IN_HANDSET_MIC;
839 }
840 } else {
841 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
842 snd_device = SND_DEVICE_IN_HANDSET_MIC;
843 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
844 snd_device = SND_DEVICE_IN_HEADSET_MIC;
845 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
846 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
847 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
848 snd_device = SND_DEVICE_IN_HANDSET_MIC;
849 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700850 if (adev->bt_wb_speech_enabled) {
851 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
852 } else {
853 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
854 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700855 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
856 snd_device = SND_DEVICE_IN_HDMI_MIC;
857 } else {
858 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
859 ALOGW("%s: Using default handset-mic", __func__);
860 snd_device = SND_DEVICE_IN_HANDSET_MIC;
861 }
862 }
863exit:
864 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
865 return snd_device;
866}
867
868int platform_set_hdmi_channels(void *platform, int channel_count)
869{
870 struct platform_data *my_data = (struct platform_data *)platform;
871 struct audio_device *adev = my_data->adev;
872 struct mixer_ctl *ctl;
873 const char *channel_cnt_str = NULL;
874 const char *mixer_ctl_name = "HDMI_RX Channels";
875 switch (channel_count) {
876 case 8:
877 channel_cnt_str = "Eight"; break;
878 case 7:
879 channel_cnt_str = "Seven"; break;
880 case 6:
881 channel_cnt_str = "Six"; break;
882 case 5:
883 channel_cnt_str = "Five"; break;
884 case 4:
885 channel_cnt_str = "Four"; break;
886 case 3:
887 channel_cnt_str = "Three"; break;
888 default:
889 channel_cnt_str = "Two"; break;
890 }
891 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
892 if (!ctl) {
893 ALOGE("%s: Could not get ctl for mixer cmd - %s",
894 __func__, mixer_ctl_name);
895 return -EINVAL;
896 }
897 ALOGV("HDMI channel count: %s", channel_cnt_str);
898 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
899 return 0;
900}
901
Haynes Mathew George24ca9ad2014-06-18 15:14:18 -0700902int platform_edid_get_max_channels(void *platform __unused)
Eric Laurentb23d5282013-05-14 15:27:20 -0700903{
904 FILE *file;
905 struct audio_block_header header;
906 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
907 char *sad = block;
908 int num_audio_blocks;
909 int channel_count;
910 int max_channels = 0;
911 int i;
912
913 file = fopen(AUDIO_DATA_BLOCK_PATH, "rb");
914 if (file == NULL) {
915 ALOGE("Unable to open '%s'", AUDIO_DATA_BLOCK_PATH);
916 return 0;
917 }
918
919 /* Read audio block header */
920 fread(&header, 1, sizeof(header), file);
921
922 /* Read SAD blocks, clamping the maximum size for safety */
923 if (header.length > (int)sizeof(block))
924 header.length = (int)sizeof(block);
925 fread(&block, header.length, 1, file);
926
927 fclose(file);
928
929 /* Calculate the number of SAD blocks */
930 num_audio_blocks = header.length / SAD_BLOCK_SIZE;
931
932 for (i = 0; i < num_audio_blocks; i++) {
933 /* Only consider LPCM blocks */
934 if ((sad[0] >> 3) != EDID_FORMAT_LPCM)
935 continue;
936
937 channel_count = (sad[0] & 0x7) + 1;
938 if (channel_count > max_channels)
939 max_channels = channel_count;
940
941 /* Advance to next block */
942 sad += 3;
943 }
944
945 return max_channels;
946}
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700947
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700948int platform_set_incall_recording_session_id(void *platform __unused,
949 uint32_t session_id __unused, int rec_mode __unused)
950{
Haynes Mathew George24ca9ad2014-06-18 15:14:18 -0700951 ALOGE("%s: Not implemented", __func__);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700952 return -ENOSYS;
953}
954
955int platform_stop_incall_recording_usecase(void *platform __unused)
956{
Haynes Mathew George24ca9ad2014-06-18 15:14:18 -0700957 ALOGE("%s: Not implemented", __func__);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700958 return -ENOSYS;
959}
960
961int platform_start_incall_music_usecase(void *platform __unused)
962{
Haynes Mathew George24ca9ad2014-06-18 15:14:18 -0700963 ALOGE("%s: Not implemented", __func__);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700964 return -ENOSYS;
965}
966
967int platform_stop_incall_music_usecase(void *platform __unused)
968{
Haynes Mathew George24ca9ad2014-06-18 15:14:18 -0700969 ALOGE("%s: Not implemented", __func__);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700970 return -ENOSYS;
971}
972
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700973int platform_set_parameters(void *platform __unused,
974 struct str_parms *parms __unused)
975{
976 ALOGE("%s: Not implemented", __func__);
977 return -ENOSYS;
978}
979
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700980/* Delay in Us */
981int64_t platform_render_latency(audio_usecase_t usecase)
982{
983 switch (usecase) {
984 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
985 return DEEP_BUFFER_PLATFORM_DELAY;
986 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
987 return LOW_LATENCY_PLATFORM_DELAY;
988 default:
989 return 0;
990 }
991}
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700992
Haynes Mathew George24ca9ad2014-06-18 15:14:18 -0700993int platform_switch_voice_call_enable_device_config(void *platform __unused,
994 snd_device_t out_snd_device __unused,
995 snd_device_t in_snd_device __unused)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700996{
997 return 0;
998}
999
Haynes Mathew George24ca9ad2014-06-18 15:14:18 -07001000int platform_switch_voice_call_usecase_route_post(void *platform __unused,
1001 snd_device_t out_snd_device __unused,
1002 snd_device_t in_snd_device __unused)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001003{
1004 return 0;
1005}
Haynes Mathew George24ca9ad2014-06-18 15:14:18 -07001006
1007int platform_get_sample_rate(void *platform __unused, uint32_t *rate __unused)
1008{
1009 return -ENOSYS;
1010}
Haynes Mathew George98c95622014-06-20 19:14:25 -07001011
1012int platform_get_usecase_index(const char * usecase __unused)
1013{
1014 return -ENOSYS;
1015}
1016
1017int platform_set_usecase_pcm_id(audio_usecase_t usecase __unused, int32_t type __unused,
1018 int32_t pcm_id __unused)
1019{
1020 return -ENOSYS;
1021}
1022
1023int platform_set_snd_device_backend(snd_device_t device __unused,
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001024 const char *backend __unused,
1025 const char *hw_interface __unused)
Haynes Mathew George98c95622014-06-20 19:14:25 -07001026{
1027 return -ENOSYS;
1028}
Eric Laurentcefbbac2014-09-04 13:54:10 -05001029
vivek mehta1a9b7c02015-06-25 11:49:38 -07001030void platform_set_echo_reference(struct audio_device *adev __unused,
1031 bool enable __unused,
1032 audio_devices_t out_device __unused)
Eric Laurentcefbbac2014-09-04 13:54:10 -05001033{
1034 return;
1035}
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07001036
1037int platform_swap_lr_channels(struct audio_device *adev, bool swap_channels)
1038{
1039 // only update the selected device if there is active pcm playback
1040 struct audio_usecase *usecase;
1041 struct listnode *node;
1042 struct platform_data *my_data = (struct platform_data *)adev->platform;
1043 int status = 0;
1044
1045 if (my_data->speaker_lr_swap != swap_channels) {
1046 my_data->speaker_lr_swap = swap_channels;
1047
1048 list_for_each(node, &adev->usecase_list) {
1049 usecase = node_to_item(node, struct audio_usecase, list);
1050 if (usecase->type == PCM_PLAYBACK &&
1051 usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) {
1052 const char *mixer_path;
1053 if (swap_channels) {
1054 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER_REVERSE);
1055 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
1056 } else {
1057 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER);
1058 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
1059 }
1060 break;
1061 }
1062 }
1063 }
1064 return status;
1065}
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001066
1067bool platform_send_gain_dep_cal(void *platform __unused,
1068 int level __unused)
1069{
1070 return 0;
1071}
1072
1073bool platform_can_split_snd_device(snd_device_t in_snd_device __unused,
1074 int *num_devices __unused,
1075 snd_device_t *out_snd_devices __unused)
1076{
1077 return false;
1078}
1079
1080bool platform_check_backends_match(snd_device_t snd_device1 __unused,
1081 snd_device_t snd_device2 __unused)
1082{
1083 return true;
1084}