blob: d123646eee2344e434dbf50b62a013c3038fa44a [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>
Haynes Mathew Georgee6e2d442018-02-22 18:51:56 -080023#include <log/log.h>
Eric Laurentb23d5282013-05-14 15:27:20 -070024#include <cutils/properties.h>
25#include <audio_hw.h>
26#include <platform_api.h>
27#include "platform.h"
David Lind6229bd2017-07-06 15:28:55 -070028#include "audio_extn.h"
Eric Laurentb23d5282013-05-14 15:27:20 -070029
30#define LIB_ACDB_LOADER "libacdbloader.so"
31#define LIB_CSD_CLIENT "libcsd-client.so"
32
33#define DUALMIC_CONFIG_NONE 0 /* Target does not contain 2 mics */
34#define DUALMIC_CONFIG_ENDFIRE 1
35#define DUALMIC_CONFIG_BROADSIDE 2
36
37/*
38 * This is the sysfs path for the HDMI audio data block
39 */
40#define AUDIO_DATA_BLOCK_PATH "/sys/class/graphics/fb1/audio_data_block"
sangwoo1b9f4b32013-06-21 18:22:55 -070041#define MIXER_XML_PATH "/system/etc/mixer_paths.xml"
Eric Laurentb23d5282013-05-14 15:27:20 -070042
43/*
44 * This file will have a maximum of 38 bytes:
45 *
46 * 4 bytes: number of audio blocks
47 * 4 bytes: total length of Short Audio Descriptor (SAD) blocks
48 * Maximum 10 * 3 bytes: SAD blocks
49 */
50#define MAX_SAD_BLOCKS 10
51#define SAD_BLOCK_SIZE 3
52
53/* EDID format ID for LPCM audio */
54#define EDID_FORMAT_LPCM 1
55
56struct audio_block_header
57{
58 int reserved;
59 int length;
60};
61
62
63typedef void (*acdb_deallocate_t)();
64typedef int (*acdb_init_t)();
65typedef void (*acdb_send_audio_cal_t)(int, int);
66typedef void (*acdb_send_voice_cal_t)(int, int);
67
68typedef int (*csd_client_init_t)();
69typedef int (*csd_client_deinit_t)();
70typedef int (*csd_disable_device_t)();
71typedef int (*csd_enable_device_t)(int, int, uint32_t);
72typedef int (*csd_volume_t)(int);
73typedef int (*csd_mic_mute_t)(int);
74typedef int (*csd_start_voice_t)();
75typedef int (*csd_stop_voice_t)();
76
77
78/* Audio calibration related functions */
79struct platform_data {
80 struct audio_device *adev;
81 bool fluence_in_spkr_mode;
82 bool fluence_in_voice_call;
83 bool fluence_in_voice_rec;
84 int dualmic_config;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -070085 bool speaker_lr_swap;
Eric Laurentb23d5282013-05-14 15:27:20 -070086
87 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},
David Lind6229bd2017-07-06 15:28:55 -0700108 [USECASE_AUDIO_PLAYBACK_HIFI] = {1, 1},
Eric Laurentb23d5282013-05-14 15:27:20 -0700109 [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",
David Linfb3c9952018-01-19 14:57:43 -0800121 [SND_DEVICE_OUT_SPEAKER_SAFE] = "speaker-safe",
Eric Laurentb23d5282013-05-14 15:27:20 -0700122 [SND_DEVICE_OUT_HEADPHONES] = "headphones",
123 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones",
124 [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker",
125 [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones",
126 [SND_DEVICE_OUT_HDMI] = "hdmi",
127 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi",
128 [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700129 [SND_DEVICE_OUT_BT_SCO_WB] = "bt-sco-headset-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700130 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = "voice-handset-tmus",
Eric Laurent788f41f2015-08-24 12:21:50 -0700131 [SND_DEVICE_OUT_VOICE_HANDSET] = "voice-handset-tmus",
132 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = "voice-handset-tmus",
Eric Laurentb23d5282013-05-14 15:27:20 -0700133 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones",
134 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones",
135 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset",
Eric Laurentb1b07992017-06-29 09:20:02 -0700136 [SND_DEVICE_OUT_USB_HEADSET] = "usb-headset",
137 [SND_DEVICE_OUT_USB_HEADPHONES] = "usb-headphones",
138 [SND_DEVICE_OUT_VOICE_USB_HEADSET] = "usb-headset",
139 [SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = "usb-headphones",
140
Eric Laurentb23d5282013-05-14 15:27:20 -0700141
142 /* Capture sound devices */
143 [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
144 [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
145 [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
146 [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic",
147 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "voice-speaker-mic",
148 [SND_DEVICE_IN_HEADSET_MIC_AEC] = "headset-mic",
149 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
150 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
151 [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic",
152 [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700153 [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700154 [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic",
155 [SND_DEVICE_IN_VOICE_DMIC_EF] = "voice-dmic-ef",
156 [SND_DEVICE_IN_VOICE_DMIC_BS] = "voice-dmic-bs",
157 [SND_DEVICE_IN_VOICE_DMIC_EF_TMUS] = "voice-dmic-ef-tmus",
158 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_EF] = "voice-speaker-dmic-ef",
159 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BS] = "voice-speaker-dmic-bs",
160 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
161 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
162 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
163 [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
164 [SND_DEVICE_IN_VOICE_REC_DMIC_EF] = "voice-rec-dmic-ef",
165 [SND_DEVICE_IN_VOICE_REC_DMIC_BS] = "voice-rec-dmic-bs",
166 [SND_DEVICE_IN_VOICE_REC_DMIC_EF_FLUENCE] = "voice-rec-dmic-ef-fluence",
167 [SND_DEVICE_IN_VOICE_REC_DMIC_BS_FLUENCE] = "voice-rec-dmic-bs-fluence",
168};
169
170/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
171static const int acdb_device_table[SND_DEVICE_MAX] = {
172 [SND_DEVICE_NONE] = -1,
173 [SND_DEVICE_OUT_HANDSET] = 7,
174 [SND_DEVICE_OUT_SPEAKER] = 14,
175 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 14,
David Linfb3c9952018-01-19 14:57:43 -0800176 [SND_DEVICE_OUT_SPEAKER_SAFE] = 14,
Eric Laurentb23d5282013-05-14 15:27:20 -0700177 [SND_DEVICE_OUT_HEADPHONES] = 10,
178 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
179 [SND_DEVICE_OUT_VOICE_SPEAKER] = 14,
180 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
181 [SND_DEVICE_OUT_HDMI] = 18,
182 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 14,
183 [SND_DEVICE_OUT_BT_SCO] = 22,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700184 [SND_DEVICE_OUT_BT_SCO_WB] = 39,
Eric Laurentb23d5282013-05-14 15:27:20 -0700185 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = 81,
Eric Laurent788f41f2015-08-24 12:21:50 -0700186 [SND_DEVICE_OUT_VOICE_HANDSET] = 81,
187 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = 81,
Eric Laurentb23d5282013-05-14 15:27:20 -0700188 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
189 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
190 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
Eric Laurentb1b07992017-06-29 09:20:02 -0700191 [SND_DEVICE_OUT_USB_HEADSET] = 45,
192 [SND_DEVICE_OUT_USB_HEADPHONES] = 45,
193 [SND_DEVICE_OUT_VOICE_USB_HEADSET] = 45,
194 [SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = 45,
Eric Laurentb23d5282013-05-14 15:27:20 -0700195
196 [SND_DEVICE_IN_HANDSET_MIC] = 4,
197 [SND_DEVICE_IN_SPEAKER_MIC] = 4,
198 [SND_DEVICE_IN_HEADSET_MIC] = 8,
199 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 40,
200 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 42,
201 [SND_DEVICE_IN_HEADSET_MIC_AEC] = 47,
202 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
203 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = 8,
204 [SND_DEVICE_IN_HDMI_MIC] = 4,
205 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700206 [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38,
Eric Laurentb23d5282013-05-14 15:27:20 -0700207 [SND_DEVICE_IN_CAMCORDER_MIC] = 61,
208 [SND_DEVICE_IN_VOICE_DMIC_EF] = 6,
209 [SND_DEVICE_IN_VOICE_DMIC_BS] = 5,
210 [SND_DEVICE_IN_VOICE_DMIC_EF_TMUS] = 91,
211 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_EF] = 13,
212 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BS] = 12,
213 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
214 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
215 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
216 [SND_DEVICE_IN_VOICE_REC_MIC] = 62,
217 /* TODO: Update with proper acdb ids */
218 [SND_DEVICE_IN_VOICE_REC_DMIC_EF] = 62,
219 [SND_DEVICE_IN_VOICE_REC_DMIC_BS] = 62,
220 [SND_DEVICE_IN_VOICE_REC_DMIC_EF_FLUENCE] = 6,
221 [SND_DEVICE_IN_VOICE_REC_DMIC_BS_FLUENCE] = 5,
222};
223
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700224#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
225#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
226
Eric Laurentb23d5282013-05-14 15:27:20 -0700227static pthread_once_t check_op_once_ctl = PTHREAD_ONCE_INIT;
228static bool is_tmus = false;
229
230static void check_operator()
231{
232 char value[PROPERTY_VALUE_MAX];
233 int mccmnc;
234 property_get("gsm.sim.operator.numeric",value,"0");
235 mccmnc = atoi(value);
236 ALOGD("%s: tmus mccmnc %d", __func__, mccmnc);
237 switch(mccmnc) {
238 /* TMUS MCC(310), MNC(490, 260, 026) */
239 case 310490:
240 case 310260:
241 case 310026:
242 is_tmus = true;
243 break;
244 }
245}
246
247bool is_operator_tmus()
248{
249 pthread_once(&check_op_once_ctl, check_operator);
250 return is_tmus;
251}
252
253static int set_echo_reference(struct mixer *mixer, const char* ec_ref)
254{
255 struct mixer_ctl *ctl;
256 const char *mixer_ctl_name = "EC_REF_RX";
257
258 ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name);
259 if (!ctl) {
260 ALOGE("%s: Could not get ctl for mixer cmd - %s",
261 __func__, mixer_ctl_name);
262 return -EINVAL;
263 }
264 ALOGV("Setting EC Reference: %s", ec_ref);
265 mixer_ctl_set_enum_by_string(ctl, ec_ref);
266 return 0;
267}
268
269void *platform_init(struct audio_device *adev)
270{
271 char platform[PROPERTY_VALUE_MAX];
272 char baseband[PROPERTY_VALUE_MAX];
273 char value[PROPERTY_VALUE_MAX];
274 struct platform_data *my_data;
275
sangwoo1b9f4b32013-06-21 18:22:55 -0700276 adev->mixer = mixer_open(MIXER_CARD);
277
278 if (!adev->mixer) {
279 ALOGE("Unable to open the mixer, aborting.");
280 return NULL;
281 }
282
283 adev->audio_route = audio_route_init(MIXER_CARD, MIXER_XML_PATH);
284 if (!adev->audio_route) {
285 ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
286 return NULL;
287 }
288
Eric Laurentb23d5282013-05-14 15:27:20 -0700289 my_data = calloc(1, sizeof(struct platform_data));
290
291 my_data->adev = adev;
292 my_data->dualmic_config = DUALMIC_CONFIG_NONE;
293 my_data->fluence_in_spkr_mode = false;
294 my_data->fluence_in_voice_call = false;
295 my_data->fluence_in_voice_rec = false;
296
297 property_get("persist.audio.dualmic.config",value,"");
298 if (!strcmp("broadside", value)) {
299 my_data->dualmic_config = DUALMIC_CONFIG_BROADSIDE;
300 adev->acdb_settings |= DMIC_FLAG;
301 } else if (!strcmp("endfire", value)) {
302 my_data->dualmic_config = DUALMIC_CONFIG_ENDFIRE;
303 adev->acdb_settings |= DMIC_FLAG;
304 }
305
306 if (my_data->dualmic_config != DUALMIC_CONFIG_NONE) {
307 property_get("persist.audio.fluence.voicecall",value,"");
308 if (!strcmp("true", value)) {
309 my_data->fluence_in_voice_call = true;
310 }
311
312 property_get("persist.audio.fluence.voicerec",value,"");
313 if (!strcmp("true", value)) {
314 my_data->fluence_in_voice_rec = true;
315 }
316
317 property_get("persist.audio.fluence.speaker",value,"");
318 if (!strcmp("true", value)) {
319 my_data->fluence_in_spkr_mode = true;
320 }
321 }
322
323 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
324 if (my_data->acdb_handle == NULL) {
325 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
326 } else {
327 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
328 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
329 "acdb_loader_deallocate_ACDB");
330 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
331 "acdb_loader_send_audio_cal");
332 if (!my_data->acdb_send_audio_cal)
333 ALOGW("%s: Could not find the symbol acdb_send_audio_cal from %s",
334 __func__, LIB_ACDB_LOADER);
335 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
336 "acdb_loader_send_voice_cal");
337 my_data->acdb_init = (acdb_init_t)dlsym(my_data->acdb_handle,
338 "acdb_loader_init_ACDB");
339 if (my_data->acdb_init == NULL)
340 ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__, dlerror());
341 else
342 my_data->acdb_init();
343 }
344
345 /* If platform is Fusion3, load CSD Client specific symbols
346 * Voice call is handled by MDM and apps processor talks to
347 * MDM through CSD Client
348 */
349 property_get("ro.board.platform", platform, "");
350 property_get("ro.baseband", baseband, "");
351 if (!strcmp("msm8960", platform) && !strcmp("mdm", baseband)) {
352 my_data->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
353 if (my_data->csd_client == NULL)
354 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
355 }
356
357 if (my_data->csd_client) {
358 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
359 my_data->csd_client_deinit = (csd_client_deinit_t)dlsym(my_data->csd_client,
360 "csd_client_deinit");
361 my_data->csd_disable_device = (csd_disable_device_t)dlsym(my_data->csd_client,
362 "csd_client_disable_device");
363 my_data->csd_enable_device = (csd_enable_device_t)dlsym(my_data->csd_client,
364 "csd_client_enable_device");
365 my_data->csd_start_voice = (csd_start_voice_t)dlsym(my_data->csd_client,
366 "csd_client_start_voice");
367 my_data->csd_stop_voice = (csd_stop_voice_t)dlsym(my_data->csd_client,
368 "csd_client_stop_voice");
369 my_data->csd_volume = (csd_volume_t)dlsym(my_data->csd_client,
370 "csd_client_volume");
371 my_data->csd_mic_mute = (csd_mic_mute_t)dlsym(my_data->csd_client,
372 "csd_client_mic_mute");
373 my_data->csd_client_init = (csd_client_init_t)dlsym(my_data->csd_client,
374 "csd_client_init");
375
376 if (my_data->csd_client_init == NULL) {
377 ALOGE("%s: dlsym error %s for csd_client_init", __func__, dlerror());
378 } else {
379 my_data->csd_client_init();
380 }
381 }
382
383 return my_data;
384}
385
386void platform_deinit(void *platform)
387{
388 free(platform);
389}
390
391const char *platform_get_snd_device_name(snd_device_t snd_device)
392{
393 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX)
394 return device_table[snd_device];
395 else
Ravi Kumar Alamanda64026462014-09-15 00:08:58 -0700396 return "none";
Eric Laurentb23d5282013-05-14 15:27:20 -0700397}
398
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -0500399void platform_add_backend_name(void *platform __unused, char *mixer_path,
400 snd_device_t snd_device)
Eric Laurentb23d5282013-05-14 15:27:20 -0700401{
402 if (snd_device == SND_DEVICE_IN_BT_SCO_MIC)
403 strcat(mixer_path, " bt-sco");
404 else if(snd_device == SND_DEVICE_OUT_BT_SCO)
405 strcat(mixer_path, " bt-sco");
406 else if (snd_device == SND_DEVICE_OUT_HDMI)
407 strcat(mixer_path, " hdmi");
408 else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HDMI)
409 strcat(mixer_path, " speaker-and-hdmi");
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700410 else if (snd_device == SND_DEVICE_OUT_BT_SCO_WB ||
411 snd_device == SND_DEVICE_IN_BT_SCO_MIC_WB)
412 strcat(mixer_path, " bt-sco-wb");
Eric Laurentb23d5282013-05-14 15:27:20 -0700413}
414
415int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
416{
417 int device_id;
418 if (device_type == PCM_PLAYBACK)
419 device_id = pcm_device_table[usecase][0];
420 else
421 device_id = pcm_device_table[usecase][1];
422 return device_id;
423}
424
Haynes Mathew George98c95622014-06-20 19:14:25 -0700425int platform_get_snd_device_index(char *snd_device_index_name __unused)
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700426{
427 return -ENODEV;
428}
429
Haynes Mathew George98c95622014-06-20 19:14:25 -0700430int platform_set_snd_device_acdb_id(snd_device_t snd_device __unused,
431 unsigned int acdb_id __unused)
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700432{
433 return -ENODEV;
434}
435
David Lind6229bd2017-07-06 15:28:55 -0700436int platform_get_default_app_type_v2(void *platform __unused, usecase_type_t type __unused,
Yamit Mehtae3b99562016-09-16 22:44:00 +0530437 int *app_type __unused)
438{
439 ALOGE("%s: Not implemented", __func__);
440 return -ENOSYS;
441}
442
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700443int platform_get_snd_device_acdb_id(snd_device_t snd_device __unused)
444{
445 ALOGE("%s: Not implemented", __func__);
446 return -ENOSYS;
447}
448
Eric Laurent788f41f2015-08-24 12:21:50 -0700449void platform_add_operator_specific_device(snd_device_t snd_device __unused,
450 const char *operator __unused,
451 const char *mixer_path __unused,
452 unsigned int acdb_id __unused)
keunhui.park2f7306a2015-07-16 16:48:06 +0900453{
454}
455
Eric Laurentb23d5282013-05-14 15:27:20 -0700456int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
457{
458 struct platform_data *my_data = (struct platform_data *)platform;
459 int acdb_dev_id, acdb_dev_type;
460
461 acdb_dev_id = acdb_device_table[snd_device];
462 if (acdb_dev_id < 0) {
463 ALOGE("%s: Could not find acdb id for device(%d)",
464 __func__, snd_device);
465 return -EINVAL;
466 }
467 if (my_data->acdb_send_audio_cal) {
Eric Laurent994a6932013-07-17 11:51:42 -0700468 ("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Eric Laurentb23d5282013-05-14 15:27:20 -0700469 __func__, snd_device, acdb_dev_id);
470 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
471 snd_device < SND_DEVICE_OUT_END)
472 acdb_dev_type = ACDB_DEV_TYPE_OUT;
473 else
474 acdb_dev_type = ACDB_DEV_TYPE_IN;
475 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
476 }
477 return 0;
478}
479
480int platform_switch_voice_call_device_pre(void *platform)
481{
482 struct platform_data *my_data = (struct platform_data *)platform;
483 int ret = 0;
484
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -0700485 if (my_data->csd_client != NULL &&
486 voice_is_in_call(my_data->adev)) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700487 /* This must be called before disabling the mixer controls on APQ side */
488 if (my_data->csd_disable_device == NULL) {
489 ALOGE("%s: dlsym error for csd_disable_device", __func__);
490 } else {
491 ret = my_data->csd_disable_device();
492 if (ret < 0) {
493 ALOGE("%s: csd_client_disable_device, failed, error %d",
494 __func__, ret);
495 }
496 }
497 }
498 return ret;
499}
500
501int platform_switch_voice_call_device_post(void *platform,
502 snd_device_t out_snd_device,
503 snd_device_t in_snd_device)
504{
505 struct platform_data *my_data = (struct platform_data *)platform;
506 int acdb_rx_id, acdb_tx_id;
507 int ret = 0;
508
509 if (my_data->csd_client) {
510 if (my_data->csd_enable_device == NULL) {
511 ALOGE("%s: dlsym error for csd_enable_device",
512 __func__);
513 } else {
514 acdb_rx_id = acdb_device_table[out_snd_device];
515 acdb_tx_id = acdb_device_table[in_snd_device];
516
517 if (acdb_rx_id > 0 || acdb_tx_id > 0) {
518 ret = my_data->csd_enable_device(acdb_rx_id, acdb_tx_id,
519 my_data->adev->acdb_settings);
520 if (ret < 0) {
521 ALOGE("%s: csd_enable_device, failed, error %d",
522 __func__, ret);
523 }
524 } else {
525 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
526 acdb_rx_id, acdb_tx_id);
527 }
528 }
529 }
530
531 return ret;
532}
533
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700534int platform_start_voice_call(void *platform, uint32_t vsid __unused)
Eric Laurentb23d5282013-05-14 15:27:20 -0700535{
536 struct platform_data *my_data = (struct platform_data *)platform;
537 int ret = 0;
538
539 if (my_data->csd_client) {
540 if (my_data->csd_start_voice == NULL) {
541 ALOGE("dlsym error for csd_client_start_voice");
542 ret = -ENOSYS;
543 } else {
544 ret = my_data->csd_start_voice();
545 if (ret < 0) {
546 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
547 }
548 }
549 }
550
551 return ret;
552}
553
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700554int platform_stop_voice_call(void *platform, uint32_t vsid __unused)
Eric Laurentb23d5282013-05-14 15:27:20 -0700555{
556 struct platform_data *my_data = (struct platform_data *)platform;
557 int ret = 0;
558
559 if (my_data->csd_client) {
560 if (my_data->csd_stop_voice == NULL) {
561 ALOGE("dlsym error for csd_stop_voice");
562 } else {
563 ret = my_data->csd_stop_voice();
564 if (ret < 0) {
565 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
566 }
567 }
568 }
569
570 return ret;
571}
572
vivek mehtab6506412015-08-07 16:55:17 -0700573void platform_set_speaker_gain_in_combo(struct audio_device *adev __unused,
Eric Laurent788f41f2015-08-24 12:21:50 -0700574 snd_device_t snd_device __unused,
vivek mehtab6506412015-08-07 16:55:17 -0700575 bool enable __unused) {
576}
577
Eric Laurentb23d5282013-05-14 15:27:20 -0700578int platform_set_voice_volume(void *platform, int volume)
579{
580 struct platform_data *my_data = (struct platform_data *)platform;
581 int ret = 0;
582
583 if (my_data->csd_client) {
584 if (my_data->csd_volume == NULL) {
585 ALOGE("%s: dlsym error for csd_volume", __func__);
586 } else {
587 ret = my_data->csd_volume(volume);
588 if (ret < 0) {
589 ALOGE("%s: csd_volume error %d", __func__, ret);
590 }
591 }
592 } else {
593 ALOGE("%s: No CSD Client present", __func__);
594 }
595
596 return ret;
597}
598
599int platform_set_mic_mute(void *platform, bool state)
600{
601 struct platform_data *my_data = (struct platform_data *)platform;
602 int ret = 0;
603
604 if (my_data->adev->mode == AUDIO_MODE_IN_CALL) {
605 if (my_data->csd_client) {
606 if (my_data->csd_mic_mute == NULL) {
607 ALOGE("%s: dlsym error for csd_mic_mute", __func__);
608 } else {
609 ret = my_data->csd_mic_mute(state);
610 if (ret < 0) {
611 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
612 }
613 }
614 } else {
615 ALOGE("%s: No CSD Client present", __func__);
616 }
617 }
618
619 return ret;
620}
621
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700622int platform_set_device_mute(void *platform __unused, bool state __unused, char *dir __unused)
623{
Haynes Mathew George24ca9ad2014-06-18 15:14:18 -0700624 ALOGE("%s: Not implemented", __func__);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700625 return -ENOSYS;
626}
627
Eric Laurentb23d5282013-05-14 15:27:20 -0700628snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
629{
630 struct platform_data *my_data = (struct platform_data *)platform;
631 struct audio_device *adev = my_data->adev;
632 audio_mode_t mode = adev->mode;
633 snd_device_t snd_device = SND_DEVICE_NONE;
634
635 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
636 if (devices == AUDIO_DEVICE_NONE ||
637 devices & AUDIO_DEVICE_BIT_IN) {
638 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
639 goto exit;
640 }
641
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -0700642 if (voice_is_in_call(adev)) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700643 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
644 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
Haynes Mathew George24ca9ad2014-06-18 15:14:18 -0700645 if (adev->voice.tty_mode == TTY_MODE_FULL)
Eric Laurentb23d5282013-05-14 15:27:20 -0700646 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
Haynes Mathew George24ca9ad2014-06-18 15:14:18 -0700647 else if (adev->voice.tty_mode == TTY_MODE_VCO)
Eric Laurentb23d5282013-05-14 15:27:20 -0700648 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
Haynes Mathew George24ca9ad2014-06-18 15:14:18 -0700649 else if (adev->voice.tty_mode == TTY_MODE_HCO)
Eric Laurentb23d5282013-05-14 15:27:20 -0700650 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
651 else
652 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
653 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700654 if (adev->bt_wb_speech_enabled) {
655 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
656 } else {
657 snd_device = SND_DEVICE_OUT_BT_SCO;
658 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700659 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
660 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
661 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
662 if (is_operator_tmus())
663 snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS;
664 else
665 snd_device = SND_DEVICE_OUT_HANDSET;
666 }
667 if (snd_device != SND_DEVICE_NONE) {
668 goto exit;
669 }
670 }
671
672 if (popcount(devices) == 2) {
673 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
674 AUDIO_DEVICE_OUT_SPEAKER)) {
675 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
676 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
677 AUDIO_DEVICE_OUT_SPEAKER)) {
678 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
679 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
680 AUDIO_DEVICE_OUT_SPEAKER)) {
681 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
682 } else {
683 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
684 goto exit;
685 }
686 if (snd_device != SND_DEVICE_NONE) {
687 goto exit;
688 }
689 }
690
691 if (popcount(devices) != 1) {
692 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
693 goto exit;
694 }
695
696 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
697 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
698 snd_device = SND_DEVICE_OUT_HEADPHONES;
699 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -0700700 if (my_data->speaker_lr_swap)
Eric Laurentb23d5282013-05-14 15:27:20 -0700701 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
702 else
703 snd_device = SND_DEVICE_OUT_SPEAKER;
704 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700705 if (adev->bt_wb_speech_enabled) {
706 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
707 } else {
708 snd_device = SND_DEVICE_OUT_BT_SCO;
709 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700710 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
711 snd_device = SND_DEVICE_OUT_HDMI ;
712 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
713 snd_device = SND_DEVICE_OUT_HANDSET;
714 } else {
715 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
716 }
717exit:
718 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
719 return snd_device;
720}
721
722snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
723{
724 struct platform_data *my_data = (struct platform_data *)platform;
725 struct audio_device *adev = my_data->adev;
726 audio_source_t source = (adev->active_input == NULL) ?
727 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
728
729 audio_mode_t mode = adev->mode;
730 audio_devices_t in_device = ((adev->active_input == NULL) ?
731 AUDIO_DEVICE_NONE : adev->active_input->device)
732 & ~AUDIO_DEVICE_BIT_IN;
733 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
734 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
735 snd_device_t snd_device = SND_DEVICE_NONE;
736
737 ALOGV("%s: enter: out_device(%#x) in_device(%#x)",
738 __func__, out_device, in_device);
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -0700739 if ((out_device != AUDIO_DEVICE_NONE) && voice_is_in_call(adev)) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700740 if (adev->voice.tty_mode != TTY_MODE_OFF) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700741 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
742 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700743 switch (adev->voice.tty_mode) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700744 case TTY_MODE_FULL:
745 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
746 break;
747 case TTY_MODE_VCO:
748 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
749 break;
750 case TTY_MODE_HCO:
751 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
752 break;
753 default:
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700754 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
Eric Laurentb23d5282013-05-14 15:27:20 -0700755 }
756 goto exit;
757 }
758 }
759 if (out_device & AUDIO_DEVICE_OUT_EARPIECE ||
760 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
761 if (my_data->fluence_in_voice_call == false) {
762 snd_device = SND_DEVICE_IN_HANDSET_MIC;
763 } else {
764 if (my_data->dualmic_config == DUALMIC_CONFIG_ENDFIRE) {
765 if (is_operator_tmus())
766 snd_device = SND_DEVICE_IN_VOICE_DMIC_EF_TMUS;
767 else
768 snd_device = SND_DEVICE_IN_VOICE_DMIC_EF;
769 } else if(my_data->dualmic_config == DUALMIC_CONFIG_BROADSIDE)
770 snd_device = SND_DEVICE_IN_VOICE_DMIC_BS;
771 else
772 snd_device = SND_DEVICE_IN_HANDSET_MIC;
773 }
774 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
775 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
776 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700777 if (adev->bt_wb_speech_enabled) {
778 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
779 } else {
780 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
781 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700782 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
783 if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode &&
784 my_data->dualmic_config == DUALMIC_CONFIG_ENDFIRE) {
785 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC_EF;
786 } else if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode &&
787 my_data->dualmic_config == DUALMIC_CONFIG_BROADSIDE) {
788 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BS;
789 } else {
790 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
791 }
792 }
793 } else if (source == AUDIO_SOURCE_CAMCORDER) {
794 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
795 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
796 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
797 }
798 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
799 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
800 if (my_data->dualmic_config == DUALMIC_CONFIG_ENDFIRE) {
801 if (channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK)
802 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_EF;
803 else if (my_data->fluence_in_voice_rec)
804 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_EF_FLUENCE;
805 } else if (my_data->dualmic_config == DUALMIC_CONFIG_BROADSIDE) {
806 if (channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK)
807 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_BS;
808 else if (my_data->fluence_in_voice_rec)
809 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_BS_FLUENCE;
810 }
811
812 if (snd_device == SND_DEVICE_NONE) {
813 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
814 }
815 }
Eric Laurent50a38ed2015-10-14 18:48:06 -0700816 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION ||
817 mode == AUDIO_MODE_IN_COMMUNICATION) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700818 if (out_device & AUDIO_DEVICE_OUT_SPEAKER)
819 in_device = AUDIO_DEVICE_IN_BACK_MIC;
820 if (adev->active_input) {
821 if (adev->active_input->enable_aec) {
822 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
823 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
824 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
825 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
826 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
827 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
828 }
829 set_echo_reference(adev->mixer, "SLIM_RX");
830 } else
831 set_echo_reference(adev->mixer, "NONE");
832 }
833 } else if (source == AUDIO_SOURCE_DEFAULT) {
834 goto exit;
835 }
836
837
838 if (snd_device != SND_DEVICE_NONE) {
839 goto exit;
840 }
841
842 if (in_device != AUDIO_DEVICE_NONE &&
843 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
844 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
845 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
846 snd_device = SND_DEVICE_IN_HANDSET_MIC;
847 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
848 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
849 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
850 snd_device = SND_DEVICE_IN_HEADSET_MIC;
851 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700852 if (adev->bt_wb_speech_enabled) {
853 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
854 } else {
855 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
856 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700857 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
858 snd_device = SND_DEVICE_IN_HDMI_MIC;
859 } else {
860 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
861 ALOGW("%s: Using default handset-mic", __func__);
862 snd_device = SND_DEVICE_IN_HANDSET_MIC;
863 }
864 } else {
865 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
866 snd_device = SND_DEVICE_IN_HANDSET_MIC;
867 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
868 snd_device = SND_DEVICE_IN_HEADSET_MIC;
869 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
870 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
871 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
872 snd_device = SND_DEVICE_IN_HANDSET_MIC;
873 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700874 if (adev->bt_wb_speech_enabled) {
875 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
876 } else {
877 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
878 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700879 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
880 snd_device = SND_DEVICE_IN_HDMI_MIC;
881 } else {
882 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
883 ALOGW("%s: Using default handset-mic", __func__);
884 snd_device = SND_DEVICE_IN_HANDSET_MIC;
885 }
886 }
887exit:
888 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
889 return snd_device;
890}
891
892int platform_set_hdmi_channels(void *platform, int channel_count)
893{
894 struct platform_data *my_data = (struct platform_data *)platform;
895 struct audio_device *adev = my_data->adev;
896 struct mixer_ctl *ctl;
897 const char *channel_cnt_str = NULL;
898 const char *mixer_ctl_name = "HDMI_RX Channels";
899 switch (channel_count) {
900 case 8:
901 channel_cnt_str = "Eight"; break;
902 case 7:
903 channel_cnt_str = "Seven"; break;
904 case 6:
905 channel_cnt_str = "Six"; break;
906 case 5:
907 channel_cnt_str = "Five"; break;
908 case 4:
909 channel_cnt_str = "Four"; break;
910 case 3:
911 channel_cnt_str = "Three"; break;
912 default:
913 channel_cnt_str = "Two"; break;
914 }
915 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
916 if (!ctl) {
917 ALOGE("%s: Could not get ctl for mixer cmd - %s",
918 __func__, mixer_ctl_name);
919 return -EINVAL;
920 }
921 ALOGV("HDMI channel count: %s", channel_cnt_str);
922 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
923 return 0;
924}
925
Haynes Mathew George24ca9ad2014-06-18 15:14:18 -0700926int platform_edid_get_max_channels(void *platform __unused)
Eric Laurentb23d5282013-05-14 15:27:20 -0700927{
928 FILE *file;
929 struct audio_block_header header;
930 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
931 char *sad = block;
932 int num_audio_blocks;
933 int channel_count;
934 int max_channels = 0;
935 int i;
936
937 file = fopen(AUDIO_DATA_BLOCK_PATH, "rb");
938 if (file == NULL) {
939 ALOGE("Unable to open '%s'", AUDIO_DATA_BLOCK_PATH);
940 return 0;
941 }
942
943 /* Read audio block header */
944 fread(&header, 1, sizeof(header), file);
945
946 /* Read SAD blocks, clamping the maximum size for safety */
947 if (header.length > (int)sizeof(block))
948 header.length = (int)sizeof(block);
949 fread(&block, header.length, 1, file);
950
951 fclose(file);
952
953 /* Calculate the number of SAD blocks */
954 num_audio_blocks = header.length / SAD_BLOCK_SIZE;
955
956 for (i = 0; i < num_audio_blocks; i++) {
957 /* Only consider LPCM blocks */
958 if ((sad[0] >> 3) != EDID_FORMAT_LPCM)
959 continue;
960
961 channel_count = (sad[0] & 0x7) + 1;
962 if (channel_count > max_channels)
963 max_channels = channel_count;
964
965 /* Advance to next block */
966 sad += 3;
967 }
968
969 return max_channels;
970}
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700971
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700972int platform_set_incall_recording_session_id(void *platform __unused,
973 uint32_t session_id __unused, int rec_mode __unused)
974{
Haynes Mathew George24ca9ad2014-06-18 15:14:18 -0700975 ALOGE("%s: Not implemented", __func__);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700976 return -ENOSYS;
977}
978
979int platform_stop_incall_recording_usecase(void *platform __unused)
980{
Haynes Mathew George24ca9ad2014-06-18 15:14:18 -0700981 ALOGE("%s: Not implemented", __func__);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700982 return -ENOSYS;
983}
984
985int platform_start_incall_music_usecase(void *platform __unused)
986{
Haynes Mathew George24ca9ad2014-06-18 15:14:18 -0700987 ALOGE("%s: Not implemented", __func__);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700988 return -ENOSYS;
989}
990
991int platform_stop_incall_music_usecase(void *platform __unused)
992{
Haynes Mathew George24ca9ad2014-06-18 15:14:18 -0700993 ALOGE("%s: Not implemented", __func__);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700994 return -ENOSYS;
995}
996
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700997int platform_set_parameters(void *platform __unused,
998 struct str_parms *parms __unused)
999{
1000 ALOGE("%s: Not implemented", __func__);
1001 return -ENOSYS;
1002}
1003
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07001004/* Delay in Us */
1005int64_t platform_render_latency(audio_usecase_t usecase)
1006{
1007 switch (usecase) {
1008 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
1009 return DEEP_BUFFER_PLATFORM_DELAY;
1010 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
1011 return LOW_LATENCY_PLATFORM_DELAY;
1012 default:
1013 return 0;
1014 }
1015}
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001016
Haynes Mathew George24ca9ad2014-06-18 15:14:18 -07001017int platform_switch_voice_call_enable_device_config(void *platform __unused,
1018 snd_device_t out_snd_device __unused,
1019 snd_device_t in_snd_device __unused)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001020{
1021 return 0;
1022}
1023
Haynes Mathew George24ca9ad2014-06-18 15:14:18 -07001024int platform_switch_voice_call_usecase_route_post(void *platform __unused,
1025 snd_device_t out_snd_device __unused,
1026 snd_device_t in_snd_device __unused)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001027{
1028 return 0;
1029}
Haynes Mathew George24ca9ad2014-06-18 15:14:18 -07001030
1031int platform_get_sample_rate(void *platform __unused, uint32_t *rate __unused)
1032{
1033 return -ENOSYS;
1034}
Haynes Mathew George98c95622014-06-20 19:14:25 -07001035
1036int platform_get_usecase_index(const char * usecase __unused)
1037{
1038 return -ENOSYS;
1039}
1040
1041int platform_set_usecase_pcm_id(audio_usecase_t usecase __unused, int32_t type __unused,
1042 int32_t pcm_id __unused)
1043{
1044 return -ENOSYS;
1045}
1046
1047int platform_set_snd_device_backend(snd_device_t device __unused,
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001048 const char *backend __unused,
1049 const char *hw_interface __unused)
Haynes Mathew George98c95622014-06-20 19:14:25 -07001050{
1051 return -ENOSYS;
1052}
Eric Laurentcefbbac2014-09-04 13:54:10 -05001053
vivek mehta1a9b7c02015-06-25 11:49:38 -07001054void platform_set_echo_reference(struct audio_device *adev __unused,
1055 bool enable __unused,
1056 audio_devices_t out_device __unused)
Eric Laurentcefbbac2014-09-04 13:54:10 -05001057{
1058 return;
1059}
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07001060
vivek mehtae59cfb22017-06-16 15:57:11 -07001061#define DEFAULT_NOMINAL_SPEAKER_GAIN 20
1062int ramp_speaker_gain(struct audio_device *adev, bool ramp_up, int target_ramp_up_gain) {
1063 // backup_gain: gain to try to set in case of an error during ramp
1064 int start_gain, end_gain, step, backup_gain, i;
1065 bool error = false;
1066 const struct mixer_ctl *ctl;
1067 const char *mixer_ctl_name_gain_left = "Left Speaker Gain";
1068 const char *mixer_ctl_name_gain_right = "Right Speaker Gain";
1069 struct mixer_ctl *ctl_left = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_left);
1070 struct mixer_ctl *ctl_right = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_right);
1071 if (!ctl_left || !ctl_right) {
1072 ALOGE("%s: Could not get ctl for mixer cmd - %s or %s, not applying speaker gain ramp",
1073 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
1074 return -EINVAL;
1075 } else if ((mixer_ctl_get_num_values(ctl_left) != 1)
1076 || (mixer_ctl_get_num_values(ctl_right) != 1)) {
1077 ALOGE("%s: Unexpected num values for mixer cmd - %s or %s, not applying speaker gain ramp",
1078 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
1079 return -EINVAL;
1080 }
1081 if (ramp_up) {
1082 start_gain = 0;
1083 end_gain = target_ramp_up_gain > 0 ? target_ramp_up_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
1084 step = +1;
1085 backup_gain = end_gain;
1086 } else {
1087 // using same gain on left and right
1088 const int left_gain = mixer_ctl_get_value(ctl_left, 0);
1089 start_gain = left_gain > 0 ? left_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
1090 end_gain = 0;
1091 step = -1;
1092 backup_gain = start_gain;
1093 }
1094 for (i = start_gain ; i != (end_gain + step) ; i += step) {
1095 //ALOGV("setting speaker gain to %d", i);
1096 if (mixer_ctl_set_value(ctl_left, 0, i)) {
1097 ALOGE("%s: error setting %s to %d during gain ramp",
1098 __func__, mixer_ctl_name_gain_left, i);
1099 error = true;
1100 break;
1101 }
1102 if (mixer_ctl_set_value(ctl_right, 0, i)) {
1103 ALOGE("%s: error setting %s to %d during gain ramp",
1104 __func__, mixer_ctl_name_gain_right, i);
1105 error = true;
1106 break;
1107 }
1108 usleep(1000);
1109 }
1110 if (error) {
1111 // an error occured during the ramp, let's still try to go back to a safe volume
1112 if (mixer_ctl_set_value(ctl_left, 0, backup_gain)) {
1113 ALOGE("%s: error restoring left gain to %d", __func__, backup_gain);
1114 }
1115 if (mixer_ctl_set_value(ctl_right, 0, backup_gain)) {
1116 ALOGE("%s: error restoring right gain to %d", __func__, backup_gain);
1117 }
1118 }
1119 return start_gain;
1120}
1121
1122int platform_set_swap_mixer(struct audio_device *adev, bool swap_channels)
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07001123{
vivek mehtae59cfb22017-06-16 15:57:11 -07001124 const char *mixer_ctl_name = "Swap channel";
1125 struct mixer_ctl *ctl;
1126 const char *mixer_path;
1127 struct platform_data *my_data = (struct platform_data *)adev->platform;
1128
1129 // forced to set to swap, but device not rotated ... ignore set
1130 if (swap_channels && !my_data->speaker_lr_swap)
1131 return 0;
1132
1133 ALOGV("%s:", __func__);
1134
1135 if (swap_channels) {
1136 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER_REVERSE);
1137 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
1138 } else {
1139 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER);
1140 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
1141 }
1142
1143 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1144 if (!ctl) {
1145 ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name);
1146 return -EINVAL;
1147 }
1148
1149 if (mixer_ctl_set_value(ctl, 0, swap_channels) < 0) {
1150 ALOGE("%s: Could not set reverse cotrol %d",__func__, swap_channels);
1151 return -EINVAL;
1152 }
1153
1154 ALOGV("platfor_force_swap_channel :: Channel orientation ( %s ) ",
1155 swap_channels?"R --> L":"L --> R");
1156
1157 return 0;
1158}
1159
1160int platform_check_and_set_swap_lr_channels(struct audio_device *adev, bool swap_channels)
1161{
1162 // only update if there is active pcm playback on speaker
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07001163 struct audio_usecase *usecase;
1164 struct listnode *node;
1165 struct platform_data *my_data = (struct platform_data *)adev->platform;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07001166
vivek mehtae59cfb22017-06-16 15:57:11 -07001167 my_data->speaker_lr_swap = swap_channels;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07001168
vivek mehtae59cfb22017-06-16 15:57:11 -07001169 return platform_set_swap_channels(adev, swap_channels);
1170}
1171
1172int platform_set_swap_channels(struct audio_device *adev, bool swap_channels)
1173{
1174 // only update if there is active pcm playback on speaker
1175 struct audio_usecase *usecase;
1176 struct listnode *node;
1177 struct platform_data *my_data = (struct platform_data *)adev->platform;
1178
1179 // do not swap channels in audio modes with concurrent capture and playback
1180 // as this may break the echo reference
1181 if ((adev->mode == AUDIO_MODE_IN_COMMUNICATION) || (adev->mode == AUDIO_MODE_IN_CALL)) {
1182 ALOGV("%s: will not swap due to audio mode %d", __func__, adev->mode);
1183 return 0;
1184 }
1185
1186 list_for_each(node, &adev->usecase_list) {
1187 usecase = node_to_item(node, struct audio_usecase, list);
1188 if (usecase->type == PCM_PLAYBACK &&
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07001189 usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) {
vivek mehtae59cfb22017-06-16 15:57:11 -07001190 /*
1191 * If acdb tuning is different for SPEAKER_REVERSE, it is must
1192 * to perform device switch to disable the current backend to
1193 * enable it with new acdb data.
1194 */
1195 if (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
1196 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]) {
1197 const int initial_skpr_gain = ramp_speaker_gain(adev, false /*ramp_up*/, -1);
1198 select_devices(adev, usecase->id);
1199 if (initial_skpr_gain != -EINVAL)
1200 ramp_speaker_gain(adev, true /*ramp_up*/, initial_skpr_gain);
1201
1202 } else {
1203 platform_set_swap_mixer(adev, swap_channels);
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07001204 }
vivek mehtae59cfb22017-06-16 15:57:11 -07001205 break;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07001206 }
1207 }
vivek mehtae59cfb22017-06-16 15:57:11 -07001208
1209 return 0;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07001210}
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001211
1212bool platform_send_gain_dep_cal(void *platform __unused,
1213 int level __unused)
1214{
vivek mehtafb4d7bd2016-04-29 03:16:47 -07001215 return true;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001216}
1217
Haynes Mathew George2d809e02016-09-22 17:38:16 -07001218int platform_can_split_snd_device(snd_device_t in_snd_device __unused,
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001219 int *num_devices __unused,
1220 snd_device_t *out_snd_devices __unused)
1221{
Haynes Mathew George2d809e02016-09-22 17:38:16 -07001222 return -ENOSYS;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001223}
1224
1225bool platform_check_backends_match(snd_device_t snd_device1 __unused,
1226 snd_device_t snd_device2 __unused)
1227{
1228 return true;
1229}
vivek mehtade4849c2016-03-03 17:23:38 -08001230
1231int platform_get_snd_device_name_extn(void *platform __unused,
1232 snd_device_t snd_device,
1233 char *device_name)
1234{
David Benjamin1565f992016-09-21 12:10:34 -04001235 strlcpy(device_name, platform_get_snd_device_name(snd_device),
1236 DEVICE_NAME_MAX_SIZE);
vivek mehtade4849c2016-03-03 17:23:38 -08001237 return 0;
1238}
1239
David Linee3fe402017-03-13 10:00:42 -07001240bool platform_check_and_set_playback_backend_cfg(struct audio_device* adev __unused,
1241 struct audio_usecase *usecase __unused,
1242 snd_device_t snd_device __unused)
1243{
1244 return false;
1245}
1246
vivek mehta4ed66e62016-04-15 23:33:34 -07001247bool platform_check_and_set_capture_backend_cfg(struct audio_device* adev __unused,
David Lind6229bd2017-07-06 15:28:55 -07001248 struct audio_usecase *usecase __unused, snd_device_t snd_device __unused)
vivek mehta4ed66e62016-04-15 23:33:34 -07001249{
1250 return false;
1251}
1252
vivek mehtaa8d7c922016-05-25 14:40:44 -07001253bool platform_add_gain_level_mapping(struct amp_db_and_gain_table *tbl_entry __unused)
1254{
1255 return false;
1256}
1257
1258int platform_get_gain_level_mapping(struct amp_db_and_gain_table *mapping_tbl __unused,
1259 int table_size __unused)
1260{
1261 return 0;
1262}
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001263
Tom Cherry8721b4d2016-07-14 16:12:23 -07001264int platform_snd_card_update(void *platform __unused,
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001265 card_status_t status __unused)
1266{
1267 return -1;
1268}
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001269
David Lind6229bd2017-07-06 15:28:55 -07001270int platform_get_snd_device_backend_index(snd_device_t snd_device __unused)
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001271{
1272 return -ENOSYS;
1273}
1274
David Lind6229bd2017-07-06 15:28:55 -07001275void platform_check_and_update_copp_sample_rate(void* platform __unused, snd_device_t snd_device __unused,
1276 unsigned int stream_sr __unused, int* sample_rate __unused)
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001277{
1278
1279}
1280
David Lind6229bd2017-07-06 15:28:55 -07001281int platform_send_audio_calibration_v2(void *platform __unused, struct audio_usecase *usecase __unused,
1282 int app_type __unused, int sample_rate __unused)
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001283{
1284 return -ENOSYS;
1285}
1286
1287bool platform_supports_app_type_cfg() { return false; }
1288
vivek mehtaa68fea62017-06-08 19:04:02 -07001289void platform_add_app_type(const char *uc_type __unused,
1290 const char *mode __unused,
1291 int bw __unused, int app_type __unused,
1292 int max_sr __unused) {}
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001293
vivek mehtaa68fea62017-06-08 19:04:02 -07001294int platform_get_app_type_v2(void *platform __unused,
1295 enum usecase_type_t type __unused,
1296 const char *mode __unused,
1297 int bw __unused, int sr __unused,
1298 int *app_type __unused) {
1299 return -ENOSYS;
1300}
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001301
vivek mehta90933872017-06-15 18:04:39 -07001302int platform_set_sidetone(struct audio_device *adev,
1303 snd_device_t out_snd_device,
1304 bool enable, char *str)
1305{
1306 int ret;
1307 if (out_snd_device == SND_DEVICE_OUT_USB_HEADSET ||
1308 out_snd_device == SND_DEVICE_OUT_VOICE_USB_HEADSET) {
1309 ret = audio_extn_usb_enable_sidetone(out_snd_device, enable);
1310 if (ret)
1311 ALOGI("%s: usb device %d does not support device sidetone\n",
1312 __func__, out_snd_device);
1313 } else {
1314 ALOGV("%s: sidetone out device(%d) mixer cmd = %s\n",
1315 __func__, out_snd_device, str);
1316 if (enable)
1317 audio_route_apply_and_update_path(adev->audio_route, str);
1318 else
1319 audio_route_reset_and_update_path(adev->audio_route, str);
1320 }
1321 return 0;
1322}
Haynes Mathew George96483a22017-03-28 14:52:47 -07001323
1324int platform_get_mmap_data_fd(void *platform __unused, int fe_dev __unused, int dir __unused,
1325 int *fd __unused, uint32_t *size __unused)
1326{
1327 return -ENOSYS;
1328}