blob: c5a15cf6be638f417605bcfa65a3be11c9e6f50b [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},
161
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700162 [USECASE_AUDIO_RECORD] = {AUDIO_RECORD_PCM_DEVICE,
163 AUDIO_RECORD_PCM_DEVICE},
164 [USECASE_AUDIO_RECORD_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
165 LOWLATENCY_PCM_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700166
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700167 [USECASE_VOICE_CALL] = {VOICE_CALL_PCM_DEVICE,
168 VOICE_CALL_PCM_DEVICE},
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700169 [USECASE_VOICE2_CALL] = {VOICE2_CALL_PCM_DEVICE, VOICE2_CALL_PCM_DEVICE},
170 [USECASE_VOLTE_CALL] = {VOLTE_CALL_PCM_DEVICE, VOLTE_CALL_PCM_DEVICE},
171 [USECASE_QCHAT_CALL] = {QCHAT_CALL_PCM_DEVICE, QCHAT_CALL_PCM_DEVICE},
172 [USECASE_VOWLAN_CALL] = {VOWLAN_CALL_PCM_DEVICE, VOWLAN_CALL_PCM_DEVICE},
vivek mehtaa51fd402016-02-04 19:49:33 -0800173 [USECASE_VOICEMMODE1_CALL] = {VOICEMMODE1_CALL_PCM_DEVICE,
174 VOICEMMODE1_CALL_PCM_DEVICE},
175 [USECASE_VOICEMMODE2_CALL] = {VOICEMMODE2_CALL_PCM_DEVICE,
176 VOICEMMODE2_CALL_PCM_DEVICE},
177
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700178 [USECASE_INCALL_REC_UPLINK] = {AUDIO_RECORD_PCM_DEVICE,
179 AUDIO_RECORD_PCM_DEVICE},
180 [USECASE_INCALL_REC_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
181 AUDIO_RECORD_PCM_DEVICE},
182 [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
183 AUDIO_RECORD_PCM_DEVICE},
Ravi Kumar Alamanda8e6e98f2013-11-05 15:57:39 -0800184 [USECASE_AUDIO_HFP_SCO] = {HFP_PCM_RX, HFP_SCO_RX},
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700185
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700186 [USECASE_AUDIO_SPKR_CALIB_RX] = {SPKR_PROT_CALIB_RX_PCM_DEVICE, -1},
187 [USECASE_AUDIO_SPKR_CALIB_TX] = {-1, SPKR_PROT_CALIB_TX_PCM_DEVICE},
188
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700189 [USECASE_AUDIO_PLAYBACK_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
190 AFE_PROXY_RECORD_PCM_DEVICE},
191 [USECASE_AUDIO_RECORD_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
192 AFE_PROXY_RECORD_PCM_DEVICE},
zhaoyang yin4211fad2015-06-04 21:13:25 +0800193 [USECASE_AUDIO_DSM_FEEDBACK] = {QUAT_MI2S_PCM_DEVICE, QUAT_MI2S_PCM_DEVICE},
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700194
Eric Laurentb23d5282013-05-14 15:27:20 -0700195};
196
197/* Array to store sound devices */
198static const char * const device_table[SND_DEVICE_MAX] = {
199 [SND_DEVICE_NONE] = "none",
200 /* Playback sound devices */
201 [SND_DEVICE_OUT_HANDSET] = "handset",
202 [SND_DEVICE_OUT_SPEAKER] = "speaker",
203 [SND_DEVICE_OUT_SPEAKER_REVERSE] = "speaker-reverse",
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700204 [SND_DEVICE_OUT_SPEAKER_SAFE] = "speaker-safe",
Eric Laurentb23d5282013-05-14 15:27:20 -0700205 [SND_DEVICE_OUT_HEADPHONES] = "headphones",
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500206 [SND_DEVICE_OUT_LINE] = "line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700207 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones",
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700208 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = "speaker-safe-and-headphones",
Eric Laurent744996b2014-10-01 11:40:40 -0500209 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = "speaker-and-line",
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700210 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = "speaker-safe-and-line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700211 [SND_DEVICE_OUT_VOICE_HANDSET] = "voice-handset",
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500212 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = "voice-hac-handset",
Eric Laurentb23d5282013-05-14 15:27:20 -0700213 [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker",
214 [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones",
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500215 [SND_DEVICE_OUT_VOICE_LINE] = "voice-line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700216 [SND_DEVICE_OUT_HDMI] = "hdmi",
217 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi",
218 [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700219 [SND_DEVICE_OUT_BT_SCO_WB] = "bt-sco-headset-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700220 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = "voice-handset-tmus",
221 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones",
222 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones",
223 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700224 [SND_DEVICE_OUT_VOICE_TX] = "voice-tx",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700225 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = "speaker-protected",
226 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = "voice-speaker-protected",
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -0700227 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = "voice-speaker-hfp",
Eric Laurentb23d5282013-05-14 15:27:20 -0700228
229 /* Capture sound devices */
230 [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700231 [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700232 [SND_DEVICE_IN_HANDSET_MIC_NS] = "handset-mic",
233 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = "handset-mic",
234 [SND_DEVICE_IN_HANDSET_DMIC] = "dmic-endfire",
235 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = "dmic-endfire",
236 [SND_DEVICE_IN_HANDSET_DMIC_NS] = "dmic-endfire",
237 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = "dmic-endfire",
238 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = "dmic-endfire",
239
240 [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
241 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "speaker-mic",
242 [SND_DEVICE_IN_SPEAKER_MIC_NS] = "speaker-mic",
243 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = "speaker-mic",
244 [SND_DEVICE_IN_SPEAKER_DMIC] = "speaker-dmic-endfire",
245 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = "speaker-dmic-endfire",
246 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = "speaker-dmic-endfire",
247 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = "speaker-dmic-endfire",
248 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = "speaker-dmic-endfire",
249
250 [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
Eric Laurentcefbbac2014-09-04 13:54:10 -0500251 [SND_DEVICE_IN_HEADSET_MIC_AEC] = "headset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700252
Eric Laurentb23d5282013-05-14 15:27:20 -0700253 [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic",
254 [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700255 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = "bt-sco-mic",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700256 [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700257 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = "bt-sco-mic-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700258 [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700259
260 [SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef",
261 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = "voice-dmic-ef-tmus",
262 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
263 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = "voice-speaker-dmic-ef",
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -0700264 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = "voice-speaker-mic-hfp",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700265 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700266 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
267 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
268 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700269
Eric Laurentb23d5282013-05-14 15:27:20 -0700270 [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700271 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = "voice-rec-mic",
vivek mehta733c1df2016-04-04 15:09:24 -0700272 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = "voice-rec-mic",
vivek mehtaf3440682016-05-11 14:24:37 -0700273 [SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700274 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = "voice-rec-dmic-ef",
275 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence",
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700276 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = "headset-mic",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700277
Ricardo Garcia9034bc42016-04-04 07:11:46 -0700278 [SND_DEVICE_IN_UNPROCESSED_MIC] = "unprocessed-mic",
vivek mehta0125e782016-06-16 18:03:11 -0700279 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = "unprocessed-stereo-mic",
280 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = "unprocessed-three-mic",
281 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = "unprocessed-quad-mic",
282 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = "unprocessed-headset-mic",
rago90fb9612015-12-02 11:37:53 -0800283
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700284 [SND_DEVICE_IN_VOICE_RX] = "voice-rx",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700285
Prashant Malanic92c5962015-08-11 15:10:18 -0700286 [SND_DEVICE_IN_THREE_MIC] = "three-mic",
287 [SND_DEVICE_IN_QUAD_MIC] = "quad-mic",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700288 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = "vi-feedback",
Prashant Malanic92c5962015-08-11 15:10:18 -0700289 [SND_DEVICE_IN_HANDSET_TMIC] = "three-mic",
290 [SND_DEVICE_IN_HANDSET_QMIC] = "quad-mic",
vivek mehta733c1df2016-04-04 15:09:24 -0700291 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = "three-mic",
292 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = "quad-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700293};
294
295/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700296static int acdb_device_table[SND_DEVICE_MAX] = {
Eric Laurentb23d5282013-05-14 15:27:20 -0700297 [SND_DEVICE_NONE] = -1,
298 [SND_DEVICE_OUT_HANDSET] = 7,
299 [SND_DEVICE_OUT_SPEAKER] = 15,
300 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 15,
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700301 [SND_DEVICE_OUT_SPEAKER_SAFE] = 15,
Eric Laurentb23d5282013-05-14 15:27:20 -0700302 [SND_DEVICE_OUT_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500303 [SND_DEVICE_OUT_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700304 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700305 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500306 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = 77,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700307 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = 77,
Ravi Kumar Alamanda235c3482014-08-21 17:32:44 -0700308 [SND_DEVICE_OUT_VOICE_HANDSET] = ACDB_ID_VOICE_HANDSET,
309 [SND_DEVICE_OUT_VOICE_SPEAKER] = ACDB_ID_VOICE_SPEAKER,
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500310 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = 53,
Eric Laurentb23d5282013-05-14 15:27:20 -0700311 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500312 [SND_DEVICE_OUT_VOICE_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700313 [SND_DEVICE_OUT_HDMI] = 18,
314 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 15,
315 [SND_DEVICE_OUT_BT_SCO] = 22,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700316 [SND_DEVICE_OUT_BT_SCO_WB] = 39,
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700317 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = ACDB_ID_VOICE_HANDSET_TMUS,
Eric Laurentb23d5282013-05-14 15:27:20 -0700318 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
319 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
320 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700321 [SND_DEVICE_OUT_VOICE_TX] = 45,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700322 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = 124,
323 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = 101,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700324 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = ACDB_ID_VOICE_SPEAKER,
Eric Laurentb23d5282013-05-14 15:27:20 -0700325
326 [SND_DEVICE_IN_HANDSET_MIC] = 4,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700327 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 106,
328 [SND_DEVICE_IN_HANDSET_MIC_NS] = 107,
329 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = 108,
330 [SND_DEVICE_IN_HANDSET_DMIC] = 41,
331 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = 109,
332 [SND_DEVICE_IN_HANDSET_DMIC_NS] = 110,
333 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = 111,
334 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = 34,
335
336 [SND_DEVICE_IN_SPEAKER_MIC] = 11,
337 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 112,
338 [SND_DEVICE_IN_SPEAKER_MIC_NS] = 113,
339 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = 114,
340 [SND_DEVICE_IN_SPEAKER_DMIC] = 43,
341 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = 115,
342 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = 116,
343 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = 117,
344 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = 35,
345
rago90fb9612015-12-02 11:37:53 -0800346 [SND_DEVICE_IN_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentcefbbac2014-09-04 13:54:10 -0500347 [SND_DEVICE_IN_HEADSET_MIC_AEC] = ACDB_ID_HEADSET_MIC_AEC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700348
Eric Laurentb23d5282013-05-14 15:27:20 -0700349 [SND_DEVICE_IN_HDMI_MIC] = 4,
350 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700351 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = 21,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700352 [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700353 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = 38,
Eric Laurentb23d5282013-05-14 15:27:20 -0700354 [SND_DEVICE_IN_CAMCORDER_MIC] = 61,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700355
356 [SND_DEVICE_IN_VOICE_DMIC] = 41,
357 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = ACDB_ID_VOICE_DMIC_EF_TMUS,
358 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700359 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = 11,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700360 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 43,
rago90fb9612015-12-02 11:37:53 -0800361 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentb23d5282013-05-14 15:27:20 -0700362 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
363 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
364 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700365
rago90fb9612015-12-02 11:37:53 -0800366 [SND_DEVICE_IN_VOICE_REC_MIC] = ACDB_ID_VOICE_REC_MIC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700367 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = 113,
vivek mehta733c1df2016-04-04 15:09:24 -0700368 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = 112,
vivek mehtaf3440682016-05-11 14:24:37 -0700369 [SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = 114,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700370 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = 35,
371 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 43,
rago90fb9612015-12-02 11:37:53 -0800372 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
373
374 [SND_DEVICE_IN_UNPROCESSED_MIC] = ACDB_ID_VOICE_REC_MIC,
375 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
vivek mehta4ed66e62016-04-15 23:33:34 -0700376 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = 35,
377 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = 125,
378 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = 125,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700379
380 [SND_DEVICE_IN_VOICE_RX] = 44,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700381
Prashant Malanic92c5962015-08-11 15:10:18 -0700382 [SND_DEVICE_IN_THREE_MIC] = 46,
383 [SND_DEVICE_IN_QUAD_MIC] = 46,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700384 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = 102,
Prashant Malanic92c5962015-08-11 15:10:18 -0700385 [SND_DEVICE_IN_HANDSET_TMIC] = 125,
386 [SND_DEVICE_IN_HANDSET_QMIC] = 125,
vivek mehta733c1df2016-04-04 15:09:24 -0700387 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = 125, /* override this for new target to 140 */
388 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = 125, /* override this for new target to 140 */
Eric Laurentb23d5282013-05-14 15:27:20 -0700389};
390
Haynes Mathew George98c95622014-06-20 19:14:25 -0700391struct name_to_index {
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700392 char name[100];
393 unsigned int index;
394};
395
396#define TO_NAME_INDEX(X) #X, X
397
Haynes Mathew George98c95622014-06-20 19:14:25 -0700398/* Used to get index from parsed string */
399static const struct name_to_index snd_device_name_index[SND_DEVICE_MAX] = {
400 /* out */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700401 {TO_NAME_INDEX(SND_DEVICE_OUT_HANDSET)},
402 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER)},
403 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_REVERSE)},
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700404 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700405 {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500406 {TO_NAME_INDEX(SND_DEVICE_OUT_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700407 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700408 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES)},
Eric Laurent744996b2014-10-01 11:40:40 -0500409 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_LINE)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700410 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700411 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET)},
412 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700413 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_HFP)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700414 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500415 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700416 {TO_NAME_INDEX(SND_DEVICE_OUT_HDMI)},
417 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HDMI)},
418 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO)},
419 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO_WB)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700420 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET_TMUS)},
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500421 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HAC_HANDSET)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700422 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES)},
423 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES)},
424 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700425
426 /* in */
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700427 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED)},
428 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700429 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700430 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700431 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_NS)},
432 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)},
433 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC)},
434 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC)},
435 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_NS)},
436 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)},
437 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_STEREO)},
438
439 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700440 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700441 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_NS)},
442 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)},
443 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC)},
444 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC)},
445 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS)},
446 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)},
447 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_STEREO)},
448
449 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC)},
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700450 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700451
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700452 {TO_NAME_INDEX(SND_DEVICE_IN_HDMI_MIC)},
453 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700454 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700455 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700456 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700457 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700458
459 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC)},
460 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC_TMUS)},
461 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700462 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700463 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC)},
464 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEADSET_MIC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700465 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC)},
466 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC)},
467 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700468
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700469 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700470 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_NS)},
vivek mehta733c1df2016-04-04 15:09:24 -0700471 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC)},
vivek mehtaf3440682016-05-11 14:24:37 -0700472 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700473 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_STEREO)},
474 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE)},
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700475 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_HEADSET_MIC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700476
rago90fb9612015-12-02 11:37:53 -0800477 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_MIC)},
478 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC)},
vivek mehta4ed66e62016-04-15 23:33:34 -0700479 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_STEREO_MIC)},
480 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_THREE_MIC)},
481 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_QUAD_MIC)},
rago90fb9612015-12-02 11:37:53 -0800482
Prashant Malanic92c5962015-08-11 15:10:18 -0700483 {TO_NAME_INDEX(SND_DEVICE_IN_THREE_MIC)},
484 {TO_NAME_INDEX(SND_DEVICE_IN_QUAD_MIC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700485 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_VI_FEEDBACK)},
Prashant Malanic92c5962015-08-11 15:10:18 -0700486 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC)},
487 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC)},
vivek mehta733c1df2016-04-04 15:09:24 -0700488 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC_AEC)},
489 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC_AEC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700490};
491
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700492static char * backend_tag_table[SND_DEVICE_MAX] = {0};
493static char * hw_interface_table[SND_DEVICE_MAX] = {0};
Haynes Mathew George98c95622014-06-20 19:14:25 -0700494
495static const struct name_to_index usecase_name_index[AUDIO_USECASE_MAX] = {
496 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_DEEP_BUFFER)},
497 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_LOW_LATENCY)},
498 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_MULTI_CH)},
499 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD)},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700500 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_TTS)},
501 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_ULL)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700502 {TO_NAME_INDEX(USECASE_AUDIO_RECORD)},
503 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_LOW_LATENCY)},
504 {TO_NAME_INDEX(USECASE_VOICE_CALL)},
505 {TO_NAME_INDEX(USECASE_VOICE2_CALL)},
506 {TO_NAME_INDEX(USECASE_VOLTE_CALL)},
507 {TO_NAME_INDEX(USECASE_QCHAT_CALL)},
508 {TO_NAME_INDEX(USECASE_VOWLAN_CALL)},
509 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK)},
510 {TO_NAME_INDEX(USECASE_INCALL_REC_DOWNLINK)},
511 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK_AND_DOWNLINK)},
512 {TO_NAME_INDEX(USECASE_AUDIO_HFP_SCO)},
vivek mehta01197db2016-11-22 18:54:02 -0800513 {TO_NAME_INDEX(USECASE_VOICEMMODE1_CALL)},
514 {TO_NAME_INDEX(USECASE_VOICEMMODE2_CALL)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700515};
516
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700517#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
518#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
Haynes Mathew George03c40102016-01-29 17:57:48 -0800519#define ULL_PLATFORM_DELAY (7*1000LL)
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700520
Eric Laurentb23d5282013-05-14 15:27:20 -0700521static pthread_once_t check_op_once_ctl = PTHREAD_ONCE_INIT;
522static bool is_tmus = false;
523
524static void check_operator()
525{
526 char value[PROPERTY_VALUE_MAX];
527 int mccmnc;
528 property_get("gsm.sim.operator.numeric",value,"0");
529 mccmnc = atoi(value);
Eric Laurent2bafff12016-03-17 12:17:23 -0700530 ALOGD("%s: tmus mccmnc %d", __func__, mccmnc);
Eric Laurentb23d5282013-05-14 15:27:20 -0700531 switch(mccmnc) {
532 /* TMUS MCC(310), MNC(490, 260, 026) */
533 case 310490:
534 case 310260:
535 case 310026:
sangwon.jeonb891db52013-09-14 17:39:15 +0900536 /* Add new TMUS MNC(800, 660, 580, 310, 270, 250, 240, 230, 220, 210, 200, 160) */
537 case 310800:
538 case 310660:
539 case 310580:
540 case 310310:
541 case 310270:
542 case 310250:
543 case 310240:
544 case 310230:
545 case 310220:
546 case 310210:
547 case 310200:
548 case 310160:
Eric Laurentb23d5282013-05-14 15:27:20 -0700549 is_tmus = true;
550 break;
551 }
552}
553
554bool is_operator_tmus()
555{
556 pthread_once(&check_op_once_ctl, check_operator);
557 return is_tmus;
558}
559
keunhui.park2f7306a2015-07-16 16:48:06 +0900560static char *get_current_operator()
561{
562 struct listnode *node;
563 struct operator_info *info_item;
564 char mccmnc[PROPERTY_VALUE_MAX];
565 char *ret = NULL;
566
Tom Cherry7fea2042016-11-10 18:05:59 -0800567 property_get("gsm.sim.operator.numeric",mccmnc,"00000");
keunhui.park2f7306a2015-07-16 16:48:06 +0900568
569 list_for_each(node, &operator_info_list) {
570 info_item = node_to_item(node, struct operator_info, list);
571 if (strstr(info_item->mccmnc, mccmnc) != NULL) {
572 ret = info_item->name;
573 }
574 }
575
576 return ret;
577}
578
579static struct operator_specific_device *get_operator_specific_device(snd_device_t snd_device)
580{
581 struct listnode *node;
582 struct operator_specific_device *ret = NULL;
583 struct operator_specific_device *device_item;
584 char *operator_name;
585
586 operator_name = get_current_operator();
587 if (operator_name == NULL)
588 return ret;
589
590 list_for_each(node, operator_specific_device_table[snd_device]) {
591 device_item = node_to_item(node, struct operator_specific_device, list);
592 if (strcmp(operator_name, device_item->operator) == 0) {
593 ret = device_item;
594 }
595 }
596
597 return ret;
598}
599
600
601static int get_operator_specific_device_acdb_id(snd_device_t snd_device)
602{
603 struct operator_specific_device *device;
604 int ret = acdb_device_table[snd_device];
605
606 device = get_operator_specific_device(snd_device);
607 if (device != NULL)
608 ret = device->acdb_id;
609
610 return ret;
611}
612
613static const char *get_operator_specific_device_mixer_path(snd_device_t snd_device)
614{
615 struct operator_specific_device *device;
616 const char *ret = device_table[snd_device];
617
618 device = get_operator_specific_device(snd_device);
619 if (device != NULL)
620 ret = device->mixer_path;
621
622 return ret;
623}
624
vivek mehta1a9b7c02015-06-25 11:49:38 -0700625bool platform_send_gain_dep_cal(void *platform, int level)
626{
627 bool ret_val = false;
628 struct platform_data *my_data = (struct platform_data *)platform;
629 struct audio_device *adev = my_data->adev;
630 int acdb_dev_id, app_type;
631 int acdb_dev_type = MSM_SNDDEV_CAP_RX;
632 int mode = CAL_MODE_RTAC;
633 struct listnode *node;
634 struct audio_usecase *usecase;
vivek mehta1a9b7c02015-06-25 11:49:38 -0700635
636 if (my_data->acdb_send_gain_dep_cal == NULL) {
637 ALOGE("%s: dlsym error for acdb_send_gain_dep_cal", __func__);
638 return ret_val;
639 }
640
641 if (!voice_is_in_call(adev)) {
642 ALOGV("%s: Not Voice call usecase, apply new cal for level %d",
643 __func__, level);
644 app_type = DEFAULT_APP_TYPE_RX_PATH;
645
646 // find the current active sound device
647 list_for_each(node, &adev->usecase_list) {
648 usecase = node_to_item(node, struct audio_usecase, list);
649
650 if (usecase != NULL &&
651 usecase->type == PCM_PLAYBACK &&
652 (usecase->stream.out->devices == AUDIO_DEVICE_OUT_SPEAKER)) {
653
654 ALOGV("%s: out device is %d", __func__, usecase->out_snd_device);
vivek mehta4cb82982015-07-13 12:05:49 -0700655 if (audio_extn_spkr_prot_is_enabled()) {
656 acdb_dev_id = audio_extn_spkr_prot_get_acdb_id(usecase->out_snd_device);
657 } else {
658 acdb_dev_id = acdb_device_table[usecase->out_snd_device];
659 }
660
vivek mehta1a9b7c02015-06-25 11:49:38 -0700661 if (!my_data->acdb_send_gain_dep_cal(acdb_dev_id, app_type,
662 acdb_dev_type, mode, level)) {
663 // set ret_val true if at least one calibration is set successfully
664 ret_val = true;
665 } else {
666 ALOGE("%s: my_data->acdb_send_gain_dep_cal failed ", __func__);
667 }
668 } else {
669 ALOGW("%s: Usecase list is empty", __func__);
670 }
671 }
672 } else {
673 ALOGW("%s: Voice call in progress .. ignore setting new cal",
674 __func__);
675 }
676 return ret_val;
677}
678
Eric Laurentcefbbac2014-09-04 13:54:10 -0500679void platform_set_echo_reference(struct audio_device *adev, bool enable, audio_devices_t out_device)
Eric Laurentb23d5282013-05-14 15:27:20 -0700680{
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800681 struct platform_data *my_data = (struct platform_data *)adev->platform;
Eric Laurentcefbbac2014-09-04 13:54:10 -0500682 snd_device_t snd_device = SND_DEVICE_NONE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700683
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800684 if (strcmp(my_data->ec_ref_mixer_path, "")) {
685 ALOGV("%s: diabling %s", __func__, my_data->ec_ref_mixer_path);
686 audio_route_reset_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
Eric Laurentcefbbac2014-09-04 13:54:10 -0500687 }
688
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800689 if (enable) {
690 strcpy(my_data->ec_ref_mixer_path, "echo-reference");
691 if (out_device != AUDIO_DEVICE_NONE) {
692 snd_device = platform_get_output_snd_device(adev->platform, out_device);
693 platform_add_backend_name(adev->platform, my_data->ec_ref_mixer_path, snd_device);
694 }
Eric Laurentcefbbac2014-09-04 13:54:10 -0500695
Joe Onorato188b6222016-03-01 11:02:27 -0800696 ALOGV("%s: enabling %s", __func__, my_data->ec_ref_mixer_path);
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800697 audio_route_apply_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
698 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700699}
700
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700701static struct csd_data *open_csd_client(bool i2s_ext_modem)
702{
703 struct csd_data *csd = calloc(1, sizeof(struct csd_data));
704
705 csd->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
706 if (csd->csd_client == NULL) {
707 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
708 goto error;
709 } else {
710 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
711
712 csd->deinit = (deinit_t)dlsym(csd->csd_client,
713 "csd_client_deinit");
714 if (csd->deinit == NULL) {
715 ALOGE("%s: dlsym error %s for csd_client_deinit", __func__,
716 dlerror());
717 goto error;
718 }
719 csd->disable_device = (disable_device_t)dlsym(csd->csd_client,
720 "csd_client_disable_device");
721 if (csd->disable_device == NULL) {
722 ALOGE("%s: dlsym error %s for csd_client_disable_device",
723 __func__, dlerror());
724 goto error;
725 }
726 csd->enable_device_config = (enable_device_config_t)dlsym(csd->csd_client,
727 "csd_client_enable_device_config");
728 if (csd->enable_device_config == NULL) {
729 ALOGE("%s: dlsym error %s for csd_client_enable_device_config",
730 __func__, dlerror());
731 goto error;
732 }
733 csd->enable_device = (enable_device_t)dlsym(csd->csd_client,
734 "csd_client_enable_device");
735 if (csd->enable_device == NULL) {
736 ALOGE("%s: dlsym error %s for csd_client_enable_device",
737 __func__, dlerror());
738 goto error;
739 }
740 csd->start_voice = (start_voice_t)dlsym(csd->csd_client,
741 "csd_client_start_voice");
742 if (csd->start_voice == NULL) {
743 ALOGE("%s: dlsym error %s for csd_client_start_voice",
744 __func__, dlerror());
745 goto error;
746 }
747 csd->stop_voice = (stop_voice_t)dlsym(csd->csd_client,
748 "csd_client_stop_voice");
749 if (csd->stop_voice == NULL) {
750 ALOGE("%s: dlsym error %s for csd_client_stop_voice",
751 __func__, dlerror());
752 goto error;
753 }
754 csd->volume = (volume_t)dlsym(csd->csd_client,
755 "csd_client_volume");
756 if (csd->volume == NULL) {
757 ALOGE("%s: dlsym error %s for csd_client_volume",
758 __func__, dlerror());
759 goto error;
760 }
761 csd->mic_mute = (mic_mute_t)dlsym(csd->csd_client,
762 "csd_client_mic_mute");
763 if (csd->mic_mute == NULL) {
764 ALOGE("%s: dlsym error %s for csd_client_mic_mute",
765 __func__, dlerror());
766 goto error;
767 }
768 csd->slow_talk = (slow_talk_t)dlsym(csd->csd_client,
769 "csd_client_slow_talk");
770 if (csd->slow_talk == NULL) {
771 ALOGE("%s: dlsym error %s for csd_client_slow_talk",
772 __func__, dlerror());
773 goto error;
774 }
775 csd->start_playback = (start_playback_t)dlsym(csd->csd_client,
776 "csd_client_start_playback");
777 if (csd->start_playback == NULL) {
778 ALOGE("%s: dlsym error %s for csd_client_start_playback",
779 __func__, dlerror());
780 goto error;
781 }
782 csd->stop_playback = (stop_playback_t)dlsym(csd->csd_client,
783 "csd_client_stop_playback");
784 if (csd->stop_playback == NULL) {
785 ALOGE("%s: dlsym error %s for csd_client_stop_playback",
786 __func__, dlerror());
787 goto error;
788 }
789 csd->start_record = (start_record_t)dlsym(csd->csd_client,
790 "csd_client_start_record");
791 if (csd->start_record == NULL) {
792 ALOGE("%s: dlsym error %s for csd_client_start_record",
793 __func__, dlerror());
794 goto error;
795 }
796 csd->stop_record = (stop_record_t)dlsym(csd->csd_client,
797 "csd_client_stop_record");
798 if (csd->stop_record == NULL) {
799 ALOGE("%s: dlsym error %s for csd_client_stop_record",
800 __func__, dlerror());
801 goto error;
802 }
803
804 csd->get_sample_rate = (get_sample_rate_t)dlsym(csd->csd_client,
805 "csd_client_get_sample_rate");
806 if (csd->get_sample_rate == NULL) {
807 ALOGE("%s: dlsym error %s for csd_client_get_sample_rate",
808 __func__, dlerror());
809
810 goto error;
811 }
812
813 csd->init = (init_t)dlsym(csd->csd_client, "csd_client_init");
814
815 if (csd->init == NULL) {
816 ALOGE("%s: dlsym error %s for csd_client_init",
817 __func__, dlerror());
818 goto error;
819 } else {
820 csd->init(i2s_ext_modem);
821 }
822 }
823 return csd;
824
825error:
826 free(csd);
827 csd = NULL;
828 return csd;
829}
830
831void close_csd_client(struct csd_data *csd)
832{
833 if (csd != NULL) {
834 csd->deinit();
835 dlclose(csd->csd_client);
836 free(csd);
837 csd = NULL;
838 }
839}
840
841static void platform_csd_init(struct platform_data *my_data)
842{
843#ifdef PLATFORM_MSM8084
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700844 int32_t modems, (*count_modems)(void);
845 const char *name = "libdetectmodem.so";
846 const char *func = "count_modems";
847 const char *error;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700848
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700849 my_data->csd = NULL;
850
851 void *lib = dlopen(name, RTLD_NOW);
852 error = dlerror();
853 if (!lib) {
854 ALOGE("%s: could not find %s: %s", __func__, name, error);
855 return;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700856 }
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700857
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700858 count_modems = NULL;
859 *(void **)(&count_modems) = dlsym(lib, func);
860 error = dlerror();
861 if (!count_modems) {
862 ALOGE("%s: could not find symbol %s in %s: %s",
863 __func__, func, name, error);
864 goto done;
865 }
866
867 modems = count_modems();
868 if (modems < 0) {
869 ALOGE("%s: count_modems failed\n", __func__);
870 goto done;
871 }
872
Eric Laurent2bafff12016-03-17 12:17:23 -0700873 ALOGD("%s: num_modems %d\n", __func__, modems);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700874 if (modems > 0)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700875 my_data->csd = open_csd_client(false /*is_i2s_ext_modem*/);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700876
877done:
878 dlclose(lib);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700879#else
880 my_data->csd = NULL;
881#endif
882}
883
Eric Laurentc6333382015-09-14 12:43:44 -0700884static void set_platform_defaults(struct platform_data * my_data)
Haynes Mathew George98c95622014-06-20 19:14:25 -0700885{
886 int32_t dev;
887 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700888 backend_tag_table[dev] = NULL;
889 hw_interface_table[dev] = NULL;
keunhui.park2f7306a2015-07-16 16:48:06 +0900890 operator_specific_device_table[dev] = NULL;
Haynes Mathew George98c95622014-06-20 19:14:25 -0700891 }
892
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700893 // To overwrite these go to the audio_platform_info.xml file.
894 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("bt-sco");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700895 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("bt-sco");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700896 backend_tag_table[SND_DEVICE_OUT_BT_SCO] = strdup("bt-sco");
897 backend_tag_table[SND_DEVICE_OUT_HDMI] = strdup("hdmi");
898 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("speaker-and-hdmi");
899 backend_tag_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("bt-sco-wb");
900 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("bt-sco-wb");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700901 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("bt-sco-wb");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700902 backend_tag_table[SND_DEVICE_OUT_VOICE_TX] = strdup("afe-proxy");
903 backend_tag_table[SND_DEVICE_IN_VOICE_RX] = strdup("afe-proxy");
Haynes Mathew George98c95622014-06-20 19:14:25 -0700904
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700905 hw_interface_table[SND_DEVICE_OUT_HANDSET] = strdup("SLIMBUS_0_RX");
906 hw_interface_table[SND_DEVICE_OUT_SPEAKER] = strdup("SLIMBUS_0_RX");
907 hw_interface_table[SND_DEVICE_OUT_SPEAKER_REVERSE] = strdup("SLIMBUS_0_RX");
908 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE] = strdup("SLIMBUS_0_RX");
909 hw_interface_table[SND_DEVICE_OUT_HEADPHONES] = strdup("SLIMBUS_0_RX");
910 hw_interface_table[SND_DEVICE_OUT_LINE] = strdup("SLIMBUS_0_RX");
911 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700912 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700913 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700914 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700915 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET] = strdup("SLIMBUS_0_RX");
916 hw_interface_table[SND_DEVICE_OUT_VOICE_HAC_HANDSET] = strdup("SLIMBUS_0_RX");
917 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER] = strdup("SLIMBUS_0_RX");
918 hw_interface_table[SND_DEVICE_OUT_VOICE_HEADPHONES] = strdup("SLIMBUS_0_RX");
919 hw_interface_table[SND_DEVICE_OUT_VOICE_LINE] = strdup("SLIMBUS_0_RX");
920 hw_interface_table[SND_DEVICE_OUT_HDMI] = strdup("HDMI_RX");
921 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("SLIMBUS_0_RX-and-HDMI_RX");
922 hw_interface_table[SND_DEVICE_OUT_BT_SCO] = strdup("SEC_AUX_PCM_RX");
923 hw_interface_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("SEC_AUX_PCM_RX");
924 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = strdup("SLIMBUS_0_RX");
925 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = strdup("SLIMBUS_0_RX");
926 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = strdup("SLIMBUS_0_RX");
927 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = strdup("SLIMBUS_0_RX");
928 hw_interface_table[SND_DEVICE_OUT_VOICE_TX] = strdup("AFE_PCM_RX");
929 hw_interface_table[SND_DEVICE_OUT_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
930 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
Eric Laurentc6333382015-09-14 12:43:44 -0700931
932 my_data->max_mic_count = PLATFORM_DEFAULT_MIC_COUNT;
Haynes Mathew George98c95622014-06-20 19:14:25 -0700933}
934
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +0900935void get_cvd_version(char *cvd_version, struct audio_device *adev)
936{
937 struct mixer_ctl *ctl;
938 int count;
939 int ret = 0;
940
941 ctl = mixer_get_ctl_by_name(adev->mixer, CVD_VERSION_MIXER_CTL);
942 if (!ctl) {
943 ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__, CVD_VERSION_MIXER_CTL);
944 goto done;
945 }
946 mixer_ctl_update(ctl);
947
948 count = mixer_ctl_get_num_values(ctl);
949 if (count > MAX_CVD_VERSION_STRING_SIZE)
950 count = MAX_CVD_VERSION_STRING_SIZE - 1;
951
952 ret = mixer_ctl_get_array(ctl, cvd_version, count);
953 if (ret != 0) {
954 ALOGE("%s: ERROR! mixer_ctl_get_array() failed to get CVD Version", __func__);
955 goto done;
956 }
957
958done:
959 return;
960}
961
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -0700962static int platform_acdb_init(void *platform)
963{
964 struct platform_data *my_data = (struct platform_data *)platform;
965 struct audio_device *adev = my_data->adev;
966
967 if (!my_data->acdb_init) {
968 ALOGE("%s: no acdb_init fn provided", __func__);
969 return -1;
970 }
971
972 if (my_data->acdb_initialized) {
973 ALOGW("acdb is already initialized");
974 return 0;
975 }
976
Thierry Strudel92232b42017-01-26 10:51:48 -0800977#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -0700978 char *cvd_version = calloc(1, MAX_CVD_VERSION_STRING_SIZE);
979 if (!cvd_version)
980 ALOGE("failed to allocate cvd_version");
981 else {
982 get_cvd_version(cvd_version, adev);
983 my_data->acdb_init((char *)my_data->snd_card_name, cvd_version, 0);
984 free(cvd_version);
985 }
986#elif defined (PLATFORM_MSM8084)
987 my_data->acdb_init((char *)my_data->snd_card_name);
988#else
989 my_data->acdb_init();
990#endif
991 my_data->acdb_initialized = true;
992 return 0;
993}
994
Eric Laurentb23d5282013-05-14 15:27:20 -0700995void *platform_init(struct audio_device *adev)
996{
997 char value[PROPERTY_VALUE_MAX];
vivek mehta60ea4152016-02-18 17:10:26 -0800998 struct platform_data *my_data = NULL;
999 int retry_num = 0, snd_card_num = 0, key = 0, ret = 0;
1000 bool dual_mic_config = false, use_default_mixer_path = true;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001001 const char *snd_card_name;
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001002 char *cvd_version = NULL;
vivek mehta60ea4152016-02-18 17:10:26 -08001003 char *snd_internal_name = NULL;
1004 char *tmp = NULL;
1005 char mixer_xml_file[MIXER_PATH_MAX_LENGTH]= {0};
vivek mehtade4849c2016-03-03 17:23:38 -08001006 char platform_info_file[MIXER_PATH_MAX_LENGTH]= {0};
1007 struct snd_card_split *snd_split_handle = NULL;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001008 my_data = calloc(1, sizeof(struct platform_data));
1009
1010 my_data->adev = adev;
1011
keunhui.park2f7306a2015-07-16 16:48:06 +09001012 list_init(&operator_info_list);
1013
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001014 set_platform_defaults(my_data);
vivek mehta2b0e5a62016-09-02 17:31:58 -07001015 bool card_verifed[MAX_SND_CARD] = {0};
1016 const int retry_limit = property_get_int32("audio.snd_card.open.retries", RETRY_NUMBER);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001017
vivek mehta2b0e5a62016-09-02 17:31:58 -07001018 for (;;) {
1019 if (snd_card_num >= MAX_SND_CARD) {
1020 if (retry_num++ >= retry_limit) {
1021 ALOGE("%s: Unable to find correct sound card, aborting.", __func__);
1022 goto init_failed;
1023 }
sangwoo1b9f4b32013-06-21 18:22:55 -07001024
vivek mehta2b0e5a62016-09-02 17:31:58 -07001025 snd_card_num = 0;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001026 usleep(RETRY_US);
vivek mehta2b0e5a62016-09-02 17:31:58 -07001027 continue;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001028 }
1029
vivek mehta2b0e5a62016-09-02 17:31:58 -07001030 if (card_verifed[snd_card_num]) {
1031 ++snd_card_num;
1032 continue;
1033 }
1034
1035 adev->mixer = mixer_open(snd_card_num);
1036
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001037 if (!adev->mixer) {
1038 ALOGE("%s: Unable to open the mixer card: %d", __func__,
vivek mehta2b0e5a62016-09-02 17:31:58 -07001039 snd_card_num);
1040 ++snd_card_num;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001041 continue;
1042 }
1043
vivek mehta2b0e5a62016-09-02 17:31:58 -07001044 card_verifed[snd_card_num] = true;
1045
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001046 snd_card_name = mixer_get_name(adev->mixer);
vivek mehtade4849c2016-03-03 17:23:38 -08001047 my_data->hw_info = hw_info_init(snd_card_name);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001048
vivek mehtade4849c2016-03-03 17:23:38 -08001049 audio_extn_set_snd_card_split(snd_card_name);
1050 snd_split_handle = audio_extn_get_snd_card_split();
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001051
vivek mehtade4849c2016-03-03 17:23:38 -08001052 /* Get the codec internal name from the sound card and/or form factor
1053 * name and form the mixer paths and platfor info file name dynamically.
1054 * This is generic way of picking any codec and forma factor name based
1055 * mixer and platform info files in future with no code change.
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001056
vivek mehtade4849c2016-03-03 17:23:38 -08001057 * current code extends and looks for any of the exteneded mixer path and
1058 * platform info file present based on codec and form factor.
vivek mehta60ea4152016-02-18 17:10:26 -08001059
vivek mehtade4849c2016-03-03 17:23:38 -08001060 * order of picking appropriate file is
1061 * <i> mixer_paths_<codec_name>_<form_factor>.xml, if file not present
1062 * <ii> mixer_paths_<codec_name>.xml, if file not present
1063 * <iii> mixer_paths.xml
1064
1065 * same order is followed for audio_platform_info.xml as well
1066 */
1067
1068 // need to carryforward old file name
1069 if (!strncmp(snd_card_name, TOMTOM_8226_SND_CARD_NAME,
Eric Laurentf9583c32016-03-28 13:50:50 -07001070 min(strlen(TOMTOM_8226_SND_CARD_NAME), strlen(snd_card_name)))) {
vivek mehtade4849c2016-03-03 17:23:38 -08001071 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
vivek mehta60ea4152016-02-18 17:10:26 -08001072 MIXER_XML_BASE_STRING, TOMTOM_MIXER_FILE_SUFFIX );
vivek mehtade4849c2016-03-03 17:23:38 -08001073 } else {
Ed Tamb0b0d572016-03-21 10:45:37 -07001074
vivek mehtade4849c2016-03-03 17:23:38 -08001075 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s_%s.xml",
1076 MIXER_XML_BASE_STRING, snd_split_handle->snd_card,
1077 snd_split_handle->form_factor);
1078
1079 if (F_OK != access(mixer_xml_file, 0)) {
1080 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1081 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1082 MIXER_XML_BASE_STRING, snd_split_handle->snd_card);
1083
1084 if (F_OK != access(mixer_xml_file, 0)) {
1085 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1086 strlcpy(mixer_xml_file, MIXER_XML_DEFAULT_PATH, MIXER_PATH_MAX_LENGTH);
1087 }
1088 }
1089
1090 snprintf(platform_info_file, sizeof(platform_info_file), "%s_%s_%s.xml",
1091 PLATFORM_INFO_XML_BASE_STRING, snd_split_handle->snd_card,
1092 snd_split_handle->form_factor);
1093
1094 if (F_OK != access(platform_info_file, 0)) {
1095 memset(platform_info_file, 0, sizeof(platform_info_file));
1096 snprintf(platform_info_file, sizeof(platform_info_file), "%s_%s.xml",
1097 PLATFORM_INFO_XML_BASE_STRING, snd_split_handle->snd_card);
1098
1099 if (F_OK != access(platform_info_file, 0)) {
1100 memset(platform_info_file, 0, sizeof(platform_info_file));
1101 strlcpy(platform_info_file, PLATFORM_INFO_XML_PATH, MIXER_PATH_MAX_LENGTH);
vivek mehta60ea4152016-02-18 17:10:26 -08001102 }
1103 }
Uday Kishore Pasupuleti11dd2232015-06-24 14:18:01 -07001104 }
1105
vivek mehtade4849c2016-03-03 17:23:38 -08001106 /* Initialize platform specific ids and/or backends*/
1107 platform_info_init(platform_info_file, my_data);
1108
1109 /* validate the sound card name
1110 * my_data->snd_card_name can contain
1111 * <a> complete sound card name, i.e. <device>-<codec>-<form_factor>-snd-card
1112 * example: msm8994-tomtom-mtp-snd-card
1113 * <b> or sub string of the card name, i.e. <device>-<codec>
1114 * example: msm8994-tomtom
Eric Laurentf9583c32016-03-28 13:50:50 -07001115 * snd_card_name is truncated to 32 charaters as per mixer_get_name() implementation
1116 * so use min of my_data->snd_card_name and snd_card_name length for comparison
vivek mehtade4849c2016-03-03 17:23:38 -08001117 */
1118
1119 if (my_data->snd_card_name != NULL &&
Eric Laurentf9583c32016-03-28 13:50:50 -07001120 strncmp(snd_card_name, my_data->snd_card_name,
1121 min(strlen(snd_card_name), strlen(my_data->snd_card_name))) != 0) {
vivek mehtade4849c2016-03-03 17:23:38 -08001122 ALOGI("%s: found valid sound card %s, but not primary sound card %s",
1123 __func__, snd_card_name, my_data->snd_card_name);
vivek mehta2b0e5a62016-09-02 17:31:58 -07001124 ++snd_card_num;
1125 mixer_close(adev->mixer);
1126 adev->mixer = NULL;
vivek mehtade4849c2016-03-03 17:23:38 -08001127 hw_info_deinit(my_data->hw_info);
1128 my_data->hw_info = NULL;
1129 continue;
Ed Tam70b5c142016-03-21 19:14:29 -07001130 }
vivek mehtade4849c2016-03-03 17:23:38 -08001131 ALOGI("%s: found sound card %s, primary sound card expeted is %s",
1132 __func__, snd_card_name, my_data->snd_card_name);
vivek mehta60ea4152016-02-18 17:10:26 -08001133
1134 ALOGD("%s: Loading mixer file: %s", __func__, mixer_xml_file);
1135 adev->audio_route = audio_route_init(snd_card_num, mixer_xml_file);
1136
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001137 if (!adev->audio_route) {
1138 ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
vivek mehta2b0e5a62016-09-02 17:31:58 -07001139 mixer_close(adev->mixer);
1140 adev->mixer = NULL;
1141 hw_info_deinit(my_data->hw_info);
1142 my_data->hw_info = NULL;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001143 goto init_failed;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001144 }
1145 adev->snd_card = snd_card_num;
Eric Laurent2bafff12016-03-17 12:17:23 -07001146 ALOGD("%s: Opened sound card:%d", __func__, snd_card_num);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001147 break;
sangwoo1b9f4b32013-06-21 18:22:55 -07001148 }
1149
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09001150 //set max volume step for voice call
1151 property_get("ro.config.vc_call_vol_steps", value, TOSTRING(MAX_VOL_INDEX));
1152 my_data->max_vol_index = atoi(value);
1153
vivek mehta65ad12d2015-08-13 18:32:48 -07001154 property_get("persist.audio.dualmic.config",value,"");
1155 if (!strcmp("endfire", value)) {
1156 dual_mic_config = true;
1157 }
1158
Prashant Malanic92c5962015-08-11 15:10:18 -07001159 my_data->source_mic_type = SOURCE_DUAL_MIC;
1160
Eric Laurentb23d5282013-05-14 15:27:20 -07001161 my_data->fluence_in_spkr_mode = false;
1162 my_data->fluence_in_voice_call = false;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001163 my_data->fluence_in_voice_comm = false;
Eric Laurentb23d5282013-05-14 15:27:20 -07001164 my_data->fluence_in_voice_rec = false;
1165
vivek mehta65ad12d2015-08-13 18:32:48 -07001166 property_get("ro.qc.sdk.audio.fluencetype", value, "none");
Prashant Malanic92c5962015-08-11 15:10:18 -07001167 if (!strcmp("fluencepro", value)) {
1168 my_data->fluence_type = FLUENCE_PRO_ENABLE;
vivek mehta65ad12d2015-08-13 18:32:48 -07001169 } else if (!strcmp("fluence", value) || (dual_mic_config)) {
Prashant Malanic92c5962015-08-11 15:10:18 -07001170 my_data->fluence_type = FLUENCE_ENABLE;
1171 } else if (!strcmp("none", value)) {
1172 my_data->fluence_type = FLUENCE_DISABLE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001173 }
1174
Prashant Malanic92c5962015-08-11 15:10:18 -07001175 if (my_data->fluence_type != FLUENCE_DISABLE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001176 property_get("persist.audio.fluence.voicecall",value,"");
1177 if (!strcmp("true", value)) {
1178 my_data->fluence_in_voice_call = true;
1179 }
1180
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001181 property_get("persist.audio.fluence.voicecomm",value,"");
1182 if (!strcmp("true", value)) {
1183 my_data->fluence_in_voice_comm = true;
1184 }
1185
Eric Laurentb23d5282013-05-14 15:27:20 -07001186 property_get("persist.audio.fluence.voicerec",value,"");
1187 if (!strcmp("true", value)) {
1188 my_data->fluence_in_voice_rec = true;
1189 }
1190
1191 property_get("persist.audio.fluence.speaker",value,"");
1192 if (!strcmp("true", value)) {
1193 my_data->fluence_in_spkr_mode = true;
1194 }
1195 }
1196
Prashant Malanic92c5962015-08-11 15:10:18 -07001197 // support max to mono, example if max count is 3, usecase supports Three, dual and mono mic
1198 switch (my_data->max_mic_count) {
1199 case 4:
1200 my_data->source_mic_type |= SOURCE_QUAD_MIC;
1201 case 3:
1202 my_data->source_mic_type |= SOURCE_THREE_MIC;
1203 case 2:
1204 my_data->source_mic_type |= SOURCE_DUAL_MIC;
1205 case 1:
1206 my_data->source_mic_type |= SOURCE_MONO_MIC;
1207 break;
1208 default:
1209 ALOGE("%s: max_mic_count (%d), is not supported, setting to default",
1210 __func__, my_data->max_mic_count);
1211 my_data->source_mic_type = SOURCE_MONO_MIC|SOURCE_DUAL_MIC;
1212 break;
1213 }
1214
1215 ALOGV("%s: Fluence_Type(%d) max_mic_count(%d) mic_type(0x%x) fluence_in_voice_call(%d)"
1216 " fluence_in_voice_comm(%d) fluence_in_voice_rec(%d) fluence_in_spkr_mode(%d) ",
1217 __func__, my_data->fluence_type, my_data->max_mic_count, my_data->source_mic_type,
1218 my_data->fluence_in_voice_call, my_data->fluence_in_voice_comm,
1219 my_data->fluence_in_voice_rec, my_data->fluence_in_spkr_mode);
1220
Eric Laurentb23d5282013-05-14 15:27:20 -07001221 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
1222 if (my_data->acdb_handle == NULL) {
1223 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
1224 } else {
1225 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
1226 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
1227 "acdb_loader_deallocate_ACDB");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001228 if (!my_data->acdb_deallocate)
1229 ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s",
1230 __func__, LIB_ACDB_LOADER);
1231
Eric Laurentb23d5282013-05-14 15:27:20 -07001232 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
1233 "acdb_loader_send_audio_cal");
1234 if (!my_data->acdb_send_audio_cal)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001235 ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s",
Eric Laurentb23d5282013-05-14 15:27:20 -07001236 __func__, LIB_ACDB_LOADER);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001237
Eric Laurentb23d5282013-05-14 15:27:20 -07001238 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
1239 "acdb_loader_send_voice_cal");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001240 if (!my_data->acdb_send_voice_cal)
1241 ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s",
1242 __func__, LIB_ACDB_LOADER);
1243
1244 my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle,
1245 "acdb_loader_reload_vocvoltable");
1246 if (!my_data->acdb_reload_vocvoltable)
1247 ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s",
1248 __func__, LIB_ACDB_LOADER);
vivek mehta1a9b7c02015-06-25 11:49:38 -07001249
1250 my_data->acdb_send_gain_dep_cal = (acdb_send_gain_dep_cal_t)dlsym(my_data->acdb_handle,
1251 "acdb_loader_send_gain_dep_cal");
1252 if (!my_data->acdb_send_gain_dep_cal)
1253 ALOGV("%s: Could not find the symbol acdb_loader_send_gain_dep_cal from %s",
1254 __func__, LIB_ACDB_LOADER);
1255
Thierry Strudel92232b42017-01-26 10:51:48 -08001256#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998)
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001257 acdb_init_v2_cvd_t acdb_init;
1258 acdb_init = (acdb_init_v2_cvd_t)dlsym(my_data->acdb_handle,
1259 "acdb_loader_init_v2");
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001260 if (acdb_init == NULL)
1261 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1262 dlerror());
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001263
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001264#elif defined (PLATFORM_MSM8084)
1265 acdb_init_v2_t acdb_init;
1266 acdb_init = (acdb_init_v2_t)dlsym(my_data->acdb_handle,
1267 "acdb_loader_init_v2");
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001268 if (acdb_init == NULL)
1269 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1270 dlerror());
1271
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001272#else
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001273 acdb_init_t acdb_init;
1274 acdb_init = (acdb_init_t)dlsym(my_data->acdb_handle,
Eric Laurentb23d5282013-05-14 15:27:20 -07001275 "acdb_loader_init_ACDB");
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001276 if (acdb_init == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001277 ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__,
1278 dlerror());
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001279#endif
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001280 my_data->acdb_init = acdb_init;
Eric Laurentb23d5282013-05-14 15:27:20 -07001281
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001282 my_data->acdb_send_custom_top = (acdb_send_custom_top_t)
1283 dlsym(my_data->acdb_handle,
1284 "acdb_loader_send_common_custom_topology");
1285
1286 if (!my_data->acdb_send_custom_top)
1287 ALOGE("%s: Could not find the symbol acdb_get_default_app_type from %s",
1288 __func__, LIB_ACDB_LOADER);
1289
1290 platform_acdb_init(my_data);
1291 }
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001292
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001293 audio_extn_spkr_prot_init(adev);
Haynes Mathew George98c95622014-06-20 19:14:25 -07001294
Ravi Kumar Alamanda76315572015-04-23 13:13:56 -07001295 audio_extn_hwdep_cal_send(adev->snd_card, my_data->acdb_handle);
1296
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001297 /* load csd client */
1298 platform_csd_init(my_data);
1299
Eric Laurentb23d5282013-05-14 15:27:20 -07001300 return my_data;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001301
1302init_failed:
1303 if (my_data)
1304 free(my_data);
1305 return NULL;
Eric Laurentb23d5282013-05-14 15:27:20 -07001306}
1307
1308void platform_deinit(void *platform)
1309{
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001310 int32_t dev;
keunhui.park2f7306a2015-07-16 16:48:06 +09001311 struct operator_info *info_item;
1312 struct operator_specific_device *device_item;
1313 struct listnode *node;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001314
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001315 struct platform_data *my_data = (struct platform_data *)platform;
1316 close_csd_client(my_data->csd);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001317
vivek mehtade4849c2016-03-03 17:23:38 -08001318 hw_info_deinit(my_data->hw_info);
1319
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001320 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1321 if (backend_tag_table[dev])
1322 free(backend_tag_table[dev]);
1323 if (hw_interface_table[dev])
1324 free(hw_interface_table[dev]);
keunhui.park2f7306a2015-07-16 16:48:06 +09001325 if (operator_specific_device_table[dev]) {
1326 while (!list_empty(operator_specific_device_table[dev])) {
1327 node = list_head(operator_specific_device_table[dev]);
1328 list_remove(node);
1329 device_item = node_to_item(node, struct operator_specific_device, list);
1330 free(device_item->operator);
1331 free(device_item->mixer_path);
1332 free(device_item);
1333 }
1334 free(operator_specific_device_table[dev]);
1335 }
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001336 }
1337
1338 if (my_data->snd_card_name)
1339 free(my_data->snd_card_name);
1340
keunhui.park2f7306a2015-07-16 16:48:06 +09001341 while (!list_empty(&operator_info_list)) {
1342 node = list_head(&operator_info_list);
1343 list_remove(node);
1344 info_item = node_to_item(node, struct operator_info, list);
1345 free(info_item->name);
1346 free(info_item->mccmnc);
1347 free(info_item);
1348 }
1349
Eric Laurentb23d5282013-05-14 15:27:20 -07001350 free(platform);
1351}
1352
1353const char *platform_get_snd_device_name(snd_device_t snd_device)
1354{
keunhui.park2f7306a2015-07-16 16:48:06 +09001355 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1356 if (operator_specific_device_table[snd_device] != NULL) {
1357 return get_operator_specific_device_mixer_path(snd_device);
1358 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001359 return device_table[snd_device];
keunhui.park2f7306a2015-07-16 16:48:06 +09001360 } else
Ravi Kumar Alamanda64026462014-09-15 00:08:58 -07001361 return "none";
Eric Laurentb23d5282013-05-14 15:27:20 -07001362}
1363
vivek mehtade4849c2016-03-03 17:23:38 -08001364int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
1365 char *device_name)
1366{
1367 struct platform_data *my_data = (struct platform_data *)platform;
1368
David Benjamin1565f992016-09-21 12:10:34 -04001369 if (platform == NULL) {
vivek mehtade4849c2016-03-03 17:23:38 -08001370 ALOGW("%s: something wrong, use legacy get_snd_device name", __func__);
David Benjamin1565f992016-09-21 12:10:34 -04001371 strlcpy(device_name, platform_get_snd_device_name(snd_device),
1372 DEVICE_NAME_MAX_SIZE);
vivek mehtade4849c2016-03-03 17:23:38 -08001373 } else if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1374 if (operator_specific_device_table[snd_device] != NULL) {
1375 strlcpy(device_name, get_operator_specific_device_mixer_path(snd_device),
1376 DEVICE_NAME_MAX_SIZE);
1377 } else {
1378 strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE);
1379 }
1380 hw_info_append_hw_type(my_data->hw_info, snd_device, device_name);
1381 } else {
1382 strlcpy(device_name, "none", DEVICE_NAME_MAX_SIZE);
1383 }
1384
1385 return 0;
1386}
1387
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001388void platform_add_backend_name(void *platform, char *mixer_path,
1389 snd_device_t snd_device)
Eric Laurentb23d5282013-05-14 15:27:20 -07001390{
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001391 struct platform_data *my_data = (struct platform_data *)platform;
1392
Haynes Mathew George98c95622014-06-20 19:14:25 -07001393 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1394 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1395 return;
Ravi Kumar Alamanda1de6e5a2014-06-19 21:55:39 -05001396 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001397
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001398 const char * suffix = backend_tag_table[snd_device];
Haynes Mathew George98c95622014-06-20 19:14:25 -07001399
1400 if (suffix != NULL) {
1401 strcat(mixer_path, " ");
1402 strcat(mixer_path, suffix);
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001403 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001404}
1405
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001406bool platform_check_backends_match(snd_device_t snd_device1, snd_device_t snd_device2)
1407{
1408 bool result = true;
1409
1410 ALOGV("%s: snd_device1 = %s, snd_device2 = %s", __func__,
1411 platform_get_snd_device_name(snd_device1),
1412 platform_get_snd_device_name(snd_device2));
1413
1414 if ((snd_device1 < SND_DEVICE_MIN) || (snd_device1 >= SND_DEVICE_MAX)) {
1415 ALOGE("%s: Invalid snd_device = %s", __func__,
1416 platform_get_snd_device_name(snd_device1));
1417 return false;
1418 }
1419 if ((snd_device2 < SND_DEVICE_MIN) || (snd_device2 >= SND_DEVICE_MAX)) {
1420 ALOGE("%s: Invalid snd_device = %s", __func__,
1421 platform_get_snd_device_name(snd_device2));
1422 return false;
1423 }
1424 const char * be_itf1 = hw_interface_table[snd_device1];
1425 const char * be_itf2 = hw_interface_table[snd_device2];
1426
1427 if (NULL != be_itf1 && NULL != be_itf2) {
Eric Laurente63e61d2015-09-10 12:19:33 -07001428 if ((NULL == strstr(be_itf2, be_itf1)) && (NULL == strstr(be_itf1, be_itf2)))
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001429 result = false;
1430 }
1431
1432 ALOGV("%s: be_itf1 = %s, be_itf2 = %s, match %d", __func__, be_itf1, be_itf2, result);
1433 return result;
1434}
1435
Eric Laurentb23d5282013-05-14 15:27:20 -07001436int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
1437{
1438 int device_id;
1439 if (device_type == PCM_PLAYBACK)
1440 device_id = pcm_device_table[usecase][0];
1441 else
1442 device_id = pcm_device_table[usecase][1];
1443 return device_id;
1444}
1445
Haynes Mathew George98c95622014-06-20 19:14:25 -07001446static int find_index(const struct name_to_index * table, int32_t len,
1447 const char * name)
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001448{
1449 int ret = 0;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001450 int32_t i;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001451
Haynes Mathew George98c95622014-06-20 19:14:25 -07001452 if (table == NULL) {
1453 ALOGE("%s: table is NULL", __func__);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001454 ret = -ENODEV;
1455 goto done;
1456 }
1457
Haynes Mathew George98c95622014-06-20 19:14:25 -07001458 if (name == NULL) {
1459 ALOGE("null key");
1460 ret = -ENODEV;
1461 goto done;
1462 }
1463
1464 for (i=0; i < len; i++) {
1465 if (!strcmp(table[i].name, name)) {
1466 ret = table[i].index;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001467 goto done;
1468 }
1469 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001470 ALOGE("%s: Could not find index for name = %s",
1471 __func__, name);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001472 ret = -ENODEV;
1473done:
1474 return ret;
1475}
1476
Haynes Mathew George98c95622014-06-20 19:14:25 -07001477int platform_get_snd_device_index(char *device_name)
1478{
1479 return find_index(snd_device_name_index, SND_DEVICE_MAX, device_name);
1480}
1481
1482int platform_get_usecase_index(const char *usecase_name)
1483{
1484 return find_index(usecase_name_index, AUDIO_USECASE_MAX, usecase_name);
1485}
1486
keunhui.park2f7306a2015-07-16 16:48:06 +09001487void platform_add_operator_specific_device(snd_device_t snd_device,
1488 const char *operator,
1489 const char *mixer_path,
1490 unsigned int acdb_id)
1491{
1492 struct operator_specific_device *device;
1493
1494 if (operator_specific_device_table[snd_device] == NULL) {
1495 operator_specific_device_table[snd_device] =
1496 (struct listnode *)calloc(1, sizeof(struct listnode));
1497 list_init(operator_specific_device_table[snd_device]);
1498 }
1499
1500 device = (struct operator_specific_device *)calloc(1, sizeof(struct operator_specific_device));
1501
1502 device->operator = strdup(operator);
1503 device->mixer_path = strdup(mixer_path);
1504 device->acdb_id = acdb_id;
1505
1506 list_add_tail(operator_specific_device_table[snd_device], &device->list);
1507
Eric Laurent2bafff12016-03-17 12:17:23 -07001508 ALOGD("%s: device[%s] -> operator[%s] mixer_path[%s] acdb_id[%d]", __func__,
keunhui.park2f7306a2015-07-16 16:48:06 +09001509 platform_get_snd_device_name(snd_device), operator, mixer_path, acdb_id);
1510
1511}
1512
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001513int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
1514{
1515 int ret = 0;
1516
1517 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1518 ALOGE("%s: Invalid snd_device = %d",
1519 __func__, snd_device);
1520 ret = -EINVAL;
1521 goto done;
1522 }
1523
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001524 ALOGV("%s: acdb_device_table[%s]: old = %d new = %d", __func__,
1525 platform_get_snd_device_name(snd_device), acdb_device_table[snd_device], acdb_id);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001526 acdb_device_table[snd_device] = acdb_id;
1527done:
1528 return ret;
1529}
1530
Glenn Kastencbe06ca2016-11-09 10:49:26 -08001531int platform_get_default_app_type_v2(void *platform __unused, usecase_type_t type __unused,
1532 int *app_type __unused)
Yamit Mehtae3b99562016-09-16 22:44:00 +05301533{
1534 ALOGE("%s: Not implemented", __func__);
1535 return -ENOSYS;
1536}
1537
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001538int platform_get_snd_device_acdb_id(snd_device_t snd_device)
1539{
1540 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1541 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1542 return -EINVAL;
1543 }
keunhui.park2f7306a2015-07-16 16:48:06 +09001544
1545 if (operator_specific_device_table[snd_device] != NULL)
1546 return get_operator_specific_device_acdb_id(snd_device);
1547 else
1548 return acdb_device_table[snd_device];
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001549}
1550
Eric Laurentb23d5282013-05-14 15:27:20 -07001551int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
1552{
1553 struct platform_data *my_data = (struct platform_data *)platform;
1554 int acdb_dev_id, acdb_dev_type;
1555
Ravi Kumar Alamandaadf0f3b2015-06-04 02:34:02 -07001556 acdb_dev_id = acdb_device_table[audio_extn_get_spkr_prot_snd_device(snd_device)];
Eric Laurentb23d5282013-05-14 15:27:20 -07001557 if (acdb_dev_id < 0) {
1558 ALOGE("%s: Could not find acdb id for device(%d)",
1559 __func__, snd_device);
1560 return -EINVAL;
1561 }
1562 if (my_data->acdb_send_audio_cal) {
Joe Onorato188b6222016-03-01 11:02:27 -08001563 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Eric Laurentb23d5282013-05-14 15:27:20 -07001564 __func__, snd_device, acdb_dev_id);
1565 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
1566 snd_device < SND_DEVICE_OUT_END)
1567 acdb_dev_type = ACDB_DEV_TYPE_OUT;
1568 else
1569 acdb_dev_type = ACDB_DEV_TYPE_IN;
1570 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
1571 }
1572 return 0;
1573}
1574
1575int platform_switch_voice_call_device_pre(void *platform)
1576{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001577 struct platform_data *my_data = (struct platform_data *)platform;
1578 int ret = 0;
1579
1580 if (my_data->csd != NULL &&
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001581 voice_is_in_call(my_data->adev)) {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001582 /* This must be called before disabling mixer controls on APQ side */
1583 ret = my_data->csd->disable_device();
1584 if (ret < 0) {
1585 ALOGE("%s: csd_client_disable_device, failed, error %d",
1586 __func__, ret);
1587 }
1588 }
1589 return ret;
1590}
1591
1592int platform_switch_voice_call_enable_device_config(void *platform,
1593 snd_device_t out_snd_device,
1594 snd_device_t in_snd_device)
1595{
1596 struct platform_data *my_data = (struct platform_data *)platform;
1597 int acdb_rx_id, acdb_tx_id;
1598 int ret = 0;
1599
1600 if (my_data->csd == NULL)
1601 return ret;
1602
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001603 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1604 audio_extn_spkr_prot_is_enabled())
keunhui.park2f7306a2015-07-16 16:48:06 +09001605 acdb_rx_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_SPEAKER_PROTECTED);
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001606 else
keunhui.park2f7306a2015-07-16 16:48:06 +09001607 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001608
keunhui.park2f7306a2015-07-16 16:48:06 +09001609 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001610
1611 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
1612 ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
1613 if (ret < 0) {
1614 ALOGE("%s: csd_enable_device_config, failed, error %d",
1615 __func__, ret);
1616 }
1617 } else {
1618 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1619 acdb_rx_id, acdb_tx_id);
1620 }
1621
1622 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001623}
1624
1625int platform_switch_voice_call_device_post(void *platform,
1626 snd_device_t out_snd_device,
1627 snd_device_t in_snd_device)
1628{
1629 struct platform_data *my_data = (struct platform_data *)platform;
1630 int acdb_rx_id, acdb_tx_id;
1631
1632 if (my_data->acdb_send_voice_cal == NULL) {
1633 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
1634 } else {
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001635 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1636 audio_extn_spkr_prot_is_enabled())
1637 out_snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED;
1638
keunhui.park2f7306a2015-07-16 16:48:06 +09001639 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
1640 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07001641
1642 if (acdb_rx_id > 0 && acdb_tx_id > 0)
1643 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
1644 else
1645 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1646 acdb_rx_id, acdb_tx_id);
1647 }
1648
1649 return 0;
1650}
1651
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001652int platform_switch_voice_call_usecase_route_post(void *platform,
1653 snd_device_t out_snd_device,
1654 snd_device_t in_snd_device)
1655{
1656 struct platform_data *my_data = (struct platform_data *)platform;
1657 int acdb_rx_id, acdb_tx_id;
1658 int ret = 0;
1659
1660 if (my_data->csd == NULL)
1661 return ret;
1662
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001663 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1664 audio_extn_spkr_prot_is_enabled())
keunhui.park2f7306a2015-07-16 16:48:06 +09001665 acdb_rx_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED);
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001666 else
keunhui.park2f7306a2015-07-16 16:48:06 +09001667 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001668
keunhui.park2f7306a2015-07-16 16:48:06 +09001669 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001670
1671 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
1672 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
1673 my_data->adev->acdb_settings);
1674 if (ret < 0) {
1675 ALOGE("%s: csd_enable_device, failed, error %d", __func__, ret);
1676 }
1677 } else {
1678 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1679 acdb_rx_id, acdb_tx_id);
1680 }
1681
1682 return ret;
1683}
1684
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001685int platform_start_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07001686{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001687 struct platform_data *my_data = (struct platform_data *)platform;
1688 int ret = 0;
1689
1690 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001691 ret = my_data->csd->start_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001692 if (ret < 0) {
1693 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
1694 }
1695 }
1696 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001697}
1698
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001699int platform_stop_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07001700{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001701 struct platform_data *my_data = (struct platform_data *)platform;
1702 int ret = 0;
1703
1704 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001705 ret = my_data->csd->stop_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001706 if (ret < 0) {
1707 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
1708 }
1709 }
1710 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001711}
1712
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001713int platform_get_sample_rate(void *platform, uint32_t *rate)
1714{
1715 struct platform_data *my_data = (struct platform_data *)platform;
1716 int ret = 0;
1717
1718 if (my_data->csd != NULL) {
1719 ret = my_data->csd->get_sample_rate(rate);
1720 if (ret < 0) {
1721 ALOGE("%s: csd_get_sample_rate error %d\n", __func__, ret);
1722 }
1723 }
1724 return ret;
1725}
1726
vivek mehtab6506412015-08-07 16:55:17 -07001727void platform_set_speaker_gain_in_combo(struct audio_device *adev,
1728 snd_device_t snd_device,
1729 bool enable)
1730{
1731 const char* name;
1732 switch (snd_device) {
1733 case SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES:
1734 if (enable)
1735 name = "spkr-gain-in-headphone-combo";
1736 else
1737 name = "speaker-gain-default";
1738 break;
1739 case SND_DEVICE_OUT_SPEAKER_AND_LINE:
1740 if (enable)
1741 name = "spkr-gain-in-line-combo";
1742 else
1743 name = "speaker-gain-default";
1744 break;
1745 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES:
1746 if (enable)
1747 name = "spkr-safe-gain-in-headphone-combo";
1748 else
1749 name = "speaker-safe-gain-default";
1750 break;
1751 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE:
1752 if (enable)
1753 name = "spkr-safe-gain-in-line-combo";
1754 else
1755 name = "speaker-safe-gain-default";
1756 break;
1757 default:
1758 return;
1759 }
1760
1761 audio_route_apply_and_update_path(adev->audio_route, name);
1762}
1763
Eric Laurentb23d5282013-05-14 15:27:20 -07001764int platform_set_voice_volume(void *platform, int volume)
1765{
1766 struct platform_data *my_data = (struct platform_data *)platform;
1767 struct audio_device *adev = my_data->adev;
1768 struct mixer_ctl *ctl;
sangwoo53b2cf02013-07-25 19:18:44 -07001769 const char *mixer_ctl_name = "Voice Rx Gain";
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001770 int vol_index = 0, ret = 0;
1771 uint32_t set_values[ ] = {0,
1772 ALL_SESSION_VSID,
1773 DEFAULT_VOLUME_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07001774
1775 // Voice volume levels are mapped to adsp volume levels as follows.
1776 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
1777 // But this values don't changed in kernel. So, below change is need.
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09001778 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, my_data->max_vol_index);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001779 set_values[0] = vol_index;
Eric Laurentb23d5282013-05-14 15:27:20 -07001780
1781 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1782 if (!ctl) {
1783 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1784 __func__, mixer_ctl_name);
1785 return -EINVAL;
1786 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001787 ALOGV("Setting voice volume index: %d", set_values[0]);
1788 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1789
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001790 if (my_data->csd != NULL) {
1791 ret = my_data->csd->volume(ALL_SESSION_VSID, volume,
1792 DEFAULT_VOLUME_RAMP_DURATION_MS);
1793 if (ret < 0) {
1794 ALOGE("%s: csd_volume error %d", __func__, ret);
1795 }
1796 }
1797 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001798}
1799
1800int platform_set_mic_mute(void *platform, bool state)
1801{
1802 struct platform_data *my_data = (struct platform_data *)platform;
1803 struct audio_device *adev = my_data->adev;
1804 struct mixer_ctl *ctl;
1805 const char *mixer_ctl_name = "Voice Tx Mute";
sangwoo53b2cf02013-07-25 19:18:44 -07001806 int ret = 0;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001807 uint32_t set_values[ ] = {0,
1808 ALL_SESSION_VSID,
1809 DEFAULT_MUTE_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07001810
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09001811 if (adev->mode != AUDIO_MODE_IN_CALL &&
1812 adev->mode != AUDIO_MODE_IN_COMMUNICATION)
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001813 return 0;
1814
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09001815 if (adev->enable_hfp)
1816 mixer_ctl_name = "HFP Tx Mute";
1817
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001818 set_values[0] = state;
1819 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1820 if (!ctl) {
1821 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1822 __func__, mixer_ctl_name);
1823 return -EINVAL;
1824 }
1825 ALOGV("Setting voice mute state: %d", state);
1826 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1827
1828 if (my_data->csd != NULL) {
1829 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state,
1830 DEFAULT_MUTE_RAMP_DURATION_MS);
sangwoo53b2cf02013-07-25 19:18:44 -07001831 if (ret < 0) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001832 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
sangwoo53b2cf02013-07-25 19:18:44 -07001833 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001834 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001835 return ret;
1836}
Eric Laurentb23d5282013-05-14 15:27:20 -07001837
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001838int platform_set_device_mute(void *platform, bool state, char *dir)
1839{
1840 struct platform_data *my_data = (struct platform_data *)platform;
1841 struct audio_device *adev = my_data->adev;
1842 struct mixer_ctl *ctl;
1843 char *mixer_ctl_name = NULL;
1844 int ret = 0;
1845 uint32_t set_values[ ] = {0,
1846 ALL_SESSION_VSID,
1847 0};
1848 if(dir == NULL) {
1849 ALOGE("%s: Invalid direction:%s", __func__, dir);
1850 return -EINVAL;
1851 }
1852
1853 if (!strncmp("rx", dir, sizeof("rx"))) {
1854 mixer_ctl_name = "Voice Rx Device Mute";
1855 } else if (!strncmp("tx", dir, sizeof("tx"))) {
1856 mixer_ctl_name = "Voice Tx Device Mute";
1857 } else {
1858 return -EINVAL;
1859 }
1860
1861 set_values[0] = state;
1862 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1863 if (!ctl) {
1864 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1865 __func__, mixer_ctl_name);
1866 return -EINVAL;
1867 }
1868
1869 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
1870 __func__,state, mixer_ctl_name);
1871 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1872
1873 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001874}
1875
Haynes Mathew George2d809e02016-09-22 17:38:16 -07001876int platform_can_split_snd_device(snd_device_t snd_device,
1877 int *num_devices,
1878 snd_device_t *new_snd_devices)
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001879{
Haynes Mathew George2d809e02016-09-22 17:38:16 -07001880 int ret = -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001881 if (NULL == num_devices || NULL == new_snd_devices) {
1882 ALOGE("%s: NULL pointer ..", __func__);
Haynes Mathew George2d809e02016-09-22 17:38:16 -07001883 return -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001884 }
1885
1886 /*
1887 * If wired headset/headphones/line devices share the same backend
Haynes Mathew George2d809e02016-09-22 17:38:16 -07001888 * with speaker/earpiece this routine returns -EINVAL.
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001889 */
1890 if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES &&
1891 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_HEADPHONES)) {
1892 *num_devices = 2;
1893 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
1894 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07001895 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001896 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_LINE &&
1897 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_LINE)) {
1898 *num_devices = 2;
1899 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
1900 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07001901 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001902 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES &&
1903 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_HEADPHONES)) {
1904 *num_devices = 2;
1905 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
1906 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07001907 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001908 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE &&
1909 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_LINE)) {
1910 *num_devices = 2;
1911 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
1912 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07001913 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001914 }
Haynes Mathew George2d809e02016-09-22 17:38:16 -07001915 return ret;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001916}
1917
Eric Laurentb23d5282013-05-14 15:27:20 -07001918snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
1919{
1920 struct platform_data *my_data = (struct platform_data *)platform;
1921 struct audio_device *adev = my_data->adev;
1922 audio_mode_t mode = adev->mode;
1923 snd_device_t snd_device = SND_DEVICE_NONE;
1924
1925 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
1926 if (devices == AUDIO_DEVICE_NONE ||
1927 devices & AUDIO_DEVICE_BIT_IN) {
1928 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
1929 goto exit;
1930 }
1931
Eric Laurent1b491552015-09-15 17:52:41 -07001932 if (popcount(devices) == 2) {
1933 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
1934 AUDIO_DEVICE_OUT_SPEAKER) ||
1935 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
1936 AUDIO_DEVICE_OUT_SPEAKER)) {
1937 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
1938 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
1939 AUDIO_DEVICE_OUT_SPEAKER)) {
1940 snd_device = SND_DEVICE_OUT_SPEAKER_AND_LINE;
1941 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
1942 AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
1943 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
1944 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
1945 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES;
1946 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
1947 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
1948 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE;
1949 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
1950 AUDIO_DEVICE_OUT_SPEAKER)) {
1951 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
1952 } else {
1953 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
1954 goto exit;
1955 }
1956 if (snd_device != SND_DEVICE_NONE) {
1957 goto exit;
1958 }
1959 }
1960
1961 if (popcount(devices) != 1) {
1962 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
1963 goto exit;
1964 }
1965
Madhuri Athota3f6051b2016-10-13 23:25:38 +05301966 if (voice_is_in_call(adev) || adev->enable_voicerx || audio_extn_hfp_is_active(adev)) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001967 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05001968 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
1969 devices & AUDIO_DEVICE_OUT_LINE) {
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001970 if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05001971 (adev->voice.tty_mode == TTY_MODE_FULL))
Eric Laurentb23d5282013-05-14 15:27:20 -07001972 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001973 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05001974 (adev->voice.tty_mode == TTY_MODE_VCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07001975 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001976 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05001977 (adev->voice.tty_mode == TTY_MODE_HCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07001978 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05001979 else {
1980 if (devices & AUDIO_DEVICE_OUT_LINE)
1981 snd_device = SND_DEVICE_OUT_VOICE_LINE;
1982 else
1983 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
1984 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001985 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07001986 if (adev->bt_wb_speech_enabled) {
1987 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
1988 } else {
1989 snd_device = SND_DEVICE_OUT_BT_SCO;
1990 }
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07001991 } else if (devices & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07001992 if (!adev->enable_hfp) {
1993 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
1994 } else {
1995 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_HFP;
1996 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001997 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05001998 if(adev->voice.hac)
1999 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2000 else if (is_operator_tmus())
Eric Laurentb23d5282013-05-14 15:27:20 -07002001 snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS;
2002 else
Eric Laurentb4d368e2014-06-25 10:21:54 -05002003 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002004 } else if (devices & AUDIO_DEVICE_OUT_TELEPHONY_TX)
2005 snd_device = SND_DEVICE_OUT_VOICE_TX;
2006
Eric Laurentb23d5282013-05-14 15:27:20 -07002007 if (snd_device != SND_DEVICE_NONE) {
2008 goto exit;
2009 }
2010 }
2011
Eric Laurentb23d5282013-05-14 15:27:20 -07002012 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2013 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2014 snd_device = SND_DEVICE_OUT_HEADPHONES;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002015 } else if (devices & AUDIO_DEVICE_OUT_LINE) {
2016 snd_device = SND_DEVICE_OUT_LINE;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002017 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) {
2018 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE;
Eric Laurentb23d5282013-05-14 15:27:20 -07002019 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002020 if (my_data->speaker_lr_swap)
Eric Laurentb23d5282013-05-14 15:27:20 -07002021 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
2022 else
2023 snd_device = SND_DEVICE_OUT_SPEAKER;
2024 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002025 if (adev->bt_wb_speech_enabled) {
2026 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2027 } else {
2028 snd_device = SND_DEVICE_OUT_BT_SCO;
2029 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002030 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2031 snd_device = SND_DEVICE_OUT_HDMI ;
2032 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002033 /*HAC support for voice-ish audio (eg visual voicemail)*/
2034 if(adev->voice.hac)
2035 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2036 else
2037 snd_device = SND_DEVICE_OUT_HANDSET;
Eric Laurentb23d5282013-05-14 15:27:20 -07002038 } else {
2039 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
2040 }
2041exit:
2042 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
2043 return snd_device;
2044}
2045
2046snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
2047{
2048 struct platform_data *my_data = (struct platform_data *)platform;
2049 struct audio_device *adev = my_data->adev;
2050 audio_source_t source = (adev->active_input == NULL) ?
2051 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
2052
2053 audio_mode_t mode = adev->mode;
2054 audio_devices_t in_device = ((adev->active_input == NULL) ?
2055 AUDIO_DEVICE_NONE : adev->active_input->device)
2056 & ~AUDIO_DEVICE_BIT_IN;
2057 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
2058 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
2059 snd_device_t snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002060 int channel_count = popcount(channel_mask);
Eric Laurentb23d5282013-05-14 15:27:20 -07002061
Prashant Malanic92c5962015-08-11 15:10:18 -07002062 ALOGV("%s: enter: out_device(%#x) in_device(%#x) channel_count (%d) channel_mask (0x%x)",
2063 __func__, out_device, in_device, channel_count, channel_mask);
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002064 if ((out_device != AUDIO_DEVICE_NONE) && voice_is_in_call(adev)) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002065 if (adev->voice.tty_mode != TTY_MODE_OFF) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002066 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002067 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2068 out_device & AUDIO_DEVICE_OUT_LINE) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002069 switch (adev->voice.tty_mode) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002070 case TTY_MODE_FULL:
2071 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
2072 break;
2073 case TTY_MODE_VCO:
2074 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
2075 break;
2076 case TTY_MODE_HCO:
2077 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
2078 break;
2079 default:
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002080 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
Eric Laurentb23d5282013-05-14 15:27:20 -07002081 }
2082 goto exit;
2083 }
2084 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002085 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002086 if (my_data->fluence_in_voice_call == false) {
2087 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2088 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002089 if (is_operator_tmus())
2090 snd_device = SND_DEVICE_IN_VOICE_DMIC_TMUS;
Eric Laurentb23d5282013-05-14 15:27:20 -07002091 else
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002092 snd_device = SND_DEVICE_IN_VOICE_DMIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002093 }
2094 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2095 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
2096 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002097 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002098 if (adev->bluetooth_nrec)
2099 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2100 else
2101 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002102 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002103 if (adev->bluetooth_nrec)
2104 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2105 else
2106 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002107 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002108 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Prashant Malanic92c5962015-08-11 15:10:18 -07002109 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
2110 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2111 out_device & AUDIO_DEVICE_OUT_LINE) {
2112 if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
2113 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
2114 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
2115 } else {
2116 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2117 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002118 }
vivek mehtafe121d52015-08-10 23:39:23 -07002119
2120 //select default
2121 if (snd_device == SND_DEVICE_NONE) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002122 if (!adev->enable_hfp) {
2123 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2124 } else {
2125 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP;
2126 platform_set_echo_reference(adev, true, out_device);
2127 }
vivek mehtafe121d52015-08-10 23:39:23 -07002128 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002129 } else if (out_device & AUDIO_DEVICE_OUT_TELEPHONY_TX) {
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002130 snd_device = SND_DEVICE_IN_VOICE_RX;
Prashant Malanic92c5962015-08-11 15:10:18 -07002131 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002132 } else if (source == AUDIO_SOURCE_CAMCORDER) {
2133 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
2134 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2135 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
2136 }
2137 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
2138 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002139 if (my_data->fluence_in_voice_rec && channel_count == 1) {
2140 if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2141 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002142 if (adev->active_input->enable_aec)
2143 snd_device = SND_DEVICE_IN_HANDSET_QMIC_AEC;
2144 else
2145 snd_device = SND_DEVICE_IN_HANDSET_QMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002146 } else if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2147 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002148 if (adev->active_input->enable_aec)
2149 snd_device = SND_DEVICE_IN_HANDSET_TMIC_AEC;
2150 else
2151 snd_device = SND_DEVICE_IN_HANDSET_TMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002152 } else if (((my_data->fluence_type == FLUENCE_PRO_ENABLE) ||
2153 (my_data->fluence_type == FLUENCE_ENABLE)) &&
2154 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002155 if (adev->active_input->enable_aec)
2156 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
2157 else
2158 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
Prashant Malanic92c5962015-08-11 15:10:18 -07002159 }
2160 platform_set_echo_reference(adev, true, out_device);
2161 } else if ((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) &&
2162 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2163 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002164 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002165 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
2166 snd_device = SND_DEVICE_IN_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002167 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002168 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2169 snd_device = SND_DEVICE_IN_QUAD_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002170 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002171 if (snd_device == SND_DEVICE_NONE) {
vivek mehtaf3440682016-05-11 14:24:37 -07002172 if (adev->active_input->enable_aec) {
2173 if (adev->active_input->enable_ns) {
2174 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS;
2175 } else {
2176 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC;
2177 }
vivek mehta733c1df2016-04-04 15:09:24 -07002178 platform_set_echo_reference(adev, true, out_device);
vivek mehtaf3440682016-05-11 14:24:37 -07002179 } else if (adev->active_input->enable_ns) {
2180 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
2181 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002182 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
vivek mehtaf3440682016-05-11 14:24:37 -07002183 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002184 }
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -07002185 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2186 snd_device = SND_DEVICE_IN_VOICE_REC_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002187 }
rago90fb9612015-12-02 11:37:53 -08002188 } else if (source == AUDIO_SOURCE_UNPROCESSED) {
2189 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
vivek mehta4ed66e62016-04-15 23:33:34 -07002190 if (((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) ||
2191 (channel_mask == AUDIO_CHANNEL_IN_STEREO)) &&
2192 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2193 snd_device = SND_DEVICE_IN_UNPROCESSED_STEREO_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002194 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07002195 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
2196 snd_device = SND_DEVICE_IN_UNPROCESSED_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002197 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07002198 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2199 snd_device = SND_DEVICE_IN_UNPROCESSED_QUAD_MIC;
2200 } else {
2201 snd_device = SND_DEVICE_IN_UNPROCESSED_MIC;
2202 }
rago90fb9612015-12-02 11:37:53 -08002203 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2204 snd_device = SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC;
2205 }
Eric Laurent50a38ed2015-10-14 18:48:06 -07002206 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION ||
rago90fb9612015-12-02 11:37:53 -08002207 mode == AUDIO_MODE_IN_COMMUNICATION) {
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002208 if (out_device & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE))
Eric Laurentb23d5282013-05-14 15:27:20 -07002209 in_device = AUDIO_DEVICE_IN_BACK_MIC;
2210 if (adev->active_input) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002211 if (adev->active_input->enable_aec &&
2212 adev->active_input->enable_ns) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002213 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002214 if (my_data->fluence_in_spkr_mode &&
2215 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002216 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002217 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002218 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002219 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002220 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002221 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002222 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002223 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002224 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002225 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002226 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002227 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002228 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2229 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002230 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002231 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002232 } else if (adev->active_input->enable_aec) {
2233 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2234 if (my_data->fluence_in_spkr_mode &&
2235 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_SPEAKER_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002238 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002239 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002240 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002241 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2242 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002243 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002244 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002245 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002246 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002247 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002248 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2249 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
2250 }
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08002251 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002252 } else if (adev->active_input->enable_ns) {
2253 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2254 if (my_data->fluence_in_spkr_mode &&
2255 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_SPEAKER_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002258 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002259 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002260 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002261 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2262 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002263 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002264 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002265 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002266 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002267 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002268 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002269 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002270 }
2271 } else if (source == AUDIO_SOURCE_DEFAULT) {
2272 goto exit;
2273 }
2274
2275
2276 if (snd_device != SND_DEVICE_NONE) {
2277 goto exit;
2278 }
2279
2280 if (in_device != AUDIO_DEVICE_NONE &&
2281 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
2282 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
2283 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002284 if ((my_data->source_mic_type & SOURCE_QUAD_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002285 channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002286 snd_device = SND_DEVICE_IN_QUAD_MIC;
2287 } else if ((my_data->source_mic_type & SOURCE_THREE_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002288 channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002289 snd_device = SND_DEVICE_IN_THREE_MIC;
2290 } else if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2291 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002292 snd_device = SND_DEVICE_IN_HANDSET_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002293 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2294 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002295 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002296 } else {
2297 ALOGE("%s: something wrong (1): source type (%d) channel_count (%d) .."
2298 " channel mask (0x%x) no combination found .. setting to mono", __func__,
2299 my_data->source_mic_type, channel_count, channel_mask);
2300 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2301 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002302 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002303 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_SPEAKER_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_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002309 } else {
2310 ALOGE("%s: something wrong (2): source type (%d) channel_count (%d) .."
2311 " no combination found .. setting to mono", __func__,
2312 my_data->source_mic_type, channel_count);
2313 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
2314 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002315 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2316 snd_device = SND_DEVICE_IN_HEADSET_MIC;
2317 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002318 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002319 if (adev->bluetooth_nrec)
2320 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2321 else
2322 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002323 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002324 if (adev->bluetooth_nrec)
2325 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2326 else
2327 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002328 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002329 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
2330 snd_device = SND_DEVICE_IN_HDMI_MIC;
2331 } else {
2332 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
2333 ALOGW("%s: Using default handset-mic", __func__);
2334 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2335 }
2336 } else {
2337 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
2338 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2339 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2340 snd_device = SND_DEVICE_IN_HEADSET_MIC;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002341 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002342 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002343 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002344 out_device & AUDIO_DEVICE_OUT_LINE) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002345 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2346 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002347 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002348 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2349 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002350 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002351 } else {
2352 ALOGE("%s: something wrong (3): source type (%d) channel_count (%d) .."
2353 " no combination found .. setting to mono", __func__,
2354 my_data->source_mic_type, channel_count);
2355 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
2356 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002357 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002358 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002359 if (adev->bluetooth_nrec)
2360 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2361 else
2362 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002363 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002364 if (adev->bluetooth_nrec)
2365 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2366 else
2367 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002368 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002369 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2370 snd_device = SND_DEVICE_IN_HDMI_MIC;
2371 } else {
2372 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
2373 ALOGW("%s: Using default handset-mic", __func__);
2374 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2375 }
2376 }
2377exit:
2378 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
2379 return snd_device;
2380}
2381
2382int platform_set_hdmi_channels(void *platform, int channel_count)
2383{
2384 struct platform_data *my_data = (struct platform_data *)platform;
2385 struct audio_device *adev = my_data->adev;
2386 struct mixer_ctl *ctl;
2387 const char *channel_cnt_str = NULL;
2388 const char *mixer_ctl_name = "HDMI_RX Channels";
2389 switch (channel_count) {
2390 case 8:
2391 channel_cnt_str = "Eight"; break;
2392 case 7:
2393 channel_cnt_str = "Seven"; break;
2394 case 6:
2395 channel_cnt_str = "Six"; break;
2396 case 5:
2397 channel_cnt_str = "Five"; break;
2398 case 4:
2399 channel_cnt_str = "Four"; break;
2400 case 3:
2401 channel_cnt_str = "Three"; break;
2402 default:
2403 channel_cnt_str = "Two"; break;
2404 }
2405 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2406 if (!ctl) {
2407 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2408 __func__, mixer_ctl_name);
2409 return -EINVAL;
2410 }
2411 ALOGV("HDMI channel count: %s", channel_cnt_str);
2412 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
2413 return 0;
2414}
2415
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002416int platform_edid_get_max_channels(void *platform)
Eric Laurentb23d5282013-05-14 15:27:20 -07002417{
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002418 struct platform_data *my_data = (struct platform_data *)platform;
2419 struct audio_device *adev = my_data->adev;
Eric Laurentb23d5282013-05-14 15:27:20 -07002420 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
2421 char *sad = block;
2422 int num_audio_blocks;
2423 int channel_count;
2424 int max_channels = 0;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002425 int i, ret, count;
Eric Laurentb23d5282013-05-14 15:27:20 -07002426
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002427 struct mixer_ctl *ctl;
2428
2429 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
2430 if (!ctl) {
2431 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2432 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
Eric Laurentb23d5282013-05-14 15:27:20 -07002433 return 0;
2434 }
2435
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002436 mixer_ctl_update(ctl);
2437
2438 count = mixer_ctl_get_num_values(ctl);
Eric Laurentb23d5282013-05-14 15:27:20 -07002439
2440 /* Read SAD blocks, clamping the maximum size for safety */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002441 if (count > (int)sizeof(block))
2442 count = (int)sizeof(block);
Eric Laurentb23d5282013-05-14 15:27:20 -07002443
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002444 ret = mixer_ctl_get_array(ctl, block, count);
2445 if (ret != 0) {
2446 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
2447 return 0;
2448 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002449
2450 /* Calculate the number of SAD blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002451 num_audio_blocks = count / SAD_BLOCK_SIZE;
Eric Laurentb23d5282013-05-14 15:27:20 -07002452
2453 for (i = 0; i < num_audio_blocks; i++) {
2454 /* Only consider LPCM blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002455 if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
2456 sad += 3;
Eric Laurentb23d5282013-05-14 15:27:20 -07002457 continue;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002458 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002459
2460 channel_count = (sad[0] & 0x7) + 1;
2461 if (channel_count > max_channels)
2462 max_channels = channel_count;
2463
2464 /* Advance to next block */
2465 sad += 3;
2466 }
2467
2468 return max_channels;
2469}
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07002470
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002471int platform_set_incall_recording_session_id(void *platform,
2472 uint32_t session_id, int rec_mode)
2473{
2474 int ret = 0;
2475 struct platform_data *my_data = (struct platform_data *)platform;
2476 struct audio_device *adev = my_data->adev;
2477 struct mixer_ctl *ctl;
2478 const char *mixer_ctl_name = "Voc VSID";
2479 int num_ctl_values;
2480 int i;
2481
2482 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2483 if (!ctl) {
2484 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2485 __func__, mixer_ctl_name);
2486 ret = -EINVAL;
2487 } else {
2488 num_ctl_values = mixer_ctl_get_num_values(ctl);
2489 for (i = 0; i < num_ctl_values; i++) {
2490 if (mixer_ctl_set_value(ctl, i, session_id)) {
2491 ALOGV("Error: invalid session_id: %x", session_id);
2492 ret = -EINVAL;
2493 break;
2494 }
2495 }
2496 }
2497
2498 if (my_data->csd != NULL) {
2499 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
2500 if (ret < 0) {
2501 ALOGE("%s: csd_client_start_record failed, error %d",
2502 __func__, ret);
2503 }
2504 }
2505
2506 return ret;
2507}
2508
2509int platform_stop_incall_recording_usecase(void *platform)
2510{
2511 int ret = 0;
2512 struct platform_data *my_data = (struct platform_data *)platform;
2513
2514 if (my_data->csd != NULL) {
2515 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
2516 if (ret < 0) {
2517 ALOGE("%s: csd_client_stop_record failed, error %d",
2518 __func__, ret);
2519 }
2520 }
2521
2522 return ret;
2523}
2524
2525int platform_start_incall_music_usecase(void *platform)
2526{
2527 int ret = 0;
2528 struct platform_data *my_data = (struct platform_data *)platform;
2529
2530 if (my_data->csd != NULL) {
2531 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
2532 if (ret < 0) {
2533 ALOGE("%s: csd_client_start_playback failed, error %d",
2534 __func__, ret);
2535 }
2536 }
2537
2538 return ret;
2539}
2540
2541int platform_stop_incall_music_usecase(void *platform)
2542{
2543 int ret = 0;
2544 struct platform_data *my_data = (struct platform_data *)platform;
2545
2546 if (my_data->csd != NULL) {
2547 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
2548 if (ret < 0) {
2549 ALOGE("%s: csd_client_stop_playback failed, error %d",
2550 __func__, ret);
2551 }
2552 }
2553
2554 return ret;
2555}
2556
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002557int platform_set_parameters(void *platform, struct str_parms *parms)
2558{
2559 struct platform_data *my_data = (struct platform_data *)platform;
keunhui.park2f7306a2015-07-16 16:48:06 +09002560 char value[128];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002561 char *kv_pairs = str_parms_to_str(parms);
2562 int ret = 0, err;
2563
2564 if (kv_pairs == NULL) {
2565 ret = -EINVAL;
2566 ALOGE("%s: key-value pair is NULL",__func__);
2567 goto done;
2568 }
2569
2570 ALOGV("%s: enter: %s", __func__, kv_pairs);
2571
2572 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME,
2573 value, sizeof(value));
2574 if (err >= 0) {
2575 str_parms_del(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME);
2576 my_data->snd_card_name = strdup(value);
2577 ALOGV("%s: sound card name %s", __func__, my_data->snd_card_name);
2578 }
2579
keunhui.park2f7306a2015-07-16 16:48:06 +09002580 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO,
2581 value, sizeof(value));
2582 if (err >= 0) {
2583 struct operator_info *info;
2584 char *str = value;
2585 char *name;
2586
2587 str_parms_del(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO);
2588 info = (struct operator_info *)calloc(1, sizeof(struct operator_info));
2589 name = strtok(str, ";");
2590 info->name = strdup(name);
2591 info->mccmnc = strdup(str + strlen(name) + 1);
2592
2593 list_add_tail(&operator_info_list, &info->list);
Joe Onorato188b6222016-03-01 11:02:27 -08002594 ALOGV("%s: add operator[%s] mccmnc[%s]", __func__, info->name, info->mccmnc);
keunhui.park2f7306a2015-07-16 16:48:06 +09002595 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002596
2597 memset(value, 0, sizeof(value));
Eric Laurentc6333382015-09-14 12:43:44 -07002598 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT,
Prashant Malanic92c5962015-08-11 15:10:18 -07002599 value, sizeof(value));
2600 if (err >= 0) {
Eric Laurentc6333382015-09-14 12:43:44 -07002601 str_parms_del(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT);
Prashant Malanic92c5962015-08-11 15:10:18 -07002602 my_data->max_mic_count = atoi(value);
2603 ALOGV("%s: max_mic_count %s/%d", __func__, value, my_data->max_mic_count);
Prashant Malanic92c5962015-08-11 15:10:18 -07002604 }
2605
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002606done:
2607 ALOGV("%s: exit with code(%d)", __func__, ret);
2608 if (kv_pairs != NULL)
2609 free(kv_pairs);
2610
2611 return ret;
2612}
2613
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07002614/* Delay in Us */
2615int64_t platform_render_latency(audio_usecase_t usecase)
2616{
2617 switch (usecase) {
2618 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
2619 return DEEP_BUFFER_PLATFORM_DELAY;
2620 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
2621 return LOW_LATENCY_PLATFORM_DELAY;
Haynes Mathew George03c40102016-01-29 17:57:48 -08002622 case USECASE_AUDIO_PLAYBACK_ULL:
2623 return ULL_PLATFORM_DELAY;
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07002624 default:
2625 return 0;
2626 }
2627}
Haynes Mathew George98c95622014-06-20 19:14:25 -07002628
vivek mehta4ed66e62016-04-15 23:33:34 -07002629bool platform_check_and_set_capture_backend_cfg(struct audio_device* adev,
David Benjaminc9d8d892016-09-21 12:04:55 -04002630 struct audio_usecase *usecase __unused,
2631 snd_device_t snd_device __unused)
vivek mehta4ed66e62016-04-15 23:33:34 -07002632{
2633 enum pcm_format in_pcm_format = PCM_FORMAT_S16_LE;
2634
2635 if (adev && adev->active_input)
2636 in_pcm_format = adev->active_input->config.format;
2637
2638 // allow 24 bit recording only if voice call is not active
2639 if (!voice_is_in_call(adev) &&
2640 adev->mode != AUDIO_MODE_IN_COMMUNICATION &&
2641 in_pcm_format == PCM_FORMAT_S24_LE) {
2642 audio_route_apply_and_update_path(adev->audio_route, "set-capture-format-24le");
2643 } else {
2644 audio_route_apply_and_update_path(adev->audio_route, "set-capture-format-default");
2645 }
2646
2647 return true;
2648}
2649
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002650int platform_set_snd_device_backend(snd_device_t device, const char *backend_tag,
2651 const char * hw_interface)
Haynes Mathew George98c95622014-06-20 19:14:25 -07002652{
2653 int ret = 0;
2654
2655 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
2656 ALOGE("%s: Invalid snd_device = %d",
2657 __func__, device);
2658 ret = -EINVAL;
2659 goto done;
2660 }
2661
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002662 ALOGV("%s: backend_tag_table[%s]: old = %s new = %s", __func__,
2663 platform_get_snd_device_name(device),
2664 backend_tag_table[device] != NULL ? backend_tag_table[device]: "null", backend_tag);
2665 if (backend_tag_table[device]) {
2666 free(backend_tag_table[device]);
Haynes Mathew George98c95622014-06-20 19:14:25 -07002667 }
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002668 backend_tag_table[device] = strdup(backend_tag);
2669
2670 if (hw_interface != NULL) {
2671 if (hw_interface_table[device])
2672 free(hw_interface_table[device]);
2673 ALOGV("%s: hw_interface_table[%d] = %s", __func__, device, hw_interface);
2674 hw_interface_table[device] = strdup(hw_interface);
2675 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07002676done:
2677 return ret;
2678}
2679
2680int platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t pcm_id)
2681{
2682 int ret = 0;
2683 if ((usecase <= USECASE_INVALID) || (usecase >= AUDIO_USECASE_MAX)) {
2684 ALOGE("%s: invalid usecase case idx %d", __func__, usecase);
2685 ret = -EINVAL;
2686 goto done;
2687 }
2688
2689 if ((type != 0) && (type != 1)) {
2690 ALOGE("%s: invalid usecase type", __func__);
2691 ret = -EINVAL;
2692 }
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002693 ALOGV("%s: pcm_device_table[%d][%d] = %d", __func__, usecase, type, pcm_id);
Haynes Mathew George98c95622014-06-20 19:14:25 -07002694 pcm_device_table[usecase][type] = pcm_id;
2695done:
2696 return ret;
2697}
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002698
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07002699#define DEFAULT_NOMINAL_SPEAKER_GAIN 20
2700int ramp_speaker_gain(struct audio_device *adev, bool ramp_up, int target_ramp_up_gain) {
2701 // backup_gain: gain to try to set in case of an error during ramp
2702 int start_gain, end_gain, step, backup_gain, i;
2703 bool error = false;
2704 const struct mixer_ctl *ctl;
2705 const char *mixer_ctl_name_gain_left = "Left Speaker Gain";
2706 const char *mixer_ctl_name_gain_right = "Right Speaker Gain";
2707 struct mixer_ctl *ctl_left = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_left);
2708 struct mixer_ctl *ctl_right = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_right);
2709 if (!ctl_left || !ctl_right) {
2710 ALOGE("%s: Could not get ctl for mixer cmd - %s or %s, not applying speaker gain ramp",
2711 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
2712 return -EINVAL;
2713 } else if ((mixer_ctl_get_num_values(ctl_left) != 1)
2714 || (mixer_ctl_get_num_values(ctl_right) != 1)) {
2715 ALOGE("%s: Unexpected num values for mixer cmd - %s or %s, not applying speaker gain ramp",
2716 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
2717 return -EINVAL;
2718 }
2719 if (ramp_up) {
2720 start_gain = 0;
2721 end_gain = target_ramp_up_gain > 0 ? target_ramp_up_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
2722 step = +1;
2723 backup_gain = end_gain;
2724 } else {
2725 // using same gain on left and right
2726 const int left_gain = mixer_ctl_get_value(ctl_left, 0);
2727 start_gain = left_gain > 0 ? left_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
2728 end_gain = 0;
2729 step = -1;
2730 backup_gain = start_gain;
2731 }
2732 for (i = start_gain ; i != (end_gain + step) ; i += step) {
2733 //ALOGV("setting speaker gain to %d", i);
2734 if (mixer_ctl_set_value(ctl_left, 0, i)) {
2735 ALOGE("%s: error setting %s to %d during gain ramp",
2736 __func__, mixer_ctl_name_gain_left, i);
2737 error = true;
2738 break;
2739 }
2740 if (mixer_ctl_set_value(ctl_right, 0, i)) {
2741 ALOGE("%s: error setting %s to %d during gain ramp",
2742 __func__, mixer_ctl_name_gain_right, i);
2743 error = true;
2744 break;
2745 }
2746 usleep(1000);
2747 }
2748 if (error) {
2749 // an error occured during the ramp, let's still try to go back to a safe volume
2750 if (mixer_ctl_set_value(ctl_left, 0, backup_gain)) {
2751 ALOGE("%s: error restoring left gain to %d", __func__, backup_gain);
2752 }
2753 if (mixer_ctl_set_value(ctl_right, 0, backup_gain)) {
2754 ALOGE("%s: error restoring right gain to %d", __func__, backup_gain);
2755 }
2756 }
2757 return start_gain;
2758}
2759
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002760int platform_swap_lr_channels(struct audio_device *adev, bool swap_channels)
2761{
2762 // only update if there is active pcm playback on speaker
2763 struct audio_usecase *usecase;
2764 struct listnode *node;
2765 struct platform_data *my_data = (struct platform_data *)adev->platform;
2766
2767 if (my_data->speaker_lr_swap != swap_channels) {
Jean-Michel Trivif7148702016-09-16 18:23:05 -07002768
2769 // do not swap channels in audio modes with concurrent capture and playback
2770 // as this may break the echo reference
2771 if ((adev->mode == AUDIO_MODE_IN_COMMUNICATION) || (adev->mode == AUDIO_MODE_IN_CALL)) {
2772 ALOGV("%s: will not swap due to audio mode %d", __func__, adev->mode);
2773 return 0;
2774 }
2775
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002776 my_data->speaker_lr_swap = swap_channels;
2777
2778 list_for_each(node, &adev->usecase_list) {
2779 usecase = node_to_item(node, struct audio_usecase, list);
2780 if (usecase->type == PCM_PLAYBACK &&
Ravi Kumar Alamanda425e1542015-09-22 09:11:18 -07002781 usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) {
2782 /*
2783 * If acdb tuning is different for SPEAKER_REVERSE, it is must
2784 * to perform device switch to disable the current backend to
2785 * enable it with new acdb data.
2786 */
2787 if (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
2788 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]) {
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07002789 const int initial_skpr_gain = ramp_speaker_gain(adev, false /*ramp_up*/, -1);
Ravi Kumar Alamanda425e1542015-09-22 09:11:18 -07002790 select_devices(adev, usecase->id);
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07002791 if (initial_skpr_gain != -EINVAL) {
2792 ramp_speaker_gain(adev, true /*ramp_up*/, initial_skpr_gain);
2793 }
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002794 } else {
Ravi Kumar Alamanda425e1542015-09-22 09:11:18 -07002795 const char *mixer_path;
2796 if (swap_channels) {
2797 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER_REVERSE);
2798 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
2799 } else {
2800 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER);
2801 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
2802 }
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002803 }
2804 break;
2805 }
2806 }
2807 }
2808 return 0;
2809}
vivek mehtaa8d7c922016-05-25 14:40:44 -07002810
2811static struct amp_db_and_gain_table tbl_mapping[MAX_VOLUME_CAL_STEPS];
2812static int num_gain_tbl_entry = 0;
2813
2814bool platform_add_gain_level_mapping(struct amp_db_and_gain_table *tbl_entry) {
2815
2816 ALOGV("%s: enter .. add %f %f %d", __func__, tbl_entry->amp, tbl_entry->db, tbl_entry->level);
2817 if (num_gain_tbl_entry == -1) {
2818 ALOGE("%s: num entry beyond valid step levels or corrupted..rejecting custom mapping",
2819 __func__);
2820 return false;
2821 }
2822
2823 if (num_gain_tbl_entry >= MAX_VOLUME_CAL_STEPS) {
2824 ALOGE("%s: max entry reached max[%d] current index[%d] .. rejecting", __func__,
2825 MAX_VOLUME_CAL_STEPS, num_gain_tbl_entry);
2826 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
2827 return false;
2828 }
2829
2830 if (num_gain_tbl_entry > 0 && tbl_mapping[num_gain_tbl_entry - 1].amp >= tbl_entry->amp) {
2831 ALOGE("%s: value not in ascending order .. rejecting custom mapping", __func__);
2832 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
2833 return false;
2834 }
2835
2836 tbl_mapping[num_gain_tbl_entry] = *tbl_entry;
2837 ++num_gain_tbl_entry;
2838
2839 return true;
2840}
2841
2842int platform_get_gain_level_mapping(struct amp_db_and_gain_table *mapping_tbl,
2843 int table_size) {
2844 int itt = 0;
2845 ALOGV("platform_get_gain_level_mapping called ");
2846
2847 if (num_gain_tbl_entry <= 0 || num_gain_tbl_entry > MAX_VOLUME_CAL_STEPS) {
2848 ALOGD("%s: empty or currupted gain_mapping_table", __func__);
2849 return 0;
2850 }
2851
2852 for (; itt < num_gain_tbl_entry && itt <= table_size; itt++) {
2853 mapping_tbl[itt] = tbl_mapping[itt];
2854 ALOGV("%s: added amp[%f] db[%f] level[%d]", __func__,
2855 mapping_tbl[itt].amp, mapping_tbl[itt].db, mapping_tbl[itt].level);
2856 }
2857
2858 return num_gain_tbl_entry;
2859}
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07002860
2861int platform_snd_card_update(void *platform, card_status_t status)
2862{
2863 struct platform_data *my_data = (struct platform_data *)platform;
2864 struct audio_device *adev = my_data->adev;
2865
2866 if (status == CARD_STATUS_ONLINE) {
2867 if (my_data->acdb_send_custom_top)
2868 my_data->acdb_send_custom_top();
2869 }
2870 return 0;
2871}