blob: dc079b92fd69ab6fb0f4dfa1351ec3997c5806e9 [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;
108 int btsco_sample_rate;
109 bool slowtalk;
110 /* Audio calibration related functions */
111 void *acdb_handle;
112 int voice_feature_set;
113 acdb_init_t acdb_init;
114 acdb_deallocate_t acdb_deallocate;
115 acdb_send_audio_cal_t acdb_send_audio_cal;
116 acdb_send_voice_cal_t acdb_send_voice_cal;
117 acdb_reload_vocvoltable_t acdb_reload_vocvoltable;
Naresh Tannirue3b18452014-03-04 14:44:27 +0530118
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530119 void *hw_info;
120 struct csd_data *csd;
Naresh Tannirue3b18452014-03-04 14:44:27 +0530121};
122
123static const int pcm_device_table[AUDIO_USECASE_MAX][2] = {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530124 [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = {DEEP_BUFFER_PCM_DEVICE,
125 DEEP_BUFFER_PCM_DEVICE},
126 [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
127 LOWLATENCY_PCM_DEVICE},
128 [USECASE_AUDIO_PLAYBACK_MULTI_CH] = {MULTIMEDIA2_PCM_DEVICE,
129 MULTIMEDIA2_PCM_DEVICE},
130 [USECASE_AUDIO_PLAYBACK_OFFLOAD] =
131 {PLAYBACK_OFFLOAD_DEVICE, PLAYBACK_OFFLOAD_DEVICE},
132 [USECASE_AUDIO_RECORD] = {AUDIO_RECORD_PCM_DEVICE, AUDIO_RECORD_PCM_DEVICE},
133 [USECASE_AUDIO_RECORD_COMPRESS] = {COMPRESS_CAPTURE_DEVICE, COMPRESS_CAPTURE_DEVICE},
134 [USECASE_AUDIO_RECORD_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
135 LOWLATENCY_PCM_DEVICE},
136 [USECASE_AUDIO_RECORD_FM_VIRTUAL] = {MULTIMEDIA2_PCM_DEVICE,
137 MULTIMEDIA2_PCM_DEVICE},
138 [USECASE_AUDIO_PLAYBACK_FM] = {FM_PLAYBACK_PCM_DEVICE, FM_CAPTURE_PCM_DEVICE},
139 [USECASE_AUDIO_HFP_SCO] = {HFP_PCM_RX, HFP_SCO_RX},
140 [USECASE_AUDIO_HFP_SCO_WB] = {HFP_PCM_RX, HFP_SCO_RX},
141 [USECASE_VOICE_CALL] = {VOICE_CALL_PCM_DEVICE, VOICE_CALL_PCM_DEVICE},
142 [USECASE_VOICE2_CALL] = {VOICE2_CALL_PCM_DEVICE, VOICE2_CALL_PCM_DEVICE},
143 [USECASE_VOLTE_CALL] = {VOLTE_CALL_PCM_DEVICE, VOLTE_CALL_PCM_DEVICE},
144 [USECASE_QCHAT_CALL] = {QCHAT_CALL_PCM_DEVICE, QCHAT_CALL_PCM_DEVICE},
145 [USECASE_COMPRESS_VOIP_CALL] = {COMPRESS_VOIP_CALL_PCM_DEVICE, COMPRESS_VOIP_CALL_PCM_DEVICE},
146 [USECASE_INCALL_REC_UPLINK] = {AUDIO_RECORD_PCM_DEVICE,
147 AUDIO_RECORD_PCM_DEVICE},
148 [USECASE_INCALL_REC_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
149 AUDIO_RECORD_PCM_DEVICE},
150 [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
151 AUDIO_RECORD_PCM_DEVICE},
152 [USECASE_INCALL_REC_UPLINK_COMPRESS] = {COMPRESS_CAPTURE_DEVICE,
153 COMPRESS_CAPTURE_DEVICE},
154 [USECASE_INCALL_REC_DOWNLINK_COMPRESS] = {COMPRESS_CAPTURE_DEVICE,
155 COMPRESS_CAPTURE_DEVICE},
156 [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK_COMPRESS] = {COMPRESS_CAPTURE_DEVICE,
157 COMPRESS_CAPTURE_DEVICE},
158 [USECASE_INCALL_MUSIC_UPLINK] = {INCALL_MUSIC_UPLINK_PCM_DEVICE,
159 INCALL_MUSIC_UPLINK_PCM_DEVICE},
160 [USECASE_INCALL_MUSIC_UPLINK2] = {INCALL_MUSIC_UPLINK2_PCM_DEVICE,
161 INCALL_MUSIC_UPLINK2_PCM_DEVICE},
162 [USECASE_AUDIO_SPKR_CALIB_RX] = {SPKR_PROT_CALIB_RX_PCM_DEVICE, -1},
163 [USECASE_AUDIO_SPKR_CALIB_TX] = {-1, SPKR_PROT_CALIB_TX_PCM_DEVICE},
Naresh Tannirue3b18452014-03-04 14:44:27 +0530164};
165
166/* Array to store sound devices */
167static const char * const device_table[SND_DEVICE_MAX] = {
168 [SND_DEVICE_NONE] = "none",
169 /* Playback sound devices */
170 [SND_DEVICE_OUT_HANDSET] = "handset",
171 [SND_DEVICE_OUT_SPEAKER] = "speaker",
172 [SND_DEVICE_OUT_SPEAKER_REVERSE] = "speaker-reverse",
173 [SND_DEVICE_OUT_HEADPHONES] = "headphones",
174 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones",
175 [SND_DEVICE_OUT_VOICE_HANDSET] = "voice-handset",
176 [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker",
177 [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones",
178 [SND_DEVICE_OUT_HDMI] = "hdmi",
179 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi",
180 [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530181 [SND_DEVICE_OUT_BT_SCO_WB] = "bt-sco-headset-wb",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530182 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones",
183 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones",
184 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530185 [SND_DEVICE_OUT_AFE_PROXY] = "afe-proxy",
186 [SND_DEVICE_OUT_USB_HEADSET] = "usb-headphones",
187 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = "speaker-and-usb-headphones",
188 [SND_DEVICE_OUT_TRANSMISSION_FM] = "transmission-fm",
189 [SND_DEVICE_OUT_ANC_HEADSET] = "anc-headphones",
190 [SND_DEVICE_OUT_ANC_FB_HEADSET] = "anc-fb-headphones",
191 [SND_DEVICE_OUT_VOICE_ANC_HEADSET] = "voice-anc-headphones",
192 [SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET] = "voice-anc-fb-headphones",
193 [SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET] = "speaker-and-anc-headphones",
194 [SND_DEVICE_OUT_ANC_HANDSET] = "anc-handset",
195 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = "speaker-protected",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530196
197 /* Capture sound devices */
198 [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530199 [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530200 [SND_DEVICE_IN_HANDSET_MIC_NS] = "handset-mic",
201 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = "handset-mic",
202 [SND_DEVICE_IN_HANDSET_DMIC] = "dmic-endfire",
203 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = "dmic-endfire",
204 [SND_DEVICE_IN_HANDSET_DMIC_NS] = "dmic-endfire",
205 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = "dmic-endfire",
206 [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
207 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "speaker-mic",
208 [SND_DEVICE_IN_SPEAKER_MIC_NS] = "speaker-mic",
209 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = "speaker-mic",
210 [SND_DEVICE_IN_SPEAKER_DMIC] = "speaker-dmic-endfire",
211 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = "speaker-dmic-endfire",
212 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = "speaker-dmic-endfire",
213 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = "speaker-dmic-endfire",
214 [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
215 [SND_DEVICE_IN_HEADSET_MIC_FLUENCE] = "headset-mic",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530216 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
217 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
218 [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic",
219 [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530220 [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530221 [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530222 [SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef",
223 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = "voice-speaker-dmic-ef",
224 [SND_DEVICE_IN_VOICE_SPEAKER_QMIC] = "voice-speaker-qmic",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530225 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
226 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
227 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
228 [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530229 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = "voice-rec-mic",
230 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = "voice-rec-dmic-ef",
231 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence",
232 [SND_DEVICE_IN_USB_HEADSET_MIC] = "usb-headset-mic",
233 [SND_DEVICE_IN_CAPTURE_FM] = "capture-fm",
234 [SND_DEVICE_IN_AANC_HANDSET_MIC] = "aanc-handset-mic",
235 [SND_DEVICE_IN_QUAD_MIC] = "quad-mic",
236 [SND_DEVICE_IN_HANDSET_STEREO_DMIC] = "handset-stereo-dmic-ef",
237 [SND_DEVICE_IN_SPEAKER_STEREO_DMIC] = "speaker-stereo-dmic-ef",
238 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = "vi-feedback",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530239};
240
241/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530242static int acdb_device_table[SND_DEVICE_MAX] = {
Naresh Tannirue3b18452014-03-04 14:44:27 +0530243 [SND_DEVICE_NONE] = -1,
244 [SND_DEVICE_OUT_HANDSET] = 7,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530245 [SND_DEVICE_OUT_SPEAKER] = 14,
246 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 14,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530247 [SND_DEVICE_OUT_HEADPHONES] = 10,
248 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
249 [SND_DEVICE_OUT_VOICE_HANDSET] = 7,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530250 [SND_DEVICE_OUT_VOICE_SPEAKER] = 14,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530251 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
252 [SND_DEVICE_OUT_HDMI] = 18,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530253 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 14,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530254 [SND_DEVICE_OUT_BT_SCO] = 22,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530255 [SND_DEVICE_OUT_BT_SCO_WB] = 39,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530256 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
257 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
258 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530259 [SND_DEVICE_OUT_AFE_PROXY] = 0,
260 [SND_DEVICE_OUT_USB_HEADSET] = 45,
261 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = 14,
262 [SND_DEVICE_OUT_TRANSMISSION_FM] = 0,
263 [SND_DEVICE_OUT_ANC_HEADSET] = 26,
264 [SND_DEVICE_OUT_ANC_FB_HEADSET] = 27,
265 [SND_DEVICE_OUT_VOICE_ANC_HEADSET] = 26,
266 [SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET] = 27,
267 [SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET] = 26,
268 [SND_DEVICE_OUT_ANC_HANDSET] = 103,
269 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = 101,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530270
271 [SND_DEVICE_IN_HANDSET_MIC] = 4,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530272 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 106,
273 [SND_DEVICE_IN_HANDSET_MIC_NS] = 107,
274 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = 108,
275 [SND_DEVICE_IN_HANDSET_DMIC] = 41,
276 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = 109,
277 [SND_DEVICE_IN_HANDSET_DMIC_NS] = 110,
278 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = 111,
279 [SND_DEVICE_IN_SPEAKER_MIC] = 11,
280 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 112,
281 [SND_DEVICE_IN_SPEAKER_MIC_NS] = 113,
282 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = 114,
283 [SND_DEVICE_IN_SPEAKER_DMIC] = 43,
284 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = 115,
285 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = 116,
286 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = 117,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530287 [SND_DEVICE_IN_HEADSET_MIC] = 8,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530288 [SND_DEVICE_IN_HEADSET_MIC_FLUENCE] = 47,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530289 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
290 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = 8,
291 [SND_DEVICE_IN_HDMI_MIC] = 4,
292 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530293 [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38,
294 [SND_DEVICE_IN_CAMCORDER_MIC] = 4,
295 [SND_DEVICE_IN_VOICE_DMIC] = 41,
296 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 43,
297 [SND_DEVICE_IN_VOICE_SPEAKER_QMIC] = 19,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530298 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
299 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
300 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530301 [SND_DEVICE_IN_VOICE_REC_MIC] = 4,
302 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = 107,
303 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = 34,
304 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 41,
305 [SND_DEVICE_IN_USB_HEADSET_MIC] = 44,
306 [SND_DEVICE_IN_CAPTURE_FM] = 0,
307 [SND_DEVICE_IN_AANC_HANDSET_MIC] = 104,
308 [SND_DEVICE_IN_QUAD_MIC] = 46,
309 [SND_DEVICE_IN_HANDSET_STEREO_DMIC] = 34,
310 [SND_DEVICE_IN_SPEAKER_STEREO_DMIC] = 35,
311 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = 102,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530312};
313
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530314struct snd_device_index {
315 char name[100];
316 unsigned int index;
317};
Naresh Tannirue3b18452014-03-04 14:44:27 +0530318
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530319#define TO_NAME_INDEX(X) #X, X
Naresh Tannirue3b18452014-03-04 14:44:27 +0530320
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530321/* Used to get index from parsed sting */
322struct snd_device_index snd_device_name_index[SND_DEVICE_MAX] = {
323 {TO_NAME_INDEX(SND_DEVICE_OUT_HANDSET)},
324 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER)},
325 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_REVERSE)},
326 {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES)},
327 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES)},
328 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET)},
329 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER)},
330 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADPHONES)},
331 {TO_NAME_INDEX(SND_DEVICE_OUT_HDMI)},
332 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HDMI)},
333 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO)},
334 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO_WB)},
335 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES)},
336 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES)},
337 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET)},
338 {TO_NAME_INDEX(SND_DEVICE_OUT_AFE_PROXY)},
339 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADSET)},
340 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET)},
341 {TO_NAME_INDEX(SND_DEVICE_OUT_TRANSMISSION_FM)},
342 {TO_NAME_INDEX(SND_DEVICE_OUT_ANC_HEADSET)},
343 {TO_NAME_INDEX(SND_DEVICE_OUT_ANC_FB_HEADSET)},
344 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_ANC_HEADSET)},
345 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET)},
346 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET)},
347 {TO_NAME_INDEX(SND_DEVICE_OUT_ANC_HANDSET)},
348 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED)},
349 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC)},
350 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC)},
351 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_NS)},
352 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)},
353 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC)},
354 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC)},
355 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_NS)},
356 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)},
357 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC)},
358 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC)},
359 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_NS)},
360 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)},
361 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC)},
362 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC)},
363 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS)},
364 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)},
365 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC)},
366 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC_FLUENCE)},
367 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC)},
368 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEADSET_MIC)},
369 {TO_NAME_INDEX(SND_DEVICE_IN_HDMI_MIC)},
370 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC)},
371 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB)},
372 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_MIC)},
373 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC)},
374 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC)},
375 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_QMIC)},
376 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC)},
377 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC)},
378 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC)},
379 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC)},
380 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_NS)},
381 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_STEREO)},
382 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE)},
383 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC)},
384 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_FM)},
385 {TO_NAME_INDEX(SND_DEVICE_IN_AANC_HANDSET_MIC)},
386 {TO_NAME_INDEX(SND_DEVICE_IN_QUAD_MIC)},
387 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_STEREO_DMIC)},
388 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_STEREO_DMIC)},
389 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_VI_FEEDBACK)},
390};
391
392#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
393#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
Naresh Tannirue3b18452014-03-04 14:44:27 +0530394
395static int set_echo_reference(struct mixer *mixer, const char* ec_ref)
396{
397 struct mixer_ctl *ctl;
398 const char *mixer_ctl_name = "EC_REF_RX";
399
400 ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name);
401 if (!ctl) {
402 ALOGE("%s: Could not get ctl for mixer cmd - %s",
403 __func__, mixer_ctl_name);
404 return -EINVAL;
405 }
406 ALOGV("Setting EC Reference: %s", ec_ref);
407 mixer_ctl_set_enum_by_string(ctl, ec_ref);
408 return 0;
409}
410
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530411static struct csd_data *open_csd_client()
412{
413 struct csd_data *csd = calloc(1, sizeof(struct csd_data));
414
415 csd->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
416 if (csd->csd_client == NULL) {
417 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
418 goto error;
419 } else {
420 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
421
422 csd->deinit = (deinit_t)dlsym(csd->csd_client,
423 "csd_client_deinit");
424 if (csd->deinit == NULL) {
425 ALOGE("%s: dlsym error %s for csd_client_deinit", __func__,
426 dlerror());
427 goto error;
428 }
429 csd->disable_device = (disable_device_t)dlsym(csd->csd_client,
430 "csd_client_disable_device");
431 if (csd->disable_device == NULL) {
432 ALOGE("%s: dlsym error %s for csd_client_disable_device",
433 __func__, dlerror());
434 goto error;
435 }
436 csd->enable_device_config = (enable_device_config_t)dlsym(csd->csd_client,
437 "csd_client_enable_device_config");
438 if (csd->enable_device_config == NULL) {
439 ALOGE("%s: dlsym error %s for csd_client_enable_device_config",
440 __func__, dlerror());
441 goto error;
442 }
443 csd->enable_device = (enable_device_t)dlsym(csd->csd_client,
444 "csd_client_enable_device");
445 if (csd->enable_device == NULL) {
446 ALOGE("%s: dlsym error %s for csd_client_enable_device",
447 __func__, dlerror());
448 goto error;
449 }
450 csd->start_voice = (start_voice_t)dlsym(csd->csd_client,
451 "csd_client_start_voice");
452 if (csd->start_voice == NULL) {
453 ALOGE("%s: dlsym error %s for csd_client_start_voice",
454 __func__, dlerror());
455 goto error;
456 }
457 csd->stop_voice = (stop_voice_t)dlsym(csd->csd_client,
458 "csd_client_stop_voice");
459 if (csd->stop_voice == NULL) {
460 ALOGE("%s: dlsym error %s for csd_client_stop_voice",
461 __func__, dlerror());
462 goto error;
463 }
464 csd->volume = (volume_t)dlsym(csd->csd_client,
465 "csd_client_volume");
466 if (csd->volume == NULL) {
467 ALOGE("%s: dlsym error %s for csd_client_volume",
468 __func__, dlerror());
469 goto error;
470 }
471 csd->mic_mute = (mic_mute_t)dlsym(csd->csd_client,
472 "csd_client_mic_mute");
473 if (csd->mic_mute == NULL) {
474 ALOGE("%s: dlsym error %s for csd_client_mic_mute",
475 __func__, dlerror());
476 goto error;
477 }
478 csd->slow_talk = (slow_talk_t)dlsym(csd->csd_client,
479 "csd_client_slow_talk");
480 if (csd->slow_talk == NULL) {
481 ALOGE("%s: dlsym error %s for csd_client_slow_talk",
482 __func__, dlerror());
483 goto error;
484 }
485 csd->start_playback = (start_playback_t)dlsym(csd->csd_client,
486 "csd_client_start_playback");
487 if (csd->start_playback == NULL) {
488 ALOGE("%s: dlsym error %s for csd_client_start_playback",
489 __func__, dlerror());
490 goto error;
491 }
492 csd->stop_playback = (stop_playback_t)dlsym(csd->csd_client,
493 "csd_client_stop_playback");
494 if (csd->stop_playback == NULL) {
495 ALOGE("%s: dlsym error %s for csd_client_stop_playback",
496 __func__, dlerror());
497 goto error;
498 }
499 csd->start_record = (start_record_t)dlsym(csd->csd_client,
500 "csd_client_start_record");
501 if (csd->start_record == NULL) {
502 ALOGE("%s: dlsym error %s for csd_client_start_record",
503 __func__, dlerror());
504 goto error;
505 }
506 csd->stop_record = (stop_record_t)dlsym(csd->csd_client,
507 "csd_client_stop_record");
508 if (csd->stop_record == NULL) {
509 ALOGE("%s: dlsym error %s for csd_client_stop_record",
510 __func__, dlerror());
511 goto error;
512 }
513 csd->init = (init_t)dlsym(csd->csd_client, "csd_client_init");
514
515 if (csd->init == NULL) {
516 ALOGE("%s: dlsym error %s for csd_client_init",
517 __func__, dlerror());
518 goto error;
519 } else {
520 csd->init();
521 }
522 }
523 return csd;
524
525error:
526 free(csd);
527 csd = NULL;
528 return csd;
529}
530
531void close_csd_client(struct csd_data *csd)
532{
533 if (csd != NULL) {
534 csd->deinit();
535 dlclose(csd->csd_client);
536 free(csd);
537 csd = NULL;
538 }
539}
540
Naresh Tannirue3b18452014-03-04 14:44:27 +0530541void *platform_init(struct audio_device *adev)
542{
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530543 char platform[PROPERTY_VALUE_MAX];
544 char baseband[PROPERTY_VALUE_MAX];
Naresh Tannirue3b18452014-03-04 14:44:27 +0530545 char value[PROPERTY_VALUE_MAX];
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530546 struct platform_data *my_data = NULL;
547 int retry_num = 0, snd_card_num = 0;
548 const char *snd_card_name;
Naresh Tannirue3b18452014-03-04 14:44:27 +0530549
550 my_data = calloc(1, sizeof(struct platform_data));
551
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530552 while (snd_card_num < MAX_SND_CARD) {
553 adev->mixer = mixer_open(snd_card_num);
554
555 while (!adev->mixer && retry_num < RETRY_NUMBER) {
556 usleep(RETRY_US);
557 adev->mixer = mixer_open(snd_card_num);
558 retry_num++;
559 }
560
561 if (!adev->mixer) {
562 ALOGE("%s: Unable to open the mixer card: %d", __func__,
563 snd_card_num);
564 retry_num = 0;
565 snd_card_num++;
566 continue;
567 }
568
569 snd_card_name = mixer_get_name(adev->mixer);
570 ALOGV("%s: snd_card_name: %s", __func__, snd_card_name);
571
572 my_data->hw_info = hw_info_init(snd_card_name);
573 if (!my_data->hw_info) {
574 ALOGE("%s: Failed to init hardware info", __func__);
575 } else {
576 if (audio_extn_read_xml(adev, snd_card_num, MIXER_XML_PATH,
577 MIXER_XML_PATH_AUXPCM) == -ENOSYS)
578 adev->audio_route = audio_route_init(snd_card_num,
579 MIXER_XML_PATH);
580 if (!adev->audio_route) {
581 ALOGE("%s: Failed to init audio route controls, aborting.",
582 __func__);
583 free(my_data);
584 return NULL;
585 }
586 adev->snd_card = snd_card_num;
587 ALOGD("%s: Opened sound card:%d", __func__, snd_card_num);
588 break;
589 }
590 retry_num = 0;
591 snd_card_num++;
592 }
593
594 if (snd_card_num >= MAX_SND_CARD) {
595 ALOGE("%s: Unable to find correct sound card, aborting.", __func__);
596 free(my_data);
597 return NULL;
598 }
599
Naresh Tannirue3b18452014-03-04 14:44:27 +0530600 my_data->adev = adev;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530601 my_data->btsco_sample_rate = SAMPLE_RATE_8KHZ;
Naresh Tannirue3b18452014-03-04 14:44:27 +0530602 my_data->fluence_in_spkr_mode = false;
603 my_data->fluence_in_voice_call = false;
604 my_data->fluence_in_voice_rec = false;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530605 my_data->fluence_in_audio_rec = false;
606 my_data->fluence_type = FLUENCE_NONE;
Naresh Tannirue3b18452014-03-04 14:44:27 +0530607
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530608 property_get("ro.qc.sdk.audio.fluencetype", value, "");
609 if (!strncmp("fluencepro", value, sizeof("fluencepro"))) {
610 my_data->fluence_type = FLUENCE_QUAD_MIC | FLUENCE_DUAL_MIC;
611 } else if (!strncmp("fluence", value, sizeof("fluence"))) {
612 my_data->fluence_type = FLUENCE_DUAL_MIC;
613 } else {
614 my_data->fluence_type = FLUENCE_NONE;
Naresh Tannirue3b18452014-03-04 14:44:27 +0530615 }
616
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530617 if (my_data->fluence_type != FLUENCE_NONE) {
Naresh Tannirue3b18452014-03-04 14:44:27 +0530618 property_get("persist.audio.fluence.voicecall",value,"");
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530619 if (!strncmp("true", value, sizeof("true"))) {
Naresh Tannirue3b18452014-03-04 14:44:27 +0530620 my_data->fluence_in_voice_call = true;
621 }
622
623 property_get("persist.audio.fluence.voicerec",value,"");
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530624 if (!strncmp("true", value, sizeof("true"))) {
Naresh Tannirue3b18452014-03-04 14:44:27 +0530625 my_data->fluence_in_voice_rec = true;
626 }
627
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530628 property_get("persist.audio.fluence.audiorec",value,"");
629 if (!strncmp("true", value, sizeof("true"))) {
630 my_data->fluence_in_audio_rec = true;
631 }
632
Naresh Tannirue3b18452014-03-04 14:44:27 +0530633 property_get("persist.audio.fluence.speaker",value,"");
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530634 if (!strncmp("true", value, sizeof("true"))) {
Naresh Tannirue3b18452014-03-04 14:44:27 +0530635 my_data->fluence_in_spkr_mode = true;
636 }
637 }
638
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530639 my_data->voice_feature_set = VOICE_FEATURE_SET_DEFAULT;
Naresh Tannirue3b18452014-03-04 14:44:27 +0530640 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
641 if (my_data->acdb_handle == NULL) {
642 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
643 } else {
644 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
645 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
646 "acdb_loader_deallocate_ACDB");
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530647 if (!my_data->acdb_deallocate)
648 ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s",
649 __func__, LIB_ACDB_LOADER);
650
Naresh Tannirue3b18452014-03-04 14:44:27 +0530651 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
652 "acdb_loader_send_audio_cal");
653 if (!my_data->acdb_send_audio_cal)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530654 ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530655 __func__, LIB_ACDB_LOADER);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530656
Naresh Tannirue3b18452014-03-04 14:44:27 +0530657 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
658 "acdb_loader_send_voice_cal");
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530659 if (!my_data->acdb_send_voice_cal)
660 ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s",
661 __func__, LIB_ACDB_LOADER);
662
663 my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle,
664 "acdb_loader_reload_vocvoltable");
665 if (!my_data->acdb_reload_vocvoltable)
666 ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s",
667 __func__, LIB_ACDB_LOADER);
668
Naresh Tannirue3b18452014-03-04 14:44:27 +0530669 my_data->acdb_init = (acdb_init_t)dlsym(my_data->acdb_handle,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530670 "acdb_loader_init_v2");
Naresh Tannirue3b18452014-03-04 14:44:27 +0530671 if (my_data->acdb_init == NULL)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530672 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__, dlerror());
Naresh Tannirue3b18452014-03-04 14:44:27 +0530673 else
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530674 my_data->acdb_init(snd_card_name);
Naresh Tannirue3b18452014-03-04 14:44:27 +0530675 }
676
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530677 /* Initialize ACDB ID's */
678 platform_info_init(PLATFORM_INFO_XML_PATH);
679
680 /* init usb */
681 audio_extn_usb_init(adev);
682 /* update sound cards appropriately */
683 audio_extn_usb_set_proxy_sound_card(adev->snd_card);
684
685 /* Read one time ssr property */
686 audio_extn_ssr_update_enabled();
687 audio_extn_spkr_prot_init(adev);
Naresh Tannirue3b18452014-03-04 14:44:27 +0530688 return my_data;
689}
690
691void platform_deinit(void *platform)
692{
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530693 struct platform_data *my_data = (struct platform_data *)platform;
694
695 hw_info_deinit(my_data->hw_info);
696 close_csd_client(my_data->csd);
697
Naresh Tannirue3b18452014-03-04 14:44:27 +0530698 free(platform);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530699 /* deinit usb */
700 audio_extn_usb_deinit();
Naresh Tannirue3b18452014-03-04 14:44:27 +0530701}
702
703const char *platform_get_snd_device_name(snd_device_t snd_device)
704{
705 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX)
706 return device_table[snd_device];
707 else
708 return "";
709}
710
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530711int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
712 char *device_name)
713{
714 struct platform_data *my_data = (struct platform_data *)platform;
715
716 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
717 strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE);
718 hw_info_append_hw_type(my_data->hw_info, snd_device, device_name);
719 } else {
720 strlcpy(device_name, "", DEVICE_NAME_MAX_SIZE);
721 return -EINVAL;
722 }
723
724 return 0;
725}
726
Naresh Tannirue3b18452014-03-04 14:44:27 +0530727void platform_add_backend_name(char *mixer_path, snd_device_t snd_device)
728{
729 if (snd_device == SND_DEVICE_IN_BT_SCO_MIC)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530730 strlcat(mixer_path, " bt-sco", MIXER_PATH_MAX_LENGTH);
731 else if (snd_device == SND_DEVICE_IN_BT_SCO_MIC_WB)
732 strlcat(mixer_path, " bt-sco-wb", MIXER_PATH_MAX_LENGTH);
Naresh Tannirue3b18452014-03-04 14:44:27 +0530733 else if(snd_device == SND_DEVICE_OUT_BT_SCO)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530734 strlcat(mixer_path, " bt-sco", MIXER_PATH_MAX_LENGTH);
735 else if(snd_device == SND_DEVICE_OUT_BT_SCO_WB)
736 strlcat(mixer_path, " bt-sco-wb", MIXER_PATH_MAX_LENGTH);
Naresh Tannirue3b18452014-03-04 14:44:27 +0530737 else if (snd_device == SND_DEVICE_OUT_HDMI)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530738 strlcat(mixer_path, " hdmi", MIXER_PATH_MAX_LENGTH);
Naresh Tannirue3b18452014-03-04 14:44:27 +0530739 else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HDMI)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530740 strlcat(mixer_path, " speaker-and-hdmi", MIXER_PATH_MAX_LENGTH);
741 else if (snd_device == SND_DEVICE_OUT_AFE_PROXY)
742 strlcat(mixer_path, " afe-proxy", MIXER_PATH_MAX_LENGTH);
743 else if (snd_device == SND_DEVICE_OUT_USB_HEADSET)
744 strlcat(mixer_path, " usb-headphones", MIXER_PATH_MAX_LENGTH);
745 else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET)
746 strlcat(mixer_path, " speaker-and-usb-headphones",
747 MIXER_PATH_MAX_LENGTH);
748 else if (snd_device == SND_DEVICE_IN_USB_HEADSET_MIC)
749 strlcat(mixer_path, " usb-headset-mic", MIXER_PATH_MAX_LENGTH);
750 else if (snd_device == SND_DEVICE_IN_CAPTURE_FM)
751 strlcat(mixer_path, " capture-fm", MIXER_PATH_MAX_LENGTH);
752 else if (snd_device == SND_DEVICE_OUT_TRANSMISSION_FM)
753 strlcat(mixer_path, " transmission-fm", MIXER_PATH_MAX_LENGTH);
Naresh Tannirue3b18452014-03-04 14:44:27 +0530754}
755
756int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
757{
758 int device_id;
759 if (device_type == PCM_PLAYBACK)
760 device_id = pcm_device_table[usecase][0];
761 else
762 device_id = pcm_device_table[usecase][1];
763 return device_id;
764}
765
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530766int platform_get_snd_device_index(char *snd_device_index_name)
767{
768 int ret = 0;
769 int i;
770
771 if (snd_device_index_name == NULL) {
772 ALOGE("%s: snd_device_index_name is NULL", __func__);
773 ret = -ENODEV;
774 goto done;
775 }
776
777 for (i=0; i < SND_DEVICE_MAX; i++) {
778 if(strcmp(snd_device_name_index[i].name, snd_device_index_name) == 0) {
779 ret = snd_device_name_index[i].index;
780 goto done;
781 }
782 }
783 ALOGE("%s: Could not find index for snd_device_index_name = %s",
784 __func__, snd_device_index_name);
785 ret = -ENODEV;
786done:
787 return ret;
788}
789
790int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
791{
792 int ret = 0;
793
794 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
795 ALOGE("%s: Invalid snd_device = %d",
796 __func__, snd_device);
797 ret = -EINVAL;
798 goto done;
799 }
800
801 acdb_device_table[snd_device] = acdb_id;
802done:
803 return ret;
804}
805
Naresh Tannirue3b18452014-03-04 14:44:27 +0530806int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
807{
808 struct platform_data *my_data = (struct platform_data *)platform;
809 int acdb_dev_id, acdb_dev_type;
810
811 acdb_dev_id = acdb_device_table[snd_device];
812 if (acdb_dev_id < 0) {
813 ALOGE("%s: Could not find acdb id for device(%d)",
814 __func__, snd_device);
815 return -EINVAL;
816 }
817 if (my_data->acdb_send_audio_cal) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530818 ("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530819 __func__, snd_device, acdb_dev_id);
820 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
821 snd_device < SND_DEVICE_OUT_END)
822 acdb_dev_type = ACDB_DEV_TYPE_OUT;
823 else
824 acdb_dev_type = ACDB_DEV_TYPE_IN;
825 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
826 }
827 return 0;
828}
829
830int platform_switch_voice_call_device_pre(void *platform)
831{
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530832 struct platform_data *my_data = (struct platform_data *)platform;
833 int ret = 0;
834
835 if (my_data->csd != NULL &&
836 my_data->adev->mode == AUDIO_MODE_IN_CALL) {
837 /* This must be called before disabling mixer controls on APQ side */
838 ret = my_data->csd->disable_device();
839 if (ret < 0) {
840 ALOGE("%s: csd_client_disable_device, failed, error %d",
841 __func__, ret);
842 }
843 }
844 return ret;
Naresh Tannirue3b18452014-03-04 14:44:27 +0530845}
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530846int platform_switch_voice_call_enable_device_config(void *platform,
847 snd_device_t out_snd_device,
848 snd_device_t in_snd_device)
849{
850 struct platform_data *my_data = (struct platform_data *)platform;
851 int acdb_rx_id, acdb_tx_id;
852 int ret = 0;
853
854 acdb_rx_id = acdb_device_table[out_snd_device];
855 acdb_tx_id = acdb_device_table[in_snd_device];
856
857 if (my_data->csd != NULL) {
858 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
859 ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
860 if (ret < 0) {
861 ALOGE("%s: csd_enable_device_config, failed, error %d",
862 __func__, ret);
863 }
864 } else {
865 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
866 acdb_rx_id, acdb_tx_id);
867 }
868 }
869 return ret;
870}
871
Naresh Tannirue3b18452014-03-04 14:44:27 +0530872
873int platform_switch_voice_call_device_post(void *platform,
874 snd_device_t out_snd_device,
875 snd_device_t in_snd_device)
876{
877 struct platform_data *my_data = (struct platform_data *)platform;
878 int acdb_rx_id, acdb_tx_id;
879
880 if (my_data->acdb_send_voice_cal == NULL) {
881 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
882 } else {
883 acdb_rx_id = acdb_device_table[out_snd_device];
884 acdb_tx_id = acdb_device_table[in_snd_device];
885
886 if (acdb_rx_id > 0 && acdb_tx_id > 0)
887 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
888 else
889 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
890 acdb_rx_id, acdb_tx_id);
891 }
892
893 return 0;
894}
895
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530896int platform_switch_voice_call_usecase_route_post(void *platform,
897 snd_device_t out_snd_device,
898 snd_device_t in_snd_device)
Naresh Tannirue3b18452014-03-04 14:44:27 +0530899{
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530900 struct platform_data *my_data = (struct platform_data *)platform;
901 int acdb_rx_id, acdb_tx_id;
902 int ret = 0;
903
904 acdb_rx_id = acdb_device_table[out_snd_device];
905 acdb_tx_id = acdb_device_table[in_snd_device];
906
907 if (my_data->csd != NULL) {
908 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
909 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
910 my_data->adev->acdb_settings);
911 if (ret < 0) {
912 ALOGE("%s: csd_enable_device, failed, error %d",
913 __func__, ret);
914 }
915 } else {
916 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
917 acdb_rx_id, acdb_tx_id);
918 }
919 }
920 return ret;
Naresh Tannirue3b18452014-03-04 14:44:27 +0530921}
922
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530923int platform_start_voice_call(void *platform, uint32_t vsid)
924{
925 struct platform_data *my_data = (struct platform_data *)platform;
926 int ret = 0;
927
928 if (my_data->csd != NULL) {
929 ret = my_data->csd->start_voice(vsid);
930 if (ret < 0) {
931 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
932 }
933 }
934 return ret;
935}
936
937int platform_stop_voice_call(void *platform, uint32_t vsid)
938{
939 struct platform_data *my_data = (struct platform_data *)platform;
940 int ret = 0;
941
942 if (my_data->csd != NULL) {
943 ret = my_data->csd->stop_voice(vsid);
944 if (ret < 0) {
945 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
946 }
947 }
948 return ret;
949}
950int platform_get_sample_rate(void *platform, uint32_t *rate)
Naresh Tannirue3b18452014-03-04 14:44:27 +0530951{
952 return 0;
953}
954
955int platform_set_voice_volume(void *platform, int volume)
956{
957 struct platform_data *my_data = (struct platform_data *)platform;
958 struct audio_device *adev = my_data->adev;
959 struct mixer_ctl *ctl;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530960 const char *mixer_ctl_name = "Voice Rx Gain";
961 int vol_index = 0, ret = 0;
962 uint32_t set_values[ ] = {0,
963 ALL_SESSION_VSID,
964 DEFAULT_VOLUME_RAMP_DURATION_MS};
Naresh Tannirue3b18452014-03-04 14:44:27 +0530965
966 // Voice volume levels are mapped to adsp volume levels as follows.
967 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
968 // But this values don't changed in kernel. So, below change is need.
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530969 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, MAX_VOL_INDEX);
970 set_values[0] = vol_index;
Naresh Tannirue3b18452014-03-04 14:44:27 +0530971
972 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
973 if (!ctl) {
974 ALOGE("%s: Could not get ctl for mixer cmd - %s",
975 __func__, mixer_ctl_name);
976 return -EINVAL;
977 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530978 ALOGV("Setting voice volume index: %d", set_values[0]);
979 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
Naresh Tannirue3b18452014-03-04 14:44:27 +0530980
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530981 if (my_data->csd != NULL) {
982 ret = my_data->csd->volume(ALL_SESSION_VSID, volume);
983 if (ret < 0) {
984 ALOGE("%s: csd_volume error %d", __func__, ret);
985 }
986 }
987 return ret;
Naresh Tannirue3b18452014-03-04 14:44:27 +0530988}
989
990int platform_set_mic_mute(void *platform, bool state)
991{
992 struct platform_data *my_data = (struct platform_data *)platform;
993 struct audio_device *adev = my_data->adev;
994 struct mixer_ctl *ctl;
995 const char *mixer_ctl_name = "Voice Tx Mute";
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530996 int ret = 0;
997 uint32_t set_values[ ] = {0,
998 ALL_SESSION_VSID,
999 DEFAULT_VOLUME_RAMP_DURATION_MS};
Naresh Tannirue3b18452014-03-04 14:44:27 +05301000
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301001 set_values[0] = state;
1002 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1003 if (!ctl) {
1004 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1005 __func__, mixer_ctl_name);
1006 return -EINVAL;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301007 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301008 ALOGV("Setting voice mute state: %d", state);
1009 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
Naresh Tannirue3b18452014-03-04 14:44:27 +05301010
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301011 if (my_data->csd != NULL) {
1012 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state);
1013 if (ret < 0) {
1014 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
1015 }
1016 }
1017 return ret;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301018}
1019
Shiv Maliyappanahallic6fd8ee2014-03-07 15:31:55 -08001020int platform_set_device_mute(void *platform, bool state, char *dir)
1021{
1022 struct platform_data *my_data = (struct platform_data *)platform;
1023 struct audio_device *adev = my_data->adev;
1024 struct mixer_ctl *ctl;
1025 char *mixer_ctl_name = NULL;
1026 int ret = 0;
1027 uint32_t set_values[ ] = {0,
1028 ALL_SESSION_VSID,
1029 0};
1030 if(dir == NULL) {
1031 ALOGE("%s: Invalid direction:%s", __func__, dir);
1032 return -EINVAL;
1033 }
1034
1035 if (!strncmp("rx", dir, sizeof("rx"))) {
1036 mixer_ctl_name = "Voice Rx Device Mute";
1037 } else if (!strncmp("tx", dir, sizeof("tx"))) {
1038 mixer_ctl_name = "Voice Tx Device Mute";
1039 } else {
1040 return -EINVAL;
1041 }
1042
1043 set_values[0] = state;
1044 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1045 if (!ctl) {
1046 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1047 __func__, mixer_ctl_name);
1048 return -EINVAL;
1049 }
1050
1051 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
1052 __func__,state, mixer_ctl_name);
1053 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1054
1055 return ret;
1056}
1057
Naresh Tannirue3b18452014-03-04 14:44:27 +05301058snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
1059{
1060 struct platform_data *my_data = (struct platform_data *)platform;
1061 struct audio_device *adev = my_data->adev;
1062 audio_mode_t mode = adev->mode;
1063 snd_device_t snd_device = SND_DEVICE_NONE;
1064
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301065 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
1066 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
1067 int channel_count = popcount(channel_mask);
1068
Naresh Tannirue3b18452014-03-04 14:44:27 +05301069 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
1070 if (devices == AUDIO_DEVICE_NONE ||
1071 devices & AUDIO_DEVICE_BIT_IN) {
1072 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
1073 goto exit;
1074 }
1075
Naresh Tannirue3b18452014-03-04 14:44:27 +05301076 if (popcount(devices) == 2) {
1077 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
1078 AUDIO_DEVICE_OUT_SPEAKER)) {
1079 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
1080 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
1081 AUDIO_DEVICE_OUT_SPEAKER)) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301082 if (audio_extn_get_anc_enabled())
1083 snd_device = SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET;
1084 else
1085 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301086 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
1087 AUDIO_DEVICE_OUT_SPEAKER)) {
1088 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301089 } else if (devices == (AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET |
1090 AUDIO_DEVICE_OUT_SPEAKER)) {
1091 snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301092 } else {
1093 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
1094 goto exit;
1095 }
1096 if (snd_device != SND_DEVICE_NONE) {
1097 goto exit;
1098 }
1099 }
1100
1101 if (popcount(devices) != 1) {
1102 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
1103 goto exit;
1104 }
1105
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301106 if ((mode == AUDIO_MODE_IN_CALL) ||
1107 voice_extn_compress_voip_is_active(adev)) {
1108 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1109 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
1110 if ((adev->voice.tty_mode != TTY_MODE_OFF) &&
1111 !voice_extn_compress_voip_is_active(adev)) {
1112 switch (adev->voice.tty_mode) {
1113 case TTY_MODE_FULL:
1114 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
1115 break;
1116 case TTY_MODE_VCO:
1117 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
1118 break;
1119 case TTY_MODE_HCO:
1120 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
1121 break;
1122 default:
1123 ALOGE("%s: Invalid TTY mode (%#x)",
1124 __func__, adev->voice.tty_mode);
1125 }
1126 } else if (audio_extn_get_anc_enabled()) {
1127 if (audio_extn_should_use_fb_anc())
1128 snd_device = SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET;
1129 else
1130 snd_device = SND_DEVICE_OUT_VOICE_ANC_HEADSET;
1131 } else {
1132 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
1133 }
1134 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
1135 if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ)
1136 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
1137 else
1138 snd_device = SND_DEVICE_OUT_BT_SCO;
1139 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
1140 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
1141 } else if (devices & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
1142 devices & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
1143 snd_device = SND_DEVICE_OUT_USB_HEADSET;
1144 } else if (devices & AUDIO_DEVICE_OUT_FM_TX) {
1145 snd_device = SND_DEVICE_OUT_TRANSMISSION_FM;
1146 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
1147 if (audio_extn_should_use_handset_anc(channel_count))
1148 snd_device = SND_DEVICE_OUT_ANC_HANDSET;
1149 else
1150 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
1151 }
1152 if (snd_device != SND_DEVICE_NONE) {
1153 goto exit;
1154 }
1155 }
1156
Naresh Tannirue3b18452014-03-04 14:44:27 +05301157 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1158 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301159 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADSET
1160 && audio_extn_get_anc_enabled()) {
1161 if (audio_extn_should_use_fb_anc())
1162 snd_device = SND_DEVICE_OUT_ANC_FB_HEADSET;
1163 else
1164 snd_device = SND_DEVICE_OUT_ANC_HEADSET;
1165 }
1166 else
1167 snd_device = SND_DEVICE_OUT_HEADPHONES;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301168 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
1169 if (adev->speaker_lr_swap)
1170 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
1171 else
1172 snd_device = SND_DEVICE_OUT_SPEAKER;
1173 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301174 if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ)
1175 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
1176 else
1177 snd_device = SND_DEVICE_OUT_BT_SCO;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301178 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
1179 snd_device = SND_DEVICE_OUT_HDMI ;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301180 } else if (devices & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
1181 devices & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
1182 snd_device = SND_DEVICE_OUT_USB_HEADSET;
1183 } else if (devices & AUDIO_DEVICE_OUT_FM_TX) {
1184 snd_device = SND_DEVICE_OUT_TRANSMISSION_FM;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301185 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
1186 snd_device = SND_DEVICE_OUT_HANDSET;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301187 } else if (devices & AUDIO_DEVICE_OUT_PROXY) {
1188 ALOGD("%s: setting sink capability for Proxy", __func__);
1189 audio_extn_set_afe_proxy_channel_mixer(adev);
1190 snd_device = SND_DEVICE_OUT_AFE_PROXY;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301191 } else {
1192 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
1193 }
1194exit:
1195 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
1196 return snd_device;
1197}
1198
1199snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
1200{
1201 struct platform_data *my_data = (struct platform_data *)platform;
1202 struct audio_device *adev = my_data->adev;
1203 audio_source_t source = (adev->active_input == NULL) ?
1204 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
1205
1206 audio_mode_t mode = adev->mode;
1207 audio_devices_t in_device = ((adev->active_input == NULL) ?
1208 AUDIO_DEVICE_NONE : adev->active_input->device)
1209 & ~AUDIO_DEVICE_BIT_IN;
1210 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
1211 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
1212 snd_device_t snd_device = SND_DEVICE_NONE;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301213 int channel_count = popcount(channel_mask);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301214
1215 ALOGV("%s: enter: out_device(%#x) in_device(%#x)",
1216 __func__, out_device, in_device);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301217 if ((out_device != AUDIO_DEVICE_NONE) && ((mode == AUDIO_MODE_IN_CALL) ||
1218 voice_extn_compress_voip_is_active(adev))) {
1219 if ((adev->voice.tty_mode != TTY_MODE_OFF) &&
1220 !voice_extn_compress_voip_is_active(adev)) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301221 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1222 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301223 switch (adev->voice.tty_mode) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301224 case TTY_MODE_FULL:
1225 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
1226 break;
1227 case TTY_MODE_VCO:
1228 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
1229 break;
1230 case TTY_MODE_HCO:
1231 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
1232 break;
1233 default:
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301234 ALOGE("%s: Invalid TTY mode (%#x)",
1235 __func__, adev->voice.tty_mode);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301236 }
1237 goto exit;
1238 }
1239 }
1240 if (out_device & AUDIO_DEVICE_OUT_EARPIECE ||
1241 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301242 if (out_device & AUDIO_DEVICE_OUT_EARPIECE &&
1243 audio_extn_should_use_handset_anc(channel_count)) {
1244 snd_device = SND_DEVICE_IN_AANC_HANDSET_MIC;
1245 } else if (my_data->fluence_type == FLUENCE_NONE ||
1246 my_data->fluence_in_voice_call == false) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301247 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301248 set_echo_reference(adev->mixer, EC_REF_RX);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301249 } else {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301250 snd_device = SND_DEVICE_IN_VOICE_DMIC;
1251 adev->acdb_settings |= DMIC_FLAG;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301252 }
1253 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
1254 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
1255 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301256 if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ)
1257 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
1258 else
1259 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301260 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301261 if (my_data->fluence_type != FLUENCE_NONE &&
1262 my_data->fluence_in_voice_call &&
1263 my_data->fluence_in_spkr_mode) {
1264 if(my_data->fluence_type & FLUENCE_QUAD_MIC) {
1265 adev->acdb_settings |= QMIC_FLAG;
1266 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_QMIC;
1267 } else {
1268 adev->acdb_settings |= DMIC_FLAG;
1269 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
1270 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05301271 } else {
1272 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
1273 }
1274 }
1275 } else if (source == AUDIO_SOURCE_CAMCORDER) {
1276 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
1277 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
1278 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
1279 }
1280 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
1281 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301282 if (channel_count == 2) {
1283 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
1284 adev->acdb_settings |= DMIC_FLAG;
1285 } else if (adev->active_input->enable_ns)
1286 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
1287 else if (my_data->fluence_type != FLUENCE_NONE &&
1288 my_data->fluence_in_voice_rec) {
1289 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
1290 adev->acdb_settings |= DMIC_FLAG;
1291 } else {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301292 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
1293 }
1294 }
1295 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION) {
1296 if (out_device & AUDIO_DEVICE_OUT_SPEAKER)
1297 in_device = AUDIO_DEVICE_IN_BACK_MIC;
1298 if (adev->active_input) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301299 if (adev->active_input->enable_aec &&
1300 adev->active_input->enable_ns) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301301 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301302 if (my_data->fluence_type & FLUENCE_DUAL_MIC &&
1303 my_data->fluence_in_spkr_mode) {
1304 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
1305 adev->acdb_settings |= DMIC_FLAG;
1306 } else
1307 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301308 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301309 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1310 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
1311 adev->acdb_settings |= DMIC_FLAG;
1312 } else
1313 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301314 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301315 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301316 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301317 set_echo_reference(adev->mixer, EC_REF_RX);
1318 } else if (adev->active_input->enable_aec) {
1319 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
1320 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1321 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
1322 adev->acdb_settings |= DMIC_FLAG;
1323 } else
1324 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
1325 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
1326 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1327 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
1328 adev->acdb_settings |= DMIC_FLAG;
1329 } else
1330 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
1331 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
1332 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
1333 }
1334 set_echo_reference(adev->mixer, EC_REF_RX);
1335 } else if (adev->active_input->enable_ns) {
1336 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
1337 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1338 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
1339 adev->acdb_settings |= DMIC_FLAG;
1340 } else
1341 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
1342 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
1343 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1344 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
1345 adev->acdb_settings |= DMIC_FLAG;
1346 } else
1347 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
1348 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
1349 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
1350 }
1351 set_echo_reference(adev->mixer, "NONE");
Naresh Tannirue3b18452014-03-04 14:44:27 +05301352 } else
1353 set_echo_reference(adev->mixer, "NONE");
1354 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301355 } else if (source == AUDIO_SOURCE_MIC) {
1356 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC &&
1357 channel_count == 1 ) {
1358 if(my_data->fluence_type & FLUENCE_DUAL_MIC &&
1359 my_data->fluence_in_audio_rec)
1360 snd_device = SND_DEVICE_IN_HANDSET_DMIC;
1361 }
1362 } else if (source == AUDIO_SOURCE_FM_RX ||
1363 source == AUDIO_SOURCE_FM_RX_A2DP) {
1364 snd_device = SND_DEVICE_IN_CAPTURE_FM;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301365 } else if (source == AUDIO_SOURCE_DEFAULT) {
1366 goto exit;
1367 }
1368
1369
1370 if (snd_device != SND_DEVICE_NONE) {
1371 goto exit;
1372 }
1373
1374 if (in_device != AUDIO_DEVICE_NONE &&
1375 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
1376 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
1377 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301378 if (audio_extn_ssr_get_enabled() && channel_count == 6)
1379 snd_device = SND_DEVICE_IN_QUAD_MIC;
1380 else if (channel_count == 2)
1381 snd_device = SND_DEVICE_IN_HANDSET_STEREO_DMIC;
1382 else
1383 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301384 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
1385 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
1386 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
1387 snd_device = SND_DEVICE_IN_HEADSET_MIC;
1388 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301389 if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ)
1390 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
1391 else
1392 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301393 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
1394 snd_device = SND_DEVICE_IN_HDMI_MIC;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301395 } else if (in_device & AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET ||
1396 in_device & AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET) {
1397 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
1398 } else if (in_device & AUDIO_DEVICE_IN_FM_RX) {
1399 snd_device = SND_DEVICE_IN_CAPTURE_FM;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301400 } else {
1401 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
1402 ALOGW("%s: Using default handset-mic", __func__);
1403 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1404 }
1405 } else {
1406 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
1407 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1408 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
1409 snd_device = SND_DEVICE_IN_HEADSET_MIC;
1410 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301411 if (channel_count > 1)
1412 snd_device = SND_DEVICE_IN_SPEAKER_STEREO_DMIC;
1413 else
1414 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301415 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
1416 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1417 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301418 if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ)
1419 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
1420 else
1421 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301422 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
1423 snd_device = SND_DEVICE_IN_HDMI_MIC;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301424 } else if (out_device & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
1425 out_device & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
1426 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301427 } else {
1428 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
1429 ALOGW("%s: Using default handset-mic", __func__);
1430 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1431 }
1432 }
1433exit:
1434 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
1435 return snd_device;
1436}
1437
1438int platform_set_hdmi_channels(void *platform, int channel_count)
1439{
1440 struct platform_data *my_data = (struct platform_data *)platform;
1441 struct audio_device *adev = my_data->adev;
1442 struct mixer_ctl *ctl;
1443 const char *channel_cnt_str = NULL;
1444 const char *mixer_ctl_name = "HDMI_RX Channels";
1445 switch (channel_count) {
1446 case 8:
1447 channel_cnt_str = "Eight"; break;
1448 case 7:
1449 channel_cnt_str = "Seven"; break;
1450 case 6:
1451 channel_cnt_str = "Six"; break;
1452 case 5:
1453 channel_cnt_str = "Five"; break;
1454 case 4:
1455 channel_cnt_str = "Four"; break;
1456 case 3:
1457 channel_cnt_str = "Three"; break;
1458 default:
1459 channel_cnt_str = "Two"; break;
1460 }
1461 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1462 if (!ctl) {
1463 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1464 __func__, mixer_ctl_name);
1465 return -EINVAL;
1466 }
1467 ALOGV("HDMI channel count: %s", channel_cnt_str);
1468 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
1469 return 0;
1470}
1471
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301472int platform_edid_get_max_channels(void *platform)
Naresh Tannirue3b18452014-03-04 14:44:27 +05301473{
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301474 struct platform_data *my_data = (struct platform_data *)platform;
1475 struct audio_device *adev = my_data->adev;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301476 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
1477 char *sad = block;
1478 int num_audio_blocks;
1479 int channel_count;
1480 int max_channels = 0;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301481 int i, ret, count;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301482
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301483 struct mixer_ctl *ctl;
1484
1485 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
1486 if (!ctl) {
1487 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1488 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301489 return 0;
1490 }
1491
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301492 mixer_ctl_update(ctl);
1493
1494 count = mixer_ctl_get_num_values(ctl);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301495
1496 /* Read SAD blocks, clamping the maximum size for safety */
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301497 if (count > (int)sizeof(block))
1498 count = (int)sizeof(block);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301499
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301500 ret = mixer_ctl_get_array(ctl, block, count);
1501 if (ret != 0) {
1502 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
1503 return 0;
1504 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05301505
1506 /* Calculate the number of SAD blocks */
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301507 num_audio_blocks = count / SAD_BLOCK_SIZE;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301508
1509 for (i = 0; i < num_audio_blocks; i++) {
1510 /* Only consider LPCM blocks */
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301511 if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
1512 sad += 3;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301513 continue;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301514 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05301515
1516 channel_count = (sad[0] & 0x7) + 1;
1517 if (channel_count > max_channels)
1518 max_channels = channel_count;
1519
1520 /* Advance to next block */
1521 sad += 3;
1522 }
1523
1524 return max_channels;
1525}
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301526
1527static int platform_set_slowtalk(struct platform_data *my_data, bool state)
1528{
1529 int ret = 0;
1530 struct audio_device *adev = my_data->adev;
1531 struct mixer_ctl *ctl;
1532 const char *mixer_ctl_name = "Slowtalk Enable";
1533 uint32_t set_values[ ] = {0,
1534 ALL_SESSION_VSID};
1535
1536 set_values[0] = state;
1537 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1538 if (!ctl) {
1539 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1540 __func__, mixer_ctl_name);
1541 ret = -EINVAL;
1542 } else {
1543 ALOGV("Setting slowtalk state: %d", state);
1544 ret = mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1545 my_data->slowtalk = state;
1546 }
1547
1548 if (my_data->csd != NULL) {
1549 ret = my_data->csd->slow_talk(ALL_SESSION_VSID, state);
1550 if (ret < 0) {
1551 ALOGE("%s: csd_client_disable_device, failed, error %d",
1552 __func__, ret);
1553 }
1554 }
1555 return ret;
1556}
1557
1558int platform_set_parameters(void *platform, struct str_parms *parms)
1559{
1560 struct platform_data *my_data = (struct platform_data *)platform;
1561 char *str;
1562 char value[256] = {0};
1563 int val;
1564 int ret = 0, err;
1565
1566 ALOGV("%s: enter: %s", __func__, str_parms_to_str(parms));
1567
1568 err = str_parms_get_int(parms, AUDIO_PARAMETER_KEY_BTSCO, &val);
1569 if (err >= 0) {
1570 str_parms_del(parms, AUDIO_PARAMETER_KEY_BTSCO);
1571 my_data->btsco_sample_rate = val;
1572 if (val == SAMPLE_RATE_16KHZ) {
1573 audio_route_apply_path(my_data->adev->audio_route,
1574 "bt-sco-wb-samplerate");
1575 audio_route_update_mixer(my_data->adev->audio_route);
1576 }
1577 }
1578
1579 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_SLOWTALK, value, sizeof(value));
1580 if (err >= 0) {
1581 bool state = false;
1582 if (!strncmp("true", value, sizeof("true"))) {
1583 state = true;
1584 }
1585
1586 str_parms_del(parms, AUDIO_PARAMETER_KEY_SLOWTALK);
1587 ret = platform_set_slowtalk(my_data, state);
1588 if (ret)
1589 ALOGE("%s: Failed to set slow talk err: %d", __func__, ret);
1590 }
1591
1592 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_VOLUME_BOOST,
1593 value, sizeof(value));
1594 if (err >= 0) {
1595 str_parms_del(parms, AUDIO_PARAMETER_KEY_VOLUME_BOOST);
1596
1597 if (my_data->acdb_reload_vocvoltable == NULL) {
1598 ALOGE("%s: acdb_reload_vocvoltable is NULL", __func__);
1599 } else if (!strcmp(value, "on")) {
1600 if (!my_data->acdb_reload_vocvoltable(VOICE_FEATURE_SET_VOLUME_BOOST)) {
1601 my_data->voice_feature_set = 1;
1602 }
1603 } else {
1604 if (!my_data->acdb_reload_vocvoltable(VOICE_FEATURE_SET_DEFAULT)) {
1605 my_data->voice_feature_set = 0;
1606 }
1607 }
1608 }
1609
1610 ALOGV("%s: exit with code(%d)", __func__, ret);
1611 return ret;
1612}
1613
1614int platform_set_incall_recording_session_id(void *platform,
1615 uint32_t session_id, int rec_mode)
1616{
1617 int ret = 0;
1618 struct platform_data *my_data = (struct platform_data *)platform;
1619 struct audio_device *adev = my_data->adev;
1620 struct mixer_ctl *ctl;
1621 const char *mixer_ctl_name = "Voc VSID";
1622 int num_ctl_values;
1623 int i;
1624
1625 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1626 if (!ctl) {
1627 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1628 __func__, mixer_ctl_name);
1629 ret = -EINVAL;
1630 } else {
1631 num_ctl_values = mixer_ctl_get_num_values(ctl);
1632 for (i = 0; i < num_ctl_values; i++) {
1633 if (mixer_ctl_set_value(ctl, i, session_id)) {
1634 ALOGV("Error: invalid session_id: %x", session_id);
1635 ret = -EINVAL;
1636 break;
1637 }
1638 }
1639 }
1640
1641 if (my_data->csd != NULL) {
1642 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
1643 if (ret < 0) {
1644 ALOGE("%s: csd_client_start_record failed, error %d",
1645 __func__, ret);
1646 }
1647 }
1648
1649 return ret;
1650}
1651
1652int platform_stop_incall_recording_usecase(void *platform)
1653{
1654 int ret = 0;
1655 struct platform_data *my_data = (struct platform_data *)platform;
1656
1657 if (my_data->csd != NULL) {
1658 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
1659 if (ret < 0) {
1660 ALOGE("%s: csd_client_stop_record failed, error %d",
1661 __func__, ret);
1662 }
1663 }
1664
1665 return ret;
1666}
1667
1668int platform_start_incall_music_usecase(void *platform)
1669{
1670 int ret = 0;
1671 struct platform_data *my_data = (struct platform_data *)platform;
1672
1673 if (my_data->csd != NULL) {
1674 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
1675 if (ret < 0) {
1676 ALOGE("%s: csd_client_start_playback failed, error %d",
1677 __func__, ret);
1678 }
1679 }
1680
1681 return ret;
1682}
1683
1684int platform_stop_incall_music_usecase(void *platform)
1685{
1686 int ret = 0;
1687 struct platform_data *my_data = (struct platform_data *)platform;
1688
1689 if (my_data->csd != NULL) {
1690 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
1691 if (ret < 0) {
1692 ALOGE("%s: csd_client_stop_playback failed, error %d",
1693 __func__, ret);
1694 }
1695 }
1696
1697 return ret;
1698}
1699
1700void platform_get_parameters(void *platform,
1701 struct str_parms *query,
1702 struct str_parms *reply)
1703{
1704 struct platform_data *my_data = (struct platform_data *)platform;
1705 char *str = NULL;
1706 char value[256] = {0};
1707 int ret;
1708 int fluence_type;
1709
1710 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_FLUENCE_TYPE,
1711 value, sizeof(value));
1712 if (ret >= 0) {
1713 if (my_data->fluence_type & FLUENCE_QUAD_MIC) {
1714 strlcpy(value, "fluencepro", sizeof(value));
1715 } else if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1716 strlcpy(value, "fluence", sizeof(value));
1717 } else {
1718 strlcpy(value, "none", sizeof(value));
1719 }
1720
1721 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_FLUENCE_TYPE, value);
1722 }
1723
1724 memset(value, 0, sizeof(value));
1725 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_SLOWTALK,
1726 value, sizeof(value));
1727 if (ret >= 0) {
1728 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_SLOWTALK,
1729 my_data->slowtalk?"true":"false");
1730 }
1731
1732 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_VOLUME_BOOST,
1733 value, sizeof(value));
1734 if (ret >= 0) {
1735 if (my_data->voice_feature_set == VOICE_FEATURE_SET_VOLUME_BOOST) {
1736 strlcpy(value, "on", sizeof(value));
1737 } else {
1738 strlcpy(value, "off", sizeof(value));
1739 }
1740
1741 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_VOLUME_BOOST, value);
1742 }
1743
1744 ALOGV("%s: exit: returns - %s", __func__, str_parms_to_str(reply));
1745}
1746
1747/* Delay in Us */
1748int64_t platform_render_latency(audio_usecase_t usecase)
1749{
1750 switch (usecase) {
1751 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
1752 return DEEP_BUFFER_PLATFORM_DELAY;
1753 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
1754 return LOW_LATENCY_PLATFORM_DELAY;
1755 default:
1756 return 0;
1757 }
1758}
1759
1760int platform_update_usecase_from_source(int source, int usecase)
1761{
1762 ALOGV("%s: input source :%d", __func__, source);
1763 if(source == AUDIO_SOURCE_FM_RX_A2DP)
1764 usecase = USECASE_AUDIO_RECORD_FM_VIRTUAL;
1765 return usecase;
1766}
1767
1768bool platform_listen_update_status(snd_device_t snd_device)
1769{
1770 if ((snd_device >= SND_DEVICE_IN_BEGIN) &&
1771 (snd_device < SND_DEVICE_IN_END) &&
1772 (snd_device != SND_DEVICE_IN_CAPTURE_FM) &&
1773 (snd_device != SND_DEVICE_IN_CAPTURE_VI_FEEDBACK))
1774 return true;
1775 else
1776 return false;
1777}
1778
1779/* Read offload buffer size from a property.
1780 * If value is not power of 2 round it to
1781 * power of 2.
1782 */
1783uint32_t platform_get_compress_offload_buffer_size(audio_offload_info_t* info)
1784{
1785 char value[PROPERTY_VALUE_MAX] = {0};
1786 uint32_t fragment_size = COMPRESS_OFFLOAD_FRAGMENT_SIZE;
1787 if((property_get("audio.offload.buffer.size.kb", value, "")) &&
1788 atoi(value)) {
1789 fragment_size = atoi(value) * 1024;
1790 }
1791
1792 if (info != NULL && info->has_video && info->is_streaming) {
1793 fragment_size = COMPRESS_OFFLOAD_FRAGMENT_SIZE_FOR_AV_STREAMING;
1794 ALOGV("%s: offload fragment size reduced for AV streaming to %d",
1795 __func__, out->compr_config.fragment_size);
1796 }
1797
1798 fragment_size = ALIGN( fragment_size, 1024);
1799
1800 if(fragment_size < MIN_COMPRESS_OFFLOAD_FRAGMENT_SIZE)
1801 fragment_size = MIN_COMPRESS_OFFLOAD_FRAGMENT_SIZE;
1802 else if(fragment_size > MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE)
1803 fragment_size = MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE;
1804 ALOGV("%s: fragment_size %d", __func__, fragment_size);
1805 return fragment_size;
1806}
1807
1808uint32_t platform_get_pcm_offload_buffer_size(audio_offload_info_t* info)
1809{
1810 uint32_t fragment_size = MIN_PCM_OFFLOAD_FRAGMENT_SIZE;
1811 uint32_t bits_per_sample = 16;
1812
1813 if (info->format == AUDIO_FORMAT_PCM_24_BIT_OFFLOAD) {
1814 bits_per_sample = 32;
1815 }
1816
1817 if (!info->has_video) {
1818 fragment_size = MAX_PCM_OFFLOAD_FRAGMENT_SIZE;
1819
1820 } else if (info->has_video && info->is_streaming) {
1821 fragment_size = (PCM_OFFLOAD_BUFFER_DURATION_FOR_AV_STREAMING
1822 * info->sample_rate
1823 * bits_per_sample
1824 * popcount(info->channel_mask))/1000;
1825
1826 } else if (info->has_video) {
1827 fragment_size = (PCM_OFFLOAD_BUFFER_DURATION_FOR_AV
1828 * info->sample_rate
1829 * bits_per_sample
1830 * popcount(info->channel_mask))/1000;
1831 }
1832
1833 fragment_size = ALIGN( fragment_size, 1024);
1834
1835 if(fragment_size < MIN_PCM_OFFLOAD_FRAGMENT_SIZE)
1836 fragment_size = MIN_PCM_OFFLOAD_FRAGMENT_SIZE;
1837 else if(fragment_size > MAX_PCM_OFFLOAD_FRAGMENT_SIZE)
1838 fragment_size = MAX_PCM_OFFLOAD_FRAGMENT_SIZE;
1839
1840 ALOGV("%s: fragment_size %d", __func__, fragment_size);
1841 return fragment_size;
1842}
1843