blob: d3c0aea85cabfb4559fcdb6cfe2a0df4e502c0e0 [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"
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",
121 [SND_DEVICE_OUT_HEADPHONES] = "headphones",
122 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones",
123 [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker",
124 [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones",
125 [SND_DEVICE_OUT_HDMI] = "hdmi",
126 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi",
127 [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700128 [SND_DEVICE_OUT_BT_SCO_WB] = "bt-sco-headset-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700129 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = "voice-handset-tmus",
Eric Laurent788f41f2015-08-24 12:21:50 -0700130 [SND_DEVICE_OUT_VOICE_HANDSET] = "voice-handset-tmus",
131 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = "voice-handset-tmus",
Eric Laurentb23d5282013-05-14 15:27:20 -0700132 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones",
133 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones",
134 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset",
Eric Laurentb1b07992017-06-29 09:20:02 -0700135 [SND_DEVICE_OUT_USB_HEADSET] = "usb-headset",
136 [SND_DEVICE_OUT_USB_HEADPHONES] = "usb-headphones",
137 [SND_DEVICE_OUT_VOICE_USB_HEADSET] = "usb-headset",
138 [SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = "usb-headphones",
139
Eric Laurentb23d5282013-05-14 15:27:20 -0700140
141 /* Capture sound devices */
142 [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
143 [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
144 [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
145 [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic",
146 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "voice-speaker-mic",
147 [SND_DEVICE_IN_HEADSET_MIC_AEC] = "headset-mic",
148 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
149 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
150 [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic",
151 [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700152 [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700153 [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic",
154 [SND_DEVICE_IN_VOICE_DMIC_EF] = "voice-dmic-ef",
155 [SND_DEVICE_IN_VOICE_DMIC_BS] = "voice-dmic-bs",
156 [SND_DEVICE_IN_VOICE_DMIC_EF_TMUS] = "voice-dmic-ef-tmus",
157 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_EF] = "voice-speaker-dmic-ef",
158 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BS] = "voice-speaker-dmic-bs",
159 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
160 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
161 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
162 [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
163 [SND_DEVICE_IN_VOICE_REC_DMIC_EF] = "voice-rec-dmic-ef",
164 [SND_DEVICE_IN_VOICE_REC_DMIC_BS] = "voice-rec-dmic-bs",
165 [SND_DEVICE_IN_VOICE_REC_DMIC_EF_FLUENCE] = "voice-rec-dmic-ef-fluence",
166 [SND_DEVICE_IN_VOICE_REC_DMIC_BS_FLUENCE] = "voice-rec-dmic-bs-fluence",
167};
168
169/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
170static const int acdb_device_table[SND_DEVICE_MAX] = {
171 [SND_DEVICE_NONE] = -1,
172 [SND_DEVICE_OUT_HANDSET] = 7,
173 [SND_DEVICE_OUT_SPEAKER] = 14,
174 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 14,
175 [SND_DEVICE_OUT_HEADPHONES] = 10,
176 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
177 [SND_DEVICE_OUT_VOICE_SPEAKER] = 14,
178 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
179 [SND_DEVICE_OUT_HDMI] = 18,
180 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 14,
181 [SND_DEVICE_OUT_BT_SCO] = 22,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700182 [SND_DEVICE_OUT_BT_SCO_WB] = 39,
Eric Laurentb23d5282013-05-14 15:27:20 -0700183 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = 81,
Eric Laurent788f41f2015-08-24 12:21:50 -0700184 [SND_DEVICE_OUT_VOICE_HANDSET] = 81,
185 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = 81,
Eric Laurentb23d5282013-05-14 15:27:20 -0700186 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
187 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
188 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
Eric Laurentb1b07992017-06-29 09:20:02 -0700189 [SND_DEVICE_OUT_USB_HEADSET] = 45,
190 [SND_DEVICE_OUT_USB_HEADPHONES] = 45,
191 [SND_DEVICE_OUT_VOICE_USB_HEADSET] = 45,
192 [SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = 45,
Eric Laurentb23d5282013-05-14 15:27:20 -0700193
194 [SND_DEVICE_IN_HANDSET_MIC] = 4,
195 [SND_DEVICE_IN_SPEAKER_MIC] = 4,
196 [SND_DEVICE_IN_HEADSET_MIC] = 8,
197 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 40,
198 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 42,
199 [SND_DEVICE_IN_HEADSET_MIC_AEC] = 47,
200 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
201 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = 8,
202 [SND_DEVICE_IN_HDMI_MIC] = 4,
203 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700204 [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38,
Eric Laurentb23d5282013-05-14 15:27:20 -0700205 [SND_DEVICE_IN_CAMCORDER_MIC] = 61,
206 [SND_DEVICE_IN_VOICE_DMIC_EF] = 6,
207 [SND_DEVICE_IN_VOICE_DMIC_BS] = 5,
208 [SND_DEVICE_IN_VOICE_DMIC_EF_TMUS] = 91,
209 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_EF] = 13,
210 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BS] = 12,
211 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
212 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
213 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
214 [SND_DEVICE_IN_VOICE_REC_MIC] = 62,
215 /* TODO: Update with proper acdb ids */
216 [SND_DEVICE_IN_VOICE_REC_DMIC_EF] = 62,
217 [SND_DEVICE_IN_VOICE_REC_DMIC_BS] = 62,
218 [SND_DEVICE_IN_VOICE_REC_DMIC_EF_FLUENCE] = 6,
219 [SND_DEVICE_IN_VOICE_REC_DMIC_BS_FLUENCE] = 5,
220};
221
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700222#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
223#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
224
Eric Laurentb23d5282013-05-14 15:27:20 -0700225static pthread_once_t check_op_once_ctl = PTHREAD_ONCE_INIT;
226static bool is_tmus = false;
227
228static void check_operator()
229{
230 char value[PROPERTY_VALUE_MAX];
231 int mccmnc;
232 property_get("gsm.sim.operator.numeric",value,"0");
233 mccmnc = atoi(value);
234 ALOGD("%s: tmus mccmnc %d", __func__, mccmnc);
235 switch(mccmnc) {
236 /* TMUS MCC(310), MNC(490, 260, 026) */
237 case 310490:
238 case 310260:
239 case 310026:
240 is_tmus = true;
241 break;
242 }
243}
244
245bool is_operator_tmus()
246{
247 pthread_once(&check_op_once_ctl, check_operator);
248 return is_tmus;
249}
250
251static int set_echo_reference(struct mixer *mixer, const char* ec_ref)
252{
253 struct mixer_ctl *ctl;
254 const char *mixer_ctl_name = "EC_REF_RX";
255
256 ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name);
257 if (!ctl) {
258 ALOGE("%s: Could not get ctl for mixer cmd - %s",
259 __func__, mixer_ctl_name);
260 return -EINVAL;
261 }
262 ALOGV("Setting EC Reference: %s", ec_ref);
263 mixer_ctl_set_enum_by_string(ctl, ec_ref);
264 return 0;
265}
266
267void *platform_init(struct audio_device *adev)
268{
269 char platform[PROPERTY_VALUE_MAX];
270 char baseband[PROPERTY_VALUE_MAX];
271 char value[PROPERTY_VALUE_MAX];
272 struct platform_data *my_data;
273
sangwoo1b9f4b32013-06-21 18:22:55 -0700274 adev->mixer = mixer_open(MIXER_CARD);
275
276 if (!adev->mixer) {
277 ALOGE("Unable to open the mixer, aborting.");
278 return NULL;
279 }
280
281 adev->audio_route = audio_route_init(MIXER_CARD, MIXER_XML_PATH);
282 if (!adev->audio_route) {
283 ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
284 return NULL;
285 }
286
Eric Laurentb23d5282013-05-14 15:27:20 -0700287 my_data = calloc(1, sizeof(struct platform_data));
288
289 my_data->adev = adev;
290 my_data->dualmic_config = DUALMIC_CONFIG_NONE;
291 my_data->fluence_in_spkr_mode = false;
292 my_data->fluence_in_voice_call = false;
293 my_data->fluence_in_voice_rec = false;
294
295 property_get("persist.audio.dualmic.config",value,"");
296 if (!strcmp("broadside", value)) {
297 my_data->dualmic_config = DUALMIC_CONFIG_BROADSIDE;
298 adev->acdb_settings |= DMIC_FLAG;
299 } else if (!strcmp("endfire", value)) {
300 my_data->dualmic_config = DUALMIC_CONFIG_ENDFIRE;
301 adev->acdb_settings |= DMIC_FLAG;
302 }
303
304 if (my_data->dualmic_config != DUALMIC_CONFIG_NONE) {
305 property_get("persist.audio.fluence.voicecall",value,"");
306 if (!strcmp("true", value)) {
307 my_data->fluence_in_voice_call = true;
308 }
309
310 property_get("persist.audio.fluence.voicerec",value,"");
311 if (!strcmp("true", value)) {
312 my_data->fluence_in_voice_rec = true;
313 }
314
315 property_get("persist.audio.fluence.speaker",value,"");
316 if (!strcmp("true", value)) {
317 my_data->fluence_in_spkr_mode = true;
318 }
319 }
320
321 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
322 if (my_data->acdb_handle == NULL) {
323 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
324 } else {
325 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
326 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
327 "acdb_loader_deallocate_ACDB");
328 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
329 "acdb_loader_send_audio_cal");
330 if (!my_data->acdb_send_audio_cal)
331 ALOGW("%s: Could not find the symbol acdb_send_audio_cal from %s",
332 __func__, LIB_ACDB_LOADER);
333 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
334 "acdb_loader_send_voice_cal");
335 my_data->acdb_init = (acdb_init_t)dlsym(my_data->acdb_handle,
336 "acdb_loader_init_ACDB");
337 if (my_data->acdb_init == NULL)
338 ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__, dlerror());
339 else
340 my_data->acdb_init();
341 }
342
343 /* If platform is Fusion3, load CSD Client specific symbols
344 * Voice call is handled by MDM and apps processor talks to
345 * MDM through CSD Client
346 */
347 property_get("ro.board.platform", platform, "");
348 property_get("ro.baseband", baseband, "");
349 if (!strcmp("msm8960", platform) && !strcmp("mdm", baseband)) {
350 my_data->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
351 if (my_data->csd_client == NULL)
352 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
353 }
354
355 if (my_data->csd_client) {
356 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
357 my_data->csd_client_deinit = (csd_client_deinit_t)dlsym(my_data->csd_client,
358 "csd_client_deinit");
359 my_data->csd_disable_device = (csd_disable_device_t)dlsym(my_data->csd_client,
360 "csd_client_disable_device");
361 my_data->csd_enable_device = (csd_enable_device_t)dlsym(my_data->csd_client,
362 "csd_client_enable_device");
363 my_data->csd_start_voice = (csd_start_voice_t)dlsym(my_data->csd_client,
364 "csd_client_start_voice");
365 my_data->csd_stop_voice = (csd_stop_voice_t)dlsym(my_data->csd_client,
366 "csd_client_stop_voice");
367 my_data->csd_volume = (csd_volume_t)dlsym(my_data->csd_client,
368 "csd_client_volume");
369 my_data->csd_mic_mute = (csd_mic_mute_t)dlsym(my_data->csd_client,
370 "csd_client_mic_mute");
371 my_data->csd_client_init = (csd_client_init_t)dlsym(my_data->csd_client,
372 "csd_client_init");
373
374 if (my_data->csd_client_init == NULL) {
375 ALOGE("%s: dlsym error %s for csd_client_init", __func__, dlerror());
376 } else {
377 my_data->csd_client_init();
378 }
379 }
380
381 return my_data;
382}
383
384void platform_deinit(void *platform)
385{
386 free(platform);
387}
388
389const char *platform_get_snd_device_name(snd_device_t snd_device)
390{
391 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX)
392 return device_table[snd_device];
393 else
Ravi Kumar Alamanda64026462014-09-15 00:08:58 -0700394 return "none";
Eric Laurentb23d5282013-05-14 15:27:20 -0700395}
396
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -0500397void platform_add_backend_name(void *platform __unused, char *mixer_path,
398 snd_device_t snd_device)
Eric Laurentb23d5282013-05-14 15:27:20 -0700399{
400 if (snd_device == SND_DEVICE_IN_BT_SCO_MIC)
401 strcat(mixer_path, " bt-sco");
402 else if(snd_device == SND_DEVICE_OUT_BT_SCO)
403 strcat(mixer_path, " bt-sco");
404 else if (snd_device == SND_DEVICE_OUT_HDMI)
405 strcat(mixer_path, " hdmi");
406 else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HDMI)
407 strcat(mixer_path, " speaker-and-hdmi");
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700408 else if (snd_device == SND_DEVICE_OUT_BT_SCO_WB ||
409 snd_device == SND_DEVICE_IN_BT_SCO_MIC_WB)
410 strcat(mixer_path, " bt-sco-wb");
Eric Laurentb23d5282013-05-14 15:27:20 -0700411}
412
413int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
414{
415 int device_id;
416 if (device_type == PCM_PLAYBACK)
417 device_id = pcm_device_table[usecase][0];
418 else
419 device_id = pcm_device_table[usecase][1];
420 return device_id;
421}
422
Haynes Mathew George98c95622014-06-20 19:14:25 -0700423int platform_get_snd_device_index(char *snd_device_index_name __unused)
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700424{
425 return -ENODEV;
426}
427
Haynes Mathew George98c95622014-06-20 19:14:25 -0700428int platform_set_snd_device_acdb_id(snd_device_t snd_device __unused,
429 unsigned int acdb_id __unused)
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700430{
431 return -ENODEV;
432}
433
David Lind6229bd2017-07-06 15:28:55 -0700434int platform_get_default_app_type_v2(void *platform __unused, usecase_type_t type __unused,
Yamit Mehtae3b99562016-09-16 22:44:00 +0530435 int *app_type __unused)
436{
437 ALOGE("%s: Not implemented", __func__);
438 return -ENOSYS;
439}
440
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700441int platform_get_snd_device_acdb_id(snd_device_t snd_device __unused)
442{
443 ALOGE("%s: Not implemented", __func__);
444 return -ENOSYS;
445}
446
Eric Laurent788f41f2015-08-24 12:21:50 -0700447void platform_add_operator_specific_device(snd_device_t snd_device __unused,
448 const char *operator __unused,
449 const char *mixer_path __unused,
450 unsigned int acdb_id __unused)
keunhui.park2f7306a2015-07-16 16:48:06 +0900451{
452}
453
Eric Laurentb23d5282013-05-14 15:27:20 -0700454int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
455{
456 struct platform_data *my_data = (struct platform_data *)platform;
457 int acdb_dev_id, acdb_dev_type;
458
459 acdb_dev_id = acdb_device_table[snd_device];
460 if (acdb_dev_id < 0) {
461 ALOGE("%s: Could not find acdb id for device(%d)",
462 __func__, snd_device);
463 return -EINVAL;
464 }
465 if (my_data->acdb_send_audio_cal) {
Eric Laurent994a6932013-07-17 11:51:42 -0700466 ("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Eric Laurentb23d5282013-05-14 15:27:20 -0700467 __func__, snd_device, acdb_dev_id);
468 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
469 snd_device < SND_DEVICE_OUT_END)
470 acdb_dev_type = ACDB_DEV_TYPE_OUT;
471 else
472 acdb_dev_type = ACDB_DEV_TYPE_IN;
473 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
474 }
475 return 0;
476}
477
478int platform_switch_voice_call_device_pre(void *platform)
479{
480 struct platform_data *my_data = (struct platform_data *)platform;
481 int ret = 0;
482
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -0700483 if (my_data->csd_client != NULL &&
484 voice_is_in_call(my_data->adev)) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700485 /* This must be called before disabling the mixer controls on APQ side */
486 if (my_data->csd_disable_device == NULL) {
487 ALOGE("%s: dlsym error for csd_disable_device", __func__);
488 } else {
489 ret = my_data->csd_disable_device();
490 if (ret < 0) {
491 ALOGE("%s: csd_client_disable_device, failed, error %d",
492 __func__, ret);
493 }
494 }
495 }
496 return ret;
497}
498
499int platform_switch_voice_call_device_post(void *platform,
500 snd_device_t out_snd_device,
501 snd_device_t in_snd_device)
502{
503 struct platform_data *my_data = (struct platform_data *)platform;
504 int acdb_rx_id, acdb_tx_id;
505 int ret = 0;
506
507 if (my_data->csd_client) {
508 if (my_data->csd_enable_device == NULL) {
509 ALOGE("%s: dlsym error for csd_enable_device",
510 __func__);
511 } else {
512 acdb_rx_id = acdb_device_table[out_snd_device];
513 acdb_tx_id = acdb_device_table[in_snd_device];
514
515 if (acdb_rx_id > 0 || acdb_tx_id > 0) {
516 ret = my_data->csd_enable_device(acdb_rx_id, acdb_tx_id,
517 my_data->adev->acdb_settings);
518 if (ret < 0) {
519 ALOGE("%s: csd_enable_device, failed, error %d",
520 __func__, ret);
521 }
522 } else {
523 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
524 acdb_rx_id, acdb_tx_id);
525 }
526 }
527 }
528
529 return ret;
530}
531
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700532int platform_start_voice_call(void *platform, uint32_t vsid __unused)
Eric Laurentb23d5282013-05-14 15:27:20 -0700533{
534 struct platform_data *my_data = (struct platform_data *)platform;
535 int ret = 0;
536
537 if (my_data->csd_client) {
538 if (my_data->csd_start_voice == NULL) {
539 ALOGE("dlsym error for csd_client_start_voice");
540 ret = -ENOSYS;
541 } else {
542 ret = my_data->csd_start_voice();
543 if (ret < 0) {
544 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
545 }
546 }
547 }
548
549 return ret;
550}
551
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700552int platform_stop_voice_call(void *platform, uint32_t vsid __unused)
Eric Laurentb23d5282013-05-14 15:27:20 -0700553{
554 struct platform_data *my_data = (struct platform_data *)platform;
555 int ret = 0;
556
557 if (my_data->csd_client) {
558 if (my_data->csd_stop_voice == NULL) {
559 ALOGE("dlsym error for csd_stop_voice");
560 } else {
561 ret = my_data->csd_stop_voice();
562 if (ret < 0) {
563 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
564 }
565 }
566 }
567
568 return ret;
569}
570
vivek mehtab6506412015-08-07 16:55:17 -0700571void platform_set_speaker_gain_in_combo(struct audio_device *adev __unused,
Eric Laurent788f41f2015-08-24 12:21:50 -0700572 snd_device_t snd_device __unused,
vivek mehtab6506412015-08-07 16:55:17 -0700573 bool enable __unused) {
574}
575
Eric Laurentb23d5282013-05-14 15:27:20 -0700576int platform_set_voice_volume(void *platform, int volume)
577{
578 struct platform_data *my_data = (struct platform_data *)platform;
579 int ret = 0;
580
581 if (my_data->csd_client) {
582 if (my_data->csd_volume == NULL) {
583 ALOGE("%s: dlsym error for csd_volume", __func__);
584 } else {
585 ret = my_data->csd_volume(volume);
586 if (ret < 0) {
587 ALOGE("%s: csd_volume error %d", __func__, ret);
588 }
589 }
590 } else {
591 ALOGE("%s: No CSD Client present", __func__);
592 }
593
594 return ret;
595}
596
597int platform_set_mic_mute(void *platform, bool state)
598{
599 struct platform_data *my_data = (struct platform_data *)platform;
600 int ret = 0;
601
602 if (my_data->adev->mode == AUDIO_MODE_IN_CALL) {
603 if (my_data->csd_client) {
604 if (my_data->csd_mic_mute == NULL) {
605 ALOGE("%s: dlsym error for csd_mic_mute", __func__);
606 } else {
607 ret = my_data->csd_mic_mute(state);
608 if (ret < 0) {
609 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
610 }
611 }
612 } else {
613 ALOGE("%s: No CSD Client present", __func__);
614 }
615 }
616
617 return ret;
618}
619
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700620int platform_set_device_mute(void *platform __unused, bool state __unused, char *dir __unused)
621{
Haynes Mathew George24ca9ad2014-06-18 15:14:18 -0700622 ALOGE("%s: Not implemented", __func__);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700623 return -ENOSYS;
624}
625
Eric Laurentb23d5282013-05-14 15:27:20 -0700626snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
627{
628 struct platform_data *my_data = (struct platform_data *)platform;
629 struct audio_device *adev = my_data->adev;
630 audio_mode_t mode = adev->mode;
631 snd_device_t snd_device = SND_DEVICE_NONE;
632
633 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
634 if (devices == AUDIO_DEVICE_NONE ||
635 devices & AUDIO_DEVICE_BIT_IN) {
636 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
637 goto exit;
638 }
639
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -0700640 if (voice_is_in_call(adev)) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700641 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
642 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
Haynes Mathew George24ca9ad2014-06-18 15:14:18 -0700643 if (adev->voice.tty_mode == TTY_MODE_FULL)
Eric Laurentb23d5282013-05-14 15:27:20 -0700644 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
Haynes Mathew George24ca9ad2014-06-18 15:14:18 -0700645 else if (adev->voice.tty_mode == TTY_MODE_VCO)
Eric Laurentb23d5282013-05-14 15:27:20 -0700646 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
Haynes Mathew George24ca9ad2014-06-18 15:14:18 -0700647 else if (adev->voice.tty_mode == TTY_MODE_HCO)
Eric Laurentb23d5282013-05-14 15:27:20 -0700648 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
649 else
650 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
651 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700652 if (adev->bt_wb_speech_enabled) {
653 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
654 } else {
655 snd_device = SND_DEVICE_OUT_BT_SCO;
656 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700657 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
658 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
659 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
660 if (is_operator_tmus())
661 snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS;
662 else
663 snd_device = SND_DEVICE_OUT_HANDSET;
664 }
665 if (snd_device != SND_DEVICE_NONE) {
666 goto exit;
667 }
668 }
669
670 if (popcount(devices) == 2) {
671 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
672 AUDIO_DEVICE_OUT_SPEAKER)) {
673 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
674 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
675 AUDIO_DEVICE_OUT_SPEAKER)) {
676 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
677 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
678 AUDIO_DEVICE_OUT_SPEAKER)) {
679 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
680 } else {
681 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
682 goto exit;
683 }
684 if (snd_device != SND_DEVICE_NONE) {
685 goto exit;
686 }
687 }
688
689 if (popcount(devices) != 1) {
690 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
691 goto exit;
692 }
693
694 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
695 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
696 snd_device = SND_DEVICE_OUT_HEADPHONES;
697 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -0700698 if (my_data->speaker_lr_swap)
Eric Laurentb23d5282013-05-14 15:27:20 -0700699 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
700 else
701 snd_device = SND_DEVICE_OUT_SPEAKER;
702 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700703 if (adev->bt_wb_speech_enabled) {
704 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
705 } else {
706 snd_device = SND_DEVICE_OUT_BT_SCO;
707 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700708 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
709 snd_device = SND_DEVICE_OUT_HDMI ;
710 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
711 snd_device = SND_DEVICE_OUT_HANDSET;
712 } else {
713 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
714 }
715exit:
716 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
717 return snd_device;
718}
719
720snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
721{
722 struct platform_data *my_data = (struct platform_data *)platform;
723 struct audio_device *adev = my_data->adev;
724 audio_source_t source = (adev->active_input == NULL) ?
725 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
726
727 audio_mode_t mode = adev->mode;
728 audio_devices_t in_device = ((adev->active_input == NULL) ?
729 AUDIO_DEVICE_NONE : adev->active_input->device)
730 & ~AUDIO_DEVICE_BIT_IN;
731 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
732 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
733 snd_device_t snd_device = SND_DEVICE_NONE;
734
735 ALOGV("%s: enter: out_device(%#x) in_device(%#x)",
736 __func__, out_device, in_device);
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -0700737 if ((out_device != AUDIO_DEVICE_NONE) && voice_is_in_call(adev)) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700738 if (adev->voice.tty_mode != TTY_MODE_OFF) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700739 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
740 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700741 switch (adev->voice.tty_mode) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700742 case TTY_MODE_FULL:
743 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
744 break;
745 case TTY_MODE_VCO:
746 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
747 break;
748 case TTY_MODE_HCO:
749 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
750 break;
751 default:
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700752 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
Eric Laurentb23d5282013-05-14 15:27:20 -0700753 }
754 goto exit;
755 }
756 }
757 if (out_device & AUDIO_DEVICE_OUT_EARPIECE ||
758 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
759 if (my_data->fluence_in_voice_call == false) {
760 snd_device = SND_DEVICE_IN_HANDSET_MIC;
761 } else {
762 if (my_data->dualmic_config == DUALMIC_CONFIG_ENDFIRE) {
763 if (is_operator_tmus())
764 snd_device = SND_DEVICE_IN_VOICE_DMIC_EF_TMUS;
765 else
766 snd_device = SND_DEVICE_IN_VOICE_DMIC_EF;
767 } else if(my_data->dualmic_config == DUALMIC_CONFIG_BROADSIDE)
768 snd_device = SND_DEVICE_IN_VOICE_DMIC_BS;
769 else
770 snd_device = SND_DEVICE_IN_HANDSET_MIC;
771 }
772 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
773 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
774 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700775 if (adev->bt_wb_speech_enabled) {
776 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
777 } else {
778 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
779 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700780 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
781 if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode &&
782 my_data->dualmic_config == DUALMIC_CONFIG_ENDFIRE) {
783 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC_EF;
784 } else if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode &&
785 my_data->dualmic_config == DUALMIC_CONFIG_BROADSIDE) {
786 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BS;
787 } else {
788 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
789 }
790 }
791 } else if (source == AUDIO_SOURCE_CAMCORDER) {
792 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
793 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
794 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
795 }
796 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
797 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
798 if (my_data->dualmic_config == DUALMIC_CONFIG_ENDFIRE) {
799 if (channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK)
800 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_EF;
801 else if (my_data->fluence_in_voice_rec)
802 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_EF_FLUENCE;
803 } else if (my_data->dualmic_config == DUALMIC_CONFIG_BROADSIDE) {
804 if (channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK)
805 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_BS;
806 else if (my_data->fluence_in_voice_rec)
807 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_BS_FLUENCE;
808 }
809
810 if (snd_device == SND_DEVICE_NONE) {
811 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
812 }
813 }
Eric Laurent50a38ed2015-10-14 18:48:06 -0700814 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION ||
815 mode == AUDIO_MODE_IN_COMMUNICATION) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700816 if (out_device & AUDIO_DEVICE_OUT_SPEAKER)
817 in_device = AUDIO_DEVICE_IN_BACK_MIC;
818 if (adev->active_input) {
819 if (adev->active_input->enable_aec) {
820 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
821 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
822 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
823 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
824 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
825 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
826 }
827 set_echo_reference(adev->mixer, "SLIM_RX");
828 } else
829 set_echo_reference(adev->mixer, "NONE");
830 }
831 } else if (source == AUDIO_SOURCE_DEFAULT) {
832 goto exit;
833 }
834
835
836 if (snd_device != SND_DEVICE_NONE) {
837 goto exit;
838 }
839
840 if (in_device != AUDIO_DEVICE_NONE &&
841 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
842 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
843 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
844 snd_device = SND_DEVICE_IN_HANDSET_MIC;
845 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
846 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
847 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
848 snd_device = SND_DEVICE_IN_HEADSET_MIC;
849 } else if (in_device & AUDIO_DEVICE_IN_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 (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
856 snd_device = SND_DEVICE_IN_HDMI_MIC;
857 } else {
858 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
859 ALOGW("%s: Using default handset-mic", __func__);
860 snd_device = SND_DEVICE_IN_HANDSET_MIC;
861 }
862 } else {
863 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
864 snd_device = SND_DEVICE_IN_HANDSET_MIC;
865 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
866 snd_device = SND_DEVICE_IN_HEADSET_MIC;
867 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
868 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
869 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
870 snd_device = SND_DEVICE_IN_HANDSET_MIC;
871 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700872 if (adev->bt_wb_speech_enabled) {
873 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
874 } else {
875 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
876 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700877 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
878 snd_device = SND_DEVICE_IN_HDMI_MIC;
879 } else {
880 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
881 ALOGW("%s: Using default handset-mic", __func__);
882 snd_device = SND_DEVICE_IN_HANDSET_MIC;
883 }
884 }
885exit:
886 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
887 return snd_device;
888}
889
890int platform_set_hdmi_channels(void *platform, int channel_count)
891{
892 struct platform_data *my_data = (struct platform_data *)platform;
893 struct audio_device *adev = my_data->adev;
894 struct mixer_ctl *ctl;
895 const char *channel_cnt_str = NULL;
896 const char *mixer_ctl_name = "HDMI_RX Channels";
897 switch (channel_count) {
898 case 8:
899 channel_cnt_str = "Eight"; break;
900 case 7:
901 channel_cnt_str = "Seven"; break;
902 case 6:
903 channel_cnt_str = "Six"; break;
904 case 5:
905 channel_cnt_str = "Five"; break;
906 case 4:
907 channel_cnt_str = "Four"; break;
908 case 3:
909 channel_cnt_str = "Three"; break;
910 default:
911 channel_cnt_str = "Two"; break;
912 }
913 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
914 if (!ctl) {
915 ALOGE("%s: Could not get ctl for mixer cmd - %s",
916 __func__, mixer_ctl_name);
917 return -EINVAL;
918 }
919 ALOGV("HDMI channel count: %s", channel_cnt_str);
920 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
921 return 0;
922}
923
Haynes Mathew George24ca9ad2014-06-18 15:14:18 -0700924int platform_edid_get_max_channels(void *platform __unused)
Eric Laurentb23d5282013-05-14 15:27:20 -0700925{
926 FILE *file;
927 struct audio_block_header header;
928 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
929 char *sad = block;
930 int num_audio_blocks;
931 int channel_count;
932 int max_channels = 0;
933 int i;
934
935 file = fopen(AUDIO_DATA_BLOCK_PATH, "rb");
936 if (file == NULL) {
937 ALOGE("Unable to open '%s'", AUDIO_DATA_BLOCK_PATH);
938 return 0;
939 }
940
941 /* Read audio block header */
942 fread(&header, 1, sizeof(header), file);
943
944 /* Read SAD blocks, clamping the maximum size for safety */
945 if (header.length > (int)sizeof(block))
946 header.length = (int)sizeof(block);
947 fread(&block, header.length, 1, file);
948
949 fclose(file);
950
951 /* Calculate the number of SAD blocks */
952 num_audio_blocks = header.length / SAD_BLOCK_SIZE;
953
954 for (i = 0; i < num_audio_blocks; i++) {
955 /* Only consider LPCM blocks */
956 if ((sad[0] >> 3) != EDID_FORMAT_LPCM)
957 continue;
958
959 channel_count = (sad[0] & 0x7) + 1;
960 if (channel_count > max_channels)
961 max_channels = channel_count;
962
963 /* Advance to next block */
964 sad += 3;
965 }
966
967 return max_channels;
968}
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700969
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700970int platform_set_incall_recording_session_id(void *platform __unused,
971 uint32_t session_id __unused, int rec_mode __unused)
972{
Haynes Mathew George24ca9ad2014-06-18 15:14:18 -0700973 ALOGE("%s: Not implemented", __func__);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700974 return -ENOSYS;
975}
976
977int platform_stop_incall_recording_usecase(void *platform __unused)
978{
Haynes Mathew George24ca9ad2014-06-18 15:14:18 -0700979 ALOGE("%s: Not implemented", __func__);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700980 return -ENOSYS;
981}
982
983int platform_start_incall_music_usecase(void *platform __unused)
984{
Haynes Mathew George24ca9ad2014-06-18 15:14:18 -0700985 ALOGE("%s: Not implemented", __func__);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700986 return -ENOSYS;
987}
988
989int platform_stop_incall_music_usecase(void *platform __unused)
990{
Haynes Mathew George24ca9ad2014-06-18 15:14:18 -0700991 ALOGE("%s: Not implemented", __func__);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700992 return -ENOSYS;
993}
994
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700995int platform_set_parameters(void *platform __unused,
996 struct str_parms *parms __unused)
997{
998 ALOGE("%s: Not implemented", __func__);
999 return -ENOSYS;
1000}
1001
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07001002/* Delay in Us */
1003int64_t platform_render_latency(audio_usecase_t usecase)
1004{
1005 switch (usecase) {
1006 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
1007 return DEEP_BUFFER_PLATFORM_DELAY;
1008 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
1009 return LOW_LATENCY_PLATFORM_DELAY;
1010 default:
1011 return 0;
1012 }
1013}
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001014
Haynes Mathew George24ca9ad2014-06-18 15:14:18 -07001015int platform_switch_voice_call_enable_device_config(void *platform __unused,
1016 snd_device_t out_snd_device __unused,
1017 snd_device_t in_snd_device __unused)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001018{
1019 return 0;
1020}
1021
Haynes Mathew George24ca9ad2014-06-18 15:14:18 -07001022int platform_switch_voice_call_usecase_route_post(void *platform __unused,
1023 snd_device_t out_snd_device __unused,
1024 snd_device_t in_snd_device __unused)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001025{
1026 return 0;
1027}
Haynes Mathew George24ca9ad2014-06-18 15:14:18 -07001028
1029int platform_get_sample_rate(void *platform __unused, uint32_t *rate __unused)
1030{
1031 return -ENOSYS;
1032}
Haynes Mathew George98c95622014-06-20 19:14:25 -07001033
1034int platform_get_usecase_index(const char * usecase __unused)
1035{
1036 return -ENOSYS;
1037}
1038
1039int platform_set_usecase_pcm_id(audio_usecase_t usecase __unused, int32_t type __unused,
1040 int32_t pcm_id __unused)
1041{
1042 return -ENOSYS;
1043}
1044
1045int platform_set_snd_device_backend(snd_device_t device __unused,
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001046 const char *backend __unused,
1047 const char *hw_interface __unused)
Haynes Mathew George98c95622014-06-20 19:14:25 -07001048{
1049 return -ENOSYS;
1050}
Eric Laurentcefbbac2014-09-04 13:54:10 -05001051
vivek mehta1a9b7c02015-06-25 11:49:38 -07001052void platform_set_echo_reference(struct audio_device *adev __unused,
1053 bool enable __unused,
1054 audio_devices_t out_device __unused)
Eric Laurentcefbbac2014-09-04 13:54:10 -05001055{
1056 return;
1057}
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07001058
vivek mehtae59cfb22017-06-16 15:57:11 -07001059#define DEFAULT_NOMINAL_SPEAKER_GAIN 20
1060int ramp_speaker_gain(struct audio_device *adev, bool ramp_up, int target_ramp_up_gain) {
1061 // backup_gain: gain to try to set in case of an error during ramp
1062 int start_gain, end_gain, step, backup_gain, i;
1063 bool error = false;
1064 const struct mixer_ctl *ctl;
1065 const char *mixer_ctl_name_gain_left = "Left Speaker Gain";
1066 const char *mixer_ctl_name_gain_right = "Right Speaker Gain";
1067 struct mixer_ctl *ctl_left = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_left);
1068 struct mixer_ctl *ctl_right = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_right);
1069 if (!ctl_left || !ctl_right) {
1070 ALOGE("%s: Could not get ctl for mixer cmd - %s or %s, not applying speaker gain ramp",
1071 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
1072 return -EINVAL;
1073 } else if ((mixer_ctl_get_num_values(ctl_left) != 1)
1074 || (mixer_ctl_get_num_values(ctl_right) != 1)) {
1075 ALOGE("%s: Unexpected num values for mixer cmd - %s or %s, not applying speaker gain ramp",
1076 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
1077 return -EINVAL;
1078 }
1079 if (ramp_up) {
1080 start_gain = 0;
1081 end_gain = target_ramp_up_gain > 0 ? target_ramp_up_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
1082 step = +1;
1083 backup_gain = end_gain;
1084 } else {
1085 // using same gain on left and right
1086 const int left_gain = mixer_ctl_get_value(ctl_left, 0);
1087 start_gain = left_gain > 0 ? left_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
1088 end_gain = 0;
1089 step = -1;
1090 backup_gain = start_gain;
1091 }
1092 for (i = start_gain ; i != (end_gain + step) ; i += step) {
1093 //ALOGV("setting speaker gain to %d", i);
1094 if (mixer_ctl_set_value(ctl_left, 0, i)) {
1095 ALOGE("%s: error setting %s to %d during gain ramp",
1096 __func__, mixer_ctl_name_gain_left, i);
1097 error = true;
1098 break;
1099 }
1100 if (mixer_ctl_set_value(ctl_right, 0, i)) {
1101 ALOGE("%s: error setting %s to %d during gain ramp",
1102 __func__, mixer_ctl_name_gain_right, i);
1103 error = true;
1104 break;
1105 }
1106 usleep(1000);
1107 }
1108 if (error) {
1109 // an error occured during the ramp, let's still try to go back to a safe volume
1110 if (mixer_ctl_set_value(ctl_left, 0, backup_gain)) {
1111 ALOGE("%s: error restoring left gain to %d", __func__, backup_gain);
1112 }
1113 if (mixer_ctl_set_value(ctl_right, 0, backup_gain)) {
1114 ALOGE("%s: error restoring right gain to %d", __func__, backup_gain);
1115 }
1116 }
1117 return start_gain;
1118}
1119
1120int platform_set_swap_mixer(struct audio_device *adev, bool swap_channels)
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07001121{
vivek mehtae59cfb22017-06-16 15:57:11 -07001122 const char *mixer_ctl_name = "Swap channel";
1123 struct mixer_ctl *ctl;
1124 const char *mixer_path;
1125 struct platform_data *my_data = (struct platform_data *)adev->platform;
1126
1127 // forced to set to swap, but device not rotated ... ignore set
1128 if (swap_channels && !my_data->speaker_lr_swap)
1129 return 0;
1130
1131 ALOGV("%s:", __func__);
1132
1133 if (swap_channels) {
1134 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER_REVERSE);
1135 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
1136 } else {
1137 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER);
1138 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
1139 }
1140
1141 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1142 if (!ctl) {
1143 ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name);
1144 return -EINVAL;
1145 }
1146
1147 if (mixer_ctl_set_value(ctl, 0, swap_channels) < 0) {
1148 ALOGE("%s: Could not set reverse cotrol %d",__func__, swap_channels);
1149 return -EINVAL;
1150 }
1151
1152 ALOGV("platfor_force_swap_channel :: Channel orientation ( %s ) ",
1153 swap_channels?"R --> L":"L --> R");
1154
1155 return 0;
1156}
1157
1158int platform_check_and_set_swap_lr_channels(struct audio_device *adev, bool swap_channels)
1159{
1160 // only update if there is active pcm playback on speaker
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07001161 struct audio_usecase *usecase;
1162 struct listnode *node;
1163 struct platform_data *my_data = (struct platform_data *)adev->platform;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07001164
vivek mehtae59cfb22017-06-16 15:57:11 -07001165 my_data->speaker_lr_swap = swap_channels;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07001166
vivek mehtae59cfb22017-06-16 15:57:11 -07001167 return platform_set_swap_channels(adev, swap_channels);
1168}
1169
1170int platform_set_swap_channels(struct audio_device *adev, bool swap_channels)
1171{
1172 // only update if there is active pcm playback on speaker
1173 struct audio_usecase *usecase;
1174 struct listnode *node;
1175 struct platform_data *my_data = (struct platform_data *)adev->platform;
1176
1177 // do not swap channels in audio modes with concurrent capture and playback
1178 // as this may break the echo reference
1179 if ((adev->mode == AUDIO_MODE_IN_COMMUNICATION) || (adev->mode == AUDIO_MODE_IN_CALL)) {
1180 ALOGV("%s: will not swap due to audio mode %d", __func__, adev->mode);
1181 return 0;
1182 }
1183
1184 list_for_each(node, &adev->usecase_list) {
1185 usecase = node_to_item(node, struct audio_usecase, list);
1186 if (usecase->type == PCM_PLAYBACK &&
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07001187 usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) {
vivek mehtae59cfb22017-06-16 15:57:11 -07001188 /*
1189 * If acdb tuning is different for SPEAKER_REVERSE, it is must
1190 * to perform device switch to disable the current backend to
1191 * enable it with new acdb data.
1192 */
1193 if (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
1194 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]) {
1195 const int initial_skpr_gain = ramp_speaker_gain(adev, false /*ramp_up*/, -1);
1196 select_devices(adev, usecase->id);
1197 if (initial_skpr_gain != -EINVAL)
1198 ramp_speaker_gain(adev, true /*ramp_up*/, initial_skpr_gain);
1199
1200 } else {
1201 platform_set_swap_mixer(adev, swap_channels);
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07001202 }
vivek mehtae59cfb22017-06-16 15:57:11 -07001203 break;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07001204 }
1205 }
vivek mehtae59cfb22017-06-16 15:57:11 -07001206
1207 return 0;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07001208}
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001209
1210bool platform_send_gain_dep_cal(void *platform __unused,
1211 int level __unused)
1212{
vivek mehtafb4d7bd2016-04-29 03:16:47 -07001213 return true;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001214}
1215
Haynes Mathew George2d809e02016-09-22 17:38:16 -07001216int platform_can_split_snd_device(snd_device_t in_snd_device __unused,
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001217 int *num_devices __unused,
1218 snd_device_t *out_snd_devices __unused)
1219{
Haynes Mathew George2d809e02016-09-22 17:38:16 -07001220 return -ENOSYS;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001221}
1222
1223bool platform_check_backends_match(snd_device_t snd_device1 __unused,
1224 snd_device_t snd_device2 __unused)
1225{
1226 return true;
1227}
vivek mehtade4849c2016-03-03 17:23:38 -08001228
1229int platform_get_snd_device_name_extn(void *platform __unused,
1230 snd_device_t snd_device,
1231 char *device_name)
1232{
David Benjamin1565f992016-09-21 12:10:34 -04001233 strlcpy(device_name, platform_get_snd_device_name(snd_device),
1234 DEVICE_NAME_MAX_SIZE);
vivek mehtade4849c2016-03-03 17:23:38 -08001235 return 0;
1236}
1237
David Linee3fe402017-03-13 10:00:42 -07001238bool platform_check_and_set_playback_backend_cfg(struct audio_device* adev __unused,
1239 struct audio_usecase *usecase __unused,
1240 snd_device_t snd_device __unused)
1241{
1242 return false;
1243}
1244
vivek mehta4ed66e62016-04-15 23:33:34 -07001245bool platform_check_and_set_capture_backend_cfg(struct audio_device* adev __unused,
David Lind6229bd2017-07-06 15:28:55 -07001246 struct audio_usecase *usecase __unused, snd_device_t snd_device __unused)
vivek mehta4ed66e62016-04-15 23:33:34 -07001247{
1248 return false;
1249}
1250
vivek mehtaa8d7c922016-05-25 14:40:44 -07001251bool platform_add_gain_level_mapping(struct amp_db_and_gain_table *tbl_entry __unused)
1252{
1253 return false;
1254}
1255
1256int platform_get_gain_level_mapping(struct amp_db_and_gain_table *mapping_tbl __unused,
1257 int table_size __unused)
1258{
1259 return 0;
1260}
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001261
Tom Cherry8721b4d2016-07-14 16:12:23 -07001262int platform_snd_card_update(void *platform __unused,
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001263 card_status_t status __unused)
1264{
1265 return -1;
1266}
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001267
David Lind6229bd2017-07-06 15:28:55 -07001268int platform_get_snd_device_backend_index(snd_device_t snd_device __unused)
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001269{
1270 return -ENOSYS;
1271}
1272
David Lind6229bd2017-07-06 15:28:55 -07001273void platform_check_and_update_copp_sample_rate(void* platform __unused, snd_device_t snd_device __unused,
1274 unsigned int stream_sr __unused, int* sample_rate __unused)
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001275{
1276
1277}
1278
David Lind6229bd2017-07-06 15:28:55 -07001279int platform_send_audio_calibration_v2(void *platform __unused, struct audio_usecase *usecase __unused,
1280 int app_type __unused, int sample_rate __unused)
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001281{
1282 return -ENOSYS;
1283}
1284
1285bool platform_supports_app_type_cfg() { return false; }
1286
vivek mehtaa68fea62017-06-08 19:04:02 -07001287void platform_add_app_type(const char *uc_type __unused,
1288 const char *mode __unused,
1289 int bw __unused, int app_type __unused,
1290 int max_sr __unused) {}
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001291
vivek mehtaa68fea62017-06-08 19:04:02 -07001292int platform_get_app_type_v2(void *platform __unused,
1293 enum usecase_type_t type __unused,
1294 const char *mode __unused,
1295 int bw __unused, int sr __unused,
1296 int *app_type __unused) {
1297 return -ENOSYS;
1298}
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001299
vivek mehta90933872017-06-15 18:04:39 -07001300int platform_set_sidetone(struct audio_device *adev,
1301 snd_device_t out_snd_device,
1302 bool enable, char *str)
1303{
1304 int ret;
1305 if (out_snd_device == SND_DEVICE_OUT_USB_HEADSET ||
1306 out_snd_device == SND_DEVICE_OUT_VOICE_USB_HEADSET) {
1307 ret = audio_extn_usb_enable_sidetone(out_snd_device, enable);
1308 if (ret)
1309 ALOGI("%s: usb device %d does not support device sidetone\n",
1310 __func__, out_snd_device);
1311 } else {
1312 ALOGV("%s: sidetone out device(%d) mixer cmd = %s\n",
1313 __func__, out_snd_device, str);
1314 if (enable)
1315 audio_route_apply_and_update_path(adev->audio_route, str);
1316 else
1317 audio_route_reset_and_update_path(adev->audio_route, str);
1318 }
1319 return 0;
1320}
Haynes Mathew George96483a22017-03-28 14:52:47 -07001321
1322int platform_get_mmap_data_fd(void *platform __unused, int fe_dev __unused, int dir __unused,
1323 int *fd __unused, uint32_t *size __unused)
1324{
1325 return -ENOSYS;
1326}