blob: a97d5be53d3175388f34b2de146bce0565955a7f [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;
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -0700123#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996)
124 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)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700513};
514
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700515#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
516#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
Haynes Mathew George03c40102016-01-29 17:57:48 -0800517#define ULL_PLATFORM_DELAY (7*1000LL)
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700518
Eric Laurentb23d5282013-05-14 15:27:20 -0700519static pthread_once_t check_op_once_ctl = PTHREAD_ONCE_INIT;
520static bool is_tmus = false;
521
522static void check_operator()
523{
524 char value[PROPERTY_VALUE_MAX];
525 int mccmnc;
526 property_get("gsm.sim.operator.numeric",value,"0");
527 mccmnc = atoi(value);
Eric Laurent2bafff12016-03-17 12:17:23 -0700528 ALOGD("%s: tmus mccmnc %d", __func__, mccmnc);
Eric Laurentb23d5282013-05-14 15:27:20 -0700529 switch(mccmnc) {
530 /* TMUS MCC(310), MNC(490, 260, 026) */
531 case 310490:
532 case 310260:
533 case 310026:
sangwon.jeonb891db52013-09-14 17:39:15 +0900534 /* Add new TMUS MNC(800, 660, 580, 310, 270, 250, 240, 230, 220, 210, 200, 160) */
535 case 310800:
536 case 310660:
537 case 310580:
538 case 310310:
539 case 310270:
540 case 310250:
541 case 310240:
542 case 310230:
543 case 310220:
544 case 310210:
545 case 310200:
546 case 310160:
Eric Laurentb23d5282013-05-14 15:27:20 -0700547 is_tmus = true;
548 break;
549 }
550}
551
552bool is_operator_tmus()
553{
554 pthread_once(&check_op_once_ctl, check_operator);
555 return is_tmus;
556}
557
keunhui.park2f7306a2015-07-16 16:48:06 +0900558static char *get_current_operator()
559{
560 struct listnode *node;
561 struct operator_info *info_item;
562 char mccmnc[PROPERTY_VALUE_MAX];
563 char *ret = NULL;
564
565 property_get("gsm.sim.operator.numeric",mccmnc,"0");
566
567 list_for_each(node, &operator_info_list) {
568 info_item = node_to_item(node, struct operator_info, list);
569 if (strstr(info_item->mccmnc, mccmnc) != NULL) {
570 ret = info_item->name;
571 }
572 }
573
574 return ret;
575}
576
577static struct operator_specific_device *get_operator_specific_device(snd_device_t snd_device)
578{
579 struct listnode *node;
580 struct operator_specific_device *ret = NULL;
581 struct operator_specific_device *device_item;
582 char *operator_name;
583
584 operator_name = get_current_operator();
585 if (operator_name == NULL)
586 return ret;
587
588 list_for_each(node, operator_specific_device_table[snd_device]) {
589 device_item = node_to_item(node, struct operator_specific_device, list);
590 if (strcmp(operator_name, device_item->operator) == 0) {
591 ret = device_item;
592 }
593 }
594
595 return ret;
596}
597
598
599static int get_operator_specific_device_acdb_id(snd_device_t snd_device)
600{
601 struct operator_specific_device *device;
602 int ret = acdb_device_table[snd_device];
603
604 device = get_operator_specific_device(snd_device);
605 if (device != NULL)
606 ret = device->acdb_id;
607
608 return ret;
609}
610
611static const char *get_operator_specific_device_mixer_path(snd_device_t snd_device)
612{
613 struct operator_specific_device *device;
614 const char *ret = device_table[snd_device];
615
616 device = get_operator_specific_device(snd_device);
617 if (device != NULL)
618 ret = device->mixer_path;
619
620 return ret;
621}
622
vivek mehta1a9b7c02015-06-25 11:49:38 -0700623bool platform_send_gain_dep_cal(void *platform, int level)
624{
625 bool ret_val = false;
626 struct platform_data *my_data = (struct platform_data *)platform;
627 struct audio_device *adev = my_data->adev;
628 int acdb_dev_id, app_type;
629 int acdb_dev_type = MSM_SNDDEV_CAP_RX;
630 int mode = CAL_MODE_RTAC;
631 struct listnode *node;
632 struct audio_usecase *usecase;
vivek mehta1a9b7c02015-06-25 11:49:38 -0700633
634 if (my_data->acdb_send_gain_dep_cal == NULL) {
635 ALOGE("%s: dlsym error for acdb_send_gain_dep_cal", __func__);
636 return ret_val;
637 }
638
639 if (!voice_is_in_call(adev)) {
640 ALOGV("%s: Not Voice call usecase, apply new cal for level %d",
641 __func__, level);
642 app_type = DEFAULT_APP_TYPE_RX_PATH;
643
644 // find the current active sound device
645 list_for_each(node, &adev->usecase_list) {
646 usecase = node_to_item(node, struct audio_usecase, list);
647
648 if (usecase != NULL &&
649 usecase->type == PCM_PLAYBACK &&
650 (usecase->stream.out->devices == AUDIO_DEVICE_OUT_SPEAKER)) {
651
652 ALOGV("%s: out device is %d", __func__, usecase->out_snd_device);
vivek mehta4cb82982015-07-13 12:05:49 -0700653 if (audio_extn_spkr_prot_is_enabled()) {
654 acdb_dev_id = audio_extn_spkr_prot_get_acdb_id(usecase->out_snd_device);
655 } else {
656 acdb_dev_id = acdb_device_table[usecase->out_snd_device];
657 }
658
vivek mehta1a9b7c02015-06-25 11:49:38 -0700659 if (!my_data->acdb_send_gain_dep_cal(acdb_dev_id, app_type,
660 acdb_dev_type, mode, level)) {
661 // set ret_val true if at least one calibration is set successfully
662 ret_val = true;
663 } else {
664 ALOGE("%s: my_data->acdb_send_gain_dep_cal failed ", __func__);
665 }
666 } else {
667 ALOGW("%s: Usecase list is empty", __func__);
668 }
669 }
670 } else {
671 ALOGW("%s: Voice call in progress .. ignore setting new cal",
672 __func__);
673 }
674 return ret_val;
675}
676
Eric Laurentcefbbac2014-09-04 13:54:10 -0500677void platform_set_echo_reference(struct audio_device *adev, bool enable, audio_devices_t out_device)
Eric Laurentb23d5282013-05-14 15:27:20 -0700678{
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800679 struct platform_data *my_data = (struct platform_data *)adev->platform;
Eric Laurentcefbbac2014-09-04 13:54:10 -0500680 snd_device_t snd_device = SND_DEVICE_NONE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700681
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800682 if (strcmp(my_data->ec_ref_mixer_path, "")) {
683 ALOGV("%s: diabling %s", __func__, my_data->ec_ref_mixer_path);
684 audio_route_reset_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
Eric Laurentcefbbac2014-09-04 13:54:10 -0500685 }
686
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800687 if (enable) {
688 strcpy(my_data->ec_ref_mixer_path, "echo-reference");
689 if (out_device != AUDIO_DEVICE_NONE) {
690 snd_device = platform_get_output_snd_device(adev->platform, out_device);
691 platform_add_backend_name(adev->platform, my_data->ec_ref_mixer_path, snd_device);
692 }
Eric Laurentcefbbac2014-09-04 13:54:10 -0500693
Joe Onorato188b6222016-03-01 11:02:27 -0800694 ALOGV("%s: enabling %s", __func__, my_data->ec_ref_mixer_path);
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800695 audio_route_apply_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
696 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700697}
698
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700699static struct csd_data *open_csd_client(bool i2s_ext_modem)
700{
701 struct csd_data *csd = calloc(1, sizeof(struct csd_data));
702
703 csd->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
704 if (csd->csd_client == NULL) {
705 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
706 goto error;
707 } else {
708 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
709
710 csd->deinit = (deinit_t)dlsym(csd->csd_client,
711 "csd_client_deinit");
712 if (csd->deinit == NULL) {
713 ALOGE("%s: dlsym error %s for csd_client_deinit", __func__,
714 dlerror());
715 goto error;
716 }
717 csd->disable_device = (disable_device_t)dlsym(csd->csd_client,
718 "csd_client_disable_device");
719 if (csd->disable_device == NULL) {
720 ALOGE("%s: dlsym error %s for csd_client_disable_device",
721 __func__, dlerror());
722 goto error;
723 }
724 csd->enable_device_config = (enable_device_config_t)dlsym(csd->csd_client,
725 "csd_client_enable_device_config");
726 if (csd->enable_device_config == NULL) {
727 ALOGE("%s: dlsym error %s for csd_client_enable_device_config",
728 __func__, dlerror());
729 goto error;
730 }
731 csd->enable_device = (enable_device_t)dlsym(csd->csd_client,
732 "csd_client_enable_device");
733 if (csd->enable_device == NULL) {
734 ALOGE("%s: dlsym error %s for csd_client_enable_device",
735 __func__, dlerror());
736 goto error;
737 }
738 csd->start_voice = (start_voice_t)dlsym(csd->csd_client,
739 "csd_client_start_voice");
740 if (csd->start_voice == NULL) {
741 ALOGE("%s: dlsym error %s for csd_client_start_voice",
742 __func__, dlerror());
743 goto error;
744 }
745 csd->stop_voice = (stop_voice_t)dlsym(csd->csd_client,
746 "csd_client_stop_voice");
747 if (csd->stop_voice == NULL) {
748 ALOGE("%s: dlsym error %s for csd_client_stop_voice",
749 __func__, dlerror());
750 goto error;
751 }
752 csd->volume = (volume_t)dlsym(csd->csd_client,
753 "csd_client_volume");
754 if (csd->volume == NULL) {
755 ALOGE("%s: dlsym error %s for csd_client_volume",
756 __func__, dlerror());
757 goto error;
758 }
759 csd->mic_mute = (mic_mute_t)dlsym(csd->csd_client,
760 "csd_client_mic_mute");
761 if (csd->mic_mute == NULL) {
762 ALOGE("%s: dlsym error %s for csd_client_mic_mute",
763 __func__, dlerror());
764 goto error;
765 }
766 csd->slow_talk = (slow_talk_t)dlsym(csd->csd_client,
767 "csd_client_slow_talk");
768 if (csd->slow_talk == NULL) {
769 ALOGE("%s: dlsym error %s for csd_client_slow_talk",
770 __func__, dlerror());
771 goto error;
772 }
773 csd->start_playback = (start_playback_t)dlsym(csd->csd_client,
774 "csd_client_start_playback");
775 if (csd->start_playback == NULL) {
776 ALOGE("%s: dlsym error %s for csd_client_start_playback",
777 __func__, dlerror());
778 goto error;
779 }
780 csd->stop_playback = (stop_playback_t)dlsym(csd->csd_client,
781 "csd_client_stop_playback");
782 if (csd->stop_playback == NULL) {
783 ALOGE("%s: dlsym error %s for csd_client_stop_playback",
784 __func__, dlerror());
785 goto error;
786 }
787 csd->start_record = (start_record_t)dlsym(csd->csd_client,
788 "csd_client_start_record");
789 if (csd->start_record == NULL) {
790 ALOGE("%s: dlsym error %s for csd_client_start_record",
791 __func__, dlerror());
792 goto error;
793 }
794 csd->stop_record = (stop_record_t)dlsym(csd->csd_client,
795 "csd_client_stop_record");
796 if (csd->stop_record == NULL) {
797 ALOGE("%s: dlsym error %s for csd_client_stop_record",
798 __func__, dlerror());
799 goto error;
800 }
801
802 csd->get_sample_rate = (get_sample_rate_t)dlsym(csd->csd_client,
803 "csd_client_get_sample_rate");
804 if (csd->get_sample_rate == NULL) {
805 ALOGE("%s: dlsym error %s for csd_client_get_sample_rate",
806 __func__, dlerror());
807
808 goto error;
809 }
810
811 csd->init = (init_t)dlsym(csd->csd_client, "csd_client_init");
812
813 if (csd->init == NULL) {
814 ALOGE("%s: dlsym error %s for csd_client_init",
815 __func__, dlerror());
816 goto error;
817 } else {
818 csd->init(i2s_ext_modem);
819 }
820 }
821 return csd;
822
823error:
824 free(csd);
825 csd = NULL;
826 return csd;
827}
828
829void close_csd_client(struct csd_data *csd)
830{
831 if (csd != NULL) {
832 csd->deinit();
833 dlclose(csd->csd_client);
834 free(csd);
835 csd = NULL;
836 }
837}
838
839static void platform_csd_init(struct platform_data *my_data)
840{
841#ifdef PLATFORM_MSM8084
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700842 int32_t modems, (*count_modems)(void);
843 const char *name = "libdetectmodem.so";
844 const char *func = "count_modems";
845 const char *error;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700846
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700847 my_data->csd = NULL;
848
849 void *lib = dlopen(name, RTLD_NOW);
850 error = dlerror();
851 if (!lib) {
852 ALOGE("%s: could not find %s: %s", __func__, name, error);
853 return;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700854 }
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700855
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700856 count_modems = NULL;
857 *(void **)(&count_modems) = dlsym(lib, func);
858 error = dlerror();
859 if (!count_modems) {
860 ALOGE("%s: could not find symbol %s in %s: %s",
861 __func__, func, name, error);
862 goto done;
863 }
864
865 modems = count_modems();
866 if (modems < 0) {
867 ALOGE("%s: count_modems failed\n", __func__);
868 goto done;
869 }
870
Eric Laurent2bafff12016-03-17 12:17:23 -0700871 ALOGD("%s: num_modems %d\n", __func__, modems);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700872 if (modems > 0)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700873 my_data->csd = open_csd_client(false /*is_i2s_ext_modem*/);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700874
875done:
876 dlclose(lib);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700877#else
878 my_data->csd = NULL;
879#endif
880}
881
Eric Laurentc6333382015-09-14 12:43:44 -0700882static void set_platform_defaults(struct platform_data * my_data)
Haynes Mathew George98c95622014-06-20 19:14:25 -0700883{
884 int32_t dev;
885 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700886 backend_tag_table[dev] = NULL;
887 hw_interface_table[dev] = NULL;
keunhui.park2f7306a2015-07-16 16:48:06 +0900888 operator_specific_device_table[dev] = NULL;
Haynes Mathew George98c95622014-06-20 19:14:25 -0700889 }
890
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700891 // To overwrite these go to the audio_platform_info.xml file.
892 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("bt-sco");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700893 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("bt-sco");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700894 backend_tag_table[SND_DEVICE_OUT_BT_SCO] = strdup("bt-sco");
895 backend_tag_table[SND_DEVICE_OUT_HDMI] = strdup("hdmi");
896 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("speaker-and-hdmi");
897 backend_tag_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("bt-sco-wb");
898 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("bt-sco-wb");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700899 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("bt-sco-wb");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700900 backend_tag_table[SND_DEVICE_OUT_VOICE_TX] = strdup("afe-proxy");
901 backend_tag_table[SND_DEVICE_IN_VOICE_RX] = strdup("afe-proxy");
Haynes Mathew George98c95622014-06-20 19:14:25 -0700902
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700903 hw_interface_table[SND_DEVICE_OUT_HANDSET] = strdup("SLIMBUS_0_RX");
904 hw_interface_table[SND_DEVICE_OUT_SPEAKER] = strdup("SLIMBUS_0_RX");
905 hw_interface_table[SND_DEVICE_OUT_SPEAKER_REVERSE] = strdup("SLIMBUS_0_RX");
906 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE] = strdup("SLIMBUS_0_RX");
907 hw_interface_table[SND_DEVICE_OUT_HEADPHONES] = strdup("SLIMBUS_0_RX");
908 hw_interface_table[SND_DEVICE_OUT_LINE] = strdup("SLIMBUS_0_RX");
909 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700910 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700911 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700912 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700913 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET] = strdup("SLIMBUS_0_RX");
914 hw_interface_table[SND_DEVICE_OUT_VOICE_HAC_HANDSET] = strdup("SLIMBUS_0_RX");
915 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER] = strdup("SLIMBUS_0_RX");
916 hw_interface_table[SND_DEVICE_OUT_VOICE_HEADPHONES] = strdup("SLIMBUS_0_RX");
917 hw_interface_table[SND_DEVICE_OUT_VOICE_LINE] = strdup("SLIMBUS_0_RX");
918 hw_interface_table[SND_DEVICE_OUT_HDMI] = strdup("HDMI_RX");
919 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("SLIMBUS_0_RX-and-HDMI_RX");
920 hw_interface_table[SND_DEVICE_OUT_BT_SCO] = strdup("SEC_AUX_PCM_RX");
921 hw_interface_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("SEC_AUX_PCM_RX");
922 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = strdup("SLIMBUS_0_RX");
923 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = strdup("SLIMBUS_0_RX");
924 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = strdup("SLIMBUS_0_RX");
925 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = strdup("SLIMBUS_0_RX");
926 hw_interface_table[SND_DEVICE_OUT_VOICE_TX] = strdup("AFE_PCM_RX");
927 hw_interface_table[SND_DEVICE_OUT_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
928 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
Eric Laurentc6333382015-09-14 12:43:44 -0700929
930 my_data->max_mic_count = PLATFORM_DEFAULT_MIC_COUNT;
Haynes Mathew George98c95622014-06-20 19:14:25 -0700931}
932
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +0900933void get_cvd_version(char *cvd_version, struct audio_device *adev)
934{
935 struct mixer_ctl *ctl;
936 int count;
937 int ret = 0;
938
939 ctl = mixer_get_ctl_by_name(adev->mixer, CVD_VERSION_MIXER_CTL);
940 if (!ctl) {
941 ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__, CVD_VERSION_MIXER_CTL);
942 goto done;
943 }
944 mixer_ctl_update(ctl);
945
946 count = mixer_ctl_get_num_values(ctl);
947 if (count > MAX_CVD_VERSION_STRING_SIZE)
948 count = MAX_CVD_VERSION_STRING_SIZE - 1;
949
950 ret = mixer_ctl_get_array(ctl, cvd_version, count);
951 if (ret != 0) {
952 ALOGE("%s: ERROR! mixer_ctl_get_array() failed to get CVD Version", __func__);
953 goto done;
954 }
955
956done:
957 return;
958}
959
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -0700960static int platform_acdb_init(void *platform)
961{
962 struct platform_data *my_data = (struct platform_data *)platform;
963 struct audio_device *adev = my_data->adev;
964
965 if (!my_data->acdb_init) {
966 ALOGE("%s: no acdb_init fn provided", __func__);
967 return -1;
968 }
969
970 if (my_data->acdb_initialized) {
971 ALOGW("acdb is already initialized");
972 return 0;
973 }
974
975#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996)
976 char *cvd_version = calloc(1, MAX_CVD_VERSION_STRING_SIZE);
977 if (!cvd_version)
978 ALOGE("failed to allocate cvd_version");
979 else {
980 get_cvd_version(cvd_version, adev);
981 my_data->acdb_init((char *)my_data->snd_card_name, cvd_version, 0);
982 free(cvd_version);
983 }
984#elif defined (PLATFORM_MSM8084)
985 my_data->acdb_init((char *)my_data->snd_card_name);
986#else
987 my_data->acdb_init();
988#endif
989 my_data->acdb_initialized = true;
990 return 0;
991}
992
Eric Laurentb23d5282013-05-14 15:27:20 -0700993void *platform_init(struct audio_device *adev)
994{
995 char value[PROPERTY_VALUE_MAX];
vivek mehta60ea4152016-02-18 17:10:26 -0800996 struct platform_data *my_data = NULL;
997 int retry_num = 0, snd_card_num = 0, key = 0, ret = 0;
998 bool dual_mic_config = false, use_default_mixer_path = true;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700999 const char *snd_card_name;
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001000 char *cvd_version = NULL;
vivek mehta60ea4152016-02-18 17:10:26 -08001001 char *snd_internal_name = NULL;
1002 char *tmp = NULL;
1003 char mixer_xml_file[MIXER_PATH_MAX_LENGTH]= {0};
vivek mehtade4849c2016-03-03 17:23:38 -08001004 char platform_info_file[MIXER_PATH_MAX_LENGTH]= {0};
1005 struct snd_card_split *snd_split_handle = NULL;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001006 my_data = calloc(1, sizeof(struct platform_data));
1007
1008 my_data->adev = adev;
1009
keunhui.park2f7306a2015-07-16 16:48:06 +09001010 list_init(&operator_info_list);
1011
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001012 set_platform_defaults(my_data);
vivek mehta2b0e5a62016-09-02 17:31:58 -07001013 bool card_verifed[MAX_SND_CARD] = {0};
1014 const int retry_limit = property_get_int32("audio.snd_card.open.retries", RETRY_NUMBER);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001015
vivek mehta2b0e5a62016-09-02 17:31:58 -07001016 for (;;) {
1017 if (snd_card_num >= MAX_SND_CARD) {
1018 if (retry_num++ >= retry_limit) {
1019 ALOGE("%s: Unable to find correct sound card, aborting.", __func__);
1020 goto init_failed;
1021 }
sangwoo1b9f4b32013-06-21 18:22:55 -07001022
vivek mehta2b0e5a62016-09-02 17:31:58 -07001023 snd_card_num = 0;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001024 usleep(RETRY_US);
vivek mehta2b0e5a62016-09-02 17:31:58 -07001025 continue;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001026 }
1027
vivek mehta2b0e5a62016-09-02 17:31:58 -07001028 if (card_verifed[snd_card_num]) {
1029 ++snd_card_num;
1030 continue;
1031 }
1032
1033 adev->mixer = mixer_open(snd_card_num);
1034
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001035 if (!adev->mixer) {
1036 ALOGE("%s: Unable to open the mixer card: %d", __func__,
vivek mehta2b0e5a62016-09-02 17:31:58 -07001037 snd_card_num);
1038 ++snd_card_num;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001039 continue;
1040 }
1041
vivek mehta2b0e5a62016-09-02 17:31:58 -07001042 card_verifed[snd_card_num] = true;
1043
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001044 snd_card_name = mixer_get_name(adev->mixer);
vivek mehtade4849c2016-03-03 17:23:38 -08001045 my_data->hw_info = hw_info_init(snd_card_name);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001046
vivek mehtade4849c2016-03-03 17:23:38 -08001047 audio_extn_set_snd_card_split(snd_card_name);
1048 snd_split_handle = audio_extn_get_snd_card_split();
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001049
vivek mehtade4849c2016-03-03 17:23:38 -08001050 /* Get the codec internal name from the sound card and/or form factor
1051 * name and form the mixer paths and platfor info file name dynamically.
1052 * This is generic way of picking any codec and forma factor name based
1053 * mixer and platform info files in future with no code change.
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001054
vivek mehtade4849c2016-03-03 17:23:38 -08001055 * current code extends and looks for any of the exteneded mixer path and
1056 * platform info file present based on codec and form factor.
vivek mehta60ea4152016-02-18 17:10:26 -08001057
vivek mehtade4849c2016-03-03 17:23:38 -08001058 * order of picking appropriate file is
1059 * <i> mixer_paths_<codec_name>_<form_factor>.xml, if file not present
1060 * <ii> mixer_paths_<codec_name>.xml, if file not present
1061 * <iii> mixer_paths.xml
1062
1063 * same order is followed for audio_platform_info.xml as well
1064 */
1065
1066 // need to carryforward old file name
1067 if (!strncmp(snd_card_name, TOMTOM_8226_SND_CARD_NAME,
Eric Laurentf9583c32016-03-28 13:50:50 -07001068 min(strlen(TOMTOM_8226_SND_CARD_NAME), strlen(snd_card_name)))) {
vivek mehtade4849c2016-03-03 17:23:38 -08001069 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
vivek mehta60ea4152016-02-18 17:10:26 -08001070 MIXER_XML_BASE_STRING, TOMTOM_MIXER_FILE_SUFFIX );
vivek mehtade4849c2016-03-03 17:23:38 -08001071 } else {
Ed Tamb0b0d572016-03-21 10:45:37 -07001072
vivek mehtade4849c2016-03-03 17:23:38 -08001073 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s_%s.xml",
1074 MIXER_XML_BASE_STRING, snd_split_handle->snd_card,
1075 snd_split_handle->form_factor);
1076
1077 if (F_OK != access(mixer_xml_file, 0)) {
1078 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1079 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1080 MIXER_XML_BASE_STRING, snd_split_handle->snd_card);
1081
1082 if (F_OK != access(mixer_xml_file, 0)) {
1083 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1084 strlcpy(mixer_xml_file, MIXER_XML_DEFAULT_PATH, MIXER_PATH_MAX_LENGTH);
1085 }
1086 }
1087
1088 snprintf(platform_info_file, sizeof(platform_info_file), "%s_%s_%s.xml",
1089 PLATFORM_INFO_XML_BASE_STRING, snd_split_handle->snd_card,
1090 snd_split_handle->form_factor);
1091
1092 if (F_OK != access(platform_info_file, 0)) {
1093 memset(platform_info_file, 0, sizeof(platform_info_file));
1094 snprintf(platform_info_file, sizeof(platform_info_file), "%s_%s.xml",
1095 PLATFORM_INFO_XML_BASE_STRING, snd_split_handle->snd_card);
1096
1097 if (F_OK != access(platform_info_file, 0)) {
1098 memset(platform_info_file, 0, sizeof(platform_info_file));
1099 strlcpy(platform_info_file, PLATFORM_INFO_XML_PATH, MIXER_PATH_MAX_LENGTH);
vivek mehta60ea4152016-02-18 17:10:26 -08001100 }
1101 }
Uday Kishore Pasupuleti11dd2232015-06-24 14:18:01 -07001102 }
1103
vivek mehtade4849c2016-03-03 17:23:38 -08001104 /* Initialize platform specific ids and/or backends*/
1105 platform_info_init(platform_info_file, my_data);
1106
1107 /* validate the sound card name
1108 * my_data->snd_card_name can contain
1109 * <a> complete sound card name, i.e. <device>-<codec>-<form_factor>-snd-card
1110 * example: msm8994-tomtom-mtp-snd-card
1111 * <b> or sub string of the card name, i.e. <device>-<codec>
1112 * example: msm8994-tomtom
Eric Laurentf9583c32016-03-28 13:50:50 -07001113 * snd_card_name is truncated to 32 charaters as per mixer_get_name() implementation
1114 * so use min of my_data->snd_card_name and snd_card_name length for comparison
vivek mehtade4849c2016-03-03 17:23:38 -08001115 */
1116
1117 if (my_data->snd_card_name != NULL &&
Eric Laurentf9583c32016-03-28 13:50:50 -07001118 strncmp(snd_card_name, my_data->snd_card_name,
1119 min(strlen(snd_card_name), strlen(my_data->snd_card_name))) != 0) {
vivek mehtade4849c2016-03-03 17:23:38 -08001120 ALOGI("%s: found valid sound card %s, but not primary sound card %s",
1121 __func__, snd_card_name, my_data->snd_card_name);
vivek mehta2b0e5a62016-09-02 17:31:58 -07001122 ++snd_card_num;
1123 mixer_close(adev->mixer);
1124 adev->mixer = NULL;
vivek mehtade4849c2016-03-03 17:23:38 -08001125 hw_info_deinit(my_data->hw_info);
1126 my_data->hw_info = NULL;
1127 continue;
Ed Tam70b5c142016-03-21 19:14:29 -07001128 }
vivek mehtade4849c2016-03-03 17:23:38 -08001129 ALOGI("%s: found sound card %s, primary sound card expeted is %s",
1130 __func__, snd_card_name, my_data->snd_card_name);
vivek mehta60ea4152016-02-18 17:10:26 -08001131
1132 ALOGD("%s: Loading mixer file: %s", __func__, mixer_xml_file);
1133 adev->audio_route = audio_route_init(snd_card_num, mixer_xml_file);
1134
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001135 if (!adev->audio_route) {
1136 ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
vivek mehta2b0e5a62016-09-02 17:31:58 -07001137 mixer_close(adev->mixer);
1138 adev->mixer = NULL;
1139 hw_info_deinit(my_data->hw_info);
1140 my_data->hw_info = NULL;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001141 goto init_failed;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001142 }
1143 adev->snd_card = snd_card_num;
Eric Laurent2bafff12016-03-17 12:17:23 -07001144 ALOGD("%s: Opened sound card:%d", __func__, snd_card_num);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001145 break;
sangwoo1b9f4b32013-06-21 18:22:55 -07001146 }
1147
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09001148 //set max volume step for voice call
1149 property_get("ro.config.vc_call_vol_steps", value, TOSTRING(MAX_VOL_INDEX));
1150 my_data->max_vol_index = atoi(value);
1151
vivek mehta65ad12d2015-08-13 18:32:48 -07001152 property_get("persist.audio.dualmic.config",value,"");
1153 if (!strcmp("endfire", value)) {
1154 dual_mic_config = true;
1155 }
1156
Prashant Malanic92c5962015-08-11 15:10:18 -07001157 my_data->source_mic_type = SOURCE_DUAL_MIC;
1158
Eric Laurentb23d5282013-05-14 15:27:20 -07001159 my_data->fluence_in_spkr_mode = false;
1160 my_data->fluence_in_voice_call = false;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001161 my_data->fluence_in_voice_comm = false;
Eric Laurentb23d5282013-05-14 15:27:20 -07001162 my_data->fluence_in_voice_rec = false;
1163
vivek mehta65ad12d2015-08-13 18:32:48 -07001164 property_get("ro.qc.sdk.audio.fluencetype", value, "none");
Prashant Malanic92c5962015-08-11 15:10:18 -07001165 if (!strcmp("fluencepro", value)) {
1166 my_data->fluence_type = FLUENCE_PRO_ENABLE;
vivek mehta65ad12d2015-08-13 18:32:48 -07001167 } else if (!strcmp("fluence", value) || (dual_mic_config)) {
Prashant Malanic92c5962015-08-11 15:10:18 -07001168 my_data->fluence_type = FLUENCE_ENABLE;
1169 } else if (!strcmp("none", value)) {
1170 my_data->fluence_type = FLUENCE_DISABLE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001171 }
1172
Prashant Malanic92c5962015-08-11 15:10:18 -07001173 if (my_data->fluence_type != FLUENCE_DISABLE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001174 property_get("persist.audio.fluence.voicecall",value,"");
1175 if (!strcmp("true", value)) {
1176 my_data->fluence_in_voice_call = true;
1177 }
1178
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001179 property_get("persist.audio.fluence.voicecomm",value,"");
1180 if (!strcmp("true", value)) {
1181 my_data->fluence_in_voice_comm = true;
1182 }
1183
Eric Laurentb23d5282013-05-14 15:27:20 -07001184 property_get("persist.audio.fluence.voicerec",value,"");
1185 if (!strcmp("true", value)) {
1186 my_data->fluence_in_voice_rec = true;
1187 }
1188
1189 property_get("persist.audio.fluence.speaker",value,"");
1190 if (!strcmp("true", value)) {
1191 my_data->fluence_in_spkr_mode = true;
1192 }
1193 }
1194
Prashant Malanic92c5962015-08-11 15:10:18 -07001195 // support max to mono, example if max count is 3, usecase supports Three, dual and mono mic
1196 switch (my_data->max_mic_count) {
1197 case 4:
1198 my_data->source_mic_type |= SOURCE_QUAD_MIC;
1199 case 3:
1200 my_data->source_mic_type |= SOURCE_THREE_MIC;
1201 case 2:
1202 my_data->source_mic_type |= SOURCE_DUAL_MIC;
1203 case 1:
1204 my_data->source_mic_type |= SOURCE_MONO_MIC;
1205 break;
1206 default:
1207 ALOGE("%s: max_mic_count (%d), is not supported, setting to default",
1208 __func__, my_data->max_mic_count);
1209 my_data->source_mic_type = SOURCE_MONO_MIC|SOURCE_DUAL_MIC;
1210 break;
1211 }
1212
1213 ALOGV("%s: Fluence_Type(%d) max_mic_count(%d) mic_type(0x%x) fluence_in_voice_call(%d)"
1214 " fluence_in_voice_comm(%d) fluence_in_voice_rec(%d) fluence_in_spkr_mode(%d) ",
1215 __func__, my_data->fluence_type, my_data->max_mic_count, my_data->source_mic_type,
1216 my_data->fluence_in_voice_call, my_data->fluence_in_voice_comm,
1217 my_data->fluence_in_voice_rec, my_data->fluence_in_spkr_mode);
1218
Eric Laurentb23d5282013-05-14 15:27:20 -07001219 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
1220 if (my_data->acdb_handle == NULL) {
1221 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
1222 } else {
1223 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
1224 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
1225 "acdb_loader_deallocate_ACDB");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001226 if (!my_data->acdb_deallocate)
1227 ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s",
1228 __func__, LIB_ACDB_LOADER);
1229
Eric Laurentb23d5282013-05-14 15:27:20 -07001230 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
1231 "acdb_loader_send_audio_cal");
1232 if (!my_data->acdb_send_audio_cal)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001233 ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s",
Eric Laurentb23d5282013-05-14 15:27:20 -07001234 __func__, LIB_ACDB_LOADER);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001235
Eric Laurentb23d5282013-05-14 15:27:20 -07001236 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
1237 "acdb_loader_send_voice_cal");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001238 if (!my_data->acdb_send_voice_cal)
1239 ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s",
1240 __func__, LIB_ACDB_LOADER);
1241
1242 my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle,
1243 "acdb_loader_reload_vocvoltable");
1244 if (!my_data->acdb_reload_vocvoltable)
1245 ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s",
1246 __func__, LIB_ACDB_LOADER);
vivek mehta1a9b7c02015-06-25 11:49:38 -07001247
1248 my_data->acdb_send_gain_dep_cal = (acdb_send_gain_dep_cal_t)dlsym(my_data->acdb_handle,
1249 "acdb_loader_send_gain_dep_cal");
1250 if (!my_data->acdb_send_gain_dep_cal)
1251 ALOGV("%s: Could not find the symbol acdb_loader_send_gain_dep_cal from %s",
1252 __func__, LIB_ACDB_LOADER);
1253
vivek mehtac698f132016-02-25 18:50:35 -08001254#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996)
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001255 acdb_init_v2_cvd_t acdb_init;
1256 acdb_init = (acdb_init_v2_cvd_t)dlsym(my_data->acdb_handle,
1257 "acdb_loader_init_v2");
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001258 if (acdb_init == NULL)
1259 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1260 dlerror());
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001261
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001262#elif defined (PLATFORM_MSM8084)
1263 acdb_init_v2_t acdb_init;
1264 acdb_init = (acdb_init_v2_t)dlsym(my_data->acdb_handle,
1265 "acdb_loader_init_v2");
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001266 if (acdb_init == NULL)
1267 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1268 dlerror());
1269
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001270#else
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001271 acdb_init_t acdb_init;
1272 acdb_init = (acdb_init_t)dlsym(my_data->acdb_handle,
Eric Laurentb23d5282013-05-14 15:27:20 -07001273 "acdb_loader_init_ACDB");
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001274 if (acdb_init == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001275 ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__,
1276 dlerror());
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001277#endif
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001278 my_data->acdb_init = acdb_init;
Eric Laurentb23d5282013-05-14 15:27:20 -07001279
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001280 my_data->acdb_send_custom_top = (acdb_send_custom_top_t)
1281 dlsym(my_data->acdb_handle,
1282 "acdb_loader_send_common_custom_topology");
1283
1284 if (!my_data->acdb_send_custom_top)
1285 ALOGE("%s: Could not find the symbol acdb_get_default_app_type from %s",
1286 __func__, LIB_ACDB_LOADER);
1287
1288 platform_acdb_init(my_data);
1289 }
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001290
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001291 audio_extn_spkr_prot_init(adev);
Haynes Mathew George98c95622014-06-20 19:14:25 -07001292
Ravi Kumar Alamanda76315572015-04-23 13:13:56 -07001293 audio_extn_hwdep_cal_send(adev->snd_card, my_data->acdb_handle);
1294
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001295 /* load csd client */
1296 platform_csd_init(my_data);
1297
Eric Laurentb23d5282013-05-14 15:27:20 -07001298 return my_data;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001299
1300init_failed:
1301 if (my_data)
1302 free(my_data);
1303 return NULL;
Eric Laurentb23d5282013-05-14 15:27:20 -07001304}
1305
1306void platform_deinit(void *platform)
1307{
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001308 int32_t dev;
keunhui.park2f7306a2015-07-16 16:48:06 +09001309 struct operator_info *info_item;
1310 struct operator_specific_device *device_item;
1311 struct listnode *node;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001312
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001313 struct platform_data *my_data = (struct platform_data *)platform;
1314 close_csd_client(my_data->csd);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001315
vivek mehtade4849c2016-03-03 17:23:38 -08001316 hw_info_deinit(my_data->hw_info);
1317
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001318 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1319 if (backend_tag_table[dev])
1320 free(backend_tag_table[dev]);
1321 if (hw_interface_table[dev])
1322 free(hw_interface_table[dev]);
keunhui.park2f7306a2015-07-16 16:48:06 +09001323 if (operator_specific_device_table[dev]) {
1324 while (!list_empty(operator_specific_device_table[dev])) {
1325 node = list_head(operator_specific_device_table[dev]);
1326 list_remove(node);
1327 device_item = node_to_item(node, struct operator_specific_device, list);
1328 free(device_item->operator);
1329 free(device_item->mixer_path);
1330 free(device_item);
1331 }
1332 free(operator_specific_device_table[dev]);
1333 }
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001334 }
1335
1336 if (my_data->snd_card_name)
1337 free(my_data->snd_card_name);
1338
keunhui.park2f7306a2015-07-16 16:48:06 +09001339 while (!list_empty(&operator_info_list)) {
1340 node = list_head(&operator_info_list);
1341 list_remove(node);
1342 info_item = node_to_item(node, struct operator_info, list);
1343 free(info_item->name);
1344 free(info_item->mccmnc);
1345 free(info_item);
1346 }
1347
Eric Laurentb23d5282013-05-14 15:27:20 -07001348 free(platform);
1349}
1350
1351const char *platform_get_snd_device_name(snd_device_t snd_device)
1352{
keunhui.park2f7306a2015-07-16 16:48:06 +09001353 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1354 if (operator_specific_device_table[snd_device] != NULL) {
1355 return get_operator_specific_device_mixer_path(snd_device);
1356 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001357 return device_table[snd_device];
keunhui.park2f7306a2015-07-16 16:48:06 +09001358 } else
Ravi Kumar Alamanda64026462014-09-15 00:08:58 -07001359 return "none";
Eric Laurentb23d5282013-05-14 15:27:20 -07001360}
1361
vivek mehtade4849c2016-03-03 17:23:38 -08001362int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
1363 char *device_name)
1364{
1365 struct platform_data *my_data = (struct platform_data *)platform;
1366
David Benjamin1565f992016-09-21 12:10:34 -04001367 if (platform == NULL) {
vivek mehtade4849c2016-03-03 17:23:38 -08001368 ALOGW("%s: something wrong, use legacy get_snd_device name", __func__);
David Benjamin1565f992016-09-21 12:10:34 -04001369 strlcpy(device_name, platform_get_snd_device_name(snd_device),
1370 DEVICE_NAME_MAX_SIZE);
vivek mehtade4849c2016-03-03 17:23:38 -08001371 } else if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1372 if (operator_specific_device_table[snd_device] != NULL) {
1373 strlcpy(device_name, get_operator_specific_device_mixer_path(snd_device),
1374 DEVICE_NAME_MAX_SIZE);
1375 } else {
1376 strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE);
1377 }
1378 hw_info_append_hw_type(my_data->hw_info, snd_device, device_name);
1379 } else {
1380 strlcpy(device_name, "none", DEVICE_NAME_MAX_SIZE);
1381 }
1382
1383 return 0;
1384}
1385
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001386void platform_add_backend_name(void *platform, char *mixer_path,
1387 snd_device_t snd_device)
Eric Laurentb23d5282013-05-14 15:27:20 -07001388{
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001389 struct platform_data *my_data = (struct platform_data *)platform;
1390
Haynes Mathew George98c95622014-06-20 19:14:25 -07001391 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1392 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1393 return;
Ravi Kumar Alamanda1de6e5a2014-06-19 21:55:39 -05001394 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001395
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001396 const char * suffix = backend_tag_table[snd_device];
Haynes Mathew George98c95622014-06-20 19:14:25 -07001397
1398 if (suffix != NULL) {
1399 strcat(mixer_path, " ");
1400 strcat(mixer_path, suffix);
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001401 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001402}
1403
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001404bool platform_check_backends_match(snd_device_t snd_device1, snd_device_t snd_device2)
1405{
1406 bool result = true;
1407
1408 ALOGV("%s: snd_device1 = %s, snd_device2 = %s", __func__,
1409 platform_get_snd_device_name(snd_device1),
1410 platform_get_snd_device_name(snd_device2));
1411
1412 if ((snd_device1 < SND_DEVICE_MIN) || (snd_device1 >= SND_DEVICE_MAX)) {
1413 ALOGE("%s: Invalid snd_device = %s", __func__,
1414 platform_get_snd_device_name(snd_device1));
1415 return false;
1416 }
1417 if ((snd_device2 < SND_DEVICE_MIN) || (snd_device2 >= SND_DEVICE_MAX)) {
1418 ALOGE("%s: Invalid snd_device = %s", __func__,
1419 platform_get_snd_device_name(snd_device2));
1420 return false;
1421 }
1422 const char * be_itf1 = hw_interface_table[snd_device1];
1423 const char * be_itf2 = hw_interface_table[snd_device2];
1424
1425 if (NULL != be_itf1 && NULL != be_itf2) {
Eric Laurente63e61d2015-09-10 12:19:33 -07001426 if ((NULL == strstr(be_itf2, be_itf1)) && (NULL == strstr(be_itf1, be_itf2)))
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001427 result = false;
1428 }
1429
1430 ALOGV("%s: be_itf1 = %s, be_itf2 = %s, match %d", __func__, be_itf1, be_itf2, result);
1431 return result;
1432}
1433
Eric Laurentb23d5282013-05-14 15:27:20 -07001434int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
1435{
1436 int device_id;
1437 if (device_type == PCM_PLAYBACK)
1438 device_id = pcm_device_table[usecase][0];
1439 else
1440 device_id = pcm_device_table[usecase][1];
1441 return device_id;
1442}
1443
Haynes Mathew George98c95622014-06-20 19:14:25 -07001444static int find_index(const struct name_to_index * table, int32_t len,
1445 const char * name)
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001446{
1447 int ret = 0;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001448 int32_t i;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001449
Haynes Mathew George98c95622014-06-20 19:14:25 -07001450 if (table == NULL) {
1451 ALOGE("%s: table is NULL", __func__);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001452 ret = -ENODEV;
1453 goto done;
1454 }
1455
Haynes Mathew George98c95622014-06-20 19:14:25 -07001456 if (name == NULL) {
1457 ALOGE("null key");
1458 ret = -ENODEV;
1459 goto done;
1460 }
1461
1462 for (i=0; i < len; i++) {
1463 if (!strcmp(table[i].name, name)) {
1464 ret = table[i].index;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001465 goto done;
1466 }
1467 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001468 ALOGE("%s: Could not find index for name = %s",
1469 __func__, name);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001470 ret = -ENODEV;
1471done:
1472 return ret;
1473}
1474
Haynes Mathew George98c95622014-06-20 19:14:25 -07001475int platform_get_snd_device_index(char *device_name)
1476{
1477 return find_index(snd_device_name_index, SND_DEVICE_MAX, device_name);
1478}
1479
1480int platform_get_usecase_index(const char *usecase_name)
1481{
1482 return find_index(usecase_name_index, AUDIO_USECASE_MAX, usecase_name);
1483}
1484
keunhui.park2f7306a2015-07-16 16:48:06 +09001485void platform_add_operator_specific_device(snd_device_t snd_device,
1486 const char *operator,
1487 const char *mixer_path,
1488 unsigned int acdb_id)
1489{
1490 struct operator_specific_device *device;
1491
1492 if (operator_specific_device_table[snd_device] == NULL) {
1493 operator_specific_device_table[snd_device] =
1494 (struct listnode *)calloc(1, sizeof(struct listnode));
1495 list_init(operator_specific_device_table[snd_device]);
1496 }
1497
1498 device = (struct operator_specific_device *)calloc(1, sizeof(struct operator_specific_device));
1499
1500 device->operator = strdup(operator);
1501 device->mixer_path = strdup(mixer_path);
1502 device->acdb_id = acdb_id;
1503
1504 list_add_tail(operator_specific_device_table[snd_device], &device->list);
1505
Eric Laurent2bafff12016-03-17 12:17:23 -07001506 ALOGD("%s: device[%s] -> operator[%s] mixer_path[%s] acdb_id[%d]", __func__,
keunhui.park2f7306a2015-07-16 16:48:06 +09001507 platform_get_snd_device_name(snd_device), operator, mixer_path, acdb_id);
1508
1509}
1510
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001511int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
1512{
1513 int ret = 0;
1514
1515 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1516 ALOGE("%s: Invalid snd_device = %d",
1517 __func__, snd_device);
1518 ret = -EINVAL;
1519 goto done;
1520 }
1521
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001522 ALOGV("%s: acdb_device_table[%s]: old = %d new = %d", __func__,
1523 platform_get_snd_device_name(snd_device), acdb_device_table[snd_device], acdb_id);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001524 acdb_device_table[snd_device] = acdb_id;
1525done:
1526 return ret;
1527}
1528
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001529int platform_get_snd_device_acdb_id(snd_device_t snd_device)
1530{
1531 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1532 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1533 return -EINVAL;
1534 }
keunhui.park2f7306a2015-07-16 16:48:06 +09001535
1536 if (operator_specific_device_table[snd_device] != NULL)
1537 return get_operator_specific_device_acdb_id(snd_device);
1538 else
1539 return acdb_device_table[snd_device];
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001540}
1541
Eric Laurentb23d5282013-05-14 15:27:20 -07001542int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
1543{
1544 struct platform_data *my_data = (struct platform_data *)platform;
1545 int acdb_dev_id, acdb_dev_type;
1546
Ravi Kumar Alamandaadf0f3b2015-06-04 02:34:02 -07001547 acdb_dev_id = acdb_device_table[audio_extn_get_spkr_prot_snd_device(snd_device)];
Eric Laurentb23d5282013-05-14 15:27:20 -07001548 if (acdb_dev_id < 0) {
1549 ALOGE("%s: Could not find acdb id for device(%d)",
1550 __func__, snd_device);
1551 return -EINVAL;
1552 }
1553 if (my_data->acdb_send_audio_cal) {
Joe Onorato188b6222016-03-01 11:02:27 -08001554 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Eric Laurentb23d5282013-05-14 15:27:20 -07001555 __func__, snd_device, acdb_dev_id);
1556 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
1557 snd_device < SND_DEVICE_OUT_END)
1558 acdb_dev_type = ACDB_DEV_TYPE_OUT;
1559 else
1560 acdb_dev_type = ACDB_DEV_TYPE_IN;
1561 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
1562 }
1563 return 0;
1564}
1565
1566int platform_switch_voice_call_device_pre(void *platform)
1567{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001568 struct platform_data *my_data = (struct platform_data *)platform;
1569 int ret = 0;
1570
1571 if (my_data->csd != NULL &&
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001572 voice_is_in_call(my_data->adev)) {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001573 /* This must be called before disabling mixer controls on APQ side */
1574 ret = my_data->csd->disable_device();
1575 if (ret < 0) {
1576 ALOGE("%s: csd_client_disable_device, failed, error %d",
1577 __func__, ret);
1578 }
1579 }
1580 return ret;
1581}
1582
1583int platform_switch_voice_call_enable_device_config(void *platform,
1584 snd_device_t out_snd_device,
1585 snd_device_t in_snd_device)
1586{
1587 struct platform_data *my_data = (struct platform_data *)platform;
1588 int acdb_rx_id, acdb_tx_id;
1589 int ret = 0;
1590
1591 if (my_data->csd == NULL)
1592 return ret;
1593
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001594 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1595 audio_extn_spkr_prot_is_enabled())
keunhui.park2f7306a2015-07-16 16:48:06 +09001596 acdb_rx_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_SPEAKER_PROTECTED);
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001597 else
keunhui.park2f7306a2015-07-16 16:48:06 +09001598 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001599
keunhui.park2f7306a2015-07-16 16:48:06 +09001600 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001601
1602 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
1603 ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
1604 if (ret < 0) {
1605 ALOGE("%s: csd_enable_device_config, failed, error %d",
1606 __func__, ret);
1607 }
1608 } else {
1609 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1610 acdb_rx_id, acdb_tx_id);
1611 }
1612
1613 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001614}
1615
1616int platform_switch_voice_call_device_post(void *platform,
1617 snd_device_t out_snd_device,
1618 snd_device_t in_snd_device)
1619{
1620 struct platform_data *my_data = (struct platform_data *)platform;
1621 int acdb_rx_id, acdb_tx_id;
1622
1623 if (my_data->acdb_send_voice_cal == NULL) {
1624 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
1625 } else {
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001626 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1627 audio_extn_spkr_prot_is_enabled())
1628 out_snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED;
1629
keunhui.park2f7306a2015-07-16 16:48:06 +09001630 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
1631 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07001632
1633 if (acdb_rx_id > 0 && acdb_tx_id > 0)
1634 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
1635 else
1636 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1637 acdb_rx_id, acdb_tx_id);
1638 }
1639
1640 return 0;
1641}
1642
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001643int platform_switch_voice_call_usecase_route_post(void *platform,
1644 snd_device_t out_snd_device,
1645 snd_device_t in_snd_device)
1646{
1647 struct platform_data *my_data = (struct platform_data *)platform;
1648 int acdb_rx_id, acdb_tx_id;
1649 int ret = 0;
1650
1651 if (my_data->csd == NULL)
1652 return ret;
1653
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001654 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1655 audio_extn_spkr_prot_is_enabled())
keunhui.park2f7306a2015-07-16 16:48:06 +09001656 acdb_rx_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED);
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001657 else
keunhui.park2f7306a2015-07-16 16:48:06 +09001658 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001659
keunhui.park2f7306a2015-07-16 16:48:06 +09001660 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001661
1662 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
1663 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
1664 my_data->adev->acdb_settings);
1665 if (ret < 0) {
1666 ALOGE("%s: csd_enable_device, failed, error %d", __func__, ret);
1667 }
1668 } else {
1669 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1670 acdb_rx_id, acdb_tx_id);
1671 }
1672
1673 return ret;
1674}
1675
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001676int platform_start_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07001677{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001678 struct platform_data *my_data = (struct platform_data *)platform;
1679 int ret = 0;
1680
1681 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001682 ret = my_data->csd->start_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001683 if (ret < 0) {
1684 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
1685 }
1686 }
1687 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001688}
1689
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001690int platform_stop_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07001691{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001692 struct platform_data *my_data = (struct platform_data *)platform;
1693 int ret = 0;
1694
1695 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001696 ret = my_data->csd->stop_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001697 if (ret < 0) {
1698 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
1699 }
1700 }
1701 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001702}
1703
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001704int platform_get_sample_rate(void *platform, uint32_t *rate)
1705{
1706 struct platform_data *my_data = (struct platform_data *)platform;
1707 int ret = 0;
1708
1709 if (my_data->csd != NULL) {
1710 ret = my_data->csd->get_sample_rate(rate);
1711 if (ret < 0) {
1712 ALOGE("%s: csd_get_sample_rate error %d\n", __func__, ret);
1713 }
1714 }
1715 return ret;
1716}
1717
vivek mehtab6506412015-08-07 16:55:17 -07001718void platform_set_speaker_gain_in_combo(struct audio_device *adev,
1719 snd_device_t snd_device,
1720 bool enable)
1721{
1722 const char* name;
1723 switch (snd_device) {
1724 case SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES:
1725 if (enable)
1726 name = "spkr-gain-in-headphone-combo";
1727 else
1728 name = "speaker-gain-default";
1729 break;
1730 case SND_DEVICE_OUT_SPEAKER_AND_LINE:
1731 if (enable)
1732 name = "spkr-gain-in-line-combo";
1733 else
1734 name = "speaker-gain-default";
1735 break;
1736 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES:
1737 if (enable)
1738 name = "spkr-safe-gain-in-headphone-combo";
1739 else
1740 name = "speaker-safe-gain-default";
1741 break;
1742 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE:
1743 if (enable)
1744 name = "spkr-safe-gain-in-line-combo";
1745 else
1746 name = "speaker-safe-gain-default";
1747 break;
1748 default:
1749 return;
1750 }
1751
1752 audio_route_apply_and_update_path(adev->audio_route, name);
1753}
1754
Eric Laurentb23d5282013-05-14 15:27:20 -07001755int platform_set_voice_volume(void *platform, int volume)
1756{
1757 struct platform_data *my_data = (struct platform_data *)platform;
1758 struct audio_device *adev = my_data->adev;
1759 struct mixer_ctl *ctl;
sangwoo53b2cf02013-07-25 19:18:44 -07001760 const char *mixer_ctl_name = "Voice Rx Gain";
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001761 int vol_index = 0, ret = 0;
1762 uint32_t set_values[ ] = {0,
1763 ALL_SESSION_VSID,
1764 DEFAULT_VOLUME_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07001765
1766 // Voice volume levels are mapped to adsp volume levels as follows.
1767 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
1768 // But this values don't changed in kernel. So, below change is need.
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09001769 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, my_data->max_vol_index);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001770 set_values[0] = vol_index;
Eric Laurentb23d5282013-05-14 15:27:20 -07001771
1772 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1773 if (!ctl) {
1774 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1775 __func__, mixer_ctl_name);
1776 return -EINVAL;
1777 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001778 ALOGV("Setting voice volume index: %d", set_values[0]);
1779 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1780
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001781 if (my_data->csd != NULL) {
1782 ret = my_data->csd->volume(ALL_SESSION_VSID, volume,
1783 DEFAULT_VOLUME_RAMP_DURATION_MS);
1784 if (ret < 0) {
1785 ALOGE("%s: csd_volume error %d", __func__, ret);
1786 }
1787 }
1788 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001789}
1790
1791int platform_set_mic_mute(void *platform, bool state)
1792{
1793 struct platform_data *my_data = (struct platform_data *)platform;
1794 struct audio_device *adev = my_data->adev;
1795 struct mixer_ctl *ctl;
1796 const char *mixer_ctl_name = "Voice Tx Mute";
sangwoo53b2cf02013-07-25 19:18:44 -07001797 int ret = 0;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001798 uint32_t set_values[ ] = {0,
1799 ALL_SESSION_VSID,
1800 DEFAULT_MUTE_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07001801
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09001802 if (adev->mode != AUDIO_MODE_IN_CALL &&
1803 adev->mode != AUDIO_MODE_IN_COMMUNICATION)
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001804 return 0;
1805
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09001806 if (adev->enable_hfp)
1807 mixer_ctl_name = "HFP Tx Mute";
1808
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001809 set_values[0] = state;
1810 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1811 if (!ctl) {
1812 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1813 __func__, mixer_ctl_name);
1814 return -EINVAL;
1815 }
1816 ALOGV("Setting voice mute state: %d", state);
1817 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1818
1819 if (my_data->csd != NULL) {
1820 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state,
1821 DEFAULT_MUTE_RAMP_DURATION_MS);
sangwoo53b2cf02013-07-25 19:18:44 -07001822 if (ret < 0) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001823 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
sangwoo53b2cf02013-07-25 19:18:44 -07001824 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001825 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001826 return ret;
1827}
Eric Laurentb23d5282013-05-14 15:27:20 -07001828
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001829int platform_set_device_mute(void *platform, bool state, char *dir)
1830{
1831 struct platform_data *my_data = (struct platform_data *)platform;
1832 struct audio_device *adev = my_data->adev;
1833 struct mixer_ctl *ctl;
1834 char *mixer_ctl_name = NULL;
1835 int ret = 0;
1836 uint32_t set_values[ ] = {0,
1837 ALL_SESSION_VSID,
1838 0};
1839 if(dir == NULL) {
1840 ALOGE("%s: Invalid direction:%s", __func__, dir);
1841 return -EINVAL;
1842 }
1843
1844 if (!strncmp("rx", dir, sizeof("rx"))) {
1845 mixer_ctl_name = "Voice Rx Device Mute";
1846 } else if (!strncmp("tx", dir, sizeof("tx"))) {
1847 mixer_ctl_name = "Voice Tx Device Mute";
1848 } else {
1849 return -EINVAL;
1850 }
1851
1852 set_values[0] = state;
1853 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1854 if (!ctl) {
1855 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1856 __func__, mixer_ctl_name);
1857 return -EINVAL;
1858 }
1859
1860 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
1861 __func__,state, mixer_ctl_name);
1862 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1863
1864 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001865}
1866
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001867bool platform_can_split_snd_device(snd_device_t snd_device,
1868 int *num_devices,
1869 snd_device_t *new_snd_devices)
1870{
1871 bool status = false;
1872
1873 if (NULL == num_devices || NULL == new_snd_devices) {
1874 ALOGE("%s: NULL pointer ..", __func__);
1875 return false;
1876 }
1877
1878 /*
1879 * If wired headset/headphones/line devices share the same backend
1880 * with speaker/earpiece this routine returns false.
1881 */
1882 if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES &&
1883 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_HEADPHONES)) {
1884 *num_devices = 2;
1885 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
1886 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
1887 status = true;
1888 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_LINE &&
1889 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_LINE)) {
1890 *num_devices = 2;
1891 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
1892 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
1893 status = true;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001894 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES &&
1895 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_HEADPHONES)) {
1896 *num_devices = 2;
1897 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
1898 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
1899 status = true;
1900 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE &&
1901 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_LINE)) {
1902 *num_devices = 2;
1903 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
1904 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
1905 status = true;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001906 }
1907 return status;
1908}
1909
Eric Laurentb23d5282013-05-14 15:27:20 -07001910snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
1911{
1912 struct platform_data *my_data = (struct platform_data *)platform;
1913 struct audio_device *adev = my_data->adev;
1914 audio_mode_t mode = adev->mode;
1915 snd_device_t snd_device = SND_DEVICE_NONE;
1916
1917 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
1918 if (devices == AUDIO_DEVICE_NONE ||
1919 devices & AUDIO_DEVICE_BIT_IN) {
1920 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
1921 goto exit;
1922 }
1923
Eric Laurent1b491552015-09-15 17:52:41 -07001924 if (popcount(devices) == 2) {
1925 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
1926 AUDIO_DEVICE_OUT_SPEAKER) ||
1927 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
1928 AUDIO_DEVICE_OUT_SPEAKER)) {
1929 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
1930 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
1931 AUDIO_DEVICE_OUT_SPEAKER)) {
1932 snd_device = SND_DEVICE_OUT_SPEAKER_AND_LINE;
1933 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
1934 AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
1935 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
1936 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
1937 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES;
1938 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
1939 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
1940 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE;
1941 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
1942 AUDIO_DEVICE_OUT_SPEAKER)) {
1943 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
1944 } else {
1945 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
1946 goto exit;
1947 }
1948 if (snd_device != SND_DEVICE_NONE) {
1949 goto exit;
1950 }
1951 }
1952
1953 if (popcount(devices) != 1) {
1954 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
1955 goto exit;
1956 }
1957
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001958 if (voice_is_in_call(adev) || adev->enable_voicerx) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001959 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05001960 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
1961 devices & AUDIO_DEVICE_OUT_LINE) {
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001962 if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05001963 (adev->voice.tty_mode == TTY_MODE_FULL))
Eric Laurentb23d5282013-05-14 15:27:20 -07001964 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001965 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05001966 (adev->voice.tty_mode == TTY_MODE_VCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07001967 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001968 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05001969 (adev->voice.tty_mode == TTY_MODE_HCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07001970 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05001971 else {
1972 if (devices & AUDIO_DEVICE_OUT_LINE)
1973 snd_device = SND_DEVICE_OUT_VOICE_LINE;
1974 else
1975 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
1976 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001977 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07001978 if (adev->bt_wb_speech_enabled) {
1979 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
1980 } else {
1981 snd_device = SND_DEVICE_OUT_BT_SCO;
1982 }
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07001983 } else if (devices & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07001984 if (!adev->enable_hfp) {
1985 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
1986 } else {
1987 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_HFP;
1988 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001989 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05001990 if(adev->voice.hac)
1991 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
1992 else if (is_operator_tmus())
Eric Laurentb23d5282013-05-14 15:27:20 -07001993 snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS;
1994 else
Eric Laurentb4d368e2014-06-25 10:21:54 -05001995 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07001996 } else if (devices & AUDIO_DEVICE_OUT_TELEPHONY_TX)
1997 snd_device = SND_DEVICE_OUT_VOICE_TX;
1998
Eric Laurentb23d5282013-05-14 15:27:20 -07001999 if (snd_device != SND_DEVICE_NONE) {
2000 goto exit;
2001 }
2002 }
2003
Eric Laurentb23d5282013-05-14 15:27:20 -07002004 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2005 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2006 snd_device = SND_DEVICE_OUT_HEADPHONES;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002007 } else if (devices & AUDIO_DEVICE_OUT_LINE) {
2008 snd_device = SND_DEVICE_OUT_LINE;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002009 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) {
2010 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE;
Eric Laurentb23d5282013-05-14 15:27:20 -07002011 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002012 if (my_data->speaker_lr_swap)
Eric Laurentb23d5282013-05-14 15:27:20 -07002013 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
2014 else
2015 snd_device = SND_DEVICE_OUT_SPEAKER;
2016 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002017 if (adev->bt_wb_speech_enabled) {
2018 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2019 } else {
2020 snd_device = SND_DEVICE_OUT_BT_SCO;
2021 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002022 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2023 snd_device = SND_DEVICE_OUT_HDMI ;
2024 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002025 /*HAC support for voice-ish audio (eg visual voicemail)*/
2026 if(adev->voice.hac)
2027 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2028 else
2029 snd_device = SND_DEVICE_OUT_HANDSET;
Eric Laurentb23d5282013-05-14 15:27:20 -07002030 } else {
2031 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
2032 }
2033exit:
2034 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
2035 return snd_device;
2036}
2037
2038snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
2039{
2040 struct platform_data *my_data = (struct platform_data *)platform;
2041 struct audio_device *adev = my_data->adev;
2042 audio_source_t source = (adev->active_input == NULL) ?
2043 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
2044
2045 audio_mode_t mode = adev->mode;
2046 audio_devices_t in_device = ((adev->active_input == NULL) ?
2047 AUDIO_DEVICE_NONE : adev->active_input->device)
2048 & ~AUDIO_DEVICE_BIT_IN;
2049 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
2050 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
2051 snd_device_t snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002052 int channel_count = popcount(channel_mask);
Eric Laurentb23d5282013-05-14 15:27:20 -07002053
Prashant Malanic92c5962015-08-11 15:10:18 -07002054 ALOGV("%s: enter: out_device(%#x) in_device(%#x) channel_count (%d) channel_mask (0x%x)",
2055 __func__, out_device, in_device, channel_count, channel_mask);
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002056 if ((out_device != AUDIO_DEVICE_NONE) && voice_is_in_call(adev)) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002057 if (adev->voice.tty_mode != TTY_MODE_OFF) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002058 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002059 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2060 out_device & AUDIO_DEVICE_OUT_LINE) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002061 switch (adev->voice.tty_mode) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002062 case TTY_MODE_FULL:
2063 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
2064 break;
2065 case TTY_MODE_VCO:
2066 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
2067 break;
2068 case TTY_MODE_HCO:
2069 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
2070 break;
2071 default:
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002072 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
Eric Laurentb23d5282013-05-14 15:27:20 -07002073 }
2074 goto exit;
2075 }
2076 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002077 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002078 if (my_data->fluence_in_voice_call == false) {
2079 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2080 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002081 if (is_operator_tmus())
2082 snd_device = SND_DEVICE_IN_VOICE_DMIC_TMUS;
Eric Laurentb23d5282013-05-14 15:27:20 -07002083 else
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002084 snd_device = SND_DEVICE_IN_VOICE_DMIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002085 }
2086 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2087 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
2088 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002089 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002090 if (adev->bluetooth_nrec)
2091 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2092 else
2093 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002094 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002095 if (adev->bluetooth_nrec)
2096 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2097 else
2098 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002099 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002100 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Prashant Malanic92c5962015-08-11 15:10:18 -07002101 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
2102 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2103 out_device & AUDIO_DEVICE_OUT_LINE) {
2104 if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
2105 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
2106 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
2107 } else {
2108 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2109 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002110 }
vivek mehtafe121d52015-08-10 23:39:23 -07002111
2112 //select default
2113 if (snd_device == SND_DEVICE_NONE) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002114 if (!adev->enable_hfp) {
2115 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2116 } else {
2117 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP;
2118 platform_set_echo_reference(adev, true, out_device);
2119 }
vivek mehtafe121d52015-08-10 23:39:23 -07002120 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002121 } else if (out_device & AUDIO_DEVICE_OUT_TELEPHONY_TX) {
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002122 snd_device = SND_DEVICE_IN_VOICE_RX;
Prashant Malanic92c5962015-08-11 15:10:18 -07002123 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002124 } else if (source == AUDIO_SOURCE_CAMCORDER) {
2125 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
2126 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2127 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
2128 }
2129 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
2130 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002131 if (my_data->fluence_in_voice_rec && channel_count == 1) {
2132 if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2133 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002134 if (adev->active_input->enable_aec)
2135 snd_device = SND_DEVICE_IN_HANDSET_QMIC_AEC;
2136 else
2137 snd_device = SND_DEVICE_IN_HANDSET_QMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002138 } else if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2139 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002140 if (adev->active_input->enable_aec)
2141 snd_device = SND_DEVICE_IN_HANDSET_TMIC_AEC;
2142 else
2143 snd_device = SND_DEVICE_IN_HANDSET_TMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002144 } else if (((my_data->fluence_type == FLUENCE_PRO_ENABLE) ||
2145 (my_data->fluence_type == FLUENCE_ENABLE)) &&
2146 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002147 if (adev->active_input->enable_aec)
2148 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
2149 else
2150 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
Prashant Malanic92c5962015-08-11 15:10:18 -07002151 }
2152 platform_set_echo_reference(adev, true, out_device);
2153 } else if ((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) &&
2154 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2155 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
2156 } else if (((int)channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
2157 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
2158 snd_device = SND_DEVICE_IN_THREE_MIC;
2159 } else if (((int)channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
2160 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2161 snd_device = SND_DEVICE_IN_QUAD_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002162 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002163 if (snd_device == SND_DEVICE_NONE) {
vivek mehtaf3440682016-05-11 14:24:37 -07002164 if (adev->active_input->enable_aec) {
2165 if (adev->active_input->enable_ns) {
2166 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS;
2167 } else {
2168 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC;
2169 }
vivek mehta733c1df2016-04-04 15:09:24 -07002170 platform_set_echo_reference(adev, true, out_device);
vivek mehtaf3440682016-05-11 14:24:37 -07002171 } else if (adev->active_input->enable_ns) {
2172 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
2173 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002174 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
vivek mehtaf3440682016-05-11 14:24:37 -07002175 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002176 }
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -07002177 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2178 snd_device = SND_DEVICE_IN_VOICE_REC_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002179 }
rago90fb9612015-12-02 11:37:53 -08002180 } else if (source == AUDIO_SOURCE_UNPROCESSED) {
2181 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
vivek mehta4ed66e62016-04-15 23:33:34 -07002182 if (((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) ||
2183 (channel_mask == AUDIO_CHANNEL_IN_STEREO)) &&
2184 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2185 snd_device = SND_DEVICE_IN_UNPROCESSED_STEREO_MIC;
2186 } else if (((int)channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
2187 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
2188 snd_device = SND_DEVICE_IN_UNPROCESSED_THREE_MIC;
2189 } else if (((int)channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
2190 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2191 snd_device = SND_DEVICE_IN_UNPROCESSED_QUAD_MIC;
2192 } else {
2193 snd_device = SND_DEVICE_IN_UNPROCESSED_MIC;
2194 }
rago90fb9612015-12-02 11:37:53 -08002195 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2196 snd_device = SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC;
2197 }
Eric Laurent50a38ed2015-10-14 18:48:06 -07002198 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION ||
rago90fb9612015-12-02 11:37:53 -08002199 mode == AUDIO_MODE_IN_COMMUNICATION) {
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002200 if (out_device & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE))
Eric Laurentb23d5282013-05-14 15:27:20 -07002201 in_device = AUDIO_DEVICE_IN_BACK_MIC;
2202 if (adev->active_input) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002203 if (adev->active_input->enable_aec &&
2204 adev->active_input->enable_ns) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002205 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002206 if (my_data->fluence_in_spkr_mode &&
2207 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002208 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002209 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002210 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002211 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002212 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002213 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002214 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002215 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002216 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002217 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002218 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002219 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002220 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2221 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002222 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002223 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002224 } else if (adev->active_input->enable_aec) {
2225 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2226 if (my_data->fluence_in_spkr_mode &&
2227 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002228 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002229 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002230 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002231 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002232 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002233 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2234 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002235 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002236 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002237 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002238 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002239 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002240 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2241 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
2242 }
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08002243 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002244 } else if (adev->active_input->enable_ns) {
2245 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2246 if (my_data->fluence_in_spkr_mode &&
2247 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002248 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002249 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002250 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002251 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002252 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002253 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2254 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002255 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002256 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002257 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002258 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002259 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002260 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002261 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002262 }
2263 } else if (source == AUDIO_SOURCE_DEFAULT) {
2264 goto exit;
2265 }
2266
2267
2268 if (snd_device != SND_DEVICE_NONE) {
2269 goto exit;
2270 }
2271
2272 if (in_device != AUDIO_DEVICE_NONE &&
2273 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
2274 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
2275 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002276 if ((my_data->source_mic_type & SOURCE_QUAD_MIC) &&
2277 (int)channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) {
2278 snd_device = SND_DEVICE_IN_QUAD_MIC;
2279 } else if ((my_data->source_mic_type & SOURCE_THREE_MIC) &&
2280 (int)channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) {
2281 snd_device = SND_DEVICE_IN_THREE_MIC;
2282 } else if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2283 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002284 snd_device = SND_DEVICE_IN_HANDSET_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002285 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2286 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002287 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002288 } else {
2289 ALOGE("%s: something wrong (1): source type (%d) channel_count (%d) .."
2290 " channel mask (0x%x) no combination found .. setting to mono", __func__,
2291 my_data->source_mic_type, channel_count, channel_mask);
2292 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2293 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002294 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002295 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2296 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002297 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002298 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2299 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002300 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002301 } else {
2302 ALOGE("%s: something wrong (2): source type (%d) channel_count (%d) .."
2303 " no combination found .. setting to mono", __func__,
2304 my_data->source_mic_type, channel_count);
2305 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
2306 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002307 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2308 snd_device = SND_DEVICE_IN_HEADSET_MIC;
2309 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002310 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002311 if (adev->bluetooth_nrec)
2312 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2313 else
2314 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002315 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002316 if (adev->bluetooth_nrec)
2317 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2318 else
2319 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002320 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002321 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
2322 snd_device = SND_DEVICE_IN_HDMI_MIC;
2323 } else {
2324 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
2325 ALOGW("%s: Using default handset-mic", __func__);
2326 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2327 }
2328 } else {
2329 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
2330 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2331 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2332 snd_device = SND_DEVICE_IN_HEADSET_MIC;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002333 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002334 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002335 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002336 out_device & AUDIO_DEVICE_OUT_LINE) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002337 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2338 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002339 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002340 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2341 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002342 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002343 } else {
2344 ALOGE("%s: something wrong (3): source type (%d) channel_count (%d) .."
2345 " no combination found .. setting to mono", __func__,
2346 my_data->source_mic_type, channel_count);
2347 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
2348 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002349 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002350 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002351 if (adev->bluetooth_nrec)
2352 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2353 else
2354 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002355 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002356 if (adev->bluetooth_nrec)
2357 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2358 else
2359 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002360 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002361 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2362 snd_device = SND_DEVICE_IN_HDMI_MIC;
2363 } else {
2364 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
2365 ALOGW("%s: Using default handset-mic", __func__);
2366 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2367 }
2368 }
2369exit:
2370 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
2371 return snd_device;
2372}
2373
2374int platform_set_hdmi_channels(void *platform, int channel_count)
2375{
2376 struct platform_data *my_data = (struct platform_data *)platform;
2377 struct audio_device *adev = my_data->adev;
2378 struct mixer_ctl *ctl;
2379 const char *channel_cnt_str = NULL;
2380 const char *mixer_ctl_name = "HDMI_RX Channels";
2381 switch (channel_count) {
2382 case 8:
2383 channel_cnt_str = "Eight"; break;
2384 case 7:
2385 channel_cnt_str = "Seven"; break;
2386 case 6:
2387 channel_cnt_str = "Six"; break;
2388 case 5:
2389 channel_cnt_str = "Five"; break;
2390 case 4:
2391 channel_cnt_str = "Four"; break;
2392 case 3:
2393 channel_cnt_str = "Three"; break;
2394 default:
2395 channel_cnt_str = "Two"; break;
2396 }
2397 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2398 if (!ctl) {
2399 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2400 __func__, mixer_ctl_name);
2401 return -EINVAL;
2402 }
2403 ALOGV("HDMI channel count: %s", channel_cnt_str);
2404 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
2405 return 0;
2406}
2407
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002408int platform_edid_get_max_channels(void *platform)
Eric Laurentb23d5282013-05-14 15:27:20 -07002409{
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002410 struct platform_data *my_data = (struct platform_data *)platform;
2411 struct audio_device *adev = my_data->adev;
Eric Laurentb23d5282013-05-14 15:27:20 -07002412 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
2413 char *sad = block;
2414 int num_audio_blocks;
2415 int channel_count;
2416 int max_channels = 0;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002417 int i, ret, count;
Eric Laurentb23d5282013-05-14 15:27:20 -07002418
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002419 struct mixer_ctl *ctl;
2420
2421 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
2422 if (!ctl) {
2423 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2424 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
Eric Laurentb23d5282013-05-14 15:27:20 -07002425 return 0;
2426 }
2427
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002428 mixer_ctl_update(ctl);
2429
2430 count = mixer_ctl_get_num_values(ctl);
Eric Laurentb23d5282013-05-14 15:27:20 -07002431
2432 /* Read SAD blocks, clamping the maximum size for safety */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002433 if (count > (int)sizeof(block))
2434 count = (int)sizeof(block);
Eric Laurentb23d5282013-05-14 15:27:20 -07002435
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002436 ret = mixer_ctl_get_array(ctl, block, count);
2437 if (ret != 0) {
2438 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
2439 return 0;
2440 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002441
2442 /* Calculate the number of SAD blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002443 num_audio_blocks = count / SAD_BLOCK_SIZE;
Eric Laurentb23d5282013-05-14 15:27:20 -07002444
2445 for (i = 0; i < num_audio_blocks; i++) {
2446 /* Only consider LPCM blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002447 if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
2448 sad += 3;
Eric Laurentb23d5282013-05-14 15:27:20 -07002449 continue;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002450 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002451
2452 channel_count = (sad[0] & 0x7) + 1;
2453 if (channel_count > max_channels)
2454 max_channels = channel_count;
2455
2456 /* Advance to next block */
2457 sad += 3;
2458 }
2459
2460 return max_channels;
2461}
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07002462
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002463int platform_set_incall_recording_session_id(void *platform,
2464 uint32_t session_id, int rec_mode)
2465{
2466 int ret = 0;
2467 struct platform_data *my_data = (struct platform_data *)platform;
2468 struct audio_device *adev = my_data->adev;
2469 struct mixer_ctl *ctl;
2470 const char *mixer_ctl_name = "Voc VSID";
2471 int num_ctl_values;
2472 int i;
2473
2474 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2475 if (!ctl) {
2476 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2477 __func__, mixer_ctl_name);
2478 ret = -EINVAL;
2479 } else {
2480 num_ctl_values = mixer_ctl_get_num_values(ctl);
2481 for (i = 0; i < num_ctl_values; i++) {
2482 if (mixer_ctl_set_value(ctl, i, session_id)) {
2483 ALOGV("Error: invalid session_id: %x", session_id);
2484 ret = -EINVAL;
2485 break;
2486 }
2487 }
2488 }
2489
2490 if (my_data->csd != NULL) {
2491 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
2492 if (ret < 0) {
2493 ALOGE("%s: csd_client_start_record failed, error %d",
2494 __func__, ret);
2495 }
2496 }
2497
2498 return ret;
2499}
2500
2501int platform_stop_incall_recording_usecase(void *platform)
2502{
2503 int ret = 0;
2504 struct platform_data *my_data = (struct platform_data *)platform;
2505
2506 if (my_data->csd != NULL) {
2507 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
2508 if (ret < 0) {
2509 ALOGE("%s: csd_client_stop_record failed, error %d",
2510 __func__, ret);
2511 }
2512 }
2513
2514 return ret;
2515}
2516
2517int platform_start_incall_music_usecase(void *platform)
2518{
2519 int ret = 0;
2520 struct platform_data *my_data = (struct platform_data *)platform;
2521
2522 if (my_data->csd != NULL) {
2523 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
2524 if (ret < 0) {
2525 ALOGE("%s: csd_client_start_playback failed, error %d",
2526 __func__, ret);
2527 }
2528 }
2529
2530 return ret;
2531}
2532
2533int platform_stop_incall_music_usecase(void *platform)
2534{
2535 int ret = 0;
2536 struct platform_data *my_data = (struct platform_data *)platform;
2537
2538 if (my_data->csd != NULL) {
2539 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
2540 if (ret < 0) {
2541 ALOGE("%s: csd_client_stop_playback failed, error %d",
2542 __func__, ret);
2543 }
2544 }
2545
2546 return ret;
2547}
2548
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002549int platform_set_parameters(void *platform, struct str_parms *parms)
2550{
2551 struct platform_data *my_data = (struct platform_data *)platform;
keunhui.park2f7306a2015-07-16 16:48:06 +09002552 char value[128];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002553 char *kv_pairs = str_parms_to_str(parms);
2554 int ret = 0, err;
2555
2556 if (kv_pairs == NULL) {
2557 ret = -EINVAL;
2558 ALOGE("%s: key-value pair is NULL",__func__);
2559 goto done;
2560 }
2561
2562 ALOGV("%s: enter: %s", __func__, kv_pairs);
2563
2564 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME,
2565 value, sizeof(value));
2566 if (err >= 0) {
2567 str_parms_del(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME);
2568 my_data->snd_card_name = strdup(value);
2569 ALOGV("%s: sound card name %s", __func__, my_data->snd_card_name);
2570 }
2571
keunhui.park2f7306a2015-07-16 16:48:06 +09002572 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO,
2573 value, sizeof(value));
2574 if (err >= 0) {
2575 struct operator_info *info;
2576 char *str = value;
2577 char *name;
2578
2579 str_parms_del(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO);
2580 info = (struct operator_info *)calloc(1, sizeof(struct operator_info));
2581 name = strtok(str, ";");
2582 info->name = strdup(name);
2583 info->mccmnc = strdup(str + strlen(name) + 1);
2584
2585 list_add_tail(&operator_info_list, &info->list);
Joe Onorato188b6222016-03-01 11:02:27 -08002586 ALOGV("%s: add operator[%s] mccmnc[%s]", __func__, info->name, info->mccmnc);
keunhui.park2f7306a2015-07-16 16:48:06 +09002587 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002588
2589 memset(value, 0, sizeof(value));
Eric Laurentc6333382015-09-14 12:43:44 -07002590 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT,
Prashant Malanic92c5962015-08-11 15:10:18 -07002591 value, sizeof(value));
2592 if (err >= 0) {
Eric Laurentc6333382015-09-14 12:43:44 -07002593 str_parms_del(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT);
Prashant Malanic92c5962015-08-11 15:10:18 -07002594 my_data->max_mic_count = atoi(value);
2595 ALOGV("%s: max_mic_count %s/%d", __func__, value, my_data->max_mic_count);
Prashant Malanic92c5962015-08-11 15:10:18 -07002596 }
2597
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002598done:
2599 ALOGV("%s: exit with code(%d)", __func__, ret);
2600 if (kv_pairs != NULL)
2601 free(kv_pairs);
2602
2603 return ret;
2604}
2605
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07002606/* Delay in Us */
2607int64_t platform_render_latency(audio_usecase_t usecase)
2608{
2609 switch (usecase) {
2610 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
2611 return DEEP_BUFFER_PLATFORM_DELAY;
2612 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
2613 return LOW_LATENCY_PLATFORM_DELAY;
Haynes Mathew George03c40102016-01-29 17:57:48 -08002614 case USECASE_AUDIO_PLAYBACK_ULL:
2615 return ULL_PLATFORM_DELAY;
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07002616 default:
2617 return 0;
2618 }
2619}
Haynes Mathew George98c95622014-06-20 19:14:25 -07002620
vivek mehta4ed66e62016-04-15 23:33:34 -07002621bool platform_check_and_set_capture_backend_cfg(struct audio_device* adev,
David Benjaminc9d8d892016-09-21 12:04:55 -04002622 struct audio_usecase *usecase __unused,
2623 snd_device_t snd_device __unused)
vivek mehta4ed66e62016-04-15 23:33:34 -07002624{
2625 enum pcm_format in_pcm_format = PCM_FORMAT_S16_LE;
2626
2627 if (adev && adev->active_input)
2628 in_pcm_format = adev->active_input->config.format;
2629
2630 // allow 24 bit recording only if voice call is not active
2631 if (!voice_is_in_call(adev) &&
2632 adev->mode != AUDIO_MODE_IN_COMMUNICATION &&
2633 in_pcm_format == PCM_FORMAT_S24_LE) {
2634 audio_route_apply_and_update_path(adev->audio_route, "set-capture-format-24le");
2635 } else {
2636 audio_route_apply_and_update_path(adev->audio_route, "set-capture-format-default");
2637 }
2638
2639 return true;
2640}
2641
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002642int platform_set_snd_device_backend(snd_device_t device, const char *backend_tag,
2643 const char * hw_interface)
Haynes Mathew George98c95622014-06-20 19:14:25 -07002644{
2645 int ret = 0;
2646
2647 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
2648 ALOGE("%s: Invalid snd_device = %d",
2649 __func__, device);
2650 ret = -EINVAL;
2651 goto done;
2652 }
2653
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002654 ALOGV("%s: backend_tag_table[%s]: old = %s new = %s", __func__,
2655 platform_get_snd_device_name(device),
2656 backend_tag_table[device] != NULL ? backend_tag_table[device]: "null", backend_tag);
2657 if (backend_tag_table[device]) {
2658 free(backend_tag_table[device]);
Haynes Mathew George98c95622014-06-20 19:14:25 -07002659 }
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002660 backend_tag_table[device] = strdup(backend_tag);
2661
2662 if (hw_interface != NULL) {
2663 if (hw_interface_table[device])
2664 free(hw_interface_table[device]);
2665 ALOGV("%s: hw_interface_table[%d] = %s", __func__, device, hw_interface);
2666 hw_interface_table[device] = strdup(hw_interface);
2667 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07002668done:
2669 return ret;
2670}
2671
2672int platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t pcm_id)
2673{
2674 int ret = 0;
2675 if ((usecase <= USECASE_INVALID) || (usecase >= AUDIO_USECASE_MAX)) {
2676 ALOGE("%s: invalid usecase case idx %d", __func__, usecase);
2677 ret = -EINVAL;
2678 goto done;
2679 }
2680
2681 if ((type != 0) && (type != 1)) {
2682 ALOGE("%s: invalid usecase type", __func__);
2683 ret = -EINVAL;
2684 }
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002685 ALOGV("%s: pcm_device_table[%d][%d] = %d", __func__, usecase, type, pcm_id);
Haynes Mathew George98c95622014-06-20 19:14:25 -07002686 pcm_device_table[usecase][type] = pcm_id;
2687done:
2688 return ret;
2689}
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002690
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07002691#define DEFAULT_NOMINAL_SPEAKER_GAIN 20
2692int ramp_speaker_gain(struct audio_device *adev, bool ramp_up, int target_ramp_up_gain) {
2693 // backup_gain: gain to try to set in case of an error during ramp
2694 int start_gain, end_gain, step, backup_gain, i;
2695 bool error = false;
2696 const struct mixer_ctl *ctl;
2697 const char *mixer_ctl_name_gain_left = "Left Speaker Gain";
2698 const char *mixer_ctl_name_gain_right = "Right Speaker Gain";
2699 struct mixer_ctl *ctl_left = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_left);
2700 struct mixer_ctl *ctl_right = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_right);
2701 if (!ctl_left || !ctl_right) {
2702 ALOGE("%s: Could not get ctl for mixer cmd - %s or %s, not applying speaker gain ramp",
2703 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
2704 return -EINVAL;
2705 } else if ((mixer_ctl_get_num_values(ctl_left) != 1)
2706 || (mixer_ctl_get_num_values(ctl_right) != 1)) {
2707 ALOGE("%s: Unexpected num values for mixer cmd - %s or %s, not applying speaker gain ramp",
2708 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
2709 return -EINVAL;
2710 }
2711 if (ramp_up) {
2712 start_gain = 0;
2713 end_gain = target_ramp_up_gain > 0 ? target_ramp_up_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
2714 step = +1;
2715 backup_gain = end_gain;
2716 } else {
2717 // using same gain on left and right
2718 const int left_gain = mixer_ctl_get_value(ctl_left, 0);
2719 start_gain = left_gain > 0 ? left_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
2720 end_gain = 0;
2721 step = -1;
2722 backup_gain = start_gain;
2723 }
2724 for (i = start_gain ; i != (end_gain + step) ; i += step) {
2725 //ALOGV("setting speaker gain to %d", i);
2726 if (mixer_ctl_set_value(ctl_left, 0, i)) {
2727 ALOGE("%s: error setting %s to %d during gain ramp",
2728 __func__, mixer_ctl_name_gain_left, i);
2729 error = true;
2730 break;
2731 }
2732 if (mixer_ctl_set_value(ctl_right, 0, i)) {
2733 ALOGE("%s: error setting %s to %d during gain ramp",
2734 __func__, mixer_ctl_name_gain_right, i);
2735 error = true;
2736 break;
2737 }
2738 usleep(1000);
2739 }
2740 if (error) {
2741 // an error occured during the ramp, let's still try to go back to a safe volume
2742 if (mixer_ctl_set_value(ctl_left, 0, backup_gain)) {
2743 ALOGE("%s: error restoring left gain to %d", __func__, backup_gain);
2744 }
2745 if (mixer_ctl_set_value(ctl_right, 0, backup_gain)) {
2746 ALOGE("%s: error restoring right gain to %d", __func__, backup_gain);
2747 }
2748 }
2749 return start_gain;
2750}
2751
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002752int platform_swap_lr_channels(struct audio_device *adev, bool swap_channels)
2753{
2754 // only update if there is active pcm playback on speaker
2755 struct audio_usecase *usecase;
2756 struct listnode *node;
2757 struct platform_data *my_data = (struct platform_data *)adev->platform;
2758
2759 if (my_data->speaker_lr_swap != swap_channels) {
2760 my_data->speaker_lr_swap = swap_channels;
2761
2762 list_for_each(node, &adev->usecase_list) {
2763 usecase = node_to_item(node, struct audio_usecase, list);
2764 if (usecase->type == PCM_PLAYBACK &&
Ravi Kumar Alamanda425e1542015-09-22 09:11:18 -07002765 usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) {
2766 /*
2767 * If acdb tuning is different for SPEAKER_REVERSE, it is must
2768 * to perform device switch to disable the current backend to
2769 * enable it with new acdb data.
2770 */
2771 if (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
2772 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]) {
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07002773 const int initial_skpr_gain = ramp_speaker_gain(adev, false /*ramp_up*/, -1);
Ravi Kumar Alamanda425e1542015-09-22 09:11:18 -07002774 select_devices(adev, usecase->id);
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07002775 if (initial_skpr_gain != -EINVAL) {
2776 ramp_speaker_gain(adev, true /*ramp_up*/, initial_skpr_gain);
2777 }
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002778 } else {
Ravi Kumar Alamanda425e1542015-09-22 09:11:18 -07002779 const char *mixer_path;
2780 if (swap_channels) {
2781 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER_REVERSE);
2782 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
2783 } else {
2784 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER);
2785 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
2786 }
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002787 }
2788 break;
2789 }
2790 }
2791 }
2792 return 0;
2793}
vivek mehtaa8d7c922016-05-25 14:40:44 -07002794
2795static struct amp_db_and_gain_table tbl_mapping[MAX_VOLUME_CAL_STEPS];
2796static int num_gain_tbl_entry = 0;
2797
2798bool platform_add_gain_level_mapping(struct amp_db_and_gain_table *tbl_entry) {
2799
2800 ALOGV("%s: enter .. add %f %f %d", __func__, tbl_entry->amp, tbl_entry->db, tbl_entry->level);
2801 if (num_gain_tbl_entry == -1) {
2802 ALOGE("%s: num entry beyond valid step levels or corrupted..rejecting custom mapping",
2803 __func__);
2804 return false;
2805 }
2806
2807 if (num_gain_tbl_entry >= MAX_VOLUME_CAL_STEPS) {
2808 ALOGE("%s: max entry reached max[%d] current index[%d] .. rejecting", __func__,
2809 MAX_VOLUME_CAL_STEPS, num_gain_tbl_entry);
2810 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
2811 return false;
2812 }
2813
2814 if (num_gain_tbl_entry > 0 && tbl_mapping[num_gain_tbl_entry - 1].amp >= tbl_entry->amp) {
2815 ALOGE("%s: value not in ascending order .. rejecting custom mapping", __func__);
2816 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
2817 return false;
2818 }
2819
2820 tbl_mapping[num_gain_tbl_entry] = *tbl_entry;
2821 ++num_gain_tbl_entry;
2822
2823 return true;
2824}
2825
2826int platform_get_gain_level_mapping(struct amp_db_and_gain_table *mapping_tbl,
2827 int table_size) {
2828 int itt = 0;
2829 ALOGV("platform_get_gain_level_mapping called ");
2830
2831 if (num_gain_tbl_entry <= 0 || num_gain_tbl_entry > MAX_VOLUME_CAL_STEPS) {
2832 ALOGD("%s: empty or currupted gain_mapping_table", __func__);
2833 return 0;
2834 }
2835
2836 for (; itt < num_gain_tbl_entry && itt <= table_size; itt++) {
2837 mapping_tbl[itt] = tbl_mapping[itt];
2838 ALOGV("%s: added amp[%f] db[%f] level[%d]", __func__,
2839 mapping_tbl[itt].amp, mapping_tbl[itt].db, mapping_tbl[itt].level);
2840 }
2841
2842 return num_gain_tbl_entry;
2843}
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07002844
2845int platform_snd_card_update(void *platform, card_status_t status)
2846{
2847 struct platform_data *my_data = (struct platform_data *)platform;
2848 struct audio_device *adev = my_data->adev;
2849
2850 if (status == CARD_STATUS_ONLINE) {
2851 if (my_data->acdb_send_custom_top)
2852 my_data->acdb_send_custom_top();
2853 }
2854 return 0;
2855}