blob: a9f6623a4eb822bcd74d86abd8026dc26f8d564c [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
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700434int platform_get_snd_device_acdb_id(snd_device_t snd_device __unused)
435{
436 ALOGE("%s: Not implemented", __func__);
437 return -ENOSYS;
438}
439
Eric Laurent788f41f2015-08-24 12:21:50 -0700440void platform_add_operator_specific_device(snd_device_t snd_device __unused,
441 const char *operator __unused,
442 const char *mixer_path __unused,
443 unsigned int acdb_id __unused)
keunhui.park2f7306a2015-07-16 16:48:06 +0900444{
445}
446
Eric Laurentb23d5282013-05-14 15:27:20 -0700447int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
448{
449 struct platform_data *my_data = (struct platform_data *)platform;
450 int acdb_dev_id, acdb_dev_type;
451
452 acdb_dev_id = acdb_device_table[snd_device];
453 if (acdb_dev_id < 0) {
454 ALOGE("%s: Could not find acdb id for device(%d)",
455 __func__, snd_device);
456 return -EINVAL;
457 }
458 if (my_data->acdb_send_audio_cal) {
Eric Laurent994a6932013-07-17 11:51:42 -0700459 ("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Eric Laurentb23d5282013-05-14 15:27:20 -0700460 __func__, snd_device, acdb_dev_id);
461 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
462 snd_device < SND_DEVICE_OUT_END)
463 acdb_dev_type = ACDB_DEV_TYPE_OUT;
464 else
465 acdb_dev_type = ACDB_DEV_TYPE_IN;
466 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
467 }
468 return 0;
469}
470
471int platform_switch_voice_call_device_pre(void *platform)
472{
473 struct platform_data *my_data = (struct platform_data *)platform;
474 int ret = 0;
475
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -0700476 if (my_data->csd_client != NULL &&
477 voice_is_in_call(my_data->adev)) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700478 /* This must be called before disabling the mixer controls on APQ side */
479 if (my_data->csd_disable_device == NULL) {
480 ALOGE("%s: dlsym error for csd_disable_device", __func__);
481 } else {
482 ret = my_data->csd_disable_device();
483 if (ret < 0) {
484 ALOGE("%s: csd_client_disable_device, failed, error %d",
485 __func__, ret);
486 }
487 }
488 }
489 return ret;
490}
491
492int platform_switch_voice_call_device_post(void *platform,
493 snd_device_t out_snd_device,
494 snd_device_t in_snd_device)
495{
496 struct platform_data *my_data = (struct platform_data *)platform;
497 int acdb_rx_id, acdb_tx_id;
498 int ret = 0;
499
500 if (my_data->csd_client) {
501 if (my_data->csd_enable_device == NULL) {
502 ALOGE("%s: dlsym error for csd_enable_device",
503 __func__);
504 } else {
505 acdb_rx_id = acdb_device_table[out_snd_device];
506 acdb_tx_id = acdb_device_table[in_snd_device];
507
508 if (acdb_rx_id > 0 || acdb_tx_id > 0) {
509 ret = my_data->csd_enable_device(acdb_rx_id, acdb_tx_id,
510 my_data->adev->acdb_settings);
511 if (ret < 0) {
512 ALOGE("%s: csd_enable_device, failed, error %d",
513 __func__, ret);
514 }
515 } else {
516 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
517 acdb_rx_id, acdb_tx_id);
518 }
519 }
520 }
521
522 return ret;
523}
524
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700525int platform_start_voice_call(void *platform, uint32_t vsid __unused)
Eric Laurentb23d5282013-05-14 15:27:20 -0700526{
527 struct platform_data *my_data = (struct platform_data *)platform;
528 int ret = 0;
529
530 if (my_data->csd_client) {
531 if (my_data->csd_start_voice == NULL) {
532 ALOGE("dlsym error for csd_client_start_voice");
533 ret = -ENOSYS;
534 } else {
535 ret = my_data->csd_start_voice();
536 if (ret < 0) {
537 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
538 }
539 }
540 }
541
542 return ret;
543}
544
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700545int platform_stop_voice_call(void *platform, uint32_t vsid __unused)
Eric Laurentb23d5282013-05-14 15:27:20 -0700546{
547 struct platform_data *my_data = (struct platform_data *)platform;
548 int ret = 0;
549
550 if (my_data->csd_client) {
551 if (my_data->csd_stop_voice == NULL) {
552 ALOGE("dlsym error for csd_stop_voice");
553 } else {
554 ret = my_data->csd_stop_voice();
555 if (ret < 0) {
556 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
557 }
558 }
559 }
560
561 return ret;
562}
563
vivek mehtab6506412015-08-07 16:55:17 -0700564void platform_set_speaker_gain_in_combo(struct audio_device *adev __unused,
Eric Laurent788f41f2015-08-24 12:21:50 -0700565 snd_device_t snd_device __unused,
vivek mehtab6506412015-08-07 16:55:17 -0700566 bool enable __unused) {
567}
568
Eric Laurentb23d5282013-05-14 15:27:20 -0700569int platform_set_voice_volume(void *platform, int volume)
570{
571 struct platform_data *my_data = (struct platform_data *)platform;
572 int ret = 0;
573
574 if (my_data->csd_client) {
575 if (my_data->csd_volume == NULL) {
576 ALOGE("%s: dlsym error for csd_volume", __func__);
577 } else {
578 ret = my_data->csd_volume(volume);
579 if (ret < 0) {
580 ALOGE("%s: csd_volume error %d", __func__, ret);
581 }
582 }
583 } else {
584 ALOGE("%s: No CSD Client present", __func__);
585 }
586
587 return ret;
588}
589
590int platform_set_mic_mute(void *platform, bool state)
591{
592 struct platform_data *my_data = (struct platform_data *)platform;
593 int ret = 0;
594
595 if (my_data->adev->mode == AUDIO_MODE_IN_CALL) {
596 if (my_data->csd_client) {
597 if (my_data->csd_mic_mute == NULL) {
598 ALOGE("%s: dlsym error for csd_mic_mute", __func__);
599 } else {
600 ret = my_data->csd_mic_mute(state);
601 if (ret < 0) {
602 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
603 }
604 }
605 } else {
606 ALOGE("%s: No CSD Client present", __func__);
607 }
608 }
609
610 return ret;
611}
612
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700613int platform_set_device_mute(void *platform __unused, bool state __unused, char *dir __unused)
614{
Haynes Mathew George24ca9ad2014-06-18 15:14:18 -0700615 ALOGE("%s: Not implemented", __func__);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700616 return -ENOSYS;
617}
618
Eric Laurentb23d5282013-05-14 15:27:20 -0700619snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
620{
621 struct platform_data *my_data = (struct platform_data *)platform;
622 struct audio_device *adev = my_data->adev;
623 audio_mode_t mode = adev->mode;
624 snd_device_t snd_device = SND_DEVICE_NONE;
625
626 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
627 if (devices == AUDIO_DEVICE_NONE ||
628 devices & AUDIO_DEVICE_BIT_IN) {
629 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
630 goto exit;
631 }
632
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -0700633 if (voice_is_in_call(adev)) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700634 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
635 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
Haynes Mathew George24ca9ad2014-06-18 15:14:18 -0700636 if (adev->voice.tty_mode == TTY_MODE_FULL)
Eric Laurentb23d5282013-05-14 15:27:20 -0700637 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
Haynes Mathew George24ca9ad2014-06-18 15:14:18 -0700638 else if (adev->voice.tty_mode == TTY_MODE_VCO)
Eric Laurentb23d5282013-05-14 15:27:20 -0700639 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
Haynes Mathew George24ca9ad2014-06-18 15:14:18 -0700640 else if (adev->voice.tty_mode == TTY_MODE_HCO)
Eric Laurentb23d5282013-05-14 15:27:20 -0700641 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
642 else
643 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
644 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700645 if (adev->bt_wb_speech_enabled) {
646 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
647 } else {
648 snd_device = SND_DEVICE_OUT_BT_SCO;
649 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700650 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
651 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
652 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
653 if (is_operator_tmus())
654 snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS;
655 else
656 snd_device = SND_DEVICE_OUT_HANDSET;
657 }
658 if (snd_device != SND_DEVICE_NONE) {
659 goto exit;
660 }
661 }
662
663 if (popcount(devices) == 2) {
664 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
665 AUDIO_DEVICE_OUT_SPEAKER)) {
666 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
667 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
668 AUDIO_DEVICE_OUT_SPEAKER)) {
669 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
670 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
671 AUDIO_DEVICE_OUT_SPEAKER)) {
672 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
673 } else {
674 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
675 goto exit;
676 }
677 if (snd_device != SND_DEVICE_NONE) {
678 goto exit;
679 }
680 }
681
682 if (popcount(devices) != 1) {
683 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
684 goto exit;
685 }
686
687 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
688 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
689 snd_device = SND_DEVICE_OUT_HEADPHONES;
690 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -0700691 if (my_data->speaker_lr_swap)
Eric Laurentb23d5282013-05-14 15:27:20 -0700692 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
693 else
694 snd_device = SND_DEVICE_OUT_SPEAKER;
695 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700696 if (adev->bt_wb_speech_enabled) {
697 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
698 } else {
699 snd_device = SND_DEVICE_OUT_BT_SCO;
700 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700701 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
702 snd_device = SND_DEVICE_OUT_HDMI ;
703 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
704 snd_device = SND_DEVICE_OUT_HANDSET;
705 } else {
706 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
707 }
708exit:
709 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
710 return snd_device;
711}
712
713snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
714{
715 struct platform_data *my_data = (struct platform_data *)platform;
716 struct audio_device *adev = my_data->adev;
717 audio_source_t source = (adev->active_input == NULL) ?
718 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
719
720 audio_mode_t mode = adev->mode;
721 audio_devices_t in_device = ((adev->active_input == NULL) ?
722 AUDIO_DEVICE_NONE : adev->active_input->device)
723 & ~AUDIO_DEVICE_BIT_IN;
724 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
725 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
726 snd_device_t snd_device = SND_DEVICE_NONE;
727
728 ALOGV("%s: enter: out_device(%#x) in_device(%#x)",
729 __func__, out_device, in_device);
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -0700730 if ((out_device != AUDIO_DEVICE_NONE) && voice_is_in_call(adev)) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700731 if (adev->voice.tty_mode != TTY_MODE_OFF) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700732 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
733 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700734 switch (adev->voice.tty_mode) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700735 case TTY_MODE_FULL:
736 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
737 break;
738 case TTY_MODE_VCO:
739 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
740 break;
741 case TTY_MODE_HCO:
742 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
743 break;
744 default:
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700745 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
Eric Laurentb23d5282013-05-14 15:27:20 -0700746 }
747 goto exit;
748 }
749 }
750 if (out_device & AUDIO_DEVICE_OUT_EARPIECE ||
751 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
752 if (my_data->fluence_in_voice_call == false) {
753 snd_device = SND_DEVICE_IN_HANDSET_MIC;
754 } else {
755 if (my_data->dualmic_config == DUALMIC_CONFIG_ENDFIRE) {
756 if (is_operator_tmus())
757 snd_device = SND_DEVICE_IN_VOICE_DMIC_EF_TMUS;
758 else
759 snd_device = SND_DEVICE_IN_VOICE_DMIC_EF;
760 } else if(my_data->dualmic_config == DUALMIC_CONFIG_BROADSIDE)
761 snd_device = SND_DEVICE_IN_VOICE_DMIC_BS;
762 else
763 snd_device = SND_DEVICE_IN_HANDSET_MIC;
764 }
765 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
766 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
767 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700768 if (adev->bt_wb_speech_enabled) {
769 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
770 } else {
771 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
772 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700773 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
774 if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode &&
775 my_data->dualmic_config == DUALMIC_CONFIG_ENDFIRE) {
776 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC_EF;
777 } else if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode &&
778 my_data->dualmic_config == DUALMIC_CONFIG_BROADSIDE) {
779 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BS;
780 } else {
781 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
782 }
783 }
784 } else if (source == AUDIO_SOURCE_CAMCORDER) {
785 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
786 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
787 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
788 }
789 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
790 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
791 if (my_data->dualmic_config == DUALMIC_CONFIG_ENDFIRE) {
792 if (channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK)
793 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_EF;
794 else if (my_data->fluence_in_voice_rec)
795 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_EF_FLUENCE;
796 } else if (my_data->dualmic_config == DUALMIC_CONFIG_BROADSIDE) {
797 if (channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK)
798 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_BS;
799 else if (my_data->fluence_in_voice_rec)
800 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_BS_FLUENCE;
801 }
802
803 if (snd_device == SND_DEVICE_NONE) {
804 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
805 }
806 }
Eric Laurent50a38ed2015-10-14 18:48:06 -0700807 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION ||
808 mode == AUDIO_MODE_IN_COMMUNICATION) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700809 if (out_device & AUDIO_DEVICE_OUT_SPEAKER)
810 in_device = AUDIO_DEVICE_IN_BACK_MIC;
811 if (adev->active_input) {
812 if (adev->active_input->enable_aec) {
813 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
814 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
815 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
816 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
817 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
818 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
819 }
820 set_echo_reference(adev->mixer, "SLIM_RX");
821 } else
822 set_echo_reference(adev->mixer, "NONE");
823 }
824 } else if (source == AUDIO_SOURCE_DEFAULT) {
825 goto exit;
826 }
827
828
829 if (snd_device != SND_DEVICE_NONE) {
830 goto exit;
831 }
832
833 if (in_device != AUDIO_DEVICE_NONE &&
834 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
835 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
836 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
837 snd_device = SND_DEVICE_IN_HANDSET_MIC;
838 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
839 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
840 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
841 snd_device = SND_DEVICE_IN_HEADSET_MIC;
842 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700843 if (adev->bt_wb_speech_enabled) {
844 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
845 } else {
846 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
847 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700848 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
849 snd_device = SND_DEVICE_IN_HDMI_MIC;
850 } else {
851 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
852 ALOGW("%s: Using default handset-mic", __func__);
853 snd_device = SND_DEVICE_IN_HANDSET_MIC;
854 }
855 } else {
856 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
857 snd_device = SND_DEVICE_IN_HANDSET_MIC;
858 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
859 snd_device = SND_DEVICE_IN_HEADSET_MIC;
860 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
861 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
862 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
863 snd_device = SND_DEVICE_IN_HANDSET_MIC;
864 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700865 if (adev->bt_wb_speech_enabled) {
866 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
867 } else {
868 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
869 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700870 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
871 snd_device = SND_DEVICE_IN_HDMI_MIC;
872 } else {
873 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
874 ALOGW("%s: Using default handset-mic", __func__);
875 snd_device = SND_DEVICE_IN_HANDSET_MIC;
876 }
877 }
878exit:
879 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
880 return snd_device;
881}
882
883int platform_set_hdmi_channels(void *platform, int channel_count)
884{
885 struct platform_data *my_data = (struct platform_data *)platform;
886 struct audio_device *adev = my_data->adev;
887 struct mixer_ctl *ctl;
888 const char *channel_cnt_str = NULL;
889 const char *mixer_ctl_name = "HDMI_RX Channels";
890 switch (channel_count) {
891 case 8:
892 channel_cnt_str = "Eight"; break;
893 case 7:
894 channel_cnt_str = "Seven"; break;
895 case 6:
896 channel_cnt_str = "Six"; break;
897 case 5:
898 channel_cnt_str = "Five"; break;
899 case 4:
900 channel_cnt_str = "Four"; break;
901 case 3:
902 channel_cnt_str = "Three"; break;
903 default:
904 channel_cnt_str = "Two"; break;
905 }
906 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
907 if (!ctl) {
908 ALOGE("%s: Could not get ctl for mixer cmd - %s",
909 __func__, mixer_ctl_name);
910 return -EINVAL;
911 }
912 ALOGV("HDMI channel count: %s", channel_cnt_str);
913 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
914 return 0;
915}
916
Haynes Mathew George24ca9ad2014-06-18 15:14:18 -0700917int platform_edid_get_max_channels(void *platform __unused)
Eric Laurentb23d5282013-05-14 15:27:20 -0700918{
919 FILE *file;
920 struct audio_block_header header;
921 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
922 char *sad = block;
923 int num_audio_blocks;
924 int channel_count;
925 int max_channels = 0;
926 int i;
927
928 file = fopen(AUDIO_DATA_BLOCK_PATH, "rb");
929 if (file == NULL) {
930 ALOGE("Unable to open '%s'", AUDIO_DATA_BLOCK_PATH);
931 return 0;
932 }
933
934 /* Read audio block header */
935 fread(&header, 1, sizeof(header), file);
936
937 /* Read SAD blocks, clamping the maximum size for safety */
938 if (header.length > (int)sizeof(block))
939 header.length = (int)sizeof(block);
940 fread(&block, header.length, 1, file);
941
942 fclose(file);
943
944 /* Calculate the number of SAD blocks */
945 num_audio_blocks = header.length / SAD_BLOCK_SIZE;
946
947 for (i = 0; i < num_audio_blocks; i++) {
948 /* Only consider LPCM blocks */
949 if ((sad[0] >> 3) != EDID_FORMAT_LPCM)
950 continue;
951
952 channel_count = (sad[0] & 0x7) + 1;
953 if (channel_count > max_channels)
954 max_channels = channel_count;
955
956 /* Advance to next block */
957 sad += 3;
958 }
959
960 return max_channels;
961}
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700962
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700963int platform_set_incall_recording_session_id(void *platform __unused,
964 uint32_t session_id __unused, int rec_mode __unused)
965{
Haynes Mathew George24ca9ad2014-06-18 15:14:18 -0700966 ALOGE("%s: Not implemented", __func__);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700967 return -ENOSYS;
968}
969
970int platform_stop_incall_recording_usecase(void *platform __unused)
971{
Haynes Mathew George24ca9ad2014-06-18 15:14:18 -0700972 ALOGE("%s: Not implemented", __func__);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700973 return -ENOSYS;
974}
975
976int platform_start_incall_music_usecase(void *platform __unused)
977{
Haynes Mathew George24ca9ad2014-06-18 15:14:18 -0700978 ALOGE("%s: Not implemented", __func__);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700979 return -ENOSYS;
980}
981
982int platform_stop_incall_music_usecase(void *platform __unused)
983{
Haynes Mathew George24ca9ad2014-06-18 15:14:18 -0700984 ALOGE("%s: Not implemented", __func__);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700985 return -ENOSYS;
986}
987
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700988int platform_set_parameters(void *platform __unused,
989 struct str_parms *parms __unused)
990{
991 ALOGE("%s: Not implemented", __func__);
992 return -ENOSYS;
993}
994
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700995/* Delay in Us */
996int64_t platform_render_latency(audio_usecase_t usecase)
997{
998 switch (usecase) {
999 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
1000 return DEEP_BUFFER_PLATFORM_DELAY;
1001 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
1002 return LOW_LATENCY_PLATFORM_DELAY;
1003 default:
1004 return 0;
1005 }
1006}
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001007
Haynes Mathew George24ca9ad2014-06-18 15:14:18 -07001008int platform_switch_voice_call_enable_device_config(void *platform __unused,
1009 snd_device_t out_snd_device __unused,
1010 snd_device_t in_snd_device __unused)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001011{
1012 return 0;
1013}
1014
Haynes Mathew George24ca9ad2014-06-18 15:14:18 -07001015int platform_switch_voice_call_usecase_route_post(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}
Haynes Mathew George24ca9ad2014-06-18 15:14:18 -07001021
1022int platform_get_sample_rate(void *platform __unused, uint32_t *rate __unused)
1023{
1024 return -ENOSYS;
1025}
Haynes Mathew George98c95622014-06-20 19:14:25 -07001026
1027int platform_get_usecase_index(const char * usecase __unused)
1028{
1029 return -ENOSYS;
1030}
1031
1032int platform_set_usecase_pcm_id(audio_usecase_t usecase __unused, int32_t type __unused,
1033 int32_t pcm_id __unused)
1034{
1035 return -ENOSYS;
1036}
1037
1038int platform_set_snd_device_backend(snd_device_t device __unused,
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001039 const char *backend __unused,
1040 const char *hw_interface __unused)
Haynes Mathew George98c95622014-06-20 19:14:25 -07001041{
1042 return -ENOSYS;
1043}
Eric Laurentcefbbac2014-09-04 13:54:10 -05001044
vivek mehta1a9b7c02015-06-25 11:49:38 -07001045void platform_set_echo_reference(struct audio_device *adev __unused,
1046 bool enable __unused,
1047 audio_devices_t out_device __unused)
Eric Laurentcefbbac2014-09-04 13:54:10 -05001048{
1049 return;
1050}
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07001051
vivek mehtae59cfb22017-06-16 15:57:11 -07001052#define DEFAULT_NOMINAL_SPEAKER_GAIN 20
1053int ramp_speaker_gain(struct audio_device *adev, bool ramp_up, int target_ramp_up_gain) {
1054 // backup_gain: gain to try to set in case of an error during ramp
1055 int start_gain, end_gain, step, backup_gain, i;
1056 bool error = false;
1057 const struct mixer_ctl *ctl;
1058 const char *mixer_ctl_name_gain_left = "Left Speaker Gain";
1059 const char *mixer_ctl_name_gain_right = "Right Speaker Gain";
1060 struct mixer_ctl *ctl_left = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_left);
1061 struct mixer_ctl *ctl_right = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_right);
1062 if (!ctl_left || !ctl_right) {
1063 ALOGE("%s: Could not get ctl for mixer cmd - %s or %s, not applying speaker gain ramp",
1064 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
1065 return -EINVAL;
1066 } else if ((mixer_ctl_get_num_values(ctl_left) != 1)
1067 || (mixer_ctl_get_num_values(ctl_right) != 1)) {
1068 ALOGE("%s: Unexpected num values for mixer cmd - %s or %s, not applying speaker gain ramp",
1069 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
1070 return -EINVAL;
1071 }
1072 if (ramp_up) {
1073 start_gain = 0;
1074 end_gain = target_ramp_up_gain > 0 ? target_ramp_up_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
1075 step = +1;
1076 backup_gain = end_gain;
1077 } else {
1078 // using same gain on left and right
1079 const int left_gain = mixer_ctl_get_value(ctl_left, 0);
1080 start_gain = left_gain > 0 ? left_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
1081 end_gain = 0;
1082 step = -1;
1083 backup_gain = start_gain;
1084 }
1085 for (i = start_gain ; i != (end_gain + step) ; i += step) {
1086 //ALOGV("setting speaker gain to %d", i);
1087 if (mixer_ctl_set_value(ctl_left, 0, i)) {
1088 ALOGE("%s: error setting %s to %d during gain ramp",
1089 __func__, mixer_ctl_name_gain_left, i);
1090 error = true;
1091 break;
1092 }
1093 if (mixer_ctl_set_value(ctl_right, 0, i)) {
1094 ALOGE("%s: error setting %s to %d during gain ramp",
1095 __func__, mixer_ctl_name_gain_right, i);
1096 error = true;
1097 break;
1098 }
1099 usleep(1000);
1100 }
1101 if (error) {
1102 // an error occured during the ramp, let's still try to go back to a safe volume
1103 if (mixer_ctl_set_value(ctl_left, 0, backup_gain)) {
1104 ALOGE("%s: error restoring left gain to %d", __func__, backup_gain);
1105 }
1106 if (mixer_ctl_set_value(ctl_right, 0, backup_gain)) {
1107 ALOGE("%s: error restoring right gain to %d", __func__, backup_gain);
1108 }
1109 }
1110 return start_gain;
1111}
1112
1113int platform_set_swap_mixer(struct audio_device *adev, bool swap_channels)
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07001114{
vivek mehtae59cfb22017-06-16 15:57:11 -07001115 const char *mixer_ctl_name = "Swap channel";
1116 struct mixer_ctl *ctl;
1117 const char *mixer_path;
1118 struct platform_data *my_data = (struct platform_data *)adev->platform;
1119
1120 // forced to set to swap, but device not rotated ... ignore set
1121 if (swap_channels && !my_data->speaker_lr_swap)
1122 return 0;
1123
1124 ALOGV("%s:", __func__);
1125
1126 if (swap_channels) {
1127 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER_REVERSE);
1128 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
1129 } else {
1130 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER);
1131 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
1132 }
1133
1134 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1135 if (!ctl) {
1136 ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name);
1137 return -EINVAL;
1138 }
1139
1140 if (mixer_ctl_set_value(ctl, 0, swap_channels) < 0) {
1141 ALOGE("%s: Could not set reverse cotrol %d",__func__, swap_channels);
1142 return -EINVAL;
1143 }
1144
1145 ALOGV("platfor_force_swap_channel :: Channel orientation ( %s ) ",
1146 swap_channels?"R --> L":"L --> R");
1147
1148 return 0;
1149}
1150
1151int platform_check_and_set_swap_lr_channels(struct audio_device *adev, bool swap_channels)
1152{
1153 // only update if there is active pcm playback on speaker
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07001154 struct audio_usecase *usecase;
1155 struct listnode *node;
1156 struct platform_data *my_data = (struct platform_data *)adev->platform;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07001157
vivek mehtae59cfb22017-06-16 15:57:11 -07001158 my_data->speaker_lr_swap = swap_channels;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07001159
vivek mehtae59cfb22017-06-16 15:57:11 -07001160 return platform_set_swap_channels(adev, swap_channels);
1161}
1162
1163int platform_set_swap_channels(struct audio_device *adev, bool swap_channels)
1164{
1165 // only update if there is active pcm playback on speaker
1166 struct audio_usecase *usecase;
1167 struct listnode *node;
1168 struct platform_data *my_data = (struct platform_data *)adev->platform;
1169
1170 // do not swap channels in audio modes with concurrent capture and playback
1171 // as this may break the echo reference
1172 if ((adev->mode == AUDIO_MODE_IN_COMMUNICATION) || (adev->mode == AUDIO_MODE_IN_CALL)) {
1173 ALOGV("%s: will not swap due to audio mode %d", __func__, adev->mode);
1174 return 0;
1175 }
1176
1177 list_for_each(node, &adev->usecase_list) {
1178 usecase = node_to_item(node, struct audio_usecase, list);
1179 if (usecase->type == PCM_PLAYBACK &&
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07001180 usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) {
vivek mehtae59cfb22017-06-16 15:57:11 -07001181 /*
1182 * If acdb tuning is different for SPEAKER_REVERSE, it is must
1183 * to perform device switch to disable the current backend to
1184 * enable it with new acdb data.
1185 */
1186 if (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
1187 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]) {
1188 const int initial_skpr_gain = ramp_speaker_gain(adev, false /*ramp_up*/, -1);
1189 select_devices(adev, usecase->id);
1190 if (initial_skpr_gain != -EINVAL)
1191 ramp_speaker_gain(adev, true /*ramp_up*/, initial_skpr_gain);
1192
1193 } else {
1194 platform_set_swap_mixer(adev, swap_channels);
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07001195 }
vivek mehtae59cfb22017-06-16 15:57:11 -07001196 break;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07001197 }
1198 }
vivek mehtae59cfb22017-06-16 15:57:11 -07001199
1200 return 0;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07001201}
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001202
1203bool platform_send_gain_dep_cal(void *platform __unused,
1204 int level __unused)
1205{
vivek mehtafb4d7bd2016-04-29 03:16:47 -07001206 return true;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001207}
1208
Haynes Mathew George2d809e02016-09-22 17:38:16 -07001209int platform_can_split_snd_device(snd_device_t in_snd_device __unused,
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001210 int *num_devices __unused,
1211 snd_device_t *out_snd_devices __unused)
1212{
Haynes Mathew George2d809e02016-09-22 17:38:16 -07001213 return -ENOSYS;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001214}
1215
1216bool platform_check_backends_match(snd_device_t snd_device1 __unused,
1217 snd_device_t snd_device2 __unused)
1218{
1219 return true;
1220}
vivek mehtade4849c2016-03-03 17:23:38 -08001221
1222int platform_get_snd_device_name_extn(void *platform __unused,
1223 snd_device_t snd_device,
1224 char *device_name)
1225{
David Benjamin1565f992016-09-21 12:10:34 -04001226 strlcpy(device_name, platform_get_snd_device_name(snd_device),
1227 DEVICE_NAME_MAX_SIZE);
vivek mehtade4849c2016-03-03 17:23:38 -08001228 return 0;
1229}
1230
Simon Shieldsff01e902016-09-08 20:23:27 +10001231bool platform_check_and_set_capture_backend_cfg (struct audio_device* adev __unused,
David Linee3fe402017-03-13 10:00:42 -07001232 struct audio_usecase *usecase __unused,
1233 snd_device_t snd_device __unused)
1234{
1235 return false;
1236}
1237
Simon Shieldsff01e902016-09-08 20:23:27 +10001238
1239bool platform_check_and_set_playback_backend_cfg(struct audio_device* adev __unused,
1240 struct audio_usecase *usecase __unused,
1241 snd_device_t snd_device __unused)
vivek mehta4ed66e62016-04-15 23:33:34 -07001242{
1243 return false;
1244}
1245
vivek mehtaa8d7c922016-05-25 14:40:44 -07001246bool platform_add_gain_level_mapping(struct amp_db_and_gain_table *tbl_entry __unused)
1247{
1248 return false;
1249}
1250
1251int platform_get_gain_level_mapping(struct amp_db_and_gain_table *mapping_tbl __unused,
1252 int table_size __unused)
1253{
1254 return 0;
1255}
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001256
Tom Cherry8721b4d2016-07-14 16:12:23 -07001257int platform_snd_card_update(void *platform __unused,
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001258 card_status_t status __unused)
1259{
1260 return -1;
1261}
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001262
David Lind6229bd2017-07-06 15:28:55 -07001263int platform_get_snd_device_backend_index(snd_device_t snd_device __unused)
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001264{
1265 return -ENOSYS;
1266}
1267
David Lind6229bd2017-07-06 15:28:55 -07001268void platform_check_and_update_copp_sample_rate(void* platform __unused, snd_device_t snd_device __unused,
1269 unsigned int stream_sr __unused, int* sample_rate __unused)
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001270{
1271
1272}
1273
David Lind6229bd2017-07-06 15:28:55 -07001274int platform_send_audio_calibration_v2(void *platform __unused, struct audio_usecase *usecase __unused,
1275 int app_type __unused, int sample_rate __unused)
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001276{
1277 return -ENOSYS;
1278}
1279
1280bool platform_supports_app_type_cfg() { return false; }
1281
vivek mehtaa68fea62017-06-08 19:04:02 -07001282void platform_add_app_type(const char *uc_type __unused,
1283 const char *mode __unused,
1284 int bw __unused, int app_type __unused,
1285 int max_sr __unused) {}
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001286
vivek mehtaa68fea62017-06-08 19:04:02 -07001287int platform_get_app_type_v2(void *platform __unused,
1288 enum usecase_type_t type __unused,
1289 const char *mode __unused,
1290 int bw __unused, int sr __unused,
1291 int *app_type __unused) {
1292 return -ENOSYS;
1293}
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001294
vivek mehta90933872017-06-15 18:04:39 -07001295int platform_set_sidetone(struct audio_device *adev,
1296 snd_device_t out_snd_device,
1297 bool enable, char *str)
1298{
1299 int ret;
1300 if (out_snd_device == SND_DEVICE_OUT_USB_HEADSET ||
1301 out_snd_device == SND_DEVICE_OUT_VOICE_USB_HEADSET) {
1302 ret = audio_extn_usb_enable_sidetone(out_snd_device, enable);
1303 if (ret)
1304 ALOGI("%s: usb device %d does not support device sidetone\n",
1305 __func__, out_snd_device);
1306 } else {
1307 ALOGV("%s: sidetone out device(%d) mixer cmd = %s\n",
1308 __func__, out_snd_device, str);
1309 if (enable)
1310 audio_route_apply_and_update_path(adev->audio_route, str);
1311 else
1312 audio_route_reset_and_update_path(adev->audio_route, str);
1313 }
1314 return 0;
1315}
Haynes Mathew George96483a22017-03-28 14:52:47 -07001316
1317int platform_get_mmap_data_fd(void *platform __unused, int fe_dev __unused, int dir __unused,
1318 int *fd __unused, uint32_t *size __unused)
1319{
1320 return -ENOSYS;
1321}
Simon Shieldsff01e902016-09-08 20:23:27 +10001322
1323int platform_get_default_app_type_v2(void *platform __unused, usecase_type_t type __unused,
1324 int *app_type __unused)
1325{
1326 ALOGE("%s: Not implemented", __func__);
1327 return -ENOSYS;
1328}