blob: fb14330ae30d8795d3e67b827cc62167f9e4b378 [file] [log] [blame]
Eric Laurentb23d5282013-05-14 15:27:20 -07001/*
Shiv Maliyappanahalli3e064fd2013-12-16 15:54:40 -08002 * Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -07003 * Not a Contribution.
4 *
Shiv Maliyappanahalli8911f282014-01-10 15:56:19 -08005 * Copyright (C) 2013 The Android Open Source Project
Eric Laurentb23d5282013-05-14 15:27:20 -07006 *
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"
Narsinga Rao Chella05573b72013-11-15 15:21:40 -080033#include "voice_extn.h"
Eric Laurentb23d5282013-05-14 15:27:20 -070034
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -070035#define MIXER_XML_PATH "/system/etc/mixer_paths.xml"
Damir Didjustof1d46c72013-11-06 17:59:04 -080036#define MIXER_XML_PATH_AUXPCM "/system/etc/mixer_paths_auxpcm.xml"
Eric Laurentb23d5282013-05-14 15:27:20 -070037#define LIB_ACDB_LOADER "libacdbloader.so"
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -070038#define AUDIO_DATA_BLOCK_MIXER_CTL "HDMI EDID"
Eric Laurentb23d5282013-05-14 15:27:20 -070039
Eric Laurentb23d5282013-05-14 15:27:20 -070040/*
Eric Laurentb23d5282013-05-14 15:27:20 -070041 * This file will have a maximum of 38 bytes:
42 *
43 * 4 bytes: number of audio blocks
44 * 4 bytes: total length of Short Audio Descriptor (SAD) blocks
45 * Maximum 10 * 3 bytes: SAD blocks
46 */
47#define MAX_SAD_BLOCKS 10
48#define SAD_BLOCK_SIZE 3
49
50/* EDID format ID for LPCM audio */
51#define EDID_FORMAT_LPCM 1
52
sangwoo1b9f4b32013-06-21 18:22:55 -070053/* Retry for delay in FW loading*/
54#define RETRY_NUMBER 10
55#define RETRY_US 500000
Apoorv Raghuvanshi84fa2fe2013-12-04 11:57:47 -080056#define MAX_SND_CARD 8
sangwoo1b9f4b32013-06-21 18:22:55 -070057
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -070058#define SAMPLE_RATE_8KHZ 8000
59#define SAMPLE_RATE_16KHZ 16000
60
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -070061#define AUDIO_PARAMETER_KEY_FLUENCE_TYPE "fluence"
62#define AUDIO_PARAMETER_KEY_BTSCO "bt_samplerate"
63#define AUDIO_PARAMETER_KEY_SLOWTALK "st_enable"
Ben Rombergerc1dc70d2013-12-19 15:11:17 -080064#define AUDIO_PARAMETER_KEY_VOLUME_BOOST "volume_boost"
65
66enum {
67 VOICE_FEATURE_SET_DEFAULT,
68 VOICE_FEATURE_SET_VOLUME_BOOST
69};
sangwoo53b2cf02013-07-25 19:18:44 -070070
Eric Laurentb23d5282013-05-14 15:27:20 -070071struct audio_block_header
72{
73 int reserved;
74 int length;
75};
76
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -080077/* Audio calibration related functions */
Eric Laurentb23d5282013-05-14 15:27:20 -070078typedef void (*acdb_deallocate_t)();
Ben Romberger490d3472014-01-15 17:11:59 -080079typedef int (*acdb_init_t)(char *);
Eric Laurentb23d5282013-05-14 15:27:20 -070080typedef void (*acdb_send_audio_cal_t)(int, int);
81typedef void (*acdb_send_voice_cal_t)(int, int);
Ben Rombergerc1dc70d2013-12-19 15:11:17 -080082typedef int (*acdb_reload_vocvoltable_t)(int);
Eric Laurentb23d5282013-05-14 15:27:20 -070083
Eric Laurentb23d5282013-05-14 15:27:20 -070084struct platform_data {
85 struct audio_device *adev;
86 bool fluence_in_spkr_mode;
87 bool fluence_in_voice_call;
88 bool fluence_in_voice_rec;
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -080089 bool fluence_in_audio_rec;
Mingming Yin8e5a4f62013-10-07 15:23:41 -070090 int fluence_type;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -070091 int btsco_sample_rate;
92 bool slowtalk;
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -070093 /* Audio calibration related functions */
Ben Rombergerc1dc70d2013-12-19 15:11:17 -080094 void *acdb_handle;
95 int voice_feature_set;
96 acdb_init_t acdb_init;
97 acdb_deallocate_t acdb_deallocate;
98 acdb_send_audio_cal_t acdb_send_audio_cal;
99 acdb_send_voice_cal_t acdb_send_voice_cal;
100 acdb_reload_vocvoltable_t acdb_reload_vocvoltable;
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -0700101
102 void *hw_info;
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -0800103 struct csd_data *csd;
Eric Laurentb23d5282013-05-14 15:27:20 -0700104};
105
106static const int pcm_device_table[AUDIO_USECASE_MAX][2] = {
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700107 [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = {DEEP_BUFFER_PCM_DEVICE,
108 DEEP_BUFFER_PCM_DEVICE},
109 [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
Preetam Singh Ranawatde84f1a2013-11-01 14:58:16 -0700110 LOWLATENCY_PCM_DEVICE},
111 [USECASE_AUDIO_PLAYBACK_MULTI_CH] = {MULTIMEDIA2_PCM_DEVICE,
112 MULTIMEDIA2_PCM_DEVICE},
Krishnankutty Kolathappillya43f96e2013-11-01 12:17:53 -0700113 [USECASE_AUDIO_PLAYBACK_OFFLOAD] =
114 {PLAYBACK_OFFLOAD_DEVICE, PLAYBACK_OFFLOAD_DEVICE},
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700115 [USECASE_AUDIO_RECORD] = {AUDIO_RECORD_PCM_DEVICE, AUDIO_RECORD_PCM_DEVICE},
Mingming Yine62d7842013-10-25 16:26:03 -0700116 [USECASE_AUDIO_RECORD_COMPRESS] = {COMPRESS_CAPTURE_DEVICE, COMPRESS_CAPTURE_DEVICE},
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700117 [USECASE_AUDIO_RECORD_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
118 LOWLATENCY_PCM_DEVICE},
Preetam Singh Ranawatde84f1a2013-11-01 14:58:16 -0700119 [USECASE_AUDIO_RECORD_FM_VIRTUAL] = {MULTIMEDIA2_PCM_DEVICE,
120 MULTIMEDIA2_PCM_DEVICE},
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -0700121 [USECASE_AUDIO_PLAYBACK_FM] = {FM_PLAYBACK_PCM_DEVICE, FM_CAPTURE_PCM_DEVICE},
Vimal Puthanveed5b4d3f12013-11-05 15:57:39 -0800122 [USECASE_AUDIO_HFP_SCO] = {HFP_PCM_RX, HFP_SCO_RX},
Vimal Puthanveed47e64852013-12-20 13:23:39 -0800123 [USECASE_AUDIO_HFP_SCO_WB] = {HFP_PCM_RX, HFP_SCO_RX},
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700124 [USECASE_VOICE_CALL] = {VOICE_CALL_PCM_DEVICE, VOICE_CALL_PCM_DEVICE},
125 [USECASE_VOICE2_CALL] = {VOICE2_CALL_PCM_DEVICE, VOICE2_CALL_PCM_DEVICE},
126 [USECASE_VOLTE_CALL] = {VOLTE_CALL_PCM_DEVICE, VOLTE_CALL_PCM_DEVICE},
127 [USECASE_QCHAT_CALL] = {QCHAT_CALL_PCM_DEVICE, QCHAT_CALL_PCM_DEVICE},
Narsinga Rao Chella05573b72013-11-15 15:21:40 -0800128 [USECASE_COMPRESS_VOIP_CALL] = {COMPRESS_VOIP_CALL_PCM_DEVICE, COMPRESS_VOIP_CALL_PCM_DEVICE},
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700129 [USECASE_INCALL_REC_UPLINK] = {AUDIO_RECORD_PCM_DEVICE,
130 AUDIO_RECORD_PCM_DEVICE},
131 [USECASE_INCALL_REC_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
132 AUDIO_RECORD_PCM_DEVICE},
133 [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
134 AUDIO_RECORD_PCM_DEVICE},
Helen Zenge56b4852013-12-03 16:54:40 -0800135 [USECASE_INCALL_REC_UPLINK_COMPRESS] = {COMPRESS_CAPTURE_DEVICE,
136 COMPRESS_CAPTURE_DEVICE},
137 [USECASE_INCALL_REC_DOWNLINK_COMPRESS] = {COMPRESS_CAPTURE_DEVICE,
138 COMPRESS_CAPTURE_DEVICE},
139 [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK_COMPRESS] = {COMPRESS_CAPTURE_DEVICE,
140 COMPRESS_CAPTURE_DEVICE},
Shiv Maliyappanahallif3b9a422013-10-22 16:38:08 -0700141 [USECASE_INCALL_MUSIC_UPLINK] = {INCALL_MUSIC_UPLINK_PCM_DEVICE,
142 INCALL_MUSIC_UPLINK_PCM_DEVICE},
143 [USECASE_INCALL_MUSIC_UPLINK2] = {INCALL_MUSIC_UPLINK2_PCM_DEVICE,
144 INCALL_MUSIC_UPLINK2_PCM_DEVICE},
Gopikrishnaiah Anandanf538cef2013-10-28 14:06:03 -0700145 [USECASE_AUDIO_SPKR_CALIB_RX] = {SPKR_PROT_CALIB_RX_PCM_DEVICE, -1},
146 [USECASE_AUDIO_SPKR_CALIB_TX] = {-1, SPKR_PROT_CALIB_TX_PCM_DEVICE},
Eric Laurentb23d5282013-05-14 15:27:20 -0700147};
148
149/* Array to store sound devices */
150static const char * const device_table[SND_DEVICE_MAX] = {
151 [SND_DEVICE_NONE] = "none",
152 /* Playback sound devices */
153 [SND_DEVICE_OUT_HANDSET] = "handset",
154 [SND_DEVICE_OUT_SPEAKER] = "speaker",
155 [SND_DEVICE_OUT_SPEAKER_REVERSE] = "speaker-reverse",
156 [SND_DEVICE_OUT_HEADPHONES] = "headphones",
157 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones",
158 [SND_DEVICE_OUT_VOICE_HANDSET] = "voice-handset",
159 [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker",
160 [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones",
161 [SND_DEVICE_OUT_HDMI] = "hdmi",
162 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi",
163 [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset",
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700164 [SND_DEVICE_OUT_BT_SCO_WB] = "bt-sco-headset-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700165 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones",
166 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones",
167 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset",
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -0700168 [SND_DEVICE_OUT_AFE_PROXY] = "afe-proxy",
169 [SND_DEVICE_OUT_USB_HEADSET] = "usb-headphones",
170 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = "speaker-and-usb-headphones",
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -0700171 [SND_DEVICE_OUT_TRANSMISSION_FM] = "transmission-fm",
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700172 [SND_DEVICE_OUT_ANC_HEADSET] = "anc-headphones",
173 [SND_DEVICE_OUT_ANC_FB_HEADSET] = "anc-fb-headphones",
174 [SND_DEVICE_OUT_VOICE_ANC_HEADSET] = "voice-anc-headphones",
175 [SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET] = "voice-anc-fb-headphones",
176 [SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET] = "speaker-and-anc-headphones",
177 [SND_DEVICE_OUT_ANC_HANDSET] = "anc-handset",
Gopikrishnaiah Anandanf538cef2013-10-28 14:06:03 -0700178 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = "speaker-protected",
Eric Laurentb23d5282013-05-14 15:27:20 -0700179
180 /* Capture sound devices */
181 [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700182 [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic",
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800183 [SND_DEVICE_IN_HANDSET_MIC_NS] = "handset-mic",
184 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = "handset-mic",
185 [SND_DEVICE_IN_HANDSET_DMIC] = "dmic-endfire",
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -0800186 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = "dmic-endfire",
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800187 [SND_DEVICE_IN_HANDSET_DMIC_NS] = "dmic-endfire",
188 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = "dmic-endfire",
189 [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -0800190 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "speaker-mic",
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800191 [SND_DEVICE_IN_SPEAKER_MIC_NS] = "speaker-mic",
192 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = "speaker-mic",
193 [SND_DEVICE_IN_SPEAKER_DMIC] = "speaker-dmic-endfire",
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -0800194 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = "speaker-dmic-endfire",
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800195 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = "speaker-dmic-endfire",
196 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = "speaker-dmic-endfire",
197 [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
198 [SND_DEVICE_IN_HEADSET_MIC_FLUENCE] = "headset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700199 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
200 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
201 [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic",
202 [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700203 [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700204 [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic",
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700205 [SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef",
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700206 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = "voice-speaker-dmic-ef",
Vidyakumar Athotaadfe4e32013-12-13 14:51:26 -0800207 [SND_DEVICE_IN_VOICE_SPEAKER_QMIC] = "voice-speaker-qmic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700208 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
209 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
210 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
211 [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800212 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = "voice-rec-mic",
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -0800213 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = "voice-rec-dmic-ef",
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700214 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence",
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -0700215 [SND_DEVICE_IN_USB_HEADSET_MIC] = "usb-headset-mic",
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -0700216 [SND_DEVICE_IN_CAPTURE_FM] = "capture-fm",
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700217 [SND_DEVICE_IN_AANC_HANDSET_MIC] = "aanc-handset-mic",
Apoorv Raghuvanshi6178a3f2013-10-19 12:38:54 -0700218 [SND_DEVICE_IN_QUAD_MIC] = "quad-mic",
Apoorv Raghuvanshi6bd8dbf2013-10-19 18:37:52 -0700219 [SND_DEVICE_IN_HANDSET_STEREO_DMIC] = "handset-stereo-dmic-ef",
220 [SND_DEVICE_IN_SPEAKER_STEREO_DMIC] = "speaker-stereo-dmic-ef",
Gopikrishnaiah Anandanf538cef2013-10-28 14:06:03 -0700221 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = "vi-feedback",
Eric Laurentb23d5282013-05-14 15:27:20 -0700222};
223
224/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
Ben Romberger55886882014-01-10 13:49:02 -0800225static int acdb_device_table[SND_DEVICE_MAX] = {
Eric Laurentb23d5282013-05-14 15:27:20 -0700226 [SND_DEVICE_NONE] = -1,
227 [SND_DEVICE_OUT_HANDSET] = 7,
Vidyakumar Athotac29d4ab2013-11-14 16:58:02 -0800228 [SND_DEVICE_OUT_SPEAKER] = 14,
229 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 14,
Eric Laurentb23d5282013-05-14 15:27:20 -0700230 [SND_DEVICE_OUT_HEADPHONES] = 10,
231 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
232 [SND_DEVICE_OUT_VOICE_HANDSET] = 7,
Vidyakumar Athotac29d4ab2013-11-14 16:58:02 -0800233 [SND_DEVICE_OUT_VOICE_SPEAKER] = 14,
Eric Laurentb23d5282013-05-14 15:27:20 -0700234 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
235 [SND_DEVICE_OUT_HDMI] = 18,
Vidyakumar Athotac29d4ab2013-11-14 16:58:02 -0800236 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 14,
Eric Laurentb23d5282013-05-14 15:27:20 -0700237 [SND_DEVICE_OUT_BT_SCO] = 22,
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700238 [SND_DEVICE_OUT_BT_SCO_WB] = 39,
Eric Laurentb23d5282013-05-14 15:27:20 -0700239 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
240 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
241 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -0700242 [SND_DEVICE_OUT_AFE_PROXY] = 0,
Vidyakumar Athotab9522202014-01-14 20:08:27 -0800243 [SND_DEVICE_OUT_USB_HEADSET] = 45,
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -0700244 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = 14,
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -0700245 [SND_DEVICE_OUT_TRANSMISSION_FM] = 0,
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700246 [SND_DEVICE_OUT_ANC_HEADSET] = 26,
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -0700247 [SND_DEVICE_OUT_ANC_FB_HEADSET] = 27,
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700248 [SND_DEVICE_OUT_VOICE_ANC_HEADSET] = 26,
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -0700249 [SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET] = 27,
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700250 [SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET] = 26,
251 [SND_DEVICE_OUT_ANC_HANDSET] = 103,
Gopikrishnaiah Anandanf538cef2013-10-28 14:06:03 -0700252 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = 101,
Eric Laurentb23d5282013-05-14 15:27:20 -0700253
254 [SND_DEVICE_IN_HANDSET_MIC] = 4,
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800255 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 106,
256 [SND_DEVICE_IN_HANDSET_MIC_NS] = 107,
257 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = 108,
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -0800258 [SND_DEVICE_IN_HANDSET_DMIC] = 41,
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800259 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = 109,
260 [SND_DEVICE_IN_HANDSET_DMIC_NS] = 110,
261 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = 111,
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -0800262 [SND_DEVICE_IN_SPEAKER_MIC] = 11,
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800263 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 112,
264 [SND_DEVICE_IN_SPEAKER_MIC_NS] = 113,
265 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = 114,
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -0800266 [SND_DEVICE_IN_SPEAKER_DMIC] = 43,
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800267 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = 115,
268 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = 116,
269 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = 117,
Eric Laurentb23d5282013-05-14 15:27:20 -0700270 [SND_DEVICE_IN_HEADSET_MIC] = 8,
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800271 [SND_DEVICE_IN_HEADSET_MIC_FLUENCE] = 47,
Eric Laurentb23d5282013-05-14 15:27:20 -0700272 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
273 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = 8,
274 [SND_DEVICE_IN_HDMI_MIC] = 4,
275 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700276 [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38,
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -0800277 [SND_DEVICE_IN_CAMCORDER_MIC] = 4,
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700278 [SND_DEVICE_IN_VOICE_DMIC] = 41,
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700279 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 43,
Vidyakumar Athotaadfe4e32013-12-13 14:51:26 -0800280 [SND_DEVICE_IN_VOICE_SPEAKER_QMIC] = 19,
Eric Laurentb23d5282013-05-14 15:27:20 -0700281 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
282 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
283 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -0800284 [SND_DEVICE_IN_VOICE_REC_MIC] = 4,
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800285 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = 107,
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -0800286 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = 34,
287 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 41,
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -0700288 [SND_DEVICE_IN_USB_HEADSET_MIC] = 44,
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -0700289 [SND_DEVICE_IN_CAPTURE_FM] = 0,
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700290 [SND_DEVICE_IN_AANC_HANDSET_MIC] = 104,
Apoorv Raghuvanshi6178a3f2013-10-19 12:38:54 -0700291 [SND_DEVICE_IN_QUAD_MIC] = 46,
Apoorv Raghuvanshi6bd8dbf2013-10-19 18:37:52 -0700292 [SND_DEVICE_IN_HANDSET_STEREO_DMIC] = 34,
293 [SND_DEVICE_IN_SPEAKER_STEREO_DMIC] = 35,
Gopikrishnaiah Anandanf538cef2013-10-28 14:06:03 -0700294 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = 102,
Eric Laurentb23d5282013-05-14 15:27:20 -0700295};
296
Ben Romberger61764e32014-01-10 13:49:02 -0800297struct snd_device_index {
298 char name[100];
299 unsigned int index;
300};
301
302#define TO_NAME_INDEX(X) #X, X
303
304/* Used to get index from parsed sting */
305struct snd_device_index snd_device_name_index[SND_DEVICE_MAX] = {
306 {TO_NAME_INDEX(SND_DEVICE_OUT_HANDSET)},
307 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER)},
308 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_REVERSE)},
309 {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES)},
310 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES)},
311 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET)},
312 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER)},
313 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADPHONES)},
314 {TO_NAME_INDEX(SND_DEVICE_OUT_HDMI)},
315 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HDMI)},
316 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO)},
317 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO_WB)},
318 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES)},
319 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES)},
320 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET)},
321 {TO_NAME_INDEX(SND_DEVICE_OUT_AFE_PROXY)},
322 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADSET)},
323 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET)},
324 {TO_NAME_INDEX(SND_DEVICE_OUT_TRANSMISSION_FM)},
325 {TO_NAME_INDEX(SND_DEVICE_OUT_ANC_HEADSET)},
326 {TO_NAME_INDEX(SND_DEVICE_OUT_ANC_FB_HEADSET)},
327 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_ANC_HEADSET)},
328 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET)},
329 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET)},
330 {TO_NAME_INDEX(SND_DEVICE_OUT_ANC_HANDSET)},
331 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED)},
332 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC)},
333 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC)},
334 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_NS)},
335 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)},
336 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC)},
337 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC)},
338 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_NS)},
339 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)},
340 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC)},
341 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC)},
342 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_NS)},
343 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)},
344 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC)},
345 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC)},
346 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS)},
347 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)},
348 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC)},
349 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC_FLUENCE)},
350 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC)},
351 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEADSET_MIC)},
352 {TO_NAME_INDEX(SND_DEVICE_IN_HDMI_MIC)},
353 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC)},
354 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB)},
355 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_MIC)},
356 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC)},
357 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC)},
358 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_QMIC)},
359 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC)},
360 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC)},
361 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC)},
362 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC)},
363 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_NS)},
364 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_STEREO)},
365 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE)},
366 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC)},
367 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_FM)},
368 {TO_NAME_INDEX(SND_DEVICE_IN_AANC_HANDSET_MIC)},
369 {TO_NAME_INDEX(SND_DEVICE_IN_QUAD_MIC)},
370 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_STEREO_DMIC)},
371 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_STEREO_DMIC)},
372 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_VI_FEEDBACK)},
373};
374
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700375#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
376#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
377
Eric Laurentb23d5282013-05-14 15:27:20 -0700378static int set_echo_reference(struct mixer *mixer, const char* ec_ref)
379{
380 struct mixer_ctl *ctl;
381 const char *mixer_ctl_name = "EC_REF_RX";
382
383 ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name);
384 if (!ctl) {
385 ALOGE("%s: Could not get ctl for mixer cmd - %s",
386 __func__, mixer_ctl_name);
387 return -EINVAL;
388 }
389 ALOGV("Setting EC Reference: %s", ec_ref);
390 mixer_ctl_set_enum_by_string(ctl, ec_ref);
391 return 0;
392}
393
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -0800394static struct csd_data *open_csd_client()
395{
396 struct csd_data *csd = calloc(1, sizeof(struct csd_data));
397
398 csd->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
399 if (csd->csd_client == NULL) {
400 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
401 goto error;
402 } else {
403 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
404
405 csd->deinit = (deinit_t)dlsym(csd->csd_client,
406 "csd_client_deinit");
407 if (csd->deinit == NULL) {
408 ALOGE("%s: dlsym error %s for csd_client_deinit", __func__,
409 dlerror());
410 goto error;
411 }
412 csd->disable_device = (disable_device_t)dlsym(csd->csd_client,
413 "csd_client_disable_device");
414 if (csd->disable_device == NULL) {
415 ALOGE("%s: dlsym error %s for csd_client_disable_device",
416 __func__, dlerror());
417 goto error;
418 }
Vidyakumar Athota545dbd32013-11-13 17:30:53 -0800419 csd->enable_device_config = (enable_device_config_t)dlsym(csd->csd_client,
420 "csd_client_enable_device_config");
421 if (csd->enable_device_config == NULL) {
422 ALOGE("%s: dlsym error %s for csd_client_enable_device_config",
423 __func__, dlerror());
424 goto error;
425 }
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -0800426 csd->enable_device = (enable_device_t)dlsym(csd->csd_client,
427 "csd_client_enable_device");
428 if (csd->enable_device == NULL) {
429 ALOGE("%s: dlsym error %s for csd_client_enable_device",
430 __func__, dlerror());
431 goto error;
432 }
433 csd->start_voice = (start_voice_t)dlsym(csd->csd_client,
434 "csd_client_start_voice");
435 if (csd->start_voice == NULL) {
436 ALOGE("%s: dlsym error %s for csd_client_start_voice",
437 __func__, dlerror());
438 goto error;
439 }
440 csd->stop_voice = (stop_voice_t)dlsym(csd->csd_client,
441 "csd_client_stop_voice");
442 if (csd->stop_voice == NULL) {
443 ALOGE("%s: dlsym error %s for csd_client_stop_voice",
444 __func__, dlerror());
445 goto error;
446 }
447 csd->volume = (volume_t)dlsym(csd->csd_client,
448 "csd_client_volume");
449 if (csd->volume == NULL) {
450 ALOGE("%s: dlsym error %s for csd_client_volume",
451 __func__, dlerror());
452 goto error;
453 }
454 csd->mic_mute = (mic_mute_t)dlsym(csd->csd_client,
455 "csd_client_mic_mute");
456 if (csd->mic_mute == NULL) {
457 ALOGE("%s: dlsym error %s for csd_client_mic_mute",
458 __func__, dlerror());
459 goto error;
460 }
461 csd->slow_talk = (slow_talk_t)dlsym(csd->csd_client,
462 "csd_client_slow_talk");
463 if (csd->slow_talk == NULL) {
464 ALOGE("%s: dlsym error %s for csd_client_slow_talk",
465 __func__, dlerror());
466 goto error;
467 }
468 csd->start_playback = (start_playback_t)dlsym(csd->csd_client,
469 "csd_client_start_playback");
470 if (csd->start_playback == NULL) {
471 ALOGE("%s: dlsym error %s for csd_client_start_playback",
472 __func__, dlerror());
473 goto error;
474 }
475 csd->stop_playback = (stop_playback_t)dlsym(csd->csd_client,
476 "csd_client_stop_playback");
477 if (csd->stop_playback == NULL) {
478 ALOGE("%s: dlsym error %s for csd_client_stop_playback",
479 __func__, dlerror());
480 goto error;
481 }
482 csd->start_record = (start_record_t)dlsym(csd->csd_client,
483 "csd_client_start_record");
484 if (csd->start_record == NULL) {
485 ALOGE("%s: dlsym error %s for csd_client_start_record",
486 __func__, dlerror());
487 goto error;
488 }
489 csd->stop_record = (stop_record_t)dlsym(csd->csd_client,
490 "csd_client_stop_record");
491 if (csd->stop_record == NULL) {
492 ALOGE("%s: dlsym error %s for csd_client_stop_record",
493 __func__, dlerror());
494 goto error;
495 }
496 csd->init = (init_t)dlsym(csd->csd_client, "csd_client_init");
497
498 if (csd->init == NULL) {
499 ALOGE("%s: dlsym error %s for csd_client_init",
500 __func__, dlerror());
501 goto error;
502 } else {
503 csd->init();
504 }
505 }
506 return csd;
507
508error:
509 free(csd);
510 csd = NULL;
511 return csd;
512}
513
514void close_csd_client(struct csd_data *csd)
515{
516 if (csd != NULL) {
517 csd->deinit();
518 dlclose(csd->csd_client);
519 free(csd);
520 csd = NULL;
521 }
522}
523
Eric Laurentb23d5282013-05-14 15:27:20 -0700524void *platform_init(struct audio_device *adev)
525{
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -0800526 char platform[PROPERTY_VALUE_MAX];
527 char baseband[PROPERTY_VALUE_MAX];
Eric Laurentb23d5282013-05-14 15:27:20 -0700528 char value[PROPERTY_VALUE_MAX];
Apoorv Raghuvanshi84fa2fe2013-12-04 11:57:47 -0800529 struct platform_data *my_data = NULL;
530 int retry_num = 0, snd_card_num = 0;
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -0700531 const char *snd_card_name;
sangwoo1b9f4b32013-06-21 18:22:55 -0700532
Eric Laurentb23d5282013-05-14 15:27:20 -0700533 my_data = calloc(1, sizeof(struct platform_data));
534
Apoorv Raghuvanshi84fa2fe2013-12-04 11:57:47 -0800535 while (snd_card_num < MAX_SND_CARD) {
536 adev->mixer = mixer_open(snd_card_num);
537
538 while (!adev->mixer && retry_num < RETRY_NUMBER) {
539 usleep(RETRY_US);
540 adev->mixer = mixer_open(snd_card_num);
541 retry_num++;
542 }
543
544 if (!adev->mixer) {
545 ALOGE("%s: Unable to open the mixer card: %d", __func__,
546 snd_card_num);
547 retry_num = 0;
548 snd_card_num++;
549 continue;
550 }
551
552 snd_card_name = mixer_get_name(adev->mixer);
553 ALOGV("%s: snd_card_name: %s", __func__, snd_card_name);
554
555 my_data->hw_info = hw_info_init(snd_card_name);
556 if (!my_data->hw_info) {
557 ALOGE("%s: Failed to init hardware info", __func__);
558 } else {
559 if (audio_extn_read_xml(adev, snd_card_num, MIXER_XML_PATH,
560 MIXER_XML_PATH_AUXPCM) == -ENOSYS)
561 adev->audio_route = audio_route_init(snd_card_num,
562 MIXER_XML_PATH);
563 if (!adev->audio_route) {
564 ALOGE("%s: Failed to init audio route controls, aborting.",
565 __func__);
566 free(my_data);
567 return NULL;
568 }
569 adev->snd_card = snd_card_num;
570 ALOGD("%s: Opened sound card:%d", __func__, snd_card_num);
571 break;
572 }
573 retry_num = 0;
574 snd_card_num++;
575 }
576
577 if (snd_card_num >= MAX_SND_CARD) {
578 ALOGE("%s: Unable to find correct sound card, aborting.", __func__);
579 free(my_data);
580 return NULL;
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -0700581 }
582
Eric Laurentb23d5282013-05-14 15:27:20 -0700583 my_data->adev = adev;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700584 my_data->btsco_sample_rate = SAMPLE_RATE_8KHZ;
Eric Laurentb23d5282013-05-14 15:27:20 -0700585 my_data->fluence_in_spkr_mode = false;
586 my_data->fluence_in_voice_call = false;
587 my_data->fluence_in_voice_rec = false;
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -0800588 my_data->fluence_in_audio_rec = false;
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700589 my_data->fluence_type = FLUENCE_NONE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700590
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700591 property_get("ro.qc.sdk.audio.fluencetype", value, "");
592 if (!strncmp("fluencepro", value, sizeof("fluencepro"))) {
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -0800593 my_data->fluence_type = FLUENCE_QUAD_MIC | FLUENCE_DUAL_MIC;
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700594 } else if (!strncmp("fluence", value, sizeof("fluence"))) {
595 my_data->fluence_type = FLUENCE_DUAL_MIC;
596 } else {
597 my_data->fluence_type = FLUENCE_NONE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700598 }
599
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700600 if (my_data->fluence_type != FLUENCE_NONE) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700601 property_get("persist.audio.fluence.voicecall",value,"");
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700602 if (!strncmp("true", value, sizeof("true"))) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700603 my_data->fluence_in_voice_call = true;
604 }
605
606 property_get("persist.audio.fluence.voicerec",value,"");
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700607 if (!strncmp("true", value, sizeof("true"))) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700608 my_data->fluence_in_voice_rec = true;
609 }
610
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -0800611 property_get("persist.audio.fluence.audiorec",value,"");
612 if (!strncmp("true", value, sizeof("true"))) {
613 my_data->fluence_in_audio_rec = true;
614 }
615
Eric Laurentb23d5282013-05-14 15:27:20 -0700616 property_get("persist.audio.fluence.speaker",value,"");
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700617 if (!strncmp("true", value, sizeof("true"))) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700618 my_data->fluence_in_spkr_mode = true;
619 }
620 }
621
Ben Rombergerc1dc70d2013-12-19 15:11:17 -0800622 my_data->voice_feature_set = VOICE_FEATURE_SET_DEFAULT;
Eric Laurentb23d5282013-05-14 15:27:20 -0700623 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
624 if (my_data->acdb_handle == NULL) {
625 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
626 } else {
627 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
628 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
629 "acdb_loader_deallocate_ACDB");
Ben Rombergerc1dc70d2013-12-19 15:11:17 -0800630 if (!my_data->acdb_deallocate)
631 ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s",
632 __func__, LIB_ACDB_LOADER);
633
Eric Laurentb23d5282013-05-14 15:27:20 -0700634 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
635 "acdb_loader_send_audio_cal");
636 if (!my_data->acdb_send_audio_cal)
Ben Rombergerc1dc70d2013-12-19 15:11:17 -0800637 ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s",
Eric Laurentb23d5282013-05-14 15:27:20 -0700638 __func__, LIB_ACDB_LOADER);
Ben Rombergerc1dc70d2013-12-19 15:11:17 -0800639
Eric Laurentb23d5282013-05-14 15:27:20 -0700640 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
641 "acdb_loader_send_voice_cal");
Ben Rombergerc1dc70d2013-12-19 15:11:17 -0800642 if (!my_data->acdb_send_voice_cal)
643 ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s",
644 __func__, LIB_ACDB_LOADER);
645
646 my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle,
647 "acdb_loader_reload_vocvoltable");
648 if (!my_data->acdb_reload_vocvoltable)
649 ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s",
650 __func__, LIB_ACDB_LOADER);
651
Eric Laurentb23d5282013-05-14 15:27:20 -0700652 my_data->acdb_init = (acdb_init_t)dlsym(my_data->acdb_handle,
Ben Romberger490d3472014-01-15 17:11:59 -0800653 "acdb_loader_init_v2");
Eric Laurentb23d5282013-05-14 15:27:20 -0700654 if (my_data->acdb_init == NULL)
Ben Romberger490d3472014-01-15 17:11:59 -0800655 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__, dlerror());
Eric Laurentb23d5282013-05-14 15:27:20 -0700656 else
Ben Romberger490d3472014-01-15 17:11:59 -0800657 my_data->acdb_init(snd_card_name);
Eric Laurentb23d5282013-05-14 15:27:20 -0700658 }
659
Ben Romberger55886882014-01-10 13:49:02 -0800660 /* Initialize ACDB ID's */
661 platform_info_init();
662
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -0800663 /* If platform is apq8084 and baseband is MDM, load CSD Client specific
664 * symbols. Voice call is handled by MDM and apps processor talks to
665 * MDM through CSD Client
666 */
667 property_get("ro.board.platform", platform, "");
668 property_get("ro.baseband", baseband, "");
669 if (!strncmp("apq8084", platform, sizeof("apq8084")) &&
670 !strncmp("mdm", baseband, sizeof("mdm"))) {
671 my_data->csd = open_csd_client();
672 }
673
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -0700674 /* init usb */
675 audio_extn_usb_init(adev);
Apoorv Raghuvanshi84fa2fe2013-12-04 11:57:47 -0800676 /* update sound cards appropriately */
677 audio_extn_usb_set_proxy_sound_card(adev->snd_card);
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -0700678
Apoorv Raghuvanshi6178a3f2013-10-19 12:38:54 -0700679 /* Read one time ssr property */
Mingming Yin49be8032013-12-19 12:51:25 -0800680 audio_extn_ssr_update_enabled();
Gopikrishnaiah Anandanf538cef2013-10-28 14:06:03 -0700681 audio_extn_spkr_prot_init(adev);
Eric Laurentb23d5282013-05-14 15:27:20 -0700682 return my_data;
683}
684
685void platform_deinit(void *platform)
686{
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -0700687 struct platform_data *my_data = (struct platform_data *)platform;
688
689 hw_info_deinit(my_data->hw_info);
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -0800690 close_csd_client(my_data->csd);
691
Eric Laurentb23d5282013-05-14 15:27:20 -0700692 free(platform);
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -0700693 /* deinit usb */
694 audio_extn_usb_deinit();
Eric Laurentb23d5282013-05-14 15:27:20 -0700695}
696
697const char *platform_get_snd_device_name(snd_device_t snd_device)
698{
699 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX)
700 return device_table[snd_device];
701 else
702 return "";
703}
704
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -0700705int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
706 char *device_name)
707{
708 struct platform_data *my_data = (struct platform_data *)platform;
709
710 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
711 strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE);
712 hw_info_append_hw_type(my_data->hw_info, snd_device, device_name);
713 } else {
714 strlcpy(device_name, "", DEVICE_NAME_MAX_SIZE);
715 return -EINVAL;
716 }
717
718 return 0;
719}
720
Eric Laurentb23d5282013-05-14 15:27:20 -0700721void platform_add_backend_name(char *mixer_path, snd_device_t snd_device)
722{
723 if (snd_device == SND_DEVICE_IN_BT_SCO_MIC)
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700724 strlcat(mixer_path, " bt-sco", MIXER_PATH_MAX_LENGTH);
725 else if (snd_device == SND_DEVICE_IN_BT_SCO_MIC_WB)
726 strlcat(mixer_path, " bt-sco-wb", MIXER_PATH_MAX_LENGTH);
Eric Laurentb23d5282013-05-14 15:27:20 -0700727 else if(snd_device == SND_DEVICE_OUT_BT_SCO)
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700728 strlcat(mixer_path, " bt-sco", MIXER_PATH_MAX_LENGTH);
729 else if(snd_device == SND_DEVICE_OUT_BT_SCO_WB)
730 strlcat(mixer_path, " bt-sco-wb", MIXER_PATH_MAX_LENGTH);
Eric Laurentb23d5282013-05-14 15:27:20 -0700731 else if (snd_device == SND_DEVICE_OUT_HDMI)
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700732 strlcat(mixer_path, " hdmi", MIXER_PATH_MAX_LENGTH);
Eric Laurentb23d5282013-05-14 15:27:20 -0700733 else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HDMI)
734 strcat(mixer_path, " speaker-and-hdmi");
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -0700735 else if (snd_device == SND_DEVICE_OUT_AFE_PROXY)
736 strlcat(mixer_path, " afe-proxy", MIXER_PATH_MAX_LENGTH);
737 else if (snd_device == SND_DEVICE_OUT_USB_HEADSET)
738 strlcat(mixer_path, " usb-headphones", MIXER_PATH_MAX_LENGTH);
739 else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET)
740 strlcat(mixer_path, " speaker-and-usb-headphones",
741 MIXER_PATH_MAX_LENGTH);
742 else if (snd_device == SND_DEVICE_IN_USB_HEADSET_MIC)
743 strlcat(mixer_path, " usb-headset-mic", MIXER_PATH_MAX_LENGTH);
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -0700744 else if (snd_device == SND_DEVICE_IN_CAPTURE_FM)
745 strlcat(mixer_path, " capture-fm", MIXER_PATH_MAX_LENGTH);
746 else if (snd_device == SND_DEVICE_OUT_TRANSMISSION_FM)
747 strlcat(mixer_path, " transmission-fm", MIXER_PATH_MAX_LENGTH);
Eric Laurentb23d5282013-05-14 15:27:20 -0700748}
749
750int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
751{
752 int device_id;
753 if (device_type == PCM_PLAYBACK)
754 device_id = pcm_device_table[usecase][0];
755 else
756 device_id = pcm_device_table[usecase][1];
757 return device_id;
758}
759
Ben Romberger61764e32014-01-10 13:49:02 -0800760int platform_get_snd_device_index(char *snd_device_index_name)
761{
762 int ret = 0;
763 int i;
764
765 if (snd_device_index_name == NULL) {
766 ALOGE("%s: snd_device_index_name is NULL", __func__);
767 ret = -ENODEV;
768 goto done;
769 }
770
771 for (i=0; i < SND_DEVICE_MAX; i++) {
772 if(strcmp(snd_device_name_index[i].name, snd_device_index_name) == 0) {
773 ret = snd_device_name_index[i].index;
774 goto done;
775 }
776 }
777 ALOGE("%s: Could not find index for snd_device_index_name = %s",
778 __func__, snd_device_index_name);
779 ret = -ENODEV;
780done:
781 return ret;
782}
783
Ben Romberger55886882014-01-10 13:49:02 -0800784int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
785{
786 int ret = 0;
787
788 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
789 ALOGE("%s: Invalid snd_device = %d",
790 __func__, snd_device);
791 ret = -EINVAL;
792 goto done;
793 }
794
795 acdb_device_table[snd_device] = acdb_id;
796done:
797 return ret;
798}
799
Eric Laurentb23d5282013-05-14 15:27:20 -0700800int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
801{
802 struct platform_data *my_data = (struct platform_data *)platform;
803 int acdb_dev_id, acdb_dev_type;
804
805 acdb_dev_id = acdb_device_table[snd_device];
806 if (acdb_dev_id < 0) {
807 ALOGE("%s: Could not find acdb id for device(%d)",
808 __func__, snd_device);
809 return -EINVAL;
810 }
811 if (my_data->acdb_send_audio_cal) {
Eric Laurent994a6932013-07-17 11:51:42 -0700812 ("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Eric Laurentb23d5282013-05-14 15:27:20 -0700813 __func__, snd_device, acdb_dev_id);
814 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
815 snd_device < SND_DEVICE_OUT_END)
816 acdb_dev_type = ACDB_DEV_TYPE_OUT;
817 else
818 acdb_dev_type = ACDB_DEV_TYPE_IN;
819 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
820 }
821 return 0;
822}
823
824int platform_switch_voice_call_device_pre(void *platform)
825{
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -0800826 struct platform_data *my_data = (struct platform_data *)platform;
827 int ret = 0;
828
Vidyakumar Athota1fd21792013-11-15 14:50:57 -0800829 if (my_data->csd != NULL &&
830 my_data->adev->mode == AUDIO_MODE_IN_CALL) {
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -0800831 /* This must be called before disabling mixer controls on APQ side */
832 ret = my_data->csd->disable_device();
833 if (ret < 0) {
834 ALOGE("%s: csd_client_disable_device, failed, error %d",
835 __func__, ret);
836 }
837 }
838 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -0700839}
840
Vidyakumar Athota545dbd32013-11-13 17:30:53 -0800841int platform_switch_voice_call_enable_device_config(void *platform,
842 snd_device_t out_snd_device,
843 snd_device_t in_snd_device)
844{
845 struct platform_data *my_data = (struct platform_data *)platform;
846 int acdb_rx_id, acdb_tx_id;
847 int ret = 0;
848
849 acdb_rx_id = acdb_device_table[out_snd_device];
850 acdb_tx_id = acdb_device_table[in_snd_device];
851
852 if (my_data->csd != NULL) {
853 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
854 ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
855 if (ret < 0) {
856 ALOGE("%s: csd_enable_device_config, failed, error %d",
857 __func__, ret);
858 }
859 } else {
860 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
861 acdb_rx_id, acdb_tx_id);
862 }
863 }
864 return ret;
865}
866
Eric Laurentb23d5282013-05-14 15:27:20 -0700867int platform_switch_voice_call_device_post(void *platform,
868 snd_device_t out_snd_device,
869 snd_device_t in_snd_device)
870{
871 struct platform_data *my_data = (struct platform_data *)platform;
872 int acdb_rx_id, acdb_tx_id;
873
874 if (my_data->acdb_send_voice_cal == NULL) {
875 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
876 } else {
Vidyakumar Athota1fd21792013-11-15 14:50:57 -0800877 acdb_rx_id = acdb_device_table[out_snd_device];
878 acdb_tx_id = acdb_device_table[in_snd_device];
879
Eric Laurentb23d5282013-05-14 15:27:20 -0700880 if (acdb_rx_id > 0 && acdb_tx_id > 0)
881 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
882 else
883 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
884 acdb_rx_id, acdb_tx_id);
885 }
886
Vidyakumar Athota1fd21792013-11-15 14:50:57 -0800887 return 0;
888}
889
890int platform_switch_voice_call_usecase_route_post(void *platform,
891 snd_device_t out_snd_device,
892 snd_device_t in_snd_device)
893{
894 struct platform_data *my_data = (struct platform_data *)platform;
895 int acdb_rx_id, acdb_tx_id;
896 int ret = 0;
897
898 acdb_rx_id = acdb_device_table[out_snd_device];
899 acdb_tx_id = acdb_device_table[in_snd_device];
900
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -0800901 if (my_data->csd != NULL) {
Vidyakumar Athota1fd21792013-11-15 14:50:57 -0800902 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -0800903 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
904 my_data->adev->acdb_settings);
905 if (ret < 0) {
906 ALOGE("%s: csd_enable_device, failed, error %d",
907 __func__, ret);
908 }
909 } else {
910 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
911 acdb_rx_id, acdb_tx_id);
912 }
913 }
914 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -0700915}
916
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -0800917int platform_start_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -0700918{
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -0800919 struct platform_data *my_data = (struct platform_data *)platform;
920 int ret = 0;
921
922 if (my_data->csd != NULL) {
923 ret = my_data->csd->start_voice(vsid);
924 if (ret < 0) {
925 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
926 }
927 }
928 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -0700929}
930
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -0800931int platform_stop_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -0700932{
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -0800933 struct platform_data *my_data = (struct platform_data *)platform;
934 int ret = 0;
935
936 if (my_data->csd != NULL) {
937 ret = my_data->csd->stop_voice(vsid);
938 if (ret < 0) {
939 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
940 }
941 }
942 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -0700943}
944
945int platform_set_voice_volume(void *platform, int volume)
946{
947 struct platform_data *my_data = (struct platform_data *)platform;
948 struct audio_device *adev = my_data->adev;
949 struct mixer_ctl *ctl;
sangwoo53b2cf02013-07-25 19:18:44 -0700950 const char *mixer_ctl_name = "Voice Rx Gain";
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -0800951 int vol_index = 0, ret = 0;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700952 uint32_t set_values[ ] = {0,
953 ALL_SESSION_VSID,
954 DEFAULT_VOLUME_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -0700955
956 // Voice volume levels are mapped to adsp volume levels as follows.
957 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
958 // But this values don't changed in kernel. So, below change is need.
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700959 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, MAX_VOL_INDEX);
960 set_values[0] = vol_index;
Eric Laurentb23d5282013-05-14 15:27:20 -0700961
962 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
963 if (!ctl) {
964 ALOGE("%s: Could not get ctl for mixer cmd - %s",
965 __func__, mixer_ctl_name);
966 return -EINVAL;
967 }
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700968 ALOGV("Setting voice volume index: %d", set_values[0]);
969 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
Eric Laurentb23d5282013-05-14 15:27:20 -0700970
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -0800971 if (my_data->csd != NULL) {
972 ret = my_data->csd->volume(ALL_SESSION_VSID, volume);
973 if (ret < 0) {
974 ALOGE("%s: csd_volume error %d", __func__, ret);
975 }
976 }
977 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -0700978}
979
980int platform_set_mic_mute(void *platform, bool state)
981{
982 struct platform_data *my_data = (struct platform_data *)platform;
983 struct audio_device *adev = my_data->adev;
984 struct mixer_ctl *ctl;
985 const char *mixer_ctl_name = "Voice Tx Mute";
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -0800986 int ret = 0;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700987 uint32_t set_values[ ] = {0,
988 ALL_SESSION_VSID,
989 DEFAULT_VOLUME_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -0700990
Narsinga Rao Chella05573b72013-11-15 15:21:40 -0800991 set_values[0] = state;
992 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
993 if (!ctl) {
994 ALOGE("%s: Could not get ctl for mixer cmd - %s",
995 __func__, mixer_ctl_name);
996 return -EINVAL;
997 }
998 ALOGV("Setting voice mute state: %d", state);
999 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
Eric Laurentb23d5282013-05-14 15:27:20 -07001000
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08001001 if (my_data->csd != NULL) {
1002 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state);
1003 if (ret < 0) {
1004 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08001005 }
1006 }
1007 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001008}
1009
1010snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
1011{
1012 struct platform_data *my_data = (struct platform_data *)platform;
1013 struct audio_device *adev = my_data->adev;
1014 audio_mode_t mode = adev->mode;
1015 snd_device_t snd_device = SND_DEVICE_NONE;
1016
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -07001017 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
1018 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
1019 int channel_count = popcount(channel_mask);
1020
Eric Laurentb23d5282013-05-14 15:27:20 -07001021 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
1022 if (devices == AUDIO_DEVICE_NONE ||
1023 devices & AUDIO_DEVICE_BIT_IN) {
1024 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
1025 goto exit;
1026 }
1027
Mingming Yin4a72d652014-01-03 18:54:18 -08001028 if (popcount(devices) == 2) {
1029 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
1030 AUDIO_DEVICE_OUT_SPEAKER)) {
1031 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
1032 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
1033 AUDIO_DEVICE_OUT_SPEAKER)) {
1034 if (audio_extn_get_anc_enabled())
1035 snd_device = SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET;
1036 else
1037 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
1038 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
1039 AUDIO_DEVICE_OUT_SPEAKER)) {
1040 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
1041 } else if (devices == (AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET |
1042 AUDIO_DEVICE_OUT_SPEAKER)) {
1043 snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET;
1044 } else {
1045 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
1046 goto exit;
1047 }
1048 if (snd_device != SND_DEVICE_NONE) {
1049 goto exit;
1050 }
1051 }
1052
1053 if (popcount(devices) != 1) {
1054 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
1055 goto exit;
1056 }
1057
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08001058 if ((mode == AUDIO_MODE_IN_CALL) ||
1059 voice_extn_compress_voip_is_active(adev)) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001060 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1061 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08001062 if ((adev->voice.tty_mode != TTY_MODE_OFF) &&
1063 !voice_extn_compress_voip_is_active(adev)) {
1064 switch (adev->voice.tty_mode) {
1065 case TTY_MODE_FULL:
1066 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
1067 break;
1068 case TTY_MODE_VCO:
1069 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
1070 break;
1071 case TTY_MODE_HCO:
1072 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
1073 break;
1074 default:
1075 ALOGE("%s: Invalid TTY mode (%#x)",
1076 __func__, adev->voice.tty_mode);
1077 }
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07001078 } else if (audio_extn_get_anc_enabled()) {
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -07001079 if (audio_extn_should_use_fb_anc())
1080 snd_device = SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET;
1081 else
1082 snd_device = SND_DEVICE_OUT_VOICE_ANC_HEADSET;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07001083 } else {
Eric Laurentb23d5282013-05-14 15:27:20 -07001084 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07001085 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001086 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07001087 if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ)
1088 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
1089 else
1090 snd_device = SND_DEVICE_OUT_BT_SCO;
Eric Laurentb23d5282013-05-14 15:27:20 -07001091 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
1092 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -07001093 } else if (devices & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
1094 devices & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
1095 snd_device = SND_DEVICE_OUT_USB_HEADSET;
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -07001096 } else if (devices & AUDIO_DEVICE_OUT_FM_TX) {
1097 snd_device = SND_DEVICE_OUT_TRANSMISSION_FM;
Eric Laurentb23d5282013-05-14 15:27:20 -07001098 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Ravi Kumar Alamandaceb40822013-11-06 11:01:47 -08001099 if (audio_extn_should_use_handset_anc(channel_count))
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -07001100 snd_device = SND_DEVICE_OUT_ANC_HANDSET;
Eric Laurentb23d5282013-05-14 15:27:20 -07001101 else
Mingming Yin8e5a4f62013-10-07 15:23:41 -07001102 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
Eric Laurentb23d5282013-05-14 15:27:20 -07001103 }
1104 if (snd_device != SND_DEVICE_NONE) {
1105 goto exit;
1106 }
1107 }
1108
Eric Laurentb23d5282013-05-14 15:27:20 -07001109 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1110 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -07001111 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADSET
1112 && audio_extn_get_anc_enabled()) {
1113 if (audio_extn_should_use_fb_anc())
1114 snd_device = SND_DEVICE_OUT_ANC_FB_HEADSET;
1115 else
1116 snd_device = SND_DEVICE_OUT_ANC_HEADSET;
1117 }
1118 else
1119 snd_device = SND_DEVICE_OUT_HEADPHONES;
Eric Laurentb23d5282013-05-14 15:27:20 -07001120 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
1121 if (adev->speaker_lr_swap)
1122 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
1123 else
1124 snd_device = SND_DEVICE_OUT_SPEAKER;
1125 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07001126 if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ)
1127 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
1128 else
1129 snd_device = SND_DEVICE_OUT_BT_SCO;
Eric Laurentb23d5282013-05-14 15:27:20 -07001130 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
1131 snd_device = SND_DEVICE_OUT_HDMI ;
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -07001132 } else if (devices & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
1133 devices & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
1134 snd_device = SND_DEVICE_OUT_USB_HEADSET;
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -07001135 } else if (devices & AUDIO_DEVICE_OUT_FM_TX) {
1136 snd_device = SND_DEVICE_OUT_TRANSMISSION_FM;
Eric Laurentb23d5282013-05-14 15:27:20 -07001137 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
1138 snd_device = SND_DEVICE_OUT_HANDSET;
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -07001139 } else if (devices & AUDIO_DEVICE_OUT_PROXY) {
1140 ALOGD("%s: setting sink capability for Proxy", __func__);
1141 audio_extn_set_afe_proxy_channel_mixer(adev);
1142 snd_device = SND_DEVICE_OUT_AFE_PROXY;
Eric Laurentb23d5282013-05-14 15:27:20 -07001143 } else {
1144 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
1145 }
1146exit:
1147 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
1148 return snd_device;
1149}
1150
1151snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
1152{
1153 struct platform_data *my_data = (struct platform_data *)platform;
1154 struct audio_device *adev = my_data->adev;
1155 audio_source_t source = (adev->active_input == NULL) ?
1156 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
1157
1158 audio_mode_t mode = adev->mode;
1159 audio_devices_t in_device = ((adev->active_input == NULL) ?
1160 AUDIO_DEVICE_NONE : adev->active_input->device)
1161 & ~AUDIO_DEVICE_BIT_IN;
1162 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
1163 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
1164 snd_device_t snd_device = SND_DEVICE_NONE;
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -07001165 int channel_count = popcount(channel_mask);
Eric Laurentb23d5282013-05-14 15:27:20 -07001166
1167 ALOGV("%s: enter: out_device(%#x) in_device(%#x)",
1168 __func__, out_device, in_device);
Helen Zeng067b96b2013-11-26 12:10:29 -08001169 if ((out_device != AUDIO_DEVICE_NONE) && ((mode == AUDIO_MODE_IN_CALL) ||
1170 voice_extn_compress_voip_is_active(adev))) {
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08001171 if ((adev->voice.tty_mode != TTY_MODE_OFF) &&
1172 !voice_extn_compress_voip_is_active(adev)) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001173 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1174 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07001175 switch (adev->voice.tty_mode) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001176 case TTY_MODE_FULL:
1177 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
1178 break;
1179 case TTY_MODE_VCO:
1180 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
1181 break;
1182 case TTY_MODE_HCO:
1183 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
1184 break;
1185 default:
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07001186 ALOGE("%s: Invalid TTY mode (%#x)",
1187 __func__, adev->voice.tty_mode);
Eric Laurentb23d5282013-05-14 15:27:20 -07001188 }
1189 goto exit;
1190 }
1191 }
1192 if (out_device & AUDIO_DEVICE_OUT_EARPIECE ||
1193 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -07001194 if (out_device & AUDIO_DEVICE_OUT_EARPIECE &&
1195 audio_extn_should_use_handset_anc(channel_count)) {
1196 snd_device = SND_DEVICE_IN_AANC_HANDSET_MIC;
1197 } else if (my_data->fluence_type == FLUENCE_NONE ||
Mingming Yin8e5a4f62013-10-07 15:23:41 -07001198 my_data->fluence_in_voice_call == false) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001199 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Laxminath Kasam7294f522013-12-11 05:07:00 +05301200 set_echo_reference(adev->mixer, EC_REF_RX);
Eric Laurentb23d5282013-05-14 15:27:20 -07001201 } else {
Ravi Kumar Alamandaceb40822013-11-06 11:01:47 -08001202 snd_device = SND_DEVICE_IN_VOICE_DMIC;
Mingming Yin8e5a4f62013-10-07 15:23:41 -07001203 adev->acdb_settings |= DMIC_FLAG;
Eric Laurentb23d5282013-05-14 15:27:20 -07001204 }
1205 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
1206 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
1207 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07001208 if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ)
1209 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
1210 else
1211 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07001212 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
Mingming Yin8e5a4f62013-10-07 15:23:41 -07001213 if (my_data->fluence_type != FLUENCE_NONE &&
1214 my_data->fluence_in_voice_call &&
1215 my_data->fluence_in_spkr_mode) {
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -08001216 if(my_data->fluence_type & FLUENCE_QUAD_MIC) {
Mingming Yin8e5a4f62013-10-07 15:23:41 -07001217 adev->acdb_settings |= QMIC_FLAG;
1218 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_QMIC;
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -08001219 } else {
1220 adev->acdb_settings |= DMIC_FLAG;
1221 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
Mingming Yin8e5a4f62013-10-07 15:23:41 -07001222 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001223 } else {
1224 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
1225 }
1226 }
1227 } else if (source == AUDIO_SOURCE_CAMCORDER) {
1228 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
1229 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
1230 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
1231 }
1232 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
1233 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -08001234 if (channel_count == 2) {
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -08001235 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
Mingming Yin8e5a4f62013-10-07 15:23:41 -07001236 adev->acdb_settings |= DMIC_FLAG;
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -08001237 } else if (adev->active_input->enable_ns)
1238 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
1239 else if (my_data->fluence_type != FLUENCE_NONE &&
1240 my_data->fluence_in_voice_rec) {
1241 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
1242 adev->acdb_settings |= DMIC_FLAG;
1243 } else {
1244 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
1245 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001246 }
1247 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION) {
1248 if (out_device & AUDIO_DEVICE_OUT_SPEAKER)
1249 in_device = AUDIO_DEVICE_IN_BACK_MIC;
1250 if (adev->active_input) {
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -08001251 if (adev->active_input->enable_aec &&
1252 adev->active_input->enable_ns) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001253 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -08001254 if (my_data->fluence_type & FLUENCE_DUAL_MIC &&
1255 my_data->fluence_in_spkr_mode) {
1256 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
1257 adev->acdb_settings |= DMIC_FLAG;
1258 } else
1259 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
Eric Laurentb23d5282013-05-14 15:27:20 -07001260 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -08001261 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1262 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
1263 adev->acdb_settings |= DMIC_FLAG;
1264 } else
1265 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
Eric Laurentb23d5282013-05-14 15:27:20 -07001266 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -08001267 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001268 }
Laxminath Kasam7294f522013-12-11 05:07:00 +05301269 set_echo_reference(adev->mixer, EC_REF_RX);
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -08001270 } else if (adev->active_input->enable_aec) {
1271 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
1272 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1273 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
1274 adev->acdb_settings |= DMIC_FLAG;
1275 } else
1276 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
1277 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
1278 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1279 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
1280 adev->acdb_settings |= DMIC_FLAG;
1281 } else
1282 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
1283 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
1284 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
1285 }
Laxminath Kasam7294f522013-12-11 05:07:00 +05301286 set_echo_reference(adev->mixer, EC_REF_RX);
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -08001287 } else if (adev->active_input->enable_ns) {
1288 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
1289 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1290 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
1291 adev->acdb_settings |= DMIC_FLAG;
1292 } else
1293 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
1294 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
1295 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1296 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
1297 adev->acdb_settings |= DMIC_FLAG;
1298 } else
1299 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
1300 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
1301 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
1302 }
1303 set_echo_reference(adev->mixer, "NONE");
Eric Laurentb23d5282013-05-14 15:27:20 -07001304 } else
1305 set_echo_reference(adev->mixer, "NONE");
1306 }
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -08001307 } else if (source == AUDIO_SOURCE_MIC) {
Apoorv Raghuvanshic0536542013-11-14 16:25:59 -08001308 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC &&
1309 channel_count == 1 ) {
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -08001310 if(my_data->fluence_type & FLUENCE_DUAL_MIC &&
1311 my_data->fluence_in_audio_rec)
1312 snd_device = SND_DEVICE_IN_HANDSET_DMIC;
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -08001313 }
Mingming Yinab429782013-11-07 11:16:55 -08001314 } else if (source == AUDIO_SOURCE_FM_RX ||
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -08001315 source == AUDIO_SOURCE_FM_RX_A2DP) {
Preetam Singh Ranawatde84f1a2013-11-01 14:58:16 -07001316 snd_device = SND_DEVICE_IN_CAPTURE_FM;
Eric Laurentb23d5282013-05-14 15:27:20 -07001317 } else if (source == AUDIO_SOURCE_DEFAULT) {
1318 goto exit;
1319 }
1320
1321
1322 if (snd_device != SND_DEVICE_NONE) {
1323 goto exit;
1324 }
1325
1326 if (in_device != AUDIO_DEVICE_NONE &&
1327 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
1328 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
1329 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Apoorv Raghuvanshi6178a3f2013-10-19 12:38:54 -07001330 if (audio_extn_ssr_get_enabled() && channel_count == 6)
1331 snd_device = SND_DEVICE_IN_QUAD_MIC;
Walter Yangbc136bd2014-01-17 11:24:23 +08001332 else if (my_data->fluence_type & (FLUENCE_DUAL_MIC | FLUENCE_QUAD_MIC) &&
1333 channel_count == 2)
Apoorv Raghuvanshi6bd8dbf2013-10-19 18:37:52 -07001334 snd_device = SND_DEVICE_IN_HANDSET_STEREO_DMIC;
Apoorv Raghuvanshi6178a3f2013-10-19 12:38:54 -07001335 else
1336 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07001337 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
1338 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
1339 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
1340 snd_device = SND_DEVICE_IN_HEADSET_MIC;
1341 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07001342 if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ)
1343 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
1344 else
1345 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07001346 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
1347 snd_device = SND_DEVICE_IN_HDMI_MIC;
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -07001348 } else if (in_device & AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET ||
1349 in_device & AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET) {
1350 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -07001351 } else if (in_device & AUDIO_DEVICE_IN_FM_RX) {
1352 snd_device = SND_DEVICE_IN_CAPTURE_FM;
Eric Laurentb23d5282013-05-14 15:27:20 -07001353 } else {
1354 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
1355 ALOGW("%s: Using default handset-mic", __func__);
1356 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1357 }
1358 } else {
1359 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
1360 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1361 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
1362 snd_device = SND_DEVICE_IN_HEADSET_MIC;
1363 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
Apoorv Raghuvanshi6bd8dbf2013-10-19 18:37:52 -07001364 if (channel_count > 1)
1365 snd_device = SND_DEVICE_IN_SPEAKER_STEREO_DMIC;
1366 else
1367 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07001368 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
1369 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1370 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07001371 if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ)
1372 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
1373 else
1374 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07001375 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
1376 snd_device = SND_DEVICE_IN_HDMI_MIC;
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -07001377 } else if (out_device & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
1378 out_device & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
1379 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07001380 } else {
1381 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
1382 ALOGW("%s: Using default handset-mic", __func__);
1383 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1384 }
1385 }
1386exit:
1387 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
1388 return snd_device;
1389}
1390
1391int platform_set_hdmi_channels(void *platform, int channel_count)
1392{
1393 struct platform_data *my_data = (struct platform_data *)platform;
1394 struct audio_device *adev = my_data->adev;
1395 struct mixer_ctl *ctl;
1396 const char *channel_cnt_str = NULL;
1397 const char *mixer_ctl_name = "HDMI_RX Channels";
1398 switch (channel_count) {
1399 case 8:
1400 channel_cnt_str = "Eight"; break;
1401 case 7:
1402 channel_cnt_str = "Seven"; break;
1403 case 6:
1404 channel_cnt_str = "Six"; break;
1405 case 5:
1406 channel_cnt_str = "Five"; break;
1407 case 4:
1408 channel_cnt_str = "Four"; break;
1409 case 3:
1410 channel_cnt_str = "Three"; break;
1411 default:
1412 channel_cnt_str = "Two"; break;
1413 }
1414 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1415 if (!ctl) {
1416 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1417 __func__, mixer_ctl_name);
1418 return -EINVAL;
1419 }
1420 ALOGV("HDMI channel count: %s", channel_cnt_str);
1421 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
1422 return 0;
1423}
1424
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07001425int platform_edid_get_max_channels(void *platform)
Eric Laurentb23d5282013-05-14 15:27:20 -07001426{
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07001427 struct platform_data *my_data = (struct platform_data *)platform;
1428 struct audio_device *adev = my_data->adev;
Eric Laurentb23d5282013-05-14 15:27:20 -07001429 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
1430 char *sad = block;
1431 int num_audio_blocks;
1432 int channel_count;
1433 int max_channels = 0;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07001434 int i, ret, count;
Eric Laurentb23d5282013-05-14 15:27:20 -07001435
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07001436 struct mixer_ctl *ctl;
1437
1438 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
1439 if (!ctl) {
1440 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1441 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
Eric Laurentb23d5282013-05-14 15:27:20 -07001442 return 0;
1443 }
1444
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07001445 mixer_ctl_update(ctl);
1446
1447 count = mixer_ctl_get_num_values(ctl);
Eric Laurentb23d5282013-05-14 15:27:20 -07001448
1449 /* Read SAD blocks, clamping the maximum size for safety */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07001450 if (count > (int)sizeof(block))
1451 count = (int)sizeof(block);
Eric Laurentb23d5282013-05-14 15:27:20 -07001452
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07001453 ret = mixer_ctl_get_array(ctl, block, count);
1454 if (ret != 0) {
1455 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
1456 return 0;
1457 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001458
1459 /* Calculate the number of SAD blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07001460 num_audio_blocks = count / SAD_BLOCK_SIZE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001461
1462 for (i = 0; i < num_audio_blocks; i++) {
1463 /* Only consider LPCM blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07001464 if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
1465 sad += 3;
Eric Laurentb23d5282013-05-14 15:27:20 -07001466 continue;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07001467 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001468
1469 channel_count = (sad[0] & 0x7) + 1;
1470 if (channel_count > max_channels)
1471 max_channels = channel_count;
1472
1473 /* Advance to next block */
1474 sad += 3;
1475 }
1476
1477 return max_channels;
1478}
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07001479
1480static int platform_set_slowtalk(struct platform_data *my_data, bool state)
1481{
1482 int ret = 0;
1483 struct audio_device *adev = my_data->adev;
1484 struct mixer_ctl *ctl;
1485 const char *mixer_ctl_name = "Slowtalk Enable";
1486 uint32_t set_values[ ] = {0,
1487 ALL_SESSION_VSID};
1488
1489 set_values[0] = state;
1490 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1491 if (!ctl) {
1492 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1493 __func__, mixer_ctl_name);
1494 ret = -EINVAL;
1495 } else {
1496 ALOGV("Setting slowtalk state: %d", state);
1497 ret = mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1498 my_data->slowtalk = state;
1499 }
1500
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08001501 if (my_data->csd != NULL) {
1502 ret = my_data->csd->slow_talk(ALL_SESSION_VSID, state);
1503 if (ret < 0) {
1504 ALOGE("%s: csd_client_disable_device, failed, error %d",
1505 __func__, ret);
1506 }
1507 }
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07001508 return ret;
1509}
1510
1511int platform_set_parameters(void *platform, struct str_parms *parms)
1512{
1513 struct platform_data *my_data = (struct platform_data *)platform;
1514 char *str;
Vidyakumar Athota3ade2792013-12-02 11:02:20 -08001515 char value[256] = {0};
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07001516 int val;
Shiv Maliyappanahalli3e064fd2013-12-16 15:54:40 -08001517 int ret = 0, err;
Krishnankutty Kolathappilly061a9492014-01-31 18:12:13 -08001518 char *kv_pairs = str_parms_to_str(parms);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07001519
Krishnankutty Kolathappilly061a9492014-01-31 18:12:13 -08001520 ALOGV_IF(kv_pairs != NULL, "%s: enter: %s", __func__, kv_pairs);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07001521
Shiv Maliyappanahalli3e064fd2013-12-16 15:54:40 -08001522 err = str_parms_get_int(parms, AUDIO_PARAMETER_KEY_BTSCO, &val);
1523 if (err >= 0) {
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07001524 str_parms_del(parms, AUDIO_PARAMETER_KEY_BTSCO);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07001525 my_data->btsco_sample_rate = val;
Vidyakumar Athota67c42712013-12-04 14:03:06 -08001526 if (val == SAMPLE_RATE_16KHZ) {
1527 audio_route_apply_path(my_data->adev->audio_route,
1528 "bt-sco-wb-samplerate");
1529 audio_route_update_mixer(my_data->adev->audio_route);
1530 }
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07001531 }
1532
Shiv Maliyappanahalli3e064fd2013-12-16 15:54:40 -08001533 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_SLOWTALK, value, sizeof(value));
1534 if (err >= 0) {
Vidyakumar Athota3ade2792013-12-02 11:02:20 -08001535 bool state = false;
1536 if (!strncmp("true", value, sizeof("true"))) {
1537 state = true;
1538 }
1539
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07001540 str_parms_del(parms, AUDIO_PARAMETER_KEY_SLOWTALK);
Vidyakumar Athota3ade2792013-12-02 11:02:20 -08001541 ret = platform_set_slowtalk(my_data, state);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07001542 if (ret)
1543 ALOGE("%s: Failed to set slow talk err: %d", __func__, ret);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07001544 }
1545
Shiv Maliyappanahalli3e064fd2013-12-16 15:54:40 -08001546 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_VOLUME_BOOST,
Ben Rombergerc1dc70d2013-12-19 15:11:17 -08001547 value, sizeof(value));
Shiv Maliyappanahalli3e064fd2013-12-16 15:54:40 -08001548 if (err >= 0) {
Ben Rombergerc1dc70d2013-12-19 15:11:17 -08001549 str_parms_del(parms, AUDIO_PARAMETER_KEY_VOLUME_BOOST);
1550
1551 if (my_data->acdb_reload_vocvoltable == NULL) {
1552 ALOGE("%s: acdb_reload_vocvoltable is NULL", __func__);
1553 } else if (!strcmp(value, "on")) {
1554 if (!my_data->acdb_reload_vocvoltable(VOICE_FEATURE_SET_VOLUME_BOOST)) {
1555 my_data->voice_feature_set = 1;
1556 }
1557 } else {
1558 if (!my_data->acdb_reload_vocvoltable(VOICE_FEATURE_SET_DEFAULT)) {
1559 my_data->voice_feature_set = 0;
1560 }
1561 }
1562 }
1563
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07001564 ALOGV("%s: exit with code(%d)", __func__, ret);
Krishnankutty Kolathappilly061a9492014-01-31 18:12:13 -08001565 free(kv_pairs);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07001566 return ret;
1567}
1568
Vidyakumar Athota2850d532013-11-19 16:02:12 -08001569int platform_set_incall_recording_session_id(void *platform,
1570 uint32_t session_id, int rec_mode)
Shiv Maliyappanahallida107642013-10-17 11:16:13 -07001571{
1572 int ret = 0;
1573 struct platform_data *my_data = (struct platform_data *)platform;
1574 struct audio_device *adev = my_data->adev;
1575 struct mixer_ctl *ctl;
1576 const char *mixer_ctl_name = "Voc VSID";
1577 int num_ctl_values;
1578 int i;
1579
1580 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1581 if (!ctl) {
1582 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1583 __func__, mixer_ctl_name);
1584 ret = -EINVAL;
1585 } else {
1586 num_ctl_values = mixer_ctl_get_num_values(ctl);
1587 for (i = 0; i < num_ctl_values; i++) {
1588 if (mixer_ctl_set_value(ctl, i, session_id)) {
1589 ALOGV("Error: invalid session_id: %x", session_id);
1590 ret = -EINVAL;
1591 break;
1592 }
1593 }
1594 }
1595
Vidyakumar Athota2850d532013-11-19 16:02:12 -08001596 if (my_data->csd != NULL) {
1597 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
1598 if (ret < 0) {
1599 ALOGE("%s: csd_client_start_record failed, error %d",
1600 __func__, ret);
1601 }
1602 }
1603
1604 return ret;
1605}
1606
1607int platform_stop_incall_recording_usecase(void *platform)
1608{
1609 int ret = 0;
1610 struct platform_data *my_data = (struct platform_data *)platform;
1611
1612 if (my_data->csd != NULL) {
1613 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
1614 if (ret < 0) {
1615 ALOGE("%s: csd_client_stop_record failed, error %d",
1616 __func__, ret);
1617 }
1618 }
1619
1620 return ret;
1621}
1622
1623int platform_start_incall_music_usecase(void *platform)
1624{
1625 int ret = 0;
1626 struct platform_data *my_data = (struct platform_data *)platform;
1627
1628 if (my_data->csd != NULL) {
1629 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
1630 if (ret < 0) {
1631 ALOGE("%s: csd_client_start_playback failed, error %d",
1632 __func__, ret);
1633 }
1634 }
1635
1636 return ret;
1637}
1638
1639int platform_stop_incall_music_usecase(void *platform)
1640{
1641 int ret = 0;
1642 struct platform_data *my_data = (struct platform_data *)platform;
1643
1644 if (my_data->csd != NULL) {
1645 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
1646 if (ret < 0) {
1647 ALOGE("%s: csd_client_stop_playback failed, error %d",
1648 __func__, ret);
1649 }
1650 }
1651
Shiv Maliyappanahallida107642013-10-17 11:16:13 -07001652 return ret;
1653}
1654
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07001655void platform_get_parameters(void *platform,
1656 struct str_parms *query,
1657 struct str_parms *reply)
1658{
1659 struct platform_data *my_data = (struct platform_data *)platform;
1660 char *str = NULL;
1661 char value[256] = {0};
1662 int ret;
1663 int fluence_type;
Krishnankutty Kolathappilly061a9492014-01-31 18:12:13 -08001664 char *kv_pairs = NULL;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07001665
1666 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_FLUENCE_TYPE,
1667 value, sizeof(value));
1668 if (ret >= 0) {
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -08001669 if (my_data->fluence_type & FLUENCE_QUAD_MIC) {
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07001670 strlcpy(value, "fluencepro", sizeof(value));
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -08001671 } else if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07001672 strlcpy(value, "fluence", sizeof(value));
1673 } else {
1674 strlcpy(value, "none", sizeof(value));
1675 }
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07001676
1677 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_FLUENCE_TYPE, value);
1678 }
1679
Shiv Maliyappanahalli9d899292013-11-20 14:43:01 -08001680 memset(value, 0, sizeof(value));
1681 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_SLOWTALK,
1682 value, sizeof(value));
1683 if (ret >= 0) {
Vidyakumar Athota3ade2792013-12-02 11:02:20 -08001684 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_SLOWTALK,
1685 my_data->slowtalk?"true":"false");
Shiv Maliyappanahalli9d899292013-11-20 14:43:01 -08001686 }
1687
Ben Rombergerc1dc70d2013-12-19 15:11:17 -08001688 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_VOLUME_BOOST,
1689 value, sizeof(value));
1690 if (ret >= 0) {
1691 if (my_data->voice_feature_set == VOICE_FEATURE_SET_VOLUME_BOOST) {
1692 strlcpy(value, "on", sizeof(value));
1693 } else {
1694 strlcpy(value, "off", sizeof(value));
1695 }
1696
1697 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_VOLUME_BOOST, value);
1698 }
1699
Krishnankutty Kolathappilly061a9492014-01-31 18:12:13 -08001700 kv_pairs = str_parms_to_str(reply);
1701 ALOGV_IF(kv_pairs != NULL, "%s: exit: returns - %s", __func__, kv_pairs);
1702 free(reply);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07001703}
1704
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07001705/* Delay in Us */
1706int64_t platform_render_latency(audio_usecase_t usecase)
1707{
1708 switch (usecase) {
1709 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
1710 return DEEP_BUFFER_PLATFORM_DELAY;
1711 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
1712 return LOW_LATENCY_PLATFORM_DELAY;
1713 default:
1714 return 0;
1715 }
1716}
Preetam Singh Ranawatde84f1a2013-11-01 14:58:16 -07001717
Mingming Yine62d7842013-10-25 16:26:03 -07001718int platform_update_usecase_from_source(int source, int usecase)
Preetam Singh Ranawatde84f1a2013-11-01 14:58:16 -07001719{
Mingming Yinab429782013-11-07 11:16:55 -08001720 ALOGV("%s: input source :%d", __func__, source);
1721 if(source == AUDIO_SOURCE_FM_RX_A2DP)
Mingming Yine62d7842013-10-25 16:26:03 -07001722 usecase = USECASE_AUDIO_RECORD_FM_VIRTUAL;
1723 return usecase;
Preetam Singh Ranawatde84f1a2013-11-01 14:58:16 -07001724}
Kiran Kandide144c82013-11-20 15:58:32 -08001725
1726bool platform_listen_update_status(snd_device_t snd_device)
1727{
1728 if ((snd_device >= SND_DEVICE_IN_BEGIN) &&
1729 (snd_device < SND_DEVICE_IN_END) &&
1730 (snd_device != SND_DEVICE_IN_CAPTURE_FM) &&
1731 (snd_device != SND_DEVICE_IN_CAPTURE_VI_FEEDBACK))
1732 return true;
1733 else
1734 return false;
1735}