blob: 8f11acd3ccb89e3e0fcbeb10a702531e2fb89ff2 [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"
Walter Yang7ca90d92014-05-06 17:48:02 +080037#define MIXER_XML_PATH_QRD_SKUH "/system/etc/mixer_paths_qrd_skuh.xml"
38#define MIXER_XML_PATH_QRD_SKUI "/system/etc/mixer_paths_qrd_skui.xml"
Naresh Tannirudb72d1e2014-03-05 17:33:47 +053039#define MIXER_XML_PATH_AUXPCM "/system/etc/mixer_paths_auxpcm.xml"
40#define PLATFORM_INFO_XML_PATH "/system/etc/audio_platform_info.xml"
Naresh Tannirue3b18452014-03-04 14:44:27 +053041#define LIB_ACDB_LOADER "libacdbloader.so"
Naresh Tannirudb72d1e2014-03-05 17:33:47 +053042#define AUDIO_DATA_BLOCK_MIXER_CTL "HDMI EDID"
Naresh Tannirue3b18452014-03-04 14:44:27 +053043
Naresh Tannirudb72d1e2014-03-05 17:33:47 +053044#define MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE (256 * 1024)
45#define MIN_COMPRESS_OFFLOAD_FRAGMENT_SIZE (2 * 1024)
46#define COMPRESS_OFFLOAD_FRAGMENT_SIZE_FOR_AV_STREAMING (2 * 1024)
47#define COMPRESS_OFFLOAD_FRAGMENT_SIZE (32 * 1024)
48/* Used in calculating fragment size for pcm offload */
49#define PCM_OFFLOAD_BUFFER_DURATION_FOR_AV 2000 /* 2 secs */
50#define PCM_OFFLOAD_BUFFER_DURATION_FOR_AV_STREAMING 100 /* 100 millisecs */
Naresh Tannirue3b18452014-03-04 14:44:27 +053051
Naresh Tannirudb72d1e2014-03-05 17:33:47 +053052/* MAX PCM fragment size cannot be increased further due
53 * to flinger's cblk size of 1mb,and it has to be a multiple of
54 * 24 - lcm of channels supported by DSP
Naresh Tannirue3b18452014-03-04 14:44:27 +053055 */
Naresh Tannirudb72d1e2014-03-05 17:33:47 +053056#define MAX_PCM_OFFLOAD_FRAGMENT_SIZE (240 * 1024)
57#define MIN_PCM_OFFLOAD_FRAGMENT_SIZE (32 * 1024)
Naresh Tannirue3b18452014-03-04 14:44:27 +053058
Naresh Tannirudb72d1e2014-03-05 17:33:47 +053059#define ALIGN( num, to ) (((num) + (to-1)) & (~(to-1)))
Naresh Tannirue3b18452014-03-04 14:44:27 +053060/*
61 * This file will have a maximum of 38 bytes:
62 *
63 * 4 bytes: number of audio blocks
64 * 4 bytes: total length of Short Audio Descriptor (SAD) blocks
65 * Maximum 10 * 3 bytes: SAD blocks
66 */
67#define MAX_SAD_BLOCKS 10
68#define SAD_BLOCK_SIZE 3
69
70/* EDID format ID for LPCM audio */
71#define EDID_FORMAT_LPCM 1
72
Naresh Tannirudb72d1e2014-03-05 17:33:47 +053073/* Retry for delay in FW loading*/
74#define RETRY_NUMBER 20
75#define RETRY_US 500000
76#define MAX_SND_CARD 8
77
78#define SAMPLE_RATE_8KHZ 8000
79#define SAMPLE_RATE_16KHZ 16000
80
81#define AUDIO_PARAMETER_KEY_FLUENCE_TYPE "fluence"
82#define AUDIO_PARAMETER_KEY_BTSCO "bt_samplerate"
83#define AUDIO_PARAMETER_KEY_SLOWTALK "st_enable"
84#define AUDIO_PARAMETER_KEY_VOLUME_BOOST "volume_boost"
85
86enum {
87 VOICE_FEATURE_SET_DEFAULT,
88 VOICE_FEATURE_SET_VOLUME_BOOST
89};
90
Naresh Tannirue3b18452014-03-04 14:44:27 +053091struct audio_block_header
92{
93 int reserved;
94 int length;
95};
96
Naresh Tannirudb72d1e2014-03-05 17:33:47 +053097/* Audio calibration related functions */
Naresh Tannirue3b18452014-03-04 14:44:27 +053098typedef void (*acdb_deallocate_t)();
Naresh Tannirudb72d1e2014-03-05 17:33:47 +053099typedef int (*acdb_init_t)(char *);
Naresh Tannirue3b18452014-03-04 14:44:27 +0530100typedef void (*acdb_send_audio_cal_t)(int, int);
101typedef void (*acdb_send_voice_cal_t)(int, int);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530102typedef int (*acdb_reload_vocvoltable_t)(int);
Naresh Tannirue3b18452014-03-04 14:44:27 +0530103
Naresh Tannirue3b18452014-03-04 14:44:27 +0530104struct platform_data {
105 struct audio_device *adev;
106 bool fluence_in_spkr_mode;
107 bool fluence_in_voice_call;
108 bool fluence_in_voice_rec;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530109 bool fluence_in_audio_rec;
110 int fluence_type;
Venkata Narendra Kumar Gutta88fd0bc2014-03-27 19:47:56 +0530111 char fluence_cap[PROPERTY_VALUE_MAX];
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530112 int btsco_sample_rate;
113 bool slowtalk;
114 /* Audio calibration related functions */
115 void *acdb_handle;
116 int voice_feature_set;
117 acdb_init_t acdb_init;
118 acdb_deallocate_t acdb_deallocate;
119 acdb_send_audio_cal_t acdb_send_audio_cal;
120 acdb_send_voice_cal_t acdb_send_voice_cal;
121 acdb_reload_vocvoltable_t acdb_reload_vocvoltable;
Naresh Tannirue3b18452014-03-04 14:44:27 +0530122
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530123 void *hw_info;
124 struct csd_data *csd;
Naresh Tannirue3b18452014-03-04 14:44:27 +0530125};
126
127static const int pcm_device_table[AUDIO_USECASE_MAX][2] = {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530128 [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = {DEEP_BUFFER_PCM_DEVICE,
129 DEEP_BUFFER_PCM_DEVICE},
130 [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
131 LOWLATENCY_PCM_DEVICE},
132 [USECASE_AUDIO_PLAYBACK_MULTI_CH] = {MULTIMEDIA2_PCM_DEVICE,
133 MULTIMEDIA2_PCM_DEVICE},
134 [USECASE_AUDIO_PLAYBACK_OFFLOAD] =
135 {PLAYBACK_OFFLOAD_DEVICE, PLAYBACK_OFFLOAD_DEVICE},
136 [USECASE_AUDIO_RECORD] = {AUDIO_RECORD_PCM_DEVICE, AUDIO_RECORD_PCM_DEVICE},
137 [USECASE_AUDIO_RECORD_COMPRESS] = {COMPRESS_CAPTURE_DEVICE, COMPRESS_CAPTURE_DEVICE},
138 [USECASE_AUDIO_RECORD_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
139 LOWLATENCY_PCM_DEVICE},
140 [USECASE_AUDIO_RECORD_FM_VIRTUAL] = {MULTIMEDIA2_PCM_DEVICE,
141 MULTIMEDIA2_PCM_DEVICE},
142 [USECASE_AUDIO_PLAYBACK_FM] = {FM_PLAYBACK_PCM_DEVICE, FM_CAPTURE_PCM_DEVICE},
143 [USECASE_AUDIO_HFP_SCO] = {HFP_PCM_RX, HFP_SCO_RX},
144 [USECASE_AUDIO_HFP_SCO_WB] = {HFP_PCM_RX, HFP_SCO_RX},
145 [USECASE_VOICE_CALL] = {VOICE_CALL_PCM_DEVICE, VOICE_CALL_PCM_DEVICE},
146 [USECASE_VOICE2_CALL] = {VOICE2_CALL_PCM_DEVICE, VOICE2_CALL_PCM_DEVICE},
147 [USECASE_VOLTE_CALL] = {VOLTE_CALL_PCM_DEVICE, VOLTE_CALL_PCM_DEVICE},
148 [USECASE_QCHAT_CALL] = {QCHAT_CALL_PCM_DEVICE, QCHAT_CALL_PCM_DEVICE},
Karthik Reddy Katta3b0a60c2014-04-06 14:52:37 +0530149 [USECASE_VOWLAN_CALL] = {VOWLAN_CALL_PCM_DEVICE, VOWLAN_CALL_PCM_DEVICE},
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530150 [USECASE_COMPRESS_VOIP_CALL] = {COMPRESS_VOIP_CALL_PCM_DEVICE, COMPRESS_VOIP_CALL_PCM_DEVICE},
151 [USECASE_INCALL_REC_UPLINK] = {AUDIO_RECORD_PCM_DEVICE,
152 AUDIO_RECORD_PCM_DEVICE},
153 [USECASE_INCALL_REC_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
154 AUDIO_RECORD_PCM_DEVICE},
155 [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
156 AUDIO_RECORD_PCM_DEVICE},
157 [USECASE_INCALL_REC_UPLINK_COMPRESS] = {COMPRESS_CAPTURE_DEVICE,
158 COMPRESS_CAPTURE_DEVICE},
159 [USECASE_INCALL_REC_DOWNLINK_COMPRESS] = {COMPRESS_CAPTURE_DEVICE,
160 COMPRESS_CAPTURE_DEVICE},
161 [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK_COMPRESS] = {COMPRESS_CAPTURE_DEVICE,
162 COMPRESS_CAPTURE_DEVICE},
163 [USECASE_INCALL_MUSIC_UPLINK] = {INCALL_MUSIC_UPLINK_PCM_DEVICE,
164 INCALL_MUSIC_UPLINK_PCM_DEVICE},
165 [USECASE_INCALL_MUSIC_UPLINK2] = {INCALL_MUSIC_UPLINK2_PCM_DEVICE,
166 INCALL_MUSIC_UPLINK2_PCM_DEVICE},
167 [USECASE_AUDIO_SPKR_CALIB_RX] = {SPKR_PROT_CALIB_RX_PCM_DEVICE, -1},
168 [USECASE_AUDIO_SPKR_CALIB_TX] = {-1, SPKR_PROT_CALIB_TX_PCM_DEVICE},
Naresh Tannirue3b18452014-03-04 14:44:27 +0530169};
170
171/* Array to store sound devices */
172static const char * const device_table[SND_DEVICE_MAX] = {
173 [SND_DEVICE_NONE] = "none",
174 /* Playback sound devices */
175 [SND_DEVICE_OUT_HANDSET] = "handset",
176 [SND_DEVICE_OUT_SPEAKER] = "speaker",
177 [SND_DEVICE_OUT_SPEAKER_REVERSE] = "speaker-reverse",
178 [SND_DEVICE_OUT_HEADPHONES] = "headphones",
179 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones",
180 [SND_DEVICE_OUT_VOICE_HANDSET] = "voice-handset",
181 [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker",
182 [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones",
183 [SND_DEVICE_OUT_HDMI] = "hdmi",
184 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi",
185 [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530186 [SND_DEVICE_OUT_BT_SCO_WB] = "bt-sco-headset-wb",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530187 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones",
188 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones",
189 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530190 [SND_DEVICE_OUT_AFE_PROXY] = "afe-proxy",
191 [SND_DEVICE_OUT_USB_HEADSET] = "usb-headphones",
192 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = "speaker-and-usb-headphones",
193 [SND_DEVICE_OUT_TRANSMISSION_FM] = "transmission-fm",
194 [SND_DEVICE_OUT_ANC_HEADSET] = "anc-headphones",
195 [SND_DEVICE_OUT_ANC_FB_HEADSET] = "anc-fb-headphones",
196 [SND_DEVICE_OUT_VOICE_ANC_HEADSET] = "voice-anc-headphones",
197 [SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET] = "voice-anc-fb-headphones",
198 [SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET] = "speaker-and-anc-headphones",
199 [SND_DEVICE_OUT_ANC_HANDSET] = "anc-handset",
200 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = "speaker-protected",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530201
202 /* Capture sound devices */
203 [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530204 [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530205 [SND_DEVICE_IN_HANDSET_MIC_NS] = "handset-mic",
206 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = "handset-mic",
207 [SND_DEVICE_IN_HANDSET_DMIC] = "dmic-endfire",
208 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = "dmic-endfire",
209 [SND_DEVICE_IN_HANDSET_DMIC_NS] = "dmic-endfire",
210 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = "dmic-endfire",
211 [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
212 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "speaker-mic",
213 [SND_DEVICE_IN_SPEAKER_MIC_NS] = "speaker-mic",
214 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = "speaker-mic",
215 [SND_DEVICE_IN_SPEAKER_DMIC] = "speaker-dmic-endfire",
216 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = "speaker-dmic-endfire",
217 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = "speaker-dmic-endfire",
218 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = "speaker-dmic-endfire",
219 [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
220 [SND_DEVICE_IN_HEADSET_MIC_FLUENCE] = "headset-mic",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530221 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
222 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
223 [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic",
224 [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530225 [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530226 [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530227 [SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef",
228 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = "voice-speaker-dmic-ef",
229 [SND_DEVICE_IN_VOICE_SPEAKER_QMIC] = "voice-speaker-qmic",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530230 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
231 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
232 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
233 [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530234 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = "voice-rec-mic",
235 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = "voice-rec-dmic-ef",
236 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence",
237 [SND_DEVICE_IN_USB_HEADSET_MIC] = "usb-headset-mic",
238 [SND_DEVICE_IN_CAPTURE_FM] = "capture-fm",
239 [SND_DEVICE_IN_AANC_HANDSET_MIC] = "aanc-handset-mic",
240 [SND_DEVICE_IN_QUAD_MIC] = "quad-mic",
241 [SND_DEVICE_IN_HANDSET_STEREO_DMIC] = "handset-stereo-dmic-ef",
242 [SND_DEVICE_IN_SPEAKER_STEREO_DMIC] = "speaker-stereo-dmic-ef",
243 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = "vi-feedback",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530244};
245
246/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530247static int acdb_device_table[SND_DEVICE_MAX] = {
Naresh Tannirue3b18452014-03-04 14:44:27 +0530248 [SND_DEVICE_NONE] = -1,
249 [SND_DEVICE_OUT_HANDSET] = 7,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530250 [SND_DEVICE_OUT_SPEAKER] = 14,
251 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 14,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530252 [SND_DEVICE_OUT_HEADPHONES] = 10,
253 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
254 [SND_DEVICE_OUT_VOICE_HANDSET] = 7,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530255 [SND_DEVICE_OUT_VOICE_SPEAKER] = 14,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530256 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
257 [SND_DEVICE_OUT_HDMI] = 18,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530258 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 14,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530259 [SND_DEVICE_OUT_BT_SCO] = 22,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530260 [SND_DEVICE_OUT_BT_SCO_WB] = 39,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530261 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
262 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
263 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530264 [SND_DEVICE_OUT_AFE_PROXY] = 0,
265 [SND_DEVICE_OUT_USB_HEADSET] = 45,
266 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = 14,
267 [SND_DEVICE_OUT_TRANSMISSION_FM] = 0,
268 [SND_DEVICE_OUT_ANC_HEADSET] = 26,
269 [SND_DEVICE_OUT_ANC_FB_HEADSET] = 27,
270 [SND_DEVICE_OUT_VOICE_ANC_HEADSET] = 26,
271 [SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET] = 27,
272 [SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET] = 26,
273 [SND_DEVICE_OUT_ANC_HANDSET] = 103,
274 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = 101,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530275
276 [SND_DEVICE_IN_HANDSET_MIC] = 4,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530277 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 106,
278 [SND_DEVICE_IN_HANDSET_MIC_NS] = 107,
279 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = 108,
280 [SND_DEVICE_IN_HANDSET_DMIC] = 41,
281 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = 109,
282 [SND_DEVICE_IN_HANDSET_DMIC_NS] = 110,
283 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = 111,
284 [SND_DEVICE_IN_SPEAKER_MIC] = 11,
285 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 112,
286 [SND_DEVICE_IN_SPEAKER_MIC_NS] = 113,
287 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = 114,
288 [SND_DEVICE_IN_SPEAKER_DMIC] = 43,
289 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = 115,
290 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = 116,
291 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = 117,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530292 [SND_DEVICE_IN_HEADSET_MIC] = 8,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530293 [SND_DEVICE_IN_HEADSET_MIC_FLUENCE] = 47,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530294 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
295 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = 8,
296 [SND_DEVICE_IN_HDMI_MIC] = 4,
297 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530298 [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38,
299 [SND_DEVICE_IN_CAMCORDER_MIC] = 4,
300 [SND_DEVICE_IN_VOICE_DMIC] = 41,
301 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 43,
302 [SND_DEVICE_IN_VOICE_SPEAKER_QMIC] = 19,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530303 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
304 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
305 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530306 [SND_DEVICE_IN_VOICE_REC_MIC] = 4,
307 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = 107,
308 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = 34,
309 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 41,
310 [SND_DEVICE_IN_USB_HEADSET_MIC] = 44,
311 [SND_DEVICE_IN_CAPTURE_FM] = 0,
312 [SND_DEVICE_IN_AANC_HANDSET_MIC] = 104,
313 [SND_DEVICE_IN_QUAD_MIC] = 46,
314 [SND_DEVICE_IN_HANDSET_STEREO_DMIC] = 34,
315 [SND_DEVICE_IN_SPEAKER_STEREO_DMIC] = 35,
316 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = 102,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530317};
318
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530319struct snd_device_index {
320 char name[100];
321 unsigned int index;
322};
Naresh Tannirue3b18452014-03-04 14:44:27 +0530323
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530324#define TO_NAME_INDEX(X) #X, X
Naresh Tannirue3b18452014-03-04 14:44:27 +0530325
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530326/* Used to get index from parsed sting */
327struct snd_device_index snd_device_name_index[SND_DEVICE_MAX] = {
328 {TO_NAME_INDEX(SND_DEVICE_OUT_HANDSET)},
329 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER)},
330 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_REVERSE)},
331 {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES)},
332 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES)},
333 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET)},
334 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER)},
335 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADPHONES)},
336 {TO_NAME_INDEX(SND_DEVICE_OUT_HDMI)},
337 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HDMI)},
338 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO)},
339 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO_WB)},
340 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES)},
341 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES)},
342 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET)},
343 {TO_NAME_INDEX(SND_DEVICE_OUT_AFE_PROXY)},
344 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADSET)},
345 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET)},
346 {TO_NAME_INDEX(SND_DEVICE_OUT_TRANSMISSION_FM)},
347 {TO_NAME_INDEX(SND_DEVICE_OUT_ANC_HEADSET)},
348 {TO_NAME_INDEX(SND_DEVICE_OUT_ANC_FB_HEADSET)},
349 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_ANC_HEADSET)},
350 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET)},
351 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET)},
352 {TO_NAME_INDEX(SND_DEVICE_OUT_ANC_HANDSET)},
353 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED)},
354 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC)},
355 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC)},
356 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_NS)},
357 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)},
358 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC)},
359 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC)},
360 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_NS)},
361 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)},
362 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC)},
363 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC)},
364 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_NS)},
365 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)},
366 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC)},
367 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC)},
368 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS)},
369 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)},
370 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC)},
371 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC_FLUENCE)},
372 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC)},
373 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEADSET_MIC)},
374 {TO_NAME_INDEX(SND_DEVICE_IN_HDMI_MIC)},
375 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC)},
376 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB)},
377 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_MIC)},
378 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC)},
379 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC)},
380 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_QMIC)},
381 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC)},
382 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC)},
383 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC)},
384 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC)},
385 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_NS)},
386 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_STEREO)},
387 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE)},
388 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC)},
389 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_FM)},
390 {TO_NAME_INDEX(SND_DEVICE_IN_AANC_HANDSET_MIC)},
391 {TO_NAME_INDEX(SND_DEVICE_IN_QUAD_MIC)},
392 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_STEREO_DMIC)},
393 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_STEREO_DMIC)},
394 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_VI_FEEDBACK)},
395};
396
397#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
398#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
Naresh Tannirue3b18452014-03-04 14:44:27 +0530399
Asish Bhattacharya4ff24802014-04-24 17:46:54 +0530400static void query_platform(const char *snd_card_name,
401 char *mixer_xml_path)
402{
403 if (!strncmp(snd_card_name, "msm8x16-snd-card-mtp",
404 sizeof("msm8x16-snd-card-mtp"))) {
405 strlcpy(mixer_xml_path, MIXER_XML_PATH_MTP,
406 sizeof(MIXER_XML_PATH_MTP));
Walter Yang7ca90d92014-05-06 17:48:02 +0800407 } else if (!strncmp(snd_card_name, "msm8x16-skuh-snd-card",
408 sizeof("msm8x16-skuh-snd-card"))) {
409 strlcpy(mixer_xml_path, MIXER_XML_PATH_QRD_SKUH,
410 sizeof(MIXER_XML_PATH_QRD_SKUH));
411 } else if (!strncmp(snd_card_name, "msm8x16-skui-snd-card",
412 sizeof("msm8x16-skui-snd-card"))) {
413 strlcpy(mixer_xml_path, MIXER_XML_PATH_QRD_SKUI,
414 sizeof(MIXER_XML_PATH_QRD_SKUI));
Yamit Mehtac6003e22014-05-19 10:26:02 +0530415 } if (!strncmp(snd_card_name, "msm8939-snd-card-mtp",
416 sizeof("msm8939-snd-card-mtp"))) {
417 strlcpy(mixer_xml_path, MIXER_XML_PATH,
418 sizeof(MIXER_XML_PATH));
Asish Bhattacharya4ff24802014-04-24 17:46:54 +0530419 } else {
420 strlcpy(mixer_xml_path, MIXER_XML_PATH,
421 sizeof(MIXER_XML_PATH));
422 }
423}
424
Naresh Tannirue3b18452014-03-04 14:44:27 +0530425static int set_echo_reference(struct mixer *mixer, const char* ec_ref)
426{
427 struct mixer_ctl *ctl;
428 const char *mixer_ctl_name = "EC_REF_RX";
429
430 ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name);
431 if (!ctl) {
432 ALOGE("%s: Could not get ctl for mixer cmd - %s",
433 __func__, mixer_ctl_name);
434 return -EINVAL;
435 }
436 ALOGV("Setting EC Reference: %s", ec_ref);
437 mixer_ctl_set_enum_by_string(ctl, ec_ref);
438 return 0;
439}
440
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530441static struct csd_data *open_csd_client()
442{
443 struct csd_data *csd = calloc(1, sizeof(struct csd_data));
444
445 csd->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
446 if (csd->csd_client == NULL) {
447 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
448 goto error;
449 } else {
450 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
451
452 csd->deinit = (deinit_t)dlsym(csd->csd_client,
453 "csd_client_deinit");
454 if (csd->deinit == NULL) {
455 ALOGE("%s: dlsym error %s for csd_client_deinit", __func__,
456 dlerror());
457 goto error;
458 }
459 csd->disable_device = (disable_device_t)dlsym(csd->csd_client,
460 "csd_client_disable_device");
461 if (csd->disable_device == NULL) {
462 ALOGE("%s: dlsym error %s for csd_client_disable_device",
463 __func__, dlerror());
464 goto error;
465 }
466 csd->enable_device_config = (enable_device_config_t)dlsym(csd->csd_client,
467 "csd_client_enable_device_config");
468 if (csd->enable_device_config == NULL) {
469 ALOGE("%s: dlsym error %s for csd_client_enable_device_config",
470 __func__, dlerror());
471 goto error;
472 }
473 csd->enable_device = (enable_device_t)dlsym(csd->csd_client,
474 "csd_client_enable_device");
475 if (csd->enable_device == NULL) {
476 ALOGE("%s: dlsym error %s for csd_client_enable_device",
477 __func__, dlerror());
478 goto error;
479 }
480 csd->start_voice = (start_voice_t)dlsym(csd->csd_client,
481 "csd_client_start_voice");
482 if (csd->start_voice == NULL) {
483 ALOGE("%s: dlsym error %s for csd_client_start_voice",
484 __func__, dlerror());
485 goto error;
486 }
487 csd->stop_voice = (stop_voice_t)dlsym(csd->csd_client,
488 "csd_client_stop_voice");
489 if (csd->stop_voice == NULL) {
490 ALOGE("%s: dlsym error %s for csd_client_stop_voice",
491 __func__, dlerror());
492 goto error;
493 }
494 csd->volume = (volume_t)dlsym(csd->csd_client,
495 "csd_client_volume");
496 if (csd->volume == NULL) {
497 ALOGE("%s: dlsym error %s for csd_client_volume",
498 __func__, dlerror());
499 goto error;
500 }
501 csd->mic_mute = (mic_mute_t)dlsym(csd->csd_client,
502 "csd_client_mic_mute");
503 if (csd->mic_mute == NULL) {
504 ALOGE("%s: dlsym error %s for csd_client_mic_mute",
505 __func__, dlerror());
506 goto error;
507 }
508 csd->slow_talk = (slow_talk_t)dlsym(csd->csd_client,
509 "csd_client_slow_talk");
510 if (csd->slow_talk == NULL) {
511 ALOGE("%s: dlsym error %s for csd_client_slow_talk",
512 __func__, dlerror());
513 goto error;
514 }
515 csd->start_playback = (start_playback_t)dlsym(csd->csd_client,
516 "csd_client_start_playback");
517 if (csd->start_playback == NULL) {
518 ALOGE("%s: dlsym error %s for csd_client_start_playback",
519 __func__, dlerror());
520 goto error;
521 }
522 csd->stop_playback = (stop_playback_t)dlsym(csd->csd_client,
523 "csd_client_stop_playback");
524 if (csd->stop_playback == NULL) {
525 ALOGE("%s: dlsym error %s for csd_client_stop_playback",
526 __func__, dlerror());
527 goto error;
528 }
529 csd->start_record = (start_record_t)dlsym(csd->csd_client,
530 "csd_client_start_record");
531 if (csd->start_record == NULL) {
532 ALOGE("%s: dlsym error %s for csd_client_start_record",
533 __func__, dlerror());
534 goto error;
535 }
536 csd->stop_record = (stop_record_t)dlsym(csd->csd_client,
537 "csd_client_stop_record");
538 if (csd->stop_record == NULL) {
539 ALOGE("%s: dlsym error %s for csd_client_stop_record",
540 __func__, dlerror());
541 goto error;
542 }
543 csd->init = (init_t)dlsym(csd->csd_client, "csd_client_init");
544
545 if (csd->init == NULL) {
546 ALOGE("%s: dlsym error %s for csd_client_init",
547 __func__, dlerror());
548 goto error;
549 } else {
550 csd->init();
551 }
552 }
553 return csd;
554
555error:
556 free(csd);
557 csd = NULL;
558 return csd;
559}
560
561void close_csd_client(struct csd_data *csd)
562{
563 if (csd != NULL) {
564 csd->deinit();
565 dlclose(csd->csd_client);
566 free(csd);
567 csd = NULL;
568 }
569}
570
Naresh Tannirue3b18452014-03-04 14:44:27 +0530571void *platform_init(struct audio_device *adev)
572{
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530573 char platform[PROPERTY_VALUE_MAX];
574 char baseband[PROPERTY_VALUE_MAX];
Naresh Tannirue3b18452014-03-04 14:44:27 +0530575 char value[PROPERTY_VALUE_MAX];
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530576 struct platform_data *my_data = NULL;
577 int retry_num = 0, snd_card_num = 0;
578 const char *snd_card_name;
Asish Bhattacharya4ff24802014-04-24 17:46:54 +0530579 char mixer_xml_path[100];
Naresh Tannirue3b18452014-03-04 14:44:27 +0530580
581 my_data = calloc(1, sizeof(struct platform_data));
582
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530583 while (snd_card_num < MAX_SND_CARD) {
584 adev->mixer = mixer_open(snd_card_num);
585
586 while (!adev->mixer && retry_num < RETRY_NUMBER) {
587 usleep(RETRY_US);
588 adev->mixer = mixer_open(snd_card_num);
589 retry_num++;
590 }
591
592 if (!adev->mixer) {
593 ALOGE("%s: Unable to open the mixer card: %d", __func__,
594 snd_card_num);
595 retry_num = 0;
596 snd_card_num++;
597 continue;
598 }
599
600 snd_card_name = mixer_get_name(adev->mixer);
601 ALOGV("%s: snd_card_name: %s", __func__, snd_card_name);
602
603 my_data->hw_info = hw_info_init(snd_card_name);
604 if (!my_data->hw_info) {
605 ALOGE("%s: Failed to init hardware info", __func__);
606 } else {
Asish Bhattacharya4ff24802014-04-24 17:46:54 +0530607 query_platform(snd_card_name, mixer_xml_path);
608 ALOGD("%s: mixer path file is %s", __func__,
609 mixer_xml_path);
610 if (audio_extn_read_xml(adev, snd_card_num, mixer_xml_path,
611 MIXER_XML_PATH_AUXPCM) == -ENOSYS) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530612 adev->audio_route = audio_route_init(snd_card_num,
Asish Bhattacharya4ff24802014-04-24 17:46:54 +0530613 mixer_xml_path);
614 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530615 if (!adev->audio_route) {
616 ALOGE("%s: Failed to init audio route controls, aborting.",
617 __func__);
618 free(my_data);
619 return NULL;
620 }
621 adev->snd_card = snd_card_num;
622 ALOGD("%s: Opened sound card:%d", __func__, snd_card_num);
623 break;
624 }
625 retry_num = 0;
626 snd_card_num++;
627 }
628
629 if (snd_card_num >= MAX_SND_CARD) {
630 ALOGE("%s: Unable to find correct sound card, aborting.", __func__);
631 free(my_data);
632 return NULL;
633 }
634
Naresh Tannirue3b18452014-03-04 14:44:27 +0530635 my_data->adev = adev;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530636 my_data->btsco_sample_rate = SAMPLE_RATE_8KHZ;
Naresh Tannirue3b18452014-03-04 14:44:27 +0530637 my_data->fluence_in_spkr_mode = false;
638 my_data->fluence_in_voice_call = false;
639 my_data->fluence_in_voice_rec = false;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530640 my_data->fluence_in_audio_rec = false;
641 my_data->fluence_type = FLUENCE_NONE;
Naresh Tannirue3b18452014-03-04 14:44:27 +0530642
Venkata Narendra Kumar Gutta88fd0bc2014-03-27 19:47:56 +0530643 property_get("ro.qc.sdk.audio.fluencetype", my_data->fluence_cap, "");
644 if (!strncmp("fluencepro", my_data->fluence_cap, sizeof("fluencepro"))) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530645 my_data->fluence_type = FLUENCE_QUAD_MIC | FLUENCE_DUAL_MIC;
Venkata Narendra Kumar Gutta88fd0bc2014-03-27 19:47:56 +0530646 } else if (!strncmp("fluence", my_data->fluence_cap, sizeof("fluence"))) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530647 my_data->fluence_type = FLUENCE_DUAL_MIC;
648 } else {
649 my_data->fluence_type = FLUENCE_NONE;
Naresh Tannirue3b18452014-03-04 14:44:27 +0530650 }
651
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530652 if (my_data->fluence_type != FLUENCE_NONE) {
Naresh Tannirue3b18452014-03-04 14:44:27 +0530653 property_get("persist.audio.fluence.voicecall",value,"");
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530654 if (!strncmp("true", value, sizeof("true"))) {
Naresh Tannirue3b18452014-03-04 14:44:27 +0530655 my_data->fluence_in_voice_call = true;
656 }
657
658 property_get("persist.audio.fluence.voicerec",value,"");
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530659 if (!strncmp("true", value, sizeof("true"))) {
Naresh Tannirue3b18452014-03-04 14:44:27 +0530660 my_data->fluence_in_voice_rec = true;
661 }
662
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530663 property_get("persist.audio.fluence.audiorec",value,"");
664 if (!strncmp("true", value, sizeof("true"))) {
665 my_data->fluence_in_audio_rec = true;
666 }
667
Naresh Tannirue3b18452014-03-04 14:44:27 +0530668 property_get("persist.audio.fluence.speaker",value,"");
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530669 if (!strncmp("true", value, sizeof("true"))) {
Naresh Tannirue3b18452014-03-04 14:44:27 +0530670 my_data->fluence_in_spkr_mode = true;
671 }
672 }
673
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530674 my_data->voice_feature_set = VOICE_FEATURE_SET_DEFAULT;
Naresh Tannirue3b18452014-03-04 14:44:27 +0530675 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
676 if (my_data->acdb_handle == NULL) {
677 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
678 } else {
679 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
680 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
681 "acdb_loader_deallocate_ACDB");
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530682 if (!my_data->acdb_deallocate)
683 ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s",
684 __func__, LIB_ACDB_LOADER);
685
Naresh Tannirue3b18452014-03-04 14:44:27 +0530686 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
687 "acdb_loader_send_audio_cal");
688 if (!my_data->acdb_send_audio_cal)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530689 ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530690 __func__, LIB_ACDB_LOADER);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530691
Naresh Tannirue3b18452014-03-04 14:44:27 +0530692 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
693 "acdb_loader_send_voice_cal");
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530694 if (!my_data->acdb_send_voice_cal)
695 ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s",
696 __func__, LIB_ACDB_LOADER);
697
698 my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle,
699 "acdb_loader_reload_vocvoltable");
700 if (!my_data->acdb_reload_vocvoltable)
701 ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s",
702 __func__, LIB_ACDB_LOADER);
703
Naresh Tannirue3b18452014-03-04 14:44:27 +0530704 my_data->acdb_init = (acdb_init_t)dlsym(my_data->acdb_handle,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530705 "acdb_loader_init_v2");
Naresh Tannirue3b18452014-03-04 14:44:27 +0530706 if (my_data->acdb_init == NULL)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530707 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__, dlerror());
Naresh Tannirue3b18452014-03-04 14:44:27 +0530708 else
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530709 my_data->acdb_init(snd_card_name);
Naresh Tannirue3b18452014-03-04 14:44:27 +0530710 }
711
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530712 /* Initialize ACDB ID's */
713 platform_info_init(PLATFORM_INFO_XML_PATH);
714
715 /* init usb */
716 audio_extn_usb_init(adev);
717 /* update sound cards appropriately */
718 audio_extn_usb_set_proxy_sound_card(adev->snd_card);
719
720 /* Read one time ssr property */
721 audio_extn_ssr_update_enabled();
722 audio_extn_spkr_prot_init(adev);
Dhananjay Kumar89ea3bd2014-04-29 15:45:57 +0530723
724 audio_extn_dolby_set_license(adev);
725
Naresh Tannirue3b18452014-03-04 14:44:27 +0530726 return my_data;
727}
728
729void platform_deinit(void *platform)
730{
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530731 struct platform_data *my_data = (struct platform_data *)platform;
732
733 hw_info_deinit(my_data->hw_info);
734 close_csd_client(my_data->csd);
735
Naresh Tannirue3b18452014-03-04 14:44:27 +0530736 free(platform);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530737 /* deinit usb */
738 audio_extn_usb_deinit();
Naresh Tannirue3b18452014-03-04 14:44:27 +0530739}
740
741const char *platform_get_snd_device_name(snd_device_t snd_device)
742{
743 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX)
744 return device_table[snd_device];
745 else
746 return "";
747}
748
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530749int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
750 char *device_name)
751{
752 struct platform_data *my_data = (struct platform_data *)platform;
753
754 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
755 strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE);
756 hw_info_append_hw_type(my_data->hw_info, snd_device, device_name);
757 } else {
758 strlcpy(device_name, "", DEVICE_NAME_MAX_SIZE);
759 return -EINVAL;
760 }
761
762 return 0;
763}
764
Naresh Tannirue3b18452014-03-04 14:44:27 +0530765void platform_add_backend_name(char *mixer_path, snd_device_t snd_device)
766{
767 if (snd_device == SND_DEVICE_IN_BT_SCO_MIC)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530768 strlcat(mixer_path, " bt-sco", MIXER_PATH_MAX_LENGTH);
769 else if (snd_device == SND_DEVICE_IN_BT_SCO_MIC_WB)
770 strlcat(mixer_path, " bt-sco-wb", MIXER_PATH_MAX_LENGTH);
Naresh Tannirue3b18452014-03-04 14:44:27 +0530771 else if(snd_device == SND_DEVICE_OUT_BT_SCO)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530772 strlcat(mixer_path, " bt-sco", MIXER_PATH_MAX_LENGTH);
773 else if(snd_device == SND_DEVICE_OUT_BT_SCO_WB)
774 strlcat(mixer_path, " bt-sco-wb", MIXER_PATH_MAX_LENGTH);
Naresh Tannirue3b18452014-03-04 14:44:27 +0530775 else if (snd_device == SND_DEVICE_OUT_HDMI)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530776 strlcat(mixer_path, " hdmi", MIXER_PATH_MAX_LENGTH);
Naresh Tannirue3b18452014-03-04 14:44:27 +0530777 else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HDMI)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530778 strlcat(mixer_path, " speaker-and-hdmi", MIXER_PATH_MAX_LENGTH);
779 else if (snd_device == SND_DEVICE_OUT_AFE_PROXY)
780 strlcat(mixer_path, " afe-proxy", MIXER_PATH_MAX_LENGTH);
781 else if (snd_device == SND_DEVICE_OUT_USB_HEADSET)
782 strlcat(mixer_path, " usb-headphones", MIXER_PATH_MAX_LENGTH);
783 else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET)
784 strlcat(mixer_path, " speaker-and-usb-headphones",
785 MIXER_PATH_MAX_LENGTH);
786 else if (snd_device == SND_DEVICE_IN_USB_HEADSET_MIC)
787 strlcat(mixer_path, " usb-headset-mic", MIXER_PATH_MAX_LENGTH);
788 else if (snd_device == SND_DEVICE_IN_CAPTURE_FM)
789 strlcat(mixer_path, " capture-fm", MIXER_PATH_MAX_LENGTH);
790 else if (snd_device == SND_DEVICE_OUT_TRANSMISSION_FM)
791 strlcat(mixer_path, " transmission-fm", MIXER_PATH_MAX_LENGTH);
Naresh Tannirue3b18452014-03-04 14:44:27 +0530792}
793
794int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
795{
796 int device_id;
797 if (device_type == PCM_PLAYBACK)
798 device_id = pcm_device_table[usecase][0];
799 else
800 device_id = pcm_device_table[usecase][1];
801 return device_id;
802}
803
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530804int platform_get_snd_device_index(char *snd_device_index_name)
805{
806 int ret = 0;
807 int i;
808
809 if (snd_device_index_name == NULL) {
810 ALOGE("%s: snd_device_index_name is NULL", __func__);
811 ret = -ENODEV;
812 goto done;
813 }
814
815 for (i=0; i < SND_DEVICE_MAX; i++) {
816 if(strcmp(snd_device_name_index[i].name, snd_device_index_name) == 0) {
817 ret = snd_device_name_index[i].index;
818 goto done;
819 }
820 }
821 ALOGE("%s: Could not find index for snd_device_index_name = %s",
822 __func__, snd_device_index_name);
823 ret = -ENODEV;
824done:
825 return ret;
826}
827
Venkata Narendra Kumar Gutta88fd0bc2014-03-27 19:47:56 +0530828int platform_set_fluence_type(void *platform, char *value)
829{
830 int ret = 0;
831 int fluence_type = FLUENCE_NONE;
832 int fluence_flag = NONE_FLAG;
833 struct platform_data *my_data = (struct platform_data *)platform;
834 struct audio_device *adev = my_data->adev;
835
836 ALOGV("%s: fluence type:%d", __func__, my_data->fluence_type);
837
838 /* only dual mic turn on and off is supported as of now through setparameters */
839 if (!strncmp(AUDIO_PARAMETER_VALUE_DUALMIC,value, sizeof(AUDIO_PARAMETER_VALUE_DUALMIC))) {
840 if (!strncmp("fluencepro", my_data->fluence_cap, sizeof("fluencepro")) ||
841 !strncmp("fluence", my_data->fluence_cap, sizeof("fluence"))) {
842 ALOGV("fluence dualmic feature enabled \n");
843 fluence_type = FLUENCE_DUAL_MIC;
844 fluence_flag = DMIC_FLAG;
845 } else {
846 ALOGE("%s: Failed to set DUALMIC", __func__);
847 ret = -1;
848 goto done;
849 }
850 } else if (!strncmp(AUDIO_PARAMETER_KEY_NO_FLUENCE, value, sizeof(AUDIO_PARAMETER_KEY_NO_FLUENCE))) {
851 ALOGV("fluence disabled");
852 fluence_type = FLUENCE_NONE;
853 } else {
854 ALOGE("Invalid fluence value : %s",value);
855 ret = -1;
856 goto done;
857 }
858
859 if (fluence_type != my_data->fluence_type) {
860 ALOGV("%s: Updating fluence_type to :%d", __func__, fluence_type);
861 my_data->fluence_type = fluence_type;
862 adev->acdb_settings = (adev->acdb_settings & FLUENCE_MODE_CLEAR) | fluence_flag;
863 }
864done:
865 return ret;
866}
867
868int platform_get_fluence_type(void *platform, char *value, uint32_t len)
869{
870 int ret = 0;
871 struct platform_data *my_data = (struct platform_data *)platform;
872
873 if (my_data->fluence_type == FLUENCE_QUAD_MIC) {
874 strlcpy(value, "quadmic", len);
875 } else if (my_data->fluence_type == FLUENCE_DUAL_MIC) {
876 strlcpy(value, "dualmic", len);
877 } else if (my_data->fluence_type == FLUENCE_NONE) {
878 strlcpy(value, "none", len);
879 } else
880 ret = -1;
881
882 return ret;
883}
884
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530885int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
886{
887 int ret = 0;
888
889 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
890 ALOGE("%s: Invalid snd_device = %d",
891 __func__, snd_device);
892 ret = -EINVAL;
893 goto done;
894 }
895
896 acdb_device_table[snd_device] = acdb_id;
897done:
898 return ret;
899}
900
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700901int platform_get_snd_device_acdb_id(snd_device_t snd_device)
902{
903 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
904 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
905 return -EINVAL;
906 }
907 return acdb_device_table[snd_device];
908}
909
Naresh Tannirue3b18452014-03-04 14:44:27 +0530910int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
911{
912 struct platform_data *my_data = (struct platform_data *)platform;
913 int acdb_dev_id, acdb_dev_type;
914
915 acdb_dev_id = acdb_device_table[snd_device];
916 if (acdb_dev_id < 0) {
917 ALOGE("%s: Could not find acdb id for device(%d)",
918 __func__, snd_device);
919 return -EINVAL;
920 }
921 if (my_data->acdb_send_audio_cal) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530922 ("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530923 __func__, snd_device, acdb_dev_id);
924 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
925 snd_device < SND_DEVICE_OUT_END)
926 acdb_dev_type = ACDB_DEV_TYPE_OUT;
927 else
928 acdb_dev_type = ACDB_DEV_TYPE_IN;
929 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
930 }
931 return 0;
932}
933
934int platform_switch_voice_call_device_pre(void *platform)
935{
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530936 struct platform_data *my_data = (struct platform_data *)platform;
937 int ret = 0;
938
939 if (my_data->csd != NULL &&
940 my_data->adev->mode == AUDIO_MODE_IN_CALL) {
941 /* This must be called before disabling mixer controls on APQ side */
942 ret = my_data->csd->disable_device();
943 if (ret < 0) {
944 ALOGE("%s: csd_client_disable_device, failed, error %d",
945 __func__, ret);
946 }
947 }
948 return ret;
Naresh Tannirue3b18452014-03-04 14:44:27 +0530949}
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530950int platform_switch_voice_call_enable_device_config(void *platform,
951 snd_device_t out_snd_device,
952 snd_device_t in_snd_device)
953{
954 struct platform_data *my_data = (struct platform_data *)platform;
955 int acdb_rx_id, acdb_tx_id;
956 int ret = 0;
957
958 acdb_rx_id = acdb_device_table[out_snd_device];
959 acdb_tx_id = acdb_device_table[in_snd_device];
960
961 if (my_data->csd != NULL) {
962 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
963 ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
964 if (ret < 0) {
965 ALOGE("%s: csd_enable_device_config, failed, error %d",
966 __func__, ret);
967 }
968 } else {
969 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
970 acdb_rx_id, acdb_tx_id);
971 }
972 }
973 return ret;
974}
975
Naresh Tannirue3b18452014-03-04 14:44:27 +0530976
977int platform_switch_voice_call_device_post(void *platform,
978 snd_device_t out_snd_device,
979 snd_device_t in_snd_device)
980{
981 struct platform_data *my_data = (struct platform_data *)platform;
982 int acdb_rx_id, acdb_tx_id;
983
984 if (my_data->acdb_send_voice_cal == NULL) {
985 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
986 } else {
987 acdb_rx_id = acdb_device_table[out_snd_device];
988 acdb_tx_id = acdb_device_table[in_snd_device];
989
990 if (acdb_rx_id > 0 && acdb_tx_id > 0)
991 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
992 else
993 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
994 acdb_rx_id, acdb_tx_id);
995 }
996
997 return 0;
998}
999
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301000int platform_switch_voice_call_usecase_route_post(void *platform,
1001 snd_device_t out_snd_device,
1002 snd_device_t in_snd_device)
Naresh Tannirue3b18452014-03-04 14:44:27 +05301003{
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301004 struct platform_data *my_data = (struct platform_data *)platform;
1005 int acdb_rx_id, acdb_tx_id;
1006 int ret = 0;
1007
1008 acdb_rx_id = acdb_device_table[out_snd_device];
1009 acdb_tx_id = acdb_device_table[in_snd_device];
1010
1011 if (my_data->csd != NULL) {
1012 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
1013 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
1014 my_data->adev->acdb_settings);
1015 if (ret < 0) {
1016 ALOGE("%s: csd_enable_device, failed, error %d",
1017 __func__, ret);
1018 }
1019 } else {
1020 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1021 acdb_rx_id, acdb_tx_id);
1022 }
1023 }
1024 return ret;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301025}
1026
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301027int platform_start_voice_call(void *platform, uint32_t vsid)
1028{
1029 struct platform_data *my_data = (struct platform_data *)platform;
1030 int ret = 0;
1031
1032 if (my_data->csd != NULL) {
1033 ret = my_data->csd->start_voice(vsid);
1034 if (ret < 0) {
1035 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
1036 }
1037 }
1038 return ret;
1039}
1040
1041int platform_stop_voice_call(void *platform, uint32_t vsid)
1042{
1043 struct platform_data *my_data = (struct platform_data *)platform;
1044 int ret = 0;
1045
1046 if (my_data->csd != NULL) {
1047 ret = my_data->csd->stop_voice(vsid);
1048 if (ret < 0) {
1049 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
1050 }
1051 }
1052 return ret;
1053}
1054int platform_get_sample_rate(void *platform, uint32_t *rate)
Naresh Tannirue3b18452014-03-04 14:44:27 +05301055{
1056 return 0;
1057}
1058
1059int platform_set_voice_volume(void *platform, int volume)
1060{
1061 struct platform_data *my_data = (struct platform_data *)platform;
1062 struct audio_device *adev = my_data->adev;
1063 struct mixer_ctl *ctl;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301064 const char *mixer_ctl_name = "Voice Rx Gain";
1065 int vol_index = 0, ret = 0;
1066 uint32_t set_values[ ] = {0,
1067 ALL_SESSION_VSID,
1068 DEFAULT_VOLUME_RAMP_DURATION_MS};
Naresh Tannirue3b18452014-03-04 14:44:27 +05301069
1070 // Voice volume levels are mapped to adsp volume levels as follows.
1071 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
1072 // But this values don't changed in kernel. So, below change is need.
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301073 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, MAX_VOL_INDEX);
1074 set_values[0] = vol_index;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301075
1076 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1077 if (!ctl) {
1078 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1079 __func__, mixer_ctl_name);
1080 return -EINVAL;
1081 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301082 ALOGV("Setting voice volume index: %d", set_values[0]);
1083 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
Naresh Tannirue3b18452014-03-04 14:44:27 +05301084
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301085 if (my_data->csd != NULL) {
1086 ret = my_data->csd->volume(ALL_SESSION_VSID, volume);
1087 if (ret < 0) {
1088 ALOGE("%s: csd_volume error %d", __func__, ret);
1089 }
1090 }
1091 return ret;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301092}
1093
1094int platform_set_mic_mute(void *platform, bool state)
1095{
1096 struct platform_data *my_data = (struct platform_data *)platform;
1097 struct audio_device *adev = my_data->adev;
1098 struct mixer_ctl *ctl;
1099 const char *mixer_ctl_name = "Voice Tx Mute";
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301100 int ret = 0;
1101 uint32_t set_values[ ] = {0,
1102 ALL_SESSION_VSID,
1103 DEFAULT_VOLUME_RAMP_DURATION_MS};
Naresh Tannirue3b18452014-03-04 14:44:27 +05301104
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301105 set_values[0] = state;
1106 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1107 if (!ctl) {
1108 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1109 __func__, mixer_ctl_name);
1110 return -EINVAL;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301111 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301112 ALOGV("Setting voice mute state: %d", state);
1113 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
Naresh Tannirue3b18452014-03-04 14:44:27 +05301114
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301115 if (my_data->csd != NULL) {
1116 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state);
1117 if (ret < 0) {
1118 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
1119 }
1120 }
1121 return ret;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301122}
1123
Shiv Maliyappanahallic6fd8ee2014-03-07 15:31:55 -08001124int platform_set_device_mute(void *platform, bool state, char *dir)
1125{
1126 struct platform_data *my_data = (struct platform_data *)platform;
1127 struct audio_device *adev = my_data->adev;
1128 struct mixer_ctl *ctl;
1129 char *mixer_ctl_name = NULL;
1130 int ret = 0;
1131 uint32_t set_values[ ] = {0,
1132 ALL_SESSION_VSID,
1133 0};
1134 if(dir == NULL) {
1135 ALOGE("%s: Invalid direction:%s", __func__, dir);
1136 return -EINVAL;
1137 }
1138
1139 if (!strncmp("rx", dir, sizeof("rx"))) {
1140 mixer_ctl_name = "Voice Rx Device Mute";
1141 } else if (!strncmp("tx", dir, sizeof("tx"))) {
1142 mixer_ctl_name = "Voice Tx Device Mute";
1143 } else {
1144 return -EINVAL;
1145 }
1146
1147 set_values[0] = state;
1148 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1149 if (!ctl) {
1150 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1151 __func__, mixer_ctl_name);
1152 return -EINVAL;
1153 }
1154
1155 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
1156 __func__,state, mixer_ctl_name);
1157 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1158
1159 return ret;
1160}
1161
Naresh Tannirue3b18452014-03-04 14:44:27 +05301162snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
1163{
1164 struct platform_data *my_data = (struct platform_data *)platform;
1165 struct audio_device *adev = my_data->adev;
1166 audio_mode_t mode = adev->mode;
1167 snd_device_t snd_device = SND_DEVICE_NONE;
1168
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301169 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
1170 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
1171 int channel_count = popcount(channel_mask);
1172
Naresh Tannirue3b18452014-03-04 14:44:27 +05301173 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
1174 if (devices == AUDIO_DEVICE_NONE ||
1175 devices & AUDIO_DEVICE_BIT_IN) {
1176 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
1177 goto exit;
1178 }
1179
Naresh Tannirue3b18452014-03-04 14:44:27 +05301180 if (popcount(devices) == 2) {
1181 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
1182 AUDIO_DEVICE_OUT_SPEAKER)) {
1183 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
1184 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
1185 AUDIO_DEVICE_OUT_SPEAKER)) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301186 if (audio_extn_get_anc_enabled())
1187 snd_device = SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET;
1188 else
1189 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301190 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
1191 AUDIO_DEVICE_OUT_SPEAKER)) {
1192 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301193 } else if (devices == (AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET |
1194 AUDIO_DEVICE_OUT_SPEAKER)) {
1195 snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301196 } else {
1197 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
1198 goto exit;
1199 }
1200 if (snd_device != SND_DEVICE_NONE) {
1201 goto exit;
1202 }
1203 }
1204
1205 if (popcount(devices) != 1) {
1206 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
1207 goto exit;
1208 }
1209
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301210 if ((mode == AUDIO_MODE_IN_CALL) ||
1211 voice_extn_compress_voip_is_active(adev)) {
1212 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1213 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
1214 if ((adev->voice.tty_mode != TTY_MODE_OFF) &&
1215 !voice_extn_compress_voip_is_active(adev)) {
1216 switch (adev->voice.tty_mode) {
1217 case TTY_MODE_FULL:
1218 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
1219 break;
1220 case TTY_MODE_VCO:
1221 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
1222 break;
1223 case TTY_MODE_HCO:
1224 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
1225 break;
1226 default:
1227 ALOGE("%s: Invalid TTY mode (%#x)",
1228 __func__, adev->voice.tty_mode);
1229 }
1230 } else if (audio_extn_get_anc_enabled()) {
1231 if (audio_extn_should_use_fb_anc())
1232 snd_device = SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET;
1233 else
1234 snd_device = SND_DEVICE_OUT_VOICE_ANC_HEADSET;
1235 } else {
1236 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
1237 }
1238 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
1239 if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ)
1240 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
1241 else
1242 snd_device = SND_DEVICE_OUT_BT_SCO;
1243 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
1244 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
1245 } else if (devices & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
1246 devices & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
1247 snd_device = SND_DEVICE_OUT_USB_HEADSET;
1248 } else if (devices & AUDIO_DEVICE_OUT_FM_TX) {
1249 snd_device = SND_DEVICE_OUT_TRANSMISSION_FM;
1250 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
1251 if (audio_extn_should_use_handset_anc(channel_count))
1252 snd_device = SND_DEVICE_OUT_ANC_HANDSET;
1253 else
1254 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
1255 }
1256 if (snd_device != SND_DEVICE_NONE) {
1257 goto exit;
1258 }
1259 }
1260
Naresh Tannirue3b18452014-03-04 14:44:27 +05301261 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1262 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301263 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADSET
1264 && audio_extn_get_anc_enabled()) {
1265 if (audio_extn_should_use_fb_anc())
1266 snd_device = SND_DEVICE_OUT_ANC_FB_HEADSET;
1267 else
1268 snd_device = SND_DEVICE_OUT_ANC_HEADSET;
1269 }
1270 else
1271 snd_device = SND_DEVICE_OUT_HEADPHONES;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301272 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
1273 if (adev->speaker_lr_swap)
1274 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
1275 else
1276 snd_device = SND_DEVICE_OUT_SPEAKER;
1277 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301278 if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ)
1279 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
1280 else
1281 snd_device = SND_DEVICE_OUT_BT_SCO;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301282 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
1283 snd_device = SND_DEVICE_OUT_HDMI ;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301284 } else if (devices & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
1285 devices & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
Mingming Yin5a7c5d62014-03-05 17:45:03 -08001286 ALOGD("%s: setting USB hadset channel capability(2) for Proxy", __func__);
1287 audio_extn_set_afe_proxy_channel_mixer(adev, 2);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301288 snd_device = SND_DEVICE_OUT_USB_HEADSET;
1289 } else if (devices & AUDIO_DEVICE_OUT_FM_TX) {
1290 snd_device = SND_DEVICE_OUT_TRANSMISSION_FM;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301291 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
1292 snd_device = SND_DEVICE_OUT_HANDSET;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301293 } else if (devices & AUDIO_DEVICE_OUT_PROXY) {
Mingming Yin5a7c5d62014-03-05 17:45:03 -08001294 channel_count = audio_extn_get_afe_proxy_channel_count();
1295 ALOGD("%s: setting sink capability(%d) for Proxy", __func__, channel_count);
1296 audio_extn_set_afe_proxy_channel_mixer(adev, channel_count);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301297 snd_device = SND_DEVICE_OUT_AFE_PROXY;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301298 } else {
1299 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
1300 }
1301exit:
1302 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
1303 return snd_device;
1304}
1305
1306snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
1307{
1308 struct platform_data *my_data = (struct platform_data *)platform;
1309 struct audio_device *adev = my_data->adev;
1310 audio_source_t source = (adev->active_input == NULL) ?
1311 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
1312
1313 audio_mode_t mode = adev->mode;
1314 audio_devices_t in_device = ((adev->active_input == NULL) ?
1315 AUDIO_DEVICE_NONE : adev->active_input->device)
1316 & ~AUDIO_DEVICE_BIT_IN;
1317 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
1318 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
1319 snd_device_t snd_device = SND_DEVICE_NONE;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301320 int channel_count = popcount(channel_mask);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301321
1322 ALOGV("%s: enter: out_device(%#x) in_device(%#x)",
1323 __func__, out_device, in_device);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301324 if ((out_device != AUDIO_DEVICE_NONE) && ((mode == AUDIO_MODE_IN_CALL) ||
1325 voice_extn_compress_voip_is_active(adev))) {
1326 if ((adev->voice.tty_mode != TTY_MODE_OFF) &&
1327 !voice_extn_compress_voip_is_active(adev)) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301328 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1329 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301330 switch (adev->voice.tty_mode) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301331 case TTY_MODE_FULL:
1332 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
1333 break;
1334 case TTY_MODE_VCO:
1335 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
1336 break;
1337 case TTY_MODE_HCO:
1338 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
1339 break;
1340 default:
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301341 ALOGE("%s: Invalid TTY mode (%#x)",
1342 __func__, adev->voice.tty_mode);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301343 }
1344 goto exit;
1345 }
1346 }
1347 if (out_device & AUDIO_DEVICE_OUT_EARPIECE ||
1348 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301349 if (out_device & AUDIO_DEVICE_OUT_EARPIECE &&
1350 audio_extn_should_use_handset_anc(channel_count)) {
1351 snd_device = SND_DEVICE_IN_AANC_HANDSET_MIC;
1352 } else if (my_data->fluence_type == FLUENCE_NONE ||
1353 my_data->fluence_in_voice_call == false) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301354 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301355 set_echo_reference(adev->mixer, EC_REF_RX);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301356 } else {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301357 snd_device = SND_DEVICE_IN_VOICE_DMIC;
1358 adev->acdb_settings |= DMIC_FLAG;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301359 }
1360 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
1361 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
Satya Krishna Pindiproli624c7802014-04-11 11:33:27 +05301362 set_echo_reference(adev->mixer, EC_REF_RX);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301363 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301364 if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ)
1365 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
1366 else
1367 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301368 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301369 if (my_data->fluence_type != FLUENCE_NONE &&
1370 my_data->fluence_in_voice_call &&
1371 my_data->fluence_in_spkr_mode) {
1372 if(my_data->fluence_type & FLUENCE_QUAD_MIC) {
1373 adev->acdb_settings |= QMIC_FLAG;
1374 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_QMIC;
1375 } else {
1376 adev->acdb_settings |= DMIC_FLAG;
1377 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
1378 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05301379 } else {
1380 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
Satya Krishna Pindiproli624c7802014-04-11 11:33:27 +05301381 set_echo_reference(adev->mixer, EC_REF_RX);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301382 }
1383 }
1384 } else if (source == AUDIO_SOURCE_CAMCORDER) {
1385 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
1386 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
1387 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
1388 }
1389 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
1390 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301391 if (channel_count == 2) {
1392 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
1393 adev->acdb_settings |= DMIC_FLAG;
1394 } else if (adev->active_input->enable_ns)
1395 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
1396 else if (my_data->fluence_type != FLUENCE_NONE &&
1397 my_data->fluence_in_voice_rec) {
1398 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
1399 adev->acdb_settings |= DMIC_FLAG;
1400 } else {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301401 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
1402 }
1403 }
1404 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION) {
1405 if (out_device & AUDIO_DEVICE_OUT_SPEAKER)
1406 in_device = AUDIO_DEVICE_IN_BACK_MIC;
1407 if (adev->active_input) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301408 if (adev->active_input->enable_aec &&
1409 adev->active_input->enable_ns) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301410 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301411 if (my_data->fluence_type & FLUENCE_DUAL_MIC &&
1412 my_data->fluence_in_spkr_mode) {
1413 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
1414 adev->acdb_settings |= DMIC_FLAG;
1415 } else
1416 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301417 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301418 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1419 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
1420 adev->acdb_settings |= DMIC_FLAG;
1421 } else
1422 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301423 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301424 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301425 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301426 set_echo_reference(adev->mixer, EC_REF_RX);
1427 } else if (adev->active_input->enable_aec) {
1428 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
1429 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1430 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
1431 adev->acdb_settings |= DMIC_FLAG;
1432 } else
1433 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
1434 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
1435 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1436 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
1437 adev->acdb_settings |= DMIC_FLAG;
1438 } else
1439 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
1440 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
1441 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
1442 }
1443 set_echo_reference(adev->mixer, EC_REF_RX);
1444 } else if (adev->active_input->enable_ns) {
1445 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
1446 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1447 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
1448 adev->acdb_settings |= DMIC_FLAG;
1449 } else
1450 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
1451 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
1452 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1453 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
1454 adev->acdb_settings |= DMIC_FLAG;
1455 } else
1456 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
1457 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
1458 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
1459 }
1460 set_echo_reference(adev->mixer, "NONE");
Naresh Tannirue3b18452014-03-04 14:44:27 +05301461 } else
1462 set_echo_reference(adev->mixer, "NONE");
1463 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301464 } else if (source == AUDIO_SOURCE_MIC) {
1465 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC &&
1466 channel_count == 1 ) {
1467 if(my_data->fluence_type & FLUENCE_DUAL_MIC &&
1468 my_data->fluence_in_audio_rec)
1469 snd_device = SND_DEVICE_IN_HANDSET_DMIC;
1470 }
1471 } else if (source == AUDIO_SOURCE_FM_RX ||
1472 source == AUDIO_SOURCE_FM_RX_A2DP) {
1473 snd_device = SND_DEVICE_IN_CAPTURE_FM;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301474 } else if (source == AUDIO_SOURCE_DEFAULT) {
1475 goto exit;
1476 }
1477
1478
1479 if (snd_device != SND_DEVICE_NONE) {
1480 goto exit;
1481 }
1482
1483 if (in_device != AUDIO_DEVICE_NONE &&
1484 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
1485 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
1486 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301487 if (audio_extn_ssr_get_enabled() && channel_count == 6)
1488 snd_device = SND_DEVICE_IN_QUAD_MIC;
1489 else if (channel_count == 2)
1490 snd_device = SND_DEVICE_IN_HANDSET_STEREO_DMIC;
1491 else
1492 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301493 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
1494 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
1495 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
1496 snd_device = SND_DEVICE_IN_HEADSET_MIC;
1497 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301498 if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ)
1499 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
1500 else
1501 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301502 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
1503 snd_device = SND_DEVICE_IN_HDMI_MIC;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301504 } else if (in_device & AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET ||
1505 in_device & AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET) {
1506 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
1507 } else if (in_device & AUDIO_DEVICE_IN_FM_RX) {
1508 snd_device = SND_DEVICE_IN_CAPTURE_FM;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301509 } else {
1510 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
1511 ALOGW("%s: Using default handset-mic", __func__);
1512 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1513 }
1514 } else {
1515 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
1516 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1517 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
1518 snd_device = SND_DEVICE_IN_HEADSET_MIC;
1519 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301520 if (channel_count > 1)
1521 snd_device = SND_DEVICE_IN_SPEAKER_STEREO_DMIC;
1522 else
1523 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301524 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
1525 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1526 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301527 if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ)
1528 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
1529 else
1530 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301531 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
1532 snd_device = SND_DEVICE_IN_HDMI_MIC;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301533 } else if (out_device & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
1534 out_device & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
1535 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301536 } else {
1537 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
1538 ALOGW("%s: Using default handset-mic", __func__);
1539 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1540 }
1541 }
1542exit:
1543 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
1544 return snd_device;
1545}
1546
1547int platform_set_hdmi_channels(void *platform, int channel_count)
1548{
1549 struct platform_data *my_data = (struct platform_data *)platform;
1550 struct audio_device *adev = my_data->adev;
1551 struct mixer_ctl *ctl;
1552 const char *channel_cnt_str = NULL;
1553 const char *mixer_ctl_name = "HDMI_RX Channels";
1554 switch (channel_count) {
1555 case 8:
1556 channel_cnt_str = "Eight"; break;
1557 case 7:
1558 channel_cnt_str = "Seven"; break;
1559 case 6:
1560 channel_cnt_str = "Six"; break;
1561 case 5:
1562 channel_cnt_str = "Five"; break;
1563 case 4:
1564 channel_cnt_str = "Four"; break;
1565 case 3:
1566 channel_cnt_str = "Three"; break;
1567 default:
1568 channel_cnt_str = "Two"; break;
1569 }
1570 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1571 if (!ctl) {
1572 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1573 __func__, mixer_ctl_name);
1574 return -EINVAL;
1575 }
1576 ALOGV("HDMI channel count: %s", channel_cnt_str);
1577 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
1578 return 0;
1579}
1580
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301581int platform_edid_get_max_channels(void *platform)
Naresh Tannirue3b18452014-03-04 14:44:27 +05301582{
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301583 struct platform_data *my_data = (struct platform_data *)platform;
1584 struct audio_device *adev = my_data->adev;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301585 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
1586 char *sad = block;
1587 int num_audio_blocks;
1588 int channel_count;
1589 int max_channels = 0;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301590 int i, ret, count;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301591
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301592 struct mixer_ctl *ctl;
1593
1594 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
1595 if (!ctl) {
1596 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1597 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301598 return 0;
1599 }
1600
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301601 mixer_ctl_update(ctl);
1602
1603 count = mixer_ctl_get_num_values(ctl);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301604
1605 /* Read SAD blocks, clamping the maximum size for safety */
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301606 if (count > (int)sizeof(block))
1607 count = (int)sizeof(block);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301608
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301609 ret = mixer_ctl_get_array(ctl, block, count);
1610 if (ret != 0) {
1611 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
1612 return 0;
1613 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05301614
1615 /* Calculate the number of SAD blocks */
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301616 num_audio_blocks = count / SAD_BLOCK_SIZE;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301617
1618 for (i = 0; i < num_audio_blocks; i++) {
1619 /* Only consider LPCM blocks */
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301620 if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
1621 sad += 3;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301622 continue;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301623 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05301624
1625 channel_count = (sad[0] & 0x7) + 1;
1626 if (channel_count > max_channels)
1627 max_channels = channel_count;
1628
1629 /* Advance to next block */
1630 sad += 3;
1631 }
1632
1633 return max_channels;
1634}
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301635
1636static int platform_set_slowtalk(struct platform_data *my_data, bool state)
1637{
1638 int ret = 0;
1639 struct audio_device *adev = my_data->adev;
1640 struct mixer_ctl *ctl;
1641 const char *mixer_ctl_name = "Slowtalk Enable";
1642 uint32_t set_values[ ] = {0,
1643 ALL_SESSION_VSID};
1644
1645 set_values[0] = state;
1646 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1647 if (!ctl) {
1648 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1649 __func__, mixer_ctl_name);
1650 ret = -EINVAL;
1651 } else {
1652 ALOGV("Setting slowtalk state: %d", state);
1653 ret = mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1654 my_data->slowtalk = state;
1655 }
1656
1657 if (my_data->csd != NULL) {
1658 ret = my_data->csd->slow_talk(ALL_SESSION_VSID, state);
1659 if (ret < 0) {
1660 ALOGE("%s: csd_client_disable_device, failed, error %d",
1661 __func__, ret);
1662 }
1663 }
1664 return ret;
1665}
1666
1667int platform_set_parameters(void *platform, struct str_parms *parms)
1668{
1669 struct platform_data *my_data = (struct platform_data *)platform;
1670 char *str;
1671 char value[256] = {0};
1672 int val;
1673 int ret = 0, err;
1674
1675 ALOGV("%s: enter: %s", __func__, str_parms_to_str(parms));
1676
1677 err = str_parms_get_int(parms, AUDIO_PARAMETER_KEY_BTSCO, &val);
1678 if (err >= 0) {
1679 str_parms_del(parms, AUDIO_PARAMETER_KEY_BTSCO);
1680 my_data->btsco_sample_rate = val;
1681 if (val == SAMPLE_RATE_16KHZ) {
Haynes Mathew George1376ca62014-04-24 11:55:48 -07001682 audio_route_apply_and_update_path(my_data->adev->audio_route,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301683 "bt-sco-wb-samplerate");
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301684 }
1685 }
1686
1687 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_SLOWTALK, value, sizeof(value));
1688 if (err >= 0) {
1689 bool state = false;
1690 if (!strncmp("true", value, sizeof("true"))) {
1691 state = true;
1692 }
1693
1694 str_parms_del(parms, AUDIO_PARAMETER_KEY_SLOWTALK);
1695 ret = platform_set_slowtalk(my_data, state);
1696 if (ret)
1697 ALOGE("%s: Failed to set slow talk err: %d", __func__, ret);
1698 }
1699
1700 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_VOLUME_BOOST,
1701 value, sizeof(value));
1702 if (err >= 0) {
1703 str_parms_del(parms, AUDIO_PARAMETER_KEY_VOLUME_BOOST);
1704
1705 if (my_data->acdb_reload_vocvoltable == NULL) {
1706 ALOGE("%s: acdb_reload_vocvoltable is NULL", __func__);
1707 } else if (!strcmp(value, "on")) {
1708 if (!my_data->acdb_reload_vocvoltable(VOICE_FEATURE_SET_VOLUME_BOOST)) {
1709 my_data->voice_feature_set = 1;
1710 }
1711 } else {
1712 if (!my_data->acdb_reload_vocvoltable(VOICE_FEATURE_SET_DEFAULT)) {
1713 my_data->voice_feature_set = 0;
1714 }
1715 }
1716 }
1717
1718 ALOGV("%s: exit with code(%d)", __func__, ret);
1719 return ret;
1720}
1721
1722int platform_set_incall_recording_session_id(void *platform,
1723 uint32_t session_id, int rec_mode)
1724{
1725 int ret = 0;
1726 struct platform_data *my_data = (struct platform_data *)platform;
1727 struct audio_device *adev = my_data->adev;
1728 struct mixer_ctl *ctl;
1729 const char *mixer_ctl_name = "Voc VSID";
1730 int num_ctl_values;
1731 int i;
1732
1733 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1734 if (!ctl) {
1735 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1736 __func__, mixer_ctl_name);
1737 ret = -EINVAL;
1738 } else {
1739 num_ctl_values = mixer_ctl_get_num_values(ctl);
1740 for (i = 0; i < num_ctl_values; i++) {
1741 if (mixer_ctl_set_value(ctl, i, session_id)) {
1742 ALOGV("Error: invalid session_id: %x", session_id);
1743 ret = -EINVAL;
1744 break;
1745 }
1746 }
1747 }
1748
1749 if (my_data->csd != NULL) {
1750 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
1751 if (ret < 0) {
1752 ALOGE("%s: csd_client_start_record failed, error %d",
1753 __func__, ret);
1754 }
1755 }
1756
1757 return ret;
1758}
1759
1760int platform_stop_incall_recording_usecase(void *platform)
1761{
1762 int ret = 0;
1763 struct platform_data *my_data = (struct platform_data *)platform;
1764
1765 if (my_data->csd != NULL) {
1766 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
1767 if (ret < 0) {
1768 ALOGE("%s: csd_client_stop_record failed, error %d",
1769 __func__, ret);
1770 }
1771 }
1772
1773 return ret;
1774}
1775
1776int platform_start_incall_music_usecase(void *platform)
1777{
1778 int ret = 0;
1779 struct platform_data *my_data = (struct platform_data *)platform;
1780
1781 if (my_data->csd != NULL) {
1782 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
1783 if (ret < 0) {
1784 ALOGE("%s: csd_client_start_playback failed, error %d",
1785 __func__, ret);
1786 }
1787 }
1788
1789 return ret;
1790}
1791
1792int platform_stop_incall_music_usecase(void *platform)
1793{
1794 int ret = 0;
1795 struct platform_data *my_data = (struct platform_data *)platform;
1796
1797 if (my_data->csd != NULL) {
1798 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
1799 if (ret < 0) {
1800 ALOGE("%s: csd_client_stop_playback failed, error %d",
1801 __func__, ret);
1802 }
1803 }
1804
1805 return ret;
1806}
1807
1808void platform_get_parameters(void *platform,
1809 struct str_parms *query,
1810 struct str_parms *reply)
1811{
1812 struct platform_data *my_data = (struct platform_data *)platform;
1813 char *str = NULL;
1814 char value[256] = {0};
1815 int ret;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301816
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301817 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_SLOWTALK,
1818 value, sizeof(value));
1819 if (ret >= 0) {
1820 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_SLOWTALK,
1821 my_data->slowtalk?"true":"false");
1822 }
1823
1824 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_VOLUME_BOOST,
1825 value, sizeof(value));
1826 if (ret >= 0) {
1827 if (my_data->voice_feature_set == VOICE_FEATURE_SET_VOLUME_BOOST) {
1828 strlcpy(value, "on", sizeof(value));
1829 } else {
1830 strlcpy(value, "off", sizeof(value));
1831 }
1832
1833 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_VOLUME_BOOST, value);
1834 }
1835
1836 ALOGV("%s: exit: returns - %s", __func__, str_parms_to_str(reply));
1837}
1838
1839/* Delay in Us */
1840int64_t platform_render_latency(audio_usecase_t usecase)
1841{
1842 switch (usecase) {
1843 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
1844 return DEEP_BUFFER_PLATFORM_DELAY;
1845 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
1846 return LOW_LATENCY_PLATFORM_DELAY;
1847 default:
1848 return 0;
1849 }
1850}
1851
1852int platform_update_usecase_from_source(int source, int usecase)
1853{
1854 ALOGV("%s: input source :%d", __func__, source);
1855 if(source == AUDIO_SOURCE_FM_RX_A2DP)
1856 usecase = USECASE_AUDIO_RECORD_FM_VIRTUAL;
1857 return usecase;
1858}
1859
1860bool platform_listen_update_status(snd_device_t snd_device)
1861{
1862 if ((snd_device >= SND_DEVICE_IN_BEGIN) &&
1863 (snd_device < SND_DEVICE_IN_END) &&
1864 (snd_device != SND_DEVICE_IN_CAPTURE_FM) &&
1865 (snd_device != SND_DEVICE_IN_CAPTURE_VI_FEEDBACK))
1866 return true;
1867 else
1868 return false;
1869}
1870
1871/* Read offload buffer size from a property.
1872 * If value is not power of 2 round it to
1873 * power of 2.
1874 */
1875uint32_t platform_get_compress_offload_buffer_size(audio_offload_info_t* info)
1876{
1877 char value[PROPERTY_VALUE_MAX] = {0};
1878 uint32_t fragment_size = COMPRESS_OFFLOAD_FRAGMENT_SIZE;
1879 if((property_get("audio.offload.buffer.size.kb", value, "")) &&
1880 atoi(value)) {
1881 fragment_size = atoi(value) * 1024;
1882 }
1883
1884 if (info != NULL && info->has_video && info->is_streaming) {
1885 fragment_size = COMPRESS_OFFLOAD_FRAGMENT_SIZE_FOR_AV_STREAMING;
1886 ALOGV("%s: offload fragment size reduced for AV streaming to %d",
1887 __func__, out->compr_config.fragment_size);
1888 }
1889
1890 fragment_size = ALIGN( fragment_size, 1024);
1891
1892 if(fragment_size < MIN_COMPRESS_OFFLOAD_FRAGMENT_SIZE)
1893 fragment_size = MIN_COMPRESS_OFFLOAD_FRAGMENT_SIZE;
1894 else if(fragment_size > MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE)
1895 fragment_size = MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE;
1896 ALOGV("%s: fragment_size %d", __func__, fragment_size);
1897 return fragment_size;
1898}
1899
1900uint32_t platform_get_pcm_offload_buffer_size(audio_offload_info_t* info)
1901{
1902 uint32_t fragment_size = MIN_PCM_OFFLOAD_FRAGMENT_SIZE;
1903 uint32_t bits_per_sample = 16;
1904
1905 if (info->format == AUDIO_FORMAT_PCM_24_BIT_OFFLOAD) {
1906 bits_per_sample = 32;
1907 }
1908
1909 if (!info->has_video) {
1910 fragment_size = MAX_PCM_OFFLOAD_FRAGMENT_SIZE;
1911
1912 } else if (info->has_video && info->is_streaming) {
1913 fragment_size = (PCM_OFFLOAD_BUFFER_DURATION_FOR_AV_STREAMING
1914 * info->sample_rate
1915 * bits_per_sample
1916 * popcount(info->channel_mask))/1000;
1917
1918 } else if (info->has_video) {
1919 fragment_size = (PCM_OFFLOAD_BUFFER_DURATION_FOR_AV
1920 * info->sample_rate
1921 * bits_per_sample
1922 * popcount(info->channel_mask))/1000;
1923 }
1924
1925 fragment_size = ALIGN( fragment_size, 1024);
1926
1927 if(fragment_size < MIN_PCM_OFFLOAD_FRAGMENT_SIZE)
1928 fragment_size = MIN_PCM_OFFLOAD_FRAGMENT_SIZE;
1929 else if(fragment_size > MAX_PCM_OFFLOAD_FRAGMENT_SIZE)
1930 fragment_size = MAX_PCM_OFFLOAD_FRAGMENT_SIZE;
1931
1932 ALOGV("%s: fragment_size %d", __func__, fragment_size);
1933 return fragment_size;
1934}
1935