blob: c71706c850140dd8c60f8ff89096186d3117f064 [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
Naresh Tannirue3b18452014-03-04 14:44:27 +0530897int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
898{
899 struct platform_data *my_data = (struct platform_data *)platform;
900 int acdb_dev_id, acdb_dev_type;
901
902 acdb_dev_id = acdb_device_table[snd_device];
903 if (acdb_dev_id < 0) {
904 ALOGE("%s: Could not find acdb id for device(%d)",
905 __func__, snd_device);
906 return -EINVAL;
907 }
908 if (my_data->acdb_send_audio_cal) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530909 ("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530910 __func__, snd_device, acdb_dev_id);
911 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
912 snd_device < SND_DEVICE_OUT_END)
913 acdb_dev_type = ACDB_DEV_TYPE_OUT;
914 else
915 acdb_dev_type = ACDB_DEV_TYPE_IN;
916 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
917 }
918 return 0;
919}
920
921int platform_switch_voice_call_device_pre(void *platform)
922{
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530923 struct platform_data *my_data = (struct platform_data *)platform;
924 int ret = 0;
925
926 if (my_data->csd != NULL &&
927 my_data->adev->mode == AUDIO_MODE_IN_CALL) {
928 /* This must be called before disabling mixer controls on APQ side */
929 ret = my_data->csd->disable_device();
930 if (ret < 0) {
931 ALOGE("%s: csd_client_disable_device, failed, error %d",
932 __func__, ret);
933 }
934 }
935 return ret;
Naresh Tannirue3b18452014-03-04 14:44:27 +0530936}
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530937int platform_switch_voice_call_enable_device_config(void *platform,
938 snd_device_t out_snd_device,
939 snd_device_t in_snd_device)
940{
941 struct platform_data *my_data = (struct platform_data *)platform;
942 int acdb_rx_id, acdb_tx_id;
943 int ret = 0;
944
945 acdb_rx_id = acdb_device_table[out_snd_device];
946 acdb_tx_id = acdb_device_table[in_snd_device];
947
948 if (my_data->csd != NULL) {
949 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
950 ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
951 if (ret < 0) {
952 ALOGE("%s: csd_enable_device_config, failed, error %d",
953 __func__, ret);
954 }
955 } else {
956 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
957 acdb_rx_id, acdb_tx_id);
958 }
959 }
960 return ret;
961}
962
Naresh Tannirue3b18452014-03-04 14:44:27 +0530963
964int platform_switch_voice_call_device_post(void *platform,
965 snd_device_t out_snd_device,
966 snd_device_t in_snd_device)
967{
968 struct platform_data *my_data = (struct platform_data *)platform;
969 int acdb_rx_id, acdb_tx_id;
970
971 if (my_data->acdb_send_voice_cal == NULL) {
972 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
973 } else {
974 acdb_rx_id = acdb_device_table[out_snd_device];
975 acdb_tx_id = acdb_device_table[in_snd_device];
976
977 if (acdb_rx_id > 0 && acdb_tx_id > 0)
978 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
979 else
980 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
981 acdb_rx_id, acdb_tx_id);
982 }
983
984 return 0;
985}
986
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530987int platform_switch_voice_call_usecase_route_post(void *platform,
988 snd_device_t out_snd_device,
989 snd_device_t in_snd_device)
Naresh Tannirue3b18452014-03-04 14:44:27 +0530990{
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530991 struct platform_data *my_data = (struct platform_data *)platform;
992 int acdb_rx_id, acdb_tx_id;
993 int ret = 0;
994
995 acdb_rx_id = acdb_device_table[out_snd_device];
996 acdb_tx_id = acdb_device_table[in_snd_device];
997
998 if (my_data->csd != NULL) {
999 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
1000 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
1001 my_data->adev->acdb_settings);
1002 if (ret < 0) {
1003 ALOGE("%s: csd_enable_device, failed, error %d",
1004 __func__, ret);
1005 }
1006 } else {
1007 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1008 acdb_rx_id, acdb_tx_id);
1009 }
1010 }
1011 return ret;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301012}
1013
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301014int platform_start_voice_call(void *platform, uint32_t vsid)
1015{
1016 struct platform_data *my_data = (struct platform_data *)platform;
1017 int ret = 0;
1018
1019 if (my_data->csd != NULL) {
1020 ret = my_data->csd->start_voice(vsid);
1021 if (ret < 0) {
1022 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
1023 }
1024 }
1025 return ret;
1026}
1027
1028int platform_stop_voice_call(void *platform, uint32_t vsid)
1029{
1030 struct platform_data *my_data = (struct platform_data *)platform;
1031 int ret = 0;
1032
1033 if (my_data->csd != NULL) {
1034 ret = my_data->csd->stop_voice(vsid);
1035 if (ret < 0) {
1036 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
1037 }
1038 }
1039 return ret;
1040}
1041int platform_get_sample_rate(void *platform, uint32_t *rate)
Naresh Tannirue3b18452014-03-04 14:44:27 +05301042{
1043 return 0;
1044}
1045
1046int platform_set_voice_volume(void *platform, int volume)
1047{
1048 struct platform_data *my_data = (struct platform_data *)platform;
1049 struct audio_device *adev = my_data->adev;
1050 struct mixer_ctl *ctl;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301051 const char *mixer_ctl_name = "Voice Rx Gain";
1052 int vol_index = 0, ret = 0;
1053 uint32_t set_values[ ] = {0,
1054 ALL_SESSION_VSID,
1055 DEFAULT_VOLUME_RAMP_DURATION_MS};
Naresh Tannirue3b18452014-03-04 14:44:27 +05301056
1057 // Voice volume levels are mapped to adsp volume levels as follows.
1058 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
1059 // But this values don't changed in kernel. So, below change is need.
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301060 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, MAX_VOL_INDEX);
1061 set_values[0] = vol_index;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301062
1063 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1064 if (!ctl) {
1065 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1066 __func__, mixer_ctl_name);
1067 return -EINVAL;
1068 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301069 ALOGV("Setting voice volume index: %d", set_values[0]);
1070 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
Naresh Tannirue3b18452014-03-04 14:44:27 +05301071
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301072 if (my_data->csd != NULL) {
1073 ret = my_data->csd->volume(ALL_SESSION_VSID, volume);
1074 if (ret < 0) {
1075 ALOGE("%s: csd_volume error %d", __func__, ret);
1076 }
1077 }
1078 return ret;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301079}
1080
1081int platform_set_mic_mute(void *platform, bool state)
1082{
1083 struct platform_data *my_data = (struct platform_data *)platform;
1084 struct audio_device *adev = my_data->adev;
1085 struct mixer_ctl *ctl;
1086 const char *mixer_ctl_name = "Voice Tx Mute";
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301087 int ret = 0;
1088 uint32_t set_values[ ] = {0,
1089 ALL_SESSION_VSID,
1090 DEFAULT_VOLUME_RAMP_DURATION_MS};
Naresh Tannirue3b18452014-03-04 14:44:27 +05301091
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301092 set_values[0] = state;
1093 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1094 if (!ctl) {
1095 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1096 __func__, mixer_ctl_name);
1097 return -EINVAL;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301098 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301099 ALOGV("Setting voice mute state: %d", state);
1100 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
Naresh Tannirue3b18452014-03-04 14:44:27 +05301101
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301102 if (my_data->csd != NULL) {
1103 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state);
1104 if (ret < 0) {
1105 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
1106 }
1107 }
1108 return ret;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301109}
1110
Shiv Maliyappanahallic6fd8ee2014-03-07 15:31:55 -08001111int platform_set_device_mute(void *platform, bool state, char *dir)
1112{
1113 struct platform_data *my_data = (struct platform_data *)platform;
1114 struct audio_device *adev = my_data->adev;
1115 struct mixer_ctl *ctl;
1116 char *mixer_ctl_name = NULL;
1117 int ret = 0;
1118 uint32_t set_values[ ] = {0,
1119 ALL_SESSION_VSID,
1120 0};
1121 if(dir == NULL) {
1122 ALOGE("%s: Invalid direction:%s", __func__, dir);
1123 return -EINVAL;
1124 }
1125
1126 if (!strncmp("rx", dir, sizeof("rx"))) {
1127 mixer_ctl_name = "Voice Rx Device Mute";
1128 } else if (!strncmp("tx", dir, sizeof("tx"))) {
1129 mixer_ctl_name = "Voice Tx Device Mute";
1130 } else {
1131 return -EINVAL;
1132 }
1133
1134 set_values[0] = state;
1135 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1136 if (!ctl) {
1137 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1138 __func__, mixer_ctl_name);
1139 return -EINVAL;
1140 }
1141
1142 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
1143 __func__,state, mixer_ctl_name);
1144 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1145
1146 return ret;
1147}
1148
Naresh Tannirue3b18452014-03-04 14:44:27 +05301149snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
1150{
1151 struct platform_data *my_data = (struct platform_data *)platform;
1152 struct audio_device *adev = my_data->adev;
1153 audio_mode_t mode = adev->mode;
1154 snd_device_t snd_device = SND_DEVICE_NONE;
1155
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301156 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
1157 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
1158 int channel_count = popcount(channel_mask);
1159
Naresh Tannirue3b18452014-03-04 14:44:27 +05301160 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
1161 if (devices == AUDIO_DEVICE_NONE ||
1162 devices & AUDIO_DEVICE_BIT_IN) {
1163 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
1164 goto exit;
1165 }
1166
Naresh Tannirue3b18452014-03-04 14:44:27 +05301167 if (popcount(devices) == 2) {
1168 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
1169 AUDIO_DEVICE_OUT_SPEAKER)) {
1170 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
1171 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
1172 AUDIO_DEVICE_OUT_SPEAKER)) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301173 if (audio_extn_get_anc_enabled())
1174 snd_device = SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET;
1175 else
1176 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301177 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
1178 AUDIO_DEVICE_OUT_SPEAKER)) {
1179 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301180 } else if (devices == (AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET |
1181 AUDIO_DEVICE_OUT_SPEAKER)) {
1182 snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301183 } else {
1184 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
1185 goto exit;
1186 }
1187 if (snd_device != SND_DEVICE_NONE) {
1188 goto exit;
1189 }
1190 }
1191
1192 if (popcount(devices) != 1) {
1193 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
1194 goto exit;
1195 }
1196
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301197 if ((mode == AUDIO_MODE_IN_CALL) ||
1198 voice_extn_compress_voip_is_active(adev)) {
1199 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1200 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
1201 if ((adev->voice.tty_mode != TTY_MODE_OFF) &&
1202 !voice_extn_compress_voip_is_active(adev)) {
1203 switch (adev->voice.tty_mode) {
1204 case TTY_MODE_FULL:
1205 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
1206 break;
1207 case TTY_MODE_VCO:
1208 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
1209 break;
1210 case TTY_MODE_HCO:
1211 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
1212 break;
1213 default:
1214 ALOGE("%s: Invalid TTY mode (%#x)",
1215 __func__, adev->voice.tty_mode);
1216 }
1217 } else if (audio_extn_get_anc_enabled()) {
1218 if (audio_extn_should_use_fb_anc())
1219 snd_device = SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET;
1220 else
1221 snd_device = SND_DEVICE_OUT_VOICE_ANC_HEADSET;
1222 } else {
1223 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
1224 }
1225 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
1226 if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ)
1227 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
1228 else
1229 snd_device = SND_DEVICE_OUT_BT_SCO;
1230 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
1231 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
1232 } else if (devices & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
1233 devices & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
1234 snd_device = SND_DEVICE_OUT_USB_HEADSET;
1235 } else if (devices & AUDIO_DEVICE_OUT_FM_TX) {
1236 snd_device = SND_DEVICE_OUT_TRANSMISSION_FM;
1237 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
1238 if (audio_extn_should_use_handset_anc(channel_count))
1239 snd_device = SND_DEVICE_OUT_ANC_HANDSET;
1240 else
1241 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
1242 }
1243 if (snd_device != SND_DEVICE_NONE) {
1244 goto exit;
1245 }
1246 }
1247
Naresh Tannirue3b18452014-03-04 14:44:27 +05301248 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1249 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301250 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADSET
1251 && audio_extn_get_anc_enabled()) {
1252 if (audio_extn_should_use_fb_anc())
1253 snd_device = SND_DEVICE_OUT_ANC_FB_HEADSET;
1254 else
1255 snd_device = SND_DEVICE_OUT_ANC_HEADSET;
1256 }
1257 else
1258 snd_device = SND_DEVICE_OUT_HEADPHONES;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301259 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
1260 if (adev->speaker_lr_swap)
1261 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
1262 else
1263 snd_device = SND_DEVICE_OUT_SPEAKER;
1264 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301265 if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ)
1266 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
1267 else
1268 snd_device = SND_DEVICE_OUT_BT_SCO;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301269 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
1270 snd_device = SND_DEVICE_OUT_HDMI ;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301271 } else if (devices & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
1272 devices & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
Mingming Yin5a7c5d62014-03-05 17:45:03 -08001273 ALOGD("%s: setting USB hadset channel capability(2) for Proxy", __func__);
1274 audio_extn_set_afe_proxy_channel_mixer(adev, 2);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301275 snd_device = SND_DEVICE_OUT_USB_HEADSET;
1276 } else if (devices & AUDIO_DEVICE_OUT_FM_TX) {
1277 snd_device = SND_DEVICE_OUT_TRANSMISSION_FM;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301278 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
1279 snd_device = SND_DEVICE_OUT_HANDSET;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301280 } else if (devices & AUDIO_DEVICE_OUT_PROXY) {
Mingming Yin5a7c5d62014-03-05 17:45:03 -08001281 channel_count = audio_extn_get_afe_proxy_channel_count();
1282 ALOGD("%s: setting sink capability(%d) for Proxy", __func__, channel_count);
1283 audio_extn_set_afe_proxy_channel_mixer(adev, channel_count);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301284 snd_device = SND_DEVICE_OUT_AFE_PROXY;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301285 } else {
1286 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
1287 }
1288exit:
1289 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
1290 return snd_device;
1291}
1292
1293snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
1294{
1295 struct platform_data *my_data = (struct platform_data *)platform;
1296 struct audio_device *adev = my_data->adev;
1297 audio_source_t source = (adev->active_input == NULL) ?
1298 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
1299
1300 audio_mode_t mode = adev->mode;
1301 audio_devices_t in_device = ((adev->active_input == NULL) ?
1302 AUDIO_DEVICE_NONE : adev->active_input->device)
1303 & ~AUDIO_DEVICE_BIT_IN;
1304 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
1305 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
1306 snd_device_t snd_device = SND_DEVICE_NONE;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301307 int channel_count = popcount(channel_mask);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301308
1309 ALOGV("%s: enter: out_device(%#x) in_device(%#x)",
1310 __func__, out_device, in_device);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301311 if ((out_device != AUDIO_DEVICE_NONE) && ((mode == AUDIO_MODE_IN_CALL) ||
1312 voice_extn_compress_voip_is_active(adev))) {
1313 if ((adev->voice.tty_mode != TTY_MODE_OFF) &&
1314 !voice_extn_compress_voip_is_active(adev)) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301315 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1316 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301317 switch (adev->voice.tty_mode) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301318 case TTY_MODE_FULL:
1319 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
1320 break;
1321 case TTY_MODE_VCO:
1322 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
1323 break;
1324 case TTY_MODE_HCO:
1325 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
1326 break;
1327 default:
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301328 ALOGE("%s: Invalid TTY mode (%#x)",
1329 __func__, adev->voice.tty_mode);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301330 }
1331 goto exit;
1332 }
1333 }
1334 if (out_device & AUDIO_DEVICE_OUT_EARPIECE ||
1335 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301336 if (out_device & AUDIO_DEVICE_OUT_EARPIECE &&
1337 audio_extn_should_use_handset_anc(channel_count)) {
1338 snd_device = SND_DEVICE_IN_AANC_HANDSET_MIC;
1339 } else if (my_data->fluence_type == FLUENCE_NONE ||
1340 my_data->fluence_in_voice_call == false) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301341 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301342 set_echo_reference(adev->mixer, EC_REF_RX);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301343 } else {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301344 snd_device = SND_DEVICE_IN_VOICE_DMIC;
1345 adev->acdb_settings |= DMIC_FLAG;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301346 }
1347 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
1348 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
Satya Krishna Pindiproli624c7802014-04-11 11:33:27 +05301349 set_echo_reference(adev->mixer, EC_REF_RX);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301350 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301351 if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ)
1352 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
1353 else
1354 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301355 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301356 if (my_data->fluence_type != FLUENCE_NONE &&
1357 my_data->fluence_in_voice_call &&
1358 my_data->fluence_in_spkr_mode) {
1359 if(my_data->fluence_type & FLUENCE_QUAD_MIC) {
1360 adev->acdb_settings |= QMIC_FLAG;
1361 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_QMIC;
1362 } else {
1363 adev->acdb_settings |= DMIC_FLAG;
1364 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
1365 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05301366 } else {
1367 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
Satya Krishna Pindiproli624c7802014-04-11 11:33:27 +05301368 set_echo_reference(adev->mixer, EC_REF_RX);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301369 }
1370 }
1371 } else if (source == AUDIO_SOURCE_CAMCORDER) {
1372 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
1373 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
1374 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
1375 }
1376 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
1377 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301378 if (channel_count == 2) {
1379 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
1380 adev->acdb_settings |= DMIC_FLAG;
1381 } else if (adev->active_input->enable_ns)
1382 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
1383 else if (my_data->fluence_type != FLUENCE_NONE &&
1384 my_data->fluence_in_voice_rec) {
1385 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
1386 adev->acdb_settings |= DMIC_FLAG;
1387 } else {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301388 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
1389 }
1390 }
1391 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION) {
1392 if (out_device & AUDIO_DEVICE_OUT_SPEAKER)
1393 in_device = AUDIO_DEVICE_IN_BACK_MIC;
1394 if (adev->active_input) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301395 if (adev->active_input->enable_aec &&
1396 adev->active_input->enable_ns) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301397 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301398 if (my_data->fluence_type & FLUENCE_DUAL_MIC &&
1399 my_data->fluence_in_spkr_mode) {
1400 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
1401 adev->acdb_settings |= DMIC_FLAG;
1402 } else
1403 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301404 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301405 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1406 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
1407 adev->acdb_settings |= DMIC_FLAG;
1408 } else
1409 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301410 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301411 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301412 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301413 set_echo_reference(adev->mixer, EC_REF_RX);
1414 } else if (adev->active_input->enable_aec) {
1415 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
1416 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1417 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
1418 adev->acdb_settings |= DMIC_FLAG;
1419 } else
1420 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
1421 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
1422 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1423 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
1424 adev->acdb_settings |= DMIC_FLAG;
1425 } else
1426 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
1427 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
1428 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
1429 }
1430 set_echo_reference(adev->mixer, EC_REF_RX);
1431 } else if (adev->active_input->enable_ns) {
1432 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
1433 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1434 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
1435 adev->acdb_settings |= DMIC_FLAG;
1436 } else
1437 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
1438 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
1439 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1440 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
1441 adev->acdb_settings |= DMIC_FLAG;
1442 } else
1443 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
1444 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
1445 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
1446 }
1447 set_echo_reference(adev->mixer, "NONE");
Naresh Tannirue3b18452014-03-04 14:44:27 +05301448 } else
1449 set_echo_reference(adev->mixer, "NONE");
1450 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301451 } else if (source == AUDIO_SOURCE_MIC) {
1452 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC &&
1453 channel_count == 1 ) {
1454 if(my_data->fluence_type & FLUENCE_DUAL_MIC &&
1455 my_data->fluence_in_audio_rec)
1456 snd_device = SND_DEVICE_IN_HANDSET_DMIC;
1457 }
1458 } else if (source == AUDIO_SOURCE_FM_RX ||
1459 source == AUDIO_SOURCE_FM_RX_A2DP) {
1460 snd_device = SND_DEVICE_IN_CAPTURE_FM;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301461 } else if (source == AUDIO_SOURCE_DEFAULT) {
1462 goto exit;
1463 }
1464
1465
1466 if (snd_device != SND_DEVICE_NONE) {
1467 goto exit;
1468 }
1469
1470 if (in_device != AUDIO_DEVICE_NONE &&
1471 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
1472 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
1473 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301474 if (audio_extn_ssr_get_enabled() && channel_count == 6)
1475 snd_device = SND_DEVICE_IN_QUAD_MIC;
1476 else if (channel_count == 2)
1477 snd_device = SND_DEVICE_IN_HANDSET_STEREO_DMIC;
1478 else
1479 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301480 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
1481 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
1482 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
1483 snd_device = SND_DEVICE_IN_HEADSET_MIC;
1484 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301485 if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ)
1486 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
1487 else
1488 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301489 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
1490 snd_device = SND_DEVICE_IN_HDMI_MIC;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301491 } else if (in_device & AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET ||
1492 in_device & AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET) {
1493 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
1494 } else if (in_device & AUDIO_DEVICE_IN_FM_RX) {
1495 snd_device = SND_DEVICE_IN_CAPTURE_FM;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301496 } else {
1497 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
1498 ALOGW("%s: Using default handset-mic", __func__);
1499 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1500 }
1501 } else {
1502 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
1503 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1504 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
1505 snd_device = SND_DEVICE_IN_HEADSET_MIC;
1506 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301507 if (channel_count > 1)
1508 snd_device = SND_DEVICE_IN_SPEAKER_STEREO_DMIC;
1509 else
1510 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301511 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
1512 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1513 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301514 if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ)
1515 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
1516 else
1517 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301518 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
1519 snd_device = SND_DEVICE_IN_HDMI_MIC;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301520 } else if (out_device & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
1521 out_device & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
1522 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301523 } else {
1524 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
1525 ALOGW("%s: Using default handset-mic", __func__);
1526 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1527 }
1528 }
1529exit:
1530 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
1531 return snd_device;
1532}
1533
1534int platform_set_hdmi_channels(void *platform, int channel_count)
1535{
1536 struct platform_data *my_data = (struct platform_data *)platform;
1537 struct audio_device *adev = my_data->adev;
1538 struct mixer_ctl *ctl;
1539 const char *channel_cnt_str = NULL;
1540 const char *mixer_ctl_name = "HDMI_RX Channels";
1541 switch (channel_count) {
1542 case 8:
1543 channel_cnt_str = "Eight"; break;
1544 case 7:
1545 channel_cnt_str = "Seven"; break;
1546 case 6:
1547 channel_cnt_str = "Six"; break;
1548 case 5:
1549 channel_cnt_str = "Five"; break;
1550 case 4:
1551 channel_cnt_str = "Four"; break;
1552 case 3:
1553 channel_cnt_str = "Three"; break;
1554 default:
1555 channel_cnt_str = "Two"; break;
1556 }
1557 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1558 if (!ctl) {
1559 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1560 __func__, mixer_ctl_name);
1561 return -EINVAL;
1562 }
1563 ALOGV("HDMI channel count: %s", channel_cnt_str);
1564 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
1565 return 0;
1566}
1567
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301568int platform_edid_get_max_channels(void *platform)
Naresh Tannirue3b18452014-03-04 14:44:27 +05301569{
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301570 struct platform_data *my_data = (struct platform_data *)platform;
1571 struct audio_device *adev = my_data->adev;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301572 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
1573 char *sad = block;
1574 int num_audio_blocks;
1575 int channel_count;
1576 int max_channels = 0;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301577 int i, ret, count;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301578
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301579 struct mixer_ctl *ctl;
1580
1581 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
1582 if (!ctl) {
1583 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1584 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301585 return 0;
1586 }
1587
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301588 mixer_ctl_update(ctl);
1589
1590 count = mixer_ctl_get_num_values(ctl);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301591
1592 /* Read SAD blocks, clamping the maximum size for safety */
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301593 if (count > (int)sizeof(block))
1594 count = (int)sizeof(block);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301595
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301596 ret = mixer_ctl_get_array(ctl, block, count);
1597 if (ret != 0) {
1598 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
1599 return 0;
1600 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05301601
1602 /* Calculate the number of SAD blocks */
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301603 num_audio_blocks = count / SAD_BLOCK_SIZE;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301604
1605 for (i = 0; i < num_audio_blocks; i++) {
1606 /* Only consider LPCM blocks */
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301607 if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
1608 sad += 3;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301609 continue;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301610 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05301611
1612 channel_count = (sad[0] & 0x7) + 1;
1613 if (channel_count > max_channels)
1614 max_channels = channel_count;
1615
1616 /* Advance to next block */
1617 sad += 3;
1618 }
1619
1620 return max_channels;
1621}
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301622
1623static int platform_set_slowtalk(struct platform_data *my_data, bool state)
1624{
1625 int ret = 0;
1626 struct audio_device *adev = my_data->adev;
1627 struct mixer_ctl *ctl;
1628 const char *mixer_ctl_name = "Slowtalk Enable";
1629 uint32_t set_values[ ] = {0,
1630 ALL_SESSION_VSID};
1631
1632 set_values[0] = state;
1633 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1634 if (!ctl) {
1635 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1636 __func__, mixer_ctl_name);
1637 ret = -EINVAL;
1638 } else {
1639 ALOGV("Setting slowtalk state: %d", state);
1640 ret = mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1641 my_data->slowtalk = state;
1642 }
1643
1644 if (my_data->csd != NULL) {
1645 ret = my_data->csd->slow_talk(ALL_SESSION_VSID, state);
1646 if (ret < 0) {
1647 ALOGE("%s: csd_client_disable_device, failed, error %d",
1648 __func__, ret);
1649 }
1650 }
1651 return ret;
1652}
1653
1654int platform_set_parameters(void *platform, struct str_parms *parms)
1655{
1656 struct platform_data *my_data = (struct platform_data *)platform;
1657 char *str;
1658 char value[256] = {0};
1659 int val;
1660 int ret = 0, err;
1661
1662 ALOGV("%s: enter: %s", __func__, str_parms_to_str(parms));
1663
1664 err = str_parms_get_int(parms, AUDIO_PARAMETER_KEY_BTSCO, &val);
1665 if (err >= 0) {
1666 str_parms_del(parms, AUDIO_PARAMETER_KEY_BTSCO);
1667 my_data->btsco_sample_rate = val;
1668 if (val == SAMPLE_RATE_16KHZ) {
Haynes Mathew George1376ca62014-04-24 11:55:48 -07001669 audio_route_apply_and_update_path(my_data->adev->audio_route,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301670 "bt-sco-wb-samplerate");
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301671 }
1672 }
1673
1674 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_SLOWTALK, value, sizeof(value));
1675 if (err >= 0) {
1676 bool state = false;
1677 if (!strncmp("true", value, sizeof("true"))) {
1678 state = true;
1679 }
1680
1681 str_parms_del(parms, AUDIO_PARAMETER_KEY_SLOWTALK);
1682 ret = platform_set_slowtalk(my_data, state);
1683 if (ret)
1684 ALOGE("%s: Failed to set slow talk err: %d", __func__, ret);
1685 }
1686
1687 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_VOLUME_BOOST,
1688 value, sizeof(value));
1689 if (err >= 0) {
1690 str_parms_del(parms, AUDIO_PARAMETER_KEY_VOLUME_BOOST);
1691
1692 if (my_data->acdb_reload_vocvoltable == NULL) {
1693 ALOGE("%s: acdb_reload_vocvoltable is NULL", __func__);
1694 } else if (!strcmp(value, "on")) {
1695 if (!my_data->acdb_reload_vocvoltable(VOICE_FEATURE_SET_VOLUME_BOOST)) {
1696 my_data->voice_feature_set = 1;
1697 }
1698 } else {
1699 if (!my_data->acdb_reload_vocvoltable(VOICE_FEATURE_SET_DEFAULT)) {
1700 my_data->voice_feature_set = 0;
1701 }
1702 }
1703 }
1704
1705 ALOGV("%s: exit with code(%d)", __func__, ret);
1706 return ret;
1707}
1708
1709int platform_set_incall_recording_session_id(void *platform,
1710 uint32_t session_id, int rec_mode)
1711{
1712 int ret = 0;
1713 struct platform_data *my_data = (struct platform_data *)platform;
1714 struct audio_device *adev = my_data->adev;
1715 struct mixer_ctl *ctl;
1716 const char *mixer_ctl_name = "Voc VSID";
1717 int num_ctl_values;
1718 int i;
1719
1720 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1721 if (!ctl) {
1722 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1723 __func__, mixer_ctl_name);
1724 ret = -EINVAL;
1725 } else {
1726 num_ctl_values = mixer_ctl_get_num_values(ctl);
1727 for (i = 0; i < num_ctl_values; i++) {
1728 if (mixer_ctl_set_value(ctl, i, session_id)) {
1729 ALOGV("Error: invalid session_id: %x", session_id);
1730 ret = -EINVAL;
1731 break;
1732 }
1733 }
1734 }
1735
1736 if (my_data->csd != NULL) {
1737 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
1738 if (ret < 0) {
1739 ALOGE("%s: csd_client_start_record failed, error %d",
1740 __func__, ret);
1741 }
1742 }
1743
1744 return ret;
1745}
1746
1747int platform_stop_incall_recording_usecase(void *platform)
1748{
1749 int ret = 0;
1750 struct platform_data *my_data = (struct platform_data *)platform;
1751
1752 if (my_data->csd != NULL) {
1753 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
1754 if (ret < 0) {
1755 ALOGE("%s: csd_client_stop_record failed, error %d",
1756 __func__, ret);
1757 }
1758 }
1759
1760 return ret;
1761}
1762
1763int platform_start_incall_music_usecase(void *platform)
1764{
1765 int ret = 0;
1766 struct platform_data *my_data = (struct platform_data *)platform;
1767
1768 if (my_data->csd != NULL) {
1769 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
1770 if (ret < 0) {
1771 ALOGE("%s: csd_client_start_playback failed, error %d",
1772 __func__, ret);
1773 }
1774 }
1775
1776 return ret;
1777}
1778
1779int platform_stop_incall_music_usecase(void *platform)
1780{
1781 int ret = 0;
1782 struct platform_data *my_data = (struct platform_data *)platform;
1783
1784 if (my_data->csd != NULL) {
1785 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
1786 if (ret < 0) {
1787 ALOGE("%s: csd_client_stop_playback failed, error %d",
1788 __func__, ret);
1789 }
1790 }
1791
1792 return ret;
1793}
1794
1795void platform_get_parameters(void *platform,
1796 struct str_parms *query,
1797 struct str_parms *reply)
1798{
1799 struct platform_data *my_data = (struct platform_data *)platform;
1800 char *str = NULL;
1801 char value[256] = {0};
1802 int ret;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301803
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301804 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_SLOWTALK,
1805 value, sizeof(value));
1806 if (ret >= 0) {
1807 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_SLOWTALK,
1808 my_data->slowtalk?"true":"false");
1809 }
1810
1811 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_VOLUME_BOOST,
1812 value, sizeof(value));
1813 if (ret >= 0) {
1814 if (my_data->voice_feature_set == VOICE_FEATURE_SET_VOLUME_BOOST) {
1815 strlcpy(value, "on", sizeof(value));
1816 } else {
1817 strlcpy(value, "off", sizeof(value));
1818 }
1819
1820 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_VOLUME_BOOST, value);
1821 }
1822
1823 ALOGV("%s: exit: returns - %s", __func__, str_parms_to_str(reply));
1824}
1825
1826/* Delay in Us */
1827int64_t platform_render_latency(audio_usecase_t usecase)
1828{
1829 switch (usecase) {
1830 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
1831 return DEEP_BUFFER_PLATFORM_DELAY;
1832 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
1833 return LOW_LATENCY_PLATFORM_DELAY;
1834 default:
1835 return 0;
1836 }
1837}
1838
1839int platform_update_usecase_from_source(int source, int usecase)
1840{
1841 ALOGV("%s: input source :%d", __func__, source);
1842 if(source == AUDIO_SOURCE_FM_RX_A2DP)
1843 usecase = USECASE_AUDIO_RECORD_FM_VIRTUAL;
1844 return usecase;
1845}
1846
1847bool platform_listen_update_status(snd_device_t snd_device)
1848{
1849 if ((snd_device >= SND_DEVICE_IN_BEGIN) &&
1850 (snd_device < SND_DEVICE_IN_END) &&
1851 (snd_device != SND_DEVICE_IN_CAPTURE_FM) &&
1852 (snd_device != SND_DEVICE_IN_CAPTURE_VI_FEEDBACK))
1853 return true;
1854 else
1855 return false;
1856}
1857
1858/* Read offload buffer size from a property.
1859 * If value is not power of 2 round it to
1860 * power of 2.
1861 */
1862uint32_t platform_get_compress_offload_buffer_size(audio_offload_info_t* info)
1863{
1864 char value[PROPERTY_VALUE_MAX] = {0};
1865 uint32_t fragment_size = COMPRESS_OFFLOAD_FRAGMENT_SIZE;
1866 if((property_get("audio.offload.buffer.size.kb", value, "")) &&
1867 atoi(value)) {
1868 fragment_size = atoi(value) * 1024;
1869 }
1870
1871 if (info != NULL && info->has_video && info->is_streaming) {
1872 fragment_size = COMPRESS_OFFLOAD_FRAGMENT_SIZE_FOR_AV_STREAMING;
1873 ALOGV("%s: offload fragment size reduced for AV streaming to %d",
1874 __func__, out->compr_config.fragment_size);
1875 }
1876
1877 fragment_size = ALIGN( fragment_size, 1024);
1878
1879 if(fragment_size < MIN_COMPRESS_OFFLOAD_FRAGMENT_SIZE)
1880 fragment_size = MIN_COMPRESS_OFFLOAD_FRAGMENT_SIZE;
1881 else if(fragment_size > MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE)
1882 fragment_size = MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE;
1883 ALOGV("%s: fragment_size %d", __func__, fragment_size);
1884 return fragment_size;
1885}
1886
1887uint32_t platform_get_pcm_offload_buffer_size(audio_offload_info_t* info)
1888{
1889 uint32_t fragment_size = MIN_PCM_OFFLOAD_FRAGMENT_SIZE;
1890 uint32_t bits_per_sample = 16;
1891
1892 if (info->format == AUDIO_FORMAT_PCM_24_BIT_OFFLOAD) {
1893 bits_per_sample = 32;
1894 }
1895
1896 if (!info->has_video) {
1897 fragment_size = MAX_PCM_OFFLOAD_FRAGMENT_SIZE;
1898
1899 } else if (info->has_video && info->is_streaming) {
1900 fragment_size = (PCM_OFFLOAD_BUFFER_DURATION_FOR_AV_STREAMING
1901 * info->sample_rate
1902 * bits_per_sample
1903 * popcount(info->channel_mask))/1000;
1904
1905 } else if (info->has_video) {
1906 fragment_size = (PCM_OFFLOAD_BUFFER_DURATION_FOR_AV
1907 * info->sample_rate
1908 * bits_per_sample
1909 * popcount(info->channel_mask))/1000;
1910 }
1911
1912 fragment_size = ALIGN( fragment_size, 1024);
1913
1914 if(fragment_size < MIN_PCM_OFFLOAD_FRAGMENT_SIZE)
1915 fragment_size = MIN_PCM_OFFLOAD_FRAGMENT_SIZE;
1916 else if(fragment_size > MAX_PCM_OFFLOAD_FRAGMENT_SIZE)
1917 fragment_size = MAX_PCM_OFFLOAD_FRAGMENT_SIZE;
1918
1919 ALOGV("%s: fragment_size %d", __func__, fragment_size);
1920 return fragment_size;
1921}
1922