platform.c revision cefbbac40220d4e7690d204eecff5f6ae3f63069
1b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent/*
24b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava * Copyright (C) 2013-2014 The Android Open Source Project
3b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent *
4b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent * Licensed under the Apache License, Version 2.0 (the "License");
5b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent * you may not use this file except in compliance with the License.
6b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent * You may obtain a copy of the License at
7b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent *
8b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent *      http://www.apache.org/licenses/LICENSE-2.0
9b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent *
10b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent * Unless required by applicable law or agreed to in writing, software
11b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent * distributed under the License is distributed on an "AS IS" BASIS,
12b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent * See the License for the specific language governing permissions and
14b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent * limitations under the License.
15b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent */
16b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
17b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent#define LOG_TAG "msm8974_platform"
18b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent/*#define LOG_NDEBUG 0*/
19b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent#define LOG_NDDEBUG 0
20b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
21b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent#include <stdlib.h>
22b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent#include <dlfcn.h>
23b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent#include <cutils/log.h>
249f3065480c81bf01d3af65bfd3da09e1fb74b520Ravi Kumar Alamanda#include <cutils/str_parms.h>
25b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent#include <cutils/properties.h>
26b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent#include <audio_hw.h>
27b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent#include <platform_api.h>
28b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent#include "platform.h"
29b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
3047cd4cbdb19543338d5c887e3d7bcd2513c5c3adHaynes Mathew George#define MIXER_XML_PATH "/system/etc/mixer_paths.xml"
31b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent#define LIB_ACDB_LOADER "libacdbloader.so"
3247cd4cbdb19543338d5c887e3d7bcd2513c5c3adHaynes Mathew George#define AUDIO_DATA_BLOCK_MIXER_CTL "HDMI EDID"
33b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
34b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent#define DUALMIC_CONFIG_NONE 0      /* Target does not contain 2 mics */
35b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent#define DUALMIC_CONFIG_ENDFIRE 1
36b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent#define DUALMIC_CONFIG_BROADSIDE 2
37b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
38b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent/*
39b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent * This file will have a maximum of 38 bytes:
40b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent *
41b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent * 4 bytes: number of audio blocks
42b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent * 4 bytes: total length of Short Audio Descriptor (SAD) blocks
43b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent * Maximum 10 * 3 bytes: SAD blocks
44b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent */
45b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent#define MAX_SAD_BLOCKS      10
46b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent#define SAD_BLOCK_SIZE      3
47b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
48b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent/* EDID format ID for LPCM audio */
49b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent#define EDID_FORMAT_LPCM    1
50b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
511b9f4b3708d1ed1204bdb1dec370ad2e9db7a779sangwoo/* Retry for delay in FW loading*/
521b9f4b3708d1ed1204bdb1dec370ad2e9db7a779sangwoo#define RETRY_NUMBER 10
531b9f4b3708d1ed1204bdb1dec370ad2e9db7a779sangwoo#define RETRY_US 500000
544b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava#define MAX_SND_CARD 8
5553b2cf0c72aa18a5848919e2309731af652e84f9sangwoo
56b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurentstruct audio_block_header
57b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent{
58b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    int reserved;
59b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    int length;
60b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent};
61b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
6283281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda/* Audio calibration related functions */
63b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurenttypedef void (*acdb_deallocate_t)();
6483281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda#ifdef PLATFORM_MSM8084
6583281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamandatypedef int  (*acdb_init_t)(char *);
6683281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda#else
67b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurenttypedef int  (*acdb_init_t)();
6883281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda#endif
69b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurenttypedef void (*acdb_send_audio_cal_t)(int, int);
70b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurenttypedef void (*acdb_send_voice_cal_t)(int, int);
7183281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamandatypedef int (*acdb_reload_vocvoltable_t)(int);
72b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
73b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent/* Audio calibration related functions */
74b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurentstruct platform_data {
75b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    struct audio_device *adev;
76b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    bool fluence_in_spkr_mode;
77b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    bool fluence_in_voice_call;
783ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    bool fluence_in_voice_comm;
79b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    bool fluence_in_voice_rec;
80b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    int  dualmic_config;
81b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    void *acdb_handle;
823ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    acdb_init_t                acdb_init;
833ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    acdb_deallocate_t          acdb_deallocate;
843ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    acdb_send_audio_cal_t      acdb_send_audio_cal;
853ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    acdb_send_voice_cal_t      acdb_send_voice_cal;
8683281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    acdb_reload_vocvoltable_t  acdb_reload_vocvoltable;
8783281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    struct csd_data *csd;
88299760a41231bd0f6d9991fb189977347365c72bRavi Kumar Alamanda    bool ext_speaker;
89299760a41231bd0f6d9991fb189977347365c72bRavi Kumar Alamanda    bool ext_earpiece;
90b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent};
91b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
9298c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew Georgestatic int pcm_device_table[AUDIO_USECASE_MAX][2] = {
9383281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = {DEEP_BUFFER_PCM_DEVICE,
9483281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                                            DEEP_BUFFER_PCM_DEVICE},
9583281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
9683281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                                            LOWLATENCY_PCM_DEVICE},
9783281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    [USECASE_AUDIO_PLAYBACK_MULTI_CH] = {MULTIMEDIA2_PCM_DEVICE,
9883281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                                         MULTIMEDIA2_PCM_DEVICE},
9983281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    [USECASE_AUDIO_PLAYBACK_OFFLOAD] = {PLAYBACK_OFFLOAD_DEVICE,
10083281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                                        PLAYBACK_OFFLOAD_DEVICE},
10183281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    [USECASE_AUDIO_RECORD] = {AUDIO_RECORD_PCM_DEVICE,
10283281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                              AUDIO_RECORD_PCM_DEVICE},
10383281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    [USECASE_AUDIO_RECORD_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
10483281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                                          LOWLATENCY_PCM_DEVICE},
10583281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    [USECASE_VOICE_CALL] = {VOICE_CALL_PCM_DEVICE,
10683281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                            VOICE_CALL_PCM_DEVICE},
1074b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    [USECASE_VOICE2_CALL] = {VOICE2_CALL_PCM_DEVICE, VOICE2_CALL_PCM_DEVICE},
1084b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    [USECASE_VOLTE_CALL] = {VOLTE_CALL_PCM_DEVICE, VOLTE_CALL_PCM_DEVICE},
1094b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    [USECASE_QCHAT_CALL] = {QCHAT_CALL_PCM_DEVICE, QCHAT_CALL_PCM_DEVICE},
1104b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    [USECASE_VOWLAN_CALL] = {VOWLAN_CALL_PCM_DEVICE, VOWLAN_CALL_PCM_DEVICE},
1114b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    [USECASE_INCALL_REC_UPLINK] = {AUDIO_RECORD_PCM_DEVICE,
1124b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava                                   AUDIO_RECORD_PCM_DEVICE},
1134b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    [USECASE_INCALL_REC_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
1144b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava                                     AUDIO_RECORD_PCM_DEVICE},
1154b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
1164b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava                                                AUDIO_RECORD_PCM_DEVICE},
1178e6e98fc5af6d6f79bc71eb37df470380ae82fadRavi Kumar Alamanda    [USECASE_AUDIO_HFP_SCO] = {HFP_PCM_RX, HFP_SCO_RX},
11899c752d87eb818fc3cfb2e5c6790b1ea0bc88da5Ravi Kumar Alamanda
11999c752d87eb818fc3cfb2e5c6790b1ea0bc88da5Ravi Kumar Alamanda    [USECASE_AUDIO_PLAYBACK_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
12099c752d87eb818fc3cfb2e5c6790b1ea0bc88da5Ravi Kumar Alamanda                                          AFE_PROXY_RECORD_PCM_DEVICE},
12199c752d87eb818fc3cfb2e5c6790b1ea0bc88da5Ravi Kumar Alamanda    [USECASE_AUDIO_RECORD_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
12299c752d87eb818fc3cfb2e5c6790b1ea0bc88da5Ravi Kumar Alamanda                                        AFE_PROXY_RECORD_PCM_DEVICE},
12399c752d87eb818fc3cfb2e5c6790b1ea0bc88da5Ravi Kumar Alamanda
124b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent};
125b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
126b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent/* Array to store sound devices */
127b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurentstatic const char * const device_table[SND_DEVICE_MAX] = {
128b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_NONE] = "none",
129b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    /* Playback sound devices */
130b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_OUT_HANDSET] = "handset",
131b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_OUT_SPEAKER] = "speaker",
132b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_OUT_SPEAKER_REVERSE] = "speaker-reverse",
1331b0d8ce4ec97a57b38a401dbd1e16ac5cf4c4671Eric Laurent    [SND_DEVICE_OUT_SPEAKER_SAFE] = "speaker-safe",
134b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_OUT_HEADPHONES] = "headphones",
13509f2e0e6bf8accf1728ca89e780702d53f2c5b6dEric Laurent    [SND_DEVICE_OUT_LINE] = "line",
136b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones",
137744996b561b92473cc8ba23275811eb1a6b44d5eEric Laurent    [SND_DEVICE_OUT_SPEAKER_AND_LINE] = "speaker-and-line",
138b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_OUT_VOICE_HANDSET] = "voice-handset",
1399d0d3f1537b5d157a2c31e0744303524b846446eEric Laurent    [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = "voice-hac-handset",
140b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker",
141b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones",
14209f2e0e6bf8accf1728ca89e780702d53f2c5b6dEric Laurent    [SND_DEVICE_OUT_VOICE_LINE] = "voice-line",
143b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_OUT_HDMI] = "hdmi",
144b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi",
145b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset",
1469f3065480c81bf01d3af65bfd3da09e1fb74b520Ravi Kumar Alamanda    [SND_DEVICE_OUT_BT_SCO_WB] = "bt-sco-headset-wb",
147b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = "voice-handset-tmus",
148b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones",
149b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones",
150b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset",
15199c752d87eb818fc3cfb2e5c6790b1ea0bc88da5Ravi Kumar Alamanda    [SND_DEVICE_OUT_VOICE_TX] = "voice-tx",
152b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
153b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    /* Capture sound devices */
154b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
1553ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic",
1563ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_HANDSET_MIC_NS] = "handset-mic",
1573ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = "handset-mic",
1583ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_HANDSET_DMIC] = "dmic-endfire",
1593ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_HANDSET_DMIC_AEC] = "dmic-endfire",
1603ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_HANDSET_DMIC_NS] = "dmic-endfire",
1613ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = "dmic-endfire",
1623ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = "dmic-endfire",
1633ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda
164b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
1653ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "speaker-mic",
1663ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_SPEAKER_MIC_NS] = "speaker-mic",
1673ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = "speaker-mic",
1683ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_SPEAKER_DMIC] = "speaker-dmic-endfire",
1693ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = "speaker-dmic-endfire",
1703ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_SPEAKER_DMIC_NS] = "speaker-dmic-endfire",
1713ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = "speaker-dmic-endfire",
1723ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = "speaker-dmic-endfire",
1733ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda
174b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
175cefbbac40220d4e7690d204eecff5f6ae3f63069Eric Laurent    [SND_DEVICE_IN_HEADSET_MIC_AEC] = "headset-mic",
1763ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda
177b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic",
178b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
1799f3065480c81bf01d3af65bfd3da09e1fb74b520Ravi Kumar Alamanda    [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb",
1803ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda
181b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic",
1823ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda
1833ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef",
1843ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_VOICE_DMIC_TMUS] = "voice-dmic-ef-tmus",
1853ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
1863ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = "voice-speaker-dmic-ef",
1873ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
188b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
189b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
190b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
1913ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda
192b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
1933ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_VOICE_REC_MIC_NS] = "voice-rec-mic",
1943ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = "voice-rec-dmic-ef",
1953ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence",
19699c752d87eb818fc3cfb2e5c6790b1ea0bc88da5Ravi Kumar Alamanda
19799c752d87eb818fc3cfb2e5c6790b1ea0bc88da5Ravi Kumar Alamanda    [SND_DEVICE_IN_VOICE_RX] = "voice-rx",
198b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent};
199b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
200b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
2015bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew Georgestatic int acdb_device_table[SND_DEVICE_MAX] = {
202b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_NONE] = -1,
203b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_OUT_HANDSET] = 7,
204b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_OUT_SPEAKER] = 15,
205b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_OUT_SPEAKER_REVERSE] = 15,
2061b0d8ce4ec97a57b38a401dbd1e16ac5cf4c4671Eric Laurent    [SND_DEVICE_OUT_SPEAKER_SAFE] = 15,
207b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_OUT_HEADPHONES] = 10,
208744996b561b92473cc8ba23275811eb1a6b44d5eEric Laurent    [SND_DEVICE_OUT_LINE] = 77,
209b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
210744996b561b92473cc8ba23275811eb1a6b44d5eEric Laurent    [SND_DEVICE_OUT_SPEAKER_AND_LINE] = 77,
211235c34827f7b3b8977fe76dea1fb8d818fd74312Ravi Kumar Alamanda    [SND_DEVICE_OUT_VOICE_HANDSET] = ACDB_ID_VOICE_HANDSET,
212235c34827f7b3b8977fe76dea1fb8d818fd74312Ravi Kumar Alamanda    [SND_DEVICE_OUT_VOICE_SPEAKER] = ACDB_ID_VOICE_SPEAKER,
2139d0d3f1537b5d157a2c31e0744303524b846446eEric Laurent    [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = 53,
214b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
215744996b561b92473cc8ba23275811eb1a6b44d5eEric Laurent    [SND_DEVICE_OUT_VOICE_LINE] = 77,
216b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_OUT_HDMI] = 18,
217b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 15,
218b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_OUT_BT_SCO] = 22,
2199f3065480c81bf01d3af65bfd3da09e1fb74b520Ravi Kumar Alamanda    [SND_DEVICE_OUT_BT_SCO_WB] = 39,
22083281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = ACDB_ID_VOICE_HANDSET_TMUS,
221b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
222b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
223b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
22499c752d87eb818fc3cfb2e5c6790b1ea0bc88da5Ravi Kumar Alamanda    [SND_DEVICE_OUT_VOICE_TX] = 45,
225b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
226b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_IN_HANDSET_MIC] = 4,
2273ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_HANDSET_MIC_AEC] = 106,
2283ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_HANDSET_MIC_NS] = 107,
2293ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = 108,
2303ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_HANDSET_DMIC] = 41,
2313ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_HANDSET_DMIC_AEC] = 109,
2323ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_HANDSET_DMIC_NS] = 110,
2333ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = 111,
2343ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = 34,
2353ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda
2363ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_SPEAKER_MIC] = 11,
2373ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 112,
2383ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_SPEAKER_MIC_NS] = 113,
2393ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = 114,
2403ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_SPEAKER_DMIC] = 43,
2413ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = 115,
2423ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_SPEAKER_DMIC_NS] = 116,
2433ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = 117,
2443ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = 35,
2453ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda
246b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_IN_HEADSET_MIC] = 8,
247cefbbac40220d4e7690d204eecff5f6ae3f63069Eric Laurent    [SND_DEVICE_IN_HEADSET_MIC_AEC] = ACDB_ID_HEADSET_MIC_AEC,
2483ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda
249b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_IN_HDMI_MIC] = 4,
250b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_IN_BT_SCO_MIC] = 21,
2519f3065480c81bf01d3af65bfd3da09e1fb74b520Ravi Kumar Alamanda    [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38,
2523ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda
253b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_IN_CAMCORDER_MIC] = 61,
2543ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda
2553ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_VOICE_DMIC] = 41,
2563ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_VOICE_DMIC_TMUS] = ACDB_ID_VOICE_DMIC_EF_TMUS,
2573ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
2583ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 43,
2593ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_VOICE_HEADSET_MIC] = 8,
260b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
261b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
262b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
2633ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda
264b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_IN_VOICE_REC_MIC] = 62,
2653ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_VOICE_REC_MIC_NS] = 113,
2663ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = 35,
2673ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 43,
26899c752d87eb818fc3cfb2e5c6790b1ea0bc88da5Ravi Kumar Alamanda
26999c752d87eb818fc3cfb2e5c6790b1ea0bc88da5Ravi Kumar Alamanda    [SND_DEVICE_IN_VOICE_RX] = 44,
270b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent};
271b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
27298c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew Georgestruct name_to_index {
2735bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George    char name[100];
2745bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George    unsigned int index;
2755bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George};
2765bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George
2775bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George#define TO_NAME_INDEX(X)   #X, X
2785bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George
27998c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George/* Used to get index from parsed string */
28098c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew Georgestatic const struct name_to_index snd_device_name_index[SND_DEVICE_MAX] = {
28198c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    /* out */
2825bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George    {TO_NAME_INDEX(SND_DEVICE_OUT_HANDSET)},
2835bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George    {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER)},
2845bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George    {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_REVERSE)},
2851b0d8ce4ec97a57b38a401dbd1e16ac5cf4c4671Eric Laurent    {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE)},
2865bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George    {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES)},
28709f2e0e6bf8accf1728ca89e780702d53f2c5b6dEric Laurent    {TO_NAME_INDEX(SND_DEVICE_OUT_LINE)},
2885bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George    {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES)},
289744996b561b92473cc8ba23275811eb1a6b44d5eEric Laurent    {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_LINE)},
2905bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George    {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET)},
2915bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George    {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER)},
2925bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George    {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADPHONES)},
29309f2e0e6bf8accf1728ca89e780702d53f2c5b6dEric Laurent    {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_LINE)},
2945bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George    {TO_NAME_INDEX(SND_DEVICE_OUT_HDMI)},
2955bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George    {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HDMI)},
2965bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George    {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO)},
2975bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George    {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO_WB)},
29898c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET_TMUS)},
2999d0d3f1537b5d157a2c31e0744303524b846446eEric Laurent    {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HAC_HANDSET)},
3005bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George    {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES)},
3015bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George    {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES)},
3025bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George    {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET)},
30398c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George
30498c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    /* in */
3055bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George    {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC)},
30698c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC)},
3073ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_NS)},
3083ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)},
3093ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC)},
3103ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC)},
3113ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_NS)},
3123ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)},
3133ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_STEREO)},
3143ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda
3153ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC)},
31698c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC)},
3173ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_NS)},
3183ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)},
3193ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC)},
3203ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC)},
3213ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS)},
3223ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)},
3233ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_STEREO)},
3243ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda
3253ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC)},
3263ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda
3275bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George    {TO_NAME_INDEX(SND_DEVICE_IN_HDMI_MIC)},
3285bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George    {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC)},
3295bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George    {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB)},
3303ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda
3315bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George    {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_MIC)},
3323ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda
3333ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC)},
3343ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC_TMUS)},
3353ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC)},
3363ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC)},
3373ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEADSET_MIC)},
3385bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George    {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC)},
3395bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George    {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC)},
3405bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George    {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC)},
3413ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda
3425bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George    {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC)},
3433ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_NS)},
3443ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_STEREO)},
3453ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE)},
34698c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George};
34798c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George
34898c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew Georgestatic char * backend_table[SND_DEVICE_MAX] = {0};
34998c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George
35098c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew Georgestatic const struct name_to_index usecase_name_index[AUDIO_USECASE_MAX] = {
35198c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_DEEP_BUFFER)},
35298c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_LOW_LATENCY)},
35398c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_MULTI_CH)},
35498c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD)},
35598c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    {TO_NAME_INDEX(USECASE_AUDIO_RECORD)},
35698c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    {TO_NAME_INDEX(USECASE_AUDIO_RECORD_LOW_LATENCY)},
35798c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    {TO_NAME_INDEX(USECASE_VOICE_CALL)},
35898c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    {TO_NAME_INDEX(USECASE_VOICE2_CALL)},
35998c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    {TO_NAME_INDEX(USECASE_VOLTE_CALL)},
36098c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    {TO_NAME_INDEX(USECASE_QCHAT_CALL)},
36198c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    {TO_NAME_INDEX(USECASE_VOWLAN_CALL)},
36298c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK)},
36398c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    {TO_NAME_INDEX(USECASE_INCALL_REC_DOWNLINK)},
36498c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK_AND_DOWNLINK)},
36598c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    {TO_NAME_INDEX(USECASE_AUDIO_HFP_SCO)},
3665bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George};
3675bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George
3687ff216f80f6e53235b4239c6fb7da9b0d5127738Haynes Mathew George#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
3697ff216f80f6e53235b4239c6fb7da9b0d5127738Haynes Mathew George#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
3707ff216f80f6e53235b4239c6fb7da9b0d5127738Haynes Mathew George
371b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurentstatic pthread_once_t check_op_once_ctl = PTHREAD_ONCE_INIT;
372b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurentstatic bool is_tmus = false;
373b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
374b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurentstatic void check_operator()
375b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent{
376b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    char value[PROPERTY_VALUE_MAX];
377b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    int mccmnc;
378b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    property_get("gsm.sim.operator.numeric",value,"0");
379b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    mccmnc = atoi(value);
380b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    ALOGD("%s: tmus mccmnc %d", __func__, mccmnc);
381b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    switch(mccmnc) {
382b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    /* TMUS MCC(310), MNC(490, 260, 026) */
383b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    case 310490:
384b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    case 310260:
385b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    case 310026:
386b891db5473ab23a0cbc52d566a97c3d3529f8dddsangwon.jeon    /* Add new TMUS MNC(800, 660, 580, 310, 270, 250, 240, 230, 220, 210, 200, 160) */
387b891db5473ab23a0cbc52d566a97c3d3529f8dddsangwon.jeon    case 310800:
388b891db5473ab23a0cbc52d566a97c3d3529f8dddsangwon.jeon    case 310660:
389b891db5473ab23a0cbc52d566a97c3d3529f8dddsangwon.jeon    case 310580:
390b891db5473ab23a0cbc52d566a97c3d3529f8dddsangwon.jeon    case 310310:
391b891db5473ab23a0cbc52d566a97c3d3529f8dddsangwon.jeon    case 310270:
392b891db5473ab23a0cbc52d566a97c3d3529f8dddsangwon.jeon    case 310250:
393b891db5473ab23a0cbc52d566a97c3d3529f8dddsangwon.jeon    case 310240:
394b891db5473ab23a0cbc52d566a97c3d3529f8dddsangwon.jeon    case 310230:
395b891db5473ab23a0cbc52d566a97c3d3529f8dddsangwon.jeon    case 310220:
396b891db5473ab23a0cbc52d566a97c3d3529f8dddsangwon.jeon    case 310210:
397b891db5473ab23a0cbc52d566a97c3d3529f8dddsangwon.jeon    case 310200:
398b891db5473ab23a0cbc52d566a97c3d3529f8dddsangwon.jeon    case 310160:
399b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        is_tmus = true;
400b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        break;
401b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    }
402b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent}
403b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
404b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurentbool is_operator_tmus()
405b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent{
406b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    pthread_once(&check_op_once_ctl, check_operator);
407b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    return is_tmus;
408b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent}
409b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
410cefbbac40220d4e7690d204eecff5f6ae3f63069Eric Laurentvoid platform_set_echo_reference(struct audio_device *adev, bool enable, audio_devices_t out_device)
411b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent{
412cefbbac40220d4e7690d204eecff5f6ae3f63069Eric Laurent    char mixer_path[50] = { 0 } ;
413cefbbac40220d4e7690d204eecff5f6ae3f63069Eric Laurent    snd_device_t snd_device = SND_DEVICE_NONE;
414cefbbac40220d4e7690d204eecff5f6ae3f63069Eric Laurent    struct listnode *node;
415cefbbac40220d4e7690d204eecff5f6ae3f63069Eric Laurent    struct audio_usecase *usecase;
416cefbbac40220d4e7690d204eecff5f6ae3f63069Eric Laurent
417cefbbac40220d4e7690d204eecff5f6ae3f63069Eric Laurent    strcpy(mixer_path, "echo-reference");
418cefbbac40220d4e7690d204eecff5f6ae3f63069Eric Laurent    if (out_device != AUDIO_DEVICE_NONE) {
419cefbbac40220d4e7690d204eecff5f6ae3f63069Eric Laurent        snd_device = platform_get_output_snd_device(adev->platform, out_device);
420cefbbac40220d4e7690d204eecff5f6ae3f63069Eric Laurent        platform_add_backend_name(adev->platform, mixer_path, snd_device);
421cefbbac40220d4e7690d204eecff5f6ae3f63069Eric Laurent    }
422cefbbac40220d4e7690d204eecff5f6ae3f63069Eric Laurent
4233ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    if (enable)
424cefbbac40220d4e7690d204eecff5f6ae3f63069Eric Laurent        audio_route_apply_and_update_path(adev->audio_route, mixer_path);
4253ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    else
426cefbbac40220d4e7690d204eecff5f6ae3f63069Eric Laurent        audio_route_reset_and_update_path(adev->audio_route, mixer_path);
427b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
428cefbbac40220d4e7690d204eecff5f6ae3f63069Eric Laurent    ALOGV("Setting EC Reference: %d for %s", enable, mixer_path);
429b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent}
430b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
43183281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamandastatic struct csd_data *open_csd_client(bool i2s_ext_modem)
43283281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda{
43383281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    struct csd_data *csd = calloc(1, sizeof(struct csd_data));
43483281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda
43583281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    csd->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
43683281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    if (csd->csd_client == NULL) {
43783281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
43883281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        goto error;
43983281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    } else {
44083281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
44183281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda
44283281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        csd->deinit = (deinit_t)dlsym(csd->csd_client,
44383281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                                             "csd_client_deinit");
44483281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        if (csd->deinit == NULL) {
44583281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            ALOGE("%s: dlsym error %s for csd_client_deinit", __func__,
44683281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                  dlerror());
44783281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            goto error;
44883281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        }
44983281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        csd->disable_device = (disable_device_t)dlsym(csd->csd_client,
45083281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                                             "csd_client_disable_device");
45183281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        if (csd->disable_device == NULL) {
45283281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            ALOGE("%s: dlsym error %s for csd_client_disable_device",
45383281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                  __func__, dlerror());
45483281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            goto error;
45583281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        }
45683281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        csd->enable_device_config = (enable_device_config_t)dlsym(csd->csd_client,
45783281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                                               "csd_client_enable_device_config");
45883281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        if (csd->enable_device_config == NULL) {
45983281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            ALOGE("%s: dlsym error %s for csd_client_enable_device_config",
46083281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                  __func__, dlerror());
46183281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            goto error;
46283281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        }
46383281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        csd->enable_device = (enable_device_t)dlsym(csd->csd_client,
46483281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                                             "csd_client_enable_device");
46583281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        if (csd->enable_device == NULL) {
46683281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            ALOGE("%s: dlsym error %s for csd_client_enable_device",
46783281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                  __func__, dlerror());
46883281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            goto error;
46983281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        }
47083281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        csd->start_voice = (start_voice_t)dlsym(csd->csd_client,
47183281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                                             "csd_client_start_voice");
47283281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        if (csd->start_voice == NULL) {
47383281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            ALOGE("%s: dlsym error %s for csd_client_start_voice",
47483281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                  __func__, dlerror());
47583281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            goto error;
47683281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        }
47783281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        csd->stop_voice = (stop_voice_t)dlsym(csd->csd_client,
47883281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                                             "csd_client_stop_voice");
47983281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        if (csd->stop_voice == NULL) {
48083281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            ALOGE("%s: dlsym error %s for csd_client_stop_voice",
48183281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                  __func__, dlerror());
48283281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            goto error;
48383281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        }
48483281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        csd->volume = (volume_t)dlsym(csd->csd_client,
48583281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                                             "csd_client_volume");
48683281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        if (csd->volume == NULL) {
48783281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            ALOGE("%s: dlsym error %s for csd_client_volume",
48883281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                  __func__, dlerror());
48983281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            goto error;
49083281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        }
49183281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        csd->mic_mute = (mic_mute_t)dlsym(csd->csd_client,
49283281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                                             "csd_client_mic_mute");
49383281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        if (csd->mic_mute == NULL) {
49483281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            ALOGE("%s: dlsym error %s for csd_client_mic_mute",
49583281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                  __func__, dlerror());
49683281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            goto error;
49783281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        }
49883281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        csd->slow_talk = (slow_talk_t)dlsym(csd->csd_client,
49983281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                                             "csd_client_slow_talk");
50083281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        if (csd->slow_talk == NULL) {
50183281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            ALOGE("%s: dlsym error %s for csd_client_slow_talk",
50283281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                  __func__, dlerror());
50383281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            goto error;
50483281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        }
50583281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        csd->start_playback = (start_playback_t)dlsym(csd->csd_client,
50683281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                                             "csd_client_start_playback");
50783281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        if (csd->start_playback == NULL) {
50883281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            ALOGE("%s: dlsym error %s for csd_client_start_playback",
50983281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                  __func__, dlerror());
51083281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            goto error;
51183281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        }
51283281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        csd->stop_playback = (stop_playback_t)dlsym(csd->csd_client,
51383281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                                             "csd_client_stop_playback");
51483281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        if (csd->stop_playback == NULL) {
51583281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            ALOGE("%s: dlsym error %s for csd_client_stop_playback",
51683281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                  __func__, dlerror());
51783281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            goto error;
51883281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        }
51983281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        csd->start_record = (start_record_t)dlsym(csd->csd_client,
52083281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                                             "csd_client_start_record");
52183281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        if (csd->start_record == NULL) {
52283281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            ALOGE("%s: dlsym error %s for csd_client_start_record",
52383281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                  __func__, dlerror());
52483281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            goto error;
52583281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        }
52683281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        csd->stop_record = (stop_record_t)dlsym(csd->csd_client,
52783281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                                             "csd_client_stop_record");
52883281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        if (csd->stop_record == NULL) {
52983281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            ALOGE("%s: dlsym error %s for csd_client_stop_record",
53083281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                  __func__, dlerror());
53183281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            goto error;
53283281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        }
53383281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda
53483281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        csd->get_sample_rate = (get_sample_rate_t)dlsym(csd->csd_client,
53583281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                                             "csd_client_get_sample_rate");
53683281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        if (csd->get_sample_rate == NULL) {
53783281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            ALOGE("%s: dlsym error %s for csd_client_get_sample_rate",
53883281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                  __func__, dlerror());
53983281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda
54083281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            goto error;
54183281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        }
54283281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda
54383281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        csd->init = (init_t)dlsym(csd->csd_client, "csd_client_init");
54483281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda
54583281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        if (csd->init == NULL) {
54683281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            ALOGE("%s: dlsym error %s for csd_client_init",
54783281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                  __func__, dlerror());
54883281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            goto error;
54983281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        } else {
55083281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            csd->init(i2s_ext_modem);
55183281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        }
55283281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    }
55383281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    return csd;
55483281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda
55583281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamandaerror:
55683281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    free(csd);
55783281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    csd = NULL;
55883281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    return csd;
55983281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda}
56083281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda
56183281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamandavoid close_csd_client(struct csd_data *csd)
56283281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda{
56383281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    if (csd != NULL) {
56483281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        csd->deinit();
56583281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        dlclose(csd->csd_client);
56683281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        free(csd);
56783281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        csd = NULL;
56883281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    }
56983281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda}
57083281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda
57183281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamandastatic void platform_csd_init(struct platform_data *my_data)
57283281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda{
57383281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda#ifdef PLATFORM_MSM8084
574ae9a10c15cf960e9b2b1159ade6414f80689db5fIliyan Malchev    int32_t modems, (*count_modems)(void);
575ae9a10c15cf960e9b2b1159ade6414f80689db5fIliyan Malchev    const char *name = "libdetectmodem.so";
576ae9a10c15cf960e9b2b1159ade6414f80689db5fIliyan Malchev    const char *func = "count_modems";
577ae9a10c15cf960e9b2b1159ade6414f80689db5fIliyan Malchev    const char *error;
578ae9a10c15cf960e9b2b1159ade6414f80689db5fIliyan Malchev
579ae9a10c15cf960e9b2b1159ade6414f80689db5fIliyan Malchev    my_data->csd = NULL;
580ae9a10c15cf960e9b2b1159ade6414f80689db5fIliyan Malchev
581ae9a10c15cf960e9b2b1159ade6414f80689db5fIliyan Malchev    void *lib = dlopen(name, RTLD_NOW);
582ae9a10c15cf960e9b2b1159ade6414f80689db5fIliyan Malchev    error = dlerror();
583ae9a10c15cf960e9b2b1159ade6414f80689db5fIliyan Malchev    if (!lib) {
584ae9a10c15cf960e9b2b1159ade6414f80689db5fIliyan Malchev        ALOGE("%s: could not find %s: %s", __func__, name, error);
585ae9a10c15cf960e9b2b1159ade6414f80689db5fIliyan Malchev        return;
586ae9a10c15cf960e9b2b1159ade6414f80689db5fIliyan Malchev    }
587ae9a10c15cf960e9b2b1159ade6414f80689db5fIliyan Malchev
588ae9a10c15cf960e9b2b1159ade6414f80689db5fIliyan Malchev    count_modems = NULL;
589ae9a10c15cf960e9b2b1159ade6414f80689db5fIliyan Malchev    *(void **)(&count_modems) = dlsym(lib, func);
590ae9a10c15cf960e9b2b1159ade6414f80689db5fIliyan Malchev    error = dlerror();
591ae9a10c15cf960e9b2b1159ade6414f80689db5fIliyan Malchev    if (!count_modems) {
592ae9a10c15cf960e9b2b1159ade6414f80689db5fIliyan Malchev        ALOGE("%s: could not find symbol %s in %s: %s",
593ae9a10c15cf960e9b2b1159ade6414f80689db5fIliyan Malchev              __func__, func, name, error);
594ae9a10c15cf960e9b2b1159ade6414f80689db5fIliyan Malchev        goto done;
59583281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    }
59683281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda
597ae9a10c15cf960e9b2b1159ade6414f80689db5fIliyan Malchev    modems = count_modems();
598ae9a10c15cf960e9b2b1159ade6414f80689db5fIliyan Malchev    if (modems < 0) {
599ae9a10c15cf960e9b2b1159ade6414f80689db5fIliyan Malchev        ALOGE("%s: count_modems failed\n", __func__);
600ae9a10c15cf960e9b2b1159ade6414f80689db5fIliyan Malchev        goto done;
601ae9a10c15cf960e9b2b1159ade6414f80689db5fIliyan Malchev    }
602ae9a10c15cf960e9b2b1159ade6414f80689db5fIliyan Malchev
603ae9a10c15cf960e9b2b1159ade6414f80689db5fIliyan Malchev    ALOGD("%s: num_modems %d\n", __func__, modems);
604ae9a10c15cf960e9b2b1159ade6414f80689db5fIliyan Malchev    if (modems > 0)
60583281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        my_data->csd = open_csd_client(false /*is_i2s_ext_modem*/);
606ae9a10c15cf960e9b2b1159ade6414f80689db5fIliyan Malchev
607ae9a10c15cf960e9b2b1159ade6414f80689db5fIliyan Malchevdone:
608ae9a10c15cf960e9b2b1159ade6414f80689db5fIliyan Malchev    dlclose(lib);
60983281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda#else
61083281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda     my_data->csd = NULL;
61183281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda#endif
61283281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda}
61383281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda
61498c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew Georgestatic void set_platform_defaults(struct platform_data * my_data)
61598c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George{
61698c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    int32_t dev;
61798c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
61898c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George        backend_table[dev] = NULL;
61998c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    }
62098c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George
62198c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    // TBD - do these go to the platform-info.xml file.
62298c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    // will help in avoiding strdups here
62398c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    backend_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("bt-sco");
62498c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    backend_table[SND_DEVICE_OUT_BT_SCO] = strdup("bt-sco");
62598c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    backend_table[SND_DEVICE_OUT_HDMI] = strdup("hdmi");
62698c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    backend_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("speaker-and-hdmi");
62798c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    backend_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("bt-sco-wb");
62898c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    backend_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("bt-sco-wb");
62999c752d87eb818fc3cfb2e5c6790b1ea0bc88da5Ravi Kumar Alamanda    backend_table[SND_DEVICE_OUT_VOICE_TX] = strdup("afe-proxy");
63099c752d87eb818fc3cfb2e5c6790b1ea0bc88da5Ravi Kumar Alamanda    backend_table[SND_DEVICE_IN_VOICE_RX] = strdup("afe-proxy");
63198c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George
63298c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    if (my_data->ext_speaker) {
63398c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George        backend_table[SND_DEVICE_OUT_SPEAKER] = strdup("speaker");
6341b0d8ce4ec97a57b38a401dbd1e16ac5cf4c4671Eric Laurent        backend_table[SND_DEVICE_OUT_SPEAKER_SAFE] = strdup("speaker");
63598c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George        backend_table[SND_DEVICE_OUT_VOICE_SPEAKER] = strdup("speaker");
63698c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George        backend_table[SND_DEVICE_OUT_SPEAKER_REVERSE] = strdup("speaker");
63798c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George        backend_table[SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] =
63898c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George            strdup("speaker-and-headphones");
639744996b561b92473cc8ba23275811eb1a6b44d5eEric Laurent        backend_table[SND_DEVICE_OUT_SPEAKER_AND_LINE] =
640744996b561b92473cc8ba23275811eb1a6b44d5eEric Laurent            strdup("speaker-and-line");
64198c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    }
64298c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George
64398c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    if (my_data->ext_earpiece) {
64498c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George        backend_table[SND_DEVICE_OUT_VOICE_HANDSET] = strdup("handset");
6459d0d3f1537b5d157a2c31e0744303524b846446eEric Laurent        backend_table[SND_DEVICE_OUT_VOICE_HAC_HANDSET] = strdup("handset");
64698c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George        backend_table[SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = strdup("handset");
64798c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George        backend_table[SND_DEVICE_OUT_HANDSET] = strdup("handset");
64898c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George        backend_table[SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = strdup("handset");
64998c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    }
65098c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George}
65198c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George
652b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurentvoid *platform_init(struct audio_device *adev)
653b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent{
654b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    char value[PROPERTY_VALUE_MAX];
655b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    struct platform_data *my_data;
6564b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    int retry_num = 0, snd_card_num = 0;
65783281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    const char *snd_card_name;
6581b9f4b3708d1ed1204bdb1dec370ad2e9db7a779sangwoo
6594b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    while (snd_card_num < MAX_SND_CARD) {
6604b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        adev->mixer = mixer_open(snd_card_num);
6611b9f4b3708d1ed1204bdb1dec370ad2e9db7a779sangwoo
6624b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        while (!adev->mixer && retry_num < RETRY_NUMBER) {
6634b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava            usleep(RETRY_US);
6644b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava            adev->mixer = mixer_open(snd_card_num);
6654b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava            retry_num++;
6664b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        }
66783281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda
6684b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        if (!adev->mixer) {
6694b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava            ALOGE("%s: Unable to open the mixer card: %d", __func__,
6704b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava                   snd_card_num);
6714b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava            retry_num = 0;
6724b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava            snd_card_num++;
6734b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava            continue;
6744b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        }
675cedf1ac3c00e331b5f51b077f26c1367544ddd65Haynes Mathew George
6764b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        snd_card_name = mixer_get_name(adev->mixer);
6774b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        ALOGD("%s: snd_card_name: %s", __func__, snd_card_name);
678a609e8ebdfeca875b6d35ccfb3fb8b87710f3499Eric Laurent
6794b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        adev->audio_route = audio_route_init(snd_card_num, MIXER_XML_PATH);
6804b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        if (!adev->audio_route) {
6814b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava            ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
6824b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava            return NULL;
6834b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        }
6844b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        adev->snd_card = snd_card_num;
6854b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        ALOGD("%s: Opened sound card:%d", __func__, snd_card_num);
6864b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        break;
6874b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    }
6884b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava
6894b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    if (snd_card_num >= MAX_SND_CARD) {
6904b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        ALOGE("%s: Unable to find correct sound card, aborting.", __func__);
6911b9f4b3708d1ed1204bdb1dec370ad2e9db7a779sangwoo        return NULL;
6921b9f4b3708d1ed1204bdb1dec370ad2e9db7a779sangwoo    }
693b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
694b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    my_data = calloc(1, sizeof(struct platform_data));
695b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
696b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    my_data->adev = adev;
697b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    my_data->dualmic_config = DUALMIC_CONFIG_NONE;
698b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    my_data->fluence_in_spkr_mode = false;
699b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    my_data->fluence_in_voice_call = false;
7003ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    my_data->fluence_in_voice_comm = false;
701b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    my_data->fluence_in_voice_rec = false;
702b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
703299760a41231bd0f6d9991fb189977347365c72bRavi Kumar Alamanda    /*
704299760a41231bd0f6d9991fb189977347365c72bRavi Kumar Alamanda     * The default assumption is that earpiece (handset), speaker and headphones
705299760a41231bd0f6d9991fb189977347365c72bRavi Kumar Alamanda     * devices are connected to internal HW codec and communicated through
706299760a41231bd0f6d9991fb189977347365c72bRavi Kumar Alamanda     * slimbus backend. If any platform communicates with speaker or earpiece
707299760a41231bd0f6d9991fb189977347365c72bRavi Kumar Alamanda     * or headphones through non-slimbus backend such as MI2S or AUXPCM etc.,
708299760a41231bd0f6d9991fb189977347365c72bRavi Kumar Alamanda     * the ext_xxxx flags must be set accordingly.
709299760a41231bd0f6d9991fb189977347365c72bRavi Kumar Alamanda     */
710299760a41231bd0f6d9991fb189977347365c72bRavi Kumar Alamanda    if (strstr(snd_card_name, "tfa9890_stereo")) {
711299760a41231bd0f6d9991fb189977347365c72bRavi Kumar Alamanda        my_data->ext_speaker = true;
712299760a41231bd0f6d9991fb189977347365c72bRavi Kumar Alamanda        my_data->ext_earpiece = true;
713299760a41231bd0f6d9991fb189977347365c72bRavi Kumar Alamanda    } else if (strstr(snd_card_name, "tfa9890")) {
714299760a41231bd0f6d9991fb189977347365c72bRavi Kumar Alamanda        my_data->ext_speaker = true;
715299760a41231bd0f6d9991fb189977347365c72bRavi Kumar Alamanda    }
716299760a41231bd0f6d9991fb189977347365c72bRavi Kumar Alamanda
717b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    property_get("persist.audio.dualmic.config",value,"");
718b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    if (!strcmp("broadside", value)) {
7193ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda        ALOGE("%s: Unsupported dualmic configuration", __func__);
720b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    } else if (!strcmp("endfire", value)) {
721b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        my_data->dualmic_config = DUALMIC_CONFIG_ENDFIRE;
722b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    }
723b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
724b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    if (my_data->dualmic_config != DUALMIC_CONFIG_NONE) {
725b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        property_get("persist.audio.fluence.voicecall",value,"");
726b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        if (!strcmp("true", value)) {
727b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            my_data->fluence_in_voice_call = true;
728b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        }
729b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
7303ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda        property_get("persist.audio.fluence.voicecomm",value,"");
7313ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda        if (!strcmp("true", value)) {
7323ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda            my_data->fluence_in_voice_comm = true;
7333ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda        }
7343ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda
735b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        property_get("persist.audio.fluence.voicerec",value,"");
736b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        if (!strcmp("true", value)) {
737b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            my_data->fluence_in_voice_rec = true;
738b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        }
739b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
740b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        property_get("persist.audio.fluence.speaker",value,"");
741b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        if (!strcmp("true", value)) {
742b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            my_data->fluence_in_spkr_mode = true;
743b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        }
744b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    }
745b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
746b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
747b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    if (my_data->acdb_handle == NULL) {
748b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
749b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    } else {
750b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
751b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
752b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent                                                    "acdb_loader_deallocate_ACDB");
75383281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        if (!my_data->acdb_deallocate)
75483281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s",
75583281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                  __func__, LIB_ACDB_LOADER);
75683281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda
757b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
758b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent                                                    "acdb_loader_send_audio_cal");
759b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        if (!my_data->acdb_send_audio_cal)
76083281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s",
761b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent                  __func__, LIB_ACDB_LOADER);
76283281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda
763b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
764b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent                                                    "acdb_loader_send_voice_cal");
76583281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        if (!my_data->acdb_send_voice_cal)
76683281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s",
76783281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                  __func__, LIB_ACDB_LOADER);
76883281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda
76983281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle,
77083281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                                                    "acdb_loader_reload_vocvoltable");
77183281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        if (!my_data->acdb_reload_vocvoltable)
77283281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s",
77383281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                  __func__, LIB_ACDB_LOADER);
77483281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda#ifdef PLATFORM_MSM8084
77583281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        my_data->acdb_init = (acdb_init_t)dlsym(my_data->acdb_handle,
77683281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                                                    "acdb_loader_init_v2");
77783281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        if (my_data->acdb_init == NULL)
77883281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__, dlerror());
77983281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        else
78098c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George            my_data->acdb_init((char *)snd_card_name);
78183281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda#else
782b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        my_data->acdb_init = (acdb_init_t)dlsym(my_data->acdb_handle,
783b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent                                                    "acdb_loader_init_ACDB");
784b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        if (my_data->acdb_init == NULL)
785b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__, dlerror());
786b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        else
787b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            my_data->acdb_init();
78883281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda#endif
7895bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George
790b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    }
791b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
79298c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    set_platform_defaults(my_data);
79398c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George
79498c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    /* Initialize platform specific ids and/or backends*/
79598c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    platform_info_init();
79698c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George
79783281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    /* load csd client */
79883281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    platform_csd_init(my_data);
79983281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda
800b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    return my_data;
801b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent}
802b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
803b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurentvoid platform_deinit(void *platform)
804b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent{
8054b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    struct platform_data *my_data = (struct platform_data *)platform;
8064b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    close_csd_client(my_data->csd);
807b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    free(platform);
808b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent}
809b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
810b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurentconst char *platform_get_snd_device_name(snd_device_t snd_device)
811b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent{
812b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX)
813b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        return device_table[snd_device];
814b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    else
8156402646dbd962f62c37abbb1d435907d54da77ddRavi Kumar Alamanda        return "none";
816b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent}
817b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
818299760a41231bd0f6d9991fb189977347365c72bRavi Kumar Alamandavoid platform_add_backend_name(void *platform, char *mixer_path,
819299760a41231bd0f6d9991fb189977347365c72bRavi Kumar Alamanda                               snd_device_t snd_device)
820b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent{
821299760a41231bd0f6d9991fb189977347365c72bRavi Kumar Alamanda    struct platform_data *my_data = (struct platform_data *)platform;
822299760a41231bd0f6d9991fb189977347365c72bRavi Kumar Alamanda
82398c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
82498c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George        ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
82598c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George        return;
8261de6e5aac3120408a003dc8b5f7fdd68c40f436dRavi Kumar Alamanda    }
82798c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George
82898c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    const char * suffix = backend_table[snd_device];
82998c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George
83098c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    if (suffix != NULL) {
83198c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George        strcat(mixer_path, " ");
83298c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George        strcat(mixer_path, suffix);
833299760a41231bd0f6d9991fb189977347365c72bRavi Kumar Alamanda    }
834b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent}
835b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
836b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurentint platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
837b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent{
838b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    int device_id;
839b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    if (device_type == PCM_PLAYBACK)
840b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        device_id = pcm_device_table[usecase][0];
841b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    else
842b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        device_id = pcm_device_table[usecase][1];
843b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    return device_id;
844b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent}
845b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
84698c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew Georgestatic int find_index(const struct name_to_index * table, int32_t len,
84798c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George                      const char * name)
8485bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George{
8495bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George    int ret = 0;
85098c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    int32_t i;
8515bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George
85298c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    if (table == NULL) {
85398c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George        ALOGE("%s: table is NULL", __func__);
8545bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George        ret = -ENODEV;
8555bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George        goto done;
8565bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George    }
8575bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George
85898c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    if (name == NULL) {
85998c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George        ALOGE("null key");
86098c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George        ret = -ENODEV;
86198c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George        goto done;
86298c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    }
86398c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George
86498c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    for (i=0; i < len; i++) {
86598c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George        if (!strcmp(table[i].name, name)) {
86698c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George            ret = table[i].index;
8675bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George            goto done;
8685bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George        }
8695bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George    }
87098c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    ALOGE("%s: Could not find index for name = %s",
87198c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George            __func__, name);
8725bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George    ret = -ENODEV;
8735bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew Georgedone:
8745bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George    return ret;
8755bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George}
8765bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George
87798c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew Georgeint platform_get_snd_device_index(char *device_name)
87898c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George{
87998c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    return find_index(snd_device_name_index, SND_DEVICE_MAX, device_name);
88098c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George}
88198c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George
88298c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew Georgeint platform_get_usecase_index(const char *usecase_name)
88398c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George{
88498c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    return find_index(usecase_name_index, AUDIO_USECASE_MAX, usecase_name);
88598c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George}
88698c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George
8875bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew Georgeint platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
8885bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George{
8895bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George    int ret = 0;
8905bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George
8915bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George    if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
8925bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George        ALOGE("%s: Invalid snd_device = %d",
8935bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George            __func__, snd_device);
8945bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George        ret = -EINVAL;
8955bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George        goto done;
8965bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George    }
8975bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George
8985bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George    acdb_device_table[snd_device] = acdb_id;
8995bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew Georgedone:
9005bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George    return ret;
9015bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George}
9025bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George
903b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurentint platform_send_audio_calibration(void *platform, snd_device_t snd_device)
904b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent{
905b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    struct platform_data *my_data = (struct platform_data *)platform;
906b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    int acdb_dev_id, acdb_dev_type;
907b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
908b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    acdb_dev_id = acdb_device_table[snd_device];
909b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    if (acdb_dev_id < 0) {
910b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        ALOGE("%s: Could not find acdb id for device(%d)",
911b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent              __func__, snd_device);
912b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        return -EINVAL;
913b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    }
914b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    if (my_data->acdb_send_audio_cal) {
9153ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda        ALOGD("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
916b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent              __func__, snd_device, acdb_dev_id);
917b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        if (snd_device >= SND_DEVICE_OUT_BEGIN &&
918b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent                snd_device < SND_DEVICE_OUT_END)
919b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            acdb_dev_type = ACDB_DEV_TYPE_OUT;
920b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        else
921b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            acdb_dev_type = ACDB_DEV_TYPE_IN;
922b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
923b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    }
924b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    return 0;
925b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent}
926b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
927b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurentint platform_switch_voice_call_device_pre(void *platform)
928b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent{
92983281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    struct platform_data *my_data = (struct platform_data *)platform;
93083281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    int ret = 0;
93183281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda
93283281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    if (my_data->csd != NULL &&
93383281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        my_data->adev->mode == AUDIO_MODE_IN_CALL) {
93483281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        /* This must be called before disabling mixer controls on APQ side */
93583281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        ret = my_data->csd->disable_device();
93683281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        if (ret < 0) {
93783281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            ALOGE("%s: csd_client_disable_device, failed, error %d",
93883281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                  __func__, ret);
93983281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        }
94083281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    }
94183281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    return ret;
94283281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda}
94383281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda
94483281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamandaint platform_switch_voice_call_enable_device_config(void *platform,
94583281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                                                    snd_device_t out_snd_device,
94683281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                                                    snd_device_t in_snd_device)
94783281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda{
94883281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    struct platform_data *my_data = (struct platform_data *)platform;
94983281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    int acdb_rx_id, acdb_tx_id;
95083281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    int ret = 0;
95183281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda
95283281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    if (my_data->csd == NULL)
95383281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        return ret;
95483281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda
95583281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    acdb_rx_id = acdb_device_table[out_snd_device];
95683281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda
95783281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    acdb_tx_id = acdb_device_table[in_snd_device];
95883281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda
95983281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    if (acdb_rx_id > 0 && acdb_tx_id > 0) {
96083281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
96183281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        if (ret < 0) {
96283281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            ALOGE("%s: csd_enable_device_config, failed, error %d",
96383281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                  __func__, ret);
96483281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        }
96583281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    } else {
96683281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
96783281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda              acdb_rx_id, acdb_tx_id);
96883281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    }
96983281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda
97083281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    return ret;
971b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent}
972b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
973b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurentint platform_switch_voice_call_device_post(void *platform,
974b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent                                           snd_device_t out_snd_device,
975b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent                                           snd_device_t in_snd_device)
976b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent{
977b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    struct platform_data *my_data = (struct platform_data *)platform;
978b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    int acdb_rx_id, acdb_tx_id;
979b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
980b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    if (my_data->acdb_send_voice_cal == NULL) {
981b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
982b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    } else {
983b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        acdb_rx_id = acdb_device_table[out_snd_device];
984b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        acdb_tx_id = acdb_device_table[in_snd_device];
985b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
986b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        if (acdb_rx_id > 0 && acdb_tx_id > 0)
987b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
988b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        else
989b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
990b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent                  acdb_rx_id, acdb_tx_id);
991b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    }
992b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
993b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    return 0;
994b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent}
995b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
99683281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamandaint platform_switch_voice_call_usecase_route_post(void *platform,
99783281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                                                  snd_device_t out_snd_device,
99883281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                                                  snd_device_t in_snd_device)
99983281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda{
100083281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    struct platform_data *my_data = (struct platform_data *)platform;
100183281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    int acdb_rx_id, acdb_tx_id;
100283281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    int ret = 0;
100383281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda
100483281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    if (my_data->csd == NULL)
100583281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        return ret;
100683281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda
100783281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    acdb_rx_id = acdb_device_table[out_snd_device];
100883281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda
100983281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    acdb_tx_id = acdb_device_table[in_snd_device];
101083281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda
101183281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    if (acdb_rx_id > 0 && acdb_tx_id > 0) {
101283281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
101383281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                                          my_data->adev->acdb_settings);
101483281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        if (ret < 0) {
101583281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            ALOGE("%s: csd_enable_device, failed, error %d", __func__, ret);
101683281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        }
101783281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    } else {
101883281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
101983281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda              acdb_rx_id, acdb_tx_id);
102083281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    }
102183281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda
102283281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    return ret;
102383281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda}
102483281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda
10254b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastavaint platform_start_voice_call(void *platform, uint32_t vsid)
1026b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent{
102783281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    struct platform_data *my_data = (struct platform_data *)platform;
102883281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    int ret = 0;
102983281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda
103083281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    if (my_data->csd != NULL) {
10314b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        ret = my_data->csd->start_voice(vsid);
103283281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        if (ret < 0) {
103383281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
103483281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        }
103583281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    }
103683281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    return ret;
1037b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent}
1038b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
10394b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastavaint platform_stop_voice_call(void *platform, uint32_t vsid)
1040b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent{
104183281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    struct platform_data *my_data = (struct platform_data *)platform;
104283281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    int ret = 0;
104383281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda
104483281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    if (my_data->csd != NULL) {
10454b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        ret = my_data->csd->stop_voice(vsid);
104683281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        if (ret < 0) {
104783281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
104883281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        }
104983281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    }
105083281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    return ret;
1051b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent}
1052b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
10534b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastavaint platform_get_sample_rate(void *platform, uint32_t *rate)
10544b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava{
10554b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    struct platform_data *my_data = (struct platform_data *)platform;
10564b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    int ret = 0;
10574b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava
10584b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    if (my_data->csd != NULL) {
10594b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        ret = my_data->csd->get_sample_rate(rate);
10604b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        if (ret < 0) {
10614b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava            ALOGE("%s: csd_get_sample_rate error %d\n", __func__, ret);
10624b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        }
10634b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    }
10644b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    return ret;
10654b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava}
10664b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava
1067b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurentint platform_set_voice_volume(void *platform, int volume)
1068b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent{
1069b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    struct platform_data *my_data = (struct platform_data *)platform;
1070b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    struct audio_device *adev = my_data->adev;
1071b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    struct mixer_ctl *ctl;
107253b2cf0c72aa18a5848919e2309731af652e84f9sangwoo    const char *mixer_ctl_name = "Voice Rx Gain";
10734b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    int vol_index = 0, ret = 0;
10744b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    uint32_t set_values[ ] = {0,
10754b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava                              ALL_SESSION_VSID,
10764b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava                              DEFAULT_VOLUME_RAMP_DURATION_MS};
1077b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
1078b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    // Voice volume levels are mapped to adsp volume levels as follows.
1079b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1  0 -> 0
1080b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    // But this values don't changed in kernel. So, below change is need.
10814b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, MAX_VOL_INDEX);
10824b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    set_values[0] = vol_index;
1083b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
1084b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1085b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    if (!ctl) {
1086b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        ALOGE("%s: Could not get ctl for mixer cmd - %s",
1087b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent              __func__, mixer_ctl_name);
1088b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        return -EINVAL;
1089b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    }
10904b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    ALOGV("Setting voice volume index: %d", set_values[0]);
10914b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
10924b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava
109383281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    if (my_data->csd != NULL) {
109483281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        ret = my_data->csd->volume(ALL_SESSION_VSID, volume,
109583281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                                   DEFAULT_VOLUME_RAMP_DURATION_MS);
109683281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        if (ret < 0) {
109783281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            ALOGE("%s: csd_volume error %d", __func__, ret);
109883281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        }
109983281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    }
110083281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    return ret;
1101b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent}
1102b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
1103b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurentint platform_set_mic_mute(void *platform, bool state)
1104b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent{
1105b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    struct platform_data *my_data = (struct platform_data *)platform;
1106b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    struct audio_device *adev = my_data->adev;
1107b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    struct mixer_ctl *ctl;
1108b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    const char *mixer_ctl_name = "Voice Tx Mute";
110953b2cf0c72aa18a5848919e2309731af652e84f9sangwoo    int ret = 0;
11104b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    uint32_t set_values[ ] = {0,
11114b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava                              ALL_SESSION_VSID,
11124b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava                              DEFAULT_MUTE_RAMP_DURATION_MS};
1113cedf1ac3c00e331b5f51b077f26c1367544ddd65Haynes Mathew George
11144b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    if (adev->mode != AUDIO_MODE_IN_CALL)
11154b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        return 0;
11164b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava
11174b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    set_values[0] = state;
11184b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
11194b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    if (!ctl) {
11204b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        ALOGE("%s: Could not get ctl for mixer cmd - %s",
11214b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava              __func__, mixer_ctl_name);
11224b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        return -EINVAL;
11234b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    }
11244b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    ALOGV("Setting voice mute state: %d", state);
11254b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
11264b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava
11274b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    if (my_data->csd != NULL) {
11284b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state,
11294b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava                                     DEFAULT_MUTE_RAMP_DURATION_MS);
1130a609e8ebdfeca875b6d35ccfb3fb8b87710f3499Eric Laurent        if (ret < 0) {
11314b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava            ALOGE("%s: csd_mic_mute error %d", __func__, ret);
113253b2cf0c72aa18a5848919e2309731af652e84f9sangwoo        }
1133cedf1ac3c00e331b5f51b077f26c1367544ddd65Haynes Mathew George    }
11344b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    return ret;
11354b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava}
1136cedf1ac3c00e331b5f51b077f26c1367544ddd65Haynes Mathew George
11374b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastavaint platform_set_device_mute(void *platform, bool state, char *dir)
11384b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava{
11394b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    struct platform_data *my_data = (struct platform_data *)platform;
11404b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    struct audio_device *adev = my_data->adev;
11414b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    struct mixer_ctl *ctl;
11424b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    char *mixer_ctl_name = NULL;
11434b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    int ret = 0;
11444b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    uint32_t set_values[ ] = {0,
11454b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava                              ALL_SESSION_VSID,
11464b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava                              0};
11474b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    if(dir == NULL) {
11484b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        ALOGE("%s: Invalid direction:%s", __func__, dir);
11494b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        return -EINVAL;
11504b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    }
11514b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava
11524b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    if (!strncmp("rx", dir, sizeof("rx"))) {
11534b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        mixer_ctl_name = "Voice Rx Device Mute";
11544b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    } else if (!strncmp("tx", dir, sizeof("tx"))) {
11554b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        mixer_ctl_name = "Voice Tx Device Mute";
11564b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    } else {
11574b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        return -EINVAL;
11584b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    }
11594b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava
11604b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    set_values[0] = state;
11614b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
11624b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    if (!ctl) {
11634b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        ALOGE("%s: Could not get ctl for mixer cmd - %s",
11644b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava              __func__, mixer_ctl_name);
11654b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        return -EINVAL;
11664b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    }
11674b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava
11684b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
11694b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava          __func__,state, mixer_ctl_name);
11704b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
11714b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava
11724b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    return ret;
1173b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent}
1174b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
1175b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurentsnd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
1176b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent{
1177b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    struct platform_data *my_data = (struct platform_data *)platform;
1178b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    struct audio_device *adev = my_data->adev;
1179b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    audio_mode_t mode = adev->mode;
1180b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    snd_device_t snd_device = SND_DEVICE_NONE;
1181b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
1182b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    ALOGV("%s: enter: output devices(%#x)", __func__, devices);
1183b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    if (devices == AUDIO_DEVICE_NONE ||
1184b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        devices & AUDIO_DEVICE_BIT_IN) {
1185b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
1186b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        goto exit;
1187b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    }
1188b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
1189cefbbac40220d4e7690d204eecff5f6ae3f63069Eric Laurent    if ((mode == AUDIO_MODE_IN_CALL) ||
1190cefbbac40220d4e7690d204eecff5f6ae3f63069Eric Laurent        (adev->enable_voicerx)) {
1191b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
119209f2e0e6bf8accf1728ca89e780702d53f2c5b6dEric Laurent            devices & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
119309f2e0e6bf8accf1728ca89e780702d53f2c5b6dEric Laurent            devices & AUDIO_DEVICE_OUT_LINE) {
1194cefbbac40220d4e7690d204eecff5f6ae3f63069Eric Laurent            if ((mode == AUDIO_MODE_IN_CALL) &&
1195cefbbac40220d4e7690d204eecff5f6ae3f63069Eric Laurent                (adev->voice.tty_mode == TTY_MODE_FULL))
1196b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent                snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
1197cefbbac40220d4e7690d204eecff5f6ae3f63069Eric Laurent            else if ((mode == AUDIO_MODE_IN_CALL) &&
1198cefbbac40220d4e7690d204eecff5f6ae3f63069Eric Laurent                (adev->voice.tty_mode == TTY_MODE_VCO))
1199b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent                snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
1200cefbbac40220d4e7690d204eecff5f6ae3f63069Eric Laurent            else if ((mode == AUDIO_MODE_IN_CALL) &&
1201cefbbac40220d4e7690d204eecff5f6ae3f63069Eric Laurent                (adev->voice.tty_mode == TTY_MODE_HCO))
1202b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent                snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
120309f2e0e6bf8accf1728ca89e780702d53f2c5b6dEric Laurent            else {
120409f2e0e6bf8accf1728ca89e780702d53f2c5b6dEric Laurent                if (devices & AUDIO_DEVICE_OUT_LINE)
120509f2e0e6bf8accf1728ca89e780702d53f2c5b6dEric Laurent                    snd_device = SND_DEVICE_OUT_VOICE_LINE;
120609f2e0e6bf8accf1728ca89e780702d53f2c5b6dEric Laurent                else
120709f2e0e6bf8accf1728ca89e780702d53f2c5b6dEric Laurent                    snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
120809f2e0e6bf8accf1728ca89e780702d53f2c5b6dEric Laurent                }
1209b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
12109f3065480c81bf01d3af65bfd3da09e1fb74b520Ravi Kumar Alamanda            if (adev->bt_wb_speech_enabled) {
12119f3065480c81bf01d3af65bfd3da09e1fb74b520Ravi Kumar Alamanda                snd_device = SND_DEVICE_OUT_BT_SCO_WB;
12129f3065480c81bf01d3af65bfd3da09e1fb74b520Ravi Kumar Alamanda            } else {
12139f3065480c81bf01d3af65bfd3da09e1fb74b520Ravi Kumar Alamanda                snd_device = SND_DEVICE_OUT_BT_SCO;
12149f3065480c81bf01d3af65bfd3da09e1fb74b520Ravi Kumar Alamanda            }
12151b0d8ce4ec97a57b38a401dbd1e16ac5cf4c4671Eric Laurent        } else if (devices & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
1216b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
1217b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
12189d0d3f1537b5d157a2c31e0744303524b846446eEric Laurent            if(adev->voice.hac)
12199d0d3f1537b5d157a2c31e0744303524b846446eEric Laurent                snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
12209d0d3f1537b5d157a2c31e0744303524b846446eEric Laurent            else if (is_operator_tmus())
1221b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent                snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS;
1222b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            else
1223b4d368e0fe6006657ebc4e1f9ba01a072c4ca2c7Eric Laurent                snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
122499c752d87eb818fc3cfb2e5c6790b1ea0bc88da5Ravi Kumar Alamanda        } else if (devices & AUDIO_DEVICE_OUT_TELEPHONY_TX)
122599c752d87eb818fc3cfb2e5c6790b1ea0bc88da5Ravi Kumar Alamanda            snd_device = SND_DEVICE_OUT_VOICE_TX;
122699c752d87eb818fc3cfb2e5c6790b1ea0bc88da5Ravi Kumar Alamanda
1227b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        if (snd_device != SND_DEVICE_NONE) {
1228b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            goto exit;
1229b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        }
1230b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    }
1231b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
1232b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    if (popcount(devices) == 2) {
1233b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
1234b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent                        AUDIO_DEVICE_OUT_SPEAKER)) {
1235b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
1236b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
1237b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent                               AUDIO_DEVICE_OUT_SPEAKER)) {
1238b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
1239744996b561b92473cc8ba23275811eb1a6b44d5eEric Laurent        } else if (devices == (AUDIO_DEVICE_OUT_LINE |
1240744996b561b92473cc8ba23275811eb1a6b44d5eEric Laurent                               AUDIO_DEVICE_OUT_SPEAKER)) {
1241744996b561b92473cc8ba23275811eb1a6b44d5eEric Laurent            snd_device = SND_DEVICE_OUT_SPEAKER_AND_LINE;
1242b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
1243b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent                               AUDIO_DEVICE_OUT_SPEAKER)) {
1244b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
1245b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        } else {
1246b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
1247b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            goto exit;
1248b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        }
1249b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        if (snd_device != SND_DEVICE_NONE) {
1250b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            goto exit;
1251b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        }
1252b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    }
1253b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
1254b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    if (popcount(devices) != 1) {
1255b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
1256b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        goto exit;
1257b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    }
1258b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
1259b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1260b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
1261b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        snd_device = SND_DEVICE_OUT_HEADPHONES;
126209f2e0e6bf8accf1728ca89e780702d53f2c5b6dEric Laurent    } else if (devices & AUDIO_DEVICE_OUT_LINE) {
126309f2e0e6bf8accf1728ca89e780702d53f2c5b6dEric Laurent        snd_device = SND_DEVICE_OUT_LINE;
12641b0d8ce4ec97a57b38a401dbd1e16ac5cf4c4671Eric Laurent    } else if (devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) {
12651b0d8ce4ec97a57b38a401dbd1e16ac5cf4c4671Eric Laurent        snd_device = SND_DEVICE_OUT_SPEAKER_SAFE;
1266b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
1267b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        if (adev->speaker_lr_swap)
1268b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
1269b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        else
1270b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            snd_device = SND_DEVICE_OUT_SPEAKER;
1271b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
12729f3065480c81bf01d3af65bfd3da09e1fb74b520Ravi Kumar Alamanda        if (adev->bt_wb_speech_enabled) {
12739f3065480c81bf01d3af65bfd3da09e1fb74b520Ravi Kumar Alamanda            snd_device = SND_DEVICE_OUT_BT_SCO_WB;
12749f3065480c81bf01d3af65bfd3da09e1fb74b520Ravi Kumar Alamanda        } else {
12759f3065480c81bf01d3af65bfd3da09e1fb74b520Ravi Kumar Alamanda            snd_device = SND_DEVICE_OUT_BT_SCO;
12769f3065480c81bf01d3af65bfd3da09e1fb74b520Ravi Kumar Alamanda        }
1277b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
1278b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        snd_device = SND_DEVICE_OUT_HDMI ;
1279b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
12809d0d3f1537b5d157a2c31e0744303524b846446eEric Laurent        /*HAC support for voice-ish audio (eg visual voicemail)*/
12819d0d3f1537b5d157a2c31e0744303524b846446eEric Laurent        if(adev->voice.hac)
12829d0d3f1537b5d157a2c31e0744303524b846446eEric Laurent            snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
12839d0d3f1537b5d157a2c31e0744303524b846446eEric Laurent        else
12849d0d3f1537b5d157a2c31e0744303524b846446eEric Laurent            snd_device = SND_DEVICE_OUT_HANDSET;
1285b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    } else {
1286b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        ALOGE("%s: Unknown device(s) %#x", __func__, devices);
1287b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    }
1288b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurentexit:
1289b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
1290b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    return snd_device;
1291b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent}
1292b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
1293b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurentsnd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
1294b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent{
1295b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    struct platform_data *my_data = (struct platform_data *)platform;
1296b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    struct audio_device *adev = my_data->adev;
1297b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    audio_source_t  source = (adev->active_input == NULL) ?
1298b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent                                AUDIO_SOURCE_DEFAULT : adev->active_input->source;
1299b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
1300b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    audio_mode_t    mode   = adev->mode;
1301b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    audio_devices_t in_device = ((adev->active_input == NULL) ?
1302b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent                                    AUDIO_DEVICE_NONE : adev->active_input->device)
1303b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent                                & ~AUDIO_DEVICE_BIT_IN;
1304b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
1305b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent                                AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
1306b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    snd_device_t snd_device = SND_DEVICE_NONE;
13073ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    int channel_count = popcount(channel_mask);
1308b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
1309b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    ALOGV("%s: enter: out_device(%#x) in_device(%#x)",
1310b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent          __func__, out_device, in_device);
1311b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    if (mode == AUDIO_MODE_IN_CALL) {
1312b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        if (out_device == AUDIO_DEVICE_NONE) {
1313b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            ALOGE("%s: No output device set for voice call", __func__);
1314b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            goto exit;
1315b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        }
13164b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        if (adev->voice.tty_mode != TTY_MODE_OFF) {
1317b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
131809f2e0e6bf8accf1728ca89e780702d53f2c5b6dEric Laurent                out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
131909f2e0e6bf8accf1728ca89e780702d53f2c5b6dEric Laurent                out_device & AUDIO_DEVICE_OUT_LINE) {
13204b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava                switch (adev->voice.tty_mode) {
1321b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent                case TTY_MODE_FULL:
1322b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent                    snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
1323b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent                    break;
1324b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent                case TTY_MODE_VCO:
1325b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent                    snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
1326b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent                    break;
1327b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent                case TTY_MODE_HCO:
1328b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent                    snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
1329b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent                    break;
1330b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent                default:
13314b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava                    ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
1332b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent                }
1333b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent                goto exit;
1334b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            }
1335b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        }
1336b991fb007d870cbd682273e5fc7413b9d238a6d9Eric Laurent        if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
1337b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            if (my_data->fluence_in_voice_call == false) {
1338b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent                snd_device = SND_DEVICE_IN_HANDSET_MIC;
1339b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            } else {
13403ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                if (is_operator_tmus())
13413ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                    snd_device = SND_DEVICE_IN_VOICE_DMIC_TMUS;
1342b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent                else
13433ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                    snd_device = SND_DEVICE_IN_VOICE_DMIC;
1344b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            }
1345b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
1346b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
1347b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
13489f3065480c81bf01d3af65bfd3da09e1fb74b520Ravi Kumar Alamanda            if (adev->bt_wb_speech_enabled) {
13499f3065480c81bf01d3af65bfd3da09e1fb74b520Ravi Kumar Alamanda                snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
13509f3065480c81bf01d3af65bfd3da09e1fb74b520Ravi Kumar Alamanda            } else {
13519f3065480c81bf01d3af65bfd3da09e1fb74b520Ravi Kumar Alamanda                snd_device = SND_DEVICE_IN_BT_SCO_MIC;
13529f3065480c81bf01d3af65bfd3da09e1fb74b520Ravi Kumar Alamanda            }
1353b991fb007d870cbd682273e5fc7413b9d238a6d9Eric Laurent        } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
13541b0d8ce4ec97a57b38a401dbd1e16ac5cf4c4671Eric Laurent            out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
1355b991fb007d870cbd682273e5fc7413b9d238a6d9Eric Laurent            out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1356b991fb007d870cbd682273e5fc7413b9d238a6d9Eric Laurent            out_device & AUDIO_DEVICE_OUT_LINE) {
1357b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode &&
13583ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                    my_data->dualmic_config != DUALMIC_CONFIG_NONE) {
13593ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
1360b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            } else {
1361b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent                snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
1362b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            }
136399c752d87eb818fc3cfb2e5c6790b1ea0bc88da5Ravi Kumar Alamanda        } else if (out_device & AUDIO_DEVICE_OUT_TELEPHONY_TX)
136499c752d87eb818fc3cfb2e5c6790b1ea0bc88da5Ravi Kumar Alamanda            snd_device = SND_DEVICE_IN_VOICE_RX;
1365b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    } else if (source == AUDIO_SOURCE_CAMCORDER) {
1366b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
1367b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            in_device & AUDIO_DEVICE_IN_BACK_MIC) {
1368b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
1369b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        }
1370b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
1371b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
13723ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda            if (my_data->dualmic_config != DUALMIC_CONFIG_NONE) {
1373b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent                if (channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK)
13743ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                    snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
13753ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                else if (my_data->fluence_in_voice_rec &&
13763ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                         adev->active_input->enable_ns)
13773ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                    snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
1378b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            }
1379b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
1380b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            if (snd_device == SND_DEVICE_NONE) {
13813ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                if (adev->active_input->enable_ns)
13823ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                    snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
13833ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                else
13843ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                    snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
1385b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            }
1386b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        }
1387b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION) {
13881b0d8ce4ec97a57b38a401dbd1e16ac5cf4c4671Eric Laurent        if (out_device & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE))
1389b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            in_device = AUDIO_DEVICE_IN_BACK_MIC;
1390b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        if (adev->active_input) {
13913ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda            if (adev->active_input->enable_aec &&
13923ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                    adev->active_input->enable_ns) {
13933ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
13943ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                    if (my_data->fluence_in_spkr_mode &&
13953ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                            my_data->fluence_in_voice_comm &&
13963ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                            my_data->dualmic_config != DUALMIC_CONFIG_NONE) {
13973ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                        snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
13983ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                    } else
13993ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                        snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
14003ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
14013ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                    if (my_data->fluence_in_voice_comm &&
14023ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                            my_data->dualmic_config != DUALMIC_CONFIG_NONE) {
14033ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                        snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
14043ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                    } else
14053ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                        snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
1406cefbbac40220d4e7690d204eecff5f6ae3f63069Eric Laurent                } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
1407cefbbac40220d4e7690d204eecff5f6ae3f63069Eric Laurent                    snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
14083ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                }
1409cefbbac40220d4e7690d204eecff5f6ae3f63069Eric Laurent                platform_set_echo_reference(adev, true, out_device);
14103ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda            } else if (adev->active_input->enable_aec) {
1411b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent                if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
14123ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                    if (my_data->fluence_in_spkr_mode &&
14133ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                            my_data->fluence_in_voice_comm &&
14143ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                            my_data->dualmic_config != DUALMIC_CONFIG_NONE) {
14153ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                        snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
14163ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                    } else
14173ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                        snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
1418b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent                } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
14193ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                    if (my_data->fluence_in_voice_comm &&
14203ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                            my_data->dualmic_config != DUALMIC_CONFIG_NONE) {
14213ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                        snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
14223ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                    } else
14233ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                        snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
1424cefbbac40220d4e7690d204eecff5f6ae3f63069Eric Laurent               } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
1425cefbbac40220d4e7690d204eecff5f6ae3f63069Eric Laurent                   snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
1426cefbbac40220d4e7690d204eecff5f6ae3f63069Eric Laurent               }
1427cefbbac40220d4e7690d204eecff5f6ae3f63069Eric Laurent                platform_set_echo_reference(adev, true, out_device);
14283ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda            } else if (adev->active_input->enable_ns) {
14293ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
14303ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                    if (my_data->fluence_in_spkr_mode &&
14313ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                            my_data->fluence_in_voice_comm &&
14323ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                            my_data->dualmic_config != DUALMIC_CONFIG_NONE) {
14333ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                        snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
14343ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                    } else
14353ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                        snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
14363ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
14373ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                    if (my_data->fluence_in_voice_comm &&
14383ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                            my_data->dualmic_config != DUALMIC_CONFIG_NONE) {
14393ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                        snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
14403ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                    } else
14413ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                        snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
14423ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                }
1443cefbbac40220d4e7690d204eecff5f6ae3f63069Eric Laurent            }
1444b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        }
1445b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    } else if (source == AUDIO_SOURCE_DEFAULT) {
1446b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        goto exit;
1447b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    }
1448b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
1449b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
1450b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    if (snd_device != SND_DEVICE_NONE) {
1451b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        goto exit;
1452b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    }
1453b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
1454b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    if (in_device != AUDIO_DEVICE_NONE &&
1455b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
1456b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
1457b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
14583ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda            if (my_data->dualmic_config != DUALMIC_CONFIG_NONE &&
14593ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                    channel_count == 2)
14603ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                snd_device = SND_DEVICE_IN_HANDSET_DMIC_STEREO;
14613ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda            else
14623ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                snd_device = SND_DEVICE_IN_HANDSET_MIC;
1463b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
14643ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda            if (my_data->dualmic_config != DUALMIC_CONFIG_NONE &&
14653ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                    channel_count == 2)
14663ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
14673ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda            else
14683ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                snd_device = SND_DEVICE_IN_SPEAKER_MIC;
1469b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
1470b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            snd_device = SND_DEVICE_IN_HEADSET_MIC;
1471b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
14729f3065480c81bf01d3af65bfd3da09e1fb74b520Ravi Kumar Alamanda            if (adev->bt_wb_speech_enabled) {
14739f3065480c81bf01d3af65bfd3da09e1fb74b520Ravi Kumar Alamanda                snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
14749f3065480c81bf01d3af65bfd3da09e1fb74b520Ravi Kumar Alamanda            } else {
14759f3065480c81bf01d3af65bfd3da09e1fb74b520Ravi Kumar Alamanda                snd_device = SND_DEVICE_IN_BT_SCO_MIC;
14769f3065480c81bf01d3af65bfd3da09e1fb74b520Ravi Kumar Alamanda            }
1477b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
1478b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            snd_device = SND_DEVICE_IN_HDMI_MIC;
1479b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        } else {
1480b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
1481b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            ALOGW("%s: Using default handset-mic", __func__);
1482b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            snd_device = SND_DEVICE_IN_HANDSET_MIC;
1483b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        }
1484b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    } else {
1485b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
1486b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            snd_device = SND_DEVICE_IN_HANDSET_MIC;
1487b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
1488b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            snd_device = SND_DEVICE_IN_HEADSET_MIC;
14893ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda        } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
14901b0d8ce4ec97a57b38a401dbd1e16ac5cf4c4671Eric Laurent                   out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
14913ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                   out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
149209f2e0e6bf8accf1728ca89e780702d53f2c5b6dEric Laurent                   out_device & AUDIO_DEVICE_OUT_LINE) {
14933ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda            if (channel_count == 2)
14943ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
14953ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda            else
14963ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                snd_device = SND_DEVICE_IN_SPEAKER_MIC;
1497b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
14989f3065480c81bf01d3af65bfd3da09e1fb74b520Ravi Kumar Alamanda            if (adev->bt_wb_speech_enabled) {
14999f3065480c81bf01d3af65bfd3da09e1fb74b520Ravi Kumar Alamanda                snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
15009f3065480c81bf01d3af65bfd3da09e1fb74b520Ravi Kumar Alamanda            } else {
15019f3065480c81bf01d3af65bfd3da09e1fb74b520Ravi Kumar Alamanda                snd_device = SND_DEVICE_IN_BT_SCO_MIC;
15029f3065480c81bf01d3af65bfd3da09e1fb74b520Ravi Kumar Alamanda            }
1503b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
1504b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            snd_device = SND_DEVICE_IN_HDMI_MIC;
1505b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        } else {
1506b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
1507b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            ALOGW("%s: Using default handset-mic", __func__);
1508b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            snd_device = SND_DEVICE_IN_HANDSET_MIC;
1509b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        }
1510b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    }
1511b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurentexit:
1512b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
1513b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    return snd_device;
1514b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent}
1515b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
1516b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurentint platform_set_hdmi_channels(void *platform,  int channel_count)
1517b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent{
1518b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    struct platform_data *my_data = (struct platform_data *)platform;
1519b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    struct audio_device *adev = my_data->adev;
1520b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    struct mixer_ctl *ctl;
1521b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    const char *channel_cnt_str = NULL;
1522b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    const char *mixer_ctl_name = "HDMI_RX Channels";
1523b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    switch (channel_count) {
1524b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    case 8:
1525b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        channel_cnt_str = "Eight"; break;
1526b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    case 7:
1527b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        channel_cnt_str = "Seven"; break;
1528b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    case 6:
1529b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        channel_cnt_str = "Six"; break;
1530b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    case 5:
1531b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        channel_cnt_str = "Five"; break;
1532b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    case 4:
1533b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        channel_cnt_str = "Four"; break;
1534b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    case 3:
1535b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        channel_cnt_str = "Three"; break;
1536b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    default:
1537b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        channel_cnt_str = "Two"; break;
1538b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    }
1539b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1540b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    if (!ctl) {
1541b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        ALOGE("%s: Could not get ctl for mixer cmd - %s",
1542b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent              __func__, mixer_ctl_name);
1543b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        return -EINVAL;
1544b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    }
1545b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    ALOGV("HDMI channel count: %s", channel_cnt_str);
1546b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
1547b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    return 0;
1548b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent}
1549b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
155047cd4cbdb19543338d5c887e3d7bcd2513c5c3adHaynes Mathew Georgeint platform_edid_get_max_channels(void *platform)
1551b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent{
155247cd4cbdb19543338d5c887e3d7bcd2513c5c3adHaynes Mathew George    struct platform_data *my_data = (struct platform_data *)platform;
155347cd4cbdb19543338d5c887e3d7bcd2513c5c3adHaynes Mathew George    struct audio_device *adev = my_data->adev;
1554b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
1555b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    char *sad = block;
1556b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    int num_audio_blocks;
1557b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    int channel_count;
1558b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    int max_channels = 0;
155947cd4cbdb19543338d5c887e3d7bcd2513c5c3adHaynes Mathew George    int i, ret, count;
1560b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
156147cd4cbdb19543338d5c887e3d7bcd2513c5c3adHaynes Mathew George    struct mixer_ctl *ctl;
156247cd4cbdb19543338d5c887e3d7bcd2513c5c3adHaynes Mathew George
156347cd4cbdb19543338d5c887e3d7bcd2513c5c3adHaynes Mathew George    ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
156447cd4cbdb19543338d5c887e3d7bcd2513c5c3adHaynes Mathew George    if (!ctl) {
156547cd4cbdb19543338d5c887e3d7bcd2513c5c3adHaynes Mathew George        ALOGE("%s: Could not get ctl for mixer cmd - %s",
156647cd4cbdb19543338d5c887e3d7bcd2513c5c3adHaynes Mathew George              __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
1567b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        return 0;
1568b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    }
1569b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
157047cd4cbdb19543338d5c887e3d7bcd2513c5c3adHaynes Mathew George    mixer_ctl_update(ctl);
157147cd4cbdb19543338d5c887e3d7bcd2513c5c3adHaynes Mathew George
157247cd4cbdb19543338d5c887e3d7bcd2513c5c3adHaynes Mathew George    count = mixer_ctl_get_num_values(ctl);
1573b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
1574b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    /* Read SAD blocks, clamping the maximum size for safety */
157547cd4cbdb19543338d5c887e3d7bcd2513c5c3adHaynes Mathew George    if (count > (int)sizeof(block))
157647cd4cbdb19543338d5c887e3d7bcd2513c5c3adHaynes Mathew George        count = (int)sizeof(block);
1577b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
157847cd4cbdb19543338d5c887e3d7bcd2513c5c3adHaynes Mathew George    ret = mixer_ctl_get_array(ctl, block, count);
157947cd4cbdb19543338d5c887e3d7bcd2513c5c3adHaynes Mathew George    if (ret != 0) {
158047cd4cbdb19543338d5c887e3d7bcd2513c5c3adHaynes Mathew George        ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
158147cd4cbdb19543338d5c887e3d7bcd2513c5c3adHaynes Mathew George        return 0;
158247cd4cbdb19543338d5c887e3d7bcd2513c5c3adHaynes Mathew George    }
1583b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
1584b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    /* Calculate the number of SAD blocks */
158547cd4cbdb19543338d5c887e3d7bcd2513c5c3adHaynes Mathew George    num_audio_blocks = count / SAD_BLOCK_SIZE;
1586b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
1587b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    for (i = 0; i < num_audio_blocks; i++) {
1588b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        /* Only consider LPCM blocks */
158947cd4cbdb19543338d5c887e3d7bcd2513c5c3adHaynes Mathew George        if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
159047cd4cbdb19543338d5c887e3d7bcd2513c5c3adHaynes Mathew George            sad += 3;
1591b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            continue;
159247cd4cbdb19543338d5c887e3d7bcd2513c5c3adHaynes Mathew George        }
1593b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
1594b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        channel_count = (sad[0] & 0x7) + 1;
1595b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        if (channel_count > max_channels)
1596b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            max_channels = channel_count;
1597b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
1598b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        /* Advance to next block */
1599b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        sad += 3;
1600b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    }
1601b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
1602b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    return max_channels;
1603b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent}
16047ff216f80f6e53235b4239c6fb7da9b0d5127738Haynes Mathew George
16054b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastavaint platform_set_incall_recording_session_id(void *platform,
16064b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava                                             uint32_t session_id, int rec_mode)
16074b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava{
16084b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    int ret = 0;
16094b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    struct platform_data *my_data = (struct platform_data *)platform;
16104b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    struct audio_device *adev = my_data->adev;
16114b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    struct mixer_ctl *ctl;
16124b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    const char *mixer_ctl_name = "Voc VSID";
16134b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    int num_ctl_values;
16144b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    int i;
16154b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava
16164b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
16174b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    if (!ctl) {
16184b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        ALOGE("%s: Could not get ctl for mixer cmd - %s",
16194b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava              __func__, mixer_ctl_name);
16204b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        ret = -EINVAL;
16214b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    } else {
16224b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        num_ctl_values = mixer_ctl_get_num_values(ctl);
16234b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        for (i = 0; i < num_ctl_values; i++) {
16244b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava            if (mixer_ctl_set_value(ctl, i, session_id)) {
16254b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava                ALOGV("Error: invalid session_id: %x", session_id);
16264b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava                ret = -EINVAL;
16274b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava                break;
16284b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava            }
16294b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        }
16304b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    }
16314b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava
16324b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    if (my_data->csd != NULL) {
16334b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
16344b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        if (ret < 0) {
16354b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava            ALOGE("%s: csd_client_start_record failed, error %d",
16364b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava                  __func__, ret);
16374b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        }
16384b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    }
16394b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava
16404b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    return ret;
16414b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava}
16424b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava
16434b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastavaint platform_stop_incall_recording_usecase(void *platform)
16444b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava{
16454b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    int ret = 0;
16464b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    struct platform_data *my_data = (struct platform_data *)platform;
16474b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava
16484b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    if (my_data->csd != NULL) {
16494b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        ret = my_data->csd->stop_record(ALL_SESSION_VSID);
16504b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        if (ret < 0) {
16514b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava            ALOGE("%s: csd_client_stop_record failed, error %d",
16524b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava                  __func__, ret);
16534b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        }
16544b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    }
16554b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava
16564b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    return ret;
16574b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava}
16584b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava
16594b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastavaint platform_start_incall_music_usecase(void *platform)
16604b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava{
16614b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    int ret = 0;
16624b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    struct platform_data *my_data = (struct platform_data *)platform;
16634b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava
16644b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    if (my_data->csd != NULL) {
16654b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        ret = my_data->csd->start_playback(ALL_SESSION_VSID);
16664b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        if (ret < 0) {
16674b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava            ALOGE("%s: csd_client_start_playback failed, error %d",
16684b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava                  __func__, ret);
16694b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        }
16704b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    }
16714b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava
16724b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    return ret;
16734b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava}
16744b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava
16754b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastavaint platform_stop_incall_music_usecase(void *platform)
16764b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava{
16774b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    int ret = 0;
16784b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    struct platform_data *my_data = (struct platform_data *)platform;
16794b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava
16804b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    if (my_data->csd != NULL) {
16814b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
16824b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        if (ret < 0) {
16834b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava            ALOGE("%s: csd_client_stop_playback failed, error %d",
16844b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava                  __func__, ret);
16854b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        }
16864b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    }
16874b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava
16884b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    return ret;
16894b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava}
16904b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava
16917ff216f80f6e53235b4239c6fb7da9b0d5127738Haynes Mathew George/* Delay in Us */
16927ff216f80f6e53235b4239c6fb7da9b0d5127738Haynes Mathew Georgeint64_t platform_render_latency(audio_usecase_t usecase)
16937ff216f80f6e53235b4239c6fb7da9b0d5127738Haynes Mathew George{
16947ff216f80f6e53235b4239c6fb7da9b0d5127738Haynes Mathew George    switch (usecase) {
16957ff216f80f6e53235b4239c6fb7da9b0d5127738Haynes Mathew George        case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
16967ff216f80f6e53235b4239c6fb7da9b0d5127738Haynes Mathew George            return DEEP_BUFFER_PLATFORM_DELAY;
16977ff216f80f6e53235b4239c6fb7da9b0d5127738Haynes Mathew George        case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
16987ff216f80f6e53235b4239c6fb7da9b0d5127738Haynes Mathew George            return LOW_LATENCY_PLATFORM_DELAY;
16997ff216f80f6e53235b4239c6fb7da9b0d5127738Haynes Mathew George        default:
17007ff216f80f6e53235b4239c6fb7da9b0d5127738Haynes Mathew George            return 0;
17017ff216f80f6e53235b4239c6fb7da9b0d5127738Haynes Mathew George    }
17027ff216f80f6e53235b4239c6fb7da9b0d5127738Haynes Mathew George}
170398c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George
170498c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew Georgeint platform_set_snd_device_backend(snd_device_t device, const char *backend)
170598c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George{
170698c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    int ret = 0;
170798c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George
170898c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
170998c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George        ALOGE("%s: Invalid snd_device = %d",
171098c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George            __func__, device);
171198c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George        ret = -EINVAL;
171298c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George        goto done;
171398c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    }
171498c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George
171598c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    if (backend_table[device]) {
171698c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George        free(backend_table[device]);
171798c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    }
171898c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    backend_table[device] = strdup(backend);
171998c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew Georgedone:
172098c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    return ret;
172198c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George}
172298c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George
172398c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew Georgeint platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t pcm_id)
172498c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George{
172598c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    int ret = 0;
172698c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    if ((usecase <= USECASE_INVALID) || (usecase >= AUDIO_USECASE_MAX)) {
172798c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George        ALOGE("%s: invalid usecase case idx %d", __func__, usecase);
172898c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George        ret = -EINVAL;
172998c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George        goto done;
173098c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    }
173198c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George
173298c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    if ((type != 0) && (type != 1)) {
173398c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George        ALOGE("%s: invalid usecase type", __func__);
173498c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George        ret = -EINVAL;
173598c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    }
173698c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    pcm_device_table[usecase][type] = pcm_id;
173798c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew Georgedone:
173898c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    return ret;
173998c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George}
1740