blob: 8cb2599f152428331e52f601f5abbef10c748ddb [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"
36#define MIXER_XML_PATH_AUXPCM "/system/etc/mixer_paths_auxpcm.xml"
37#define PLATFORM_INFO_XML_PATH "/system/etc/audio_platform_info.xml"
Naresh Tannirue3b18452014-03-04 14:44:27 +053038#define LIB_ACDB_LOADER "libacdbloader.so"
Naresh Tannirudb72d1e2014-03-05 17:33:47 +053039#define AUDIO_DATA_BLOCK_MIXER_CTL "HDMI EDID"
Naresh Tannirue3b18452014-03-04 14:44:27 +053040
Naresh Tannirudb72d1e2014-03-05 17:33:47 +053041#define MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE (256 * 1024)
42#define MIN_COMPRESS_OFFLOAD_FRAGMENT_SIZE (2 * 1024)
43#define COMPRESS_OFFLOAD_FRAGMENT_SIZE_FOR_AV_STREAMING (2 * 1024)
44#define COMPRESS_OFFLOAD_FRAGMENT_SIZE (32 * 1024)
45/* Used in calculating fragment size for pcm offload */
46#define PCM_OFFLOAD_BUFFER_DURATION_FOR_AV 2000 /* 2 secs */
47#define PCM_OFFLOAD_BUFFER_DURATION_FOR_AV_STREAMING 100 /* 100 millisecs */
Naresh Tannirue3b18452014-03-04 14:44:27 +053048
Naresh Tannirudb72d1e2014-03-05 17:33:47 +053049/* MAX PCM fragment size cannot be increased further due
50 * to flinger's cblk size of 1mb,and it has to be a multiple of
51 * 24 - lcm of channels supported by DSP
Naresh Tannirue3b18452014-03-04 14:44:27 +053052 */
Naresh Tannirudb72d1e2014-03-05 17:33:47 +053053#define MAX_PCM_OFFLOAD_FRAGMENT_SIZE (240 * 1024)
54#define MIN_PCM_OFFLOAD_FRAGMENT_SIZE (32 * 1024)
Naresh Tannirue3b18452014-03-04 14:44:27 +053055
Naresh Tannirudb72d1e2014-03-05 17:33:47 +053056#define ALIGN( num, to ) (((num) + (to-1)) & (~(to-1)))
Naresh Tannirue3b18452014-03-04 14:44:27 +053057/*
58 * This file will have a maximum of 38 bytes:
59 *
60 * 4 bytes: number of audio blocks
61 * 4 bytes: total length of Short Audio Descriptor (SAD) blocks
62 * Maximum 10 * 3 bytes: SAD blocks
63 */
64#define MAX_SAD_BLOCKS 10
65#define SAD_BLOCK_SIZE 3
66
67/* EDID format ID for LPCM audio */
68#define EDID_FORMAT_LPCM 1
69
Naresh Tannirudb72d1e2014-03-05 17:33:47 +053070/* Retry for delay in FW loading*/
71#define RETRY_NUMBER 20
72#define RETRY_US 500000
73#define MAX_SND_CARD 8
74
75#define SAMPLE_RATE_8KHZ 8000
76#define SAMPLE_RATE_16KHZ 16000
77
78#define AUDIO_PARAMETER_KEY_FLUENCE_TYPE "fluence"
79#define AUDIO_PARAMETER_KEY_BTSCO "bt_samplerate"
80#define AUDIO_PARAMETER_KEY_SLOWTALK "st_enable"
81#define AUDIO_PARAMETER_KEY_VOLUME_BOOST "volume_boost"
82
83enum {
84 VOICE_FEATURE_SET_DEFAULT,
85 VOICE_FEATURE_SET_VOLUME_BOOST
86};
87
Naresh Tannirue3b18452014-03-04 14:44:27 +053088struct audio_block_header
89{
90 int reserved;
91 int length;
92};
93
Naresh Tannirudb72d1e2014-03-05 17:33:47 +053094/* Audio calibration related functions */
Naresh Tannirue3b18452014-03-04 14:44:27 +053095typedef void (*acdb_deallocate_t)();
Naresh Tannirudb72d1e2014-03-05 17:33:47 +053096typedef int (*acdb_init_t)(char *);
Naresh Tannirue3b18452014-03-04 14:44:27 +053097typedef void (*acdb_send_audio_cal_t)(int, int);
98typedef void (*acdb_send_voice_cal_t)(int, int);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +053099typedef int (*acdb_reload_vocvoltable_t)(int);
Naresh Tannirue3b18452014-03-04 14:44:27 +0530100
Naresh Tannirue3b18452014-03-04 14:44:27 +0530101struct platform_data {
102 struct audio_device *adev;
103 bool fluence_in_spkr_mode;
104 bool fluence_in_voice_call;
105 bool fluence_in_voice_rec;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530106 bool fluence_in_audio_rec;
107 int fluence_type;
Venkata Narendra Kumar Gutta88fd0bc2014-03-27 19:47:56 +0530108 char fluence_cap[PROPERTY_VALUE_MAX];
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530109 int btsco_sample_rate;
110 bool slowtalk;
111 /* Audio calibration related functions */
112 void *acdb_handle;
113 int voice_feature_set;
114 acdb_init_t acdb_init;
115 acdb_deallocate_t acdb_deallocate;
116 acdb_send_audio_cal_t acdb_send_audio_cal;
117 acdb_send_voice_cal_t acdb_send_voice_cal;
118 acdb_reload_vocvoltable_t acdb_reload_vocvoltable;
Naresh Tannirue3b18452014-03-04 14:44:27 +0530119
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530120 void *hw_info;
121 struct csd_data *csd;
Naresh Tannirue3b18452014-03-04 14:44:27 +0530122};
123
124static const int pcm_device_table[AUDIO_USECASE_MAX][2] = {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530125 [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = {DEEP_BUFFER_PCM_DEVICE,
126 DEEP_BUFFER_PCM_DEVICE},
127 [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
128 LOWLATENCY_PCM_DEVICE},
129 [USECASE_AUDIO_PLAYBACK_MULTI_CH] = {MULTIMEDIA2_PCM_DEVICE,
130 MULTIMEDIA2_PCM_DEVICE},
131 [USECASE_AUDIO_PLAYBACK_OFFLOAD] =
132 {PLAYBACK_OFFLOAD_DEVICE, PLAYBACK_OFFLOAD_DEVICE},
133 [USECASE_AUDIO_RECORD] = {AUDIO_RECORD_PCM_DEVICE, AUDIO_RECORD_PCM_DEVICE},
134 [USECASE_AUDIO_RECORD_COMPRESS] = {COMPRESS_CAPTURE_DEVICE, COMPRESS_CAPTURE_DEVICE},
135 [USECASE_AUDIO_RECORD_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
136 LOWLATENCY_PCM_DEVICE},
137 [USECASE_AUDIO_RECORD_FM_VIRTUAL] = {MULTIMEDIA2_PCM_DEVICE,
138 MULTIMEDIA2_PCM_DEVICE},
139 [USECASE_AUDIO_PLAYBACK_FM] = {FM_PLAYBACK_PCM_DEVICE, FM_CAPTURE_PCM_DEVICE},
140 [USECASE_AUDIO_HFP_SCO] = {HFP_PCM_RX, HFP_SCO_RX},
141 [USECASE_AUDIO_HFP_SCO_WB] = {HFP_PCM_RX, HFP_SCO_RX},
142 [USECASE_VOICE_CALL] = {VOICE_CALL_PCM_DEVICE, VOICE_CALL_PCM_DEVICE},
143 [USECASE_VOICE2_CALL] = {VOICE2_CALL_PCM_DEVICE, VOICE2_CALL_PCM_DEVICE},
144 [USECASE_VOLTE_CALL] = {VOLTE_CALL_PCM_DEVICE, VOLTE_CALL_PCM_DEVICE},
145 [USECASE_QCHAT_CALL] = {QCHAT_CALL_PCM_DEVICE, QCHAT_CALL_PCM_DEVICE},
146 [USECASE_COMPRESS_VOIP_CALL] = {COMPRESS_VOIP_CALL_PCM_DEVICE, COMPRESS_VOIP_CALL_PCM_DEVICE},
147 [USECASE_INCALL_REC_UPLINK] = {AUDIO_RECORD_PCM_DEVICE,
148 AUDIO_RECORD_PCM_DEVICE},
149 [USECASE_INCALL_REC_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
150 AUDIO_RECORD_PCM_DEVICE},
151 [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
152 AUDIO_RECORD_PCM_DEVICE},
153 [USECASE_INCALL_REC_UPLINK_COMPRESS] = {COMPRESS_CAPTURE_DEVICE,
154 COMPRESS_CAPTURE_DEVICE},
155 [USECASE_INCALL_REC_DOWNLINK_COMPRESS] = {COMPRESS_CAPTURE_DEVICE,
156 COMPRESS_CAPTURE_DEVICE},
157 [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK_COMPRESS] = {COMPRESS_CAPTURE_DEVICE,
158 COMPRESS_CAPTURE_DEVICE},
159 [USECASE_INCALL_MUSIC_UPLINK] = {INCALL_MUSIC_UPLINK_PCM_DEVICE,
160 INCALL_MUSIC_UPLINK_PCM_DEVICE},
161 [USECASE_INCALL_MUSIC_UPLINK2] = {INCALL_MUSIC_UPLINK2_PCM_DEVICE,
162 INCALL_MUSIC_UPLINK2_PCM_DEVICE},
163 [USECASE_AUDIO_SPKR_CALIB_RX] = {SPKR_PROT_CALIB_RX_PCM_DEVICE, -1},
164 [USECASE_AUDIO_SPKR_CALIB_TX] = {-1, SPKR_PROT_CALIB_TX_PCM_DEVICE},
Naresh Tannirue3b18452014-03-04 14:44:27 +0530165};
166
167/* Array to store sound devices */
168static const char * const device_table[SND_DEVICE_MAX] = {
169 [SND_DEVICE_NONE] = "none",
170 /* Playback sound devices */
171 [SND_DEVICE_OUT_HANDSET] = "handset",
172 [SND_DEVICE_OUT_SPEAKER] = "speaker",
173 [SND_DEVICE_OUT_SPEAKER_REVERSE] = "speaker-reverse",
174 [SND_DEVICE_OUT_HEADPHONES] = "headphones",
175 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones",
176 [SND_DEVICE_OUT_VOICE_HANDSET] = "voice-handset",
177 [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker",
178 [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones",
179 [SND_DEVICE_OUT_HDMI] = "hdmi",
180 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi",
181 [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530182 [SND_DEVICE_OUT_BT_SCO_WB] = "bt-sco-headset-wb",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530183 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones",
184 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones",
185 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530186 [SND_DEVICE_OUT_AFE_PROXY] = "afe-proxy",
187 [SND_DEVICE_OUT_USB_HEADSET] = "usb-headphones",
188 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = "speaker-and-usb-headphones",
189 [SND_DEVICE_OUT_TRANSMISSION_FM] = "transmission-fm",
190 [SND_DEVICE_OUT_ANC_HEADSET] = "anc-headphones",
191 [SND_DEVICE_OUT_ANC_FB_HEADSET] = "anc-fb-headphones",
192 [SND_DEVICE_OUT_VOICE_ANC_HEADSET] = "voice-anc-headphones",
193 [SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET] = "voice-anc-fb-headphones",
194 [SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET] = "speaker-and-anc-headphones",
195 [SND_DEVICE_OUT_ANC_HANDSET] = "anc-handset",
196 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = "speaker-protected",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530197
198 /* Capture sound devices */
199 [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530200 [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530201 [SND_DEVICE_IN_HANDSET_MIC_NS] = "handset-mic",
202 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = "handset-mic",
203 [SND_DEVICE_IN_HANDSET_DMIC] = "dmic-endfire",
204 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = "dmic-endfire",
205 [SND_DEVICE_IN_HANDSET_DMIC_NS] = "dmic-endfire",
206 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = "dmic-endfire",
207 [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
208 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "speaker-mic",
209 [SND_DEVICE_IN_SPEAKER_MIC_NS] = "speaker-mic",
210 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = "speaker-mic",
211 [SND_DEVICE_IN_SPEAKER_DMIC] = "speaker-dmic-endfire",
212 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = "speaker-dmic-endfire",
213 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = "speaker-dmic-endfire",
214 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = "speaker-dmic-endfire",
215 [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
216 [SND_DEVICE_IN_HEADSET_MIC_FLUENCE] = "headset-mic",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530217 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
218 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
219 [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic",
220 [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530221 [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530222 [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530223 [SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef",
224 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = "voice-speaker-dmic-ef",
225 [SND_DEVICE_IN_VOICE_SPEAKER_QMIC] = "voice-speaker-qmic",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530226 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
227 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
228 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
229 [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530230 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = "voice-rec-mic",
231 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = "voice-rec-dmic-ef",
232 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence",
233 [SND_DEVICE_IN_USB_HEADSET_MIC] = "usb-headset-mic",
234 [SND_DEVICE_IN_CAPTURE_FM] = "capture-fm",
235 [SND_DEVICE_IN_AANC_HANDSET_MIC] = "aanc-handset-mic",
236 [SND_DEVICE_IN_QUAD_MIC] = "quad-mic",
237 [SND_DEVICE_IN_HANDSET_STEREO_DMIC] = "handset-stereo-dmic-ef",
238 [SND_DEVICE_IN_SPEAKER_STEREO_DMIC] = "speaker-stereo-dmic-ef",
239 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = "vi-feedback",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530240};
241
242/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530243static int acdb_device_table[SND_DEVICE_MAX] = {
Naresh Tannirue3b18452014-03-04 14:44:27 +0530244 [SND_DEVICE_NONE] = -1,
245 [SND_DEVICE_OUT_HANDSET] = 7,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530246 [SND_DEVICE_OUT_SPEAKER] = 14,
247 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 14,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530248 [SND_DEVICE_OUT_HEADPHONES] = 10,
249 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
250 [SND_DEVICE_OUT_VOICE_HANDSET] = 7,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530251 [SND_DEVICE_OUT_VOICE_SPEAKER] = 14,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530252 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
253 [SND_DEVICE_OUT_HDMI] = 18,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530254 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 14,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530255 [SND_DEVICE_OUT_BT_SCO] = 22,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530256 [SND_DEVICE_OUT_BT_SCO_WB] = 39,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530257 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
258 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
259 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530260 [SND_DEVICE_OUT_AFE_PROXY] = 0,
261 [SND_DEVICE_OUT_USB_HEADSET] = 45,
262 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = 14,
263 [SND_DEVICE_OUT_TRANSMISSION_FM] = 0,
264 [SND_DEVICE_OUT_ANC_HEADSET] = 26,
265 [SND_DEVICE_OUT_ANC_FB_HEADSET] = 27,
266 [SND_DEVICE_OUT_VOICE_ANC_HEADSET] = 26,
267 [SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET] = 27,
268 [SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET] = 26,
269 [SND_DEVICE_OUT_ANC_HANDSET] = 103,
270 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = 101,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530271
272 [SND_DEVICE_IN_HANDSET_MIC] = 4,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530273 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 106,
274 [SND_DEVICE_IN_HANDSET_MIC_NS] = 107,
275 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = 108,
276 [SND_DEVICE_IN_HANDSET_DMIC] = 41,
277 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = 109,
278 [SND_DEVICE_IN_HANDSET_DMIC_NS] = 110,
279 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = 111,
280 [SND_DEVICE_IN_SPEAKER_MIC] = 11,
281 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 112,
282 [SND_DEVICE_IN_SPEAKER_MIC_NS] = 113,
283 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = 114,
284 [SND_DEVICE_IN_SPEAKER_DMIC] = 43,
285 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = 115,
286 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = 116,
287 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = 117,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530288 [SND_DEVICE_IN_HEADSET_MIC] = 8,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530289 [SND_DEVICE_IN_HEADSET_MIC_FLUENCE] = 47,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530290 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
291 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = 8,
292 [SND_DEVICE_IN_HDMI_MIC] = 4,
293 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530294 [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38,
295 [SND_DEVICE_IN_CAMCORDER_MIC] = 4,
296 [SND_DEVICE_IN_VOICE_DMIC] = 41,
297 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 43,
298 [SND_DEVICE_IN_VOICE_SPEAKER_QMIC] = 19,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530299 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
300 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
301 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530302 [SND_DEVICE_IN_VOICE_REC_MIC] = 4,
303 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = 107,
304 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = 34,
305 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 41,
306 [SND_DEVICE_IN_USB_HEADSET_MIC] = 44,
307 [SND_DEVICE_IN_CAPTURE_FM] = 0,
308 [SND_DEVICE_IN_AANC_HANDSET_MIC] = 104,
309 [SND_DEVICE_IN_QUAD_MIC] = 46,
310 [SND_DEVICE_IN_HANDSET_STEREO_DMIC] = 34,
311 [SND_DEVICE_IN_SPEAKER_STEREO_DMIC] = 35,
312 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = 102,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530313};
314
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530315struct snd_device_index {
316 char name[100];
317 unsigned int index;
318};
Naresh Tannirue3b18452014-03-04 14:44:27 +0530319
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530320#define TO_NAME_INDEX(X) #X, X
Naresh Tannirue3b18452014-03-04 14:44:27 +0530321
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530322/* Used to get index from parsed sting */
323struct snd_device_index snd_device_name_index[SND_DEVICE_MAX] = {
324 {TO_NAME_INDEX(SND_DEVICE_OUT_HANDSET)},
325 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER)},
326 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_REVERSE)},
327 {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES)},
328 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES)},
329 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET)},
330 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER)},
331 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADPHONES)},
332 {TO_NAME_INDEX(SND_DEVICE_OUT_HDMI)},
333 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HDMI)},
334 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO)},
335 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO_WB)},
336 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES)},
337 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES)},
338 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET)},
339 {TO_NAME_INDEX(SND_DEVICE_OUT_AFE_PROXY)},
340 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADSET)},
341 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET)},
342 {TO_NAME_INDEX(SND_DEVICE_OUT_TRANSMISSION_FM)},
343 {TO_NAME_INDEX(SND_DEVICE_OUT_ANC_HEADSET)},
344 {TO_NAME_INDEX(SND_DEVICE_OUT_ANC_FB_HEADSET)},
345 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_ANC_HEADSET)},
346 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET)},
347 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET)},
348 {TO_NAME_INDEX(SND_DEVICE_OUT_ANC_HANDSET)},
349 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED)},
350 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC)},
351 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC)},
352 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_NS)},
353 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)},
354 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC)},
355 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC)},
356 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_NS)},
357 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)},
358 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC)},
359 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC)},
360 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_NS)},
361 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)},
362 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC)},
363 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC)},
364 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS)},
365 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)},
366 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC)},
367 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC_FLUENCE)},
368 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC)},
369 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEADSET_MIC)},
370 {TO_NAME_INDEX(SND_DEVICE_IN_HDMI_MIC)},
371 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC)},
372 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB)},
373 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_MIC)},
374 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC)},
375 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC)},
376 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_QMIC)},
377 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC)},
378 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC)},
379 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC)},
380 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC)},
381 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_NS)},
382 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_STEREO)},
383 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE)},
384 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC)},
385 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_FM)},
386 {TO_NAME_INDEX(SND_DEVICE_IN_AANC_HANDSET_MIC)},
387 {TO_NAME_INDEX(SND_DEVICE_IN_QUAD_MIC)},
388 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_STEREO_DMIC)},
389 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_STEREO_DMIC)},
390 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_VI_FEEDBACK)},
391};
392
393#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
394#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
Naresh Tannirue3b18452014-03-04 14:44:27 +0530395
396static int set_echo_reference(struct mixer *mixer, const char* ec_ref)
397{
398 struct mixer_ctl *ctl;
399 const char *mixer_ctl_name = "EC_REF_RX";
400
401 ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name);
402 if (!ctl) {
403 ALOGE("%s: Could not get ctl for mixer cmd - %s",
404 __func__, mixer_ctl_name);
405 return -EINVAL;
406 }
407 ALOGV("Setting EC Reference: %s", ec_ref);
408 mixer_ctl_set_enum_by_string(ctl, ec_ref);
409 return 0;
410}
411
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530412static struct csd_data *open_csd_client()
413{
414 struct csd_data *csd = calloc(1, sizeof(struct csd_data));
415
416 csd->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
417 if (csd->csd_client == NULL) {
418 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
419 goto error;
420 } else {
421 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
422
423 csd->deinit = (deinit_t)dlsym(csd->csd_client,
424 "csd_client_deinit");
425 if (csd->deinit == NULL) {
426 ALOGE("%s: dlsym error %s for csd_client_deinit", __func__,
427 dlerror());
428 goto error;
429 }
430 csd->disable_device = (disable_device_t)dlsym(csd->csd_client,
431 "csd_client_disable_device");
432 if (csd->disable_device == NULL) {
433 ALOGE("%s: dlsym error %s for csd_client_disable_device",
434 __func__, dlerror());
435 goto error;
436 }
437 csd->enable_device_config = (enable_device_config_t)dlsym(csd->csd_client,
438 "csd_client_enable_device_config");
439 if (csd->enable_device_config == NULL) {
440 ALOGE("%s: dlsym error %s for csd_client_enable_device_config",
441 __func__, dlerror());
442 goto error;
443 }
444 csd->enable_device = (enable_device_t)dlsym(csd->csd_client,
445 "csd_client_enable_device");
446 if (csd->enable_device == NULL) {
447 ALOGE("%s: dlsym error %s for csd_client_enable_device",
448 __func__, dlerror());
449 goto error;
450 }
451 csd->start_voice = (start_voice_t)dlsym(csd->csd_client,
452 "csd_client_start_voice");
453 if (csd->start_voice == NULL) {
454 ALOGE("%s: dlsym error %s for csd_client_start_voice",
455 __func__, dlerror());
456 goto error;
457 }
458 csd->stop_voice = (stop_voice_t)dlsym(csd->csd_client,
459 "csd_client_stop_voice");
460 if (csd->stop_voice == NULL) {
461 ALOGE("%s: dlsym error %s for csd_client_stop_voice",
462 __func__, dlerror());
463 goto error;
464 }
465 csd->volume = (volume_t)dlsym(csd->csd_client,
466 "csd_client_volume");
467 if (csd->volume == NULL) {
468 ALOGE("%s: dlsym error %s for csd_client_volume",
469 __func__, dlerror());
470 goto error;
471 }
472 csd->mic_mute = (mic_mute_t)dlsym(csd->csd_client,
473 "csd_client_mic_mute");
474 if (csd->mic_mute == NULL) {
475 ALOGE("%s: dlsym error %s for csd_client_mic_mute",
476 __func__, dlerror());
477 goto error;
478 }
479 csd->slow_talk = (slow_talk_t)dlsym(csd->csd_client,
480 "csd_client_slow_talk");
481 if (csd->slow_talk == NULL) {
482 ALOGE("%s: dlsym error %s for csd_client_slow_talk",
483 __func__, dlerror());
484 goto error;
485 }
486 csd->start_playback = (start_playback_t)dlsym(csd->csd_client,
487 "csd_client_start_playback");
488 if (csd->start_playback == NULL) {
489 ALOGE("%s: dlsym error %s for csd_client_start_playback",
490 __func__, dlerror());
491 goto error;
492 }
493 csd->stop_playback = (stop_playback_t)dlsym(csd->csd_client,
494 "csd_client_stop_playback");
495 if (csd->stop_playback == NULL) {
496 ALOGE("%s: dlsym error %s for csd_client_stop_playback",
497 __func__, dlerror());
498 goto error;
499 }
500 csd->start_record = (start_record_t)dlsym(csd->csd_client,
501 "csd_client_start_record");
502 if (csd->start_record == NULL) {
503 ALOGE("%s: dlsym error %s for csd_client_start_record",
504 __func__, dlerror());
505 goto error;
506 }
507 csd->stop_record = (stop_record_t)dlsym(csd->csd_client,
508 "csd_client_stop_record");
509 if (csd->stop_record == NULL) {
510 ALOGE("%s: dlsym error %s for csd_client_stop_record",
511 __func__, dlerror());
512 goto error;
513 }
514 csd->init = (init_t)dlsym(csd->csd_client, "csd_client_init");
515
516 if (csd->init == NULL) {
517 ALOGE("%s: dlsym error %s for csd_client_init",
518 __func__, dlerror());
519 goto error;
520 } else {
521 csd->init();
522 }
523 }
524 return csd;
525
526error:
527 free(csd);
528 csd = NULL;
529 return csd;
530}
531
532void close_csd_client(struct csd_data *csd)
533{
534 if (csd != NULL) {
535 csd->deinit();
536 dlclose(csd->csd_client);
537 free(csd);
538 csd = NULL;
539 }
540}
541
Naresh Tannirue3b18452014-03-04 14:44:27 +0530542void *platform_init(struct audio_device *adev)
543{
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530544 char platform[PROPERTY_VALUE_MAX];
545 char baseband[PROPERTY_VALUE_MAX];
Naresh Tannirue3b18452014-03-04 14:44:27 +0530546 char value[PROPERTY_VALUE_MAX];
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530547 struct platform_data *my_data = NULL;
548 int retry_num = 0, snd_card_num = 0;
549 const char *snd_card_name;
Naresh Tannirue3b18452014-03-04 14:44:27 +0530550
551 my_data = calloc(1, sizeof(struct platform_data));
552
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530553 while (snd_card_num < MAX_SND_CARD) {
554 adev->mixer = mixer_open(snd_card_num);
555
556 while (!adev->mixer && retry_num < RETRY_NUMBER) {
557 usleep(RETRY_US);
558 adev->mixer = mixer_open(snd_card_num);
559 retry_num++;
560 }
561
562 if (!adev->mixer) {
563 ALOGE("%s: Unable to open the mixer card: %d", __func__,
564 snd_card_num);
565 retry_num = 0;
566 snd_card_num++;
567 continue;
568 }
569
570 snd_card_name = mixer_get_name(adev->mixer);
571 ALOGV("%s: snd_card_name: %s", __func__, snd_card_name);
572
573 my_data->hw_info = hw_info_init(snd_card_name);
574 if (!my_data->hw_info) {
575 ALOGE("%s: Failed to init hardware info", __func__);
576 } else {
577 if (audio_extn_read_xml(adev, snd_card_num, MIXER_XML_PATH,
578 MIXER_XML_PATH_AUXPCM) == -ENOSYS)
579 adev->audio_route = audio_route_init(snd_card_num,
580 MIXER_XML_PATH);
581 if (!adev->audio_route) {
582 ALOGE("%s: Failed to init audio route controls, aborting.",
583 __func__);
584 free(my_data);
585 return NULL;
586 }
587 adev->snd_card = snd_card_num;
588 ALOGD("%s: Opened sound card:%d", __func__, snd_card_num);
589 break;
590 }
591 retry_num = 0;
592 snd_card_num++;
593 }
594
595 if (snd_card_num >= MAX_SND_CARD) {
596 ALOGE("%s: Unable to find correct sound card, aborting.", __func__);
597 free(my_data);
598 return NULL;
599 }
600
Naresh Tannirue3b18452014-03-04 14:44:27 +0530601 my_data->adev = adev;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530602 my_data->btsco_sample_rate = SAMPLE_RATE_8KHZ;
Naresh Tannirue3b18452014-03-04 14:44:27 +0530603 my_data->fluence_in_spkr_mode = false;
604 my_data->fluence_in_voice_call = false;
605 my_data->fluence_in_voice_rec = false;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530606 my_data->fluence_in_audio_rec = false;
607 my_data->fluence_type = FLUENCE_NONE;
Naresh Tannirue3b18452014-03-04 14:44:27 +0530608
Venkata Narendra Kumar Gutta88fd0bc2014-03-27 19:47:56 +0530609 property_get("ro.qc.sdk.audio.fluencetype", my_data->fluence_cap, "");
610 if (!strncmp("fluencepro", my_data->fluence_cap, sizeof("fluencepro"))) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530611 my_data->fluence_type = FLUENCE_QUAD_MIC | FLUENCE_DUAL_MIC;
Venkata Narendra Kumar Gutta88fd0bc2014-03-27 19:47:56 +0530612 } else if (!strncmp("fluence", my_data->fluence_cap, sizeof("fluence"))) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530613 my_data->fluence_type = FLUENCE_DUAL_MIC;
614 } else {
615 my_data->fluence_type = FLUENCE_NONE;
Naresh Tannirue3b18452014-03-04 14:44:27 +0530616 }
617
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530618 if (my_data->fluence_type != FLUENCE_NONE) {
Naresh Tannirue3b18452014-03-04 14:44:27 +0530619 property_get("persist.audio.fluence.voicecall",value,"");
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530620 if (!strncmp("true", value, sizeof("true"))) {
Naresh Tannirue3b18452014-03-04 14:44:27 +0530621 my_data->fluence_in_voice_call = true;
622 }
623
624 property_get("persist.audio.fluence.voicerec",value,"");
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530625 if (!strncmp("true", value, sizeof("true"))) {
Naresh Tannirue3b18452014-03-04 14:44:27 +0530626 my_data->fluence_in_voice_rec = true;
627 }
628
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530629 property_get("persist.audio.fluence.audiorec",value,"");
630 if (!strncmp("true", value, sizeof("true"))) {
631 my_data->fluence_in_audio_rec = true;
632 }
633
Naresh Tannirue3b18452014-03-04 14:44:27 +0530634 property_get("persist.audio.fluence.speaker",value,"");
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530635 if (!strncmp("true", value, sizeof("true"))) {
Naresh Tannirue3b18452014-03-04 14:44:27 +0530636 my_data->fluence_in_spkr_mode = true;
637 }
638 }
639
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530640 my_data->voice_feature_set = VOICE_FEATURE_SET_DEFAULT;
Naresh Tannirue3b18452014-03-04 14:44:27 +0530641 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
642 if (my_data->acdb_handle == NULL) {
643 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
644 } else {
645 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
646 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
647 "acdb_loader_deallocate_ACDB");
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530648 if (!my_data->acdb_deallocate)
649 ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s",
650 __func__, LIB_ACDB_LOADER);
651
Naresh Tannirue3b18452014-03-04 14:44:27 +0530652 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
653 "acdb_loader_send_audio_cal");
654 if (!my_data->acdb_send_audio_cal)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530655 ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530656 __func__, LIB_ACDB_LOADER);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530657
Naresh Tannirue3b18452014-03-04 14:44:27 +0530658 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
659 "acdb_loader_send_voice_cal");
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530660 if (!my_data->acdb_send_voice_cal)
661 ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s",
662 __func__, LIB_ACDB_LOADER);
663
664 my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle,
665 "acdb_loader_reload_vocvoltable");
666 if (!my_data->acdb_reload_vocvoltable)
667 ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s",
668 __func__, LIB_ACDB_LOADER);
669
Naresh Tannirue3b18452014-03-04 14:44:27 +0530670 my_data->acdb_init = (acdb_init_t)dlsym(my_data->acdb_handle,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530671 "acdb_loader_init_v2");
Naresh Tannirue3b18452014-03-04 14:44:27 +0530672 if (my_data->acdb_init == NULL)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530673 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__, dlerror());
Naresh Tannirue3b18452014-03-04 14:44:27 +0530674 else
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530675 my_data->acdb_init(snd_card_name);
Naresh Tannirue3b18452014-03-04 14:44:27 +0530676 }
677
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530678 /* Initialize ACDB ID's */
679 platform_info_init(PLATFORM_INFO_XML_PATH);
680
681 /* init usb */
682 audio_extn_usb_init(adev);
683 /* update sound cards appropriately */
684 audio_extn_usb_set_proxy_sound_card(adev->snd_card);
685
686 /* Read one time ssr property */
687 audio_extn_ssr_update_enabled();
688 audio_extn_spkr_prot_init(adev);
Naresh Tannirue3b18452014-03-04 14:44:27 +0530689 return my_data;
690}
691
692void platform_deinit(void *platform)
693{
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530694 struct platform_data *my_data = (struct platform_data *)platform;
695
696 hw_info_deinit(my_data->hw_info);
697 close_csd_client(my_data->csd);
698
Naresh Tannirue3b18452014-03-04 14:44:27 +0530699 free(platform);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530700 /* deinit usb */
701 audio_extn_usb_deinit();
Naresh Tannirue3b18452014-03-04 14:44:27 +0530702}
703
704const char *platform_get_snd_device_name(snd_device_t snd_device)
705{
706 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX)
707 return device_table[snd_device];
708 else
709 return "";
710}
711
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530712int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
713 char *device_name)
714{
715 struct platform_data *my_data = (struct platform_data *)platform;
716
717 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
718 strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE);
719 hw_info_append_hw_type(my_data->hw_info, snd_device, device_name);
720 } else {
721 strlcpy(device_name, "", DEVICE_NAME_MAX_SIZE);
722 return -EINVAL;
723 }
724
725 return 0;
726}
727
Naresh Tannirue3b18452014-03-04 14:44:27 +0530728void platform_add_backend_name(char *mixer_path, snd_device_t snd_device)
729{
730 if (snd_device == SND_DEVICE_IN_BT_SCO_MIC)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530731 strlcat(mixer_path, " bt-sco", MIXER_PATH_MAX_LENGTH);
732 else if (snd_device == SND_DEVICE_IN_BT_SCO_MIC_WB)
733 strlcat(mixer_path, " bt-sco-wb", MIXER_PATH_MAX_LENGTH);
Naresh Tannirue3b18452014-03-04 14:44:27 +0530734 else if(snd_device == SND_DEVICE_OUT_BT_SCO)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530735 strlcat(mixer_path, " bt-sco", MIXER_PATH_MAX_LENGTH);
736 else if(snd_device == SND_DEVICE_OUT_BT_SCO_WB)
737 strlcat(mixer_path, " bt-sco-wb", MIXER_PATH_MAX_LENGTH);
Naresh Tannirue3b18452014-03-04 14:44:27 +0530738 else if (snd_device == SND_DEVICE_OUT_HDMI)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530739 strlcat(mixer_path, " hdmi", MIXER_PATH_MAX_LENGTH);
Naresh Tannirue3b18452014-03-04 14:44:27 +0530740 else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HDMI)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530741 strlcat(mixer_path, " speaker-and-hdmi", MIXER_PATH_MAX_LENGTH);
742 else if (snd_device == SND_DEVICE_OUT_AFE_PROXY)
743 strlcat(mixer_path, " afe-proxy", MIXER_PATH_MAX_LENGTH);
744 else if (snd_device == SND_DEVICE_OUT_USB_HEADSET)
745 strlcat(mixer_path, " usb-headphones", MIXER_PATH_MAX_LENGTH);
746 else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET)
747 strlcat(mixer_path, " speaker-and-usb-headphones",
748 MIXER_PATH_MAX_LENGTH);
749 else if (snd_device == SND_DEVICE_IN_USB_HEADSET_MIC)
750 strlcat(mixer_path, " usb-headset-mic", MIXER_PATH_MAX_LENGTH);
751 else if (snd_device == SND_DEVICE_IN_CAPTURE_FM)
752 strlcat(mixer_path, " capture-fm", MIXER_PATH_MAX_LENGTH);
753 else if (snd_device == SND_DEVICE_OUT_TRANSMISSION_FM)
754 strlcat(mixer_path, " transmission-fm", MIXER_PATH_MAX_LENGTH);
Naresh Tannirue3b18452014-03-04 14:44:27 +0530755}
756
757int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
758{
759 int device_id;
760 if (device_type == PCM_PLAYBACK)
761 device_id = pcm_device_table[usecase][0];
762 else
763 device_id = pcm_device_table[usecase][1];
764 return device_id;
765}
766
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530767int platform_get_snd_device_index(char *snd_device_index_name)
768{
769 int ret = 0;
770 int i;
771
772 if (snd_device_index_name == NULL) {
773 ALOGE("%s: snd_device_index_name is NULL", __func__);
774 ret = -ENODEV;
775 goto done;
776 }
777
778 for (i=0; i < SND_DEVICE_MAX; i++) {
779 if(strcmp(snd_device_name_index[i].name, snd_device_index_name) == 0) {
780 ret = snd_device_name_index[i].index;
781 goto done;
782 }
783 }
784 ALOGE("%s: Could not find index for snd_device_index_name = %s",
785 __func__, snd_device_index_name);
786 ret = -ENODEV;
787done:
788 return ret;
789}
790
Venkata Narendra Kumar Gutta88fd0bc2014-03-27 19:47:56 +0530791int platform_set_fluence_type(void *platform, char *value)
792{
793 int ret = 0;
794 int fluence_type = FLUENCE_NONE;
795 int fluence_flag = NONE_FLAG;
796 struct platform_data *my_data = (struct platform_data *)platform;
797 struct audio_device *adev = my_data->adev;
798
799 ALOGV("%s: fluence type:%d", __func__, my_data->fluence_type);
800
801 /* only dual mic turn on and off is supported as of now through setparameters */
802 if (!strncmp(AUDIO_PARAMETER_VALUE_DUALMIC,value, sizeof(AUDIO_PARAMETER_VALUE_DUALMIC))) {
803 if (!strncmp("fluencepro", my_data->fluence_cap, sizeof("fluencepro")) ||
804 !strncmp("fluence", my_data->fluence_cap, sizeof("fluence"))) {
805 ALOGV("fluence dualmic feature enabled \n");
806 fluence_type = FLUENCE_DUAL_MIC;
807 fluence_flag = DMIC_FLAG;
808 } else {
809 ALOGE("%s: Failed to set DUALMIC", __func__);
810 ret = -1;
811 goto done;
812 }
813 } else if (!strncmp(AUDIO_PARAMETER_KEY_NO_FLUENCE, value, sizeof(AUDIO_PARAMETER_KEY_NO_FLUENCE))) {
814 ALOGV("fluence disabled");
815 fluence_type = FLUENCE_NONE;
816 } else {
817 ALOGE("Invalid fluence value : %s",value);
818 ret = -1;
819 goto done;
820 }
821
822 if (fluence_type != my_data->fluence_type) {
823 ALOGV("%s: Updating fluence_type to :%d", __func__, fluence_type);
824 my_data->fluence_type = fluence_type;
825 adev->acdb_settings = (adev->acdb_settings & FLUENCE_MODE_CLEAR) | fluence_flag;
826 }
827done:
828 return ret;
829}
830
831int platform_get_fluence_type(void *platform, char *value, uint32_t len)
832{
833 int ret = 0;
834 struct platform_data *my_data = (struct platform_data *)platform;
835
836 if (my_data->fluence_type == FLUENCE_QUAD_MIC) {
837 strlcpy(value, "quadmic", len);
838 } else if (my_data->fluence_type == FLUENCE_DUAL_MIC) {
839 strlcpy(value, "dualmic", len);
840 } else if (my_data->fluence_type == FLUENCE_NONE) {
841 strlcpy(value, "none", len);
842 } else
843 ret = -1;
844
845 return ret;
846}
847
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530848int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
849{
850 int ret = 0;
851
852 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
853 ALOGE("%s: Invalid snd_device = %d",
854 __func__, snd_device);
855 ret = -EINVAL;
856 goto done;
857 }
858
859 acdb_device_table[snd_device] = acdb_id;
860done:
861 return ret;
862}
863
Naresh Tannirue3b18452014-03-04 14:44:27 +0530864int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
865{
866 struct platform_data *my_data = (struct platform_data *)platform;
867 int acdb_dev_id, acdb_dev_type;
868
869 acdb_dev_id = acdb_device_table[snd_device];
870 if (acdb_dev_id < 0) {
871 ALOGE("%s: Could not find acdb id for device(%d)",
872 __func__, snd_device);
873 return -EINVAL;
874 }
875 if (my_data->acdb_send_audio_cal) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530876 ("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530877 __func__, snd_device, acdb_dev_id);
878 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
879 snd_device < SND_DEVICE_OUT_END)
880 acdb_dev_type = ACDB_DEV_TYPE_OUT;
881 else
882 acdb_dev_type = ACDB_DEV_TYPE_IN;
883 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
884 }
885 return 0;
886}
887
888int platform_switch_voice_call_device_pre(void *platform)
889{
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530890 struct platform_data *my_data = (struct platform_data *)platform;
891 int ret = 0;
892
893 if (my_data->csd != NULL &&
894 my_data->adev->mode == AUDIO_MODE_IN_CALL) {
895 /* This must be called before disabling mixer controls on APQ side */
896 ret = my_data->csd->disable_device();
897 if (ret < 0) {
898 ALOGE("%s: csd_client_disable_device, failed, error %d",
899 __func__, ret);
900 }
901 }
902 return ret;
Naresh Tannirue3b18452014-03-04 14:44:27 +0530903}
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530904int platform_switch_voice_call_enable_device_config(void *platform,
905 snd_device_t out_snd_device,
906 snd_device_t in_snd_device)
907{
908 struct platform_data *my_data = (struct platform_data *)platform;
909 int acdb_rx_id, acdb_tx_id;
910 int ret = 0;
911
912 acdb_rx_id = acdb_device_table[out_snd_device];
913 acdb_tx_id = acdb_device_table[in_snd_device];
914
915 if (my_data->csd != NULL) {
916 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
917 ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
918 if (ret < 0) {
919 ALOGE("%s: csd_enable_device_config, failed, error %d",
920 __func__, ret);
921 }
922 } else {
923 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
924 acdb_rx_id, acdb_tx_id);
925 }
926 }
927 return ret;
928}
929
Naresh Tannirue3b18452014-03-04 14:44:27 +0530930
931int platform_switch_voice_call_device_post(void *platform,
932 snd_device_t out_snd_device,
933 snd_device_t in_snd_device)
934{
935 struct platform_data *my_data = (struct platform_data *)platform;
936 int acdb_rx_id, acdb_tx_id;
937
938 if (my_data->acdb_send_voice_cal == NULL) {
939 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
940 } else {
941 acdb_rx_id = acdb_device_table[out_snd_device];
942 acdb_tx_id = acdb_device_table[in_snd_device];
943
944 if (acdb_rx_id > 0 && acdb_tx_id > 0)
945 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
946 else
947 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
948 acdb_rx_id, acdb_tx_id);
949 }
950
951 return 0;
952}
953
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530954int platform_switch_voice_call_usecase_route_post(void *platform,
955 snd_device_t out_snd_device,
956 snd_device_t in_snd_device)
Naresh Tannirue3b18452014-03-04 14:44:27 +0530957{
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530958 struct platform_data *my_data = (struct platform_data *)platform;
959 int acdb_rx_id, acdb_tx_id;
960 int ret = 0;
961
962 acdb_rx_id = acdb_device_table[out_snd_device];
963 acdb_tx_id = acdb_device_table[in_snd_device];
964
965 if (my_data->csd != NULL) {
966 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
967 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
968 my_data->adev->acdb_settings);
969 if (ret < 0) {
970 ALOGE("%s: csd_enable_device, failed, error %d",
971 __func__, ret);
972 }
973 } else {
974 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
975 acdb_rx_id, acdb_tx_id);
976 }
977 }
978 return ret;
Naresh Tannirue3b18452014-03-04 14:44:27 +0530979}
980
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530981int platform_start_voice_call(void *platform, uint32_t vsid)
982{
983 struct platform_data *my_data = (struct platform_data *)platform;
984 int ret = 0;
985
986 if (my_data->csd != NULL) {
987 ret = my_data->csd->start_voice(vsid);
988 if (ret < 0) {
989 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
990 }
991 }
992 return ret;
993}
994
995int platform_stop_voice_call(void *platform, uint32_t vsid)
996{
997 struct platform_data *my_data = (struct platform_data *)platform;
998 int ret = 0;
999
1000 if (my_data->csd != NULL) {
1001 ret = my_data->csd->stop_voice(vsid);
1002 if (ret < 0) {
1003 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
1004 }
1005 }
1006 return ret;
1007}
1008int platform_get_sample_rate(void *platform, uint32_t *rate)
Naresh Tannirue3b18452014-03-04 14:44:27 +05301009{
1010 return 0;
1011}
1012
1013int platform_set_voice_volume(void *platform, int volume)
1014{
1015 struct platform_data *my_data = (struct platform_data *)platform;
1016 struct audio_device *adev = my_data->adev;
1017 struct mixer_ctl *ctl;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301018 const char *mixer_ctl_name = "Voice Rx Gain";
1019 int vol_index = 0, ret = 0;
1020 uint32_t set_values[ ] = {0,
1021 ALL_SESSION_VSID,
1022 DEFAULT_VOLUME_RAMP_DURATION_MS};
Naresh Tannirue3b18452014-03-04 14:44:27 +05301023
1024 // Voice volume levels are mapped to adsp volume levels as follows.
1025 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
1026 // But this values don't changed in kernel. So, below change is need.
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301027 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, MAX_VOL_INDEX);
1028 set_values[0] = vol_index;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301029
1030 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1031 if (!ctl) {
1032 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1033 __func__, mixer_ctl_name);
1034 return -EINVAL;
1035 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301036 ALOGV("Setting voice volume index: %d", set_values[0]);
1037 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
Naresh Tannirue3b18452014-03-04 14:44:27 +05301038
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301039 if (my_data->csd != NULL) {
1040 ret = my_data->csd->volume(ALL_SESSION_VSID, volume);
1041 if (ret < 0) {
1042 ALOGE("%s: csd_volume error %d", __func__, ret);
1043 }
1044 }
1045 return ret;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301046}
1047
1048int platform_set_mic_mute(void *platform, bool state)
1049{
1050 struct platform_data *my_data = (struct platform_data *)platform;
1051 struct audio_device *adev = my_data->adev;
1052 struct mixer_ctl *ctl;
1053 const char *mixer_ctl_name = "Voice Tx Mute";
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301054 int ret = 0;
1055 uint32_t set_values[ ] = {0,
1056 ALL_SESSION_VSID,
1057 DEFAULT_VOLUME_RAMP_DURATION_MS};
Naresh Tannirue3b18452014-03-04 14:44:27 +05301058
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301059 set_values[0] = state;
1060 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1061 if (!ctl) {
1062 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1063 __func__, mixer_ctl_name);
1064 return -EINVAL;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301065 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301066 ALOGV("Setting voice mute state: %d", state);
1067 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
Naresh Tannirue3b18452014-03-04 14:44:27 +05301068
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301069 if (my_data->csd != NULL) {
1070 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state);
1071 if (ret < 0) {
1072 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
1073 }
1074 }
1075 return ret;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301076}
1077
Shiv Maliyappanahallic6fd8ee2014-03-07 15:31:55 -08001078int platform_set_device_mute(void *platform, bool state, char *dir)
1079{
1080 struct platform_data *my_data = (struct platform_data *)platform;
1081 struct audio_device *adev = my_data->adev;
1082 struct mixer_ctl *ctl;
1083 char *mixer_ctl_name = NULL;
1084 int ret = 0;
1085 uint32_t set_values[ ] = {0,
1086 ALL_SESSION_VSID,
1087 0};
1088 if(dir == NULL) {
1089 ALOGE("%s: Invalid direction:%s", __func__, dir);
1090 return -EINVAL;
1091 }
1092
1093 if (!strncmp("rx", dir, sizeof("rx"))) {
1094 mixer_ctl_name = "Voice Rx Device Mute";
1095 } else if (!strncmp("tx", dir, sizeof("tx"))) {
1096 mixer_ctl_name = "Voice Tx Device Mute";
1097 } else {
1098 return -EINVAL;
1099 }
1100
1101 set_values[0] = state;
1102 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1103 if (!ctl) {
1104 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1105 __func__, mixer_ctl_name);
1106 return -EINVAL;
1107 }
1108
1109 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
1110 __func__,state, mixer_ctl_name);
1111 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1112
1113 return ret;
1114}
1115
Naresh Tannirue3b18452014-03-04 14:44:27 +05301116snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
1117{
1118 struct platform_data *my_data = (struct platform_data *)platform;
1119 struct audio_device *adev = my_data->adev;
1120 audio_mode_t mode = adev->mode;
1121 snd_device_t snd_device = SND_DEVICE_NONE;
1122
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301123 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
1124 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
1125 int channel_count = popcount(channel_mask);
1126
Naresh Tannirue3b18452014-03-04 14:44:27 +05301127 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
1128 if (devices == AUDIO_DEVICE_NONE ||
1129 devices & AUDIO_DEVICE_BIT_IN) {
1130 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
1131 goto exit;
1132 }
1133
Naresh Tannirue3b18452014-03-04 14:44:27 +05301134 if (popcount(devices) == 2) {
1135 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
1136 AUDIO_DEVICE_OUT_SPEAKER)) {
1137 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
1138 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
1139 AUDIO_DEVICE_OUT_SPEAKER)) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301140 if (audio_extn_get_anc_enabled())
1141 snd_device = SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET;
1142 else
1143 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301144 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
1145 AUDIO_DEVICE_OUT_SPEAKER)) {
1146 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301147 } else if (devices == (AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET |
1148 AUDIO_DEVICE_OUT_SPEAKER)) {
1149 snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301150 } else {
1151 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
1152 goto exit;
1153 }
1154 if (snd_device != SND_DEVICE_NONE) {
1155 goto exit;
1156 }
1157 }
1158
1159 if (popcount(devices) != 1) {
1160 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
1161 goto exit;
1162 }
1163
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301164 if ((mode == AUDIO_MODE_IN_CALL) ||
1165 voice_extn_compress_voip_is_active(adev)) {
1166 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1167 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
1168 if ((adev->voice.tty_mode != TTY_MODE_OFF) &&
1169 !voice_extn_compress_voip_is_active(adev)) {
1170 switch (adev->voice.tty_mode) {
1171 case TTY_MODE_FULL:
1172 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
1173 break;
1174 case TTY_MODE_VCO:
1175 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
1176 break;
1177 case TTY_MODE_HCO:
1178 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
1179 break;
1180 default:
1181 ALOGE("%s: Invalid TTY mode (%#x)",
1182 __func__, adev->voice.tty_mode);
1183 }
1184 } else if (audio_extn_get_anc_enabled()) {
1185 if (audio_extn_should_use_fb_anc())
1186 snd_device = SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET;
1187 else
1188 snd_device = SND_DEVICE_OUT_VOICE_ANC_HEADSET;
1189 } else {
1190 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
1191 }
1192 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
1193 if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ)
1194 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
1195 else
1196 snd_device = SND_DEVICE_OUT_BT_SCO;
1197 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
1198 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
1199 } else if (devices & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
1200 devices & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
1201 snd_device = SND_DEVICE_OUT_USB_HEADSET;
1202 } else if (devices & AUDIO_DEVICE_OUT_FM_TX) {
1203 snd_device = SND_DEVICE_OUT_TRANSMISSION_FM;
1204 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
1205 if (audio_extn_should_use_handset_anc(channel_count))
1206 snd_device = SND_DEVICE_OUT_ANC_HANDSET;
1207 else
1208 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
1209 }
1210 if (snd_device != SND_DEVICE_NONE) {
1211 goto exit;
1212 }
1213 }
1214
Naresh Tannirue3b18452014-03-04 14:44:27 +05301215 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1216 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301217 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADSET
1218 && audio_extn_get_anc_enabled()) {
1219 if (audio_extn_should_use_fb_anc())
1220 snd_device = SND_DEVICE_OUT_ANC_FB_HEADSET;
1221 else
1222 snd_device = SND_DEVICE_OUT_ANC_HEADSET;
1223 }
1224 else
1225 snd_device = SND_DEVICE_OUT_HEADPHONES;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301226 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
1227 if (adev->speaker_lr_swap)
1228 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
1229 else
1230 snd_device = SND_DEVICE_OUT_SPEAKER;
1231 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301232 if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ)
1233 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
1234 else
1235 snd_device = SND_DEVICE_OUT_BT_SCO;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301236 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
1237 snd_device = SND_DEVICE_OUT_HDMI ;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301238 } else if (devices & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
1239 devices & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
Mingming Yin5a7c5d62014-03-05 17:45:03 -08001240 ALOGD("%s: setting USB hadset channel capability(2) for Proxy", __func__);
1241 audio_extn_set_afe_proxy_channel_mixer(adev, 2);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301242 snd_device = SND_DEVICE_OUT_USB_HEADSET;
1243 } else if (devices & AUDIO_DEVICE_OUT_FM_TX) {
1244 snd_device = SND_DEVICE_OUT_TRANSMISSION_FM;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301245 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
1246 snd_device = SND_DEVICE_OUT_HANDSET;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301247 } else if (devices & AUDIO_DEVICE_OUT_PROXY) {
Mingming Yin5a7c5d62014-03-05 17:45:03 -08001248 channel_count = audio_extn_get_afe_proxy_channel_count();
1249 ALOGD("%s: setting sink capability(%d) for Proxy", __func__, channel_count);
1250 audio_extn_set_afe_proxy_channel_mixer(adev, channel_count);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301251 snd_device = SND_DEVICE_OUT_AFE_PROXY;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301252 } else {
1253 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
1254 }
1255exit:
1256 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
1257 return snd_device;
1258}
1259
1260snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
1261{
1262 struct platform_data *my_data = (struct platform_data *)platform;
1263 struct audio_device *adev = my_data->adev;
1264 audio_source_t source = (adev->active_input == NULL) ?
1265 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
1266
1267 audio_mode_t mode = adev->mode;
1268 audio_devices_t in_device = ((adev->active_input == NULL) ?
1269 AUDIO_DEVICE_NONE : adev->active_input->device)
1270 & ~AUDIO_DEVICE_BIT_IN;
1271 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
1272 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
1273 snd_device_t snd_device = SND_DEVICE_NONE;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301274 int channel_count = popcount(channel_mask);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301275
1276 ALOGV("%s: enter: out_device(%#x) in_device(%#x)",
1277 __func__, out_device, in_device);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301278 if ((out_device != AUDIO_DEVICE_NONE) && ((mode == AUDIO_MODE_IN_CALL) ||
1279 voice_extn_compress_voip_is_active(adev))) {
1280 if ((adev->voice.tty_mode != TTY_MODE_OFF) &&
1281 !voice_extn_compress_voip_is_active(adev)) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301282 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1283 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301284 switch (adev->voice.tty_mode) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301285 case TTY_MODE_FULL:
1286 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
1287 break;
1288 case TTY_MODE_VCO:
1289 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
1290 break;
1291 case TTY_MODE_HCO:
1292 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
1293 break;
1294 default:
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301295 ALOGE("%s: Invalid TTY mode (%#x)",
1296 __func__, adev->voice.tty_mode);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301297 }
1298 goto exit;
1299 }
1300 }
1301 if (out_device & AUDIO_DEVICE_OUT_EARPIECE ||
1302 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301303 if (out_device & AUDIO_DEVICE_OUT_EARPIECE &&
1304 audio_extn_should_use_handset_anc(channel_count)) {
1305 snd_device = SND_DEVICE_IN_AANC_HANDSET_MIC;
1306 } else if (my_data->fluence_type == FLUENCE_NONE ||
1307 my_data->fluence_in_voice_call == false) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301308 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301309 set_echo_reference(adev->mixer, EC_REF_RX);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301310 } else {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301311 snd_device = SND_DEVICE_IN_VOICE_DMIC;
1312 adev->acdb_settings |= DMIC_FLAG;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301313 }
1314 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
1315 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
1316 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301317 if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ)
1318 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
1319 else
1320 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301321 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301322 if (my_data->fluence_type != FLUENCE_NONE &&
1323 my_data->fluence_in_voice_call &&
1324 my_data->fluence_in_spkr_mode) {
1325 if(my_data->fluence_type & FLUENCE_QUAD_MIC) {
1326 adev->acdb_settings |= QMIC_FLAG;
1327 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_QMIC;
1328 } else {
1329 adev->acdb_settings |= DMIC_FLAG;
1330 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
1331 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05301332 } else {
1333 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
1334 }
1335 }
1336 } else if (source == AUDIO_SOURCE_CAMCORDER) {
1337 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
1338 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
1339 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
1340 }
1341 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
1342 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301343 if (channel_count == 2) {
1344 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
1345 adev->acdb_settings |= DMIC_FLAG;
1346 } else if (adev->active_input->enable_ns)
1347 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
1348 else if (my_data->fluence_type != FLUENCE_NONE &&
1349 my_data->fluence_in_voice_rec) {
1350 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
1351 adev->acdb_settings |= DMIC_FLAG;
1352 } else {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301353 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
1354 }
1355 }
1356 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION) {
1357 if (out_device & AUDIO_DEVICE_OUT_SPEAKER)
1358 in_device = AUDIO_DEVICE_IN_BACK_MIC;
1359 if (adev->active_input) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301360 if (adev->active_input->enable_aec &&
1361 adev->active_input->enable_ns) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301362 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301363 if (my_data->fluence_type & FLUENCE_DUAL_MIC &&
1364 my_data->fluence_in_spkr_mode) {
1365 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
1366 adev->acdb_settings |= DMIC_FLAG;
1367 } else
1368 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301369 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301370 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1371 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
1372 adev->acdb_settings |= DMIC_FLAG;
1373 } else
1374 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301375 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301376 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301377 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301378 set_echo_reference(adev->mixer, EC_REF_RX);
1379 } else if (adev->active_input->enable_aec) {
1380 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
1381 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1382 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
1383 adev->acdb_settings |= DMIC_FLAG;
1384 } else
1385 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
1386 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
1387 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1388 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
1389 adev->acdb_settings |= DMIC_FLAG;
1390 } else
1391 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
1392 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
1393 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
1394 }
1395 set_echo_reference(adev->mixer, EC_REF_RX);
1396 } else if (adev->active_input->enable_ns) {
1397 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
1398 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1399 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
1400 adev->acdb_settings |= DMIC_FLAG;
1401 } else
1402 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
1403 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
1404 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1405 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
1406 adev->acdb_settings |= DMIC_FLAG;
1407 } else
1408 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
1409 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
1410 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
1411 }
1412 set_echo_reference(adev->mixer, "NONE");
Naresh Tannirue3b18452014-03-04 14:44:27 +05301413 } else
1414 set_echo_reference(adev->mixer, "NONE");
1415 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301416 } else if (source == AUDIO_SOURCE_MIC) {
1417 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC &&
1418 channel_count == 1 ) {
1419 if(my_data->fluence_type & FLUENCE_DUAL_MIC &&
1420 my_data->fluence_in_audio_rec)
1421 snd_device = SND_DEVICE_IN_HANDSET_DMIC;
1422 }
1423 } else if (source == AUDIO_SOURCE_FM_RX ||
1424 source == AUDIO_SOURCE_FM_RX_A2DP) {
1425 snd_device = SND_DEVICE_IN_CAPTURE_FM;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301426 } else if (source == AUDIO_SOURCE_DEFAULT) {
1427 goto exit;
1428 }
1429
1430
1431 if (snd_device != SND_DEVICE_NONE) {
1432 goto exit;
1433 }
1434
1435 if (in_device != AUDIO_DEVICE_NONE &&
1436 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
1437 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
1438 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301439 if (audio_extn_ssr_get_enabled() && channel_count == 6)
1440 snd_device = SND_DEVICE_IN_QUAD_MIC;
1441 else if (channel_count == 2)
1442 snd_device = SND_DEVICE_IN_HANDSET_STEREO_DMIC;
1443 else
1444 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301445 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
1446 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
1447 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
1448 snd_device = SND_DEVICE_IN_HEADSET_MIC;
1449 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301450 if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ)
1451 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
1452 else
1453 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301454 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
1455 snd_device = SND_DEVICE_IN_HDMI_MIC;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301456 } else if (in_device & AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET ||
1457 in_device & AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET) {
1458 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
1459 } else if (in_device & AUDIO_DEVICE_IN_FM_RX) {
1460 snd_device = SND_DEVICE_IN_CAPTURE_FM;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301461 } else {
1462 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
1463 ALOGW("%s: Using default handset-mic", __func__);
1464 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1465 }
1466 } else {
1467 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
1468 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1469 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
1470 snd_device = SND_DEVICE_IN_HEADSET_MIC;
1471 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301472 if (channel_count > 1)
1473 snd_device = SND_DEVICE_IN_SPEAKER_STEREO_DMIC;
1474 else
1475 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301476 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
1477 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1478 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301479 if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ)
1480 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
1481 else
1482 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301483 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
1484 snd_device = SND_DEVICE_IN_HDMI_MIC;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301485 } else if (out_device & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
1486 out_device & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
1487 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301488 } else {
1489 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
1490 ALOGW("%s: Using default handset-mic", __func__);
1491 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1492 }
1493 }
1494exit:
1495 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
1496 return snd_device;
1497}
1498
1499int platform_set_hdmi_channels(void *platform, int channel_count)
1500{
1501 struct platform_data *my_data = (struct platform_data *)platform;
1502 struct audio_device *adev = my_data->adev;
1503 struct mixer_ctl *ctl;
1504 const char *channel_cnt_str = NULL;
1505 const char *mixer_ctl_name = "HDMI_RX Channels";
1506 switch (channel_count) {
1507 case 8:
1508 channel_cnt_str = "Eight"; break;
1509 case 7:
1510 channel_cnt_str = "Seven"; break;
1511 case 6:
1512 channel_cnt_str = "Six"; break;
1513 case 5:
1514 channel_cnt_str = "Five"; break;
1515 case 4:
1516 channel_cnt_str = "Four"; break;
1517 case 3:
1518 channel_cnt_str = "Three"; break;
1519 default:
1520 channel_cnt_str = "Two"; break;
1521 }
1522 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1523 if (!ctl) {
1524 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1525 __func__, mixer_ctl_name);
1526 return -EINVAL;
1527 }
1528 ALOGV("HDMI channel count: %s", channel_cnt_str);
1529 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
1530 return 0;
1531}
1532
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301533int platform_edid_get_max_channels(void *platform)
Naresh Tannirue3b18452014-03-04 14:44:27 +05301534{
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301535 struct platform_data *my_data = (struct platform_data *)platform;
1536 struct audio_device *adev = my_data->adev;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301537 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
1538 char *sad = block;
1539 int num_audio_blocks;
1540 int channel_count;
1541 int max_channels = 0;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301542 int i, ret, count;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301543
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301544 struct mixer_ctl *ctl;
1545
1546 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
1547 if (!ctl) {
1548 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1549 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301550 return 0;
1551 }
1552
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301553 mixer_ctl_update(ctl);
1554
1555 count = mixer_ctl_get_num_values(ctl);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301556
1557 /* Read SAD blocks, clamping the maximum size for safety */
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301558 if (count > (int)sizeof(block))
1559 count = (int)sizeof(block);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301560
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301561 ret = mixer_ctl_get_array(ctl, block, count);
1562 if (ret != 0) {
1563 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
1564 return 0;
1565 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05301566
1567 /* Calculate the number of SAD blocks */
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301568 num_audio_blocks = count / SAD_BLOCK_SIZE;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301569
1570 for (i = 0; i < num_audio_blocks; i++) {
1571 /* Only consider LPCM blocks */
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301572 if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
1573 sad += 3;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301574 continue;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301575 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05301576
1577 channel_count = (sad[0] & 0x7) + 1;
1578 if (channel_count > max_channels)
1579 max_channels = channel_count;
1580
1581 /* Advance to next block */
1582 sad += 3;
1583 }
1584
1585 return max_channels;
1586}
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301587
1588static int platform_set_slowtalk(struct platform_data *my_data, bool state)
1589{
1590 int ret = 0;
1591 struct audio_device *adev = my_data->adev;
1592 struct mixer_ctl *ctl;
1593 const char *mixer_ctl_name = "Slowtalk Enable";
1594 uint32_t set_values[ ] = {0,
1595 ALL_SESSION_VSID};
1596
1597 set_values[0] = state;
1598 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1599 if (!ctl) {
1600 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1601 __func__, mixer_ctl_name);
1602 ret = -EINVAL;
1603 } else {
1604 ALOGV("Setting slowtalk state: %d", state);
1605 ret = mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1606 my_data->slowtalk = state;
1607 }
1608
1609 if (my_data->csd != NULL) {
1610 ret = my_data->csd->slow_talk(ALL_SESSION_VSID, state);
1611 if (ret < 0) {
1612 ALOGE("%s: csd_client_disable_device, failed, error %d",
1613 __func__, ret);
1614 }
1615 }
1616 return ret;
1617}
1618
1619int platform_set_parameters(void *platform, struct str_parms *parms)
1620{
1621 struct platform_data *my_data = (struct platform_data *)platform;
1622 char *str;
1623 char value[256] = {0};
1624 int val;
1625 int ret = 0, err;
1626
1627 ALOGV("%s: enter: %s", __func__, str_parms_to_str(parms));
1628
1629 err = str_parms_get_int(parms, AUDIO_PARAMETER_KEY_BTSCO, &val);
1630 if (err >= 0) {
1631 str_parms_del(parms, AUDIO_PARAMETER_KEY_BTSCO);
1632 my_data->btsco_sample_rate = val;
1633 if (val == SAMPLE_RATE_16KHZ) {
1634 audio_route_apply_path(my_data->adev->audio_route,
1635 "bt-sco-wb-samplerate");
1636 audio_route_update_mixer(my_data->adev->audio_route);
1637 }
1638 }
1639
1640 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_SLOWTALK, value, sizeof(value));
1641 if (err >= 0) {
1642 bool state = false;
1643 if (!strncmp("true", value, sizeof("true"))) {
1644 state = true;
1645 }
1646
1647 str_parms_del(parms, AUDIO_PARAMETER_KEY_SLOWTALK);
1648 ret = platform_set_slowtalk(my_data, state);
1649 if (ret)
1650 ALOGE("%s: Failed to set slow talk err: %d", __func__, ret);
1651 }
1652
1653 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_VOLUME_BOOST,
1654 value, sizeof(value));
1655 if (err >= 0) {
1656 str_parms_del(parms, AUDIO_PARAMETER_KEY_VOLUME_BOOST);
1657
1658 if (my_data->acdb_reload_vocvoltable == NULL) {
1659 ALOGE("%s: acdb_reload_vocvoltable is NULL", __func__);
1660 } else if (!strcmp(value, "on")) {
1661 if (!my_data->acdb_reload_vocvoltable(VOICE_FEATURE_SET_VOLUME_BOOST)) {
1662 my_data->voice_feature_set = 1;
1663 }
1664 } else {
1665 if (!my_data->acdb_reload_vocvoltable(VOICE_FEATURE_SET_DEFAULT)) {
1666 my_data->voice_feature_set = 0;
1667 }
1668 }
1669 }
1670
1671 ALOGV("%s: exit with code(%d)", __func__, ret);
1672 return ret;
1673}
1674
1675int platform_set_incall_recording_session_id(void *platform,
1676 uint32_t session_id, int rec_mode)
1677{
1678 int ret = 0;
1679 struct platform_data *my_data = (struct platform_data *)platform;
1680 struct audio_device *adev = my_data->adev;
1681 struct mixer_ctl *ctl;
1682 const char *mixer_ctl_name = "Voc VSID";
1683 int num_ctl_values;
1684 int i;
1685
1686 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1687 if (!ctl) {
1688 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1689 __func__, mixer_ctl_name);
1690 ret = -EINVAL;
1691 } else {
1692 num_ctl_values = mixer_ctl_get_num_values(ctl);
1693 for (i = 0; i < num_ctl_values; i++) {
1694 if (mixer_ctl_set_value(ctl, i, session_id)) {
1695 ALOGV("Error: invalid session_id: %x", session_id);
1696 ret = -EINVAL;
1697 break;
1698 }
1699 }
1700 }
1701
1702 if (my_data->csd != NULL) {
1703 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
1704 if (ret < 0) {
1705 ALOGE("%s: csd_client_start_record failed, error %d",
1706 __func__, ret);
1707 }
1708 }
1709
1710 return ret;
1711}
1712
1713int platform_stop_incall_recording_usecase(void *platform)
1714{
1715 int ret = 0;
1716 struct platform_data *my_data = (struct platform_data *)platform;
1717
1718 if (my_data->csd != NULL) {
1719 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
1720 if (ret < 0) {
1721 ALOGE("%s: csd_client_stop_record failed, error %d",
1722 __func__, ret);
1723 }
1724 }
1725
1726 return ret;
1727}
1728
1729int platform_start_incall_music_usecase(void *platform)
1730{
1731 int ret = 0;
1732 struct platform_data *my_data = (struct platform_data *)platform;
1733
1734 if (my_data->csd != NULL) {
1735 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
1736 if (ret < 0) {
1737 ALOGE("%s: csd_client_start_playback failed, error %d",
1738 __func__, ret);
1739 }
1740 }
1741
1742 return ret;
1743}
1744
1745int platform_stop_incall_music_usecase(void *platform)
1746{
1747 int ret = 0;
1748 struct platform_data *my_data = (struct platform_data *)platform;
1749
1750 if (my_data->csd != NULL) {
1751 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
1752 if (ret < 0) {
1753 ALOGE("%s: csd_client_stop_playback failed, error %d",
1754 __func__, ret);
1755 }
1756 }
1757
1758 return ret;
1759}
1760
1761void platform_get_parameters(void *platform,
1762 struct str_parms *query,
1763 struct str_parms *reply)
1764{
1765 struct platform_data *my_data = (struct platform_data *)platform;
1766 char *str = NULL;
1767 char value[256] = {0};
1768 int ret;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301769
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301770 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_SLOWTALK,
1771 value, sizeof(value));
1772 if (ret >= 0) {
1773 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_SLOWTALK,
1774 my_data->slowtalk?"true":"false");
1775 }
1776
1777 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_VOLUME_BOOST,
1778 value, sizeof(value));
1779 if (ret >= 0) {
1780 if (my_data->voice_feature_set == VOICE_FEATURE_SET_VOLUME_BOOST) {
1781 strlcpy(value, "on", sizeof(value));
1782 } else {
1783 strlcpy(value, "off", sizeof(value));
1784 }
1785
1786 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_VOLUME_BOOST, value);
1787 }
1788
1789 ALOGV("%s: exit: returns - %s", __func__, str_parms_to_str(reply));
1790}
1791
1792/* Delay in Us */
1793int64_t platform_render_latency(audio_usecase_t usecase)
1794{
1795 switch (usecase) {
1796 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
1797 return DEEP_BUFFER_PLATFORM_DELAY;
1798 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
1799 return LOW_LATENCY_PLATFORM_DELAY;
1800 default:
1801 return 0;
1802 }
1803}
1804
1805int platform_update_usecase_from_source(int source, int usecase)
1806{
1807 ALOGV("%s: input source :%d", __func__, source);
1808 if(source == AUDIO_SOURCE_FM_RX_A2DP)
1809 usecase = USECASE_AUDIO_RECORD_FM_VIRTUAL;
1810 return usecase;
1811}
1812
1813bool platform_listen_update_status(snd_device_t snd_device)
1814{
1815 if ((snd_device >= SND_DEVICE_IN_BEGIN) &&
1816 (snd_device < SND_DEVICE_IN_END) &&
1817 (snd_device != SND_DEVICE_IN_CAPTURE_FM) &&
1818 (snd_device != SND_DEVICE_IN_CAPTURE_VI_FEEDBACK))
1819 return true;
1820 else
1821 return false;
1822}
1823
1824/* Read offload buffer size from a property.
1825 * If value is not power of 2 round it to
1826 * power of 2.
1827 */
1828uint32_t platform_get_compress_offload_buffer_size(audio_offload_info_t* info)
1829{
1830 char value[PROPERTY_VALUE_MAX] = {0};
1831 uint32_t fragment_size = COMPRESS_OFFLOAD_FRAGMENT_SIZE;
1832 if((property_get("audio.offload.buffer.size.kb", value, "")) &&
1833 atoi(value)) {
1834 fragment_size = atoi(value) * 1024;
1835 }
1836
1837 if (info != NULL && info->has_video && info->is_streaming) {
1838 fragment_size = COMPRESS_OFFLOAD_FRAGMENT_SIZE_FOR_AV_STREAMING;
1839 ALOGV("%s: offload fragment size reduced for AV streaming to %d",
1840 __func__, out->compr_config.fragment_size);
1841 }
1842
1843 fragment_size = ALIGN( fragment_size, 1024);
1844
1845 if(fragment_size < MIN_COMPRESS_OFFLOAD_FRAGMENT_SIZE)
1846 fragment_size = MIN_COMPRESS_OFFLOAD_FRAGMENT_SIZE;
1847 else if(fragment_size > MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE)
1848 fragment_size = MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE;
1849 ALOGV("%s: fragment_size %d", __func__, fragment_size);
1850 return fragment_size;
1851}
1852
1853uint32_t platform_get_pcm_offload_buffer_size(audio_offload_info_t* info)
1854{
1855 uint32_t fragment_size = MIN_PCM_OFFLOAD_FRAGMENT_SIZE;
1856 uint32_t bits_per_sample = 16;
1857
1858 if (info->format == AUDIO_FORMAT_PCM_24_BIT_OFFLOAD) {
1859 bits_per_sample = 32;
1860 }
1861
1862 if (!info->has_video) {
1863 fragment_size = MAX_PCM_OFFLOAD_FRAGMENT_SIZE;
1864
1865 } else if (info->has_video && info->is_streaming) {
1866 fragment_size = (PCM_OFFLOAD_BUFFER_DURATION_FOR_AV_STREAMING
1867 * info->sample_rate
1868 * bits_per_sample
1869 * popcount(info->channel_mask))/1000;
1870
1871 } else if (info->has_video) {
1872 fragment_size = (PCM_OFFLOAD_BUFFER_DURATION_FOR_AV
1873 * info->sample_rate
1874 * bits_per_sample
1875 * popcount(info->channel_mask))/1000;
1876 }
1877
1878 fragment_size = ALIGN( fragment_size, 1024);
1879
1880 if(fragment_size < MIN_PCM_OFFLOAD_FRAGMENT_SIZE)
1881 fragment_size = MIN_PCM_OFFLOAD_FRAGMENT_SIZE;
1882 else if(fragment_size > MAX_PCM_OFFLOAD_FRAGMENT_SIZE)
1883 fragment_size = MAX_PCM_OFFLOAD_FRAGMENT_SIZE;
1884
1885 ALOGV("%s: fragment_size %d", __func__, fragment_size);
1886 return fragment_size;
1887}
1888