blob: 134fdbb28fc7a18e6707d074100301bc802badd2 [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"
Eric Laurentb23d5282013-05-14 15:27:20 -070035#define LIB_ACDB_LOADER "libacdbloader.so"
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -070036#define AUDIO_DATA_BLOCK_MIXER_CTL "HDMI EDID"
Eric Laurentb23d5282013-05-14 15:27:20 -070037
Eric Laurentb23d5282013-05-14 15:27:20 -070038/*
Eric Laurentb23d5282013-05-14 15:27:20 -070039 * This file will have a maximum of 38 bytes:
40 *
41 * 4 bytes: number of audio blocks
42 * 4 bytes: total length of Short Audio Descriptor (SAD) blocks
43 * Maximum 10 * 3 bytes: SAD blocks
44 */
45#define MAX_SAD_BLOCKS 10
46#define SAD_BLOCK_SIZE 3
47
48/* EDID format ID for LPCM audio */
49#define EDID_FORMAT_LPCM 1
50
sangwoo1b9f4b32013-06-21 18:22:55 -070051/* Retry for delay in FW loading*/
52#define RETRY_NUMBER 10
53#define RETRY_US 500000
54
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -070055#define SAMPLE_RATE_8KHZ 8000
56#define SAMPLE_RATE_16KHZ 16000
57
sangwoo53b2cf02013-07-25 19:18:44 -070058#define MAX_VOL_INDEX 5
59#define MIN_VOL_INDEX 0
60#define percent_to_index(val, min, max) \
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -070061 ((val) * ((max) - (min)) * 0.01 + (min) + .5)
62
63#define AUDIO_PARAMETER_KEY_FLUENCE_TYPE "fluence"
64#define AUDIO_PARAMETER_KEY_BTSCO "bt_samplerate"
65#define AUDIO_PARAMETER_KEY_SLOWTALK "st_enable"
sangwoo53b2cf02013-07-25 19:18:44 -070066
Eric Laurentb23d5282013-05-14 15:27:20 -070067struct audio_block_header
68{
69 int reserved;
70 int length;
71};
72
73typedef void (*acdb_deallocate_t)();
74typedef int (*acdb_init_t)();
75typedef void (*acdb_send_audio_cal_t)(int, int);
76typedef void (*acdb_send_voice_cal_t)(int, int);
77
78/* Audio calibration related functions */
79struct 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
88 void *acdb_handle;
89 acdb_init_t acdb_init;
90 acdb_deallocate_t acdb_deallocate;
91 acdb_send_audio_cal_t acdb_send_audio_cal;
92 acdb_send_voice_cal_t acdb_send_voice_cal;
93};
94
95static const int pcm_device_table[AUDIO_USECASE_MAX][2] = {
Mingming Yin8e5a4f62013-10-07 15:23:41 -070096 [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = {DEEP_BUFFER_PCM_DEVICE,
97 DEEP_BUFFER_PCM_DEVICE},
98 [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
99 LOWLATENCY_PCM_DEVICE},
100 [USECASE_AUDIO_PLAYBACK_MULTI_CH] = {MULTI_CHANNEL_PCM_DEVICE,
101 MULTI_CHANNEL_PCM_DEVICE},
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700102 [USECASE_AUDIO_RECORD] = {AUDIO_RECORD_PCM_DEVICE, AUDIO_RECORD_PCM_DEVICE},
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700103 [USECASE_AUDIO_RECORD_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
104 LOWLATENCY_PCM_DEVICE},
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -0700105 [USECASE_AUDIO_PLAYBACK_FM] = {FM_PLAYBACK_PCM_DEVICE, FM_CAPTURE_PCM_DEVICE},
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700106 [USECASE_VOICE_CALL] = {VOICE_CALL_PCM_DEVICE, VOICE_CALL_PCM_DEVICE},
107 [USECASE_VOICE2_CALL] = {VOICE2_CALL_PCM_DEVICE, VOICE2_CALL_PCM_DEVICE},
108 [USECASE_VOLTE_CALL] = {VOLTE_CALL_PCM_DEVICE, VOLTE_CALL_PCM_DEVICE},
109 [USECASE_QCHAT_CALL] = {QCHAT_CALL_PCM_DEVICE, QCHAT_CALL_PCM_DEVICE},
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700110 [USECASE_INCALL_REC_UPLINK] = {AUDIO_RECORD_PCM_DEVICE,
111 AUDIO_RECORD_PCM_DEVICE},
112 [USECASE_INCALL_REC_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
113 AUDIO_RECORD_PCM_DEVICE},
114 [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
115 AUDIO_RECORD_PCM_DEVICE},
Eric Laurentb23d5282013-05-14 15:27:20 -0700116};
117
118/* Array to store sound devices */
119static const char * const device_table[SND_DEVICE_MAX] = {
120 [SND_DEVICE_NONE] = "none",
121 /* Playback sound devices */
122 [SND_DEVICE_OUT_HANDSET] = "handset",
123 [SND_DEVICE_OUT_SPEAKER] = "speaker",
124 [SND_DEVICE_OUT_SPEAKER_REVERSE] = "speaker-reverse",
125 [SND_DEVICE_OUT_HEADPHONES] = "headphones",
126 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones",
127 [SND_DEVICE_OUT_VOICE_HANDSET] = "voice-handset",
128 [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker",
129 [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones",
130 [SND_DEVICE_OUT_HDMI] = "hdmi",
131 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi",
132 [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset",
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700133 [SND_DEVICE_OUT_BT_SCO_WB] = "bt-sco-headset-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700134 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = "voice-handset-tmus",
135 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones",
136 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones",
137 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset",
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -0700138 [SND_DEVICE_OUT_AFE_PROXY] = "afe-proxy",
139 [SND_DEVICE_OUT_USB_HEADSET] = "usb-headphones",
140 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = "speaker-and-usb-headphones",
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -0700141 [SND_DEVICE_OUT_TRANSMISSION_FM] = "transmission-fm",
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700142 [SND_DEVICE_OUT_ANC_HEADSET] = "anc-headphones",
143 [SND_DEVICE_OUT_ANC_FB_HEADSET] = "anc-fb-headphones",
144 [SND_DEVICE_OUT_VOICE_ANC_HEADSET] = "voice-anc-headphones",
145 [SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET] = "voice-anc-fb-headphones",
146 [SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET] = "speaker-and-anc-headphones",
147 [SND_DEVICE_OUT_ANC_HANDSET] = "anc-handset",
Eric Laurentb23d5282013-05-14 15:27:20 -0700148
149 /* Capture sound devices */
150 [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
151 [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
152 [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
153 [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic",
154 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "voice-speaker-mic",
155 [SND_DEVICE_IN_HEADSET_MIC_AEC] = "headset-mic",
156 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
157 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
158 [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic",
159 [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700160 [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700161 [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic",
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700162 [SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef",
163 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = "voice-dmic-ef-tmus",
164 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = "voice-speaker-dmic-ef",
Eric Laurentb23d5282013-05-14 15:27:20 -0700165 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
166 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
167 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
168 [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700169 [SND_DEVICE_IN_VOICE_REC_DMIC] = "voice-rec-dmic-ef",
170 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence",
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -0700171 [SND_DEVICE_IN_USB_HEADSET_MIC] = "usb-headset-mic",
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -0700172 [SND_DEVICE_IN_CAPTURE_FM] = "capture-fm",
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700173 [SND_DEVICE_IN_AANC_HANDSET_MIC] = "aanc-handset-mic",
Apoorv Raghuvanshi6178a3f2013-10-19 12:38:54 -0700174 [SND_DEVICE_IN_QUAD_MIC] = "quad-mic",
Apoorv Raghuvanshi6bd8dbf2013-10-19 18:37:52 -0700175 [SND_DEVICE_IN_HANDSET_STEREO_DMIC] = "handset-stereo-dmic-ef",
176 [SND_DEVICE_IN_SPEAKER_STEREO_DMIC] = "speaker-stereo-dmic-ef",
Eric Laurentb23d5282013-05-14 15:27:20 -0700177};
178
179/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
180static const int acdb_device_table[SND_DEVICE_MAX] = {
181 [SND_DEVICE_NONE] = -1,
182 [SND_DEVICE_OUT_HANDSET] = 7,
183 [SND_DEVICE_OUT_SPEAKER] = 15,
184 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 15,
185 [SND_DEVICE_OUT_HEADPHONES] = 10,
186 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
187 [SND_DEVICE_OUT_VOICE_HANDSET] = 7,
188 [SND_DEVICE_OUT_VOICE_SPEAKER] = 15,
189 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
190 [SND_DEVICE_OUT_HDMI] = 18,
191 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 15,
192 [SND_DEVICE_OUT_BT_SCO] = 22,
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700193 [SND_DEVICE_OUT_BT_SCO_WB] = 39,
sangwooc69476f2013-07-26 16:57:26 -0700194 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = 88,
Eric Laurentb23d5282013-05-14 15:27:20 -0700195 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
196 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
197 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -0700198 [SND_DEVICE_OUT_AFE_PROXY] = 0,
199 [SND_DEVICE_OUT_USB_HEADSET] = 0,
200 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = 14,
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -0700201 [SND_DEVICE_OUT_TRANSMISSION_FM] = 0,
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700202 [SND_DEVICE_OUT_ANC_HEADSET] = 26,
203 [SND_DEVICE_OUT_ANC_FB_HEADSET] = 26,
204 [SND_DEVICE_OUT_VOICE_ANC_HEADSET] = 26,
205 [SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET] = 26,
206 [SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET] = 26,
207 [SND_DEVICE_OUT_ANC_HANDSET] = 103,
Eric Laurentb23d5282013-05-14 15:27:20 -0700208
209 [SND_DEVICE_IN_HANDSET_MIC] = 4,
210 [SND_DEVICE_IN_SPEAKER_MIC] = 4, /* ToDo: Check if this needs to changed to 11 */
211 [SND_DEVICE_IN_HEADSET_MIC] = 8,
212 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 40,
213 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 42,
214 [SND_DEVICE_IN_HEADSET_MIC_AEC] = 47,
215 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
216 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = 8,
217 [SND_DEVICE_IN_HDMI_MIC] = 4,
218 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700219 [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38,
Eric Laurentb23d5282013-05-14 15:27:20 -0700220 [SND_DEVICE_IN_CAMCORDER_MIC] = 61,
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700221 [SND_DEVICE_IN_VOICE_DMIC] = 41,
222 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = 89,
223 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 43,
Eric Laurentb23d5282013-05-14 15:27:20 -0700224 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
225 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
226 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
227 [SND_DEVICE_IN_VOICE_REC_MIC] = 62,
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -0700228 [SND_DEVICE_IN_USB_HEADSET_MIC] = 44,
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -0700229 [SND_DEVICE_IN_CAPTURE_FM] = 0,
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700230 [SND_DEVICE_IN_AANC_HANDSET_MIC] = 104,
Apoorv Raghuvanshi6178a3f2013-10-19 12:38:54 -0700231 [SND_DEVICE_IN_QUAD_MIC] = 46,
Apoorv Raghuvanshi6bd8dbf2013-10-19 18:37:52 -0700232 [SND_DEVICE_IN_HANDSET_STEREO_DMIC] = 34,
233 [SND_DEVICE_IN_SPEAKER_STEREO_DMIC] = 35,
Eric Laurentb23d5282013-05-14 15:27:20 -0700234 /* TODO: Update with proper acdb ids */
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700235 [SND_DEVICE_IN_VOICE_REC_DMIC] = 62,
236 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 6,
Eric Laurentb23d5282013-05-14 15:27:20 -0700237};
238
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700239#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
240#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
241
Eric Laurentb23d5282013-05-14 15:27:20 -0700242static pthread_once_t check_op_once_ctl = PTHREAD_ONCE_INIT;
243static bool is_tmus = false;
244
245static void check_operator()
246{
247 char value[PROPERTY_VALUE_MAX];
248 int mccmnc;
249 property_get("gsm.sim.operator.numeric",value,"0");
250 mccmnc = atoi(value);
251 ALOGD("%s: tmus mccmnc %d", __func__, mccmnc);
252 switch(mccmnc) {
253 /* TMUS MCC(310), MNC(490, 260, 026) */
254 case 310490:
255 case 310260:
256 case 310026:
sangwon.jeonb891db52013-09-14 17:39:15 +0900257 /* Add new TMUS MNC(800, 660, 580, 310, 270, 250, 240, 230, 220, 210, 200, 160) */
258 case 310800:
259 case 310660:
260 case 310580:
261 case 310310:
262 case 310270:
263 case 310250:
264 case 310240:
265 case 310230:
266 case 310220:
267 case 310210:
268 case 310200:
269 case 310160:
Eric Laurentb23d5282013-05-14 15:27:20 -0700270 is_tmus = true;
271 break;
272 }
273}
274
275bool is_operator_tmus()
276{
277 pthread_once(&check_op_once_ctl, check_operator);
278 return is_tmus;
279}
280
281static int set_echo_reference(struct mixer *mixer, const char* ec_ref)
282{
283 struct mixer_ctl *ctl;
284 const char *mixer_ctl_name = "EC_REF_RX";
285
286 ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name);
287 if (!ctl) {
288 ALOGE("%s: Could not get ctl for mixer cmd - %s",
289 __func__, mixer_ctl_name);
290 return -EINVAL;
291 }
292 ALOGV("Setting EC Reference: %s", ec_ref);
293 mixer_ctl_set_enum_by_string(ctl, ec_ref);
294 return 0;
295}
296
297void *platform_init(struct audio_device *adev)
298{
299 char value[PROPERTY_VALUE_MAX];
300 struct platform_data *my_data;
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -0700301 int retry_num = 0, ret;
sangwoo1b9f4b32013-06-21 18:22:55 -0700302
303 adev->mixer = mixer_open(MIXER_CARD);
304
305 while (!adev->mixer && retry_num < RETRY_NUMBER) {
306 usleep(RETRY_US);
307 adev->mixer = mixer_open(MIXER_CARD);
308 retry_num++;
309 }
310
311 if (!adev->mixer) {
312 ALOGE("Unable to open the mixer, aborting.");
313 return NULL;
314 }
315
316 adev->audio_route = audio_route_init(MIXER_CARD, MIXER_XML_PATH);
317 if (!adev->audio_route) {
318 ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
319 return NULL;
320 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700321
322 my_data = calloc(1, sizeof(struct platform_data));
323
324 my_data->adev = adev;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700325 my_data->btsco_sample_rate = SAMPLE_RATE_8KHZ;
Eric Laurentb23d5282013-05-14 15:27:20 -0700326 my_data->fluence_in_spkr_mode = false;
327 my_data->fluence_in_voice_call = false;
328 my_data->fluence_in_voice_rec = false;
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700329 my_data->fluence_type = FLUENCE_NONE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700330
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700331 property_get("ro.qc.sdk.audio.fluencetype", value, "");
332 if (!strncmp("fluencepro", value, sizeof("fluencepro"))) {
333 my_data->fluence_type = FLUENCE_QUAD_MIC;
334 } else if (!strncmp("fluence", value, sizeof("fluence"))) {
335 my_data->fluence_type = FLUENCE_DUAL_MIC;
336 } else {
337 my_data->fluence_type = FLUENCE_NONE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700338 }
339
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700340 if (my_data->fluence_type != FLUENCE_NONE) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700341 property_get("persist.audio.fluence.voicecall",value,"");
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700342 if (!strncmp("true", value, sizeof("true"))) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700343 my_data->fluence_in_voice_call = true;
344 }
345
346 property_get("persist.audio.fluence.voicerec",value,"");
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700347 if (!strncmp("true", value, sizeof("true"))) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700348 my_data->fluence_in_voice_rec = true;
349 }
350
351 property_get("persist.audio.fluence.speaker",value,"");
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700352 if (!strncmp("true", value, sizeof("true"))) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700353 my_data->fluence_in_spkr_mode = true;
354 }
355 }
356
357 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
358 if (my_data->acdb_handle == NULL) {
359 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
360 } else {
361 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
362 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
363 "acdb_loader_deallocate_ACDB");
364 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
365 "acdb_loader_send_audio_cal");
366 if (!my_data->acdb_send_audio_cal)
367 ALOGW("%s: Could not find the symbol acdb_send_audio_cal from %s",
368 __func__, LIB_ACDB_LOADER);
369 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
370 "acdb_loader_send_voice_cal");
371 my_data->acdb_init = (acdb_init_t)dlsym(my_data->acdb_handle,
372 "acdb_loader_init_ACDB");
373 if (my_data->acdb_init == NULL)
374 ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__, dlerror());
375 else
376 my_data->acdb_init();
377 }
378
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -0700379 /* init usb */
380 audio_extn_usb_init(adev);
381
Apoorv Raghuvanshi6178a3f2013-10-19 12:38:54 -0700382 /* Read one time ssr property */
383 audio_extn_ssr_update_enabled(adev);
384
Eric Laurentb23d5282013-05-14 15:27:20 -0700385 return my_data;
386}
387
388void platform_deinit(void *platform)
389{
390 free(platform);
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -0700391 /* deinit usb */
392 audio_extn_usb_deinit();
Eric Laurentb23d5282013-05-14 15:27:20 -0700393}
394
395const char *platform_get_snd_device_name(snd_device_t snd_device)
396{
397 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX)
398 return device_table[snd_device];
399 else
400 return "";
401}
402
403void platform_add_backend_name(char *mixer_path, snd_device_t snd_device)
404{
405 if (snd_device == SND_DEVICE_IN_BT_SCO_MIC)
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700406 strlcat(mixer_path, " bt-sco", MIXER_PATH_MAX_LENGTH);
407 else if (snd_device == SND_DEVICE_IN_BT_SCO_MIC_WB)
408 strlcat(mixer_path, " bt-sco-wb", MIXER_PATH_MAX_LENGTH);
Eric Laurentb23d5282013-05-14 15:27:20 -0700409 else if(snd_device == SND_DEVICE_OUT_BT_SCO)
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700410 strlcat(mixer_path, " bt-sco", MIXER_PATH_MAX_LENGTH);
411 else if(snd_device == SND_DEVICE_OUT_BT_SCO_WB)
412 strlcat(mixer_path, " bt-sco-wb", MIXER_PATH_MAX_LENGTH);
Eric Laurentb23d5282013-05-14 15:27:20 -0700413 else if (snd_device == SND_DEVICE_OUT_HDMI)
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700414 strlcat(mixer_path, " hdmi", MIXER_PATH_MAX_LENGTH);
Eric Laurentb23d5282013-05-14 15:27:20 -0700415 else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HDMI)
416 strcat(mixer_path, " speaker-and-hdmi");
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -0700417 else if (snd_device == SND_DEVICE_OUT_AFE_PROXY)
418 strlcat(mixer_path, " afe-proxy", MIXER_PATH_MAX_LENGTH);
419 else if (snd_device == SND_DEVICE_OUT_USB_HEADSET)
420 strlcat(mixer_path, " usb-headphones", MIXER_PATH_MAX_LENGTH);
421 else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET)
422 strlcat(mixer_path, " speaker-and-usb-headphones",
423 MIXER_PATH_MAX_LENGTH);
424 else if (snd_device == SND_DEVICE_IN_USB_HEADSET_MIC)
425 strlcat(mixer_path, " usb-headset-mic", MIXER_PATH_MAX_LENGTH);
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -0700426 else if (snd_device == SND_DEVICE_IN_CAPTURE_FM)
427 strlcat(mixer_path, " capture-fm", MIXER_PATH_MAX_LENGTH);
428 else if (snd_device == SND_DEVICE_OUT_TRANSMISSION_FM)
429 strlcat(mixer_path, " transmission-fm", MIXER_PATH_MAX_LENGTH);
Eric Laurentb23d5282013-05-14 15:27:20 -0700430}
431
432int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
433{
434 int device_id;
435 if (device_type == PCM_PLAYBACK)
436 device_id = pcm_device_table[usecase][0];
437 else
438 device_id = pcm_device_table[usecase][1];
439 return device_id;
440}
441
442int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
443{
444 struct platform_data *my_data = (struct platform_data *)platform;
445 int acdb_dev_id, acdb_dev_type;
446
447 acdb_dev_id = acdb_device_table[snd_device];
448 if (acdb_dev_id < 0) {
449 ALOGE("%s: Could not find acdb id for device(%d)",
450 __func__, snd_device);
451 return -EINVAL;
452 }
453 if (my_data->acdb_send_audio_cal) {
Eric Laurent994a6932013-07-17 11:51:42 -0700454 ("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Eric Laurentb23d5282013-05-14 15:27:20 -0700455 __func__, snd_device, acdb_dev_id);
456 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
457 snd_device < SND_DEVICE_OUT_END)
458 acdb_dev_type = ACDB_DEV_TYPE_OUT;
459 else
460 acdb_dev_type = ACDB_DEV_TYPE_IN;
461 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
462 }
463 return 0;
464}
465
466int platform_switch_voice_call_device_pre(void *platform)
467{
468 return 0;
469}
470
471int platform_switch_voice_call_device_post(void *platform,
472 snd_device_t out_snd_device,
473 snd_device_t in_snd_device)
474{
475 struct platform_data *my_data = (struct platform_data *)platform;
476 int acdb_rx_id, acdb_tx_id;
477
478 if (my_data->acdb_send_voice_cal == NULL) {
479 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
480 } else {
481 acdb_rx_id = acdb_device_table[out_snd_device];
482 acdb_tx_id = acdb_device_table[in_snd_device];
483
484 if (acdb_rx_id > 0 && acdb_tx_id > 0)
485 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
486 else
487 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
488 acdb_rx_id, acdb_tx_id);
489 }
490
491 return 0;
492}
493
494int platform_start_voice_call(void *platform)
495{
496 return 0;
497}
498
499int platform_stop_voice_call(void *platform)
500{
501 return 0;
502}
503
504int platform_set_voice_volume(void *platform, int volume)
505{
506 struct platform_data *my_data = (struct platform_data *)platform;
507 struct audio_device *adev = my_data->adev;
508 struct mixer_ctl *ctl;
sangwoo53b2cf02013-07-25 19:18:44 -0700509 const char *mixer_ctl_name = "Voice Rx Gain";
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700510 int vol_index = 0;
511 uint32_t set_values[ ] = {0,
512 ALL_SESSION_VSID,
513 DEFAULT_VOLUME_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -0700514
515 // Voice volume levels are mapped to adsp volume levels as follows.
516 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
517 // But this values don't changed in kernel. So, below change is need.
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700518 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, MAX_VOL_INDEX);
519 set_values[0] = vol_index;
Eric Laurentb23d5282013-05-14 15:27:20 -0700520
521 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
522 if (!ctl) {
523 ALOGE("%s: Could not get ctl for mixer cmd - %s",
524 __func__, mixer_ctl_name);
525 return -EINVAL;
526 }
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700527 ALOGV("Setting voice volume index: %d", set_values[0]);
528 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
Eric Laurentb23d5282013-05-14 15:27:20 -0700529
530 return 0;
531}
532
533int platform_set_mic_mute(void *platform, bool state)
534{
535 struct platform_data *my_data = (struct platform_data *)platform;
536 struct audio_device *adev = my_data->adev;
537 struct mixer_ctl *ctl;
538 const char *mixer_ctl_name = "Voice Tx Mute";
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700539 uint32_t set_values[ ] = {0,
540 ALL_SESSION_VSID,
541 DEFAULT_VOLUME_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -0700542
543 if (adev->mode == AUDIO_MODE_IN_CALL) {
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700544 set_values[0] = state;
Eric Laurentb23d5282013-05-14 15:27:20 -0700545 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
546 if (!ctl) {
547 ALOGE("%s: Could not get ctl for mixer cmd - %s",
548 __func__, mixer_ctl_name);
549 return -EINVAL;
550 }
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700551 ALOGV("Setting voice mute state: %d", state);
552 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
Eric Laurentb23d5282013-05-14 15:27:20 -0700553 }
554
555 return 0;
556}
557
558snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
559{
560 struct platform_data *my_data = (struct platform_data *)platform;
561 struct audio_device *adev = my_data->adev;
562 audio_mode_t mode = adev->mode;
563 snd_device_t snd_device = SND_DEVICE_NONE;
564
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700565 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
566 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
567 int channel_count = popcount(channel_mask);
568
Eric Laurentb23d5282013-05-14 15:27:20 -0700569 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
570 if (devices == AUDIO_DEVICE_NONE ||
571 devices & AUDIO_DEVICE_BIT_IN) {
572 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
573 goto exit;
574 }
575
576 if (mode == AUDIO_MODE_IN_CALL) {
577 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
578 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700579 if (adev->voice.tty_mode == TTY_MODE_FULL) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700580 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700581 } else if (adev->voice.tty_mode == TTY_MODE_VCO) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700582 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700583 } else if (adev->voice.tty_mode == TTY_MODE_HCO) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700584 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700585 } else if (audio_extn_get_anc_enabled()) {
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700586 if (audio_extn_should_use_fb_anc())
587 snd_device = SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET;
588 else
589 snd_device = SND_DEVICE_OUT_VOICE_ANC_HEADSET;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700590 } else {
Eric Laurentb23d5282013-05-14 15:27:20 -0700591 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700592 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700593 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700594 if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ)
595 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
596 else
597 snd_device = SND_DEVICE_OUT_BT_SCO;
Eric Laurentb23d5282013-05-14 15:27:20 -0700598 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
599 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -0700600 } else if (devices & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
601 devices & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
602 snd_device = SND_DEVICE_OUT_USB_HEADSET;
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -0700603 } else if (devices & AUDIO_DEVICE_OUT_FM_TX) {
604 snd_device = SND_DEVICE_OUT_TRANSMISSION_FM;
Eric Laurentb23d5282013-05-14 15:27:20 -0700605 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
606 if (is_operator_tmus())
607 snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS;
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700608 else if (audio_extn_should_use_handset_anc(channel_count))
609 snd_device = SND_DEVICE_OUT_ANC_HANDSET;
Eric Laurentb23d5282013-05-14 15:27:20 -0700610 else
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700611 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
Eric Laurentb23d5282013-05-14 15:27:20 -0700612 }
613 if (snd_device != SND_DEVICE_NONE) {
614 goto exit;
615 }
616 }
617
618 if (popcount(devices) == 2) {
619 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
620 AUDIO_DEVICE_OUT_SPEAKER)) {
621 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
622 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
623 AUDIO_DEVICE_OUT_SPEAKER)) {
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700624 if (audio_extn_get_anc_enabled())
625 snd_device = SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET;
626 else
627 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
Eric Laurentb23d5282013-05-14 15:27:20 -0700628 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
629 AUDIO_DEVICE_OUT_SPEAKER)) {
630 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -0700631 } else if (devices == (AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET |
632 AUDIO_DEVICE_OUT_SPEAKER)) {
633 snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET;
Eric Laurentb23d5282013-05-14 15:27:20 -0700634 } else {
635 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
636 goto exit;
637 }
638 if (snd_device != SND_DEVICE_NONE) {
639 goto exit;
640 }
641 }
642
643 if (popcount(devices) != 1) {
644 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
645 goto exit;
646 }
647
648 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
649 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700650 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADSET
651 && audio_extn_get_anc_enabled()) {
652 if (audio_extn_should_use_fb_anc())
653 snd_device = SND_DEVICE_OUT_ANC_FB_HEADSET;
654 else
655 snd_device = SND_DEVICE_OUT_ANC_HEADSET;
656 }
657 else
658 snd_device = SND_DEVICE_OUT_HEADPHONES;
Eric Laurentb23d5282013-05-14 15:27:20 -0700659 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
660 if (adev->speaker_lr_swap)
661 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
662 else
663 snd_device = SND_DEVICE_OUT_SPEAKER;
664 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700665 if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ)
666 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
667 else
668 snd_device = SND_DEVICE_OUT_BT_SCO;
Eric Laurentb23d5282013-05-14 15:27:20 -0700669 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
670 snd_device = SND_DEVICE_OUT_HDMI ;
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -0700671 } else if (devices & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
672 devices & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
673 snd_device = SND_DEVICE_OUT_USB_HEADSET;
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -0700674 } else if (devices & AUDIO_DEVICE_OUT_FM_TX) {
675 snd_device = SND_DEVICE_OUT_TRANSMISSION_FM;
Eric Laurentb23d5282013-05-14 15:27:20 -0700676 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
677 snd_device = SND_DEVICE_OUT_HANDSET;
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -0700678 } else if (devices & AUDIO_DEVICE_OUT_PROXY) {
679 ALOGD("%s: setting sink capability for Proxy", __func__);
680 audio_extn_set_afe_proxy_channel_mixer(adev);
681 snd_device = SND_DEVICE_OUT_AFE_PROXY;
Eric Laurentb23d5282013-05-14 15:27:20 -0700682 } else {
683 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
684 }
685exit:
686 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
687 return snd_device;
688}
689
690snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
691{
692 struct platform_data *my_data = (struct platform_data *)platform;
693 struct audio_device *adev = my_data->adev;
694 audio_source_t source = (adev->active_input == NULL) ?
695 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
696
697 audio_mode_t mode = adev->mode;
698 audio_devices_t in_device = ((adev->active_input == NULL) ?
699 AUDIO_DEVICE_NONE : adev->active_input->device)
700 & ~AUDIO_DEVICE_BIT_IN;
701 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
702 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
703 snd_device_t snd_device = SND_DEVICE_NONE;
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700704 int channel_count = popcount(channel_mask);
Eric Laurentb23d5282013-05-14 15:27:20 -0700705
706 ALOGV("%s: enter: out_device(%#x) in_device(%#x)",
707 __func__, out_device, in_device);
708 if (mode == AUDIO_MODE_IN_CALL) {
709 if (out_device == AUDIO_DEVICE_NONE) {
710 ALOGE("%s: No output device set for voice call", __func__);
711 goto exit;
712 }
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700713 if (adev->voice.tty_mode != TTY_MODE_OFF) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700714 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
715 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700716 switch (adev->voice.tty_mode) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700717 case TTY_MODE_FULL:
718 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
719 break;
720 case TTY_MODE_VCO:
721 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
722 break;
723 case TTY_MODE_HCO:
724 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
725 break;
726 default:
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700727 ALOGE("%s: Invalid TTY mode (%#x)",
728 __func__, adev->voice.tty_mode);
Eric Laurentb23d5282013-05-14 15:27:20 -0700729 }
730 goto exit;
731 }
732 }
733 if (out_device & AUDIO_DEVICE_OUT_EARPIECE ||
734 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700735 if (out_device & AUDIO_DEVICE_OUT_EARPIECE &&
736 audio_extn_should_use_handset_anc(channel_count)) {
737 snd_device = SND_DEVICE_IN_AANC_HANDSET_MIC;
738 } else if (my_data->fluence_type == FLUENCE_NONE ||
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700739 my_data->fluence_in_voice_call == false) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700740 snd_device = SND_DEVICE_IN_HANDSET_MIC;
741 } else {
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700742 if (is_operator_tmus())
743 snd_device = SND_DEVICE_IN_VOICE_DMIC_TMUS;
Eric Laurentb23d5282013-05-14 15:27:20 -0700744 else
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700745 snd_device = SND_DEVICE_IN_VOICE_DMIC;
746 adev->acdb_settings |= DMIC_FLAG;
Eric Laurentb23d5282013-05-14 15:27:20 -0700747 }
748 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
749 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
750 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700751 if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ)
752 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
753 else
754 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -0700755 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700756 if (my_data->fluence_type != FLUENCE_NONE &&
757 my_data->fluence_in_voice_call &&
758 my_data->fluence_in_spkr_mode) {
759 if(my_data->fluence_type == FLUENCE_DUAL_MIC) {
760 adev->acdb_settings |= DMIC_FLAG;
761 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
762 } else {
763 adev->acdb_settings |= QMIC_FLAG;
764 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_QMIC;
765 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700766 } else {
767 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
768 }
769 }
770 } else if (source == AUDIO_SOURCE_CAMCORDER) {
771 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
772 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
773 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
774 }
775 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
776 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700777 if (channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK)
778 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC;
779 else if (my_data->fluence_in_voice_rec)
780 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700781
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700782 if (snd_device == SND_DEVICE_NONE)
Eric Laurentb23d5282013-05-14 15:27:20 -0700783 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700784 else
785 adev->acdb_settings |= DMIC_FLAG;
Eric Laurentb23d5282013-05-14 15:27:20 -0700786 }
787 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION) {
788 if (out_device & AUDIO_DEVICE_OUT_SPEAKER)
789 in_device = AUDIO_DEVICE_IN_BACK_MIC;
790 if (adev->active_input) {
791 if (adev->active_input->enable_aec) {
792 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
793 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
794 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
795 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
796 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
797 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
798 }
799 set_echo_reference(adev->mixer, "SLIM_RX");
800 } else
801 set_echo_reference(adev->mixer, "NONE");
802 }
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -0700803 } else if (source == AUDIO_SOURCE_FM_RX) {
804 if (in_device & AUDIO_DEVICE_IN_FM_RX) {
805 snd_device = SND_DEVICE_IN_CAPTURE_FM;
806 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700807 } else if (source == AUDIO_SOURCE_DEFAULT) {
808 goto exit;
809 }
810
811
812 if (snd_device != SND_DEVICE_NONE) {
813 goto exit;
814 }
815
816 if (in_device != AUDIO_DEVICE_NONE &&
817 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
818 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
819 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Apoorv Raghuvanshi6178a3f2013-10-19 12:38:54 -0700820 if (audio_extn_ssr_get_enabled() && channel_count == 6)
821 snd_device = SND_DEVICE_IN_QUAD_MIC;
Apoorv Raghuvanshi6bd8dbf2013-10-19 18:37:52 -0700822 else if (channel_count > 1)
823 snd_device = SND_DEVICE_IN_HANDSET_STEREO_DMIC;
Apoorv Raghuvanshi6178a3f2013-10-19 12:38:54 -0700824 else
825 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -0700826 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
827 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
828 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
829 snd_device = SND_DEVICE_IN_HEADSET_MIC;
830 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700831 if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ)
832 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
833 else
834 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -0700835 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
836 snd_device = SND_DEVICE_IN_HDMI_MIC;
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -0700837 } else if (in_device & AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET ||
838 in_device & AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET) {
839 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -0700840 } else if (in_device & AUDIO_DEVICE_IN_FM_RX) {
841 snd_device = SND_DEVICE_IN_CAPTURE_FM;
Eric Laurentb23d5282013-05-14 15:27:20 -0700842 } else {
843 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
844 ALOGW("%s: Using default handset-mic", __func__);
845 snd_device = SND_DEVICE_IN_HANDSET_MIC;
846 }
847 } else {
848 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
849 snd_device = SND_DEVICE_IN_HANDSET_MIC;
850 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
851 snd_device = SND_DEVICE_IN_HEADSET_MIC;
852 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
Apoorv Raghuvanshi6bd8dbf2013-10-19 18:37:52 -0700853 if (channel_count > 1)
854 snd_device = SND_DEVICE_IN_SPEAKER_STEREO_DMIC;
855 else
856 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -0700857 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
858 snd_device = SND_DEVICE_IN_HANDSET_MIC;
859 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700860 if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ)
861 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
862 else
863 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -0700864 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
865 snd_device = SND_DEVICE_IN_HDMI_MIC;
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -0700866 } else if (out_device & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
867 out_device & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
868 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -0700869 } else {
870 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
871 ALOGW("%s: Using default handset-mic", __func__);
872 snd_device = SND_DEVICE_IN_HANDSET_MIC;
873 }
874 }
875exit:
876 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
877 return snd_device;
878}
879
880int platform_set_hdmi_channels(void *platform, int channel_count)
881{
882 struct platform_data *my_data = (struct platform_data *)platform;
883 struct audio_device *adev = my_data->adev;
884 struct mixer_ctl *ctl;
885 const char *channel_cnt_str = NULL;
886 const char *mixer_ctl_name = "HDMI_RX Channels";
887 switch (channel_count) {
888 case 8:
889 channel_cnt_str = "Eight"; break;
890 case 7:
891 channel_cnt_str = "Seven"; break;
892 case 6:
893 channel_cnt_str = "Six"; break;
894 case 5:
895 channel_cnt_str = "Five"; break;
896 case 4:
897 channel_cnt_str = "Four"; break;
898 case 3:
899 channel_cnt_str = "Three"; break;
900 default:
901 channel_cnt_str = "Two"; break;
902 }
903 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
904 if (!ctl) {
905 ALOGE("%s: Could not get ctl for mixer cmd - %s",
906 __func__, mixer_ctl_name);
907 return -EINVAL;
908 }
909 ALOGV("HDMI channel count: %s", channel_cnt_str);
910 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
911 return 0;
912}
913
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -0700914int platform_edid_get_max_channels(void *platform)
Eric Laurentb23d5282013-05-14 15:27:20 -0700915{
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -0700916 struct platform_data *my_data = (struct platform_data *)platform;
917 struct audio_device *adev = my_data->adev;
Eric Laurentb23d5282013-05-14 15:27:20 -0700918 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
919 char *sad = block;
920 int num_audio_blocks;
921 int channel_count;
922 int max_channels = 0;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -0700923 int i, ret, count;
Eric Laurentb23d5282013-05-14 15:27:20 -0700924
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -0700925 struct mixer_ctl *ctl;
926
927 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
928 if (!ctl) {
929 ALOGE("%s: Could not get ctl for mixer cmd - %s",
930 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
Eric Laurentb23d5282013-05-14 15:27:20 -0700931 return 0;
932 }
933
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -0700934 mixer_ctl_update(ctl);
935
936 count = mixer_ctl_get_num_values(ctl);
Eric Laurentb23d5282013-05-14 15:27:20 -0700937
938 /* Read SAD blocks, clamping the maximum size for safety */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -0700939 if (count > (int)sizeof(block))
940 count = (int)sizeof(block);
Eric Laurentb23d5282013-05-14 15:27:20 -0700941
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -0700942 ret = mixer_ctl_get_array(ctl, block, count);
943 if (ret != 0) {
944 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
945 return 0;
946 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700947
948 /* Calculate the number of SAD blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -0700949 num_audio_blocks = count / SAD_BLOCK_SIZE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700950
951 for (i = 0; i < num_audio_blocks; i++) {
952 /* Only consider LPCM blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -0700953 if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
954 sad += 3;
Eric Laurentb23d5282013-05-14 15:27:20 -0700955 continue;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -0700956 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700957
958 channel_count = (sad[0] & 0x7) + 1;
959 if (channel_count > max_channels)
960 max_channels = channel_count;
961
962 /* Advance to next block */
963 sad += 3;
964 }
965
966 return max_channels;
967}
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700968
969static int platform_set_slowtalk(struct platform_data *my_data, bool state)
970{
971 int ret = 0;
972 struct audio_device *adev = my_data->adev;
973 struct mixer_ctl *ctl;
974 const char *mixer_ctl_name = "Slowtalk Enable";
975 uint32_t set_values[ ] = {0,
976 ALL_SESSION_VSID};
977
978 set_values[0] = state;
979 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
980 if (!ctl) {
981 ALOGE("%s: Could not get ctl for mixer cmd - %s",
982 __func__, mixer_ctl_name);
983 ret = -EINVAL;
984 } else {
985 ALOGV("Setting slowtalk state: %d", state);
986 ret = mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
987 my_data->slowtalk = state;
988 }
989
990 return ret;
991}
992
993int platform_set_parameters(void *platform, struct str_parms *parms)
994{
995 struct platform_data *my_data = (struct platform_data *)platform;
996 char *str;
997 char value[32];
998 int val;
999 int ret = 0;
1000
1001 ALOGV("%s: enter: %s", __func__, str_parms_to_str(parms));
1002
1003 ret = str_parms_get_int(parms, AUDIO_PARAMETER_KEY_BTSCO, &val);
1004 if (ret >= 0) {
1005 str_parms_del(parms, AUDIO_PARAMETER_KEY_BTSCO);
1006 pthread_mutex_lock(&my_data->adev->lock);
1007 my_data->btsco_sample_rate = val;
1008 pthread_mutex_unlock(&my_data->adev->lock);
1009 }
1010
1011 ret = str_parms_get_int(parms, AUDIO_PARAMETER_KEY_SLOWTALK, &val);
1012 if (ret >= 0) {
1013 str_parms_del(parms, AUDIO_PARAMETER_KEY_SLOWTALK);
1014 pthread_mutex_lock(&my_data->adev->lock);
1015 ret = platform_set_slowtalk(my_data, val);
1016 if (ret)
1017 ALOGE("%s: Failed to set slow talk err: %d", __func__, ret);
1018 pthread_mutex_unlock(&my_data->adev->lock);
1019 }
1020
1021 ALOGV("%s: exit with code(%d)", __func__, ret);
1022 return ret;
1023}
1024
Shiv Maliyappanahallida107642013-10-17 11:16:13 -07001025int platform_set_incall_recoding_session_id(void *platform,
1026 uint32_t session_id)
1027{
1028 int ret = 0;
1029 struct platform_data *my_data = (struct platform_data *)platform;
1030 struct audio_device *adev = my_data->adev;
1031 struct mixer_ctl *ctl;
1032 const char *mixer_ctl_name = "Voc VSID";
1033 int num_ctl_values;
1034 int i;
1035
1036 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1037 if (!ctl) {
1038 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1039 __func__, mixer_ctl_name);
1040 ret = -EINVAL;
1041 } else {
1042 num_ctl_values = mixer_ctl_get_num_values(ctl);
1043 for (i = 0; i < num_ctl_values; i++) {
1044 if (mixer_ctl_set_value(ctl, i, session_id)) {
1045 ALOGV("Error: invalid session_id: %x", session_id);
1046 ret = -EINVAL;
1047 break;
1048 }
1049 }
1050 }
1051
1052 return ret;
1053}
1054
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07001055void platform_get_parameters(void *platform,
1056 struct str_parms *query,
1057 struct str_parms *reply)
1058{
1059 struct platform_data *my_data = (struct platform_data *)platform;
1060 char *str = NULL;
1061 char value[256] = {0};
1062 int ret;
1063 int fluence_type;
1064
1065 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_FLUENCE_TYPE,
1066 value, sizeof(value));
1067 if (ret >= 0) {
1068 pthread_mutex_lock(&my_data->adev->lock);
1069 if (my_data->fluence_type == FLUENCE_QUAD_MIC) {
1070 strlcpy(value, "fluencepro", sizeof(value));
1071 } else if (my_data->fluence_type == FLUENCE_DUAL_MIC) {
1072 strlcpy(value, "fluence", sizeof(value));
1073 } else {
1074 strlcpy(value, "none", sizeof(value));
1075 }
1076 pthread_mutex_unlock(&my_data->adev->lock);
1077
1078 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_FLUENCE_TYPE, value);
1079 }
1080
1081 ALOGV("%s: exit: returns - %s", __func__, str_parms_to_str(reply));
1082}
1083
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07001084/* Delay in Us */
1085int64_t platform_render_latency(audio_usecase_t usecase)
1086{
1087 switch (usecase) {
1088 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
1089 return DEEP_BUFFER_PLATFORM_DELAY;
1090 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
1091 return LOW_LATENCY_PLATFORM_DELAY;
1092 default:
1093 return 0;
1094 }
1095}