blob: d2a680739ceb3ca90839b21ae526727b6b309571 [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));
Asish Bhattacharya4ff24802014-04-24 17:46:54 +0530415 } else {
416 strlcpy(mixer_xml_path, MIXER_XML_PATH,
417 sizeof(MIXER_XML_PATH));
418 }
419}
420
Naresh Tannirue3b18452014-03-04 14:44:27 +0530421static int set_echo_reference(struct mixer *mixer, const char* ec_ref)
422{
423 struct mixer_ctl *ctl;
424 const char *mixer_ctl_name = "EC_REF_RX";
425
426 ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name);
427 if (!ctl) {
428 ALOGE("%s: Could not get ctl for mixer cmd - %s",
429 __func__, mixer_ctl_name);
430 return -EINVAL;
431 }
432 ALOGV("Setting EC Reference: %s", ec_ref);
433 mixer_ctl_set_enum_by_string(ctl, ec_ref);
434 return 0;
435}
436
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530437static struct csd_data *open_csd_client()
438{
439 struct csd_data *csd = calloc(1, sizeof(struct csd_data));
440
441 csd->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
442 if (csd->csd_client == NULL) {
443 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
444 goto error;
445 } else {
446 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
447
448 csd->deinit = (deinit_t)dlsym(csd->csd_client,
449 "csd_client_deinit");
450 if (csd->deinit == NULL) {
451 ALOGE("%s: dlsym error %s for csd_client_deinit", __func__,
452 dlerror());
453 goto error;
454 }
455 csd->disable_device = (disable_device_t)dlsym(csd->csd_client,
456 "csd_client_disable_device");
457 if (csd->disable_device == NULL) {
458 ALOGE("%s: dlsym error %s for csd_client_disable_device",
459 __func__, dlerror());
460 goto error;
461 }
462 csd->enable_device_config = (enable_device_config_t)dlsym(csd->csd_client,
463 "csd_client_enable_device_config");
464 if (csd->enable_device_config == NULL) {
465 ALOGE("%s: dlsym error %s for csd_client_enable_device_config",
466 __func__, dlerror());
467 goto error;
468 }
469 csd->enable_device = (enable_device_t)dlsym(csd->csd_client,
470 "csd_client_enable_device");
471 if (csd->enable_device == NULL) {
472 ALOGE("%s: dlsym error %s for csd_client_enable_device",
473 __func__, dlerror());
474 goto error;
475 }
476 csd->start_voice = (start_voice_t)dlsym(csd->csd_client,
477 "csd_client_start_voice");
478 if (csd->start_voice == NULL) {
479 ALOGE("%s: dlsym error %s for csd_client_start_voice",
480 __func__, dlerror());
481 goto error;
482 }
483 csd->stop_voice = (stop_voice_t)dlsym(csd->csd_client,
484 "csd_client_stop_voice");
485 if (csd->stop_voice == NULL) {
486 ALOGE("%s: dlsym error %s for csd_client_stop_voice",
487 __func__, dlerror());
488 goto error;
489 }
490 csd->volume = (volume_t)dlsym(csd->csd_client,
491 "csd_client_volume");
492 if (csd->volume == NULL) {
493 ALOGE("%s: dlsym error %s for csd_client_volume",
494 __func__, dlerror());
495 goto error;
496 }
497 csd->mic_mute = (mic_mute_t)dlsym(csd->csd_client,
498 "csd_client_mic_mute");
499 if (csd->mic_mute == NULL) {
500 ALOGE("%s: dlsym error %s for csd_client_mic_mute",
501 __func__, dlerror());
502 goto error;
503 }
504 csd->slow_talk = (slow_talk_t)dlsym(csd->csd_client,
505 "csd_client_slow_talk");
506 if (csd->slow_talk == NULL) {
507 ALOGE("%s: dlsym error %s for csd_client_slow_talk",
508 __func__, dlerror());
509 goto error;
510 }
511 csd->start_playback = (start_playback_t)dlsym(csd->csd_client,
512 "csd_client_start_playback");
513 if (csd->start_playback == NULL) {
514 ALOGE("%s: dlsym error %s for csd_client_start_playback",
515 __func__, dlerror());
516 goto error;
517 }
518 csd->stop_playback = (stop_playback_t)dlsym(csd->csd_client,
519 "csd_client_stop_playback");
520 if (csd->stop_playback == NULL) {
521 ALOGE("%s: dlsym error %s for csd_client_stop_playback",
522 __func__, dlerror());
523 goto error;
524 }
525 csd->start_record = (start_record_t)dlsym(csd->csd_client,
526 "csd_client_start_record");
527 if (csd->start_record == NULL) {
528 ALOGE("%s: dlsym error %s for csd_client_start_record",
529 __func__, dlerror());
530 goto error;
531 }
532 csd->stop_record = (stop_record_t)dlsym(csd->csd_client,
533 "csd_client_stop_record");
534 if (csd->stop_record == NULL) {
535 ALOGE("%s: dlsym error %s for csd_client_stop_record",
536 __func__, dlerror());
537 goto error;
538 }
539 csd->init = (init_t)dlsym(csd->csd_client, "csd_client_init");
540
541 if (csd->init == NULL) {
542 ALOGE("%s: dlsym error %s for csd_client_init",
543 __func__, dlerror());
544 goto error;
545 } else {
546 csd->init();
547 }
548 }
549 return csd;
550
551error:
552 free(csd);
553 csd = NULL;
554 return csd;
555}
556
557void close_csd_client(struct csd_data *csd)
558{
559 if (csd != NULL) {
560 csd->deinit();
561 dlclose(csd->csd_client);
562 free(csd);
563 csd = NULL;
564 }
565}
566
Naresh Tannirue3b18452014-03-04 14:44:27 +0530567void *platform_init(struct audio_device *adev)
568{
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530569 char platform[PROPERTY_VALUE_MAX];
570 char baseband[PROPERTY_VALUE_MAX];
Naresh Tannirue3b18452014-03-04 14:44:27 +0530571 char value[PROPERTY_VALUE_MAX];
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530572 struct platform_data *my_data = NULL;
573 int retry_num = 0, snd_card_num = 0;
574 const char *snd_card_name;
Asish Bhattacharya4ff24802014-04-24 17:46:54 +0530575 char mixer_xml_path[100];
Naresh Tannirue3b18452014-03-04 14:44:27 +0530576
577 my_data = calloc(1, sizeof(struct platform_data));
578
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530579 while (snd_card_num < MAX_SND_CARD) {
580 adev->mixer = mixer_open(snd_card_num);
581
582 while (!adev->mixer && retry_num < RETRY_NUMBER) {
583 usleep(RETRY_US);
584 adev->mixer = mixer_open(snd_card_num);
585 retry_num++;
586 }
587
588 if (!adev->mixer) {
589 ALOGE("%s: Unable to open the mixer card: %d", __func__,
590 snd_card_num);
591 retry_num = 0;
592 snd_card_num++;
593 continue;
594 }
595
596 snd_card_name = mixer_get_name(adev->mixer);
597 ALOGV("%s: snd_card_name: %s", __func__, snd_card_name);
598
599 my_data->hw_info = hw_info_init(snd_card_name);
600 if (!my_data->hw_info) {
601 ALOGE("%s: Failed to init hardware info", __func__);
602 } else {
Asish Bhattacharya4ff24802014-04-24 17:46:54 +0530603 query_platform(snd_card_name, mixer_xml_path);
604 ALOGD("%s: mixer path file is %s", __func__,
605 mixer_xml_path);
606 if (audio_extn_read_xml(adev, snd_card_num, mixer_xml_path,
607 MIXER_XML_PATH_AUXPCM) == -ENOSYS) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530608 adev->audio_route = audio_route_init(snd_card_num,
Asish Bhattacharya4ff24802014-04-24 17:46:54 +0530609 mixer_xml_path);
610 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530611 if (!adev->audio_route) {
612 ALOGE("%s: Failed to init audio route controls, aborting.",
613 __func__);
614 free(my_data);
615 return NULL;
616 }
617 adev->snd_card = snd_card_num;
618 ALOGD("%s: Opened sound card:%d", __func__, snd_card_num);
619 break;
620 }
621 retry_num = 0;
622 snd_card_num++;
623 }
624
625 if (snd_card_num >= MAX_SND_CARD) {
626 ALOGE("%s: Unable to find correct sound card, aborting.", __func__);
627 free(my_data);
628 return NULL;
629 }
630
Naresh Tannirue3b18452014-03-04 14:44:27 +0530631 my_data->adev = adev;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530632 my_data->btsco_sample_rate = SAMPLE_RATE_8KHZ;
Naresh Tannirue3b18452014-03-04 14:44:27 +0530633 my_data->fluence_in_spkr_mode = false;
634 my_data->fluence_in_voice_call = false;
635 my_data->fluence_in_voice_rec = false;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530636 my_data->fluence_in_audio_rec = false;
637 my_data->fluence_type = FLUENCE_NONE;
Naresh Tannirue3b18452014-03-04 14:44:27 +0530638
Venkata Narendra Kumar Gutta88fd0bc2014-03-27 19:47:56 +0530639 property_get("ro.qc.sdk.audio.fluencetype", my_data->fluence_cap, "");
640 if (!strncmp("fluencepro", my_data->fluence_cap, sizeof("fluencepro"))) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530641 my_data->fluence_type = FLUENCE_QUAD_MIC | FLUENCE_DUAL_MIC;
Venkata Narendra Kumar Gutta88fd0bc2014-03-27 19:47:56 +0530642 } else if (!strncmp("fluence", my_data->fluence_cap, sizeof("fluence"))) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530643 my_data->fluence_type = FLUENCE_DUAL_MIC;
644 } else {
645 my_data->fluence_type = FLUENCE_NONE;
Naresh Tannirue3b18452014-03-04 14:44:27 +0530646 }
647
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530648 if (my_data->fluence_type != FLUENCE_NONE) {
Naresh Tannirue3b18452014-03-04 14:44:27 +0530649 property_get("persist.audio.fluence.voicecall",value,"");
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530650 if (!strncmp("true", value, sizeof("true"))) {
Naresh Tannirue3b18452014-03-04 14:44:27 +0530651 my_data->fluence_in_voice_call = true;
652 }
653
654 property_get("persist.audio.fluence.voicerec",value,"");
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530655 if (!strncmp("true", value, sizeof("true"))) {
Naresh Tannirue3b18452014-03-04 14:44:27 +0530656 my_data->fluence_in_voice_rec = true;
657 }
658
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530659 property_get("persist.audio.fluence.audiorec",value,"");
660 if (!strncmp("true", value, sizeof("true"))) {
661 my_data->fluence_in_audio_rec = true;
662 }
663
Naresh Tannirue3b18452014-03-04 14:44:27 +0530664 property_get("persist.audio.fluence.speaker",value,"");
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530665 if (!strncmp("true", value, sizeof("true"))) {
Naresh Tannirue3b18452014-03-04 14:44:27 +0530666 my_data->fluence_in_spkr_mode = true;
667 }
668 }
669
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530670 my_data->voice_feature_set = VOICE_FEATURE_SET_DEFAULT;
Naresh Tannirue3b18452014-03-04 14:44:27 +0530671 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
672 if (my_data->acdb_handle == NULL) {
673 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
674 } else {
675 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
676 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
677 "acdb_loader_deallocate_ACDB");
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530678 if (!my_data->acdb_deallocate)
679 ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s",
680 __func__, LIB_ACDB_LOADER);
681
Naresh Tannirue3b18452014-03-04 14:44:27 +0530682 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
683 "acdb_loader_send_audio_cal");
684 if (!my_data->acdb_send_audio_cal)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530685 ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530686 __func__, LIB_ACDB_LOADER);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530687
Naresh Tannirue3b18452014-03-04 14:44:27 +0530688 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
689 "acdb_loader_send_voice_cal");
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530690 if (!my_data->acdb_send_voice_cal)
691 ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s",
692 __func__, LIB_ACDB_LOADER);
693
694 my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle,
695 "acdb_loader_reload_vocvoltable");
696 if (!my_data->acdb_reload_vocvoltable)
697 ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s",
698 __func__, LIB_ACDB_LOADER);
699
Naresh Tannirue3b18452014-03-04 14:44:27 +0530700 my_data->acdb_init = (acdb_init_t)dlsym(my_data->acdb_handle,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530701 "acdb_loader_init_v2");
Naresh Tannirue3b18452014-03-04 14:44:27 +0530702 if (my_data->acdb_init == NULL)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530703 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__, dlerror());
Naresh Tannirue3b18452014-03-04 14:44:27 +0530704 else
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530705 my_data->acdb_init(snd_card_name);
Naresh Tannirue3b18452014-03-04 14:44:27 +0530706 }
707
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530708 /* Initialize ACDB ID's */
709 platform_info_init(PLATFORM_INFO_XML_PATH);
710
711 /* init usb */
712 audio_extn_usb_init(adev);
713 /* update sound cards appropriately */
714 audio_extn_usb_set_proxy_sound_card(adev->snd_card);
715
716 /* Read one time ssr property */
717 audio_extn_ssr_update_enabled();
718 audio_extn_spkr_prot_init(adev);
Dhananjay Kumar89ea3bd2014-04-29 15:45:57 +0530719
720 audio_extn_dolby_set_license(adev);
721
Naresh Tannirue3b18452014-03-04 14:44:27 +0530722 return my_data;
723}
724
725void platform_deinit(void *platform)
726{
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530727 struct platform_data *my_data = (struct platform_data *)platform;
728
729 hw_info_deinit(my_data->hw_info);
730 close_csd_client(my_data->csd);
731
Naresh Tannirue3b18452014-03-04 14:44:27 +0530732 free(platform);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530733 /* deinit usb */
734 audio_extn_usb_deinit();
Naresh Tannirue3b18452014-03-04 14:44:27 +0530735}
736
737const char *platform_get_snd_device_name(snd_device_t snd_device)
738{
739 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX)
740 return device_table[snd_device];
741 else
742 return "";
743}
744
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530745int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
746 char *device_name)
747{
748 struct platform_data *my_data = (struct platform_data *)platform;
749
750 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
751 strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE);
752 hw_info_append_hw_type(my_data->hw_info, snd_device, device_name);
753 } else {
754 strlcpy(device_name, "", DEVICE_NAME_MAX_SIZE);
755 return -EINVAL;
756 }
757
758 return 0;
759}
760
Naresh Tannirue3b18452014-03-04 14:44:27 +0530761void platform_add_backend_name(char *mixer_path, snd_device_t snd_device)
762{
763 if (snd_device == SND_DEVICE_IN_BT_SCO_MIC)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530764 strlcat(mixer_path, " bt-sco", MIXER_PATH_MAX_LENGTH);
765 else if (snd_device == SND_DEVICE_IN_BT_SCO_MIC_WB)
766 strlcat(mixer_path, " bt-sco-wb", MIXER_PATH_MAX_LENGTH);
Naresh Tannirue3b18452014-03-04 14:44:27 +0530767 else if(snd_device == SND_DEVICE_OUT_BT_SCO)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530768 strlcat(mixer_path, " bt-sco", MIXER_PATH_MAX_LENGTH);
769 else if(snd_device == SND_DEVICE_OUT_BT_SCO_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_HDMI)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530772 strlcat(mixer_path, " hdmi", MIXER_PATH_MAX_LENGTH);
Naresh Tannirue3b18452014-03-04 14:44:27 +0530773 else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HDMI)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530774 strlcat(mixer_path, " speaker-and-hdmi", MIXER_PATH_MAX_LENGTH);
775 else if (snd_device == SND_DEVICE_OUT_AFE_PROXY)
776 strlcat(mixer_path, " afe-proxy", MIXER_PATH_MAX_LENGTH);
777 else if (snd_device == SND_DEVICE_OUT_USB_HEADSET)
778 strlcat(mixer_path, " usb-headphones", MIXER_PATH_MAX_LENGTH);
779 else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET)
780 strlcat(mixer_path, " speaker-and-usb-headphones",
781 MIXER_PATH_MAX_LENGTH);
782 else if (snd_device == SND_DEVICE_IN_USB_HEADSET_MIC)
783 strlcat(mixer_path, " usb-headset-mic", MIXER_PATH_MAX_LENGTH);
784 else if (snd_device == SND_DEVICE_IN_CAPTURE_FM)
785 strlcat(mixer_path, " capture-fm", MIXER_PATH_MAX_LENGTH);
786 else if (snd_device == SND_DEVICE_OUT_TRANSMISSION_FM)
787 strlcat(mixer_path, " transmission-fm", MIXER_PATH_MAX_LENGTH);
Naresh Tannirue3b18452014-03-04 14:44:27 +0530788}
789
790int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
791{
792 int device_id;
793 if (device_type == PCM_PLAYBACK)
794 device_id = pcm_device_table[usecase][0];
795 else
796 device_id = pcm_device_table[usecase][1];
797 return device_id;
798}
799
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530800int platform_get_snd_device_index(char *snd_device_index_name)
801{
802 int ret = 0;
803 int i;
804
805 if (snd_device_index_name == NULL) {
806 ALOGE("%s: snd_device_index_name is NULL", __func__);
807 ret = -ENODEV;
808 goto done;
809 }
810
811 for (i=0; i < SND_DEVICE_MAX; i++) {
812 if(strcmp(snd_device_name_index[i].name, snd_device_index_name) == 0) {
813 ret = snd_device_name_index[i].index;
814 goto done;
815 }
816 }
817 ALOGE("%s: Could not find index for snd_device_index_name = %s",
818 __func__, snd_device_index_name);
819 ret = -ENODEV;
820done:
821 return ret;
822}
823
Venkata Narendra Kumar Gutta88fd0bc2014-03-27 19:47:56 +0530824int platform_set_fluence_type(void *platform, char *value)
825{
826 int ret = 0;
827 int fluence_type = FLUENCE_NONE;
828 int fluence_flag = NONE_FLAG;
829 struct platform_data *my_data = (struct platform_data *)platform;
830 struct audio_device *adev = my_data->adev;
831
832 ALOGV("%s: fluence type:%d", __func__, my_data->fluence_type);
833
834 /* only dual mic turn on and off is supported as of now through setparameters */
835 if (!strncmp(AUDIO_PARAMETER_VALUE_DUALMIC,value, sizeof(AUDIO_PARAMETER_VALUE_DUALMIC))) {
836 if (!strncmp("fluencepro", my_data->fluence_cap, sizeof("fluencepro")) ||
837 !strncmp("fluence", my_data->fluence_cap, sizeof("fluence"))) {
838 ALOGV("fluence dualmic feature enabled \n");
839 fluence_type = FLUENCE_DUAL_MIC;
840 fluence_flag = DMIC_FLAG;
841 } else {
842 ALOGE("%s: Failed to set DUALMIC", __func__);
843 ret = -1;
844 goto done;
845 }
846 } else if (!strncmp(AUDIO_PARAMETER_KEY_NO_FLUENCE, value, sizeof(AUDIO_PARAMETER_KEY_NO_FLUENCE))) {
847 ALOGV("fluence disabled");
848 fluence_type = FLUENCE_NONE;
849 } else {
850 ALOGE("Invalid fluence value : %s",value);
851 ret = -1;
852 goto done;
853 }
854
855 if (fluence_type != my_data->fluence_type) {
856 ALOGV("%s: Updating fluence_type to :%d", __func__, fluence_type);
857 my_data->fluence_type = fluence_type;
858 adev->acdb_settings = (adev->acdb_settings & FLUENCE_MODE_CLEAR) | fluence_flag;
859 }
860done:
861 return ret;
862}
863
864int platform_get_fluence_type(void *platform, char *value, uint32_t len)
865{
866 int ret = 0;
867 struct platform_data *my_data = (struct platform_data *)platform;
868
869 if (my_data->fluence_type == FLUENCE_QUAD_MIC) {
870 strlcpy(value, "quadmic", len);
871 } else if (my_data->fluence_type == FLUENCE_DUAL_MIC) {
872 strlcpy(value, "dualmic", len);
873 } else if (my_data->fluence_type == FLUENCE_NONE) {
874 strlcpy(value, "none", len);
875 } else
876 ret = -1;
877
878 return ret;
879}
880
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530881int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
882{
883 int ret = 0;
884
885 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
886 ALOGE("%s: Invalid snd_device = %d",
887 __func__, snd_device);
888 ret = -EINVAL;
889 goto done;
890 }
891
892 acdb_device_table[snd_device] = acdb_id;
893done:
894 return ret;
895}
896
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700897int platform_get_snd_device_acdb_id(snd_device_t snd_device)
898{
899 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
900 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
901 return -EINVAL;
902 }
903 return acdb_device_table[snd_device];
904}
905
Naresh Tannirue3b18452014-03-04 14:44:27 +0530906int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
907{
908 struct platform_data *my_data = (struct platform_data *)platform;
909 int acdb_dev_id, acdb_dev_type;
910
911 acdb_dev_id = acdb_device_table[snd_device];
912 if (acdb_dev_id < 0) {
913 ALOGE("%s: Could not find acdb id for device(%d)",
914 __func__, snd_device);
915 return -EINVAL;
916 }
917 if (my_data->acdb_send_audio_cal) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530918 ("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530919 __func__, snd_device, acdb_dev_id);
920 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
921 snd_device < SND_DEVICE_OUT_END)
922 acdb_dev_type = ACDB_DEV_TYPE_OUT;
923 else
924 acdb_dev_type = ACDB_DEV_TYPE_IN;
925 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
926 }
927 return 0;
928}
929
930int platform_switch_voice_call_device_pre(void *platform)
931{
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530932 struct platform_data *my_data = (struct platform_data *)platform;
933 int ret = 0;
934
935 if (my_data->csd != NULL &&
936 my_data->adev->mode == AUDIO_MODE_IN_CALL) {
937 /* This must be called before disabling mixer controls on APQ side */
938 ret = my_data->csd->disable_device();
939 if (ret < 0) {
940 ALOGE("%s: csd_client_disable_device, failed, error %d",
941 __func__, ret);
942 }
943 }
944 return ret;
Naresh Tannirue3b18452014-03-04 14:44:27 +0530945}
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530946int platform_switch_voice_call_enable_device_config(void *platform,
947 snd_device_t out_snd_device,
948 snd_device_t in_snd_device)
949{
950 struct platform_data *my_data = (struct platform_data *)platform;
951 int acdb_rx_id, acdb_tx_id;
952 int ret = 0;
953
954 acdb_rx_id = acdb_device_table[out_snd_device];
955 acdb_tx_id = acdb_device_table[in_snd_device];
956
957 if (my_data->csd != NULL) {
958 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
959 ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
960 if (ret < 0) {
961 ALOGE("%s: csd_enable_device_config, failed, error %d",
962 __func__, ret);
963 }
964 } else {
965 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
966 acdb_rx_id, acdb_tx_id);
967 }
968 }
969 return ret;
970}
971
Naresh Tannirue3b18452014-03-04 14:44:27 +0530972
973int platform_switch_voice_call_device_post(void *platform,
974 snd_device_t out_snd_device,
975 snd_device_t in_snd_device)
976{
977 struct platform_data *my_data = (struct platform_data *)platform;
978 int acdb_rx_id, acdb_tx_id;
979
980 if (my_data->acdb_send_voice_cal == NULL) {
981 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
982 } else {
983 acdb_rx_id = acdb_device_table[out_snd_device];
984 acdb_tx_id = acdb_device_table[in_snd_device];
985
986 if (acdb_rx_id > 0 && acdb_tx_id > 0)
987 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
988 else
989 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
990 acdb_rx_id, acdb_tx_id);
991 }
992
993 return 0;
994}
995
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530996int platform_switch_voice_call_usecase_route_post(void *platform,
997 snd_device_t out_snd_device,
998 snd_device_t in_snd_device)
Naresh Tannirue3b18452014-03-04 14:44:27 +0530999{
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301000 struct platform_data *my_data = (struct platform_data *)platform;
1001 int acdb_rx_id, acdb_tx_id;
1002 int ret = 0;
1003
1004 acdb_rx_id = acdb_device_table[out_snd_device];
1005 acdb_tx_id = acdb_device_table[in_snd_device];
1006
1007 if (my_data->csd != NULL) {
1008 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
1009 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
1010 my_data->adev->acdb_settings);
1011 if (ret < 0) {
1012 ALOGE("%s: csd_enable_device, failed, error %d",
1013 __func__, ret);
1014 }
1015 } else {
1016 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1017 acdb_rx_id, acdb_tx_id);
1018 }
1019 }
1020 return ret;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301021}
1022
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301023int platform_start_voice_call(void *platform, uint32_t vsid)
1024{
1025 struct platform_data *my_data = (struct platform_data *)platform;
1026 int ret = 0;
1027
1028 if (my_data->csd != NULL) {
1029 ret = my_data->csd->start_voice(vsid);
1030 if (ret < 0) {
1031 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
1032 }
1033 }
1034 return ret;
1035}
1036
1037int platform_stop_voice_call(void *platform, uint32_t vsid)
1038{
1039 struct platform_data *my_data = (struct platform_data *)platform;
1040 int ret = 0;
1041
1042 if (my_data->csd != NULL) {
1043 ret = my_data->csd->stop_voice(vsid);
1044 if (ret < 0) {
1045 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
1046 }
1047 }
1048 return ret;
1049}
1050int platform_get_sample_rate(void *platform, uint32_t *rate)
Naresh Tannirue3b18452014-03-04 14:44:27 +05301051{
1052 return 0;
1053}
1054
1055int platform_set_voice_volume(void *platform, int volume)
1056{
1057 struct platform_data *my_data = (struct platform_data *)platform;
1058 struct audio_device *adev = my_data->adev;
1059 struct mixer_ctl *ctl;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301060 const char *mixer_ctl_name = "Voice Rx Gain";
1061 int vol_index = 0, ret = 0;
1062 uint32_t set_values[ ] = {0,
1063 ALL_SESSION_VSID,
1064 DEFAULT_VOLUME_RAMP_DURATION_MS};
Naresh Tannirue3b18452014-03-04 14:44:27 +05301065
1066 // Voice volume levels are mapped to adsp volume levels as follows.
1067 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
1068 // But this values don't changed in kernel. So, below change is need.
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301069 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, MAX_VOL_INDEX);
1070 set_values[0] = vol_index;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301071
1072 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1073 if (!ctl) {
1074 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1075 __func__, mixer_ctl_name);
1076 return -EINVAL;
1077 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301078 ALOGV("Setting voice volume index: %d", set_values[0]);
1079 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
Naresh Tannirue3b18452014-03-04 14:44:27 +05301080
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301081 if (my_data->csd != NULL) {
1082 ret = my_data->csd->volume(ALL_SESSION_VSID, volume);
1083 if (ret < 0) {
1084 ALOGE("%s: csd_volume error %d", __func__, ret);
1085 }
1086 }
1087 return ret;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301088}
1089
1090int platform_set_mic_mute(void *platform, bool state)
1091{
1092 struct platform_data *my_data = (struct platform_data *)platform;
1093 struct audio_device *adev = my_data->adev;
1094 struct mixer_ctl *ctl;
1095 const char *mixer_ctl_name = "Voice Tx Mute";
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301096 int ret = 0;
1097 uint32_t set_values[ ] = {0,
1098 ALL_SESSION_VSID,
1099 DEFAULT_VOLUME_RAMP_DURATION_MS};
Naresh Tannirue3b18452014-03-04 14:44:27 +05301100
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301101 set_values[0] = state;
1102 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1103 if (!ctl) {
1104 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1105 __func__, mixer_ctl_name);
1106 return -EINVAL;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301107 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301108 ALOGV("Setting voice mute state: %d", state);
1109 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
Naresh Tannirue3b18452014-03-04 14:44:27 +05301110
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301111 if (my_data->csd != NULL) {
1112 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state);
1113 if (ret < 0) {
1114 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
1115 }
1116 }
1117 return ret;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301118}
1119
Shiv Maliyappanahallic6fd8ee2014-03-07 15:31:55 -08001120int platform_set_device_mute(void *platform, bool state, char *dir)
1121{
1122 struct platform_data *my_data = (struct platform_data *)platform;
1123 struct audio_device *adev = my_data->adev;
1124 struct mixer_ctl *ctl;
1125 char *mixer_ctl_name = NULL;
1126 int ret = 0;
1127 uint32_t set_values[ ] = {0,
1128 ALL_SESSION_VSID,
1129 0};
1130 if(dir == NULL) {
1131 ALOGE("%s: Invalid direction:%s", __func__, dir);
1132 return -EINVAL;
1133 }
1134
1135 if (!strncmp("rx", dir, sizeof("rx"))) {
1136 mixer_ctl_name = "Voice Rx Device Mute";
1137 } else if (!strncmp("tx", dir, sizeof("tx"))) {
1138 mixer_ctl_name = "Voice Tx Device Mute";
1139 } else {
1140 return -EINVAL;
1141 }
1142
1143 set_values[0] = state;
1144 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1145 if (!ctl) {
1146 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1147 __func__, mixer_ctl_name);
1148 return -EINVAL;
1149 }
1150
1151 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
1152 __func__,state, mixer_ctl_name);
1153 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1154
1155 return ret;
1156}
1157
Naresh Tannirue3b18452014-03-04 14:44:27 +05301158snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
1159{
1160 struct platform_data *my_data = (struct platform_data *)platform;
1161 struct audio_device *adev = my_data->adev;
1162 audio_mode_t mode = adev->mode;
1163 snd_device_t snd_device = SND_DEVICE_NONE;
1164
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301165 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
1166 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
1167 int channel_count = popcount(channel_mask);
1168
Naresh Tannirue3b18452014-03-04 14:44:27 +05301169 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
1170 if (devices == AUDIO_DEVICE_NONE ||
1171 devices & AUDIO_DEVICE_BIT_IN) {
1172 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
1173 goto exit;
1174 }
1175
Naresh Tannirue3b18452014-03-04 14:44:27 +05301176 if (popcount(devices) == 2) {
1177 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
1178 AUDIO_DEVICE_OUT_SPEAKER)) {
1179 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
1180 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
1181 AUDIO_DEVICE_OUT_SPEAKER)) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301182 if (audio_extn_get_anc_enabled())
1183 snd_device = SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET;
1184 else
1185 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301186 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
1187 AUDIO_DEVICE_OUT_SPEAKER)) {
1188 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301189 } else if (devices == (AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET |
1190 AUDIO_DEVICE_OUT_SPEAKER)) {
1191 snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301192 } else {
1193 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
1194 goto exit;
1195 }
1196 if (snd_device != SND_DEVICE_NONE) {
1197 goto exit;
1198 }
1199 }
1200
1201 if (popcount(devices) != 1) {
1202 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
1203 goto exit;
1204 }
1205
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301206 if ((mode == AUDIO_MODE_IN_CALL) ||
1207 voice_extn_compress_voip_is_active(adev)) {
1208 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1209 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
1210 if ((adev->voice.tty_mode != TTY_MODE_OFF) &&
1211 !voice_extn_compress_voip_is_active(adev)) {
1212 switch (adev->voice.tty_mode) {
1213 case TTY_MODE_FULL:
1214 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
1215 break;
1216 case TTY_MODE_VCO:
1217 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
1218 break;
1219 case TTY_MODE_HCO:
1220 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
1221 break;
1222 default:
1223 ALOGE("%s: Invalid TTY mode (%#x)",
1224 __func__, adev->voice.tty_mode);
1225 }
1226 } else if (audio_extn_get_anc_enabled()) {
1227 if (audio_extn_should_use_fb_anc())
1228 snd_device = SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET;
1229 else
1230 snd_device = SND_DEVICE_OUT_VOICE_ANC_HEADSET;
1231 } else {
1232 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
1233 }
1234 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
1235 if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ)
1236 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
1237 else
1238 snd_device = SND_DEVICE_OUT_BT_SCO;
1239 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
1240 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
1241 } else if (devices & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
1242 devices & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
1243 snd_device = SND_DEVICE_OUT_USB_HEADSET;
1244 } else if (devices & AUDIO_DEVICE_OUT_FM_TX) {
1245 snd_device = SND_DEVICE_OUT_TRANSMISSION_FM;
1246 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
1247 if (audio_extn_should_use_handset_anc(channel_count))
1248 snd_device = SND_DEVICE_OUT_ANC_HANDSET;
1249 else
1250 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
1251 }
1252 if (snd_device != SND_DEVICE_NONE) {
1253 goto exit;
1254 }
1255 }
1256
Naresh Tannirue3b18452014-03-04 14:44:27 +05301257 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1258 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301259 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADSET
1260 && audio_extn_get_anc_enabled()) {
1261 if (audio_extn_should_use_fb_anc())
1262 snd_device = SND_DEVICE_OUT_ANC_FB_HEADSET;
1263 else
1264 snd_device = SND_DEVICE_OUT_ANC_HEADSET;
1265 }
1266 else
1267 snd_device = SND_DEVICE_OUT_HEADPHONES;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301268 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
1269 if (adev->speaker_lr_swap)
1270 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
1271 else
1272 snd_device = SND_DEVICE_OUT_SPEAKER;
1273 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301274 if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ)
1275 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
1276 else
1277 snd_device = SND_DEVICE_OUT_BT_SCO;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301278 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
1279 snd_device = SND_DEVICE_OUT_HDMI ;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301280 } else if (devices & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
1281 devices & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
Mingming Yin5a7c5d62014-03-05 17:45:03 -08001282 ALOGD("%s: setting USB hadset channel capability(2) for Proxy", __func__);
1283 audio_extn_set_afe_proxy_channel_mixer(adev, 2);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301284 snd_device = SND_DEVICE_OUT_USB_HEADSET;
1285 } else if (devices & AUDIO_DEVICE_OUT_FM_TX) {
1286 snd_device = SND_DEVICE_OUT_TRANSMISSION_FM;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301287 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
1288 snd_device = SND_DEVICE_OUT_HANDSET;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301289 } else if (devices & AUDIO_DEVICE_OUT_PROXY) {
Mingming Yin5a7c5d62014-03-05 17:45:03 -08001290 channel_count = audio_extn_get_afe_proxy_channel_count();
1291 ALOGD("%s: setting sink capability(%d) for Proxy", __func__, channel_count);
1292 audio_extn_set_afe_proxy_channel_mixer(adev, channel_count);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301293 snd_device = SND_DEVICE_OUT_AFE_PROXY;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301294 } else {
1295 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
1296 }
1297exit:
1298 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
1299 return snd_device;
1300}
1301
1302snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
1303{
1304 struct platform_data *my_data = (struct platform_data *)platform;
1305 struct audio_device *adev = my_data->adev;
1306 audio_source_t source = (adev->active_input == NULL) ?
1307 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
1308
1309 audio_mode_t mode = adev->mode;
1310 audio_devices_t in_device = ((adev->active_input == NULL) ?
1311 AUDIO_DEVICE_NONE : adev->active_input->device)
1312 & ~AUDIO_DEVICE_BIT_IN;
1313 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
1314 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
1315 snd_device_t snd_device = SND_DEVICE_NONE;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301316 int channel_count = popcount(channel_mask);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301317
1318 ALOGV("%s: enter: out_device(%#x) in_device(%#x)",
1319 __func__, out_device, in_device);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301320 if ((out_device != AUDIO_DEVICE_NONE) && ((mode == AUDIO_MODE_IN_CALL) ||
1321 voice_extn_compress_voip_is_active(adev))) {
1322 if ((adev->voice.tty_mode != TTY_MODE_OFF) &&
1323 !voice_extn_compress_voip_is_active(adev)) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301324 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1325 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301326 switch (adev->voice.tty_mode) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301327 case TTY_MODE_FULL:
1328 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
1329 break;
1330 case TTY_MODE_VCO:
1331 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
1332 break;
1333 case TTY_MODE_HCO:
1334 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
1335 break;
1336 default:
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301337 ALOGE("%s: Invalid TTY mode (%#x)",
1338 __func__, adev->voice.tty_mode);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301339 }
1340 goto exit;
1341 }
1342 }
1343 if (out_device & AUDIO_DEVICE_OUT_EARPIECE ||
1344 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301345 if (out_device & AUDIO_DEVICE_OUT_EARPIECE &&
1346 audio_extn_should_use_handset_anc(channel_count)) {
1347 snd_device = SND_DEVICE_IN_AANC_HANDSET_MIC;
1348 } else if (my_data->fluence_type == FLUENCE_NONE ||
1349 my_data->fluence_in_voice_call == false) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301350 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301351 set_echo_reference(adev->mixer, EC_REF_RX);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301352 } else {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301353 snd_device = SND_DEVICE_IN_VOICE_DMIC;
1354 adev->acdb_settings |= DMIC_FLAG;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301355 }
1356 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
1357 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
Satya Krishna Pindiproli624c7802014-04-11 11:33:27 +05301358 set_echo_reference(adev->mixer, EC_REF_RX);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301359 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301360 if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ)
1361 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
1362 else
1363 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301364 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301365 if (my_data->fluence_type != FLUENCE_NONE &&
1366 my_data->fluence_in_voice_call &&
1367 my_data->fluence_in_spkr_mode) {
1368 if(my_data->fluence_type & FLUENCE_QUAD_MIC) {
1369 adev->acdb_settings |= QMIC_FLAG;
1370 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_QMIC;
1371 } else {
1372 adev->acdb_settings |= DMIC_FLAG;
1373 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
1374 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05301375 } else {
1376 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
Satya Krishna Pindiproli624c7802014-04-11 11:33:27 +05301377 set_echo_reference(adev->mixer, EC_REF_RX);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301378 }
1379 }
1380 } else if (source == AUDIO_SOURCE_CAMCORDER) {
1381 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
1382 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
1383 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
1384 }
1385 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
1386 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301387 if (channel_count == 2) {
1388 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
1389 adev->acdb_settings |= DMIC_FLAG;
1390 } else if (adev->active_input->enable_ns)
1391 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
1392 else if (my_data->fluence_type != FLUENCE_NONE &&
1393 my_data->fluence_in_voice_rec) {
1394 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
1395 adev->acdb_settings |= DMIC_FLAG;
1396 } else {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301397 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
1398 }
1399 }
1400 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION) {
1401 if (out_device & AUDIO_DEVICE_OUT_SPEAKER)
1402 in_device = AUDIO_DEVICE_IN_BACK_MIC;
1403 if (adev->active_input) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301404 if (adev->active_input->enable_aec &&
1405 adev->active_input->enable_ns) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301406 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301407 if (my_data->fluence_type & FLUENCE_DUAL_MIC &&
1408 my_data->fluence_in_spkr_mode) {
1409 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
1410 adev->acdb_settings |= DMIC_FLAG;
1411 } else
1412 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301413 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301414 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1415 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
1416 adev->acdb_settings |= DMIC_FLAG;
1417 } else
1418 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301419 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301420 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301421 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301422 set_echo_reference(adev->mixer, EC_REF_RX);
1423 } else if (adev->active_input->enable_aec) {
1424 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
1425 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1426 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
1427 adev->acdb_settings |= DMIC_FLAG;
1428 } else
1429 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
1430 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
1431 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1432 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
1433 adev->acdb_settings |= DMIC_FLAG;
1434 } else
1435 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
1436 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
1437 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
1438 }
1439 set_echo_reference(adev->mixer, EC_REF_RX);
1440 } else if (adev->active_input->enable_ns) {
1441 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
1442 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1443 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
1444 adev->acdb_settings |= DMIC_FLAG;
1445 } else
1446 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
1447 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
1448 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1449 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
1450 adev->acdb_settings |= DMIC_FLAG;
1451 } else
1452 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
1453 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
1454 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
1455 }
1456 set_echo_reference(adev->mixer, "NONE");
Naresh Tannirue3b18452014-03-04 14:44:27 +05301457 } else
1458 set_echo_reference(adev->mixer, "NONE");
1459 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301460 } else if (source == AUDIO_SOURCE_MIC) {
1461 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC &&
1462 channel_count == 1 ) {
1463 if(my_data->fluence_type & FLUENCE_DUAL_MIC &&
1464 my_data->fluence_in_audio_rec)
1465 snd_device = SND_DEVICE_IN_HANDSET_DMIC;
1466 }
1467 } else if (source == AUDIO_SOURCE_FM_RX ||
1468 source == AUDIO_SOURCE_FM_RX_A2DP) {
1469 snd_device = SND_DEVICE_IN_CAPTURE_FM;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301470 } else if (source == AUDIO_SOURCE_DEFAULT) {
1471 goto exit;
1472 }
1473
1474
1475 if (snd_device != SND_DEVICE_NONE) {
1476 goto exit;
1477 }
1478
1479 if (in_device != AUDIO_DEVICE_NONE &&
1480 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
1481 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
1482 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301483 if (audio_extn_ssr_get_enabled() && channel_count == 6)
1484 snd_device = SND_DEVICE_IN_QUAD_MIC;
1485 else if (channel_count == 2)
1486 snd_device = SND_DEVICE_IN_HANDSET_STEREO_DMIC;
1487 else
1488 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301489 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
1490 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
1491 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
1492 snd_device = SND_DEVICE_IN_HEADSET_MIC;
1493 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301494 if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ)
1495 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
1496 else
1497 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301498 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
1499 snd_device = SND_DEVICE_IN_HDMI_MIC;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301500 } else if (in_device & AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET ||
1501 in_device & AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET) {
1502 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
1503 } else if (in_device & AUDIO_DEVICE_IN_FM_RX) {
1504 snd_device = SND_DEVICE_IN_CAPTURE_FM;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301505 } else {
1506 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
1507 ALOGW("%s: Using default handset-mic", __func__);
1508 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1509 }
1510 } else {
1511 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
1512 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1513 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
1514 snd_device = SND_DEVICE_IN_HEADSET_MIC;
1515 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301516 if (channel_count > 1)
1517 snd_device = SND_DEVICE_IN_SPEAKER_STEREO_DMIC;
1518 else
1519 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301520 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
1521 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1522 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301523 if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ)
1524 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
1525 else
1526 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301527 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
1528 snd_device = SND_DEVICE_IN_HDMI_MIC;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301529 } else if (out_device & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
1530 out_device & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
1531 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301532 } else {
1533 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
1534 ALOGW("%s: Using default handset-mic", __func__);
1535 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1536 }
1537 }
1538exit:
1539 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
1540 return snd_device;
1541}
1542
1543int platform_set_hdmi_channels(void *platform, int channel_count)
1544{
1545 struct platform_data *my_data = (struct platform_data *)platform;
1546 struct audio_device *adev = my_data->adev;
1547 struct mixer_ctl *ctl;
1548 const char *channel_cnt_str = NULL;
1549 const char *mixer_ctl_name = "HDMI_RX Channels";
1550 switch (channel_count) {
1551 case 8:
1552 channel_cnt_str = "Eight"; break;
1553 case 7:
1554 channel_cnt_str = "Seven"; break;
1555 case 6:
1556 channel_cnt_str = "Six"; break;
1557 case 5:
1558 channel_cnt_str = "Five"; break;
1559 case 4:
1560 channel_cnt_str = "Four"; break;
1561 case 3:
1562 channel_cnt_str = "Three"; break;
1563 default:
1564 channel_cnt_str = "Two"; break;
1565 }
1566 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1567 if (!ctl) {
1568 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1569 __func__, mixer_ctl_name);
1570 return -EINVAL;
1571 }
1572 ALOGV("HDMI channel count: %s", channel_cnt_str);
1573 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
1574 return 0;
1575}
1576
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301577int platform_edid_get_max_channels(void *platform)
Naresh Tannirue3b18452014-03-04 14:44:27 +05301578{
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301579 struct platform_data *my_data = (struct platform_data *)platform;
1580 struct audio_device *adev = my_data->adev;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301581 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
1582 char *sad = block;
1583 int num_audio_blocks;
1584 int channel_count;
1585 int max_channels = 0;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301586 int i, ret, count;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301587
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301588 struct mixer_ctl *ctl;
1589
1590 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
1591 if (!ctl) {
1592 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1593 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301594 return 0;
1595 }
1596
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301597 mixer_ctl_update(ctl);
1598
1599 count = mixer_ctl_get_num_values(ctl);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301600
1601 /* Read SAD blocks, clamping the maximum size for safety */
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301602 if (count > (int)sizeof(block))
1603 count = (int)sizeof(block);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301604
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301605 ret = mixer_ctl_get_array(ctl, block, count);
1606 if (ret != 0) {
1607 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
1608 return 0;
1609 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05301610
1611 /* Calculate the number of SAD blocks */
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301612 num_audio_blocks = count / SAD_BLOCK_SIZE;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301613
1614 for (i = 0; i < num_audio_blocks; i++) {
1615 /* Only consider LPCM blocks */
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301616 if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
1617 sad += 3;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301618 continue;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301619 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05301620
1621 channel_count = (sad[0] & 0x7) + 1;
1622 if (channel_count > max_channels)
1623 max_channels = channel_count;
1624
1625 /* Advance to next block */
1626 sad += 3;
1627 }
1628
1629 return max_channels;
1630}
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301631
1632static int platform_set_slowtalk(struct platform_data *my_data, bool state)
1633{
1634 int ret = 0;
1635 struct audio_device *adev = my_data->adev;
1636 struct mixer_ctl *ctl;
1637 const char *mixer_ctl_name = "Slowtalk Enable";
1638 uint32_t set_values[ ] = {0,
1639 ALL_SESSION_VSID};
1640
1641 set_values[0] = state;
1642 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1643 if (!ctl) {
1644 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1645 __func__, mixer_ctl_name);
1646 ret = -EINVAL;
1647 } else {
1648 ALOGV("Setting slowtalk state: %d", state);
1649 ret = mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1650 my_data->slowtalk = state;
1651 }
1652
1653 if (my_data->csd != NULL) {
1654 ret = my_data->csd->slow_talk(ALL_SESSION_VSID, state);
1655 if (ret < 0) {
1656 ALOGE("%s: csd_client_disable_device, failed, error %d",
1657 __func__, ret);
1658 }
1659 }
1660 return ret;
1661}
1662
1663int platform_set_parameters(void *platform, struct str_parms *parms)
1664{
1665 struct platform_data *my_data = (struct platform_data *)platform;
1666 char *str;
1667 char value[256] = {0};
1668 int val;
1669 int ret = 0, err;
1670
1671 ALOGV("%s: enter: %s", __func__, str_parms_to_str(parms));
1672
1673 err = str_parms_get_int(parms, AUDIO_PARAMETER_KEY_BTSCO, &val);
1674 if (err >= 0) {
1675 str_parms_del(parms, AUDIO_PARAMETER_KEY_BTSCO);
1676 my_data->btsco_sample_rate = val;
1677 if (val == SAMPLE_RATE_16KHZ) {
Haynes Mathew George1376ca62014-04-24 11:55:48 -07001678 audio_route_apply_and_update_path(my_data->adev->audio_route,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301679 "bt-sco-wb-samplerate");
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301680 }
1681 }
1682
1683 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_SLOWTALK, value, sizeof(value));
1684 if (err >= 0) {
1685 bool state = false;
1686 if (!strncmp("true", value, sizeof("true"))) {
1687 state = true;
1688 }
1689
1690 str_parms_del(parms, AUDIO_PARAMETER_KEY_SLOWTALK);
1691 ret = platform_set_slowtalk(my_data, state);
1692 if (ret)
1693 ALOGE("%s: Failed to set slow talk err: %d", __func__, ret);
1694 }
1695
1696 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_VOLUME_BOOST,
1697 value, sizeof(value));
1698 if (err >= 0) {
1699 str_parms_del(parms, AUDIO_PARAMETER_KEY_VOLUME_BOOST);
1700
1701 if (my_data->acdb_reload_vocvoltable == NULL) {
1702 ALOGE("%s: acdb_reload_vocvoltable is NULL", __func__);
1703 } else if (!strcmp(value, "on")) {
1704 if (!my_data->acdb_reload_vocvoltable(VOICE_FEATURE_SET_VOLUME_BOOST)) {
1705 my_data->voice_feature_set = 1;
1706 }
1707 } else {
1708 if (!my_data->acdb_reload_vocvoltable(VOICE_FEATURE_SET_DEFAULT)) {
1709 my_data->voice_feature_set = 0;
1710 }
1711 }
1712 }
1713
1714 ALOGV("%s: exit with code(%d)", __func__, ret);
1715 return ret;
1716}
1717
1718int platform_set_incall_recording_session_id(void *platform,
1719 uint32_t session_id, int rec_mode)
1720{
1721 int ret = 0;
1722 struct platform_data *my_data = (struct platform_data *)platform;
1723 struct audio_device *adev = my_data->adev;
1724 struct mixer_ctl *ctl;
1725 const char *mixer_ctl_name = "Voc VSID";
1726 int num_ctl_values;
1727 int i;
1728
1729 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1730 if (!ctl) {
1731 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1732 __func__, mixer_ctl_name);
1733 ret = -EINVAL;
1734 } else {
1735 num_ctl_values = mixer_ctl_get_num_values(ctl);
1736 for (i = 0; i < num_ctl_values; i++) {
1737 if (mixer_ctl_set_value(ctl, i, session_id)) {
1738 ALOGV("Error: invalid session_id: %x", session_id);
1739 ret = -EINVAL;
1740 break;
1741 }
1742 }
1743 }
1744
1745 if (my_data->csd != NULL) {
1746 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
1747 if (ret < 0) {
1748 ALOGE("%s: csd_client_start_record failed, error %d",
1749 __func__, ret);
1750 }
1751 }
1752
1753 return ret;
1754}
1755
1756int platform_stop_incall_recording_usecase(void *platform)
1757{
1758 int ret = 0;
1759 struct platform_data *my_data = (struct platform_data *)platform;
1760
1761 if (my_data->csd != NULL) {
1762 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
1763 if (ret < 0) {
1764 ALOGE("%s: csd_client_stop_record failed, error %d",
1765 __func__, ret);
1766 }
1767 }
1768
1769 return ret;
1770}
1771
1772int platform_start_incall_music_usecase(void *platform)
1773{
1774 int ret = 0;
1775 struct platform_data *my_data = (struct platform_data *)platform;
1776
1777 if (my_data->csd != NULL) {
1778 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
1779 if (ret < 0) {
1780 ALOGE("%s: csd_client_start_playback failed, error %d",
1781 __func__, ret);
1782 }
1783 }
1784
1785 return ret;
1786}
1787
1788int platform_stop_incall_music_usecase(void *platform)
1789{
1790 int ret = 0;
1791 struct platform_data *my_data = (struct platform_data *)platform;
1792
1793 if (my_data->csd != NULL) {
1794 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
1795 if (ret < 0) {
1796 ALOGE("%s: csd_client_stop_playback failed, error %d",
1797 __func__, ret);
1798 }
1799 }
1800
1801 return ret;
1802}
1803
1804void platform_get_parameters(void *platform,
1805 struct str_parms *query,
1806 struct str_parms *reply)
1807{
1808 struct platform_data *my_data = (struct platform_data *)platform;
1809 char *str = NULL;
1810 char value[256] = {0};
1811 int ret;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301812
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301813 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_SLOWTALK,
1814 value, sizeof(value));
1815 if (ret >= 0) {
1816 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_SLOWTALK,
1817 my_data->slowtalk?"true":"false");
1818 }
1819
1820 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_VOLUME_BOOST,
1821 value, sizeof(value));
1822 if (ret >= 0) {
1823 if (my_data->voice_feature_set == VOICE_FEATURE_SET_VOLUME_BOOST) {
1824 strlcpy(value, "on", sizeof(value));
1825 } else {
1826 strlcpy(value, "off", sizeof(value));
1827 }
1828
1829 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_VOLUME_BOOST, value);
1830 }
1831
1832 ALOGV("%s: exit: returns - %s", __func__, str_parms_to_str(reply));
1833}
1834
1835/* Delay in Us */
1836int64_t platform_render_latency(audio_usecase_t usecase)
1837{
1838 switch (usecase) {
1839 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
1840 return DEEP_BUFFER_PLATFORM_DELAY;
1841 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
1842 return LOW_LATENCY_PLATFORM_DELAY;
1843 default:
1844 return 0;
1845 }
1846}
1847
1848int platform_update_usecase_from_source(int source, int usecase)
1849{
1850 ALOGV("%s: input source :%d", __func__, source);
1851 if(source == AUDIO_SOURCE_FM_RX_A2DP)
1852 usecase = USECASE_AUDIO_RECORD_FM_VIRTUAL;
1853 return usecase;
1854}
1855
1856bool platform_listen_update_status(snd_device_t snd_device)
1857{
1858 if ((snd_device >= SND_DEVICE_IN_BEGIN) &&
1859 (snd_device < SND_DEVICE_IN_END) &&
1860 (snd_device != SND_DEVICE_IN_CAPTURE_FM) &&
1861 (snd_device != SND_DEVICE_IN_CAPTURE_VI_FEEDBACK))
1862 return true;
1863 else
1864 return false;
1865}
1866
1867/* Read offload buffer size from a property.
1868 * If value is not power of 2 round it to
1869 * power of 2.
1870 */
1871uint32_t platform_get_compress_offload_buffer_size(audio_offload_info_t* info)
1872{
1873 char value[PROPERTY_VALUE_MAX] = {0};
1874 uint32_t fragment_size = COMPRESS_OFFLOAD_FRAGMENT_SIZE;
1875 if((property_get("audio.offload.buffer.size.kb", value, "")) &&
1876 atoi(value)) {
1877 fragment_size = atoi(value) * 1024;
1878 }
1879
1880 if (info != NULL && info->has_video && info->is_streaming) {
1881 fragment_size = COMPRESS_OFFLOAD_FRAGMENT_SIZE_FOR_AV_STREAMING;
1882 ALOGV("%s: offload fragment size reduced for AV streaming to %d",
1883 __func__, out->compr_config.fragment_size);
1884 }
1885
1886 fragment_size = ALIGN( fragment_size, 1024);
1887
1888 if(fragment_size < MIN_COMPRESS_OFFLOAD_FRAGMENT_SIZE)
1889 fragment_size = MIN_COMPRESS_OFFLOAD_FRAGMENT_SIZE;
1890 else if(fragment_size > MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE)
1891 fragment_size = MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE;
1892 ALOGV("%s: fragment_size %d", __func__, fragment_size);
1893 return fragment_size;
1894}
1895
1896uint32_t platform_get_pcm_offload_buffer_size(audio_offload_info_t* info)
1897{
1898 uint32_t fragment_size = MIN_PCM_OFFLOAD_FRAGMENT_SIZE;
1899 uint32_t bits_per_sample = 16;
1900
1901 if (info->format == AUDIO_FORMAT_PCM_24_BIT_OFFLOAD) {
1902 bits_per_sample = 32;
1903 }
1904
1905 if (!info->has_video) {
1906 fragment_size = MAX_PCM_OFFLOAD_FRAGMENT_SIZE;
1907
1908 } else if (info->has_video && info->is_streaming) {
1909 fragment_size = (PCM_OFFLOAD_BUFFER_DURATION_FOR_AV_STREAMING
1910 * info->sample_rate
1911 * bits_per_sample
1912 * popcount(info->channel_mask))/1000;
1913
1914 } else if (info->has_video) {
1915 fragment_size = (PCM_OFFLOAD_BUFFER_DURATION_FOR_AV
1916 * info->sample_rate
1917 * bits_per_sample
1918 * popcount(info->channel_mask))/1000;
1919 }
1920
1921 fragment_size = ALIGN( fragment_size, 1024);
1922
1923 if(fragment_size < MIN_PCM_OFFLOAD_FRAGMENT_SIZE)
1924 fragment_size = MIN_PCM_OFFLOAD_FRAGMENT_SIZE;
1925 else if(fragment_size > MAX_PCM_OFFLOAD_FRAGMENT_SIZE)
1926 fragment_size = MAX_PCM_OFFLOAD_FRAGMENT_SIZE;
1927
1928 ALOGV("%s: fragment_size %d", __func__, fragment_size);
1929 return fragment_size;
1930}
1931