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