blob: 47f14e6bc345f2af6fe1a8395fe6c4a0ee9dfb52 [file] [log] [blame]
Eric Laurentb23d5282013-05-14 15:27:20 -07001/*
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -07002 * Copyright (c) 2013, The Linux Foundation. All rights reserved.
3 * Not a Contribution.
4 *
Eric Laurentb23d5282013-05-14 15:27:20 -07005 * 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
20#define LOG_TAG "msm8974_platform"
21/*#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>
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -070028#include <cutils/str_parms.h>
Eric Laurentb23d5282013-05-14 15:27:20 -070029#include <audio_hw.h>
30#include <platform_api.h>
31#include "platform.h"
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -070032#include "audio_extn.h"
Eric Laurentb23d5282013-05-14 15:27:20 -070033
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -070034#define MIXER_XML_PATH "/system/etc/mixer_paths.xml"
Damir Didjustof1d46c72013-11-06 17:59:04 -080035#define MIXER_XML_PATH_AUXPCM "/system/etc/mixer_paths_auxpcm.xml"
Eric Laurentb23d5282013-05-14 15:27:20 -070036#define LIB_ACDB_LOADER "libacdbloader.so"
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -070037#define AUDIO_DATA_BLOCK_MIXER_CTL "HDMI EDID"
Eric Laurentb23d5282013-05-14 15:27:20 -070038
Eric Laurentb23d5282013-05-14 15:27:20 -070039/*
Eric Laurentb23d5282013-05-14 15:27:20 -070040 * This file will have a maximum of 38 bytes:
41 *
42 * 4 bytes: number of audio blocks
43 * 4 bytes: total length of Short Audio Descriptor (SAD) blocks
44 * Maximum 10 * 3 bytes: SAD blocks
45 */
46#define MAX_SAD_BLOCKS 10
47#define SAD_BLOCK_SIZE 3
48
49/* EDID format ID for LPCM audio */
50#define EDID_FORMAT_LPCM 1
51
sangwoo1b9f4b32013-06-21 18:22:55 -070052/* Retry for delay in FW loading*/
53#define RETRY_NUMBER 10
54#define RETRY_US 500000
55
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -070056#define SAMPLE_RATE_8KHZ 8000
57#define SAMPLE_RATE_16KHZ 16000
58
sangwoo53b2cf02013-07-25 19:18:44 -070059#define MAX_VOL_INDEX 5
60#define MIN_VOL_INDEX 0
61#define percent_to_index(val, min, max) \
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -070062 ((val) * ((max) - (min)) * 0.01 + (min) + .5)
63
64#define AUDIO_PARAMETER_KEY_FLUENCE_TYPE "fluence"
65#define AUDIO_PARAMETER_KEY_BTSCO "bt_samplerate"
66#define AUDIO_PARAMETER_KEY_SLOWTALK "st_enable"
sangwoo53b2cf02013-07-25 19:18:44 -070067
Eric Laurentb23d5282013-05-14 15:27:20 -070068struct audio_block_header
69{
70 int reserved;
71 int length;
72};
73
74typedef void (*acdb_deallocate_t)();
75typedef int (*acdb_init_t)();
76typedef void (*acdb_send_audio_cal_t)(int, int);
77typedef void (*acdb_send_voice_cal_t)(int, int);
78
Eric Laurentb23d5282013-05-14 15:27:20 -070079struct platform_data {
80 struct audio_device *adev;
81 bool fluence_in_spkr_mode;
82 bool fluence_in_voice_call;
83 bool fluence_in_voice_rec;
Mingming Yin8e5a4f62013-10-07 15:23:41 -070084 int fluence_type;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -070085 int btsco_sample_rate;
86 bool slowtalk;
Eric Laurentb23d5282013-05-14 15:27:20 -070087
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -070088 /* Audio calibration related functions */
Eric Laurentb23d5282013-05-14 15:27:20 -070089 void *acdb_handle;
90 acdb_init_t acdb_init;
91 acdb_deallocate_t acdb_deallocate;
92 acdb_send_audio_cal_t acdb_send_audio_cal;
93 acdb_send_voice_cal_t acdb_send_voice_cal;
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -070094
95 void *hw_info;
Eric Laurentb23d5282013-05-14 15:27:20 -070096};
97
98static const int pcm_device_table[AUDIO_USECASE_MAX][2] = {
Mingming Yin8e5a4f62013-10-07 15:23:41 -070099 [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = {DEEP_BUFFER_PCM_DEVICE,
100 DEEP_BUFFER_PCM_DEVICE},
101 [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
Preetam Singh Ranawatde84f1a2013-11-01 14:58:16 -0700102 LOWLATENCY_PCM_DEVICE},
103 [USECASE_AUDIO_PLAYBACK_MULTI_CH] = {MULTIMEDIA2_PCM_DEVICE,
104 MULTIMEDIA2_PCM_DEVICE},
Krishnankutty Kolathappillya43f96e2013-11-01 12:17:53 -0700105 [USECASE_AUDIO_PLAYBACK_OFFLOAD] =
106 {PLAYBACK_OFFLOAD_DEVICE, PLAYBACK_OFFLOAD_DEVICE},
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700107 [USECASE_AUDIO_RECORD] = {AUDIO_RECORD_PCM_DEVICE, AUDIO_RECORD_PCM_DEVICE},
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700108 [USECASE_AUDIO_RECORD_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
109 LOWLATENCY_PCM_DEVICE},
Preetam Singh Ranawatde84f1a2013-11-01 14:58:16 -0700110 [USECASE_AUDIO_RECORD_FM_VIRTUAL] = {MULTIMEDIA2_PCM_DEVICE,
111 MULTIMEDIA2_PCM_DEVICE},
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -0700112 [USECASE_AUDIO_PLAYBACK_FM] = {FM_PLAYBACK_PCM_DEVICE, FM_CAPTURE_PCM_DEVICE},
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700113 [USECASE_VOICE_CALL] = {VOICE_CALL_PCM_DEVICE, VOICE_CALL_PCM_DEVICE},
114 [USECASE_VOICE2_CALL] = {VOICE2_CALL_PCM_DEVICE, VOICE2_CALL_PCM_DEVICE},
115 [USECASE_VOLTE_CALL] = {VOLTE_CALL_PCM_DEVICE, VOLTE_CALL_PCM_DEVICE},
116 [USECASE_QCHAT_CALL] = {QCHAT_CALL_PCM_DEVICE, QCHAT_CALL_PCM_DEVICE},
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700117 [USECASE_INCALL_REC_UPLINK] = {AUDIO_RECORD_PCM_DEVICE,
118 AUDIO_RECORD_PCM_DEVICE},
119 [USECASE_INCALL_REC_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
120 AUDIO_RECORD_PCM_DEVICE},
121 [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
122 AUDIO_RECORD_PCM_DEVICE},
Shiv Maliyappanahallif3b9a422013-10-22 16:38:08 -0700123 [USECASE_INCALL_MUSIC_UPLINK] = {INCALL_MUSIC_UPLINK_PCM_DEVICE,
124 INCALL_MUSIC_UPLINK_PCM_DEVICE},
125 [USECASE_INCALL_MUSIC_UPLINK2] = {INCALL_MUSIC_UPLINK2_PCM_DEVICE,
126 INCALL_MUSIC_UPLINK2_PCM_DEVICE},
Eric Laurentb23d5282013-05-14 15:27:20 -0700127};
128
129/* Array to store sound devices */
130static const char * const device_table[SND_DEVICE_MAX] = {
131 [SND_DEVICE_NONE] = "none",
132 /* Playback sound devices */
133 [SND_DEVICE_OUT_HANDSET] = "handset",
134 [SND_DEVICE_OUT_SPEAKER] = "speaker",
135 [SND_DEVICE_OUT_SPEAKER_REVERSE] = "speaker-reverse",
136 [SND_DEVICE_OUT_HEADPHONES] = "headphones",
137 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones",
138 [SND_DEVICE_OUT_VOICE_HANDSET] = "voice-handset",
139 [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker",
140 [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones",
141 [SND_DEVICE_OUT_HDMI] = "hdmi",
142 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi",
143 [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset",
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700144 [SND_DEVICE_OUT_BT_SCO_WB] = "bt-sco-headset-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700145 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = "voice-handset-tmus",
146 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones",
147 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones",
148 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset",
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -0700149 [SND_DEVICE_OUT_AFE_PROXY] = "afe-proxy",
150 [SND_DEVICE_OUT_USB_HEADSET] = "usb-headphones",
151 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = "speaker-and-usb-headphones",
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -0700152 [SND_DEVICE_OUT_TRANSMISSION_FM] = "transmission-fm",
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700153 [SND_DEVICE_OUT_ANC_HEADSET] = "anc-headphones",
154 [SND_DEVICE_OUT_ANC_FB_HEADSET] = "anc-fb-headphones",
155 [SND_DEVICE_OUT_VOICE_ANC_HEADSET] = "voice-anc-headphones",
156 [SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET] = "voice-anc-fb-headphones",
157 [SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET] = "speaker-and-anc-headphones",
158 [SND_DEVICE_OUT_ANC_HANDSET] = "anc-handset",
Eric Laurentb23d5282013-05-14 15:27:20 -0700159
160 /* Capture sound devices */
161 [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
162 [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
163 [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
164 [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic",
165 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "voice-speaker-mic",
166 [SND_DEVICE_IN_HEADSET_MIC_AEC] = "headset-mic",
167 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
168 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
169 [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic",
170 [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700171 [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700172 [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic",
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700173 [SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef",
174 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = "voice-dmic-ef-tmus",
175 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = "voice-speaker-dmic-ef",
Eric Laurentb23d5282013-05-14 15:27:20 -0700176 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
177 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
178 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
179 [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700180 [SND_DEVICE_IN_VOICE_REC_DMIC] = "voice-rec-dmic-ef",
181 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence",
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -0700182 [SND_DEVICE_IN_USB_HEADSET_MIC] = "usb-headset-mic",
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -0700183 [SND_DEVICE_IN_CAPTURE_FM] = "capture-fm",
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700184 [SND_DEVICE_IN_AANC_HANDSET_MIC] = "aanc-handset-mic",
Apoorv Raghuvanshi6178a3f2013-10-19 12:38:54 -0700185 [SND_DEVICE_IN_QUAD_MIC] = "quad-mic",
Apoorv Raghuvanshi6bd8dbf2013-10-19 18:37:52 -0700186 [SND_DEVICE_IN_HANDSET_STEREO_DMIC] = "handset-stereo-dmic-ef",
187 [SND_DEVICE_IN_SPEAKER_STEREO_DMIC] = "speaker-stereo-dmic-ef",
Eric Laurentb23d5282013-05-14 15:27:20 -0700188};
189
190/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
191static const int acdb_device_table[SND_DEVICE_MAX] = {
192 [SND_DEVICE_NONE] = -1,
193 [SND_DEVICE_OUT_HANDSET] = 7,
194 [SND_DEVICE_OUT_SPEAKER] = 15,
195 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 15,
196 [SND_DEVICE_OUT_HEADPHONES] = 10,
197 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
198 [SND_DEVICE_OUT_VOICE_HANDSET] = 7,
199 [SND_DEVICE_OUT_VOICE_SPEAKER] = 15,
200 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
201 [SND_DEVICE_OUT_HDMI] = 18,
202 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 15,
203 [SND_DEVICE_OUT_BT_SCO] = 22,
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700204 [SND_DEVICE_OUT_BT_SCO_WB] = 39,
sangwooc69476f2013-07-26 16:57:26 -0700205 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = 88,
Eric Laurentb23d5282013-05-14 15:27:20 -0700206 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
207 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
208 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -0700209 [SND_DEVICE_OUT_AFE_PROXY] = 0,
210 [SND_DEVICE_OUT_USB_HEADSET] = 0,
211 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = 14,
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -0700212 [SND_DEVICE_OUT_TRANSMISSION_FM] = 0,
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700213 [SND_DEVICE_OUT_ANC_HEADSET] = 26,
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -0700214 [SND_DEVICE_OUT_ANC_FB_HEADSET] = 27,
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700215 [SND_DEVICE_OUT_VOICE_ANC_HEADSET] = 26,
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -0700216 [SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET] = 27,
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700217 [SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET] = 26,
218 [SND_DEVICE_OUT_ANC_HANDSET] = 103,
Eric Laurentb23d5282013-05-14 15:27:20 -0700219
220 [SND_DEVICE_IN_HANDSET_MIC] = 4,
221 [SND_DEVICE_IN_SPEAKER_MIC] = 4, /* ToDo: Check if this needs to changed to 11 */
222 [SND_DEVICE_IN_HEADSET_MIC] = 8,
223 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 40,
224 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 42,
225 [SND_DEVICE_IN_HEADSET_MIC_AEC] = 47,
226 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
227 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = 8,
228 [SND_DEVICE_IN_HDMI_MIC] = 4,
229 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700230 [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38,
Eric Laurentb23d5282013-05-14 15:27:20 -0700231 [SND_DEVICE_IN_CAMCORDER_MIC] = 61,
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700232 [SND_DEVICE_IN_VOICE_DMIC] = 41,
233 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = 89,
234 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 43,
Eric Laurentb23d5282013-05-14 15:27:20 -0700235 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
236 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
237 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
238 [SND_DEVICE_IN_VOICE_REC_MIC] = 62,
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -0700239 [SND_DEVICE_IN_USB_HEADSET_MIC] = 44,
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -0700240 [SND_DEVICE_IN_CAPTURE_FM] = 0,
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700241 [SND_DEVICE_IN_AANC_HANDSET_MIC] = 104,
Apoorv Raghuvanshi6178a3f2013-10-19 12:38:54 -0700242 [SND_DEVICE_IN_QUAD_MIC] = 46,
Apoorv Raghuvanshi6bd8dbf2013-10-19 18:37:52 -0700243 [SND_DEVICE_IN_HANDSET_STEREO_DMIC] = 34,
244 [SND_DEVICE_IN_SPEAKER_STEREO_DMIC] = 35,
Eric Laurentb23d5282013-05-14 15:27:20 -0700245 /* TODO: Update with proper acdb ids */
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700246 [SND_DEVICE_IN_VOICE_REC_DMIC] = 62,
247 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 6,
Eric Laurentb23d5282013-05-14 15:27:20 -0700248};
249
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700250#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
251#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
252
Eric Laurentb23d5282013-05-14 15:27:20 -0700253static pthread_once_t check_op_once_ctl = PTHREAD_ONCE_INIT;
254static bool is_tmus = false;
255
256static void check_operator()
257{
258 char value[PROPERTY_VALUE_MAX];
259 int mccmnc;
260 property_get("gsm.sim.operator.numeric",value,"0");
261 mccmnc = atoi(value);
262 ALOGD("%s: tmus mccmnc %d", __func__, mccmnc);
263 switch(mccmnc) {
264 /* TMUS MCC(310), MNC(490, 260, 026) */
265 case 310490:
266 case 310260:
267 case 310026:
sangwon.jeonb891db52013-09-14 17:39:15 +0900268 /* Add new TMUS MNC(800, 660, 580, 310, 270, 250, 240, 230, 220, 210, 200, 160) */
269 case 310800:
270 case 310660:
271 case 310580:
272 case 310310:
273 case 310270:
274 case 310250:
275 case 310240:
276 case 310230:
277 case 310220:
278 case 310210:
279 case 310200:
280 case 310160:
Eric Laurentb23d5282013-05-14 15:27:20 -0700281 is_tmus = true;
282 break;
283 }
284}
285
286bool is_operator_tmus()
287{
288 pthread_once(&check_op_once_ctl, check_operator);
289 return is_tmus;
290}
291
292static int set_echo_reference(struct mixer *mixer, const char* ec_ref)
293{
294 struct mixer_ctl *ctl;
295 const char *mixer_ctl_name = "EC_REF_RX";
296
297 ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name);
298 if (!ctl) {
299 ALOGE("%s: Could not get ctl for mixer cmd - %s",
300 __func__, mixer_ctl_name);
301 return -EINVAL;
302 }
303 ALOGV("Setting EC Reference: %s", ec_ref);
304 mixer_ctl_set_enum_by_string(ctl, ec_ref);
305 return 0;
306}
307
308void *platform_init(struct audio_device *adev)
309{
310 char value[PROPERTY_VALUE_MAX];
311 struct platform_data *my_data;
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -0700312 int retry_num = 0;
313 const char *snd_card_name;
sangwoo1b9f4b32013-06-21 18:22:55 -0700314
315 adev->mixer = mixer_open(MIXER_CARD);
316
317 while (!adev->mixer && retry_num < RETRY_NUMBER) {
318 usleep(RETRY_US);
319 adev->mixer = mixer_open(MIXER_CARD);
320 retry_num++;
321 }
322
323 if (!adev->mixer) {
324 ALOGE("Unable to open the mixer, aborting.");
325 return NULL;
326 }
327
Damir Didjustof1d46c72013-11-06 17:59:04 -0800328 if (audio_extn_read_xml(adev, MIXER_CARD, MIXER_XML_PATH,
329 MIXER_XML_PATH_AUXPCM) == -ENOSYS)
330 adev->audio_route = audio_route_init(MIXER_CARD, MIXER_XML_PATH);
331
sangwoo1b9f4b32013-06-21 18:22:55 -0700332 if (!adev->audio_route) {
333 ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
334 return NULL;
335 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700336
337 my_data = calloc(1, sizeof(struct platform_data));
338
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -0700339 snd_card_name = mixer_get_name(adev->mixer);
340 my_data->hw_info = hw_info_init(snd_card_name);
341 if (!my_data->hw_info) {
342 ALOGE("%s: Failed to init hardware info", __func__);
343 }
344
Eric Laurentb23d5282013-05-14 15:27:20 -0700345 my_data->adev = adev;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700346 my_data->btsco_sample_rate = SAMPLE_RATE_8KHZ;
Eric Laurentb23d5282013-05-14 15:27:20 -0700347 my_data->fluence_in_spkr_mode = false;
348 my_data->fluence_in_voice_call = false;
349 my_data->fluence_in_voice_rec = false;
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700350 my_data->fluence_type = FLUENCE_NONE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700351
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700352 property_get("ro.qc.sdk.audio.fluencetype", value, "");
353 if (!strncmp("fluencepro", value, sizeof("fluencepro"))) {
354 my_data->fluence_type = FLUENCE_QUAD_MIC;
355 } else if (!strncmp("fluence", value, sizeof("fluence"))) {
356 my_data->fluence_type = FLUENCE_DUAL_MIC;
357 } else {
358 my_data->fluence_type = FLUENCE_NONE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700359 }
360
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700361 if (my_data->fluence_type != FLUENCE_NONE) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700362 property_get("persist.audio.fluence.voicecall",value,"");
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700363 if (!strncmp("true", value, sizeof("true"))) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700364 my_data->fluence_in_voice_call = true;
365 }
366
367 property_get("persist.audio.fluence.voicerec",value,"");
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700368 if (!strncmp("true", value, sizeof("true"))) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700369 my_data->fluence_in_voice_rec = true;
370 }
371
372 property_get("persist.audio.fluence.speaker",value,"");
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700373 if (!strncmp("true", value, sizeof("true"))) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700374 my_data->fluence_in_spkr_mode = true;
375 }
376 }
377
378 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
379 if (my_data->acdb_handle == NULL) {
380 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
381 } else {
382 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
383 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
384 "acdb_loader_deallocate_ACDB");
385 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
386 "acdb_loader_send_audio_cal");
387 if (!my_data->acdb_send_audio_cal)
388 ALOGW("%s: Could not find the symbol acdb_send_audio_cal from %s",
389 __func__, LIB_ACDB_LOADER);
390 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
391 "acdb_loader_send_voice_cal");
392 my_data->acdb_init = (acdb_init_t)dlsym(my_data->acdb_handle,
393 "acdb_loader_init_ACDB");
394 if (my_data->acdb_init == NULL)
395 ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__, dlerror());
396 else
397 my_data->acdb_init();
398 }
399
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -0700400 /* init usb */
401 audio_extn_usb_init(adev);
402
Apoorv Raghuvanshi6178a3f2013-10-19 12:38:54 -0700403 /* Read one time ssr property */
404 audio_extn_ssr_update_enabled(adev);
405
Eric Laurentb23d5282013-05-14 15:27:20 -0700406 return my_data;
407}
408
409void platform_deinit(void *platform)
410{
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -0700411 struct platform_data *my_data = (struct platform_data *)platform;
412
413 hw_info_deinit(my_data->hw_info);
Eric Laurentb23d5282013-05-14 15:27:20 -0700414 free(platform);
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -0700415 /* deinit usb */
416 audio_extn_usb_deinit();
Eric Laurentb23d5282013-05-14 15:27:20 -0700417}
418
419const char *platform_get_snd_device_name(snd_device_t snd_device)
420{
421 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX)
422 return device_table[snd_device];
423 else
424 return "";
425}
426
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -0700427int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
428 char *device_name)
429{
430 struct platform_data *my_data = (struct platform_data *)platform;
431
432 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
433 strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE);
434 hw_info_append_hw_type(my_data->hw_info, snd_device, device_name);
435 } else {
436 strlcpy(device_name, "", DEVICE_NAME_MAX_SIZE);
437 return -EINVAL;
438 }
439
440 return 0;
441}
442
Eric Laurentb23d5282013-05-14 15:27:20 -0700443void platform_add_backend_name(char *mixer_path, snd_device_t snd_device)
444{
445 if (snd_device == SND_DEVICE_IN_BT_SCO_MIC)
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700446 strlcat(mixer_path, " bt-sco", MIXER_PATH_MAX_LENGTH);
447 else if (snd_device == SND_DEVICE_IN_BT_SCO_MIC_WB)
448 strlcat(mixer_path, " bt-sco-wb", MIXER_PATH_MAX_LENGTH);
Eric Laurentb23d5282013-05-14 15:27:20 -0700449 else if(snd_device == SND_DEVICE_OUT_BT_SCO)
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700450 strlcat(mixer_path, " bt-sco", MIXER_PATH_MAX_LENGTH);
451 else if(snd_device == SND_DEVICE_OUT_BT_SCO_WB)
452 strlcat(mixer_path, " bt-sco-wb", MIXER_PATH_MAX_LENGTH);
Eric Laurentb23d5282013-05-14 15:27:20 -0700453 else if (snd_device == SND_DEVICE_OUT_HDMI)
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700454 strlcat(mixer_path, " hdmi", MIXER_PATH_MAX_LENGTH);
Eric Laurentb23d5282013-05-14 15:27:20 -0700455 else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HDMI)
456 strcat(mixer_path, " speaker-and-hdmi");
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -0700457 else if (snd_device == SND_DEVICE_OUT_AFE_PROXY)
458 strlcat(mixer_path, " afe-proxy", MIXER_PATH_MAX_LENGTH);
459 else if (snd_device == SND_DEVICE_OUT_USB_HEADSET)
460 strlcat(mixer_path, " usb-headphones", MIXER_PATH_MAX_LENGTH);
461 else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET)
462 strlcat(mixer_path, " speaker-and-usb-headphones",
463 MIXER_PATH_MAX_LENGTH);
464 else if (snd_device == SND_DEVICE_IN_USB_HEADSET_MIC)
465 strlcat(mixer_path, " usb-headset-mic", MIXER_PATH_MAX_LENGTH);
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -0700466 else if (snd_device == SND_DEVICE_IN_CAPTURE_FM)
467 strlcat(mixer_path, " capture-fm", MIXER_PATH_MAX_LENGTH);
468 else if (snd_device == SND_DEVICE_OUT_TRANSMISSION_FM)
469 strlcat(mixer_path, " transmission-fm", MIXER_PATH_MAX_LENGTH);
Eric Laurentb23d5282013-05-14 15:27:20 -0700470}
471
472int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
473{
474 int device_id;
475 if (device_type == PCM_PLAYBACK)
476 device_id = pcm_device_table[usecase][0];
477 else
478 device_id = pcm_device_table[usecase][1];
479 return device_id;
480}
481
482int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
483{
484 struct platform_data *my_data = (struct platform_data *)platform;
485 int acdb_dev_id, acdb_dev_type;
486
487 acdb_dev_id = acdb_device_table[snd_device];
488 if (acdb_dev_id < 0) {
489 ALOGE("%s: Could not find acdb id for device(%d)",
490 __func__, snd_device);
491 return -EINVAL;
492 }
493 if (my_data->acdb_send_audio_cal) {
Eric Laurent994a6932013-07-17 11:51:42 -0700494 ("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Eric Laurentb23d5282013-05-14 15:27:20 -0700495 __func__, snd_device, acdb_dev_id);
496 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
497 snd_device < SND_DEVICE_OUT_END)
498 acdb_dev_type = ACDB_DEV_TYPE_OUT;
499 else
500 acdb_dev_type = ACDB_DEV_TYPE_IN;
501 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
502 }
503 return 0;
504}
505
506int platform_switch_voice_call_device_pre(void *platform)
507{
508 return 0;
509}
510
511int platform_switch_voice_call_device_post(void *platform,
512 snd_device_t out_snd_device,
513 snd_device_t in_snd_device)
514{
515 struct platform_data *my_data = (struct platform_data *)platform;
516 int acdb_rx_id, acdb_tx_id;
517
518 if (my_data->acdb_send_voice_cal == NULL) {
519 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
520 } else {
521 acdb_rx_id = acdb_device_table[out_snd_device];
522 acdb_tx_id = acdb_device_table[in_snd_device];
523
524 if (acdb_rx_id > 0 && acdb_tx_id > 0)
525 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
526 else
527 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
528 acdb_rx_id, acdb_tx_id);
529 }
530
531 return 0;
532}
533
534int platform_start_voice_call(void *platform)
535{
536 return 0;
537}
538
539int platform_stop_voice_call(void *platform)
540{
541 return 0;
542}
543
544int platform_set_voice_volume(void *platform, int volume)
545{
546 struct platform_data *my_data = (struct platform_data *)platform;
547 struct audio_device *adev = my_data->adev;
548 struct mixer_ctl *ctl;
sangwoo53b2cf02013-07-25 19:18:44 -0700549 const char *mixer_ctl_name = "Voice Rx Gain";
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700550 int vol_index = 0;
551 uint32_t set_values[ ] = {0,
552 ALL_SESSION_VSID,
553 DEFAULT_VOLUME_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -0700554
555 // Voice volume levels are mapped to adsp volume levels as follows.
556 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
557 // But this values don't changed in kernel. So, below change is need.
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700558 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, MAX_VOL_INDEX);
559 set_values[0] = vol_index;
Eric Laurentb23d5282013-05-14 15:27:20 -0700560
561 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
562 if (!ctl) {
563 ALOGE("%s: Could not get ctl for mixer cmd - %s",
564 __func__, mixer_ctl_name);
565 return -EINVAL;
566 }
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700567 ALOGV("Setting voice volume index: %d", set_values[0]);
568 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
Eric Laurentb23d5282013-05-14 15:27:20 -0700569
570 return 0;
571}
572
573int platform_set_mic_mute(void *platform, bool state)
574{
575 struct platform_data *my_data = (struct platform_data *)platform;
576 struct audio_device *adev = my_data->adev;
577 struct mixer_ctl *ctl;
578 const char *mixer_ctl_name = "Voice Tx Mute";
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700579 uint32_t set_values[ ] = {0,
580 ALL_SESSION_VSID,
581 DEFAULT_VOLUME_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -0700582
583 if (adev->mode == AUDIO_MODE_IN_CALL) {
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700584 set_values[0] = state;
Eric Laurentb23d5282013-05-14 15:27:20 -0700585 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
586 if (!ctl) {
587 ALOGE("%s: Could not get ctl for mixer cmd - %s",
588 __func__, mixer_ctl_name);
589 return -EINVAL;
590 }
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700591 ALOGV("Setting voice mute state: %d", state);
592 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
Eric Laurentb23d5282013-05-14 15:27:20 -0700593 }
594
595 return 0;
596}
597
598snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
599{
600 struct platform_data *my_data = (struct platform_data *)platform;
601 struct audio_device *adev = my_data->adev;
602 audio_mode_t mode = adev->mode;
603 snd_device_t snd_device = SND_DEVICE_NONE;
604
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700605 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
606 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
607 int channel_count = popcount(channel_mask);
608
Eric Laurentb23d5282013-05-14 15:27:20 -0700609 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
610 if (devices == AUDIO_DEVICE_NONE ||
611 devices & AUDIO_DEVICE_BIT_IN) {
612 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
613 goto exit;
614 }
615
616 if (mode == AUDIO_MODE_IN_CALL) {
617 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
618 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700619 if (adev->voice.tty_mode == TTY_MODE_FULL) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700620 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700621 } else if (adev->voice.tty_mode == TTY_MODE_VCO) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700622 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700623 } else if (adev->voice.tty_mode == TTY_MODE_HCO) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700624 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700625 } else if (audio_extn_get_anc_enabled()) {
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700626 if (audio_extn_should_use_fb_anc())
627 snd_device = SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET;
628 else
629 snd_device = SND_DEVICE_OUT_VOICE_ANC_HEADSET;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700630 } else {
Eric Laurentb23d5282013-05-14 15:27:20 -0700631 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700632 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700633 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700634 if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ)
635 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
636 else
637 snd_device = SND_DEVICE_OUT_BT_SCO;
Eric Laurentb23d5282013-05-14 15:27:20 -0700638 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
639 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -0700640 } else if (devices & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
641 devices & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
642 snd_device = SND_DEVICE_OUT_USB_HEADSET;
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -0700643 } else if (devices & AUDIO_DEVICE_OUT_FM_TX) {
644 snd_device = SND_DEVICE_OUT_TRANSMISSION_FM;
Eric Laurentb23d5282013-05-14 15:27:20 -0700645 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
646 if (is_operator_tmus())
647 snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS;
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700648 else if (audio_extn_should_use_handset_anc(channel_count))
649 snd_device = SND_DEVICE_OUT_ANC_HANDSET;
Eric Laurentb23d5282013-05-14 15:27:20 -0700650 else
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700651 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
Eric Laurentb23d5282013-05-14 15:27:20 -0700652 }
653 if (snd_device != SND_DEVICE_NONE) {
654 goto exit;
655 }
656 }
657
658 if (popcount(devices) == 2) {
659 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
660 AUDIO_DEVICE_OUT_SPEAKER)) {
661 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
662 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
663 AUDIO_DEVICE_OUT_SPEAKER)) {
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700664 if (audio_extn_get_anc_enabled())
665 snd_device = SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET;
666 else
667 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
Eric Laurentb23d5282013-05-14 15:27:20 -0700668 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
669 AUDIO_DEVICE_OUT_SPEAKER)) {
670 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -0700671 } else if (devices == (AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET |
672 AUDIO_DEVICE_OUT_SPEAKER)) {
673 snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET;
Eric Laurentb23d5282013-05-14 15:27:20 -0700674 } else {
675 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
676 goto exit;
677 }
678 if (snd_device != SND_DEVICE_NONE) {
679 goto exit;
680 }
681 }
682
683 if (popcount(devices) != 1) {
684 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
685 goto exit;
686 }
687
688 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
689 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700690 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADSET
691 && audio_extn_get_anc_enabled()) {
692 if (audio_extn_should_use_fb_anc())
693 snd_device = SND_DEVICE_OUT_ANC_FB_HEADSET;
694 else
695 snd_device = SND_DEVICE_OUT_ANC_HEADSET;
696 }
697 else
698 snd_device = SND_DEVICE_OUT_HEADPHONES;
Eric Laurentb23d5282013-05-14 15:27:20 -0700699 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
700 if (adev->speaker_lr_swap)
701 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
702 else
703 snd_device = SND_DEVICE_OUT_SPEAKER;
704 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700705 if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ)
706 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
707 else
708 snd_device = SND_DEVICE_OUT_BT_SCO;
Eric Laurentb23d5282013-05-14 15:27:20 -0700709 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
710 snd_device = SND_DEVICE_OUT_HDMI ;
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -0700711 } else if (devices & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
712 devices & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
713 snd_device = SND_DEVICE_OUT_USB_HEADSET;
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -0700714 } else if (devices & AUDIO_DEVICE_OUT_FM_TX) {
715 snd_device = SND_DEVICE_OUT_TRANSMISSION_FM;
Eric Laurentb23d5282013-05-14 15:27:20 -0700716 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
717 snd_device = SND_DEVICE_OUT_HANDSET;
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -0700718 } else if (devices & AUDIO_DEVICE_OUT_PROXY) {
719 ALOGD("%s: setting sink capability for Proxy", __func__);
720 audio_extn_set_afe_proxy_channel_mixer(adev);
721 snd_device = SND_DEVICE_OUT_AFE_PROXY;
Eric Laurentb23d5282013-05-14 15:27:20 -0700722 } else {
723 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
724 }
725exit:
726 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
727 return snd_device;
728}
729
730snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
731{
732 struct platform_data *my_data = (struct platform_data *)platform;
733 struct audio_device *adev = my_data->adev;
734 audio_source_t source = (adev->active_input == NULL) ?
735 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
736
737 audio_mode_t mode = adev->mode;
738 audio_devices_t in_device = ((adev->active_input == NULL) ?
739 AUDIO_DEVICE_NONE : adev->active_input->device)
740 & ~AUDIO_DEVICE_BIT_IN;
741 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
742 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
743 snd_device_t snd_device = SND_DEVICE_NONE;
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700744 int channel_count = popcount(channel_mask);
Eric Laurentb23d5282013-05-14 15:27:20 -0700745
746 ALOGV("%s: enter: out_device(%#x) in_device(%#x)",
747 __func__, out_device, in_device);
748 if (mode == AUDIO_MODE_IN_CALL) {
749 if (out_device == AUDIO_DEVICE_NONE) {
750 ALOGE("%s: No output device set for voice call", __func__);
751 goto exit;
752 }
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700753 if (adev->voice.tty_mode != TTY_MODE_OFF) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700754 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
755 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700756 switch (adev->voice.tty_mode) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700757 case TTY_MODE_FULL:
758 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
759 break;
760 case TTY_MODE_VCO:
761 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
762 break;
763 case TTY_MODE_HCO:
764 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
765 break;
766 default:
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700767 ALOGE("%s: Invalid TTY mode (%#x)",
768 __func__, adev->voice.tty_mode);
Eric Laurentb23d5282013-05-14 15:27:20 -0700769 }
770 goto exit;
771 }
772 }
773 if (out_device & AUDIO_DEVICE_OUT_EARPIECE ||
774 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700775 if (out_device & AUDIO_DEVICE_OUT_EARPIECE &&
776 audio_extn_should_use_handset_anc(channel_count)) {
777 snd_device = SND_DEVICE_IN_AANC_HANDSET_MIC;
778 } else if (my_data->fluence_type == FLUENCE_NONE ||
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700779 my_data->fluence_in_voice_call == false) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700780 snd_device = SND_DEVICE_IN_HANDSET_MIC;
781 } else {
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700782 if (is_operator_tmus())
783 snd_device = SND_DEVICE_IN_VOICE_DMIC_TMUS;
Eric Laurentb23d5282013-05-14 15:27:20 -0700784 else
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700785 snd_device = SND_DEVICE_IN_VOICE_DMIC;
786 adev->acdb_settings |= DMIC_FLAG;
Eric Laurentb23d5282013-05-14 15:27:20 -0700787 }
788 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
789 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
790 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700791 if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ)
792 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
793 else
794 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -0700795 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700796 if (my_data->fluence_type != FLUENCE_NONE &&
797 my_data->fluence_in_voice_call &&
798 my_data->fluence_in_spkr_mode) {
799 if(my_data->fluence_type == FLUENCE_DUAL_MIC) {
800 adev->acdb_settings |= DMIC_FLAG;
801 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
802 } else {
803 adev->acdb_settings |= QMIC_FLAG;
804 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_QMIC;
805 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700806 } else {
807 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
808 }
809 }
810 } else if (source == AUDIO_SOURCE_CAMCORDER) {
811 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
812 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
813 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
814 }
815 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
816 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700817 if (channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK)
818 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC;
819 else if (my_data->fluence_in_voice_rec)
820 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700821
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700822 if (snd_device == SND_DEVICE_NONE)
Eric Laurentb23d5282013-05-14 15:27:20 -0700823 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700824 else
825 adev->acdb_settings |= DMIC_FLAG;
Eric Laurentb23d5282013-05-14 15:27:20 -0700826 }
827 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION) {
828 if (out_device & AUDIO_DEVICE_OUT_SPEAKER)
829 in_device = AUDIO_DEVICE_IN_BACK_MIC;
830 if (adev->active_input) {
831 if (adev->active_input->enable_aec) {
832 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
833 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
834 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
835 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
836 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
837 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
838 }
839 set_echo_reference(adev->mixer, "SLIM_RX");
840 } else
841 set_echo_reference(adev->mixer, "NONE");
842 }
Mingming Yinab429782013-11-07 11:16:55 -0800843 } else if (source == AUDIO_SOURCE_FM_RX ||
844 source == AUDIO_SOURCE_FM_RX_A2DP) {
Preetam Singh Ranawatde84f1a2013-11-01 14:58:16 -0700845 snd_device = SND_DEVICE_IN_CAPTURE_FM;
Eric Laurentb23d5282013-05-14 15:27:20 -0700846 } else if (source == AUDIO_SOURCE_DEFAULT) {
847 goto exit;
848 }
849
850
851 if (snd_device != SND_DEVICE_NONE) {
852 goto exit;
853 }
854
855 if (in_device != AUDIO_DEVICE_NONE &&
856 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
857 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
858 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Apoorv Raghuvanshi6178a3f2013-10-19 12:38:54 -0700859 if (audio_extn_ssr_get_enabled() && channel_count == 6)
860 snd_device = SND_DEVICE_IN_QUAD_MIC;
Ravi Kumar Alamandafae42112013-11-07 23:31:54 -0800861 else if (channel_count == 2)
Apoorv Raghuvanshi6bd8dbf2013-10-19 18:37:52 -0700862 snd_device = SND_DEVICE_IN_HANDSET_STEREO_DMIC;
Apoorv Raghuvanshi6178a3f2013-10-19 12:38:54 -0700863 else
864 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -0700865 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
866 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
867 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
868 snd_device = SND_DEVICE_IN_HEADSET_MIC;
869 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700870 if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ)
871 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
872 else
873 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -0700874 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
875 snd_device = SND_DEVICE_IN_HDMI_MIC;
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -0700876 } else if (in_device & AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET ||
877 in_device & AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET) {
878 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -0700879 } else if (in_device & AUDIO_DEVICE_IN_FM_RX) {
880 snd_device = SND_DEVICE_IN_CAPTURE_FM;
Eric Laurentb23d5282013-05-14 15:27:20 -0700881 } else {
882 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
883 ALOGW("%s: Using default handset-mic", __func__);
884 snd_device = SND_DEVICE_IN_HANDSET_MIC;
885 }
886 } else {
887 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
888 snd_device = SND_DEVICE_IN_HANDSET_MIC;
889 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
890 snd_device = SND_DEVICE_IN_HEADSET_MIC;
891 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
Apoorv Raghuvanshi6bd8dbf2013-10-19 18:37:52 -0700892 if (channel_count > 1)
893 snd_device = SND_DEVICE_IN_SPEAKER_STEREO_DMIC;
894 else
895 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -0700896 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
897 snd_device = SND_DEVICE_IN_HANDSET_MIC;
898 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700899 if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ)
900 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
901 else
902 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -0700903 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
904 snd_device = SND_DEVICE_IN_HDMI_MIC;
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -0700905 } else if (out_device & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
906 out_device & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
907 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -0700908 } else {
909 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
910 ALOGW("%s: Using default handset-mic", __func__);
911 snd_device = SND_DEVICE_IN_HANDSET_MIC;
912 }
913 }
914exit:
915 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
916 return snd_device;
917}
918
919int platform_set_hdmi_channels(void *platform, int channel_count)
920{
921 struct platform_data *my_data = (struct platform_data *)platform;
922 struct audio_device *adev = my_data->adev;
923 struct mixer_ctl *ctl;
924 const char *channel_cnt_str = NULL;
925 const char *mixer_ctl_name = "HDMI_RX Channels";
926 switch (channel_count) {
927 case 8:
928 channel_cnt_str = "Eight"; break;
929 case 7:
930 channel_cnt_str = "Seven"; break;
931 case 6:
932 channel_cnt_str = "Six"; break;
933 case 5:
934 channel_cnt_str = "Five"; break;
935 case 4:
936 channel_cnt_str = "Four"; break;
937 case 3:
938 channel_cnt_str = "Three"; break;
939 default:
940 channel_cnt_str = "Two"; break;
941 }
942 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
943 if (!ctl) {
944 ALOGE("%s: Could not get ctl for mixer cmd - %s",
945 __func__, mixer_ctl_name);
946 return -EINVAL;
947 }
948 ALOGV("HDMI channel count: %s", channel_cnt_str);
949 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
950 return 0;
951}
952
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -0700953int platform_edid_get_max_channels(void *platform)
Eric Laurentb23d5282013-05-14 15:27:20 -0700954{
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -0700955 struct platform_data *my_data = (struct platform_data *)platform;
956 struct audio_device *adev = my_data->adev;
Eric Laurentb23d5282013-05-14 15:27:20 -0700957 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
958 char *sad = block;
959 int num_audio_blocks;
960 int channel_count;
961 int max_channels = 0;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -0700962 int i, ret, count;
Eric Laurentb23d5282013-05-14 15:27:20 -0700963
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -0700964 struct mixer_ctl *ctl;
965
966 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
967 if (!ctl) {
968 ALOGE("%s: Could not get ctl for mixer cmd - %s",
969 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
Eric Laurentb23d5282013-05-14 15:27:20 -0700970 return 0;
971 }
972
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -0700973 mixer_ctl_update(ctl);
974
975 count = mixer_ctl_get_num_values(ctl);
Eric Laurentb23d5282013-05-14 15:27:20 -0700976
977 /* Read SAD blocks, clamping the maximum size for safety */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -0700978 if (count > (int)sizeof(block))
979 count = (int)sizeof(block);
Eric Laurentb23d5282013-05-14 15:27:20 -0700980
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -0700981 ret = mixer_ctl_get_array(ctl, block, count);
982 if (ret != 0) {
983 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
984 return 0;
985 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700986
987 /* Calculate the number of SAD blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -0700988 num_audio_blocks = count / SAD_BLOCK_SIZE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700989
990 for (i = 0; i < num_audio_blocks; i++) {
991 /* Only consider LPCM blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -0700992 if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
993 sad += 3;
Eric Laurentb23d5282013-05-14 15:27:20 -0700994 continue;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -0700995 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700996
997 channel_count = (sad[0] & 0x7) + 1;
998 if (channel_count > max_channels)
999 max_channels = channel_count;
1000
1001 /* Advance to next block */
1002 sad += 3;
1003 }
1004
1005 return max_channels;
1006}
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07001007
1008static int platform_set_slowtalk(struct platform_data *my_data, bool state)
1009{
1010 int ret = 0;
1011 struct audio_device *adev = my_data->adev;
1012 struct mixer_ctl *ctl;
1013 const char *mixer_ctl_name = "Slowtalk Enable";
1014 uint32_t set_values[ ] = {0,
1015 ALL_SESSION_VSID};
1016
1017 set_values[0] = state;
1018 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1019 if (!ctl) {
1020 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1021 __func__, mixer_ctl_name);
1022 ret = -EINVAL;
1023 } else {
1024 ALOGV("Setting slowtalk state: %d", state);
1025 ret = mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1026 my_data->slowtalk = state;
1027 }
1028
1029 return ret;
1030}
1031
1032int platform_set_parameters(void *platform, struct str_parms *parms)
1033{
1034 struct platform_data *my_data = (struct platform_data *)platform;
1035 char *str;
1036 char value[32];
1037 int val;
1038 int ret = 0;
1039
1040 ALOGV("%s: enter: %s", __func__, str_parms_to_str(parms));
1041
1042 ret = str_parms_get_int(parms, AUDIO_PARAMETER_KEY_BTSCO, &val);
1043 if (ret >= 0) {
1044 str_parms_del(parms, AUDIO_PARAMETER_KEY_BTSCO);
1045 pthread_mutex_lock(&my_data->adev->lock);
1046 my_data->btsco_sample_rate = val;
1047 pthread_mutex_unlock(&my_data->adev->lock);
1048 }
1049
1050 ret = str_parms_get_int(parms, AUDIO_PARAMETER_KEY_SLOWTALK, &val);
1051 if (ret >= 0) {
1052 str_parms_del(parms, AUDIO_PARAMETER_KEY_SLOWTALK);
1053 pthread_mutex_lock(&my_data->adev->lock);
1054 ret = platform_set_slowtalk(my_data, val);
1055 if (ret)
1056 ALOGE("%s: Failed to set slow talk err: %d", __func__, ret);
1057 pthread_mutex_unlock(&my_data->adev->lock);
1058 }
1059
1060 ALOGV("%s: exit with code(%d)", __func__, ret);
1061 return ret;
1062}
1063
Shiv Maliyappanahallida107642013-10-17 11:16:13 -07001064int platform_set_incall_recoding_session_id(void *platform,
1065 uint32_t session_id)
1066{
1067 int ret = 0;
1068 struct platform_data *my_data = (struct platform_data *)platform;
1069 struct audio_device *adev = my_data->adev;
1070 struct mixer_ctl *ctl;
1071 const char *mixer_ctl_name = "Voc VSID";
1072 int num_ctl_values;
1073 int i;
1074
1075 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1076 if (!ctl) {
1077 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1078 __func__, mixer_ctl_name);
1079 ret = -EINVAL;
1080 } else {
1081 num_ctl_values = mixer_ctl_get_num_values(ctl);
1082 for (i = 0; i < num_ctl_values; i++) {
1083 if (mixer_ctl_set_value(ctl, i, session_id)) {
1084 ALOGV("Error: invalid session_id: %x", session_id);
1085 ret = -EINVAL;
1086 break;
1087 }
1088 }
1089 }
1090
1091 return ret;
1092}
1093
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07001094void platform_get_parameters(void *platform,
1095 struct str_parms *query,
1096 struct str_parms *reply)
1097{
1098 struct platform_data *my_data = (struct platform_data *)platform;
1099 char *str = NULL;
1100 char value[256] = {0};
1101 int ret;
1102 int fluence_type;
1103
1104 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_FLUENCE_TYPE,
1105 value, sizeof(value));
1106 if (ret >= 0) {
1107 pthread_mutex_lock(&my_data->adev->lock);
1108 if (my_data->fluence_type == FLUENCE_QUAD_MIC) {
1109 strlcpy(value, "fluencepro", sizeof(value));
1110 } else if (my_data->fluence_type == FLUENCE_DUAL_MIC) {
1111 strlcpy(value, "fluence", sizeof(value));
1112 } else {
1113 strlcpy(value, "none", sizeof(value));
1114 }
1115 pthread_mutex_unlock(&my_data->adev->lock);
1116
1117 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_FLUENCE_TYPE, value);
1118 }
1119
1120 ALOGV("%s: exit: returns - %s", __func__, str_parms_to_str(reply));
1121}
1122
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07001123/* Delay in Us */
1124int64_t platform_render_latency(audio_usecase_t usecase)
1125{
1126 switch (usecase) {
1127 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
1128 return DEEP_BUFFER_PLATFORM_DELAY;
1129 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
1130 return LOW_LATENCY_PLATFORM_DELAY;
1131 default:
1132 return 0;
1133 }
1134}
Preetam Singh Ranawatde84f1a2013-11-01 14:58:16 -07001135
1136int platform_get_usecase_from_source(int source)
1137{
Mingming Yinab429782013-11-07 11:16:55 -08001138 ALOGV("%s: input source :%d", __func__, source);
1139 if(source == AUDIO_SOURCE_FM_RX_A2DP)
Preetam Singh Ranawatde84f1a2013-11-01 14:58:16 -07001140 return USECASE_AUDIO_RECORD_FM_VIRTUAL;
1141 else
1142 return USECASE_AUDIO_RECORD;
1143}