blob: d573438615e675e9ea6a4769797c5d3119253330 [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);
Naresh Tannirue3b18452014-03-04 14:44:27 +0530719 return my_data;
720}
721
722void platform_deinit(void *platform)
723{
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530724 struct platform_data *my_data = (struct platform_data *)platform;
725
726 hw_info_deinit(my_data->hw_info);
727 close_csd_client(my_data->csd);
728
Naresh Tannirue3b18452014-03-04 14:44:27 +0530729 free(platform);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530730 /* deinit usb */
731 audio_extn_usb_deinit();
Naresh Tannirue3b18452014-03-04 14:44:27 +0530732}
733
734const char *platform_get_snd_device_name(snd_device_t snd_device)
735{
736 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX)
737 return device_table[snd_device];
738 else
739 return "";
740}
741
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530742int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
743 char *device_name)
744{
745 struct platform_data *my_data = (struct platform_data *)platform;
746
747 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
748 strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE);
749 hw_info_append_hw_type(my_data->hw_info, snd_device, device_name);
750 } else {
751 strlcpy(device_name, "", DEVICE_NAME_MAX_SIZE);
752 return -EINVAL;
753 }
754
755 return 0;
756}
757
Naresh Tannirue3b18452014-03-04 14:44:27 +0530758void platform_add_backend_name(char *mixer_path, snd_device_t snd_device)
759{
760 if (snd_device == SND_DEVICE_IN_BT_SCO_MIC)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530761 strlcat(mixer_path, " bt-sco", MIXER_PATH_MAX_LENGTH);
762 else if (snd_device == SND_DEVICE_IN_BT_SCO_MIC_WB)
763 strlcat(mixer_path, " bt-sco-wb", MIXER_PATH_MAX_LENGTH);
Naresh Tannirue3b18452014-03-04 14:44:27 +0530764 else if(snd_device == SND_DEVICE_OUT_BT_SCO)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530765 strlcat(mixer_path, " bt-sco", MIXER_PATH_MAX_LENGTH);
766 else if(snd_device == SND_DEVICE_OUT_BT_SCO_WB)
767 strlcat(mixer_path, " bt-sco-wb", MIXER_PATH_MAX_LENGTH);
Naresh Tannirue3b18452014-03-04 14:44:27 +0530768 else if (snd_device == SND_DEVICE_OUT_HDMI)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530769 strlcat(mixer_path, " hdmi", MIXER_PATH_MAX_LENGTH);
Naresh Tannirue3b18452014-03-04 14:44:27 +0530770 else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HDMI)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530771 strlcat(mixer_path, " speaker-and-hdmi", MIXER_PATH_MAX_LENGTH);
772 else if (snd_device == SND_DEVICE_OUT_AFE_PROXY)
773 strlcat(mixer_path, " afe-proxy", MIXER_PATH_MAX_LENGTH);
774 else if (snd_device == SND_DEVICE_OUT_USB_HEADSET)
775 strlcat(mixer_path, " usb-headphones", MIXER_PATH_MAX_LENGTH);
776 else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET)
777 strlcat(mixer_path, " speaker-and-usb-headphones",
778 MIXER_PATH_MAX_LENGTH);
779 else if (snd_device == SND_DEVICE_IN_USB_HEADSET_MIC)
780 strlcat(mixer_path, " usb-headset-mic", MIXER_PATH_MAX_LENGTH);
781 else if (snd_device == SND_DEVICE_IN_CAPTURE_FM)
782 strlcat(mixer_path, " capture-fm", MIXER_PATH_MAX_LENGTH);
783 else if (snd_device == SND_DEVICE_OUT_TRANSMISSION_FM)
784 strlcat(mixer_path, " transmission-fm", MIXER_PATH_MAX_LENGTH);
Naresh Tannirue3b18452014-03-04 14:44:27 +0530785}
786
787int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
788{
789 int device_id;
790 if (device_type == PCM_PLAYBACK)
791 device_id = pcm_device_table[usecase][0];
792 else
793 device_id = pcm_device_table[usecase][1];
794 return device_id;
795}
796
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530797int platform_get_snd_device_index(char *snd_device_index_name)
798{
799 int ret = 0;
800 int i;
801
802 if (snd_device_index_name == NULL) {
803 ALOGE("%s: snd_device_index_name is NULL", __func__);
804 ret = -ENODEV;
805 goto done;
806 }
807
808 for (i=0; i < SND_DEVICE_MAX; i++) {
809 if(strcmp(snd_device_name_index[i].name, snd_device_index_name) == 0) {
810 ret = snd_device_name_index[i].index;
811 goto done;
812 }
813 }
814 ALOGE("%s: Could not find index for snd_device_index_name = %s",
815 __func__, snd_device_index_name);
816 ret = -ENODEV;
817done:
818 return ret;
819}
820
Venkata Narendra Kumar Gutta88fd0bc2014-03-27 19:47:56 +0530821int platform_set_fluence_type(void *platform, char *value)
822{
823 int ret = 0;
824 int fluence_type = FLUENCE_NONE;
825 int fluence_flag = NONE_FLAG;
826 struct platform_data *my_data = (struct platform_data *)platform;
827 struct audio_device *adev = my_data->adev;
828
829 ALOGV("%s: fluence type:%d", __func__, my_data->fluence_type);
830
831 /* only dual mic turn on and off is supported as of now through setparameters */
832 if (!strncmp(AUDIO_PARAMETER_VALUE_DUALMIC,value, sizeof(AUDIO_PARAMETER_VALUE_DUALMIC))) {
833 if (!strncmp("fluencepro", my_data->fluence_cap, sizeof("fluencepro")) ||
834 !strncmp("fluence", my_data->fluence_cap, sizeof("fluence"))) {
835 ALOGV("fluence dualmic feature enabled \n");
836 fluence_type = FLUENCE_DUAL_MIC;
837 fluence_flag = DMIC_FLAG;
838 } else {
839 ALOGE("%s: Failed to set DUALMIC", __func__);
840 ret = -1;
841 goto done;
842 }
843 } else if (!strncmp(AUDIO_PARAMETER_KEY_NO_FLUENCE, value, sizeof(AUDIO_PARAMETER_KEY_NO_FLUENCE))) {
844 ALOGV("fluence disabled");
845 fluence_type = FLUENCE_NONE;
846 } else {
847 ALOGE("Invalid fluence value : %s",value);
848 ret = -1;
849 goto done;
850 }
851
852 if (fluence_type != my_data->fluence_type) {
853 ALOGV("%s: Updating fluence_type to :%d", __func__, fluence_type);
854 my_data->fluence_type = fluence_type;
855 adev->acdb_settings = (adev->acdb_settings & FLUENCE_MODE_CLEAR) | fluence_flag;
856 }
857done:
858 return ret;
859}
860
861int platform_get_fluence_type(void *platform, char *value, uint32_t len)
862{
863 int ret = 0;
864 struct platform_data *my_data = (struct platform_data *)platform;
865
866 if (my_data->fluence_type == FLUENCE_QUAD_MIC) {
867 strlcpy(value, "quadmic", len);
868 } else if (my_data->fluence_type == FLUENCE_DUAL_MIC) {
869 strlcpy(value, "dualmic", len);
870 } else if (my_data->fluence_type == FLUENCE_NONE) {
871 strlcpy(value, "none", len);
872 } else
873 ret = -1;
874
875 return ret;
876}
877
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530878int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
879{
880 int ret = 0;
881
882 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
883 ALOGE("%s: Invalid snd_device = %d",
884 __func__, snd_device);
885 ret = -EINVAL;
886 goto done;
887 }
888
889 acdb_device_table[snd_device] = acdb_id;
890done:
891 return ret;
892}
893
Naresh Tannirue3b18452014-03-04 14:44:27 +0530894int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
895{
896 struct platform_data *my_data = (struct platform_data *)platform;
897 int acdb_dev_id, acdb_dev_type;
898
899 acdb_dev_id = acdb_device_table[snd_device];
900 if (acdb_dev_id < 0) {
901 ALOGE("%s: Could not find acdb id for device(%d)",
902 __func__, snd_device);
903 return -EINVAL;
904 }
905 if (my_data->acdb_send_audio_cal) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530906 ("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530907 __func__, snd_device, acdb_dev_id);
908 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
909 snd_device < SND_DEVICE_OUT_END)
910 acdb_dev_type = ACDB_DEV_TYPE_OUT;
911 else
912 acdb_dev_type = ACDB_DEV_TYPE_IN;
913 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
914 }
915 return 0;
916}
917
918int platform_switch_voice_call_device_pre(void *platform)
919{
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530920 struct platform_data *my_data = (struct platform_data *)platform;
921 int ret = 0;
922
923 if (my_data->csd != NULL &&
924 my_data->adev->mode == AUDIO_MODE_IN_CALL) {
925 /* This must be called before disabling mixer controls on APQ side */
926 ret = my_data->csd->disable_device();
927 if (ret < 0) {
928 ALOGE("%s: csd_client_disable_device, failed, error %d",
929 __func__, ret);
930 }
931 }
932 return ret;
Naresh Tannirue3b18452014-03-04 14:44:27 +0530933}
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530934int platform_switch_voice_call_enable_device_config(void *platform,
935 snd_device_t out_snd_device,
936 snd_device_t in_snd_device)
937{
938 struct platform_data *my_data = (struct platform_data *)platform;
939 int acdb_rx_id, acdb_tx_id;
940 int ret = 0;
941
942 acdb_rx_id = acdb_device_table[out_snd_device];
943 acdb_tx_id = acdb_device_table[in_snd_device];
944
945 if (my_data->csd != NULL) {
946 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
947 ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
948 if (ret < 0) {
949 ALOGE("%s: csd_enable_device_config, failed, error %d",
950 __func__, ret);
951 }
952 } else {
953 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
954 acdb_rx_id, acdb_tx_id);
955 }
956 }
957 return ret;
958}
959
Naresh Tannirue3b18452014-03-04 14:44:27 +0530960
961int platform_switch_voice_call_device_post(void *platform,
962 snd_device_t out_snd_device,
963 snd_device_t in_snd_device)
964{
965 struct platform_data *my_data = (struct platform_data *)platform;
966 int acdb_rx_id, acdb_tx_id;
967
968 if (my_data->acdb_send_voice_cal == NULL) {
969 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
970 } else {
971 acdb_rx_id = acdb_device_table[out_snd_device];
972 acdb_tx_id = acdb_device_table[in_snd_device];
973
974 if (acdb_rx_id > 0 && acdb_tx_id > 0)
975 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
976 else
977 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
978 acdb_rx_id, acdb_tx_id);
979 }
980
981 return 0;
982}
983
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530984int platform_switch_voice_call_usecase_route_post(void *platform,
985 snd_device_t out_snd_device,
986 snd_device_t in_snd_device)
Naresh Tannirue3b18452014-03-04 14:44:27 +0530987{
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530988 struct platform_data *my_data = (struct platform_data *)platform;
989 int acdb_rx_id, acdb_tx_id;
990 int ret = 0;
991
992 acdb_rx_id = acdb_device_table[out_snd_device];
993 acdb_tx_id = acdb_device_table[in_snd_device];
994
995 if (my_data->csd != NULL) {
996 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
997 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
998 my_data->adev->acdb_settings);
999 if (ret < 0) {
1000 ALOGE("%s: csd_enable_device, failed, error %d",
1001 __func__, ret);
1002 }
1003 } else {
1004 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1005 acdb_rx_id, acdb_tx_id);
1006 }
1007 }
1008 return ret;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301009}
1010
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301011int platform_start_voice_call(void *platform, uint32_t vsid)
1012{
1013 struct platform_data *my_data = (struct platform_data *)platform;
1014 int ret = 0;
1015
1016 if (my_data->csd != NULL) {
1017 ret = my_data->csd->start_voice(vsid);
1018 if (ret < 0) {
1019 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
1020 }
1021 }
1022 return ret;
1023}
1024
1025int platform_stop_voice_call(void *platform, uint32_t vsid)
1026{
1027 struct platform_data *my_data = (struct platform_data *)platform;
1028 int ret = 0;
1029
1030 if (my_data->csd != NULL) {
1031 ret = my_data->csd->stop_voice(vsid);
1032 if (ret < 0) {
1033 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
1034 }
1035 }
1036 return ret;
1037}
1038int platform_get_sample_rate(void *platform, uint32_t *rate)
Naresh Tannirue3b18452014-03-04 14:44:27 +05301039{
1040 return 0;
1041}
1042
1043int platform_set_voice_volume(void *platform, int volume)
1044{
1045 struct platform_data *my_data = (struct platform_data *)platform;
1046 struct audio_device *adev = my_data->adev;
1047 struct mixer_ctl *ctl;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301048 const char *mixer_ctl_name = "Voice Rx Gain";
1049 int vol_index = 0, ret = 0;
1050 uint32_t set_values[ ] = {0,
1051 ALL_SESSION_VSID,
1052 DEFAULT_VOLUME_RAMP_DURATION_MS};
Naresh Tannirue3b18452014-03-04 14:44:27 +05301053
1054 // Voice volume levels are mapped to adsp volume levels as follows.
1055 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
1056 // But this values don't changed in kernel. So, below change is need.
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301057 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, MAX_VOL_INDEX);
1058 set_values[0] = vol_index;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301059
1060 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1061 if (!ctl) {
1062 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1063 __func__, mixer_ctl_name);
1064 return -EINVAL;
1065 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301066 ALOGV("Setting voice volume index: %d", set_values[0]);
1067 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
Naresh Tannirue3b18452014-03-04 14:44:27 +05301068
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301069 if (my_data->csd != NULL) {
1070 ret = my_data->csd->volume(ALL_SESSION_VSID, volume);
1071 if (ret < 0) {
1072 ALOGE("%s: csd_volume error %d", __func__, ret);
1073 }
1074 }
1075 return ret;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301076}
1077
1078int platform_set_mic_mute(void *platform, bool state)
1079{
1080 struct platform_data *my_data = (struct platform_data *)platform;
1081 struct audio_device *adev = my_data->adev;
1082 struct mixer_ctl *ctl;
1083 const char *mixer_ctl_name = "Voice Tx Mute";
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301084 int ret = 0;
1085 uint32_t set_values[ ] = {0,
1086 ALL_SESSION_VSID,
1087 DEFAULT_VOLUME_RAMP_DURATION_MS};
Naresh Tannirue3b18452014-03-04 14:44:27 +05301088
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301089 set_values[0] = state;
1090 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1091 if (!ctl) {
1092 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1093 __func__, mixer_ctl_name);
1094 return -EINVAL;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301095 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301096 ALOGV("Setting voice mute state: %d", state);
1097 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
Naresh Tannirue3b18452014-03-04 14:44:27 +05301098
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301099 if (my_data->csd != NULL) {
1100 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state);
1101 if (ret < 0) {
1102 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
1103 }
1104 }
1105 return ret;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301106}
1107
Shiv Maliyappanahallic6fd8ee2014-03-07 15:31:55 -08001108int platform_set_device_mute(void *platform, bool state, char *dir)
1109{
1110 struct platform_data *my_data = (struct platform_data *)platform;
1111 struct audio_device *adev = my_data->adev;
1112 struct mixer_ctl *ctl;
1113 char *mixer_ctl_name = NULL;
1114 int ret = 0;
1115 uint32_t set_values[ ] = {0,
1116 ALL_SESSION_VSID,
1117 0};
1118 if(dir == NULL) {
1119 ALOGE("%s: Invalid direction:%s", __func__, dir);
1120 return -EINVAL;
1121 }
1122
1123 if (!strncmp("rx", dir, sizeof("rx"))) {
1124 mixer_ctl_name = "Voice Rx Device Mute";
1125 } else if (!strncmp("tx", dir, sizeof("tx"))) {
1126 mixer_ctl_name = "Voice Tx Device Mute";
1127 } else {
1128 return -EINVAL;
1129 }
1130
1131 set_values[0] = state;
1132 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1133 if (!ctl) {
1134 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1135 __func__, mixer_ctl_name);
1136 return -EINVAL;
1137 }
1138
1139 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
1140 __func__,state, mixer_ctl_name);
1141 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1142
1143 return ret;
1144}
1145
Naresh Tannirue3b18452014-03-04 14:44:27 +05301146snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
1147{
1148 struct platform_data *my_data = (struct platform_data *)platform;
1149 struct audio_device *adev = my_data->adev;
1150 audio_mode_t mode = adev->mode;
1151 snd_device_t snd_device = SND_DEVICE_NONE;
1152
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301153 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
1154 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
1155 int channel_count = popcount(channel_mask);
1156
Naresh Tannirue3b18452014-03-04 14:44:27 +05301157 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
1158 if (devices == AUDIO_DEVICE_NONE ||
1159 devices & AUDIO_DEVICE_BIT_IN) {
1160 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
1161 goto exit;
1162 }
1163
Naresh Tannirue3b18452014-03-04 14:44:27 +05301164 if (popcount(devices) == 2) {
1165 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
1166 AUDIO_DEVICE_OUT_SPEAKER)) {
1167 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
1168 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
1169 AUDIO_DEVICE_OUT_SPEAKER)) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301170 if (audio_extn_get_anc_enabled())
1171 snd_device = SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET;
1172 else
1173 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301174 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
1175 AUDIO_DEVICE_OUT_SPEAKER)) {
1176 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301177 } else if (devices == (AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET |
1178 AUDIO_DEVICE_OUT_SPEAKER)) {
1179 snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301180 } else {
1181 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
1182 goto exit;
1183 }
1184 if (snd_device != SND_DEVICE_NONE) {
1185 goto exit;
1186 }
1187 }
1188
1189 if (popcount(devices) != 1) {
1190 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
1191 goto exit;
1192 }
1193
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301194 if ((mode == AUDIO_MODE_IN_CALL) ||
1195 voice_extn_compress_voip_is_active(adev)) {
1196 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1197 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
1198 if ((adev->voice.tty_mode != TTY_MODE_OFF) &&
1199 !voice_extn_compress_voip_is_active(adev)) {
1200 switch (adev->voice.tty_mode) {
1201 case TTY_MODE_FULL:
1202 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
1203 break;
1204 case TTY_MODE_VCO:
1205 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
1206 break;
1207 case TTY_MODE_HCO:
1208 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
1209 break;
1210 default:
1211 ALOGE("%s: Invalid TTY mode (%#x)",
1212 __func__, adev->voice.tty_mode);
1213 }
1214 } else if (audio_extn_get_anc_enabled()) {
1215 if (audio_extn_should_use_fb_anc())
1216 snd_device = SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET;
1217 else
1218 snd_device = SND_DEVICE_OUT_VOICE_ANC_HEADSET;
1219 } else {
1220 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
1221 }
1222 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
1223 if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ)
1224 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
1225 else
1226 snd_device = SND_DEVICE_OUT_BT_SCO;
1227 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
1228 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
1229 } else if (devices & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
1230 devices & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
1231 snd_device = SND_DEVICE_OUT_USB_HEADSET;
1232 } else if (devices & AUDIO_DEVICE_OUT_FM_TX) {
1233 snd_device = SND_DEVICE_OUT_TRANSMISSION_FM;
1234 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
1235 if (audio_extn_should_use_handset_anc(channel_count))
1236 snd_device = SND_DEVICE_OUT_ANC_HANDSET;
1237 else
1238 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
1239 }
1240 if (snd_device != SND_DEVICE_NONE) {
1241 goto exit;
1242 }
1243 }
1244
Naresh Tannirue3b18452014-03-04 14:44:27 +05301245 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1246 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301247 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADSET
1248 && audio_extn_get_anc_enabled()) {
1249 if (audio_extn_should_use_fb_anc())
1250 snd_device = SND_DEVICE_OUT_ANC_FB_HEADSET;
1251 else
1252 snd_device = SND_DEVICE_OUT_ANC_HEADSET;
1253 }
1254 else
1255 snd_device = SND_DEVICE_OUT_HEADPHONES;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301256 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
1257 if (adev->speaker_lr_swap)
1258 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
1259 else
1260 snd_device = SND_DEVICE_OUT_SPEAKER;
1261 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301262 if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ)
1263 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
1264 else
1265 snd_device = SND_DEVICE_OUT_BT_SCO;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301266 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
1267 snd_device = SND_DEVICE_OUT_HDMI ;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301268 } else if (devices & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
1269 devices & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
Mingming Yin5a7c5d62014-03-05 17:45:03 -08001270 ALOGD("%s: setting USB hadset channel capability(2) for Proxy", __func__);
1271 audio_extn_set_afe_proxy_channel_mixer(adev, 2);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301272 snd_device = SND_DEVICE_OUT_USB_HEADSET;
1273 } else if (devices & AUDIO_DEVICE_OUT_FM_TX) {
1274 snd_device = SND_DEVICE_OUT_TRANSMISSION_FM;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301275 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
1276 snd_device = SND_DEVICE_OUT_HANDSET;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301277 } else if (devices & AUDIO_DEVICE_OUT_PROXY) {
Mingming Yin5a7c5d62014-03-05 17:45:03 -08001278 channel_count = audio_extn_get_afe_proxy_channel_count();
1279 ALOGD("%s: setting sink capability(%d) for Proxy", __func__, channel_count);
1280 audio_extn_set_afe_proxy_channel_mixer(adev, channel_count);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301281 snd_device = SND_DEVICE_OUT_AFE_PROXY;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301282 } else {
1283 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
1284 }
1285exit:
1286 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
1287 return snd_device;
1288}
1289
1290snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
1291{
1292 struct platform_data *my_data = (struct platform_data *)platform;
1293 struct audio_device *adev = my_data->adev;
1294 audio_source_t source = (adev->active_input == NULL) ?
1295 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
1296
1297 audio_mode_t mode = adev->mode;
1298 audio_devices_t in_device = ((adev->active_input == NULL) ?
1299 AUDIO_DEVICE_NONE : adev->active_input->device)
1300 & ~AUDIO_DEVICE_BIT_IN;
1301 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
1302 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
1303 snd_device_t snd_device = SND_DEVICE_NONE;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301304 int channel_count = popcount(channel_mask);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301305
1306 ALOGV("%s: enter: out_device(%#x) in_device(%#x)",
1307 __func__, out_device, in_device);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301308 if ((out_device != AUDIO_DEVICE_NONE) && ((mode == AUDIO_MODE_IN_CALL) ||
1309 voice_extn_compress_voip_is_active(adev))) {
1310 if ((adev->voice.tty_mode != TTY_MODE_OFF) &&
1311 !voice_extn_compress_voip_is_active(adev)) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301312 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1313 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301314 switch (adev->voice.tty_mode) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301315 case TTY_MODE_FULL:
1316 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
1317 break;
1318 case TTY_MODE_VCO:
1319 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
1320 break;
1321 case TTY_MODE_HCO:
1322 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
1323 break;
1324 default:
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301325 ALOGE("%s: Invalid TTY mode (%#x)",
1326 __func__, adev->voice.tty_mode);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301327 }
1328 goto exit;
1329 }
1330 }
1331 if (out_device & AUDIO_DEVICE_OUT_EARPIECE ||
1332 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301333 if (out_device & AUDIO_DEVICE_OUT_EARPIECE &&
1334 audio_extn_should_use_handset_anc(channel_count)) {
1335 snd_device = SND_DEVICE_IN_AANC_HANDSET_MIC;
1336 } else if (my_data->fluence_type == FLUENCE_NONE ||
1337 my_data->fluence_in_voice_call == false) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301338 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301339 set_echo_reference(adev->mixer, EC_REF_RX);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301340 } else {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301341 snd_device = SND_DEVICE_IN_VOICE_DMIC;
1342 adev->acdb_settings |= DMIC_FLAG;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301343 }
1344 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
1345 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
Satya Krishna Pindiproli624c7802014-04-11 11:33:27 +05301346 set_echo_reference(adev->mixer, EC_REF_RX);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301347 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301348 if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ)
1349 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
1350 else
1351 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301352 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301353 if (my_data->fluence_type != FLUENCE_NONE &&
1354 my_data->fluence_in_voice_call &&
1355 my_data->fluence_in_spkr_mode) {
1356 if(my_data->fluence_type & FLUENCE_QUAD_MIC) {
1357 adev->acdb_settings |= QMIC_FLAG;
1358 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_QMIC;
1359 } else {
1360 adev->acdb_settings |= DMIC_FLAG;
1361 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
1362 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05301363 } else {
1364 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
Satya Krishna Pindiproli624c7802014-04-11 11:33:27 +05301365 set_echo_reference(adev->mixer, EC_REF_RX);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301366 }
1367 }
1368 } else if (source == AUDIO_SOURCE_CAMCORDER) {
1369 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
1370 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
1371 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
1372 }
1373 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
1374 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301375 if (channel_count == 2) {
1376 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
1377 adev->acdb_settings |= DMIC_FLAG;
1378 } else if (adev->active_input->enable_ns)
1379 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
1380 else if (my_data->fluence_type != FLUENCE_NONE &&
1381 my_data->fluence_in_voice_rec) {
1382 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
1383 adev->acdb_settings |= DMIC_FLAG;
1384 } else {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301385 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
1386 }
1387 }
1388 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION) {
1389 if (out_device & AUDIO_DEVICE_OUT_SPEAKER)
1390 in_device = AUDIO_DEVICE_IN_BACK_MIC;
1391 if (adev->active_input) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301392 if (adev->active_input->enable_aec &&
1393 adev->active_input->enable_ns) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301394 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301395 if (my_data->fluence_type & FLUENCE_DUAL_MIC &&
1396 my_data->fluence_in_spkr_mode) {
1397 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
1398 adev->acdb_settings |= DMIC_FLAG;
1399 } else
1400 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301401 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301402 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1403 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
1404 adev->acdb_settings |= DMIC_FLAG;
1405 } else
1406 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301407 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301408 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301409 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301410 set_echo_reference(adev->mixer, EC_REF_RX);
1411 } else if (adev->active_input->enable_aec) {
1412 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
1413 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1414 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
1415 adev->acdb_settings |= DMIC_FLAG;
1416 } else
1417 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
1418 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
1419 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1420 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
1421 adev->acdb_settings |= DMIC_FLAG;
1422 } else
1423 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
1424 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
1425 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
1426 }
1427 set_echo_reference(adev->mixer, EC_REF_RX);
1428 } else if (adev->active_input->enable_ns) {
1429 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
1430 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1431 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
1432 adev->acdb_settings |= DMIC_FLAG;
1433 } else
1434 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
1435 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
1436 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1437 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
1438 adev->acdb_settings |= DMIC_FLAG;
1439 } else
1440 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
1441 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
1442 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
1443 }
1444 set_echo_reference(adev->mixer, "NONE");
Naresh Tannirue3b18452014-03-04 14:44:27 +05301445 } else
1446 set_echo_reference(adev->mixer, "NONE");
1447 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301448 } else if (source == AUDIO_SOURCE_MIC) {
1449 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC &&
1450 channel_count == 1 ) {
1451 if(my_data->fluence_type & FLUENCE_DUAL_MIC &&
1452 my_data->fluence_in_audio_rec)
1453 snd_device = SND_DEVICE_IN_HANDSET_DMIC;
1454 }
1455 } else if (source == AUDIO_SOURCE_FM_RX ||
1456 source == AUDIO_SOURCE_FM_RX_A2DP) {
1457 snd_device = SND_DEVICE_IN_CAPTURE_FM;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301458 } else if (source == AUDIO_SOURCE_DEFAULT) {
1459 goto exit;
1460 }
1461
1462
1463 if (snd_device != SND_DEVICE_NONE) {
1464 goto exit;
1465 }
1466
1467 if (in_device != AUDIO_DEVICE_NONE &&
1468 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
1469 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
1470 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301471 if (audio_extn_ssr_get_enabled() && channel_count == 6)
1472 snd_device = SND_DEVICE_IN_QUAD_MIC;
1473 else if (channel_count == 2)
1474 snd_device = SND_DEVICE_IN_HANDSET_STEREO_DMIC;
1475 else
1476 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301477 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
1478 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
1479 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
1480 snd_device = SND_DEVICE_IN_HEADSET_MIC;
1481 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301482 if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ)
1483 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
1484 else
1485 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301486 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
1487 snd_device = SND_DEVICE_IN_HDMI_MIC;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301488 } else if (in_device & AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET ||
1489 in_device & AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET) {
1490 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
1491 } else if (in_device & AUDIO_DEVICE_IN_FM_RX) {
1492 snd_device = SND_DEVICE_IN_CAPTURE_FM;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301493 } else {
1494 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
1495 ALOGW("%s: Using default handset-mic", __func__);
1496 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1497 }
1498 } else {
1499 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
1500 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1501 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
1502 snd_device = SND_DEVICE_IN_HEADSET_MIC;
1503 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301504 if (channel_count > 1)
1505 snd_device = SND_DEVICE_IN_SPEAKER_STEREO_DMIC;
1506 else
1507 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301508 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
1509 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1510 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301511 if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ)
1512 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
1513 else
1514 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301515 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
1516 snd_device = SND_DEVICE_IN_HDMI_MIC;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301517 } else if (out_device & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
1518 out_device & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
1519 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301520 } else {
1521 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
1522 ALOGW("%s: Using default handset-mic", __func__);
1523 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1524 }
1525 }
1526exit:
1527 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
1528 return snd_device;
1529}
1530
1531int platform_set_hdmi_channels(void *platform, int channel_count)
1532{
1533 struct platform_data *my_data = (struct platform_data *)platform;
1534 struct audio_device *adev = my_data->adev;
1535 struct mixer_ctl *ctl;
1536 const char *channel_cnt_str = NULL;
1537 const char *mixer_ctl_name = "HDMI_RX Channels";
1538 switch (channel_count) {
1539 case 8:
1540 channel_cnt_str = "Eight"; break;
1541 case 7:
1542 channel_cnt_str = "Seven"; break;
1543 case 6:
1544 channel_cnt_str = "Six"; break;
1545 case 5:
1546 channel_cnt_str = "Five"; break;
1547 case 4:
1548 channel_cnt_str = "Four"; break;
1549 case 3:
1550 channel_cnt_str = "Three"; break;
1551 default:
1552 channel_cnt_str = "Two"; break;
1553 }
1554 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1555 if (!ctl) {
1556 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1557 __func__, mixer_ctl_name);
1558 return -EINVAL;
1559 }
1560 ALOGV("HDMI channel count: %s", channel_cnt_str);
1561 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
1562 return 0;
1563}
1564
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301565int platform_edid_get_max_channels(void *platform)
Naresh Tannirue3b18452014-03-04 14:44:27 +05301566{
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301567 struct platform_data *my_data = (struct platform_data *)platform;
1568 struct audio_device *adev = my_data->adev;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301569 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
1570 char *sad = block;
1571 int num_audio_blocks;
1572 int channel_count;
1573 int max_channels = 0;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301574 int i, ret, count;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301575
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301576 struct mixer_ctl *ctl;
1577
1578 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
1579 if (!ctl) {
1580 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1581 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301582 return 0;
1583 }
1584
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301585 mixer_ctl_update(ctl);
1586
1587 count = mixer_ctl_get_num_values(ctl);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301588
1589 /* Read SAD blocks, clamping the maximum size for safety */
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301590 if (count > (int)sizeof(block))
1591 count = (int)sizeof(block);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301592
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301593 ret = mixer_ctl_get_array(ctl, block, count);
1594 if (ret != 0) {
1595 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
1596 return 0;
1597 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05301598
1599 /* Calculate the number of SAD blocks */
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301600 num_audio_blocks = count / SAD_BLOCK_SIZE;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301601
1602 for (i = 0; i < num_audio_blocks; i++) {
1603 /* Only consider LPCM blocks */
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301604 if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
1605 sad += 3;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301606 continue;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301607 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05301608
1609 channel_count = (sad[0] & 0x7) + 1;
1610 if (channel_count > max_channels)
1611 max_channels = channel_count;
1612
1613 /* Advance to next block */
1614 sad += 3;
1615 }
1616
1617 return max_channels;
1618}
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301619
1620static int platform_set_slowtalk(struct platform_data *my_data, bool state)
1621{
1622 int ret = 0;
1623 struct audio_device *adev = my_data->adev;
1624 struct mixer_ctl *ctl;
1625 const char *mixer_ctl_name = "Slowtalk Enable";
1626 uint32_t set_values[ ] = {0,
1627 ALL_SESSION_VSID};
1628
1629 set_values[0] = state;
1630 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1631 if (!ctl) {
1632 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1633 __func__, mixer_ctl_name);
1634 ret = -EINVAL;
1635 } else {
1636 ALOGV("Setting slowtalk state: %d", state);
1637 ret = mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1638 my_data->slowtalk = state;
1639 }
1640
1641 if (my_data->csd != NULL) {
1642 ret = my_data->csd->slow_talk(ALL_SESSION_VSID, state);
1643 if (ret < 0) {
1644 ALOGE("%s: csd_client_disable_device, failed, error %d",
1645 __func__, ret);
1646 }
1647 }
1648 return ret;
1649}
1650
1651int platform_set_parameters(void *platform, struct str_parms *parms)
1652{
1653 struct platform_data *my_data = (struct platform_data *)platform;
1654 char *str;
1655 char value[256] = {0};
1656 int val;
1657 int ret = 0, err;
1658
1659 ALOGV("%s: enter: %s", __func__, str_parms_to_str(parms));
1660
1661 err = str_parms_get_int(parms, AUDIO_PARAMETER_KEY_BTSCO, &val);
1662 if (err >= 0) {
1663 str_parms_del(parms, AUDIO_PARAMETER_KEY_BTSCO);
1664 my_data->btsco_sample_rate = val;
1665 if (val == SAMPLE_RATE_16KHZ) {
Haynes Mathew George1376ca62014-04-24 11:55:48 -07001666 audio_route_apply_and_update_path(my_data->adev->audio_route,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301667 "bt-sco-wb-samplerate");
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301668 }
1669 }
1670
1671 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_SLOWTALK, value, sizeof(value));
1672 if (err >= 0) {
1673 bool state = false;
1674 if (!strncmp("true", value, sizeof("true"))) {
1675 state = true;
1676 }
1677
1678 str_parms_del(parms, AUDIO_PARAMETER_KEY_SLOWTALK);
1679 ret = platform_set_slowtalk(my_data, state);
1680 if (ret)
1681 ALOGE("%s: Failed to set slow talk err: %d", __func__, ret);
1682 }
1683
1684 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_VOLUME_BOOST,
1685 value, sizeof(value));
1686 if (err >= 0) {
1687 str_parms_del(parms, AUDIO_PARAMETER_KEY_VOLUME_BOOST);
1688
1689 if (my_data->acdb_reload_vocvoltable == NULL) {
1690 ALOGE("%s: acdb_reload_vocvoltable is NULL", __func__);
1691 } else if (!strcmp(value, "on")) {
1692 if (!my_data->acdb_reload_vocvoltable(VOICE_FEATURE_SET_VOLUME_BOOST)) {
1693 my_data->voice_feature_set = 1;
1694 }
1695 } else {
1696 if (!my_data->acdb_reload_vocvoltable(VOICE_FEATURE_SET_DEFAULT)) {
1697 my_data->voice_feature_set = 0;
1698 }
1699 }
1700 }
1701
1702 ALOGV("%s: exit with code(%d)", __func__, ret);
1703 return ret;
1704}
1705
1706int platform_set_incall_recording_session_id(void *platform,
1707 uint32_t session_id, int rec_mode)
1708{
1709 int ret = 0;
1710 struct platform_data *my_data = (struct platform_data *)platform;
1711 struct audio_device *adev = my_data->adev;
1712 struct mixer_ctl *ctl;
1713 const char *mixer_ctl_name = "Voc VSID";
1714 int num_ctl_values;
1715 int i;
1716
1717 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1718 if (!ctl) {
1719 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1720 __func__, mixer_ctl_name);
1721 ret = -EINVAL;
1722 } else {
1723 num_ctl_values = mixer_ctl_get_num_values(ctl);
1724 for (i = 0; i < num_ctl_values; i++) {
1725 if (mixer_ctl_set_value(ctl, i, session_id)) {
1726 ALOGV("Error: invalid session_id: %x", session_id);
1727 ret = -EINVAL;
1728 break;
1729 }
1730 }
1731 }
1732
1733 if (my_data->csd != NULL) {
1734 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
1735 if (ret < 0) {
1736 ALOGE("%s: csd_client_start_record failed, error %d",
1737 __func__, ret);
1738 }
1739 }
1740
1741 return ret;
1742}
1743
1744int platform_stop_incall_recording_usecase(void *platform)
1745{
1746 int ret = 0;
1747 struct platform_data *my_data = (struct platform_data *)platform;
1748
1749 if (my_data->csd != NULL) {
1750 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
1751 if (ret < 0) {
1752 ALOGE("%s: csd_client_stop_record failed, error %d",
1753 __func__, ret);
1754 }
1755 }
1756
1757 return ret;
1758}
1759
1760int platform_start_incall_music_usecase(void *platform)
1761{
1762 int ret = 0;
1763 struct platform_data *my_data = (struct platform_data *)platform;
1764
1765 if (my_data->csd != NULL) {
1766 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
1767 if (ret < 0) {
1768 ALOGE("%s: csd_client_start_playback failed, error %d",
1769 __func__, ret);
1770 }
1771 }
1772
1773 return ret;
1774}
1775
1776int platform_stop_incall_music_usecase(void *platform)
1777{
1778 int ret = 0;
1779 struct platform_data *my_data = (struct platform_data *)platform;
1780
1781 if (my_data->csd != NULL) {
1782 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
1783 if (ret < 0) {
1784 ALOGE("%s: csd_client_stop_playback failed, error %d",
1785 __func__, ret);
1786 }
1787 }
1788
1789 return ret;
1790}
1791
1792void platform_get_parameters(void *platform,
1793 struct str_parms *query,
1794 struct str_parms *reply)
1795{
1796 struct platform_data *my_data = (struct platform_data *)platform;
1797 char *str = NULL;
1798 char value[256] = {0};
1799 int ret;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301800
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301801 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_SLOWTALK,
1802 value, sizeof(value));
1803 if (ret >= 0) {
1804 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_SLOWTALK,
1805 my_data->slowtalk?"true":"false");
1806 }
1807
1808 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_VOLUME_BOOST,
1809 value, sizeof(value));
1810 if (ret >= 0) {
1811 if (my_data->voice_feature_set == VOICE_FEATURE_SET_VOLUME_BOOST) {
1812 strlcpy(value, "on", sizeof(value));
1813 } else {
1814 strlcpy(value, "off", sizeof(value));
1815 }
1816
1817 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_VOLUME_BOOST, value);
1818 }
1819
1820 ALOGV("%s: exit: returns - %s", __func__, str_parms_to_str(reply));
1821}
1822
1823/* Delay in Us */
1824int64_t platform_render_latency(audio_usecase_t usecase)
1825{
1826 switch (usecase) {
1827 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
1828 return DEEP_BUFFER_PLATFORM_DELAY;
1829 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
1830 return LOW_LATENCY_PLATFORM_DELAY;
1831 default:
1832 return 0;
1833 }
1834}
1835
1836int platform_update_usecase_from_source(int source, int usecase)
1837{
1838 ALOGV("%s: input source :%d", __func__, source);
1839 if(source == AUDIO_SOURCE_FM_RX_A2DP)
1840 usecase = USECASE_AUDIO_RECORD_FM_VIRTUAL;
1841 return usecase;
1842}
1843
1844bool platform_listen_update_status(snd_device_t snd_device)
1845{
1846 if ((snd_device >= SND_DEVICE_IN_BEGIN) &&
1847 (snd_device < SND_DEVICE_IN_END) &&
1848 (snd_device != SND_DEVICE_IN_CAPTURE_FM) &&
1849 (snd_device != SND_DEVICE_IN_CAPTURE_VI_FEEDBACK))
1850 return true;
1851 else
1852 return false;
1853}
1854
1855/* Read offload buffer size from a property.
1856 * If value is not power of 2 round it to
1857 * power of 2.
1858 */
1859uint32_t platform_get_compress_offload_buffer_size(audio_offload_info_t* info)
1860{
1861 char value[PROPERTY_VALUE_MAX] = {0};
1862 uint32_t fragment_size = COMPRESS_OFFLOAD_FRAGMENT_SIZE;
1863 if((property_get("audio.offload.buffer.size.kb", value, "")) &&
1864 atoi(value)) {
1865 fragment_size = atoi(value) * 1024;
1866 }
1867
1868 if (info != NULL && info->has_video && info->is_streaming) {
1869 fragment_size = COMPRESS_OFFLOAD_FRAGMENT_SIZE_FOR_AV_STREAMING;
1870 ALOGV("%s: offload fragment size reduced for AV streaming to %d",
1871 __func__, out->compr_config.fragment_size);
1872 }
1873
1874 fragment_size = ALIGN( fragment_size, 1024);
1875
1876 if(fragment_size < MIN_COMPRESS_OFFLOAD_FRAGMENT_SIZE)
1877 fragment_size = MIN_COMPRESS_OFFLOAD_FRAGMENT_SIZE;
1878 else if(fragment_size > MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE)
1879 fragment_size = MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE;
1880 ALOGV("%s: fragment_size %d", __func__, fragment_size);
1881 return fragment_size;
1882}
1883
1884uint32_t platform_get_pcm_offload_buffer_size(audio_offload_info_t* info)
1885{
1886 uint32_t fragment_size = MIN_PCM_OFFLOAD_FRAGMENT_SIZE;
1887 uint32_t bits_per_sample = 16;
1888
1889 if (info->format == AUDIO_FORMAT_PCM_24_BIT_OFFLOAD) {
1890 bits_per_sample = 32;
1891 }
1892
1893 if (!info->has_video) {
1894 fragment_size = MAX_PCM_OFFLOAD_FRAGMENT_SIZE;
1895
1896 } else if (info->has_video && info->is_streaming) {
1897 fragment_size = (PCM_OFFLOAD_BUFFER_DURATION_FOR_AV_STREAMING
1898 * info->sample_rate
1899 * bits_per_sample
1900 * popcount(info->channel_mask))/1000;
1901
1902 } else if (info->has_video) {
1903 fragment_size = (PCM_OFFLOAD_BUFFER_DURATION_FOR_AV
1904 * info->sample_rate
1905 * bits_per_sample
1906 * popcount(info->channel_mask))/1000;
1907 }
1908
1909 fragment_size = ALIGN( fragment_size, 1024);
1910
1911 if(fragment_size < MIN_PCM_OFFLOAD_FRAGMENT_SIZE)
1912 fragment_size = MIN_PCM_OFFLOAD_FRAGMENT_SIZE;
1913 else if(fragment_size > MAX_PCM_OFFLOAD_FRAGMENT_SIZE)
1914 fragment_size = MAX_PCM_OFFLOAD_FRAGMENT_SIZE;
1915
1916 ALOGV("%s: fragment_size %d", __func__, fragment_size);
1917 return fragment_size;
1918}
1919