blob: 9f9a0306a455b05b4fc54678d88d4d0e92fd2c38 [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>
26#include <cutils/log.h>
27#include <cutils/properties.h>
Naresh Tannirudb72d1e2014-03-05 17:33:47 +053028#include <cutils/str_parms.h>
Naresh Tannirue3b18452014-03-04 14:44:27 +053029#include <audio_hw.h>
30#include <platform_api.h>
31#include "platform.h"
Naresh Tannirudb72d1e2014-03-05 17:33:47 +053032#include "audio_extn.h"
33#include "voice_extn.h"
Naresh Tannirue3b18452014-03-04 14:44:27 +053034
Naresh Tannirudb72d1e2014-03-05 17:33:47 +053035#define MIXER_XML_PATH "/system/etc/mixer_paths.xml"
Asish Bhattacharya4ff24802014-04-24 17:46:54 +053036#define MIXER_XML_PATH_MTP "/system/etc/mixer_paths_mtp.xml"
Naresh Tannirudb72d1e2014-03-05 17:33:47 +053037#define MIXER_XML_PATH_AUXPCM "/system/etc/mixer_paths_auxpcm.xml"
38#define PLATFORM_INFO_XML_PATH "/system/etc/audio_platform_info.xml"
Naresh Tannirue3b18452014-03-04 14:44:27 +053039#define LIB_ACDB_LOADER "libacdbloader.so"
Naresh Tannirudb72d1e2014-03-05 17:33:47 +053040#define AUDIO_DATA_BLOCK_MIXER_CTL "HDMI EDID"
Naresh Tannirue3b18452014-03-04 14:44:27 +053041
Naresh Tannirudb72d1e2014-03-05 17:33:47 +053042#define MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE (256 * 1024)
43#define MIN_COMPRESS_OFFLOAD_FRAGMENT_SIZE (2 * 1024)
44#define COMPRESS_OFFLOAD_FRAGMENT_SIZE_FOR_AV_STREAMING (2 * 1024)
45#define COMPRESS_OFFLOAD_FRAGMENT_SIZE (32 * 1024)
46/* Used in calculating fragment size for pcm offload */
47#define PCM_OFFLOAD_BUFFER_DURATION_FOR_AV 2000 /* 2 secs */
48#define PCM_OFFLOAD_BUFFER_DURATION_FOR_AV_STREAMING 100 /* 100 millisecs */
Naresh Tannirue3b18452014-03-04 14:44:27 +053049
Naresh Tannirudb72d1e2014-03-05 17:33:47 +053050/* MAX PCM fragment size cannot be increased further due
51 * to flinger's cblk size of 1mb,and it has to be a multiple of
52 * 24 - lcm of channels supported by DSP
Naresh Tannirue3b18452014-03-04 14:44:27 +053053 */
Naresh Tannirudb72d1e2014-03-05 17:33:47 +053054#define MAX_PCM_OFFLOAD_FRAGMENT_SIZE (240 * 1024)
55#define MIN_PCM_OFFLOAD_FRAGMENT_SIZE (32 * 1024)
Naresh Tannirue3b18452014-03-04 14:44:27 +053056
Naresh Tannirudb72d1e2014-03-05 17:33:47 +053057#define ALIGN( num, to ) (((num) + (to-1)) & (~(to-1)))
Naresh Tannirue3b18452014-03-04 14:44:27 +053058/*
59 * This file will have a maximum of 38 bytes:
60 *
61 * 4 bytes: number of audio blocks
62 * 4 bytes: total length of Short Audio Descriptor (SAD) blocks
63 * Maximum 10 * 3 bytes: SAD blocks
64 */
65#define MAX_SAD_BLOCKS 10
66#define SAD_BLOCK_SIZE 3
67
68/* EDID format ID for LPCM audio */
69#define EDID_FORMAT_LPCM 1
70
Naresh Tannirudb72d1e2014-03-05 17:33:47 +053071/* Retry for delay in FW loading*/
72#define RETRY_NUMBER 20
73#define RETRY_US 500000
74#define MAX_SND_CARD 8
75
76#define SAMPLE_RATE_8KHZ 8000
77#define SAMPLE_RATE_16KHZ 16000
78
79#define AUDIO_PARAMETER_KEY_FLUENCE_TYPE "fluence"
80#define AUDIO_PARAMETER_KEY_BTSCO "bt_samplerate"
81#define AUDIO_PARAMETER_KEY_SLOWTALK "st_enable"
82#define AUDIO_PARAMETER_KEY_VOLUME_BOOST "volume_boost"
83
84enum {
85 VOICE_FEATURE_SET_DEFAULT,
86 VOICE_FEATURE_SET_VOLUME_BOOST
87};
88
Naresh Tannirue3b18452014-03-04 14:44:27 +053089struct audio_block_header
90{
91 int reserved;
92 int length;
93};
94
Naresh Tannirudb72d1e2014-03-05 17:33:47 +053095/* Audio calibration related functions */
Naresh Tannirue3b18452014-03-04 14:44:27 +053096typedef void (*acdb_deallocate_t)();
Naresh Tannirudb72d1e2014-03-05 17:33:47 +053097typedef int (*acdb_init_t)(char *);
Naresh Tannirue3b18452014-03-04 14:44:27 +053098typedef void (*acdb_send_audio_cal_t)(int, int);
99typedef void (*acdb_send_voice_cal_t)(int, int);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530100typedef int (*acdb_reload_vocvoltable_t)(int);
Naresh Tannirue3b18452014-03-04 14:44:27 +0530101
Naresh Tannirue3b18452014-03-04 14:44:27 +0530102struct platform_data {
103 struct audio_device *adev;
104 bool fluence_in_spkr_mode;
105 bool fluence_in_voice_call;
106 bool fluence_in_voice_rec;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530107 bool fluence_in_audio_rec;
108 int fluence_type;
Venkata Narendra Kumar Gutta88fd0bc2014-03-27 19:47:56 +0530109 char fluence_cap[PROPERTY_VALUE_MAX];
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530110 int btsco_sample_rate;
111 bool slowtalk;
112 /* Audio calibration related functions */
113 void *acdb_handle;
114 int voice_feature_set;
115 acdb_init_t acdb_init;
116 acdb_deallocate_t acdb_deallocate;
117 acdb_send_audio_cal_t acdb_send_audio_cal;
118 acdb_send_voice_cal_t acdb_send_voice_cal;
119 acdb_reload_vocvoltable_t acdb_reload_vocvoltable;
Naresh Tannirue3b18452014-03-04 14:44:27 +0530120
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530121 void *hw_info;
122 struct csd_data *csd;
Naresh Tannirue3b18452014-03-04 14:44:27 +0530123};
124
125static const int pcm_device_table[AUDIO_USECASE_MAX][2] = {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530126 [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = {DEEP_BUFFER_PCM_DEVICE,
127 DEEP_BUFFER_PCM_DEVICE},
128 [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
129 LOWLATENCY_PCM_DEVICE},
130 [USECASE_AUDIO_PLAYBACK_MULTI_CH] = {MULTIMEDIA2_PCM_DEVICE,
131 MULTIMEDIA2_PCM_DEVICE},
132 [USECASE_AUDIO_PLAYBACK_OFFLOAD] =
133 {PLAYBACK_OFFLOAD_DEVICE, PLAYBACK_OFFLOAD_DEVICE},
134 [USECASE_AUDIO_RECORD] = {AUDIO_RECORD_PCM_DEVICE, AUDIO_RECORD_PCM_DEVICE},
135 [USECASE_AUDIO_RECORD_COMPRESS] = {COMPRESS_CAPTURE_DEVICE, COMPRESS_CAPTURE_DEVICE},
136 [USECASE_AUDIO_RECORD_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
137 LOWLATENCY_PCM_DEVICE},
138 [USECASE_AUDIO_RECORD_FM_VIRTUAL] = {MULTIMEDIA2_PCM_DEVICE,
139 MULTIMEDIA2_PCM_DEVICE},
140 [USECASE_AUDIO_PLAYBACK_FM] = {FM_PLAYBACK_PCM_DEVICE, FM_CAPTURE_PCM_DEVICE},
141 [USECASE_AUDIO_HFP_SCO] = {HFP_PCM_RX, HFP_SCO_RX},
142 [USECASE_AUDIO_HFP_SCO_WB] = {HFP_PCM_RX, HFP_SCO_RX},
143 [USECASE_VOICE_CALL] = {VOICE_CALL_PCM_DEVICE, VOICE_CALL_PCM_DEVICE},
144 [USECASE_VOICE2_CALL] = {VOICE2_CALL_PCM_DEVICE, VOICE2_CALL_PCM_DEVICE},
145 [USECASE_VOLTE_CALL] = {VOLTE_CALL_PCM_DEVICE, VOLTE_CALL_PCM_DEVICE},
146 [USECASE_QCHAT_CALL] = {QCHAT_CALL_PCM_DEVICE, QCHAT_CALL_PCM_DEVICE},
Karthik Reddy Katta3b0a60c2014-04-06 14:52:37 +0530147 [USECASE_VOWLAN_CALL] = {VOWLAN_CALL_PCM_DEVICE, VOWLAN_CALL_PCM_DEVICE},
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530148 [USECASE_COMPRESS_VOIP_CALL] = {COMPRESS_VOIP_CALL_PCM_DEVICE, COMPRESS_VOIP_CALL_PCM_DEVICE},
149 [USECASE_INCALL_REC_UPLINK] = {AUDIO_RECORD_PCM_DEVICE,
150 AUDIO_RECORD_PCM_DEVICE},
151 [USECASE_INCALL_REC_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
152 AUDIO_RECORD_PCM_DEVICE},
153 [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
154 AUDIO_RECORD_PCM_DEVICE},
155 [USECASE_INCALL_REC_UPLINK_COMPRESS] = {COMPRESS_CAPTURE_DEVICE,
156 COMPRESS_CAPTURE_DEVICE},
157 [USECASE_INCALL_REC_DOWNLINK_COMPRESS] = {COMPRESS_CAPTURE_DEVICE,
158 COMPRESS_CAPTURE_DEVICE},
159 [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK_COMPRESS] = {COMPRESS_CAPTURE_DEVICE,
160 COMPRESS_CAPTURE_DEVICE},
161 [USECASE_INCALL_MUSIC_UPLINK] = {INCALL_MUSIC_UPLINK_PCM_DEVICE,
162 INCALL_MUSIC_UPLINK_PCM_DEVICE},
163 [USECASE_INCALL_MUSIC_UPLINK2] = {INCALL_MUSIC_UPLINK2_PCM_DEVICE,
164 INCALL_MUSIC_UPLINK2_PCM_DEVICE},
165 [USECASE_AUDIO_SPKR_CALIB_RX] = {SPKR_PROT_CALIB_RX_PCM_DEVICE, -1},
166 [USECASE_AUDIO_SPKR_CALIB_TX] = {-1, SPKR_PROT_CALIB_TX_PCM_DEVICE},
Naresh Tannirue3b18452014-03-04 14:44:27 +0530167};
168
169/* Array to store sound devices */
170static const char * const device_table[SND_DEVICE_MAX] = {
171 [SND_DEVICE_NONE] = "none",
172 /* Playback sound devices */
173 [SND_DEVICE_OUT_HANDSET] = "handset",
174 [SND_DEVICE_OUT_SPEAKER] = "speaker",
175 [SND_DEVICE_OUT_SPEAKER_REVERSE] = "speaker-reverse",
176 [SND_DEVICE_OUT_HEADPHONES] = "headphones",
177 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones",
178 [SND_DEVICE_OUT_VOICE_HANDSET] = "voice-handset",
179 [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker",
180 [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones",
181 [SND_DEVICE_OUT_HDMI] = "hdmi",
182 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi",
183 [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530184 [SND_DEVICE_OUT_BT_SCO_WB] = "bt-sco-headset-wb",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530185 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones",
186 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones",
187 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530188 [SND_DEVICE_OUT_AFE_PROXY] = "afe-proxy",
189 [SND_DEVICE_OUT_USB_HEADSET] = "usb-headphones",
190 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = "speaker-and-usb-headphones",
191 [SND_DEVICE_OUT_TRANSMISSION_FM] = "transmission-fm",
192 [SND_DEVICE_OUT_ANC_HEADSET] = "anc-headphones",
193 [SND_DEVICE_OUT_ANC_FB_HEADSET] = "anc-fb-headphones",
194 [SND_DEVICE_OUT_VOICE_ANC_HEADSET] = "voice-anc-headphones",
195 [SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET] = "voice-anc-fb-headphones",
196 [SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET] = "speaker-and-anc-headphones",
197 [SND_DEVICE_OUT_ANC_HANDSET] = "anc-handset",
198 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = "speaker-protected",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530199
200 /* Capture sound devices */
201 [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530202 [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530203 [SND_DEVICE_IN_HANDSET_MIC_NS] = "handset-mic",
204 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = "handset-mic",
205 [SND_DEVICE_IN_HANDSET_DMIC] = "dmic-endfire",
206 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = "dmic-endfire",
207 [SND_DEVICE_IN_HANDSET_DMIC_NS] = "dmic-endfire",
208 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = "dmic-endfire",
209 [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
210 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "speaker-mic",
211 [SND_DEVICE_IN_SPEAKER_MIC_NS] = "speaker-mic",
212 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = "speaker-mic",
213 [SND_DEVICE_IN_SPEAKER_DMIC] = "speaker-dmic-endfire",
214 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = "speaker-dmic-endfire",
215 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = "speaker-dmic-endfire",
216 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = "speaker-dmic-endfire",
217 [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
218 [SND_DEVICE_IN_HEADSET_MIC_FLUENCE] = "headset-mic",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530219 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
220 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
221 [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic",
222 [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530223 [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530224 [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530225 [SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef",
226 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = "voice-speaker-dmic-ef",
227 [SND_DEVICE_IN_VOICE_SPEAKER_QMIC] = "voice-speaker-qmic",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530228 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
229 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
230 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
231 [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530232 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = "voice-rec-mic",
233 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = "voice-rec-dmic-ef",
234 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence",
235 [SND_DEVICE_IN_USB_HEADSET_MIC] = "usb-headset-mic",
236 [SND_DEVICE_IN_CAPTURE_FM] = "capture-fm",
237 [SND_DEVICE_IN_AANC_HANDSET_MIC] = "aanc-handset-mic",
238 [SND_DEVICE_IN_QUAD_MIC] = "quad-mic",
239 [SND_DEVICE_IN_HANDSET_STEREO_DMIC] = "handset-stereo-dmic-ef",
240 [SND_DEVICE_IN_SPEAKER_STEREO_DMIC] = "speaker-stereo-dmic-ef",
241 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = "vi-feedback",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530242};
243
244/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530245static int acdb_device_table[SND_DEVICE_MAX] = {
Naresh Tannirue3b18452014-03-04 14:44:27 +0530246 [SND_DEVICE_NONE] = -1,
247 [SND_DEVICE_OUT_HANDSET] = 7,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530248 [SND_DEVICE_OUT_SPEAKER] = 14,
249 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 14,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530250 [SND_DEVICE_OUT_HEADPHONES] = 10,
251 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
252 [SND_DEVICE_OUT_VOICE_HANDSET] = 7,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530253 [SND_DEVICE_OUT_VOICE_SPEAKER] = 14,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530254 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
255 [SND_DEVICE_OUT_HDMI] = 18,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530256 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 14,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530257 [SND_DEVICE_OUT_BT_SCO] = 22,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530258 [SND_DEVICE_OUT_BT_SCO_WB] = 39,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530259 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
260 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
261 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530262 [SND_DEVICE_OUT_AFE_PROXY] = 0,
263 [SND_DEVICE_OUT_USB_HEADSET] = 45,
264 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = 14,
265 [SND_DEVICE_OUT_TRANSMISSION_FM] = 0,
266 [SND_DEVICE_OUT_ANC_HEADSET] = 26,
267 [SND_DEVICE_OUT_ANC_FB_HEADSET] = 27,
268 [SND_DEVICE_OUT_VOICE_ANC_HEADSET] = 26,
269 [SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET] = 27,
270 [SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET] = 26,
271 [SND_DEVICE_OUT_ANC_HANDSET] = 103,
272 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = 101,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530273
274 [SND_DEVICE_IN_HANDSET_MIC] = 4,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530275 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 106,
276 [SND_DEVICE_IN_HANDSET_MIC_NS] = 107,
277 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = 108,
278 [SND_DEVICE_IN_HANDSET_DMIC] = 41,
279 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = 109,
280 [SND_DEVICE_IN_HANDSET_DMIC_NS] = 110,
281 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = 111,
282 [SND_DEVICE_IN_SPEAKER_MIC] = 11,
283 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 112,
284 [SND_DEVICE_IN_SPEAKER_MIC_NS] = 113,
285 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = 114,
286 [SND_DEVICE_IN_SPEAKER_DMIC] = 43,
287 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = 115,
288 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = 116,
289 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = 117,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530290 [SND_DEVICE_IN_HEADSET_MIC] = 8,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530291 [SND_DEVICE_IN_HEADSET_MIC_FLUENCE] = 47,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530292 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
293 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = 8,
294 [SND_DEVICE_IN_HDMI_MIC] = 4,
295 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530296 [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38,
297 [SND_DEVICE_IN_CAMCORDER_MIC] = 4,
298 [SND_DEVICE_IN_VOICE_DMIC] = 41,
299 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 43,
300 [SND_DEVICE_IN_VOICE_SPEAKER_QMIC] = 19,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530301 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
302 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
303 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530304 [SND_DEVICE_IN_VOICE_REC_MIC] = 4,
305 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = 107,
306 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = 34,
307 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 41,
308 [SND_DEVICE_IN_USB_HEADSET_MIC] = 44,
309 [SND_DEVICE_IN_CAPTURE_FM] = 0,
310 [SND_DEVICE_IN_AANC_HANDSET_MIC] = 104,
311 [SND_DEVICE_IN_QUAD_MIC] = 46,
312 [SND_DEVICE_IN_HANDSET_STEREO_DMIC] = 34,
313 [SND_DEVICE_IN_SPEAKER_STEREO_DMIC] = 35,
314 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = 102,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530315};
316
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530317struct snd_device_index {
318 char name[100];
319 unsigned int index;
320};
Naresh Tannirue3b18452014-03-04 14:44:27 +0530321
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530322#define TO_NAME_INDEX(X) #X, X
Naresh Tannirue3b18452014-03-04 14:44:27 +0530323
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530324/* Used to get index from parsed sting */
325struct snd_device_index snd_device_name_index[SND_DEVICE_MAX] = {
326 {TO_NAME_INDEX(SND_DEVICE_OUT_HANDSET)},
327 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER)},
328 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_REVERSE)},
329 {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES)},
330 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES)},
331 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET)},
332 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER)},
333 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADPHONES)},
334 {TO_NAME_INDEX(SND_DEVICE_OUT_HDMI)},
335 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HDMI)},
336 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO)},
337 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO_WB)},
338 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES)},
339 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES)},
340 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET)},
341 {TO_NAME_INDEX(SND_DEVICE_OUT_AFE_PROXY)},
342 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADSET)},
343 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET)},
344 {TO_NAME_INDEX(SND_DEVICE_OUT_TRANSMISSION_FM)},
345 {TO_NAME_INDEX(SND_DEVICE_OUT_ANC_HEADSET)},
346 {TO_NAME_INDEX(SND_DEVICE_OUT_ANC_FB_HEADSET)},
347 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_ANC_HEADSET)},
348 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET)},
349 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET)},
350 {TO_NAME_INDEX(SND_DEVICE_OUT_ANC_HANDSET)},
351 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED)},
352 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC)},
353 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC)},
354 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_NS)},
355 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)},
356 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC)},
357 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC)},
358 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_NS)},
359 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)},
360 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC)},
361 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC)},
362 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_NS)},
363 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)},
364 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC)},
365 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC)},
366 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS)},
367 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)},
368 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC)},
369 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC_FLUENCE)},
370 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC)},
371 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEADSET_MIC)},
372 {TO_NAME_INDEX(SND_DEVICE_IN_HDMI_MIC)},
373 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC)},
374 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB)},
375 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_MIC)},
376 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC)},
377 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC)},
378 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_QMIC)},
379 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC)},
380 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC)},
381 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC)},
382 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC)},
383 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_NS)},
384 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_STEREO)},
385 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE)},
386 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC)},
387 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_FM)},
388 {TO_NAME_INDEX(SND_DEVICE_IN_AANC_HANDSET_MIC)},
389 {TO_NAME_INDEX(SND_DEVICE_IN_QUAD_MIC)},
390 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_STEREO_DMIC)},
391 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_STEREO_DMIC)},
392 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_VI_FEEDBACK)},
393};
394
395#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
396#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
Naresh Tannirue3b18452014-03-04 14:44:27 +0530397
Asish Bhattacharya4ff24802014-04-24 17:46:54 +0530398static void query_platform(const char *snd_card_name,
399 char *mixer_xml_path)
400{
401 if (!strncmp(snd_card_name, "msm8x16-snd-card-mtp",
402 sizeof("msm8x16-snd-card-mtp"))) {
403 strlcpy(mixer_xml_path, MIXER_XML_PATH_MTP,
404 sizeof(MIXER_XML_PATH_MTP));
405 } else {
406 strlcpy(mixer_xml_path, MIXER_XML_PATH,
407 sizeof(MIXER_XML_PATH));
408 }
409}
410
Naresh Tannirue3b18452014-03-04 14:44:27 +0530411static int set_echo_reference(struct mixer *mixer, const char* ec_ref)
412{
413 struct mixer_ctl *ctl;
414 const char *mixer_ctl_name = "EC_REF_RX";
415
416 ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name);
417 if (!ctl) {
418 ALOGE("%s: Could not get ctl for mixer cmd - %s",
419 __func__, mixer_ctl_name);
420 return -EINVAL;
421 }
422 ALOGV("Setting EC Reference: %s", ec_ref);
423 mixer_ctl_set_enum_by_string(ctl, ec_ref);
424 return 0;
425}
426
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530427static struct csd_data *open_csd_client()
428{
429 struct csd_data *csd = calloc(1, sizeof(struct csd_data));
430
431 csd->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
432 if (csd->csd_client == NULL) {
433 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
434 goto error;
435 } else {
436 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
437
438 csd->deinit = (deinit_t)dlsym(csd->csd_client,
439 "csd_client_deinit");
440 if (csd->deinit == NULL) {
441 ALOGE("%s: dlsym error %s for csd_client_deinit", __func__,
442 dlerror());
443 goto error;
444 }
445 csd->disable_device = (disable_device_t)dlsym(csd->csd_client,
446 "csd_client_disable_device");
447 if (csd->disable_device == NULL) {
448 ALOGE("%s: dlsym error %s for csd_client_disable_device",
449 __func__, dlerror());
450 goto error;
451 }
452 csd->enable_device_config = (enable_device_config_t)dlsym(csd->csd_client,
453 "csd_client_enable_device_config");
454 if (csd->enable_device_config == NULL) {
455 ALOGE("%s: dlsym error %s for csd_client_enable_device_config",
456 __func__, dlerror());
457 goto error;
458 }
459 csd->enable_device = (enable_device_t)dlsym(csd->csd_client,
460 "csd_client_enable_device");
461 if (csd->enable_device == NULL) {
462 ALOGE("%s: dlsym error %s for csd_client_enable_device",
463 __func__, dlerror());
464 goto error;
465 }
466 csd->start_voice = (start_voice_t)dlsym(csd->csd_client,
467 "csd_client_start_voice");
468 if (csd->start_voice == NULL) {
469 ALOGE("%s: dlsym error %s for csd_client_start_voice",
470 __func__, dlerror());
471 goto error;
472 }
473 csd->stop_voice = (stop_voice_t)dlsym(csd->csd_client,
474 "csd_client_stop_voice");
475 if (csd->stop_voice == NULL) {
476 ALOGE("%s: dlsym error %s for csd_client_stop_voice",
477 __func__, dlerror());
478 goto error;
479 }
480 csd->volume = (volume_t)dlsym(csd->csd_client,
481 "csd_client_volume");
482 if (csd->volume == NULL) {
483 ALOGE("%s: dlsym error %s for csd_client_volume",
484 __func__, dlerror());
485 goto error;
486 }
487 csd->mic_mute = (mic_mute_t)dlsym(csd->csd_client,
488 "csd_client_mic_mute");
489 if (csd->mic_mute == NULL) {
490 ALOGE("%s: dlsym error %s for csd_client_mic_mute",
491 __func__, dlerror());
492 goto error;
493 }
494 csd->slow_talk = (slow_talk_t)dlsym(csd->csd_client,
495 "csd_client_slow_talk");
496 if (csd->slow_talk == NULL) {
497 ALOGE("%s: dlsym error %s for csd_client_slow_talk",
498 __func__, dlerror());
499 goto error;
500 }
501 csd->start_playback = (start_playback_t)dlsym(csd->csd_client,
502 "csd_client_start_playback");
503 if (csd->start_playback == NULL) {
504 ALOGE("%s: dlsym error %s for csd_client_start_playback",
505 __func__, dlerror());
506 goto error;
507 }
508 csd->stop_playback = (stop_playback_t)dlsym(csd->csd_client,
509 "csd_client_stop_playback");
510 if (csd->stop_playback == NULL) {
511 ALOGE("%s: dlsym error %s for csd_client_stop_playback",
512 __func__, dlerror());
513 goto error;
514 }
515 csd->start_record = (start_record_t)dlsym(csd->csd_client,
516 "csd_client_start_record");
517 if (csd->start_record == NULL) {
518 ALOGE("%s: dlsym error %s for csd_client_start_record",
519 __func__, dlerror());
520 goto error;
521 }
522 csd->stop_record = (stop_record_t)dlsym(csd->csd_client,
523 "csd_client_stop_record");
524 if (csd->stop_record == NULL) {
525 ALOGE("%s: dlsym error %s for csd_client_stop_record",
526 __func__, dlerror());
527 goto error;
528 }
529 csd->init = (init_t)dlsym(csd->csd_client, "csd_client_init");
530
531 if (csd->init == NULL) {
532 ALOGE("%s: dlsym error %s for csd_client_init",
533 __func__, dlerror());
534 goto error;
535 } else {
536 csd->init();
537 }
538 }
539 return csd;
540
541error:
542 free(csd);
543 csd = NULL;
544 return csd;
545}
546
547void close_csd_client(struct csd_data *csd)
548{
549 if (csd != NULL) {
550 csd->deinit();
551 dlclose(csd->csd_client);
552 free(csd);
553 csd = NULL;
554 }
555}
556
Naresh Tannirue3b18452014-03-04 14:44:27 +0530557void *platform_init(struct audio_device *adev)
558{
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530559 char platform[PROPERTY_VALUE_MAX];
560 char baseband[PROPERTY_VALUE_MAX];
Naresh Tannirue3b18452014-03-04 14:44:27 +0530561 char value[PROPERTY_VALUE_MAX];
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530562 struct platform_data *my_data = NULL;
563 int retry_num = 0, snd_card_num = 0;
564 const char *snd_card_name;
Asish Bhattacharya4ff24802014-04-24 17:46:54 +0530565 char mixer_xml_path[100];
Naresh Tannirue3b18452014-03-04 14:44:27 +0530566
567 my_data = calloc(1, sizeof(struct platform_data));
568
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530569 while (snd_card_num < MAX_SND_CARD) {
570 adev->mixer = mixer_open(snd_card_num);
571
572 while (!adev->mixer && retry_num < RETRY_NUMBER) {
573 usleep(RETRY_US);
574 adev->mixer = mixer_open(snd_card_num);
575 retry_num++;
576 }
577
578 if (!adev->mixer) {
579 ALOGE("%s: Unable to open the mixer card: %d", __func__,
580 snd_card_num);
581 retry_num = 0;
582 snd_card_num++;
583 continue;
584 }
585
586 snd_card_name = mixer_get_name(adev->mixer);
587 ALOGV("%s: snd_card_name: %s", __func__, snd_card_name);
588
589 my_data->hw_info = hw_info_init(snd_card_name);
590 if (!my_data->hw_info) {
591 ALOGE("%s: Failed to init hardware info", __func__);
592 } else {
Asish Bhattacharya4ff24802014-04-24 17:46:54 +0530593 query_platform(snd_card_name, mixer_xml_path);
594 ALOGD("%s: mixer path file is %s", __func__,
595 mixer_xml_path);
596 if (audio_extn_read_xml(adev, snd_card_num, mixer_xml_path,
597 MIXER_XML_PATH_AUXPCM) == -ENOSYS) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530598 adev->audio_route = audio_route_init(snd_card_num,
Asish Bhattacharya4ff24802014-04-24 17:46:54 +0530599 mixer_xml_path);
600 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530601 if (!adev->audio_route) {
602 ALOGE("%s: Failed to init audio route controls, aborting.",
603 __func__);
604 free(my_data);
605 return NULL;
606 }
607 adev->snd_card = snd_card_num;
608 ALOGD("%s: Opened sound card:%d", __func__, snd_card_num);
609 break;
610 }
611 retry_num = 0;
612 snd_card_num++;
613 }
614
615 if (snd_card_num >= MAX_SND_CARD) {
616 ALOGE("%s: Unable to find correct sound card, aborting.", __func__);
617 free(my_data);
618 return NULL;
619 }
620
Naresh Tannirue3b18452014-03-04 14:44:27 +0530621 my_data->adev = adev;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530622 my_data->btsco_sample_rate = SAMPLE_RATE_8KHZ;
Naresh Tannirue3b18452014-03-04 14:44:27 +0530623 my_data->fluence_in_spkr_mode = false;
624 my_data->fluence_in_voice_call = false;
625 my_data->fluence_in_voice_rec = false;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530626 my_data->fluence_in_audio_rec = false;
627 my_data->fluence_type = FLUENCE_NONE;
Naresh Tannirue3b18452014-03-04 14:44:27 +0530628
Venkata Narendra Kumar Gutta88fd0bc2014-03-27 19:47:56 +0530629 property_get("ro.qc.sdk.audio.fluencetype", my_data->fluence_cap, "");
630 if (!strncmp("fluencepro", my_data->fluence_cap, sizeof("fluencepro"))) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530631 my_data->fluence_type = FLUENCE_QUAD_MIC | FLUENCE_DUAL_MIC;
Venkata Narendra Kumar Gutta88fd0bc2014-03-27 19:47:56 +0530632 } else if (!strncmp("fluence", my_data->fluence_cap, sizeof("fluence"))) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530633 my_data->fluence_type = FLUENCE_DUAL_MIC;
634 } else {
635 my_data->fluence_type = FLUENCE_NONE;
Naresh Tannirue3b18452014-03-04 14:44:27 +0530636 }
637
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530638 if (my_data->fluence_type != FLUENCE_NONE) {
Naresh Tannirue3b18452014-03-04 14:44:27 +0530639 property_get("persist.audio.fluence.voicecall",value,"");
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530640 if (!strncmp("true", value, sizeof("true"))) {
Naresh Tannirue3b18452014-03-04 14:44:27 +0530641 my_data->fluence_in_voice_call = true;
642 }
643
644 property_get("persist.audio.fluence.voicerec",value,"");
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530645 if (!strncmp("true", value, sizeof("true"))) {
Naresh Tannirue3b18452014-03-04 14:44:27 +0530646 my_data->fluence_in_voice_rec = true;
647 }
648
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530649 property_get("persist.audio.fluence.audiorec",value,"");
650 if (!strncmp("true", value, sizeof("true"))) {
651 my_data->fluence_in_audio_rec = true;
652 }
653
Naresh Tannirue3b18452014-03-04 14:44:27 +0530654 property_get("persist.audio.fluence.speaker",value,"");
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530655 if (!strncmp("true", value, sizeof("true"))) {
Naresh Tannirue3b18452014-03-04 14:44:27 +0530656 my_data->fluence_in_spkr_mode = true;
657 }
658 }
659
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530660 my_data->voice_feature_set = VOICE_FEATURE_SET_DEFAULT;
Naresh Tannirue3b18452014-03-04 14:44:27 +0530661 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
662 if (my_data->acdb_handle == NULL) {
663 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
664 } else {
665 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
666 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
667 "acdb_loader_deallocate_ACDB");
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530668 if (!my_data->acdb_deallocate)
669 ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s",
670 __func__, LIB_ACDB_LOADER);
671
Naresh Tannirue3b18452014-03-04 14:44:27 +0530672 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
673 "acdb_loader_send_audio_cal");
674 if (!my_data->acdb_send_audio_cal)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530675 ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530676 __func__, LIB_ACDB_LOADER);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530677
Naresh Tannirue3b18452014-03-04 14:44:27 +0530678 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
679 "acdb_loader_send_voice_cal");
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530680 if (!my_data->acdb_send_voice_cal)
681 ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s",
682 __func__, LIB_ACDB_LOADER);
683
684 my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle,
685 "acdb_loader_reload_vocvoltable");
686 if (!my_data->acdb_reload_vocvoltable)
687 ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s",
688 __func__, LIB_ACDB_LOADER);
689
Naresh Tannirue3b18452014-03-04 14:44:27 +0530690 my_data->acdb_init = (acdb_init_t)dlsym(my_data->acdb_handle,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530691 "acdb_loader_init_v2");
Naresh Tannirue3b18452014-03-04 14:44:27 +0530692 if (my_data->acdb_init == NULL)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530693 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__, dlerror());
Naresh Tannirue3b18452014-03-04 14:44:27 +0530694 else
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530695 my_data->acdb_init(snd_card_name);
Naresh Tannirue3b18452014-03-04 14:44:27 +0530696 }
697
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530698 /* Initialize ACDB ID's */
699 platform_info_init(PLATFORM_INFO_XML_PATH);
700
701 /* init usb */
702 audio_extn_usb_init(adev);
703 /* update sound cards appropriately */
704 audio_extn_usb_set_proxy_sound_card(adev->snd_card);
705
706 /* Read one time ssr property */
707 audio_extn_ssr_update_enabled();
708 audio_extn_spkr_prot_init(adev);
Naresh Tannirue3b18452014-03-04 14:44:27 +0530709 return my_data;
710}
711
712void platform_deinit(void *platform)
713{
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530714 struct platform_data *my_data = (struct platform_data *)platform;
715
716 hw_info_deinit(my_data->hw_info);
717 close_csd_client(my_data->csd);
718
Naresh Tannirue3b18452014-03-04 14:44:27 +0530719 free(platform);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530720 /* deinit usb */
721 audio_extn_usb_deinit();
Naresh Tannirue3b18452014-03-04 14:44:27 +0530722}
723
724const char *platform_get_snd_device_name(snd_device_t snd_device)
725{
726 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX)
727 return device_table[snd_device];
728 else
729 return "";
730}
731
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530732int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
733 char *device_name)
734{
735 struct platform_data *my_data = (struct platform_data *)platform;
736
737 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
738 strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE);
739 hw_info_append_hw_type(my_data->hw_info, snd_device, device_name);
740 } else {
741 strlcpy(device_name, "", DEVICE_NAME_MAX_SIZE);
742 return -EINVAL;
743 }
744
745 return 0;
746}
747
Naresh Tannirue3b18452014-03-04 14:44:27 +0530748void platform_add_backend_name(char *mixer_path, snd_device_t snd_device)
749{
750 if (snd_device == SND_DEVICE_IN_BT_SCO_MIC)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530751 strlcat(mixer_path, " bt-sco", MIXER_PATH_MAX_LENGTH);
752 else if (snd_device == SND_DEVICE_IN_BT_SCO_MIC_WB)
753 strlcat(mixer_path, " bt-sco-wb", MIXER_PATH_MAX_LENGTH);
Naresh Tannirue3b18452014-03-04 14:44:27 +0530754 else if(snd_device == SND_DEVICE_OUT_BT_SCO)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530755 strlcat(mixer_path, " bt-sco", MIXER_PATH_MAX_LENGTH);
756 else if(snd_device == SND_DEVICE_OUT_BT_SCO_WB)
757 strlcat(mixer_path, " bt-sco-wb", MIXER_PATH_MAX_LENGTH);
Naresh Tannirue3b18452014-03-04 14:44:27 +0530758 else if (snd_device == SND_DEVICE_OUT_HDMI)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530759 strlcat(mixer_path, " hdmi", MIXER_PATH_MAX_LENGTH);
Naresh Tannirue3b18452014-03-04 14:44:27 +0530760 else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HDMI)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530761 strlcat(mixer_path, " speaker-and-hdmi", MIXER_PATH_MAX_LENGTH);
762 else if (snd_device == SND_DEVICE_OUT_AFE_PROXY)
763 strlcat(mixer_path, " afe-proxy", MIXER_PATH_MAX_LENGTH);
764 else if (snd_device == SND_DEVICE_OUT_USB_HEADSET)
765 strlcat(mixer_path, " usb-headphones", MIXER_PATH_MAX_LENGTH);
766 else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET)
767 strlcat(mixer_path, " speaker-and-usb-headphones",
768 MIXER_PATH_MAX_LENGTH);
769 else if (snd_device == SND_DEVICE_IN_USB_HEADSET_MIC)
770 strlcat(mixer_path, " usb-headset-mic", MIXER_PATH_MAX_LENGTH);
771 else if (snd_device == SND_DEVICE_IN_CAPTURE_FM)
772 strlcat(mixer_path, " capture-fm", MIXER_PATH_MAX_LENGTH);
773 else if (snd_device == SND_DEVICE_OUT_TRANSMISSION_FM)
774 strlcat(mixer_path, " transmission-fm", MIXER_PATH_MAX_LENGTH);
Naresh Tannirue3b18452014-03-04 14:44:27 +0530775}
776
777int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
778{
779 int device_id;
780 if (device_type == PCM_PLAYBACK)
781 device_id = pcm_device_table[usecase][0];
782 else
783 device_id = pcm_device_table[usecase][1];
784 return device_id;
785}
786
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530787int platform_get_snd_device_index(char *snd_device_index_name)
788{
789 int ret = 0;
790 int i;
791
792 if (snd_device_index_name == NULL) {
793 ALOGE("%s: snd_device_index_name is NULL", __func__);
794 ret = -ENODEV;
795 goto done;
796 }
797
798 for (i=0; i < SND_DEVICE_MAX; i++) {
799 if(strcmp(snd_device_name_index[i].name, snd_device_index_name) == 0) {
800 ret = snd_device_name_index[i].index;
801 goto done;
802 }
803 }
804 ALOGE("%s: Could not find index for snd_device_index_name = %s",
805 __func__, snd_device_index_name);
806 ret = -ENODEV;
807done:
808 return ret;
809}
810
Venkata Narendra Kumar Gutta88fd0bc2014-03-27 19:47:56 +0530811int platform_set_fluence_type(void *platform, char *value)
812{
813 int ret = 0;
814 int fluence_type = FLUENCE_NONE;
815 int fluence_flag = NONE_FLAG;
816 struct platform_data *my_data = (struct platform_data *)platform;
817 struct audio_device *adev = my_data->adev;
818
819 ALOGV("%s: fluence type:%d", __func__, my_data->fluence_type);
820
821 /* only dual mic turn on and off is supported as of now through setparameters */
822 if (!strncmp(AUDIO_PARAMETER_VALUE_DUALMIC,value, sizeof(AUDIO_PARAMETER_VALUE_DUALMIC))) {
823 if (!strncmp("fluencepro", my_data->fluence_cap, sizeof("fluencepro")) ||
824 !strncmp("fluence", my_data->fluence_cap, sizeof("fluence"))) {
825 ALOGV("fluence dualmic feature enabled \n");
826 fluence_type = FLUENCE_DUAL_MIC;
827 fluence_flag = DMIC_FLAG;
828 } else {
829 ALOGE("%s: Failed to set DUALMIC", __func__);
830 ret = -1;
831 goto done;
832 }
833 } else if (!strncmp(AUDIO_PARAMETER_KEY_NO_FLUENCE, value, sizeof(AUDIO_PARAMETER_KEY_NO_FLUENCE))) {
834 ALOGV("fluence disabled");
835 fluence_type = FLUENCE_NONE;
836 } else {
837 ALOGE("Invalid fluence value : %s",value);
838 ret = -1;
839 goto done;
840 }
841
842 if (fluence_type != my_data->fluence_type) {
843 ALOGV("%s: Updating fluence_type to :%d", __func__, fluence_type);
844 my_data->fluence_type = fluence_type;
845 adev->acdb_settings = (adev->acdb_settings & FLUENCE_MODE_CLEAR) | fluence_flag;
846 }
847done:
848 return ret;
849}
850
851int platform_get_fluence_type(void *platform, char *value, uint32_t len)
852{
853 int ret = 0;
854 struct platform_data *my_data = (struct platform_data *)platform;
855
856 if (my_data->fluence_type == FLUENCE_QUAD_MIC) {
857 strlcpy(value, "quadmic", len);
858 } else if (my_data->fluence_type == FLUENCE_DUAL_MIC) {
859 strlcpy(value, "dualmic", len);
860 } else if (my_data->fluence_type == FLUENCE_NONE) {
861 strlcpy(value, "none", len);
862 } else
863 ret = -1;
864
865 return ret;
866}
867
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530868int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
869{
870 int ret = 0;
871
872 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
873 ALOGE("%s: Invalid snd_device = %d",
874 __func__, snd_device);
875 ret = -EINVAL;
876 goto done;
877 }
878
879 acdb_device_table[snd_device] = acdb_id;
880done:
881 return ret;
882}
883
Naresh Tannirue3b18452014-03-04 14:44:27 +0530884int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
885{
886 struct platform_data *my_data = (struct platform_data *)platform;
887 int acdb_dev_id, acdb_dev_type;
888
889 acdb_dev_id = acdb_device_table[snd_device];
890 if (acdb_dev_id < 0) {
891 ALOGE("%s: Could not find acdb id for device(%d)",
892 __func__, snd_device);
893 return -EINVAL;
894 }
895 if (my_data->acdb_send_audio_cal) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530896 ("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530897 __func__, snd_device, acdb_dev_id);
898 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
899 snd_device < SND_DEVICE_OUT_END)
900 acdb_dev_type = ACDB_DEV_TYPE_OUT;
901 else
902 acdb_dev_type = ACDB_DEV_TYPE_IN;
903 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
904 }
905 return 0;
906}
907
908int platform_switch_voice_call_device_pre(void *platform)
909{
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530910 struct platform_data *my_data = (struct platform_data *)platform;
911 int ret = 0;
912
913 if (my_data->csd != NULL &&
914 my_data->adev->mode == AUDIO_MODE_IN_CALL) {
915 /* This must be called before disabling mixer controls on APQ side */
916 ret = my_data->csd->disable_device();
917 if (ret < 0) {
918 ALOGE("%s: csd_client_disable_device, failed, error %d",
919 __func__, ret);
920 }
921 }
922 return ret;
Naresh Tannirue3b18452014-03-04 14:44:27 +0530923}
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530924int platform_switch_voice_call_enable_device_config(void *platform,
925 snd_device_t out_snd_device,
926 snd_device_t in_snd_device)
927{
928 struct platform_data *my_data = (struct platform_data *)platform;
929 int acdb_rx_id, acdb_tx_id;
930 int ret = 0;
931
932 acdb_rx_id = acdb_device_table[out_snd_device];
933 acdb_tx_id = acdb_device_table[in_snd_device];
934
935 if (my_data->csd != NULL) {
936 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
937 ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
938 if (ret < 0) {
939 ALOGE("%s: csd_enable_device_config, failed, error %d",
940 __func__, ret);
941 }
942 } else {
943 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
944 acdb_rx_id, acdb_tx_id);
945 }
946 }
947 return ret;
948}
949
Naresh Tannirue3b18452014-03-04 14:44:27 +0530950
951int platform_switch_voice_call_device_post(void *platform,
952 snd_device_t out_snd_device,
953 snd_device_t in_snd_device)
954{
955 struct platform_data *my_data = (struct platform_data *)platform;
956 int acdb_rx_id, acdb_tx_id;
957
958 if (my_data->acdb_send_voice_cal == NULL) {
959 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
960 } else {
961 acdb_rx_id = acdb_device_table[out_snd_device];
962 acdb_tx_id = acdb_device_table[in_snd_device];
963
964 if (acdb_rx_id > 0 && acdb_tx_id > 0)
965 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
966 else
967 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
968 acdb_rx_id, acdb_tx_id);
969 }
970
971 return 0;
972}
973
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530974int platform_switch_voice_call_usecase_route_post(void *platform,
975 snd_device_t out_snd_device,
976 snd_device_t in_snd_device)
Naresh Tannirue3b18452014-03-04 14:44:27 +0530977{
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530978 struct platform_data *my_data = (struct platform_data *)platform;
979 int acdb_rx_id, acdb_tx_id;
980 int ret = 0;
981
982 acdb_rx_id = acdb_device_table[out_snd_device];
983 acdb_tx_id = acdb_device_table[in_snd_device];
984
985 if (my_data->csd != NULL) {
986 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
987 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
988 my_data->adev->acdb_settings);
989 if (ret < 0) {
990 ALOGE("%s: csd_enable_device, failed, error %d",
991 __func__, ret);
992 }
993 } else {
994 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
995 acdb_rx_id, acdb_tx_id);
996 }
997 }
998 return ret;
Naresh Tannirue3b18452014-03-04 14:44:27 +0530999}
1000
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301001int platform_start_voice_call(void *platform, uint32_t vsid)
1002{
1003 struct platform_data *my_data = (struct platform_data *)platform;
1004 int ret = 0;
1005
1006 if (my_data->csd != NULL) {
1007 ret = my_data->csd->start_voice(vsid);
1008 if (ret < 0) {
1009 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
1010 }
1011 }
1012 return ret;
1013}
1014
1015int platform_stop_voice_call(void *platform, uint32_t vsid)
1016{
1017 struct platform_data *my_data = (struct platform_data *)platform;
1018 int ret = 0;
1019
1020 if (my_data->csd != NULL) {
1021 ret = my_data->csd->stop_voice(vsid);
1022 if (ret < 0) {
1023 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
1024 }
1025 }
1026 return ret;
1027}
1028int platform_get_sample_rate(void *platform, uint32_t *rate)
Naresh Tannirue3b18452014-03-04 14:44:27 +05301029{
1030 return 0;
1031}
1032
1033int platform_set_voice_volume(void *platform, int volume)
1034{
1035 struct platform_data *my_data = (struct platform_data *)platform;
1036 struct audio_device *adev = my_data->adev;
1037 struct mixer_ctl *ctl;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301038 const char *mixer_ctl_name = "Voice Rx Gain";
1039 int vol_index = 0, ret = 0;
1040 uint32_t set_values[ ] = {0,
1041 ALL_SESSION_VSID,
1042 DEFAULT_VOLUME_RAMP_DURATION_MS};
Naresh Tannirue3b18452014-03-04 14:44:27 +05301043
1044 // Voice volume levels are mapped to adsp volume levels as follows.
1045 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
1046 // But this values don't changed in kernel. So, below change is need.
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301047 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, MAX_VOL_INDEX);
1048 set_values[0] = vol_index;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301049
1050 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1051 if (!ctl) {
1052 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1053 __func__, mixer_ctl_name);
1054 return -EINVAL;
1055 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301056 ALOGV("Setting voice volume index: %d", set_values[0]);
1057 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
Naresh Tannirue3b18452014-03-04 14:44:27 +05301058
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301059 if (my_data->csd != NULL) {
1060 ret = my_data->csd->volume(ALL_SESSION_VSID, volume);
1061 if (ret < 0) {
1062 ALOGE("%s: csd_volume error %d", __func__, ret);
1063 }
1064 }
1065 return ret;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301066}
1067
1068int platform_set_mic_mute(void *platform, bool state)
1069{
1070 struct platform_data *my_data = (struct platform_data *)platform;
1071 struct audio_device *adev = my_data->adev;
1072 struct mixer_ctl *ctl;
1073 const char *mixer_ctl_name = "Voice Tx Mute";
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301074 int ret = 0;
1075 uint32_t set_values[ ] = {0,
1076 ALL_SESSION_VSID,
1077 DEFAULT_VOLUME_RAMP_DURATION_MS};
Naresh Tannirue3b18452014-03-04 14:44:27 +05301078
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301079 set_values[0] = state;
1080 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1081 if (!ctl) {
1082 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1083 __func__, mixer_ctl_name);
1084 return -EINVAL;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301085 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301086 ALOGV("Setting voice mute state: %d", state);
1087 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
Naresh Tannirue3b18452014-03-04 14:44:27 +05301088
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301089 if (my_data->csd != NULL) {
1090 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state);
1091 if (ret < 0) {
1092 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
1093 }
1094 }
1095 return ret;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301096}
1097
Shiv Maliyappanahallic6fd8ee2014-03-07 15:31:55 -08001098int platform_set_device_mute(void *platform, bool state, char *dir)
1099{
1100 struct platform_data *my_data = (struct platform_data *)platform;
1101 struct audio_device *adev = my_data->adev;
1102 struct mixer_ctl *ctl;
1103 char *mixer_ctl_name = NULL;
1104 int ret = 0;
1105 uint32_t set_values[ ] = {0,
1106 ALL_SESSION_VSID,
1107 0};
1108 if(dir == NULL) {
1109 ALOGE("%s: Invalid direction:%s", __func__, dir);
1110 return -EINVAL;
1111 }
1112
1113 if (!strncmp("rx", dir, sizeof("rx"))) {
1114 mixer_ctl_name = "Voice Rx Device Mute";
1115 } else if (!strncmp("tx", dir, sizeof("tx"))) {
1116 mixer_ctl_name = "Voice Tx Device Mute";
1117 } else {
1118 return -EINVAL;
1119 }
1120
1121 set_values[0] = state;
1122 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1123 if (!ctl) {
1124 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1125 __func__, mixer_ctl_name);
1126 return -EINVAL;
1127 }
1128
1129 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
1130 __func__,state, mixer_ctl_name);
1131 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1132
1133 return ret;
1134}
1135
Naresh Tannirue3b18452014-03-04 14:44:27 +05301136snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
1137{
1138 struct platform_data *my_data = (struct platform_data *)platform;
1139 struct audio_device *adev = my_data->adev;
1140 audio_mode_t mode = adev->mode;
1141 snd_device_t snd_device = SND_DEVICE_NONE;
1142
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301143 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
1144 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
1145 int channel_count = popcount(channel_mask);
1146
Naresh Tannirue3b18452014-03-04 14:44:27 +05301147 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
1148 if (devices == AUDIO_DEVICE_NONE ||
1149 devices & AUDIO_DEVICE_BIT_IN) {
1150 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
1151 goto exit;
1152 }
1153
Naresh Tannirue3b18452014-03-04 14:44:27 +05301154 if (popcount(devices) == 2) {
1155 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
1156 AUDIO_DEVICE_OUT_SPEAKER)) {
1157 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
1158 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
1159 AUDIO_DEVICE_OUT_SPEAKER)) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301160 if (audio_extn_get_anc_enabled())
1161 snd_device = SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET;
1162 else
1163 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301164 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
1165 AUDIO_DEVICE_OUT_SPEAKER)) {
1166 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301167 } else if (devices == (AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET |
1168 AUDIO_DEVICE_OUT_SPEAKER)) {
1169 snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301170 } else {
1171 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
1172 goto exit;
1173 }
1174 if (snd_device != SND_DEVICE_NONE) {
1175 goto exit;
1176 }
1177 }
1178
1179 if (popcount(devices) != 1) {
1180 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
1181 goto exit;
1182 }
1183
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301184 if ((mode == AUDIO_MODE_IN_CALL) ||
1185 voice_extn_compress_voip_is_active(adev)) {
1186 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1187 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
1188 if ((adev->voice.tty_mode != TTY_MODE_OFF) &&
1189 !voice_extn_compress_voip_is_active(adev)) {
1190 switch (adev->voice.tty_mode) {
1191 case TTY_MODE_FULL:
1192 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
1193 break;
1194 case TTY_MODE_VCO:
1195 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
1196 break;
1197 case TTY_MODE_HCO:
1198 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
1199 break;
1200 default:
1201 ALOGE("%s: Invalid TTY mode (%#x)",
1202 __func__, adev->voice.tty_mode);
1203 }
1204 } else if (audio_extn_get_anc_enabled()) {
1205 if (audio_extn_should_use_fb_anc())
1206 snd_device = SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET;
1207 else
1208 snd_device = SND_DEVICE_OUT_VOICE_ANC_HEADSET;
1209 } else {
1210 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
1211 }
1212 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
1213 if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ)
1214 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
1215 else
1216 snd_device = SND_DEVICE_OUT_BT_SCO;
1217 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
1218 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
1219 } else if (devices & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
1220 devices & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
1221 snd_device = SND_DEVICE_OUT_USB_HEADSET;
1222 } else if (devices & AUDIO_DEVICE_OUT_FM_TX) {
1223 snd_device = SND_DEVICE_OUT_TRANSMISSION_FM;
1224 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
1225 if (audio_extn_should_use_handset_anc(channel_count))
1226 snd_device = SND_DEVICE_OUT_ANC_HANDSET;
1227 else
1228 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
1229 }
1230 if (snd_device != SND_DEVICE_NONE) {
1231 goto exit;
1232 }
1233 }
1234
Naresh Tannirue3b18452014-03-04 14:44:27 +05301235 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1236 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301237 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADSET
1238 && audio_extn_get_anc_enabled()) {
1239 if (audio_extn_should_use_fb_anc())
1240 snd_device = SND_DEVICE_OUT_ANC_FB_HEADSET;
1241 else
1242 snd_device = SND_DEVICE_OUT_ANC_HEADSET;
1243 }
1244 else
1245 snd_device = SND_DEVICE_OUT_HEADPHONES;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301246 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
1247 if (adev->speaker_lr_swap)
1248 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
1249 else
1250 snd_device = SND_DEVICE_OUT_SPEAKER;
1251 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301252 if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ)
1253 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
1254 else
1255 snd_device = SND_DEVICE_OUT_BT_SCO;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301256 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
1257 snd_device = SND_DEVICE_OUT_HDMI ;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301258 } else if (devices & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
1259 devices & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
Mingming Yin5a7c5d62014-03-05 17:45:03 -08001260 ALOGD("%s: setting USB hadset channel capability(2) for Proxy", __func__);
1261 audio_extn_set_afe_proxy_channel_mixer(adev, 2);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301262 snd_device = SND_DEVICE_OUT_USB_HEADSET;
1263 } else if (devices & AUDIO_DEVICE_OUT_FM_TX) {
1264 snd_device = SND_DEVICE_OUT_TRANSMISSION_FM;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301265 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
1266 snd_device = SND_DEVICE_OUT_HANDSET;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301267 } else if (devices & AUDIO_DEVICE_OUT_PROXY) {
Mingming Yin5a7c5d62014-03-05 17:45:03 -08001268 channel_count = audio_extn_get_afe_proxy_channel_count();
1269 ALOGD("%s: setting sink capability(%d) for Proxy", __func__, channel_count);
1270 audio_extn_set_afe_proxy_channel_mixer(adev, channel_count);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301271 snd_device = SND_DEVICE_OUT_AFE_PROXY;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301272 } else {
1273 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
1274 }
1275exit:
1276 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
1277 return snd_device;
1278}
1279
1280snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
1281{
1282 struct platform_data *my_data = (struct platform_data *)platform;
1283 struct audio_device *adev = my_data->adev;
1284 audio_source_t source = (adev->active_input == NULL) ?
1285 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
1286
1287 audio_mode_t mode = adev->mode;
1288 audio_devices_t in_device = ((adev->active_input == NULL) ?
1289 AUDIO_DEVICE_NONE : adev->active_input->device)
1290 & ~AUDIO_DEVICE_BIT_IN;
1291 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
1292 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
1293 snd_device_t snd_device = SND_DEVICE_NONE;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301294 int channel_count = popcount(channel_mask);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301295
1296 ALOGV("%s: enter: out_device(%#x) in_device(%#x)",
1297 __func__, out_device, in_device);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301298 if ((out_device != AUDIO_DEVICE_NONE) && ((mode == AUDIO_MODE_IN_CALL) ||
1299 voice_extn_compress_voip_is_active(adev))) {
1300 if ((adev->voice.tty_mode != TTY_MODE_OFF) &&
1301 !voice_extn_compress_voip_is_active(adev)) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301302 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1303 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301304 switch (adev->voice.tty_mode) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301305 case TTY_MODE_FULL:
1306 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
1307 break;
1308 case TTY_MODE_VCO:
1309 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
1310 break;
1311 case TTY_MODE_HCO:
1312 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
1313 break;
1314 default:
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301315 ALOGE("%s: Invalid TTY mode (%#x)",
1316 __func__, adev->voice.tty_mode);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301317 }
1318 goto exit;
1319 }
1320 }
1321 if (out_device & AUDIO_DEVICE_OUT_EARPIECE ||
1322 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301323 if (out_device & AUDIO_DEVICE_OUT_EARPIECE &&
1324 audio_extn_should_use_handset_anc(channel_count)) {
1325 snd_device = SND_DEVICE_IN_AANC_HANDSET_MIC;
1326 } else if (my_data->fluence_type == FLUENCE_NONE ||
1327 my_data->fluence_in_voice_call == false) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301328 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301329 set_echo_reference(adev->mixer, EC_REF_RX);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301330 } else {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301331 snd_device = SND_DEVICE_IN_VOICE_DMIC;
1332 adev->acdb_settings |= DMIC_FLAG;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301333 }
1334 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
1335 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
Satya Krishna Pindiproli624c7802014-04-11 11:33:27 +05301336 set_echo_reference(adev->mixer, EC_REF_RX);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301337 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301338 if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ)
1339 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
1340 else
1341 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301342 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301343 if (my_data->fluence_type != FLUENCE_NONE &&
1344 my_data->fluence_in_voice_call &&
1345 my_data->fluence_in_spkr_mode) {
1346 if(my_data->fluence_type & FLUENCE_QUAD_MIC) {
1347 adev->acdb_settings |= QMIC_FLAG;
1348 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_QMIC;
1349 } else {
1350 adev->acdb_settings |= DMIC_FLAG;
1351 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
1352 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05301353 } else {
1354 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
Satya Krishna Pindiproli624c7802014-04-11 11:33:27 +05301355 set_echo_reference(adev->mixer, EC_REF_RX);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301356 }
1357 }
1358 } else if (source == AUDIO_SOURCE_CAMCORDER) {
1359 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
1360 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
1361 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
1362 }
1363 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
1364 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301365 if (channel_count == 2) {
1366 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
1367 adev->acdb_settings |= DMIC_FLAG;
1368 } else if (adev->active_input->enable_ns)
1369 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
1370 else if (my_data->fluence_type != FLUENCE_NONE &&
1371 my_data->fluence_in_voice_rec) {
1372 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
1373 adev->acdb_settings |= DMIC_FLAG;
1374 } else {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301375 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
1376 }
1377 }
1378 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION) {
1379 if (out_device & AUDIO_DEVICE_OUT_SPEAKER)
1380 in_device = AUDIO_DEVICE_IN_BACK_MIC;
1381 if (adev->active_input) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301382 if (adev->active_input->enable_aec &&
1383 adev->active_input->enable_ns) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301384 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301385 if (my_data->fluence_type & FLUENCE_DUAL_MIC &&
1386 my_data->fluence_in_spkr_mode) {
1387 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
1388 adev->acdb_settings |= DMIC_FLAG;
1389 } else
1390 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301391 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301392 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1393 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
1394 adev->acdb_settings |= DMIC_FLAG;
1395 } else
1396 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301397 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301398 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301399 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301400 set_echo_reference(adev->mixer, EC_REF_RX);
1401 } else if (adev->active_input->enable_aec) {
1402 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
1403 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1404 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
1405 adev->acdb_settings |= DMIC_FLAG;
1406 } else
1407 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
1408 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
1409 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1410 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
1411 adev->acdb_settings |= DMIC_FLAG;
1412 } else
1413 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
1414 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
1415 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
1416 }
1417 set_echo_reference(adev->mixer, EC_REF_RX);
1418 } else if (adev->active_input->enable_ns) {
1419 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
1420 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1421 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
1422 adev->acdb_settings |= DMIC_FLAG;
1423 } else
1424 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
1425 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
1426 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1427 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
1428 adev->acdb_settings |= DMIC_FLAG;
1429 } else
1430 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
1431 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
1432 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
1433 }
1434 set_echo_reference(adev->mixer, "NONE");
Naresh Tannirue3b18452014-03-04 14:44:27 +05301435 } else
1436 set_echo_reference(adev->mixer, "NONE");
1437 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301438 } else if (source == AUDIO_SOURCE_MIC) {
1439 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC &&
1440 channel_count == 1 ) {
1441 if(my_data->fluence_type & FLUENCE_DUAL_MIC &&
1442 my_data->fluence_in_audio_rec)
1443 snd_device = SND_DEVICE_IN_HANDSET_DMIC;
1444 }
1445 } else if (source == AUDIO_SOURCE_FM_RX ||
1446 source == AUDIO_SOURCE_FM_RX_A2DP) {
1447 snd_device = SND_DEVICE_IN_CAPTURE_FM;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301448 } else if (source == AUDIO_SOURCE_DEFAULT) {
1449 goto exit;
1450 }
1451
1452
1453 if (snd_device != SND_DEVICE_NONE) {
1454 goto exit;
1455 }
1456
1457 if (in_device != AUDIO_DEVICE_NONE &&
1458 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
1459 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
1460 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301461 if (audio_extn_ssr_get_enabled() && channel_count == 6)
1462 snd_device = SND_DEVICE_IN_QUAD_MIC;
1463 else if (channel_count == 2)
1464 snd_device = SND_DEVICE_IN_HANDSET_STEREO_DMIC;
1465 else
1466 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301467 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
1468 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
1469 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
1470 snd_device = SND_DEVICE_IN_HEADSET_MIC;
1471 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301472 if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ)
1473 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
1474 else
1475 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301476 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
1477 snd_device = SND_DEVICE_IN_HDMI_MIC;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301478 } else if (in_device & AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET ||
1479 in_device & AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET) {
1480 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
1481 } else if (in_device & AUDIO_DEVICE_IN_FM_RX) {
1482 snd_device = SND_DEVICE_IN_CAPTURE_FM;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301483 } else {
1484 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
1485 ALOGW("%s: Using default handset-mic", __func__);
1486 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1487 }
1488 } else {
1489 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
1490 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1491 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
1492 snd_device = SND_DEVICE_IN_HEADSET_MIC;
1493 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301494 if (channel_count > 1)
1495 snd_device = SND_DEVICE_IN_SPEAKER_STEREO_DMIC;
1496 else
1497 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301498 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
1499 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1500 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301501 if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ)
1502 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
1503 else
1504 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301505 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
1506 snd_device = SND_DEVICE_IN_HDMI_MIC;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301507 } else if (out_device & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
1508 out_device & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
1509 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301510 } else {
1511 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
1512 ALOGW("%s: Using default handset-mic", __func__);
1513 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1514 }
1515 }
1516exit:
1517 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
1518 return snd_device;
1519}
1520
1521int platform_set_hdmi_channels(void *platform, int channel_count)
1522{
1523 struct platform_data *my_data = (struct platform_data *)platform;
1524 struct audio_device *adev = my_data->adev;
1525 struct mixer_ctl *ctl;
1526 const char *channel_cnt_str = NULL;
1527 const char *mixer_ctl_name = "HDMI_RX Channels";
1528 switch (channel_count) {
1529 case 8:
1530 channel_cnt_str = "Eight"; break;
1531 case 7:
1532 channel_cnt_str = "Seven"; break;
1533 case 6:
1534 channel_cnt_str = "Six"; break;
1535 case 5:
1536 channel_cnt_str = "Five"; break;
1537 case 4:
1538 channel_cnt_str = "Four"; break;
1539 case 3:
1540 channel_cnt_str = "Three"; break;
1541 default:
1542 channel_cnt_str = "Two"; break;
1543 }
1544 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1545 if (!ctl) {
1546 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1547 __func__, mixer_ctl_name);
1548 return -EINVAL;
1549 }
1550 ALOGV("HDMI channel count: %s", channel_cnt_str);
1551 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
1552 return 0;
1553}
1554
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301555int platform_edid_get_max_channels(void *platform)
Naresh Tannirue3b18452014-03-04 14:44:27 +05301556{
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301557 struct platform_data *my_data = (struct platform_data *)platform;
1558 struct audio_device *adev = my_data->adev;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301559 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
1560 char *sad = block;
1561 int num_audio_blocks;
1562 int channel_count;
1563 int max_channels = 0;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301564 int i, ret, count;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301565
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301566 struct mixer_ctl *ctl;
1567
1568 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
1569 if (!ctl) {
1570 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1571 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301572 return 0;
1573 }
1574
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301575 mixer_ctl_update(ctl);
1576
1577 count = mixer_ctl_get_num_values(ctl);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301578
1579 /* Read SAD blocks, clamping the maximum size for safety */
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301580 if (count > (int)sizeof(block))
1581 count = (int)sizeof(block);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301582
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301583 ret = mixer_ctl_get_array(ctl, block, count);
1584 if (ret != 0) {
1585 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
1586 return 0;
1587 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05301588
1589 /* Calculate the number of SAD blocks */
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301590 num_audio_blocks = count / SAD_BLOCK_SIZE;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301591
1592 for (i = 0; i < num_audio_blocks; i++) {
1593 /* Only consider LPCM blocks */
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301594 if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
1595 sad += 3;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301596 continue;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301597 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05301598
1599 channel_count = (sad[0] & 0x7) + 1;
1600 if (channel_count > max_channels)
1601 max_channels = channel_count;
1602
1603 /* Advance to next block */
1604 sad += 3;
1605 }
1606
1607 return max_channels;
1608}
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301609
1610static int platform_set_slowtalk(struct platform_data *my_data, bool state)
1611{
1612 int ret = 0;
1613 struct audio_device *adev = my_data->adev;
1614 struct mixer_ctl *ctl;
1615 const char *mixer_ctl_name = "Slowtalk Enable";
1616 uint32_t set_values[ ] = {0,
1617 ALL_SESSION_VSID};
1618
1619 set_values[0] = state;
1620 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1621 if (!ctl) {
1622 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1623 __func__, mixer_ctl_name);
1624 ret = -EINVAL;
1625 } else {
1626 ALOGV("Setting slowtalk state: %d", state);
1627 ret = mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1628 my_data->slowtalk = state;
1629 }
1630
1631 if (my_data->csd != NULL) {
1632 ret = my_data->csd->slow_talk(ALL_SESSION_VSID, state);
1633 if (ret < 0) {
1634 ALOGE("%s: csd_client_disable_device, failed, error %d",
1635 __func__, ret);
1636 }
1637 }
1638 return ret;
1639}
1640
1641int platform_set_parameters(void *platform, struct str_parms *parms)
1642{
1643 struct platform_data *my_data = (struct platform_data *)platform;
1644 char *str;
1645 char value[256] = {0};
1646 int val;
1647 int ret = 0, err;
1648
1649 ALOGV("%s: enter: %s", __func__, str_parms_to_str(parms));
1650
1651 err = str_parms_get_int(parms, AUDIO_PARAMETER_KEY_BTSCO, &val);
1652 if (err >= 0) {
1653 str_parms_del(parms, AUDIO_PARAMETER_KEY_BTSCO);
1654 my_data->btsco_sample_rate = val;
1655 if (val == SAMPLE_RATE_16KHZ) {
1656 audio_route_apply_path(my_data->adev->audio_route,
1657 "bt-sco-wb-samplerate");
1658 audio_route_update_mixer(my_data->adev->audio_route);
1659 }
1660 }
1661
1662 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_SLOWTALK, value, sizeof(value));
1663 if (err >= 0) {
1664 bool state = false;
1665 if (!strncmp("true", value, sizeof("true"))) {
1666 state = true;
1667 }
1668
1669 str_parms_del(parms, AUDIO_PARAMETER_KEY_SLOWTALK);
1670 ret = platform_set_slowtalk(my_data, state);
1671 if (ret)
1672 ALOGE("%s: Failed to set slow talk err: %d", __func__, ret);
1673 }
1674
1675 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_VOLUME_BOOST,
1676 value, sizeof(value));
1677 if (err >= 0) {
1678 str_parms_del(parms, AUDIO_PARAMETER_KEY_VOLUME_BOOST);
1679
1680 if (my_data->acdb_reload_vocvoltable == NULL) {
1681 ALOGE("%s: acdb_reload_vocvoltable is NULL", __func__);
1682 } else if (!strcmp(value, "on")) {
1683 if (!my_data->acdb_reload_vocvoltable(VOICE_FEATURE_SET_VOLUME_BOOST)) {
1684 my_data->voice_feature_set = 1;
1685 }
1686 } else {
1687 if (!my_data->acdb_reload_vocvoltable(VOICE_FEATURE_SET_DEFAULT)) {
1688 my_data->voice_feature_set = 0;
1689 }
1690 }
1691 }
1692
1693 ALOGV("%s: exit with code(%d)", __func__, ret);
1694 return ret;
1695}
1696
1697int platform_set_incall_recording_session_id(void *platform,
1698 uint32_t session_id, int rec_mode)
1699{
1700 int ret = 0;
1701 struct platform_data *my_data = (struct platform_data *)platform;
1702 struct audio_device *adev = my_data->adev;
1703 struct mixer_ctl *ctl;
1704 const char *mixer_ctl_name = "Voc VSID";
1705 int num_ctl_values;
1706 int i;
1707
1708 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1709 if (!ctl) {
1710 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1711 __func__, mixer_ctl_name);
1712 ret = -EINVAL;
1713 } else {
1714 num_ctl_values = mixer_ctl_get_num_values(ctl);
1715 for (i = 0; i < num_ctl_values; i++) {
1716 if (mixer_ctl_set_value(ctl, i, session_id)) {
1717 ALOGV("Error: invalid session_id: %x", session_id);
1718 ret = -EINVAL;
1719 break;
1720 }
1721 }
1722 }
1723
1724 if (my_data->csd != NULL) {
1725 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
1726 if (ret < 0) {
1727 ALOGE("%s: csd_client_start_record failed, error %d",
1728 __func__, ret);
1729 }
1730 }
1731
1732 return ret;
1733}
1734
1735int platform_stop_incall_recording_usecase(void *platform)
1736{
1737 int ret = 0;
1738 struct platform_data *my_data = (struct platform_data *)platform;
1739
1740 if (my_data->csd != NULL) {
1741 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
1742 if (ret < 0) {
1743 ALOGE("%s: csd_client_stop_record failed, error %d",
1744 __func__, ret);
1745 }
1746 }
1747
1748 return ret;
1749}
1750
1751int platform_start_incall_music_usecase(void *platform)
1752{
1753 int ret = 0;
1754 struct platform_data *my_data = (struct platform_data *)platform;
1755
1756 if (my_data->csd != NULL) {
1757 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
1758 if (ret < 0) {
1759 ALOGE("%s: csd_client_start_playback failed, error %d",
1760 __func__, ret);
1761 }
1762 }
1763
1764 return ret;
1765}
1766
1767int platform_stop_incall_music_usecase(void *platform)
1768{
1769 int ret = 0;
1770 struct platform_data *my_data = (struct platform_data *)platform;
1771
1772 if (my_data->csd != NULL) {
1773 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
1774 if (ret < 0) {
1775 ALOGE("%s: csd_client_stop_playback failed, error %d",
1776 __func__, ret);
1777 }
1778 }
1779
1780 return ret;
1781}
1782
1783void platform_get_parameters(void *platform,
1784 struct str_parms *query,
1785 struct str_parms *reply)
1786{
1787 struct platform_data *my_data = (struct platform_data *)platform;
1788 char *str = NULL;
1789 char value[256] = {0};
1790 int ret;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301791
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301792 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_SLOWTALK,
1793 value, sizeof(value));
1794 if (ret >= 0) {
1795 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_SLOWTALK,
1796 my_data->slowtalk?"true":"false");
1797 }
1798
1799 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_VOLUME_BOOST,
1800 value, sizeof(value));
1801 if (ret >= 0) {
1802 if (my_data->voice_feature_set == VOICE_FEATURE_SET_VOLUME_BOOST) {
1803 strlcpy(value, "on", sizeof(value));
1804 } else {
1805 strlcpy(value, "off", sizeof(value));
1806 }
1807
1808 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_VOLUME_BOOST, value);
1809 }
1810
1811 ALOGV("%s: exit: returns - %s", __func__, str_parms_to_str(reply));
1812}
1813
1814/* Delay in Us */
1815int64_t platform_render_latency(audio_usecase_t usecase)
1816{
1817 switch (usecase) {
1818 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
1819 return DEEP_BUFFER_PLATFORM_DELAY;
1820 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
1821 return LOW_LATENCY_PLATFORM_DELAY;
1822 default:
1823 return 0;
1824 }
1825}
1826
1827int platform_update_usecase_from_source(int source, int usecase)
1828{
1829 ALOGV("%s: input source :%d", __func__, source);
1830 if(source == AUDIO_SOURCE_FM_RX_A2DP)
1831 usecase = USECASE_AUDIO_RECORD_FM_VIRTUAL;
1832 return usecase;
1833}
1834
1835bool platform_listen_update_status(snd_device_t snd_device)
1836{
1837 if ((snd_device >= SND_DEVICE_IN_BEGIN) &&
1838 (snd_device < SND_DEVICE_IN_END) &&
1839 (snd_device != SND_DEVICE_IN_CAPTURE_FM) &&
1840 (snd_device != SND_DEVICE_IN_CAPTURE_VI_FEEDBACK))
1841 return true;
1842 else
1843 return false;
1844}
1845
1846/* Read offload buffer size from a property.
1847 * If value is not power of 2 round it to
1848 * power of 2.
1849 */
1850uint32_t platform_get_compress_offload_buffer_size(audio_offload_info_t* info)
1851{
1852 char value[PROPERTY_VALUE_MAX] = {0};
1853 uint32_t fragment_size = COMPRESS_OFFLOAD_FRAGMENT_SIZE;
1854 if((property_get("audio.offload.buffer.size.kb", value, "")) &&
1855 atoi(value)) {
1856 fragment_size = atoi(value) * 1024;
1857 }
1858
1859 if (info != NULL && info->has_video && info->is_streaming) {
1860 fragment_size = COMPRESS_OFFLOAD_FRAGMENT_SIZE_FOR_AV_STREAMING;
1861 ALOGV("%s: offload fragment size reduced for AV streaming to %d",
1862 __func__, out->compr_config.fragment_size);
1863 }
1864
1865 fragment_size = ALIGN( fragment_size, 1024);
1866
1867 if(fragment_size < MIN_COMPRESS_OFFLOAD_FRAGMENT_SIZE)
1868 fragment_size = MIN_COMPRESS_OFFLOAD_FRAGMENT_SIZE;
1869 else if(fragment_size > MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE)
1870 fragment_size = MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE;
1871 ALOGV("%s: fragment_size %d", __func__, fragment_size);
1872 return fragment_size;
1873}
1874
1875uint32_t platform_get_pcm_offload_buffer_size(audio_offload_info_t* info)
1876{
1877 uint32_t fragment_size = MIN_PCM_OFFLOAD_FRAGMENT_SIZE;
1878 uint32_t bits_per_sample = 16;
1879
1880 if (info->format == AUDIO_FORMAT_PCM_24_BIT_OFFLOAD) {
1881 bits_per_sample = 32;
1882 }
1883
1884 if (!info->has_video) {
1885 fragment_size = MAX_PCM_OFFLOAD_FRAGMENT_SIZE;
1886
1887 } else if (info->has_video && info->is_streaming) {
1888 fragment_size = (PCM_OFFLOAD_BUFFER_DURATION_FOR_AV_STREAMING
1889 * info->sample_rate
1890 * bits_per_sample
1891 * popcount(info->channel_mask))/1000;
1892
1893 } else if (info->has_video) {
1894 fragment_size = (PCM_OFFLOAD_BUFFER_DURATION_FOR_AV
1895 * info->sample_rate
1896 * bits_per_sample
1897 * popcount(info->channel_mask))/1000;
1898 }
1899
1900 fragment_size = ALIGN( fragment_size, 1024);
1901
1902 if(fragment_size < MIN_PCM_OFFLOAD_FRAGMENT_SIZE)
1903 fragment_size = MIN_PCM_OFFLOAD_FRAGMENT_SIZE;
1904 else if(fragment_size > MAX_PCM_OFFLOAD_FRAGMENT_SIZE)
1905 fragment_size = MAX_PCM_OFFLOAD_FRAGMENT_SIZE;
1906
1907 ALOGV("%s: fragment_size %d", __func__, fragment_size);
1908 return fragment_size;
1909}
1910