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