blob: d3dbea41b786b46155efa130208fe197b845bef5 [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
1020snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
1021{
1022 struct platform_data *my_data = (struct platform_data *)platform;
1023 struct audio_device *adev = my_data->adev;
1024 audio_mode_t mode = adev->mode;
1025 snd_device_t snd_device = SND_DEVICE_NONE;
1026
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301027 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
1028 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
1029 int channel_count = popcount(channel_mask);
1030
Naresh Tannirue3b18452014-03-04 14:44:27 +05301031 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
1032 if (devices == AUDIO_DEVICE_NONE ||
1033 devices & AUDIO_DEVICE_BIT_IN) {
1034 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
1035 goto exit;
1036 }
1037
Naresh Tannirue3b18452014-03-04 14:44:27 +05301038 if (popcount(devices) == 2) {
1039 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
1040 AUDIO_DEVICE_OUT_SPEAKER)) {
1041 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
1042 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
1043 AUDIO_DEVICE_OUT_SPEAKER)) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301044 if (audio_extn_get_anc_enabled())
1045 snd_device = SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET;
1046 else
1047 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301048 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
1049 AUDIO_DEVICE_OUT_SPEAKER)) {
1050 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301051 } else if (devices == (AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET |
1052 AUDIO_DEVICE_OUT_SPEAKER)) {
1053 snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301054 } else {
1055 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
1056 goto exit;
1057 }
1058 if (snd_device != SND_DEVICE_NONE) {
1059 goto exit;
1060 }
1061 }
1062
1063 if (popcount(devices) != 1) {
1064 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
1065 goto exit;
1066 }
1067
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301068 if ((mode == AUDIO_MODE_IN_CALL) ||
1069 voice_extn_compress_voip_is_active(adev)) {
1070 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1071 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
1072 if ((adev->voice.tty_mode != TTY_MODE_OFF) &&
1073 !voice_extn_compress_voip_is_active(adev)) {
1074 switch (adev->voice.tty_mode) {
1075 case TTY_MODE_FULL:
1076 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
1077 break;
1078 case TTY_MODE_VCO:
1079 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
1080 break;
1081 case TTY_MODE_HCO:
1082 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
1083 break;
1084 default:
1085 ALOGE("%s: Invalid TTY mode (%#x)",
1086 __func__, adev->voice.tty_mode);
1087 }
1088 } else if (audio_extn_get_anc_enabled()) {
1089 if (audio_extn_should_use_fb_anc())
1090 snd_device = SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET;
1091 else
1092 snd_device = SND_DEVICE_OUT_VOICE_ANC_HEADSET;
1093 } else {
1094 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
1095 }
1096 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
1097 if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ)
1098 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
1099 else
1100 snd_device = SND_DEVICE_OUT_BT_SCO;
1101 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
1102 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
1103 } else if (devices & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
1104 devices & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
1105 snd_device = SND_DEVICE_OUT_USB_HEADSET;
1106 } else if (devices & AUDIO_DEVICE_OUT_FM_TX) {
1107 snd_device = SND_DEVICE_OUT_TRANSMISSION_FM;
1108 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
1109 if (audio_extn_should_use_handset_anc(channel_count))
1110 snd_device = SND_DEVICE_OUT_ANC_HANDSET;
1111 else
1112 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
1113 }
1114 if (snd_device != SND_DEVICE_NONE) {
1115 goto exit;
1116 }
1117 }
1118
Naresh Tannirue3b18452014-03-04 14:44:27 +05301119 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1120 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301121 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADSET
1122 && audio_extn_get_anc_enabled()) {
1123 if (audio_extn_should_use_fb_anc())
1124 snd_device = SND_DEVICE_OUT_ANC_FB_HEADSET;
1125 else
1126 snd_device = SND_DEVICE_OUT_ANC_HEADSET;
1127 }
1128 else
1129 snd_device = SND_DEVICE_OUT_HEADPHONES;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301130 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
1131 if (adev->speaker_lr_swap)
1132 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
1133 else
1134 snd_device = SND_DEVICE_OUT_SPEAKER;
1135 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301136 if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ)
1137 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
1138 else
1139 snd_device = SND_DEVICE_OUT_BT_SCO;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301140 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
1141 snd_device = SND_DEVICE_OUT_HDMI ;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301142 } else if (devices & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
1143 devices & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
Mingming Yin5a7c5d62014-03-05 17:45:03 -08001144 ALOGD("%s: setting USB hadset channel capability(2) for Proxy", __func__);
1145 audio_extn_set_afe_proxy_channel_mixer(adev, 2);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301146 snd_device = SND_DEVICE_OUT_USB_HEADSET;
1147 } else if (devices & AUDIO_DEVICE_OUT_FM_TX) {
1148 snd_device = SND_DEVICE_OUT_TRANSMISSION_FM;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301149 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
1150 snd_device = SND_DEVICE_OUT_HANDSET;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301151 } else if (devices & AUDIO_DEVICE_OUT_PROXY) {
Mingming Yin5a7c5d62014-03-05 17:45:03 -08001152 channel_count = audio_extn_get_afe_proxy_channel_count();
1153 ALOGD("%s: setting sink capability(%d) for Proxy", __func__, channel_count);
1154 audio_extn_set_afe_proxy_channel_mixer(adev, channel_count);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301155 snd_device = SND_DEVICE_OUT_AFE_PROXY;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301156 } else {
1157 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
1158 }
1159exit:
1160 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
1161 return snd_device;
1162}
1163
1164snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
1165{
1166 struct platform_data *my_data = (struct platform_data *)platform;
1167 struct audio_device *adev = my_data->adev;
1168 audio_source_t source = (adev->active_input == NULL) ?
1169 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
1170
1171 audio_mode_t mode = adev->mode;
1172 audio_devices_t in_device = ((adev->active_input == NULL) ?
1173 AUDIO_DEVICE_NONE : adev->active_input->device)
1174 & ~AUDIO_DEVICE_BIT_IN;
1175 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
1176 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
1177 snd_device_t snd_device = SND_DEVICE_NONE;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301178 int channel_count = popcount(channel_mask);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301179
1180 ALOGV("%s: enter: out_device(%#x) in_device(%#x)",
1181 __func__, out_device, in_device);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301182 if ((out_device != AUDIO_DEVICE_NONE) && ((mode == AUDIO_MODE_IN_CALL) ||
1183 voice_extn_compress_voip_is_active(adev))) {
1184 if ((adev->voice.tty_mode != TTY_MODE_OFF) &&
1185 !voice_extn_compress_voip_is_active(adev)) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301186 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1187 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301188 switch (adev->voice.tty_mode) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301189 case TTY_MODE_FULL:
1190 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
1191 break;
1192 case TTY_MODE_VCO:
1193 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
1194 break;
1195 case TTY_MODE_HCO:
1196 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
1197 break;
1198 default:
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301199 ALOGE("%s: Invalid TTY mode (%#x)",
1200 __func__, adev->voice.tty_mode);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301201 }
1202 goto exit;
1203 }
1204 }
1205 if (out_device & AUDIO_DEVICE_OUT_EARPIECE ||
1206 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301207 if (out_device & AUDIO_DEVICE_OUT_EARPIECE &&
1208 audio_extn_should_use_handset_anc(channel_count)) {
1209 snd_device = SND_DEVICE_IN_AANC_HANDSET_MIC;
1210 } else if (my_data->fluence_type == FLUENCE_NONE ||
1211 my_data->fluence_in_voice_call == false) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301212 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301213 set_echo_reference(adev->mixer, EC_REF_RX);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301214 } else {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301215 snd_device = SND_DEVICE_IN_VOICE_DMIC;
1216 adev->acdb_settings |= DMIC_FLAG;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301217 }
1218 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
1219 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
1220 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301221 if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ)
1222 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
1223 else
1224 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301225 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301226 if (my_data->fluence_type != FLUENCE_NONE &&
1227 my_data->fluence_in_voice_call &&
1228 my_data->fluence_in_spkr_mode) {
1229 if(my_data->fluence_type & FLUENCE_QUAD_MIC) {
1230 adev->acdb_settings |= QMIC_FLAG;
1231 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_QMIC;
1232 } else {
1233 adev->acdb_settings |= DMIC_FLAG;
1234 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
1235 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05301236 } else {
1237 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
1238 }
1239 }
1240 } else if (source == AUDIO_SOURCE_CAMCORDER) {
1241 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
1242 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
1243 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
1244 }
1245 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
1246 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301247 if (channel_count == 2) {
1248 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
1249 adev->acdb_settings |= DMIC_FLAG;
1250 } else if (adev->active_input->enable_ns)
1251 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
1252 else if (my_data->fluence_type != FLUENCE_NONE &&
1253 my_data->fluence_in_voice_rec) {
1254 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
1255 adev->acdb_settings |= DMIC_FLAG;
1256 } else {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301257 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
1258 }
1259 }
1260 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION) {
1261 if (out_device & AUDIO_DEVICE_OUT_SPEAKER)
1262 in_device = AUDIO_DEVICE_IN_BACK_MIC;
1263 if (adev->active_input) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301264 if (adev->active_input->enable_aec &&
1265 adev->active_input->enable_ns) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301266 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301267 if (my_data->fluence_type & FLUENCE_DUAL_MIC &&
1268 my_data->fluence_in_spkr_mode) {
1269 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
1270 adev->acdb_settings |= DMIC_FLAG;
1271 } else
1272 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301273 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301274 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1275 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
1276 adev->acdb_settings |= DMIC_FLAG;
1277 } else
1278 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301279 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301280 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301281 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301282 set_echo_reference(adev->mixer, EC_REF_RX);
1283 } else if (adev->active_input->enable_aec) {
1284 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
1285 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1286 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
1287 adev->acdb_settings |= DMIC_FLAG;
1288 } else
1289 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
1290 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
1291 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1292 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
1293 adev->acdb_settings |= DMIC_FLAG;
1294 } else
1295 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
1296 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
1297 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
1298 }
1299 set_echo_reference(adev->mixer, EC_REF_RX);
1300 } else if (adev->active_input->enable_ns) {
1301 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
1302 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1303 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
1304 adev->acdb_settings |= DMIC_FLAG;
1305 } else
1306 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
1307 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
1308 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1309 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
1310 adev->acdb_settings |= DMIC_FLAG;
1311 } else
1312 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
1313 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
1314 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
1315 }
1316 set_echo_reference(adev->mixer, "NONE");
Naresh Tannirue3b18452014-03-04 14:44:27 +05301317 } else
1318 set_echo_reference(adev->mixer, "NONE");
1319 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301320 } else if (source == AUDIO_SOURCE_MIC) {
1321 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC &&
1322 channel_count == 1 ) {
1323 if(my_data->fluence_type & FLUENCE_DUAL_MIC &&
1324 my_data->fluence_in_audio_rec)
1325 snd_device = SND_DEVICE_IN_HANDSET_DMIC;
1326 }
1327 } else if (source == AUDIO_SOURCE_FM_RX ||
1328 source == AUDIO_SOURCE_FM_RX_A2DP) {
1329 snd_device = SND_DEVICE_IN_CAPTURE_FM;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301330 } else if (source == AUDIO_SOURCE_DEFAULT) {
1331 goto exit;
1332 }
1333
1334
1335 if (snd_device != SND_DEVICE_NONE) {
1336 goto exit;
1337 }
1338
1339 if (in_device != AUDIO_DEVICE_NONE &&
1340 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
1341 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
1342 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301343 if (audio_extn_ssr_get_enabled() && channel_count == 6)
1344 snd_device = SND_DEVICE_IN_QUAD_MIC;
1345 else if (channel_count == 2)
1346 snd_device = SND_DEVICE_IN_HANDSET_STEREO_DMIC;
1347 else
1348 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301349 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
1350 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
1351 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
1352 snd_device = SND_DEVICE_IN_HEADSET_MIC;
1353 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301354 if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ)
1355 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
1356 else
1357 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301358 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
1359 snd_device = SND_DEVICE_IN_HDMI_MIC;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301360 } else if (in_device & AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET ||
1361 in_device & AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET) {
1362 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
1363 } else if (in_device & AUDIO_DEVICE_IN_FM_RX) {
1364 snd_device = SND_DEVICE_IN_CAPTURE_FM;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301365 } else {
1366 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
1367 ALOGW("%s: Using default handset-mic", __func__);
1368 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1369 }
1370 } else {
1371 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
1372 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1373 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
1374 snd_device = SND_DEVICE_IN_HEADSET_MIC;
1375 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301376 if (channel_count > 1)
1377 snd_device = SND_DEVICE_IN_SPEAKER_STEREO_DMIC;
1378 else
1379 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301380 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
1381 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1382 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301383 if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ)
1384 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
1385 else
1386 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301387 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
1388 snd_device = SND_DEVICE_IN_HDMI_MIC;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301389 } else if (out_device & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
1390 out_device & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
1391 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301392 } else {
1393 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
1394 ALOGW("%s: Using default handset-mic", __func__);
1395 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1396 }
1397 }
1398exit:
1399 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
1400 return snd_device;
1401}
1402
1403int platform_set_hdmi_channels(void *platform, int channel_count)
1404{
1405 struct platform_data *my_data = (struct platform_data *)platform;
1406 struct audio_device *adev = my_data->adev;
1407 struct mixer_ctl *ctl;
1408 const char *channel_cnt_str = NULL;
1409 const char *mixer_ctl_name = "HDMI_RX Channels";
1410 switch (channel_count) {
1411 case 8:
1412 channel_cnt_str = "Eight"; break;
1413 case 7:
1414 channel_cnt_str = "Seven"; break;
1415 case 6:
1416 channel_cnt_str = "Six"; break;
1417 case 5:
1418 channel_cnt_str = "Five"; break;
1419 case 4:
1420 channel_cnt_str = "Four"; break;
1421 case 3:
1422 channel_cnt_str = "Three"; break;
1423 default:
1424 channel_cnt_str = "Two"; break;
1425 }
1426 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1427 if (!ctl) {
1428 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1429 __func__, mixer_ctl_name);
1430 return -EINVAL;
1431 }
1432 ALOGV("HDMI channel count: %s", channel_cnt_str);
1433 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
1434 return 0;
1435}
1436
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301437int platform_edid_get_max_channels(void *platform)
Naresh Tannirue3b18452014-03-04 14:44:27 +05301438{
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301439 struct platform_data *my_data = (struct platform_data *)platform;
1440 struct audio_device *adev = my_data->adev;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301441 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
1442 char *sad = block;
1443 int num_audio_blocks;
1444 int channel_count;
1445 int max_channels = 0;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301446 int i, ret, count;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301447
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301448 struct mixer_ctl *ctl;
1449
1450 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
1451 if (!ctl) {
1452 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1453 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301454 return 0;
1455 }
1456
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301457 mixer_ctl_update(ctl);
1458
1459 count = mixer_ctl_get_num_values(ctl);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301460
1461 /* Read SAD blocks, clamping the maximum size for safety */
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301462 if (count > (int)sizeof(block))
1463 count = (int)sizeof(block);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301464
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301465 ret = mixer_ctl_get_array(ctl, block, count);
1466 if (ret != 0) {
1467 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
1468 return 0;
1469 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05301470
1471 /* Calculate the number of SAD blocks */
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301472 num_audio_blocks = count / SAD_BLOCK_SIZE;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301473
1474 for (i = 0; i < num_audio_blocks; i++) {
1475 /* Only consider LPCM blocks */
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301476 if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
1477 sad += 3;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301478 continue;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301479 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05301480
1481 channel_count = (sad[0] & 0x7) + 1;
1482 if (channel_count > max_channels)
1483 max_channels = channel_count;
1484
1485 /* Advance to next block */
1486 sad += 3;
1487 }
1488
1489 return max_channels;
1490}
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301491
1492static int platform_set_slowtalk(struct platform_data *my_data, bool state)
1493{
1494 int ret = 0;
1495 struct audio_device *adev = my_data->adev;
1496 struct mixer_ctl *ctl;
1497 const char *mixer_ctl_name = "Slowtalk Enable";
1498 uint32_t set_values[ ] = {0,
1499 ALL_SESSION_VSID};
1500
1501 set_values[0] = state;
1502 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1503 if (!ctl) {
1504 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1505 __func__, mixer_ctl_name);
1506 ret = -EINVAL;
1507 } else {
1508 ALOGV("Setting slowtalk state: %d", state);
1509 ret = mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1510 my_data->slowtalk = state;
1511 }
1512
1513 if (my_data->csd != NULL) {
1514 ret = my_data->csd->slow_talk(ALL_SESSION_VSID, state);
1515 if (ret < 0) {
1516 ALOGE("%s: csd_client_disable_device, failed, error %d",
1517 __func__, ret);
1518 }
1519 }
1520 return ret;
1521}
1522
1523int platform_set_parameters(void *platform, struct str_parms *parms)
1524{
1525 struct platform_data *my_data = (struct platform_data *)platform;
1526 char *str;
1527 char value[256] = {0};
1528 int val;
1529 int ret = 0, err;
1530
1531 ALOGV("%s: enter: %s", __func__, str_parms_to_str(parms));
1532
1533 err = str_parms_get_int(parms, AUDIO_PARAMETER_KEY_BTSCO, &val);
1534 if (err >= 0) {
1535 str_parms_del(parms, AUDIO_PARAMETER_KEY_BTSCO);
1536 my_data->btsco_sample_rate = val;
1537 if (val == SAMPLE_RATE_16KHZ) {
1538 audio_route_apply_path(my_data->adev->audio_route,
1539 "bt-sco-wb-samplerate");
1540 audio_route_update_mixer(my_data->adev->audio_route);
1541 }
1542 }
1543
1544 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_SLOWTALK, value, sizeof(value));
1545 if (err >= 0) {
1546 bool state = false;
1547 if (!strncmp("true", value, sizeof("true"))) {
1548 state = true;
1549 }
1550
1551 str_parms_del(parms, AUDIO_PARAMETER_KEY_SLOWTALK);
1552 ret = platform_set_slowtalk(my_data, state);
1553 if (ret)
1554 ALOGE("%s: Failed to set slow talk err: %d", __func__, ret);
1555 }
1556
1557 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_VOLUME_BOOST,
1558 value, sizeof(value));
1559 if (err >= 0) {
1560 str_parms_del(parms, AUDIO_PARAMETER_KEY_VOLUME_BOOST);
1561
1562 if (my_data->acdb_reload_vocvoltable == NULL) {
1563 ALOGE("%s: acdb_reload_vocvoltable is NULL", __func__);
1564 } else if (!strcmp(value, "on")) {
1565 if (!my_data->acdb_reload_vocvoltable(VOICE_FEATURE_SET_VOLUME_BOOST)) {
1566 my_data->voice_feature_set = 1;
1567 }
1568 } else {
1569 if (!my_data->acdb_reload_vocvoltable(VOICE_FEATURE_SET_DEFAULT)) {
1570 my_data->voice_feature_set = 0;
1571 }
1572 }
1573 }
1574
1575 ALOGV("%s: exit with code(%d)", __func__, ret);
1576 return ret;
1577}
1578
1579int platform_set_incall_recording_session_id(void *platform,
1580 uint32_t session_id, int rec_mode)
1581{
1582 int ret = 0;
1583 struct platform_data *my_data = (struct platform_data *)platform;
1584 struct audio_device *adev = my_data->adev;
1585 struct mixer_ctl *ctl;
1586 const char *mixer_ctl_name = "Voc VSID";
1587 int num_ctl_values;
1588 int i;
1589
1590 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1591 if (!ctl) {
1592 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1593 __func__, mixer_ctl_name);
1594 ret = -EINVAL;
1595 } else {
1596 num_ctl_values = mixer_ctl_get_num_values(ctl);
1597 for (i = 0; i < num_ctl_values; i++) {
1598 if (mixer_ctl_set_value(ctl, i, session_id)) {
1599 ALOGV("Error: invalid session_id: %x", session_id);
1600 ret = -EINVAL;
1601 break;
1602 }
1603 }
1604 }
1605
1606 if (my_data->csd != NULL) {
1607 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
1608 if (ret < 0) {
1609 ALOGE("%s: csd_client_start_record failed, error %d",
1610 __func__, ret);
1611 }
1612 }
1613
1614 return ret;
1615}
1616
1617int platform_stop_incall_recording_usecase(void *platform)
1618{
1619 int ret = 0;
1620 struct platform_data *my_data = (struct platform_data *)platform;
1621
1622 if (my_data->csd != NULL) {
1623 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
1624 if (ret < 0) {
1625 ALOGE("%s: csd_client_stop_record failed, error %d",
1626 __func__, ret);
1627 }
1628 }
1629
1630 return ret;
1631}
1632
1633int platform_start_incall_music_usecase(void *platform)
1634{
1635 int ret = 0;
1636 struct platform_data *my_data = (struct platform_data *)platform;
1637
1638 if (my_data->csd != NULL) {
1639 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
1640 if (ret < 0) {
1641 ALOGE("%s: csd_client_start_playback failed, error %d",
1642 __func__, ret);
1643 }
1644 }
1645
1646 return ret;
1647}
1648
1649int platform_stop_incall_music_usecase(void *platform)
1650{
1651 int ret = 0;
1652 struct platform_data *my_data = (struct platform_data *)platform;
1653
1654 if (my_data->csd != NULL) {
1655 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
1656 if (ret < 0) {
1657 ALOGE("%s: csd_client_stop_playback failed, error %d",
1658 __func__, ret);
1659 }
1660 }
1661
1662 return ret;
1663}
1664
1665void platform_get_parameters(void *platform,
1666 struct str_parms *query,
1667 struct str_parms *reply)
1668{
1669 struct platform_data *my_data = (struct platform_data *)platform;
1670 char *str = NULL;
1671 char value[256] = {0};
1672 int ret;
1673 int fluence_type;
1674
1675 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_FLUENCE_TYPE,
1676 value, sizeof(value));
1677 if (ret >= 0) {
1678 if (my_data->fluence_type & FLUENCE_QUAD_MIC) {
1679 strlcpy(value, "fluencepro", sizeof(value));
1680 } else if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1681 strlcpy(value, "fluence", sizeof(value));
1682 } else {
1683 strlcpy(value, "none", sizeof(value));
1684 }
1685
1686 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_FLUENCE_TYPE, value);
1687 }
1688
1689 memset(value, 0, sizeof(value));
1690 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_SLOWTALK,
1691 value, sizeof(value));
1692 if (ret >= 0) {
1693 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_SLOWTALK,
1694 my_data->slowtalk?"true":"false");
1695 }
1696
1697 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_VOLUME_BOOST,
1698 value, sizeof(value));
1699 if (ret >= 0) {
1700 if (my_data->voice_feature_set == VOICE_FEATURE_SET_VOLUME_BOOST) {
1701 strlcpy(value, "on", sizeof(value));
1702 } else {
1703 strlcpy(value, "off", sizeof(value));
1704 }
1705
1706 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_VOLUME_BOOST, value);
1707 }
1708
1709 ALOGV("%s: exit: returns - %s", __func__, str_parms_to_str(reply));
1710}
1711
1712/* Delay in Us */
1713int64_t platform_render_latency(audio_usecase_t usecase)
1714{
1715 switch (usecase) {
1716 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
1717 return DEEP_BUFFER_PLATFORM_DELAY;
1718 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
1719 return LOW_LATENCY_PLATFORM_DELAY;
1720 default:
1721 return 0;
1722 }
1723}
1724
1725int platform_update_usecase_from_source(int source, int usecase)
1726{
1727 ALOGV("%s: input source :%d", __func__, source);
1728 if(source == AUDIO_SOURCE_FM_RX_A2DP)
1729 usecase = USECASE_AUDIO_RECORD_FM_VIRTUAL;
1730 return usecase;
1731}
1732
1733bool platform_listen_update_status(snd_device_t snd_device)
1734{
1735 if ((snd_device >= SND_DEVICE_IN_BEGIN) &&
1736 (snd_device < SND_DEVICE_IN_END) &&
1737 (snd_device != SND_DEVICE_IN_CAPTURE_FM) &&
1738 (snd_device != SND_DEVICE_IN_CAPTURE_VI_FEEDBACK))
1739 return true;
1740 else
1741 return false;
1742}
1743
1744/* Read offload buffer size from a property.
1745 * If value is not power of 2 round it to
1746 * power of 2.
1747 */
1748uint32_t platform_get_compress_offload_buffer_size(audio_offload_info_t* info)
1749{
1750 char value[PROPERTY_VALUE_MAX] = {0};
1751 uint32_t fragment_size = COMPRESS_OFFLOAD_FRAGMENT_SIZE;
1752 if((property_get("audio.offload.buffer.size.kb", value, "")) &&
1753 atoi(value)) {
1754 fragment_size = atoi(value) * 1024;
1755 }
1756
1757 if (info != NULL && info->has_video && info->is_streaming) {
1758 fragment_size = COMPRESS_OFFLOAD_FRAGMENT_SIZE_FOR_AV_STREAMING;
1759 ALOGV("%s: offload fragment size reduced for AV streaming to %d",
1760 __func__, out->compr_config.fragment_size);
1761 }
1762
1763 fragment_size = ALIGN( fragment_size, 1024);
1764
1765 if(fragment_size < MIN_COMPRESS_OFFLOAD_FRAGMENT_SIZE)
1766 fragment_size = MIN_COMPRESS_OFFLOAD_FRAGMENT_SIZE;
1767 else if(fragment_size > MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE)
1768 fragment_size = MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE;
1769 ALOGV("%s: fragment_size %d", __func__, fragment_size);
1770 return fragment_size;
1771}
1772
1773uint32_t platform_get_pcm_offload_buffer_size(audio_offload_info_t* info)
1774{
1775 uint32_t fragment_size = MIN_PCM_OFFLOAD_FRAGMENT_SIZE;
1776 uint32_t bits_per_sample = 16;
1777
1778 if (info->format == AUDIO_FORMAT_PCM_24_BIT_OFFLOAD) {
1779 bits_per_sample = 32;
1780 }
1781
1782 if (!info->has_video) {
1783 fragment_size = MAX_PCM_OFFLOAD_FRAGMENT_SIZE;
1784
1785 } else if (info->has_video && info->is_streaming) {
1786 fragment_size = (PCM_OFFLOAD_BUFFER_DURATION_FOR_AV_STREAMING
1787 * info->sample_rate
1788 * bits_per_sample
1789 * popcount(info->channel_mask))/1000;
1790
1791 } else if (info->has_video) {
1792 fragment_size = (PCM_OFFLOAD_BUFFER_DURATION_FOR_AV
1793 * info->sample_rate
1794 * bits_per_sample
1795 * popcount(info->channel_mask))/1000;
1796 }
1797
1798 fragment_size = ALIGN( fragment_size, 1024);
1799
1800 if(fragment_size < MIN_PCM_OFFLOAD_FRAGMENT_SIZE)
1801 fragment_size = MIN_PCM_OFFLOAD_FRAGMENT_SIZE;
1802 else if(fragment_size > MAX_PCM_OFFLOAD_FRAGMENT_SIZE)
1803 fragment_size = MAX_PCM_OFFLOAD_FRAGMENT_SIZE;
1804
1805 ALOGV("%s: fragment_size %d", __func__, fragment_size);
1806 return fragment_size;
1807}
1808