blob: d92f707d42b5d15f98f62e15c46733a045d0e02c [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
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -070073/* fallback app type if the default app type from acdb loader fails */
74#define DEFAULT_APP_TYPE 0x11130
75
Naresh Tannirudb72d1e2014-03-05 17:33:47 +053076/* Retry for delay in FW loading*/
77#define RETRY_NUMBER 20
78#define RETRY_US 500000
79#define MAX_SND_CARD 8
80
81#define SAMPLE_RATE_8KHZ 8000
82#define SAMPLE_RATE_16KHZ 16000
83
84#define AUDIO_PARAMETER_KEY_FLUENCE_TYPE "fluence"
85#define AUDIO_PARAMETER_KEY_BTSCO "bt_samplerate"
86#define AUDIO_PARAMETER_KEY_SLOWTALK "st_enable"
87#define AUDIO_PARAMETER_KEY_VOLUME_BOOST "volume_boost"
88
89enum {
90 VOICE_FEATURE_SET_DEFAULT,
91 VOICE_FEATURE_SET_VOLUME_BOOST
92};
93
Naresh Tannirue3b18452014-03-04 14:44:27 +053094struct audio_block_header
95{
96 int reserved;
97 int length;
98};
99
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530100/* Audio calibration related functions */
Naresh Tannirue3b18452014-03-04 14:44:27 +0530101typedef void (*acdb_deallocate_t)();
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530102typedef int (*acdb_init_t)(char *);
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -0700103typedef void (*acdb_send_audio_cal_t)(int, int, int, int);
Naresh Tannirue3b18452014-03-04 14:44:27 +0530104typedef void (*acdb_send_voice_cal_t)(int, int);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530105typedef int (*acdb_reload_vocvoltable_t)(int);
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -0700106typedef int (*acdb_get_default_app_type_t)(void);
Naresh Tannirue3b18452014-03-04 14:44:27 +0530107
Naresh Tannirue3b18452014-03-04 14:44:27 +0530108struct platform_data {
109 struct audio_device *adev;
110 bool fluence_in_spkr_mode;
111 bool fluence_in_voice_call;
112 bool fluence_in_voice_rec;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530113 bool fluence_in_audio_rec;
114 int fluence_type;
Venkata Narendra Kumar Gutta88fd0bc2014-03-27 19:47:56 +0530115 char fluence_cap[PROPERTY_VALUE_MAX];
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530116 int btsco_sample_rate;
117 bool slowtalk;
118 /* Audio calibration related functions */
119 void *acdb_handle;
120 int voice_feature_set;
121 acdb_init_t acdb_init;
122 acdb_deallocate_t acdb_deallocate;
123 acdb_send_audio_cal_t acdb_send_audio_cal;
124 acdb_send_voice_cal_t acdb_send_voice_cal;
125 acdb_reload_vocvoltable_t acdb_reload_vocvoltable;
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -0700126 acdb_get_default_app_type_t acdb_get_default_app_type;
Naresh Tannirue3b18452014-03-04 14:44:27 +0530127
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530128 void *hw_info;
129 struct csd_data *csd;
Naresh Tannirue3b18452014-03-04 14:44:27 +0530130};
131
132static const int pcm_device_table[AUDIO_USECASE_MAX][2] = {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530133 [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = {DEEP_BUFFER_PCM_DEVICE,
134 DEEP_BUFFER_PCM_DEVICE},
135 [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
136 LOWLATENCY_PCM_DEVICE},
137 [USECASE_AUDIO_PLAYBACK_MULTI_CH] = {MULTIMEDIA2_PCM_DEVICE,
138 MULTIMEDIA2_PCM_DEVICE},
139 [USECASE_AUDIO_PLAYBACK_OFFLOAD] =
140 {PLAYBACK_OFFLOAD_DEVICE, PLAYBACK_OFFLOAD_DEVICE},
141 [USECASE_AUDIO_RECORD] = {AUDIO_RECORD_PCM_DEVICE, AUDIO_RECORD_PCM_DEVICE},
142 [USECASE_AUDIO_RECORD_COMPRESS] = {COMPRESS_CAPTURE_DEVICE, COMPRESS_CAPTURE_DEVICE},
143 [USECASE_AUDIO_RECORD_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
144 LOWLATENCY_PCM_DEVICE},
145 [USECASE_AUDIO_RECORD_FM_VIRTUAL] = {MULTIMEDIA2_PCM_DEVICE,
146 MULTIMEDIA2_PCM_DEVICE},
147 [USECASE_AUDIO_PLAYBACK_FM] = {FM_PLAYBACK_PCM_DEVICE, FM_CAPTURE_PCM_DEVICE},
148 [USECASE_AUDIO_HFP_SCO] = {HFP_PCM_RX, HFP_SCO_RX},
149 [USECASE_AUDIO_HFP_SCO_WB] = {HFP_PCM_RX, HFP_SCO_RX},
150 [USECASE_VOICE_CALL] = {VOICE_CALL_PCM_DEVICE, VOICE_CALL_PCM_DEVICE},
151 [USECASE_VOICE2_CALL] = {VOICE2_CALL_PCM_DEVICE, VOICE2_CALL_PCM_DEVICE},
152 [USECASE_VOLTE_CALL] = {VOLTE_CALL_PCM_DEVICE, VOLTE_CALL_PCM_DEVICE},
153 [USECASE_QCHAT_CALL] = {QCHAT_CALL_PCM_DEVICE, QCHAT_CALL_PCM_DEVICE},
Karthik Reddy Katta3b0a60c2014-04-06 14:52:37 +0530154 [USECASE_VOWLAN_CALL] = {VOWLAN_CALL_PCM_DEVICE, VOWLAN_CALL_PCM_DEVICE},
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530155 [USECASE_COMPRESS_VOIP_CALL] = {COMPRESS_VOIP_CALL_PCM_DEVICE, COMPRESS_VOIP_CALL_PCM_DEVICE},
156 [USECASE_INCALL_REC_UPLINK] = {AUDIO_RECORD_PCM_DEVICE,
157 AUDIO_RECORD_PCM_DEVICE},
158 [USECASE_INCALL_REC_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
159 AUDIO_RECORD_PCM_DEVICE},
160 [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
161 AUDIO_RECORD_PCM_DEVICE},
162 [USECASE_INCALL_REC_UPLINK_COMPRESS] = {COMPRESS_CAPTURE_DEVICE,
163 COMPRESS_CAPTURE_DEVICE},
164 [USECASE_INCALL_REC_DOWNLINK_COMPRESS] = {COMPRESS_CAPTURE_DEVICE,
165 COMPRESS_CAPTURE_DEVICE},
166 [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK_COMPRESS] = {COMPRESS_CAPTURE_DEVICE,
167 COMPRESS_CAPTURE_DEVICE},
168 [USECASE_INCALL_MUSIC_UPLINK] = {INCALL_MUSIC_UPLINK_PCM_DEVICE,
169 INCALL_MUSIC_UPLINK_PCM_DEVICE},
170 [USECASE_INCALL_MUSIC_UPLINK2] = {INCALL_MUSIC_UPLINK2_PCM_DEVICE,
171 INCALL_MUSIC_UPLINK2_PCM_DEVICE},
172 [USECASE_AUDIO_SPKR_CALIB_RX] = {SPKR_PROT_CALIB_RX_PCM_DEVICE, -1},
173 [USECASE_AUDIO_SPKR_CALIB_TX] = {-1, SPKR_PROT_CALIB_TX_PCM_DEVICE},
Naresh Tannirue3b18452014-03-04 14:44:27 +0530174};
175
176/* Array to store sound devices */
177static const char * const device_table[SND_DEVICE_MAX] = {
178 [SND_DEVICE_NONE] = "none",
179 /* Playback sound devices */
180 [SND_DEVICE_OUT_HANDSET] = "handset",
181 [SND_DEVICE_OUT_SPEAKER] = "speaker",
182 [SND_DEVICE_OUT_SPEAKER_REVERSE] = "speaker-reverse",
183 [SND_DEVICE_OUT_HEADPHONES] = "headphones",
184 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones",
185 [SND_DEVICE_OUT_VOICE_HANDSET] = "voice-handset",
186 [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker",
187 [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones",
188 [SND_DEVICE_OUT_HDMI] = "hdmi",
189 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi",
190 [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530191 [SND_DEVICE_OUT_BT_SCO_WB] = "bt-sco-headset-wb",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530192 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones",
193 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones",
194 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530195 [SND_DEVICE_OUT_AFE_PROXY] = "afe-proxy",
196 [SND_DEVICE_OUT_USB_HEADSET] = "usb-headphones",
197 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = "speaker-and-usb-headphones",
198 [SND_DEVICE_OUT_TRANSMISSION_FM] = "transmission-fm",
199 [SND_DEVICE_OUT_ANC_HEADSET] = "anc-headphones",
200 [SND_DEVICE_OUT_ANC_FB_HEADSET] = "anc-fb-headphones",
201 [SND_DEVICE_OUT_VOICE_ANC_HEADSET] = "voice-anc-headphones",
202 [SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET] = "voice-anc-fb-headphones",
203 [SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET] = "speaker-and-anc-headphones",
204 [SND_DEVICE_OUT_ANC_HANDSET] = "anc-handset",
205 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = "speaker-protected",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530206
207 /* Capture sound devices */
208 [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530209 [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530210 [SND_DEVICE_IN_HANDSET_MIC_NS] = "handset-mic",
211 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = "handset-mic",
212 [SND_DEVICE_IN_HANDSET_DMIC] = "dmic-endfire",
213 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = "dmic-endfire",
214 [SND_DEVICE_IN_HANDSET_DMIC_NS] = "dmic-endfire",
215 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = "dmic-endfire",
216 [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
217 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "speaker-mic",
218 [SND_DEVICE_IN_SPEAKER_MIC_NS] = "speaker-mic",
219 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = "speaker-mic",
220 [SND_DEVICE_IN_SPEAKER_DMIC] = "speaker-dmic-endfire",
221 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = "speaker-dmic-endfire",
222 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = "speaker-dmic-endfire",
223 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = "speaker-dmic-endfire",
224 [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
225 [SND_DEVICE_IN_HEADSET_MIC_FLUENCE] = "headset-mic",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530226 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
227 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
228 [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic",
229 [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530230 [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530231 [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530232 [SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef",
233 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = "voice-speaker-dmic-ef",
234 [SND_DEVICE_IN_VOICE_SPEAKER_QMIC] = "voice-speaker-qmic",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530235 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
236 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
237 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
238 [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530239 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = "voice-rec-mic",
240 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = "voice-rec-dmic-ef",
241 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence",
242 [SND_DEVICE_IN_USB_HEADSET_MIC] = "usb-headset-mic",
243 [SND_DEVICE_IN_CAPTURE_FM] = "capture-fm",
244 [SND_DEVICE_IN_AANC_HANDSET_MIC] = "aanc-handset-mic",
245 [SND_DEVICE_IN_QUAD_MIC] = "quad-mic",
246 [SND_DEVICE_IN_HANDSET_STEREO_DMIC] = "handset-stereo-dmic-ef",
247 [SND_DEVICE_IN_SPEAKER_STEREO_DMIC] = "speaker-stereo-dmic-ef",
248 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = "vi-feedback",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530249};
250
251/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530252static int acdb_device_table[SND_DEVICE_MAX] = {
Naresh Tannirue3b18452014-03-04 14:44:27 +0530253 [SND_DEVICE_NONE] = -1,
254 [SND_DEVICE_OUT_HANDSET] = 7,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530255 [SND_DEVICE_OUT_SPEAKER] = 14,
256 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 14,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530257 [SND_DEVICE_OUT_HEADPHONES] = 10,
258 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
259 [SND_DEVICE_OUT_VOICE_HANDSET] = 7,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530260 [SND_DEVICE_OUT_VOICE_SPEAKER] = 14,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530261 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
262 [SND_DEVICE_OUT_HDMI] = 18,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530263 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 14,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530264 [SND_DEVICE_OUT_BT_SCO] = 22,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530265 [SND_DEVICE_OUT_BT_SCO_WB] = 39,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530266 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
267 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
268 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530269 [SND_DEVICE_OUT_AFE_PROXY] = 0,
270 [SND_DEVICE_OUT_USB_HEADSET] = 45,
271 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = 14,
272 [SND_DEVICE_OUT_TRANSMISSION_FM] = 0,
273 [SND_DEVICE_OUT_ANC_HEADSET] = 26,
274 [SND_DEVICE_OUT_ANC_FB_HEADSET] = 27,
275 [SND_DEVICE_OUT_VOICE_ANC_HEADSET] = 26,
276 [SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET] = 27,
277 [SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET] = 26,
278 [SND_DEVICE_OUT_ANC_HANDSET] = 103,
279 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = 101,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530280
281 [SND_DEVICE_IN_HANDSET_MIC] = 4,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530282 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 106,
283 [SND_DEVICE_IN_HANDSET_MIC_NS] = 107,
284 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = 108,
285 [SND_DEVICE_IN_HANDSET_DMIC] = 41,
286 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = 109,
287 [SND_DEVICE_IN_HANDSET_DMIC_NS] = 110,
288 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = 111,
289 [SND_DEVICE_IN_SPEAKER_MIC] = 11,
290 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 112,
291 [SND_DEVICE_IN_SPEAKER_MIC_NS] = 113,
292 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = 114,
293 [SND_DEVICE_IN_SPEAKER_DMIC] = 43,
294 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = 115,
295 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = 116,
296 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = 117,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530297 [SND_DEVICE_IN_HEADSET_MIC] = 8,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530298 [SND_DEVICE_IN_HEADSET_MIC_FLUENCE] = 47,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530299 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
300 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = 8,
301 [SND_DEVICE_IN_HDMI_MIC] = 4,
302 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530303 [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38,
304 [SND_DEVICE_IN_CAMCORDER_MIC] = 4,
305 [SND_DEVICE_IN_VOICE_DMIC] = 41,
306 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 43,
307 [SND_DEVICE_IN_VOICE_SPEAKER_QMIC] = 19,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530308 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
309 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
310 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530311 [SND_DEVICE_IN_VOICE_REC_MIC] = 4,
312 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = 107,
313 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = 34,
314 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 41,
315 [SND_DEVICE_IN_USB_HEADSET_MIC] = 44,
316 [SND_DEVICE_IN_CAPTURE_FM] = 0,
317 [SND_DEVICE_IN_AANC_HANDSET_MIC] = 104,
318 [SND_DEVICE_IN_QUAD_MIC] = 46,
319 [SND_DEVICE_IN_HANDSET_STEREO_DMIC] = 34,
320 [SND_DEVICE_IN_SPEAKER_STEREO_DMIC] = 35,
321 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = 102,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530322};
323
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530324struct snd_device_index {
325 char name[100];
326 unsigned int index;
327};
Naresh Tannirue3b18452014-03-04 14:44:27 +0530328
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530329#define TO_NAME_INDEX(X) #X, X
Naresh Tannirue3b18452014-03-04 14:44:27 +0530330
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530331/* Used to get index from parsed sting */
332struct snd_device_index snd_device_name_index[SND_DEVICE_MAX] = {
333 {TO_NAME_INDEX(SND_DEVICE_OUT_HANDSET)},
334 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER)},
335 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_REVERSE)},
336 {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES)},
337 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES)},
338 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET)},
339 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER)},
340 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADPHONES)},
341 {TO_NAME_INDEX(SND_DEVICE_OUT_HDMI)},
342 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HDMI)},
343 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO)},
344 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO_WB)},
345 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES)},
346 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES)},
347 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET)},
348 {TO_NAME_INDEX(SND_DEVICE_OUT_AFE_PROXY)},
349 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADSET)},
350 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET)},
351 {TO_NAME_INDEX(SND_DEVICE_OUT_TRANSMISSION_FM)},
352 {TO_NAME_INDEX(SND_DEVICE_OUT_ANC_HEADSET)},
353 {TO_NAME_INDEX(SND_DEVICE_OUT_ANC_FB_HEADSET)},
354 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_ANC_HEADSET)},
355 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET)},
356 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET)},
357 {TO_NAME_INDEX(SND_DEVICE_OUT_ANC_HANDSET)},
358 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED)},
359 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC)},
360 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC)},
361 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_NS)},
362 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)},
363 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC)},
364 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC)},
365 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_NS)},
366 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)},
367 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC)},
368 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC)},
369 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_NS)},
370 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)},
371 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC)},
372 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC)},
373 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS)},
374 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)},
375 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC)},
376 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC_FLUENCE)},
377 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC)},
378 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEADSET_MIC)},
379 {TO_NAME_INDEX(SND_DEVICE_IN_HDMI_MIC)},
380 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC)},
381 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB)},
382 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_MIC)},
383 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC)},
384 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC)},
385 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_QMIC)},
386 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC)},
387 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC)},
388 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC)},
389 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC)},
390 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_NS)},
391 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_STEREO)},
392 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE)},
393 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC)},
394 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_FM)},
395 {TO_NAME_INDEX(SND_DEVICE_IN_AANC_HANDSET_MIC)},
396 {TO_NAME_INDEX(SND_DEVICE_IN_QUAD_MIC)},
397 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_STEREO_DMIC)},
398 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_STEREO_DMIC)},
399 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_VI_FEEDBACK)},
400};
401
402#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
403#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
Naresh Tannirue3b18452014-03-04 14:44:27 +0530404
Asish Bhattacharya4ff24802014-04-24 17:46:54 +0530405static void query_platform(const char *snd_card_name,
406 char *mixer_xml_path)
407{
408 if (!strncmp(snd_card_name, "msm8x16-snd-card-mtp",
409 sizeof("msm8x16-snd-card-mtp"))) {
410 strlcpy(mixer_xml_path, MIXER_XML_PATH_MTP,
411 sizeof(MIXER_XML_PATH_MTP));
Walter Yang7ca90d92014-05-06 17:48:02 +0800412 } else if (!strncmp(snd_card_name, "msm8x16-skuh-snd-card",
413 sizeof("msm8x16-skuh-snd-card"))) {
414 strlcpy(mixer_xml_path, MIXER_XML_PATH_QRD_SKUH,
415 sizeof(MIXER_XML_PATH_QRD_SKUH));
416 } else if (!strncmp(snd_card_name, "msm8x16-skui-snd-card",
417 sizeof("msm8x16-skui-snd-card"))) {
418 strlcpy(mixer_xml_path, MIXER_XML_PATH_QRD_SKUI,
419 sizeof(MIXER_XML_PATH_QRD_SKUI));
Yamit Mehtac6003e22014-05-19 10:26:02 +0530420 } if (!strncmp(snd_card_name, "msm8939-snd-card-mtp",
421 sizeof("msm8939-snd-card-mtp"))) {
422 strlcpy(mixer_xml_path, MIXER_XML_PATH,
423 sizeof(MIXER_XML_PATH));
Asish Bhattacharya4ff24802014-04-24 17:46:54 +0530424 } else {
425 strlcpy(mixer_xml_path, MIXER_XML_PATH,
426 sizeof(MIXER_XML_PATH));
427 }
428}
429
Naresh Tannirue3b18452014-03-04 14:44:27 +0530430static int set_echo_reference(struct mixer *mixer, const char* ec_ref)
431{
432 struct mixer_ctl *ctl;
433 const char *mixer_ctl_name = "EC_REF_RX";
434
435 ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name);
436 if (!ctl) {
437 ALOGE("%s: Could not get ctl for mixer cmd - %s",
438 __func__, mixer_ctl_name);
439 return -EINVAL;
440 }
441 ALOGV("Setting EC Reference: %s", ec_ref);
442 mixer_ctl_set_enum_by_string(ctl, ec_ref);
443 return 0;
444}
445
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530446static struct csd_data *open_csd_client()
447{
448 struct csd_data *csd = calloc(1, sizeof(struct csd_data));
449
450 csd->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
451 if (csd->csd_client == NULL) {
452 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
453 goto error;
454 } else {
455 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
456
457 csd->deinit = (deinit_t)dlsym(csd->csd_client,
458 "csd_client_deinit");
459 if (csd->deinit == NULL) {
460 ALOGE("%s: dlsym error %s for csd_client_deinit", __func__,
461 dlerror());
462 goto error;
463 }
464 csd->disable_device = (disable_device_t)dlsym(csd->csd_client,
465 "csd_client_disable_device");
466 if (csd->disable_device == NULL) {
467 ALOGE("%s: dlsym error %s for csd_client_disable_device",
468 __func__, dlerror());
469 goto error;
470 }
471 csd->enable_device_config = (enable_device_config_t)dlsym(csd->csd_client,
472 "csd_client_enable_device_config");
473 if (csd->enable_device_config == NULL) {
474 ALOGE("%s: dlsym error %s for csd_client_enable_device_config",
475 __func__, dlerror());
476 goto error;
477 }
478 csd->enable_device = (enable_device_t)dlsym(csd->csd_client,
479 "csd_client_enable_device");
480 if (csd->enable_device == NULL) {
481 ALOGE("%s: dlsym error %s for csd_client_enable_device",
482 __func__, dlerror());
483 goto error;
484 }
485 csd->start_voice = (start_voice_t)dlsym(csd->csd_client,
486 "csd_client_start_voice");
487 if (csd->start_voice == NULL) {
488 ALOGE("%s: dlsym error %s for csd_client_start_voice",
489 __func__, dlerror());
490 goto error;
491 }
492 csd->stop_voice = (stop_voice_t)dlsym(csd->csd_client,
493 "csd_client_stop_voice");
494 if (csd->stop_voice == NULL) {
495 ALOGE("%s: dlsym error %s for csd_client_stop_voice",
496 __func__, dlerror());
497 goto error;
498 }
499 csd->volume = (volume_t)dlsym(csd->csd_client,
500 "csd_client_volume");
501 if (csd->volume == NULL) {
502 ALOGE("%s: dlsym error %s for csd_client_volume",
503 __func__, dlerror());
504 goto error;
505 }
506 csd->mic_mute = (mic_mute_t)dlsym(csd->csd_client,
507 "csd_client_mic_mute");
508 if (csd->mic_mute == NULL) {
509 ALOGE("%s: dlsym error %s for csd_client_mic_mute",
510 __func__, dlerror());
511 goto error;
512 }
513 csd->slow_talk = (slow_talk_t)dlsym(csd->csd_client,
514 "csd_client_slow_talk");
515 if (csd->slow_talk == NULL) {
516 ALOGE("%s: dlsym error %s for csd_client_slow_talk",
517 __func__, dlerror());
518 goto error;
519 }
520 csd->start_playback = (start_playback_t)dlsym(csd->csd_client,
521 "csd_client_start_playback");
522 if (csd->start_playback == NULL) {
523 ALOGE("%s: dlsym error %s for csd_client_start_playback",
524 __func__, dlerror());
525 goto error;
526 }
527 csd->stop_playback = (stop_playback_t)dlsym(csd->csd_client,
528 "csd_client_stop_playback");
529 if (csd->stop_playback == NULL) {
530 ALOGE("%s: dlsym error %s for csd_client_stop_playback",
531 __func__, dlerror());
532 goto error;
533 }
534 csd->start_record = (start_record_t)dlsym(csd->csd_client,
535 "csd_client_start_record");
536 if (csd->start_record == NULL) {
537 ALOGE("%s: dlsym error %s for csd_client_start_record",
538 __func__, dlerror());
539 goto error;
540 }
541 csd->stop_record = (stop_record_t)dlsym(csd->csd_client,
542 "csd_client_stop_record");
543 if (csd->stop_record == NULL) {
544 ALOGE("%s: dlsym error %s for csd_client_stop_record",
545 __func__, dlerror());
546 goto error;
547 }
548 csd->init = (init_t)dlsym(csd->csd_client, "csd_client_init");
549
550 if (csd->init == NULL) {
551 ALOGE("%s: dlsym error %s for csd_client_init",
552 __func__, dlerror());
553 goto error;
554 } else {
555 csd->init();
556 }
557 }
558 return csd;
559
560error:
561 free(csd);
562 csd = NULL;
563 return csd;
564}
565
566void close_csd_client(struct csd_data *csd)
567{
568 if (csd != NULL) {
569 csd->deinit();
570 dlclose(csd->csd_client);
571 free(csd);
572 csd = NULL;
573 }
574}
575
Naresh Tannirue3b18452014-03-04 14:44:27 +0530576void *platform_init(struct audio_device *adev)
577{
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530578 char platform[PROPERTY_VALUE_MAX];
579 char baseband[PROPERTY_VALUE_MAX];
Naresh Tannirue3b18452014-03-04 14:44:27 +0530580 char value[PROPERTY_VALUE_MAX];
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530581 struct platform_data *my_data = NULL;
582 int retry_num = 0, snd_card_num = 0;
583 const char *snd_card_name;
Asish Bhattacharya4ff24802014-04-24 17:46:54 +0530584 char mixer_xml_path[100];
Naresh Tannirue3b18452014-03-04 14:44:27 +0530585
586 my_data = calloc(1, sizeof(struct platform_data));
587
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530588 while (snd_card_num < MAX_SND_CARD) {
589 adev->mixer = mixer_open(snd_card_num);
590
591 while (!adev->mixer && retry_num < RETRY_NUMBER) {
592 usleep(RETRY_US);
593 adev->mixer = mixer_open(snd_card_num);
594 retry_num++;
595 }
596
597 if (!adev->mixer) {
598 ALOGE("%s: Unable to open the mixer card: %d", __func__,
599 snd_card_num);
600 retry_num = 0;
601 snd_card_num++;
602 continue;
603 }
604
605 snd_card_name = mixer_get_name(adev->mixer);
606 ALOGV("%s: snd_card_name: %s", __func__, snd_card_name);
607
608 my_data->hw_info = hw_info_init(snd_card_name);
609 if (!my_data->hw_info) {
610 ALOGE("%s: Failed to init hardware info", __func__);
611 } else {
Asish Bhattacharya4ff24802014-04-24 17:46:54 +0530612 query_platform(snd_card_name, mixer_xml_path);
613 ALOGD("%s: mixer path file is %s", __func__,
614 mixer_xml_path);
615 if (audio_extn_read_xml(adev, snd_card_num, mixer_xml_path,
616 MIXER_XML_PATH_AUXPCM) == -ENOSYS) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530617 adev->audio_route = audio_route_init(snd_card_num,
Asish Bhattacharya4ff24802014-04-24 17:46:54 +0530618 mixer_xml_path);
619 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530620 if (!adev->audio_route) {
621 ALOGE("%s: Failed to init audio route controls, aborting.",
622 __func__);
623 free(my_data);
624 return NULL;
625 }
626 adev->snd_card = snd_card_num;
627 ALOGD("%s: Opened sound card:%d", __func__, snd_card_num);
628 break;
629 }
630 retry_num = 0;
631 snd_card_num++;
632 }
633
634 if (snd_card_num >= MAX_SND_CARD) {
635 ALOGE("%s: Unable to find correct sound card, aborting.", __func__);
636 free(my_data);
637 return NULL;
638 }
639
Naresh Tannirue3b18452014-03-04 14:44:27 +0530640 my_data->adev = adev;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530641 my_data->btsco_sample_rate = SAMPLE_RATE_8KHZ;
Naresh Tannirue3b18452014-03-04 14:44:27 +0530642 my_data->fluence_in_spkr_mode = false;
643 my_data->fluence_in_voice_call = false;
644 my_data->fluence_in_voice_rec = false;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530645 my_data->fluence_in_audio_rec = false;
646 my_data->fluence_type = FLUENCE_NONE;
Naresh Tannirue3b18452014-03-04 14:44:27 +0530647
Venkata Narendra Kumar Gutta88fd0bc2014-03-27 19:47:56 +0530648 property_get("ro.qc.sdk.audio.fluencetype", my_data->fluence_cap, "");
649 if (!strncmp("fluencepro", my_data->fluence_cap, sizeof("fluencepro"))) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530650 my_data->fluence_type = FLUENCE_QUAD_MIC | FLUENCE_DUAL_MIC;
Venkata Narendra Kumar Gutta88fd0bc2014-03-27 19:47:56 +0530651 } else if (!strncmp("fluence", my_data->fluence_cap, sizeof("fluence"))) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530652 my_data->fluence_type = FLUENCE_DUAL_MIC;
653 } else {
654 my_data->fluence_type = FLUENCE_NONE;
Naresh Tannirue3b18452014-03-04 14:44:27 +0530655 }
656
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530657 if (my_data->fluence_type != FLUENCE_NONE) {
Naresh Tannirue3b18452014-03-04 14:44:27 +0530658 property_get("persist.audio.fluence.voicecall",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_call = true;
661 }
662
663 property_get("persist.audio.fluence.voicerec",value,"");
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530664 if (!strncmp("true", value, sizeof("true"))) {
Naresh Tannirue3b18452014-03-04 14:44:27 +0530665 my_data->fluence_in_voice_rec = true;
666 }
667
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530668 property_get("persist.audio.fluence.audiorec",value,"");
669 if (!strncmp("true", value, sizeof("true"))) {
670 my_data->fluence_in_audio_rec = true;
671 }
672
Naresh Tannirue3b18452014-03-04 14:44:27 +0530673 property_get("persist.audio.fluence.speaker",value,"");
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530674 if (!strncmp("true", value, sizeof("true"))) {
Naresh Tannirue3b18452014-03-04 14:44:27 +0530675 my_data->fluence_in_spkr_mode = true;
676 }
677 }
678
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530679 my_data->voice_feature_set = VOICE_FEATURE_SET_DEFAULT;
Naresh Tannirue3b18452014-03-04 14:44:27 +0530680 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
681 if (my_data->acdb_handle == NULL) {
682 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
683 } else {
684 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
685 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
686 "acdb_loader_deallocate_ACDB");
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530687 if (!my_data->acdb_deallocate)
688 ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s",
689 __func__, LIB_ACDB_LOADER);
690
Naresh Tannirue3b18452014-03-04 14:44:27 +0530691 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -0700692 "acdb_loader_send_audio_cal_v2");
Naresh Tannirue3b18452014-03-04 14:44:27 +0530693 if (!my_data->acdb_send_audio_cal)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530694 ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530695 __func__, LIB_ACDB_LOADER);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530696
Naresh Tannirue3b18452014-03-04 14:44:27 +0530697 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
698 "acdb_loader_send_voice_cal");
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530699 if (!my_data->acdb_send_voice_cal)
700 ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s",
701 __func__, LIB_ACDB_LOADER);
702
703 my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle,
704 "acdb_loader_reload_vocvoltable");
705 if (!my_data->acdb_reload_vocvoltable)
706 ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s",
707 __func__, LIB_ACDB_LOADER);
708
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -0700709 my_data->acdb_get_default_app_type = (acdb_get_default_app_type_t)dlsym(
710 my_data->acdb_handle,
711 "acdb_loader_get_default_app_type");
712 if (!my_data->acdb_get_default_app_type)
713 ALOGE("%s: Could not find the symbol acdb_get_default_app_type from %s",
714 __func__, LIB_ACDB_LOADER);
715
Naresh Tannirue3b18452014-03-04 14:44:27 +0530716 my_data->acdb_init = (acdb_init_t)dlsym(my_data->acdb_handle,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530717 "acdb_loader_init_v2");
Naresh Tannirue3b18452014-03-04 14:44:27 +0530718 if (my_data->acdb_init == NULL)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530719 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__, dlerror());
Naresh Tannirue3b18452014-03-04 14:44:27 +0530720 else
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530721 my_data->acdb_init(snd_card_name);
Naresh Tannirue3b18452014-03-04 14:44:27 +0530722 }
723
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530724 /* Initialize ACDB ID's */
725 platform_info_init(PLATFORM_INFO_XML_PATH);
726
727 /* init usb */
728 audio_extn_usb_init(adev);
729 /* update sound cards appropriately */
730 audio_extn_usb_set_proxy_sound_card(adev->snd_card);
731
732 /* Read one time ssr property */
733 audio_extn_ssr_update_enabled();
734 audio_extn_spkr_prot_init(adev);
Dhananjay Kumar89ea3bd2014-04-29 15:45:57 +0530735
736 audio_extn_dolby_set_license(adev);
737
Naresh Tannirue3b18452014-03-04 14:44:27 +0530738 return my_data;
739}
740
741void platform_deinit(void *platform)
742{
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530743 struct platform_data *my_data = (struct platform_data *)platform;
744
745 hw_info_deinit(my_data->hw_info);
746 close_csd_client(my_data->csd);
747
Naresh Tannirue3b18452014-03-04 14:44:27 +0530748 free(platform);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530749 /* deinit usb */
750 audio_extn_usb_deinit();
Naresh Tannirue3b18452014-03-04 14:44:27 +0530751}
752
753const char *platform_get_snd_device_name(snd_device_t snd_device)
754{
755 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX)
756 return device_table[snd_device];
757 else
758 return "";
759}
760
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530761int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
762 char *device_name)
763{
764 struct platform_data *my_data = (struct platform_data *)platform;
765
766 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
767 strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE);
768 hw_info_append_hw_type(my_data->hw_info, snd_device, device_name);
769 } else {
770 strlcpy(device_name, "", DEVICE_NAME_MAX_SIZE);
771 return -EINVAL;
772 }
773
774 return 0;
775}
776
Naresh Tannirue3b18452014-03-04 14:44:27 +0530777void platform_add_backend_name(char *mixer_path, snd_device_t snd_device)
778{
779 if (snd_device == SND_DEVICE_IN_BT_SCO_MIC)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530780 strlcat(mixer_path, " bt-sco", MIXER_PATH_MAX_LENGTH);
781 else if (snd_device == SND_DEVICE_IN_BT_SCO_MIC_WB)
782 strlcat(mixer_path, " bt-sco-wb", MIXER_PATH_MAX_LENGTH);
Naresh Tannirue3b18452014-03-04 14:44:27 +0530783 else if(snd_device == SND_DEVICE_OUT_BT_SCO)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530784 strlcat(mixer_path, " bt-sco", MIXER_PATH_MAX_LENGTH);
785 else if(snd_device == SND_DEVICE_OUT_BT_SCO_WB)
786 strlcat(mixer_path, " bt-sco-wb", MIXER_PATH_MAX_LENGTH);
Naresh Tannirue3b18452014-03-04 14:44:27 +0530787 else if (snd_device == SND_DEVICE_OUT_HDMI)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530788 strlcat(mixer_path, " hdmi", MIXER_PATH_MAX_LENGTH);
Naresh Tannirue3b18452014-03-04 14:44:27 +0530789 else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HDMI)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530790 strlcat(mixer_path, " speaker-and-hdmi", MIXER_PATH_MAX_LENGTH);
791 else if (snd_device == SND_DEVICE_OUT_AFE_PROXY)
792 strlcat(mixer_path, " afe-proxy", MIXER_PATH_MAX_LENGTH);
793 else if (snd_device == SND_DEVICE_OUT_USB_HEADSET)
794 strlcat(mixer_path, " usb-headphones", MIXER_PATH_MAX_LENGTH);
795 else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET)
796 strlcat(mixer_path, " speaker-and-usb-headphones",
797 MIXER_PATH_MAX_LENGTH);
798 else if (snd_device == SND_DEVICE_IN_USB_HEADSET_MIC)
799 strlcat(mixer_path, " usb-headset-mic", MIXER_PATH_MAX_LENGTH);
800 else if (snd_device == SND_DEVICE_IN_CAPTURE_FM)
801 strlcat(mixer_path, " capture-fm", MIXER_PATH_MAX_LENGTH);
802 else if (snd_device == SND_DEVICE_OUT_TRANSMISSION_FM)
803 strlcat(mixer_path, " transmission-fm", MIXER_PATH_MAX_LENGTH);
Naresh Tannirue3b18452014-03-04 14:44:27 +0530804}
805
806int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
807{
808 int device_id;
809 if (device_type == PCM_PLAYBACK)
810 device_id = pcm_device_table[usecase][0];
811 else
812 device_id = pcm_device_table[usecase][1];
813 return device_id;
814}
815
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530816int platform_get_snd_device_index(char *snd_device_index_name)
817{
818 int ret = 0;
819 int i;
820
821 if (snd_device_index_name == NULL) {
822 ALOGE("%s: snd_device_index_name is NULL", __func__);
823 ret = -ENODEV;
824 goto done;
825 }
826
827 for (i=0; i < SND_DEVICE_MAX; i++) {
828 if(strcmp(snd_device_name_index[i].name, snd_device_index_name) == 0) {
829 ret = snd_device_name_index[i].index;
830 goto done;
831 }
832 }
833 ALOGE("%s: Could not find index for snd_device_index_name = %s",
834 __func__, snd_device_index_name);
835 ret = -ENODEV;
836done:
837 return ret;
838}
839
Venkata Narendra Kumar Gutta88fd0bc2014-03-27 19:47:56 +0530840int platform_set_fluence_type(void *platform, char *value)
841{
842 int ret = 0;
843 int fluence_type = FLUENCE_NONE;
844 int fluence_flag = NONE_FLAG;
845 struct platform_data *my_data = (struct platform_data *)platform;
846 struct audio_device *adev = my_data->adev;
847
848 ALOGV("%s: fluence type:%d", __func__, my_data->fluence_type);
849
850 /* only dual mic turn on and off is supported as of now through setparameters */
851 if (!strncmp(AUDIO_PARAMETER_VALUE_DUALMIC,value, sizeof(AUDIO_PARAMETER_VALUE_DUALMIC))) {
852 if (!strncmp("fluencepro", my_data->fluence_cap, sizeof("fluencepro")) ||
853 !strncmp("fluence", my_data->fluence_cap, sizeof("fluence"))) {
854 ALOGV("fluence dualmic feature enabled \n");
855 fluence_type = FLUENCE_DUAL_MIC;
856 fluence_flag = DMIC_FLAG;
857 } else {
858 ALOGE("%s: Failed to set DUALMIC", __func__);
859 ret = -1;
860 goto done;
861 }
862 } else if (!strncmp(AUDIO_PARAMETER_KEY_NO_FLUENCE, value, sizeof(AUDIO_PARAMETER_KEY_NO_FLUENCE))) {
863 ALOGV("fluence disabled");
864 fluence_type = FLUENCE_NONE;
865 } else {
866 ALOGE("Invalid fluence value : %s",value);
867 ret = -1;
868 goto done;
869 }
870
871 if (fluence_type != my_data->fluence_type) {
872 ALOGV("%s: Updating fluence_type to :%d", __func__, fluence_type);
873 my_data->fluence_type = fluence_type;
874 adev->acdb_settings = (adev->acdb_settings & FLUENCE_MODE_CLEAR) | fluence_flag;
875 }
876done:
877 return ret;
878}
879
880int platform_get_fluence_type(void *platform, char *value, uint32_t len)
881{
882 int ret = 0;
883 struct platform_data *my_data = (struct platform_data *)platform;
884
885 if (my_data->fluence_type == FLUENCE_QUAD_MIC) {
886 strlcpy(value, "quadmic", len);
887 } else if (my_data->fluence_type == FLUENCE_DUAL_MIC) {
888 strlcpy(value, "dualmic", len);
889 } else if (my_data->fluence_type == FLUENCE_NONE) {
890 strlcpy(value, "none", len);
891 } else
892 ret = -1;
893
894 return ret;
895}
896
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530897int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
898{
899 int ret = 0;
900
901 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
902 ALOGE("%s: Invalid snd_device = %d",
903 __func__, snd_device);
904 ret = -EINVAL;
905 goto done;
906 }
907
908 acdb_device_table[snd_device] = acdb_id;
909done:
910 return ret;
911}
912
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -0700913int platform_get_default_app_type(void *platform)
914{
915 struct platform_data *my_data = (struct platform_data *)platform;
916
917 if (my_data->acdb_get_default_app_type)
918 return my_data->acdb_get_default_app_type();
919 else
920 return DEFAULT_APP_TYPE;
921}
922
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700923int platform_get_snd_device_acdb_id(snd_device_t snd_device)
924{
925 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
926 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
927 return -EINVAL;
928 }
929 return acdb_device_table[snd_device];
930}
931
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -0700932int platform_send_audio_calibration(void *platform, snd_device_t snd_device,
933 int app_type, int sample_rate)
Naresh Tannirue3b18452014-03-04 14:44:27 +0530934{
935 struct platform_data *my_data = (struct platform_data *)platform;
936 int acdb_dev_id, acdb_dev_type;
937
938 acdb_dev_id = acdb_device_table[snd_device];
939 if (acdb_dev_id < 0) {
940 ALOGE("%s: Could not find acdb id for device(%d)",
941 __func__, snd_device);
942 return -EINVAL;
943 }
944 if (my_data->acdb_send_audio_cal) {
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -0700945 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530946 __func__, snd_device, acdb_dev_id);
947 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
948 snd_device < SND_DEVICE_OUT_END)
949 acdb_dev_type = ACDB_DEV_TYPE_OUT;
950 else
951 acdb_dev_type = ACDB_DEV_TYPE_IN;
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -0700952 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type, app_type,
953 sample_rate);
Naresh Tannirue3b18452014-03-04 14:44:27 +0530954 }
955 return 0;
956}
957
958int platform_switch_voice_call_device_pre(void *platform)
959{
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530960 struct platform_data *my_data = (struct platform_data *)platform;
961 int ret = 0;
962
963 if (my_data->csd != NULL &&
964 my_data->adev->mode == AUDIO_MODE_IN_CALL) {
965 /* This must be called before disabling mixer controls on APQ side */
966 ret = my_data->csd->disable_device();
967 if (ret < 0) {
968 ALOGE("%s: csd_client_disable_device, failed, error %d",
969 __func__, ret);
970 }
971 }
972 return ret;
Naresh Tannirue3b18452014-03-04 14:44:27 +0530973}
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530974int platform_switch_voice_call_enable_device_config(void *platform,
975 snd_device_t out_snd_device,
976 snd_device_t in_snd_device)
977{
978 struct platform_data *my_data = (struct platform_data *)platform;
979 int acdb_rx_id, acdb_tx_id;
980 int ret = 0;
981
982 acdb_rx_id = acdb_device_table[out_snd_device];
983 acdb_tx_id = acdb_device_table[in_snd_device];
984
985 if (my_data->csd != NULL) {
986 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
987 ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
988 if (ret < 0) {
989 ALOGE("%s: csd_enable_device_config, failed, error %d",
990 __func__, ret);
991 }
992 } else {
993 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
994 acdb_rx_id, acdb_tx_id);
995 }
996 }
997 return ret;
998}
999
Naresh Tannirue3b18452014-03-04 14:44:27 +05301000
1001int platform_switch_voice_call_device_post(void *platform,
1002 snd_device_t out_snd_device,
1003 snd_device_t in_snd_device)
1004{
1005 struct platform_data *my_data = (struct platform_data *)platform;
1006 int acdb_rx_id, acdb_tx_id;
1007
1008 if (my_data->acdb_send_voice_cal == NULL) {
1009 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
1010 } else {
1011 acdb_rx_id = acdb_device_table[out_snd_device];
1012 acdb_tx_id = acdb_device_table[in_snd_device];
1013
1014 if (acdb_rx_id > 0 && acdb_tx_id > 0)
1015 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
1016 else
1017 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1018 acdb_rx_id, acdb_tx_id);
1019 }
1020
1021 return 0;
1022}
1023
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301024int platform_switch_voice_call_usecase_route_post(void *platform,
1025 snd_device_t out_snd_device,
1026 snd_device_t in_snd_device)
Naresh Tannirue3b18452014-03-04 14:44:27 +05301027{
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301028 struct platform_data *my_data = (struct platform_data *)platform;
1029 int acdb_rx_id, acdb_tx_id;
1030 int ret = 0;
1031
1032 acdb_rx_id = acdb_device_table[out_snd_device];
1033 acdb_tx_id = acdb_device_table[in_snd_device];
1034
1035 if (my_data->csd != NULL) {
1036 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
1037 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
1038 my_data->adev->acdb_settings);
1039 if (ret < 0) {
1040 ALOGE("%s: csd_enable_device, failed, error %d",
1041 __func__, ret);
1042 }
1043 } else {
1044 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1045 acdb_rx_id, acdb_tx_id);
1046 }
1047 }
1048 return ret;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301049}
1050
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301051int platform_start_voice_call(void *platform, uint32_t vsid)
1052{
1053 struct platform_data *my_data = (struct platform_data *)platform;
1054 int ret = 0;
1055
1056 if (my_data->csd != NULL) {
1057 ret = my_data->csd->start_voice(vsid);
1058 if (ret < 0) {
1059 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
1060 }
1061 }
1062 return ret;
1063}
1064
1065int platform_stop_voice_call(void *platform, uint32_t vsid)
1066{
1067 struct platform_data *my_data = (struct platform_data *)platform;
1068 int ret = 0;
1069
1070 if (my_data->csd != NULL) {
1071 ret = my_data->csd->stop_voice(vsid);
1072 if (ret < 0) {
1073 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
1074 }
1075 }
1076 return ret;
1077}
1078int platform_get_sample_rate(void *platform, uint32_t *rate)
Naresh Tannirue3b18452014-03-04 14:44:27 +05301079{
1080 return 0;
1081}
1082
1083int platform_set_voice_volume(void *platform, int volume)
1084{
1085 struct platform_data *my_data = (struct platform_data *)platform;
1086 struct audio_device *adev = my_data->adev;
1087 struct mixer_ctl *ctl;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301088 const char *mixer_ctl_name = "Voice Rx Gain";
1089 int vol_index = 0, ret = 0;
1090 uint32_t set_values[ ] = {0,
1091 ALL_SESSION_VSID,
1092 DEFAULT_VOLUME_RAMP_DURATION_MS};
Naresh Tannirue3b18452014-03-04 14:44:27 +05301093
1094 // Voice volume levels are mapped to adsp volume levels as follows.
1095 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
1096 // But this values don't changed in kernel. So, below change is need.
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301097 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, MAX_VOL_INDEX);
1098 set_values[0] = vol_index;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301099
1100 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1101 if (!ctl) {
1102 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1103 __func__, mixer_ctl_name);
1104 return -EINVAL;
1105 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301106 ALOGV("Setting voice volume index: %d", set_values[0]);
1107 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
Naresh Tannirue3b18452014-03-04 14:44:27 +05301108
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301109 if (my_data->csd != NULL) {
1110 ret = my_data->csd->volume(ALL_SESSION_VSID, volume);
1111 if (ret < 0) {
1112 ALOGE("%s: csd_volume error %d", __func__, ret);
1113 }
1114 }
1115 return ret;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301116}
1117
1118int platform_set_mic_mute(void *platform, bool state)
1119{
1120 struct platform_data *my_data = (struct platform_data *)platform;
1121 struct audio_device *adev = my_data->adev;
1122 struct mixer_ctl *ctl;
1123 const char *mixer_ctl_name = "Voice Tx Mute";
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301124 int ret = 0;
1125 uint32_t set_values[ ] = {0,
1126 ALL_SESSION_VSID,
1127 DEFAULT_VOLUME_RAMP_DURATION_MS};
Naresh Tannirue3b18452014-03-04 14:44:27 +05301128
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301129 set_values[0] = state;
1130 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1131 if (!ctl) {
1132 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1133 __func__, mixer_ctl_name);
1134 return -EINVAL;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301135 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301136 ALOGV("Setting voice mute state: %d", state);
1137 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
Naresh Tannirue3b18452014-03-04 14:44:27 +05301138
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301139 if (my_data->csd != NULL) {
1140 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state);
1141 if (ret < 0) {
1142 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
1143 }
1144 }
1145 return ret;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301146}
1147
Shiv Maliyappanahallic6fd8ee2014-03-07 15:31:55 -08001148int platform_set_device_mute(void *platform, bool state, char *dir)
1149{
1150 struct platform_data *my_data = (struct platform_data *)platform;
1151 struct audio_device *adev = my_data->adev;
1152 struct mixer_ctl *ctl;
1153 char *mixer_ctl_name = NULL;
1154 int ret = 0;
1155 uint32_t set_values[ ] = {0,
1156 ALL_SESSION_VSID,
1157 0};
1158 if(dir == NULL) {
1159 ALOGE("%s: Invalid direction:%s", __func__, dir);
1160 return -EINVAL;
1161 }
1162
1163 if (!strncmp("rx", dir, sizeof("rx"))) {
1164 mixer_ctl_name = "Voice Rx Device Mute";
1165 } else if (!strncmp("tx", dir, sizeof("tx"))) {
1166 mixer_ctl_name = "Voice Tx Device Mute";
1167 } else {
1168 return -EINVAL;
1169 }
1170
1171 set_values[0] = state;
1172 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1173 if (!ctl) {
1174 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1175 __func__, mixer_ctl_name);
1176 return -EINVAL;
1177 }
1178
1179 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
1180 __func__,state, mixer_ctl_name);
1181 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1182
1183 return ret;
1184}
1185
Naresh Tannirue3b18452014-03-04 14:44:27 +05301186snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
1187{
1188 struct platform_data *my_data = (struct platform_data *)platform;
1189 struct audio_device *adev = my_data->adev;
1190 audio_mode_t mode = adev->mode;
1191 snd_device_t snd_device = SND_DEVICE_NONE;
1192
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301193 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
1194 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
1195 int channel_count = popcount(channel_mask);
1196
Naresh Tannirue3b18452014-03-04 14:44:27 +05301197 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
1198 if (devices == AUDIO_DEVICE_NONE ||
1199 devices & AUDIO_DEVICE_BIT_IN) {
1200 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
1201 goto exit;
1202 }
1203
Naresh Tannirue3b18452014-03-04 14:44:27 +05301204 if (popcount(devices) == 2) {
1205 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
1206 AUDIO_DEVICE_OUT_SPEAKER)) {
1207 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
1208 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
1209 AUDIO_DEVICE_OUT_SPEAKER)) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301210 if (audio_extn_get_anc_enabled())
1211 snd_device = SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET;
1212 else
1213 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301214 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
1215 AUDIO_DEVICE_OUT_SPEAKER)) {
1216 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301217 } else if (devices == (AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET |
1218 AUDIO_DEVICE_OUT_SPEAKER)) {
1219 snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301220 } else {
1221 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
1222 goto exit;
1223 }
1224 if (snd_device != SND_DEVICE_NONE) {
1225 goto exit;
1226 }
1227 }
1228
1229 if (popcount(devices) != 1) {
1230 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
1231 goto exit;
1232 }
1233
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301234 if ((mode == AUDIO_MODE_IN_CALL) ||
1235 voice_extn_compress_voip_is_active(adev)) {
1236 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1237 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
1238 if ((adev->voice.tty_mode != TTY_MODE_OFF) &&
1239 !voice_extn_compress_voip_is_active(adev)) {
1240 switch (adev->voice.tty_mode) {
1241 case TTY_MODE_FULL:
1242 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
1243 break;
1244 case TTY_MODE_VCO:
1245 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
1246 break;
1247 case TTY_MODE_HCO:
1248 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
1249 break;
1250 default:
1251 ALOGE("%s: Invalid TTY mode (%#x)",
1252 __func__, adev->voice.tty_mode);
1253 }
1254 } else if (audio_extn_get_anc_enabled()) {
1255 if (audio_extn_should_use_fb_anc())
1256 snd_device = SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET;
1257 else
1258 snd_device = SND_DEVICE_OUT_VOICE_ANC_HEADSET;
1259 } else {
1260 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
1261 }
1262 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
1263 if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ)
1264 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
1265 else
1266 snd_device = SND_DEVICE_OUT_BT_SCO;
1267 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
1268 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
1269 } else if (devices & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
1270 devices & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
1271 snd_device = SND_DEVICE_OUT_USB_HEADSET;
1272 } else if (devices & AUDIO_DEVICE_OUT_FM_TX) {
1273 snd_device = SND_DEVICE_OUT_TRANSMISSION_FM;
1274 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
1275 if (audio_extn_should_use_handset_anc(channel_count))
1276 snd_device = SND_DEVICE_OUT_ANC_HANDSET;
1277 else
1278 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
1279 }
1280 if (snd_device != SND_DEVICE_NONE) {
1281 goto exit;
1282 }
1283 }
1284
Naresh Tannirue3b18452014-03-04 14:44:27 +05301285 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1286 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301287 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADSET
1288 && audio_extn_get_anc_enabled()) {
1289 if (audio_extn_should_use_fb_anc())
1290 snd_device = SND_DEVICE_OUT_ANC_FB_HEADSET;
1291 else
1292 snd_device = SND_DEVICE_OUT_ANC_HEADSET;
1293 }
1294 else
1295 snd_device = SND_DEVICE_OUT_HEADPHONES;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301296 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
1297 if (adev->speaker_lr_swap)
1298 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
1299 else
1300 snd_device = SND_DEVICE_OUT_SPEAKER;
1301 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301302 if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ)
1303 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
1304 else
1305 snd_device = SND_DEVICE_OUT_BT_SCO;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301306 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
1307 snd_device = SND_DEVICE_OUT_HDMI ;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301308 } else if (devices & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
1309 devices & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
Mingming Yin5a7c5d62014-03-05 17:45:03 -08001310 ALOGD("%s: setting USB hadset channel capability(2) for Proxy", __func__);
1311 audio_extn_set_afe_proxy_channel_mixer(adev, 2);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301312 snd_device = SND_DEVICE_OUT_USB_HEADSET;
1313 } else if (devices & AUDIO_DEVICE_OUT_FM_TX) {
1314 snd_device = SND_DEVICE_OUT_TRANSMISSION_FM;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301315 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
1316 snd_device = SND_DEVICE_OUT_HANDSET;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301317 } else if (devices & AUDIO_DEVICE_OUT_PROXY) {
Mingming Yin5a7c5d62014-03-05 17:45:03 -08001318 channel_count = audio_extn_get_afe_proxy_channel_count();
1319 ALOGD("%s: setting sink capability(%d) for Proxy", __func__, channel_count);
1320 audio_extn_set_afe_proxy_channel_mixer(adev, channel_count);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301321 snd_device = SND_DEVICE_OUT_AFE_PROXY;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301322 } else {
1323 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
1324 }
1325exit:
1326 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
1327 return snd_device;
1328}
1329
1330snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
1331{
1332 struct platform_data *my_data = (struct platform_data *)platform;
1333 struct audio_device *adev = my_data->adev;
1334 audio_source_t source = (adev->active_input == NULL) ?
1335 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
1336
1337 audio_mode_t mode = adev->mode;
1338 audio_devices_t in_device = ((adev->active_input == NULL) ?
1339 AUDIO_DEVICE_NONE : adev->active_input->device)
1340 & ~AUDIO_DEVICE_BIT_IN;
1341 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
1342 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
1343 snd_device_t snd_device = SND_DEVICE_NONE;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301344 int channel_count = popcount(channel_mask);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301345
1346 ALOGV("%s: enter: out_device(%#x) in_device(%#x)",
1347 __func__, out_device, in_device);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301348 if ((out_device != AUDIO_DEVICE_NONE) && ((mode == AUDIO_MODE_IN_CALL) ||
1349 voice_extn_compress_voip_is_active(adev))) {
1350 if ((adev->voice.tty_mode != TTY_MODE_OFF) &&
1351 !voice_extn_compress_voip_is_active(adev)) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301352 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1353 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301354 switch (adev->voice.tty_mode) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301355 case TTY_MODE_FULL:
1356 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
1357 break;
1358 case TTY_MODE_VCO:
1359 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
1360 break;
1361 case TTY_MODE_HCO:
1362 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
1363 break;
1364 default:
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301365 ALOGE("%s: Invalid TTY mode (%#x)",
1366 __func__, adev->voice.tty_mode);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301367 }
1368 goto exit;
1369 }
1370 }
1371 if (out_device & AUDIO_DEVICE_OUT_EARPIECE ||
1372 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301373 if (out_device & AUDIO_DEVICE_OUT_EARPIECE &&
1374 audio_extn_should_use_handset_anc(channel_count)) {
1375 snd_device = SND_DEVICE_IN_AANC_HANDSET_MIC;
1376 } else if (my_data->fluence_type == FLUENCE_NONE ||
1377 my_data->fluence_in_voice_call == false) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301378 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301379 set_echo_reference(adev->mixer, EC_REF_RX);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301380 } else {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301381 snd_device = SND_DEVICE_IN_VOICE_DMIC;
1382 adev->acdb_settings |= DMIC_FLAG;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301383 }
1384 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
1385 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
Satya Krishna Pindiproli624c7802014-04-11 11:33:27 +05301386 set_echo_reference(adev->mixer, EC_REF_RX);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301387 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301388 if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ)
1389 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
1390 else
1391 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301392 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301393 if (my_data->fluence_type != FLUENCE_NONE &&
1394 my_data->fluence_in_voice_call &&
1395 my_data->fluence_in_spkr_mode) {
1396 if(my_data->fluence_type & FLUENCE_QUAD_MIC) {
1397 adev->acdb_settings |= QMIC_FLAG;
1398 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_QMIC;
1399 } else {
1400 adev->acdb_settings |= DMIC_FLAG;
1401 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
1402 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05301403 } else {
1404 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
Satya Krishna Pindiproli624c7802014-04-11 11:33:27 +05301405 set_echo_reference(adev->mixer, EC_REF_RX);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301406 }
1407 }
1408 } else if (source == AUDIO_SOURCE_CAMCORDER) {
1409 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
1410 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
1411 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
1412 }
1413 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
1414 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301415 if (channel_count == 2) {
1416 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
1417 adev->acdb_settings |= DMIC_FLAG;
1418 } else if (adev->active_input->enable_ns)
1419 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
1420 else if (my_data->fluence_type != FLUENCE_NONE &&
1421 my_data->fluence_in_voice_rec) {
1422 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
1423 adev->acdb_settings |= DMIC_FLAG;
1424 } else {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301425 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
1426 }
1427 }
1428 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION) {
1429 if (out_device & AUDIO_DEVICE_OUT_SPEAKER)
1430 in_device = AUDIO_DEVICE_IN_BACK_MIC;
1431 if (adev->active_input) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301432 if (adev->active_input->enable_aec &&
1433 adev->active_input->enable_ns) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301434 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301435 if (my_data->fluence_type & FLUENCE_DUAL_MIC &&
1436 my_data->fluence_in_spkr_mode) {
1437 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
1438 adev->acdb_settings |= DMIC_FLAG;
1439 } else
1440 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301441 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301442 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1443 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
1444 adev->acdb_settings |= DMIC_FLAG;
1445 } else
1446 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301447 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301448 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301449 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301450 set_echo_reference(adev->mixer, EC_REF_RX);
1451 } else if (adev->active_input->enable_aec) {
1452 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
1453 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1454 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
1455 adev->acdb_settings |= DMIC_FLAG;
1456 } else
1457 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
1458 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
1459 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1460 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
1461 adev->acdb_settings |= DMIC_FLAG;
1462 } else
1463 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
1464 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
1465 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
1466 }
1467 set_echo_reference(adev->mixer, EC_REF_RX);
1468 } else if (adev->active_input->enable_ns) {
1469 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
1470 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1471 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
1472 adev->acdb_settings |= DMIC_FLAG;
1473 } else
1474 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
1475 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
1476 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1477 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
1478 adev->acdb_settings |= DMIC_FLAG;
1479 } else
1480 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
1481 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
1482 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
1483 }
1484 set_echo_reference(adev->mixer, "NONE");
Naresh Tannirue3b18452014-03-04 14:44:27 +05301485 } else
1486 set_echo_reference(adev->mixer, "NONE");
1487 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301488 } else if (source == AUDIO_SOURCE_MIC) {
1489 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC &&
1490 channel_count == 1 ) {
1491 if(my_data->fluence_type & FLUENCE_DUAL_MIC &&
1492 my_data->fluence_in_audio_rec)
1493 snd_device = SND_DEVICE_IN_HANDSET_DMIC;
1494 }
1495 } else if (source == AUDIO_SOURCE_FM_RX ||
1496 source == AUDIO_SOURCE_FM_RX_A2DP) {
1497 snd_device = SND_DEVICE_IN_CAPTURE_FM;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301498 } else if (source == AUDIO_SOURCE_DEFAULT) {
1499 goto exit;
1500 }
1501
1502
1503 if (snd_device != SND_DEVICE_NONE) {
1504 goto exit;
1505 }
1506
1507 if (in_device != AUDIO_DEVICE_NONE &&
1508 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
1509 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
1510 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301511 if (audio_extn_ssr_get_enabled() && channel_count == 6)
1512 snd_device = SND_DEVICE_IN_QUAD_MIC;
1513 else if (channel_count == 2)
1514 snd_device = SND_DEVICE_IN_HANDSET_STEREO_DMIC;
1515 else
1516 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301517 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
1518 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
1519 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
1520 snd_device = SND_DEVICE_IN_HEADSET_MIC;
1521 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301522 if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ)
1523 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
1524 else
1525 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301526 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
1527 snd_device = SND_DEVICE_IN_HDMI_MIC;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301528 } else if (in_device & AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET ||
1529 in_device & AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET) {
1530 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
1531 } else if (in_device & AUDIO_DEVICE_IN_FM_RX) {
1532 snd_device = SND_DEVICE_IN_CAPTURE_FM;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301533 } else {
1534 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
1535 ALOGW("%s: Using default handset-mic", __func__);
1536 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1537 }
1538 } else {
1539 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
1540 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1541 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
1542 snd_device = SND_DEVICE_IN_HEADSET_MIC;
1543 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301544 if (channel_count > 1)
1545 snd_device = SND_DEVICE_IN_SPEAKER_STEREO_DMIC;
1546 else
1547 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301548 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
1549 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1550 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301551 if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ)
1552 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
1553 else
1554 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301555 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
1556 snd_device = SND_DEVICE_IN_HDMI_MIC;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301557 } else if (out_device & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
1558 out_device & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
1559 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301560 } else {
1561 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
1562 ALOGW("%s: Using default handset-mic", __func__);
1563 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1564 }
1565 }
1566exit:
1567 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
1568 return snd_device;
1569}
1570
1571int platform_set_hdmi_channels(void *platform, int channel_count)
1572{
1573 struct platform_data *my_data = (struct platform_data *)platform;
1574 struct audio_device *adev = my_data->adev;
1575 struct mixer_ctl *ctl;
1576 const char *channel_cnt_str = NULL;
1577 const char *mixer_ctl_name = "HDMI_RX Channels";
1578 switch (channel_count) {
1579 case 8:
1580 channel_cnt_str = "Eight"; break;
1581 case 7:
1582 channel_cnt_str = "Seven"; break;
1583 case 6:
1584 channel_cnt_str = "Six"; break;
1585 case 5:
1586 channel_cnt_str = "Five"; break;
1587 case 4:
1588 channel_cnt_str = "Four"; break;
1589 case 3:
1590 channel_cnt_str = "Three"; break;
1591 default:
1592 channel_cnt_str = "Two"; break;
1593 }
1594 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1595 if (!ctl) {
1596 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1597 __func__, mixer_ctl_name);
1598 return -EINVAL;
1599 }
1600 ALOGV("HDMI channel count: %s", channel_cnt_str);
1601 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
1602 return 0;
1603}
1604
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301605int platform_edid_get_max_channels(void *platform)
Naresh Tannirue3b18452014-03-04 14:44:27 +05301606{
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301607 struct platform_data *my_data = (struct platform_data *)platform;
1608 struct audio_device *adev = my_data->adev;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301609 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
1610 char *sad = block;
1611 int num_audio_blocks;
1612 int channel_count;
1613 int max_channels = 0;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301614 int i, ret, count;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301615
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301616 struct mixer_ctl *ctl;
1617
1618 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
1619 if (!ctl) {
1620 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1621 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301622 return 0;
1623 }
1624
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301625 mixer_ctl_update(ctl);
1626
1627 count = mixer_ctl_get_num_values(ctl);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301628
1629 /* Read SAD blocks, clamping the maximum size for safety */
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301630 if (count > (int)sizeof(block))
1631 count = (int)sizeof(block);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301632
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301633 ret = mixer_ctl_get_array(ctl, block, count);
1634 if (ret != 0) {
1635 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
1636 return 0;
1637 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05301638
1639 /* Calculate the number of SAD blocks */
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301640 num_audio_blocks = count / SAD_BLOCK_SIZE;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301641
1642 for (i = 0; i < num_audio_blocks; i++) {
1643 /* Only consider LPCM blocks */
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301644 if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
1645 sad += 3;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301646 continue;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301647 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05301648
1649 channel_count = (sad[0] & 0x7) + 1;
1650 if (channel_count > max_channels)
1651 max_channels = channel_count;
1652
1653 /* Advance to next block */
1654 sad += 3;
1655 }
1656
1657 return max_channels;
1658}
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301659
1660static int platform_set_slowtalk(struct platform_data *my_data, bool state)
1661{
1662 int ret = 0;
1663 struct audio_device *adev = my_data->adev;
1664 struct mixer_ctl *ctl;
1665 const char *mixer_ctl_name = "Slowtalk Enable";
1666 uint32_t set_values[ ] = {0,
1667 ALL_SESSION_VSID};
1668
1669 set_values[0] = state;
1670 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1671 if (!ctl) {
1672 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1673 __func__, mixer_ctl_name);
1674 ret = -EINVAL;
1675 } else {
1676 ALOGV("Setting slowtalk state: %d", state);
1677 ret = mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1678 my_data->slowtalk = state;
1679 }
1680
1681 if (my_data->csd != NULL) {
1682 ret = my_data->csd->slow_talk(ALL_SESSION_VSID, state);
1683 if (ret < 0) {
1684 ALOGE("%s: csd_client_disable_device, failed, error %d",
1685 __func__, ret);
1686 }
1687 }
1688 return ret;
1689}
1690
1691int platform_set_parameters(void *platform, struct str_parms *parms)
1692{
1693 struct platform_data *my_data = (struct platform_data *)platform;
1694 char *str;
1695 char value[256] = {0};
1696 int val;
1697 int ret = 0, err;
1698
1699 ALOGV("%s: enter: %s", __func__, str_parms_to_str(parms));
1700
1701 err = str_parms_get_int(parms, AUDIO_PARAMETER_KEY_BTSCO, &val);
1702 if (err >= 0) {
1703 str_parms_del(parms, AUDIO_PARAMETER_KEY_BTSCO);
1704 my_data->btsco_sample_rate = val;
1705 if (val == SAMPLE_RATE_16KHZ) {
Haynes Mathew George1376ca62014-04-24 11:55:48 -07001706 audio_route_apply_and_update_path(my_data->adev->audio_route,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301707 "bt-sco-wb-samplerate");
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301708 }
1709 }
1710
1711 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_SLOWTALK, value, sizeof(value));
1712 if (err >= 0) {
1713 bool state = false;
1714 if (!strncmp("true", value, sizeof("true"))) {
1715 state = true;
1716 }
1717
1718 str_parms_del(parms, AUDIO_PARAMETER_KEY_SLOWTALK);
1719 ret = platform_set_slowtalk(my_data, state);
1720 if (ret)
1721 ALOGE("%s: Failed to set slow talk err: %d", __func__, ret);
1722 }
1723
1724 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_VOLUME_BOOST,
1725 value, sizeof(value));
1726 if (err >= 0) {
1727 str_parms_del(parms, AUDIO_PARAMETER_KEY_VOLUME_BOOST);
1728
1729 if (my_data->acdb_reload_vocvoltable == NULL) {
1730 ALOGE("%s: acdb_reload_vocvoltable is NULL", __func__);
1731 } else if (!strcmp(value, "on")) {
1732 if (!my_data->acdb_reload_vocvoltable(VOICE_FEATURE_SET_VOLUME_BOOST)) {
1733 my_data->voice_feature_set = 1;
1734 }
1735 } else {
1736 if (!my_data->acdb_reload_vocvoltable(VOICE_FEATURE_SET_DEFAULT)) {
1737 my_data->voice_feature_set = 0;
1738 }
1739 }
1740 }
1741
1742 ALOGV("%s: exit with code(%d)", __func__, ret);
1743 return ret;
1744}
1745
1746int platform_set_incall_recording_session_id(void *platform,
1747 uint32_t session_id, int rec_mode)
1748{
1749 int ret = 0;
1750 struct platform_data *my_data = (struct platform_data *)platform;
1751 struct audio_device *adev = my_data->adev;
1752 struct mixer_ctl *ctl;
1753 const char *mixer_ctl_name = "Voc VSID";
1754 int num_ctl_values;
1755 int i;
1756
1757 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1758 if (!ctl) {
1759 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1760 __func__, mixer_ctl_name);
1761 ret = -EINVAL;
1762 } else {
1763 num_ctl_values = mixer_ctl_get_num_values(ctl);
1764 for (i = 0; i < num_ctl_values; i++) {
1765 if (mixer_ctl_set_value(ctl, i, session_id)) {
1766 ALOGV("Error: invalid session_id: %x", session_id);
1767 ret = -EINVAL;
1768 break;
1769 }
1770 }
1771 }
1772
1773 if (my_data->csd != NULL) {
1774 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
1775 if (ret < 0) {
1776 ALOGE("%s: csd_client_start_record failed, error %d",
1777 __func__, ret);
1778 }
1779 }
1780
1781 return ret;
1782}
1783
1784int platform_stop_incall_recording_usecase(void *platform)
1785{
1786 int ret = 0;
1787 struct platform_data *my_data = (struct platform_data *)platform;
1788
1789 if (my_data->csd != NULL) {
1790 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
1791 if (ret < 0) {
1792 ALOGE("%s: csd_client_stop_record failed, error %d",
1793 __func__, ret);
1794 }
1795 }
1796
1797 return ret;
1798}
1799
1800int platform_start_incall_music_usecase(void *platform)
1801{
1802 int ret = 0;
1803 struct platform_data *my_data = (struct platform_data *)platform;
1804
1805 if (my_data->csd != NULL) {
1806 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
1807 if (ret < 0) {
1808 ALOGE("%s: csd_client_start_playback failed, error %d",
1809 __func__, ret);
1810 }
1811 }
1812
1813 return ret;
1814}
1815
1816int platform_stop_incall_music_usecase(void *platform)
1817{
1818 int ret = 0;
1819 struct platform_data *my_data = (struct platform_data *)platform;
1820
1821 if (my_data->csd != NULL) {
1822 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
1823 if (ret < 0) {
1824 ALOGE("%s: csd_client_stop_playback failed, error %d",
1825 __func__, ret);
1826 }
1827 }
1828
1829 return ret;
1830}
1831
1832void platform_get_parameters(void *platform,
1833 struct str_parms *query,
1834 struct str_parms *reply)
1835{
1836 struct platform_data *my_data = (struct platform_data *)platform;
1837 char *str = NULL;
1838 char value[256] = {0};
1839 int ret;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301840
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301841 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_SLOWTALK,
1842 value, sizeof(value));
1843 if (ret >= 0) {
1844 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_SLOWTALK,
1845 my_data->slowtalk?"true":"false");
1846 }
1847
1848 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_VOLUME_BOOST,
1849 value, sizeof(value));
1850 if (ret >= 0) {
1851 if (my_data->voice_feature_set == VOICE_FEATURE_SET_VOLUME_BOOST) {
1852 strlcpy(value, "on", sizeof(value));
1853 } else {
1854 strlcpy(value, "off", sizeof(value));
1855 }
1856
1857 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_VOLUME_BOOST, value);
1858 }
1859
1860 ALOGV("%s: exit: returns - %s", __func__, str_parms_to_str(reply));
1861}
1862
1863/* Delay in Us */
1864int64_t platform_render_latency(audio_usecase_t usecase)
1865{
1866 switch (usecase) {
1867 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
1868 return DEEP_BUFFER_PLATFORM_DELAY;
1869 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
1870 return LOW_LATENCY_PLATFORM_DELAY;
1871 default:
1872 return 0;
1873 }
1874}
1875
1876int platform_update_usecase_from_source(int source, int usecase)
1877{
1878 ALOGV("%s: input source :%d", __func__, source);
1879 if(source == AUDIO_SOURCE_FM_RX_A2DP)
1880 usecase = USECASE_AUDIO_RECORD_FM_VIRTUAL;
1881 return usecase;
1882}
1883
1884bool platform_listen_update_status(snd_device_t snd_device)
1885{
1886 if ((snd_device >= SND_DEVICE_IN_BEGIN) &&
1887 (snd_device < SND_DEVICE_IN_END) &&
1888 (snd_device != SND_DEVICE_IN_CAPTURE_FM) &&
1889 (snd_device != SND_DEVICE_IN_CAPTURE_VI_FEEDBACK))
1890 return true;
1891 else
1892 return false;
1893}
1894
1895/* Read offload buffer size from a property.
1896 * If value is not power of 2 round it to
1897 * power of 2.
1898 */
1899uint32_t platform_get_compress_offload_buffer_size(audio_offload_info_t* info)
1900{
1901 char value[PROPERTY_VALUE_MAX] = {0};
1902 uint32_t fragment_size = COMPRESS_OFFLOAD_FRAGMENT_SIZE;
1903 if((property_get("audio.offload.buffer.size.kb", value, "")) &&
1904 atoi(value)) {
1905 fragment_size = atoi(value) * 1024;
1906 }
1907
1908 if (info != NULL && info->has_video && info->is_streaming) {
1909 fragment_size = COMPRESS_OFFLOAD_FRAGMENT_SIZE_FOR_AV_STREAMING;
1910 ALOGV("%s: offload fragment size reduced for AV streaming to %d",
1911 __func__, out->compr_config.fragment_size);
1912 }
1913
1914 fragment_size = ALIGN( fragment_size, 1024);
1915
1916 if(fragment_size < MIN_COMPRESS_OFFLOAD_FRAGMENT_SIZE)
1917 fragment_size = MIN_COMPRESS_OFFLOAD_FRAGMENT_SIZE;
1918 else if(fragment_size > MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE)
1919 fragment_size = MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE;
1920 ALOGV("%s: fragment_size %d", __func__, fragment_size);
1921 return fragment_size;
1922}
1923
1924uint32_t platform_get_pcm_offload_buffer_size(audio_offload_info_t* info)
1925{
1926 uint32_t fragment_size = MIN_PCM_OFFLOAD_FRAGMENT_SIZE;
1927 uint32_t bits_per_sample = 16;
1928
1929 if (info->format == AUDIO_FORMAT_PCM_24_BIT_OFFLOAD) {
1930 bits_per_sample = 32;
1931 }
1932
1933 if (!info->has_video) {
1934 fragment_size = MAX_PCM_OFFLOAD_FRAGMENT_SIZE;
1935
1936 } else if (info->has_video && info->is_streaming) {
1937 fragment_size = (PCM_OFFLOAD_BUFFER_DURATION_FOR_AV_STREAMING
1938 * info->sample_rate
1939 * bits_per_sample
1940 * popcount(info->channel_mask))/1000;
1941
1942 } else if (info->has_video) {
1943 fragment_size = (PCM_OFFLOAD_BUFFER_DURATION_FOR_AV
1944 * info->sample_rate
1945 * bits_per_sample
1946 * popcount(info->channel_mask))/1000;
1947 }
1948
1949 fragment_size = ALIGN( fragment_size, 1024);
1950
1951 if(fragment_size < MIN_PCM_OFFLOAD_FRAGMENT_SIZE)
1952 fragment_size = MIN_PCM_OFFLOAD_FRAGMENT_SIZE;
1953 else if(fragment_size > MAX_PCM_OFFLOAD_FRAGMENT_SIZE)
1954 fragment_size = MAX_PCM_OFFLOAD_FRAGMENT_SIZE;
1955
1956 ALOGV("%s: fragment_size %d", __func__, fragment_size);
1957 return fragment_size;
1958}
1959