blob: 005c0b8dda2864a1354899b6c03e1aa1cd40b257 [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 Uyyalafdc2ed42014-09-22 14:17:10 +0530285 [SND_DEVICE_OUT_SPEAKER] = 131,
286 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 131,
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 Uyyalafdc2ed42014-09-22 14:17:10 +0530293 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 131,
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 Uyyalafdc2ed42014-09-22 14:17:10 +0530301 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = 131,
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;
Asish Bhattacharya4ff24802014-04-24 17:46:54 +0530768 char mixer_xml_path[100];
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 }
870
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530871 my_data->voice_feature_set = VOICE_FEATURE_SET_DEFAULT;
Naresh Tannirue3b18452014-03-04 14:44:27 +0530872 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
873 if (my_data->acdb_handle == NULL) {
874 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
875 } else {
876 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
877 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
878 "acdb_loader_deallocate_ACDB");
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530879 if (!my_data->acdb_deallocate)
880 ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s",
881 __func__, LIB_ACDB_LOADER);
882
Naresh Tannirue3b18452014-03-04 14:44:27 +0530883 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 -0700884 "acdb_loader_send_audio_cal_v2");
Naresh Tannirue3b18452014-03-04 14:44:27 +0530885 if (!my_data->acdb_send_audio_cal)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530886 ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530887 __func__, LIB_ACDB_LOADER);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530888
Naresh Tannirue3b18452014-03-04 14:44:27 +0530889 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
890 "acdb_loader_send_voice_cal");
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530891 if (!my_data->acdb_send_voice_cal)
892 ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s",
893 __func__, LIB_ACDB_LOADER);
894
895 my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle,
896 "acdb_loader_reload_vocvoltable");
897 if (!my_data->acdb_reload_vocvoltable)
898 ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s",
899 __func__, LIB_ACDB_LOADER);
900
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -0700901 my_data->acdb_get_default_app_type = (acdb_get_default_app_type_t)dlsym(
902 my_data->acdb_handle,
903 "acdb_loader_get_default_app_type");
904 if (!my_data->acdb_get_default_app_type)
905 ALOGE("%s: Could not find the symbol acdb_get_default_app_type from %s",
906 __func__, LIB_ACDB_LOADER);
907
Naresh Tannirue3b18452014-03-04 14:44:27 +0530908 my_data->acdb_init = (acdb_init_t)dlsym(my_data->acdb_handle,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530909 "acdb_loader_init_v2");
Avinash Vaish71c066d2014-08-27 12:32:35 +0530910 if (my_data->acdb_init == NULL) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530911 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__, dlerror());
Avinash Vaish71c066d2014-08-27 12:32:35 +0530912 goto acdb_init_fail;
913 }
914
915 cvd_version = calloc(1, MAX_CVD_VERSION_STRING_SIZE);
916 if (!cvd_version)
917 ALOGE("Failed to allocate cvd version");
Naresh Tannirue3b18452014-03-04 14:44:27 +0530918 else
Avinash Vaish71c066d2014-08-27 12:32:35 +0530919 get_cvd_version(cvd_version, adev);
920
921 my_data->acdb_init(snd_card_name, cvd_version);
922 if (cvd_version)
923 free(cvd_version);
Naresh Tannirue3b18452014-03-04 14:44:27 +0530924 }
925
Avinash Vaish71c066d2014-08-27 12:32:35 +0530926acdb_init_fail:
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530927 /* Initialize ACDB ID's */
928 platform_info_init(PLATFORM_INFO_XML_PATH);
929
930 /* init usb */
931 audio_extn_usb_init(adev);
932 /* update sound cards appropriately */
933 audio_extn_usb_set_proxy_sound_card(adev->snd_card);
934
935 /* Read one time ssr property */
936 audio_extn_ssr_update_enabled();
937 audio_extn_spkr_prot_init(adev);
Dhananjay Kumar89ea3bd2014-04-29 15:45:57 +0530938
939 audio_extn_dolby_set_license(adev);
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +0530940 audio_hwdep_send_cal(my_data);
Dhananjay Kumar89ea3bd2014-04-29 15:45:57 +0530941
Naresh Tannirue3b18452014-03-04 14:44:27 +0530942 return my_data;
943}
944
945void platform_deinit(void *platform)
946{
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530947 struct platform_data *my_data = (struct platform_data *)platform;
948
949 hw_info_deinit(my_data->hw_info);
950 close_csd_client(my_data->csd);
951
Naresh Tannirue3b18452014-03-04 14:44:27 +0530952 free(platform);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530953 /* deinit usb */
954 audio_extn_usb_deinit();
Naresh Tannirue3b18452014-03-04 14:44:27 +0530955}
956
957const char *platform_get_snd_device_name(snd_device_t snd_device)
958{
959 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX)
960 return device_table[snd_device];
961 else
962 return "";
963}
964
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530965int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
966 char *device_name)
967{
968 struct platform_data *my_data = (struct platform_data *)platform;
969
970 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
971 strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE);
972 hw_info_append_hw_type(my_data->hw_info, snd_device, device_name);
973 } else {
974 strlcpy(device_name, "", DEVICE_NAME_MAX_SIZE);
975 return -EINVAL;
976 }
977
978 return 0;
979}
980
Naresh Tannirue3b18452014-03-04 14:44:27 +0530981void platform_add_backend_name(char *mixer_path, snd_device_t snd_device)
982{
Vicky Sehrawate240e5d2014-08-12 17:17:04 -0700983 if ((snd_device == SND_DEVICE_IN_BT_SCO_MIC) ||
984 (snd_device == SND_DEVICE_IN_BT_SCO_MIC_NREC))
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530985 strlcat(mixer_path, " bt-sco", MIXER_PATH_MAX_LENGTH);
Vicky Sehrawate240e5d2014-08-12 17:17:04 -0700986 else if ((snd_device == SND_DEVICE_IN_BT_SCO_MIC_WB) ||
987 (snd_device == SND_DEVICE_IN_BT_SCO_MIC_WB_NREC))
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530988 strlcat(mixer_path, " bt-sco-wb", MIXER_PATH_MAX_LENGTH);
Naresh Tannirue3b18452014-03-04 14:44:27 +0530989 else if(snd_device == SND_DEVICE_OUT_BT_SCO)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530990 strlcat(mixer_path, " bt-sco", MIXER_PATH_MAX_LENGTH);
991 else if(snd_device == SND_DEVICE_OUT_BT_SCO_WB)
992 strlcat(mixer_path, " bt-sco-wb", MIXER_PATH_MAX_LENGTH);
Naresh Tannirue3b18452014-03-04 14:44:27 +0530993 else if (snd_device == SND_DEVICE_OUT_HDMI)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530994 strlcat(mixer_path, " hdmi", MIXER_PATH_MAX_LENGTH);
Naresh Tannirue3b18452014-03-04 14:44:27 +0530995 else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HDMI)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530996 strlcat(mixer_path, " speaker-and-hdmi", MIXER_PATH_MAX_LENGTH);
997 else if (snd_device == SND_DEVICE_OUT_AFE_PROXY)
998 strlcat(mixer_path, " afe-proxy", MIXER_PATH_MAX_LENGTH);
999 else if (snd_device == SND_DEVICE_OUT_USB_HEADSET)
1000 strlcat(mixer_path, " usb-headphones", MIXER_PATH_MAX_LENGTH);
1001 else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET)
1002 strlcat(mixer_path, " speaker-and-usb-headphones",
1003 MIXER_PATH_MAX_LENGTH);
1004 else if (snd_device == SND_DEVICE_IN_USB_HEADSET_MIC)
1005 strlcat(mixer_path, " usb-headset-mic", MIXER_PATH_MAX_LENGTH);
1006 else if (snd_device == SND_DEVICE_IN_CAPTURE_FM)
1007 strlcat(mixer_path, " capture-fm", MIXER_PATH_MAX_LENGTH);
1008 else if (snd_device == SND_DEVICE_OUT_TRANSMISSION_FM)
1009 strlcat(mixer_path, " transmission-fm", MIXER_PATH_MAX_LENGTH);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301010}
1011
1012int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
1013{
1014 int device_id;
1015 if (device_type == PCM_PLAYBACK)
1016 device_id = pcm_device_table[usecase][0];
1017 else
1018 device_id = pcm_device_table[usecase][1];
1019 return device_id;
1020}
1021
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301022int platform_get_snd_device_index(char *snd_device_index_name)
1023{
1024 int ret = 0;
1025 int i;
1026
1027 if (snd_device_index_name == NULL) {
1028 ALOGE("%s: snd_device_index_name is NULL", __func__);
1029 ret = -ENODEV;
1030 goto done;
1031 }
1032
1033 for (i=0; i < SND_DEVICE_MAX; i++) {
1034 if(strcmp(snd_device_name_index[i].name, snd_device_index_name) == 0) {
1035 ret = snd_device_name_index[i].index;
1036 goto done;
1037 }
1038 }
1039 ALOGE("%s: Could not find index for snd_device_index_name = %s",
1040 __func__, snd_device_index_name);
1041 ret = -ENODEV;
1042done:
1043 return ret;
1044}
1045
Venkata Narendra Kumar Gutta88fd0bc2014-03-27 19:47:56 +05301046int platform_set_fluence_type(void *platform, char *value)
1047{
1048 int ret = 0;
1049 int fluence_type = FLUENCE_NONE;
1050 int fluence_flag = NONE_FLAG;
1051 struct platform_data *my_data = (struct platform_data *)platform;
1052 struct audio_device *adev = my_data->adev;
1053
1054 ALOGV("%s: fluence type:%d", __func__, my_data->fluence_type);
1055
1056 /* only dual mic turn on and off is supported as of now through setparameters */
1057 if (!strncmp(AUDIO_PARAMETER_VALUE_DUALMIC,value, sizeof(AUDIO_PARAMETER_VALUE_DUALMIC))) {
1058 if (!strncmp("fluencepro", my_data->fluence_cap, sizeof("fluencepro")) ||
1059 !strncmp("fluence", my_data->fluence_cap, sizeof("fluence"))) {
1060 ALOGV("fluence dualmic feature enabled \n");
1061 fluence_type = FLUENCE_DUAL_MIC;
1062 fluence_flag = DMIC_FLAG;
1063 } else {
1064 ALOGE("%s: Failed to set DUALMIC", __func__);
1065 ret = -1;
1066 goto done;
1067 }
1068 } else if (!strncmp(AUDIO_PARAMETER_KEY_NO_FLUENCE, value, sizeof(AUDIO_PARAMETER_KEY_NO_FLUENCE))) {
1069 ALOGV("fluence disabled");
1070 fluence_type = FLUENCE_NONE;
1071 } else {
1072 ALOGE("Invalid fluence value : %s",value);
1073 ret = -1;
1074 goto done;
1075 }
1076
1077 if (fluence_type != my_data->fluence_type) {
1078 ALOGV("%s: Updating fluence_type to :%d", __func__, fluence_type);
1079 my_data->fluence_type = fluence_type;
1080 adev->acdb_settings = (adev->acdb_settings & FLUENCE_MODE_CLEAR) | fluence_flag;
1081 }
1082done:
1083 return ret;
1084}
1085
1086int platform_get_fluence_type(void *platform, char *value, uint32_t len)
1087{
1088 int ret = 0;
1089 struct platform_data *my_data = (struct platform_data *)platform;
1090
1091 if (my_data->fluence_type == FLUENCE_QUAD_MIC) {
1092 strlcpy(value, "quadmic", len);
1093 } else if (my_data->fluence_type == FLUENCE_DUAL_MIC) {
1094 strlcpy(value, "dualmic", len);
1095 } else if (my_data->fluence_type == FLUENCE_NONE) {
1096 strlcpy(value, "none", len);
1097 } else
1098 ret = -1;
1099
1100 return ret;
1101}
1102
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301103int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
1104{
1105 int ret = 0;
1106
1107 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1108 ALOGE("%s: Invalid snd_device = %d",
1109 __func__, snd_device);
1110 ret = -EINVAL;
1111 goto done;
1112 }
1113
1114 acdb_device_table[snd_device] = acdb_id;
1115done:
1116 return ret;
1117}
1118
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -07001119int platform_get_default_app_type(void *platform)
1120{
1121 struct platform_data *my_data = (struct platform_data *)platform;
1122
1123 if (my_data->acdb_get_default_app_type)
1124 return my_data->acdb_get_default_app_type();
1125 else
1126 return DEFAULT_APP_TYPE;
1127}
1128
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -07001129int platform_get_snd_device_acdb_id(snd_device_t snd_device)
1130{
1131 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1132 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1133 return -EINVAL;
1134 }
1135 return acdb_device_table[snd_device];
1136}
1137
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -07001138int platform_send_audio_calibration(void *platform, snd_device_t snd_device,
1139 int app_type, int sample_rate)
Naresh Tannirue3b18452014-03-04 14:44:27 +05301140{
1141 struct platform_data *my_data = (struct platform_data *)platform;
1142 int acdb_dev_id, acdb_dev_type;
1143
1144 acdb_dev_id = acdb_device_table[snd_device];
1145 if (acdb_dev_id < 0) {
1146 ALOGE("%s: Could not find acdb id for device(%d)",
1147 __func__, snd_device);
1148 return -EINVAL;
1149 }
1150 if (my_data->acdb_send_audio_cal) {
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -07001151 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Naresh Tannirue3b18452014-03-04 14:44:27 +05301152 __func__, snd_device, acdb_dev_id);
1153 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
1154 snd_device < SND_DEVICE_OUT_END)
1155 acdb_dev_type = ACDB_DEV_TYPE_OUT;
1156 else
1157 acdb_dev_type = ACDB_DEV_TYPE_IN;
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -07001158 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type, app_type,
1159 sample_rate);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301160 }
1161 return 0;
1162}
1163
1164int platform_switch_voice_call_device_pre(void *platform)
1165{
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301166 struct platform_data *my_data = (struct platform_data *)platform;
1167 int ret = 0;
1168
1169 if (my_data->csd != NULL &&
1170 my_data->adev->mode == AUDIO_MODE_IN_CALL) {
1171 /* This must be called before disabling mixer controls on APQ side */
1172 ret = my_data->csd->disable_device();
1173 if (ret < 0) {
1174 ALOGE("%s: csd_client_disable_device, failed, error %d",
1175 __func__, ret);
1176 }
1177 }
1178 return ret;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301179}
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301180int platform_switch_voice_call_enable_device_config(void *platform,
1181 snd_device_t out_snd_device,
1182 snd_device_t in_snd_device)
1183{
1184 struct platform_data *my_data = (struct platform_data *)platform;
1185 int acdb_rx_id, acdb_tx_id;
1186 int ret = 0;
1187
1188 acdb_rx_id = acdb_device_table[out_snd_device];
1189 acdb_tx_id = acdb_device_table[in_snd_device];
1190
1191 if (my_data->csd != NULL) {
1192 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
1193 ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
1194 if (ret < 0) {
1195 ALOGE("%s: csd_enable_device_config, failed, error %d",
1196 __func__, ret);
1197 }
1198 } else {
1199 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1200 acdb_rx_id, acdb_tx_id);
1201 }
1202 }
1203 return ret;
1204}
1205
Naresh Tannirue3b18452014-03-04 14:44:27 +05301206
1207int platform_switch_voice_call_device_post(void *platform,
1208 snd_device_t out_snd_device,
1209 snd_device_t in_snd_device)
1210{
1211 struct platform_data *my_data = (struct platform_data *)platform;
1212 int acdb_rx_id, acdb_tx_id;
1213
1214 if (my_data->acdb_send_voice_cal == NULL) {
1215 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
1216 } else {
1217 acdb_rx_id = acdb_device_table[out_snd_device];
1218 acdb_tx_id = acdb_device_table[in_snd_device];
1219
1220 if (acdb_rx_id > 0 && acdb_tx_id > 0)
1221 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
1222 else
1223 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1224 acdb_rx_id, acdb_tx_id);
1225 }
1226
1227 return 0;
1228}
1229
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301230int platform_switch_voice_call_usecase_route_post(void *platform,
1231 snd_device_t out_snd_device,
1232 snd_device_t in_snd_device)
Naresh Tannirue3b18452014-03-04 14:44:27 +05301233{
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301234 struct platform_data *my_data = (struct platform_data *)platform;
1235 int acdb_rx_id, acdb_tx_id;
1236 int ret = 0;
1237
1238 acdb_rx_id = acdb_device_table[out_snd_device];
1239 acdb_tx_id = acdb_device_table[in_snd_device];
1240
1241 if (my_data->csd != NULL) {
1242 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
1243 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
1244 my_data->adev->acdb_settings);
1245 if (ret < 0) {
1246 ALOGE("%s: csd_enable_device, failed, error %d",
1247 __func__, ret);
1248 }
1249 } else {
1250 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1251 acdb_rx_id, acdb_tx_id);
1252 }
1253 }
1254 return ret;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301255}
1256
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301257int platform_start_voice_call(void *platform, uint32_t vsid)
1258{
1259 struct platform_data *my_data = (struct platform_data *)platform;
1260 int ret = 0;
1261
1262 if (my_data->csd != NULL) {
1263 ret = my_data->csd->start_voice(vsid);
1264 if (ret < 0) {
1265 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
1266 }
1267 }
1268 return ret;
1269}
1270
1271int platform_stop_voice_call(void *platform, uint32_t vsid)
1272{
1273 struct platform_data *my_data = (struct platform_data *)platform;
1274 int ret = 0;
1275
1276 if (my_data->csd != NULL) {
1277 ret = my_data->csd->stop_voice(vsid);
1278 if (ret < 0) {
1279 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
1280 }
1281 }
1282 return ret;
1283}
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07001284
1285int platform_get_sample_rate(void *platform __unused, uint32_t *rate __unused)
Naresh Tannirue3b18452014-03-04 14:44:27 +05301286{
1287 return 0;
1288}
1289
1290int platform_set_voice_volume(void *platform, int volume)
1291{
1292 struct platform_data *my_data = (struct platform_data *)platform;
1293 struct audio_device *adev = my_data->adev;
1294 struct mixer_ctl *ctl;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301295 const char *mixer_ctl_name = "Voice Rx Gain";
1296 int vol_index = 0, ret = 0;
1297 uint32_t set_values[ ] = {0,
1298 ALL_SESSION_VSID,
1299 DEFAULT_VOLUME_RAMP_DURATION_MS};
Naresh Tannirue3b18452014-03-04 14:44:27 +05301300
1301 // Voice volume levels are mapped to adsp volume levels as follows.
1302 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
1303 // But this values don't changed in kernel. So, below change is need.
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301304 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, MAX_VOL_INDEX);
1305 set_values[0] = vol_index;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301306
1307 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1308 if (!ctl) {
1309 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1310 __func__, mixer_ctl_name);
1311 return -EINVAL;
1312 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301313 ALOGV("Setting voice volume index: %d", set_values[0]);
1314 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
Naresh Tannirue3b18452014-03-04 14:44:27 +05301315
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301316 if (my_data->csd != NULL) {
1317 ret = my_data->csd->volume(ALL_SESSION_VSID, volume);
1318 if (ret < 0) {
1319 ALOGE("%s: csd_volume error %d", __func__, ret);
1320 }
1321 }
1322 return ret;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301323}
1324
1325int platform_set_mic_mute(void *platform, bool state)
1326{
1327 struct platform_data *my_data = (struct platform_data *)platform;
1328 struct audio_device *adev = my_data->adev;
1329 struct mixer_ctl *ctl;
1330 const char *mixer_ctl_name = "Voice Tx Mute";
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301331 int ret = 0;
1332 uint32_t set_values[ ] = {0,
1333 ALL_SESSION_VSID,
1334 DEFAULT_VOLUME_RAMP_DURATION_MS};
Naresh Tannirue3b18452014-03-04 14:44:27 +05301335
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301336 set_values[0] = state;
1337 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1338 if (!ctl) {
1339 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1340 __func__, mixer_ctl_name);
1341 return -EINVAL;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301342 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301343 ALOGV("Setting voice mute state: %d", state);
1344 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
Naresh Tannirue3b18452014-03-04 14:44:27 +05301345
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301346 if (my_data->csd != NULL) {
1347 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state);
1348 if (ret < 0) {
1349 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
1350 }
1351 }
1352 return ret;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301353}
1354
Shiv Maliyappanahallic6fd8ee2014-03-07 15:31:55 -08001355int platform_set_device_mute(void *platform, bool state, char *dir)
1356{
1357 struct platform_data *my_data = (struct platform_data *)platform;
1358 struct audio_device *adev = my_data->adev;
1359 struct mixer_ctl *ctl;
1360 char *mixer_ctl_name = NULL;
1361 int ret = 0;
1362 uint32_t set_values[ ] = {0,
1363 ALL_SESSION_VSID,
1364 0};
1365 if(dir == NULL) {
1366 ALOGE("%s: Invalid direction:%s", __func__, dir);
1367 return -EINVAL;
1368 }
1369
1370 if (!strncmp("rx", dir, sizeof("rx"))) {
1371 mixer_ctl_name = "Voice Rx Device Mute";
1372 } else if (!strncmp("tx", dir, sizeof("tx"))) {
1373 mixer_ctl_name = "Voice Tx Device Mute";
1374 } else {
1375 return -EINVAL;
1376 }
1377
1378 set_values[0] = state;
1379 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1380 if (!ctl) {
1381 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1382 __func__, mixer_ctl_name);
1383 return -EINVAL;
1384 }
1385
1386 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
1387 __func__,state, mixer_ctl_name);
1388 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1389
1390 return ret;
1391}
1392
Naresh Tannirue3b18452014-03-04 14:44:27 +05301393snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
1394{
1395 struct platform_data *my_data = (struct platform_data *)platform;
1396 struct audio_device *adev = my_data->adev;
1397 audio_mode_t mode = adev->mode;
1398 snd_device_t snd_device = SND_DEVICE_NONE;
1399
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301400 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
1401 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
1402 int channel_count = popcount(channel_mask);
1403
Naresh Tannirue3b18452014-03-04 14:44:27 +05301404 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
1405 if (devices == AUDIO_DEVICE_NONE ||
1406 devices & AUDIO_DEVICE_BIT_IN) {
1407 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
1408 goto exit;
1409 }
1410
Naresh Tannirue3b18452014-03-04 14:44:27 +05301411 if (popcount(devices) == 2) {
1412 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
1413 AUDIO_DEVICE_OUT_SPEAKER)) {
1414 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
1415 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
1416 AUDIO_DEVICE_OUT_SPEAKER)) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301417 if (audio_extn_get_anc_enabled())
1418 snd_device = SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET;
1419 else
1420 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301421 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
1422 AUDIO_DEVICE_OUT_SPEAKER)) {
1423 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301424 } else if (devices == (AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET |
1425 AUDIO_DEVICE_OUT_SPEAKER)) {
1426 snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301427 } else {
1428 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
1429 goto exit;
1430 }
1431 if (snd_device != SND_DEVICE_NONE) {
1432 goto exit;
1433 }
1434 }
1435
1436 if (popcount(devices) != 1) {
1437 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
1438 goto exit;
1439 }
1440
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301441 if ((mode == AUDIO_MODE_IN_CALL) ||
1442 voice_extn_compress_voip_is_active(adev)) {
1443 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1444 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
1445 if ((adev->voice.tty_mode != TTY_MODE_OFF) &&
1446 !voice_extn_compress_voip_is_active(adev)) {
1447 switch (adev->voice.tty_mode) {
1448 case TTY_MODE_FULL:
1449 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
1450 break;
1451 case TTY_MODE_VCO:
1452 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
1453 break;
1454 case TTY_MODE_HCO:
1455 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
1456 break;
1457 default:
1458 ALOGE("%s: Invalid TTY mode (%#x)",
1459 __func__, adev->voice.tty_mode);
1460 }
1461 } else if (audio_extn_get_anc_enabled()) {
1462 if (audio_extn_should_use_fb_anc())
1463 snd_device = SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET;
1464 else
1465 snd_device = SND_DEVICE_OUT_VOICE_ANC_HEADSET;
1466 } else {
1467 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
1468 }
1469 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Mingming Yin514a8bc2014-07-29 15:22:21 -07001470 if (adev->bt_wb_speech_enabled)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301471 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
1472 else
1473 snd_device = SND_DEVICE_OUT_BT_SCO;
1474 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
1475 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
1476 } else if (devices & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
1477 devices & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
1478 snd_device = SND_DEVICE_OUT_USB_HEADSET;
1479 } else if (devices & AUDIO_DEVICE_OUT_FM_TX) {
1480 snd_device = SND_DEVICE_OUT_TRANSMISSION_FM;
1481 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
1482 if (audio_extn_should_use_handset_anc(channel_count))
1483 snd_device = SND_DEVICE_OUT_ANC_HANDSET;
1484 else
1485 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
1486 }
1487 if (snd_device != SND_DEVICE_NONE) {
1488 goto exit;
1489 }
1490 }
1491
Naresh Tannirue3b18452014-03-04 14:44:27 +05301492 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1493 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301494 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADSET
1495 && audio_extn_get_anc_enabled()) {
1496 if (audio_extn_should_use_fb_anc())
1497 snd_device = SND_DEVICE_OUT_ANC_FB_HEADSET;
1498 else
1499 snd_device = SND_DEVICE_OUT_ANC_HEADSET;
1500 }
1501 else
1502 snd_device = SND_DEVICE_OUT_HEADPHONES;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301503 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
1504 if (adev->speaker_lr_swap)
1505 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
1506 else
1507 snd_device = SND_DEVICE_OUT_SPEAKER;
1508 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Mingming Yin514a8bc2014-07-29 15:22:21 -07001509 if (adev->bt_wb_speech_enabled)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301510 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
1511 else
1512 snd_device = SND_DEVICE_OUT_BT_SCO;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301513 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
1514 snd_device = SND_DEVICE_OUT_HDMI ;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301515 } else if (devices & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
1516 devices & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
Mingming Yin5a7c5d62014-03-05 17:45:03 -08001517 ALOGD("%s: setting USB hadset channel capability(2) for Proxy", __func__);
1518 audio_extn_set_afe_proxy_channel_mixer(adev, 2);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301519 snd_device = SND_DEVICE_OUT_USB_HEADSET;
1520 } else if (devices & AUDIO_DEVICE_OUT_FM_TX) {
1521 snd_device = SND_DEVICE_OUT_TRANSMISSION_FM;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301522 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
1523 snd_device = SND_DEVICE_OUT_HANDSET;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301524 } else if (devices & AUDIO_DEVICE_OUT_PROXY) {
Mingming Yin5a7c5d62014-03-05 17:45:03 -08001525 channel_count = audio_extn_get_afe_proxy_channel_count();
1526 ALOGD("%s: setting sink capability(%d) for Proxy", __func__, channel_count);
1527 audio_extn_set_afe_proxy_channel_mixer(adev, channel_count);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301528 snd_device = SND_DEVICE_OUT_AFE_PROXY;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301529 } else {
1530 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
1531 }
1532exit:
1533 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
1534 return snd_device;
1535}
1536
1537snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
1538{
1539 struct platform_data *my_data = (struct platform_data *)platform;
1540 struct audio_device *adev = my_data->adev;
1541 audio_source_t source = (adev->active_input == NULL) ?
1542 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
1543
1544 audio_mode_t mode = adev->mode;
1545 audio_devices_t in_device = ((adev->active_input == NULL) ?
1546 AUDIO_DEVICE_NONE : adev->active_input->device)
1547 & ~AUDIO_DEVICE_BIT_IN;
1548 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
1549 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
1550 snd_device_t snd_device = SND_DEVICE_NONE;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301551 int channel_count = popcount(channel_mask);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301552
1553 ALOGV("%s: enter: out_device(%#x) in_device(%#x)",
1554 __func__, out_device, in_device);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301555 if ((out_device != AUDIO_DEVICE_NONE) && ((mode == AUDIO_MODE_IN_CALL) ||
Satya Krishna Pindiproli2aaa6152014-05-21 15:05:22 +05301556 voice_extn_compress_voip_is_active(adev) || audio_extn_hfp_is_active(adev))) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301557 if ((adev->voice.tty_mode != TTY_MODE_OFF) &&
1558 !voice_extn_compress_voip_is_active(adev)) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301559 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1560 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301561 switch (adev->voice.tty_mode) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301562 case TTY_MODE_FULL:
1563 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
1564 break;
1565 case TTY_MODE_VCO:
1566 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
1567 break;
1568 case TTY_MODE_HCO:
1569 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
1570 break;
1571 default:
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301572 ALOGE("%s: Invalid TTY mode (%#x)",
1573 __func__, adev->voice.tty_mode);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301574 }
1575 goto exit;
1576 }
1577 }
1578 if (out_device & AUDIO_DEVICE_OUT_EARPIECE ||
1579 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301580 if (out_device & AUDIO_DEVICE_OUT_EARPIECE &&
1581 audio_extn_should_use_handset_anc(channel_count)) {
1582 snd_device = SND_DEVICE_IN_AANC_HANDSET_MIC;
1583 } else if (my_data->fluence_type == FLUENCE_NONE ||
1584 my_data->fluence_in_voice_call == false) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301585 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +05301586 if (audio_extn_hfp_is_active(adev))
1587 platform_set_echo_reference(adev->platform, true);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301588 } else {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301589 snd_device = SND_DEVICE_IN_VOICE_DMIC;
1590 adev->acdb_settings |= DMIC_FLAG;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301591 }
1592 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
1593 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +05301594 if (audio_extn_hfp_is_active(adev))
1595 platform_set_echo_reference(adev->platform, true);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301596 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Vicky Sehrawate240e5d2014-08-12 17:17:04 -07001597 if (adev->bt_wb_speech_enabled) {
1598 if (adev->bluetooth_nrec)
1599 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
1600 else
1601 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
1602 } else {
1603 if (adev->bluetooth_nrec)
1604 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
1605 else
1606 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
1607 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05301608 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301609 if (my_data->fluence_type != FLUENCE_NONE &&
1610 my_data->fluence_in_voice_call &&
1611 my_data->fluence_in_spkr_mode) {
1612 if(my_data->fluence_type & FLUENCE_QUAD_MIC) {
1613 adev->acdb_settings |= QMIC_FLAG;
1614 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_QMIC;
1615 } else {
1616 adev->acdb_settings |= DMIC_FLAG;
Karthik Reddy Kattad9fff862014-07-21 21:07:21 +05301617 if (my_data->fluence_mode == FLUENCE_BROADSIDE)
1618 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BROADSIDE;
1619 else
1620 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301621 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05301622 } else {
1623 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +05301624 if (audio_extn_hfp_is_active(adev))
1625 platform_set_echo_reference(adev->platform, true);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301626 }
1627 }
1628 } else if (source == AUDIO_SOURCE_CAMCORDER) {
1629 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
1630 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
kunleiz18a33302014-05-30 09:52:25 +08001631 if (my_data->fluence_type & FLUENCE_DUAL_MIC &&
1632 channel_count == 2)
kunleiz8f7e9e22014-06-24 15:12:02 +08001633 snd_device = SND_DEVICE_IN_HANDSET_STEREO_DMIC;
kunleiz18a33302014-05-30 09:52:25 +08001634 else
1635 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301636 }
1637 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
1638 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301639 if (channel_count == 2) {
1640 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
1641 adev->acdb_settings |= DMIC_FLAG;
1642 } else if (adev->active_input->enable_ns)
1643 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
1644 else if (my_data->fluence_type != FLUENCE_NONE &&
1645 my_data->fluence_in_voice_rec) {
1646 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
1647 adev->acdb_settings |= DMIC_FLAG;
1648 } else {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301649 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
1650 }
1651 }
1652 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION) {
1653 if (out_device & AUDIO_DEVICE_OUT_SPEAKER)
1654 in_device = AUDIO_DEVICE_IN_BACK_MIC;
1655 if (adev->active_input) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301656 if (adev->active_input->enable_aec &&
1657 adev->active_input->enable_ns) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301658 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301659 if (my_data->fluence_type & FLUENCE_DUAL_MIC &&
1660 my_data->fluence_in_spkr_mode) {
Karthik Reddy Kattad9fff862014-07-21 21:07:21 +05301661 if (my_data->fluence_mode == FLUENCE_BROADSIDE)
1662 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_BROADSIDE;
1663 else
1664 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301665 adev->acdb_settings |= DMIC_FLAG;
1666 } else
1667 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301668 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301669 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1670 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
1671 adev->acdb_settings |= DMIC_FLAG;
1672 } else
1673 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301674 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301675 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301676 }
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +05301677 platform_set_echo_reference(adev->platform, true);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301678 } else if (adev->active_input->enable_aec) {
1679 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Karthik Reddy Kattad9fff862014-07-21 21:07:21 +05301680 if (my_data->fluence_type & FLUENCE_DUAL_MIC &&
1681 my_data->fluence_in_spkr_mode) {
1682 if (my_data->fluence_mode == FLUENCE_BROADSIDE)
1683 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_BROADSIDE;
1684 else
1685 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301686 adev->acdb_settings |= DMIC_FLAG;
1687 } else
1688 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
1689 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
1690 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1691 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
1692 adev->acdb_settings |= DMIC_FLAG;
1693 } else
1694 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
1695 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
1696 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
1697 }
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +05301698 platform_set_echo_reference(adev->platform, true);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301699 } else if (adev->active_input->enable_ns) {
1700 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Karthik Reddy Kattad9fff862014-07-21 21:07:21 +05301701 if (my_data->fluence_type & FLUENCE_DUAL_MIC &&
1702 my_data->fluence_in_spkr_mode) {
1703 if (my_data->fluence_mode == FLUENCE_BROADSIDE)
1704 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS_BROADSIDE;
1705 else
1706 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301707 adev->acdb_settings |= DMIC_FLAG;
1708 } else
1709 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
1710 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
1711 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1712 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
1713 adev->acdb_settings |= DMIC_FLAG;
1714 } else
1715 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
1716 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
1717 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
1718 }
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +05301719 platform_set_echo_reference(adev->platform,false);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301720 } else
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +05301721 platform_set_echo_reference(adev->platform, false);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301722 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301723 } else if (source == AUDIO_SOURCE_MIC) {
1724 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC &&
1725 channel_count == 1 ) {
1726 if(my_data->fluence_type & FLUENCE_DUAL_MIC &&
1727 my_data->fluence_in_audio_rec)
1728 snd_device = SND_DEVICE_IN_HANDSET_DMIC;
1729 }
1730 } else if (source == AUDIO_SOURCE_FM_RX ||
1731 source == AUDIO_SOURCE_FM_RX_A2DP) {
1732 snd_device = SND_DEVICE_IN_CAPTURE_FM;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301733 } else if (source == AUDIO_SOURCE_DEFAULT) {
1734 goto exit;
1735 }
1736
1737
1738 if (snd_device != SND_DEVICE_NONE) {
1739 goto exit;
1740 }
1741
1742 if (in_device != AUDIO_DEVICE_NONE &&
1743 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
1744 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
1745 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301746 if (audio_extn_ssr_get_enabled() && channel_count == 6)
1747 snd_device = SND_DEVICE_IN_QUAD_MIC;
1748 else if (channel_count == 2)
1749 snd_device = SND_DEVICE_IN_HANDSET_STEREO_DMIC;
1750 else
1751 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301752 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
1753 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
1754 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
1755 snd_device = SND_DEVICE_IN_HEADSET_MIC;
1756 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Vicky Sehrawate240e5d2014-08-12 17:17:04 -07001757 if (adev->bt_wb_speech_enabled) {
1758 if (adev->bluetooth_nrec)
1759 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
1760 else
1761 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
1762 } else {
1763 if (adev->bluetooth_nrec)
1764 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
1765 else
1766 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
1767 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05301768 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
1769 snd_device = SND_DEVICE_IN_HDMI_MIC;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301770 } else if (in_device & AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET ||
1771 in_device & AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET) {
1772 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
1773 } else if (in_device & AUDIO_DEVICE_IN_FM_RX) {
1774 snd_device = SND_DEVICE_IN_CAPTURE_FM;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301775 } else {
1776 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
1777 ALOGW("%s: Using default handset-mic", __func__);
1778 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1779 }
1780 } else {
1781 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
1782 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1783 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
1784 snd_device = SND_DEVICE_IN_HEADSET_MIC;
1785 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301786 if (channel_count > 1)
1787 snd_device = SND_DEVICE_IN_SPEAKER_STEREO_DMIC;
1788 else
1789 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301790 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
1791 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1792 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Vicky Sehrawate240e5d2014-08-12 17:17:04 -07001793 if (adev->bt_wb_speech_enabled) {
1794 if (adev->bluetooth_nrec)
1795 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
1796 else
1797 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
1798 } else {
1799 if (adev->bluetooth_nrec)
1800 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
1801 else
1802 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
1803 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05301804 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
1805 snd_device = SND_DEVICE_IN_HDMI_MIC;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301806 } else if (out_device & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
1807 out_device & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
1808 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301809 } else {
1810 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
1811 ALOGW("%s: Using default handset-mic", __func__);
1812 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1813 }
1814 }
1815exit:
1816 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
1817 return snd_device;
1818}
1819
1820int platform_set_hdmi_channels(void *platform, int channel_count)
1821{
1822 struct platform_data *my_data = (struct platform_data *)platform;
1823 struct audio_device *adev = my_data->adev;
1824 struct mixer_ctl *ctl;
1825 const char *channel_cnt_str = NULL;
1826 const char *mixer_ctl_name = "HDMI_RX Channels";
1827 switch (channel_count) {
1828 case 8:
1829 channel_cnt_str = "Eight"; break;
1830 case 7:
1831 channel_cnt_str = "Seven"; break;
1832 case 6:
1833 channel_cnt_str = "Six"; break;
1834 case 5:
1835 channel_cnt_str = "Five"; break;
1836 case 4:
1837 channel_cnt_str = "Four"; break;
1838 case 3:
1839 channel_cnt_str = "Three"; break;
1840 default:
1841 channel_cnt_str = "Two"; break;
1842 }
1843 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1844 if (!ctl) {
1845 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1846 __func__, mixer_ctl_name);
1847 return -EINVAL;
1848 }
1849 ALOGV("HDMI channel count: %s", channel_cnt_str);
1850 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
1851 return 0;
1852}
1853
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301854int platform_edid_get_max_channels(void *platform)
Naresh Tannirue3b18452014-03-04 14:44:27 +05301855{
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301856 struct platform_data *my_data = (struct platform_data *)platform;
1857 struct audio_device *adev = my_data->adev;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301858 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
1859 char *sad = block;
1860 int num_audio_blocks;
1861 int channel_count;
1862 int max_channels = 0;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301863 int i, ret, count;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301864
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301865 struct mixer_ctl *ctl;
1866
1867 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
1868 if (!ctl) {
1869 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1870 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301871 return 0;
1872 }
1873
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301874 mixer_ctl_update(ctl);
1875
1876 count = mixer_ctl_get_num_values(ctl);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301877
1878 /* Read SAD blocks, clamping the maximum size for safety */
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301879 if (count > (int)sizeof(block))
1880 count = (int)sizeof(block);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301881
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301882 ret = mixer_ctl_get_array(ctl, block, count);
1883 if (ret != 0) {
1884 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
1885 return 0;
1886 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05301887
1888 /* Calculate the number of SAD blocks */
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301889 num_audio_blocks = count / SAD_BLOCK_SIZE;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301890
1891 for (i = 0; i < num_audio_blocks; i++) {
1892 /* Only consider LPCM blocks */
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301893 if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
1894 sad += 3;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301895 continue;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301896 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05301897
1898 channel_count = (sad[0] & 0x7) + 1;
1899 if (channel_count > max_channels)
1900 max_channels = channel_count;
1901
1902 /* Advance to next block */
1903 sad += 3;
1904 }
1905
1906 return max_channels;
1907}
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301908
1909static int platform_set_slowtalk(struct platform_data *my_data, bool state)
1910{
1911 int ret = 0;
1912 struct audio_device *adev = my_data->adev;
1913 struct mixer_ctl *ctl;
1914 const char *mixer_ctl_name = "Slowtalk Enable";
1915 uint32_t set_values[ ] = {0,
1916 ALL_SESSION_VSID};
1917
1918 set_values[0] = state;
1919 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1920 if (!ctl) {
1921 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1922 __func__, mixer_ctl_name);
1923 ret = -EINVAL;
1924 } else {
1925 ALOGV("Setting slowtalk state: %d", state);
1926 ret = mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1927 my_data->slowtalk = state;
1928 }
1929
1930 if (my_data->csd != NULL) {
1931 ret = my_data->csd->slow_talk(ALL_SESSION_VSID, state);
1932 if (ret < 0) {
1933 ALOGE("%s: csd_client_disable_device, failed, error %d",
1934 __func__, ret);
1935 }
1936 }
1937 return ret;
1938}
1939
Avinash Vaishd5fa4572014-09-15 14:41:14 +05301940static int set_hd_voice(struct platform_data *my_data, bool state)
1941{
1942 struct audio_device *adev = my_data->adev;
1943 struct mixer_ctl *ctl;
1944 const char *mixer_ctl_name = "HD Voice Enable";
1945 int ret = 0;
1946 uint32_t set_values[ ] = {0,
1947 ALL_SESSION_VSID};
1948
1949 set_values[0] = state;
1950 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1951 if (!ctl) {
1952 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1953 __func__, mixer_ctl_name);
1954 ret = -EINVAL;
1955 } else {
1956 ALOGV("Setting HD Voice state: %d", state);
1957 ret = mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1958 my_data->hd_voice = state;
1959 }
1960
1961 return ret;
1962}
1963
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301964int platform_set_parameters(void *platform, struct str_parms *parms)
1965{
1966 struct platform_data *my_data = (struct platform_data *)platform;
1967 char *str;
1968 char value[256] = {0};
1969 int val;
1970 int ret = 0, err;
Karthik Reddy Kattabfe193d2014-08-14 17:58:18 +05301971 char *kv_pairs = NULL;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301972
Karthik Reddy Kattabfe193d2014-08-14 17:58:18 +05301973 kv_pairs = str_parms_to_str(parms);
1974 ALOGV("%s: enter: - %s", __func__, kv_pairs);
1975 free(kv_pairs);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301976
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301977 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_SLOWTALK, value, sizeof(value));
1978 if (err >= 0) {
1979 bool state = false;
1980 if (!strncmp("true", value, sizeof("true"))) {
1981 state = true;
1982 }
1983
1984 str_parms_del(parms, AUDIO_PARAMETER_KEY_SLOWTALK);
1985 ret = platform_set_slowtalk(my_data, state);
1986 if (ret)
1987 ALOGE("%s: Failed to set slow talk err: %d", __func__, ret);
1988 }
1989
Avinash Vaishd5fa4572014-09-15 14:41:14 +05301990 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_HD_VOICE, value, sizeof(value));
1991 if (err >= 0) {
1992 bool state = false;
1993 if (!strncmp("true", value, sizeof("true"))) {
1994 state = true;
1995 }
1996
1997 str_parms_del(parms, AUDIO_PARAMETER_KEY_HD_VOICE);
1998 if (my_data->hd_voice != state) {
1999 ret = set_hd_voice(my_data, state);
2000 if (ret)
2001 ALOGE("%s: Failed to set HD voice err: %d", __func__, ret);
2002 } else {
2003 ALOGV("%s: HD Voice already set to %d", __func__, state);
2004 }
2005 }
2006
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302007 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_VOLUME_BOOST,
2008 value, sizeof(value));
2009 if (err >= 0) {
2010 str_parms_del(parms, AUDIO_PARAMETER_KEY_VOLUME_BOOST);
2011
2012 if (my_data->acdb_reload_vocvoltable == NULL) {
2013 ALOGE("%s: acdb_reload_vocvoltable is NULL", __func__);
2014 } else if (!strcmp(value, "on")) {
2015 if (!my_data->acdb_reload_vocvoltable(VOICE_FEATURE_SET_VOLUME_BOOST)) {
2016 my_data->voice_feature_set = 1;
2017 }
2018 } else {
2019 if (!my_data->acdb_reload_vocvoltable(VOICE_FEATURE_SET_DEFAULT)) {
2020 my_data->voice_feature_set = 0;
2021 }
2022 }
2023 }
2024
2025 ALOGV("%s: exit with code(%d)", __func__, ret);
2026 return ret;
2027}
2028
2029int platform_set_incall_recording_session_id(void *platform,
2030 uint32_t session_id, int rec_mode)
2031{
2032 int ret = 0;
2033 struct platform_data *my_data = (struct platform_data *)platform;
2034 struct audio_device *adev = my_data->adev;
2035 struct mixer_ctl *ctl;
2036 const char *mixer_ctl_name = "Voc VSID";
2037 int num_ctl_values;
2038 int i;
2039
2040 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2041 if (!ctl) {
2042 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2043 __func__, mixer_ctl_name);
2044 ret = -EINVAL;
2045 } else {
2046 num_ctl_values = mixer_ctl_get_num_values(ctl);
2047 for (i = 0; i < num_ctl_values; i++) {
2048 if (mixer_ctl_set_value(ctl, i, session_id)) {
2049 ALOGV("Error: invalid session_id: %x", session_id);
2050 ret = -EINVAL;
2051 break;
2052 }
2053 }
2054 }
2055
2056 if (my_data->csd != NULL) {
2057 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
2058 if (ret < 0) {
2059 ALOGE("%s: csd_client_start_record failed, error %d",
2060 __func__, ret);
2061 }
2062 }
2063
2064 return ret;
2065}
2066
2067int platform_stop_incall_recording_usecase(void *platform)
2068{
2069 int ret = 0;
2070 struct platform_data *my_data = (struct platform_data *)platform;
2071
2072 if (my_data->csd != NULL) {
2073 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
2074 if (ret < 0) {
2075 ALOGE("%s: csd_client_stop_record failed, error %d",
2076 __func__, ret);
2077 }
2078 }
2079
2080 return ret;
2081}
2082
2083int platform_start_incall_music_usecase(void *platform)
2084{
2085 int ret = 0;
2086 struct platform_data *my_data = (struct platform_data *)platform;
2087
2088 if (my_data->csd != NULL) {
2089 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
2090 if (ret < 0) {
2091 ALOGE("%s: csd_client_start_playback failed, error %d",
2092 __func__, ret);
2093 }
2094 }
2095
2096 return ret;
2097}
2098
2099int platform_stop_incall_music_usecase(void *platform)
2100{
2101 int ret = 0;
2102 struct platform_data *my_data = (struct platform_data *)platform;
2103
2104 if (my_data->csd != NULL) {
2105 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
2106 if (ret < 0) {
2107 ALOGE("%s: csd_client_stop_playback failed, error %d",
2108 __func__, ret);
2109 }
2110 }
2111
2112 return ret;
2113}
2114
Vidyakumar Athota21b3bb92014-04-25 11:08:08 -07002115int platform_update_lch(void *platform, struct voice_session *session,
2116 enum voice_lch_mode lch_mode)
2117{
2118 int ret = 0;
2119 struct platform_data *my_data = (struct platform_data *)platform;
2120
2121 if ((my_data->csd != NULL) && (my_data->csd->set_lch != NULL))
2122 ret = my_data->csd->set_lch(session->vsid, lch_mode);
2123 else
2124 ret = pcm_ioctl(session->pcm_tx, SNDRV_VOICE_IOCTL_LCH, &lch_mode);
2125
2126 return ret;
2127}
2128
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302129void platform_get_parameters(void *platform,
2130 struct str_parms *query,
2131 struct str_parms *reply)
2132{
2133 struct platform_data *my_data = (struct platform_data *)platform;
2134 char *str = NULL;
2135 char value[256] = {0};
2136 int ret;
Karthik Reddy Kattabfe193d2014-08-14 17:58:18 +05302137 char *kv_pairs = NULL;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302138
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302139 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_SLOWTALK,
2140 value, sizeof(value));
2141 if (ret >= 0) {
2142 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_SLOWTALK,
2143 my_data->slowtalk?"true":"false");
2144 }
2145
Avinash Vaishd5fa4572014-09-15 14:41:14 +05302146 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_HD_VOICE,
2147 value, sizeof(value));
2148 if (ret >= 0) {
2149 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_HD_VOICE,
2150 my_data->hd_voice?"true":"false");
2151 }
2152
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302153 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_VOLUME_BOOST,
2154 value, sizeof(value));
2155 if (ret >= 0) {
2156 if (my_data->voice_feature_set == VOICE_FEATURE_SET_VOLUME_BOOST) {
2157 strlcpy(value, "on", sizeof(value));
2158 } else {
2159 strlcpy(value, "off", sizeof(value));
2160 }
2161
2162 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_VOLUME_BOOST, value);
2163 }
2164
Karthik Reddy Kattabfe193d2014-08-14 17:58:18 +05302165 kv_pairs = str_parms_to_str(reply);
2166 ALOGV("%s: exit: returns - %s", __func__, kv_pairs);
2167 free(kv_pairs);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302168}
2169
2170/* Delay in Us */
2171int64_t platform_render_latency(audio_usecase_t usecase)
2172{
2173 switch (usecase) {
2174 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
2175 return DEEP_BUFFER_PLATFORM_DELAY;
2176 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
2177 return LOW_LATENCY_PLATFORM_DELAY;
2178 default:
2179 return 0;
2180 }
2181}
2182
2183int platform_update_usecase_from_source(int source, int usecase)
2184{
2185 ALOGV("%s: input source :%d", __func__, source);
2186 if(source == AUDIO_SOURCE_FM_RX_A2DP)
2187 usecase = USECASE_AUDIO_RECORD_FM_VIRTUAL;
2188 return usecase;
2189}
2190
Dhananjay Kumar45b71742014-05-29 21:47:27 +05302191bool platform_listen_device_needs_event(snd_device_t snd_device)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302192{
Dhananjay Kumar45b71742014-05-29 21:47:27 +05302193 bool needs_event = false;
2194
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302195 if ((snd_device >= SND_DEVICE_IN_BEGIN) &&
2196 (snd_device < SND_DEVICE_IN_END) &&
2197 (snd_device != SND_DEVICE_IN_CAPTURE_FM) &&
2198 (snd_device != SND_DEVICE_IN_CAPTURE_VI_FEEDBACK))
Dhananjay Kumar45b71742014-05-29 21:47:27 +05302199 needs_event = true;
2200
2201 return needs_event;
2202}
2203
2204bool platform_listen_usecase_needs_event(audio_usecase_t uc_id)
2205{
2206 bool needs_event = false;
2207
2208 switch(uc_id){
2209 /* concurrent playback usecases needs event */
2210 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
2211 case USECASE_AUDIO_PLAYBACK_MULTI_CH:
2212 case USECASE_AUDIO_PLAYBACK_OFFLOAD:
2213 needs_event = true;
2214 break;
2215 /* concurrent playback in low latency allowed */
2216 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
2217 break;
2218 /* concurrent playback FM needs event */
2219 case USECASE_AUDIO_PLAYBACK_FM:
2220 needs_event = true;
2221 break;
2222
2223 /* concurrent capture usecases, no event, capture handled by device
2224 * USECASE_AUDIO_RECORD:
2225 * USECASE_AUDIO_RECORD_COMPRESS:
2226 * USECASE_AUDIO_RECORD_LOW_LATENCY:
2227
2228 * USECASE_VOICE_CALL:
2229 * USECASE_VOICE2_CALL:
2230 * USECASE_VOLTE_CALL:
2231 * USECASE_QCHAT_CALL:
2232 * USECASE_VOWLAN_CALL:
2233 * USECASE_COMPRESS_VOIP_CALL:
2234 * USECASE_AUDIO_RECORD_FM_VIRTUAL:
2235 * USECASE_INCALL_REC_UPLINK:
2236 * USECASE_INCALL_REC_DOWNLINK:
2237 * USECASE_INCALL_REC_UPLINK_AND_DOWNLINK:
2238 * USECASE_INCALL_REC_UPLINK_COMPRESS:
2239 * USECASE_INCALL_REC_DOWNLINK_COMPRESS:
2240 * USECASE_INCALL_REC_UPLINK_AND_DOWNLINK_COMPRESS:
2241 * USECASE_INCALL_MUSIC_UPLINK:
2242 * USECASE_INCALL_MUSIC_UPLINK2:
2243 * USECASE_AUDIO_SPKR_CALIB_RX:
2244 * USECASE_AUDIO_SPKR_CALIB_TX:
2245 */
2246 default:
2247 ALOGV("%s:usecase_id[%d} no need to raise event.", __func__, uc_id);
2248 }
2249 return needs_event;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302250}
2251
Ravi Kumar Alamanda8fa6b192014-09-09 16:06:42 -07002252bool platform_sound_trigger_device_needs_event(snd_device_t snd_device)
2253{
2254 bool needs_event = false;
2255
2256 if ((snd_device >= SND_DEVICE_IN_BEGIN) &&
2257 (snd_device < SND_DEVICE_IN_END) &&
2258 (snd_device != SND_DEVICE_IN_CAPTURE_FM) &&
2259 (snd_device != SND_DEVICE_IN_CAPTURE_VI_FEEDBACK))
2260 needs_event = true;
2261
2262 return needs_event;
2263}
2264
2265bool platform_sound_trigger_usecase_needs_event(audio_usecase_t uc_id)
2266{
2267 bool needs_event = false;
2268
2269 switch(uc_id){
2270 /* concurrent playback usecases needs event */
2271 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
2272 case USECASE_AUDIO_PLAYBACK_MULTI_CH:
2273 case USECASE_AUDIO_PLAYBACK_OFFLOAD:
2274 needs_event = true;
2275 break;
2276 /* concurrent playback in low latency allowed */
2277 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
2278 break;
2279 /* concurrent playback FM needs event */
2280 case USECASE_AUDIO_PLAYBACK_FM:
2281 needs_event = true;
2282 break;
2283
2284 /* concurrent capture usecases, no event, capture handled by device
2285 * USECASE_AUDIO_RECORD:
2286 * USECASE_AUDIO_RECORD_COMPRESS:
2287 * USECASE_AUDIO_RECORD_LOW_LATENCY:
2288
2289 * USECASE_VOICE_CALL:
2290 * USECASE_VOICE2_CALL:
2291 * USECASE_VOLTE_CALL:
2292 * USECASE_QCHAT_CALL:
2293 * USECASE_VOWLAN_CALL:
2294 * USECASE_COMPRESS_VOIP_CALL:
2295 * USECASE_AUDIO_RECORD_FM_VIRTUAL:
2296 * USECASE_INCALL_REC_UPLINK:
2297 * USECASE_INCALL_REC_DOWNLINK:
2298 * USECASE_INCALL_REC_UPLINK_AND_DOWNLINK:
2299 * USECASE_INCALL_REC_UPLINK_COMPRESS:
2300 * USECASE_INCALL_REC_DOWNLINK_COMPRESS:
2301 * USECASE_INCALL_REC_UPLINK_AND_DOWNLINK_COMPRESS:
2302 * USECASE_INCALL_MUSIC_UPLINK:
2303 * USECASE_INCALL_MUSIC_UPLINK2:
2304 * USECASE_AUDIO_SPKR_CALIB_RX:
2305 * USECASE_AUDIO_SPKR_CALIB_TX:
2306 */
2307 default:
2308 ALOGV("%s:usecase_id[%d] no need to raise event.", __func__, uc_id);
2309 }
2310 return needs_event;
2311}
2312
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302313/* Read offload buffer size from a property.
2314 * If value is not power of 2 round it to
2315 * power of 2.
2316 */
2317uint32_t platform_get_compress_offload_buffer_size(audio_offload_info_t* info)
2318{
2319 char value[PROPERTY_VALUE_MAX] = {0};
2320 uint32_t fragment_size = COMPRESS_OFFLOAD_FRAGMENT_SIZE;
2321 if((property_get("audio.offload.buffer.size.kb", value, "")) &&
2322 atoi(value)) {
2323 fragment_size = atoi(value) * 1024;
2324 }
2325
2326 if (info != NULL && info->has_video && info->is_streaming) {
2327 fragment_size = COMPRESS_OFFLOAD_FRAGMENT_SIZE_FOR_AV_STREAMING;
2328 ALOGV("%s: offload fragment size reduced for AV streaming to %d",
Apoorv Raghuvanshi44bd9172014-05-28 14:50:07 -07002329 __func__, fragment_size);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302330 }
2331
2332 fragment_size = ALIGN( fragment_size, 1024);
2333
2334 if(fragment_size < MIN_COMPRESS_OFFLOAD_FRAGMENT_SIZE)
2335 fragment_size = MIN_COMPRESS_OFFLOAD_FRAGMENT_SIZE;
2336 else if(fragment_size > MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE)
2337 fragment_size = MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE;
2338 ALOGV("%s: fragment_size %d", __func__, fragment_size);
2339 return fragment_size;
2340}
2341
2342uint32_t platform_get_pcm_offload_buffer_size(audio_offload_info_t* info)
2343{
2344 uint32_t fragment_size = MIN_PCM_OFFLOAD_FRAGMENT_SIZE;
2345 uint32_t bits_per_sample = 16;
2346
2347 if (info->format == AUDIO_FORMAT_PCM_24_BIT_OFFLOAD) {
2348 bits_per_sample = 32;
2349 }
2350
2351 if (!info->has_video) {
2352 fragment_size = MAX_PCM_OFFLOAD_FRAGMENT_SIZE;
2353
2354 } else if (info->has_video && info->is_streaming) {
2355 fragment_size = (PCM_OFFLOAD_BUFFER_DURATION_FOR_AV_STREAMING
2356 * info->sample_rate
2357 * bits_per_sample
2358 * popcount(info->channel_mask))/1000;
2359
2360 } else if (info->has_video) {
2361 fragment_size = (PCM_OFFLOAD_BUFFER_DURATION_FOR_AV
2362 * info->sample_rate
2363 * bits_per_sample
2364 * popcount(info->channel_mask))/1000;
2365 }
2366
2367 fragment_size = ALIGN( fragment_size, 1024);
2368
2369 if(fragment_size < MIN_PCM_OFFLOAD_FRAGMENT_SIZE)
2370 fragment_size = MIN_PCM_OFFLOAD_FRAGMENT_SIZE;
2371 else if(fragment_size > MAX_PCM_OFFLOAD_FRAGMENT_SIZE)
2372 fragment_size = MAX_PCM_OFFLOAD_FRAGMENT_SIZE;
2373
2374 ALOGV("%s: fragment_size %d", __func__, fragment_size);
2375 return fragment_size;
2376}
2377
Mingming Yin3ee55c62014-08-04 14:23:35 -07002378bool platform_check_24_bit_support() {
2379 return false;
2380}
2381
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07002382bool platform_check_and_set_codec_backend_cfg(struct audio_device* adev __unused,
2383 struct audio_usecase *usecase __unused)
2384{
Mingming Yin3ee55c62014-08-04 14:23:35 -07002385 return false;
2386}
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07002387
2388int platform_get_usecase_index(const char * usecase __unused)
2389{
2390 return -ENOSYS;
2391}
2392
2393int platform_set_usecase_pcm_id(audio_usecase_t usecase __unused, int32_t type __unused,
2394 int32_t pcm_id __unused)
2395{
2396 return -ENOSYS;
2397}
2398
2399int platform_set_snd_device_backend(snd_device_t snd_device __unused,
2400 const char * backend __unused)
2401{
2402 return -ENOSYS;
2403}
2404