blob: d8cefda479cfa18025cc9a76ae02bc2ebcf9d5fe [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);
Dhananjay Kumar89ea3bd2014-04-29 15:45:57 +0530709
710 audio_extn_dolby_set_license(adev);
711
Naresh Tannirue3b18452014-03-04 14:44:27 +0530712 return my_data;
713}
714
715void platform_deinit(void *platform)
716{
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530717 struct platform_data *my_data = (struct platform_data *)platform;
718
719 hw_info_deinit(my_data->hw_info);
720 close_csd_client(my_data->csd);
721
Naresh Tannirue3b18452014-03-04 14:44:27 +0530722 free(platform);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530723 /* deinit usb */
724 audio_extn_usb_deinit();
Naresh Tannirue3b18452014-03-04 14:44:27 +0530725}
726
727const char *platform_get_snd_device_name(snd_device_t snd_device)
728{
729 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX)
730 return device_table[snd_device];
731 else
732 return "";
733}
734
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530735int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
736 char *device_name)
737{
738 struct platform_data *my_data = (struct platform_data *)platform;
739
740 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
741 strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE);
742 hw_info_append_hw_type(my_data->hw_info, snd_device, device_name);
743 } else {
744 strlcpy(device_name, "", DEVICE_NAME_MAX_SIZE);
745 return -EINVAL;
746 }
747
748 return 0;
749}
750
Naresh Tannirue3b18452014-03-04 14:44:27 +0530751void platform_add_backend_name(char *mixer_path, snd_device_t snd_device)
752{
753 if (snd_device == SND_DEVICE_IN_BT_SCO_MIC)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530754 strlcat(mixer_path, " bt-sco", MIXER_PATH_MAX_LENGTH);
755 else if (snd_device == SND_DEVICE_IN_BT_SCO_MIC_WB)
756 strlcat(mixer_path, " bt-sco-wb", MIXER_PATH_MAX_LENGTH);
Naresh Tannirue3b18452014-03-04 14:44:27 +0530757 else if(snd_device == SND_DEVICE_OUT_BT_SCO)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530758 strlcat(mixer_path, " bt-sco", MIXER_PATH_MAX_LENGTH);
759 else if(snd_device == SND_DEVICE_OUT_BT_SCO_WB)
760 strlcat(mixer_path, " bt-sco-wb", MIXER_PATH_MAX_LENGTH);
Naresh Tannirue3b18452014-03-04 14:44:27 +0530761 else if (snd_device == SND_DEVICE_OUT_HDMI)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530762 strlcat(mixer_path, " hdmi", MIXER_PATH_MAX_LENGTH);
Naresh Tannirue3b18452014-03-04 14:44:27 +0530763 else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HDMI)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530764 strlcat(mixer_path, " speaker-and-hdmi", MIXER_PATH_MAX_LENGTH);
765 else if (snd_device == SND_DEVICE_OUT_AFE_PROXY)
766 strlcat(mixer_path, " afe-proxy", MIXER_PATH_MAX_LENGTH);
767 else if (snd_device == SND_DEVICE_OUT_USB_HEADSET)
768 strlcat(mixer_path, " usb-headphones", MIXER_PATH_MAX_LENGTH);
769 else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET)
770 strlcat(mixer_path, " speaker-and-usb-headphones",
771 MIXER_PATH_MAX_LENGTH);
772 else if (snd_device == SND_DEVICE_IN_USB_HEADSET_MIC)
773 strlcat(mixer_path, " usb-headset-mic", MIXER_PATH_MAX_LENGTH);
774 else if (snd_device == SND_DEVICE_IN_CAPTURE_FM)
775 strlcat(mixer_path, " capture-fm", MIXER_PATH_MAX_LENGTH);
776 else if (snd_device == SND_DEVICE_OUT_TRANSMISSION_FM)
777 strlcat(mixer_path, " transmission-fm", MIXER_PATH_MAX_LENGTH);
Naresh Tannirue3b18452014-03-04 14:44:27 +0530778}
779
780int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
781{
782 int device_id;
783 if (device_type == PCM_PLAYBACK)
784 device_id = pcm_device_table[usecase][0];
785 else
786 device_id = pcm_device_table[usecase][1];
787 return device_id;
788}
789
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530790int platform_get_snd_device_index(char *snd_device_index_name)
791{
792 int ret = 0;
793 int i;
794
795 if (snd_device_index_name == NULL) {
796 ALOGE("%s: snd_device_index_name is NULL", __func__);
797 ret = -ENODEV;
798 goto done;
799 }
800
801 for (i=0; i < SND_DEVICE_MAX; i++) {
802 if(strcmp(snd_device_name_index[i].name, snd_device_index_name) == 0) {
803 ret = snd_device_name_index[i].index;
804 goto done;
805 }
806 }
807 ALOGE("%s: Could not find index for snd_device_index_name = %s",
808 __func__, snd_device_index_name);
809 ret = -ENODEV;
810done:
811 return ret;
812}
813
Venkata Narendra Kumar Gutta88fd0bc2014-03-27 19:47:56 +0530814int platform_set_fluence_type(void *platform, char *value)
815{
816 int ret = 0;
817 int fluence_type = FLUENCE_NONE;
818 int fluence_flag = NONE_FLAG;
819 struct platform_data *my_data = (struct platform_data *)platform;
820 struct audio_device *adev = my_data->adev;
821
822 ALOGV("%s: fluence type:%d", __func__, my_data->fluence_type);
823
824 /* only dual mic turn on and off is supported as of now through setparameters */
825 if (!strncmp(AUDIO_PARAMETER_VALUE_DUALMIC,value, sizeof(AUDIO_PARAMETER_VALUE_DUALMIC))) {
826 if (!strncmp("fluencepro", my_data->fluence_cap, sizeof("fluencepro")) ||
827 !strncmp("fluence", my_data->fluence_cap, sizeof("fluence"))) {
828 ALOGV("fluence dualmic feature enabled \n");
829 fluence_type = FLUENCE_DUAL_MIC;
830 fluence_flag = DMIC_FLAG;
831 } else {
832 ALOGE("%s: Failed to set DUALMIC", __func__);
833 ret = -1;
834 goto done;
835 }
836 } else if (!strncmp(AUDIO_PARAMETER_KEY_NO_FLUENCE, value, sizeof(AUDIO_PARAMETER_KEY_NO_FLUENCE))) {
837 ALOGV("fluence disabled");
838 fluence_type = FLUENCE_NONE;
839 } else {
840 ALOGE("Invalid fluence value : %s",value);
841 ret = -1;
842 goto done;
843 }
844
845 if (fluence_type != my_data->fluence_type) {
846 ALOGV("%s: Updating fluence_type to :%d", __func__, fluence_type);
847 my_data->fluence_type = fluence_type;
848 adev->acdb_settings = (adev->acdb_settings & FLUENCE_MODE_CLEAR) | fluence_flag;
849 }
850done:
851 return ret;
852}
853
854int platform_get_fluence_type(void *platform, char *value, uint32_t len)
855{
856 int ret = 0;
857 struct platform_data *my_data = (struct platform_data *)platform;
858
859 if (my_data->fluence_type == FLUENCE_QUAD_MIC) {
860 strlcpy(value, "quadmic", len);
861 } else if (my_data->fluence_type == FLUENCE_DUAL_MIC) {
862 strlcpy(value, "dualmic", len);
863 } else if (my_data->fluence_type == FLUENCE_NONE) {
864 strlcpy(value, "none", len);
865 } else
866 ret = -1;
867
868 return ret;
869}
870
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530871int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
872{
873 int ret = 0;
874
875 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
876 ALOGE("%s: Invalid snd_device = %d",
877 __func__, snd_device);
878 ret = -EINVAL;
879 goto done;
880 }
881
882 acdb_device_table[snd_device] = acdb_id;
883done:
884 return ret;
885}
886
Naresh Tannirue3b18452014-03-04 14:44:27 +0530887int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
888{
889 struct platform_data *my_data = (struct platform_data *)platform;
890 int acdb_dev_id, acdb_dev_type;
891
892 acdb_dev_id = acdb_device_table[snd_device];
893 if (acdb_dev_id < 0) {
894 ALOGE("%s: Could not find acdb id for device(%d)",
895 __func__, snd_device);
896 return -EINVAL;
897 }
898 if (my_data->acdb_send_audio_cal) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530899 ("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530900 __func__, snd_device, acdb_dev_id);
901 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
902 snd_device < SND_DEVICE_OUT_END)
903 acdb_dev_type = ACDB_DEV_TYPE_OUT;
904 else
905 acdb_dev_type = ACDB_DEV_TYPE_IN;
906 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
907 }
908 return 0;
909}
910
911int platform_switch_voice_call_device_pre(void *platform)
912{
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530913 struct platform_data *my_data = (struct platform_data *)platform;
914 int ret = 0;
915
916 if (my_data->csd != NULL &&
917 my_data->adev->mode == AUDIO_MODE_IN_CALL) {
918 /* This must be called before disabling mixer controls on APQ side */
919 ret = my_data->csd->disable_device();
920 if (ret < 0) {
921 ALOGE("%s: csd_client_disable_device, failed, error %d",
922 __func__, ret);
923 }
924 }
925 return ret;
Naresh Tannirue3b18452014-03-04 14:44:27 +0530926}
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530927int platform_switch_voice_call_enable_device_config(void *platform,
928 snd_device_t out_snd_device,
929 snd_device_t in_snd_device)
930{
931 struct platform_data *my_data = (struct platform_data *)platform;
932 int acdb_rx_id, acdb_tx_id;
933 int ret = 0;
934
935 acdb_rx_id = acdb_device_table[out_snd_device];
936 acdb_tx_id = acdb_device_table[in_snd_device];
937
938 if (my_data->csd != NULL) {
939 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
940 ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
941 if (ret < 0) {
942 ALOGE("%s: csd_enable_device_config, failed, error %d",
943 __func__, ret);
944 }
945 } else {
946 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
947 acdb_rx_id, acdb_tx_id);
948 }
949 }
950 return ret;
951}
952
Naresh Tannirue3b18452014-03-04 14:44:27 +0530953
954int platform_switch_voice_call_device_post(void *platform,
955 snd_device_t out_snd_device,
956 snd_device_t in_snd_device)
957{
958 struct platform_data *my_data = (struct platform_data *)platform;
959 int acdb_rx_id, acdb_tx_id;
960
961 if (my_data->acdb_send_voice_cal == NULL) {
962 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
963 } else {
964 acdb_rx_id = acdb_device_table[out_snd_device];
965 acdb_tx_id = acdb_device_table[in_snd_device];
966
967 if (acdb_rx_id > 0 && acdb_tx_id > 0)
968 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
969 else
970 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
971 acdb_rx_id, acdb_tx_id);
972 }
973
974 return 0;
975}
976
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530977int platform_switch_voice_call_usecase_route_post(void *platform,
978 snd_device_t out_snd_device,
979 snd_device_t in_snd_device)
Naresh Tannirue3b18452014-03-04 14:44:27 +0530980{
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530981 struct platform_data *my_data = (struct platform_data *)platform;
982 int acdb_rx_id, acdb_tx_id;
983 int ret = 0;
984
985 acdb_rx_id = acdb_device_table[out_snd_device];
986 acdb_tx_id = acdb_device_table[in_snd_device];
987
988 if (my_data->csd != NULL) {
989 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
990 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
991 my_data->adev->acdb_settings);
992 if (ret < 0) {
993 ALOGE("%s: csd_enable_device, failed, error %d",
994 __func__, ret);
995 }
996 } else {
997 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
998 acdb_rx_id, acdb_tx_id);
999 }
1000 }
1001 return ret;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301002}
1003
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301004int platform_start_voice_call(void *platform, uint32_t vsid)
1005{
1006 struct platform_data *my_data = (struct platform_data *)platform;
1007 int ret = 0;
1008
1009 if (my_data->csd != NULL) {
1010 ret = my_data->csd->start_voice(vsid);
1011 if (ret < 0) {
1012 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
1013 }
1014 }
1015 return ret;
1016}
1017
1018int platform_stop_voice_call(void *platform, uint32_t vsid)
1019{
1020 struct platform_data *my_data = (struct platform_data *)platform;
1021 int ret = 0;
1022
1023 if (my_data->csd != NULL) {
1024 ret = my_data->csd->stop_voice(vsid);
1025 if (ret < 0) {
1026 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
1027 }
1028 }
1029 return ret;
1030}
1031int platform_get_sample_rate(void *platform, uint32_t *rate)
Naresh Tannirue3b18452014-03-04 14:44:27 +05301032{
1033 return 0;
1034}
1035
1036int platform_set_voice_volume(void *platform, int volume)
1037{
1038 struct platform_data *my_data = (struct platform_data *)platform;
1039 struct audio_device *adev = my_data->adev;
1040 struct mixer_ctl *ctl;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301041 const char *mixer_ctl_name = "Voice Rx Gain";
1042 int vol_index = 0, ret = 0;
1043 uint32_t set_values[ ] = {0,
1044 ALL_SESSION_VSID,
1045 DEFAULT_VOLUME_RAMP_DURATION_MS};
Naresh Tannirue3b18452014-03-04 14:44:27 +05301046
1047 // Voice volume levels are mapped to adsp volume levels as follows.
1048 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
1049 // But this values don't changed in kernel. So, below change is need.
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301050 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, MAX_VOL_INDEX);
1051 set_values[0] = vol_index;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301052
1053 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1054 if (!ctl) {
1055 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1056 __func__, mixer_ctl_name);
1057 return -EINVAL;
1058 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301059 ALOGV("Setting voice volume index: %d", set_values[0]);
1060 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
Naresh Tannirue3b18452014-03-04 14:44:27 +05301061
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301062 if (my_data->csd != NULL) {
1063 ret = my_data->csd->volume(ALL_SESSION_VSID, volume);
1064 if (ret < 0) {
1065 ALOGE("%s: csd_volume error %d", __func__, ret);
1066 }
1067 }
1068 return ret;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301069}
1070
1071int platform_set_mic_mute(void *platform, bool state)
1072{
1073 struct platform_data *my_data = (struct platform_data *)platform;
1074 struct audio_device *adev = my_data->adev;
1075 struct mixer_ctl *ctl;
1076 const char *mixer_ctl_name = "Voice Tx Mute";
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301077 int ret = 0;
1078 uint32_t set_values[ ] = {0,
1079 ALL_SESSION_VSID,
1080 DEFAULT_VOLUME_RAMP_DURATION_MS};
Naresh Tannirue3b18452014-03-04 14:44:27 +05301081
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301082 set_values[0] = state;
1083 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1084 if (!ctl) {
1085 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1086 __func__, mixer_ctl_name);
1087 return -EINVAL;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301088 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301089 ALOGV("Setting voice mute state: %d", state);
1090 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
Naresh Tannirue3b18452014-03-04 14:44:27 +05301091
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301092 if (my_data->csd != NULL) {
1093 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state);
1094 if (ret < 0) {
1095 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
1096 }
1097 }
1098 return ret;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301099}
1100
Shiv Maliyappanahallic6fd8ee2014-03-07 15:31:55 -08001101int platform_set_device_mute(void *platform, bool state, char *dir)
1102{
1103 struct platform_data *my_data = (struct platform_data *)platform;
1104 struct audio_device *adev = my_data->adev;
1105 struct mixer_ctl *ctl;
1106 char *mixer_ctl_name = NULL;
1107 int ret = 0;
1108 uint32_t set_values[ ] = {0,
1109 ALL_SESSION_VSID,
1110 0};
1111 if(dir == NULL) {
1112 ALOGE("%s: Invalid direction:%s", __func__, dir);
1113 return -EINVAL;
1114 }
1115
1116 if (!strncmp("rx", dir, sizeof("rx"))) {
1117 mixer_ctl_name = "Voice Rx Device Mute";
1118 } else if (!strncmp("tx", dir, sizeof("tx"))) {
1119 mixer_ctl_name = "Voice Tx Device Mute";
1120 } else {
1121 return -EINVAL;
1122 }
1123
1124 set_values[0] = state;
1125 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1126 if (!ctl) {
1127 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1128 __func__, mixer_ctl_name);
1129 return -EINVAL;
1130 }
1131
1132 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
1133 __func__,state, mixer_ctl_name);
1134 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1135
1136 return ret;
1137}
1138
Naresh Tannirue3b18452014-03-04 14:44:27 +05301139snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
1140{
1141 struct platform_data *my_data = (struct platform_data *)platform;
1142 struct audio_device *adev = my_data->adev;
1143 audio_mode_t mode = adev->mode;
1144 snd_device_t snd_device = SND_DEVICE_NONE;
1145
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301146 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
1147 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
1148 int channel_count = popcount(channel_mask);
1149
Naresh Tannirue3b18452014-03-04 14:44:27 +05301150 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
1151 if (devices == AUDIO_DEVICE_NONE ||
1152 devices & AUDIO_DEVICE_BIT_IN) {
1153 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
1154 goto exit;
1155 }
1156
Naresh Tannirue3b18452014-03-04 14:44:27 +05301157 if (popcount(devices) == 2) {
1158 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
1159 AUDIO_DEVICE_OUT_SPEAKER)) {
1160 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
1161 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
1162 AUDIO_DEVICE_OUT_SPEAKER)) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301163 if (audio_extn_get_anc_enabled())
1164 snd_device = SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET;
1165 else
1166 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301167 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
1168 AUDIO_DEVICE_OUT_SPEAKER)) {
1169 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301170 } else if (devices == (AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET |
1171 AUDIO_DEVICE_OUT_SPEAKER)) {
1172 snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301173 } else {
1174 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
1175 goto exit;
1176 }
1177 if (snd_device != SND_DEVICE_NONE) {
1178 goto exit;
1179 }
1180 }
1181
1182 if (popcount(devices) != 1) {
1183 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
1184 goto exit;
1185 }
1186
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301187 if ((mode == AUDIO_MODE_IN_CALL) ||
1188 voice_extn_compress_voip_is_active(adev)) {
1189 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1190 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
1191 if ((adev->voice.tty_mode != TTY_MODE_OFF) &&
1192 !voice_extn_compress_voip_is_active(adev)) {
1193 switch (adev->voice.tty_mode) {
1194 case TTY_MODE_FULL:
1195 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
1196 break;
1197 case TTY_MODE_VCO:
1198 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
1199 break;
1200 case TTY_MODE_HCO:
1201 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
1202 break;
1203 default:
1204 ALOGE("%s: Invalid TTY mode (%#x)",
1205 __func__, adev->voice.tty_mode);
1206 }
1207 } else if (audio_extn_get_anc_enabled()) {
1208 if (audio_extn_should_use_fb_anc())
1209 snd_device = SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET;
1210 else
1211 snd_device = SND_DEVICE_OUT_VOICE_ANC_HEADSET;
1212 } else {
1213 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
1214 }
1215 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
1216 if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ)
1217 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
1218 else
1219 snd_device = SND_DEVICE_OUT_BT_SCO;
1220 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
1221 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
1222 } else if (devices & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
1223 devices & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
1224 snd_device = SND_DEVICE_OUT_USB_HEADSET;
1225 } else if (devices & AUDIO_DEVICE_OUT_FM_TX) {
1226 snd_device = SND_DEVICE_OUT_TRANSMISSION_FM;
1227 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
1228 if (audio_extn_should_use_handset_anc(channel_count))
1229 snd_device = SND_DEVICE_OUT_ANC_HANDSET;
1230 else
1231 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
1232 }
1233 if (snd_device != SND_DEVICE_NONE) {
1234 goto exit;
1235 }
1236 }
1237
Naresh Tannirue3b18452014-03-04 14:44:27 +05301238 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1239 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301240 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADSET
1241 && audio_extn_get_anc_enabled()) {
1242 if (audio_extn_should_use_fb_anc())
1243 snd_device = SND_DEVICE_OUT_ANC_FB_HEADSET;
1244 else
1245 snd_device = SND_DEVICE_OUT_ANC_HEADSET;
1246 }
1247 else
1248 snd_device = SND_DEVICE_OUT_HEADPHONES;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301249 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
1250 if (adev->speaker_lr_swap)
1251 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
1252 else
1253 snd_device = SND_DEVICE_OUT_SPEAKER;
1254 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301255 if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ)
1256 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
1257 else
1258 snd_device = SND_DEVICE_OUT_BT_SCO;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301259 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
1260 snd_device = SND_DEVICE_OUT_HDMI ;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301261 } else if (devices & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
1262 devices & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
Mingming Yin5a7c5d62014-03-05 17:45:03 -08001263 ALOGD("%s: setting USB hadset channel capability(2) for Proxy", __func__);
1264 audio_extn_set_afe_proxy_channel_mixer(adev, 2);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301265 snd_device = SND_DEVICE_OUT_USB_HEADSET;
1266 } else if (devices & AUDIO_DEVICE_OUT_FM_TX) {
1267 snd_device = SND_DEVICE_OUT_TRANSMISSION_FM;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301268 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
1269 snd_device = SND_DEVICE_OUT_HANDSET;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301270 } else if (devices & AUDIO_DEVICE_OUT_PROXY) {
Mingming Yin5a7c5d62014-03-05 17:45:03 -08001271 channel_count = audio_extn_get_afe_proxy_channel_count();
1272 ALOGD("%s: setting sink capability(%d) for Proxy", __func__, channel_count);
1273 audio_extn_set_afe_proxy_channel_mixer(adev, channel_count);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301274 snd_device = SND_DEVICE_OUT_AFE_PROXY;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301275 } else {
1276 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
1277 }
1278exit:
1279 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
1280 return snd_device;
1281}
1282
1283snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
1284{
1285 struct platform_data *my_data = (struct platform_data *)platform;
1286 struct audio_device *adev = my_data->adev;
1287 audio_source_t source = (adev->active_input == NULL) ?
1288 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
1289
1290 audio_mode_t mode = adev->mode;
1291 audio_devices_t in_device = ((adev->active_input == NULL) ?
1292 AUDIO_DEVICE_NONE : adev->active_input->device)
1293 & ~AUDIO_DEVICE_BIT_IN;
1294 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
1295 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
1296 snd_device_t snd_device = SND_DEVICE_NONE;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301297 int channel_count = popcount(channel_mask);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301298
1299 ALOGV("%s: enter: out_device(%#x) in_device(%#x)",
1300 __func__, out_device, in_device);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301301 if ((out_device != AUDIO_DEVICE_NONE) && ((mode == AUDIO_MODE_IN_CALL) ||
1302 voice_extn_compress_voip_is_active(adev))) {
1303 if ((adev->voice.tty_mode != TTY_MODE_OFF) &&
1304 !voice_extn_compress_voip_is_active(adev)) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301305 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1306 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301307 switch (adev->voice.tty_mode) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301308 case TTY_MODE_FULL:
1309 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
1310 break;
1311 case TTY_MODE_VCO:
1312 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
1313 break;
1314 case TTY_MODE_HCO:
1315 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
1316 break;
1317 default:
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301318 ALOGE("%s: Invalid TTY mode (%#x)",
1319 __func__, adev->voice.tty_mode);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301320 }
1321 goto exit;
1322 }
1323 }
1324 if (out_device & AUDIO_DEVICE_OUT_EARPIECE ||
1325 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301326 if (out_device & AUDIO_DEVICE_OUT_EARPIECE &&
1327 audio_extn_should_use_handset_anc(channel_count)) {
1328 snd_device = SND_DEVICE_IN_AANC_HANDSET_MIC;
1329 } else if (my_data->fluence_type == FLUENCE_NONE ||
1330 my_data->fluence_in_voice_call == false) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301331 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301332 set_echo_reference(adev->mixer, EC_REF_RX);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301333 } else {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301334 snd_device = SND_DEVICE_IN_VOICE_DMIC;
1335 adev->acdb_settings |= DMIC_FLAG;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301336 }
1337 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
1338 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
Satya Krishna Pindiproli624c7802014-04-11 11:33:27 +05301339 set_echo_reference(adev->mixer, EC_REF_RX);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301340 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301341 if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ)
1342 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
1343 else
1344 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301345 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301346 if (my_data->fluence_type != FLUENCE_NONE &&
1347 my_data->fluence_in_voice_call &&
1348 my_data->fluence_in_spkr_mode) {
1349 if(my_data->fluence_type & FLUENCE_QUAD_MIC) {
1350 adev->acdb_settings |= QMIC_FLAG;
1351 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_QMIC;
1352 } else {
1353 adev->acdb_settings |= DMIC_FLAG;
1354 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
1355 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05301356 } else {
1357 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
Satya Krishna Pindiproli624c7802014-04-11 11:33:27 +05301358 set_echo_reference(adev->mixer, EC_REF_RX);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301359 }
1360 }
1361 } else if (source == AUDIO_SOURCE_CAMCORDER) {
1362 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
1363 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
1364 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
1365 }
1366 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
1367 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301368 if (channel_count == 2) {
1369 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
1370 adev->acdb_settings |= DMIC_FLAG;
1371 } else if (adev->active_input->enable_ns)
1372 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
1373 else if (my_data->fluence_type != FLUENCE_NONE &&
1374 my_data->fluence_in_voice_rec) {
1375 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
1376 adev->acdb_settings |= DMIC_FLAG;
1377 } else {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301378 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
1379 }
1380 }
1381 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION) {
1382 if (out_device & AUDIO_DEVICE_OUT_SPEAKER)
1383 in_device = AUDIO_DEVICE_IN_BACK_MIC;
1384 if (adev->active_input) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301385 if (adev->active_input->enable_aec &&
1386 adev->active_input->enable_ns) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301387 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301388 if (my_data->fluence_type & FLUENCE_DUAL_MIC &&
1389 my_data->fluence_in_spkr_mode) {
1390 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
1391 adev->acdb_settings |= DMIC_FLAG;
1392 } else
1393 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301394 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301395 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1396 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
1397 adev->acdb_settings |= DMIC_FLAG;
1398 } else
1399 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301400 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301401 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301402 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301403 set_echo_reference(adev->mixer, EC_REF_RX);
1404 } else if (adev->active_input->enable_aec) {
1405 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
1406 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1407 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
1408 adev->acdb_settings |= DMIC_FLAG;
1409 } else
1410 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
1411 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
1412 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1413 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
1414 adev->acdb_settings |= DMIC_FLAG;
1415 } else
1416 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
1417 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
1418 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
1419 }
1420 set_echo_reference(adev->mixer, EC_REF_RX);
1421 } else if (adev->active_input->enable_ns) {
1422 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
1423 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1424 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
1425 adev->acdb_settings |= DMIC_FLAG;
1426 } else
1427 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
1428 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
1429 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1430 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
1431 adev->acdb_settings |= DMIC_FLAG;
1432 } else
1433 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
1434 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
1435 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
1436 }
1437 set_echo_reference(adev->mixer, "NONE");
Naresh Tannirue3b18452014-03-04 14:44:27 +05301438 } else
1439 set_echo_reference(adev->mixer, "NONE");
1440 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301441 } else if (source == AUDIO_SOURCE_MIC) {
1442 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC &&
1443 channel_count == 1 ) {
1444 if(my_data->fluence_type & FLUENCE_DUAL_MIC &&
1445 my_data->fluence_in_audio_rec)
1446 snd_device = SND_DEVICE_IN_HANDSET_DMIC;
1447 }
1448 } else if (source == AUDIO_SOURCE_FM_RX ||
1449 source == AUDIO_SOURCE_FM_RX_A2DP) {
1450 snd_device = SND_DEVICE_IN_CAPTURE_FM;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301451 } else if (source == AUDIO_SOURCE_DEFAULT) {
1452 goto exit;
1453 }
1454
1455
1456 if (snd_device != SND_DEVICE_NONE) {
1457 goto exit;
1458 }
1459
1460 if (in_device != AUDIO_DEVICE_NONE &&
1461 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
1462 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
1463 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301464 if (audio_extn_ssr_get_enabled() && channel_count == 6)
1465 snd_device = SND_DEVICE_IN_QUAD_MIC;
1466 else if (channel_count == 2)
1467 snd_device = SND_DEVICE_IN_HANDSET_STEREO_DMIC;
1468 else
1469 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301470 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
1471 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
1472 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
1473 snd_device = SND_DEVICE_IN_HEADSET_MIC;
1474 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301475 if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ)
1476 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
1477 else
1478 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301479 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
1480 snd_device = SND_DEVICE_IN_HDMI_MIC;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301481 } else if (in_device & AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET ||
1482 in_device & AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET) {
1483 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
1484 } else if (in_device & AUDIO_DEVICE_IN_FM_RX) {
1485 snd_device = SND_DEVICE_IN_CAPTURE_FM;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301486 } else {
1487 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
1488 ALOGW("%s: Using default handset-mic", __func__);
1489 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1490 }
1491 } else {
1492 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
1493 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1494 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
1495 snd_device = SND_DEVICE_IN_HEADSET_MIC;
1496 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301497 if (channel_count > 1)
1498 snd_device = SND_DEVICE_IN_SPEAKER_STEREO_DMIC;
1499 else
1500 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301501 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
1502 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1503 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301504 if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ)
1505 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
1506 else
1507 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301508 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
1509 snd_device = SND_DEVICE_IN_HDMI_MIC;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301510 } else if (out_device & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
1511 out_device & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
1512 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301513 } else {
1514 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
1515 ALOGW("%s: Using default handset-mic", __func__);
1516 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1517 }
1518 }
1519exit:
1520 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
1521 return snd_device;
1522}
1523
1524int platform_set_hdmi_channels(void *platform, int channel_count)
1525{
1526 struct platform_data *my_data = (struct platform_data *)platform;
1527 struct audio_device *adev = my_data->adev;
1528 struct mixer_ctl *ctl;
1529 const char *channel_cnt_str = NULL;
1530 const char *mixer_ctl_name = "HDMI_RX Channels";
1531 switch (channel_count) {
1532 case 8:
1533 channel_cnt_str = "Eight"; break;
1534 case 7:
1535 channel_cnt_str = "Seven"; break;
1536 case 6:
1537 channel_cnt_str = "Six"; break;
1538 case 5:
1539 channel_cnt_str = "Five"; break;
1540 case 4:
1541 channel_cnt_str = "Four"; break;
1542 case 3:
1543 channel_cnt_str = "Three"; break;
1544 default:
1545 channel_cnt_str = "Two"; break;
1546 }
1547 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1548 if (!ctl) {
1549 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1550 __func__, mixer_ctl_name);
1551 return -EINVAL;
1552 }
1553 ALOGV("HDMI channel count: %s", channel_cnt_str);
1554 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
1555 return 0;
1556}
1557
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301558int platform_edid_get_max_channels(void *platform)
Naresh Tannirue3b18452014-03-04 14:44:27 +05301559{
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301560 struct platform_data *my_data = (struct platform_data *)platform;
1561 struct audio_device *adev = my_data->adev;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301562 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
1563 char *sad = block;
1564 int num_audio_blocks;
1565 int channel_count;
1566 int max_channels = 0;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301567 int i, ret, count;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301568
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301569 struct mixer_ctl *ctl;
1570
1571 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
1572 if (!ctl) {
1573 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1574 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301575 return 0;
1576 }
1577
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301578 mixer_ctl_update(ctl);
1579
1580 count = mixer_ctl_get_num_values(ctl);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301581
1582 /* Read SAD blocks, clamping the maximum size for safety */
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301583 if (count > (int)sizeof(block))
1584 count = (int)sizeof(block);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301585
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301586 ret = mixer_ctl_get_array(ctl, block, count);
1587 if (ret != 0) {
1588 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
1589 return 0;
1590 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05301591
1592 /* Calculate the number of SAD blocks */
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301593 num_audio_blocks = count / SAD_BLOCK_SIZE;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301594
1595 for (i = 0; i < num_audio_blocks; i++) {
1596 /* Only consider LPCM blocks */
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301597 if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
1598 sad += 3;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301599 continue;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301600 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05301601
1602 channel_count = (sad[0] & 0x7) + 1;
1603 if (channel_count > max_channels)
1604 max_channels = channel_count;
1605
1606 /* Advance to next block */
1607 sad += 3;
1608 }
1609
1610 return max_channels;
1611}
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301612
1613static int platform_set_slowtalk(struct platform_data *my_data, bool state)
1614{
1615 int ret = 0;
1616 struct audio_device *adev = my_data->adev;
1617 struct mixer_ctl *ctl;
1618 const char *mixer_ctl_name = "Slowtalk Enable";
1619 uint32_t set_values[ ] = {0,
1620 ALL_SESSION_VSID};
1621
1622 set_values[0] = state;
1623 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1624 if (!ctl) {
1625 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1626 __func__, mixer_ctl_name);
1627 ret = -EINVAL;
1628 } else {
1629 ALOGV("Setting slowtalk state: %d", state);
1630 ret = mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1631 my_data->slowtalk = state;
1632 }
1633
1634 if (my_data->csd != NULL) {
1635 ret = my_data->csd->slow_talk(ALL_SESSION_VSID, state);
1636 if (ret < 0) {
1637 ALOGE("%s: csd_client_disable_device, failed, error %d",
1638 __func__, ret);
1639 }
1640 }
1641 return ret;
1642}
1643
1644int platform_set_parameters(void *platform, struct str_parms *parms)
1645{
1646 struct platform_data *my_data = (struct platform_data *)platform;
1647 char *str;
1648 char value[256] = {0};
1649 int val;
1650 int ret = 0, err;
1651
1652 ALOGV("%s: enter: %s", __func__, str_parms_to_str(parms));
1653
1654 err = str_parms_get_int(parms, AUDIO_PARAMETER_KEY_BTSCO, &val);
1655 if (err >= 0) {
1656 str_parms_del(parms, AUDIO_PARAMETER_KEY_BTSCO);
1657 my_data->btsco_sample_rate = val;
1658 if (val == SAMPLE_RATE_16KHZ) {
Haynes Mathew George1376ca62014-04-24 11:55:48 -07001659 audio_route_apply_and_update_path(my_data->adev->audio_route,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301660 "bt-sco-wb-samplerate");
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301661 }
1662 }
1663
1664 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_SLOWTALK, value, sizeof(value));
1665 if (err >= 0) {
1666 bool state = false;
1667 if (!strncmp("true", value, sizeof("true"))) {
1668 state = true;
1669 }
1670
1671 str_parms_del(parms, AUDIO_PARAMETER_KEY_SLOWTALK);
1672 ret = platform_set_slowtalk(my_data, state);
1673 if (ret)
1674 ALOGE("%s: Failed to set slow talk err: %d", __func__, ret);
1675 }
1676
1677 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_VOLUME_BOOST,
1678 value, sizeof(value));
1679 if (err >= 0) {
1680 str_parms_del(parms, AUDIO_PARAMETER_KEY_VOLUME_BOOST);
1681
1682 if (my_data->acdb_reload_vocvoltable == NULL) {
1683 ALOGE("%s: acdb_reload_vocvoltable is NULL", __func__);
1684 } else if (!strcmp(value, "on")) {
1685 if (!my_data->acdb_reload_vocvoltable(VOICE_FEATURE_SET_VOLUME_BOOST)) {
1686 my_data->voice_feature_set = 1;
1687 }
1688 } else {
1689 if (!my_data->acdb_reload_vocvoltable(VOICE_FEATURE_SET_DEFAULT)) {
1690 my_data->voice_feature_set = 0;
1691 }
1692 }
1693 }
1694
1695 ALOGV("%s: exit with code(%d)", __func__, ret);
1696 return ret;
1697}
1698
1699int platform_set_incall_recording_session_id(void *platform,
1700 uint32_t session_id, int rec_mode)
1701{
1702 int ret = 0;
1703 struct platform_data *my_data = (struct platform_data *)platform;
1704 struct audio_device *adev = my_data->adev;
1705 struct mixer_ctl *ctl;
1706 const char *mixer_ctl_name = "Voc VSID";
1707 int num_ctl_values;
1708 int i;
1709
1710 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1711 if (!ctl) {
1712 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1713 __func__, mixer_ctl_name);
1714 ret = -EINVAL;
1715 } else {
1716 num_ctl_values = mixer_ctl_get_num_values(ctl);
1717 for (i = 0; i < num_ctl_values; i++) {
1718 if (mixer_ctl_set_value(ctl, i, session_id)) {
1719 ALOGV("Error: invalid session_id: %x", session_id);
1720 ret = -EINVAL;
1721 break;
1722 }
1723 }
1724 }
1725
1726 if (my_data->csd != NULL) {
1727 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
1728 if (ret < 0) {
1729 ALOGE("%s: csd_client_start_record failed, error %d",
1730 __func__, ret);
1731 }
1732 }
1733
1734 return ret;
1735}
1736
1737int platform_stop_incall_recording_usecase(void *platform)
1738{
1739 int ret = 0;
1740 struct platform_data *my_data = (struct platform_data *)platform;
1741
1742 if (my_data->csd != NULL) {
1743 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
1744 if (ret < 0) {
1745 ALOGE("%s: csd_client_stop_record failed, error %d",
1746 __func__, ret);
1747 }
1748 }
1749
1750 return ret;
1751}
1752
1753int platform_start_incall_music_usecase(void *platform)
1754{
1755 int ret = 0;
1756 struct platform_data *my_data = (struct platform_data *)platform;
1757
1758 if (my_data->csd != NULL) {
1759 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
1760 if (ret < 0) {
1761 ALOGE("%s: csd_client_start_playback failed, error %d",
1762 __func__, ret);
1763 }
1764 }
1765
1766 return ret;
1767}
1768
1769int platform_stop_incall_music_usecase(void *platform)
1770{
1771 int ret = 0;
1772 struct platform_data *my_data = (struct platform_data *)platform;
1773
1774 if (my_data->csd != NULL) {
1775 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
1776 if (ret < 0) {
1777 ALOGE("%s: csd_client_stop_playback failed, error %d",
1778 __func__, ret);
1779 }
1780 }
1781
1782 return ret;
1783}
1784
1785void platform_get_parameters(void *platform,
1786 struct str_parms *query,
1787 struct str_parms *reply)
1788{
1789 struct platform_data *my_data = (struct platform_data *)platform;
1790 char *str = NULL;
1791 char value[256] = {0};
1792 int ret;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301793
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301794 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_SLOWTALK,
1795 value, sizeof(value));
1796 if (ret >= 0) {
1797 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_SLOWTALK,
1798 my_data->slowtalk?"true":"false");
1799 }
1800
1801 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_VOLUME_BOOST,
1802 value, sizeof(value));
1803 if (ret >= 0) {
1804 if (my_data->voice_feature_set == VOICE_FEATURE_SET_VOLUME_BOOST) {
1805 strlcpy(value, "on", sizeof(value));
1806 } else {
1807 strlcpy(value, "off", sizeof(value));
1808 }
1809
1810 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_VOLUME_BOOST, value);
1811 }
1812
1813 ALOGV("%s: exit: returns - %s", __func__, str_parms_to_str(reply));
1814}
1815
1816/* Delay in Us */
1817int64_t platform_render_latency(audio_usecase_t usecase)
1818{
1819 switch (usecase) {
1820 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
1821 return DEEP_BUFFER_PLATFORM_DELAY;
1822 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
1823 return LOW_LATENCY_PLATFORM_DELAY;
1824 default:
1825 return 0;
1826 }
1827}
1828
1829int platform_update_usecase_from_source(int source, int usecase)
1830{
1831 ALOGV("%s: input source :%d", __func__, source);
1832 if(source == AUDIO_SOURCE_FM_RX_A2DP)
1833 usecase = USECASE_AUDIO_RECORD_FM_VIRTUAL;
1834 return usecase;
1835}
1836
1837bool platform_listen_update_status(snd_device_t snd_device)
1838{
1839 if ((snd_device >= SND_DEVICE_IN_BEGIN) &&
1840 (snd_device < SND_DEVICE_IN_END) &&
1841 (snd_device != SND_DEVICE_IN_CAPTURE_FM) &&
1842 (snd_device != SND_DEVICE_IN_CAPTURE_VI_FEEDBACK))
1843 return true;
1844 else
1845 return false;
1846}
1847
1848/* Read offload buffer size from a property.
1849 * If value is not power of 2 round it to
1850 * power of 2.
1851 */
1852uint32_t platform_get_compress_offload_buffer_size(audio_offload_info_t* info)
1853{
1854 char value[PROPERTY_VALUE_MAX] = {0};
1855 uint32_t fragment_size = COMPRESS_OFFLOAD_FRAGMENT_SIZE;
1856 if((property_get("audio.offload.buffer.size.kb", value, "")) &&
1857 atoi(value)) {
1858 fragment_size = atoi(value) * 1024;
1859 }
1860
1861 if (info != NULL && info->has_video && info->is_streaming) {
1862 fragment_size = COMPRESS_OFFLOAD_FRAGMENT_SIZE_FOR_AV_STREAMING;
1863 ALOGV("%s: offload fragment size reduced for AV streaming to %d",
1864 __func__, out->compr_config.fragment_size);
1865 }
1866
1867 fragment_size = ALIGN( fragment_size, 1024);
1868
1869 if(fragment_size < MIN_COMPRESS_OFFLOAD_FRAGMENT_SIZE)
1870 fragment_size = MIN_COMPRESS_OFFLOAD_FRAGMENT_SIZE;
1871 else if(fragment_size > MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE)
1872 fragment_size = MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE;
1873 ALOGV("%s: fragment_size %d", __func__, fragment_size);
1874 return fragment_size;
1875}
1876
1877uint32_t platform_get_pcm_offload_buffer_size(audio_offload_info_t* info)
1878{
1879 uint32_t fragment_size = MIN_PCM_OFFLOAD_FRAGMENT_SIZE;
1880 uint32_t bits_per_sample = 16;
1881
1882 if (info->format == AUDIO_FORMAT_PCM_24_BIT_OFFLOAD) {
1883 bits_per_sample = 32;
1884 }
1885
1886 if (!info->has_video) {
1887 fragment_size = MAX_PCM_OFFLOAD_FRAGMENT_SIZE;
1888
1889 } else if (info->has_video && info->is_streaming) {
1890 fragment_size = (PCM_OFFLOAD_BUFFER_DURATION_FOR_AV_STREAMING
1891 * info->sample_rate
1892 * bits_per_sample
1893 * popcount(info->channel_mask))/1000;
1894
1895 } else if (info->has_video) {
1896 fragment_size = (PCM_OFFLOAD_BUFFER_DURATION_FOR_AV
1897 * info->sample_rate
1898 * bits_per_sample
1899 * popcount(info->channel_mask))/1000;
1900 }
1901
1902 fragment_size = ALIGN( fragment_size, 1024);
1903
1904 if(fragment_size < MIN_PCM_OFFLOAD_FRAGMENT_SIZE)
1905 fragment_size = MIN_PCM_OFFLOAD_FRAGMENT_SIZE;
1906 else if(fragment_size > MAX_PCM_OFFLOAD_FRAGMENT_SIZE)
1907 fragment_size = MAX_PCM_OFFLOAD_FRAGMENT_SIZE;
1908
1909 ALOGV("%s: fragment_size %d", __func__, fragment_size);
1910 return fragment_size;
1911}
1912