blob: c22da154fe477802654217b945d97520484cf693 [file] [log] [blame]
Eric Laurentb23d5282013-05-14 15:27:20 -07001/*
vivek mehtaa51fd402016-02-04 19:49:33 -08002 * Copyright (C) 2013-2016 The Android Open Source Project
Eric Laurentb23d5282013-05-14 15:27:20 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Eric Laurentb23d5282013-05-14 15:27:20 -070016#define LOG_TAG "msm8974_platform"
17/*#define LOG_NDEBUG 0*/
18#define LOG_NDDEBUG 0
19
20#include <stdlib.h>
21#include <dlfcn.h>
22#include <cutils/log.h>
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -070023#include <cutils/str_parms.h>
Eric Laurentb23d5282013-05-14 15:27:20 -070024#include <cutils/properties.h>
25#include <audio_hw.h>
26#include <platform_api.h>
27#include "platform.h"
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -070028#include "audio_extn.h"
vivek mehta1a9b7c02015-06-25 11:49:38 -070029#include <linux/msm_audio.h>
Eric Laurentb23d5282013-05-14 15:27:20 -070030
vivek mehta60ea4152016-02-18 17:10:26 -080031#define MIXER_XML_DEFAULT_PATH "/system/etc/mixer_paths.xml"
32#define MIXER_XML_BASE_STRING "/system/etc/mixer_paths"
33#define TOMTOM_8226_SND_CARD_NAME "msm8226-tomtom-snd-card"
34#define TOMTOM_MIXER_FILE_SUFFIX "wcd9330"
35
Eric Laurentb23d5282013-05-14 15:27:20 -070036#define LIB_ACDB_LOADER "libacdbloader.so"
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -070037#define AUDIO_DATA_BLOCK_MIXER_CTL "HDMI EDID"
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +090038#define CVD_VERSION_MIXER_CTL "CVD Version"
Eric Laurentb23d5282013-05-14 15:27:20 -070039
Eric Laurentf9583c32016-03-28 13:50:50 -070040#define min(a, b) ((a) < (b) ? (a) : (b))
Eric Laurentb23d5282013-05-14 15:27:20 -070041
42/*
Eric Laurentb23d5282013-05-14 15:27:20 -070043 * This file will have a maximum of 38 bytes:
44 *
45 * 4 bytes: number of audio blocks
46 * 4 bytes: total length of Short Audio Descriptor (SAD) blocks
47 * Maximum 10 * 3 bytes: SAD blocks
48 */
49#define MAX_SAD_BLOCKS 10
50#define SAD_BLOCK_SIZE 3
51
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +090052#define MAX_CVD_VERSION_STRING_SIZE 100
53
Eric Laurentb23d5282013-05-14 15:27:20 -070054/* EDID format ID for LPCM audio */
55#define EDID_FORMAT_LPCM 1
56
sangwoo1b9f4b32013-06-21 18:22:55 -070057/* Retry for delay in FW loading*/
58#define RETRY_NUMBER 10
59#define RETRY_US 500000
Vineeta Srivastava4b89e372014-06-19 14:21:42 -070060#define MAX_SND_CARD 8
sangwoo53b2cf02013-07-25 19:18:44 -070061
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -070062#define MAX_SND_CARD_NAME_LEN 31
63
vivek mehta1a9b7c02015-06-25 11:49:38 -070064#define DEFAULT_APP_TYPE_RX_PATH 0x11130
65
keunhui.parkc5aaa0e2015-07-13 10:57:37 +090066#define TOSTRING_(x) #x
67#define TOSTRING(x) TOSTRING_(x)
68
Eric Laurentb23d5282013-05-14 15:27:20 -070069struct audio_block_header
70{
71 int reserved;
72 int length;
73};
74
vivek mehta1a9b7c02015-06-25 11:49:38 -070075enum {
76 CAL_MODE_SEND = 0x1,
77 CAL_MODE_PERSIST = 0x2,
78 CAL_MODE_RTAC = 0x4
79};
80
keunhui.park2f7306a2015-07-16 16:48:06 +090081#define PLATFORM_CONFIG_KEY_OPERATOR_INFO "operator_info"
82
83struct operator_info {
84 struct listnode list;
85 char *name;
86 char *mccmnc;
87};
88
89struct operator_specific_device {
90 struct listnode list;
91 char *operator;
92 char *mixer_path;
93 int acdb_id;
94};
95
96static struct listnode operator_info_list;
97static struct listnode *operator_specific_device_table[SND_DEVICE_MAX];
98
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -070099/* Audio calibration related functions */
Eric Laurentb23d5282013-05-14 15:27:20 -0700100typedef void (*acdb_deallocate_t)();
vivek mehtac698f132016-02-25 18:50:35 -0800101typedef int (*acdb_init_v2_cvd_t)(char *, char *, int);
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +0900102typedef int (*acdb_init_v2_t)(char *);
Eric Laurentb23d5282013-05-14 15:27:20 -0700103typedef int (*acdb_init_t)();
104typedef void (*acdb_send_audio_cal_t)(int, int);
105typedef void (*acdb_send_voice_cal_t)(int, int);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700106typedef int (*acdb_reload_vocvoltable_t)(int);
vivek mehta1a9b7c02015-06-25 11:49:38 -0700107typedef int (*acdb_send_gain_dep_cal_t)(int, int, int, int, int);
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -0700108typedef int (*acdb_send_custom_top_t) (void);
Eric Laurentb23d5282013-05-14 15:27:20 -0700109
110/* Audio calibration related functions */
111struct platform_data {
112 struct audio_device *adev;
113 bool fluence_in_spkr_mode;
114 bool fluence_in_voice_call;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700115 bool fluence_in_voice_comm;
Eric Laurentb23d5282013-05-14 15:27:20 -0700116 bool fluence_in_voice_rec;
Prashant Malanic92c5962015-08-11 15:10:18 -0700117 /* 0 = no fluence, 1 = fluence, 2 = fluence pro */
118 int fluence_type;
119 int source_mic_type;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -0700120 bool speaker_lr_swap;
121
Eric Laurentb23d5282013-05-14 15:27:20 -0700122 void *acdb_handle;
Thierry Strudel92232b42017-01-26 10:51:48 -0800123#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -0700124 acdb_init_v2_cvd_t acdb_init;
125#elif defined (PLATFORM_MSM8084)
126 acdb_init_v2_t acdb_init;
127#else
128 acdb_init_t acdb_init;
129#endif
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700130 acdb_deallocate_t acdb_deallocate;
131 acdb_send_audio_cal_t acdb_send_audio_cal;
132 acdb_send_voice_cal_t acdb_send_voice_cal;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700133 acdb_reload_vocvoltable_t acdb_reload_vocvoltable;
vivek mehta1a9b7c02015-06-25 11:49:38 -0700134 acdb_send_gain_dep_cal_t acdb_send_gain_dep_cal;
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -0700135 acdb_send_custom_top_t acdb_send_custom_top;
136 bool acdb_initialized;
137
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700138 struct csd_data *csd;
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800139 char ec_ref_mixer_path[64];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700140
141 char *snd_card_name;
keunhui.parkc5aaa0e2015-07-13 10:57:37 +0900142 int max_vol_index;
Prashant Malanic92c5962015-08-11 15:10:18 -0700143 int max_mic_count;
vivek mehtade4849c2016-03-03 17:23:38 -0800144
145 void *hw_info;
Eric Laurentb23d5282013-05-14 15:27:20 -0700146};
147
Haynes Mathew George98c95622014-06-20 19:14:25 -0700148static int pcm_device_table[AUDIO_USECASE_MAX][2] = {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700149 [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = {DEEP_BUFFER_PCM_DEVICE,
150 DEEP_BUFFER_PCM_DEVICE},
151 [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
152 LOWLATENCY_PCM_DEVICE},
153 [USECASE_AUDIO_PLAYBACK_MULTI_CH] = {MULTIMEDIA2_PCM_DEVICE,
154 MULTIMEDIA2_PCM_DEVICE},
155 [USECASE_AUDIO_PLAYBACK_OFFLOAD] = {PLAYBACK_OFFLOAD_DEVICE,
156 PLAYBACK_OFFLOAD_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700157 [USECASE_AUDIO_PLAYBACK_TTS] = {MULTIMEDIA2_PCM_DEVICE,
158 MULTIMEDIA2_PCM_DEVICE},
159 [USECASE_AUDIO_PLAYBACK_ULL] = {MULTIMEDIA3_PCM_DEVICE,
160 MULTIMEDIA3_PCM_DEVICE},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800161 [USECASE_AUDIO_PLAYBACK_MMAP] = {MMAP_PLAYBACK_PCM_DEVICE,
162 MMAP_PLAYBACK_PCM_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700163
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700164 [USECASE_AUDIO_RECORD] = {AUDIO_RECORD_PCM_DEVICE,
165 AUDIO_RECORD_PCM_DEVICE},
166 [USECASE_AUDIO_RECORD_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
167 LOWLATENCY_PCM_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700168
Eric Laurent0e46adf2016-12-16 12:49:24 -0800169 [USECASE_AUDIO_RECORD_MMAP] = {MMAP_RECORD_PCM_DEVICE,
170 MMAP_RECORD_PCM_DEVICE},
171
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700172 [USECASE_VOICE_CALL] = {VOICE_CALL_PCM_DEVICE,
173 VOICE_CALL_PCM_DEVICE},
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700174 [USECASE_VOICE2_CALL] = {VOICE2_CALL_PCM_DEVICE, VOICE2_CALL_PCM_DEVICE},
175 [USECASE_VOLTE_CALL] = {VOLTE_CALL_PCM_DEVICE, VOLTE_CALL_PCM_DEVICE},
176 [USECASE_QCHAT_CALL] = {QCHAT_CALL_PCM_DEVICE, QCHAT_CALL_PCM_DEVICE},
177 [USECASE_VOWLAN_CALL] = {VOWLAN_CALL_PCM_DEVICE, VOWLAN_CALL_PCM_DEVICE},
vivek mehtaa51fd402016-02-04 19:49:33 -0800178 [USECASE_VOICEMMODE1_CALL] = {VOICEMMODE1_CALL_PCM_DEVICE,
179 VOICEMMODE1_CALL_PCM_DEVICE},
180 [USECASE_VOICEMMODE2_CALL] = {VOICEMMODE2_CALL_PCM_DEVICE,
181 VOICEMMODE2_CALL_PCM_DEVICE},
182
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700183 [USECASE_INCALL_REC_UPLINK] = {AUDIO_RECORD_PCM_DEVICE,
184 AUDIO_RECORD_PCM_DEVICE},
185 [USECASE_INCALL_REC_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
186 AUDIO_RECORD_PCM_DEVICE},
187 [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
188 AUDIO_RECORD_PCM_DEVICE},
Ravi Kumar Alamanda8e6e98f2013-11-05 15:57:39 -0800189 [USECASE_AUDIO_HFP_SCO] = {HFP_PCM_RX, HFP_SCO_RX},
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700190
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700191 [USECASE_AUDIO_SPKR_CALIB_RX] = {SPKR_PROT_CALIB_RX_PCM_DEVICE, -1},
192 [USECASE_AUDIO_SPKR_CALIB_TX] = {-1, SPKR_PROT_CALIB_TX_PCM_DEVICE},
193
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700194 [USECASE_AUDIO_PLAYBACK_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
195 AFE_PROXY_RECORD_PCM_DEVICE},
196 [USECASE_AUDIO_RECORD_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
197 AFE_PROXY_RECORD_PCM_DEVICE},
zhaoyang yin4211fad2015-06-04 21:13:25 +0800198 [USECASE_AUDIO_DSM_FEEDBACK] = {QUAT_MI2S_PCM_DEVICE, QUAT_MI2S_PCM_DEVICE},
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700199
Eric Laurentb23d5282013-05-14 15:27:20 -0700200};
201
202/* Array to store sound devices */
203static const char * const device_table[SND_DEVICE_MAX] = {
204 [SND_DEVICE_NONE] = "none",
205 /* Playback sound devices */
206 [SND_DEVICE_OUT_HANDSET] = "handset",
207 [SND_DEVICE_OUT_SPEAKER] = "speaker",
208 [SND_DEVICE_OUT_SPEAKER_REVERSE] = "speaker-reverse",
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700209 [SND_DEVICE_OUT_SPEAKER_SAFE] = "speaker-safe",
Eric Laurentb23d5282013-05-14 15:27:20 -0700210 [SND_DEVICE_OUT_HEADPHONES] = "headphones",
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500211 [SND_DEVICE_OUT_LINE] = "line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700212 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones",
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700213 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = "speaker-safe-and-headphones",
Eric Laurent744996b2014-10-01 11:40:40 -0500214 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = "speaker-and-line",
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700215 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = "speaker-safe-and-line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700216 [SND_DEVICE_OUT_VOICE_HANDSET] = "voice-handset",
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500217 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = "voice-hac-handset",
Eric Laurentb23d5282013-05-14 15:27:20 -0700218 [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker",
219 [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones",
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500220 [SND_DEVICE_OUT_VOICE_LINE] = "voice-line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700221 [SND_DEVICE_OUT_HDMI] = "hdmi",
222 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi",
223 [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700224 [SND_DEVICE_OUT_BT_SCO_WB] = "bt-sco-headset-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700225 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = "voice-handset-tmus",
226 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones",
227 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones",
228 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700229 [SND_DEVICE_OUT_VOICE_TX] = "voice-tx",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700230 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = "speaker-protected",
231 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = "voice-speaker-protected",
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -0700232 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = "voice-speaker-hfp",
Eric Laurentb23d5282013-05-14 15:27:20 -0700233
234 /* Capture sound devices */
235 [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700236 [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700237 [SND_DEVICE_IN_HANDSET_MIC_NS] = "handset-mic",
238 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = "handset-mic",
239 [SND_DEVICE_IN_HANDSET_DMIC] = "dmic-endfire",
240 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = "dmic-endfire",
241 [SND_DEVICE_IN_HANDSET_DMIC_NS] = "dmic-endfire",
242 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = "dmic-endfire",
243 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = "dmic-endfire",
244
245 [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
246 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "speaker-mic",
247 [SND_DEVICE_IN_SPEAKER_MIC_NS] = "speaker-mic",
248 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = "speaker-mic",
249 [SND_DEVICE_IN_SPEAKER_DMIC] = "speaker-dmic-endfire",
250 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = "speaker-dmic-endfire",
251 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = "speaker-dmic-endfire",
252 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = "speaker-dmic-endfire",
253 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = "speaker-dmic-endfire",
254
255 [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
Eric Laurentcefbbac2014-09-04 13:54:10 -0500256 [SND_DEVICE_IN_HEADSET_MIC_AEC] = "headset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700257
Eric Laurentb23d5282013-05-14 15:27:20 -0700258 [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic",
259 [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700260 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = "bt-sco-mic",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700261 [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700262 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = "bt-sco-mic-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700263 [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700264
265 [SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef",
266 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = "voice-dmic-ef-tmus",
267 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
268 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = "voice-speaker-dmic-ef",
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -0700269 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = "voice-speaker-mic-hfp",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700270 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700271 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
272 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
273 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700274
Eric Laurentb23d5282013-05-14 15:27:20 -0700275 [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700276 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = "voice-rec-mic",
vivek mehta733c1df2016-04-04 15:09:24 -0700277 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = "voice-rec-mic",
vivek mehtaf3440682016-05-11 14:24:37 -0700278 [SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700279 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = "voice-rec-dmic-ef",
280 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence",
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700281 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = "headset-mic",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700282
Ricardo Garcia9034bc42016-04-04 07:11:46 -0700283 [SND_DEVICE_IN_UNPROCESSED_MIC] = "unprocessed-mic",
vivek mehta0125e782016-06-16 18:03:11 -0700284 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = "unprocessed-stereo-mic",
285 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = "unprocessed-three-mic",
286 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = "unprocessed-quad-mic",
287 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = "unprocessed-headset-mic",
rago90fb9612015-12-02 11:37:53 -0800288
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700289 [SND_DEVICE_IN_VOICE_RX] = "voice-rx",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700290
Prashant Malanic92c5962015-08-11 15:10:18 -0700291 [SND_DEVICE_IN_THREE_MIC] = "three-mic",
292 [SND_DEVICE_IN_QUAD_MIC] = "quad-mic",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700293 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = "vi-feedback",
Prashant Malanic92c5962015-08-11 15:10:18 -0700294 [SND_DEVICE_IN_HANDSET_TMIC] = "three-mic",
295 [SND_DEVICE_IN_HANDSET_QMIC] = "quad-mic",
vivek mehta733c1df2016-04-04 15:09:24 -0700296 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = "three-mic",
297 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = "quad-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700298};
299
300/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700301static int acdb_device_table[SND_DEVICE_MAX] = {
Eric Laurentb23d5282013-05-14 15:27:20 -0700302 [SND_DEVICE_NONE] = -1,
303 [SND_DEVICE_OUT_HANDSET] = 7,
304 [SND_DEVICE_OUT_SPEAKER] = 15,
305 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 15,
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700306 [SND_DEVICE_OUT_SPEAKER_SAFE] = 15,
Eric Laurentb23d5282013-05-14 15:27:20 -0700307 [SND_DEVICE_OUT_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500308 [SND_DEVICE_OUT_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700309 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700310 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500311 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = 77,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700312 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = 77,
Ravi Kumar Alamanda235c3482014-08-21 17:32:44 -0700313 [SND_DEVICE_OUT_VOICE_HANDSET] = ACDB_ID_VOICE_HANDSET,
314 [SND_DEVICE_OUT_VOICE_SPEAKER] = ACDB_ID_VOICE_SPEAKER,
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500315 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = 53,
Eric Laurentb23d5282013-05-14 15:27:20 -0700316 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500317 [SND_DEVICE_OUT_VOICE_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700318 [SND_DEVICE_OUT_HDMI] = 18,
319 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 15,
320 [SND_DEVICE_OUT_BT_SCO] = 22,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700321 [SND_DEVICE_OUT_BT_SCO_WB] = 39,
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700322 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = ACDB_ID_VOICE_HANDSET_TMUS,
Eric Laurentb23d5282013-05-14 15:27:20 -0700323 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
324 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
325 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700326 [SND_DEVICE_OUT_VOICE_TX] = 45,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700327 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = 124,
328 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = 101,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700329 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = ACDB_ID_VOICE_SPEAKER,
Eric Laurentb23d5282013-05-14 15:27:20 -0700330
331 [SND_DEVICE_IN_HANDSET_MIC] = 4,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700332 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 106,
333 [SND_DEVICE_IN_HANDSET_MIC_NS] = 107,
334 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = 108,
335 [SND_DEVICE_IN_HANDSET_DMIC] = 41,
336 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = 109,
337 [SND_DEVICE_IN_HANDSET_DMIC_NS] = 110,
338 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = 111,
339 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = 34,
340
341 [SND_DEVICE_IN_SPEAKER_MIC] = 11,
342 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 112,
343 [SND_DEVICE_IN_SPEAKER_MIC_NS] = 113,
344 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = 114,
345 [SND_DEVICE_IN_SPEAKER_DMIC] = 43,
346 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = 115,
347 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = 116,
348 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = 117,
349 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = 35,
350
rago90fb9612015-12-02 11:37:53 -0800351 [SND_DEVICE_IN_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentcefbbac2014-09-04 13:54:10 -0500352 [SND_DEVICE_IN_HEADSET_MIC_AEC] = ACDB_ID_HEADSET_MIC_AEC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700353
Eric Laurentb23d5282013-05-14 15:27:20 -0700354 [SND_DEVICE_IN_HDMI_MIC] = 4,
355 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700356 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = 21,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700357 [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700358 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = 38,
Eric Laurentb23d5282013-05-14 15:27:20 -0700359 [SND_DEVICE_IN_CAMCORDER_MIC] = 61,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700360
361 [SND_DEVICE_IN_VOICE_DMIC] = 41,
362 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = ACDB_ID_VOICE_DMIC_EF_TMUS,
363 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700364 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = 11,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700365 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 43,
rago90fb9612015-12-02 11:37:53 -0800366 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentb23d5282013-05-14 15:27:20 -0700367 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
368 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
369 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700370
rago90fb9612015-12-02 11:37:53 -0800371 [SND_DEVICE_IN_VOICE_REC_MIC] = ACDB_ID_VOICE_REC_MIC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700372 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = 113,
vivek mehta733c1df2016-04-04 15:09:24 -0700373 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = 112,
vivek mehtaf3440682016-05-11 14:24:37 -0700374 [SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = 114,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700375 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = 35,
376 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 43,
rago90fb9612015-12-02 11:37:53 -0800377 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
378
379 [SND_DEVICE_IN_UNPROCESSED_MIC] = ACDB_ID_VOICE_REC_MIC,
380 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
vivek mehta4ed66e62016-04-15 23:33:34 -0700381 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = 35,
382 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = 125,
383 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = 125,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700384
385 [SND_DEVICE_IN_VOICE_RX] = 44,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700386
Prashant Malanic92c5962015-08-11 15:10:18 -0700387 [SND_DEVICE_IN_THREE_MIC] = 46,
388 [SND_DEVICE_IN_QUAD_MIC] = 46,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700389 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = 102,
Prashant Malanic92c5962015-08-11 15:10:18 -0700390 [SND_DEVICE_IN_HANDSET_TMIC] = 125,
391 [SND_DEVICE_IN_HANDSET_QMIC] = 125,
vivek mehta733c1df2016-04-04 15:09:24 -0700392 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = 125, /* override this for new target to 140 */
393 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = 125, /* override this for new target to 140 */
Eric Laurentb23d5282013-05-14 15:27:20 -0700394};
395
Haynes Mathew George98c95622014-06-20 19:14:25 -0700396struct name_to_index {
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700397 char name[100];
398 unsigned int index;
399};
400
401#define TO_NAME_INDEX(X) #X, X
402
Haynes Mathew George98c95622014-06-20 19:14:25 -0700403/* Used to get index from parsed string */
404static const struct name_to_index snd_device_name_index[SND_DEVICE_MAX] = {
405 /* out */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700406 {TO_NAME_INDEX(SND_DEVICE_OUT_HANDSET)},
407 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER)},
408 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_REVERSE)},
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700409 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700410 {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500411 {TO_NAME_INDEX(SND_DEVICE_OUT_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700412 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700413 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES)},
Eric Laurent744996b2014-10-01 11:40:40 -0500414 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_LINE)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700415 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700416 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET)},
417 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700418 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_HFP)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700419 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500420 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700421 {TO_NAME_INDEX(SND_DEVICE_OUT_HDMI)},
422 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HDMI)},
423 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO)},
424 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO_WB)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700425 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET_TMUS)},
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500426 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HAC_HANDSET)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700427 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES)},
428 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES)},
429 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700430
431 /* in */
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700432 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED)},
433 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700434 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700435 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700436 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_NS)},
437 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)},
438 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC)},
439 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC)},
440 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_NS)},
441 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)},
442 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_STEREO)},
443
444 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700445 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700446 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_NS)},
447 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)},
448 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC)},
449 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC)},
450 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS)},
451 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)},
452 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_STEREO)},
453
454 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC)},
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700455 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700456
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700457 {TO_NAME_INDEX(SND_DEVICE_IN_HDMI_MIC)},
458 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700459 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700460 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700461 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700462 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700463
464 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC)},
465 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC_TMUS)},
466 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700467 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700468 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC)},
469 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEADSET_MIC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700470 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC)},
471 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC)},
472 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700473
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700474 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700475 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_NS)},
vivek mehta733c1df2016-04-04 15:09:24 -0700476 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC)},
vivek mehtaf3440682016-05-11 14:24:37 -0700477 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700478 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_STEREO)},
479 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE)},
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700480 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_HEADSET_MIC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700481
rago90fb9612015-12-02 11:37:53 -0800482 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_MIC)},
483 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC)},
vivek mehta4ed66e62016-04-15 23:33:34 -0700484 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_STEREO_MIC)},
485 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_THREE_MIC)},
486 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_QUAD_MIC)},
rago90fb9612015-12-02 11:37:53 -0800487
Prashant Malanic92c5962015-08-11 15:10:18 -0700488 {TO_NAME_INDEX(SND_DEVICE_IN_THREE_MIC)},
489 {TO_NAME_INDEX(SND_DEVICE_IN_QUAD_MIC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700490 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_VI_FEEDBACK)},
Prashant Malanic92c5962015-08-11 15:10:18 -0700491 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC)},
492 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC)},
vivek mehta733c1df2016-04-04 15:09:24 -0700493 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC_AEC)},
494 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC_AEC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700495};
496
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700497static char * backend_tag_table[SND_DEVICE_MAX] = {0};
498static char * hw_interface_table[SND_DEVICE_MAX] = {0};
Haynes Mathew George98c95622014-06-20 19:14:25 -0700499
500static const struct name_to_index usecase_name_index[AUDIO_USECASE_MAX] = {
501 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_DEEP_BUFFER)},
502 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_LOW_LATENCY)},
503 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_MULTI_CH)},
504 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD)},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700505 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_TTS)},
506 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_ULL)},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800507 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_MMAP)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700508 {TO_NAME_INDEX(USECASE_AUDIO_RECORD)},
509 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_LOW_LATENCY)},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800510 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_MMAP)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700511 {TO_NAME_INDEX(USECASE_VOICE_CALL)},
512 {TO_NAME_INDEX(USECASE_VOICE2_CALL)},
513 {TO_NAME_INDEX(USECASE_VOLTE_CALL)},
514 {TO_NAME_INDEX(USECASE_QCHAT_CALL)},
515 {TO_NAME_INDEX(USECASE_VOWLAN_CALL)},
John Muirf1346ce2016-12-06 00:03:41 -0800516 {TO_NAME_INDEX(USECASE_VOICEMMODE1_CALL)},
517 {TO_NAME_INDEX(USECASE_VOICEMMODE2_CALL)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700518 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK)},
519 {TO_NAME_INDEX(USECASE_INCALL_REC_DOWNLINK)},
520 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK_AND_DOWNLINK)},
521 {TO_NAME_INDEX(USECASE_AUDIO_HFP_SCO)},
John Muirf1346ce2016-12-06 00:03:41 -0800522 {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_RX)},
523 {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_TX)},
524 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_AFE_PROXY)},
525 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_AFE_PROXY)},
526 {TO_NAME_INDEX(USECASE_AUDIO_DSM_FEEDBACK)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700527};
528
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700529#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
530#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
Eric Laurent0e46adf2016-12-16 12:49:24 -0800531#define ULL_PLATFORM_DELAY (3*1000LL)
532#define MMAP_PLATFORM_DELAY (3*1000LL)
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700533
Eric Laurentb23d5282013-05-14 15:27:20 -0700534static pthread_once_t check_op_once_ctl = PTHREAD_ONCE_INIT;
535static bool is_tmus = false;
536
537static void check_operator()
538{
539 char value[PROPERTY_VALUE_MAX];
540 int mccmnc;
541 property_get("gsm.sim.operator.numeric",value,"0");
542 mccmnc = atoi(value);
Eric Laurent2bafff12016-03-17 12:17:23 -0700543 ALOGD("%s: tmus mccmnc %d", __func__, mccmnc);
Eric Laurentb23d5282013-05-14 15:27:20 -0700544 switch(mccmnc) {
545 /* TMUS MCC(310), MNC(490, 260, 026) */
546 case 310490:
547 case 310260:
548 case 310026:
sangwon.jeonb891db52013-09-14 17:39:15 +0900549 /* Add new TMUS MNC(800, 660, 580, 310, 270, 250, 240, 230, 220, 210, 200, 160) */
550 case 310800:
551 case 310660:
552 case 310580:
553 case 310310:
554 case 310270:
555 case 310250:
556 case 310240:
557 case 310230:
558 case 310220:
559 case 310210:
560 case 310200:
561 case 310160:
Eric Laurentb23d5282013-05-14 15:27:20 -0700562 is_tmus = true;
563 break;
564 }
565}
566
567bool is_operator_tmus()
568{
569 pthread_once(&check_op_once_ctl, check_operator);
570 return is_tmus;
571}
572
keunhui.park2f7306a2015-07-16 16:48:06 +0900573static char *get_current_operator()
574{
575 struct listnode *node;
576 struct operator_info *info_item;
577 char mccmnc[PROPERTY_VALUE_MAX];
578 char *ret = NULL;
579
Tom Cherry7fea2042016-11-10 18:05:59 -0800580 property_get("gsm.sim.operator.numeric",mccmnc,"00000");
keunhui.park2f7306a2015-07-16 16:48:06 +0900581
582 list_for_each(node, &operator_info_list) {
583 info_item = node_to_item(node, struct operator_info, list);
584 if (strstr(info_item->mccmnc, mccmnc) != NULL) {
585 ret = info_item->name;
586 }
587 }
588
589 return ret;
590}
591
592static struct operator_specific_device *get_operator_specific_device(snd_device_t snd_device)
593{
594 struct listnode *node;
595 struct operator_specific_device *ret = NULL;
596 struct operator_specific_device *device_item;
597 char *operator_name;
598
599 operator_name = get_current_operator();
600 if (operator_name == NULL)
601 return ret;
602
603 list_for_each(node, operator_specific_device_table[snd_device]) {
604 device_item = node_to_item(node, struct operator_specific_device, list);
605 if (strcmp(operator_name, device_item->operator) == 0) {
606 ret = device_item;
607 }
608 }
609
610 return ret;
611}
612
613
614static int get_operator_specific_device_acdb_id(snd_device_t snd_device)
615{
616 struct operator_specific_device *device;
617 int ret = acdb_device_table[snd_device];
618
619 device = get_operator_specific_device(snd_device);
620 if (device != NULL)
621 ret = device->acdb_id;
622
623 return ret;
624}
625
626static const char *get_operator_specific_device_mixer_path(snd_device_t snd_device)
627{
628 struct operator_specific_device *device;
629 const char *ret = device_table[snd_device];
630
631 device = get_operator_specific_device(snd_device);
632 if (device != NULL)
633 ret = device->mixer_path;
634
635 return ret;
636}
637
vivek mehta1a9b7c02015-06-25 11:49:38 -0700638bool platform_send_gain_dep_cal(void *platform, int level)
639{
640 bool ret_val = false;
641 struct platform_data *my_data = (struct platform_data *)platform;
642 struct audio_device *adev = my_data->adev;
643 int acdb_dev_id, app_type;
644 int acdb_dev_type = MSM_SNDDEV_CAP_RX;
645 int mode = CAL_MODE_RTAC;
646 struct listnode *node;
647 struct audio_usecase *usecase;
vivek mehta1a9b7c02015-06-25 11:49:38 -0700648
649 if (my_data->acdb_send_gain_dep_cal == NULL) {
650 ALOGE("%s: dlsym error for acdb_send_gain_dep_cal", __func__);
651 return ret_val;
652 }
653
654 if (!voice_is_in_call(adev)) {
655 ALOGV("%s: Not Voice call usecase, apply new cal for level %d",
656 __func__, level);
657 app_type = DEFAULT_APP_TYPE_RX_PATH;
658
659 // find the current active sound device
660 list_for_each(node, &adev->usecase_list) {
661 usecase = node_to_item(node, struct audio_usecase, list);
662
663 if (usecase != NULL &&
664 usecase->type == PCM_PLAYBACK &&
665 (usecase->stream.out->devices == AUDIO_DEVICE_OUT_SPEAKER)) {
666
667 ALOGV("%s: out device is %d", __func__, usecase->out_snd_device);
vivek mehta4cb82982015-07-13 12:05:49 -0700668 if (audio_extn_spkr_prot_is_enabled()) {
669 acdb_dev_id = audio_extn_spkr_prot_get_acdb_id(usecase->out_snd_device);
670 } else {
671 acdb_dev_id = acdb_device_table[usecase->out_snd_device];
672 }
673
vivek mehta1a9b7c02015-06-25 11:49:38 -0700674 if (!my_data->acdb_send_gain_dep_cal(acdb_dev_id, app_type,
675 acdb_dev_type, mode, level)) {
676 // set ret_val true if at least one calibration is set successfully
677 ret_val = true;
678 } else {
679 ALOGE("%s: my_data->acdb_send_gain_dep_cal failed ", __func__);
680 }
681 } else {
682 ALOGW("%s: Usecase list is empty", __func__);
683 }
684 }
685 } else {
686 ALOGW("%s: Voice call in progress .. ignore setting new cal",
687 __func__);
688 }
689 return ret_val;
690}
691
Eric Laurentcefbbac2014-09-04 13:54:10 -0500692void platform_set_echo_reference(struct audio_device *adev, bool enable, audio_devices_t out_device)
Eric Laurentb23d5282013-05-14 15:27:20 -0700693{
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800694 struct platform_data *my_data = (struct platform_data *)adev->platform;
Eric Laurentcefbbac2014-09-04 13:54:10 -0500695 snd_device_t snd_device = SND_DEVICE_NONE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700696
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800697 if (strcmp(my_data->ec_ref_mixer_path, "")) {
698 ALOGV("%s: diabling %s", __func__, my_data->ec_ref_mixer_path);
699 audio_route_reset_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
Eric Laurentcefbbac2014-09-04 13:54:10 -0500700 }
701
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800702 if (enable) {
703 strcpy(my_data->ec_ref_mixer_path, "echo-reference");
704 if (out_device != AUDIO_DEVICE_NONE) {
705 snd_device = platform_get_output_snd_device(adev->platform, out_device);
706 platform_add_backend_name(adev->platform, my_data->ec_ref_mixer_path, snd_device);
707 }
Eric Laurentcefbbac2014-09-04 13:54:10 -0500708
Joe Onorato188b6222016-03-01 11:02:27 -0800709 ALOGV("%s: enabling %s", __func__, my_data->ec_ref_mixer_path);
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800710 audio_route_apply_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
711 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700712}
713
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700714static struct csd_data *open_csd_client(bool i2s_ext_modem)
715{
716 struct csd_data *csd = calloc(1, sizeof(struct csd_data));
717
718 csd->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
719 if (csd->csd_client == NULL) {
720 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
721 goto error;
722 } else {
723 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
724
725 csd->deinit = (deinit_t)dlsym(csd->csd_client,
726 "csd_client_deinit");
727 if (csd->deinit == NULL) {
728 ALOGE("%s: dlsym error %s for csd_client_deinit", __func__,
729 dlerror());
730 goto error;
731 }
732 csd->disable_device = (disable_device_t)dlsym(csd->csd_client,
733 "csd_client_disable_device");
734 if (csd->disable_device == NULL) {
735 ALOGE("%s: dlsym error %s for csd_client_disable_device",
736 __func__, dlerror());
737 goto error;
738 }
739 csd->enable_device_config = (enable_device_config_t)dlsym(csd->csd_client,
740 "csd_client_enable_device_config");
741 if (csd->enable_device_config == NULL) {
742 ALOGE("%s: dlsym error %s for csd_client_enable_device_config",
743 __func__, dlerror());
744 goto error;
745 }
746 csd->enable_device = (enable_device_t)dlsym(csd->csd_client,
747 "csd_client_enable_device");
748 if (csd->enable_device == NULL) {
749 ALOGE("%s: dlsym error %s for csd_client_enable_device",
750 __func__, dlerror());
751 goto error;
752 }
753 csd->start_voice = (start_voice_t)dlsym(csd->csd_client,
754 "csd_client_start_voice");
755 if (csd->start_voice == NULL) {
756 ALOGE("%s: dlsym error %s for csd_client_start_voice",
757 __func__, dlerror());
758 goto error;
759 }
760 csd->stop_voice = (stop_voice_t)dlsym(csd->csd_client,
761 "csd_client_stop_voice");
762 if (csd->stop_voice == NULL) {
763 ALOGE("%s: dlsym error %s for csd_client_stop_voice",
764 __func__, dlerror());
765 goto error;
766 }
767 csd->volume = (volume_t)dlsym(csd->csd_client,
768 "csd_client_volume");
769 if (csd->volume == NULL) {
770 ALOGE("%s: dlsym error %s for csd_client_volume",
771 __func__, dlerror());
772 goto error;
773 }
774 csd->mic_mute = (mic_mute_t)dlsym(csd->csd_client,
775 "csd_client_mic_mute");
776 if (csd->mic_mute == NULL) {
777 ALOGE("%s: dlsym error %s for csd_client_mic_mute",
778 __func__, dlerror());
779 goto error;
780 }
781 csd->slow_talk = (slow_talk_t)dlsym(csd->csd_client,
782 "csd_client_slow_talk");
783 if (csd->slow_talk == NULL) {
784 ALOGE("%s: dlsym error %s for csd_client_slow_talk",
785 __func__, dlerror());
786 goto error;
787 }
788 csd->start_playback = (start_playback_t)dlsym(csd->csd_client,
789 "csd_client_start_playback");
790 if (csd->start_playback == NULL) {
791 ALOGE("%s: dlsym error %s for csd_client_start_playback",
792 __func__, dlerror());
793 goto error;
794 }
795 csd->stop_playback = (stop_playback_t)dlsym(csd->csd_client,
796 "csd_client_stop_playback");
797 if (csd->stop_playback == NULL) {
798 ALOGE("%s: dlsym error %s for csd_client_stop_playback",
799 __func__, dlerror());
800 goto error;
801 }
802 csd->start_record = (start_record_t)dlsym(csd->csd_client,
803 "csd_client_start_record");
804 if (csd->start_record == NULL) {
805 ALOGE("%s: dlsym error %s for csd_client_start_record",
806 __func__, dlerror());
807 goto error;
808 }
809 csd->stop_record = (stop_record_t)dlsym(csd->csd_client,
810 "csd_client_stop_record");
811 if (csd->stop_record == NULL) {
812 ALOGE("%s: dlsym error %s for csd_client_stop_record",
813 __func__, dlerror());
814 goto error;
815 }
816
817 csd->get_sample_rate = (get_sample_rate_t)dlsym(csd->csd_client,
818 "csd_client_get_sample_rate");
819 if (csd->get_sample_rate == NULL) {
820 ALOGE("%s: dlsym error %s for csd_client_get_sample_rate",
821 __func__, dlerror());
822
823 goto error;
824 }
825
826 csd->init = (init_t)dlsym(csd->csd_client, "csd_client_init");
827
828 if (csd->init == NULL) {
829 ALOGE("%s: dlsym error %s for csd_client_init",
830 __func__, dlerror());
831 goto error;
832 } else {
833 csd->init(i2s_ext_modem);
834 }
835 }
836 return csd;
837
838error:
839 free(csd);
840 csd = NULL;
841 return csd;
842}
843
844void close_csd_client(struct csd_data *csd)
845{
846 if (csd != NULL) {
847 csd->deinit();
848 dlclose(csd->csd_client);
849 free(csd);
850 csd = NULL;
851 }
852}
853
854static void platform_csd_init(struct platform_data *my_data)
855{
856#ifdef PLATFORM_MSM8084
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700857 int32_t modems, (*count_modems)(void);
858 const char *name = "libdetectmodem.so";
859 const char *func = "count_modems";
860 const char *error;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700861
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700862 my_data->csd = NULL;
863
864 void *lib = dlopen(name, RTLD_NOW);
865 error = dlerror();
866 if (!lib) {
867 ALOGE("%s: could not find %s: %s", __func__, name, error);
868 return;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700869 }
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700870
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700871 count_modems = NULL;
872 *(void **)(&count_modems) = dlsym(lib, func);
873 error = dlerror();
874 if (!count_modems) {
875 ALOGE("%s: could not find symbol %s in %s: %s",
876 __func__, func, name, error);
877 goto done;
878 }
879
880 modems = count_modems();
881 if (modems < 0) {
882 ALOGE("%s: count_modems failed\n", __func__);
883 goto done;
884 }
885
Eric Laurent2bafff12016-03-17 12:17:23 -0700886 ALOGD("%s: num_modems %d\n", __func__, modems);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700887 if (modems > 0)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700888 my_data->csd = open_csd_client(false /*is_i2s_ext_modem*/);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700889
890done:
891 dlclose(lib);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700892#else
893 my_data->csd = NULL;
894#endif
895}
896
Eric Laurentc6333382015-09-14 12:43:44 -0700897static void set_platform_defaults(struct platform_data * my_data)
Haynes Mathew George98c95622014-06-20 19:14:25 -0700898{
899 int32_t dev;
900 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700901 backend_tag_table[dev] = NULL;
902 hw_interface_table[dev] = NULL;
keunhui.park2f7306a2015-07-16 16:48:06 +0900903 operator_specific_device_table[dev] = NULL;
Haynes Mathew George98c95622014-06-20 19:14:25 -0700904 }
905
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700906 // To overwrite these go to the audio_platform_info.xml file.
907 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("bt-sco");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700908 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("bt-sco");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700909 backend_tag_table[SND_DEVICE_OUT_BT_SCO] = strdup("bt-sco");
910 backend_tag_table[SND_DEVICE_OUT_HDMI] = strdup("hdmi");
911 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("speaker-and-hdmi");
912 backend_tag_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("bt-sco-wb");
913 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("bt-sco-wb");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700914 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("bt-sco-wb");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700915 backend_tag_table[SND_DEVICE_OUT_VOICE_TX] = strdup("afe-proxy");
916 backend_tag_table[SND_DEVICE_IN_VOICE_RX] = strdup("afe-proxy");
Haynes Mathew George98c95622014-06-20 19:14:25 -0700917
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700918 hw_interface_table[SND_DEVICE_OUT_HANDSET] = strdup("SLIMBUS_0_RX");
919 hw_interface_table[SND_DEVICE_OUT_SPEAKER] = strdup("SLIMBUS_0_RX");
920 hw_interface_table[SND_DEVICE_OUT_SPEAKER_REVERSE] = strdup("SLIMBUS_0_RX");
921 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE] = strdup("SLIMBUS_0_RX");
922 hw_interface_table[SND_DEVICE_OUT_HEADPHONES] = strdup("SLIMBUS_0_RX");
923 hw_interface_table[SND_DEVICE_OUT_LINE] = strdup("SLIMBUS_0_RX");
924 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700925 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700926 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700927 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700928 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET] = strdup("SLIMBUS_0_RX");
929 hw_interface_table[SND_DEVICE_OUT_VOICE_HAC_HANDSET] = strdup("SLIMBUS_0_RX");
930 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER] = strdup("SLIMBUS_0_RX");
931 hw_interface_table[SND_DEVICE_OUT_VOICE_HEADPHONES] = strdup("SLIMBUS_0_RX");
932 hw_interface_table[SND_DEVICE_OUT_VOICE_LINE] = strdup("SLIMBUS_0_RX");
933 hw_interface_table[SND_DEVICE_OUT_HDMI] = strdup("HDMI_RX");
934 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("SLIMBUS_0_RX-and-HDMI_RX");
935 hw_interface_table[SND_DEVICE_OUT_BT_SCO] = strdup("SEC_AUX_PCM_RX");
936 hw_interface_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("SEC_AUX_PCM_RX");
937 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = strdup("SLIMBUS_0_RX");
938 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = strdup("SLIMBUS_0_RX");
939 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = strdup("SLIMBUS_0_RX");
940 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = strdup("SLIMBUS_0_RX");
941 hw_interface_table[SND_DEVICE_OUT_VOICE_TX] = strdup("AFE_PCM_RX");
942 hw_interface_table[SND_DEVICE_OUT_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
943 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
Eric Laurentc6333382015-09-14 12:43:44 -0700944
945 my_data->max_mic_count = PLATFORM_DEFAULT_MIC_COUNT;
Haynes Mathew George98c95622014-06-20 19:14:25 -0700946}
947
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +0900948void get_cvd_version(char *cvd_version, struct audio_device *adev)
949{
950 struct mixer_ctl *ctl;
951 int count;
952 int ret = 0;
953
954 ctl = mixer_get_ctl_by_name(adev->mixer, CVD_VERSION_MIXER_CTL);
955 if (!ctl) {
956 ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__, CVD_VERSION_MIXER_CTL);
957 goto done;
958 }
959 mixer_ctl_update(ctl);
960
961 count = mixer_ctl_get_num_values(ctl);
962 if (count > MAX_CVD_VERSION_STRING_SIZE)
963 count = MAX_CVD_VERSION_STRING_SIZE - 1;
964
965 ret = mixer_ctl_get_array(ctl, cvd_version, count);
966 if (ret != 0) {
967 ALOGE("%s: ERROR! mixer_ctl_get_array() failed to get CVD Version", __func__);
968 goto done;
969 }
970
971done:
972 return;
973}
974
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -0700975static int platform_acdb_init(void *platform)
976{
977 struct platform_data *my_data = (struct platform_data *)platform;
978 struct audio_device *adev = my_data->adev;
979
980 if (!my_data->acdb_init) {
981 ALOGE("%s: no acdb_init fn provided", __func__);
982 return -1;
983 }
984
985 if (my_data->acdb_initialized) {
986 ALOGW("acdb is already initialized");
987 return 0;
988 }
989
Thierry Strudel92232b42017-01-26 10:51:48 -0800990#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -0700991 char *cvd_version = calloc(1, MAX_CVD_VERSION_STRING_SIZE);
992 if (!cvd_version)
993 ALOGE("failed to allocate cvd_version");
994 else {
995 get_cvd_version(cvd_version, adev);
996 my_data->acdb_init((char *)my_data->snd_card_name, cvd_version, 0);
997 free(cvd_version);
998 }
999#elif defined (PLATFORM_MSM8084)
1000 my_data->acdb_init((char *)my_data->snd_card_name);
1001#else
1002 my_data->acdb_init();
1003#endif
1004 my_data->acdb_initialized = true;
1005 return 0;
1006}
1007
Eric Laurentb23d5282013-05-14 15:27:20 -07001008void *platform_init(struct audio_device *adev)
1009{
1010 char value[PROPERTY_VALUE_MAX];
vivek mehta60ea4152016-02-18 17:10:26 -08001011 struct platform_data *my_data = NULL;
1012 int retry_num = 0, snd_card_num = 0, key = 0, ret = 0;
1013 bool dual_mic_config = false, use_default_mixer_path = true;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001014 const char *snd_card_name;
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001015 char *cvd_version = NULL;
vivek mehta60ea4152016-02-18 17:10:26 -08001016 char *snd_internal_name = NULL;
1017 char *tmp = NULL;
1018 char mixer_xml_file[MIXER_PATH_MAX_LENGTH]= {0};
vivek mehtade4849c2016-03-03 17:23:38 -08001019 char platform_info_file[MIXER_PATH_MAX_LENGTH]= {0};
1020 struct snd_card_split *snd_split_handle = NULL;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001021 my_data = calloc(1, sizeof(struct platform_data));
1022
1023 my_data->adev = adev;
1024
keunhui.park2f7306a2015-07-16 16:48:06 +09001025 list_init(&operator_info_list);
1026
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001027 set_platform_defaults(my_data);
vivek mehta2b0e5a62016-09-02 17:31:58 -07001028 bool card_verifed[MAX_SND_CARD] = {0};
1029 const int retry_limit = property_get_int32("audio.snd_card.open.retries", RETRY_NUMBER);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001030
vivek mehta2b0e5a62016-09-02 17:31:58 -07001031 for (;;) {
1032 if (snd_card_num >= MAX_SND_CARD) {
1033 if (retry_num++ >= retry_limit) {
1034 ALOGE("%s: Unable to find correct sound card, aborting.", __func__);
1035 goto init_failed;
1036 }
sangwoo1b9f4b32013-06-21 18:22:55 -07001037
vivek mehta2b0e5a62016-09-02 17:31:58 -07001038 snd_card_num = 0;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001039 usleep(RETRY_US);
vivek mehta2b0e5a62016-09-02 17:31:58 -07001040 continue;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001041 }
1042
vivek mehta2b0e5a62016-09-02 17:31:58 -07001043 if (card_verifed[snd_card_num]) {
1044 ++snd_card_num;
1045 continue;
1046 }
1047
1048 adev->mixer = mixer_open(snd_card_num);
1049
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001050 if (!adev->mixer) {
1051 ALOGE("%s: Unable to open the mixer card: %d", __func__,
vivek mehta2b0e5a62016-09-02 17:31:58 -07001052 snd_card_num);
1053 ++snd_card_num;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001054 continue;
1055 }
1056
vivek mehta2b0e5a62016-09-02 17:31:58 -07001057 card_verifed[snd_card_num] = true;
1058
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001059 snd_card_name = mixer_get_name(adev->mixer);
vivek mehtade4849c2016-03-03 17:23:38 -08001060 my_data->hw_info = hw_info_init(snd_card_name);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001061
vivek mehtade4849c2016-03-03 17:23:38 -08001062 audio_extn_set_snd_card_split(snd_card_name);
1063 snd_split_handle = audio_extn_get_snd_card_split();
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001064
vivek mehtade4849c2016-03-03 17:23:38 -08001065 /* Get the codec internal name from the sound card and/or form factor
1066 * name and form the mixer paths and platfor info file name dynamically.
1067 * This is generic way of picking any codec and forma factor name based
1068 * mixer and platform info files in future with no code change.
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001069
vivek mehtade4849c2016-03-03 17:23:38 -08001070 * current code extends and looks for any of the exteneded mixer path and
1071 * platform info file present based on codec and form factor.
vivek mehta60ea4152016-02-18 17:10:26 -08001072
vivek mehtade4849c2016-03-03 17:23:38 -08001073 * order of picking appropriate file is
1074 * <i> mixer_paths_<codec_name>_<form_factor>.xml, if file not present
1075 * <ii> mixer_paths_<codec_name>.xml, if file not present
1076 * <iii> mixer_paths.xml
1077
1078 * same order is followed for audio_platform_info.xml as well
1079 */
1080
1081 // need to carryforward old file name
1082 if (!strncmp(snd_card_name, TOMTOM_8226_SND_CARD_NAME,
Eric Laurentf9583c32016-03-28 13:50:50 -07001083 min(strlen(TOMTOM_8226_SND_CARD_NAME), strlen(snd_card_name)))) {
vivek mehtade4849c2016-03-03 17:23:38 -08001084 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
vivek mehta60ea4152016-02-18 17:10:26 -08001085 MIXER_XML_BASE_STRING, TOMTOM_MIXER_FILE_SUFFIX );
vivek mehtade4849c2016-03-03 17:23:38 -08001086 } else {
Ed Tamb0b0d572016-03-21 10:45:37 -07001087
vivek mehtade4849c2016-03-03 17:23:38 -08001088 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s_%s.xml",
1089 MIXER_XML_BASE_STRING, snd_split_handle->snd_card,
1090 snd_split_handle->form_factor);
1091
1092 if (F_OK != access(mixer_xml_file, 0)) {
1093 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1094 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1095 MIXER_XML_BASE_STRING, snd_split_handle->snd_card);
1096
1097 if (F_OK != access(mixer_xml_file, 0)) {
1098 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1099 strlcpy(mixer_xml_file, MIXER_XML_DEFAULT_PATH, MIXER_PATH_MAX_LENGTH);
1100 }
1101 }
1102
1103 snprintf(platform_info_file, sizeof(platform_info_file), "%s_%s_%s.xml",
1104 PLATFORM_INFO_XML_BASE_STRING, snd_split_handle->snd_card,
1105 snd_split_handle->form_factor);
1106
1107 if (F_OK != access(platform_info_file, 0)) {
1108 memset(platform_info_file, 0, sizeof(platform_info_file));
1109 snprintf(platform_info_file, sizeof(platform_info_file), "%s_%s.xml",
1110 PLATFORM_INFO_XML_BASE_STRING, snd_split_handle->snd_card);
1111
1112 if (F_OK != access(platform_info_file, 0)) {
1113 memset(platform_info_file, 0, sizeof(platform_info_file));
1114 strlcpy(platform_info_file, PLATFORM_INFO_XML_PATH, MIXER_PATH_MAX_LENGTH);
vivek mehta60ea4152016-02-18 17:10:26 -08001115 }
1116 }
Uday Kishore Pasupuleti11dd2232015-06-24 14:18:01 -07001117 }
1118
vivek mehtade4849c2016-03-03 17:23:38 -08001119 /* Initialize platform specific ids and/or backends*/
1120 platform_info_init(platform_info_file, my_data);
1121
1122 /* validate the sound card name
1123 * my_data->snd_card_name can contain
1124 * <a> complete sound card name, i.e. <device>-<codec>-<form_factor>-snd-card
1125 * example: msm8994-tomtom-mtp-snd-card
1126 * <b> or sub string of the card name, i.e. <device>-<codec>
1127 * example: msm8994-tomtom
Eric Laurentf9583c32016-03-28 13:50:50 -07001128 * snd_card_name is truncated to 32 charaters as per mixer_get_name() implementation
1129 * so use min of my_data->snd_card_name and snd_card_name length for comparison
vivek mehtade4849c2016-03-03 17:23:38 -08001130 */
1131
1132 if (my_data->snd_card_name != NULL &&
Eric Laurentf9583c32016-03-28 13:50:50 -07001133 strncmp(snd_card_name, my_data->snd_card_name,
1134 min(strlen(snd_card_name), strlen(my_data->snd_card_name))) != 0) {
vivek mehtade4849c2016-03-03 17:23:38 -08001135 ALOGI("%s: found valid sound card %s, but not primary sound card %s",
1136 __func__, snd_card_name, my_data->snd_card_name);
vivek mehta2b0e5a62016-09-02 17:31:58 -07001137 ++snd_card_num;
1138 mixer_close(adev->mixer);
1139 adev->mixer = NULL;
vivek mehtade4849c2016-03-03 17:23:38 -08001140 hw_info_deinit(my_data->hw_info);
1141 my_data->hw_info = NULL;
1142 continue;
Ed Tam70b5c142016-03-21 19:14:29 -07001143 }
vivek mehtade4849c2016-03-03 17:23:38 -08001144 ALOGI("%s: found sound card %s, primary sound card expeted is %s",
1145 __func__, snd_card_name, my_data->snd_card_name);
vivek mehta60ea4152016-02-18 17:10:26 -08001146
1147 ALOGD("%s: Loading mixer file: %s", __func__, mixer_xml_file);
1148 adev->audio_route = audio_route_init(snd_card_num, mixer_xml_file);
1149
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001150 if (!adev->audio_route) {
1151 ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
vivek mehta2b0e5a62016-09-02 17:31:58 -07001152 mixer_close(adev->mixer);
1153 adev->mixer = NULL;
1154 hw_info_deinit(my_data->hw_info);
1155 my_data->hw_info = NULL;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001156 goto init_failed;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001157 }
1158 adev->snd_card = snd_card_num;
Eric Laurent2bafff12016-03-17 12:17:23 -07001159 ALOGD("%s: Opened sound card:%d", __func__, snd_card_num);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001160 break;
sangwoo1b9f4b32013-06-21 18:22:55 -07001161 }
1162
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09001163 //set max volume step for voice call
1164 property_get("ro.config.vc_call_vol_steps", value, TOSTRING(MAX_VOL_INDEX));
1165 my_data->max_vol_index = atoi(value);
1166
vivek mehta65ad12d2015-08-13 18:32:48 -07001167 property_get("persist.audio.dualmic.config",value,"");
1168 if (!strcmp("endfire", value)) {
1169 dual_mic_config = true;
1170 }
1171
Prashant Malanic92c5962015-08-11 15:10:18 -07001172 my_data->source_mic_type = SOURCE_DUAL_MIC;
1173
Eric Laurentb23d5282013-05-14 15:27:20 -07001174 my_data->fluence_in_spkr_mode = false;
1175 my_data->fluence_in_voice_call = false;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001176 my_data->fluence_in_voice_comm = false;
Eric Laurentb23d5282013-05-14 15:27:20 -07001177 my_data->fluence_in_voice_rec = false;
1178
vivek mehta65ad12d2015-08-13 18:32:48 -07001179 property_get("ro.qc.sdk.audio.fluencetype", value, "none");
Prashant Malanic92c5962015-08-11 15:10:18 -07001180 if (!strcmp("fluencepro", value)) {
1181 my_data->fluence_type = FLUENCE_PRO_ENABLE;
vivek mehta65ad12d2015-08-13 18:32:48 -07001182 } else if (!strcmp("fluence", value) || (dual_mic_config)) {
Prashant Malanic92c5962015-08-11 15:10:18 -07001183 my_data->fluence_type = FLUENCE_ENABLE;
1184 } else if (!strcmp("none", value)) {
1185 my_data->fluence_type = FLUENCE_DISABLE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001186 }
1187
Prashant Malanic92c5962015-08-11 15:10:18 -07001188 if (my_data->fluence_type != FLUENCE_DISABLE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001189 property_get("persist.audio.fluence.voicecall",value,"");
1190 if (!strcmp("true", value)) {
1191 my_data->fluence_in_voice_call = true;
1192 }
1193
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001194 property_get("persist.audio.fluence.voicecomm",value,"");
1195 if (!strcmp("true", value)) {
1196 my_data->fluence_in_voice_comm = true;
1197 }
1198
Eric Laurentb23d5282013-05-14 15:27:20 -07001199 property_get("persist.audio.fluence.voicerec",value,"");
1200 if (!strcmp("true", value)) {
1201 my_data->fluence_in_voice_rec = true;
1202 }
1203
1204 property_get("persist.audio.fluence.speaker",value,"");
1205 if (!strcmp("true", value)) {
1206 my_data->fluence_in_spkr_mode = true;
1207 }
1208 }
1209
Prashant Malanic92c5962015-08-11 15:10:18 -07001210 // support max to mono, example if max count is 3, usecase supports Three, dual and mono mic
1211 switch (my_data->max_mic_count) {
1212 case 4:
1213 my_data->source_mic_type |= SOURCE_QUAD_MIC;
1214 case 3:
1215 my_data->source_mic_type |= SOURCE_THREE_MIC;
1216 case 2:
1217 my_data->source_mic_type |= SOURCE_DUAL_MIC;
1218 case 1:
1219 my_data->source_mic_type |= SOURCE_MONO_MIC;
1220 break;
1221 default:
1222 ALOGE("%s: max_mic_count (%d), is not supported, setting to default",
1223 __func__, my_data->max_mic_count);
1224 my_data->source_mic_type = SOURCE_MONO_MIC|SOURCE_DUAL_MIC;
1225 break;
1226 }
1227
1228 ALOGV("%s: Fluence_Type(%d) max_mic_count(%d) mic_type(0x%x) fluence_in_voice_call(%d)"
1229 " fluence_in_voice_comm(%d) fluence_in_voice_rec(%d) fluence_in_spkr_mode(%d) ",
1230 __func__, my_data->fluence_type, my_data->max_mic_count, my_data->source_mic_type,
1231 my_data->fluence_in_voice_call, my_data->fluence_in_voice_comm,
1232 my_data->fluence_in_voice_rec, my_data->fluence_in_spkr_mode);
1233
Eric Laurentb23d5282013-05-14 15:27:20 -07001234 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
1235 if (my_data->acdb_handle == NULL) {
1236 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
1237 } else {
1238 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
1239 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
1240 "acdb_loader_deallocate_ACDB");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001241 if (!my_data->acdb_deallocate)
1242 ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s",
1243 __func__, LIB_ACDB_LOADER);
1244
Eric Laurentb23d5282013-05-14 15:27:20 -07001245 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
1246 "acdb_loader_send_audio_cal");
1247 if (!my_data->acdb_send_audio_cal)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001248 ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s",
Eric Laurentb23d5282013-05-14 15:27:20 -07001249 __func__, LIB_ACDB_LOADER);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001250
Eric Laurentb23d5282013-05-14 15:27:20 -07001251 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
1252 "acdb_loader_send_voice_cal");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001253 if (!my_data->acdb_send_voice_cal)
1254 ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s",
1255 __func__, LIB_ACDB_LOADER);
1256
1257 my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle,
1258 "acdb_loader_reload_vocvoltable");
1259 if (!my_data->acdb_reload_vocvoltable)
1260 ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s",
1261 __func__, LIB_ACDB_LOADER);
vivek mehta1a9b7c02015-06-25 11:49:38 -07001262
1263 my_data->acdb_send_gain_dep_cal = (acdb_send_gain_dep_cal_t)dlsym(my_data->acdb_handle,
1264 "acdb_loader_send_gain_dep_cal");
1265 if (!my_data->acdb_send_gain_dep_cal)
1266 ALOGV("%s: Could not find the symbol acdb_loader_send_gain_dep_cal from %s",
1267 __func__, LIB_ACDB_LOADER);
1268
Thierry Strudel92232b42017-01-26 10:51:48 -08001269#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998)
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001270 acdb_init_v2_cvd_t acdb_init;
1271 acdb_init = (acdb_init_v2_cvd_t)dlsym(my_data->acdb_handle,
1272 "acdb_loader_init_v2");
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001273 if (acdb_init == NULL)
1274 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1275 dlerror());
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001276
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001277#elif defined (PLATFORM_MSM8084)
1278 acdb_init_v2_t acdb_init;
1279 acdb_init = (acdb_init_v2_t)dlsym(my_data->acdb_handle,
1280 "acdb_loader_init_v2");
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001281 if (acdb_init == NULL)
1282 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1283 dlerror());
1284
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001285#else
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001286 acdb_init_t acdb_init;
1287 acdb_init = (acdb_init_t)dlsym(my_data->acdb_handle,
Eric Laurentb23d5282013-05-14 15:27:20 -07001288 "acdb_loader_init_ACDB");
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001289 if (acdb_init == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001290 ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__,
1291 dlerror());
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001292#endif
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001293 my_data->acdb_init = acdb_init;
Eric Laurentb23d5282013-05-14 15:27:20 -07001294
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001295 my_data->acdb_send_custom_top = (acdb_send_custom_top_t)
1296 dlsym(my_data->acdb_handle,
1297 "acdb_loader_send_common_custom_topology");
1298
1299 if (!my_data->acdb_send_custom_top)
1300 ALOGE("%s: Could not find the symbol acdb_get_default_app_type from %s",
1301 __func__, LIB_ACDB_LOADER);
1302
1303 platform_acdb_init(my_data);
1304 }
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001305
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001306 audio_extn_spkr_prot_init(adev);
Haynes Mathew George98c95622014-06-20 19:14:25 -07001307
Ravi Kumar Alamanda76315572015-04-23 13:13:56 -07001308 audio_extn_hwdep_cal_send(adev->snd_card, my_data->acdb_handle);
1309
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001310 /* load csd client */
1311 platform_csd_init(my_data);
1312
Eric Laurentb23d5282013-05-14 15:27:20 -07001313 return my_data;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001314
1315init_failed:
1316 if (my_data)
1317 free(my_data);
1318 return NULL;
Eric Laurentb23d5282013-05-14 15:27:20 -07001319}
1320
1321void platform_deinit(void *platform)
1322{
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001323 int32_t dev;
keunhui.park2f7306a2015-07-16 16:48:06 +09001324 struct operator_info *info_item;
1325 struct operator_specific_device *device_item;
1326 struct listnode *node;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001327
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001328 struct platform_data *my_data = (struct platform_data *)platform;
1329 close_csd_client(my_data->csd);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001330
vivek mehtade4849c2016-03-03 17:23:38 -08001331 hw_info_deinit(my_data->hw_info);
1332
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001333 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1334 if (backend_tag_table[dev])
1335 free(backend_tag_table[dev]);
1336 if (hw_interface_table[dev])
1337 free(hw_interface_table[dev]);
keunhui.park2f7306a2015-07-16 16:48:06 +09001338 if (operator_specific_device_table[dev]) {
1339 while (!list_empty(operator_specific_device_table[dev])) {
1340 node = list_head(operator_specific_device_table[dev]);
1341 list_remove(node);
1342 device_item = node_to_item(node, struct operator_specific_device, list);
1343 free(device_item->operator);
1344 free(device_item->mixer_path);
1345 free(device_item);
1346 }
1347 free(operator_specific_device_table[dev]);
1348 }
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001349 }
1350
1351 if (my_data->snd_card_name)
1352 free(my_data->snd_card_name);
1353
keunhui.park2f7306a2015-07-16 16:48:06 +09001354 while (!list_empty(&operator_info_list)) {
1355 node = list_head(&operator_info_list);
1356 list_remove(node);
1357 info_item = node_to_item(node, struct operator_info, list);
1358 free(info_item->name);
1359 free(info_item->mccmnc);
1360 free(info_item);
1361 }
1362
Eric Laurentb23d5282013-05-14 15:27:20 -07001363 free(platform);
1364}
1365
1366const char *platform_get_snd_device_name(snd_device_t snd_device)
1367{
keunhui.park2f7306a2015-07-16 16:48:06 +09001368 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1369 if (operator_specific_device_table[snd_device] != NULL) {
1370 return get_operator_specific_device_mixer_path(snd_device);
1371 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001372 return device_table[snd_device];
keunhui.park2f7306a2015-07-16 16:48:06 +09001373 } else
Ravi Kumar Alamanda64026462014-09-15 00:08:58 -07001374 return "none";
Eric Laurentb23d5282013-05-14 15:27:20 -07001375}
1376
vivek mehtade4849c2016-03-03 17:23:38 -08001377int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
1378 char *device_name)
1379{
1380 struct platform_data *my_data = (struct platform_data *)platform;
1381
David Benjamin1565f992016-09-21 12:10:34 -04001382 if (platform == NULL) {
vivek mehtade4849c2016-03-03 17:23:38 -08001383 ALOGW("%s: something wrong, use legacy get_snd_device name", __func__);
David Benjamin1565f992016-09-21 12:10:34 -04001384 strlcpy(device_name, platform_get_snd_device_name(snd_device),
1385 DEVICE_NAME_MAX_SIZE);
vivek mehtade4849c2016-03-03 17:23:38 -08001386 } else if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1387 if (operator_specific_device_table[snd_device] != NULL) {
1388 strlcpy(device_name, get_operator_specific_device_mixer_path(snd_device),
1389 DEVICE_NAME_MAX_SIZE);
1390 } else {
1391 strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE);
1392 }
1393 hw_info_append_hw_type(my_data->hw_info, snd_device, device_name);
1394 } else {
1395 strlcpy(device_name, "none", DEVICE_NAME_MAX_SIZE);
1396 }
1397
1398 return 0;
1399}
1400
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001401void platform_add_backend_name(void *platform, char *mixer_path,
1402 snd_device_t snd_device)
Eric Laurentb23d5282013-05-14 15:27:20 -07001403{
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001404 struct platform_data *my_data = (struct platform_data *)platform;
1405
Haynes Mathew George98c95622014-06-20 19:14:25 -07001406 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1407 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1408 return;
Ravi Kumar Alamanda1de6e5a2014-06-19 21:55:39 -05001409 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001410
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001411 const char * suffix = backend_tag_table[snd_device];
Haynes Mathew George98c95622014-06-20 19:14:25 -07001412
1413 if (suffix != NULL) {
1414 strcat(mixer_path, " ");
1415 strcat(mixer_path, suffix);
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001416 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001417}
1418
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001419bool platform_check_backends_match(snd_device_t snd_device1, snd_device_t snd_device2)
1420{
1421 bool result = true;
1422
1423 ALOGV("%s: snd_device1 = %s, snd_device2 = %s", __func__,
1424 platform_get_snd_device_name(snd_device1),
1425 platform_get_snd_device_name(snd_device2));
1426
1427 if ((snd_device1 < SND_DEVICE_MIN) || (snd_device1 >= SND_DEVICE_MAX)) {
1428 ALOGE("%s: Invalid snd_device = %s", __func__,
1429 platform_get_snd_device_name(snd_device1));
1430 return false;
1431 }
1432 if ((snd_device2 < SND_DEVICE_MIN) || (snd_device2 >= SND_DEVICE_MAX)) {
1433 ALOGE("%s: Invalid snd_device = %s", __func__,
1434 platform_get_snd_device_name(snd_device2));
1435 return false;
1436 }
1437 const char * be_itf1 = hw_interface_table[snd_device1];
1438 const char * be_itf2 = hw_interface_table[snd_device2];
1439
1440 if (NULL != be_itf1 && NULL != be_itf2) {
Eric Laurente63e61d2015-09-10 12:19:33 -07001441 if ((NULL == strstr(be_itf2, be_itf1)) && (NULL == strstr(be_itf1, be_itf2)))
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001442 result = false;
1443 }
1444
1445 ALOGV("%s: be_itf1 = %s, be_itf2 = %s, match %d", __func__, be_itf1, be_itf2, result);
1446 return result;
1447}
1448
Eric Laurentb23d5282013-05-14 15:27:20 -07001449int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
1450{
1451 int device_id;
1452 if (device_type == PCM_PLAYBACK)
1453 device_id = pcm_device_table[usecase][0];
1454 else
1455 device_id = pcm_device_table[usecase][1];
1456 return device_id;
1457}
1458
Haynes Mathew George98c95622014-06-20 19:14:25 -07001459static int find_index(const struct name_to_index * table, int32_t len,
1460 const char * name)
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001461{
1462 int ret = 0;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001463 int32_t i;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001464
Haynes Mathew George98c95622014-06-20 19:14:25 -07001465 if (table == NULL) {
1466 ALOGE("%s: table is NULL", __func__);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001467 ret = -ENODEV;
1468 goto done;
1469 }
1470
Haynes Mathew George98c95622014-06-20 19:14:25 -07001471 if (name == NULL) {
1472 ALOGE("null key");
1473 ret = -ENODEV;
1474 goto done;
1475 }
1476
1477 for (i=0; i < len; i++) {
1478 if (!strcmp(table[i].name, name)) {
1479 ret = table[i].index;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001480 goto done;
1481 }
1482 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001483 ALOGE("%s: Could not find index for name = %s",
1484 __func__, name);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001485 ret = -ENODEV;
1486done:
1487 return ret;
1488}
1489
Haynes Mathew George98c95622014-06-20 19:14:25 -07001490int platform_get_snd_device_index(char *device_name)
1491{
1492 return find_index(snd_device_name_index, SND_DEVICE_MAX, device_name);
1493}
1494
1495int platform_get_usecase_index(const char *usecase_name)
1496{
1497 return find_index(usecase_name_index, AUDIO_USECASE_MAX, usecase_name);
1498}
1499
keunhui.park2f7306a2015-07-16 16:48:06 +09001500void platform_add_operator_specific_device(snd_device_t snd_device,
1501 const char *operator,
1502 const char *mixer_path,
1503 unsigned int acdb_id)
1504{
1505 struct operator_specific_device *device;
1506
1507 if (operator_specific_device_table[snd_device] == NULL) {
1508 operator_specific_device_table[snd_device] =
1509 (struct listnode *)calloc(1, sizeof(struct listnode));
1510 list_init(operator_specific_device_table[snd_device]);
1511 }
1512
1513 device = (struct operator_specific_device *)calloc(1, sizeof(struct operator_specific_device));
1514
1515 device->operator = strdup(operator);
1516 device->mixer_path = strdup(mixer_path);
1517 device->acdb_id = acdb_id;
1518
1519 list_add_tail(operator_specific_device_table[snd_device], &device->list);
1520
Eric Laurent2bafff12016-03-17 12:17:23 -07001521 ALOGD("%s: device[%s] -> operator[%s] mixer_path[%s] acdb_id[%d]", __func__,
keunhui.park2f7306a2015-07-16 16:48:06 +09001522 platform_get_snd_device_name(snd_device), operator, mixer_path, acdb_id);
1523
1524}
1525
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001526int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
1527{
1528 int ret = 0;
1529
1530 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1531 ALOGE("%s: Invalid snd_device = %d",
1532 __func__, snd_device);
1533 ret = -EINVAL;
1534 goto done;
1535 }
1536
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001537 ALOGV("%s: acdb_device_table[%s]: old = %d new = %d", __func__,
1538 platform_get_snd_device_name(snd_device), acdb_device_table[snd_device], acdb_id);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001539 acdb_device_table[snd_device] = acdb_id;
1540done:
1541 return ret;
1542}
1543
Glenn Kastencbe06ca2016-11-09 10:49:26 -08001544int platform_get_default_app_type_v2(void *platform __unused, usecase_type_t type __unused,
1545 int *app_type __unused)
Yamit Mehtae3b99562016-09-16 22:44:00 +05301546{
1547 ALOGE("%s: Not implemented", __func__);
1548 return -ENOSYS;
1549}
1550
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001551int platform_get_snd_device_acdb_id(snd_device_t snd_device)
1552{
1553 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1554 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1555 return -EINVAL;
1556 }
keunhui.park2f7306a2015-07-16 16:48:06 +09001557
1558 if (operator_specific_device_table[snd_device] != NULL)
1559 return get_operator_specific_device_acdb_id(snd_device);
1560 else
1561 return acdb_device_table[snd_device];
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001562}
1563
Eric Laurentb23d5282013-05-14 15:27:20 -07001564int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
1565{
1566 struct platform_data *my_data = (struct platform_data *)platform;
1567 int acdb_dev_id, acdb_dev_type;
1568
Ravi Kumar Alamandaadf0f3b2015-06-04 02:34:02 -07001569 acdb_dev_id = acdb_device_table[audio_extn_get_spkr_prot_snd_device(snd_device)];
Eric Laurentb23d5282013-05-14 15:27:20 -07001570 if (acdb_dev_id < 0) {
1571 ALOGE("%s: Could not find acdb id for device(%d)",
1572 __func__, snd_device);
1573 return -EINVAL;
1574 }
1575 if (my_data->acdb_send_audio_cal) {
Joe Onorato188b6222016-03-01 11:02:27 -08001576 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Eric Laurentb23d5282013-05-14 15:27:20 -07001577 __func__, snd_device, acdb_dev_id);
1578 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
1579 snd_device < SND_DEVICE_OUT_END)
1580 acdb_dev_type = ACDB_DEV_TYPE_OUT;
1581 else
1582 acdb_dev_type = ACDB_DEV_TYPE_IN;
1583 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
1584 }
1585 return 0;
1586}
1587
1588int platform_switch_voice_call_device_pre(void *platform)
1589{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001590 struct platform_data *my_data = (struct platform_data *)platform;
1591 int ret = 0;
1592
1593 if (my_data->csd != NULL &&
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001594 voice_is_in_call(my_data->adev)) {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001595 /* This must be called before disabling mixer controls on APQ side */
1596 ret = my_data->csd->disable_device();
1597 if (ret < 0) {
1598 ALOGE("%s: csd_client_disable_device, failed, error %d",
1599 __func__, ret);
1600 }
1601 }
1602 return ret;
1603}
1604
1605int platform_switch_voice_call_enable_device_config(void *platform,
1606 snd_device_t out_snd_device,
1607 snd_device_t in_snd_device)
1608{
1609 struct platform_data *my_data = (struct platform_data *)platform;
1610 int acdb_rx_id, acdb_tx_id;
1611 int ret = 0;
1612
1613 if (my_data->csd == NULL)
1614 return ret;
1615
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001616 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1617 audio_extn_spkr_prot_is_enabled())
keunhui.park2f7306a2015-07-16 16:48:06 +09001618 acdb_rx_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_SPEAKER_PROTECTED);
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001619 else
keunhui.park2f7306a2015-07-16 16:48:06 +09001620 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001621
keunhui.park2f7306a2015-07-16 16:48:06 +09001622 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001623
1624 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
1625 ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
1626 if (ret < 0) {
1627 ALOGE("%s: csd_enable_device_config, failed, error %d",
1628 __func__, ret);
1629 }
1630 } else {
1631 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1632 acdb_rx_id, acdb_tx_id);
1633 }
1634
1635 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001636}
1637
1638int platform_switch_voice_call_device_post(void *platform,
1639 snd_device_t out_snd_device,
1640 snd_device_t in_snd_device)
1641{
1642 struct platform_data *my_data = (struct platform_data *)platform;
1643 int acdb_rx_id, acdb_tx_id;
1644
1645 if (my_data->acdb_send_voice_cal == NULL) {
1646 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
1647 } else {
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001648 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1649 audio_extn_spkr_prot_is_enabled())
1650 out_snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED;
1651
keunhui.park2f7306a2015-07-16 16:48:06 +09001652 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
1653 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07001654
1655 if (acdb_rx_id > 0 && acdb_tx_id > 0)
1656 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
1657 else
1658 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1659 acdb_rx_id, acdb_tx_id);
1660 }
1661
1662 return 0;
1663}
1664
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001665int platform_switch_voice_call_usecase_route_post(void *platform,
1666 snd_device_t out_snd_device,
1667 snd_device_t in_snd_device)
1668{
1669 struct platform_data *my_data = (struct platform_data *)platform;
1670 int acdb_rx_id, acdb_tx_id;
1671 int ret = 0;
1672
1673 if (my_data->csd == NULL)
1674 return ret;
1675
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001676 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1677 audio_extn_spkr_prot_is_enabled())
keunhui.park2f7306a2015-07-16 16:48:06 +09001678 acdb_rx_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED);
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001679 else
keunhui.park2f7306a2015-07-16 16:48:06 +09001680 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001681
keunhui.park2f7306a2015-07-16 16:48:06 +09001682 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001683
1684 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
1685 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
1686 my_data->adev->acdb_settings);
1687 if (ret < 0) {
1688 ALOGE("%s: csd_enable_device, failed, error %d", __func__, ret);
1689 }
1690 } else {
1691 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1692 acdb_rx_id, acdb_tx_id);
1693 }
1694
1695 return ret;
1696}
1697
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001698int platform_start_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07001699{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001700 struct platform_data *my_data = (struct platform_data *)platform;
1701 int ret = 0;
1702
1703 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001704 ret = my_data->csd->start_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001705 if (ret < 0) {
1706 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
1707 }
1708 }
1709 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001710}
1711
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001712int platform_stop_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07001713{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001714 struct platform_data *my_data = (struct platform_data *)platform;
1715 int ret = 0;
1716
1717 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001718 ret = my_data->csd->stop_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001719 if (ret < 0) {
1720 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
1721 }
1722 }
1723 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001724}
1725
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001726int platform_get_sample_rate(void *platform, uint32_t *rate)
1727{
1728 struct platform_data *my_data = (struct platform_data *)platform;
1729 int ret = 0;
1730
1731 if (my_data->csd != NULL) {
1732 ret = my_data->csd->get_sample_rate(rate);
1733 if (ret < 0) {
1734 ALOGE("%s: csd_get_sample_rate error %d\n", __func__, ret);
1735 }
1736 }
1737 return ret;
1738}
1739
vivek mehtab6506412015-08-07 16:55:17 -07001740void platform_set_speaker_gain_in_combo(struct audio_device *adev,
1741 snd_device_t snd_device,
1742 bool enable)
1743{
1744 const char* name;
1745 switch (snd_device) {
1746 case SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES:
1747 if (enable)
1748 name = "spkr-gain-in-headphone-combo";
1749 else
1750 name = "speaker-gain-default";
1751 break;
1752 case SND_DEVICE_OUT_SPEAKER_AND_LINE:
1753 if (enable)
1754 name = "spkr-gain-in-line-combo";
1755 else
1756 name = "speaker-gain-default";
1757 break;
1758 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES:
1759 if (enable)
1760 name = "spkr-safe-gain-in-headphone-combo";
1761 else
1762 name = "speaker-safe-gain-default";
1763 break;
1764 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE:
1765 if (enable)
1766 name = "spkr-safe-gain-in-line-combo";
1767 else
1768 name = "speaker-safe-gain-default";
1769 break;
1770 default:
1771 return;
1772 }
1773
1774 audio_route_apply_and_update_path(adev->audio_route, name);
1775}
1776
Eric Laurentb23d5282013-05-14 15:27:20 -07001777int platform_set_voice_volume(void *platform, int volume)
1778{
1779 struct platform_data *my_data = (struct platform_data *)platform;
1780 struct audio_device *adev = my_data->adev;
1781 struct mixer_ctl *ctl;
sangwoo53b2cf02013-07-25 19:18:44 -07001782 const char *mixer_ctl_name = "Voice Rx Gain";
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001783 int vol_index = 0, ret = 0;
1784 uint32_t set_values[ ] = {0,
1785 ALL_SESSION_VSID,
1786 DEFAULT_VOLUME_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07001787
1788 // Voice volume levels are mapped to adsp volume levels as follows.
1789 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
1790 // But this values don't changed in kernel. So, below change is need.
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09001791 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, my_data->max_vol_index);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001792 set_values[0] = vol_index;
Eric Laurentb23d5282013-05-14 15:27:20 -07001793
1794 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1795 if (!ctl) {
1796 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1797 __func__, mixer_ctl_name);
1798 return -EINVAL;
1799 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001800 ALOGV("Setting voice volume index: %d", set_values[0]);
1801 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1802
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001803 if (my_data->csd != NULL) {
1804 ret = my_data->csd->volume(ALL_SESSION_VSID, volume,
1805 DEFAULT_VOLUME_RAMP_DURATION_MS);
1806 if (ret < 0) {
1807 ALOGE("%s: csd_volume error %d", __func__, ret);
1808 }
1809 }
1810 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001811}
1812
1813int platform_set_mic_mute(void *platform, bool state)
1814{
1815 struct platform_data *my_data = (struct platform_data *)platform;
1816 struct audio_device *adev = my_data->adev;
1817 struct mixer_ctl *ctl;
1818 const char *mixer_ctl_name = "Voice Tx Mute";
sangwoo53b2cf02013-07-25 19:18:44 -07001819 int ret = 0;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001820 uint32_t set_values[ ] = {0,
1821 ALL_SESSION_VSID,
1822 DEFAULT_MUTE_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07001823
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09001824 if (adev->mode != AUDIO_MODE_IN_CALL &&
1825 adev->mode != AUDIO_MODE_IN_COMMUNICATION)
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001826 return 0;
1827
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09001828 if (adev->enable_hfp)
1829 mixer_ctl_name = "HFP Tx Mute";
1830
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001831 set_values[0] = state;
1832 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1833 if (!ctl) {
1834 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1835 __func__, mixer_ctl_name);
1836 return -EINVAL;
1837 }
1838 ALOGV("Setting voice mute state: %d", state);
1839 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1840
1841 if (my_data->csd != NULL) {
1842 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state,
1843 DEFAULT_MUTE_RAMP_DURATION_MS);
sangwoo53b2cf02013-07-25 19:18:44 -07001844 if (ret < 0) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001845 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
sangwoo53b2cf02013-07-25 19:18:44 -07001846 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001847 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001848 return ret;
1849}
Eric Laurentb23d5282013-05-14 15:27:20 -07001850
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001851int platform_set_device_mute(void *platform, bool state, char *dir)
1852{
1853 struct platform_data *my_data = (struct platform_data *)platform;
1854 struct audio_device *adev = my_data->adev;
1855 struct mixer_ctl *ctl;
1856 char *mixer_ctl_name = NULL;
1857 int ret = 0;
1858 uint32_t set_values[ ] = {0,
1859 ALL_SESSION_VSID,
1860 0};
1861 if(dir == NULL) {
1862 ALOGE("%s: Invalid direction:%s", __func__, dir);
1863 return -EINVAL;
1864 }
1865
1866 if (!strncmp("rx", dir, sizeof("rx"))) {
1867 mixer_ctl_name = "Voice Rx Device Mute";
1868 } else if (!strncmp("tx", dir, sizeof("tx"))) {
1869 mixer_ctl_name = "Voice Tx Device Mute";
1870 } else {
1871 return -EINVAL;
1872 }
1873
1874 set_values[0] = state;
1875 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1876 if (!ctl) {
1877 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1878 __func__, mixer_ctl_name);
1879 return -EINVAL;
1880 }
1881
1882 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
1883 __func__,state, mixer_ctl_name);
1884 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1885
1886 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001887}
1888
Haynes Mathew George2d809e02016-09-22 17:38:16 -07001889int platform_can_split_snd_device(snd_device_t snd_device,
1890 int *num_devices,
1891 snd_device_t *new_snd_devices)
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001892{
Haynes Mathew George2d809e02016-09-22 17:38:16 -07001893 int ret = -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001894 if (NULL == num_devices || NULL == new_snd_devices) {
1895 ALOGE("%s: NULL pointer ..", __func__);
Haynes Mathew George2d809e02016-09-22 17:38:16 -07001896 return -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001897 }
1898
1899 /*
1900 * If wired headset/headphones/line devices share the same backend
Haynes Mathew George2d809e02016-09-22 17:38:16 -07001901 * with speaker/earpiece this routine returns -EINVAL.
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001902 */
1903 if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES &&
1904 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_HEADPHONES)) {
1905 *num_devices = 2;
1906 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
1907 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07001908 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001909 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_LINE &&
1910 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_LINE)) {
1911 *num_devices = 2;
1912 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
1913 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07001914 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001915 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES &&
1916 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_HEADPHONES)) {
1917 *num_devices = 2;
1918 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
1919 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07001920 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001921 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE &&
1922 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_LINE)) {
1923 *num_devices = 2;
1924 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
1925 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07001926 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001927 }
Haynes Mathew George2d809e02016-09-22 17:38:16 -07001928 return ret;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001929}
1930
Eric Laurentb23d5282013-05-14 15:27:20 -07001931snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
1932{
1933 struct platform_data *my_data = (struct platform_data *)platform;
1934 struct audio_device *adev = my_data->adev;
1935 audio_mode_t mode = adev->mode;
1936 snd_device_t snd_device = SND_DEVICE_NONE;
1937
1938 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
1939 if (devices == AUDIO_DEVICE_NONE ||
1940 devices & AUDIO_DEVICE_BIT_IN) {
1941 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
1942 goto exit;
1943 }
1944
Eric Laurent1b491552015-09-15 17:52:41 -07001945 if (popcount(devices) == 2) {
1946 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
1947 AUDIO_DEVICE_OUT_SPEAKER) ||
1948 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
1949 AUDIO_DEVICE_OUT_SPEAKER)) {
1950 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
1951 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
1952 AUDIO_DEVICE_OUT_SPEAKER)) {
1953 snd_device = SND_DEVICE_OUT_SPEAKER_AND_LINE;
1954 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
1955 AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
1956 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
1957 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
1958 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES;
1959 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
1960 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
1961 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE;
1962 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
1963 AUDIO_DEVICE_OUT_SPEAKER)) {
1964 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
1965 } else {
1966 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
1967 goto exit;
1968 }
1969 if (snd_device != SND_DEVICE_NONE) {
1970 goto exit;
1971 }
1972 }
1973
1974 if (popcount(devices) != 1) {
1975 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
1976 goto exit;
1977 }
1978
Madhuri Athota3f6051b2016-10-13 23:25:38 +05301979 if (voice_is_in_call(adev) || adev->enable_voicerx || audio_extn_hfp_is_active(adev)) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001980 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05001981 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
1982 devices & AUDIO_DEVICE_OUT_LINE) {
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001983 if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05001984 (adev->voice.tty_mode == TTY_MODE_FULL))
Eric Laurentb23d5282013-05-14 15:27:20 -07001985 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001986 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05001987 (adev->voice.tty_mode == TTY_MODE_VCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07001988 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001989 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05001990 (adev->voice.tty_mode == TTY_MODE_HCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07001991 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05001992 else {
1993 if (devices & AUDIO_DEVICE_OUT_LINE)
1994 snd_device = SND_DEVICE_OUT_VOICE_LINE;
1995 else
1996 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
1997 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001998 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07001999 if (adev->bt_wb_speech_enabled) {
2000 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2001 } else {
2002 snd_device = SND_DEVICE_OUT_BT_SCO;
2003 }
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002004 } else if (devices & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002005 if (!adev->enable_hfp) {
2006 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
2007 } else {
2008 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_HFP;
2009 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002010 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002011 if(adev->voice.hac)
2012 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2013 else if (is_operator_tmus())
Eric Laurentb23d5282013-05-14 15:27:20 -07002014 snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS;
2015 else
Eric Laurentb4d368e2014-06-25 10:21:54 -05002016 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002017 } else if (devices & AUDIO_DEVICE_OUT_TELEPHONY_TX)
2018 snd_device = SND_DEVICE_OUT_VOICE_TX;
2019
Eric Laurentb23d5282013-05-14 15:27:20 -07002020 if (snd_device != SND_DEVICE_NONE) {
2021 goto exit;
2022 }
2023 }
2024
Eric Laurentb23d5282013-05-14 15:27:20 -07002025 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2026 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2027 snd_device = SND_DEVICE_OUT_HEADPHONES;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002028 } else if (devices & AUDIO_DEVICE_OUT_LINE) {
2029 snd_device = SND_DEVICE_OUT_LINE;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002030 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) {
2031 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE;
Eric Laurentb23d5282013-05-14 15:27:20 -07002032 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002033 if (my_data->speaker_lr_swap)
Eric Laurentb23d5282013-05-14 15:27:20 -07002034 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
2035 else
2036 snd_device = SND_DEVICE_OUT_SPEAKER;
2037 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002038 if (adev->bt_wb_speech_enabled) {
2039 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2040 } else {
2041 snd_device = SND_DEVICE_OUT_BT_SCO;
2042 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002043 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2044 snd_device = SND_DEVICE_OUT_HDMI ;
2045 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002046 /*HAC support for voice-ish audio (eg visual voicemail)*/
2047 if(adev->voice.hac)
2048 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2049 else
2050 snd_device = SND_DEVICE_OUT_HANDSET;
Eric Laurentb23d5282013-05-14 15:27:20 -07002051 } else {
2052 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
2053 }
2054exit:
2055 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
2056 return snd_device;
2057}
2058
2059snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
2060{
2061 struct platform_data *my_data = (struct platform_data *)platform;
2062 struct audio_device *adev = my_data->adev;
2063 audio_source_t source = (adev->active_input == NULL) ?
2064 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
2065
2066 audio_mode_t mode = adev->mode;
2067 audio_devices_t in_device = ((adev->active_input == NULL) ?
2068 AUDIO_DEVICE_NONE : adev->active_input->device)
2069 & ~AUDIO_DEVICE_BIT_IN;
2070 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
2071 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
2072 snd_device_t snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002073 int channel_count = popcount(channel_mask);
Eric Laurentb23d5282013-05-14 15:27:20 -07002074
Prashant Malanic92c5962015-08-11 15:10:18 -07002075 ALOGV("%s: enter: out_device(%#x) in_device(%#x) channel_count (%d) channel_mask (0x%x)",
2076 __func__, out_device, in_device, channel_count, channel_mask);
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002077 if ((out_device != AUDIO_DEVICE_NONE) && voice_is_in_call(adev)) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002078 if (adev->voice.tty_mode != TTY_MODE_OFF) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002079 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002080 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2081 out_device & AUDIO_DEVICE_OUT_LINE) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002082 switch (adev->voice.tty_mode) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002083 case TTY_MODE_FULL:
2084 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
2085 break;
2086 case TTY_MODE_VCO:
2087 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
2088 break;
2089 case TTY_MODE_HCO:
2090 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
2091 break;
2092 default:
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002093 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
Eric Laurentb23d5282013-05-14 15:27:20 -07002094 }
2095 goto exit;
2096 }
2097 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002098 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002099 if (my_data->fluence_in_voice_call == false) {
2100 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2101 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002102 if (is_operator_tmus())
2103 snd_device = SND_DEVICE_IN_VOICE_DMIC_TMUS;
Eric Laurentb23d5282013-05-14 15:27:20 -07002104 else
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002105 snd_device = SND_DEVICE_IN_VOICE_DMIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002106 }
2107 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2108 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
2109 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002110 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002111 if (adev->bluetooth_nrec)
2112 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2113 else
2114 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002115 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002116 if (adev->bluetooth_nrec)
2117 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2118 else
2119 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002120 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002121 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Prashant Malanic92c5962015-08-11 15:10:18 -07002122 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
2123 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2124 out_device & AUDIO_DEVICE_OUT_LINE) {
2125 if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
2126 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
2127 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
2128 } else {
2129 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2130 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002131 }
vivek mehtafe121d52015-08-10 23:39:23 -07002132
2133 //select default
2134 if (snd_device == SND_DEVICE_NONE) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002135 if (!adev->enable_hfp) {
2136 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2137 } else {
2138 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP;
2139 platform_set_echo_reference(adev, true, out_device);
2140 }
vivek mehtafe121d52015-08-10 23:39:23 -07002141 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002142 } else if (out_device & AUDIO_DEVICE_OUT_TELEPHONY_TX) {
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002143 snd_device = SND_DEVICE_IN_VOICE_RX;
Prashant Malanic92c5962015-08-11 15:10:18 -07002144 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002145 } else if (source == AUDIO_SOURCE_CAMCORDER) {
2146 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
2147 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2148 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
2149 }
2150 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
2151 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002152 if (my_data->fluence_in_voice_rec && channel_count == 1) {
2153 if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2154 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002155 if (adev->active_input->enable_aec)
2156 snd_device = SND_DEVICE_IN_HANDSET_QMIC_AEC;
2157 else
2158 snd_device = SND_DEVICE_IN_HANDSET_QMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002159 } else if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2160 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002161 if (adev->active_input->enable_aec)
2162 snd_device = SND_DEVICE_IN_HANDSET_TMIC_AEC;
2163 else
2164 snd_device = SND_DEVICE_IN_HANDSET_TMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002165 } else if (((my_data->fluence_type == FLUENCE_PRO_ENABLE) ||
2166 (my_data->fluence_type == FLUENCE_ENABLE)) &&
2167 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002168 if (adev->active_input->enable_aec)
2169 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
2170 else
2171 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
Prashant Malanic92c5962015-08-11 15:10:18 -07002172 }
2173 platform_set_echo_reference(adev, true, out_device);
2174 } else if ((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) &&
2175 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2176 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002177 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002178 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
2179 snd_device = SND_DEVICE_IN_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002180 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002181 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2182 snd_device = SND_DEVICE_IN_QUAD_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002183 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002184 if (snd_device == SND_DEVICE_NONE) {
vivek mehtaf3440682016-05-11 14:24:37 -07002185 if (adev->active_input->enable_aec) {
2186 if (adev->active_input->enable_ns) {
2187 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS;
2188 } else {
2189 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC;
2190 }
vivek mehta733c1df2016-04-04 15:09:24 -07002191 platform_set_echo_reference(adev, true, out_device);
vivek mehtaf3440682016-05-11 14:24:37 -07002192 } else if (adev->active_input->enable_ns) {
2193 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
2194 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002195 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
vivek mehtaf3440682016-05-11 14:24:37 -07002196 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002197 }
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -07002198 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2199 snd_device = SND_DEVICE_IN_VOICE_REC_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002200 }
rago90fb9612015-12-02 11:37:53 -08002201 } else if (source == AUDIO_SOURCE_UNPROCESSED) {
2202 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
vivek mehta4ed66e62016-04-15 23:33:34 -07002203 if (((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) ||
2204 (channel_mask == AUDIO_CHANNEL_IN_STEREO)) &&
2205 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2206 snd_device = SND_DEVICE_IN_UNPROCESSED_STEREO_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002207 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07002208 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
2209 snd_device = SND_DEVICE_IN_UNPROCESSED_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002210 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07002211 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2212 snd_device = SND_DEVICE_IN_UNPROCESSED_QUAD_MIC;
2213 } else {
2214 snd_device = SND_DEVICE_IN_UNPROCESSED_MIC;
2215 }
rago90fb9612015-12-02 11:37:53 -08002216 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2217 snd_device = SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC;
2218 }
Eric Laurent50a38ed2015-10-14 18:48:06 -07002219 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION ||
rago90fb9612015-12-02 11:37:53 -08002220 mode == AUDIO_MODE_IN_COMMUNICATION) {
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002221 if (out_device & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE))
Eric Laurentb23d5282013-05-14 15:27:20 -07002222 in_device = AUDIO_DEVICE_IN_BACK_MIC;
2223 if (adev->active_input) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002224 if (adev->active_input->enable_aec &&
2225 adev->active_input->enable_ns) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002226 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002227 if (my_data->fluence_in_spkr_mode &&
2228 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002229 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002230 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002231 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002232 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002233 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002234 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002235 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002236 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002237 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002238 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002239 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002240 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002241 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2242 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002243 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002244 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002245 } else if (adev->active_input->enable_aec) {
2246 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2247 if (my_data->fluence_in_spkr_mode &&
2248 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002249 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002250 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002251 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002252 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002253 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002254 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2255 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002256 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002257 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002258 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002259 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002260 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002261 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2262 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
2263 }
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08002264 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002265 } else if (adev->active_input->enable_ns) {
2266 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2267 if (my_data->fluence_in_spkr_mode &&
2268 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002269 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002270 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002271 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002272 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002273 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002274 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2275 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002276 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002277 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002278 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002279 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002280 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002281 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002282 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002283 }
2284 } else if (source == AUDIO_SOURCE_DEFAULT) {
2285 goto exit;
2286 }
2287
2288
2289 if (snd_device != SND_DEVICE_NONE) {
2290 goto exit;
2291 }
2292
2293 if (in_device != AUDIO_DEVICE_NONE &&
2294 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
2295 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
2296 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002297 if ((my_data->source_mic_type & SOURCE_QUAD_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002298 channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002299 snd_device = SND_DEVICE_IN_QUAD_MIC;
2300 } else if ((my_data->source_mic_type & SOURCE_THREE_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002301 channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002302 snd_device = SND_DEVICE_IN_THREE_MIC;
2303 } else if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2304 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002305 snd_device = SND_DEVICE_IN_HANDSET_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002306 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2307 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002308 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002309 } else {
2310 ALOGE("%s: something wrong (1): source type (%d) channel_count (%d) .."
2311 " channel mask (0x%x) no combination found .. setting to mono", __func__,
2312 my_data->source_mic_type, channel_count, channel_mask);
2313 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2314 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002315 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002316 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2317 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002318 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002319 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2320 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002321 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002322 } else {
2323 ALOGE("%s: something wrong (2): source type (%d) channel_count (%d) .."
2324 " no combination found .. setting to mono", __func__,
2325 my_data->source_mic_type, channel_count);
2326 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
2327 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002328 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2329 snd_device = SND_DEVICE_IN_HEADSET_MIC;
2330 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002331 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002332 if (adev->bluetooth_nrec)
2333 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2334 else
2335 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002336 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002337 if (adev->bluetooth_nrec)
2338 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2339 else
2340 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002341 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002342 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
2343 snd_device = SND_DEVICE_IN_HDMI_MIC;
2344 } else {
2345 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
2346 ALOGW("%s: Using default handset-mic", __func__);
2347 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2348 }
2349 } else {
2350 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
2351 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2352 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2353 snd_device = SND_DEVICE_IN_HEADSET_MIC;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002354 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002355 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002356 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002357 out_device & AUDIO_DEVICE_OUT_LINE) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002358 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2359 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002360 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002361 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2362 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002363 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002364 } else {
2365 ALOGE("%s: something wrong (3): source type (%d) channel_count (%d) .."
2366 " no combination found .. setting to mono", __func__,
2367 my_data->source_mic_type, channel_count);
2368 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
2369 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002370 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002371 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002372 if (adev->bluetooth_nrec)
2373 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2374 else
2375 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002376 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002377 if (adev->bluetooth_nrec)
2378 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2379 else
2380 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002381 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002382 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2383 snd_device = SND_DEVICE_IN_HDMI_MIC;
2384 } else {
2385 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
2386 ALOGW("%s: Using default handset-mic", __func__);
2387 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2388 }
2389 }
2390exit:
2391 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
2392 return snd_device;
2393}
2394
2395int platform_set_hdmi_channels(void *platform, int channel_count)
2396{
2397 struct platform_data *my_data = (struct platform_data *)platform;
2398 struct audio_device *adev = my_data->adev;
2399 struct mixer_ctl *ctl;
2400 const char *channel_cnt_str = NULL;
2401 const char *mixer_ctl_name = "HDMI_RX Channels";
2402 switch (channel_count) {
2403 case 8:
2404 channel_cnt_str = "Eight"; break;
2405 case 7:
2406 channel_cnt_str = "Seven"; break;
2407 case 6:
2408 channel_cnt_str = "Six"; break;
2409 case 5:
2410 channel_cnt_str = "Five"; break;
2411 case 4:
2412 channel_cnt_str = "Four"; break;
2413 case 3:
2414 channel_cnt_str = "Three"; break;
2415 default:
2416 channel_cnt_str = "Two"; break;
2417 }
2418 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2419 if (!ctl) {
2420 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2421 __func__, mixer_ctl_name);
2422 return -EINVAL;
2423 }
2424 ALOGV("HDMI channel count: %s", channel_cnt_str);
2425 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
2426 return 0;
2427}
2428
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002429int platform_edid_get_max_channels(void *platform)
Eric Laurentb23d5282013-05-14 15:27:20 -07002430{
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002431 struct platform_data *my_data = (struct platform_data *)platform;
2432 struct audio_device *adev = my_data->adev;
Eric Laurentb23d5282013-05-14 15:27:20 -07002433 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
2434 char *sad = block;
2435 int num_audio_blocks;
2436 int channel_count;
2437 int max_channels = 0;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002438 int i, ret, count;
Eric Laurentb23d5282013-05-14 15:27:20 -07002439
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002440 struct mixer_ctl *ctl;
2441
2442 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
2443 if (!ctl) {
2444 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2445 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
Eric Laurentb23d5282013-05-14 15:27:20 -07002446 return 0;
2447 }
2448
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002449 mixer_ctl_update(ctl);
2450
2451 count = mixer_ctl_get_num_values(ctl);
Eric Laurentb23d5282013-05-14 15:27:20 -07002452
2453 /* Read SAD blocks, clamping the maximum size for safety */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002454 if (count > (int)sizeof(block))
2455 count = (int)sizeof(block);
Eric Laurentb23d5282013-05-14 15:27:20 -07002456
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002457 ret = mixer_ctl_get_array(ctl, block, count);
2458 if (ret != 0) {
2459 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
2460 return 0;
2461 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002462
2463 /* Calculate the number of SAD blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002464 num_audio_blocks = count / SAD_BLOCK_SIZE;
Eric Laurentb23d5282013-05-14 15:27:20 -07002465
2466 for (i = 0; i < num_audio_blocks; i++) {
2467 /* Only consider LPCM blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002468 if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
2469 sad += 3;
Eric Laurentb23d5282013-05-14 15:27:20 -07002470 continue;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002471 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002472
2473 channel_count = (sad[0] & 0x7) + 1;
2474 if (channel_count > max_channels)
2475 max_channels = channel_count;
2476
2477 /* Advance to next block */
2478 sad += 3;
2479 }
2480
2481 return max_channels;
2482}
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07002483
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002484int platform_set_incall_recording_session_id(void *platform,
2485 uint32_t session_id, int rec_mode)
2486{
2487 int ret = 0;
2488 struct platform_data *my_data = (struct platform_data *)platform;
2489 struct audio_device *adev = my_data->adev;
2490 struct mixer_ctl *ctl;
2491 const char *mixer_ctl_name = "Voc VSID";
2492 int num_ctl_values;
2493 int i;
2494
2495 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2496 if (!ctl) {
2497 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2498 __func__, mixer_ctl_name);
2499 ret = -EINVAL;
2500 } else {
2501 num_ctl_values = mixer_ctl_get_num_values(ctl);
2502 for (i = 0; i < num_ctl_values; i++) {
2503 if (mixer_ctl_set_value(ctl, i, session_id)) {
2504 ALOGV("Error: invalid session_id: %x", session_id);
2505 ret = -EINVAL;
2506 break;
2507 }
2508 }
2509 }
2510
2511 if (my_data->csd != NULL) {
2512 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
2513 if (ret < 0) {
2514 ALOGE("%s: csd_client_start_record failed, error %d",
2515 __func__, ret);
2516 }
2517 }
2518
2519 return ret;
2520}
2521
2522int platform_stop_incall_recording_usecase(void *platform)
2523{
2524 int ret = 0;
2525 struct platform_data *my_data = (struct platform_data *)platform;
2526
2527 if (my_data->csd != NULL) {
2528 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
2529 if (ret < 0) {
2530 ALOGE("%s: csd_client_stop_record failed, error %d",
2531 __func__, ret);
2532 }
2533 }
2534
2535 return ret;
2536}
2537
2538int platform_start_incall_music_usecase(void *platform)
2539{
2540 int ret = 0;
2541 struct platform_data *my_data = (struct platform_data *)platform;
2542
2543 if (my_data->csd != NULL) {
2544 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
2545 if (ret < 0) {
2546 ALOGE("%s: csd_client_start_playback failed, error %d",
2547 __func__, ret);
2548 }
2549 }
2550
2551 return ret;
2552}
2553
2554int platform_stop_incall_music_usecase(void *platform)
2555{
2556 int ret = 0;
2557 struct platform_data *my_data = (struct platform_data *)platform;
2558
2559 if (my_data->csd != NULL) {
2560 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
2561 if (ret < 0) {
2562 ALOGE("%s: csd_client_stop_playback failed, error %d",
2563 __func__, ret);
2564 }
2565 }
2566
2567 return ret;
2568}
2569
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002570int platform_set_parameters(void *platform, struct str_parms *parms)
2571{
2572 struct platform_data *my_data = (struct platform_data *)platform;
keunhui.park2f7306a2015-07-16 16:48:06 +09002573 char value[128];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002574 char *kv_pairs = str_parms_to_str(parms);
2575 int ret = 0, err;
2576
2577 if (kv_pairs == NULL) {
2578 ret = -EINVAL;
2579 ALOGE("%s: key-value pair is NULL",__func__);
2580 goto done;
2581 }
2582
2583 ALOGV("%s: enter: %s", __func__, kv_pairs);
2584
2585 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME,
2586 value, sizeof(value));
2587 if (err >= 0) {
2588 str_parms_del(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME);
2589 my_data->snd_card_name = strdup(value);
2590 ALOGV("%s: sound card name %s", __func__, my_data->snd_card_name);
2591 }
2592
keunhui.park2f7306a2015-07-16 16:48:06 +09002593 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO,
2594 value, sizeof(value));
2595 if (err >= 0) {
2596 struct operator_info *info;
2597 char *str = value;
2598 char *name;
2599
2600 str_parms_del(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO);
2601 info = (struct operator_info *)calloc(1, sizeof(struct operator_info));
2602 name = strtok(str, ";");
2603 info->name = strdup(name);
2604 info->mccmnc = strdup(str + strlen(name) + 1);
2605
2606 list_add_tail(&operator_info_list, &info->list);
Joe Onorato188b6222016-03-01 11:02:27 -08002607 ALOGV("%s: add operator[%s] mccmnc[%s]", __func__, info->name, info->mccmnc);
keunhui.park2f7306a2015-07-16 16:48:06 +09002608 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002609
2610 memset(value, 0, sizeof(value));
Eric Laurentc6333382015-09-14 12:43:44 -07002611 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT,
Prashant Malanic92c5962015-08-11 15:10:18 -07002612 value, sizeof(value));
2613 if (err >= 0) {
Eric Laurentc6333382015-09-14 12:43:44 -07002614 str_parms_del(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT);
Prashant Malanic92c5962015-08-11 15:10:18 -07002615 my_data->max_mic_count = atoi(value);
2616 ALOGV("%s: max_mic_count %s/%d", __func__, value, my_data->max_mic_count);
Prashant Malanic92c5962015-08-11 15:10:18 -07002617 }
2618
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002619done:
2620 ALOGV("%s: exit with code(%d)", __func__, ret);
2621 if (kv_pairs != NULL)
2622 free(kv_pairs);
2623
2624 return ret;
2625}
2626
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07002627/* Delay in Us */
2628int64_t platform_render_latency(audio_usecase_t usecase)
2629{
2630 switch (usecase) {
2631 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
2632 return DEEP_BUFFER_PLATFORM_DELAY;
2633 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
2634 return LOW_LATENCY_PLATFORM_DELAY;
Haynes Mathew George03c40102016-01-29 17:57:48 -08002635 case USECASE_AUDIO_PLAYBACK_ULL:
2636 return ULL_PLATFORM_DELAY;
Eric Laurent0e46adf2016-12-16 12:49:24 -08002637 case USECASE_AUDIO_PLAYBACK_MMAP:
2638 return MMAP_PLATFORM_DELAY;
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07002639 default:
2640 return 0;
2641 }
2642}
Haynes Mathew George98c95622014-06-20 19:14:25 -07002643
vivek mehta4ed66e62016-04-15 23:33:34 -07002644bool platform_check_and_set_capture_backend_cfg(struct audio_device* adev,
David Benjaminc9d8d892016-09-21 12:04:55 -04002645 struct audio_usecase *usecase __unused,
2646 snd_device_t snd_device __unused)
vivek mehta4ed66e62016-04-15 23:33:34 -07002647{
2648 enum pcm_format in_pcm_format = PCM_FORMAT_S16_LE;
2649
2650 if (adev && adev->active_input)
2651 in_pcm_format = adev->active_input->config.format;
2652
2653 // allow 24 bit recording only if voice call is not active
2654 if (!voice_is_in_call(adev) &&
2655 adev->mode != AUDIO_MODE_IN_COMMUNICATION &&
2656 in_pcm_format == PCM_FORMAT_S24_LE) {
2657 audio_route_apply_and_update_path(adev->audio_route, "set-capture-format-24le");
2658 } else {
2659 audio_route_apply_and_update_path(adev->audio_route, "set-capture-format-default");
2660 }
2661
2662 return true;
2663}
2664
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002665int platform_set_snd_device_backend(snd_device_t device, const char *backend_tag,
2666 const char * hw_interface)
Haynes Mathew George98c95622014-06-20 19:14:25 -07002667{
2668 int ret = 0;
2669
2670 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
2671 ALOGE("%s: Invalid snd_device = %d",
2672 __func__, device);
2673 ret = -EINVAL;
2674 goto done;
2675 }
2676
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002677 ALOGV("%s: backend_tag_table[%s]: old = %s new = %s", __func__,
2678 platform_get_snd_device_name(device),
2679 backend_tag_table[device] != NULL ? backend_tag_table[device]: "null", backend_tag);
2680 if (backend_tag_table[device]) {
2681 free(backend_tag_table[device]);
Haynes Mathew George98c95622014-06-20 19:14:25 -07002682 }
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002683 backend_tag_table[device] = strdup(backend_tag);
2684
2685 if (hw_interface != NULL) {
2686 if (hw_interface_table[device])
2687 free(hw_interface_table[device]);
2688 ALOGV("%s: hw_interface_table[%d] = %s", __func__, device, hw_interface);
2689 hw_interface_table[device] = strdup(hw_interface);
2690 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07002691done:
2692 return ret;
2693}
2694
2695int platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t pcm_id)
2696{
2697 int ret = 0;
2698 if ((usecase <= USECASE_INVALID) || (usecase >= AUDIO_USECASE_MAX)) {
2699 ALOGE("%s: invalid usecase case idx %d", __func__, usecase);
2700 ret = -EINVAL;
2701 goto done;
2702 }
2703
2704 if ((type != 0) && (type != 1)) {
2705 ALOGE("%s: invalid usecase type", __func__);
2706 ret = -EINVAL;
2707 }
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002708 ALOGV("%s: pcm_device_table[%d][%d] = %d", __func__, usecase, type, pcm_id);
Haynes Mathew George98c95622014-06-20 19:14:25 -07002709 pcm_device_table[usecase][type] = pcm_id;
2710done:
2711 return ret;
2712}
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002713
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07002714#define DEFAULT_NOMINAL_SPEAKER_GAIN 20
2715int ramp_speaker_gain(struct audio_device *adev, bool ramp_up, int target_ramp_up_gain) {
2716 // backup_gain: gain to try to set in case of an error during ramp
2717 int start_gain, end_gain, step, backup_gain, i;
2718 bool error = false;
2719 const struct mixer_ctl *ctl;
2720 const char *mixer_ctl_name_gain_left = "Left Speaker Gain";
2721 const char *mixer_ctl_name_gain_right = "Right Speaker Gain";
2722 struct mixer_ctl *ctl_left = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_left);
2723 struct mixer_ctl *ctl_right = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_right);
2724 if (!ctl_left || !ctl_right) {
2725 ALOGE("%s: Could not get ctl for mixer cmd - %s or %s, not applying speaker gain ramp",
2726 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
2727 return -EINVAL;
2728 } else if ((mixer_ctl_get_num_values(ctl_left) != 1)
2729 || (mixer_ctl_get_num_values(ctl_right) != 1)) {
2730 ALOGE("%s: Unexpected num values for mixer cmd - %s or %s, not applying speaker gain ramp",
2731 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
2732 return -EINVAL;
2733 }
2734 if (ramp_up) {
2735 start_gain = 0;
2736 end_gain = target_ramp_up_gain > 0 ? target_ramp_up_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
2737 step = +1;
2738 backup_gain = end_gain;
2739 } else {
2740 // using same gain on left and right
2741 const int left_gain = mixer_ctl_get_value(ctl_left, 0);
2742 start_gain = left_gain > 0 ? left_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
2743 end_gain = 0;
2744 step = -1;
2745 backup_gain = start_gain;
2746 }
2747 for (i = start_gain ; i != (end_gain + step) ; i += step) {
2748 //ALOGV("setting speaker gain to %d", i);
2749 if (mixer_ctl_set_value(ctl_left, 0, i)) {
2750 ALOGE("%s: error setting %s to %d during gain ramp",
2751 __func__, mixer_ctl_name_gain_left, i);
2752 error = true;
2753 break;
2754 }
2755 if (mixer_ctl_set_value(ctl_right, 0, i)) {
2756 ALOGE("%s: error setting %s to %d during gain ramp",
2757 __func__, mixer_ctl_name_gain_right, i);
2758 error = true;
2759 break;
2760 }
2761 usleep(1000);
2762 }
2763 if (error) {
2764 // an error occured during the ramp, let's still try to go back to a safe volume
2765 if (mixer_ctl_set_value(ctl_left, 0, backup_gain)) {
2766 ALOGE("%s: error restoring left gain to %d", __func__, backup_gain);
2767 }
2768 if (mixer_ctl_set_value(ctl_right, 0, backup_gain)) {
2769 ALOGE("%s: error restoring right gain to %d", __func__, backup_gain);
2770 }
2771 }
2772 return start_gain;
2773}
2774
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002775int platform_swap_lr_channels(struct audio_device *adev, bool swap_channels)
2776{
2777 // only update if there is active pcm playback on speaker
2778 struct audio_usecase *usecase;
2779 struct listnode *node;
2780 struct platform_data *my_data = (struct platform_data *)adev->platform;
2781
2782 if (my_data->speaker_lr_swap != swap_channels) {
Jean-Michel Trivif7148702016-09-16 18:23:05 -07002783
2784 // do not swap channels in audio modes with concurrent capture and playback
2785 // as this may break the echo reference
2786 if ((adev->mode == AUDIO_MODE_IN_COMMUNICATION) || (adev->mode == AUDIO_MODE_IN_CALL)) {
2787 ALOGV("%s: will not swap due to audio mode %d", __func__, adev->mode);
2788 return 0;
2789 }
2790
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002791 my_data->speaker_lr_swap = swap_channels;
2792
2793 list_for_each(node, &adev->usecase_list) {
2794 usecase = node_to_item(node, struct audio_usecase, list);
2795 if (usecase->type == PCM_PLAYBACK &&
Ravi Kumar Alamanda425e1542015-09-22 09:11:18 -07002796 usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) {
2797 /*
2798 * If acdb tuning is different for SPEAKER_REVERSE, it is must
2799 * to perform device switch to disable the current backend to
2800 * enable it with new acdb data.
2801 */
2802 if (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
2803 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]) {
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07002804 const int initial_skpr_gain = ramp_speaker_gain(adev, false /*ramp_up*/, -1);
Ravi Kumar Alamanda425e1542015-09-22 09:11:18 -07002805 select_devices(adev, usecase->id);
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07002806 if (initial_skpr_gain != -EINVAL) {
2807 ramp_speaker_gain(adev, true /*ramp_up*/, initial_skpr_gain);
2808 }
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002809 } else {
Ravi Kumar Alamanda425e1542015-09-22 09:11:18 -07002810 const char *mixer_path;
2811 if (swap_channels) {
2812 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER_REVERSE);
2813 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
2814 } else {
2815 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER);
2816 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
2817 }
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002818 }
2819 break;
2820 }
2821 }
2822 }
2823 return 0;
2824}
vivek mehtaa8d7c922016-05-25 14:40:44 -07002825
2826static struct amp_db_and_gain_table tbl_mapping[MAX_VOLUME_CAL_STEPS];
2827static int num_gain_tbl_entry = 0;
2828
2829bool platform_add_gain_level_mapping(struct amp_db_and_gain_table *tbl_entry) {
2830
2831 ALOGV("%s: enter .. add %f %f %d", __func__, tbl_entry->amp, tbl_entry->db, tbl_entry->level);
2832 if (num_gain_tbl_entry == -1) {
2833 ALOGE("%s: num entry beyond valid step levels or corrupted..rejecting custom mapping",
2834 __func__);
2835 return false;
2836 }
2837
2838 if (num_gain_tbl_entry >= MAX_VOLUME_CAL_STEPS) {
2839 ALOGE("%s: max entry reached max[%d] current index[%d] .. rejecting", __func__,
2840 MAX_VOLUME_CAL_STEPS, num_gain_tbl_entry);
2841 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
2842 return false;
2843 }
2844
2845 if (num_gain_tbl_entry > 0 && tbl_mapping[num_gain_tbl_entry - 1].amp >= tbl_entry->amp) {
2846 ALOGE("%s: value not in ascending order .. rejecting custom mapping", __func__);
2847 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
2848 return false;
2849 }
2850
2851 tbl_mapping[num_gain_tbl_entry] = *tbl_entry;
2852 ++num_gain_tbl_entry;
2853
2854 return true;
2855}
2856
2857int platform_get_gain_level_mapping(struct amp_db_and_gain_table *mapping_tbl,
2858 int table_size) {
2859 int itt = 0;
2860 ALOGV("platform_get_gain_level_mapping called ");
2861
2862 if (num_gain_tbl_entry <= 0 || num_gain_tbl_entry > MAX_VOLUME_CAL_STEPS) {
2863 ALOGD("%s: empty or currupted gain_mapping_table", __func__);
2864 return 0;
2865 }
2866
2867 for (; itt < num_gain_tbl_entry && itt <= table_size; itt++) {
2868 mapping_tbl[itt] = tbl_mapping[itt];
2869 ALOGV("%s: added amp[%f] db[%f] level[%d]", __func__,
2870 mapping_tbl[itt].amp, mapping_tbl[itt].db, mapping_tbl[itt].level);
2871 }
2872
2873 return num_gain_tbl_entry;
2874}
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07002875
2876int platform_snd_card_update(void *platform, card_status_t status)
2877{
2878 struct platform_data *my_data = (struct platform_data *)platform;
2879 struct audio_device *adev = my_data->adev;
2880
2881 if (status == CARD_STATUS_ONLINE) {
2882 if (my_data->acdb_send_custom_top)
2883 my_data->acdb_send_custom_top();
2884 }
2885 return 0;
2886}