blob: c7304a84615bd211daab7cd61ccf01b4493a8402 [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 &&
1194 my_data->adev->mode == AUDIO_MODE_IN_CALL) {
1195 /* 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
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301477 if ((mode == AUDIO_MODE_IN_CALL) ||
1478 voice_extn_compress_voip_is_active(adev)) {
1479 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1480 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
1481 if ((adev->voice.tty_mode != TTY_MODE_OFF) &&
1482 !voice_extn_compress_voip_is_active(adev)) {
1483 switch (adev->voice.tty_mode) {
1484 case TTY_MODE_FULL:
1485 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
1486 break;
1487 case TTY_MODE_VCO:
1488 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
1489 break;
1490 case TTY_MODE_HCO:
1491 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
1492 break;
1493 default:
1494 ALOGE("%s: Invalid TTY mode (%#x)",
1495 __func__, adev->voice.tty_mode);
1496 }
1497 } else if (audio_extn_get_anc_enabled()) {
1498 if (audio_extn_should_use_fb_anc())
1499 snd_device = SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET;
1500 else
1501 snd_device = SND_DEVICE_OUT_VOICE_ANC_HEADSET;
1502 } else {
1503 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
1504 }
1505 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Mingming Yin514a8bc2014-07-29 15:22:21 -07001506 if (adev->bt_wb_speech_enabled)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301507 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
1508 else
1509 snd_device = SND_DEVICE_OUT_BT_SCO;
1510 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
1511 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
1512 } else if (devices & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
1513 devices & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
1514 snd_device = SND_DEVICE_OUT_USB_HEADSET;
1515 } else if (devices & AUDIO_DEVICE_OUT_FM_TX) {
1516 snd_device = SND_DEVICE_OUT_TRANSMISSION_FM;
1517 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
1518 if (audio_extn_should_use_handset_anc(channel_count))
1519 snd_device = SND_DEVICE_OUT_ANC_HANDSET;
1520 else
1521 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
1522 }
1523 if (snd_device != SND_DEVICE_NONE) {
1524 goto exit;
1525 }
1526 }
1527
Naresh Tannirue3b18452014-03-04 14:44:27 +05301528 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1529 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301530 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADSET
1531 && audio_extn_get_anc_enabled()) {
Naresh Tanniruc0517bc2014-10-26 15:30:55 +05301532#ifdef RECORD_PLAY_CONCURRENCY
1533 if (use_voip_out_devices) {
1534 // ANC should be disabled for voip concurrency
1535 snd_device = SND_DEVICE_OUT_VOIP_HEADPHONES;
1536 } else
1537#endif
1538 {
1539 if (audio_extn_should_use_fb_anc())
1540 snd_device = SND_DEVICE_OUT_ANC_FB_HEADSET;
1541 else
1542 snd_device = SND_DEVICE_OUT_ANC_HEADSET;
1543 }
1544 } else {
1545#ifdef RECORD_PLAY_CONCURRENCY
1546 if (use_voip_out_devices)
1547 snd_device = SND_DEVICE_OUT_VOIP_HEADPHONES;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301548 else
Naresh Tanniruc0517bc2014-10-26 15:30:55 +05301549#endif
1550 snd_device = SND_DEVICE_OUT_HEADPHONES;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301551 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05301552 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
Naresh Tanniruc0517bc2014-10-26 15:30:55 +05301553#ifdef RECORD_PLAY_CONCURRENCY
1554 if (use_voip_out_devices) {
1555 snd_device = SND_DEVICE_OUT_VOIP_SPEAKER;
1556 } else
1557#endif
1558 {
1559 if (adev->speaker_lr_swap)
1560 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
1561 else
1562 snd_device = SND_DEVICE_OUT_SPEAKER;
1563 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05301564 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Mingming Yin514a8bc2014-07-29 15:22:21 -07001565 if (adev->bt_wb_speech_enabled)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301566 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
1567 else
1568 snd_device = SND_DEVICE_OUT_BT_SCO;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301569 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
1570 snd_device = SND_DEVICE_OUT_HDMI ;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301571 } else if (devices & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
1572 devices & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
Mingming Yin5a7c5d62014-03-05 17:45:03 -08001573 ALOGD("%s: setting USB hadset channel capability(2) for Proxy", __func__);
1574 audio_extn_set_afe_proxy_channel_mixer(adev, 2);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301575 snd_device = SND_DEVICE_OUT_USB_HEADSET;
1576 } else if (devices & AUDIO_DEVICE_OUT_FM_TX) {
1577 snd_device = SND_DEVICE_OUT_TRANSMISSION_FM;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301578 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Naresh Tanniruc0517bc2014-10-26 15:30:55 +05301579#ifdef RECORD_PLAY_CONCURRENCY
1580 if (use_voip_out_devices)
1581 snd_device = SND_DEVICE_OUT_VOIP_HANDSET;
1582 else
1583#endif
1584 snd_device = SND_DEVICE_OUT_HANDSET;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301585 } else if (devices & AUDIO_DEVICE_OUT_PROXY) {
Mingming Yin5a7c5d62014-03-05 17:45:03 -08001586 channel_count = audio_extn_get_afe_proxy_channel_count();
1587 ALOGD("%s: setting sink capability(%d) for Proxy", __func__, channel_count);
1588 audio_extn_set_afe_proxy_channel_mixer(adev, channel_count);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301589 snd_device = SND_DEVICE_OUT_AFE_PROXY;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301590 } else {
1591 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
1592 }
1593exit:
1594 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
1595 return snd_device;
1596}
1597
1598snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
1599{
1600 struct platform_data *my_data = (struct platform_data *)platform;
1601 struct audio_device *adev = my_data->adev;
1602 audio_source_t source = (adev->active_input == NULL) ?
1603 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
1604
1605 audio_mode_t mode = adev->mode;
1606 audio_devices_t in_device = ((adev->active_input == NULL) ?
1607 AUDIO_DEVICE_NONE : adev->active_input->device)
1608 & ~AUDIO_DEVICE_BIT_IN;
1609 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
1610 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
1611 snd_device_t snd_device = SND_DEVICE_NONE;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301612 int channel_count = popcount(channel_mask);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301613
1614 ALOGV("%s: enter: out_device(%#x) in_device(%#x)",
1615 __func__, out_device, in_device);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301616 if ((out_device != AUDIO_DEVICE_NONE) && ((mode == AUDIO_MODE_IN_CALL) ||
Satya Krishna Pindiproli2aaa6152014-05-21 15:05:22 +05301617 voice_extn_compress_voip_is_active(adev) || audio_extn_hfp_is_active(adev))) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301618 if ((adev->voice.tty_mode != TTY_MODE_OFF) &&
1619 !voice_extn_compress_voip_is_active(adev)) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301620 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1621 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301622 switch (adev->voice.tty_mode) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301623 case TTY_MODE_FULL:
1624 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
1625 break;
1626 case TTY_MODE_VCO:
1627 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
1628 break;
1629 case TTY_MODE_HCO:
1630 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
1631 break;
1632 default:
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301633 ALOGE("%s: Invalid TTY mode (%#x)",
1634 __func__, adev->voice.tty_mode);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301635 }
1636 goto exit;
1637 }
1638 }
1639 if (out_device & AUDIO_DEVICE_OUT_EARPIECE ||
1640 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301641 if (out_device & AUDIO_DEVICE_OUT_EARPIECE &&
1642 audio_extn_should_use_handset_anc(channel_count)) {
1643 snd_device = SND_DEVICE_IN_AANC_HANDSET_MIC;
1644 } else if (my_data->fluence_type == FLUENCE_NONE ||
1645 my_data->fluence_in_voice_call == false) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301646 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +05301647 if (audio_extn_hfp_is_active(adev))
1648 platform_set_echo_reference(adev->platform, true);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301649 } else {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301650 snd_device = SND_DEVICE_IN_VOICE_DMIC;
1651 adev->acdb_settings |= DMIC_FLAG;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301652 }
1653 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
1654 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +05301655 if (audio_extn_hfp_is_active(adev))
1656 platform_set_echo_reference(adev->platform, true);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301657 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Vicky Sehrawate240e5d2014-08-12 17:17:04 -07001658 if (adev->bt_wb_speech_enabled) {
1659 if (adev->bluetooth_nrec)
1660 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
1661 else
1662 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
1663 } else {
1664 if (adev->bluetooth_nrec)
1665 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
1666 else
1667 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
1668 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05301669 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301670 if (my_data->fluence_type != FLUENCE_NONE &&
1671 my_data->fluence_in_voice_call &&
1672 my_data->fluence_in_spkr_mode) {
1673 if(my_data->fluence_type & FLUENCE_QUAD_MIC) {
1674 adev->acdb_settings |= QMIC_FLAG;
1675 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_QMIC;
1676 } else {
1677 adev->acdb_settings |= DMIC_FLAG;
Karthik Reddy Kattad9fff862014-07-21 21:07:21 +05301678 if (my_data->fluence_mode == FLUENCE_BROADSIDE)
1679 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BROADSIDE;
1680 else
1681 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301682 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05301683 } else {
1684 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +05301685 if (audio_extn_hfp_is_active(adev))
1686 platform_set_echo_reference(adev->platform, true);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301687 }
1688 }
1689 } else if (source == AUDIO_SOURCE_CAMCORDER) {
1690 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
1691 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
kunleiz18a33302014-05-30 09:52:25 +08001692 if (my_data->fluence_type & FLUENCE_DUAL_MIC &&
1693 channel_count == 2)
kunleiz8f7e9e22014-06-24 15:12:02 +08001694 snd_device = SND_DEVICE_IN_HANDSET_STEREO_DMIC;
kunleiz18a33302014-05-30 09:52:25 +08001695 else
1696 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301697 }
1698 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
1699 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301700 if (channel_count == 2) {
1701 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
1702 adev->acdb_settings |= DMIC_FLAG;
1703 } else if (adev->active_input->enable_ns)
1704 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
1705 else if (my_data->fluence_type != FLUENCE_NONE &&
1706 my_data->fluence_in_voice_rec) {
1707 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
1708 adev->acdb_settings |= DMIC_FLAG;
1709 } else {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301710 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
1711 }
1712 }
1713 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION) {
1714 if (out_device & AUDIO_DEVICE_OUT_SPEAKER)
1715 in_device = AUDIO_DEVICE_IN_BACK_MIC;
1716 if (adev->active_input) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301717 if (adev->active_input->enable_aec &&
1718 adev->active_input->enable_ns) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301719 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301720 if (my_data->fluence_type & FLUENCE_DUAL_MIC &&
1721 my_data->fluence_in_spkr_mode) {
Karthik Reddy Kattad9fff862014-07-21 21:07:21 +05301722 if (my_data->fluence_mode == FLUENCE_BROADSIDE)
1723 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_BROADSIDE;
1724 else
1725 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301726 adev->acdb_settings |= DMIC_FLAG;
1727 } else
1728 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301729 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301730 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1731 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
1732 adev->acdb_settings |= DMIC_FLAG;
1733 } else
1734 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301735 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301736 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301737 }
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +05301738 platform_set_echo_reference(adev->platform, true);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301739 } else if (adev->active_input->enable_aec) {
1740 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Karthik Reddy Kattad9fff862014-07-21 21:07:21 +05301741 if (my_data->fluence_type & FLUENCE_DUAL_MIC &&
1742 my_data->fluence_in_spkr_mode) {
1743 if (my_data->fluence_mode == FLUENCE_BROADSIDE)
1744 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_BROADSIDE;
1745 else
1746 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301747 adev->acdb_settings |= DMIC_FLAG;
1748 } else
1749 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
1750 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
1751 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1752 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
1753 adev->acdb_settings |= DMIC_FLAG;
1754 } else
1755 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
1756 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
1757 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
1758 }
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +05301759 platform_set_echo_reference(adev->platform, true);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301760 } else if (adev->active_input->enable_ns) {
1761 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Karthik Reddy Kattad9fff862014-07-21 21:07:21 +05301762 if (my_data->fluence_type & FLUENCE_DUAL_MIC &&
1763 my_data->fluence_in_spkr_mode) {
1764 if (my_data->fluence_mode == FLUENCE_BROADSIDE)
1765 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS_BROADSIDE;
1766 else
1767 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301768 adev->acdb_settings |= DMIC_FLAG;
1769 } else
1770 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
1771 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
1772 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1773 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
1774 adev->acdb_settings |= DMIC_FLAG;
1775 } else
1776 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
1777 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
1778 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
1779 }
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +05301780 platform_set_echo_reference(adev->platform,false);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301781 } else
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +05301782 platform_set_echo_reference(adev->platform, false);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301783 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301784 } else if (source == AUDIO_SOURCE_MIC) {
1785 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC &&
1786 channel_count == 1 ) {
1787 if(my_data->fluence_type & FLUENCE_DUAL_MIC &&
1788 my_data->fluence_in_audio_rec)
1789 snd_device = SND_DEVICE_IN_HANDSET_DMIC;
1790 }
1791 } else if (source == AUDIO_SOURCE_FM_RX ||
1792 source == AUDIO_SOURCE_FM_RX_A2DP) {
1793 snd_device = SND_DEVICE_IN_CAPTURE_FM;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301794 } else if (source == AUDIO_SOURCE_DEFAULT) {
1795 goto exit;
1796 }
1797
1798
1799 if (snd_device != SND_DEVICE_NONE) {
1800 goto exit;
1801 }
1802
1803 if (in_device != AUDIO_DEVICE_NONE &&
1804 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
1805 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
1806 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301807 if (audio_extn_ssr_get_enabled() && channel_count == 6)
1808 snd_device = SND_DEVICE_IN_QUAD_MIC;
1809 else if (channel_count == 2)
1810 snd_device = SND_DEVICE_IN_HANDSET_STEREO_DMIC;
1811 else
1812 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301813 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
1814 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
1815 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
1816 snd_device = SND_DEVICE_IN_HEADSET_MIC;
1817 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Vicky Sehrawate240e5d2014-08-12 17:17:04 -07001818 if (adev->bt_wb_speech_enabled) {
1819 if (adev->bluetooth_nrec)
1820 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
1821 else
1822 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
1823 } else {
1824 if (adev->bluetooth_nrec)
1825 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
1826 else
1827 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
1828 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05301829 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
1830 snd_device = SND_DEVICE_IN_HDMI_MIC;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301831 } else if (in_device & AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET ||
1832 in_device & AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET) {
1833 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
1834 } else if (in_device & AUDIO_DEVICE_IN_FM_RX) {
1835 snd_device = SND_DEVICE_IN_CAPTURE_FM;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301836 } else {
1837 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
1838 ALOGW("%s: Using default handset-mic", __func__);
1839 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1840 }
1841 } else {
1842 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
1843 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1844 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
1845 snd_device = SND_DEVICE_IN_HEADSET_MIC;
1846 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301847 if (channel_count > 1)
1848 snd_device = SND_DEVICE_IN_SPEAKER_STEREO_DMIC;
1849 else
1850 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301851 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
1852 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1853 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Vicky Sehrawate240e5d2014-08-12 17:17:04 -07001854 if (adev->bt_wb_speech_enabled) {
1855 if (adev->bluetooth_nrec)
1856 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
1857 else
1858 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
1859 } else {
1860 if (adev->bluetooth_nrec)
1861 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
1862 else
1863 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
1864 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05301865 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
1866 snd_device = SND_DEVICE_IN_HDMI_MIC;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301867 } else if (out_device & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
1868 out_device & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
1869 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301870 } else {
1871 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
1872 ALOGW("%s: Using default handset-mic", __func__);
1873 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1874 }
1875 }
1876exit:
1877 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
1878 return snd_device;
1879}
1880
1881int platform_set_hdmi_channels(void *platform, int channel_count)
1882{
1883 struct platform_data *my_data = (struct platform_data *)platform;
1884 struct audio_device *adev = my_data->adev;
1885 struct mixer_ctl *ctl;
1886 const char *channel_cnt_str = NULL;
1887 const char *mixer_ctl_name = "HDMI_RX Channels";
1888 switch (channel_count) {
1889 case 8:
1890 channel_cnt_str = "Eight"; break;
1891 case 7:
1892 channel_cnt_str = "Seven"; break;
1893 case 6:
1894 channel_cnt_str = "Six"; break;
1895 case 5:
1896 channel_cnt_str = "Five"; break;
1897 case 4:
1898 channel_cnt_str = "Four"; break;
1899 case 3:
1900 channel_cnt_str = "Three"; break;
1901 default:
1902 channel_cnt_str = "Two"; break;
1903 }
1904 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1905 if (!ctl) {
1906 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1907 __func__, mixer_ctl_name);
1908 return -EINVAL;
1909 }
1910 ALOGV("HDMI channel count: %s", channel_cnt_str);
1911 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
1912 return 0;
1913}
1914
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301915int platform_edid_get_max_channels(void *platform)
Naresh Tannirue3b18452014-03-04 14:44:27 +05301916{
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301917 struct platform_data *my_data = (struct platform_data *)platform;
1918 struct audio_device *adev = my_data->adev;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301919 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
1920 char *sad = block;
1921 int num_audio_blocks;
1922 int channel_count;
1923 int max_channels = 0;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301924 int i, ret, count;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301925
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301926 struct mixer_ctl *ctl;
1927
1928 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
1929 if (!ctl) {
1930 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1931 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301932 return 0;
1933 }
1934
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301935 mixer_ctl_update(ctl);
1936
1937 count = mixer_ctl_get_num_values(ctl);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301938
1939 /* Read SAD blocks, clamping the maximum size for safety */
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301940 if (count > (int)sizeof(block))
1941 count = (int)sizeof(block);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301942
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301943 ret = mixer_ctl_get_array(ctl, block, count);
1944 if (ret != 0) {
1945 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
1946 return 0;
1947 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05301948
1949 /* Calculate the number of SAD blocks */
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301950 num_audio_blocks = count / SAD_BLOCK_SIZE;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301951
1952 for (i = 0; i < num_audio_blocks; i++) {
1953 /* Only consider LPCM blocks */
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301954 if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
1955 sad += 3;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301956 continue;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301957 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05301958
1959 channel_count = (sad[0] & 0x7) + 1;
1960 if (channel_count > max_channels)
1961 max_channels = channel_count;
1962
1963 /* Advance to next block */
1964 sad += 3;
1965 }
1966
1967 return max_channels;
1968}
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301969
1970static int platform_set_slowtalk(struct platform_data *my_data, bool state)
1971{
1972 int ret = 0;
1973 struct audio_device *adev = my_data->adev;
1974 struct mixer_ctl *ctl;
1975 const char *mixer_ctl_name = "Slowtalk Enable";
1976 uint32_t set_values[ ] = {0,
1977 ALL_SESSION_VSID};
1978
1979 set_values[0] = state;
1980 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1981 if (!ctl) {
1982 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1983 __func__, mixer_ctl_name);
1984 ret = -EINVAL;
1985 } else {
1986 ALOGV("Setting slowtalk state: %d", state);
1987 ret = mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1988 my_data->slowtalk = state;
1989 }
1990
1991 if (my_data->csd != NULL) {
1992 ret = my_data->csd->slow_talk(ALL_SESSION_VSID, state);
1993 if (ret < 0) {
1994 ALOGE("%s: csd_client_disable_device, failed, error %d",
1995 __func__, ret);
1996 }
1997 }
1998 return ret;
1999}
2000
Avinash Vaishd5fa4572014-09-15 14:41:14 +05302001static int set_hd_voice(struct platform_data *my_data, bool state)
2002{
2003 struct audio_device *adev = my_data->adev;
2004 struct mixer_ctl *ctl;
2005 const char *mixer_ctl_name = "HD Voice Enable";
2006 int ret = 0;
2007 uint32_t set_values[ ] = {0,
2008 ALL_SESSION_VSID};
2009
2010 set_values[0] = state;
2011 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2012 if (!ctl) {
2013 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2014 __func__, mixer_ctl_name);
2015 ret = -EINVAL;
2016 } else {
2017 ALOGV("Setting HD Voice state: %d", state);
2018 ret = mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2019 my_data->hd_voice = state;
2020 }
2021
2022 return ret;
2023}
2024
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302025int platform_set_parameters(void *platform, struct str_parms *parms)
2026{
2027 struct platform_data *my_data = (struct platform_data *)platform;
2028 char *str;
2029 char value[256] = {0};
2030 int val;
2031 int ret = 0, err;
Karthik Reddy Kattabfe193d2014-08-14 17:58:18 +05302032 char *kv_pairs = NULL;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302033
Karthik Reddy Kattabfe193d2014-08-14 17:58:18 +05302034 kv_pairs = str_parms_to_str(parms);
2035 ALOGV("%s: enter: - %s", __func__, kv_pairs);
2036 free(kv_pairs);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302037
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302038 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_SLOWTALK, value, sizeof(value));
2039 if (err >= 0) {
2040 bool state = false;
2041 if (!strncmp("true", value, sizeof("true"))) {
2042 state = true;
2043 }
2044
2045 str_parms_del(parms, AUDIO_PARAMETER_KEY_SLOWTALK);
2046 ret = platform_set_slowtalk(my_data, state);
2047 if (ret)
2048 ALOGE("%s: Failed to set slow talk err: %d", __func__, ret);
2049 }
2050
Avinash Vaishd5fa4572014-09-15 14:41:14 +05302051 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_HD_VOICE, value, sizeof(value));
2052 if (err >= 0) {
2053 bool state = false;
2054 if (!strncmp("true", value, sizeof("true"))) {
2055 state = true;
2056 }
2057
2058 str_parms_del(parms, AUDIO_PARAMETER_KEY_HD_VOICE);
2059 if (my_data->hd_voice != state) {
2060 ret = set_hd_voice(my_data, state);
2061 if (ret)
2062 ALOGE("%s: Failed to set HD voice err: %d", __func__, ret);
2063 } else {
2064 ALOGV("%s: HD Voice already set to %d", __func__, state);
2065 }
2066 }
2067
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302068 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_VOLUME_BOOST,
2069 value, sizeof(value));
2070 if (err >= 0) {
2071 str_parms_del(parms, AUDIO_PARAMETER_KEY_VOLUME_BOOST);
2072
2073 if (my_data->acdb_reload_vocvoltable == NULL) {
2074 ALOGE("%s: acdb_reload_vocvoltable is NULL", __func__);
2075 } else if (!strcmp(value, "on")) {
2076 if (!my_data->acdb_reload_vocvoltable(VOICE_FEATURE_SET_VOLUME_BOOST)) {
2077 my_data->voice_feature_set = 1;
2078 }
2079 } else {
2080 if (!my_data->acdb_reload_vocvoltable(VOICE_FEATURE_SET_DEFAULT)) {
2081 my_data->voice_feature_set = 0;
2082 }
2083 }
2084 }
2085
Naresh Tanniruc0517bc2014-10-26 15:30:55 +05302086#ifdef RECORD_PLAY_CONCURRENCY
2087 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_REC_PLAY_CONC, value, sizeof(value));
2088 if (err >= 0) {
2089 if (!strncmp("true", value, sizeof("true"))) {
2090 ALOGD("setting record playback concurrency to true");
2091 my_data->rec_play_conc_set = true;
2092 } else {
2093 ALOGD("setting record playback concurrency to false");
2094 my_data->rec_play_conc_set = false;
2095 }
2096 str_parms_del(parms, AUDIO_PARAMETER_KEY_REC_PLAY_CONC);
2097 }
2098#endif
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302099 ALOGV("%s: exit with code(%d)", __func__, ret);
2100 return ret;
2101}
2102
2103int platform_set_incall_recording_session_id(void *platform,
2104 uint32_t session_id, int rec_mode)
2105{
2106 int ret = 0;
2107 struct platform_data *my_data = (struct platform_data *)platform;
2108 struct audio_device *adev = my_data->adev;
2109 struct mixer_ctl *ctl;
2110 const char *mixer_ctl_name = "Voc VSID";
2111 int num_ctl_values;
2112 int i;
2113
2114 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2115 if (!ctl) {
2116 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2117 __func__, mixer_ctl_name);
2118 ret = -EINVAL;
2119 } else {
2120 num_ctl_values = mixer_ctl_get_num_values(ctl);
2121 for (i = 0; i < num_ctl_values; i++) {
2122 if (mixer_ctl_set_value(ctl, i, session_id)) {
2123 ALOGV("Error: invalid session_id: %x", session_id);
2124 ret = -EINVAL;
2125 break;
2126 }
2127 }
2128 }
2129
2130 if (my_data->csd != NULL) {
2131 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
2132 if (ret < 0) {
2133 ALOGE("%s: csd_client_start_record failed, error %d",
2134 __func__, ret);
2135 }
2136 }
2137
2138 return ret;
2139}
2140
2141int platform_stop_incall_recording_usecase(void *platform)
2142{
2143 int ret = 0;
2144 struct platform_data *my_data = (struct platform_data *)platform;
2145
2146 if (my_data->csd != NULL) {
2147 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
2148 if (ret < 0) {
2149 ALOGE("%s: csd_client_stop_record failed, error %d",
2150 __func__, ret);
2151 }
2152 }
2153
2154 return ret;
2155}
2156
2157int platform_start_incall_music_usecase(void *platform)
2158{
2159 int ret = 0;
2160 struct platform_data *my_data = (struct platform_data *)platform;
2161
2162 if (my_data->csd != NULL) {
2163 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
2164 if (ret < 0) {
2165 ALOGE("%s: csd_client_start_playback failed, error %d",
2166 __func__, ret);
2167 }
2168 }
2169
2170 return ret;
2171}
2172
2173int platform_stop_incall_music_usecase(void *platform)
2174{
2175 int ret = 0;
2176 struct platform_data *my_data = (struct platform_data *)platform;
2177
2178 if (my_data->csd != NULL) {
2179 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
2180 if (ret < 0) {
2181 ALOGE("%s: csd_client_stop_playback failed, error %d",
2182 __func__, ret);
2183 }
2184 }
2185
2186 return ret;
2187}
2188
Vidyakumar Athota21b3bb92014-04-25 11:08:08 -07002189int platform_update_lch(void *platform, struct voice_session *session,
2190 enum voice_lch_mode lch_mode)
2191{
2192 int ret = 0;
2193 struct platform_data *my_data = (struct platform_data *)platform;
2194
2195 if ((my_data->csd != NULL) && (my_data->csd->set_lch != NULL))
2196 ret = my_data->csd->set_lch(session->vsid, lch_mode);
2197 else
2198 ret = pcm_ioctl(session->pcm_tx, SNDRV_VOICE_IOCTL_LCH, &lch_mode);
2199
2200 return ret;
2201}
2202
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302203void platform_get_parameters(void *platform,
2204 struct str_parms *query,
2205 struct str_parms *reply)
2206{
2207 struct platform_data *my_data = (struct platform_data *)platform;
2208 char *str = NULL;
2209 char value[256] = {0};
2210 int ret;
Karthik Reddy Kattabfe193d2014-08-14 17:58:18 +05302211 char *kv_pairs = NULL;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302212
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302213 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_SLOWTALK,
2214 value, sizeof(value));
2215 if (ret >= 0) {
2216 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_SLOWTALK,
2217 my_data->slowtalk?"true":"false");
2218 }
2219
Avinash Vaishd5fa4572014-09-15 14:41:14 +05302220 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_HD_VOICE,
2221 value, sizeof(value));
2222 if (ret >= 0) {
2223 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_HD_VOICE,
2224 my_data->hd_voice?"true":"false");
2225 }
2226
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302227 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_VOLUME_BOOST,
2228 value, sizeof(value));
2229 if (ret >= 0) {
2230 if (my_data->voice_feature_set == VOICE_FEATURE_SET_VOLUME_BOOST) {
2231 strlcpy(value, "on", sizeof(value));
2232 } else {
2233 strlcpy(value, "off", sizeof(value));
2234 }
2235
2236 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_VOLUME_BOOST, value);
2237 }
2238
Karthik Reddy Kattabfe193d2014-08-14 17:58:18 +05302239 kv_pairs = str_parms_to_str(reply);
2240 ALOGV("%s: exit: returns - %s", __func__, kv_pairs);
2241 free(kv_pairs);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302242}
2243
2244/* Delay in Us */
2245int64_t platform_render_latency(audio_usecase_t usecase)
2246{
2247 switch (usecase) {
2248 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
2249 return DEEP_BUFFER_PLATFORM_DELAY;
2250 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
2251 return LOW_LATENCY_PLATFORM_DELAY;
2252 default:
2253 return 0;
2254 }
2255}
2256
2257int platform_update_usecase_from_source(int source, int usecase)
2258{
2259 ALOGV("%s: input source :%d", __func__, source);
2260 if(source == AUDIO_SOURCE_FM_RX_A2DP)
2261 usecase = USECASE_AUDIO_RECORD_FM_VIRTUAL;
2262 return usecase;
2263}
2264
Dhananjay Kumar45b71742014-05-29 21:47:27 +05302265bool platform_listen_device_needs_event(snd_device_t snd_device)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302266{
Dhananjay Kumar45b71742014-05-29 21:47:27 +05302267 bool needs_event = false;
2268
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302269 if ((snd_device >= SND_DEVICE_IN_BEGIN) &&
2270 (snd_device < SND_DEVICE_IN_END) &&
2271 (snd_device != SND_DEVICE_IN_CAPTURE_FM) &&
2272 (snd_device != SND_DEVICE_IN_CAPTURE_VI_FEEDBACK))
Dhananjay Kumar45b71742014-05-29 21:47:27 +05302273 needs_event = true;
2274
2275 return needs_event;
2276}
2277
2278bool platform_listen_usecase_needs_event(audio_usecase_t uc_id)
2279{
2280 bool needs_event = false;
2281
2282 switch(uc_id){
2283 /* concurrent playback usecases needs event */
2284 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
2285 case USECASE_AUDIO_PLAYBACK_MULTI_CH:
2286 case USECASE_AUDIO_PLAYBACK_OFFLOAD:
2287 needs_event = true;
2288 break;
2289 /* concurrent playback in low latency allowed */
2290 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
2291 break;
2292 /* concurrent playback FM needs event */
2293 case USECASE_AUDIO_PLAYBACK_FM:
2294 needs_event = true;
2295 break;
2296
2297 /* concurrent capture usecases, no event, capture handled by device
2298 * USECASE_AUDIO_RECORD:
2299 * USECASE_AUDIO_RECORD_COMPRESS:
2300 * USECASE_AUDIO_RECORD_LOW_LATENCY:
2301
2302 * USECASE_VOICE_CALL:
2303 * USECASE_VOICE2_CALL:
2304 * USECASE_VOLTE_CALL:
2305 * USECASE_QCHAT_CALL:
2306 * USECASE_VOWLAN_CALL:
2307 * USECASE_COMPRESS_VOIP_CALL:
2308 * USECASE_AUDIO_RECORD_FM_VIRTUAL:
2309 * USECASE_INCALL_REC_UPLINK:
2310 * USECASE_INCALL_REC_DOWNLINK:
2311 * USECASE_INCALL_REC_UPLINK_AND_DOWNLINK:
2312 * USECASE_INCALL_REC_UPLINK_COMPRESS:
2313 * USECASE_INCALL_REC_DOWNLINK_COMPRESS:
2314 * USECASE_INCALL_REC_UPLINK_AND_DOWNLINK_COMPRESS:
2315 * USECASE_INCALL_MUSIC_UPLINK:
2316 * USECASE_INCALL_MUSIC_UPLINK2:
2317 * USECASE_AUDIO_SPKR_CALIB_RX:
2318 * USECASE_AUDIO_SPKR_CALIB_TX:
2319 */
2320 default:
2321 ALOGV("%s:usecase_id[%d} no need to raise event.", __func__, uc_id);
2322 }
2323 return needs_event;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302324}
2325
Ravi Kumar Alamanda8fa6b192014-09-09 16:06:42 -07002326bool platform_sound_trigger_device_needs_event(snd_device_t snd_device)
2327{
2328 bool needs_event = false;
2329
2330 if ((snd_device >= SND_DEVICE_IN_BEGIN) &&
2331 (snd_device < SND_DEVICE_IN_END) &&
2332 (snd_device != SND_DEVICE_IN_CAPTURE_FM) &&
2333 (snd_device != SND_DEVICE_IN_CAPTURE_VI_FEEDBACK))
2334 needs_event = true;
2335
2336 return needs_event;
2337}
2338
2339bool platform_sound_trigger_usecase_needs_event(audio_usecase_t uc_id)
2340{
2341 bool needs_event = false;
2342
2343 switch(uc_id){
2344 /* concurrent playback usecases needs event */
2345 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
2346 case USECASE_AUDIO_PLAYBACK_MULTI_CH:
2347 case USECASE_AUDIO_PLAYBACK_OFFLOAD:
2348 needs_event = true;
2349 break;
2350 /* concurrent playback in low latency allowed */
2351 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
2352 break;
2353 /* concurrent playback FM needs event */
2354 case USECASE_AUDIO_PLAYBACK_FM:
2355 needs_event = true;
2356 break;
2357
2358 /* concurrent capture usecases, no event, capture handled by device
2359 * USECASE_AUDIO_RECORD:
2360 * USECASE_AUDIO_RECORD_COMPRESS:
2361 * USECASE_AUDIO_RECORD_LOW_LATENCY:
2362
2363 * USECASE_VOICE_CALL:
2364 * USECASE_VOICE2_CALL:
2365 * USECASE_VOLTE_CALL:
2366 * USECASE_QCHAT_CALL:
2367 * USECASE_VOWLAN_CALL:
2368 * USECASE_COMPRESS_VOIP_CALL:
2369 * USECASE_AUDIO_RECORD_FM_VIRTUAL:
2370 * USECASE_INCALL_REC_UPLINK:
2371 * USECASE_INCALL_REC_DOWNLINK:
2372 * USECASE_INCALL_REC_UPLINK_AND_DOWNLINK:
2373 * USECASE_INCALL_REC_UPLINK_COMPRESS:
2374 * USECASE_INCALL_REC_DOWNLINK_COMPRESS:
2375 * USECASE_INCALL_REC_UPLINK_AND_DOWNLINK_COMPRESS:
2376 * USECASE_INCALL_MUSIC_UPLINK:
2377 * USECASE_INCALL_MUSIC_UPLINK2:
2378 * USECASE_AUDIO_SPKR_CALIB_RX:
2379 * USECASE_AUDIO_SPKR_CALIB_TX:
2380 */
2381 default:
2382 ALOGV("%s:usecase_id[%d] no need to raise event.", __func__, uc_id);
2383 }
2384 return needs_event;
2385}
2386
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302387/* Read offload buffer size from a property.
2388 * If value is not power of 2 round it to
2389 * power of 2.
2390 */
2391uint32_t platform_get_compress_offload_buffer_size(audio_offload_info_t* info)
2392{
2393 char value[PROPERTY_VALUE_MAX] = {0};
2394 uint32_t fragment_size = COMPRESS_OFFLOAD_FRAGMENT_SIZE;
2395 if((property_get("audio.offload.buffer.size.kb", value, "")) &&
2396 atoi(value)) {
2397 fragment_size = atoi(value) * 1024;
2398 }
2399
2400 if (info != NULL && info->has_video && info->is_streaming) {
2401 fragment_size = COMPRESS_OFFLOAD_FRAGMENT_SIZE_FOR_AV_STREAMING;
2402 ALOGV("%s: offload fragment size reduced for AV streaming to %d",
Apoorv Raghuvanshi44bd9172014-05-28 14:50:07 -07002403 __func__, fragment_size);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302404 }
2405
2406 fragment_size = ALIGN( fragment_size, 1024);
2407
2408 if(fragment_size < MIN_COMPRESS_OFFLOAD_FRAGMENT_SIZE)
2409 fragment_size = MIN_COMPRESS_OFFLOAD_FRAGMENT_SIZE;
2410 else if(fragment_size > MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE)
2411 fragment_size = MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE;
2412 ALOGV("%s: fragment_size %d", __func__, fragment_size);
2413 return fragment_size;
2414}
2415
2416uint32_t platform_get_pcm_offload_buffer_size(audio_offload_info_t* info)
2417{
2418 uint32_t fragment_size = MIN_PCM_OFFLOAD_FRAGMENT_SIZE;
2419 uint32_t bits_per_sample = 16;
2420
2421 if (info->format == AUDIO_FORMAT_PCM_24_BIT_OFFLOAD) {
2422 bits_per_sample = 32;
2423 }
2424
2425 if (!info->has_video) {
2426 fragment_size = MAX_PCM_OFFLOAD_FRAGMENT_SIZE;
2427
2428 } else if (info->has_video && info->is_streaming) {
2429 fragment_size = (PCM_OFFLOAD_BUFFER_DURATION_FOR_AV_STREAMING
2430 * info->sample_rate
2431 * bits_per_sample
2432 * popcount(info->channel_mask))/1000;
2433
2434 } else if (info->has_video) {
2435 fragment_size = (PCM_OFFLOAD_BUFFER_DURATION_FOR_AV
2436 * info->sample_rate
2437 * bits_per_sample
2438 * popcount(info->channel_mask))/1000;
2439 }
2440
2441 fragment_size = ALIGN( fragment_size, 1024);
2442
2443 if(fragment_size < MIN_PCM_OFFLOAD_FRAGMENT_SIZE)
2444 fragment_size = MIN_PCM_OFFLOAD_FRAGMENT_SIZE;
2445 else if(fragment_size > MAX_PCM_OFFLOAD_FRAGMENT_SIZE)
2446 fragment_size = MAX_PCM_OFFLOAD_FRAGMENT_SIZE;
2447
2448 ALOGV("%s: fragment_size %d", __func__, fragment_size);
2449 return fragment_size;
2450}
2451
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07002452bool platform_check_and_set_codec_backend_cfg(struct audio_device* adev __unused,
2453 struct audio_usecase *usecase __unused)
2454{
Mingming Yin3ee55c62014-08-04 14:23:35 -07002455 return false;
2456}
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07002457
2458int platform_get_usecase_index(const char * usecase __unused)
2459{
2460 return -ENOSYS;
2461}
2462
2463int platform_set_usecase_pcm_id(audio_usecase_t usecase __unused, int32_t type __unused,
2464 int32_t pcm_id __unused)
2465{
2466 return -ENOSYS;
2467}
2468
2469int platform_set_snd_device_backend(snd_device_t snd_device __unused,
2470 const char * backend __unused)
2471{
2472 return -ENOSYS;
2473}
2474