blob: 3bfa405b0d4e31ee9a1e1bc7cf05b2b506e8dbb8 [file] [log] [blame]
Naresh Tannirue3b18452014-03-04 14:44:27 +05301/*
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302 * Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
3 * Not a Contribution.
4 *
Naresh Tannirue3b18452014-03-04 14:44:27 +05305 * Copyright (C) 2013 The Android Open Source Project
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19
Naresh Tannirudb72d1e2014-03-05 17:33:47 +053020#define LOG_TAG "msm8916_platform"
Naresh Tannirue3b18452014-03-04 14:44:27 +053021/*#define LOG_NDEBUG 0*/
22#define LOG_NDDEBUG 0
23
24#include <stdlib.h>
25#include <dlfcn.h>
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +053026#include <fcntl.h>
Vidyakumar Athota21b3bb92014-04-25 11:08:08 -070027#include <sys/ioctl.h>
Naresh Tannirue3b18452014-03-04 14:44:27 +053028#include <cutils/log.h>
29#include <cutils/properties.h>
Naresh Tannirudb72d1e2014-03-05 17:33:47 +053030#include <cutils/str_parms.h>
Naresh Tannirue3b18452014-03-04 14:44:27 +053031#include <audio_hw.h>
32#include <platform_api.h>
33#include "platform.h"
Naresh Tannirudb72d1e2014-03-05 17:33:47 +053034#include "audio_extn.h"
35#include "voice_extn.h"
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +053036#include "sound/msmcal-hwdep.h"
37#define SOUND_TRIGGER_DEVICE_HANDSET_MONO_LOW_POWER_ACDB_ID (100)
Naresh Tannirue3b18452014-03-04 14:44:27 +053038
Naresh Tannirudb72d1e2014-03-05 17:33:47 +053039#define MIXER_XML_PATH "/system/etc/mixer_paths.xml"
Asish Bhattacharya4ff24802014-04-24 17:46:54 +053040#define MIXER_XML_PATH_MTP "/system/etc/mixer_paths_mtp.xml"
Walter Yang7ca90d92014-05-06 17:48:02 +080041#define MIXER_XML_PATH_QRD_SKUH "/system/etc/mixer_paths_qrd_skuh.xml"
42#define MIXER_XML_PATH_QRD_SKUI "/system/etc/mixer_paths_qrd_skui.xml"
Walter Yang19f244a2014-06-17 13:30:08 +080043#define MIXER_XML_PATH_QRD_SKUHF "/system/etc/mixer_paths_qrd_skuhf.xml"
Meng Wangf00485b2014-06-03 19:44:38 +080044#define MIXER_XML_PATH_SKUK "/system/etc/mixer_paths_skuk.xml"
45#define MIXER_XML_PATH_AUXPCM "/system/etc/mixer_paths_auxpcm.xml"
Naresh Tannirudb72d1e2014-03-05 17:33:47 +053046#define MIXER_XML_PATH_AUXPCM "/system/etc/mixer_paths_auxpcm.xml"
Asish Bhattacharyacb8e6d02014-06-19 12:32:25 +053047#define MIXER_XML_PATH_WCD9306 "/system/etc/mixer_paths_wcd9306.xml"
Aviral Gupta8ed0eec2014-08-25 10:22:11 +053048#define MIXER_XML_PATH_WCD9330 "/system/etc/mixer_paths_wcd9330.xml"
Naresh Tannirudb72d1e2014-03-05 17:33:47 +053049#define PLATFORM_INFO_XML_PATH "/system/etc/audio_platform_info.xml"
Naresh Tannirue3b18452014-03-04 14:44:27 +053050#define LIB_ACDB_LOADER "libacdbloader.so"
Naresh Tannirudb72d1e2014-03-05 17:33:47 +053051#define AUDIO_DATA_BLOCK_MIXER_CTL "HDMI EDID"
Avinash Vaish71c066d2014-08-27 12:32:35 +053052#define CVD_VERSION_MIXER_CTL "CVD Version"
Naresh Tannirue3b18452014-03-04 14:44:27 +053053
Naresh Tannirudb72d1e2014-03-05 17:33:47 +053054#define MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE (256 * 1024)
55#define MIN_COMPRESS_OFFLOAD_FRAGMENT_SIZE (2 * 1024)
56#define COMPRESS_OFFLOAD_FRAGMENT_SIZE_FOR_AV_STREAMING (2 * 1024)
57#define COMPRESS_OFFLOAD_FRAGMENT_SIZE (32 * 1024)
58/* Used in calculating fragment size for pcm offload */
59#define PCM_OFFLOAD_BUFFER_DURATION_FOR_AV 2000 /* 2 secs */
60#define PCM_OFFLOAD_BUFFER_DURATION_FOR_AV_STREAMING 100 /* 100 millisecs */
Naresh Tannirue3b18452014-03-04 14:44:27 +053061
Naresh Tannirudb72d1e2014-03-05 17:33:47 +053062/* MAX PCM fragment size cannot be increased further due
63 * to flinger's cblk size of 1mb,and it has to be a multiple of
64 * 24 - lcm of channels supported by DSP
Naresh Tannirue3b18452014-03-04 14:44:27 +053065 */
Naresh Tannirudb72d1e2014-03-05 17:33:47 +053066#define MAX_PCM_OFFLOAD_FRAGMENT_SIZE (240 * 1024)
67#define MIN_PCM_OFFLOAD_FRAGMENT_SIZE (32 * 1024)
Naresh Tannirue3b18452014-03-04 14:44:27 +053068
Naresh Tannirudb72d1e2014-03-05 17:33:47 +053069#define ALIGN( num, to ) (((num) + (to-1)) & (~(to-1)))
Naresh Tannirue3b18452014-03-04 14:44:27 +053070/*
71 * This file will have a maximum of 38 bytes:
72 *
73 * 4 bytes: number of audio blocks
74 * 4 bytes: total length of Short Audio Descriptor (SAD) blocks
75 * Maximum 10 * 3 bytes: SAD blocks
76 */
77#define MAX_SAD_BLOCKS 10
78#define SAD_BLOCK_SIZE 3
Avinash Vaish71c066d2014-08-27 12:32:35 +053079#define MAX_CVD_VERSION_STRING_SIZE 100
Naresh Tannirue3b18452014-03-04 14:44:27 +053080
81/* EDID format ID for LPCM audio */
82#define EDID_FORMAT_LPCM 1
83
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -070084/* fallback app type if the default app type from acdb loader fails */
85#define DEFAULT_APP_TYPE 0x11130
86
Naresh Tannirudb72d1e2014-03-05 17:33:47 +053087/* Retry for delay in FW loading*/
88#define RETRY_NUMBER 20
89#define RETRY_US 500000
90#define MAX_SND_CARD 8
91
92#define SAMPLE_RATE_8KHZ 8000
93#define SAMPLE_RATE_16KHZ 16000
94
95#define AUDIO_PARAMETER_KEY_FLUENCE_TYPE "fluence"
Naresh Tannirudb72d1e2014-03-05 17:33:47 +053096#define AUDIO_PARAMETER_KEY_SLOWTALK "st_enable"
Avinash Vaishd5fa4572014-09-15 14:41:14 +053097#define AUDIO_PARAMETER_KEY_HD_VOICE "hd_voice"
Naresh Tannirudb72d1e2014-03-05 17:33:47 +053098#define AUDIO_PARAMETER_KEY_VOLUME_BOOST "volume_boost"
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +053099#define MAX_CAL_NAME 20
100
101char cal_name_info[WCD9XXX_MAX_CAL][MAX_CAL_NAME] = {
102 [WCD9XXX_ANC_CAL] = "anc_cal",
103 [WCD9XXX_MBHC_CAL] = "mbhc_cal",
104 [WCD9XXX_MAD_CAL] = "mad_cal",
105};
106
Naresh Tanniruc0517bc2014-10-26 15:30:55 +0530107#define AUDIO_PARAMETER_KEY_REC_PLAY_CONC "rec_play_conc_on"
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530108
109enum {
110 VOICE_FEATURE_SET_DEFAULT,
111 VOICE_FEATURE_SET_VOLUME_BOOST
112};
113
Naresh Tannirue3b18452014-03-04 14:44:27 +0530114struct audio_block_header
115{
116 int reserved;
117 int length;
118};
119
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530120/* Audio calibration related functions */
Naresh Tannirue3b18452014-03-04 14:44:27 +0530121typedef void (*acdb_deallocate_t)();
Avinash Vaish71c066d2014-08-27 12:32:35 +0530122typedef int (*acdb_init_t)(char *, char *);
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -0700123typedef void (*acdb_send_audio_cal_t)(int, int, int, int);
Naresh Tannirue3b18452014-03-04 14:44:27 +0530124typedef void (*acdb_send_voice_cal_t)(int, int);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530125typedef int (*acdb_reload_vocvoltable_t)(int);
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -0700126typedef int (*acdb_get_default_app_type_t)(void);
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +0530127typedef int (*acdb_loader_get_calibration_t)(char *attr, int size, void *data);
128acdb_loader_get_calibration_t acdb_loader_get_calibration;
Naresh Tannirue3b18452014-03-04 14:44:27 +0530129
Naresh Tannirue3b18452014-03-04 14:44:27 +0530130struct platform_data {
131 struct audio_device *adev;
132 bool fluence_in_spkr_mode;
133 bool fluence_in_voice_call;
134 bool fluence_in_voice_rec;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530135 bool fluence_in_audio_rec;
136 int fluence_type;
Venkata Narendra Kumar Gutta88fd0bc2014-03-27 19:47:56 +0530137 char fluence_cap[PROPERTY_VALUE_MAX];
Karthik Reddy Kattad9fff862014-07-21 21:07:21 +0530138 int fluence_mode;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530139 bool slowtalk;
Avinash Vaishd5fa4572014-09-15 14:41:14 +0530140 bool hd_voice;
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +0530141 bool ec_ref_enabled;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530142 /* Audio calibration related functions */
143 void *acdb_handle;
144 int voice_feature_set;
145 acdb_init_t acdb_init;
146 acdb_deallocate_t acdb_deallocate;
147 acdb_send_audio_cal_t acdb_send_audio_cal;
148 acdb_send_voice_cal_t acdb_send_voice_cal;
149 acdb_reload_vocvoltable_t acdb_reload_vocvoltable;
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -0700150 acdb_get_default_app_type_t acdb_get_default_app_type;
Naresh Tanniruc0517bc2014-10-26 15:30:55 +0530151#ifdef RECORD_PLAY_CONCURRENCY
152 bool rec_play_conc_set;
153#endif
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530154 void *hw_info;
155 struct csd_data *csd;
Naresh Tannirue3b18452014-03-04 14:44:27 +0530156};
157
158static const int pcm_device_table[AUDIO_USECASE_MAX][2] = {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530159 [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = {DEEP_BUFFER_PCM_DEVICE,
160 DEEP_BUFFER_PCM_DEVICE},
161 [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
162 LOWLATENCY_PCM_DEVICE},
163 [USECASE_AUDIO_PLAYBACK_MULTI_CH] = {MULTIMEDIA2_PCM_DEVICE,
164 MULTIMEDIA2_PCM_DEVICE},
165 [USECASE_AUDIO_PLAYBACK_OFFLOAD] =
166 {PLAYBACK_OFFLOAD_DEVICE, PLAYBACK_OFFLOAD_DEVICE},
167 [USECASE_AUDIO_RECORD] = {AUDIO_RECORD_PCM_DEVICE, AUDIO_RECORD_PCM_DEVICE},
168 [USECASE_AUDIO_RECORD_COMPRESS] = {COMPRESS_CAPTURE_DEVICE, COMPRESS_CAPTURE_DEVICE},
169 [USECASE_AUDIO_RECORD_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
170 LOWLATENCY_PCM_DEVICE},
171 [USECASE_AUDIO_RECORD_FM_VIRTUAL] = {MULTIMEDIA2_PCM_DEVICE,
172 MULTIMEDIA2_PCM_DEVICE},
173 [USECASE_AUDIO_PLAYBACK_FM] = {FM_PLAYBACK_PCM_DEVICE, FM_CAPTURE_PCM_DEVICE},
174 [USECASE_AUDIO_HFP_SCO] = {HFP_PCM_RX, HFP_SCO_RX},
175 [USECASE_AUDIO_HFP_SCO_WB] = {HFP_PCM_RX, HFP_SCO_RX},
176 [USECASE_VOICE_CALL] = {VOICE_CALL_PCM_DEVICE, VOICE_CALL_PCM_DEVICE},
177 [USECASE_VOICE2_CALL] = {VOICE2_CALL_PCM_DEVICE, VOICE2_CALL_PCM_DEVICE},
178 [USECASE_VOLTE_CALL] = {VOLTE_CALL_PCM_DEVICE, VOLTE_CALL_PCM_DEVICE},
179 [USECASE_QCHAT_CALL] = {QCHAT_CALL_PCM_DEVICE, QCHAT_CALL_PCM_DEVICE},
Karthik Reddy Katta3b0a60c2014-04-06 14:52:37 +0530180 [USECASE_VOWLAN_CALL] = {VOWLAN_CALL_PCM_DEVICE, VOWLAN_CALL_PCM_DEVICE},
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530181 [USECASE_COMPRESS_VOIP_CALL] = {COMPRESS_VOIP_CALL_PCM_DEVICE, COMPRESS_VOIP_CALL_PCM_DEVICE},
182 [USECASE_INCALL_REC_UPLINK] = {AUDIO_RECORD_PCM_DEVICE,
183 AUDIO_RECORD_PCM_DEVICE},
184 [USECASE_INCALL_REC_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
185 AUDIO_RECORD_PCM_DEVICE},
186 [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
187 AUDIO_RECORD_PCM_DEVICE},
188 [USECASE_INCALL_REC_UPLINK_COMPRESS] = {COMPRESS_CAPTURE_DEVICE,
189 COMPRESS_CAPTURE_DEVICE},
190 [USECASE_INCALL_REC_DOWNLINK_COMPRESS] = {COMPRESS_CAPTURE_DEVICE,
191 COMPRESS_CAPTURE_DEVICE},
192 [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK_COMPRESS] = {COMPRESS_CAPTURE_DEVICE,
193 COMPRESS_CAPTURE_DEVICE},
194 [USECASE_INCALL_MUSIC_UPLINK] = {INCALL_MUSIC_UPLINK_PCM_DEVICE,
195 INCALL_MUSIC_UPLINK_PCM_DEVICE},
196 [USECASE_INCALL_MUSIC_UPLINK2] = {INCALL_MUSIC_UPLINK2_PCM_DEVICE,
197 INCALL_MUSIC_UPLINK2_PCM_DEVICE},
198 [USECASE_AUDIO_SPKR_CALIB_RX] = {SPKR_PROT_CALIB_RX_PCM_DEVICE, -1},
199 [USECASE_AUDIO_SPKR_CALIB_TX] = {-1, SPKR_PROT_CALIB_TX_PCM_DEVICE},
Naresh Tannirue3b18452014-03-04 14:44:27 +0530200};
201
202/* Array to store sound devices */
203static const char * const device_table[SND_DEVICE_MAX] = {
204 [SND_DEVICE_NONE] = "none",
205 /* Playback sound devices */
206 [SND_DEVICE_OUT_HANDSET] = "handset",
207 [SND_DEVICE_OUT_SPEAKER] = "speaker",
208 [SND_DEVICE_OUT_SPEAKER_REVERSE] = "speaker-reverse",
209 [SND_DEVICE_OUT_HEADPHONES] = "headphones",
210 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones",
211 [SND_DEVICE_OUT_VOICE_HANDSET] = "voice-handset",
212 [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker",
213 [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones",
214 [SND_DEVICE_OUT_HDMI] = "hdmi",
215 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi",
216 [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530217 [SND_DEVICE_OUT_BT_SCO_WB] = "bt-sco-headset-wb",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530218 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones",
219 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones",
220 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530221 [SND_DEVICE_OUT_AFE_PROXY] = "afe-proxy",
222 [SND_DEVICE_OUT_USB_HEADSET] = "usb-headphones",
223 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = "speaker-and-usb-headphones",
224 [SND_DEVICE_OUT_TRANSMISSION_FM] = "transmission-fm",
225 [SND_DEVICE_OUT_ANC_HEADSET] = "anc-headphones",
226 [SND_DEVICE_OUT_ANC_FB_HEADSET] = "anc-fb-headphones",
227 [SND_DEVICE_OUT_VOICE_ANC_HEADSET] = "voice-anc-headphones",
228 [SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET] = "voice-anc-fb-headphones",
229 [SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET] = "speaker-and-anc-headphones",
230 [SND_DEVICE_OUT_ANC_HANDSET] = "anc-handset",
231 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = "speaker-protected",
Naresh Tanniruc0517bc2014-10-26 15:30:55 +0530232#ifdef RECORD_PLAY_CONCURRENCY
233 [SND_DEVICE_OUT_VOIP_HANDSET] = "voip-handset",
234 [SND_DEVICE_OUT_VOIP_SPEAKER] = "voip-speaker",
235 [SND_DEVICE_OUT_VOIP_HEADPHONES] = "voip-headphones",
236#endif
Naresh Tannirue3b18452014-03-04 14:44:27 +0530237
238 /* Capture sound devices */
239 [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530240 [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530241 [SND_DEVICE_IN_HANDSET_MIC_NS] = "handset-mic",
242 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = "handset-mic",
243 [SND_DEVICE_IN_HANDSET_DMIC] = "dmic-endfire",
244 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = "dmic-endfire",
245 [SND_DEVICE_IN_HANDSET_DMIC_NS] = "dmic-endfire",
246 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = "dmic-endfire",
247 [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
248 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "speaker-mic",
249 [SND_DEVICE_IN_SPEAKER_MIC_NS] = "speaker-mic",
250 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = "speaker-mic",
251 [SND_DEVICE_IN_SPEAKER_DMIC] = "speaker-dmic-endfire",
252 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = "speaker-dmic-endfire",
253 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = "speaker-dmic-endfire",
254 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = "speaker-dmic-endfire",
255 [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
256 [SND_DEVICE_IN_HEADSET_MIC_FLUENCE] = "headset-mic",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530257 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
258 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
259 [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic",
260 [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
Vicky Sehrawate240e5d2014-08-12 17:17:04 -0700261 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = "bt-sco-mic",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530262 [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb",
Vicky Sehrawate240e5d2014-08-12 17:17:04 -0700263 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = "bt-sco-mic-wb",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530264 [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530265 [SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef",
266 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = "voice-speaker-dmic-ef",
267 [SND_DEVICE_IN_VOICE_SPEAKER_QMIC] = "voice-speaker-qmic",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530268 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
269 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
270 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
271 [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530272 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = "voice-rec-mic",
273 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = "voice-rec-dmic-ef",
274 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence",
275 [SND_DEVICE_IN_USB_HEADSET_MIC] = "usb-headset-mic",
276 [SND_DEVICE_IN_CAPTURE_FM] = "capture-fm",
277 [SND_DEVICE_IN_AANC_HANDSET_MIC] = "aanc-handset-mic",
278 [SND_DEVICE_IN_QUAD_MIC] = "quad-mic",
279 [SND_DEVICE_IN_HANDSET_STEREO_DMIC] = "handset-stereo-dmic-ef",
280 [SND_DEVICE_IN_SPEAKER_STEREO_DMIC] = "speaker-stereo-dmic-ef",
281 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = "vi-feedback",
Karthik Reddy Kattad9fff862014-07-21 21:07:21 +0530282 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BROADSIDE] = "voice-speaker-dmic-broadside",
283 [SND_DEVICE_IN_SPEAKER_DMIC_BROADSIDE] = "speaker-dmic-broadside",
284 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_BROADSIDE] = "speaker-dmic-broadside",
285 [SND_DEVICE_IN_SPEAKER_DMIC_NS_BROADSIDE] = "speaker-dmic-broadside",
286 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_BROADSIDE] = "speaker-dmic-broadside",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530287};
288
289/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530290static int acdb_device_table[SND_DEVICE_MAX] = {
Naresh Tannirue3b18452014-03-04 14:44:27 +0530291 [SND_DEVICE_NONE] = -1,
292 [SND_DEVICE_OUT_HANDSET] = 7,
Srikanth Uyyalaa675cd12014-10-15 14:48:11 +0530293 [SND_DEVICE_OUT_SPEAKER] = 14,
294 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 14,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530295 [SND_DEVICE_OUT_HEADPHONES] = 10,
296 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
297 [SND_DEVICE_OUT_VOICE_HANDSET] = 7,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530298 [SND_DEVICE_OUT_VOICE_SPEAKER] = 14,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530299 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
300 [SND_DEVICE_OUT_HDMI] = 18,
Srikanth Uyyalaa675cd12014-10-15 14:48:11 +0530301 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 14,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530302 [SND_DEVICE_OUT_BT_SCO] = 22,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530303 [SND_DEVICE_OUT_BT_SCO_WB] = 39,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530304 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
305 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
306 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530307 [SND_DEVICE_OUT_AFE_PROXY] = 0,
308 [SND_DEVICE_OUT_USB_HEADSET] = 45,
Srikanth Uyyalaa675cd12014-10-15 14:48:11 +0530309 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = 14,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530310 [SND_DEVICE_OUT_TRANSMISSION_FM] = 0,
311 [SND_DEVICE_OUT_ANC_HEADSET] = 26,
312 [SND_DEVICE_OUT_ANC_FB_HEADSET] = 27,
313 [SND_DEVICE_OUT_VOICE_ANC_HEADSET] = 26,
314 [SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET] = 27,
315 [SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET] = 26,
316 [SND_DEVICE_OUT_ANC_HANDSET] = 103,
317 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = 101,
Naresh Tanniruc0517bc2014-10-26 15:30:55 +0530318#ifdef RECORD_PLAY_CONCURRENCY
319 [SND_DEVICE_OUT_VOIP_HANDSET] = 133,
320 [SND_DEVICE_OUT_VOIP_SPEAKER] = 132,
321 [SND_DEVICE_OUT_VOIP_HEADPHONES] = 134,
322#endif
Naresh Tannirue3b18452014-03-04 14:44:27 +0530323
324 [SND_DEVICE_IN_HANDSET_MIC] = 4,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530325 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 106,
326 [SND_DEVICE_IN_HANDSET_MIC_NS] = 107,
327 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = 108,
328 [SND_DEVICE_IN_HANDSET_DMIC] = 41,
329 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = 109,
330 [SND_DEVICE_IN_HANDSET_DMIC_NS] = 110,
331 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = 111,
332 [SND_DEVICE_IN_SPEAKER_MIC] = 11,
333 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 112,
334 [SND_DEVICE_IN_SPEAKER_MIC_NS] = 113,
335 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = 114,
336 [SND_DEVICE_IN_SPEAKER_DMIC] = 43,
337 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = 115,
338 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = 116,
339 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = 117,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530340 [SND_DEVICE_IN_HEADSET_MIC] = 8,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530341 [SND_DEVICE_IN_HEADSET_MIC_FLUENCE] = 47,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530342 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
343 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = 8,
344 [SND_DEVICE_IN_HDMI_MIC] = 4,
345 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
Vicky Sehrawate240e5d2014-08-12 17:17:04 -0700346 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = 122,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530347 [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38,
Vicky Sehrawate240e5d2014-08-12 17:17:04 -0700348 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = 123,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530349 [SND_DEVICE_IN_CAMCORDER_MIC] = 4,
350 [SND_DEVICE_IN_VOICE_DMIC] = 41,
351 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 43,
352 [SND_DEVICE_IN_VOICE_SPEAKER_QMIC] = 19,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530353 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
354 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
355 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530356 [SND_DEVICE_IN_VOICE_REC_MIC] = 4,
357 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = 107,
358 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = 34,
359 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 41,
360 [SND_DEVICE_IN_USB_HEADSET_MIC] = 44,
361 [SND_DEVICE_IN_CAPTURE_FM] = 0,
362 [SND_DEVICE_IN_AANC_HANDSET_MIC] = 104,
363 [SND_DEVICE_IN_QUAD_MIC] = 46,
364 [SND_DEVICE_IN_HANDSET_STEREO_DMIC] = 34,
365 [SND_DEVICE_IN_SPEAKER_STEREO_DMIC] = 35,
366 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = 102,
Karthik Reddy Kattad9fff862014-07-21 21:07:21 +0530367 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BROADSIDE] = 12,
368 [SND_DEVICE_IN_SPEAKER_DMIC_BROADSIDE] = 12,
369 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_BROADSIDE] = 119,
370 [SND_DEVICE_IN_SPEAKER_DMIC_NS_BROADSIDE] = 121,
371 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_BROADSIDE] = 120,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530372};
373
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530374struct snd_device_index {
375 char name[100];
376 unsigned int index;
377};
Naresh Tannirue3b18452014-03-04 14:44:27 +0530378
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530379#define TO_NAME_INDEX(X) #X, X
Naresh Tannirue3b18452014-03-04 14:44:27 +0530380
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530381/* Used to get index from parsed sting */
382struct snd_device_index snd_device_name_index[SND_DEVICE_MAX] = {
383 {TO_NAME_INDEX(SND_DEVICE_OUT_HANDSET)},
384 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER)},
385 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_REVERSE)},
386 {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES)},
387 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES)},
388 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET)},
389 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER)},
390 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADPHONES)},
391 {TO_NAME_INDEX(SND_DEVICE_OUT_HDMI)},
392 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HDMI)},
393 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO)},
394 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO_WB)},
395 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES)},
396 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES)},
397 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET)},
398 {TO_NAME_INDEX(SND_DEVICE_OUT_AFE_PROXY)},
399 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADSET)},
400 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET)},
401 {TO_NAME_INDEX(SND_DEVICE_OUT_TRANSMISSION_FM)},
402 {TO_NAME_INDEX(SND_DEVICE_OUT_ANC_HEADSET)},
403 {TO_NAME_INDEX(SND_DEVICE_OUT_ANC_FB_HEADSET)},
404 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_ANC_HEADSET)},
405 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET)},
406 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET)},
407 {TO_NAME_INDEX(SND_DEVICE_OUT_ANC_HANDSET)},
408 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED)},
Naresh Tanniruc0517bc2014-10-26 15:30:55 +0530409#ifdef RECORD_PLAY_CONCURRENCY
410 {TO_NAME_INDEX(SND_DEVICE_OUT_VOIP_HANDSET)},
411 {TO_NAME_INDEX(SND_DEVICE_OUT_VOIP_SPEAKER)},
412 {TO_NAME_INDEX(SND_DEVICE_OUT_VOIP_HEADPHONES)},
413#endif
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530414 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC)},
415 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC)},
416 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_NS)},
417 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)},
418 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC)},
419 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC)},
420 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_NS)},
421 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)},
422 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC)},
423 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC)},
424 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_NS)},
425 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)},
426 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC)},
427 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC)},
428 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS)},
429 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)},
430 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC)},
431 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC_FLUENCE)},
432 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC)},
433 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEADSET_MIC)},
434 {TO_NAME_INDEX(SND_DEVICE_IN_HDMI_MIC)},
435 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC)},
Vicky Sehrawate240e5d2014-08-12 17:17:04 -0700436 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_NREC)},
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530437 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB)},
Vicky Sehrawate240e5d2014-08-12 17:17:04 -0700438 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB_NREC)},
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530439 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_MIC)},
440 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC)},
441 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC)},
442 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_QMIC)},
443 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC)},
444 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC)},
445 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC)},
446 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC)},
447 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_NS)},
448 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_STEREO)},
449 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE)},
450 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC)},
451 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_FM)},
452 {TO_NAME_INDEX(SND_DEVICE_IN_AANC_HANDSET_MIC)},
453 {TO_NAME_INDEX(SND_DEVICE_IN_QUAD_MIC)},
454 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_STEREO_DMIC)},
455 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_STEREO_DMIC)},
456 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_VI_FEEDBACK)},
457};
458
459#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
460#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
Naresh Tannirue3b18452014-03-04 14:44:27 +0530461
Asish Bhattacharya4ff24802014-04-24 17:46:54 +0530462static void query_platform(const char *snd_card_name,
463 char *mixer_xml_path)
464{
465 if (!strncmp(snd_card_name, "msm8x16-snd-card-mtp",
466 sizeof("msm8x16-snd-card-mtp"))) {
467 strlcpy(mixer_xml_path, MIXER_XML_PATH_MTP,
468 sizeof(MIXER_XML_PATH_MTP));
Walter Yang7ca90d92014-05-06 17:48:02 +0800469 } else if (!strncmp(snd_card_name, "msm8x16-skuh-snd-card",
470 sizeof("msm8x16-skuh-snd-card"))) {
471 strlcpy(mixer_xml_path, MIXER_XML_PATH_QRD_SKUH,
472 sizeof(MIXER_XML_PATH_QRD_SKUH));
473 } else if (!strncmp(snd_card_name, "msm8x16-skui-snd-card",
474 sizeof("msm8x16-skui-snd-card"))) {
475 strlcpy(mixer_xml_path, MIXER_XML_PATH_QRD_SKUI,
476 sizeof(MIXER_XML_PATH_QRD_SKUI));
Walter Yang19f244a2014-06-17 13:30:08 +0800477 } else if (!strncmp(snd_card_name, "msm8x16-skuhf-snd-card",
478 sizeof("msm8x16-skuhf-snd-card"))) {
479 strlcpy(mixer_xml_path, MIXER_XML_PATH_QRD_SKUHF,
480 sizeof(MIXER_XML_PATH_QRD_SKUHF));
Walter Yangc899d572014-05-27 21:52:17 +0800481 } else if (!strncmp(snd_card_name, "msm8939-snd-card-mtp",
Yamit Mehtac6003e22014-05-19 10:26:02 +0530482 sizeof("msm8939-snd-card-mtp"))) {
Aravind Kumar71ba22b2014-06-23 15:18:50 +0530483 strlcpy(mixer_xml_path, MIXER_XML_PATH_MTP,
484 sizeof(MIXER_XML_PATH_MTP));
Meng Wangf00485b2014-06-03 19:44:38 +0800485 } else if (!strncmp(snd_card_name, "msm8939-snd-card-skuk",
486 sizeof("msm8939-snd-card-skuk"))) {
487 strlcpy(mixer_xml_path, MIXER_XML_PATH_SKUK,
488 sizeof(MIXER_XML_PATH_SKUK));
Asish Bhattacharyacb8e6d02014-06-19 12:32:25 +0530489 } else if (!strncmp(snd_card_name, "msm8939-tapan-snd-card",
490 sizeof("msm8939-tapan-snd-card"))) {
491 strlcpy(mixer_xml_path, MIXER_XML_PATH_WCD9306,
492 sizeof(MIXER_XML_PATH_WCD9306));
493 } else if (!strncmp(snd_card_name, "msm8939-tapan9302-snd-card",
494 sizeof("msm8939-tapan9302-snd-card"))) {
495 strlcpy(mixer_xml_path, MIXER_XML_PATH_WCD9306,
496 sizeof(MIXER_XML_PATH_WCD9306));
Aviral Gupta8ed0eec2014-08-25 10:22:11 +0530497 } else if (!strncmp(snd_card_name, "msm8939-tomtom9330-snd-card",
498 sizeof("msm8939-tomtom9330-snd-card"))) {
499 strlcpy(mixer_xml_path, MIXER_XML_PATH_WCD9330,
500 sizeof(MIXER_XML_PATH_WCD9330));
Asish Bhattacharya4ff24802014-04-24 17:46:54 +0530501 } else {
502 strlcpy(mixer_xml_path, MIXER_XML_PATH,
503 sizeof(MIXER_XML_PATH));
504 }
505}
506
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +0530507void platform_set_echo_reference(void *platform, bool enable)
Naresh Tannirue3b18452014-03-04 14:44:27 +0530508{
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +0530509 struct platform_data *my_data = (struct platform_data *)platform;
510 struct audio_device *adev = my_data->adev;
Naresh Tannirue3b18452014-03-04 14:44:27 +0530511
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +0530512 if (enable) {
513 my_data->ec_ref_enabled = enable;
514 audio_route_apply_and_update_path(adev->audio_route, "echo-reference");
515 } else {
516 if (my_data->ec_ref_enabled) {
517 audio_route_reset_and_update_path(adev->audio_route, "echo-reference");
518 my_data->ec_ref_enabled = enable;
519 } else {
520 ALOGV("EC reference is already disabled : %d", my_data->ec_ref_enabled);
521 }
522 }
Venkata Narendra Kumar Gutta3fa54c72014-08-18 18:02:21 +0530523
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +0530524 ALOGV("Setting EC Reference: %d", enable);
Naresh Tannirue3b18452014-03-04 14:44:27 +0530525}
526
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530527static struct csd_data *open_csd_client()
528{
529 struct csd_data *csd = calloc(1, sizeof(struct csd_data));
530
531 csd->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
532 if (csd->csd_client == NULL) {
533 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
534 goto error;
535 } else {
536 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
537
538 csd->deinit = (deinit_t)dlsym(csd->csd_client,
539 "csd_client_deinit");
540 if (csd->deinit == NULL) {
541 ALOGE("%s: dlsym error %s for csd_client_deinit", __func__,
542 dlerror());
543 goto error;
544 }
545 csd->disable_device = (disable_device_t)dlsym(csd->csd_client,
546 "csd_client_disable_device");
547 if (csd->disable_device == NULL) {
548 ALOGE("%s: dlsym error %s for csd_client_disable_device",
549 __func__, dlerror());
550 goto error;
551 }
552 csd->enable_device_config = (enable_device_config_t)dlsym(csd->csd_client,
553 "csd_client_enable_device_config");
554 if (csd->enable_device_config == NULL) {
555 ALOGE("%s: dlsym error %s for csd_client_enable_device_config",
556 __func__, dlerror());
557 goto error;
558 }
559 csd->enable_device = (enable_device_t)dlsym(csd->csd_client,
560 "csd_client_enable_device");
561 if (csd->enable_device == NULL) {
562 ALOGE("%s: dlsym error %s for csd_client_enable_device",
563 __func__, dlerror());
564 goto error;
565 }
566 csd->start_voice = (start_voice_t)dlsym(csd->csd_client,
567 "csd_client_start_voice");
568 if (csd->start_voice == NULL) {
569 ALOGE("%s: dlsym error %s for csd_client_start_voice",
570 __func__, dlerror());
571 goto error;
572 }
573 csd->stop_voice = (stop_voice_t)dlsym(csd->csd_client,
574 "csd_client_stop_voice");
575 if (csd->stop_voice == NULL) {
576 ALOGE("%s: dlsym error %s for csd_client_stop_voice",
577 __func__, dlerror());
578 goto error;
579 }
580 csd->volume = (volume_t)dlsym(csd->csd_client,
581 "csd_client_volume");
582 if (csd->volume == NULL) {
583 ALOGE("%s: dlsym error %s for csd_client_volume",
584 __func__, dlerror());
585 goto error;
586 }
587 csd->mic_mute = (mic_mute_t)dlsym(csd->csd_client,
588 "csd_client_mic_mute");
589 if (csd->mic_mute == NULL) {
590 ALOGE("%s: dlsym error %s for csd_client_mic_mute",
591 __func__, dlerror());
592 goto error;
593 }
594 csd->slow_talk = (slow_talk_t)dlsym(csd->csd_client,
595 "csd_client_slow_talk");
596 if (csd->slow_talk == NULL) {
597 ALOGE("%s: dlsym error %s for csd_client_slow_talk",
598 __func__, dlerror());
599 goto error;
600 }
601 csd->start_playback = (start_playback_t)dlsym(csd->csd_client,
602 "csd_client_start_playback");
603 if (csd->start_playback == NULL) {
604 ALOGE("%s: dlsym error %s for csd_client_start_playback",
605 __func__, dlerror());
606 goto error;
607 }
608 csd->stop_playback = (stop_playback_t)dlsym(csd->csd_client,
609 "csd_client_stop_playback");
610 if (csd->stop_playback == NULL) {
611 ALOGE("%s: dlsym error %s for csd_client_stop_playback",
612 __func__, dlerror());
613 goto error;
614 }
Vidyakumar Athota21b3bb92014-04-25 11:08:08 -0700615 csd->set_lch = (set_lch_t)dlsym(csd->csd_client, "csd_client_set_lch");
616 if (csd->set_lch == NULL) {
617 ALOGE("%s: dlsym error %s for csd_client_set_lch",
618 __func__, dlerror());
619 /* Ignore the error as this is not mandatory function for
620 * basic voice call to work.
621 */
622 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530623 csd->start_record = (start_record_t)dlsym(csd->csd_client,
624 "csd_client_start_record");
625 if (csd->start_record == NULL) {
626 ALOGE("%s: dlsym error %s for csd_client_start_record",
627 __func__, dlerror());
628 goto error;
629 }
630 csd->stop_record = (stop_record_t)dlsym(csd->csd_client,
631 "csd_client_stop_record");
632 if (csd->stop_record == NULL) {
633 ALOGE("%s: dlsym error %s for csd_client_stop_record",
634 __func__, dlerror());
635 goto error;
636 }
637 csd->init = (init_t)dlsym(csd->csd_client, "csd_client_init");
638
639 if (csd->init == NULL) {
640 ALOGE("%s: dlsym error %s for csd_client_init",
641 __func__, dlerror());
642 goto error;
643 } else {
644 csd->init();
645 }
646 }
647 return csd;
648
649error:
650 free(csd);
651 csd = NULL;
652 return csd;
653}
654
655void close_csd_client(struct csd_data *csd)
656{
657 if (csd != NULL) {
658 csd->deinit();
659 dlclose(csd->csd_client);
660 free(csd);
661 csd = NULL;
662 }
663}
664
Avinash Vaish71c066d2014-08-27 12:32:35 +0530665void get_cvd_version(char *cvd_version, struct audio_device *adev)
666{
667 struct mixer_ctl *ctl;
668 int count;
669 int ret = 0;
670
671 ctl = mixer_get_ctl_by_name(adev->mixer, CVD_VERSION_MIXER_CTL);
672 if (!ctl) {
673 ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__, CVD_VERSION_MIXER_CTL);
674 goto done;
675 }
676 mixer_ctl_update(ctl);
677
678 count = mixer_ctl_get_num_values(ctl);
679 if (count > MAX_CVD_VERSION_STRING_SIZE)
680 count = MAX_CVD_VERSION_STRING_SIZE;
681
682 ret = mixer_ctl_get_array(ctl, cvd_version, count);
683 if (ret != 0) {
684 ALOGE("%s: ERROR! mixer_ctl_get_array() failed to get CVD Version", __func__);
685 goto done;
686 }
687
688done:
689 return;
690}
691
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +0530692static int hw_util_open(int card_no)
693{
694 int fd = -1;
695 char dev_name[256];
696
697 snprintf(dev_name, sizeof(dev_name), "/dev/snd/hwC%uD%u",
698 card_no, WCD9XXX_CODEC_HWDEP_NODE);
699 ALOGD("%s Opening device %s\n", __func__, dev_name);
700 fd = open(dev_name, O_WRONLY);
701 if (fd < 0) {
702 ALOGE("%s: cannot open device '%s'\n", __func__, dev_name);
703 return fd;
704 }
705 ALOGD("%s success", __func__);
706 return fd;
707}
708
709struct param_data {
710 int use_case;
711 int acdb_id;
712 int get_size;
713 int buff_size;
714 int data_size;
715 void *buff;
716};
717
718static int send_codec_cal(acdb_loader_get_calibration_t acdb_loader_get_calibration, int fd)
719{
720 int ret = 0, type;
721
722 for (type = WCD9XXX_ANC_CAL; type < WCD9XXX_MAX_CAL; type++) {
723 struct wcdcal_ioctl_buffer codec_buffer;
724 struct param_data calib;
725
726 if (!strcmp(cal_name_info[type], "mad_cal"))
727 calib.acdb_id = SOUND_TRIGGER_DEVICE_HANDSET_MONO_LOW_POWER_ACDB_ID;
728 calib.get_size = 1;
729 ret = acdb_loader_get_calibration(cal_name_info[type], sizeof(struct param_data),
730 &calib);
731 if (ret < 0) {
732 ALOGE("%s get_calibration failed\n", __func__);
733 return ret;
734 }
735 calib.get_size = 0;
736 calib.buff = malloc(calib.buff_size);
737 ret = acdb_loader_get_calibration(cal_name_info[type],
738 sizeof(struct param_data), &calib);
739 if (ret < 0) {
740 ALOGE("%s get_calibration failed\n", __func__);
741 free(calib.buff);
742 return ret;
743 }
744 codec_buffer.buffer = calib.buff;
745 codec_buffer.size = calib.data_size;
746 codec_buffer.cal_type = type;
747 if (ioctl(fd, SNDRV_CTL_IOCTL_HWDEP_CAL_TYPE, &codec_buffer) < 0)
748 ALOGE("Failed to call ioctl for %s err=%d",
749 cal_name_info[type], errno);
750 ALOGD("%s cal sent for %s", __func__, cal_name_info[type]);
751 free(calib.buff);
752 }
753 return ret;
754}
755
756static void audio_hwdep_send_cal(struct platform_data *plat_data)
757{
758 int fd;
759
760 fd = hw_util_open(plat_data->adev->snd_card);
761 if (fd == -1) {
762 ALOGE("%s error open\n", __func__);
763 return;
764 }
765
766 acdb_loader_get_calibration = (acdb_loader_get_calibration_t)
767 dlsym(plat_data->acdb_handle, "acdb_loader_get_calibration");
768
769 if (acdb_loader_get_calibration == NULL) {
770 ALOGE("%s: ERROR. dlsym Error:%s acdb_loader_get_calibration", __func__,
771 dlerror());
772 return;
773 }
774 if (send_codec_cal(acdb_loader_get_calibration, fd) < 0)
775 ALOGE("%s: Could not send anc cal", __FUNCTION__);
776}
777
Naresh Tannirue3b18452014-03-04 14:44:27 +0530778void *platform_init(struct audio_device *adev)
779{
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530780 char platform[PROPERTY_VALUE_MAX];
781 char baseband[PROPERTY_VALUE_MAX];
Naresh Tannirue3b18452014-03-04 14:44:27 +0530782 char value[PROPERTY_VALUE_MAX];
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530783 struct platform_data *my_data = NULL;
784 int retry_num = 0, snd_card_num = 0;
785 const char *snd_card_name;
Srikanth Uyyalaa675cd12014-10-15 14:48:11 +0530786 char mixer_xml_path[100],ffspEnable[PROPERTY_VALUE_MAX];
Avinash Vaish71c066d2014-08-27 12:32:35 +0530787 char *cvd_version = NULL;
Naresh Tannirue3b18452014-03-04 14:44:27 +0530788
789 my_data = calloc(1, sizeof(struct platform_data));
790
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530791 while (snd_card_num < MAX_SND_CARD) {
792 adev->mixer = mixer_open(snd_card_num);
793
794 while (!adev->mixer && retry_num < RETRY_NUMBER) {
795 usleep(RETRY_US);
796 adev->mixer = mixer_open(snd_card_num);
797 retry_num++;
798 }
799
800 if (!adev->mixer) {
801 ALOGE("%s: Unable to open the mixer card: %d", __func__,
802 snd_card_num);
803 retry_num = 0;
804 snd_card_num++;
805 continue;
806 }
807
808 snd_card_name = mixer_get_name(adev->mixer);
809 ALOGV("%s: snd_card_name: %s", __func__, snd_card_name);
810
811 my_data->hw_info = hw_info_init(snd_card_name);
812 if (!my_data->hw_info) {
813 ALOGE("%s: Failed to init hardware info", __func__);
814 } else {
Asish Bhattacharya4ff24802014-04-24 17:46:54 +0530815 query_platform(snd_card_name, mixer_xml_path);
816 ALOGD("%s: mixer path file is %s", __func__,
817 mixer_xml_path);
818 if (audio_extn_read_xml(adev, snd_card_num, mixer_xml_path,
819 MIXER_XML_PATH_AUXPCM) == -ENOSYS) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530820 adev->audio_route = audio_route_init(snd_card_num,
Asish Bhattacharya4ff24802014-04-24 17:46:54 +0530821 mixer_xml_path);
822 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530823 if (!adev->audio_route) {
824 ALOGE("%s: Failed to init audio route controls, aborting.",
825 __func__);
826 free(my_data);
827 return NULL;
828 }
829 adev->snd_card = snd_card_num;
830 ALOGD("%s: Opened sound card:%d", __func__, snd_card_num);
831 break;
832 }
833 retry_num = 0;
834 snd_card_num++;
835 }
836
837 if (snd_card_num >= MAX_SND_CARD) {
838 ALOGE("%s: Unable to find correct sound card, aborting.", __func__);
839 free(my_data);
840 return NULL;
841 }
842
Naresh Tannirue3b18452014-03-04 14:44:27 +0530843 my_data->adev = adev;
Naresh Tannirue3b18452014-03-04 14:44:27 +0530844 my_data->fluence_in_spkr_mode = false;
845 my_data->fluence_in_voice_call = false;
846 my_data->fluence_in_voice_rec = false;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530847 my_data->fluence_in_audio_rec = false;
848 my_data->fluence_type = FLUENCE_NONE;
Karthik Reddy Kattad9fff862014-07-21 21:07:21 +0530849 my_data->fluence_mode = FLUENCE_ENDFIRE;
Avinash Vaishd5fa4572014-09-15 14:41:14 +0530850 my_data->slowtalk = false;
851 my_data->hd_voice = false;
Naresh Tannirue3b18452014-03-04 14:44:27 +0530852
Venkata Narendra Kumar Gutta88fd0bc2014-03-27 19:47:56 +0530853 property_get("ro.qc.sdk.audio.fluencetype", my_data->fluence_cap, "");
854 if (!strncmp("fluencepro", my_data->fluence_cap, sizeof("fluencepro"))) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530855 my_data->fluence_type = FLUENCE_QUAD_MIC | FLUENCE_DUAL_MIC;
Venkata Narendra Kumar Gutta88fd0bc2014-03-27 19:47:56 +0530856 } else if (!strncmp("fluence", my_data->fluence_cap, sizeof("fluence"))) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530857 my_data->fluence_type = FLUENCE_DUAL_MIC;
858 } else {
859 my_data->fluence_type = FLUENCE_NONE;
Naresh Tannirue3b18452014-03-04 14:44:27 +0530860 }
861
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530862 if (my_data->fluence_type != FLUENCE_NONE) {
Naresh Tannirue3b18452014-03-04 14:44:27 +0530863 property_get("persist.audio.fluence.voicecall",value,"");
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530864 if (!strncmp("true", value, sizeof("true"))) {
Naresh Tannirue3b18452014-03-04 14:44:27 +0530865 my_data->fluence_in_voice_call = true;
866 }
867
868 property_get("persist.audio.fluence.voicerec",value,"");
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530869 if (!strncmp("true", value, sizeof("true"))) {
Naresh Tannirue3b18452014-03-04 14:44:27 +0530870 my_data->fluence_in_voice_rec = true;
871 }
872
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530873 property_get("persist.audio.fluence.audiorec",value,"");
874 if (!strncmp("true", value, sizeof("true"))) {
875 my_data->fluence_in_audio_rec = true;
876 }
877
Naresh Tannirue3b18452014-03-04 14:44:27 +0530878 property_get("persist.audio.fluence.speaker",value,"");
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530879 if (!strncmp("true", value, sizeof("true"))) {
Naresh Tannirue3b18452014-03-04 14:44:27 +0530880 my_data->fluence_in_spkr_mode = true;
881 }
Karthik Reddy Kattad9fff862014-07-21 21:07:21 +0530882
883 property_get("persist.audio.fluence.mode",value,"");
884 if (!strncmp("broadside", value, sizeof("broadside"))) {
885 my_data->fluence_mode = FLUENCE_BROADSIDE;
886 }
Naresh Tannirue3b18452014-03-04 14:44:27 +0530887 }
Srikanth Uyyalaa675cd12014-10-15 14:48:11 +0530888 property_get("persist.audio.FFSP.enable", ffspEnable, "");
889 if (!strncmp("true", ffspEnable, sizeof("true"))) {
890 acdb_device_table[SND_DEVICE_OUT_SPEAKER] = 131;
891 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE] = 131;
892 acdb_device_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 131;
893 acdb_device_table[SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = 131;
894 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530895 my_data->voice_feature_set = VOICE_FEATURE_SET_DEFAULT;
Naresh Tannirue3b18452014-03-04 14:44:27 +0530896 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
897 if (my_data->acdb_handle == NULL) {
898 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
899 } else {
900 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
901 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
902 "acdb_loader_deallocate_ACDB");
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530903 if (!my_data->acdb_deallocate)
904 ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s",
905 __func__, LIB_ACDB_LOADER);
906
Naresh Tannirue3b18452014-03-04 14:44:27 +0530907 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -0700908 "acdb_loader_send_audio_cal_v2");
Naresh Tannirue3b18452014-03-04 14:44:27 +0530909 if (!my_data->acdb_send_audio_cal)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530910 ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530911 __func__, LIB_ACDB_LOADER);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530912
Naresh Tannirue3b18452014-03-04 14:44:27 +0530913 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
914 "acdb_loader_send_voice_cal");
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530915 if (!my_data->acdb_send_voice_cal)
916 ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s",
917 __func__, LIB_ACDB_LOADER);
918
919 my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle,
920 "acdb_loader_reload_vocvoltable");
921 if (!my_data->acdb_reload_vocvoltable)
922 ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s",
923 __func__, LIB_ACDB_LOADER);
924
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -0700925 my_data->acdb_get_default_app_type = (acdb_get_default_app_type_t)dlsym(
926 my_data->acdb_handle,
927 "acdb_loader_get_default_app_type");
928 if (!my_data->acdb_get_default_app_type)
929 ALOGE("%s: Could not find the symbol acdb_get_default_app_type from %s",
930 __func__, LIB_ACDB_LOADER);
931
Naresh Tannirue3b18452014-03-04 14:44:27 +0530932 my_data->acdb_init = (acdb_init_t)dlsym(my_data->acdb_handle,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530933 "acdb_loader_init_v2");
Avinash Vaish71c066d2014-08-27 12:32:35 +0530934 if (my_data->acdb_init == NULL) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530935 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__, dlerror());
Avinash Vaish71c066d2014-08-27 12:32:35 +0530936 goto acdb_init_fail;
937 }
938
939 cvd_version = calloc(1, MAX_CVD_VERSION_STRING_SIZE);
940 if (!cvd_version)
941 ALOGE("Failed to allocate cvd version");
Naresh Tannirue3b18452014-03-04 14:44:27 +0530942 else
Avinash Vaish71c066d2014-08-27 12:32:35 +0530943 get_cvd_version(cvd_version, adev);
944
945 my_data->acdb_init(snd_card_name, cvd_version);
946 if (cvd_version)
947 free(cvd_version);
Naresh Tannirue3b18452014-03-04 14:44:27 +0530948 }
949
Avinash Vaish71c066d2014-08-27 12:32:35 +0530950acdb_init_fail:
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530951 /* Initialize ACDB ID's */
952 platform_info_init(PLATFORM_INFO_XML_PATH);
953
954 /* init usb */
955 audio_extn_usb_init(adev);
956 /* update sound cards appropriately */
957 audio_extn_usb_set_proxy_sound_card(adev->snd_card);
958
959 /* Read one time ssr property */
960 audio_extn_ssr_update_enabled();
961 audio_extn_spkr_prot_init(adev);
Dhananjay Kumar89ea3bd2014-04-29 15:45:57 +0530962
963 audio_extn_dolby_set_license(adev);
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +0530964 audio_hwdep_send_cal(my_data);
Dhananjay Kumar89ea3bd2014-04-29 15:45:57 +0530965
Naresh Tannirue3b18452014-03-04 14:44:27 +0530966 return my_data;
967}
968
969void platform_deinit(void *platform)
970{
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530971 struct platform_data *my_data = (struct platform_data *)platform;
972
973 hw_info_deinit(my_data->hw_info);
974 close_csd_client(my_data->csd);
975
Naresh Tannirue3b18452014-03-04 14:44:27 +0530976 free(platform);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530977 /* deinit usb */
978 audio_extn_usb_deinit();
Naresh Tannirue3b18452014-03-04 14:44:27 +0530979}
980
981const char *platform_get_snd_device_name(snd_device_t snd_device)
982{
983 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX)
984 return device_table[snd_device];
985 else
986 return "";
987}
988
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530989int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
990 char *device_name)
991{
992 struct platform_data *my_data = (struct platform_data *)platform;
993
994 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
995 strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE);
996 hw_info_append_hw_type(my_data->hw_info, snd_device, device_name);
997 } else {
998 strlcpy(device_name, "", DEVICE_NAME_MAX_SIZE);
999 return -EINVAL;
1000 }
1001
1002 return 0;
1003}
1004
Naresh Tannirue3b18452014-03-04 14:44:27 +05301005void platform_add_backend_name(char *mixer_path, snd_device_t snd_device)
1006{
Vicky Sehrawate240e5d2014-08-12 17:17:04 -07001007 if ((snd_device == SND_DEVICE_IN_BT_SCO_MIC) ||
1008 (snd_device == SND_DEVICE_IN_BT_SCO_MIC_NREC))
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301009 strlcat(mixer_path, " bt-sco", MIXER_PATH_MAX_LENGTH);
Vicky Sehrawate240e5d2014-08-12 17:17:04 -07001010 else if ((snd_device == SND_DEVICE_IN_BT_SCO_MIC_WB) ||
1011 (snd_device == SND_DEVICE_IN_BT_SCO_MIC_WB_NREC))
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301012 strlcat(mixer_path, " bt-sco-wb", MIXER_PATH_MAX_LENGTH);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301013 else if(snd_device == SND_DEVICE_OUT_BT_SCO)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301014 strlcat(mixer_path, " bt-sco", MIXER_PATH_MAX_LENGTH);
1015 else if(snd_device == SND_DEVICE_OUT_BT_SCO_WB)
1016 strlcat(mixer_path, " bt-sco-wb", MIXER_PATH_MAX_LENGTH);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301017 else if (snd_device == SND_DEVICE_OUT_HDMI)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301018 strlcat(mixer_path, " hdmi", MIXER_PATH_MAX_LENGTH);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301019 else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HDMI)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301020 strlcat(mixer_path, " speaker-and-hdmi", MIXER_PATH_MAX_LENGTH);
1021 else if (snd_device == SND_DEVICE_OUT_AFE_PROXY)
1022 strlcat(mixer_path, " afe-proxy", MIXER_PATH_MAX_LENGTH);
1023 else if (snd_device == SND_DEVICE_OUT_USB_HEADSET)
1024 strlcat(mixer_path, " usb-headphones", MIXER_PATH_MAX_LENGTH);
1025 else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET)
1026 strlcat(mixer_path, " speaker-and-usb-headphones",
1027 MIXER_PATH_MAX_LENGTH);
1028 else if (snd_device == SND_DEVICE_IN_USB_HEADSET_MIC)
1029 strlcat(mixer_path, " usb-headset-mic", MIXER_PATH_MAX_LENGTH);
1030 else if (snd_device == SND_DEVICE_IN_CAPTURE_FM)
1031 strlcat(mixer_path, " capture-fm", MIXER_PATH_MAX_LENGTH);
1032 else if (snd_device == SND_DEVICE_OUT_TRANSMISSION_FM)
1033 strlcat(mixer_path, " transmission-fm", MIXER_PATH_MAX_LENGTH);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301034}
1035
1036int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
1037{
1038 int device_id;
1039 if (device_type == PCM_PLAYBACK)
1040 device_id = pcm_device_table[usecase][0];
1041 else
1042 device_id = pcm_device_table[usecase][1];
1043 return device_id;
1044}
1045
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301046int platform_get_snd_device_index(char *snd_device_index_name)
1047{
1048 int ret = 0;
1049 int i;
1050
1051 if (snd_device_index_name == NULL) {
1052 ALOGE("%s: snd_device_index_name is NULL", __func__);
1053 ret = -ENODEV;
1054 goto done;
1055 }
1056
1057 for (i=0; i < SND_DEVICE_MAX; i++) {
1058 if(strcmp(snd_device_name_index[i].name, snd_device_index_name) == 0) {
1059 ret = snd_device_name_index[i].index;
1060 goto done;
1061 }
1062 }
1063 ALOGE("%s: Could not find index for snd_device_index_name = %s",
1064 __func__, snd_device_index_name);
1065 ret = -ENODEV;
1066done:
1067 return ret;
1068}
1069
Venkata Narendra Kumar Gutta88fd0bc2014-03-27 19:47:56 +05301070int platform_set_fluence_type(void *platform, char *value)
1071{
1072 int ret = 0;
1073 int fluence_type = FLUENCE_NONE;
1074 int fluence_flag = NONE_FLAG;
1075 struct platform_data *my_data = (struct platform_data *)platform;
1076 struct audio_device *adev = my_data->adev;
1077
1078 ALOGV("%s: fluence type:%d", __func__, my_data->fluence_type);
1079
1080 /* only dual mic turn on and off is supported as of now through setparameters */
1081 if (!strncmp(AUDIO_PARAMETER_VALUE_DUALMIC,value, sizeof(AUDIO_PARAMETER_VALUE_DUALMIC))) {
1082 if (!strncmp("fluencepro", my_data->fluence_cap, sizeof("fluencepro")) ||
1083 !strncmp("fluence", my_data->fluence_cap, sizeof("fluence"))) {
1084 ALOGV("fluence dualmic feature enabled \n");
1085 fluence_type = FLUENCE_DUAL_MIC;
1086 fluence_flag = DMIC_FLAG;
1087 } else {
1088 ALOGE("%s: Failed to set DUALMIC", __func__);
1089 ret = -1;
1090 goto done;
1091 }
1092 } else if (!strncmp(AUDIO_PARAMETER_KEY_NO_FLUENCE, value, sizeof(AUDIO_PARAMETER_KEY_NO_FLUENCE))) {
1093 ALOGV("fluence disabled");
1094 fluence_type = FLUENCE_NONE;
1095 } else {
1096 ALOGE("Invalid fluence value : %s",value);
1097 ret = -1;
1098 goto done;
1099 }
1100
1101 if (fluence_type != my_data->fluence_type) {
1102 ALOGV("%s: Updating fluence_type to :%d", __func__, fluence_type);
1103 my_data->fluence_type = fluence_type;
1104 adev->acdb_settings = (adev->acdb_settings & FLUENCE_MODE_CLEAR) | fluence_flag;
1105 }
1106done:
1107 return ret;
1108}
1109
1110int platform_get_fluence_type(void *platform, char *value, uint32_t len)
1111{
1112 int ret = 0;
1113 struct platform_data *my_data = (struct platform_data *)platform;
1114
1115 if (my_data->fluence_type == FLUENCE_QUAD_MIC) {
1116 strlcpy(value, "quadmic", len);
1117 } else if (my_data->fluence_type == FLUENCE_DUAL_MIC) {
1118 strlcpy(value, "dualmic", len);
1119 } else if (my_data->fluence_type == FLUENCE_NONE) {
1120 strlcpy(value, "none", len);
1121 } else
1122 ret = -1;
1123
1124 return ret;
1125}
1126
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301127int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
1128{
1129 int ret = 0;
1130
1131 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1132 ALOGE("%s: Invalid snd_device = %d",
1133 __func__, snd_device);
1134 ret = -EINVAL;
1135 goto done;
1136 }
1137
1138 acdb_device_table[snd_device] = acdb_id;
1139done:
1140 return ret;
1141}
1142
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -07001143int platform_get_default_app_type(void *platform)
1144{
1145 struct platform_data *my_data = (struct platform_data *)platform;
1146
1147 if (my_data->acdb_get_default_app_type)
1148 return my_data->acdb_get_default_app_type();
1149 else
1150 return DEFAULT_APP_TYPE;
1151}
1152
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -07001153int platform_get_snd_device_acdb_id(snd_device_t snd_device)
1154{
1155 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1156 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1157 return -EINVAL;
1158 }
1159 return acdb_device_table[snd_device];
1160}
1161
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -07001162int platform_send_audio_calibration(void *platform, snd_device_t snd_device,
1163 int app_type, int sample_rate)
Naresh Tannirue3b18452014-03-04 14:44:27 +05301164{
1165 struct platform_data *my_data = (struct platform_data *)platform;
1166 int acdb_dev_id, acdb_dev_type;
1167
1168 acdb_dev_id = acdb_device_table[snd_device];
1169 if (acdb_dev_id < 0) {
1170 ALOGE("%s: Could not find acdb id for device(%d)",
1171 __func__, snd_device);
1172 return -EINVAL;
1173 }
1174 if (my_data->acdb_send_audio_cal) {
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -07001175 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Naresh Tannirue3b18452014-03-04 14:44:27 +05301176 __func__, snd_device, acdb_dev_id);
1177 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
1178 snd_device < SND_DEVICE_OUT_END)
1179 acdb_dev_type = ACDB_DEV_TYPE_OUT;
1180 else
1181 acdb_dev_type = ACDB_DEV_TYPE_IN;
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -07001182 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type, app_type,
1183 sample_rate);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301184 }
1185 return 0;
1186}
1187
1188int platform_switch_voice_call_device_pre(void *platform)
1189{
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301190 struct platform_data *my_data = (struct platform_data *)platform;
1191 int ret = 0;
1192
1193 if (my_data->csd != NULL &&
Ravi Kumar Alamandabe149392014-10-20 17:07:43 -07001194 voice_is_in_call(my_data->adev)) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301195 /* This must be called before disabling mixer controls on APQ side */
1196 ret = my_data->csd->disable_device();
1197 if (ret < 0) {
1198 ALOGE("%s: csd_client_disable_device, failed, error %d",
1199 __func__, ret);
1200 }
1201 }
1202 return ret;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301203}
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301204int platform_switch_voice_call_enable_device_config(void *platform,
1205 snd_device_t out_snd_device,
1206 snd_device_t in_snd_device)
1207{
1208 struct platform_data *my_data = (struct platform_data *)platform;
1209 int acdb_rx_id, acdb_tx_id;
1210 int ret = 0;
1211
1212 acdb_rx_id = acdb_device_table[out_snd_device];
1213 acdb_tx_id = acdb_device_table[in_snd_device];
1214
1215 if (my_data->csd != NULL) {
1216 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
1217 ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
1218 if (ret < 0) {
1219 ALOGE("%s: csd_enable_device_config, failed, error %d",
1220 __func__, ret);
1221 }
1222 } else {
1223 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1224 acdb_rx_id, acdb_tx_id);
1225 }
1226 }
1227 return ret;
1228}
1229
Naresh Tannirue3b18452014-03-04 14:44:27 +05301230
1231int platform_switch_voice_call_device_post(void *platform,
1232 snd_device_t out_snd_device,
1233 snd_device_t in_snd_device)
1234{
1235 struct platform_data *my_data = (struct platform_data *)platform;
1236 int acdb_rx_id, acdb_tx_id;
1237
1238 if (my_data->acdb_send_voice_cal == NULL) {
1239 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
1240 } else {
1241 acdb_rx_id = acdb_device_table[out_snd_device];
1242 acdb_tx_id = acdb_device_table[in_snd_device];
1243
1244 if (acdb_rx_id > 0 && acdb_tx_id > 0)
1245 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
1246 else
1247 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1248 acdb_rx_id, acdb_tx_id);
1249 }
1250
1251 return 0;
1252}
1253
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301254int platform_switch_voice_call_usecase_route_post(void *platform,
1255 snd_device_t out_snd_device,
1256 snd_device_t in_snd_device)
Naresh Tannirue3b18452014-03-04 14:44:27 +05301257{
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301258 struct platform_data *my_data = (struct platform_data *)platform;
1259 int acdb_rx_id, acdb_tx_id;
1260 int ret = 0;
1261
1262 acdb_rx_id = acdb_device_table[out_snd_device];
1263 acdb_tx_id = acdb_device_table[in_snd_device];
1264
1265 if (my_data->csd != NULL) {
1266 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
1267 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
1268 my_data->adev->acdb_settings);
1269 if (ret < 0) {
1270 ALOGE("%s: csd_enable_device, failed, error %d",
1271 __func__, ret);
1272 }
1273 } else {
1274 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1275 acdb_rx_id, acdb_tx_id);
1276 }
1277 }
1278 return ret;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301279}
1280
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301281int platform_start_voice_call(void *platform, uint32_t vsid)
1282{
1283 struct platform_data *my_data = (struct platform_data *)platform;
1284 int ret = 0;
1285
1286 if (my_data->csd != NULL) {
1287 ret = my_data->csd->start_voice(vsid);
1288 if (ret < 0) {
1289 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
1290 }
1291 }
1292 return ret;
1293}
1294
1295int platform_stop_voice_call(void *platform, uint32_t vsid)
1296{
1297 struct platform_data *my_data = (struct platform_data *)platform;
1298 int ret = 0;
1299
1300 if (my_data->csd != NULL) {
1301 ret = my_data->csd->stop_voice(vsid);
1302 if (ret < 0) {
1303 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
1304 }
1305 }
1306 return ret;
1307}
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07001308
1309int platform_get_sample_rate(void *platform __unused, uint32_t *rate __unused)
Naresh Tannirue3b18452014-03-04 14:44:27 +05301310{
1311 return 0;
1312}
1313
1314int platform_set_voice_volume(void *platform, int volume)
1315{
1316 struct platform_data *my_data = (struct platform_data *)platform;
1317 struct audio_device *adev = my_data->adev;
1318 struct mixer_ctl *ctl;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301319 const char *mixer_ctl_name = "Voice Rx Gain";
1320 int vol_index = 0, ret = 0;
1321 uint32_t set_values[ ] = {0,
1322 ALL_SESSION_VSID,
1323 DEFAULT_VOLUME_RAMP_DURATION_MS};
Naresh Tannirue3b18452014-03-04 14:44:27 +05301324
1325 // Voice volume levels are mapped to adsp volume levels as follows.
1326 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
1327 // But this values don't changed in kernel. So, below change is need.
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301328 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, MAX_VOL_INDEX);
1329 set_values[0] = vol_index;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301330
1331 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1332 if (!ctl) {
1333 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1334 __func__, mixer_ctl_name);
1335 return -EINVAL;
1336 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301337 ALOGV("Setting voice volume index: %d", set_values[0]);
1338 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
Naresh Tannirue3b18452014-03-04 14:44:27 +05301339
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301340 if (my_data->csd != NULL) {
1341 ret = my_data->csd->volume(ALL_SESSION_VSID, volume);
1342 if (ret < 0) {
1343 ALOGE("%s: csd_volume error %d", __func__, ret);
1344 }
1345 }
1346 return ret;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301347}
1348
1349int platform_set_mic_mute(void *platform, bool state)
1350{
1351 struct platform_data *my_data = (struct platform_data *)platform;
1352 struct audio_device *adev = my_data->adev;
1353 struct mixer_ctl *ctl;
1354 const char *mixer_ctl_name = "Voice Tx Mute";
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301355 int ret = 0;
1356 uint32_t set_values[ ] = {0,
1357 ALL_SESSION_VSID,
1358 DEFAULT_VOLUME_RAMP_DURATION_MS};
Naresh Tannirue3b18452014-03-04 14:44:27 +05301359
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301360 set_values[0] = state;
1361 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1362 if (!ctl) {
1363 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1364 __func__, mixer_ctl_name);
1365 return -EINVAL;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301366 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301367 ALOGV("Setting voice mute state: %d", state);
1368 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
Naresh Tannirue3b18452014-03-04 14:44:27 +05301369
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301370 if (my_data->csd != NULL) {
1371 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state);
1372 if (ret < 0) {
1373 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
1374 }
1375 }
1376 return ret;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301377}
1378
Shiv Maliyappanahallic6fd8ee2014-03-07 15:31:55 -08001379int platform_set_device_mute(void *platform, bool state, char *dir)
1380{
1381 struct platform_data *my_data = (struct platform_data *)platform;
1382 struct audio_device *adev = my_data->adev;
1383 struct mixer_ctl *ctl;
1384 char *mixer_ctl_name = NULL;
1385 int ret = 0;
1386 uint32_t set_values[ ] = {0,
1387 ALL_SESSION_VSID,
1388 0};
1389 if(dir == NULL) {
1390 ALOGE("%s: Invalid direction:%s", __func__, dir);
1391 return -EINVAL;
1392 }
1393
1394 if (!strncmp("rx", dir, sizeof("rx"))) {
1395 mixer_ctl_name = "Voice Rx Device Mute";
1396 } else if (!strncmp("tx", dir, sizeof("tx"))) {
1397 mixer_ctl_name = "Voice Tx Device Mute";
1398 } else {
1399 return -EINVAL;
1400 }
1401
1402 set_values[0] = state;
1403 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1404 if (!ctl) {
1405 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1406 __func__, mixer_ctl_name);
1407 return -EINVAL;
1408 }
1409
1410 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
1411 __func__,state, mixer_ctl_name);
1412 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1413
1414 return ret;
1415}
1416
Naresh Tannirue3b18452014-03-04 14:44:27 +05301417snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
1418{
1419 struct platform_data *my_data = (struct platform_data *)platform;
1420 struct audio_device *adev = my_data->adev;
1421 audio_mode_t mode = adev->mode;
1422 snd_device_t snd_device = SND_DEVICE_NONE;
Naresh Tanniruc0517bc2014-10-26 15:30:55 +05301423#ifdef RECORD_PLAY_CONCURRENCY
1424 bool use_voip_out_devices = false;
1425 bool prop_rec_play_enabled = false;
1426 char recConcPropValue[PROPERTY_VALUE_MAX];
1427
1428 if (property_get("rec.playback.conc.disabled", recConcPropValue, NULL)) {
1429 prop_rec_play_enabled = atoi(recConcPropValue) || !strncmp("true", recConcPropValue, 4);
1430 }
1431 use_voip_out_devices = prop_rec_play_enabled &&
1432 (my_data->rec_play_conc_set || adev->mode == AUDIO_MODE_IN_COMMUNICATION);
1433 ALOGV("platform_get_output_snd_device use_voip_out_devices : %d",use_voip_out_devices);
1434#endif
Naresh Tannirue3b18452014-03-04 14:44:27 +05301435
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301436 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
1437 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
1438 int channel_count = popcount(channel_mask);
1439
Naresh Tannirue3b18452014-03-04 14:44:27 +05301440 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
1441 if (devices == AUDIO_DEVICE_NONE ||
1442 devices & AUDIO_DEVICE_BIT_IN) {
1443 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
1444 goto exit;
1445 }
1446
Naresh Tannirue3b18452014-03-04 14:44:27 +05301447 if (popcount(devices) == 2) {
1448 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
1449 AUDIO_DEVICE_OUT_SPEAKER)) {
1450 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
1451 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
1452 AUDIO_DEVICE_OUT_SPEAKER)) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301453 if (audio_extn_get_anc_enabled())
1454 snd_device = SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET;
1455 else
1456 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301457 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
1458 AUDIO_DEVICE_OUT_SPEAKER)) {
1459 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301460 } else if (devices == (AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET |
1461 AUDIO_DEVICE_OUT_SPEAKER)) {
1462 snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301463 } else {
1464 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
1465 goto exit;
1466 }
1467 if (snd_device != SND_DEVICE_NONE) {
1468 goto exit;
1469 }
1470 }
1471
1472 if (popcount(devices) != 1) {
1473 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
1474 goto exit;
1475 }
1476
Ravi Kumar Alamandabe149392014-10-20 17:07:43 -07001477 if (voice_is_in_call(adev) || voice_extn_compress_voip_is_active(adev)) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301478 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1479 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
1480 if ((adev->voice.tty_mode != TTY_MODE_OFF) &&
1481 !voice_extn_compress_voip_is_active(adev)) {
1482 switch (adev->voice.tty_mode) {
1483 case TTY_MODE_FULL:
1484 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
1485 break;
1486 case TTY_MODE_VCO:
1487 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
1488 break;
1489 case TTY_MODE_HCO:
1490 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
1491 break;
1492 default:
1493 ALOGE("%s: Invalid TTY mode (%#x)",
1494 __func__, adev->voice.tty_mode);
1495 }
1496 } else if (audio_extn_get_anc_enabled()) {
1497 if (audio_extn_should_use_fb_anc())
1498 snd_device = SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET;
1499 else
1500 snd_device = SND_DEVICE_OUT_VOICE_ANC_HEADSET;
1501 } else {
1502 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
1503 }
1504 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Mingming Yin514a8bc2014-07-29 15:22:21 -07001505 if (adev->bt_wb_speech_enabled)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301506 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
1507 else
1508 snd_device = SND_DEVICE_OUT_BT_SCO;
1509 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
1510 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
1511 } else if (devices & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
1512 devices & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
1513 snd_device = SND_DEVICE_OUT_USB_HEADSET;
1514 } else if (devices & AUDIO_DEVICE_OUT_FM_TX) {
1515 snd_device = SND_DEVICE_OUT_TRANSMISSION_FM;
1516 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
1517 if (audio_extn_should_use_handset_anc(channel_count))
1518 snd_device = SND_DEVICE_OUT_ANC_HANDSET;
1519 else
1520 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
1521 }
1522 if (snd_device != SND_DEVICE_NONE) {
1523 goto exit;
1524 }
1525 }
1526
Naresh Tannirue3b18452014-03-04 14:44:27 +05301527 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1528 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301529 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADSET
1530 && audio_extn_get_anc_enabled()) {
Naresh Tanniruc0517bc2014-10-26 15:30:55 +05301531#ifdef RECORD_PLAY_CONCURRENCY
1532 if (use_voip_out_devices) {
1533 // ANC should be disabled for voip concurrency
1534 snd_device = SND_DEVICE_OUT_VOIP_HEADPHONES;
1535 } else
1536#endif
1537 {
1538 if (audio_extn_should_use_fb_anc())
1539 snd_device = SND_DEVICE_OUT_ANC_FB_HEADSET;
1540 else
1541 snd_device = SND_DEVICE_OUT_ANC_HEADSET;
1542 }
1543 } else {
1544#ifdef RECORD_PLAY_CONCURRENCY
1545 if (use_voip_out_devices)
1546 snd_device = SND_DEVICE_OUT_VOIP_HEADPHONES;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301547 else
Naresh Tanniruc0517bc2014-10-26 15:30:55 +05301548#endif
1549 snd_device = SND_DEVICE_OUT_HEADPHONES;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301550 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05301551 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
Naresh Tanniruc0517bc2014-10-26 15:30:55 +05301552#ifdef RECORD_PLAY_CONCURRENCY
1553 if (use_voip_out_devices) {
1554 snd_device = SND_DEVICE_OUT_VOIP_SPEAKER;
1555 } else
1556#endif
1557 {
1558 if (adev->speaker_lr_swap)
1559 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
1560 else
1561 snd_device = SND_DEVICE_OUT_SPEAKER;
1562 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05301563 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Mingming Yin514a8bc2014-07-29 15:22:21 -07001564 if (adev->bt_wb_speech_enabled)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301565 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
1566 else
1567 snd_device = SND_DEVICE_OUT_BT_SCO;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301568 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
1569 snd_device = SND_DEVICE_OUT_HDMI ;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301570 } else if (devices & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
1571 devices & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
Mingming Yin5a7c5d62014-03-05 17:45:03 -08001572 ALOGD("%s: setting USB hadset channel capability(2) for Proxy", __func__);
1573 audio_extn_set_afe_proxy_channel_mixer(adev, 2);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301574 snd_device = SND_DEVICE_OUT_USB_HEADSET;
1575 } else if (devices & AUDIO_DEVICE_OUT_FM_TX) {
1576 snd_device = SND_DEVICE_OUT_TRANSMISSION_FM;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301577 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Naresh Tanniruc0517bc2014-10-26 15:30:55 +05301578#ifdef RECORD_PLAY_CONCURRENCY
1579 if (use_voip_out_devices)
1580 snd_device = SND_DEVICE_OUT_VOIP_HANDSET;
1581 else
1582#endif
1583 snd_device = SND_DEVICE_OUT_HANDSET;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301584 } else if (devices & AUDIO_DEVICE_OUT_PROXY) {
Mingming Yin5a7c5d62014-03-05 17:45:03 -08001585 channel_count = audio_extn_get_afe_proxy_channel_count();
1586 ALOGD("%s: setting sink capability(%d) for Proxy", __func__, channel_count);
1587 audio_extn_set_afe_proxy_channel_mixer(adev, channel_count);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301588 snd_device = SND_DEVICE_OUT_AFE_PROXY;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301589 } else {
1590 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
1591 }
1592exit:
1593 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
1594 return snd_device;
1595}
1596
1597snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
1598{
1599 struct platform_data *my_data = (struct platform_data *)platform;
1600 struct audio_device *adev = my_data->adev;
1601 audio_source_t source = (adev->active_input == NULL) ?
1602 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
1603
1604 audio_mode_t mode = adev->mode;
1605 audio_devices_t in_device = ((adev->active_input == NULL) ?
1606 AUDIO_DEVICE_NONE : adev->active_input->device)
1607 & ~AUDIO_DEVICE_BIT_IN;
1608 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
1609 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
1610 snd_device_t snd_device = SND_DEVICE_NONE;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301611 int channel_count = popcount(channel_mask);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301612
1613 ALOGV("%s: enter: out_device(%#x) in_device(%#x)",
1614 __func__, out_device, in_device);
Ravi Kumar Alamandabe149392014-10-20 17:07:43 -07001615 if ((out_device != AUDIO_DEVICE_NONE) && (voice_is_in_call(adev) ||
Satya Krishna Pindiproli2aaa6152014-05-21 15:05:22 +05301616 voice_extn_compress_voip_is_active(adev) || audio_extn_hfp_is_active(adev))) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301617 if ((adev->voice.tty_mode != TTY_MODE_OFF) &&
1618 !voice_extn_compress_voip_is_active(adev)) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301619 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1620 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301621 switch (adev->voice.tty_mode) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301622 case TTY_MODE_FULL:
1623 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
1624 break;
1625 case TTY_MODE_VCO:
1626 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
1627 break;
1628 case TTY_MODE_HCO:
1629 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
1630 break;
1631 default:
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301632 ALOGE("%s: Invalid TTY mode (%#x)",
1633 __func__, adev->voice.tty_mode);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301634 }
1635 goto exit;
1636 }
1637 }
1638 if (out_device & AUDIO_DEVICE_OUT_EARPIECE ||
1639 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301640 if (out_device & AUDIO_DEVICE_OUT_EARPIECE &&
1641 audio_extn_should_use_handset_anc(channel_count)) {
1642 snd_device = SND_DEVICE_IN_AANC_HANDSET_MIC;
1643 } else if (my_data->fluence_type == FLUENCE_NONE ||
1644 my_data->fluence_in_voice_call == false) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301645 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +05301646 if (audio_extn_hfp_is_active(adev))
1647 platform_set_echo_reference(adev->platform, true);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301648 } else {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301649 snd_device = SND_DEVICE_IN_VOICE_DMIC;
1650 adev->acdb_settings |= DMIC_FLAG;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301651 }
1652 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
1653 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +05301654 if (audio_extn_hfp_is_active(adev))
1655 platform_set_echo_reference(adev->platform, true);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301656 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Vicky Sehrawate240e5d2014-08-12 17:17:04 -07001657 if (adev->bt_wb_speech_enabled) {
1658 if (adev->bluetooth_nrec)
1659 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
1660 else
1661 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
1662 } else {
1663 if (adev->bluetooth_nrec)
1664 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
1665 else
1666 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
1667 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05301668 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301669 if (my_data->fluence_type != FLUENCE_NONE &&
1670 my_data->fluence_in_voice_call &&
1671 my_data->fluence_in_spkr_mode) {
1672 if(my_data->fluence_type & FLUENCE_QUAD_MIC) {
1673 adev->acdb_settings |= QMIC_FLAG;
1674 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_QMIC;
1675 } else {
1676 adev->acdb_settings |= DMIC_FLAG;
Karthik Reddy Kattad9fff862014-07-21 21:07:21 +05301677 if (my_data->fluence_mode == FLUENCE_BROADSIDE)
1678 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BROADSIDE;
1679 else
1680 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301681 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05301682 } else {
1683 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +05301684 if (audio_extn_hfp_is_active(adev))
1685 platform_set_echo_reference(adev->platform, true);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301686 }
1687 }
1688 } else if (source == AUDIO_SOURCE_CAMCORDER) {
1689 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
1690 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
kunleiz18a33302014-05-30 09:52:25 +08001691 if (my_data->fluence_type & FLUENCE_DUAL_MIC &&
1692 channel_count == 2)
kunleiz8f7e9e22014-06-24 15:12:02 +08001693 snd_device = SND_DEVICE_IN_HANDSET_STEREO_DMIC;
kunleiz18a33302014-05-30 09:52:25 +08001694 else
1695 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301696 }
1697 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
1698 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301699 if (channel_count == 2) {
1700 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
1701 adev->acdb_settings |= DMIC_FLAG;
1702 } else if (adev->active_input->enable_ns)
1703 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
1704 else if (my_data->fluence_type != FLUENCE_NONE &&
1705 my_data->fluence_in_voice_rec) {
1706 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
1707 adev->acdb_settings |= DMIC_FLAG;
1708 } else {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301709 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
1710 }
1711 }
1712 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION) {
1713 if (out_device & AUDIO_DEVICE_OUT_SPEAKER)
1714 in_device = AUDIO_DEVICE_IN_BACK_MIC;
1715 if (adev->active_input) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301716 if (adev->active_input->enable_aec &&
1717 adev->active_input->enable_ns) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301718 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301719 if (my_data->fluence_type & FLUENCE_DUAL_MIC &&
1720 my_data->fluence_in_spkr_mode) {
Karthik Reddy Kattad9fff862014-07-21 21:07:21 +05301721 if (my_data->fluence_mode == FLUENCE_BROADSIDE)
1722 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_BROADSIDE;
1723 else
1724 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301725 adev->acdb_settings |= DMIC_FLAG;
1726 } else
1727 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301728 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301729 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1730 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
1731 adev->acdb_settings |= DMIC_FLAG;
1732 } else
1733 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301734 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301735 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301736 }
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +05301737 platform_set_echo_reference(adev->platform, true);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301738 } else if (adev->active_input->enable_aec) {
1739 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Karthik Reddy Kattad9fff862014-07-21 21:07:21 +05301740 if (my_data->fluence_type & FLUENCE_DUAL_MIC &&
1741 my_data->fluence_in_spkr_mode) {
1742 if (my_data->fluence_mode == FLUENCE_BROADSIDE)
1743 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_BROADSIDE;
1744 else
1745 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301746 adev->acdb_settings |= DMIC_FLAG;
1747 } else
1748 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
1749 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
1750 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1751 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
1752 adev->acdb_settings |= DMIC_FLAG;
1753 } else
1754 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
1755 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
1756 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
1757 }
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +05301758 platform_set_echo_reference(adev->platform, true);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301759 } else if (adev->active_input->enable_ns) {
1760 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Karthik Reddy Kattad9fff862014-07-21 21:07:21 +05301761 if (my_data->fluence_type & FLUENCE_DUAL_MIC &&
1762 my_data->fluence_in_spkr_mode) {
1763 if (my_data->fluence_mode == FLUENCE_BROADSIDE)
1764 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS_BROADSIDE;
1765 else
1766 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301767 adev->acdb_settings |= DMIC_FLAG;
1768 } else
1769 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
1770 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
1771 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1772 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
1773 adev->acdb_settings |= DMIC_FLAG;
1774 } else
1775 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
1776 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
1777 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
1778 }
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +05301779 platform_set_echo_reference(adev->platform,false);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301780 } else
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +05301781 platform_set_echo_reference(adev->platform, false);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301782 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301783 } else if (source == AUDIO_SOURCE_MIC) {
1784 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC &&
1785 channel_count == 1 ) {
1786 if(my_data->fluence_type & FLUENCE_DUAL_MIC &&
1787 my_data->fluence_in_audio_rec)
1788 snd_device = SND_DEVICE_IN_HANDSET_DMIC;
1789 }
1790 } else if (source == AUDIO_SOURCE_FM_RX ||
1791 source == AUDIO_SOURCE_FM_RX_A2DP) {
1792 snd_device = SND_DEVICE_IN_CAPTURE_FM;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301793 } else if (source == AUDIO_SOURCE_DEFAULT) {
1794 goto exit;
1795 }
1796
1797
1798 if (snd_device != SND_DEVICE_NONE) {
1799 goto exit;
1800 }
1801
1802 if (in_device != AUDIO_DEVICE_NONE &&
1803 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
1804 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
1805 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301806 if (audio_extn_ssr_get_enabled() && channel_count == 6)
1807 snd_device = SND_DEVICE_IN_QUAD_MIC;
1808 else if (channel_count == 2)
1809 snd_device = SND_DEVICE_IN_HANDSET_STEREO_DMIC;
1810 else
1811 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301812 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
1813 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
1814 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
1815 snd_device = SND_DEVICE_IN_HEADSET_MIC;
1816 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Vicky Sehrawate240e5d2014-08-12 17:17:04 -07001817 if (adev->bt_wb_speech_enabled) {
1818 if (adev->bluetooth_nrec)
1819 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
1820 else
1821 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
1822 } else {
1823 if (adev->bluetooth_nrec)
1824 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
1825 else
1826 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
1827 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05301828 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
1829 snd_device = SND_DEVICE_IN_HDMI_MIC;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301830 } else if (in_device & AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET ||
1831 in_device & AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET) {
1832 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
1833 } else if (in_device & AUDIO_DEVICE_IN_FM_RX) {
1834 snd_device = SND_DEVICE_IN_CAPTURE_FM;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301835 } else {
1836 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
1837 ALOGW("%s: Using default handset-mic", __func__);
1838 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1839 }
1840 } else {
1841 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
1842 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1843 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
1844 snd_device = SND_DEVICE_IN_HEADSET_MIC;
1845 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301846 if (channel_count > 1)
1847 snd_device = SND_DEVICE_IN_SPEAKER_STEREO_DMIC;
1848 else
1849 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301850 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
1851 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1852 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Vicky Sehrawate240e5d2014-08-12 17:17:04 -07001853 if (adev->bt_wb_speech_enabled) {
1854 if (adev->bluetooth_nrec)
1855 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
1856 else
1857 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
1858 } else {
1859 if (adev->bluetooth_nrec)
1860 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
1861 else
1862 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
1863 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05301864 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
1865 snd_device = SND_DEVICE_IN_HDMI_MIC;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301866 } else if (out_device & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
1867 out_device & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
1868 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301869 } else {
1870 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
1871 ALOGW("%s: Using default handset-mic", __func__);
1872 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1873 }
1874 }
1875exit:
1876 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
1877 return snd_device;
1878}
1879
1880int platform_set_hdmi_channels(void *platform, int channel_count)
1881{
1882 struct platform_data *my_data = (struct platform_data *)platform;
1883 struct audio_device *adev = my_data->adev;
1884 struct mixer_ctl *ctl;
1885 const char *channel_cnt_str = NULL;
1886 const char *mixer_ctl_name = "HDMI_RX Channels";
1887 switch (channel_count) {
1888 case 8:
1889 channel_cnt_str = "Eight"; break;
1890 case 7:
1891 channel_cnt_str = "Seven"; break;
1892 case 6:
1893 channel_cnt_str = "Six"; break;
1894 case 5:
1895 channel_cnt_str = "Five"; break;
1896 case 4:
1897 channel_cnt_str = "Four"; break;
1898 case 3:
1899 channel_cnt_str = "Three"; break;
1900 default:
1901 channel_cnt_str = "Two"; break;
1902 }
1903 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1904 if (!ctl) {
1905 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1906 __func__, mixer_ctl_name);
1907 return -EINVAL;
1908 }
1909 ALOGV("HDMI channel count: %s", channel_cnt_str);
1910 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
1911 return 0;
1912}
1913
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301914int platform_edid_get_max_channels(void *platform)
Naresh Tannirue3b18452014-03-04 14:44:27 +05301915{
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301916 struct platform_data *my_data = (struct platform_data *)platform;
1917 struct audio_device *adev = my_data->adev;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301918 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
1919 char *sad = block;
1920 int num_audio_blocks;
1921 int channel_count;
1922 int max_channels = 0;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301923 int i, ret, count;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301924
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301925 struct mixer_ctl *ctl;
1926
1927 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
1928 if (!ctl) {
1929 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1930 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301931 return 0;
1932 }
1933
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301934 mixer_ctl_update(ctl);
1935
1936 count = mixer_ctl_get_num_values(ctl);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301937
1938 /* Read SAD blocks, clamping the maximum size for safety */
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301939 if (count > (int)sizeof(block))
1940 count = (int)sizeof(block);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301941
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301942 ret = mixer_ctl_get_array(ctl, block, count);
1943 if (ret != 0) {
1944 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
1945 return 0;
1946 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05301947
1948 /* Calculate the number of SAD blocks */
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301949 num_audio_blocks = count / SAD_BLOCK_SIZE;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301950
1951 for (i = 0; i < num_audio_blocks; i++) {
1952 /* Only consider LPCM blocks */
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301953 if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
1954 sad += 3;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301955 continue;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301956 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05301957
1958 channel_count = (sad[0] & 0x7) + 1;
1959 if (channel_count > max_channels)
1960 max_channels = channel_count;
1961
1962 /* Advance to next block */
1963 sad += 3;
1964 }
1965
1966 return max_channels;
1967}
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301968
1969static int platform_set_slowtalk(struct platform_data *my_data, bool state)
1970{
1971 int ret = 0;
1972 struct audio_device *adev = my_data->adev;
1973 struct mixer_ctl *ctl;
1974 const char *mixer_ctl_name = "Slowtalk Enable";
1975 uint32_t set_values[ ] = {0,
1976 ALL_SESSION_VSID};
1977
1978 set_values[0] = state;
1979 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1980 if (!ctl) {
1981 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1982 __func__, mixer_ctl_name);
1983 ret = -EINVAL;
1984 } else {
1985 ALOGV("Setting slowtalk state: %d", state);
1986 ret = mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1987 my_data->slowtalk = state;
1988 }
1989
1990 if (my_data->csd != NULL) {
1991 ret = my_data->csd->slow_talk(ALL_SESSION_VSID, state);
1992 if (ret < 0) {
1993 ALOGE("%s: csd_client_disable_device, failed, error %d",
1994 __func__, ret);
1995 }
1996 }
1997 return ret;
1998}
1999
Avinash Vaishd5fa4572014-09-15 14:41:14 +05302000static int set_hd_voice(struct platform_data *my_data, bool state)
2001{
2002 struct audio_device *adev = my_data->adev;
2003 struct mixer_ctl *ctl;
2004 const char *mixer_ctl_name = "HD Voice Enable";
2005 int ret = 0;
2006 uint32_t set_values[ ] = {0,
2007 ALL_SESSION_VSID};
2008
2009 set_values[0] = state;
2010 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2011 if (!ctl) {
2012 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2013 __func__, mixer_ctl_name);
2014 ret = -EINVAL;
2015 } else {
2016 ALOGV("Setting HD Voice state: %d", state);
2017 ret = mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2018 my_data->hd_voice = state;
2019 }
2020
2021 return ret;
2022}
2023
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302024int platform_set_parameters(void *platform, struct str_parms *parms)
2025{
2026 struct platform_data *my_data = (struct platform_data *)platform;
2027 char *str;
2028 char value[256] = {0};
2029 int val;
2030 int ret = 0, err;
Karthik Reddy Kattabfe193d2014-08-14 17:58:18 +05302031 char *kv_pairs = NULL;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302032
Karthik Reddy Kattabfe193d2014-08-14 17:58:18 +05302033 kv_pairs = str_parms_to_str(parms);
2034 ALOGV("%s: enter: - %s", __func__, kv_pairs);
2035 free(kv_pairs);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302036
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302037 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_SLOWTALK, value, sizeof(value));
2038 if (err >= 0) {
2039 bool state = false;
2040 if (!strncmp("true", value, sizeof("true"))) {
2041 state = true;
2042 }
2043
2044 str_parms_del(parms, AUDIO_PARAMETER_KEY_SLOWTALK);
2045 ret = platform_set_slowtalk(my_data, state);
2046 if (ret)
2047 ALOGE("%s: Failed to set slow talk err: %d", __func__, ret);
2048 }
2049
Avinash Vaishd5fa4572014-09-15 14:41:14 +05302050 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_HD_VOICE, value, sizeof(value));
2051 if (err >= 0) {
2052 bool state = false;
2053 if (!strncmp("true", value, sizeof("true"))) {
2054 state = true;
2055 }
2056
2057 str_parms_del(parms, AUDIO_PARAMETER_KEY_HD_VOICE);
2058 if (my_data->hd_voice != state) {
2059 ret = set_hd_voice(my_data, state);
2060 if (ret)
2061 ALOGE("%s: Failed to set HD voice err: %d", __func__, ret);
2062 } else {
2063 ALOGV("%s: HD Voice already set to %d", __func__, state);
2064 }
2065 }
2066
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302067 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_VOLUME_BOOST,
2068 value, sizeof(value));
2069 if (err >= 0) {
2070 str_parms_del(parms, AUDIO_PARAMETER_KEY_VOLUME_BOOST);
2071
2072 if (my_data->acdb_reload_vocvoltable == NULL) {
2073 ALOGE("%s: acdb_reload_vocvoltable is NULL", __func__);
2074 } else if (!strcmp(value, "on")) {
2075 if (!my_data->acdb_reload_vocvoltable(VOICE_FEATURE_SET_VOLUME_BOOST)) {
2076 my_data->voice_feature_set = 1;
2077 }
2078 } else {
2079 if (!my_data->acdb_reload_vocvoltable(VOICE_FEATURE_SET_DEFAULT)) {
2080 my_data->voice_feature_set = 0;
2081 }
2082 }
2083 }
2084
Naresh Tanniruc0517bc2014-10-26 15:30:55 +05302085#ifdef RECORD_PLAY_CONCURRENCY
2086 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_REC_PLAY_CONC, value, sizeof(value));
2087 if (err >= 0) {
2088 if (!strncmp("true", value, sizeof("true"))) {
2089 ALOGD("setting record playback concurrency to true");
2090 my_data->rec_play_conc_set = true;
2091 } else {
2092 ALOGD("setting record playback concurrency to false");
2093 my_data->rec_play_conc_set = false;
2094 }
2095 str_parms_del(parms, AUDIO_PARAMETER_KEY_REC_PLAY_CONC);
2096 }
2097#endif
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302098 ALOGV("%s: exit with code(%d)", __func__, ret);
2099 return ret;
2100}
2101
2102int platform_set_incall_recording_session_id(void *platform,
2103 uint32_t session_id, int rec_mode)
2104{
2105 int ret = 0;
2106 struct platform_data *my_data = (struct platform_data *)platform;
2107 struct audio_device *adev = my_data->adev;
2108 struct mixer_ctl *ctl;
2109 const char *mixer_ctl_name = "Voc VSID";
2110 int num_ctl_values;
2111 int i;
2112
2113 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2114 if (!ctl) {
2115 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2116 __func__, mixer_ctl_name);
2117 ret = -EINVAL;
2118 } else {
2119 num_ctl_values = mixer_ctl_get_num_values(ctl);
2120 for (i = 0; i < num_ctl_values; i++) {
2121 if (mixer_ctl_set_value(ctl, i, session_id)) {
2122 ALOGV("Error: invalid session_id: %x", session_id);
2123 ret = -EINVAL;
2124 break;
2125 }
2126 }
2127 }
2128
2129 if (my_data->csd != NULL) {
2130 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
2131 if (ret < 0) {
2132 ALOGE("%s: csd_client_start_record failed, error %d",
2133 __func__, ret);
2134 }
2135 }
2136
2137 return ret;
2138}
2139
2140int platform_stop_incall_recording_usecase(void *platform)
2141{
2142 int ret = 0;
2143 struct platform_data *my_data = (struct platform_data *)platform;
2144
2145 if (my_data->csd != NULL) {
2146 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
2147 if (ret < 0) {
2148 ALOGE("%s: csd_client_stop_record failed, error %d",
2149 __func__, ret);
2150 }
2151 }
2152
2153 return ret;
2154}
2155
2156int platform_start_incall_music_usecase(void *platform)
2157{
2158 int ret = 0;
2159 struct platform_data *my_data = (struct platform_data *)platform;
2160
2161 if (my_data->csd != NULL) {
2162 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
2163 if (ret < 0) {
2164 ALOGE("%s: csd_client_start_playback failed, error %d",
2165 __func__, ret);
2166 }
2167 }
2168
2169 return ret;
2170}
2171
2172int platform_stop_incall_music_usecase(void *platform)
2173{
2174 int ret = 0;
2175 struct platform_data *my_data = (struct platform_data *)platform;
2176
2177 if (my_data->csd != NULL) {
2178 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
2179 if (ret < 0) {
2180 ALOGE("%s: csd_client_stop_playback failed, error %d",
2181 __func__, ret);
2182 }
2183 }
2184
2185 return ret;
2186}
2187
Vidyakumar Athota21b3bb92014-04-25 11:08:08 -07002188int platform_update_lch(void *platform, struct voice_session *session,
2189 enum voice_lch_mode lch_mode)
2190{
2191 int ret = 0;
2192 struct platform_data *my_data = (struct platform_data *)platform;
2193
2194 if ((my_data->csd != NULL) && (my_data->csd->set_lch != NULL))
2195 ret = my_data->csd->set_lch(session->vsid, lch_mode);
2196 else
2197 ret = pcm_ioctl(session->pcm_tx, SNDRV_VOICE_IOCTL_LCH, &lch_mode);
2198
2199 return ret;
2200}
2201
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302202void platform_get_parameters(void *platform,
2203 struct str_parms *query,
2204 struct str_parms *reply)
2205{
2206 struct platform_data *my_data = (struct platform_data *)platform;
2207 char *str = NULL;
2208 char value[256] = {0};
2209 int ret;
Karthik Reddy Kattabfe193d2014-08-14 17:58:18 +05302210 char *kv_pairs = NULL;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302211
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302212 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_SLOWTALK,
2213 value, sizeof(value));
2214 if (ret >= 0) {
2215 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_SLOWTALK,
2216 my_data->slowtalk?"true":"false");
2217 }
2218
Avinash Vaishd5fa4572014-09-15 14:41:14 +05302219 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_HD_VOICE,
2220 value, sizeof(value));
2221 if (ret >= 0) {
2222 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_HD_VOICE,
2223 my_data->hd_voice?"true":"false");
2224 }
2225
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302226 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_VOLUME_BOOST,
2227 value, sizeof(value));
2228 if (ret >= 0) {
2229 if (my_data->voice_feature_set == VOICE_FEATURE_SET_VOLUME_BOOST) {
2230 strlcpy(value, "on", sizeof(value));
2231 } else {
2232 strlcpy(value, "off", sizeof(value));
2233 }
2234
2235 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_VOLUME_BOOST, value);
2236 }
2237
Karthik Reddy Kattabfe193d2014-08-14 17:58:18 +05302238 kv_pairs = str_parms_to_str(reply);
2239 ALOGV("%s: exit: returns - %s", __func__, kv_pairs);
2240 free(kv_pairs);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302241}
2242
2243/* Delay in Us */
2244int64_t platform_render_latency(audio_usecase_t usecase)
2245{
2246 switch (usecase) {
2247 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
2248 return DEEP_BUFFER_PLATFORM_DELAY;
2249 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
2250 return LOW_LATENCY_PLATFORM_DELAY;
2251 default:
2252 return 0;
2253 }
2254}
2255
2256int platform_update_usecase_from_source(int source, int usecase)
2257{
2258 ALOGV("%s: input source :%d", __func__, source);
2259 if(source == AUDIO_SOURCE_FM_RX_A2DP)
2260 usecase = USECASE_AUDIO_RECORD_FM_VIRTUAL;
2261 return usecase;
2262}
2263
Dhananjay Kumar45b71742014-05-29 21:47:27 +05302264bool platform_listen_device_needs_event(snd_device_t snd_device)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302265{
Dhananjay Kumar45b71742014-05-29 21:47:27 +05302266 bool needs_event = false;
2267
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302268 if ((snd_device >= SND_DEVICE_IN_BEGIN) &&
2269 (snd_device < SND_DEVICE_IN_END) &&
2270 (snd_device != SND_DEVICE_IN_CAPTURE_FM) &&
2271 (snd_device != SND_DEVICE_IN_CAPTURE_VI_FEEDBACK))
Dhananjay Kumar45b71742014-05-29 21:47:27 +05302272 needs_event = true;
2273
2274 return needs_event;
2275}
2276
2277bool platform_listen_usecase_needs_event(audio_usecase_t uc_id)
2278{
2279 bool needs_event = false;
2280
2281 switch(uc_id){
2282 /* concurrent playback usecases needs event */
2283 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
2284 case USECASE_AUDIO_PLAYBACK_MULTI_CH:
2285 case USECASE_AUDIO_PLAYBACK_OFFLOAD:
2286 needs_event = true;
2287 break;
2288 /* concurrent playback in low latency allowed */
2289 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
2290 break;
2291 /* concurrent playback FM needs event */
2292 case USECASE_AUDIO_PLAYBACK_FM:
2293 needs_event = true;
2294 break;
2295
2296 /* concurrent capture usecases, no event, capture handled by device
2297 * USECASE_AUDIO_RECORD:
2298 * USECASE_AUDIO_RECORD_COMPRESS:
2299 * USECASE_AUDIO_RECORD_LOW_LATENCY:
2300
2301 * USECASE_VOICE_CALL:
2302 * USECASE_VOICE2_CALL:
2303 * USECASE_VOLTE_CALL:
2304 * USECASE_QCHAT_CALL:
2305 * USECASE_VOWLAN_CALL:
2306 * USECASE_COMPRESS_VOIP_CALL:
2307 * USECASE_AUDIO_RECORD_FM_VIRTUAL:
2308 * USECASE_INCALL_REC_UPLINK:
2309 * USECASE_INCALL_REC_DOWNLINK:
2310 * USECASE_INCALL_REC_UPLINK_AND_DOWNLINK:
2311 * USECASE_INCALL_REC_UPLINK_COMPRESS:
2312 * USECASE_INCALL_REC_DOWNLINK_COMPRESS:
2313 * USECASE_INCALL_REC_UPLINK_AND_DOWNLINK_COMPRESS:
2314 * USECASE_INCALL_MUSIC_UPLINK:
2315 * USECASE_INCALL_MUSIC_UPLINK2:
2316 * USECASE_AUDIO_SPKR_CALIB_RX:
2317 * USECASE_AUDIO_SPKR_CALIB_TX:
2318 */
2319 default:
2320 ALOGV("%s:usecase_id[%d} no need to raise event.", __func__, uc_id);
2321 }
2322 return needs_event;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302323}
2324
Ravi Kumar Alamanda8fa6b192014-09-09 16:06:42 -07002325bool platform_sound_trigger_device_needs_event(snd_device_t snd_device)
2326{
2327 bool needs_event = false;
2328
2329 if ((snd_device >= SND_DEVICE_IN_BEGIN) &&
2330 (snd_device < SND_DEVICE_IN_END) &&
2331 (snd_device != SND_DEVICE_IN_CAPTURE_FM) &&
2332 (snd_device != SND_DEVICE_IN_CAPTURE_VI_FEEDBACK))
2333 needs_event = true;
2334
2335 return needs_event;
2336}
2337
2338bool platform_sound_trigger_usecase_needs_event(audio_usecase_t uc_id)
2339{
2340 bool needs_event = false;
2341
2342 switch(uc_id){
2343 /* concurrent playback usecases needs event */
2344 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
2345 case USECASE_AUDIO_PLAYBACK_MULTI_CH:
2346 case USECASE_AUDIO_PLAYBACK_OFFLOAD:
2347 needs_event = true;
2348 break;
2349 /* concurrent playback in low latency allowed */
2350 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
2351 break;
2352 /* concurrent playback FM needs event */
2353 case USECASE_AUDIO_PLAYBACK_FM:
2354 needs_event = true;
2355 break;
2356
2357 /* concurrent capture usecases, no event, capture handled by device
2358 * USECASE_AUDIO_RECORD:
2359 * USECASE_AUDIO_RECORD_COMPRESS:
2360 * USECASE_AUDIO_RECORD_LOW_LATENCY:
2361
2362 * USECASE_VOICE_CALL:
2363 * USECASE_VOICE2_CALL:
2364 * USECASE_VOLTE_CALL:
2365 * USECASE_QCHAT_CALL:
2366 * USECASE_VOWLAN_CALL:
2367 * USECASE_COMPRESS_VOIP_CALL:
2368 * USECASE_AUDIO_RECORD_FM_VIRTUAL:
2369 * USECASE_INCALL_REC_UPLINK:
2370 * USECASE_INCALL_REC_DOWNLINK:
2371 * USECASE_INCALL_REC_UPLINK_AND_DOWNLINK:
2372 * USECASE_INCALL_REC_UPLINK_COMPRESS:
2373 * USECASE_INCALL_REC_DOWNLINK_COMPRESS:
2374 * USECASE_INCALL_REC_UPLINK_AND_DOWNLINK_COMPRESS:
2375 * USECASE_INCALL_MUSIC_UPLINK:
2376 * USECASE_INCALL_MUSIC_UPLINK2:
2377 * USECASE_AUDIO_SPKR_CALIB_RX:
2378 * USECASE_AUDIO_SPKR_CALIB_TX:
2379 */
2380 default:
2381 ALOGV("%s:usecase_id[%d] no need to raise event.", __func__, uc_id);
2382 }
2383 return needs_event;
2384}
2385
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302386/* Read offload buffer size from a property.
2387 * If value is not power of 2 round it to
2388 * power of 2.
2389 */
2390uint32_t platform_get_compress_offload_buffer_size(audio_offload_info_t* info)
2391{
2392 char value[PROPERTY_VALUE_MAX] = {0};
2393 uint32_t fragment_size = COMPRESS_OFFLOAD_FRAGMENT_SIZE;
2394 if((property_get("audio.offload.buffer.size.kb", value, "")) &&
2395 atoi(value)) {
2396 fragment_size = atoi(value) * 1024;
2397 }
2398
2399 if (info != NULL && info->has_video && info->is_streaming) {
2400 fragment_size = COMPRESS_OFFLOAD_FRAGMENT_SIZE_FOR_AV_STREAMING;
2401 ALOGV("%s: offload fragment size reduced for AV streaming to %d",
Apoorv Raghuvanshi44bd9172014-05-28 14:50:07 -07002402 __func__, fragment_size);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302403 }
2404
2405 fragment_size = ALIGN( fragment_size, 1024);
2406
2407 if(fragment_size < MIN_COMPRESS_OFFLOAD_FRAGMENT_SIZE)
2408 fragment_size = MIN_COMPRESS_OFFLOAD_FRAGMENT_SIZE;
2409 else if(fragment_size > MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE)
2410 fragment_size = MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE;
2411 ALOGV("%s: fragment_size %d", __func__, fragment_size);
2412 return fragment_size;
2413}
2414
2415uint32_t platform_get_pcm_offload_buffer_size(audio_offload_info_t* info)
2416{
2417 uint32_t fragment_size = MIN_PCM_OFFLOAD_FRAGMENT_SIZE;
2418 uint32_t bits_per_sample = 16;
2419
2420 if (info->format == AUDIO_FORMAT_PCM_24_BIT_OFFLOAD) {
2421 bits_per_sample = 32;
2422 }
2423
2424 if (!info->has_video) {
2425 fragment_size = MAX_PCM_OFFLOAD_FRAGMENT_SIZE;
2426
2427 } else if (info->has_video && info->is_streaming) {
2428 fragment_size = (PCM_OFFLOAD_BUFFER_DURATION_FOR_AV_STREAMING
2429 * info->sample_rate
2430 * bits_per_sample
2431 * popcount(info->channel_mask))/1000;
2432
2433 } else if (info->has_video) {
2434 fragment_size = (PCM_OFFLOAD_BUFFER_DURATION_FOR_AV
2435 * info->sample_rate
2436 * bits_per_sample
2437 * popcount(info->channel_mask))/1000;
2438 }
2439
2440 fragment_size = ALIGN( fragment_size, 1024);
2441
2442 if(fragment_size < MIN_PCM_OFFLOAD_FRAGMENT_SIZE)
2443 fragment_size = MIN_PCM_OFFLOAD_FRAGMENT_SIZE;
2444 else if(fragment_size > MAX_PCM_OFFLOAD_FRAGMENT_SIZE)
2445 fragment_size = MAX_PCM_OFFLOAD_FRAGMENT_SIZE;
2446
2447 ALOGV("%s: fragment_size %d", __func__, fragment_size);
2448 return fragment_size;
2449}
2450
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07002451bool platform_check_and_set_codec_backend_cfg(struct audio_device* adev __unused,
2452 struct audio_usecase *usecase __unused)
2453{
Mingming Yin3ee55c62014-08-04 14:23:35 -07002454 return false;
2455}
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07002456
2457int platform_get_usecase_index(const char * usecase __unused)
2458{
2459 return -ENOSYS;
2460}
2461
2462int platform_set_usecase_pcm_id(audio_usecase_t usecase __unused, int32_t type __unused,
2463 int32_t pcm_id __unused)
2464{
2465 return -ENOSYS;
2466}
2467
2468int platform_set_snd_device_backend(snd_device_t snd_device __unused,
2469 const char * backend __unused)
2470{
2471 return -ENOSYS;
2472}
2473