platform.c revision 50a38ed90672924763c4cb18773fca64588faecc
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#define LOG_TAG "msm8974_platform"
17b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent/*#define LOG_NDEBUG 0*/
18b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent#define LOG_NDDEBUG 0
19b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
20b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent#include <stdlib.h>
21b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent#include <dlfcn.h>
22b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent#include <cutils/log.h>
239f3065480c81bf01d3af65bfd3da09e1fb74b520Ravi Kumar Alamanda#include <cutils/str_parms.h>
24b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent#include <cutils/properties.h>
25b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent#include <audio_hw.h>
26b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent#include <platform_api.h>
27b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent#include "platform.h"
2863863001b659b66a367800c39f4a016ec5d544d7Ravi Kumar Alamanda#include "audio_extn.h"
291a9b7c0f180df7fe390f2839e8214667727aaa49vivek mehta#include <linux/msm_audio.h>
30b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
3147cd4cbdb19543338d5c887e3d7bcd2513c5c3adHaynes Mathew George#define MIXER_XML_PATH "/system/etc/mixer_paths.xml"
32b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent#define LIB_ACDB_LOADER "libacdbloader.so"
3347cd4cbdb19543338d5c887e3d7bcd2513c5c3adHaynes Mathew George#define AUDIO_DATA_BLOCK_MIXER_CTL "HDMI EDID"
345c049df87e3fad47fb1a6975e41c68eda9a8b594Ravi Kumar Alamanda#define CVD_VERSION_MIXER_CTL "CVD Version"
35b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
36b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
37b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent/*
38b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent * This file will have a maximum of 38 bytes:
39b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent *
40b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent * 4 bytes: number of audio blocks
41b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent * 4 bytes: total length of Short Audio Descriptor (SAD) blocks
42b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent * Maximum 10 * 3 bytes: SAD blocks
43b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent */
44b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent#define MAX_SAD_BLOCKS      10
45b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent#define SAD_BLOCK_SIZE      3
46b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
475c049df87e3fad47fb1a6975e41c68eda9a8b594Ravi Kumar Alamanda#define MAX_CVD_VERSION_STRING_SIZE    100
485c049df87e3fad47fb1a6975e41c68eda9a8b594Ravi Kumar Alamanda
49b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent/* EDID format ID for LPCM audio */
50b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent#define EDID_FORMAT_LPCM    1
51b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
521b9f4b3708d1ed1204bdb1dec370ad2e9db7a779sangwoo/* Retry for delay in FW loading*/
531b9f4b3708d1ed1204bdb1dec370ad2e9db7a779sangwoo#define RETRY_NUMBER 10
541b9f4b3708d1ed1204bdb1dec370ad2e9db7a779sangwoo#define RETRY_US 500000
554b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava#define MAX_SND_CARD 8
5653b2cf0c72aa18a5848919e2309731af652e84f9sangwoo
57c4f57314a49fb83ed602395d9fe0c0164c9e863dRavi Kumar Alamanda#define MAX_SND_CARD_NAME_LEN 31
58c4f57314a49fb83ed602395d9fe0c0164c9e863dRavi Kumar Alamanda
591a9b7c0f180df7fe390f2839e8214667727aaa49vivek mehta#define DEFAULT_APP_TYPE_RX_PATH  0x11130
601a9b7c0f180df7fe390f2839e8214667727aaa49vivek mehta
61c5aaa0e767b83fa8299861a739a4a1cb8e9bee0fkeunhui.park#define TOSTRING_(x) #x
62c5aaa0e767b83fa8299861a739a4a1cb8e9bee0fkeunhui.park#define TOSTRING(x) TOSTRING_(x)
63c5aaa0e767b83fa8299861a739a4a1cb8e9bee0fkeunhui.park
64b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurentstruct audio_block_header
65b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent{
66b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    int reserved;
67b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    int length;
68b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent};
69b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
701a9b7c0f180df7fe390f2839e8214667727aaa49vivek mehtaenum {
711a9b7c0f180df7fe390f2839e8214667727aaa49vivek mehta    CAL_MODE_SEND           = 0x1,
721a9b7c0f180df7fe390f2839e8214667727aaa49vivek mehta    CAL_MODE_PERSIST        = 0x2,
731a9b7c0f180df7fe390f2839e8214667727aaa49vivek mehta    CAL_MODE_RTAC           = 0x4
741a9b7c0f180df7fe390f2839e8214667727aaa49vivek mehta};
751a9b7c0f180df7fe390f2839e8214667727aaa49vivek mehta
762f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park#define PLATFORM_CONFIG_KEY_OPERATOR_INFO "operator_info"
772f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park
782f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.parkstruct operator_info {
792f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park    struct listnode list;
802f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park    char *name;
812f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park    char *mccmnc;
822f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park};
832f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park
842f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.parkstruct operator_specific_device {
852f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park    struct listnode list;
862f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park    char *operator;
872f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park    char *mixer_path;
882f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park    int acdb_id;
892f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park};
902f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park
912f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.parkstatic struct listnode operator_info_list;
922f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.parkstatic struct listnode *operator_specific_device_table[SND_DEVICE_MAX];
932f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park
9483281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda/* Audio calibration related functions */
95b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurenttypedef void (*acdb_deallocate_t)();
965c049df87e3fad47fb1a6975e41c68eda9a8b594Ravi Kumar Alamandatypedef int  (*acdb_init_v2_cvd_t)(char *, char *);
975c049df87e3fad47fb1a6975e41c68eda9a8b594Ravi Kumar Alamandatypedef int  (*acdb_init_v2_t)(char *);
98b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurenttypedef int  (*acdb_init_t)();
99b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurenttypedef void (*acdb_send_audio_cal_t)(int, int);
100b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurenttypedef void (*acdb_send_voice_cal_t)(int, int);
10183281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamandatypedef int (*acdb_reload_vocvoltable_t)(int);
1021a9b7c0f180df7fe390f2839e8214667727aaa49vivek mehtatypedef int (*acdb_send_gain_dep_cal_t)(int, int, int, int, int);
103b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
104b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent/* Audio calibration related functions */
105b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurentstruct platform_data {
106b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    struct audio_device *adev;
107b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    bool fluence_in_spkr_mode;
108b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    bool fluence_in_voice_call;
1093ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    bool fluence_in_voice_comm;
110b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    bool fluence_in_voice_rec;
111dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta    /* 0 = no fluence, 1 = fluence, 2 = fluence pro */
112dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta    int  fluence_type;
113dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta    int  source_mic_type;
1141f60cf8ce4276473878a22956ae546911353ebd2Ravi Kumar Alamanda    bool speaker_lr_swap;
1151f60cf8ce4276473878a22956ae546911353ebd2Ravi Kumar Alamanda
116b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    void *acdb_handle;
1173ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    acdb_deallocate_t          acdb_deallocate;
1183ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    acdb_send_audio_cal_t      acdb_send_audio_cal;
1193ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    acdb_send_voice_cal_t      acdb_send_voice_cal;
12083281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    acdb_reload_vocvoltable_t  acdb_reload_vocvoltable;
1211a9b7c0f180df7fe390f2839e8214667727aaa49vivek mehta    acdb_send_gain_dep_cal_t   acdb_send_gain_dep_cal;
12283281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    struct csd_data *csd;
123f28290178598c01d29f152a46483e5e8bd67b0e0Ravi Kumar Alamanda    char ec_ref_mixer_path[64];
124c4f57314a49fb83ed602395d9fe0c0164c9e863dRavi Kumar Alamanda
125c4f57314a49fb83ed602395d9fe0c0164c9e863dRavi Kumar Alamanda    char *snd_card_name;
126c5aaa0e767b83fa8299861a739a4a1cb8e9bee0fkeunhui.park    int max_vol_index;
127dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta    int max_mic_count;
128b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent};
129b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
13098c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew Georgestatic int pcm_device_table[AUDIO_USECASE_MAX][2] = {
13183281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = {DEEP_BUFFER_PCM_DEVICE,
13283281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                                            DEEP_BUFFER_PCM_DEVICE},
13383281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
13483281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                                            LOWLATENCY_PCM_DEVICE},
13583281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    [USECASE_AUDIO_PLAYBACK_MULTI_CH] = {MULTIMEDIA2_PCM_DEVICE,
13683281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                                         MULTIMEDIA2_PCM_DEVICE},
13783281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    [USECASE_AUDIO_PLAYBACK_OFFLOAD] = {PLAYBACK_OFFLOAD_DEVICE,
13883281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                                        PLAYBACK_OFFLOAD_DEVICE},
1392bc7b02259e0edf38432b258594da29571f29713Ravi Kumar Alamanda    [USECASE_AUDIO_PLAYBACK_TTS] = {MULTIMEDIA2_PCM_DEVICE,
1402bc7b02259e0edf38432b258594da29571f29713Ravi Kumar Alamanda                                        MULTIMEDIA2_PCM_DEVICE},
1412bc7b02259e0edf38432b258594da29571f29713Ravi Kumar Alamanda    [USECASE_AUDIO_PLAYBACK_ULL] = {MULTIMEDIA3_PCM_DEVICE,
1422bc7b02259e0edf38432b258594da29571f29713Ravi Kumar Alamanda                                    MULTIMEDIA3_PCM_DEVICE},
1432bc7b02259e0edf38432b258594da29571f29713Ravi Kumar Alamanda
14483281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    [USECASE_AUDIO_RECORD] = {AUDIO_RECORD_PCM_DEVICE,
14583281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                              AUDIO_RECORD_PCM_DEVICE},
14683281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    [USECASE_AUDIO_RECORD_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
14783281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                                          LOWLATENCY_PCM_DEVICE},
1482bc7b02259e0edf38432b258594da29571f29713Ravi Kumar Alamanda
14983281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    [USECASE_VOICE_CALL] = {VOICE_CALL_PCM_DEVICE,
15083281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                            VOICE_CALL_PCM_DEVICE},
1514b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    [USECASE_VOICE2_CALL] = {VOICE2_CALL_PCM_DEVICE, VOICE2_CALL_PCM_DEVICE},
1524b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    [USECASE_VOLTE_CALL] = {VOLTE_CALL_PCM_DEVICE, VOLTE_CALL_PCM_DEVICE},
1534b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    [USECASE_QCHAT_CALL] = {QCHAT_CALL_PCM_DEVICE, QCHAT_CALL_PCM_DEVICE},
1544b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    [USECASE_VOWLAN_CALL] = {VOWLAN_CALL_PCM_DEVICE, VOWLAN_CALL_PCM_DEVICE},
1554b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    [USECASE_INCALL_REC_UPLINK] = {AUDIO_RECORD_PCM_DEVICE,
1564b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava                                   AUDIO_RECORD_PCM_DEVICE},
1574b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    [USECASE_INCALL_REC_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
1584b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava                                     AUDIO_RECORD_PCM_DEVICE},
1594b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
1604b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava                                                AUDIO_RECORD_PCM_DEVICE},
1618e6e98fc5af6d6f79bc71eb37df470380ae82fadRavi Kumar Alamanda    [USECASE_AUDIO_HFP_SCO] = {HFP_PCM_RX, HFP_SCO_RX},
16299c752d87eb818fc3cfb2e5c6790b1ea0bc88da5Ravi Kumar Alamanda
16363863001b659b66a367800c39f4a016ec5d544d7Ravi Kumar Alamanda    [USECASE_AUDIO_SPKR_CALIB_RX] = {SPKR_PROT_CALIB_RX_PCM_DEVICE, -1},
16463863001b659b66a367800c39f4a016ec5d544d7Ravi Kumar Alamanda    [USECASE_AUDIO_SPKR_CALIB_TX] = {-1, SPKR_PROT_CALIB_TX_PCM_DEVICE},
16563863001b659b66a367800c39f4a016ec5d544d7Ravi Kumar Alamanda
16699c752d87eb818fc3cfb2e5c6790b1ea0bc88da5Ravi Kumar Alamanda    [USECASE_AUDIO_PLAYBACK_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
16799c752d87eb818fc3cfb2e5c6790b1ea0bc88da5Ravi Kumar Alamanda                                          AFE_PROXY_RECORD_PCM_DEVICE},
16899c752d87eb818fc3cfb2e5c6790b1ea0bc88da5Ravi Kumar Alamanda    [USECASE_AUDIO_RECORD_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
16999c752d87eb818fc3cfb2e5c6790b1ea0bc88da5Ravi Kumar Alamanda                                        AFE_PROXY_RECORD_PCM_DEVICE},
1704211fad32ff21574a3935dbe28397c55a1895649zhaoyang yin    [USECASE_AUDIO_DSM_FEEDBACK] = {QUAT_MI2S_PCM_DEVICE, QUAT_MI2S_PCM_DEVICE},
17199c752d87eb818fc3cfb2e5c6790b1ea0bc88da5Ravi Kumar Alamanda
172b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent};
173b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
174b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent/* Array to store sound devices */
175b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurentstatic const char * const device_table[SND_DEVICE_MAX] = {
176b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_NONE] = "none",
177b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    /* Playback sound devices */
178b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_OUT_HANDSET] = "handset",
179b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_OUT_SPEAKER] = "speaker",
180b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_OUT_SPEAKER_REVERSE] = "speaker-reverse",
1811b0d8ce4ec97a57b38a401dbd1e16ac5cf4c4671Eric Laurent    [SND_DEVICE_OUT_SPEAKER_SAFE] = "speaker-safe",
182b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_OUT_HEADPHONES] = "headphones",
18309f2e0e6bf8accf1728ca89e780702d53f2c5b6dEric Laurent    [SND_DEVICE_OUT_LINE] = "line",
184b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones",
1853b86d472a707dd29cd692909fc80cf45a8fec481Ravi Kumar Alamanda    [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = "speaker-safe-and-headphones",
186744996b561b92473cc8ba23275811eb1a6b44d5eEric Laurent    [SND_DEVICE_OUT_SPEAKER_AND_LINE] = "speaker-and-line",
1873b86d472a707dd29cd692909fc80cf45a8fec481Ravi Kumar Alamanda    [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = "speaker-safe-and-line",
188b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_OUT_VOICE_HANDSET] = "voice-handset",
1899d0d3f1537b5d157a2c31e0744303524b846446eEric Laurent    [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = "voice-hac-handset",
190b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker",
191b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones",
19209f2e0e6bf8accf1728ca89e780702d53f2c5b6dEric Laurent    [SND_DEVICE_OUT_VOICE_LINE] = "voice-line",
193b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_OUT_HDMI] = "hdmi",
194b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi",
195b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset",
1969f3065480c81bf01d3af65bfd3da09e1fb74b520Ravi Kumar Alamanda    [SND_DEVICE_OUT_BT_SCO_WB] = "bt-sco-headset-wb",
197b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = "voice-handset-tmus",
198b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones",
199b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones",
200b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset",
20199c752d87eb818fc3cfb2e5c6790b1ea0bc88da5Ravi Kumar Alamanda    [SND_DEVICE_OUT_VOICE_TX] = "voice-tx",
20263863001b659b66a367800c39f4a016ec5d544d7Ravi Kumar Alamanda    [SND_DEVICE_OUT_SPEAKER_PROTECTED] = "speaker-protected",
20363863001b659b66a367800c39f4a016ec5d544d7Ravi Kumar Alamanda    [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = "voice-speaker-protected",
204b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
205b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    /* Capture sound devices */
206b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
2073ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic",
2083ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_HANDSET_MIC_NS] = "handset-mic",
2093ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = "handset-mic",
2103ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_HANDSET_DMIC] = "dmic-endfire",
2113ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_HANDSET_DMIC_AEC] = "dmic-endfire",
2123ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_HANDSET_DMIC_NS] = "dmic-endfire",
2133ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = "dmic-endfire",
2143ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = "dmic-endfire",
2153ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda
216b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
2173ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "speaker-mic",
2183ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_SPEAKER_MIC_NS] = "speaker-mic",
2193ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = "speaker-mic",
2203ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_SPEAKER_DMIC] = "speaker-dmic-endfire",
2213ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = "speaker-dmic-endfire",
2223ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_SPEAKER_DMIC_NS] = "speaker-dmic-endfire",
2233ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = "speaker-dmic-endfire",
2243ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = "speaker-dmic-endfire",
2253ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda
226b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
227cefbbac40220d4e7690d204eecff5f6ae3f63069Eric Laurent    [SND_DEVICE_IN_HEADSET_MIC_AEC] = "headset-mic",
2283ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda
229b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic",
230b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
231e258e6871b27aa4b63b4b44fe2e318ded4d4e511Ravi Kumar Alamanda    [SND_DEVICE_IN_BT_SCO_MIC_NREC] = "bt-sco-mic",
2329f3065480c81bf01d3af65bfd3da09e1fb74b520Ravi Kumar Alamanda    [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb",
233e258e6871b27aa4b63b4b44fe2e318ded4d4e511Ravi Kumar Alamanda    [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = "bt-sco-mic-wb",
234b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic",
2353ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda
2363ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef",
2373ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_VOICE_DMIC_TMUS] = "voice-dmic-ef-tmus",
2383ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
2393ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = "voice-speaker-dmic-ef",
2403ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
241b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
242b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
243b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
2443ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda
245b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
2463ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_VOICE_REC_MIC_NS] = "voice-rec-mic",
2473ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = "voice-rec-dmic-ef",
2483ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence",
2498c83fe85b6d1257298208de043acece927787c3fJean-Michel Trivi    [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = "headset-mic",
25099c752d87eb818fc3cfb2e5c6790b1ea0bc88da5Ravi Kumar Alamanda
25199c752d87eb818fc3cfb2e5c6790b1ea0bc88da5Ravi Kumar Alamanda    [SND_DEVICE_IN_VOICE_RX] = "voice-rx",
25263863001b659b66a367800c39f4a016ec5d544d7Ravi Kumar Alamanda
253dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta    [SND_DEVICE_IN_THREE_MIC] = "three-mic",
254dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta    [SND_DEVICE_IN_QUAD_MIC] = "quad-mic",
25563863001b659b66a367800c39f4a016ec5d544d7Ravi Kumar Alamanda    [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = "vi-feedback",
256dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta    [SND_DEVICE_IN_HANDSET_TMIC] = "three-mic",
257dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta    [SND_DEVICE_IN_HANDSET_QMIC] = "quad-mic",
258b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent};
259b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
260b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
2615bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew Georgestatic int acdb_device_table[SND_DEVICE_MAX] = {
262b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_NONE] = -1,
263b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_OUT_HANDSET] = 7,
264b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_OUT_SPEAKER] = 15,
265b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_OUT_SPEAKER_REVERSE] = 15,
2661b0d8ce4ec97a57b38a401dbd1e16ac5cf4c4671Eric Laurent    [SND_DEVICE_OUT_SPEAKER_SAFE] = 15,
267b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_OUT_HEADPHONES] = 10,
268744996b561b92473cc8ba23275811eb1a6b44d5eEric Laurent    [SND_DEVICE_OUT_LINE] = 77,
269b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
2703b86d472a707dd29cd692909fc80cf45a8fec481Ravi Kumar Alamanda    [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = 10,
271744996b561b92473cc8ba23275811eb1a6b44d5eEric Laurent    [SND_DEVICE_OUT_SPEAKER_AND_LINE] = 77,
2723b86d472a707dd29cd692909fc80cf45a8fec481Ravi Kumar Alamanda    [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = 77,
273235c34827f7b3b8977fe76dea1fb8d818fd74312Ravi Kumar Alamanda    [SND_DEVICE_OUT_VOICE_HANDSET] = ACDB_ID_VOICE_HANDSET,
274235c34827f7b3b8977fe76dea1fb8d818fd74312Ravi Kumar Alamanda    [SND_DEVICE_OUT_VOICE_SPEAKER] = ACDB_ID_VOICE_SPEAKER,
2759d0d3f1537b5d157a2c31e0744303524b846446eEric Laurent    [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = 53,
276b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
277744996b561b92473cc8ba23275811eb1a6b44d5eEric Laurent    [SND_DEVICE_OUT_VOICE_LINE] = 77,
278b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_OUT_HDMI] = 18,
279b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 15,
280b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_OUT_BT_SCO] = 22,
2819f3065480c81bf01d3af65bfd3da09e1fb74b520Ravi Kumar Alamanda    [SND_DEVICE_OUT_BT_SCO_WB] = 39,
28283281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = ACDB_ID_VOICE_HANDSET_TMUS,
283b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
284b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
285b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
28699c752d87eb818fc3cfb2e5c6790b1ea0bc88da5Ravi Kumar Alamanda    [SND_DEVICE_OUT_VOICE_TX] = 45,
28763863001b659b66a367800c39f4a016ec5d544d7Ravi Kumar Alamanda    [SND_DEVICE_OUT_SPEAKER_PROTECTED] = 124,
28863863001b659b66a367800c39f4a016ec5d544d7Ravi Kumar Alamanda    [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = 101,
289b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
290b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_IN_HANDSET_MIC] = 4,
2913ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_HANDSET_MIC_AEC] = 106,
2923ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_HANDSET_MIC_NS] = 107,
2933ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = 108,
2943ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_HANDSET_DMIC] = 41,
2953ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_HANDSET_DMIC_AEC] = 109,
2963ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_HANDSET_DMIC_NS] = 110,
2973ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = 111,
2983ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = 34,
2993ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda
3003ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_SPEAKER_MIC] = 11,
3013ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 112,
3023ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_SPEAKER_MIC_NS] = 113,
3033ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = 114,
3043ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_SPEAKER_DMIC] = 43,
3053ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = 115,
3063ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_SPEAKER_DMIC_NS] = 116,
3073ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = 117,
3083ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = 35,
3093ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda
310b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_IN_HEADSET_MIC] = 8,
311cefbbac40220d4e7690d204eecff5f6ae3f63069Eric Laurent    [SND_DEVICE_IN_HEADSET_MIC_AEC] = ACDB_ID_HEADSET_MIC_AEC,
3123ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda
313b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_IN_HDMI_MIC] = 4,
314b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_IN_BT_SCO_MIC] = 21,
315e258e6871b27aa4b63b4b44fe2e318ded4d4e511Ravi Kumar Alamanda    [SND_DEVICE_IN_BT_SCO_MIC_NREC] = 21,
3169f3065480c81bf01d3af65bfd3da09e1fb74b520Ravi Kumar Alamanda    [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38,
317e258e6871b27aa4b63b4b44fe2e318ded4d4e511Ravi Kumar Alamanda    [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = 38,
318b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_IN_CAMCORDER_MIC] = 61,
3193ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda
3203ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_VOICE_DMIC] = 41,
3213ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_VOICE_DMIC_TMUS] = ACDB_ID_VOICE_DMIC_EF_TMUS,
3223ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
3233ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 43,
3243ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_VOICE_HEADSET_MIC] = 8,
325b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
326b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
327b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
3283ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda
329b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    [SND_DEVICE_IN_VOICE_REC_MIC] = 62,
3303ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_VOICE_REC_MIC_NS] = 113,
3313ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = 35,
3323ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 43,
3338c83fe85b6d1257298208de043acece927787c3fJean-Michel Trivi    [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = 8,
33499c752d87eb818fc3cfb2e5c6790b1ea0bc88da5Ravi Kumar Alamanda
33599c752d87eb818fc3cfb2e5c6790b1ea0bc88da5Ravi Kumar Alamanda    [SND_DEVICE_IN_VOICE_RX] = 44,
33663863001b659b66a367800c39f4a016ec5d544d7Ravi Kumar Alamanda
337dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta    [SND_DEVICE_IN_THREE_MIC] = 46,
338dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta    [SND_DEVICE_IN_QUAD_MIC] = 46,
33963863001b659b66a367800c39f4a016ec5d544d7Ravi Kumar Alamanda    [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = 102,
340dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta    [SND_DEVICE_IN_HANDSET_TMIC] = 125,
341dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta    [SND_DEVICE_IN_HANDSET_QMIC] = 125,
342b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent};
343b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
34498c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew Georgestruct name_to_index {
3455bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George    char name[100];
3465bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George    unsigned int index;
3475bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George};
3485bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George
3495bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George#define TO_NAME_INDEX(X)   #X, X
3505bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George
35198c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George/* Used to get index from parsed string */
35298c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew Georgestatic const struct name_to_index snd_device_name_index[SND_DEVICE_MAX] = {
35398c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    /* out */
3545bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George    {TO_NAME_INDEX(SND_DEVICE_OUT_HANDSET)},
3555bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George    {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER)},
3565bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George    {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_REVERSE)},
3571b0d8ce4ec97a57b38a401dbd1e16ac5cf4c4671Eric Laurent    {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE)},
3585bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George    {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES)},
35909f2e0e6bf8accf1728ca89e780702d53f2c5b6dEric Laurent    {TO_NAME_INDEX(SND_DEVICE_OUT_LINE)},
3605bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George    {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES)},
3613b86d472a707dd29cd692909fc80cf45a8fec481Ravi Kumar Alamanda    {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES)},
362744996b561b92473cc8ba23275811eb1a6b44d5eEric Laurent    {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_LINE)},
3633b86d472a707dd29cd692909fc80cf45a8fec481Ravi Kumar Alamanda    {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE)},
3645bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George    {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET)},
3655bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George    {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER)},
3665bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George    {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADPHONES)},
36709f2e0e6bf8accf1728ca89e780702d53f2c5b6dEric Laurent    {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_LINE)},
3685bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George    {TO_NAME_INDEX(SND_DEVICE_OUT_HDMI)},
3695bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George    {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HDMI)},
3705bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George    {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO)},
3715bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George    {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO_WB)},
37298c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET_TMUS)},
3739d0d3f1537b5d157a2c31e0744303524b846446eEric Laurent    {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HAC_HANDSET)},
3745bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George    {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES)},
3755bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George    {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES)},
3765bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George    {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET)},
37798c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George
37898c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    /* in */
37963863001b659b66a367800c39f4a016ec5d544d7Ravi Kumar Alamanda    {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED)},
38063863001b659b66a367800c39f4a016ec5d544d7Ravi Kumar Alamanda    {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED)},
3815bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George    {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC)},
38298c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC)},
3833ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_NS)},
3843ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)},
3853ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC)},
3863ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC)},
3873ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_NS)},
3883ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)},
3893ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_STEREO)},
3903ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda
3913ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC)},
39298c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC)},
3933ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_NS)},
3943ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)},
3953ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC)},
3963ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC)},
3973ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS)},
3983ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)},
3993ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_STEREO)},
4003ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda
4013ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC)},
402b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda    {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC_AEC)},
4033ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda
4045bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George    {TO_NAME_INDEX(SND_DEVICE_IN_HDMI_MIC)},
4055bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George    {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC)},
406e258e6871b27aa4b63b4b44fe2e318ded4d4e511Ravi Kumar Alamanda    {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_NREC)},
4075bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George    {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB)},
408e258e6871b27aa4b63b4b44fe2e318ded4d4e511Ravi Kumar Alamanda    {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB_NREC)},
4095bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George    {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_MIC)},
4103ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda
4113ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC)},
4123ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC_TMUS)},
4133ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC)},
4143ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC)},
4153ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEADSET_MIC)},
4165bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George    {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC)},
4175bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George    {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC)},
4185bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George    {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC)},
4193ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda
4205bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George    {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC)},
4213ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_NS)},
4223ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_STEREO)},
4233ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE)},
4248c83fe85b6d1257298208de043acece927787c3fJean-Michel Trivi    {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_HEADSET_MIC)},
42563863001b659b66a367800c39f4a016ec5d544d7Ravi Kumar Alamanda
426dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta    {TO_NAME_INDEX(SND_DEVICE_IN_THREE_MIC)},
427dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta    {TO_NAME_INDEX(SND_DEVICE_IN_QUAD_MIC)},
42863863001b659b66a367800c39f4a016ec5d544d7Ravi Kumar Alamanda    {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_VI_FEEDBACK)},
429dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta    {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC)},
430dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta    {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC)},
43198c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George};
43298c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George
433b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamandastatic char * backend_tag_table[SND_DEVICE_MAX] = {0};
434b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamandastatic char * hw_interface_table[SND_DEVICE_MAX] = {0};
43598c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George
43698c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew Georgestatic const struct name_to_index usecase_name_index[AUDIO_USECASE_MAX] = {
43798c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_DEEP_BUFFER)},
43898c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_LOW_LATENCY)},
43998c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_MULTI_CH)},
44098c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD)},
4412bc7b02259e0edf38432b258594da29571f29713Ravi Kumar Alamanda    {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_TTS)},
4422bc7b02259e0edf38432b258594da29571f29713Ravi Kumar Alamanda    {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_ULL)},
44398c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    {TO_NAME_INDEX(USECASE_AUDIO_RECORD)},
44498c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    {TO_NAME_INDEX(USECASE_AUDIO_RECORD_LOW_LATENCY)},
44598c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    {TO_NAME_INDEX(USECASE_VOICE_CALL)},
44698c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    {TO_NAME_INDEX(USECASE_VOICE2_CALL)},
44798c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    {TO_NAME_INDEX(USECASE_VOLTE_CALL)},
44898c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    {TO_NAME_INDEX(USECASE_QCHAT_CALL)},
44998c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    {TO_NAME_INDEX(USECASE_VOWLAN_CALL)},
45098c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK)},
45198c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    {TO_NAME_INDEX(USECASE_INCALL_REC_DOWNLINK)},
45298c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK_AND_DOWNLINK)},
45398c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    {TO_NAME_INDEX(USECASE_AUDIO_HFP_SCO)},
4545bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George};
4555bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George
4567ff216f80f6e53235b4239c6fb7da9b0d5127738Haynes Mathew George#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
4577ff216f80f6e53235b4239c6fb7da9b0d5127738Haynes Mathew George#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
4587ff216f80f6e53235b4239c6fb7da9b0d5127738Haynes Mathew George
459b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurentstatic pthread_once_t check_op_once_ctl = PTHREAD_ONCE_INIT;
460b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurentstatic bool is_tmus = false;
461b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
462b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurentstatic void check_operator()
463b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent{
464b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    char value[PROPERTY_VALUE_MAX];
465b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    int mccmnc;
466b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    property_get("gsm.sim.operator.numeric",value,"0");
467b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    mccmnc = atoi(value);
468b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    ALOGD("%s: tmus mccmnc %d", __func__, mccmnc);
469b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    switch(mccmnc) {
470b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    /* TMUS MCC(310), MNC(490, 260, 026) */
471b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    case 310490:
472b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    case 310260:
473b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    case 310026:
474b891db5473ab23a0cbc52d566a97c3d3529f8dddsangwon.jeon    /* Add new TMUS MNC(800, 660, 580, 310, 270, 250, 240, 230, 220, 210, 200, 160) */
475b891db5473ab23a0cbc52d566a97c3d3529f8dddsangwon.jeon    case 310800:
476b891db5473ab23a0cbc52d566a97c3d3529f8dddsangwon.jeon    case 310660:
477b891db5473ab23a0cbc52d566a97c3d3529f8dddsangwon.jeon    case 310580:
478b891db5473ab23a0cbc52d566a97c3d3529f8dddsangwon.jeon    case 310310:
479b891db5473ab23a0cbc52d566a97c3d3529f8dddsangwon.jeon    case 310270:
480b891db5473ab23a0cbc52d566a97c3d3529f8dddsangwon.jeon    case 310250:
481b891db5473ab23a0cbc52d566a97c3d3529f8dddsangwon.jeon    case 310240:
482b891db5473ab23a0cbc52d566a97c3d3529f8dddsangwon.jeon    case 310230:
483b891db5473ab23a0cbc52d566a97c3d3529f8dddsangwon.jeon    case 310220:
484b891db5473ab23a0cbc52d566a97c3d3529f8dddsangwon.jeon    case 310210:
485b891db5473ab23a0cbc52d566a97c3d3529f8dddsangwon.jeon    case 310200:
486b891db5473ab23a0cbc52d566a97c3d3529f8dddsangwon.jeon    case 310160:
487b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        is_tmus = true;
488b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        break;
489b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    }
490b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent}
491b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
492b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurentbool is_operator_tmus()
493b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent{
494b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    pthread_once(&check_op_once_ctl, check_operator);
495b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    return is_tmus;
496b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent}
497b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
4982f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.parkstatic char *get_current_operator()
4992f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park{
5002f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park    struct listnode *node;
5012f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park    struct operator_info *info_item;
5022f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park    char mccmnc[PROPERTY_VALUE_MAX];
5032f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park    char *ret = NULL;
5042f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park
5052f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park    property_get("gsm.sim.operator.numeric",mccmnc,"0");
5062f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park
5072f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park    list_for_each(node, &operator_info_list) {
5082f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park        info_item = node_to_item(node, struct operator_info, list);
5092f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park        if (strstr(info_item->mccmnc, mccmnc) != NULL) {
5102f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park            ret = info_item->name;
5112f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park        }
5122f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park    }
5132f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park
5142f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park    return ret;
5152f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park}
5162f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park
5172f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.parkstatic struct operator_specific_device *get_operator_specific_device(snd_device_t snd_device)
5182f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park{
5192f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park    struct listnode *node;
5202f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park    struct operator_specific_device *ret = NULL;
5212f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park    struct operator_specific_device *device_item;
5222f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park    char *operator_name;
5232f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park
5242f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park    operator_name = get_current_operator();
5252f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park    if (operator_name == NULL)
5262f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park        return ret;
5272f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park
5282f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park    list_for_each(node, operator_specific_device_table[snd_device]) {
5292f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park        device_item = node_to_item(node, struct operator_specific_device, list);
5302f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park        if (strcmp(operator_name, device_item->operator) == 0) {
5312f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park            ret = device_item;
5322f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park        }
5332f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park    }
5342f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park
5352f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park    return ret;
5362f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park}
5372f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park
5382f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park
5392f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.parkstatic int get_operator_specific_device_acdb_id(snd_device_t snd_device)
5402f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park{
5412f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park    struct operator_specific_device *device;
5422f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park    int ret = acdb_device_table[snd_device];
5432f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park
5442f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park    device = get_operator_specific_device(snd_device);
5452f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park    if (device != NULL)
5462f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park        ret = device->acdb_id;
5472f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park
5482f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park    return ret;
5492f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park}
5502f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park
5512f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.parkstatic const char *get_operator_specific_device_mixer_path(snd_device_t snd_device)
5522f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park{
5532f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park    struct operator_specific_device *device;
5542f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park    const char *ret = device_table[snd_device];
5552f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park
5562f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park    device = get_operator_specific_device(snd_device);
5572f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park    if (device != NULL)
5582f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park        ret = device->mixer_path;
5592f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park
5602f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park    return ret;
5612f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park}
5622f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park
5631a9b7c0f180df7fe390f2839e8214667727aaa49vivek mehtabool platform_send_gain_dep_cal(void *platform, int level)
5641a9b7c0f180df7fe390f2839e8214667727aaa49vivek mehta{
5651a9b7c0f180df7fe390f2839e8214667727aaa49vivek mehta    bool ret_val = false;
5661a9b7c0f180df7fe390f2839e8214667727aaa49vivek mehta    struct platform_data *my_data = (struct platform_data *)platform;
5671a9b7c0f180df7fe390f2839e8214667727aaa49vivek mehta    struct audio_device *adev = my_data->adev;
5681a9b7c0f180df7fe390f2839e8214667727aaa49vivek mehta    int acdb_dev_id, app_type;
5691a9b7c0f180df7fe390f2839e8214667727aaa49vivek mehta    int acdb_dev_type = MSM_SNDDEV_CAP_RX;
5701a9b7c0f180df7fe390f2839e8214667727aaa49vivek mehta    int mode = CAL_MODE_RTAC;
5711a9b7c0f180df7fe390f2839e8214667727aaa49vivek mehta    struct listnode *node;
5721a9b7c0f180df7fe390f2839e8214667727aaa49vivek mehta    struct audio_usecase *usecase;
5731a9b7c0f180df7fe390f2839e8214667727aaa49vivek mehta
5741a9b7c0f180df7fe390f2839e8214667727aaa49vivek mehta    if (my_data->acdb_send_gain_dep_cal == NULL) {
5751a9b7c0f180df7fe390f2839e8214667727aaa49vivek mehta        ALOGE("%s: dlsym error for acdb_send_gain_dep_cal", __func__);
5761a9b7c0f180df7fe390f2839e8214667727aaa49vivek mehta        return ret_val;
5771a9b7c0f180df7fe390f2839e8214667727aaa49vivek mehta    }
5781a9b7c0f180df7fe390f2839e8214667727aaa49vivek mehta
5791a9b7c0f180df7fe390f2839e8214667727aaa49vivek mehta    if (!voice_is_in_call(adev)) {
5801a9b7c0f180df7fe390f2839e8214667727aaa49vivek mehta        ALOGV("%s: Not Voice call usecase, apply new cal for level %d",
5811a9b7c0f180df7fe390f2839e8214667727aaa49vivek mehta               __func__, level);
5821a9b7c0f180df7fe390f2839e8214667727aaa49vivek mehta        app_type = DEFAULT_APP_TYPE_RX_PATH;
5831a9b7c0f180df7fe390f2839e8214667727aaa49vivek mehta
5841a9b7c0f180df7fe390f2839e8214667727aaa49vivek mehta        // find the current active sound device
5851a9b7c0f180df7fe390f2839e8214667727aaa49vivek mehta        list_for_each(node, &adev->usecase_list) {
5861a9b7c0f180df7fe390f2839e8214667727aaa49vivek mehta            usecase = node_to_item(node, struct audio_usecase, list);
5871a9b7c0f180df7fe390f2839e8214667727aaa49vivek mehta
5881a9b7c0f180df7fe390f2839e8214667727aaa49vivek mehta            if (usecase != NULL &&
5891a9b7c0f180df7fe390f2839e8214667727aaa49vivek mehta                usecase->type == PCM_PLAYBACK &&
5901a9b7c0f180df7fe390f2839e8214667727aaa49vivek mehta                (usecase->stream.out->devices == AUDIO_DEVICE_OUT_SPEAKER)) {
5911a9b7c0f180df7fe390f2839e8214667727aaa49vivek mehta
5921a9b7c0f180df7fe390f2839e8214667727aaa49vivek mehta                ALOGV("%s: out device is %d", __func__,  usecase->out_snd_device);
5934cb8298a322ef5be6f8db002e50c764fdecc2c55vivek mehta                if (audio_extn_spkr_prot_is_enabled()) {
5944cb8298a322ef5be6f8db002e50c764fdecc2c55vivek mehta                    acdb_dev_id = audio_extn_spkr_prot_get_acdb_id(usecase->out_snd_device);
5954cb8298a322ef5be6f8db002e50c764fdecc2c55vivek mehta                } else {
5964cb8298a322ef5be6f8db002e50c764fdecc2c55vivek mehta                    acdb_dev_id = acdb_device_table[usecase->out_snd_device];
5974cb8298a322ef5be6f8db002e50c764fdecc2c55vivek mehta                }
5984cb8298a322ef5be6f8db002e50c764fdecc2c55vivek mehta
5991a9b7c0f180df7fe390f2839e8214667727aaa49vivek mehta                if (!my_data->acdb_send_gain_dep_cal(acdb_dev_id, app_type,
6001a9b7c0f180df7fe390f2839e8214667727aaa49vivek mehta                                                     acdb_dev_type, mode, level)) {
6011a9b7c0f180df7fe390f2839e8214667727aaa49vivek mehta                    // set ret_val true if at least one calibration is set successfully
6021a9b7c0f180df7fe390f2839e8214667727aaa49vivek mehta                    ret_val = true;
6031a9b7c0f180df7fe390f2839e8214667727aaa49vivek mehta                } else {
6041a9b7c0f180df7fe390f2839e8214667727aaa49vivek mehta                    ALOGE("%s: my_data->acdb_send_gain_dep_cal failed ", __func__);
6051a9b7c0f180df7fe390f2839e8214667727aaa49vivek mehta                }
6061a9b7c0f180df7fe390f2839e8214667727aaa49vivek mehta            } else {
6071a9b7c0f180df7fe390f2839e8214667727aaa49vivek mehta                ALOGW("%s: Usecase list is empty", __func__);
6081a9b7c0f180df7fe390f2839e8214667727aaa49vivek mehta            }
6091a9b7c0f180df7fe390f2839e8214667727aaa49vivek mehta        }
6101a9b7c0f180df7fe390f2839e8214667727aaa49vivek mehta    } else {
6111a9b7c0f180df7fe390f2839e8214667727aaa49vivek mehta        ALOGW("%s: Voice call in progress .. ignore setting new cal",
6121a9b7c0f180df7fe390f2839e8214667727aaa49vivek mehta              __func__);
6131a9b7c0f180df7fe390f2839e8214667727aaa49vivek mehta    }
6141a9b7c0f180df7fe390f2839e8214667727aaa49vivek mehta    return ret_val;
6151a9b7c0f180df7fe390f2839e8214667727aaa49vivek mehta}
6161a9b7c0f180df7fe390f2839e8214667727aaa49vivek mehta
617cefbbac40220d4e7690d204eecff5f6ae3f63069Eric Laurentvoid platform_set_echo_reference(struct audio_device *adev, bool enable, audio_devices_t out_device)
618b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent{
619f28290178598c01d29f152a46483e5e8bd67b0e0Ravi Kumar Alamanda    struct platform_data *my_data = (struct platform_data *)adev->platform;
620cefbbac40220d4e7690d204eecff5f6ae3f63069Eric Laurent    snd_device_t snd_device = SND_DEVICE_NONE;
621cefbbac40220d4e7690d204eecff5f6ae3f63069Eric Laurent
622f28290178598c01d29f152a46483e5e8bd67b0e0Ravi Kumar Alamanda    if (strcmp(my_data->ec_ref_mixer_path, "")) {
623f28290178598c01d29f152a46483e5e8bd67b0e0Ravi Kumar Alamanda        ALOGV("%s: diabling %s", __func__, my_data->ec_ref_mixer_path);
624f28290178598c01d29f152a46483e5e8bd67b0e0Ravi Kumar Alamanda        audio_route_reset_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
625cefbbac40220d4e7690d204eecff5f6ae3f63069Eric Laurent    }
626cefbbac40220d4e7690d204eecff5f6ae3f63069Eric Laurent
627f28290178598c01d29f152a46483e5e8bd67b0e0Ravi Kumar Alamanda    if (enable) {
628f28290178598c01d29f152a46483e5e8bd67b0e0Ravi Kumar Alamanda        strcpy(my_data->ec_ref_mixer_path, "echo-reference");
629f28290178598c01d29f152a46483e5e8bd67b0e0Ravi Kumar Alamanda        if (out_device != AUDIO_DEVICE_NONE) {
630f28290178598c01d29f152a46483e5e8bd67b0e0Ravi Kumar Alamanda            snd_device = platform_get_output_snd_device(adev->platform, out_device);
631f28290178598c01d29f152a46483e5e8bd67b0e0Ravi Kumar Alamanda            platform_add_backend_name(adev->platform, my_data->ec_ref_mixer_path, snd_device);
632f28290178598c01d29f152a46483e5e8bd67b0e0Ravi Kumar Alamanda        }
633b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
634f28290178598c01d29f152a46483e5e8bd67b0e0Ravi Kumar Alamanda        ALOGD("%s: enabling %s", __func__, my_data->ec_ref_mixer_path);
635f28290178598c01d29f152a46483e5e8bd67b0e0Ravi Kumar Alamanda        audio_route_apply_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
636f28290178598c01d29f152a46483e5e8bd67b0e0Ravi Kumar Alamanda    }
637b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent}
638b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
63983281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamandastatic struct csd_data *open_csd_client(bool i2s_ext_modem)
64083281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda{
64183281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    struct csd_data *csd = calloc(1, sizeof(struct csd_data));
64283281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda
64383281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    csd->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
64483281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    if (csd->csd_client == NULL) {
64583281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
64683281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        goto error;
64783281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    } else {
64883281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
64983281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda
65083281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        csd->deinit = (deinit_t)dlsym(csd->csd_client,
65183281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                                             "csd_client_deinit");
65283281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        if (csd->deinit == NULL) {
65383281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            ALOGE("%s: dlsym error %s for csd_client_deinit", __func__,
65483281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                  dlerror());
65583281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            goto error;
65683281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        }
65783281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        csd->disable_device = (disable_device_t)dlsym(csd->csd_client,
65883281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                                             "csd_client_disable_device");
65983281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        if (csd->disable_device == NULL) {
66083281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            ALOGE("%s: dlsym error %s for csd_client_disable_device",
66183281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                  __func__, dlerror());
66283281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            goto error;
66383281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        }
66483281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        csd->enable_device_config = (enable_device_config_t)dlsym(csd->csd_client,
66583281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                                               "csd_client_enable_device_config");
66683281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        if (csd->enable_device_config == NULL) {
66783281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            ALOGE("%s: dlsym error %s for csd_client_enable_device_config",
66883281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                  __func__, dlerror());
66983281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            goto error;
67083281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        }
67183281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        csd->enable_device = (enable_device_t)dlsym(csd->csd_client,
67283281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                                             "csd_client_enable_device");
67383281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        if (csd->enable_device == NULL) {
67483281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            ALOGE("%s: dlsym error %s for csd_client_enable_device",
67583281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                  __func__, dlerror());
67683281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            goto error;
67783281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        }
67883281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        csd->start_voice = (start_voice_t)dlsym(csd->csd_client,
67983281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                                             "csd_client_start_voice");
68083281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        if (csd->start_voice == NULL) {
68183281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            ALOGE("%s: dlsym error %s for csd_client_start_voice",
68283281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                  __func__, dlerror());
68383281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            goto error;
68483281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        }
68583281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        csd->stop_voice = (stop_voice_t)dlsym(csd->csd_client,
68683281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                                             "csd_client_stop_voice");
68783281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        if (csd->stop_voice == NULL) {
68883281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            ALOGE("%s: dlsym error %s for csd_client_stop_voice",
68983281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                  __func__, dlerror());
69083281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            goto error;
69183281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        }
69283281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        csd->volume = (volume_t)dlsym(csd->csd_client,
69383281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                                             "csd_client_volume");
69483281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        if (csd->volume == NULL) {
69583281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            ALOGE("%s: dlsym error %s for csd_client_volume",
69683281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                  __func__, dlerror());
69783281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            goto error;
69883281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        }
69983281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        csd->mic_mute = (mic_mute_t)dlsym(csd->csd_client,
70083281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                                             "csd_client_mic_mute");
70183281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        if (csd->mic_mute == NULL) {
70283281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            ALOGE("%s: dlsym error %s for csd_client_mic_mute",
70383281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                  __func__, dlerror());
70483281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            goto error;
70583281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        }
70683281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        csd->slow_talk = (slow_talk_t)dlsym(csd->csd_client,
70783281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                                             "csd_client_slow_talk");
70883281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        if (csd->slow_talk == NULL) {
70983281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            ALOGE("%s: dlsym error %s for csd_client_slow_talk",
71083281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                  __func__, dlerror());
71183281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            goto error;
71283281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        }
71383281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        csd->start_playback = (start_playback_t)dlsym(csd->csd_client,
71483281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                                             "csd_client_start_playback");
71583281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        if (csd->start_playback == NULL) {
71683281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            ALOGE("%s: dlsym error %s for csd_client_start_playback",
71783281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                  __func__, dlerror());
71883281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            goto error;
71983281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        }
72083281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        csd->stop_playback = (stop_playback_t)dlsym(csd->csd_client,
72183281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                                             "csd_client_stop_playback");
72283281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        if (csd->stop_playback == NULL) {
72383281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            ALOGE("%s: dlsym error %s for csd_client_stop_playback",
72483281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                  __func__, dlerror());
72583281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            goto error;
72683281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        }
72783281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        csd->start_record = (start_record_t)dlsym(csd->csd_client,
72883281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                                             "csd_client_start_record");
72983281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        if (csd->start_record == NULL) {
73083281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            ALOGE("%s: dlsym error %s for csd_client_start_record",
73183281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                  __func__, dlerror());
73283281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            goto error;
73383281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        }
73483281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        csd->stop_record = (stop_record_t)dlsym(csd->csd_client,
73583281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                                             "csd_client_stop_record");
73683281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        if (csd->stop_record == NULL) {
73783281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            ALOGE("%s: dlsym error %s for csd_client_stop_record",
73883281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                  __func__, dlerror());
73983281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            goto error;
74083281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        }
74183281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda
74283281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        csd->get_sample_rate = (get_sample_rate_t)dlsym(csd->csd_client,
74383281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                                             "csd_client_get_sample_rate");
74483281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        if (csd->get_sample_rate == NULL) {
74583281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            ALOGE("%s: dlsym error %s for csd_client_get_sample_rate",
74683281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                  __func__, dlerror());
74783281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda
74883281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            goto error;
74983281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        }
75083281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda
75183281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        csd->init = (init_t)dlsym(csd->csd_client, "csd_client_init");
75283281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda
75383281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        if (csd->init == NULL) {
75483281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            ALOGE("%s: dlsym error %s for csd_client_init",
75583281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                  __func__, dlerror());
75683281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            goto error;
75783281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        } else {
75883281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            csd->init(i2s_ext_modem);
75983281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        }
76083281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    }
76183281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    return csd;
76283281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda
76383281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamandaerror:
76483281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    free(csd);
76583281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    csd = NULL;
76683281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    return csd;
76783281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda}
76883281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda
76983281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamandavoid close_csd_client(struct csd_data *csd)
77083281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda{
77183281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    if (csd != NULL) {
77283281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        csd->deinit();
77383281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        dlclose(csd->csd_client);
77483281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        free(csd);
77583281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        csd = NULL;
77683281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    }
77783281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda}
77883281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda
77983281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamandastatic void platform_csd_init(struct platform_data *my_data)
78083281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda{
78183281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda#ifdef PLATFORM_MSM8084
782ae9a10c15cf960e9b2b1159ade6414f80689db5fIliyan Malchev    int32_t modems, (*count_modems)(void);
783ae9a10c15cf960e9b2b1159ade6414f80689db5fIliyan Malchev    const char *name = "libdetectmodem.so";
784ae9a10c15cf960e9b2b1159ade6414f80689db5fIliyan Malchev    const char *func = "count_modems";
785ae9a10c15cf960e9b2b1159ade6414f80689db5fIliyan Malchev    const char *error;
786ae9a10c15cf960e9b2b1159ade6414f80689db5fIliyan Malchev
787ae9a10c15cf960e9b2b1159ade6414f80689db5fIliyan Malchev    my_data->csd = NULL;
788ae9a10c15cf960e9b2b1159ade6414f80689db5fIliyan Malchev
789ae9a10c15cf960e9b2b1159ade6414f80689db5fIliyan Malchev    void *lib = dlopen(name, RTLD_NOW);
790ae9a10c15cf960e9b2b1159ade6414f80689db5fIliyan Malchev    error = dlerror();
791ae9a10c15cf960e9b2b1159ade6414f80689db5fIliyan Malchev    if (!lib) {
792ae9a10c15cf960e9b2b1159ade6414f80689db5fIliyan Malchev        ALOGE("%s: could not find %s: %s", __func__, name, error);
793ae9a10c15cf960e9b2b1159ade6414f80689db5fIliyan Malchev        return;
794ae9a10c15cf960e9b2b1159ade6414f80689db5fIliyan Malchev    }
795ae9a10c15cf960e9b2b1159ade6414f80689db5fIliyan Malchev
796ae9a10c15cf960e9b2b1159ade6414f80689db5fIliyan Malchev    count_modems = NULL;
797ae9a10c15cf960e9b2b1159ade6414f80689db5fIliyan Malchev    *(void **)(&count_modems) = dlsym(lib, func);
798ae9a10c15cf960e9b2b1159ade6414f80689db5fIliyan Malchev    error = dlerror();
799ae9a10c15cf960e9b2b1159ade6414f80689db5fIliyan Malchev    if (!count_modems) {
800ae9a10c15cf960e9b2b1159ade6414f80689db5fIliyan Malchev        ALOGE("%s: could not find symbol %s in %s: %s",
801ae9a10c15cf960e9b2b1159ade6414f80689db5fIliyan Malchev              __func__, func, name, error);
802ae9a10c15cf960e9b2b1159ade6414f80689db5fIliyan Malchev        goto done;
80383281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    }
80483281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda
805ae9a10c15cf960e9b2b1159ade6414f80689db5fIliyan Malchev    modems = count_modems();
806ae9a10c15cf960e9b2b1159ade6414f80689db5fIliyan Malchev    if (modems < 0) {
807ae9a10c15cf960e9b2b1159ade6414f80689db5fIliyan Malchev        ALOGE("%s: count_modems failed\n", __func__);
808ae9a10c15cf960e9b2b1159ade6414f80689db5fIliyan Malchev        goto done;
809ae9a10c15cf960e9b2b1159ade6414f80689db5fIliyan Malchev    }
810ae9a10c15cf960e9b2b1159ade6414f80689db5fIliyan Malchev
811ae9a10c15cf960e9b2b1159ade6414f80689db5fIliyan Malchev    ALOGD("%s: num_modems %d\n", __func__, modems);
812ae9a10c15cf960e9b2b1159ade6414f80689db5fIliyan Malchev    if (modems > 0)
81383281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        my_data->csd = open_csd_client(false /*is_i2s_ext_modem*/);
814ae9a10c15cf960e9b2b1159ade6414f80689db5fIliyan Malchev
815ae9a10c15cf960e9b2b1159ade6414f80689db5fIliyan Malchevdone:
816ae9a10c15cf960e9b2b1159ade6414f80689db5fIliyan Malchev    dlclose(lib);
81783281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda#else
81883281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda     my_data->csd = NULL;
81983281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda#endif
82083281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda}
82183281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda
822c633338c83da3760c4965d29af2afd80d3cce840Eric Laurentstatic void set_platform_defaults(struct platform_data * my_data)
82398c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George{
82498c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    int32_t dev;
82598c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
826b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda        backend_tag_table[dev] = NULL;
827b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda        hw_interface_table[dev] = NULL;
8282f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park        operator_specific_device_table[dev] = NULL;
82998c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    }
83098c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George
831b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda    // To overwrite these go to the audio_platform_info.xml file.
832b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda    backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("bt-sco");
833e258e6871b27aa4b63b4b44fe2e318ded4d4e511Ravi Kumar Alamanda    backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("bt-sco");
834b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda    backend_tag_table[SND_DEVICE_OUT_BT_SCO] = strdup("bt-sco");
835b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda    backend_tag_table[SND_DEVICE_OUT_HDMI] = strdup("hdmi");
836b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda    backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("speaker-and-hdmi");
837b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda    backend_tag_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("bt-sco-wb");
838b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda    backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("bt-sco-wb");
839e258e6871b27aa4b63b4b44fe2e318ded4d4e511Ravi Kumar Alamanda    backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("bt-sco-wb");
840b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda    backend_tag_table[SND_DEVICE_OUT_VOICE_TX] = strdup("afe-proxy");
841b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda    backend_tag_table[SND_DEVICE_IN_VOICE_RX] = strdup("afe-proxy");
84298c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George
843b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda    hw_interface_table[SND_DEVICE_OUT_HANDSET] = strdup("SLIMBUS_0_RX");
844b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda    hw_interface_table[SND_DEVICE_OUT_SPEAKER] = strdup("SLIMBUS_0_RX");
845b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda    hw_interface_table[SND_DEVICE_OUT_SPEAKER_REVERSE] = strdup("SLIMBUS_0_RX");
846b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda    hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE] = strdup("SLIMBUS_0_RX");
847b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda    hw_interface_table[SND_DEVICE_OUT_HEADPHONES] = strdup("SLIMBUS_0_RX");
848b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda    hw_interface_table[SND_DEVICE_OUT_LINE] = strdup("SLIMBUS_0_RX");
849b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda    hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
8503b86d472a707dd29cd692909fc80cf45a8fec481Ravi Kumar Alamanda    hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
851b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda    hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_LINE] = strdup("SLIMBUS_0_RX");
8523b86d472a707dd29cd692909fc80cf45a8fec481Ravi Kumar Alamanda    hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = strdup("SLIMBUS_0_RX");
853b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda    hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET] = strdup("SLIMBUS_0_RX");
854b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda    hw_interface_table[SND_DEVICE_OUT_VOICE_HAC_HANDSET] = strdup("SLIMBUS_0_RX");
855b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda    hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER] = strdup("SLIMBUS_0_RX");
856b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda    hw_interface_table[SND_DEVICE_OUT_VOICE_HEADPHONES] = strdup("SLIMBUS_0_RX");
857b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda    hw_interface_table[SND_DEVICE_OUT_VOICE_LINE] = strdup("SLIMBUS_0_RX");
858b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda    hw_interface_table[SND_DEVICE_OUT_HDMI] = strdup("HDMI_RX");
859b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda    hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("SLIMBUS_0_RX-and-HDMI_RX");
860b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda    hw_interface_table[SND_DEVICE_OUT_BT_SCO] = strdup("SEC_AUX_PCM_RX");
861b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda    hw_interface_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("SEC_AUX_PCM_RX");
862b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda    hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = strdup("SLIMBUS_0_RX");
863b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda    hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = strdup("SLIMBUS_0_RX");
864b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda    hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = strdup("SLIMBUS_0_RX");
865b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda    hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = strdup("SLIMBUS_0_RX");
866b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda    hw_interface_table[SND_DEVICE_OUT_VOICE_TX] = strdup("AFE_PCM_RX");
867b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda    hw_interface_table[SND_DEVICE_OUT_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
868b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda    hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
869c633338c83da3760c4965d29af2afd80d3cce840Eric Laurent
870c633338c83da3760c4965d29af2afd80d3cce840Eric Laurent    my_data->max_mic_count = PLATFORM_DEFAULT_MIC_COUNT;
87198c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George}
87298c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George
8735c049df87e3fad47fb1a6975e41c68eda9a8b594Ravi Kumar Alamandavoid get_cvd_version(char *cvd_version, struct audio_device *adev)
8745c049df87e3fad47fb1a6975e41c68eda9a8b594Ravi Kumar Alamanda{
8755c049df87e3fad47fb1a6975e41c68eda9a8b594Ravi Kumar Alamanda    struct mixer_ctl *ctl;
8765c049df87e3fad47fb1a6975e41c68eda9a8b594Ravi Kumar Alamanda    int count;
8775c049df87e3fad47fb1a6975e41c68eda9a8b594Ravi Kumar Alamanda    int ret = 0;
8785c049df87e3fad47fb1a6975e41c68eda9a8b594Ravi Kumar Alamanda
8795c049df87e3fad47fb1a6975e41c68eda9a8b594Ravi Kumar Alamanda    ctl = mixer_get_ctl_by_name(adev->mixer, CVD_VERSION_MIXER_CTL);
8805c049df87e3fad47fb1a6975e41c68eda9a8b594Ravi Kumar Alamanda    if (!ctl) {
8815c049df87e3fad47fb1a6975e41c68eda9a8b594Ravi Kumar Alamanda        ALOGE("%s: Could not get ctl for mixer cmd - %s",  __func__, CVD_VERSION_MIXER_CTL);
8825c049df87e3fad47fb1a6975e41c68eda9a8b594Ravi Kumar Alamanda        goto done;
8835c049df87e3fad47fb1a6975e41c68eda9a8b594Ravi Kumar Alamanda    }
8845c049df87e3fad47fb1a6975e41c68eda9a8b594Ravi Kumar Alamanda    mixer_ctl_update(ctl);
8855c049df87e3fad47fb1a6975e41c68eda9a8b594Ravi Kumar Alamanda
8865c049df87e3fad47fb1a6975e41c68eda9a8b594Ravi Kumar Alamanda    count = mixer_ctl_get_num_values(ctl);
8875c049df87e3fad47fb1a6975e41c68eda9a8b594Ravi Kumar Alamanda    if (count > MAX_CVD_VERSION_STRING_SIZE)
8885c049df87e3fad47fb1a6975e41c68eda9a8b594Ravi Kumar Alamanda        count = MAX_CVD_VERSION_STRING_SIZE - 1;
8895c049df87e3fad47fb1a6975e41c68eda9a8b594Ravi Kumar Alamanda
8905c049df87e3fad47fb1a6975e41c68eda9a8b594Ravi Kumar Alamanda    ret = mixer_ctl_get_array(ctl, cvd_version, count);
8915c049df87e3fad47fb1a6975e41c68eda9a8b594Ravi Kumar Alamanda    if (ret != 0) {
8925c049df87e3fad47fb1a6975e41c68eda9a8b594Ravi Kumar Alamanda        ALOGE("%s: ERROR! mixer_ctl_get_array() failed to get CVD Version", __func__);
8935c049df87e3fad47fb1a6975e41c68eda9a8b594Ravi Kumar Alamanda        goto done;
8945c049df87e3fad47fb1a6975e41c68eda9a8b594Ravi Kumar Alamanda    }
8955c049df87e3fad47fb1a6975e41c68eda9a8b594Ravi Kumar Alamanda
8965c049df87e3fad47fb1a6975e41c68eda9a8b594Ravi Kumar Alamandadone:
8975c049df87e3fad47fb1a6975e41c68eda9a8b594Ravi Kumar Alamanda    return;
8985c049df87e3fad47fb1a6975e41c68eda9a8b594Ravi Kumar Alamanda}
8995c049df87e3fad47fb1a6975e41c68eda9a8b594Ravi Kumar Alamanda
900b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurentvoid *platform_init(struct audio_device *adev)
901b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent{
902b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    char value[PROPERTY_VALUE_MAX];
903b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    struct platform_data *my_data;
9044b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    int retry_num = 0, snd_card_num = 0;
90565ad12de29cc94d65b2efc76588ae69ba941ba98vivek mehta    bool dual_mic_config = false;
90683281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    const char *snd_card_name;
9075c049df87e3fad47fb1a6975e41c68eda9a8b594Ravi Kumar Alamanda    char *cvd_version = NULL;
9081b9f4b3708d1ed1204bdb1dec370ad2e9db7a779sangwoo
909c4f57314a49fb83ed602395d9fe0c0164c9e863dRavi Kumar Alamanda    my_data = calloc(1, sizeof(struct platform_data));
910c4f57314a49fb83ed602395d9fe0c0164c9e863dRavi Kumar Alamanda
911c4f57314a49fb83ed602395d9fe0c0164c9e863dRavi Kumar Alamanda    my_data->adev = adev;
912c4f57314a49fb83ed602395d9fe0c0164c9e863dRavi Kumar Alamanda
9132f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park    list_init(&operator_info_list);
9142f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park
915c4f57314a49fb83ed602395d9fe0c0164c9e863dRavi Kumar Alamanda    set_platform_defaults(my_data);
916c4f57314a49fb83ed602395d9fe0c0164c9e863dRavi Kumar Alamanda
917c4f57314a49fb83ed602395d9fe0c0164c9e863dRavi Kumar Alamanda    /* Initialize platform specific ids and/or backends*/
918c4f57314a49fb83ed602395d9fe0c0164c9e863dRavi Kumar Alamanda    platform_info_init(my_data);
919c4f57314a49fb83ed602395d9fe0c0164c9e863dRavi Kumar Alamanda
9204b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    while (snd_card_num < MAX_SND_CARD) {
9214b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        adev->mixer = mixer_open(snd_card_num);
9221b9f4b3708d1ed1204bdb1dec370ad2e9db7a779sangwoo
9234b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        while (!adev->mixer && retry_num < RETRY_NUMBER) {
9244b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava            usleep(RETRY_US);
9254b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava            adev->mixer = mixer_open(snd_card_num);
9264b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava            retry_num++;
9274b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        }
92883281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda
9294b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        if (!adev->mixer) {
9304b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava            ALOGE("%s: Unable to open the mixer card: %d", __func__,
9314b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava                   snd_card_num);
9324b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava            retry_num = 0;
9334b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava            snd_card_num++;
9344b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava            continue;
9354b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        }
936cedf1ac3c00e331b5f51b077f26c1367544ddd65Haynes Mathew George
9374b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        snd_card_name = mixer_get_name(adev->mixer);
938c4f57314a49fb83ed602395d9fe0c0164c9e863dRavi Kumar Alamanda
939c4f57314a49fb83ed602395d9fe0c0164c9e863dRavi Kumar Alamanda        /* validate the sound card name */
940c4f57314a49fb83ed602395d9fe0c0164c9e863dRavi Kumar Alamanda        if (my_data->snd_card_name != NULL &&
941c4f57314a49fb83ed602395d9fe0c0164c9e863dRavi Kumar Alamanda                strncmp(snd_card_name, my_data->snd_card_name, MAX_SND_CARD_NAME_LEN) != 0) {
942c4f57314a49fb83ed602395d9fe0c0164c9e863dRavi Kumar Alamanda            ALOGI("%s: found valid sound card %s, but not primary sound card %s",
943c4f57314a49fb83ed602395d9fe0c0164c9e863dRavi Kumar Alamanda                   __func__, snd_card_name, my_data->snd_card_name);
944c4f57314a49fb83ed602395d9fe0c0164c9e863dRavi Kumar Alamanda            retry_num = 0;
945c4f57314a49fb83ed602395d9fe0c0164c9e863dRavi Kumar Alamanda            snd_card_num++;
946c4f57314a49fb83ed602395d9fe0c0164c9e863dRavi Kumar Alamanda            continue;
947c4f57314a49fb83ed602395d9fe0c0164c9e863dRavi Kumar Alamanda        }
948c4f57314a49fb83ed602395d9fe0c0164c9e863dRavi Kumar Alamanda
9494b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        ALOGD("%s: snd_card_name: %s", __func__, snd_card_name);
950a609e8ebdfeca875b6d35ccfb3fb8b87710f3499Eric Laurent
9514b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        adev->audio_route = audio_route_init(snd_card_num, MIXER_XML_PATH);
9524b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        if (!adev->audio_route) {
9534b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava            ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
954c4f57314a49fb83ed602395d9fe0c0164c9e863dRavi Kumar Alamanda            goto init_failed;
9554b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        }
9564b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        adev->snd_card = snd_card_num;
9574b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        ALOGD("%s: Opened sound card:%d", __func__, snd_card_num);
9584b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        break;
9594b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    }
9604b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava
9614b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    if (snd_card_num >= MAX_SND_CARD) {
9624b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        ALOGE("%s: Unable to find correct sound card, aborting.", __func__);
963c4f57314a49fb83ed602395d9fe0c0164c9e863dRavi Kumar Alamanda        goto init_failed;
9641b9f4b3708d1ed1204bdb1dec370ad2e9db7a779sangwoo    }
965b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
966c5aaa0e767b83fa8299861a739a4a1cb8e9bee0fkeunhui.park    //set max volume step for voice call
967c5aaa0e767b83fa8299861a739a4a1cb8e9bee0fkeunhui.park    property_get("ro.config.vc_call_vol_steps", value, TOSTRING(MAX_VOL_INDEX));
968c5aaa0e767b83fa8299861a739a4a1cb8e9bee0fkeunhui.park    my_data->max_vol_index = atoi(value);
969c5aaa0e767b83fa8299861a739a4a1cb8e9bee0fkeunhui.park
97065ad12de29cc94d65b2efc76588ae69ba941ba98vivek mehta    property_get("persist.audio.dualmic.config",value,"");
97165ad12de29cc94d65b2efc76588ae69ba941ba98vivek mehta    if (!strcmp("endfire", value)) {
97265ad12de29cc94d65b2efc76588ae69ba941ba98vivek mehta        dual_mic_config = true;
97365ad12de29cc94d65b2efc76588ae69ba941ba98vivek mehta    }
97465ad12de29cc94d65b2efc76588ae69ba941ba98vivek mehta
975dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta    my_data->source_mic_type = SOURCE_DUAL_MIC;
976dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta
977b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    my_data->fluence_in_spkr_mode = false;
978b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    my_data->fluence_in_voice_call = false;
9793ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    my_data->fluence_in_voice_comm = false;
980b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    my_data->fluence_in_voice_rec = false;
981b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
98265ad12de29cc94d65b2efc76588ae69ba941ba98vivek mehta    property_get("ro.qc.sdk.audio.fluencetype", value, "none");
983dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta    if (!strcmp("fluencepro", value)) {
984dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta        my_data->fluence_type = FLUENCE_PRO_ENABLE;
98565ad12de29cc94d65b2efc76588ae69ba941ba98vivek mehta    } else if (!strcmp("fluence", value) || (dual_mic_config)) {
986dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta        my_data->fluence_type = FLUENCE_ENABLE;
987dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta    } else if (!strcmp("none", value)) {
988dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta        my_data->fluence_type = FLUENCE_DISABLE;
989b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    }
990b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
991dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta    if (my_data->fluence_type != FLUENCE_DISABLE) {
992b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        property_get("persist.audio.fluence.voicecall",value,"");
993b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        if (!strcmp("true", value)) {
994b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            my_data->fluence_in_voice_call = true;
995b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        }
996b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
9973ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda        property_get("persist.audio.fluence.voicecomm",value,"");
9983ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda        if (!strcmp("true", value)) {
9993ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda            my_data->fluence_in_voice_comm = true;
10003ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda        }
10013ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda
1002b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        property_get("persist.audio.fluence.voicerec",value,"");
1003b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        if (!strcmp("true", value)) {
1004b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            my_data->fluence_in_voice_rec = true;
1005b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        }
1006b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
1007b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        property_get("persist.audio.fluence.speaker",value,"");
1008b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        if (!strcmp("true", value)) {
1009b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            my_data->fluence_in_spkr_mode = true;
1010b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        }
1011b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    }
1012b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
1013dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta    // support max to mono, example if max count is 3, usecase supports Three, dual and mono mic
1014dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta    switch (my_data->max_mic_count) {
1015dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta        case 4:
1016dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta            my_data->source_mic_type |= SOURCE_QUAD_MIC;
1017dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta        case 3:
1018dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta            my_data->source_mic_type |= SOURCE_THREE_MIC;
1019dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta        case 2:
1020dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta            my_data->source_mic_type |= SOURCE_DUAL_MIC;
1021dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta        case 1:
1022dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta            my_data->source_mic_type |= SOURCE_MONO_MIC;
1023dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta            break;
1024dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta        default:
1025dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta            ALOGE("%s: max_mic_count (%d), is not supported, setting to default",
1026dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta                   __func__, my_data->max_mic_count);
1027dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta            my_data->source_mic_type = SOURCE_MONO_MIC|SOURCE_DUAL_MIC;
1028dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta            break;
1029dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta        }
1030dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta
1031dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta    ALOGV("%s: Fluence_Type(%d) max_mic_count(%d) mic_type(0x%x) fluence_in_voice_call(%d)"
1032dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta          " fluence_in_voice_comm(%d) fluence_in_voice_rec(%d) fluence_in_spkr_mode(%d) ",
1033dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta          __func__, my_data->fluence_type, my_data->max_mic_count, my_data->source_mic_type,
1034dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta          my_data->fluence_in_voice_call, my_data->fluence_in_voice_comm,
1035dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta          my_data->fluence_in_voice_rec, my_data->fluence_in_spkr_mode);
1036dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta
1037b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
1038b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    if (my_data->acdb_handle == NULL) {
1039b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
1040b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    } else {
1041b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
1042b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
1043b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent                                                    "acdb_loader_deallocate_ACDB");
104483281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        if (!my_data->acdb_deallocate)
104583281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s",
104683281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                  __func__, LIB_ACDB_LOADER);
104783281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda
1048b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
1049b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent                                                    "acdb_loader_send_audio_cal");
1050b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        if (!my_data->acdb_send_audio_cal)
105183281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s",
1052b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent                  __func__, LIB_ACDB_LOADER);
105383281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda
1054b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
1055b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent                                                    "acdb_loader_send_voice_cal");
105683281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        if (!my_data->acdb_send_voice_cal)
105783281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s",
105883281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                  __func__, LIB_ACDB_LOADER);
105983281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda
106083281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle,
106183281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                                                    "acdb_loader_reload_vocvoltable");
106283281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        if (!my_data->acdb_reload_vocvoltable)
106383281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s",
106483281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                  __func__, LIB_ACDB_LOADER);
10651a9b7c0f180df7fe390f2839e8214667727aaa49vivek mehta
10661a9b7c0f180df7fe390f2839e8214667727aaa49vivek mehta        my_data->acdb_send_gain_dep_cal = (acdb_send_gain_dep_cal_t)dlsym(my_data->acdb_handle,
10671a9b7c0f180df7fe390f2839e8214667727aaa49vivek mehta                                                    "acdb_loader_send_gain_dep_cal");
10681a9b7c0f180df7fe390f2839e8214667727aaa49vivek mehta        if (!my_data->acdb_send_gain_dep_cal)
10691a9b7c0f180df7fe390f2839e8214667727aaa49vivek mehta            ALOGV("%s: Could not find the symbol acdb_loader_send_gain_dep_cal from %s",
10701a9b7c0f180df7fe390f2839e8214667727aaa49vivek mehta                  __func__, LIB_ACDB_LOADER);
10711a9b7c0f180df7fe390f2839e8214667727aaa49vivek mehta
10725c049df87e3fad47fb1a6975e41c68eda9a8b594Ravi Kumar Alamanda#if defined (PLATFORM_MSM8994)
10735c049df87e3fad47fb1a6975e41c68eda9a8b594Ravi Kumar Alamanda        acdb_init_v2_cvd_t acdb_init;
10745c049df87e3fad47fb1a6975e41c68eda9a8b594Ravi Kumar Alamanda        acdb_init = (acdb_init_v2_cvd_t)dlsym(my_data->acdb_handle,
10755c049df87e3fad47fb1a6975e41c68eda9a8b594Ravi Kumar Alamanda                                              "acdb_loader_init_v2");
10765c049df87e3fad47fb1a6975e41c68eda9a8b594Ravi Kumar Alamanda        if (acdb_init == NULL) {
107783281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__, dlerror());
10785c049df87e3fad47fb1a6975e41c68eda9a8b594Ravi Kumar Alamanda            goto acdb_init_fail;
10795c049df87e3fad47fb1a6975e41c68eda9a8b594Ravi Kumar Alamanda        }
10805c049df87e3fad47fb1a6975e41c68eda9a8b594Ravi Kumar Alamanda
10815c049df87e3fad47fb1a6975e41c68eda9a8b594Ravi Kumar Alamanda        cvd_version = calloc(1, MAX_CVD_VERSION_STRING_SIZE);
10825c049df87e3fad47fb1a6975e41c68eda9a8b594Ravi Kumar Alamanda        get_cvd_version(cvd_version, adev);
10835c049df87e3fad47fb1a6975e41c68eda9a8b594Ravi Kumar Alamanda        if (!cvd_version)
10845c049df87e3fad47fb1a6975e41c68eda9a8b594Ravi Kumar Alamanda            ALOGE("failed to allocate cvd_version");
108583281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        else
10865c049df87e3fad47fb1a6975e41c68eda9a8b594Ravi Kumar Alamanda            acdb_init((char *)snd_card_name, cvd_version);
10875c049df87e3fad47fb1a6975e41c68eda9a8b594Ravi Kumar Alamanda        free(cvd_version);
10885c049df87e3fad47fb1a6975e41c68eda9a8b594Ravi Kumar Alamanda#elif defined (PLATFORM_MSM8084)
10895c049df87e3fad47fb1a6975e41c68eda9a8b594Ravi Kumar Alamanda        acdb_init_v2_t acdb_init;
10905c049df87e3fad47fb1a6975e41c68eda9a8b594Ravi Kumar Alamanda        acdb_init = (acdb_init_v2_t)dlsym(my_data->acdb_handle,
10915c049df87e3fad47fb1a6975e41c68eda9a8b594Ravi Kumar Alamanda                                          "acdb_loader_init_v2");
10925c049df87e3fad47fb1a6975e41c68eda9a8b594Ravi Kumar Alamanda        if (acdb_init == NULL) {
10935c049df87e3fad47fb1a6975e41c68eda9a8b594Ravi Kumar Alamanda            ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__, dlerror());
10945c049df87e3fad47fb1a6975e41c68eda9a8b594Ravi Kumar Alamanda            goto acdb_init_fail;
10955c049df87e3fad47fb1a6975e41c68eda9a8b594Ravi Kumar Alamanda        }
10965c049df87e3fad47fb1a6975e41c68eda9a8b594Ravi Kumar Alamanda        acdb_init((char *)snd_card_name);
109783281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda#else
10985c049df87e3fad47fb1a6975e41c68eda9a8b594Ravi Kumar Alamanda        acdb_init_t acdb_init;
10995c049df87e3fad47fb1a6975e41c68eda9a8b594Ravi Kumar Alamanda        acdb_init = (acdb_init_t)dlsym(my_data->acdb_handle,
1100b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent                                                    "acdb_loader_init_ACDB");
11015c049df87e3fad47fb1a6975e41c68eda9a8b594Ravi Kumar Alamanda        if (acdb_init == NULL)
1102b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__, dlerror());
1103b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        else
11045c049df87e3fad47fb1a6975e41c68eda9a8b594Ravi Kumar Alamanda            acdb_init();
110583281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda#endif
1106b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    }
1107b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
11085c049df87e3fad47fb1a6975e41c68eda9a8b594Ravi Kumar Alamandaacdb_init_fail:
11095c049df87e3fad47fb1a6975e41c68eda9a8b594Ravi Kumar Alamanda
111063863001b659b66a367800c39f4a016ec5d544d7Ravi Kumar Alamanda    audio_extn_spkr_prot_init(adev);
111198c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George
11127631557cda5515b07b06dd0def53e5813f2442f3Ravi Kumar Alamanda    audio_extn_hwdep_cal_send(adev->snd_card, my_data->acdb_handle);
11137631557cda5515b07b06dd0def53e5813f2442f3Ravi Kumar Alamanda
111483281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    /* load csd client */
111583281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    platform_csd_init(my_data);
111683281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda
1117b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    return my_data;
1118c4f57314a49fb83ed602395d9fe0c0164c9e863dRavi Kumar Alamanda
1119c4f57314a49fb83ed602395d9fe0c0164c9e863dRavi Kumar Alamandainit_failed:
1120c4f57314a49fb83ed602395d9fe0c0164c9e863dRavi Kumar Alamanda    if (my_data)
1121c4f57314a49fb83ed602395d9fe0c0164c9e863dRavi Kumar Alamanda        free(my_data);
1122c4f57314a49fb83ed602395d9fe0c0164c9e863dRavi Kumar Alamanda    return NULL;
1123b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent}
1124b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
1125b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurentvoid platform_deinit(void *platform)
1126b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent{
1127c4f57314a49fb83ed602395d9fe0c0164c9e863dRavi Kumar Alamanda    int32_t dev;
11282f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park    struct operator_info *info_item;
11292f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park    struct operator_specific_device *device_item;
11302f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park    struct listnode *node;
1131c4f57314a49fb83ed602395d9fe0c0164c9e863dRavi Kumar Alamanda
11324b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    struct platform_data *my_data = (struct platform_data *)platform;
11334b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    close_csd_client(my_data->csd);
1134c4f57314a49fb83ed602395d9fe0c0164c9e863dRavi Kumar Alamanda
1135c4f57314a49fb83ed602395d9fe0c0164c9e863dRavi Kumar Alamanda    for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1136c4f57314a49fb83ed602395d9fe0c0164c9e863dRavi Kumar Alamanda        if (backend_tag_table[dev])
1137c4f57314a49fb83ed602395d9fe0c0164c9e863dRavi Kumar Alamanda            free(backend_tag_table[dev]);
1138c4f57314a49fb83ed602395d9fe0c0164c9e863dRavi Kumar Alamanda        if (hw_interface_table[dev])
1139c4f57314a49fb83ed602395d9fe0c0164c9e863dRavi Kumar Alamanda            free(hw_interface_table[dev]);
11402f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park        if (operator_specific_device_table[dev]) {
11412f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park            while (!list_empty(operator_specific_device_table[dev])) {
11422f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park                node = list_head(operator_specific_device_table[dev]);
11432f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park                list_remove(node);
11442f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park                device_item = node_to_item(node, struct operator_specific_device, list);
11452f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park                free(device_item->operator);
11462f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park                free(device_item->mixer_path);
11472f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park                free(device_item);
11482f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park            }
11492f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park            free(operator_specific_device_table[dev]);
11502f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park        }
1151c4f57314a49fb83ed602395d9fe0c0164c9e863dRavi Kumar Alamanda    }
1152c4f57314a49fb83ed602395d9fe0c0164c9e863dRavi Kumar Alamanda
1153c4f57314a49fb83ed602395d9fe0c0164c9e863dRavi Kumar Alamanda    if (my_data->snd_card_name)
1154c4f57314a49fb83ed602395d9fe0c0164c9e863dRavi Kumar Alamanda        free(my_data->snd_card_name);
1155c4f57314a49fb83ed602395d9fe0c0164c9e863dRavi Kumar Alamanda
11562f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park    while (!list_empty(&operator_info_list)) {
11572f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park        node = list_head(&operator_info_list);
11582f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park        list_remove(node);
11592f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park        info_item = node_to_item(node, struct operator_info, list);
11602f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park        free(info_item->name);
11612f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park        free(info_item->mccmnc);
11622f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park        free(info_item);
11632f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park    }
11642f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park
1165b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    free(platform);
1166b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent}
1167b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
1168b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurentconst char *platform_get_snd_device_name(snd_device_t snd_device)
1169b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent{
11702f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park    if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
11712f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park        if (operator_specific_device_table[snd_device] != NULL) {
11722f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park            return get_operator_specific_device_mixer_path(snd_device);
11732f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park        }
1174b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        return device_table[snd_device];
11752f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park    } else
11766402646dbd962f62c37abbb1d435907d54da77ddRavi Kumar Alamanda        return "none";
1177b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent}
1178b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
1179299760a41231bd0f6d9991fb189977347365c72bRavi Kumar Alamandavoid platform_add_backend_name(void *platform, char *mixer_path,
1180299760a41231bd0f6d9991fb189977347365c72bRavi Kumar Alamanda                               snd_device_t snd_device)
1181b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent{
1182299760a41231bd0f6d9991fb189977347365c72bRavi Kumar Alamanda    struct platform_data *my_data = (struct platform_data *)platform;
1183299760a41231bd0f6d9991fb189977347365c72bRavi Kumar Alamanda
118498c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
118598c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George        ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
118698c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George        return;
11871de6e5aac3120408a003dc8b5f7fdd68c40f436dRavi Kumar Alamanda    }
118898c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George
1189b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda    const char * suffix = backend_tag_table[snd_device];
119098c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George
119198c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    if (suffix != NULL) {
119298c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George        strcat(mixer_path, " ");
119398c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George        strcat(mixer_path, suffix);
1194299760a41231bd0f6d9991fb189977347365c72bRavi Kumar Alamanda    }
1195b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent}
1196b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
1197b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamandabool platform_check_backends_match(snd_device_t snd_device1, snd_device_t snd_device2)
1198b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda{
1199b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda    bool result = true;
1200b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda
1201b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda    ALOGV("%s: snd_device1 = %s, snd_device2 = %s", __func__,
1202b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda                platform_get_snd_device_name(snd_device1),
1203b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda                platform_get_snd_device_name(snd_device2));
1204b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda
1205b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda    if ((snd_device1 < SND_DEVICE_MIN) || (snd_device1 >= SND_DEVICE_MAX)) {
1206b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda        ALOGE("%s: Invalid snd_device = %s", __func__,
1207b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda                platform_get_snd_device_name(snd_device1));
1208b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda        return false;
1209b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda    }
1210b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda    if ((snd_device2 < SND_DEVICE_MIN) || (snd_device2 >= SND_DEVICE_MAX)) {
1211b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda        ALOGE("%s: Invalid snd_device = %s", __func__,
1212b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda                platform_get_snd_device_name(snd_device2));
1213b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda        return false;
1214b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda    }
1215b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda    const char * be_itf1 = hw_interface_table[snd_device1];
1216b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda    const char * be_itf2 = hw_interface_table[snd_device2];
1217b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda
1218b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda    if (NULL != be_itf1 && NULL != be_itf2) {
1219e63e61d40e171b60b8345f2a47022d066aa589f2Eric Laurent        if ((NULL == strstr(be_itf2, be_itf1)) && (NULL == strstr(be_itf1, be_itf2)))
1220b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda            result = false;
1221b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda    }
1222b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda
1223b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda    ALOGV("%s: be_itf1 = %s, be_itf2 = %s, match %d", __func__, be_itf1, be_itf2, result);
1224b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda    return result;
1225b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda}
1226b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda
1227b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurentint platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
1228b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent{
1229b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    int device_id;
1230b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    if (device_type == PCM_PLAYBACK)
1231b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        device_id = pcm_device_table[usecase][0];
1232b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    else
1233b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        device_id = pcm_device_table[usecase][1];
1234b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    return device_id;
1235b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent}
1236b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
123798c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew Georgestatic int find_index(const struct name_to_index * table, int32_t len,
123898c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George                      const char * name)
12395bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George{
12405bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George    int ret = 0;
124198c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    int32_t i;
12425bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George
124398c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    if (table == NULL) {
124498c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George        ALOGE("%s: table is NULL", __func__);
12455bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George        ret = -ENODEV;
12465bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George        goto done;
12475bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George    }
12485bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George
124998c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    if (name == NULL) {
125098c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George        ALOGE("null key");
125198c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George        ret = -ENODEV;
125298c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George        goto done;
125398c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    }
125498c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George
125598c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    for (i=0; i < len; i++) {
125698c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George        if (!strcmp(table[i].name, name)) {
125798c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George            ret = table[i].index;
12585bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George            goto done;
12595bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George        }
12605bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George    }
126198c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    ALOGE("%s: Could not find index for name = %s",
126298c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George            __func__, name);
12635bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George    ret = -ENODEV;
12645bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew Georgedone:
12655bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George    return ret;
12665bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George}
12675bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George
126898c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew Georgeint platform_get_snd_device_index(char *device_name)
126998c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George{
127098c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    return find_index(snd_device_name_index, SND_DEVICE_MAX, device_name);
127198c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George}
127298c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George
127398c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew Georgeint platform_get_usecase_index(const char *usecase_name)
127498c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George{
127598c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    return find_index(usecase_name_index, AUDIO_USECASE_MAX, usecase_name);
127698c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George}
127798c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George
12782f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.parkvoid platform_add_operator_specific_device(snd_device_t snd_device,
12792f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park                                           const char *operator,
12802f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park                                           const char *mixer_path,
12812f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park                                           unsigned int acdb_id)
12822f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park{
12832f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park    struct operator_specific_device *device;
12842f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park
12852f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park    if (operator_specific_device_table[snd_device] == NULL) {
12862f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park        operator_specific_device_table[snd_device] =
12872f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park            (struct listnode *)calloc(1, sizeof(struct listnode));
12882f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park        list_init(operator_specific_device_table[snd_device]);
12892f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park    }
12902f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park
12912f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park    device = (struct operator_specific_device *)calloc(1, sizeof(struct operator_specific_device));
12922f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park
12932f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park    device->operator = strdup(operator);
12942f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park    device->mixer_path = strdup(mixer_path);
12952f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park    device->acdb_id = acdb_id;
12962f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park
12972f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park    list_add_tail(operator_specific_device_table[snd_device], &device->list);
12982f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park
12992f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park    ALOGD("%s : deivce[%s] -> operator[%s] mixer_path[%s] acdb_id [%d]", __func__,
13002f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park            platform_get_snd_device_name(snd_device), operator, mixer_path, acdb_id);
13012f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park
13022f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park}
13032f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park
13045bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew Georgeint platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
13055bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George{
13065bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George    int ret = 0;
13075bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George
13085bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George    if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
13095bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George        ALOGE("%s: Invalid snd_device = %d",
13105bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George            __func__, snd_device);
13115bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George        ret = -EINVAL;
13125bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George        goto done;
13135bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George    }
13145bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George
1315b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda    ALOGV("%s: acdb_device_table[%s]: old = %d new = %d", __func__,
1316b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda          platform_get_snd_device_name(snd_device), acdb_device_table[snd_device], acdb_id);
13175bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George    acdb_device_table[snd_device] = acdb_id;
13185bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew Georgedone:
13195bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George    return ret;
13205bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George}
13215bc188456348ebdfc5d3c86414952503ec41bd44Haynes Mathew George
132263863001b659b66a367800c39f4a016ec5d544d7Ravi Kumar Alamandaint platform_get_snd_device_acdb_id(snd_device_t snd_device)
132363863001b659b66a367800c39f4a016ec5d544d7Ravi Kumar Alamanda{
132463863001b659b66a367800c39f4a016ec5d544d7Ravi Kumar Alamanda    if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
132563863001b659b66a367800c39f4a016ec5d544d7Ravi Kumar Alamanda        ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
132663863001b659b66a367800c39f4a016ec5d544d7Ravi Kumar Alamanda        return -EINVAL;
132763863001b659b66a367800c39f4a016ec5d544d7Ravi Kumar Alamanda    }
13282f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park
13292f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park    if (operator_specific_device_table[snd_device] != NULL)
13302f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park        return get_operator_specific_device_acdb_id(snd_device);
13312f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park    else
13322f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park        return acdb_device_table[snd_device];
133363863001b659b66a367800c39f4a016ec5d544d7Ravi Kumar Alamanda}
133463863001b659b66a367800c39f4a016ec5d544d7Ravi Kumar Alamanda
1335b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurentint platform_send_audio_calibration(void *platform, snd_device_t snd_device)
1336b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent{
1337b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    struct platform_data *my_data = (struct platform_data *)platform;
1338b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    int acdb_dev_id, acdb_dev_type;
1339b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
1340adf0f3b3b518e98fc1056e2788dd936e87331fb1Ravi Kumar Alamanda    acdb_dev_id = acdb_device_table[audio_extn_get_spkr_prot_snd_device(snd_device)];
1341b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    if (acdb_dev_id < 0) {
1342b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        ALOGE("%s: Could not find acdb id for device(%d)",
1343b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent              __func__, snd_device);
1344b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        return -EINVAL;
1345b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    }
1346b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    if (my_data->acdb_send_audio_cal) {
13473ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda        ALOGD("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
1348b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent              __func__, snd_device, acdb_dev_id);
1349b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        if (snd_device >= SND_DEVICE_OUT_BEGIN &&
1350b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent                snd_device < SND_DEVICE_OUT_END)
1351b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            acdb_dev_type = ACDB_DEV_TYPE_OUT;
1352b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        else
1353b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            acdb_dev_type = ACDB_DEV_TYPE_IN;
1354b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
1355b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    }
1356b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    return 0;
1357b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent}
1358b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
1359b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurentint platform_switch_voice_call_device_pre(void *platform)
1360b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent{
136183281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    struct platform_data *my_data = (struct platform_data *)platform;
136283281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    int ret = 0;
136383281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda
136483281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    if (my_data->csd != NULL &&
1365b09e4a04c7a8ca770affbf48f154222ccd083f4bRavi Kumar Alamanda        voice_is_in_call(my_data->adev)) {
136683281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        /* This must be called before disabling mixer controls on APQ side */
136783281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        ret = my_data->csd->disable_device();
136883281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        if (ret < 0) {
136983281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            ALOGE("%s: csd_client_disable_device, failed, error %d",
137083281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                  __func__, ret);
137183281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        }
137283281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    }
137383281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    return ret;
137483281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda}
137583281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda
137683281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamandaint platform_switch_voice_call_enable_device_config(void *platform,
137783281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                                                    snd_device_t out_snd_device,
137883281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                                                    snd_device_t in_snd_device)
137983281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda{
138083281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    struct platform_data *my_data = (struct platform_data *)platform;
138183281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    int acdb_rx_id, acdb_tx_id;
138283281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    int ret = 0;
138383281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda
138483281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    if (my_data->csd == NULL)
138583281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        return ret;
138683281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda
138763863001b659b66a367800c39f4a016ec5d544d7Ravi Kumar Alamanda    if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
138863863001b659b66a367800c39f4a016ec5d544d7Ravi Kumar Alamanda        audio_extn_spkr_prot_is_enabled())
13892f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park        acdb_rx_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_SPEAKER_PROTECTED);
139063863001b659b66a367800c39f4a016ec5d544d7Ravi Kumar Alamanda    else
13912f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park        acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
139283281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda
13932f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park    acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
139483281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda
139583281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    if (acdb_rx_id > 0 && acdb_tx_id > 0) {
139683281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
139783281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        if (ret < 0) {
139883281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            ALOGE("%s: csd_enable_device_config, failed, error %d",
139983281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                  __func__, ret);
140083281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        }
140183281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    } else {
140283281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
140383281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda              acdb_rx_id, acdb_tx_id);
140483281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    }
140583281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda
140683281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    return ret;
1407b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent}
1408b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
1409b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurentint platform_switch_voice_call_device_post(void *platform,
1410b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent                                           snd_device_t out_snd_device,
1411b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent                                           snd_device_t in_snd_device)
1412b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent{
1413b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    struct platform_data *my_data = (struct platform_data *)platform;
1414b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    int acdb_rx_id, acdb_tx_id;
1415b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
1416b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    if (my_data->acdb_send_voice_cal == NULL) {
1417b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
1418b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    } else {
141963863001b659b66a367800c39f4a016ec5d544d7Ravi Kumar Alamanda        if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
142063863001b659b66a367800c39f4a016ec5d544d7Ravi Kumar Alamanda            audio_extn_spkr_prot_is_enabled())
142163863001b659b66a367800c39f4a016ec5d544d7Ravi Kumar Alamanda            out_snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED;
142263863001b659b66a367800c39f4a016ec5d544d7Ravi Kumar Alamanda
14232f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park        acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
14242f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park        acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
1425b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
1426b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        if (acdb_rx_id > 0 && acdb_tx_id > 0)
1427b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
1428b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        else
1429b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1430b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent                  acdb_rx_id, acdb_tx_id);
1431b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    }
1432b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
1433b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    return 0;
1434b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent}
1435b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
143683281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamandaint platform_switch_voice_call_usecase_route_post(void *platform,
143783281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                                                  snd_device_t out_snd_device,
143883281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                                                  snd_device_t in_snd_device)
143983281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda{
144083281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    struct platform_data *my_data = (struct platform_data *)platform;
144183281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    int acdb_rx_id, acdb_tx_id;
144283281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    int ret = 0;
144383281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda
144483281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    if (my_data->csd == NULL)
144583281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        return ret;
144683281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda
144763863001b659b66a367800c39f4a016ec5d544d7Ravi Kumar Alamanda    if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
144863863001b659b66a367800c39f4a016ec5d544d7Ravi Kumar Alamanda        audio_extn_spkr_prot_is_enabled())
14492f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park        acdb_rx_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED);
145063863001b659b66a367800c39f4a016ec5d544d7Ravi Kumar Alamanda    else
14512f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park        acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
145283281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda
14532f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park    acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
145483281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda
145583281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    if (acdb_rx_id > 0 && acdb_tx_id > 0) {
145683281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
145783281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                                          my_data->adev->acdb_settings);
145883281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        if (ret < 0) {
145983281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            ALOGE("%s: csd_enable_device, failed, error %d", __func__, ret);
146083281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        }
146183281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    } else {
146283281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
146383281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda              acdb_rx_id, acdb_tx_id);
146483281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    }
146583281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda
146683281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    return ret;
146783281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda}
146883281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda
14694b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastavaint platform_start_voice_call(void *platform, uint32_t vsid)
1470b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent{
147183281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    struct platform_data *my_data = (struct platform_data *)platform;
147283281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    int ret = 0;
147383281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda
147483281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    if (my_data->csd != NULL) {
14754b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        ret = my_data->csd->start_voice(vsid);
147683281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        if (ret < 0) {
147783281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
147883281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        }
147983281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    }
148083281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    return ret;
1481b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent}
1482b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
14834b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastavaint platform_stop_voice_call(void *platform, uint32_t vsid)
1484b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent{
148583281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    struct platform_data *my_data = (struct platform_data *)platform;
148683281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    int ret = 0;
148783281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda
148883281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    if (my_data->csd != NULL) {
14894b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        ret = my_data->csd->stop_voice(vsid);
149083281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        if (ret < 0) {
149183281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
149283281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        }
149383281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    }
149483281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    return ret;
1495b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent}
1496b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
14974b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastavaint platform_get_sample_rate(void *platform, uint32_t *rate)
14984b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava{
14994b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    struct platform_data *my_data = (struct platform_data *)platform;
15004b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    int ret = 0;
15014b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava
15024b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    if (my_data->csd != NULL) {
15034b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        ret = my_data->csd->get_sample_rate(rate);
15044b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        if (ret < 0) {
15054b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava            ALOGE("%s: csd_get_sample_rate error %d\n", __func__, ret);
15064b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        }
15074b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    }
15084b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    return ret;
15094b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava}
15104b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava
1511b65064161c19b4c688f8a436ed002264d9f49055vivek mehtavoid platform_set_speaker_gain_in_combo(struct audio_device *adev,
1512b65064161c19b4c688f8a436ed002264d9f49055vivek mehta                                        snd_device_t snd_device,
1513b65064161c19b4c688f8a436ed002264d9f49055vivek mehta                                        bool enable)
1514b65064161c19b4c688f8a436ed002264d9f49055vivek mehta{
1515b65064161c19b4c688f8a436ed002264d9f49055vivek mehta    const char* name;
1516b65064161c19b4c688f8a436ed002264d9f49055vivek mehta    switch (snd_device) {
1517b65064161c19b4c688f8a436ed002264d9f49055vivek mehta        case SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES:
1518b65064161c19b4c688f8a436ed002264d9f49055vivek mehta            if (enable)
1519b65064161c19b4c688f8a436ed002264d9f49055vivek mehta                name = "spkr-gain-in-headphone-combo";
1520b65064161c19b4c688f8a436ed002264d9f49055vivek mehta            else
1521b65064161c19b4c688f8a436ed002264d9f49055vivek mehta                name = "speaker-gain-default";
1522b65064161c19b4c688f8a436ed002264d9f49055vivek mehta            break;
1523b65064161c19b4c688f8a436ed002264d9f49055vivek mehta        case SND_DEVICE_OUT_SPEAKER_AND_LINE:
1524b65064161c19b4c688f8a436ed002264d9f49055vivek mehta            if (enable)
1525b65064161c19b4c688f8a436ed002264d9f49055vivek mehta                name = "spkr-gain-in-line-combo";
1526b65064161c19b4c688f8a436ed002264d9f49055vivek mehta            else
1527b65064161c19b4c688f8a436ed002264d9f49055vivek mehta                name = "speaker-gain-default";
1528b65064161c19b4c688f8a436ed002264d9f49055vivek mehta            break;
1529b65064161c19b4c688f8a436ed002264d9f49055vivek mehta        case SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES:
1530b65064161c19b4c688f8a436ed002264d9f49055vivek mehta            if (enable)
1531b65064161c19b4c688f8a436ed002264d9f49055vivek mehta                name = "spkr-safe-gain-in-headphone-combo";
1532b65064161c19b4c688f8a436ed002264d9f49055vivek mehta            else
1533b65064161c19b4c688f8a436ed002264d9f49055vivek mehta                name = "speaker-safe-gain-default";
1534b65064161c19b4c688f8a436ed002264d9f49055vivek mehta            break;
1535b65064161c19b4c688f8a436ed002264d9f49055vivek mehta        case SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE:
1536b65064161c19b4c688f8a436ed002264d9f49055vivek mehta            if (enable)
1537b65064161c19b4c688f8a436ed002264d9f49055vivek mehta                name = "spkr-safe-gain-in-line-combo";
1538b65064161c19b4c688f8a436ed002264d9f49055vivek mehta            else
1539b65064161c19b4c688f8a436ed002264d9f49055vivek mehta                name = "speaker-safe-gain-default";
1540b65064161c19b4c688f8a436ed002264d9f49055vivek mehta            break;
1541b65064161c19b4c688f8a436ed002264d9f49055vivek mehta        default:
1542b65064161c19b4c688f8a436ed002264d9f49055vivek mehta            return;
1543b65064161c19b4c688f8a436ed002264d9f49055vivek mehta    }
1544b65064161c19b4c688f8a436ed002264d9f49055vivek mehta
1545b65064161c19b4c688f8a436ed002264d9f49055vivek mehta    audio_route_apply_and_update_path(adev->audio_route, name);
1546b65064161c19b4c688f8a436ed002264d9f49055vivek mehta}
1547b65064161c19b4c688f8a436ed002264d9f49055vivek mehta
1548b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurentint platform_set_voice_volume(void *platform, int volume)
1549b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent{
1550b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    struct platform_data *my_data = (struct platform_data *)platform;
1551b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    struct audio_device *adev = my_data->adev;
1552b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    struct mixer_ctl *ctl;
155353b2cf0c72aa18a5848919e2309731af652e84f9sangwoo    const char *mixer_ctl_name = "Voice Rx Gain";
15544b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    int vol_index = 0, ret = 0;
15554b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    uint32_t set_values[ ] = {0,
15564b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava                              ALL_SESSION_VSID,
15574b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava                              DEFAULT_VOLUME_RAMP_DURATION_MS};
1558b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
1559b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    // Voice volume levels are mapped to adsp volume levels as follows.
1560b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1  0 -> 0
1561b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    // But this values don't changed in kernel. So, below change is need.
1562c5aaa0e767b83fa8299861a739a4a1cb8e9bee0fkeunhui.park    vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, my_data->max_vol_index);
15634b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    set_values[0] = vol_index;
1564b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
1565b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1566b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    if (!ctl) {
1567b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        ALOGE("%s: Could not get ctl for mixer cmd - %s",
1568b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent              __func__, mixer_ctl_name);
1569b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        return -EINVAL;
1570b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    }
15714b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    ALOGV("Setting voice volume index: %d", set_values[0]);
15724b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
15734b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava
157483281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    if (my_data->csd != NULL) {
157583281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        ret = my_data->csd->volume(ALL_SESSION_VSID, volume,
157683281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda                                   DEFAULT_VOLUME_RAMP_DURATION_MS);
157783281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        if (ret < 0) {
157883281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda            ALOGE("%s: csd_volume error %d", __func__, ret);
157983281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda        }
158083281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    }
158183281a951af159ca00517f6132fab39727b293f5Ravi Kumar Alamanda    return ret;
1582b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent}
1583b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
1584b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurentint platform_set_mic_mute(void *platform, bool state)
1585b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent{
1586b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    struct platform_data *my_data = (struct platform_data *)platform;
1587b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    struct audio_device *adev = my_data->adev;
1588b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    struct mixer_ctl *ctl;
1589b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    const char *mixer_ctl_name = "Voice Tx Mute";
159053b2cf0c72aa18a5848919e2309731af652e84f9sangwoo    int ret = 0;
15914b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    uint32_t set_values[ ] = {0,
15924b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava                              ALL_SESSION_VSID,
15934b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava                              DEFAULT_MUTE_RAMP_DURATION_MS};
1594cedf1ac3c00e331b5f51b077f26c1367544ddd65Haynes Mathew George
15954b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    if (adev->mode != AUDIO_MODE_IN_CALL)
15964b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        return 0;
15974b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava
15984b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    set_values[0] = state;
15994b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
16004b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    if (!ctl) {
16014b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        ALOGE("%s: Could not get ctl for mixer cmd - %s",
16024b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava              __func__, mixer_ctl_name);
16034b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        return -EINVAL;
16044b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    }
16054b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    ALOGV("Setting voice mute state: %d", state);
16064b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
16074b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava
16084b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    if (my_data->csd != NULL) {
16094b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state,
16104b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava                                     DEFAULT_MUTE_RAMP_DURATION_MS);
1611a609e8ebdfeca875b6d35ccfb3fb8b87710f3499Eric Laurent        if (ret < 0) {
16124b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava            ALOGE("%s: csd_mic_mute error %d", __func__, ret);
161353b2cf0c72aa18a5848919e2309731af652e84f9sangwoo        }
1614cedf1ac3c00e331b5f51b077f26c1367544ddd65Haynes Mathew George    }
16154b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    return ret;
16164b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava}
1617cedf1ac3c00e331b5f51b077f26c1367544ddd65Haynes Mathew George
16184b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastavaint platform_set_device_mute(void *platform, bool state, char *dir)
16194b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava{
16204b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    struct platform_data *my_data = (struct platform_data *)platform;
16214b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    struct audio_device *adev = my_data->adev;
16224b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    struct mixer_ctl *ctl;
16234b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    char *mixer_ctl_name = NULL;
16244b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    int ret = 0;
16254b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    uint32_t set_values[ ] = {0,
16264b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava                              ALL_SESSION_VSID,
16274b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava                              0};
16284b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    if(dir == NULL) {
16294b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        ALOGE("%s: Invalid direction:%s", __func__, dir);
16304b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        return -EINVAL;
16314b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    }
16324b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava
16334b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    if (!strncmp("rx", dir, sizeof("rx"))) {
16344b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        mixer_ctl_name = "Voice Rx Device Mute";
16354b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    } else if (!strncmp("tx", dir, sizeof("tx"))) {
16364b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        mixer_ctl_name = "Voice Tx Device Mute";
16374b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    } else {
16384b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        return -EINVAL;
16394b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    }
16404b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava
16414b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    set_values[0] = state;
16424b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
16434b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    if (!ctl) {
16444b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        ALOGE("%s: Could not get ctl for mixer cmd - %s",
16454b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava              __func__, mixer_ctl_name);
16464b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        return -EINVAL;
16474b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    }
16484b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava
16494b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
16504b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava          __func__,state, mixer_ctl_name);
16514b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
16524b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava
16534b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    return ret;
1654b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent}
1655b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
1656b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamandabool platform_can_split_snd_device(snd_device_t snd_device,
1657b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda                                   int *num_devices,
1658b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda                                   snd_device_t *new_snd_devices)
1659b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda{
1660b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda    bool status = false;
1661b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda
1662b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda    if (NULL == num_devices || NULL == new_snd_devices) {
1663b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda        ALOGE("%s: NULL pointer ..", __func__);
1664b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda        return false;
1665b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda    }
1666b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda
1667b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda    /*
1668b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda     * If wired headset/headphones/line devices share the same backend
1669b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda     * with speaker/earpiece this routine returns false.
1670b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda     */
1671b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda    if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES &&
1672b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda        !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_HEADPHONES)) {
1673b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda        *num_devices = 2;
1674b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda        new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
1675b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda        new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
1676b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda        status = true;
1677b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda    } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_LINE &&
1678b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda               !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_LINE)) {
1679b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda        *num_devices = 2;
1680b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda        new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
1681b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda        new_snd_devices[1] = SND_DEVICE_OUT_LINE;
1682b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda        status = true;
16833b86d472a707dd29cd692909fc80cf45a8fec481Ravi Kumar Alamanda    } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES &&
16843b86d472a707dd29cd692909fc80cf45a8fec481Ravi Kumar Alamanda               !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_HEADPHONES)) {
16853b86d472a707dd29cd692909fc80cf45a8fec481Ravi Kumar Alamanda        *num_devices = 2;
16863b86d472a707dd29cd692909fc80cf45a8fec481Ravi Kumar Alamanda        new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
16873b86d472a707dd29cd692909fc80cf45a8fec481Ravi Kumar Alamanda        new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
16883b86d472a707dd29cd692909fc80cf45a8fec481Ravi Kumar Alamanda        status = true;
16893b86d472a707dd29cd692909fc80cf45a8fec481Ravi Kumar Alamanda    } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE &&
16903b86d472a707dd29cd692909fc80cf45a8fec481Ravi Kumar Alamanda               !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_LINE)) {
16913b86d472a707dd29cd692909fc80cf45a8fec481Ravi Kumar Alamanda        *num_devices = 2;
16923b86d472a707dd29cd692909fc80cf45a8fec481Ravi Kumar Alamanda        new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
16933b86d472a707dd29cd692909fc80cf45a8fec481Ravi Kumar Alamanda        new_snd_devices[1] = SND_DEVICE_OUT_LINE;
16943b86d472a707dd29cd692909fc80cf45a8fec481Ravi Kumar Alamanda        status = true;
1695b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda    }
1696b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda    return status;
1697b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda}
1698b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda
1699b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurentsnd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
1700b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent{
1701b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    struct platform_data *my_data = (struct platform_data *)platform;
1702b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    struct audio_device *adev = my_data->adev;
1703b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    audio_mode_t mode = adev->mode;
1704b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    snd_device_t snd_device = SND_DEVICE_NONE;
1705b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
1706b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    ALOGV("%s: enter: output devices(%#x)", __func__, devices);
1707b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    if (devices == AUDIO_DEVICE_NONE ||
1708b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        devices & AUDIO_DEVICE_BIT_IN) {
1709b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
1710b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        goto exit;
1711b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    }
1712b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
17131b49155ca2a0b056d09f159861ad0d251a36116dEric Laurent    if (popcount(devices) == 2) {
17141b49155ca2a0b056d09f159861ad0d251a36116dEric Laurent        if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
17151b49155ca2a0b056d09f159861ad0d251a36116dEric Laurent                        AUDIO_DEVICE_OUT_SPEAKER) ||
17161b49155ca2a0b056d09f159861ad0d251a36116dEric Laurent                devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
17171b49155ca2a0b056d09f159861ad0d251a36116dEric Laurent                            AUDIO_DEVICE_OUT_SPEAKER)) {
17181b49155ca2a0b056d09f159861ad0d251a36116dEric Laurent            snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
17191b49155ca2a0b056d09f159861ad0d251a36116dEric Laurent        } else if (devices == (AUDIO_DEVICE_OUT_LINE |
17201b49155ca2a0b056d09f159861ad0d251a36116dEric Laurent                               AUDIO_DEVICE_OUT_SPEAKER)) {
17211b49155ca2a0b056d09f159861ad0d251a36116dEric Laurent            snd_device = SND_DEVICE_OUT_SPEAKER_AND_LINE;
17221b49155ca2a0b056d09f159861ad0d251a36116dEric Laurent        } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
17231b49155ca2a0b056d09f159861ad0d251a36116dEric Laurent                               AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
17241b49155ca2a0b056d09f159861ad0d251a36116dEric Laurent                   devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
17251b49155ca2a0b056d09f159861ad0d251a36116dEric Laurent                               AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
17261b49155ca2a0b056d09f159861ad0d251a36116dEric Laurent            snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES;
17271b49155ca2a0b056d09f159861ad0d251a36116dEric Laurent        } else if (devices == (AUDIO_DEVICE_OUT_LINE |
17281b49155ca2a0b056d09f159861ad0d251a36116dEric Laurent                               AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
17291b49155ca2a0b056d09f159861ad0d251a36116dEric Laurent            snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE;
17301b49155ca2a0b056d09f159861ad0d251a36116dEric Laurent        } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
17311b49155ca2a0b056d09f159861ad0d251a36116dEric Laurent                               AUDIO_DEVICE_OUT_SPEAKER)) {
17321b49155ca2a0b056d09f159861ad0d251a36116dEric Laurent            snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
17331b49155ca2a0b056d09f159861ad0d251a36116dEric Laurent        } else {
17341b49155ca2a0b056d09f159861ad0d251a36116dEric Laurent            ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
17351b49155ca2a0b056d09f159861ad0d251a36116dEric Laurent            goto exit;
17361b49155ca2a0b056d09f159861ad0d251a36116dEric Laurent        }
17371b49155ca2a0b056d09f159861ad0d251a36116dEric Laurent        if (snd_device != SND_DEVICE_NONE) {
17381b49155ca2a0b056d09f159861ad0d251a36116dEric Laurent            goto exit;
17391b49155ca2a0b056d09f159861ad0d251a36116dEric Laurent        }
17401b49155ca2a0b056d09f159861ad0d251a36116dEric Laurent    }
17411b49155ca2a0b056d09f159861ad0d251a36116dEric Laurent
17421b49155ca2a0b056d09f159861ad0d251a36116dEric Laurent    if (popcount(devices) != 1) {
17431b49155ca2a0b056d09f159861ad0d251a36116dEric Laurent        ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
17441b49155ca2a0b056d09f159861ad0d251a36116dEric Laurent        goto exit;
17451b49155ca2a0b056d09f159861ad0d251a36116dEric Laurent    }
17461b49155ca2a0b056d09f159861ad0d251a36116dEric Laurent
1747b09e4a04c7a8ca770affbf48f154222ccd083f4bRavi Kumar Alamanda    if (voice_is_in_call(adev) || adev->enable_voicerx) {
1748b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
174909f2e0e6bf8accf1728ca89e780702d53f2c5b6dEric Laurent            devices & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
175009f2e0e6bf8accf1728ca89e780702d53f2c5b6dEric Laurent            devices & AUDIO_DEVICE_OUT_LINE) {
1751b09e4a04c7a8ca770affbf48f154222ccd083f4bRavi Kumar Alamanda            if (voice_is_in_call(adev) &&
1752cefbbac40220d4e7690d204eecff5f6ae3f63069Eric Laurent                (adev->voice.tty_mode == TTY_MODE_FULL))
1753b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent                snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
1754b09e4a04c7a8ca770affbf48f154222ccd083f4bRavi Kumar Alamanda            else if (voice_is_in_call(adev) &&
1755cefbbac40220d4e7690d204eecff5f6ae3f63069Eric Laurent                (adev->voice.tty_mode == TTY_MODE_VCO))
1756b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent                snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
1757b09e4a04c7a8ca770affbf48f154222ccd083f4bRavi Kumar Alamanda            else if (voice_is_in_call(adev) &&
1758cefbbac40220d4e7690d204eecff5f6ae3f63069Eric Laurent                (adev->voice.tty_mode == TTY_MODE_HCO))
1759b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent                snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
176009f2e0e6bf8accf1728ca89e780702d53f2c5b6dEric Laurent            else {
176109f2e0e6bf8accf1728ca89e780702d53f2c5b6dEric Laurent                if (devices & AUDIO_DEVICE_OUT_LINE)
176209f2e0e6bf8accf1728ca89e780702d53f2c5b6dEric Laurent                    snd_device = SND_DEVICE_OUT_VOICE_LINE;
176309f2e0e6bf8accf1728ca89e780702d53f2c5b6dEric Laurent                else
176409f2e0e6bf8accf1728ca89e780702d53f2c5b6dEric Laurent                    snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
176509f2e0e6bf8accf1728ca89e780702d53f2c5b6dEric Laurent                }
1766b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
17679f3065480c81bf01d3af65bfd3da09e1fb74b520Ravi Kumar Alamanda            if (adev->bt_wb_speech_enabled) {
17689f3065480c81bf01d3af65bfd3da09e1fb74b520Ravi Kumar Alamanda                snd_device = SND_DEVICE_OUT_BT_SCO_WB;
17699f3065480c81bf01d3af65bfd3da09e1fb74b520Ravi Kumar Alamanda            } else {
17709f3065480c81bf01d3af65bfd3da09e1fb74b520Ravi Kumar Alamanda                snd_device = SND_DEVICE_OUT_BT_SCO;
17719f3065480c81bf01d3af65bfd3da09e1fb74b520Ravi Kumar Alamanda            }
17721b0d8ce4ec97a57b38a401dbd1e16ac5cf4c4671Eric Laurent        } else if (devices & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
1773b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
1774b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
17759d0d3f1537b5d157a2c31e0744303524b846446eEric Laurent            if(adev->voice.hac)
17769d0d3f1537b5d157a2c31e0744303524b846446eEric Laurent                snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
17779d0d3f1537b5d157a2c31e0744303524b846446eEric Laurent            else if (is_operator_tmus())
1778b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent                snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS;
1779b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            else
1780b4d368e0fe6006657ebc4e1f9ba01a072c4ca2c7Eric Laurent                snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
178199c752d87eb818fc3cfb2e5c6790b1ea0bc88da5Ravi Kumar Alamanda        } else if (devices & AUDIO_DEVICE_OUT_TELEPHONY_TX)
178299c752d87eb818fc3cfb2e5c6790b1ea0bc88da5Ravi Kumar Alamanda            snd_device = SND_DEVICE_OUT_VOICE_TX;
178399c752d87eb818fc3cfb2e5c6790b1ea0bc88da5Ravi Kumar Alamanda
1784b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        if (snd_device != SND_DEVICE_NONE) {
1785b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            goto exit;
1786b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        }
1787b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    }
1788b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
1789b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1790b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
1791b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        snd_device = SND_DEVICE_OUT_HEADPHONES;
179209f2e0e6bf8accf1728ca89e780702d53f2c5b6dEric Laurent    } else if (devices & AUDIO_DEVICE_OUT_LINE) {
179309f2e0e6bf8accf1728ca89e780702d53f2c5b6dEric Laurent        snd_device = SND_DEVICE_OUT_LINE;
17941b0d8ce4ec97a57b38a401dbd1e16ac5cf4c4671Eric Laurent    } else if (devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) {
17951b0d8ce4ec97a57b38a401dbd1e16ac5cf4c4671Eric Laurent        snd_device = SND_DEVICE_OUT_SPEAKER_SAFE;
1796b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
17971f60cf8ce4276473878a22956ae546911353ebd2Ravi Kumar Alamanda        if (my_data->speaker_lr_swap)
1798b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
1799b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        else
1800b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            snd_device = SND_DEVICE_OUT_SPEAKER;
1801b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
18029f3065480c81bf01d3af65bfd3da09e1fb74b520Ravi Kumar Alamanda        if (adev->bt_wb_speech_enabled) {
18039f3065480c81bf01d3af65bfd3da09e1fb74b520Ravi Kumar Alamanda            snd_device = SND_DEVICE_OUT_BT_SCO_WB;
18049f3065480c81bf01d3af65bfd3da09e1fb74b520Ravi Kumar Alamanda        } else {
18059f3065480c81bf01d3af65bfd3da09e1fb74b520Ravi Kumar Alamanda            snd_device = SND_DEVICE_OUT_BT_SCO;
18069f3065480c81bf01d3af65bfd3da09e1fb74b520Ravi Kumar Alamanda        }
1807b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
1808b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        snd_device = SND_DEVICE_OUT_HDMI ;
1809b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
18109d0d3f1537b5d157a2c31e0744303524b846446eEric Laurent        /*HAC support for voice-ish audio (eg visual voicemail)*/
18119d0d3f1537b5d157a2c31e0744303524b846446eEric Laurent        if(adev->voice.hac)
18129d0d3f1537b5d157a2c31e0744303524b846446eEric Laurent            snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
18139d0d3f1537b5d157a2c31e0744303524b846446eEric Laurent        else
18149d0d3f1537b5d157a2c31e0744303524b846446eEric Laurent            snd_device = SND_DEVICE_OUT_HANDSET;
1815b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    } else {
1816b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        ALOGE("%s: Unknown device(s) %#x", __func__, devices);
1817b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    }
1818b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurentexit:
1819b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
1820b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    return snd_device;
1821b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent}
1822b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
1823b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurentsnd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
1824b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent{
1825b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    struct platform_data *my_data = (struct platform_data *)platform;
1826b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    struct audio_device *adev = my_data->adev;
1827b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    audio_source_t  source = (adev->active_input == NULL) ?
1828b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent                                AUDIO_SOURCE_DEFAULT : adev->active_input->source;
1829b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
1830b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    audio_mode_t    mode   = adev->mode;
1831b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    audio_devices_t in_device = ((adev->active_input == NULL) ?
1832b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent                                    AUDIO_DEVICE_NONE : adev->active_input->device)
1833b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent                                & ~AUDIO_DEVICE_BIT_IN;
1834b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
1835b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent                                AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
1836b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    snd_device_t snd_device = SND_DEVICE_NONE;
18373ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda    int channel_count = popcount(channel_mask);
1838b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
1839dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta    ALOGV("%s: enter: out_device(%#x) in_device(%#x) channel_count (%d) channel_mask (0x%x)",
1840dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta          __func__, out_device, in_device, channel_count, channel_mask);
1841b09e4a04c7a8ca770affbf48f154222ccd083f4bRavi Kumar Alamanda    if ((out_device != AUDIO_DEVICE_NONE) && voice_is_in_call(adev)) {
18424b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        if (adev->voice.tty_mode != TTY_MODE_OFF) {
1843b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
184409f2e0e6bf8accf1728ca89e780702d53f2c5b6dEric Laurent                out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
184509f2e0e6bf8accf1728ca89e780702d53f2c5b6dEric Laurent                out_device & AUDIO_DEVICE_OUT_LINE) {
18464b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava                switch (adev->voice.tty_mode) {
1847b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent                case TTY_MODE_FULL:
1848b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent                    snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
1849b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent                    break;
1850b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent                case TTY_MODE_VCO:
1851b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent                    snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
1852b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent                    break;
1853b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent                case TTY_MODE_HCO:
1854b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent                    snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
1855b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent                    break;
1856b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent                default:
18574b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava                    ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
1858b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent                }
1859b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent                goto exit;
1860b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            }
1861b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        }
1862b991fb007d870cbd682273e5fc7413b9d238a6d9Eric Laurent        if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
1863b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            if (my_data->fluence_in_voice_call == false) {
1864b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent                snd_device = SND_DEVICE_IN_HANDSET_MIC;
1865b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            } else {
18663ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                if (is_operator_tmus())
18673ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                    snd_device = SND_DEVICE_IN_VOICE_DMIC_TMUS;
1868b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent                else
18693ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                    snd_device = SND_DEVICE_IN_VOICE_DMIC;
1870b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            }
1871b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
1872b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
1873b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
18749f3065480c81bf01d3af65bfd3da09e1fb74b520Ravi Kumar Alamanda            if (adev->bt_wb_speech_enabled) {
1875e258e6871b27aa4b63b4b44fe2e318ded4d4e511Ravi Kumar Alamanda                if (adev->bluetooth_nrec)
1876e258e6871b27aa4b63b4b44fe2e318ded4d4e511Ravi Kumar Alamanda                    snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
1877e258e6871b27aa4b63b4b44fe2e318ded4d4e511Ravi Kumar Alamanda                else
1878e258e6871b27aa4b63b4b44fe2e318ded4d4e511Ravi Kumar Alamanda                    snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
18799f3065480c81bf01d3af65bfd3da09e1fb74b520Ravi Kumar Alamanda            } else {
1880e258e6871b27aa4b63b4b44fe2e318ded4d4e511Ravi Kumar Alamanda                if (adev->bluetooth_nrec)
1881e258e6871b27aa4b63b4b44fe2e318ded4d4e511Ravi Kumar Alamanda                    snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
1882e258e6871b27aa4b63b4b44fe2e318ded4d4e511Ravi Kumar Alamanda                else
1883e258e6871b27aa4b63b4b44fe2e318ded4d4e511Ravi Kumar Alamanda                    snd_device = SND_DEVICE_IN_BT_SCO_MIC;
18849f3065480c81bf01d3af65bfd3da09e1fb74b520Ravi Kumar Alamanda            }
1885b991fb007d870cbd682273e5fc7413b9d238a6d9Eric Laurent        } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
1886dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta                   out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
1887dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta                   out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1888dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta                   out_device & AUDIO_DEVICE_OUT_LINE) {
1889dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta            if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
1890dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta                if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
1891dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta                    snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
1892dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta                } else {
1893dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta                    snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
1894dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta                }
1895b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            }
1896c090339bef3a5fb59e4fc6647b332d47cb06dbf7vivek mehta
1897c090339bef3a5fb59e4fc6647b332d47cb06dbf7vivek mehta            //select default
1898c090339bef3a5fb59e4fc6647b332d47cb06dbf7vivek mehta            if (snd_device == SND_DEVICE_NONE) {
1899c090339bef3a5fb59e4fc6647b332d47cb06dbf7vivek mehta                snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
1900c090339bef3a5fb59e4fc6647b332d47cb06dbf7vivek mehta            }
1901dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta        } else if (out_device & AUDIO_DEVICE_OUT_TELEPHONY_TX) {
190299c752d87eb818fc3cfb2e5c6790b1ea0bc88da5Ravi Kumar Alamanda            snd_device = SND_DEVICE_IN_VOICE_RX;
1903dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta        }
1904b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    } else if (source == AUDIO_SOURCE_CAMCORDER) {
1905b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
1906b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            in_device & AUDIO_DEVICE_IN_BACK_MIC) {
1907b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
1908b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        }
1909b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
1910b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
1911dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta            if (my_data->fluence_in_voice_rec && channel_count == 1) {
1912dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta                if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
1913dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta                    (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
1914dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta                    snd_device = SND_DEVICE_IN_HANDSET_QMIC;
1915dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta                } else if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
1916dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta                    (my_data->source_mic_type & SOURCE_THREE_MIC)) {
1917dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta                    snd_device = SND_DEVICE_IN_HANDSET_TMIC;
1918dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta                } else if (((my_data->fluence_type == FLUENCE_PRO_ENABLE) ||
1919dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta                    (my_data->fluence_type == FLUENCE_ENABLE)) &&
1920dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta                    (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
19213ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                    snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
1922dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta                }
1923dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta                platform_set_echo_reference(adev, true, out_device);
1924dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta            } else if ((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) &&
1925dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta                       (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
1926dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta                snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
1927dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta            } else if (((int)channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
1928dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta                       (my_data->source_mic_type & SOURCE_THREE_MIC)) {
1929dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta                snd_device = SND_DEVICE_IN_THREE_MIC;
1930dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta            } else if (((int)channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
1931dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta                       (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
1932dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta                snd_device = SND_DEVICE_IN_QUAD_MIC;
1933b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            }
1934b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            if (snd_device == SND_DEVICE_NONE) {
19353ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                if (adev->active_input->enable_ns)
19363ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                    snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
19373ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                else
19383ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                    snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
1939b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            }
19408c83fe85b6d1257298208de043acece927787c3fJean-Michel Trivi        } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
19418c83fe85b6d1257298208de043acece927787c3fJean-Michel Trivi            snd_device = SND_DEVICE_IN_VOICE_REC_HEADSET_MIC;
1942b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        }
194350a38ed90672924763c4cb18773fca64588faeccEric Laurent    } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION ||
194450a38ed90672924763c4cb18773fca64588faeccEric Laurent            mode == AUDIO_MODE_IN_COMMUNICATION) {
19451b0d8ce4ec97a57b38a401dbd1e16ac5cf4c4671Eric Laurent        if (out_device & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE))
1946b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            in_device = AUDIO_DEVICE_IN_BACK_MIC;
1947b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        if (adev->active_input) {
19483ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda            if (adev->active_input->enable_aec &&
19493ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                    adev->active_input->enable_ns) {
19503ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
19513ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                    if (my_data->fluence_in_spkr_mode &&
19523ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                            my_data->fluence_in_voice_comm &&
1953dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta                            (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
19543ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                        snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
1955dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta                    } else {
19563ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                        snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
1957dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta                    }
19583ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
19593ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                    if (my_data->fluence_in_voice_comm &&
1960dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta                            (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
19613ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                        snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
1962dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta                    } else {
19633ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                        snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
1964dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta                    }
1965cefbbac40220d4e7690d204eecff5f6ae3f63069Eric Laurent                } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
1966cefbbac40220d4e7690d204eecff5f6ae3f63069Eric Laurent                    snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
19673ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                }
1968cefbbac40220d4e7690d204eecff5f6ae3f63069Eric Laurent                platform_set_echo_reference(adev, true, out_device);
19693ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda            } else if (adev->active_input->enable_aec) {
1970b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent                if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
19713ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                    if (my_data->fluence_in_spkr_mode &&
19723ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                            my_data->fluence_in_voice_comm &&
1973dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta                            (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
19743ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                        snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
1975dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta                    } else {
19763ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                        snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
1977dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta                    }
1978b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent                } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
19793ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                    if (my_data->fluence_in_voice_comm &&
1980dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta                            (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
19813ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                        snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
1982dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta                    } else {
19833ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                        snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
1984dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta                    }
1985cefbbac40220d4e7690d204eecff5f6ae3f63069Eric Laurent               } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
1986cefbbac40220d4e7690d204eecff5f6ae3f63069Eric Laurent                   snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
1987cefbbac40220d4e7690d204eecff5f6ae3f63069Eric Laurent               }
1988f28290178598c01d29f152a46483e5e8bd67b0e0Ravi Kumar Alamanda               platform_set_echo_reference(adev, true, out_device);
19893ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda            } else if (adev->active_input->enable_ns) {
19903ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
19913ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                    if (my_data->fluence_in_spkr_mode &&
19923ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                            my_data->fluence_in_voice_comm &&
1993dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta                            (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
19943ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                        snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
1995dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta                    } else {
19963ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                        snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
1997dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta                    }
19983ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
19993ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                    if (my_data->fluence_in_voice_comm &&
2000dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta                            (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
20013ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                        snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
2002dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta                    } else {
20033ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                        snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
2004dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta                    }
20053ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                }
2006cefbbac40220d4e7690d204eecff5f6ae3f63069Eric Laurent            }
2007b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        }
2008b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    } else if (source == AUDIO_SOURCE_DEFAULT) {
2009b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        goto exit;
2010b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    }
2011b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
2012b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
2013b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    if (snd_device != SND_DEVICE_NONE) {
2014b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        goto exit;
2015b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    }
2016b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
2017b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    if (in_device != AUDIO_DEVICE_NONE &&
2018b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
2019b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
2020b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2021dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta            if ((my_data->source_mic_type & SOURCE_QUAD_MIC) &&
2022dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta                (int)channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) {
2023dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta                snd_device = SND_DEVICE_IN_QUAD_MIC;
2024dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta            } else if ((my_data->source_mic_type & SOURCE_THREE_MIC) &&
2025dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta                       (int)channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) {
2026dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta                snd_device = SND_DEVICE_IN_THREE_MIC;
2027dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta            } else if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2028dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta                       channel_count == 2) {
20293ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                snd_device = SND_DEVICE_IN_HANDSET_DMIC_STEREO;
2030dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta            } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2031dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta                       channel_count == 1) {
20323ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                snd_device = SND_DEVICE_IN_HANDSET_MIC;
2033dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta            } else {
2034dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta                ALOGE("%s: something wrong (1): source type (%d) channel_count (%d) .."
2035dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta                      " channel mask (0x%x) no combination found .. setting to mono", __func__,
2036dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta                       my_data->source_mic_type, channel_count, channel_mask);
2037dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta                snd_device = SND_DEVICE_IN_HANDSET_MIC;
2038dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta            }
2039b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2040dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta            if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2041dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta                    channel_count == 2) {
20423ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
2043dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta            } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2044dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta                    channel_count == 1) {
2045dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta                snd_device = SND_DEVICE_IN_SPEAKER_MIC;
2046dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta            } else {
2047dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta                ALOGE("%s: something wrong (2): source type (%d) channel_count (%d) .."
2048dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta                      " no combination found .. setting to mono", __func__,
2049dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta                       my_data->source_mic_type, channel_count);
20503ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                snd_device = SND_DEVICE_IN_SPEAKER_MIC;
2051dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta            }
2052b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2053b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            snd_device = SND_DEVICE_IN_HEADSET_MIC;
2054b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
20559f3065480c81bf01d3af65bfd3da09e1fb74b520Ravi Kumar Alamanda            if (adev->bt_wb_speech_enabled) {
2056e258e6871b27aa4b63b4b44fe2e318ded4d4e511Ravi Kumar Alamanda                if (adev->bluetooth_nrec)
2057e258e6871b27aa4b63b4b44fe2e318ded4d4e511Ravi Kumar Alamanda                    snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2058e258e6871b27aa4b63b4b44fe2e318ded4d4e511Ravi Kumar Alamanda                else
2059e258e6871b27aa4b63b4b44fe2e318ded4d4e511Ravi Kumar Alamanda                    snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
20609f3065480c81bf01d3af65bfd3da09e1fb74b520Ravi Kumar Alamanda            } else {
2061e258e6871b27aa4b63b4b44fe2e318ded4d4e511Ravi Kumar Alamanda                if (adev->bluetooth_nrec)
2062e258e6871b27aa4b63b4b44fe2e318ded4d4e511Ravi Kumar Alamanda                    snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2063e258e6871b27aa4b63b4b44fe2e318ded4d4e511Ravi Kumar Alamanda                else
2064e258e6871b27aa4b63b4b44fe2e318ded4d4e511Ravi Kumar Alamanda                    snd_device = SND_DEVICE_IN_BT_SCO_MIC;
20659f3065480c81bf01d3af65bfd3da09e1fb74b520Ravi Kumar Alamanda            }
2066b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
2067b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            snd_device = SND_DEVICE_IN_HDMI_MIC;
2068b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        } else {
2069b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
2070b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            ALOGW("%s: Using default handset-mic", __func__);
2071b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            snd_device = SND_DEVICE_IN_HANDSET_MIC;
2072b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        }
2073b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    } else {
2074b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
2075b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            snd_device = SND_DEVICE_IN_HANDSET_MIC;
2076b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2077b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            snd_device = SND_DEVICE_IN_HEADSET_MIC;
20783ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda        } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
20791b0d8ce4ec97a57b38a401dbd1e16ac5cf4c4671Eric Laurent                   out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
20803ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                   out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
208109f2e0e6bf8accf1728ca89e780702d53f2c5b6dEric Laurent                   out_device & AUDIO_DEVICE_OUT_LINE) {
2082dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta            if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2083dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta                    channel_count == 2) {
20843ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
2085dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta            } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2086dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta                          channel_count == 1) {
2087dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta                snd_device = SND_DEVICE_IN_SPEAKER_MIC;
2088dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta            } else {
2089dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta                ALOGE("%s: something wrong (3): source type (%d) channel_count (%d) .."
2090dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta                      " no combination found .. setting to mono", __func__,
2091dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta                       my_data->source_mic_type, channel_count);
20923ad4e1b9949d04ad90d053458b10fa4dfbfa088eRavi Kumar Alamanda                snd_device = SND_DEVICE_IN_SPEAKER_MIC;
2093dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta            }
2094b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
20959f3065480c81bf01d3af65bfd3da09e1fb74b520Ravi Kumar Alamanda            if (adev->bt_wb_speech_enabled) {
2096e258e6871b27aa4b63b4b44fe2e318ded4d4e511Ravi Kumar Alamanda                if (adev->bluetooth_nrec)
2097e258e6871b27aa4b63b4b44fe2e318ded4d4e511Ravi Kumar Alamanda                    snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2098e258e6871b27aa4b63b4b44fe2e318ded4d4e511Ravi Kumar Alamanda                else
2099e258e6871b27aa4b63b4b44fe2e318ded4d4e511Ravi Kumar Alamanda                    snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
21009f3065480c81bf01d3af65bfd3da09e1fb74b520Ravi Kumar Alamanda            } else {
2101e258e6871b27aa4b63b4b44fe2e318ded4d4e511Ravi Kumar Alamanda                if (adev->bluetooth_nrec)
2102e258e6871b27aa4b63b4b44fe2e318ded4d4e511Ravi Kumar Alamanda                    snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2103e258e6871b27aa4b63b4b44fe2e318ded4d4e511Ravi Kumar Alamanda                else
2104e258e6871b27aa4b63b4b44fe2e318ded4d4e511Ravi Kumar Alamanda                    snd_device = SND_DEVICE_IN_BT_SCO_MIC;
21059f3065480c81bf01d3af65bfd3da09e1fb74b520Ravi Kumar Alamanda            }
2106b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2107b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            snd_device = SND_DEVICE_IN_HDMI_MIC;
2108b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        } else {
2109b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
2110b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            ALOGW("%s: Using default handset-mic", __func__);
2111b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            snd_device = SND_DEVICE_IN_HANDSET_MIC;
2112b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        }
2113b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    }
2114b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurentexit:
2115b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
2116b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    return snd_device;
2117b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent}
2118b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
2119b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurentint platform_set_hdmi_channels(void *platform,  int channel_count)
2120b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent{
2121b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    struct platform_data *my_data = (struct platform_data *)platform;
2122b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    struct audio_device *adev = my_data->adev;
2123b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    struct mixer_ctl *ctl;
2124b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    const char *channel_cnt_str = NULL;
2125b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    const char *mixer_ctl_name = "HDMI_RX Channels";
2126b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    switch (channel_count) {
2127b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    case 8:
2128b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        channel_cnt_str = "Eight"; break;
2129b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    case 7:
2130b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        channel_cnt_str = "Seven"; break;
2131b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    case 6:
2132b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        channel_cnt_str = "Six"; break;
2133b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    case 5:
2134b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        channel_cnt_str = "Five"; break;
2135b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    case 4:
2136b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        channel_cnt_str = "Four"; break;
2137b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    case 3:
2138b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        channel_cnt_str = "Three"; break;
2139b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    default:
2140b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        channel_cnt_str = "Two"; break;
2141b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    }
2142b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2143b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    if (!ctl) {
2144b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        ALOGE("%s: Could not get ctl for mixer cmd - %s",
2145b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent              __func__, mixer_ctl_name);
2146b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        return -EINVAL;
2147b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    }
2148b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    ALOGV("HDMI channel count: %s", channel_cnt_str);
2149b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
2150b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    return 0;
2151b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent}
2152b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
215347cd4cbdb19543338d5c887e3d7bcd2513c5c3adHaynes Mathew Georgeint platform_edid_get_max_channels(void *platform)
2154b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent{
215547cd4cbdb19543338d5c887e3d7bcd2513c5c3adHaynes Mathew George    struct platform_data *my_data = (struct platform_data *)platform;
215647cd4cbdb19543338d5c887e3d7bcd2513c5c3adHaynes Mathew George    struct audio_device *adev = my_data->adev;
2157b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
2158b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    char *sad = block;
2159b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    int num_audio_blocks;
2160b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    int channel_count;
2161b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    int max_channels = 0;
216247cd4cbdb19543338d5c887e3d7bcd2513c5c3adHaynes Mathew George    int i, ret, count;
2163b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
216447cd4cbdb19543338d5c887e3d7bcd2513c5c3adHaynes Mathew George    struct mixer_ctl *ctl;
216547cd4cbdb19543338d5c887e3d7bcd2513c5c3adHaynes Mathew George
216647cd4cbdb19543338d5c887e3d7bcd2513c5c3adHaynes Mathew George    ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
216747cd4cbdb19543338d5c887e3d7bcd2513c5c3adHaynes Mathew George    if (!ctl) {
216847cd4cbdb19543338d5c887e3d7bcd2513c5c3adHaynes Mathew George        ALOGE("%s: Could not get ctl for mixer cmd - %s",
216947cd4cbdb19543338d5c887e3d7bcd2513c5c3adHaynes Mathew George              __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
2170b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        return 0;
2171b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    }
2172b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
217347cd4cbdb19543338d5c887e3d7bcd2513c5c3adHaynes Mathew George    mixer_ctl_update(ctl);
217447cd4cbdb19543338d5c887e3d7bcd2513c5c3adHaynes Mathew George
217547cd4cbdb19543338d5c887e3d7bcd2513c5c3adHaynes Mathew George    count = mixer_ctl_get_num_values(ctl);
2176b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
2177b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    /* Read SAD blocks, clamping the maximum size for safety */
217847cd4cbdb19543338d5c887e3d7bcd2513c5c3adHaynes Mathew George    if (count > (int)sizeof(block))
217947cd4cbdb19543338d5c887e3d7bcd2513c5c3adHaynes Mathew George        count = (int)sizeof(block);
2180b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
218147cd4cbdb19543338d5c887e3d7bcd2513c5c3adHaynes Mathew George    ret = mixer_ctl_get_array(ctl, block, count);
218247cd4cbdb19543338d5c887e3d7bcd2513c5c3adHaynes Mathew George    if (ret != 0) {
218347cd4cbdb19543338d5c887e3d7bcd2513c5c3adHaynes Mathew George        ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
218447cd4cbdb19543338d5c887e3d7bcd2513c5c3adHaynes Mathew George        return 0;
218547cd4cbdb19543338d5c887e3d7bcd2513c5c3adHaynes Mathew George    }
2186b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
2187b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    /* Calculate the number of SAD blocks */
218847cd4cbdb19543338d5c887e3d7bcd2513c5c3adHaynes Mathew George    num_audio_blocks = count / SAD_BLOCK_SIZE;
2189b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
2190b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    for (i = 0; i < num_audio_blocks; i++) {
2191b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        /* Only consider LPCM blocks */
219247cd4cbdb19543338d5c887e3d7bcd2513c5c3adHaynes Mathew George        if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
219347cd4cbdb19543338d5c887e3d7bcd2513c5c3adHaynes Mathew George            sad += 3;
2194b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            continue;
219547cd4cbdb19543338d5c887e3d7bcd2513c5c3adHaynes Mathew George        }
2196b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
2197b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        channel_count = (sad[0] & 0x7) + 1;
2198b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        if (channel_count > max_channels)
2199b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent            max_channels = channel_count;
2200b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
2201b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        /* Advance to next block */
2202b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent        sad += 3;
2203b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    }
2204b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent
2205b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent    return max_channels;
2206b23d5286490ad2dc0edf919d52428fa02dc2b2dcEric Laurent}
22077ff216f80f6e53235b4239c6fb7da9b0d5127738Haynes Mathew George
22084b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastavaint platform_set_incall_recording_session_id(void *platform,
22094b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava                                             uint32_t session_id, int rec_mode)
22104b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava{
22114b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    int ret = 0;
22124b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    struct platform_data *my_data = (struct platform_data *)platform;
22134b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    struct audio_device *adev = my_data->adev;
22144b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    struct mixer_ctl *ctl;
22154b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    const char *mixer_ctl_name = "Voc VSID";
22164b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    int num_ctl_values;
22174b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    int i;
22184b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava
22194b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
22204b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    if (!ctl) {
22214b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        ALOGE("%s: Could not get ctl for mixer cmd - %s",
22224b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava              __func__, mixer_ctl_name);
22234b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        ret = -EINVAL;
22244b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    } else {
22254b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        num_ctl_values = mixer_ctl_get_num_values(ctl);
22264b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        for (i = 0; i < num_ctl_values; i++) {
22274b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava            if (mixer_ctl_set_value(ctl, i, session_id)) {
22284b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava                ALOGV("Error: invalid session_id: %x", session_id);
22294b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava                ret = -EINVAL;
22304b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava                break;
22314b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava            }
22324b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        }
22334b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    }
22344b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava
22354b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    if (my_data->csd != NULL) {
22364b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
22374b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        if (ret < 0) {
22384b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava            ALOGE("%s: csd_client_start_record failed, error %d",
22394b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava                  __func__, ret);
22404b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        }
22414b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    }
22424b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava
22434b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    return ret;
22444b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava}
22454b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava
22464b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastavaint platform_stop_incall_recording_usecase(void *platform)
22474b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava{
22484b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    int ret = 0;
22494b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    struct platform_data *my_data = (struct platform_data *)platform;
22504b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava
22514b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    if (my_data->csd != NULL) {
22524b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        ret = my_data->csd->stop_record(ALL_SESSION_VSID);
22534b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        if (ret < 0) {
22544b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava            ALOGE("%s: csd_client_stop_record failed, error %d",
22554b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava                  __func__, ret);
22564b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        }
22574b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    }
22584b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava
22594b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    return ret;
22604b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava}
22614b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava
22624b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastavaint platform_start_incall_music_usecase(void *platform)
22634b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava{
22644b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    int ret = 0;
22654b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    struct platform_data *my_data = (struct platform_data *)platform;
22664b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava
22674b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    if (my_data->csd != NULL) {
22684b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        ret = my_data->csd->start_playback(ALL_SESSION_VSID);
22694b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        if (ret < 0) {
22704b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava            ALOGE("%s: csd_client_start_playback failed, error %d",
22714b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava                  __func__, ret);
22724b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        }
22734b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    }
22744b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava
22754b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    return ret;
22764b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava}
22774b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava
22784b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastavaint platform_stop_incall_music_usecase(void *platform)
22794b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava{
22804b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    int ret = 0;
22814b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    struct platform_data *my_data = (struct platform_data *)platform;
22824b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava
22834b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    if (my_data->csd != NULL) {
22844b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
22854b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        if (ret < 0) {
22864b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava            ALOGE("%s: csd_client_stop_playback failed, error %d",
22874b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava                  __func__, ret);
22884b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava        }
22894b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    }
22904b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava
22914b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava    return ret;
22924b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava}
22934b89e37ad290ef955abf8ac1d151728303311345Vineeta Srivastava
2294c4f57314a49fb83ed602395d9fe0c0164c9e863dRavi Kumar Alamandaint platform_set_parameters(void *platform, struct str_parms *parms)
2295c4f57314a49fb83ed602395d9fe0c0164c9e863dRavi Kumar Alamanda{
2296c4f57314a49fb83ed602395d9fe0c0164c9e863dRavi Kumar Alamanda    struct platform_data *my_data = (struct platform_data *)platform;
22972f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park    char value[128];
2298c4f57314a49fb83ed602395d9fe0c0164c9e863dRavi Kumar Alamanda    char *kv_pairs = str_parms_to_str(parms);
2299c4f57314a49fb83ed602395d9fe0c0164c9e863dRavi Kumar Alamanda    int ret = 0, err;
2300c4f57314a49fb83ed602395d9fe0c0164c9e863dRavi Kumar Alamanda
2301c4f57314a49fb83ed602395d9fe0c0164c9e863dRavi Kumar Alamanda    if (kv_pairs == NULL) {
2302c4f57314a49fb83ed602395d9fe0c0164c9e863dRavi Kumar Alamanda        ret = -EINVAL;
2303c4f57314a49fb83ed602395d9fe0c0164c9e863dRavi Kumar Alamanda        ALOGE("%s: key-value pair is NULL",__func__);
2304c4f57314a49fb83ed602395d9fe0c0164c9e863dRavi Kumar Alamanda        goto done;
2305c4f57314a49fb83ed602395d9fe0c0164c9e863dRavi Kumar Alamanda    }
2306c4f57314a49fb83ed602395d9fe0c0164c9e863dRavi Kumar Alamanda
2307c4f57314a49fb83ed602395d9fe0c0164c9e863dRavi Kumar Alamanda    ALOGV("%s: enter: %s", __func__, kv_pairs);
2308c4f57314a49fb83ed602395d9fe0c0164c9e863dRavi Kumar Alamanda
2309c4f57314a49fb83ed602395d9fe0c0164c9e863dRavi Kumar Alamanda    err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME,
2310c4f57314a49fb83ed602395d9fe0c0164c9e863dRavi Kumar Alamanda                            value, sizeof(value));
2311c4f57314a49fb83ed602395d9fe0c0164c9e863dRavi Kumar Alamanda    if (err >= 0) {
2312c4f57314a49fb83ed602395d9fe0c0164c9e863dRavi Kumar Alamanda        str_parms_del(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME);
2313c4f57314a49fb83ed602395d9fe0c0164c9e863dRavi Kumar Alamanda        my_data->snd_card_name = strdup(value);
2314c4f57314a49fb83ed602395d9fe0c0164c9e863dRavi Kumar Alamanda        ALOGV("%s: sound card name %s", __func__, my_data->snd_card_name);
2315c4f57314a49fb83ed602395d9fe0c0164c9e863dRavi Kumar Alamanda    }
2316c4f57314a49fb83ed602395d9fe0c0164c9e863dRavi Kumar Alamanda
23172f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park    err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO,
23182f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park                            value, sizeof(value));
23192f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park    if (err >= 0) {
23202f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park        struct operator_info *info;
23212f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park        char *str = value;
23222f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park        char *name;
23232f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park
23242f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park        str_parms_del(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO);
23252f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park        info = (struct operator_info *)calloc(1, sizeof(struct operator_info));
23262f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park        name = strtok(str, ";");
23272f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park        info->name = strdup(name);
23282f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park        info->mccmnc = strdup(str + strlen(name) + 1);
23292f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park
23302f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park        list_add_tail(&operator_info_list, &info->list);
23312f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park        ALOGD("%s: add operator[%s] mccmnc[%s]", __func__, info->name, info->mccmnc);
23322f7306a9dae56a1204e8ec090198ce76b167bfa9keunhui.park    }
2333dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta
2334dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta    memset(value, 0, sizeof(value));
2335c633338c83da3760c4965d29af2afd80d3cce840Eric Laurent    err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT,
2336dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta                            value, sizeof(value));
2337dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta    if (err >= 0) {
2338c633338c83da3760c4965d29af2afd80d3cce840Eric Laurent        str_parms_del(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT);
2339dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta        my_data->max_mic_count = atoi(value);
2340dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta        ALOGV("%s: max_mic_count %s/%d", __func__, value, my_data->max_mic_count);
2341dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta    }
2342dae4471837fcdbd9356e3745b66f23f921fb531bvivek mehta
2343c4f57314a49fb83ed602395d9fe0c0164c9e863dRavi Kumar Alamandadone:
2344c4f57314a49fb83ed602395d9fe0c0164c9e863dRavi Kumar Alamanda    ALOGV("%s: exit with code(%d)", __func__, ret);
2345c4f57314a49fb83ed602395d9fe0c0164c9e863dRavi Kumar Alamanda    if (kv_pairs != NULL)
2346c4f57314a49fb83ed602395d9fe0c0164c9e863dRavi Kumar Alamanda        free(kv_pairs);
2347c4f57314a49fb83ed602395d9fe0c0164c9e863dRavi Kumar Alamanda
2348c4f57314a49fb83ed602395d9fe0c0164c9e863dRavi Kumar Alamanda    return ret;
2349c4f57314a49fb83ed602395d9fe0c0164c9e863dRavi Kumar Alamanda}
2350c4f57314a49fb83ed602395d9fe0c0164c9e863dRavi Kumar Alamanda
23517ff216f80f6e53235b4239c6fb7da9b0d5127738Haynes Mathew George/* Delay in Us */
23527ff216f80f6e53235b4239c6fb7da9b0d5127738Haynes Mathew Georgeint64_t platform_render_latency(audio_usecase_t usecase)
23537ff216f80f6e53235b4239c6fb7da9b0d5127738Haynes Mathew George{
23547ff216f80f6e53235b4239c6fb7da9b0d5127738Haynes Mathew George    switch (usecase) {
23557ff216f80f6e53235b4239c6fb7da9b0d5127738Haynes Mathew George        case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
23567ff216f80f6e53235b4239c6fb7da9b0d5127738Haynes Mathew George            return DEEP_BUFFER_PLATFORM_DELAY;
23577ff216f80f6e53235b4239c6fb7da9b0d5127738Haynes Mathew George        case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
23587ff216f80f6e53235b4239c6fb7da9b0d5127738Haynes Mathew George            return LOW_LATENCY_PLATFORM_DELAY;
23597ff216f80f6e53235b4239c6fb7da9b0d5127738Haynes Mathew George        default:
23607ff216f80f6e53235b4239c6fb7da9b0d5127738Haynes Mathew George            return 0;
23617ff216f80f6e53235b4239c6fb7da9b0d5127738Haynes Mathew George    }
23627ff216f80f6e53235b4239c6fb7da9b0d5127738Haynes Mathew George}
236398c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George
2364b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamandaint platform_set_snd_device_backend(snd_device_t device, const char *backend_tag,
2365b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda                                    const char * hw_interface)
236698c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George{
236798c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    int ret = 0;
236898c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George
236998c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
237098c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George        ALOGE("%s: Invalid snd_device = %d",
237198c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George            __func__, device);
237298c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George        ret = -EINVAL;
237398c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George        goto done;
237498c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    }
237598c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George
2376b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda    ALOGV("%s: backend_tag_table[%s]: old = %s new = %s", __func__,
2377b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda          platform_get_snd_device_name(device),
2378b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda          backend_tag_table[device] != NULL ? backend_tag_table[device]: "null", backend_tag);
2379b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda    if (backend_tag_table[device]) {
2380b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda        free(backend_tag_table[device]);
2381b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda    }
2382b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda    backend_tag_table[device] = strdup(backend_tag);
2383b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda
2384b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda    if (hw_interface != NULL) {
2385b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda        if (hw_interface_table[device])
2386b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda            free(hw_interface_table[device]);
2387b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda        ALOGV("%s: hw_interface_table[%d] = %s", __func__, device, hw_interface);
2388b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda        hw_interface_table[device] = strdup(hw_interface);
238998c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    }
239098c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew Georgedone:
239198c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    return ret;
239298c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George}
239398c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George
239498c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew Georgeint platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t pcm_id)
239598c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George{
239698c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    int ret = 0;
239798c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    if ((usecase <= USECASE_INVALID) || (usecase >= AUDIO_USECASE_MAX)) {
239898c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George        ALOGE("%s: invalid usecase case idx %d", __func__, usecase);
239998c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George        ret = -EINVAL;
240098c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George        goto done;
240198c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    }
240298c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George
240398c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    if ((type != 0) && (type != 1)) {
240498c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George        ALOGE("%s: invalid usecase type", __func__);
240598c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George        ret = -EINVAL;
240698c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    }
2407b7ea4f581dab56101215e97692c265931addad80Ravi Kumar Alamanda    ALOGV("%s: pcm_device_table[%d][%d] = %d", __func__, usecase, type, pcm_id);
240898c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    pcm_device_table[usecase][type] = pcm_id;
240998c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew Georgedone:
241098c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George    return ret;
241198c95622da1e906d32dde6b6651ed5b270b9b5f1Haynes Mathew George}
24121f60cf8ce4276473878a22956ae546911353ebd2Ravi Kumar Alamanda
241388cbad341d2dd920ac74c2296f319482bd53a33dJean-Michel Trivi#define DEFAULT_NOMINAL_SPEAKER_GAIN 20
241488cbad341d2dd920ac74c2296f319482bd53a33dJean-Michel Triviint ramp_speaker_gain(struct audio_device *adev, bool ramp_up, int target_ramp_up_gain) {
241588cbad341d2dd920ac74c2296f319482bd53a33dJean-Michel Trivi    // backup_gain: gain to try to set in case of an error during ramp
241688cbad341d2dd920ac74c2296f319482bd53a33dJean-Michel Trivi    int start_gain, end_gain, step, backup_gain, i;
241788cbad341d2dd920ac74c2296f319482bd53a33dJean-Michel Trivi    bool error = false;
241888cbad341d2dd920ac74c2296f319482bd53a33dJean-Michel Trivi    const struct mixer_ctl *ctl;
241988cbad341d2dd920ac74c2296f319482bd53a33dJean-Michel Trivi    const char *mixer_ctl_name_gain_left = "Left Speaker Gain";
242088cbad341d2dd920ac74c2296f319482bd53a33dJean-Michel Trivi    const char *mixer_ctl_name_gain_right = "Right Speaker Gain";
242188cbad341d2dd920ac74c2296f319482bd53a33dJean-Michel Trivi    struct mixer_ctl *ctl_left = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_left);
242288cbad341d2dd920ac74c2296f319482bd53a33dJean-Michel Trivi    struct mixer_ctl *ctl_right = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_right);
242388cbad341d2dd920ac74c2296f319482bd53a33dJean-Michel Trivi    if (!ctl_left || !ctl_right) {
242488cbad341d2dd920ac74c2296f319482bd53a33dJean-Michel Trivi        ALOGE("%s: Could not get ctl for mixer cmd - %s or %s, not applying speaker gain ramp",
242588cbad341d2dd920ac74c2296f319482bd53a33dJean-Michel Trivi                      __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
242688cbad341d2dd920ac74c2296f319482bd53a33dJean-Michel Trivi        return -EINVAL;
242788cbad341d2dd920ac74c2296f319482bd53a33dJean-Michel Trivi    } else if ((mixer_ctl_get_num_values(ctl_left) != 1)
242888cbad341d2dd920ac74c2296f319482bd53a33dJean-Michel Trivi            || (mixer_ctl_get_num_values(ctl_right) != 1)) {
242988cbad341d2dd920ac74c2296f319482bd53a33dJean-Michel Trivi        ALOGE("%s: Unexpected num values for mixer cmd - %s or %s, not applying speaker gain ramp",
243088cbad341d2dd920ac74c2296f319482bd53a33dJean-Michel Trivi                              __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
243188cbad341d2dd920ac74c2296f319482bd53a33dJean-Michel Trivi        return -EINVAL;
243288cbad341d2dd920ac74c2296f319482bd53a33dJean-Michel Trivi    }
243388cbad341d2dd920ac74c2296f319482bd53a33dJean-Michel Trivi    if (ramp_up) {
243488cbad341d2dd920ac74c2296f319482bd53a33dJean-Michel Trivi        start_gain = 0;
243588cbad341d2dd920ac74c2296f319482bd53a33dJean-Michel Trivi        end_gain = target_ramp_up_gain > 0 ? target_ramp_up_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
243688cbad341d2dd920ac74c2296f319482bd53a33dJean-Michel Trivi        step = +1;
243788cbad341d2dd920ac74c2296f319482bd53a33dJean-Michel Trivi        backup_gain = end_gain;
243888cbad341d2dd920ac74c2296f319482bd53a33dJean-Michel Trivi    } else {
243988cbad341d2dd920ac74c2296f319482bd53a33dJean-Michel Trivi        // using same gain on left and right
244088cbad341d2dd920ac74c2296f319482bd53a33dJean-Michel Trivi        const int left_gain = mixer_ctl_get_value(ctl_left, 0);
244188cbad341d2dd920ac74c2296f319482bd53a33dJean-Michel Trivi        start_gain = left_gain > 0 ? left_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
244288cbad341d2dd920ac74c2296f319482bd53a33dJean-Michel Trivi        end_gain = 0;
244388cbad341d2dd920ac74c2296f319482bd53a33dJean-Michel Trivi        step = -1;
244488cbad341d2dd920ac74c2296f319482bd53a33dJean-Michel Trivi        backup_gain = start_gain;
244588cbad341d2dd920ac74c2296f319482bd53a33dJean-Michel Trivi    }
244688cbad341d2dd920ac74c2296f319482bd53a33dJean-Michel Trivi    for (i = start_gain ; i != (end_gain + step) ; i += step) {
244788cbad341d2dd920ac74c2296f319482bd53a33dJean-Michel Trivi        //ALOGV("setting speaker gain to %d", i);
244888cbad341d2dd920ac74c2296f319482bd53a33dJean-Michel Trivi        if (mixer_ctl_set_value(ctl_left, 0, i)) {
244988cbad341d2dd920ac74c2296f319482bd53a33dJean-Michel Trivi            ALOGE("%s: error setting %s to %d during gain ramp",
245088cbad341d2dd920ac74c2296f319482bd53a33dJean-Michel Trivi                    __func__, mixer_ctl_name_gain_left, i);
245188cbad341d2dd920ac74c2296f319482bd53a33dJean-Michel Trivi            error = true;
245288cbad341d2dd920ac74c2296f319482bd53a33dJean-Michel Trivi            break;
245388cbad341d2dd920ac74c2296f319482bd53a33dJean-Michel Trivi        }
245488cbad341d2dd920ac74c2296f319482bd53a33dJean-Michel Trivi        if (mixer_ctl_set_value(ctl_right, 0, i)) {
245588cbad341d2dd920ac74c2296f319482bd53a33dJean-Michel Trivi            ALOGE("%s: error setting %s to %d during gain ramp",
245688cbad341d2dd920ac74c2296f319482bd53a33dJean-Michel Trivi                    __func__, mixer_ctl_name_gain_right, i);
245788cbad341d2dd920ac74c2296f319482bd53a33dJean-Michel Trivi            error = true;
245888cbad341d2dd920ac74c2296f319482bd53a33dJean-Michel Trivi            break;
245988cbad341d2dd920ac74c2296f319482bd53a33dJean-Michel Trivi        }
246088cbad341d2dd920ac74c2296f319482bd53a33dJean-Michel Trivi        usleep(1000);
246188cbad341d2dd920ac74c2296f319482bd53a33dJean-Michel Trivi    }
246288cbad341d2dd920ac74c2296f319482bd53a33dJean-Michel Trivi    if (error) {
246388cbad341d2dd920ac74c2296f319482bd53a33dJean-Michel Trivi        // an error occured during the ramp, let's still try to go back to a safe volume
246488cbad341d2dd920ac74c2296f319482bd53a33dJean-Michel Trivi        if (mixer_ctl_set_value(ctl_left, 0, backup_gain)) {
246588cbad341d2dd920ac74c2296f319482bd53a33dJean-Michel Trivi            ALOGE("%s: error restoring left gain to %d", __func__, backup_gain);
246688cbad341d2dd920ac74c2296f319482bd53a33dJean-Michel Trivi        }
246788cbad341d2dd920ac74c2296f319482bd53a33dJean-Michel Trivi        if (mixer_ctl_set_value(ctl_right, 0, backup_gain)) {
246888cbad341d2dd920ac74c2296f319482bd53a33dJean-Michel Trivi            ALOGE("%s: error restoring right gain to %d", __func__, backup_gain);
246988cbad341d2dd920ac74c2296f319482bd53a33dJean-Michel Trivi        }
247088cbad341d2dd920ac74c2296f319482bd53a33dJean-Michel Trivi    }
247188cbad341d2dd920ac74c2296f319482bd53a33dJean-Michel Trivi    return start_gain;
247288cbad341d2dd920ac74c2296f319482bd53a33dJean-Michel Trivi}
247388cbad341d2dd920ac74c2296f319482bd53a33dJean-Michel Trivi
24741f60cf8ce4276473878a22956ae546911353ebd2Ravi Kumar Alamandaint platform_swap_lr_channels(struct audio_device *adev, bool swap_channels)
24751f60cf8ce4276473878a22956ae546911353ebd2Ravi Kumar Alamanda{
24761f60cf8ce4276473878a22956ae546911353ebd2Ravi Kumar Alamanda    // only update if there is active pcm playback on speaker
24771f60cf8ce4276473878a22956ae546911353ebd2Ravi Kumar Alamanda    struct audio_usecase *usecase;
24781f60cf8ce4276473878a22956ae546911353ebd2Ravi Kumar Alamanda    struct listnode *node;
24791f60cf8ce4276473878a22956ae546911353ebd2Ravi Kumar Alamanda    struct platform_data *my_data = (struct platform_data *)adev->platform;
24801f60cf8ce4276473878a22956ae546911353ebd2Ravi Kumar Alamanda
24811f60cf8ce4276473878a22956ae546911353ebd2Ravi Kumar Alamanda    if (my_data->speaker_lr_swap != swap_channels) {
24821f60cf8ce4276473878a22956ae546911353ebd2Ravi Kumar Alamanda        my_data->speaker_lr_swap = swap_channels;
24831f60cf8ce4276473878a22956ae546911353ebd2Ravi Kumar Alamanda
24841f60cf8ce4276473878a22956ae546911353ebd2Ravi Kumar Alamanda        list_for_each(node, &adev->usecase_list) {
24851f60cf8ce4276473878a22956ae546911353ebd2Ravi Kumar Alamanda            usecase = node_to_item(node, struct audio_usecase, list);
24861f60cf8ce4276473878a22956ae546911353ebd2Ravi Kumar Alamanda            if (usecase->type == PCM_PLAYBACK &&
2487425e154c046554deb7ba766e89b943e8870ee251Ravi Kumar Alamanda                    usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) {
2488425e154c046554deb7ba766e89b943e8870ee251Ravi Kumar Alamanda                /*
2489425e154c046554deb7ba766e89b943e8870ee251Ravi Kumar Alamanda                 * If acdb tuning is different for SPEAKER_REVERSE, it is must
2490425e154c046554deb7ba766e89b943e8870ee251Ravi Kumar Alamanda                 * to perform device switch to disable the current backend to
2491425e154c046554deb7ba766e89b943e8870ee251Ravi Kumar Alamanda                 * enable it with new acdb data.
2492425e154c046554deb7ba766e89b943e8870ee251Ravi Kumar Alamanda                 */
2493425e154c046554deb7ba766e89b943e8870ee251Ravi Kumar Alamanda                if (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
2494425e154c046554deb7ba766e89b943e8870ee251Ravi Kumar Alamanda                    acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]) {
249588cbad341d2dd920ac74c2296f319482bd53a33dJean-Michel Trivi                    const int initial_skpr_gain = ramp_speaker_gain(adev, false /*ramp_up*/, -1);
2496425e154c046554deb7ba766e89b943e8870ee251Ravi Kumar Alamanda                    select_devices(adev, usecase->id);
249788cbad341d2dd920ac74c2296f319482bd53a33dJean-Michel Trivi                    if (initial_skpr_gain != -EINVAL) {
249888cbad341d2dd920ac74c2296f319482bd53a33dJean-Michel Trivi                        ramp_speaker_gain(adev, true /*ramp_up*/, initial_skpr_gain);
249988cbad341d2dd920ac74c2296f319482bd53a33dJean-Michel Trivi                    }
25001f60cf8ce4276473878a22956ae546911353ebd2Ravi Kumar Alamanda                } else {
2501425e154c046554deb7ba766e89b943e8870ee251Ravi Kumar Alamanda                    const char *mixer_path;
2502425e154c046554deb7ba766e89b943e8870ee251Ravi Kumar Alamanda                    if (swap_channels) {
2503425e154c046554deb7ba766e89b943e8870ee251Ravi Kumar Alamanda                        mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER_REVERSE);
2504425e154c046554deb7ba766e89b943e8870ee251Ravi Kumar Alamanda                        audio_route_apply_and_update_path(adev->audio_route, mixer_path);
2505425e154c046554deb7ba766e89b943e8870ee251Ravi Kumar Alamanda                    } else {
2506425e154c046554deb7ba766e89b943e8870ee251Ravi Kumar Alamanda                        mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER);
2507425e154c046554deb7ba766e89b943e8870ee251Ravi Kumar Alamanda                        audio_route_apply_and_update_path(adev->audio_route, mixer_path);
2508425e154c046554deb7ba766e89b943e8870ee251Ravi Kumar Alamanda                    }
25091f60cf8ce4276473878a22956ae546911353ebd2Ravi Kumar Alamanda                }
25101f60cf8ce4276473878a22956ae546911353ebd2Ravi Kumar Alamanda                break;
25111f60cf8ce4276473878a22956ae546911353ebd2Ravi Kumar Alamanda            }
25121f60cf8ce4276473878a22956ae546911353ebd2Ravi Kumar Alamanda        }
25131f60cf8ce4276473878a22956ae546911353ebd2Ravi Kumar Alamanda    }
25141f60cf8ce4276473878a22956ae546911353ebd2Ravi Kumar Alamanda    return 0;
25151f60cf8ce4276473878a22956ae546911353ebd2Ravi Kumar Alamanda}
2516