blob: b978ae37441348ec5d642c1c370a3a6e438f481a [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 Tannirudb72d1e2014-03-05 17:33:47 +0530107
108enum {
109 VOICE_FEATURE_SET_DEFAULT,
110 VOICE_FEATURE_SET_VOLUME_BOOST
111};
112
Naresh Tannirue3b18452014-03-04 14:44:27 +0530113struct audio_block_header
114{
115 int reserved;
116 int length;
117};
118
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530119/* Audio calibration related functions */
Naresh Tannirue3b18452014-03-04 14:44:27 +0530120typedef void (*acdb_deallocate_t)();
Avinash Vaish71c066d2014-08-27 12:32:35 +0530121typedef int (*acdb_init_t)(char *, char *);
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -0700122typedef void (*acdb_send_audio_cal_t)(int, int, int, int);
Naresh Tannirue3b18452014-03-04 14:44:27 +0530123typedef void (*acdb_send_voice_cal_t)(int, int);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530124typedef int (*acdb_reload_vocvoltable_t)(int);
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -0700125typedef int (*acdb_get_default_app_type_t)(void);
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +0530126typedef int (*acdb_loader_get_calibration_t)(char *attr, int size, void *data);
127acdb_loader_get_calibration_t acdb_loader_get_calibration;
Naresh Tannirue3b18452014-03-04 14:44:27 +0530128
Naresh Tannirue3b18452014-03-04 14:44:27 +0530129struct platform_data {
130 struct audio_device *adev;
131 bool fluence_in_spkr_mode;
132 bool fluence_in_voice_call;
133 bool fluence_in_voice_rec;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530134 bool fluence_in_audio_rec;
135 int fluence_type;
Venkata Narendra Kumar Gutta88fd0bc2014-03-27 19:47:56 +0530136 char fluence_cap[PROPERTY_VALUE_MAX];
Karthik Reddy Kattad9fff862014-07-21 21:07:21 +0530137 int fluence_mode;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530138 bool slowtalk;
Avinash Vaishd5fa4572014-09-15 14:41:14 +0530139 bool hd_voice;
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +0530140 bool ec_ref_enabled;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530141 /* Audio calibration related functions */
142 void *acdb_handle;
143 int voice_feature_set;
144 acdb_init_t acdb_init;
145 acdb_deallocate_t acdb_deallocate;
146 acdb_send_audio_cal_t acdb_send_audio_cal;
147 acdb_send_voice_cal_t acdb_send_voice_cal;
148 acdb_reload_vocvoltable_t acdb_reload_vocvoltable;
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -0700149 acdb_get_default_app_type_t acdb_get_default_app_type;
Naresh Tannirue3b18452014-03-04 14:44:27 +0530150
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530151 void *hw_info;
152 struct csd_data *csd;
Naresh Tannirue3b18452014-03-04 14:44:27 +0530153};
154
155static const int pcm_device_table[AUDIO_USECASE_MAX][2] = {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530156 [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = {DEEP_BUFFER_PCM_DEVICE,
157 DEEP_BUFFER_PCM_DEVICE},
158 [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
159 LOWLATENCY_PCM_DEVICE},
160 [USECASE_AUDIO_PLAYBACK_MULTI_CH] = {MULTIMEDIA2_PCM_DEVICE,
161 MULTIMEDIA2_PCM_DEVICE},
162 [USECASE_AUDIO_PLAYBACK_OFFLOAD] =
163 {PLAYBACK_OFFLOAD_DEVICE, PLAYBACK_OFFLOAD_DEVICE},
164 [USECASE_AUDIO_RECORD] = {AUDIO_RECORD_PCM_DEVICE, AUDIO_RECORD_PCM_DEVICE},
165 [USECASE_AUDIO_RECORD_COMPRESS] = {COMPRESS_CAPTURE_DEVICE, COMPRESS_CAPTURE_DEVICE},
166 [USECASE_AUDIO_RECORD_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
167 LOWLATENCY_PCM_DEVICE},
168 [USECASE_AUDIO_RECORD_FM_VIRTUAL] = {MULTIMEDIA2_PCM_DEVICE,
169 MULTIMEDIA2_PCM_DEVICE},
170 [USECASE_AUDIO_PLAYBACK_FM] = {FM_PLAYBACK_PCM_DEVICE, FM_CAPTURE_PCM_DEVICE},
171 [USECASE_AUDIO_HFP_SCO] = {HFP_PCM_RX, HFP_SCO_RX},
172 [USECASE_AUDIO_HFP_SCO_WB] = {HFP_PCM_RX, HFP_SCO_RX},
173 [USECASE_VOICE_CALL] = {VOICE_CALL_PCM_DEVICE, VOICE_CALL_PCM_DEVICE},
174 [USECASE_VOICE2_CALL] = {VOICE2_CALL_PCM_DEVICE, VOICE2_CALL_PCM_DEVICE},
175 [USECASE_VOLTE_CALL] = {VOLTE_CALL_PCM_DEVICE, VOLTE_CALL_PCM_DEVICE},
176 [USECASE_QCHAT_CALL] = {QCHAT_CALL_PCM_DEVICE, QCHAT_CALL_PCM_DEVICE},
Karthik Reddy Katta3b0a60c2014-04-06 14:52:37 +0530177 [USECASE_VOWLAN_CALL] = {VOWLAN_CALL_PCM_DEVICE, VOWLAN_CALL_PCM_DEVICE},
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530178 [USECASE_COMPRESS_VOIP_CALL] = {COMPRESS_VOIP_CALL_PCM_DEVICE, COMPRESS_VOIP_CALL_PCM_DEVICE},
179 [USECASE_INCALL_REC_UPLINK] = {AUDIO_RECORD_PCM_DEVICE,
180 AUDIO_RECORD_PCM_DEVICE},
181 [USECASE_INCALL_REC_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
182 AUDIO_RECORD_PCM_DEVICE},
183 [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
184 AUDIO_RECORD_PCM_DEVICE},
185 [USECASE_INCALL_REC_UPLINK_COMPRESS] = {COMPRESS_CAPTURE_DEVICE,
186 COMPRESS_CAPTURE_DEVICE},
187 [USECASE_INCALL_REC_DOWNLINK_COMPRESS] = {COMPRESS_CAPTURE_DEVICE,
188 COMPRESS_CAPTURE_DEVICE},
189 [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK_COMPRESS] = {COMPRESS_CAPTURE_DEVICE,
190 COMPRESS_CAPTURE_DEVICE},
191 [USECASE_INCALL_MUSIC_UPLINK] = {INCALL_MUSIC_UPLINK_PCM_DEVICE,
192 INCALL_MUSIC_UPLINK_PCM_DEVICE},
193 [USECASE_INCALL_MUSIC_UPLINK2] = {INCALL_MUSIC_UPLINK2_PCM_DEVICE,
194 INCALL_MUSIC_UPLINK2_PCM_DEVICE},
195 [USECASE_AUDIO_SPKR_CALIB_RX] = {SPKR_PROT_CALIB_RX_PCM_DEVICE, -1},
196 [USECASE_AUDIO_SPKR_CALIB_TX] = {-1, SPKR_PROT_CALIB_TX_PCM_DEVICE},
Naresh Tannirue3b18452014-03-04 14:44:27 +0530197};
198
199/* Array to store sound devices */
200static const char * const device_table[SND_DEVICE_MAX] = {
201 [SND_DEVICE_NONE] = "none",
202 /* Playback sound devices */
203 [SND_DEVICE_OUT_HANDSET] = "handset",
204 [SND_DEVICE_OUT_SPEAKER] = "speaker",
205 [SND_DEVICE_OUT_SPEAKER_REVERSE] = "speaker-reverse",
206 [SND_DEVICE_OUT_HEADPHONES] = "headphones",
207 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones",
208 [SND_DEVICE_OUT_VOICE_HANDSET] = "voice-handset",
209 [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker",
210 [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones",
211 [SND_DEVICE_OUT_HDMI] = "hdmi",
212 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi",
213 [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530214 [SND_DEVICE_OUT_BT_SCO_WB] = "bt-sco-headset-wb",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530215 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones",
216 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones",
217 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530218 [SND_DEVICE_OUT_AFE_PROXY] = "afe-proxy",
219 [SND_DEVICE_OUT_USB_HEADSET] = "usb-headphones",
220 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = "speaker-and-usb-headphones",
221 [SND_DEVICE_OUT_TRANSMISSION_FM] = "transmission-fm",
222 [SND_DEVICE_OUT_ANC_HEADSET] = "anc-headphones",
223 [SND_DEVICE_OUT_ANC_FB_HEADSET] = "anc-fb-headphones",
224 [SND_DEVICE_OUT_VOICE_ANC_HEADSET] = "voice-anc-headphones",
225 [SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET] = "voice-anc-fb-headphones",
226 [SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET] = "speaker-and-anc-headphones",
227 [SND_DEVICE_OUT_ANC_HANDSET] = "anc-handset",
228 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = "speaker-protected",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530229
230 /* Capture sound devices */
231 [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530232 [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530233 [SND_DEVICE_IN_HANDSET_MIC_NS] = "handset-mic",
234 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = "handset-mic",
235 [SND_DEVICE_IN_HANDSET_DMIC] = "dmic-endfire",
236 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = "dmic-endfire",
237 [SND_DEVICE_IN_HANDSET_DMIC_NS] = "dmic-endfire",
238 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = "dmic-endfire",
239 [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
240 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "speaker-mic",
241 [SND_DEVICE_IN_SPEAKER_MIC_NS] = "speaker-mic",
242 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = "speaker-mic",
243 [SND_DEVICE_IN_SPEAKER_DMIC] = "speaker-dmic-endfire",
244 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = "speaker-dmic-endfire",
245 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = "speaker-dmic-endfire",
246 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = "speaker-dmic-endfire",
247 [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
248 [SND_DEVICE_IN_HEADSET_MIC_FLUENCE] = "headset-mic",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530249 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
250 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
251 [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic",
252 [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
Vicky Sehrawate240e5d2014-08-12 17:17:04 -0700253 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = "bt-sco-mic",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530254 [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb",
Vicky Sehrawate240e5d2014-08-12 17:17:04 -0700255 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = "bt-sco-mic-wb",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530256 [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530257 [SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef",
258 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = "voice-speaker-dmic-ef",
259 [SND_DEVICE_IN_VOICE_SPEAKER_QMIC] = "voice-speaker-qmic",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530260 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
261 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
262 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
263 [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530264 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = "voice-rec-mic",
265 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = "voice-rec-dmic-ef",
266 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence",
267 [SND_DEVICE_IN_USB_HEADSET_MIC] = "usb-headset-mic",
268 [SND_DEVICE_IN_CAPTURE_FM] = "capture-fm",
269 [SND_DEVICE_IN_AANC_HANDSET_MIC] = "aanc-handset-mic",
270 [SND_DEVICE_IN_QUAD_MIC] = "quad-mic",
271 [SND_DEVICE_IN_HANDSET_STEREO_DMIC] = "handset-stereo-dmic-ef",
272 [SND_DEVICE_IN_SPEAKER_STEREO_DMIC] = "speaker-stereo-dmic-ef",
273 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = "vi-feedback",
Karthik Reddy Kattad9fff862014-07-21 21:07:21 +0530274 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BROADSIDE] = "voice-speaker-dmic-broadside",
275 [SND_DEVICE_IN_SPEAKER_DMIC_BROADSIDE] = "speaker-dmic-broadside",
276 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_BROADSIDE] = "speaker-dmic-broadside",
277 [SND_DEVICE_IN_SPEAKER_DMIC_NS_BROADSIDE] = "speaker-dmic-broadside",
278 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_BROADSIDE] = "speaker-dmic-broadside",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530279};
280
281/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530282static int acdb_device_table[SND_DEVICE_MAX] = {
Naresh Tannirue3b18452014-03-04 14:44:27 +0530283 [SND_DEVICE_NONE] = -1,
284 [SND_DEVICE_OUT_HANDSET] = 7,
Srikanth Uyyalaa675cd12014-10-15 14:48:11 +0530285 [SND_DEVICE_OUT_SPEAKER] = 14,
286 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 14,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530287 [SND_DEVICE_OUT_HEADPHONES] = 10,
288 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
289 [SND_DEVICE_OUT_VOICE_HANDSET] = 7,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530290 [SND_DEVICE_OUT_VOICE_SPEAKER] = 14,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530291 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
292 [SND_DEVICE_OUT_HDMI] = 18,
Srikanth Uyyalaa675cd12014-10-15 14:48:11 +0530293 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 14,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530294 [SND_DEVICE_OUT_BT_SCO] = 22,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530295 [SND_DEVICE_OUT_BT_SCO_WB] = 39,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530296 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
297 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
298 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530299 [SND_DEVICE_OUT_AFE_PROXY] = 0,
300 [SND_DEVICE_OUT_USB_HEADSET] = 45,
Srikanth Uyyalaa675cd12014-10-15 14:48:11 +0530301 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = 14,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530302 [SND_DEVICE_OUT_TRANSMISSION_FM] = 0,
303 [SND_DEVICE_OUT_ANC_HEADSET] = 26,
304 [SND_DEVICE_OUT_ANC_FB_HEADSET] = 27,
305 [SND_DEVICE_OUT_VOICE_ANC_HEADSET] = 26,
306 [SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET] = 27,
307 [SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET] = 26,
308 [SND_DEVICE_OUT_ANC_HANDSET] = 103,
309 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = 101,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530310
311 [SND_DEVICE_IN_HANDSET_MIC] = 4,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530312 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 106,
313 [SND_DEVICE_IN_HANDSET_MIC_NS] = 107,
314 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = 108,
315 [SND_DEVICE_IN_HANDSET_DMIC] = 41,
316 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = 109,
317 [SND_DEVICE_IN_HANDSET_DMIC_NS] = 110,
318 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = 111,
319 [SND_DEVICE_IN_SPEAKER_MIC] = 11,
320 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 112,
321 [SND_DEVICE_IN_SPEAKER_MIC_NS] = 113,
322 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = 114,
323 [SND_DEVICE_IN_SPEAKER_DMIC] = 43,
324 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = 115,
325 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = 116,
326 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = 117,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530327 [SND_DEVICE_IN_HEADSET_MIC] = 8,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530328 [SND_DEVICE_IN_HEADSET_MIC_FLUENCE] = 47,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530329 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
330 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = 8,
331 [SND_DEVICE_IN_HDMI_MIC] = 4,
332 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
Vicky Sehrawate240e5d2014-08-12 17:17:04 -0700333 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = 122,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530334 [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38,
Vicky Sehrawate240e5d2014-08-12 17:17:04 -0700335 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = 123,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530336 [SND_DEVICE_IN_CAMCORDER_MIC] = 4,
337 [SND_DEVICE_IN_VOICE_DMIC] = 41,
338 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 43,
339 [SND_DEVICE_IN_VOICE_SPEAKER_QMIC] = 19,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530340 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
341 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
342 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530343 [SND_DEVICE_IN_VOICE_REC_MIC] = 4,
344 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = 107,
345 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = 34,
346 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 41,
347 [SND_DEVICE_IN_USB_HEADSET_MIC] = 44,
348 [SND_DEVICE_IN_CAPTURE_FM] = 0,
349 [SND_DEVICE_IN_AANC_HANDSET_MIC] = 104,
350 [SND_DEVICE_IN_QUAD_MIC] = 46,
351 [SND_DEVICE_IN_HANDSET_STEREO_DMIC] = 34,
352 [SND_DEVICE_IN_SPEAKER_STEREO_DMIC] = 35,
353 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = 102,
Karthik Reddy Kattad9fff862014-07-21 21:07:21 +0530354 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BROADSIDE] = 12,
355 [SND_DEVICE_IN_SPEAKER_DMIC_BROADSIDE] = 12,
356 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_BROADSIDE] = 119,
357 [SND_DEVICE_IN_SPEAKER_DMIC_NS_BROADSIDE] = 121,
358 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_BROADSIDE] = 120,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530359};
360
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530361struct snd_device_index {
362 char name[100];
363 unsigned int index;
364};
Naresh Tannirue3b18452014-03-04 14:44:27 +0530365
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530366#define TO_NAME_INDEX(X) #X, X
Naresh Tannirue3b18452014-03-04 14:44:27 +0530367
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530368/* Used to get index from parsed sting */
369struct snd_device_index snd_device_name_index[SND_DEVICE_MAX] = {
370 {TO_NAME_INDEX(SND_DEVICE_OUT_HANDSET)},
371 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER)},
372 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_REVERSE)},
373 {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES)},
374 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES)},
375 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET)},
376 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER)},
377 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADPHONES)},
378 {TO_NAME_INDEX(SND_DEVICE_OUT_HDMI)},
379 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HDMI)},
380 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO)},
381 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO_WB)},
382 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES)},
383 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES)},
384 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET)},
385 {TO_NAME_INDEX(SND_DEVICE_OUT_AFE_PROXY)},
386 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADSET)},
387 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET)},
388 {TO_NAME_INDEX(SND_DEVICE_OUT_TRANSMISSION_FM)},
389 {TO_NAME_INDEX(SND_DEVICE_OUT_ANC_HEADSET)},
390 {TO_NAME_INDEX(SND_DEVICE_OUT_ANC_FB_HEADSET)},
391 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_ANC_HEADSET)},
392 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET)},
393 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET)},
394 {TO_NAME_INDEX(SND_DEVICE_OUT_ANC_HANDSET)},
395 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED)},
396 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC)},
397 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC)},
398 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_NS)},
399 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)},
400 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC)},
401 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC)},
402 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_NS)},
403 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)},
404 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC)},
405 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC)},
406 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_NS)},
407 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)},
408 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC)},
409 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC)},
410 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS)},
411 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)},
412 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC)},
413 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC_FLUENCE)},
414 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC)},
415 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEADSET_MIC)},
416 {TO_NAME_INDEX(SND_DEVICE_IN_HDMI_MIC)},
417 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC)},
Vicky Sehrawate240e5d2014-08-12 17:17:04 -0700418 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_NREC)},
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530419 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB)},
Vicky Sehrawate240e5d2014-08-12 17:17:04 -0700420 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB_NREC)},
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530421 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_MIC)},
422 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC)},
423 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC)},
424 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_QMIC)},
425 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC)},
426 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC)},
427 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC)},
428 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC)},
429 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_NS)},
430 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_STEREO)},
431 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE)},
432 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC)},
433 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_FM)},
434 {TO_NAME_INDEX(SND_DEVICE_IN_AANC_HANDSET_MIC)},
435 {TO_NAME_INDEX(SND_DEVICE_IN_QUAD_MIC)},
436 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_STEREO_DMIC)},
437 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_STEREO_DMIC)},
438 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_VI_FEEDBACK)},
439};
440
441#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
442#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
Naresh Tannirue3b18452014-03-04 14:44:27 +0530443
Asish Bhattacharya4ff24802014-04-24 17:46:54 +0530444static void query_platform(const char *snd_card_name,
445 char *mixer_xml_path)
446{
447 if (!strncmp(snd_card_name, "msm8x16-snd-card-mtp",
448 sizeof("msm8x16-snd-card-mtp"))) {
449 strlcpy(mixer_xml_path, MIXER_XML_PATH_MTP,
450 sizeof(MIXER_XML_PATH_MTP));
Walter Yang7ca90d92014-05-06 17:48:02 +0800451 } else if (!strncmp(snd_card_name, "msm8x16-skuh-snd-card",
452 sizeof("msm8x16-skuh-snd-card"))) {
453 strlcpy(mixer_xml_path, MIXER_XML_PATH_QRD_SKUH,
454 sizeof(MIXER_XML_PATH_QRD_SKUH));
455 } else if (!strncmp(snd_card_name, "msm8x16-skui-snd-card",
456 sizeof("msm8x16-skui-snd-card"))) {
457 strlcpy(mixer_xml_path, MIXER_XML_PATH_QRD_SKUI,
458 sizeof(MIXER_XML_PATH_QRD_SKUI));
Walter Yang19f244a2014-06-17 13:30:08 +0800459 } else if (!strncmp(snd_card_name, "msm8x16-skuhf-snd-card",
460 sizeof("msm8x16-skuhf-snd-card"))) {
461 strlcpy(mixer_xml_path, MIXER_XML_PATH_QRD_SKUHF,
462 sizeof(MIXER_XML_PATH_QRD_SKUHF));
Walter Yangc899d572014-05-27 21:52:17 +0800463 } else if (!strncmp(snd_card_name, "msm8939-snd-card-mtp",
Yamit Mehtac6003e22014-05-19 10:26:02 +0530464 sizeof("msm8939-snd-card-mtp"))) {
Aravind Kumar71ba22b2014-06-23 15:18:50 +0530465 strlcpy(mixer_xml_path, MIXER_XML_PATH_MTP,
466 sizeof(MIXER_XML_PATH_MTP));
Meng Wangf00485b2014-06-03 19:44:38 +0800467 } else if (!strncmp(snd_card_name, "msm8939-snd-card-skuk",
468 sizeof("msm8939-snd-card-skuk"))) {
469 strlcpy(mixer_xml_path, MIXER_XML_PATH_SKUK,
470 sizeof(MIXER_XML_PATH_SKUK));
Asish Bhattacharyacb8e6d02014-06-19 12:32:25 +0530471 } else if (!strncmp(snd_card_name, "msm8939-tapan-snd-card",
472 sizeof("msm8939-tapan-snd-card"))) {
473 strlcpy(mixer_xml_path, MIXER_XML_PATH_WCD9306,
474 sizeof(MIXER_XML_PATH_WCD9306));
475 } else if (!strncmp(snd_card_name, "msm8939-tapan9302-snd-card",
476 sizeof("msm8939-tapan9302-snd-card"))) {
477 strlcpy(mixer_xml_path, MIXER_XML_PATH_WCD9306,
478 sizeof(MIXER_XML_PATH_WCD9306));
Aviral Gupta8ed0eec2014-08-25 10:22:11 +0530479 } else if (!strncmp(snd_card_name, "msm8939-tomtom9330-snd-card",
480 sizeof("msm8939-tomtom9330-snd-card"))) {
481 strlcpy(mixer_xml_path, MIXER_XML_PATH_WCD9330,
482 sizeof(MIXER_XML_PATH_WCD9330));
Asish Bhattacharya4ff24802014-04-24 17:46:54 +0530483 } else {
484 strlcpy(mixer_xml_path, MIXER_XML_PATH,
485 sizeof(MIXER_XML_PATH));
486 }
487}
488
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +0530489void platform_set_echo_reference(void *platform, bool enable)
Naresh Tannirue3b18452014-03-04 14:44:27 +0530490{
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +0530491 struct platform_data *my_data = (struct platform_data *)platform;
492 struct audio_device *adev = my_data->adev;
Naresh Tannirue3b18452014-03-04 14:44:27 +0530493
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +0530494 if (enable) {
495 my_data->ec_ref_enabled = enable;
496 audio_route_apply_and_update_path(adev->audio_route, "echo-reference");
497 } else {
498 if (my_data->ec_ref_enabled) {
499 audio_route_reset_and_update_path(adev->audio_route, "echo-reference");
500 my_data->ec_ref_enabled = enable;
501 } else {
502 ALOGV("EC reference is already disabled : %d", my_data->ec_ref_enabled);
503 }
504 }
Venkata Narendra Kumar Gutta3fa54c72014-08-18 18:02:21 +0530505
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +0530506 ALOGV("Setting EC Reference: %d", enable);
Naresh Tannirue3b18452014-03-04 14:44:27 +0530507}
508
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530509static struct csd_data *open_csd_client()
510{
511 struct csd_data *csd = calloc(1, sizeof(struct csd_data));
512
513 csd->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
514 if (csd->csd_client == NULL) {
515 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
516 goto error;
517 } else {
518 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
519
520 csd->deinit = (deinit_t)dlsym(csd->csd_client,
521 "csd_client_deinit");
522 if (csd->deinit == NULL) {
523 ALOGE("%s: dlsym error %s for csd_client_deinit", __func__,
524 dlerror());
525 goto error;
526 }
527 csd->disable_device = (disable_device_t)dlsym(csd->csd_client,
528 "csd_client_disable_device");
529 if (csd->disable_device == NULL) {
530 ALOGE("%s: dlsym error %s for csd_client_disable_device",
531 __func__, dlerror());
532 goto error;
533 }
534 csd->enable_device_config = (enable_device_config_t)dlsym(csd->csd_client,
535 "csd_client_enable_device_config");
536 if (csd->enable_device_config == NULL) {
537 ALOGE("%s: dlsym error %s for csd_client_enable_device_config",
538 __func__, dlerror());
539 goto error;
540 }
541 csd->enable_device = (enable_device_t)dlsym(csd->csd_client,
542 "csd_client_enable_device");
543 if (csd->enable_device == NULL) {
544 ALOGE("%s: dlsym error %s for csd_client_enable_device",
545 __func__, dlerror());
546 goto error;
547 }
548 csd->start_voice = (start_voice_t)dlsym(csd->csd_client,
549 "csd_client_start_voice");
550 if (csd->start_voice == NULL) {
551 ALOGE("%s: dlsym error %s for csd_client_start_voice",
552 __func__, dlerror());
553 goto error;
554 }
555 csd->stop_voice = (stop_voice_t)dlsym(csd->csd_client,
556 "csd_client_stop_voice");
557 if (csd->stop_voice == NULL) {
558 ALOGE("%s: dlsym error %s for csd_client_stop_voice",
559 __func__, dlerror());
560 goto error;
561 }
562 csd->volume = (volume_t)dlsym(csd->csd_client,
563 "csd_client_volume");
564 if (csd->volume == NULL) {
565 ALOGE("%s: dlsym error %s for csd_client_volume",
566 __func__, dlerror());
567 goto error;
568 }
569 csd->mic_mute = (mic_mute_t)dlsym(csd->csd_client,
570 "csd_client_mic_mute");
571 if (csd->mic_mute == NULL) {
572 ALOGE("%s: dlsym error %s for csd_client_mic_mute",
573 __func__, dlerror());
574 goto error;
575 }
576 csd->slow_talk = (slow_talk_t)dlsym(csd->csd_client,
577 "csd_client_slow_talk");
578 if (csd->slow_talk == NULL) {
579 ALOGE("%s: dlsym error %s for csd_client_slow_talk",
580 __func__, dlerror());
581 goto error;
582 }
583 csd->start_playback = (start_playback_t)dlsym(csd->csd_client,
584 "csd_client_start_playback");
585 if (csd->start_playback == NULL) {
586 ALOGE("%s: dlsym error %s for csd_client_start_playback",
587 __func__, dlerror());
588 goto error;
589 }
590 csd->stop_playback = (stop_playback_t)dlsym(csd->csd_client,
591 "csd_client_stop_playback");
592 if (csd->stop_playback == NULL) {
593 ALOGE("%s: dlsym error %s for csd_client_stop_playback",
594 __func__, dlerror());
595 goto error;
596 }
Vidyakumar Athota21b3bb92014-04-25 11:08:08 -0700597 csd->set_lch = (set_lch_t)dlsym(csd->csd_client, "csd_client_set_lch");
598 if (csd->set_lch == NULL) {
599 ALOGE("%s: dlsym error %s for csd_client_set_lch",
600 __func__, dlerror());
601 /* Ignore the error as this is not mandatory function for
602 * basic voice call to work.
603 */
604 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530605 csd->start_record = (start_record_t)dlsym(csd->csd_client,
606 "csd_client_start_record");
607 if (csd->start_record == NULL) {
608 ALOGE("%s: dlsym error %s for csd_client_start_record",
609 __func__, dlerror());
610 goto error;
611 }
612 csd->stop_record = (stop_record_t)dlsym(csd->csd_client,
613 "csd_client_stop_record");
614 if (csd->stop_record == NULL) {
615 ALOGE("%s: dlsym error %s for csd_client_stop_record",
616 __func__, dlerror());
617 goto error;
618 }
619 csd->init = (init_t)dlsym(csd->csd_client, "csd_client_init");
620
621 if (csd->init == NULL) {
622 ALOGE("%s: dlsym error %s for csd_client_init",
623 __func__, dlerror());
624 goto error;
625 } else {
626 csd->init();
627 }
628 }
629 return csd;
630
631error:
632 free(csd);
633 csd = NULL;
634 return csd;
635}
636
637void close_csd_client(struct csd_data *csd)
638{
639 if (csd != NULL) {
640 csd->deinit();
641 dlclose(csd->csd_client);
642 free(csd);
643 csd = NULL;
644 }
645}
646
Avinash Vaish71c066d2014-08-27 12:32:35 +0530647void get_cvd_version(char *cvd_version, struct audio_device *adev)
648{
649 struct mixer_ctl *ctl;
650 int count;
651 int ret = 0;
652
653 ctl = mixer_get_ctl_by_name(adev->mixer, CVD_VERSION_MIXER_CTL);
654 if (!ctl) {
655 ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__, CVD_VERSION_MIXER_CTL);
656 goto done;
657 }
658 mixer_ctl_update(ctl);
659
660 count = mixer_ctl_get_num_values(ctl);
661 if (count > MAX_CVD_VERSION_STRING_SIZE)
662 count = MAX_CVD_VERSION_STRING_SIZE;
663
664 ret = mixer_ctl_get_array(ctl, cvd_version, count);
665 if (ret != 0) {
666 ALOGE("%s: ERROR! mixer_ctl_get_array() failed to get CVD Version", __func__);
667 goto done;
668 }
669
670done:
671 return;
672}
673
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +0530674static int hw_util_open(int card_no)
675{
676 int fd = -1;
677 char dev_name[256];
678
679 snprintf(dev_name, sizeof(dev_name), "/dev/snd/hwC%uD%u",
680 card_no, WCD9XXX_CODEC_HWDEP_NODE);
681 ALOGD("%s Opening device %s\n", __func__, dev_name);
682 fd = open(dev_name, O_WRONLY);
683 if (fd < 0) {
684 ALOGE("%s: cannot open device '%s'\n", __func__, dev_name);
685 return fd;
686 }
687 ALOGD("%s success", __func__);
688 return fd;
689}
690
691struct param_data {
692 int use_case;
693 int acdb_id;
694 int get_size;
695 int buff_size;
696 int data_size;
697 void *buff;
698};
699
700static int send_codec_cal(acdb_loader_get_calibration_t acdb_loader_get_calibration, int fd)
701{
702 int ret = 0, type;
703
704 for (type = WCD9XXX_ANC_CAL; type < WCD9XXX_MAX_CAL; type++) {
705 struct wcdcal_ioctl_buffer codec_buffer;
706 struct param_data calib;
707
708 if (!strcmp(cal_name_info[type], "mad_cal"))
709 calib.acdb_id = SOUND_TRIGGER_DEVICE_HANDSET_MONO_LOW_POWER_ACDB_ID;
710 calib.get_size = 1;
711 ret = acdb_loader_get_calibration(cal_name_info[type], sizeof(struct param_data),
712 &calib);
713 if (ret < 0) {
714 ALOGE("%s get_calibration failed\n", __func__);
715 return ret;
716 }
717 calib.get_size = 0;
718 calib.buff = malloc(calib.buff_size);
719 ret = acdb_loader_get_calibration(cal_name_info[type],
720 sizeof(struct param_data), &calib);
721 if (ret < 0) {
722 ALOGE("%s get_calibration failed\n", __func__);
723 free(calib.buff);
724 return ret;
725 }
726 codec_buffer.buffer = calib.buff;
727 codec_buffer.size = calib.data_size;
728 codec_buffer.cal_type = type;
729 if (ioctl(fd, SNDRV_CTL_IOCTL_HWDEP_CAL_TYPE, &codec_buffer) < 0)
730 ALOGE("Failed to call ioctl for %s err=%d",
731 cal_name_info[type], errno);
732 ALOGD("%s cal sent for %s", __func__, cal_name_info[type]);
733 free(calib.buff);
734 }
735 return ret;
736}
737
738static void audio_hwdep_send_cal(struct platform_data *plat_data)
739{
740 int fd;
741
742 fd = hw_util_open(plat_data->adev->snd_card);
743 if (fd == -1) {
744 ALOGE("%s error open\n", __func__);
745 return;
746 }
747
748 acdb_loader_get_calibration = (acdb_loader_get_calibration_t)
749 dlsym(plat_data->acdb_handle, "acdb_loader_get_calibration");
750
751 if (acdb_loader_get_calibration == NULL) {
752 ALOGE("%s: ERROR. dlsym Error:%s acdb_loader_get_calibration", __func__,
753 dlerror());
754 return;
755 }
756 if (send_codec_cal(acdb_loader_get_calibration, fd) < 0)
757 ALOGE("%s: Could not send anc cal", __FUNCTION__);
758}
759
Naresh Tannirue3b18452014-03-04 14:44:27 +0530760void *platform_init(struct audio_device *adev)
761{
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530762 char platform[PROPERTY_VALUE_MAX];
763 char baseband[PROPERTY_VALUE_MAX];
Naresh Tannirue3b18452014-03-04 14:44:27 +0530764 char value[PROPERTY_VALUE_MAX];
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530765 struct platform_data *my_data = NULL;
766 int retry_num = 0, snd_card_num = 0;
767 const char *snd_card_name;
Srikanth Uyyalaa675cd12014-10-15 14:48:11 +0530768 char mixer_xml_path[100],ffspEnable[PROPERTY_VALUE_MAX];
Avinash Vaish71c066d2014-08-27 12:32:35 +0530769 char *cvd_version = NULL;
Naresh Tannirue3b18452014-03-04 14:44:27 +0530770
771 my_data = calloc(1, sizeof(struct platform_data));
772
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530773 while (snd_card_num < MAX_SND_CARD) {
774 adev->mixer = mixer_open(snd_card_num);
775
776 while (!adev->mixer && retry_num < RETRY_NUMBER) {
777 usleep(RETRY_US);
778 adev->mixer = mixer_open(snd_card_num);
779 retry_num++;
780 }
781
782 if (!adev->mixer) {
783 ALOGE("%s: Unable to open the mixer card: %d", __func__,
784 snd_card_num);
785 retry_num = 0;
786 snd_card_num++;
787 continue;
788 }
789
790 snd_card_name = mixer_get_name(adev->mixer);
791 ALOGV("%s: snd_card_name: %s", __func__, snd_card_name);
792
793 my_data->hw_info = hw_info_init(snd_card_name);
794 if (!my_data->hw_info) {
795 ALOGE("%s: Failed to init hardware info", __func__);
796 } else {
Asish Bhattacharya4ff24802014-04-24 17:46:54 +0530797 query_platform(snd_card_name, mixer_xml_path);
798 ALOGD("%s: mixer path file is %s", __func__,
799 mixer_xml_path);
800 if (audio_extn_read_xml(adev, snd_card_num, mixer_xml_path,
801 MIXER_XML_PATH_AUXPCM) == -ENOSYS) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530802 adev->audio_route = audio_route_init(snd_card_num,
Asish Bhattacharya4ff24802014-04-24 17:46:54 +0530803 mixer_xml_path);
804 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530805 if (!adev->audio_route) {
806 ALOGE("%s: Failed to init audio route controls, aborting.",
807 __func__);
808 free(my_data);
809 return NULL;
810 }
811 adev->snd_card = snd_card_num;
812 ALOGD("%s: Opened sound card:%d", __func__, snd_card_num);
813 break;
814 }
815 retry_num = 0;
816 snd_card_num++;
817 }
818
819 if (snd_card_num >= MAX_SND_CARD) {
820 ALOGE("%s: Unable to find correct sound card, aborting.", __func__);
821 free(my_data);
822 return NULL;
823 }
824
Naresh Tannirue3b18452014-03-04 14:44:27 +0530825 my_data->adev = adev;
Naresh Tannirue3b18452014-03-04 14:44:27 +0530826 my_data->fluence_in_spkr_mode = false;
827 my_data->fluence_in_voice_call = false;
828 my_data->fluence_in_voice_rec = false;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530829 my_data->fluence_in_audio_rec = false;
830 my_data->fluence_type = FLUENCE_NONE;
Karthik Reddy Kattad9fff862014-07-21 21:07:21 +0530831 my_data->fluence_mode = FLUENCE_ENDFIRE;
Avinash Vaishd5fa4572014-09-15 14:41:14 +0530832 my_data->slowtalk = false;
833 my_data->hd_voice = false;
Naresh Tannirue3b18452014-03-04 14:44:27 +0530834
Venkata Narendra Kumar Gutta88fd0bc2014-03-27 19:47:56 +0530835 property_get("ro.qc.sdk.audio.fluencetype", my_data->fluence_cap, "");
836 if (!strncmp("fluencepro", my_data->fluence_cap, sizeof("fluencepro"))) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530837 my_data->fluence_type = FLUENCE_QUAD_MIC | FLUENCE_DUAL_MIC;
Venkata Narendra Kumar Gutta88fd0bc2014-03-27 19:47:56 +0530838 } else if (!strncmp("fluence", my_data->fluence_cap, sizeof("fluence"))) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530839 my_data->fluence_type = FLUENCE_DUAL_MIC;
840 } else {
841 my_data->fluence_type = FLUENCE_NONE;
Naresh Tannirue3b18452014-03-04 14:44:27 +0530842 }
843
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530844 if (my_data->fluence_type != FLUENCE_NONE) {
Naresh Tannirue3b18452014-03-04 14:44:27 +0530845 property_get("persist.audio.fluence.voicecall",value,"");
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530846 if (!strncmp("true", value, sizeof("true"))) {
Naresh Tannirue3b18452014-03-04 14:44:27 +0530847 my_data->fluence_in_voice_call = true;
848 }
849
850 property_get("persist.audio.fluence.voicerec",value,"");
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530851 if (!strncmp("true", value, sizeof("true"))) {
Naresh Tannirue3b18452014-03-04 14:44:27 +0530852 my_data->fluence_in_voice_rec = true;
853 }
854
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530855 property_get("persist.audio.fluence.audiorec",value,"");
856 if (!strncmp("true", value, sizeof("true"))) {
857 my_data->fluence_in_audio_rec = true;
858 }
859
Naresh Tannirue3b18452014-03-04 14:44:27 +0530860 property_get("persist.audio.fluence.speaker",value,"");
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530861 if (!strncmp("true", value, sizeof("true"))) {
Naresh Tannirue3b18452014-03-04 14:44:27 +0530862 my_data->fluence_in_spkr_mode = true;
863 }
Karthik Reddy Kattad9fff862014-07-21 21:07:21 +0530864
865 property_get("persist.audio.fluence.mode",value,"");
866 if (!strncmp("broadside", value, sizeof("broadside"))) {
867 my_data->fluence_mode = FLUENCE_BROADSIDE;
868 }
Naresh Tannirue3b18452014-03-04 14:44:27 +0530869 }
Srikanth Uyyalaa675cd12014-10-15 14:48:11 +0530870 property_get("persist.audio.FFSP.enable", ffspEnable, "");
871 if (!strncmp("true", ffspEnable, sizeof("true"))) {
872 acdb_device_table[SND_DEVICE_OUT_SPEAKER] = 131;
873 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE] = 131;
874 acdb_device_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 131;
875 acdb_device_table[SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = 131;
876 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530877 my_data->voice_feature_set = VOICE_FEATURE_SET_DEFAULT;
Naresh Tannirue3b18452014-03-04 14:44:27 +0530878 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
879 if (my_data->acdb_handle == NULL) {
880 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
881 } else {
882 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
883 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
884 "acdb_loader_deallocate_ACDB");
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530885 if (!my_data->acdb_deallocate)
886 ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s",
887 __func__, LIB_ACDB_LOADER);
888
Naresh Tannirue3b18452014-03-04 14:44:27 +0530889 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 -0700890 "acdb_loader_send_audio_cal_v2");
Naresh Tannirue3b18452014-03-04 14:44:27 +0530891 if (!my_data->acdb_send_audio_cal)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530892 ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530893 __func__, LIB_ACDB_LOADER);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530894
Naresh Tannirue3b18452014-03-04 14:44:27 +0530895 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
896 "acdb_loader_send_voice_cal");
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530897 if (!my_data->acdb_send_voice_cal)
898 ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s",
899 __func__, LIB_ACDB_LOADER);
900
901 my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle,
902 "acdb_loader_reload_vocvoltable");
903 if (!my_data->acdb_reload_vocvoltable)
904 ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s",
905 __func__, LIB_ACDB_LOADER);
906
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -0700907 my_data->acdb_get_default_app_type = (acdb_get_default_app_type_t)dlsym(
908 my_data->acdb_handle,
909 "acdb_loader_get_default_app_type");
910 if (!my_data->acdb_get_default_app_type)
911 ALOGE("%s: Could not find the symbol acdb_get_default_app_type from %s",
912 __func__, LIB_ACDB_LOADER);
913
Naresh Tannirue3b18452014-03-04 14:44:27 +0530914 my_data->acdb_init = (acdb_init_t)dlsym(my_data->acdb_handle,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530915 "acdb_loader_init_v2");
Avinash Vaish71c066d2014-08-27 12:32:35 +0530916 if (my_data->acdb_init == NULL) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530917 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__, dlerror());
Avinash Vaish71c066d2014-08-27 12:32:35 +0530918 goto acdb_init_fail;
919 }
920
921 cvd_version = calloc(1, MAX_CVD_VERSION_STRING_SIZE);
922 if (!cvd_version)
923 ALOGE("Failed to allocate cvd version");
Naresh Tannirue3b18452014-03-04 14:44:27 +0530924 else
Avinash Vaish71c066d2014-08-27 12:32:35 +0530925 get_cvd_version(cvd_version, adev);
926
927 my_data->acdb_init(snd_card_name, cvd_version);
928 if (cvd_version)
929 free(cvd_version);
Naresh Tannirue3b18452014-03-04 14:44:27 +0530930 }
931
Avinash Vaish71c066d2014-08-27 12:32:35 +0530932acdb_init_fail:
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530933 /* Initialize ACDB ID's */
934 platform_info_init(PLATFORM_INFO_XML_PATH);
935
936 /* init usb */
937 audio_extn_usb_init(adev);
938 /* update sound cards appropriately */
939 audio_extn_usb_set_proxy_sound_card(adev->snd_card);
940
941 /* Read one time ssr property */
942 audio_extn_ssr_update_enabled();
943 audio_extn_spkr_prot_init(adev);
Dhananjay Kumar89ea3bd2014-04-29 15:45:57 +0530944
945 audio_extn_dolby_set_license(adev);
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +0530946 audio_hwdep_send_cal(my_data);
Dhananjay Kumar89ea3bd2014-04-29 15:45:57 +0530947
Naresh Tannirue3b18452014-03-04 14:44:27 +0530948 return my_data;
949}
950
951void platform_deinit(void *platform)
952{
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530953 struct platform_data *my_data = (struct platform_data *)platform;
954
955 hw_info_deinit(my_data->hw_info);
956 close_csd_client(my_data->csd);
957
Naresh Tannirue3b18452014-03-04 14:44:27 +0530958 free(platform);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530959 /* deinit usb */
960 audio_extn_usb_deinit();
Naresh Tannirue3b18452014-03-04 14:44:27 +0530961}
962
963const char *platform_get_snd_device_name(snd_device_t snd_device)
964{
965 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX)
966 return device_table[snd_device];
967 else
968 return "";
969}
970
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530971int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
972 char *device_name)
973{
974 struct platform_data *my_data = (struct platform_data *)platform;
975
976 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
977 strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE);
978 hw_info_append_hw_type(my_data->hw_info, snd_device, device_name);
979 } else {
980 strlcpy(device_name, "", DEVICE_NAME_MAX_SIZE);
981 return -EINVAL;
982 }
983
984 return 0;
985}
986
Naresh Tannirue3b18452014-03-04 14:44:27 +0530987void platform_add_backend_name(char *mixer_path, snd_device_t snd_device)
988{
Vicky Sehrawate240e5d2014-08-12 17:17:04 -0700989 if ((snd_device == SND_DEVICE_IN_BT_SCO_MIC) ||
990 (snd_device == SND_DEVICE_IN_BT_SCO_MIC_NREC))
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530991 strlcat(mixer_path, " bt-sco", MIXER_PATH_MAX_LENGTH);
Vicky Sehrawate240e5d2014-08-12 17:17:04 -0700992 else if ((snd_device == SND_DEVICE_IN_BT_SCO_MIC_WB) ||
993 (snd_device == SND_DEVICE_IN_BT_SCO_MIC_WB_NREC))
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530994 strlcat(mixer_path, " bt-sco-wb", MIXER_PATH_MAX_LENGTH);
Naresh Tannirue3b18452014-03-04 14:44:27 +0530995 else if(snd_device == SND_DEVICE_OUT_BT_SCO)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530996 strlcat(mixer_path, " bt-sco", MIXER_PATH_MAX_LENGTH);
997 else if(snd_device == SND_DEVICE_OUT_BT_SCO_WB)
998 strlcat(mixer_path, " bt-sco-wb", MIXER_PATH_MAX_LENGTH);
Naresh Tannirue3b18452014-03-04 14:44:27 +0530999 else if (snd_device == SND_DEVICE_OUT_HDMI)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301000 strlcat(mixer_path, " hdmi", MIXER_PATH_MAX_LENGTH);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301001 else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HDMI)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301002 strlcat(mixer_path, " speaker-and-hdmi", MIXER_PATH_MAX_LENGTH);
1003 else if (snd_device == SND_DEVICE_OUT_AFE_PROXY)
1004 strlcat(mixer_path, " afe-proxy", MIXER_PATH_MAX_LENGTH);
1005 else if (snd_device == SND_DEVICE_OUT_USB_HEADSET)
1006 strlcat(mixer_path, " usb-headphones", MIXER_PATH_MAX_LENGTH);
1007 else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET)
1008 strlcat(mixer_path, " speaker-and-usb-headphones",
1009 MIXER_PATH_MAX_LENGTH);
1010 else if (snd_device == SND_DEVICE_IN_USB_HEADSET_MIC)
1011 strlcat(mixer_path, " usb-headset-mic", MIXER_PATH_MAX_LENGTH);
1012 else if (snd_device == SND_DEVICE_IN_CAPTURE_FM)
1013 strlcat(mixer_path, " capture-fm", MIXER_PATH_MAX_LENGTH);
1014 else if (snd_device == SND_DEVICE_OUT_TRANSMISSION_FM)
1015 strlcat(mixer_path, " transmission-fm", MIXER_PATH_MAX_LENGTH);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301016}
1017
1018int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
1019{
1020 int device_id;
1021 if (device_type == PCM_PLAYBACK)
1022 device_id = pcm_device_table[usecase][0];
1023 else
1024 device_id = pcm_device_table[usecase][1];
1025 return device_id;
1026}
1027
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301028int platform_get_snd_device_index(char *snd_device_index_name)
1029{
1030 int ret = 0;
1031 int i;
1032
1033 if (snd_device_index_name == NULL) {
1034 ALOGE("%s: snd_device_index_name is NULL", __func__);
1035 ret = -ENODEV;
1036 goto done;
1037 }
1038
1039 for (i=0; i < SND_DEVICE_MAX; i++) {
1040 if(strcmp(snd_device_name_index[i].name, snd_device_index_name) == 0) {
1041 ret = snd_device_name_index[i].index;
1042 goto done;
1043 }
1044 }
1045 ALOGE("%s: Could not find index for snd_device_index_name = %s",
1046 __func__, snd_device_index_name);
1047 ret = -ENODEV;
1048done:
1049 return ret;
1050}
1051
Venkata Narendra Kumar Gutta88fd0bc2014-03-27 19:47:56 +05301052int platform_set_fluence_type(void *platform, char *value)
1053{
1054 int ret = 0;
1055 int fluence_type = FLUENCE_NONE;
1056 int fluence_flag = NONE_FLAG;
1057 struct platform_data *my_data = (struct platform_data *)platform;
1058 struct audio_device *adev = my_data->adev;
1059
1060 ALOGV("%s: fluence type:%d", __func__, my_data->fluence_type);
1061
1062 /* only dual mic turn on and off is supported as of now through setparameters */
1063 if (!strncmp(AUDIO_PARAMETER_VALUE_DUALMIC,value, sizeof(AUDIO_PARAMETER_VALUE_DUALMIC))) {
1064 if (!strncmp("fluencepro", my_data->fluence_cap, sizeof("fluencepro")) ||
1065 !strncmp("fluence", my_data->fluence_cap, sizeof("fluence"))) {
1066 ALOGV("fluence dualmic feature enabled \n");
1067 fluence_type = FLUENCE_DUAL_MIC;
1068 fluence_flag = DMIC_FLAG;
1069 } else {
1070 ALOGE("%s: Failed to set DUALMIC", __func__);
1071 ret = -1;
1072 goto done;
1073 }
1074 } else if (!strncmp(AUDIO_PARAMETER_KEY_NO_FLUENCE, value, sizeof(AUDIO_PARAMETER_KEY_NO_FLUENCE))) {
1075 ALOGV("fluence disabled");
1076 fluence_type = FLUENCE_NONE;
1077 } else {
1078 ALOGE("Invalid fluence value : %s",value);
1079 ret = -1;
1080 goto done;
1081 }
1082
1083 if (fluence_type != my_data->fluence_type) {
1084 ALOGV("%s: Updating fluence_type to :%d", __func__, fluence_type);
1085 my_data->fluence_type = fluence_type;
1086 adev->acdb_settings = (adev->acdb_settings & FLUENCE_MODE_CLEAR) | fluence_flag;
1087 }
1088done:
1089 return ret;
1090}
1091
1092int platform_get_fluence_type(void *platform, char *value, uint32_t len)
1093{
1094 int ret = 0;
1095 struct platform_data *my_data = (struct platform_data *)platform;
1096
1097 if (my_data->fluence_type == FLUENCE_QUAD_MIC) {
1098 strlcpy(value, "quadmic", len);
1099 } else if (my_data->fluence_type == FLUENCE_DUAL_MIC) {
1100 strlcpy(value, "dualmic", len);
1101 } else if (my_data->fluence_type == FLUENCE_NONE) {
1102 strlcpy(value, "none", len);
1103 } else
1104 ret = -1;
1105
1106 return ret;
1107}
1108
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301109int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
1110{
1111 int ret = 0;
1112
1113 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1114 ALOGE("%s: Invalid snd_device = %d",
1115 __func__, snd_device);
1116 ret = -EINVAL;
1117 goto done;
1118 }
1119
1120 acdb_device_table[snd_device] = acdb_id;
1121done:
1122 return ret;
1123}
1124
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -07001125int platform_get_default_app_type(void *platform)
1126{
1127 struct platform_data *my_data = (struct platform_data *)platform;
1128
1129 if (my_data->acdb_get_default_app_type)
1130 return my_data->acdb_get_default_app_type();
1131 else
1132 return DEFAULT_APP_TYPE;
1133}
1134
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -07001135int platform_get_snd_device_acdb_id(snd_device_t snd_device)
1136{
1137 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1138 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1139 return -EINVAL;
1140 }
1141 return acdb_device_table[snd_device];
1142}
1143
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -07001144int platform_send_audio_calibration(void *platform, snd_device_t snd_device,
1145 int app_type, int sample_rate)
Naresh Tannirue3b18452014-03-04 14:44:27 +05301146{
1147 struct platform_data *my_data = (struct platform_data *)platform;
1148 int acdb_dev_id, acdb_dev_type;
1149
1150 acdb_dev_id = acdb_device_table[snd_device];
1151 if (acdb_dev_id < 0) {
1152 ALOGE("%s: Could not find acdb id for device(%d)",
1153 __func__, snd_device);
1154 return -EINVAL;
1155 }
1156 if (my_data->acdb_send_audio_cal) {
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -07001157 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Naresh Tannirue3b18452014-03-04 14:44:27 +05301158 __func__, snd_device, acdb_dev_id);
1159 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
1160 snd_device < SND_DEVICE_OUT_END)
1161 acdb_dev_type = ACDB_DEV_TYPE_OUT;
1162 else
1163 acdb_dev_type = ACDB_DEV_TYPE_IN;
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -07001164 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type, app_type,
1165 sample_rate);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301166 }
1167 return 0;
1168}
1169
1170int platform_switch_voice_call_device_pre(void *platform)
1171{
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301172 struct platform_data *my_data = (struct platform_data *)platform;
1173 int ret = 0;
1174
1175 if (my_data->csd != NULL &&
1176 my_data->adev->mode == AUDIO_MODE_IN_CALL) {
1177 /* This must be called before disabling mixer controls on APQ side */
1178 ret = my_data->csd->disable_device();
1179 if (ret < 0) {
1180 ALOGE("%s: csd_client_disable_device, failed, error %d",
1181 __func__, ret);
1182 }
1183 }
1184 return ret;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301185}
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301186int platform_switch_voice_call_enable_device_config(void *platform,
1187 snd_device_t out_snd_device,
1188 snd_device_t in_snd_device)
1189{
1190 struct platform_data *my_data = (struct platform_data *)platform;
1191 int acdb_rx_id, acdb_tx_id;
1192 int ret = 0;
1193
1194 acdb_rx_id = acdb_device_table[out_snd_device];
1195 acdb_tx_id = acdb_device_table[in_snd_device];
1196
1197 if (my_data->csd != NULL) {
1198 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
1199 ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
1200 if (ret < 0) {
1201 ALOGE("%s: csd_enable_device_config, failed, error %d",
1202 __func__, ret);
1203 }
1204 } else {
1205 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1206 acdb_rx_id, acdb_tx_id);
1207 }
1208 }
1209 return ret;
1210}
1211
Naresh Tannirue3b18452014-03-04 14:44:27 +05301212
1213int platform_switch_voice_call_device_post(void *platform,
1214 snd_device_t out_snd_device,
1215 snd_device_t in_snd_device)
1216{
1217 struct platform_data *my_data = (struct platform_data *)platform;
1218 int acdb_rx_id, acdb_tx_id;
1219
1220 if (my_data->acdb_send_voice_cal == NULL) {
1221 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
1222 } else {
1223 acdb_rx_id = acdb_device_table[out_snd_device];
1224 acdb_tx_id = acdb_device_table[in_snd_device];
1225
1226 if (acdb_rx_id > 0 && acdb_tx_id > 0)
1227 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
1228 else
1229 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1230 acdb_rx_id, acdb_tx_id);
1231 }
1232
1233 return 0;
1234}
1235
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301236int platform_switch_voice_call_usecase_route_post(void *platform,
1237 snd_device_t out_snd_device,
1238 snd_device_t in_snd_device)
Naresh Tannirue3b18452014-03-04 14:44:27 +05301239{
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301240 struct platform_data *my_data = (struct platform_data *)platform;
1241 int acdb_rx_id, acdb_tx_id;
1242 int ret = 0;
1243
1244 acdb_rx_id = acdb_device_table[out_snd_device];
1245 acdb_tx_id = acdb_device_table[in_snd_device];
1246
1247 if (my_data->csd != NULL) {
1248 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
1249 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
1250 my_data->adev->acdb_settings);
1251 if (ret < 0) {
1252 ALOGE("%s: csd_enable_device, failed, error %d",
1253 __func__, ret);
1254 }
1255 } else {
1256 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1257 acdb_rx_id, acdb_tx_id);
1258 }
1259 }
1260 return ret;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301261}
1262
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301263int platform_start_voice_call(void *platform, uint32_t vsid)
1264{
1265 struct platform_data *my_data = (struct platform_data *)platform;
1266 int ret = 0;
1267
1268 if (my_data->csd != NULL) {
1269 ret = my_data->csd->start_voice(vsid);
1270 if (ret < 0) {
1271 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
1272 }
1273 }
1274 return ret;
1275}
1276
1277int platform_stop_voice_call(void *platform, uint32_t vsid)
1278{
1279 struct platform_data *my_data = (struct platform_data *)platform;
1280 int ret = 0;
1281
1282 if (my_data->csd != NULL) {
1283 ret = my_data->csd->stop_voice(vsid);
1284 if (ret < 0) {
1285 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
1286 }
1287 }
1288 return ret;
1289}
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07001290
1291int platform_get_sample_rate(void *platform __unused, uint32_t *rate __unused)
Naresh Tannirue3b18452014-03-04 14:44:27 +05301292{
1293 return 0;
1294}
1295
1296int platform_set_voice_volume(void *platform, int volume)
1297{
1298 struct platform_data *my_data = (struct platform_data *)platform;
1299 struct audio_device *adev = my_data->adev;
1300 struct mixer_ctl *ctl;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301301 const char *mixer_ctl_name = "Voice Rx Gain";
1302 int vol_index = 0, ret = 0;
1303 uint32_t set_values[ ] = {0,
1304 ALL_SESSION_VSID,
1305 DEFAULT_VOLUME_RAMP_DURATION_MS};
Naresh Tannirue3b18452014-03-04 14:44:27 +05301306
1307 // Voice volume levels are mapped to adsp volume levels as follows.
1308 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
1309 // But this values don't changed in kernel. So, below change is need.
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301310 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, MAX_VOL_INDEX);
1311 set_values[0] = vol_index;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301312
1313 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1314 if (!ctl) {
1315 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1316 __func__, mixer_ctl_name);
1317 return -EINVAL;
1318 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301319 ALOGV("Setting voice volume index: %d", set_values[0]);
1320 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
Naresh Tannirue3b18452014-03-04 14:44:27 +05301321
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301322 if (my_data->csd != NULL) {
1323 ret = my_data->csd->volume(ALL_SESSION_VSID, volume);
1324 if (ret < 0) {
1325 ALOGE("%s: csd_volume error %d", __func__, ret);
1326 }
1327 }
1328 return ret;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301329}
1330
1331int platform_set_mic_mute(void *platform, bool state)
1332{
1333 struct platform_data *my_data = (struct platform_data *)platform;
1334 struct audio_device *adev = my_data->adev;
1335 struct mixer_ctl *ctl;
1336 const char *mixer_ctl_name = "Voice Tx Mute";
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301337 int ret = 0;
1338 uint32_t set_values[ ] = {0,
1339 ALL_SESSION_VSID,
1340 DEFAULT_VOLUME_RAMP_DURATION_MS};
Naresh Tannirue3b18452014-03-04 14:44:27 +05301341
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301342 set_values[0] = state;
1343 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1344 if (!ctl) {
1345 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1346 __func__, mixer_ctl_name);
1347 return -EINVAL;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301348 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301349 ALOGV("Setting voice mute state: %d", state);
1350 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
Naresh Tannirue3b18452014-03-04 14:44:27 +05301351
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301352 if (my_data->csd != NULL) {
1353 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state);
1354 if (ret < 0) {
1355 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
1356 }
1357 }
1358 return ret;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301359}
1360
Shiv Maliyappanahallic6fd8ee2014-03-07 15:31:55 -08001361int platform_set_device_mute(void *platform, bool state, char *dir)
1362{
1363 struct platform_data *my_data = (struct platform_data *)platform;
1364 struct audio_device *adev = my_data->adev;
1365 struct mixer_ctl *ctl;
1366 char *mixer_ctl_name = NULL;
1367 int ret = 0;
1368 uint32_t set_values[ ] = {0,
1369 ALL_SESSION_VSID,
1370 0};
1371 if(dir == NULL) {
1372 ALOGE("%s: Invalid direction:%s", __func__, dir);
1373 return -EINVAL;
1374 }
1375
1376 if (!strncmp("rx", dir, sizeof("rx"))) {
1377 mixer_ctl_name = "Voice Rx Device Mute";
1378 } else if (!strncmp("tx", dir, sizeof("tx"))) {
1379 mixer_ctl_name = "Voice Tx Device Mute";
1380 } else {
1381 return -EINVAL;
1382 }
1383
1384 set_values[0] = state;
1385 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1386 if (!ctl) {
1387 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1388 __func__, mixer_ctl_name);
1389 return -EINVAL;
1390 }
1391
1392 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
1393 __func__,state, mixer_ctl_name);
1394 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1395
1396 return ret;
1397}
1398
Naresh Tannirue3b18452014-03-04 14:44:27 +05301399snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
1400{
1401 struct platform_data *my_data = (struct platform_data *)platform;
1402 struct audio_device *adev = my_data->adev;
1403 audio_mode_t mode = adev->mode;
1404 snd_device_t snd_device = SND_DEVICE_NONE;
1405
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301406 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
1407 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
1408 int channel_count = popcount(channel_mask);
1409
Naresh Tannirue3b18452014-03-04 14:44:27 +05301410 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
1411 if (devices == AUDIO_DEVICE_NONE ||
1412 devices & AUDIO_DEVICE_BIT_IN) {
1413 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
1414 goto exit;
1415 }
1416
Naresh Tannirue3b18452014-03-04 14:44:27 +05301417 if (popcount(devices) == 2) {
1418 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
1419 AUDIO_DEVICE_OUT_SPEAKER)) {
1420 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
1421 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
1422 AUDIO_DEVICE_OUT_SPEAKER)) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301423 if (audio_extn_get_anc_enabled())
1424 snd_device = SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET;
1425 else
1426 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301427 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
1428 AUDIO_DEVICE_OUT_SPEAKER)) {
1429 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301430 } else if (devices == (AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET |
1431 AUDIO_DEVICE_OUT_SPEAKER)) {
1432 snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301433 } else {
1434 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
1435 goto exit;
1436 }
1437 if (snd_device != SND_DEVICE_NONE) {
1438 goto exit;
1439 }
1440 }
1441
1442 if (popcount(devices) != 1) {
1443 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
1444 goto exit;
1445 }
1446
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301447 if ((mode == AUDIO_MODE_IN_CALL) ||
1448 voice_extn_compress_voip_is_active(adev)) {
1449 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1450 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
1451 if ((adev->voice.tty_mode != TTY_MODE_OFF) &&
1452 !voice_extn_compress_voip_is_active(adev)) {
1453 switch (adev->voice.tty_mode) {
1454 case TTY_MODE_FULL:
1455 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
1456 break;
1457 case TTY_MODE_VCO:
1458 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
1459 break;
1460 case TTY_MODE_HCO:
1461 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
1462 break;
1463 default:
1464 ALOGE("%s: Invalid TTY mode (%#x)",
1465 __func__, adev->voice.tty_mode);
1466 }
1467 } else if (audio_extn_get_anc_enabled()) {
1468 if (audio_extn_should_use_fb_anc())
1469 snd_device = SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET;
1470 else
1471 snd_device = SND_DEVICE_OUT_VOICE_ANC_HEADSET;
1472 } else {
1473 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
1474 }
1475 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Mingming Yin514a8bc2014-07-29 15:22:21 -07001476 if (adev->bt_wb_speech_enabled)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301477 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
1478 else
1479 snd_device = SND_DEVICE_OUT_BT_SCO;
1480 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
1481 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
1482 } else if (devices & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
1483 devices & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
1484 snd_device = SND_DEVICE_OUT_USB_HEADSET;
1485 } else if (devices & AUDIO_DEVICE_OUT_FM_TX) {
1486 snd_device = SND_DEVICE_OUT_TRANSMISSION_FM;
1487 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
1488 if (audio_extn_should_use_handset_anc(channel_count))
1489 snd_device = SND_DEVICE_OUT_ANC_HANDSET;
1490 else
1491 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
1492 }
1493 if (snd_device != SND_DEVICE_NONE) {
1494 goto exit;
1495 }
1496 }
1497
Naresh Tannirue3b18452014-03-04 14:44:27 +05301498 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1499 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301500 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADSET
1501 && audio_extn_get_anc_enabled()) {
1502 if (audio_extn_should_use_fb_anc())
1503 snd_device = SND_DEVICE_OUT_ANC_FB_HEADSET;
1504 else
1505 snd_device = SND_DEVICE_OUT_ANC_HEADSET;
1506 }
1507 else
1508 snd_device = SND_DEVICE_OUT_HEADPHONES;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301509 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
1510 if (adev->speaker_lr_swap)
1511 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
1512 else
1513 snd_device = SND_DEVICE_OUT_SPEAKER;
1514 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Mingming Yin514a8bc2014-07-29 15:22:21 -07001515 if (adev->bt_wb_speech_enabled)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301516 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
1517 else
1518 snd_device = SND_DEVICE_OUT_BT_SCO;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301519 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
1520 snd_device = SND_DEVICE_OUT_HDMI ;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301521 } else if (devices & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
1522 devices & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
Mingming Yin5a7c5d62014-03-05 17:45:03 -08001523 ALOGD("%s: setting USB hadset channel capability(2) for Proxy", __func__);
1524 audio_extn_set_afe_proxy_channel_mixer(adev, 2);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301525 snd_device = SND_DEVICE_OUT_USB_HEADSET;
1526 } else if (devices & AUDIO_DEVICE_OUT_FM_TX) {
1527 snd_device = SND_DEVICE_OUT_TRANSMISSION_FM;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301528 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
1529 snd_device = SND_DEVICE_OUT_HANDSET;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301530 } else if (devices & AUDIO_DEVICE_OUT_PROXY) {
Mingming Yin5a7c5d62014-03-05 17:45:03 -08001531 channel_count = audio_extn_get_afe_proxy_channel_count();
1532 ALOGD("%s: setting sink capability(%d) for Proxy", __func__, channel_count);
1533 audio_extn_set_afe_proxy_channel_mixer(adev, channel_count);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301534 snd_device = SND_DEVICE_OUT_AFE_PROXY;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301535 } else {
1536 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
1537 }
1538exit:
1539 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
1540 return snd_device;
1541}
1542
1543snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
1544{
1545 struct platform_data *my_data = (struct platform_data *)platform;
1546 struct audio_device *adev = my_data->adev;
1547 audio_source_t source = (adev->active_input == NULL) ?
1548 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
1549
1550 audio_mode_t mode = adev->mode;
1551 audio_devices_t in_device = ((adev->active_input == NULL) ?
1552 AUDIO_DEVICE_NONE : adev->active_input->device)
1553 & ~AUDIO_DEVICE_BIT_IN;
1554 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
1555 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
1556 snd_device_t snd_device = SND_DEVICE_NONE;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301557 int channel_count = popcount(channel_mask);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301558
1559 ALOGV("%s: enter: out_device(%#x) in_device(%#x)",
1560 __func__, out_device, in_device);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301561 if ((out_device != AUDIO_DEVICE_NONE) && ((mode == AUDIO_MODE_IN_CALL) ||
Satya Krishna Pindiproli2aaa6152014-05-21 15:05:22 +05301562 voice_extn_compress_voip_is_active(adev) || audio_extn_hfp_is_active(adev))) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301563 if ((adev->voice.tty_mode != TTY_MODE_OFF) &&
1564 !voice_extn_compress_voip_is_active(adev)) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301565 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1566 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301567 switch (adev->voice.tty_mode) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301568 case TTY_MODE_FULL:
1569 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
1570 break;
1571 case TTY_MODE_VCO:
1572 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
1573 break;
1574 case TTY_MODE_HCO:
1575 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
1576 break;
1577 default:
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301578 ALOGE("%s: Invalid TTY mode (%#x)",
1579 __func__, adev->voice.tty_mode);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301580 }
1581 goto exit;
1582 }
1583 }
1584 if (out_device & AUDIO_DEVICE_OUT_EARPIECE ||
1585 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301586 if (out_device & AUDIO_DEVICE_OUT_EARPIECE &&
1587 audio_extn_should_use_handset_anc(channel_count)) {
1588 snd_device = SND_DEVICE_IN_AANC_HANDSET_MIC;
1589 } else if (my_data->fluence_type == FLUENCE_NONE ||
1590 my_data->fluence_in_voice_call == false) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301591 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +05301592 if (audio_extn_hfp_is_active(adev))
1593 platform_set_echo_reference(adev->platform, true);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301594 } else {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301595 snd_device = SND_DEVICE_IN_VOICE_DMIC;
1596 adev->acdb_settings |= DMIC_FLAG;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301597 }
1598 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
1599 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +05301600 if (audio_extn_hfp_is_active(adev))
1601 platform_set_echo_reference(adev->platform, true);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301602 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Vicky Sehrawate240e5d2014-08-12 17:17:04 -07001603 if (adev->bt_wb_speech_enabled) {
1604 if (adev->bluetooth_nrec)
1605 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
1606 else
1607 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
1608 } else {
1609 if (adev->bluetooth_nrec)
1610 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
1611 else
1612 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
1613 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05301614 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301615 if (my_data->fluence_type != FLUENCE_NONE &&
1616 my_data->fluence_in_voice_call &&
1617 my_data->fluence_in_spkr_mode) {
1618 if(my_data->fluence_type & FLUENCE_QUAD_MIC) {
1619 adev->acdb_settings |= QMIC_FLAG;
1620 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_QMIC;
1621 } else {
1622 adev->acdb_settings |= DMIC_FLAG;
Karthik Reddy Kattad9fff862014-07-21 21:07:21 +05301623 if (my_data->fluence_mode == FLUENCE_BROADSIDE)
1624 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BROADSIDE;
1625 else
1626 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301627 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05301628 } else {
1629 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +05301630 if (audio_extn_hfp_is_active(adev))
1631 platform_set_echo_reference(adev->platform, true);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301632 }
1633 }
1634 } else if (source == AUDIO_SOURCE_CAMCORDER) {
1635 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
1636 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
kunleiz18a33302014-05-30 09:52:25 +08001637 if (my_data->fluence_type & FLUENCE_DUAL_MIC &&
1638 channel_count == 2)
kunleiz8f7e9e22014-06-24 15:12:02 +08001639 snd_device = SND_DEVICE_IN_HANDSET_STEREO_DMIC;
kunleiz18a33302014-05-30 09:52:25 +08001640 else
1641 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301642 }
1643 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
1644 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301645 if (channel_count == 2) {
1646 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
1647 adev->acdb_settings |= DMIC_FLAG;
1648 } else if (adev->active_input->enable_ns)
1649 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
1650 else if (my_data->fluence_type != FLUENCE_NONE &&
1651 my_data->fluence_in_voice_rec) {
1652 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
1653 adev->acdb_settings |= DMIC_FLAG;
1654 } else {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301655 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
1656 }
1657 }
1658 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION) {
1659 if (out_device & AUDIO_DEVICE_OUT_SPEAKER)
1660 in_device = AUDIO_DEVICE_IN_BACK_MIC;
1661 if (adev->active_input) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301662 if (adev->active_input->enable_aec &&
1663 adev->active_input->enable_ns) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301664 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301665 if (my_data->fluence_type & FLUENCE_DUAL_MIC &&
1666 my_data->fluence_in_spkr_mode) {
Karthik Reddy Kattad9fff862014-07-21 21:07:21 +05301667 if (my_data->fluence_mode == FLUENCE_BROADSIDE)
1668 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_BROADSIDE;
1669 else
1670 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301671 adev->acdb_settings |= DMIC_FLAG;
1672 } else
1673 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301674 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301675 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1676 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
1677 adev->acdb_settings |= DMIC_FLAG;
1678 } else
1679 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301680 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301681 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301682 }
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +05301683 platform_set_echo_reference(adev->platform, true);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301684 } else if (adev->active_input->enable_aec) {
1685 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Karthik Reddy Kattad9fff862014-07-21 21:07:21 +05301686 if (my_data->fluence_type & FLUENCE_DUAL_MIC &&
1687 my_data->fluence_in_spkr_mode) {
1688 if (my_data->fluence_mode == FLUENCE_BROADSIDE)
1689 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_BROADSIDE;
1690 else
1691 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301692 adev->acdb_settings |= DMIC_FLAG;
1693 } else
1694 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
1695 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
1696 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1697 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
1698 adev->acdb_settings |= DMIC_FLAG;
1699 } else
1700 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
1701 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
1702 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
1703 }
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +05301704 platform_set_echo_reference(adev->platform, true);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301705 } else if (adev->active_input->enable_ns) {
1706 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Karthik Reddy Kattad9fff862014-07-21 21:07:21 +05301707 if (my_data->fluence_type & FLUENCE_DUAL_MIC &&
1708 my_data->fluence_in_spkr_mode) {
1709 if (my_data->fluence_mode == FLUENCE_BROADSIDE)
1710 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS_BROADSIDE;
1711 else
1712 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301713 adev->acdb_settings |= DMIC_FLAG;
1714 } else
1715 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
1716 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
1717 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1718 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
1719 adev->acdb_settings |= DMIC_FLAG;
1720 } else
1721 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
1722 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
1723 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
1724 }
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +05301725 platform_set_echo_reference(adev->platform,false);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301726 } else
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +05301727 platform_set_echo_reference(adev->platform, false);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301728 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301729 } else if (source == AUDIO_SOURCE_MIC) {
1730 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC &&
1731 channel_count == 1 ) {
1732 if(my_data->fluence_type & FLUENCE_DUAL_MIC &&
1733 my_data->fluence_in_audio_rec)
1734 snd_device = SND_DEVICE_IN_HANDSET_DMIC;
1735 }
1736 } else if (source == AUDIO_SOURCE_FM_RX ||
1737 source == AUDIO_SOURCE_FM_RX_A2DP) {
1738 snd_device = SND_DEVICE_IN_CAPTURE_FM;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301739 } else if (source == AUDIO_SOURCE_DEFAULT) {
1740 goto exit;
1741 }
1742
1743
1744 if (snd_device != SND_DEVICE_NONE) {
1745 goto exit;
1746 }
1747
1748 if (in_device != AUDIO_DEVICE_NONE &&
1749 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
1750 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
1751 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301752 if (audio_extn_ssr_get_enabled() && channel_count == 6)
1753 snd_device = SND_DEVICE_IN_QUAD_MIC;
1754 else if (channel_count == 2)
1755 snd_device = SND_DEVICE_IN_HANDSET_STEREO_DMIC;
1756 else
1757 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301758 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
1759 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
1760 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
1761 snd_device = SND_DEVICE_IN_HEADSET_MIC;
1762 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Vicky Sehrawate240e5d2014-08-12 17:17:04 -07001763 if (adev->bt_wb_speech_enabled) {
1764 if (adev->bluetooth_nrec)
1765 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
1766 else
1767 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
1768 } else {
1769 if (adev->bluetooth_nrec)
1770 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
1771 else
1772 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
1773 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05301774 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
1775 snd_device = SND_DEVICE_IN_HDMI_MIC;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301776 } else if (in_device & AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET ||
1777 in_device & AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET) {
1778 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
1779 } else if (in_device & AUDIO_DEVICE_IN_FM_RX) {
1780 snd_device = SND_DEVICE_IN_CAPTURE_FM;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301781 } else {
1782 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
1783 ALOGW("%s: Using default handset-mic", __func__);
1784 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1785 }
1786 } else {
1787 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
1788 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1789 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
1790 snd_device = SND_DEVICE_IN_HEADSET_MIC;
1791 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301792 if (channel_count > 1)
1793 snd_device = SND_DEVICE_IN_SPEAKER_STEREO_DMIC;
1794 else
1795 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301796 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
1797 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1798 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Vicky Sehrawate240e5d2014-08-12 17:17:04 -07001799 if (adev->bt_wb_speech_enabled) {
1800 if (adev->bluetooth_nrec)
1801 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
1802 else
1803 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
1804 } else {
1805 if (adev->bluetooth_nrec)
1806 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
1807 else
1808 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
1809 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05301810 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
1811 snd_device = SND_DEVICE_IN_HDMI_MIC;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301812 } else if (out_device & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
1813 out_device & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
1814 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301815 } else {
1816 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
1817 ALOGW("%s: Using default handset-mic", __func__);
1818 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1819 }
1820 }
1821exit:
1822 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
1823 return snd_device;
1824}
1825
1826int platform_set_hdmi_channels(void *platform, int channel_count)
1827{
1828 struct platform_data *my_data = (struct platform_data *)platform;
1829 struct audio_device *adev = my_data->adev;
1830 struct mixer_ctl *ctl;
1831 const char *channel_cnt_str = NULL;
1832 const char *mixer_ctl_name = "HDMI_RX Channels";
1833 switch (channel_count) {
1834 case 8:
1835 channel_cnt_str = "Eight"; break;
1836 case 7:
1837 channel_cnt_str = "Seven"; break;
1838 case 6:
1839 channel_cnt_str = "Six"; break;
1840 case 5:
1841 channel_cnt_str = "Five"; break;
1842 case 4:
1843 channel_cnt_str = "Four"; break;
1844 case 3:
1845 channel_cnt_str = "Three"; break;
1846 default:
1847 channel_cnt_str = "Two"; break;
1848 }
1849 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1850 if (!ctl) {
1851 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1852 __func__, mixer_ctl_name);
1853 return -EINVAL;
1854 }
1855 ALOGV("HDMI channel count: %s", channel_cnt_str);
1856 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
1857 return 0;
1858}
1859
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301860int platform_edid_get_max_channels(void *platform)
Naresh Tannirue3b18452014-03-04 14:44:27 +05301861{
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301862 struct platform_data *my_data = (struct platform_data *)platform;
1863 struct audio_device *adev = my_data->adev;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301864 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
1865 char *sad = block;
1866 int num_audio_blocks;
1867 int channel_count;
1868 int max_channels = 0;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301869 int i, ret, count;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301870
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301871 struct mixer_ctl *ctl;
1872
1873 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
1874 if (!ctl) {
1875 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1876 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301877 return 0;
1878 }
1879
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301880 mixer_ctl_update(ctl);
1881
1882 count = mixer_ctl_get_num_values(ctl);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301883
1884 /* Read SAD blocks, clamping the maximum size for safety */
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301885 if (count > (int)sizeof(block))
1886 count = (int)sizeof(block);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301887
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301888 ret = mixer_ctl_get_array(ctl, block, count);
1889 if (ret != 0) {
1890 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
1891 return 0;
1892 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05301893
1894 /* Calculate the number of SAD blocks */
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301895 num_audio_blocks = count / SAD_BLOCK_SIZE;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301896
1897 for (i = 0; i < num_audio_blocks; i++) {
1898 /* Only consider LPCM blocks */
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301899 if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
1900 sad += 3;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301901 continue;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301902 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05301903
1904 channel_count = (sad[0] & 0x7) + 1;
1905 if (channel_count > max_channels)
1906 max_channels = channel_count;
1907
1908 /* Advance to next block */
1909 sad += 3;
1910 }
1911
1912 return max_channels;
1913}
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301914
1915static int platform_set_slowtalk(struct platform_data *my_data, bool state)
1916{
1917 int ret = 0;
1918 struct audio_device *adev = my_data->adev;
1919 struct mixer_ctl *ctl;
1920 const char *mixer_ctl_name = "Slowtalk Enable";
1921 uint32_t set_values[ ] = {0,
1922 ALL_SESSION_VSID};
1923
1924 set_values[0] = state;
1925 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1926 if (!ctl) {
1927 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1928 __func__, mixer_ctl_name);
1929 ret = -EINVAL;
1930 } else {
1931 ALOGV("Setting slowtalk state: %d", state);
1932 ret = mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1933 my_data->slowtalk = state;
1934 }
1935
1936 if (my_data->csd != NULL) {
1937 ret = my_data->csd->slow_talk(ALL_SESSION_VSID, state);
1938 if (ret < 0) {
1939 ALOGE("%s: csd_client_disable_device, failed, error %d",
1940 __func__, ret);
1941 }
1942 }
1943 return ret;
1944}
1945
Avinash Vaishd5fa4572014-09-15 14:41:14 +05301946static int set_hd_voice(struct platform_data *my_data, bool state)
1947{
1948 struct audio_device *adev = my_data->adev;
1949 struct mixer_ctl *ctl;
1950 const char *mixer_ctl_name = "HD Voice Enable";
1951 int ret = 0;
1952 uint32_t set_values[ ] = {0,
1953 ALL_SESSION_VSID};
1954
1955 set_values[0] = state;
1956 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1957 if (!ctl) {
1958 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1959 __func__, mixer_ctl_name);
1960 ret = -EINVAL;
1961 } else {
1962 ALOGV("Setting HD Voice state: %d", state);
1963 ret = mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1964 my_data->hd_voice = state;
1965 }
1966
1967 return ret;
1968}
1969
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301970int platform_set_parameters(void *platform, struct str_parms *parms)
1971{
1972 struct platform_data *my_data = (struct platform_data *)platform;
1973 char *str;
1974 char value[256] = {0};
1975 int val;
1976 int ret = 0, err;
Karthik Reddy Kattabfe193d2014-08-14 17:58:18 +05301977 char *kv_pairs = NULL;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301978
Karthik Reddy Kattabfe193d2014-08-14 17:58:18 +05301979 kv_pairs = str_parms_to_str(parms);
1980 ALOGV("%s: enter: - %s", __func__, kv_pairs);
1981 free(kv_pairs);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301982
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301983 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_SLOWTALK, value, sizeof(value));
1984 if (err >= 0) {
1985 bool state = false;
1986 if (!strncmp("true", value, sizeof("true"))) {
1987 state = true;
1988 }
1989
1990 str_parms_del(parms, AUDIO_PARAMETER_KEY_SLOWTALK);
1991 ret = platform_set_slowtalk(my_data, state);
1992 if (ret)
1993 ALOGE("%s: Failed to set slow talk err: %d", __func__, ret);
1994 }
1995
Avinash Vaishd5fa4572014-09-15 14:41:14 +05301996 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_HD_VOICE, value, sizeof(value));
1997 if (err >= 0) {
1998 bool state = false;
1999 if (!strncmp("true", value, sizeof("true"))) {
2000 state = true;
2001 }
2002
2003 str_parms_del(parms, AUDIO_PARAMETER_KEY_HD_VOICE);
2004 if (my_data->hd_voice != state) {
2005 ret = set_hd_voice(my_data, state);
2006 if (ret)
2007 ALOGE("%s: Failed to set HD voice err: %d", __func__, ret);
2008 } else {
2009 ALOGV("%s: HD Voice already set to %d", __func__, state);
2010 }
2011 }
2012
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302013 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_VOLUME_BOOST,
2014 value, sizeof(value));
2015 if (err >= 0) {
2016 str_parms_del(parms, AUDIO_PARAMETER_KEY_VOLUME_BOOST);
2017
2018 if (my_data->acdb_reload_vocvoltable == NULL) {
2019 ALOGE("%s: acdb_reload_vocvoltable is NULL", __func__);
2020 } else if (!strcmp(value, "on")) {
2021 if (!my_data->acdb_reload_vocvoltable(VOICE_FEATURE_SET_VOLUME_BOOST)) {
2022 my_data->voice_feature_set = 1;
2023 }
2024 } else {
2025 if (!my_data->acdb_reload_vocvoltable(VOICE_FEATURE_SET_DEFAULT)) {
2026 my_data->voice_feature_set = 0;
2027 }
2028 }
2029 }
2030
2031 ALOGV("%s: exit with code(%d)", __func__, ret);
2032 return ret;
2033}
2034
2035int platform_set_incall_recording_session_id(void *platform,
2036 uint32_t session_id, int rec_mode)
2037{
2038 int ret = 0;
2039 struct platform_data *my_data = (struct platform_data *)platform;
2040 struct audio_device *adev = my_data->adev;
2041 struct mixer_ctl *ctl;
2042 const char *mixer_ctl_name = "Voc VSID";
2043 int num_ctl_values;
2044 int i;
2045
2046 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2047 if (!ctl) {
2048 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2049 __func__, mixer_ctl_name);
2050 ret = -EINVAL;
2051 } else {
2052 num_ctl_values = mixer_ctl_get_num_values(ctl);
2053 for (i = 0; i < num_ctl_values; i++) {
2054 if (mixer_ctl_set_value(ctl, i, session_id)) {
2055 ALOGV("Error: invalid session_id: %x", session_id);
2056 ret = -EINVAL;
2057 break;
2058 }
2059 }
2060 }
2061
2062 if (my_data->csd != NULL) {
2063 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
2064 if (ret < 0) {
2065 ALOGE("%s: csd_client_start_record failed, error %d",
2066 __func__, ret);
2067 }
2068 }
2069
2070 return ret;
2071}
2072
2073int platform_stop_incall_recording_usecase(void *platform)
2074{
2075 int ret = 0;
2076 struct platform_data *my_data = (struct platform_data *)platform;
2077
2078 if (my_data->csd != NULL) {
2079 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
2080 if (ret < 0) {
2081 ALOGE("%s: csd_client_stop_record failed, error %d",
2082 __func__, ret);
2083 }
2084 }
2085
2086 return ret;
2087}
2088
2089int platform_start_incall_music_usecase(void *platform)
2090{
2091 int ret = 0;
2092 struct platform_data *my_data = (struct platform_data *)platform;
2093
2094 if (my_data->csd != NULL) {
2095 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
2096 if (ret < 0) {
2097 ALOGE("%s: csd_client_start_playback failed, error %d",
2098 __func__, ret);
2099 }
2100 }
2101
2102 return ret;
2103}
2104
2105int platform_stop_incall_music_usecase(void *platform)
2106{
2107 int ret = 0;
2108 struct platform_data *my_data = (struct platform_data *)platform;
2109
2110 if (my_data->csd != NULL) {
2111 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
2112 if (ret < 0) {
2113 ALOGE("%s: csd_client_stop_playback failed, error %d",
2114 __func__, ret);
2115 }
2116 }
2117
2118 return ret;
2119}
2120
Vidyakumar Athota21b3bb92014-04-25 11:08:08 -07002121int platform_update_lch(void *platform, struct voice_session *session,
2122 enum voice_lch_mode lch_mode)
2123{
2124 int ret = 0;
2125 struct platform_data *my_data = (struct platform_data *)platform;
2126
2127 if ((my_data->csd != NULL) && (my_data->csd->set_lch != NULL))
2128 ret = my_data->csd->set_lch(session->vsid, lch_mode);
2129 else
2130 ret = pcm_ioctl(session->pcm_tx, SNDRV_VOICE_IOCTL_LCH, &lch_mode);
2131
2132 return ret;
2133}
2134
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302135void platform_get_parameters(void *platform,
2136 struct str_parms *query,
2137 struct str_parms *reply)
2138{
2139 struct platform_data *my_data = (struct platform_data *)platform;
2140 char *str = NULL;
2141 char value[256] = {0};
2142 int ret;
Karthik Reddy Kattabfe193d2014-08-14 17:58:18 +05302143 char *kv_pairs = NULL;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302144
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302145 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_SLOWTALK,
2146 value, sizeof(value));
2147 if (ret >= 0) {
2148 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_SLOWTALK,
2149 my_data->slowtalk?"true":"false");
2150 }
2151
Avinash Vaishd5fa4572014-09-15 14:41:14 +05302152 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_HD_VOICE,
2153 value, sizeof(value));
2154 if (ret >= 0) {
2155 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_HD_VOICE,
2156 my_data->hd_voice?"true":"false");
2157 }
2158
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302159 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_VOLUME_BOOST,
2160 value, sizeof(value));
2161 if (ret >= 0) {
2162 if (my_data->voice_feature_set == VOICE_FEATURE_SET_VOLUME_BOOST) {
2163 strlcpy(value, "on", sizeof(value));
2164 } else {
2165 strlcpy(value, "off", sizeof(value));
2166 }
2167
2168 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_VOLUME_BOOST, value);
2169 }
2170
Karthik Reddy Kattabfe193d2014-08-14 17:58:18 +05302171 kv_pairs = str_parms_to_str(reply);
2172 ALOGV("%s: exit: returns - %s", __func__, kv_pairs);
2173 free(kv_pairs);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302174}
2175
2176/* Delay in Us */
2177int64_t platform_render_latency(audio_usecase_t usecase)
2178{
2179 switch (usecase) {
2180 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
2181 return DEEP_BUFFER_PLATFORM_DELAY;
2182 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
2183 return LOW_LATENCY_PLATFORM_DELAY;
2184 default:
2185 return 0;
2186 }
2187}
2188
2189int platform_update_usecase_from_source(int source, int usecase)
2190{
2191 ALOGV("%s: input source :%d", __func__, source);
2192 if(source == AUDIO_SOURCE_FM_RX_A2DP)
2193 usecase = USECASE_AUDIO_RECORD_FM_VIRTUAL;
2194 return usecase;
2195}
2196
Dhananjay Kumar45b71742014-05-29 21:47:27 +05302197bool platform_listen_device_needs_event(snd_device_t snd_device)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302198{
Dhananjay Kumar45b71742014-05-29 21:47:27 +05302199 bool needs_event = false;
2200
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302201 if ((snd_device >= SND_DEVICE_IN_BEGIN) &&
2202 (snd_device < SND_DEVICE_IN_END) &&
2203 (snd_device != SND_DEVICE_IN_CAPTURE_FM) &&
2204 (snd_device != SND_DEVICE_IN_CAPTURE_VI_FEEDBACK))
Dhananjay Kumar45b71742014-05-29 21:47:27 +05302205 needs_event = true;
2206
2207 return needs_event;
2208}
2209
2210bool platform_listen_usecase_needs_event(audio_usecase_t uc_id)
2211{
2212 bool needs_event = false;
2213
2214 switch(uc_id){
2215 /* concurrent playback usecases needs event */
2216 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
2217 case USECASE_AUDIO_PLAYBACK_MULTI_CH:
2218 case USECASE_AUDIO_PLAYBACK_OFFLOAD:
2219 needs_event = true;
2220 break;
2221 /* concurrent playback in low latency allowed */
2222 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
2223 break;
2224 /* concurrent playback FM needs event */
2225 case USECASE_AUDIO_PLAYBACK_FM:
2226 needs_event = true;
2227 break;
2228
2229 /* concurrent capture usecases, no event, capture handled by device
2230 * USECASE_AUDIO_RECORD:
2231 * USECASE_AUDIO_RECORD_COMPRESS:
2232 * USECASE_AUDIO_RECORD_LOW_LATENCY:
2233
2234 * USECASE_VOICE_CALL:
2235 * USECASE_VOICE2_CALL:
2236 * USECASE_VOLTE_CALL:
2237 * USECASE_QCHAT_CALL:
2238 * USECASE_VOWLAN_CALL:
2239 * USECASE_COMPRESS_VOIP_CALL:
2240 * USECASE_AUDIO_RECORD_FM_VIRTUAL:
2241 * USECASE_INCALL_REC_UPLINK:
2242 * USECASE_INCALL_REC_DOWNLINK:
2243 * USECASE_INCALL_REC_UPLINK_AND_DOWNLINK:
2244 * USECASE_INCALL_REC_UPLINK_COMPRESS:
2245 * USECASE_INCALL_REC_DOWNLINK_COMPRESS:
2246 * USECASE_INCALL_REC_UPLINK_AND_DOWNLINK_COMPRESS:
2247 * USECASE_INCALL_MUSIC_UPLINK:
2248 * USECASE_INCALL_MUSIC_UPLINK2:
2249 * USECASE_AUDIO_SPKR_CALIB_RX:
2250 * USECASE_AUDIO_SPKR_CALIB_TX:
2251 */
2252 default:
2253 ALOGV("%s:usecase_id[%d} no need to raise event.", __func__, uc_id);
2254 }
2255 return needs_event;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302256}
2257
Ravi Kumar Alamanda8fa6b192014-09-09 16:06:42 -07002258bool platform_sound_trigger_device_needs_event(snd_device_t snd_device)
2259{
2260 bool needs_event = false;
2261
2262 if ((snd_device >= SND_DEVICE_IN_BEGIN) &&
2263 (snd_device < SND_DEVICE_IN_END) &&
2264 (snd_device != SND_DEVICE_IN_CAPTURE_FM) &&
2265 (snd_device != SND_DEVICE_IN_CAPTURE_VI_FEEDBACK))
2266 needs_event = true;
2267
2268 return needs_event;
2269}
2270
2271bool platform_sound_trigger_usecase_needs_event(audio_usecase_t uc_id)
2272{
2273 bool needs_event = false;
2274
2275 switch(uc_id){
2276 /* concurrent playback usecases needs event */
2277 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
2278 case USECASE_AUDIO_PLAYBACK_MULTI_CH:
2279 case USECASE_AUDIO_PLAYBACK_OFFLOAD:
2280 needs_event = true;
2281 break;
2282 /* concurrent playback in low latency allowed */
2283 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
2284 break;
2285 /* concurrent playback FM needs event */
2286 case USECASE_AUDIO_PLAYBACK_FM:
2287 needs_event = true;
2288 break;
2289
2290 /* concurrent capture usecases, no event, capture handled by device
2291 * USECASE_AUDIO_RECORD:
2292 * USECASE_AUDIO_RECORD_COMPRESS:
2293 * USECASE_AUDIO_RECORD_LOW_LATENCY:
2294
2295 * USECASE_VOICE_CALL:
2296 * USECASE_VOICE2_CALL:
2297 * USECASE_VOLTE_CALL:
2298 * USECASE_QCHAT_CALL:
2299 * USECASE_VOWLAN_CALL:
2300 * USECASE_COMPRESS_VOIP_CALL:
2301 * USECASE_AUDIO_RECORD_FM_VIRTUAL:
2302 * USECASE_INCALL_REC_UPLINK:
2303 * USECASE_INCALL_REC_DOWNLINK:
2304 * USECASE_INCALL_REC_UPLINK_AND_DOWNLINK:
2305 * USECASE_INCALL_REC_UPLINK_COMPRESS:
2306 * USECASE_INCALL_REC_DOWNLINK_COMPRESS:
2307 * USECASE_INCALL_REC_UPLINK_AND_DOWNLINK_COMPRESS:
2308 * USECASE_INCALL_MUSIC_UPLINK:
2309 * USECASE_INCALL_MUSIC_UPLINK2:
2310 * USECASE_AUDIO_SPKR_CALIB_RX:
2311 * USECASE_AUDIO_SPKR_CALIB_TX:
2312 */
2313 default:
2314 ALOGV("%s:usecase_id[%d] no need to raise event.", __func__, uc_id);
2315 }
2316 return needs_event;
2317}
2318
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302319/* Read offload buffer size from a property.
2320 * If value is not power of 2 round it to
2321 * power of 2.
2322 */
2323uint32_t platform_get_compress_offload_buffer_size(audio_offload_info_t* info)
2324{
2325 char value[PROPERTY_VALUE_MAX] = {0};
2326 uint32_t fragment_size = COMPRESS_OFFLOAD_FRAGMENT_SIZE;
2327 if((property_get("audio.offload.buffer.size.kb", value, "")) &&
2328 atoi(value)) {
2329 fragment_size = atoi(value) * 1024;
2330 }
2331
2332 if (info != NULL && info->has_video && info->is_streaming) {
2333 fragment_size = COMPRESS_OFFLOAD_FRAGMENT_SIZE_FOR_AV_STREAMING;
2334 ALOGV("%s: offload fragment size reduced for AV streaming to %d",
Apoorv Raghuvanshi44bd9172014-05-28 14:50:07 -07002335 __func__, fragment_size);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302336 }
2337
2338 fragment_size = ALIGN( fragment_size, 1024);
2339
2340 if(fragment_size < MIN_COMPRESS_OFFLOAD_FRAGMENT_SIZE)
2341 fragment_size = MIN_COMPRESS_OFFLOAD_FRAGMENT_SIZE;
2342 else if(fragment_size > MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE)
2343 fragment_size = MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE;
2344 ALOGV("%s: fragment_size %d", __func__, fragment_size);
2345 return fragment_size;
2346}
2347
2348uint32_t platform_get_pcm_offload_buffer_size(audio_offload_info_t* info)
2349{
2350 uint32_t fragment_size = MIN_PCM_OFFLOAD_FRAGMENT_SIZE;
2351 uint32_t bits_per_sample = 16;
2352
2353 if (info->format == AUDIO_FORMAT_PCM_24_BIT_OFFLOAD) {
2354 bits_per_sample = 32;
2355 }
2356
2357 if (!info->has_video) {
2358 fragment_size = MAX_PCM_OFFLOAD_FRAGMENT_SIZE;
2359
2360 } else if (info->has_video && info->is_streaming) {
2361 fragment_size = (PCM_OFFLOAD_BUFFER_DURATION_FOR_AV_STREAMING
2362 * info->sample_rate
2363 * bits_per_sample
2364 * popcount(info->channel_mask))/1000;
2365
2366 } else if (info->has_video) {
2367 fragment_size = (PCM_OFFLOAD_BUFFER_DURATION_FOR_AV
2368 * info->sample_rate
2369 * bits_per_sample
2370 * popcount(info->channel_mask))/1000;
2371 }
2372
2373 fragment_size = ALIGN( fragment_size, 1024);
2374
2375 if(fragment_size < MIN_PCM_OFFLOAD_FRAGMENT_SIZE)
2376 fragment_size = MIN_PCM_OFFLOAD_FRAGMENT_SIZE;
2377 else if(fragment_size > MAX_PCM_OFFLOAD_FRAGMENT_SIZE)
2378 fragment_size = MAX_PCM_OFFLOAD_FRAGMENT_SIZE;
2379
2380 ALOGV("%s: fragment_size %d", __func__, fragment_size);
2381 return fragment_size;
2382}
2383
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07002384bool platform_check_and_set_codec_backend_cfg(struct audio_device* adev __unused,
2385 struct audio_usecase *usecase __unused)
2386{
Mingming Yin3ee55c62014-08-04 14:23:35 -07002387 return false;
2388}
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07002389
2390int platform_get_usecase_index(const char * usecase __unused)
2391{
2392 return -ENOSYS;
2393}
2394
2395int platform_set_usecase_pcm_id(audio_usecase_t usecase __unused, int32_t type __unused,
2396 int32_t pcm_id __unused)
2397{
2398 return -ENOSYS;
2399}
2400
2401int platform_set_snd_device_backend(snd_device_t snd_device __unused,
2402 const char * backend __unused)
2403{
2404 return -ENOSYS;
2405}
2406