blob: 546b1fd9e72cae0af1ad74996141985c10ed881d [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) {
1144 snd_device = SND_DEVICE_OUT_USB_HEADSET;
1145 } else if (devices & AUDIO_DEVICE_OUT_FM_TX) {
1146 snd_device = SND_DEVICE_OUT_TRANSMISSION_FM;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301147 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
1148 snd_device = SND_DEVICE_OUT_HANDSET;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301149 } else if (devices & AUDIO_DEVICE_OUT_PROXY) {
1150 ALOGD("%s: setting sink capability for Proxy", __func__);
1151 audio_extn_set_afe_proxy_channel_mixer(adev);
1152 snd_device = SND_DEVICE_OUT_AFE_PROXY;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301153 } else {
1154 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
1155 }
1156exit:
1157 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
1158 return snd_device;
1159}
1160
1161snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
1162{
1163 struct platform_data *my_data = (struct platform_data *)platform;
1164 struct audio_device *adev = my_data->adev;
1165 audio_source_t source = (adev->active_input == NULL) ?
1166 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
1167
1168 audio_mode_t mode = adev->mode;
1169 audio_devices_t in_device = ((adev->active_input == NULL) ?
1170 AUDIO_DEVICE_NONE : adev->active_input->device)
1171 & ~AUDIO_DEVICE_BIT_IN;
1172 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
1173 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
1174 snd_device_t snd_device = SND_DEVICE_NONE;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301175 int channel_count = popcount(channel_mask);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301176
1177 ALOGV("%s: enter: out_device(%#x) in_device(%#x)",
1178 __func__, out_device, in_device);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301179 if ((out_device != AUDIO_DEVICE_NONE) && ((mode == AUDIO_MODE_IN_CALL) ||
1180 voice_extn_compress_voip_is_active(adev))) {
1181 if ((adev->voice.tty_mode != TTY_MODE_OFF) &&
1182 !voice_extn_compress_voip_is_active(adev)) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301183 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1184 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301185 switch (adev->voice.tty_mode) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301186 case TTY_MODE_FULL:
1187 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
1188 break;
1189 case TTY_MODE_VCO:
1190 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
1191 break;
1192 case TTY_MODE_HCO:
1193 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
1194 break;
1195 default:
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301196 ALOGE("%s: Invalid TTY mode (%#x)",
1197 __func__, adev->voice.tty_mode);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301198 }
1199 goto exit;
1200 }
1201 }
1202 if (out_device & AUDIO_DEVICE_OUT_EARPIECE ||
1203 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301204 if (out_device & AUDIO_DEVICE_OUT_EARPIECE &&
1205 audio_extn_should_use_handset_anc(channel_count)) {
1206 snd_device = SND_DEVICE_IN_AANC_HANDSET_MIC;
1207 } else if (my_data->fluence_type == FLUENCE_NONE ||
1208 my_data->fluence_in_voice_call == false) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301209 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301210 set_echo_reference(adev->mixer, EC_REF_RX);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301211 } else {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301212 snd_device = SND_DEVICE_IN_VOICE_DMIC;
1213 adev->acdb_settings |= DMIC_FLAG;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301214 }
1215 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
1216 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
1217 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301218 if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ)
1219 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
1220 else
1221 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301222 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301223 if (my_data->fluence_type != FLUENCE_NONE &&
1224 my_data->fluence_in_voice_call &&
1225 my_data->fluence_in_spkr_mode) {
1226 if(my_data->fluence_type & FLUENCE_QUAD_MIC) {
1227 adev->acdb_settings |= QMIC_FLAG;
1228 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_QMIC;
1229 } else {
1230 adev->acdb_settings |= DMIC_FLAG;
1231 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
1232 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05301233 } else {
1234 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
1235 }
1236 }
1237 } else if (source == AUDIO_SOURCE_CAMCORDER) {
1238 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
1239 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
1240 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
1241 }
1242 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
1243 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301244 if (channel_count == 2) {
1245 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
1246 adev->acdb_settings |= DMIC_FLAG;
1247 } else if (adev->active_input->enable_ns)
1248 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
1249 else if (my_data->fluence_type != FLUENCE_NONE &&
1250 my_data->fluence_in_voice_rec) {
1251 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
1252 adev->acdb_settings |= DMIC_FLAG;
1253 } else {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301254 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
1255 }
1256 }
1257 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION) {
1258 if (out_device & AUDIO_DEVICE_OUT_SPEAKER)
1259 in_device = AUDIO_DEVICE_IN_BACK_MIC;
1260 if (adev->active_input) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301261 if (adev->active_input->enable_aec &&
1262 adev->active_input->enable_ns) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301263 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301264 if (my_data->fluence_type & FLUENCE_DUAL_MIC &&
1265 my_data->fluence_in_spkr_mode) {
1266 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
1267 adev->acdb_settings |= DMIC_FLAG;
1268 } else
1269 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301270 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301271 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1272 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
1273 adev->acdb_settings |= DMIC_FLAG;
1274 } else
1275 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301276 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301277 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301278 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301279 set_echo_reference(adev->mixer, EC_REF_RX);
1280 } else if (adev->active_input->enable_aec) {
1281 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
1282 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1283 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
1284 adev->acdb_settings |= DMIC_FLAG;
1285 } else
1286 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
1287 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
1288 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1289 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
1290 adev->acdb_settings |= DMIC_FLAG;
1291 } else
1292 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
1293 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
1294 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
1295 }
1296 set_echo_reference(adev->mixer, EC_REF_RX);
1297 } else if (adev->active_input->enable_ns) {
1298 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
1299 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1300 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
1301 adev->acdb_settings |= DMIC_FLAG;
1302 } else
1303 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
1304 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
1305 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1306 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
1307 adev->acdb_settings |= DMIC_FLAG;
1308 } else
1309 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
1310 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
1311 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
1312 }
1313 set_echo_reference(adev->mixer, "NONE");
Naresh Tannirue3b18452014-03-04 14:44:27 +05301314 } else
1315 set_echo_reference(adev->mixer, "NONE");
1316 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301317 } else if (source == AUDIO_SOURCE_MIC) {
1318 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC &&
1319 channel_count == 1 ) {
1320 if(my_data->fluence_type & FLUENCE_DUAL_MIC &&
1321 my_data->fluence_in_audio_rec)
1322 snd_device = SND_DEVICE_IN_HANDSET_DMIC;
1323 }
1324 } else if (source == AUDIO_SOURCE_FM_RX ||
1325 source == AUDIO_SOURCE_FM_RX_A2DP) {
1326 snd_device = SND_DEVICE_IN_CAPTURE_FM;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301327 } else if (source == AUDIO_SOURCE_DEFAULT) {
1328 goto exit;
1329 }
1330
1331
1332 if (snd_device != SND_DEVICE_NONE) {
1333 goto exit;
1334 }
1335
1336 if (in_device != AUDIO_DEVICE_NONE &&
1337 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
1338 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
1339 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301340 if (audio_extn_ssr_get_enabled() && channel_count == 6)
1341 snd_device = SND_DEVICE_IN_QUAD_MIC;
1342 else if (channel_count == 2)
1343 snd_device = SND_DEVICE_IN_HANDSET_STEREO_DMIC;
1344 else
1345 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301346 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
1347 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
1348 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
1349 snd_device = SND_DEVICE_IN_HEADSET_MIC;
1350 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301351 if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ)
1352 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
1353 else
1354 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301355 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
1356 snd_device = SND_DEVICE_IN_HDMI_MIC;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301357 } else if (in_device & AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET ||
1358 in_device & AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET) {
1359 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
1360 } else if (in_device & AUDIO_DEVICE_IN_FM_RX) {
1361 snd_device = SND_DEVICE_IN_CAPTURE_FM;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301362 } else {
1363 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
1364 ALOGW("%s: Using default handset-mic", __func__);
1365 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1366 }
1367 } else {
1368 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
1369 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1370 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
1371 snd_device = SND_DEVICE_IN_HEADSET_MIC;
1372 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301373 if (channel_count > 1)
1374 snd_device = SND_DEVICE_IN_SPEAKER_STEREO_DMIC;
1375 else
1376 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301377 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
1378 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1379 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301380 if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ)
1381 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
1382 else
1383 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301384 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
1385 snd_device = SND_DEVICE_IN_HDMI_MIC;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301386 } else if (out_device & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
1387 out_device & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
1388 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301389 } else {
1390 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
1391 ALOGW("%s: Using default handset-mic", __func__);
1392 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1393 }
1394 }
1395exit:
1396 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
1397 return snd_device;
1398}
1399
1400int platform_set_hdmi_channels(void *platform, int channel_count)
1401{
1402 struct platform_data *my_data = (struct platform_data *)platform;
1403 struct audio_device *adev = my_data->adev;
1404 struct mixer_ctl *ctl;
1405 const char *channel_cnt_str = NULL;
1406 const char *mixer_ctl_name = "HDMI_RX Channels";
1407 switch (channel_count) {
1408 case 8:
1409 channel_cnt_str = "Eight"; break;
1410 case 7:
1411 channel_cnt_str = "Seven"; break;
1412 case 6:
1413 channel_cnt_str = "Six"; break;
1414 case 5:
1415 channel_cnt_str = "Five"; break;
1416 case 4:
1417 channel_cnt_str = "Four"; break;
1418 case 3:
1419 channel_cnt_str = "Three"; break;
1420 default:
1421 channel_cnt_str = "Two"; break;
1422 }
1423 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1424 if (!ctl) {
1425 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1426 __func__, mixer_ctl_name);
1427 return -EINVAL;
1428 }
1429 ALOGV("HDMI channel count: %s", channel_cnt_str);
1430 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
1431 return 0;
1432}
1433
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301434int platform_edid_get_max_channels(void *platform)
Naresh Tannirue3b18452014-03-04 14:44:27 +05301435{
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301436 struct platform_data *my_data = (struct platform_data *)platform;
1437 struct audio_device *adev = my_data->adev;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301438 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
1439 char *sad = block;
1440 int num_audio_blocks;
1441 int channel_count;
1442 int max_channels = 0;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301443 int i, ret, count;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301444
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301445 struct mixer_ctl *ctl;
1446
1447 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
1448 if (!ctl) {
1449 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1450 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301451 return 0;
1452 }
1453
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301454 mixer_ctl_update(ctl);
1455
1456 count = mixer_ctl_get_num_values(ctl);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301457
1458 /* Read SAD blocks, clamping the maximum size for safety */
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301459 if (count > (int)sizeof(block))
1460 count = (int)sizeof(block);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301461
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301462 ret = mixer_ctl_get_array(ctl, block, count);
1463 if (ret != 0) {
1464 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
1465 return 0;
1466 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05301467
1468 /* Calculate the number of SAD blocks */
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301469 num_audio_blocks = count / SAD_BLOCK_SIZE;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301470
1471 for (i = 0; i < num_audio_blocks; i++) {
1472 /* Only consider LPCM blocks */
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301473 if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
1474 sad += 3;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301475 continue;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301476 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05301477
1478 channel_count = (sad[0] & 0x7) + 1;
1479 if (channel_count > max_channels)
1480 max_channels = channel_count;
1481
1482 /* Advance to next block */
1483 sad += 3;
1484 }
1485
1486 return max_channels;
1487}
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301488
1489static int platform_set_slowtalk(struct platform_data *my_data, bool state)
1490{
1491 int ret = 0;
1492 struct audio_device *adev = my_data->adev;
1493 struct mixer_ctl *ctl;
1494 const char *mixer_ctl_name = "Slowtalk Enable";
1495 uint32_t set_values[ ] = {0,
1496 ALL_SESSION_VSID};
1497
1498 set_values[0] = state;
1499 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1500 if (!ctl) {
1501 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1502 __func__, mixer_ctl_name);
1503 ret = -EINVAL;
1504 } else {
1505 ALOGV("Setting slowtalk state: %d", state);
1506 ret = mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1507 my_data->slowtalk = state;
1508 }
1509
1510 if (my_data->csd != NULL) {
1511 ret = my_data->csd->slow_talk(ALL_SESSION_VSID, state);
1512 if (ret < 0) {
1513 ALOGE("%s: csd_client_disable_device, failed, error %d",
1514 __func__, ret);
1515 }
1516 }
1517 return ret;
1518}
1519
1520int platform_set_parameters(void *platform, struct str_parms *parms)
1521{
1522 struct platform_data *my_data = (struct platform_data *)platform;
1523 char *str;
1524 char value[256] = {0};
1525 int val;
1526 int ret = 0, err;
1527
1528 ALOGV("%s: enter: %s", __func__, str_parms_to_str(parms));
1529
1530 err = str_parms_get_int(parms, AUDIO_PARAMETER_KEY_BTSCO, &val);
1531 if (err >= 0) {
1532 str_parms_del(parms, AUDIO_PARAMETER_KEY_BTSCO);
1533 my_data->btsco_sample_rate = val;
1534 if (val == SAMPLE_RATE_16KHZ) {
1535 audio_route_apply_path(my_data->adev->audio_route,
1536 "bt-sco-wb-samplerate");
1537 audio_route_update_mixer(my_data->adev->audio_route);
1538 }
1539 }
1540
1541 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_SLOWTALK, value, sizeof(value));
1542 if (err >= 0) {
1543 bool state = false;
1544 if (!strncmp("true", value, sizeof("true"))) {
1545 state = true;
1546 }
1547
1548 str_parms_del(parms, AUDIO_PARAMETER_KEY_SLOWTALK);
1549 ret = platform_set_slowtalk(my_data, state);
1550 if (ret)
1551 ALOGE("%s: Failed to set slow talk err: %d", __func__, ret);
1552 }
1553
1554 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_VOLUME_BOOST,
1555 value, sizeof(value));
1556 if (err >= 0) {
1557 str_parms_del(parms, AUDIO_PARAMETER_KEY_VOLUME_BOOST);
1558
1559 if (my_data->acdb_reload_vocvoltable == NULL) {
1560 ALOGE("%s: acdb_reload_vocvoltable is NULL", __func__);
1561 } else if (!strcmp(value, "on")) {
1562 if (!my_data->acdb_reload_vocvoltable(VOICE_FEATURE_SET_VOLUME_BOOST)) {
1563 my_data->voice_feature_set = 1;
1564 }
1565 } else {
1566 if (!my_data->acdb_reload_vocvoltable(VOICE_FEATURE_SET_DEFAULT)) {
1567 my_data->voice_feature_set = 0;
1568 }
1569 }
1570 }
1571
1572 ALOGV("%s: exit with code(%d)", __func__, ret);
1573 return ret;
1574}
1575
1576int platform_set_incall_recording_session_id(void *platform,
1577 uint32_t session_id, int rec_mode)
1578{
1579 int ret = 0;
1580 struct platform_data *my_data = (struct platform_data *)platform;
1581 struct audio_device *adev = my_data->adev;
1582 struct mixer_ctl *ctl;
1583 const char *mixer_ctl_name = "Voc VSID";
1584 int num_ctl_values;
1585 int i;
1586
1587 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1588 if (!ctl) {
1589 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1590 __func__, mixer_ctl_name);
1591 ret = -EINVAL;
1592 } else {
1593 num_ctl_values = mixer_ctl_get_num_values(ctl);
1594 for (i = 0; i < num_ctl_values; i++) {
1595 if (mixer_ctl_set_value(ctl, i, session_id)) {
1596 ALOGV("Error: invalid session_id: %x", session_id);
1597 ret = -EINVAL;
1598 break;
1599 }
1600 }
1601 }
1602
1603 if (my_data->csd != NULL) {
1604 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
1605 if (ret < 0) {
1606 ALOGE("%s: csd_client_start_record failed, error %d",
1607 __func__, ret);
1608 }
1609 }
1610
1611 return ret;
1612}
1613
1614int platform_stop_incall_recording_usecase(void *platform)
1615{
1616 int ret = 0;
1617 struct platform_data *my_data = (struct platform_data *)platform;
1618
1619 if (my_data->csd != NULL) {
1620 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
1621 if (ret < 0) {
1622 ALOGE("%s: csd_client_stop_record failed, error %d",
1623 __func__, ret);
1624 }
1625 }
1626
1627 return ret;
1628}
1629
1630int platform_start_incall_music_usecase(void *platform)
1631{
1632 int ret = 0;
1633 struct platform_data *my_data = (struct platform_data *)platform;
1634
1635 if (my_data->csd != NULL) {
1636 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
1637 if (ret < 0) {
1638 ALOGE("%s: csd_client_start_playback failed, error %d",
1639 __func__, ret);
1640 }
1641 }
1642
1643 return ret;
1644}
1645
1646int platform_stop_incall_music_usecase(void *platform)
1647{
1648 int ret = 0;
1649 struct platform_data *my_data = (struct platform_data *)platform;
1650
1651 if (my_data->csd != NULL) {
1652 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
1653 if (ret < 0) {
1654 ALOGE("%s: csd_client_stop_playback failed, error %d",
1655 __func__, ret);
1656 }
1657 }
1658
1659 return ret;
1660}
1661
1662void platform_get_parameters(void *platform,
1663 struct str_parms *query,
1664 struct str_parms *reply)
1665{
1666 struct platform_data *my_data = (struct platform_data *)platform;
1667 char *str = NULL;
1668 char value[256] = {0};
1669 int ret;
1670 int fluence_type;
1671
1672 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_FLUENCE_TYPE,
1673 value, sizeof(value));
1674 if (ret >= 0) {
1675 if (my_data->fluence_type & FLUENCE_QUAD_MIC) {
1676 strlcpy(value, "fluencepro", sizeof(value));
1677 } else if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1678 strlcpy(value, "fluence", sizeof(value));
1679 } else {
1680 strlcpy(value, "none", sizeof(value));
1681 }
1682
1683 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_FLUENCE_TYPE, value);
1684 }
1685
1686 memset(value, 0, sizeof(value));
1687 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_SLOWTALK,
1688 value, sizeof(value));
1689 if (ret >= 0) {
1690 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_SLOWTALK,
1691 my_data->slowtalk?"true":"false");
1692 }
1693
1694 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_VOLUME_BOOST,
1695 value, sizeof(value));
1696 if (ret >= 0) {
1697 if (my_data->voice_feature_set == VOICE_FEATURE_SET_VOLUME_BOOST) {
1698 strlcpy(value, "on", sizeof(value));
1699 } else {
1700 strlcpy(value, "off", sizeof(value));
1701 }
1702
1703 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_VOLUME_BOOST, value);
1704 }
1705
1706 ALOGV("%s: exit: returns - %s", __func__, str_parms_to_str(reply));
1707}
1708
1709/* Delay in Us */
1710int64_t platform_render_latency(audio_usecase_t usecase)
1711{
1712 switch (usecase) {
1713 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
1714 return DEEP_BUFFER_PLATFORM_DELAY;
1715 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
1716 return LOW_LATENCY_PLATFORM_DELAY;
1717 default:
1718 return 0;
1719 }
1720}
1721
1722int platform_update_usecase_from_source(int source, int usecase)
1723{
1724 ALOGV("%s: input source :%d", __func__, source);
1725 if(source == AUDIO_SOURCE_FM_RX_A2DP)
1726 usecase = USECASE_AUDIO_RECORD_FM_VIRTUAL;
1727 return usecase;
1728}
1729
1730bool platform_listen_update_status(snd_device_t snd_device)
1731{
1732 if ((snd_device >= SND_DEVICE_IN_BEGIN) &&
1733 (snd_device < SND_DEVICE_IN_END) &&
1734 (snd_device != SND_DEVICE_IN_CAPTURE_FM) &&
1735 (snd_device != SND_DEVICE_IN_CAPTURE_VI_FEEDBACK))
1736 return true;
1737 else
1738 return false;
1739}
1740
1741/* Read offload buffer size from a property.
1742 * If value is not power of 2 round it to
1743 * power of 2.
1744 */
1745uint32_t platform_get_compress_offload_buffer_size(audio_offload_info_t* info)
1746{
1747 char value[PROPERTY_VALUE_MAX] = {0};
1748 uint32_t fragment_size = COMPRESS_OFFLOAD_FRAGMENT_SIZE;
1749 if((property_get("audio.offload.buffer.size.kb", value, "")) &&
1750 atoi(value)) {
1751 fragment_size = atoi(value) * 1024;
1752 }
1753
1754 if (info != NULL && info->has_video && info->is_streaming) {
1755 fragment_size = COMPRESS_OFFLOAD_FRAGMENT_SIZE_FOR_AV_STREAMING;
1756 ALOGV("%s: offload fragment size reduced for AV streaming to %d",
1757 __func__, out->compr_config.fragment_size);
1758 }
1759
1760 fragment_size = ALIGN( fragment_size, 1024);
1761
1762 if(fragment_size < MIN_COMPRESS_OFFLOAD_FRAGMENT_SIZE)
1763 fragment_size = MIN_COMPRESS_OFFLOAD_FRAGMENT_SIZE;
1764 else if(fragment_size > MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE)
1765 fragment_size = MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE;
1766 ALOGV("%s: fragment_size %d", __func__, fragment_size);
1767 return fragment_size;
1768}
1769
1770uint32_t platform_get_pcm_offload_buffer_size(audio_offload_info_t* info)
1771{
1772 uint32_t fragment_size = MIN_PCM_OFFLOAD_FRAGMENT_SIZE;
1773 uint32_t bits_per_sample = 16;
1774
1775 if (info->format == AUDIO_FORMAT_PCM_24_BIT_OFFLOAD) {
1776 bits_per_sample = 32;
1777 }
1778
1779 if (!info->has_video) {
1780 fragment_size = MAX_PCM_OFFLOAD_FRAGMENT_SIZE;
1781
1782 } else if (info->has_video && info->is_streaming) {
1783 fragment_size = (PCM_OFFLOAD_BUFFER_DURATION_FOR_AV_STREAMING
1784 * info->sample_rate
1785 * bits_per_sample
1786 * popcount(info->channel_mask))/1000;
1787
1788 } else if (info->has_video) {
1789 fragment_size = (PCM_OFFLOAD_BUFFER_DURATION_FOR_AV
1790 * info->sample_rate
1791 * bits_per_sample
1792 * popcount(info->channel_mask))/1000;
1793 }
1794
1795 fragment_size = ALIGN( fragment_size, 1024);
1796
1797 if(fragment_size < MIN_PCM_OFFLOAD_FRAGMENT_SIZE)
1798 fragment_size = MIN_PCM_OFFLOAD_FRAGMENT_SIZE;
1799 else if(fragment_size > MAX_PCM_OFFLOAD_FRAGMENT_SIZE)
1800 fragment_size = MAX_PCM_OFFLOAD_FRAGMENT_SIZE;
1801
1802 ALOGV("%s: fragment_size %d", __func__, fragment_size);
1803 return fragment_size;
1804}
1805