blob: 789824bb9ac8fec9d6b354312265ac7909ef13b4 [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);
Eric Laurentb23d5282013-05-14 15:27:20 -0700108
109/* Audio calibration related functions */
110struct platform_data {
111 struct audio_device *adev;
112 bool fluence_in_spkr_mode;
113 bool fluence_in_voice_call;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700114 bool fluence_in_voice_comm;
Eric Laurentb23d5282013-05-14 15:27:20 -0700115 bool fluence_in_voice_rec;
Prashant Malanic92c5962015-08-11 15:10:18 -0700116 /* 0 = no fluence, 1 = fluence, 2 = fluence pro */
117 int fluence_type;
118 int source_mic_type;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -0700119 bool speaker_lr_swap;
120
Eric Laurentb23d5282013-05-14 15:27:20 -0700121 void *acdb_handle;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700122 acdb_deallocate_t acdb_deallocate;
123 acdb_send_audio_cal_t acdb_send_audio_cal;
124 acdb_send_voice_cal_t acdb_send_voice_cal;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700125 acdb_reload_vocvoltable_t acdb_reload_vocvoltable;
vivek mehta1a9b7c02015-06-25 11:49:38 -0700126 acdb_send_gain_dep_cal_t acdb_send_gain_dep_cal;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700127 struct csd_data *csd;
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800128 char ec_ref_mixer_path[64];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700129
130 char *snd_card_name;
keunhui.parkc5aaa0e2015-07-13 10:57:37 +0900131 int max_vol_index;
Prashant Malanic92c5962015-08-11 15:10:18 -0700132 int max_mic_count;
vivek mehtade4849c2016-03-03 17:23:38 -0800133
134 void *hw_info;
Eric Laurentb23d5282013-05-14 15:27:20 -0700135};
136
Haynes Mathew George98c95622014-06-20 19:14:25 -0700137static int pcm_device_table[AUDIO_USECASE_MAX][2] = {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700138 [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = {DEEP_BUFFER_PCM_DEVICE,
139 DEEP_BUFFER_PCM_DEVICE},
140 [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
141 LOWLATENCY_PCM_DEVICE},
142 [USECASE_AUDIO_PLAYBACK_MULTI_CH] = {MULTIMEDIA2_PCM_DEVICE,
143 MULTIMEDIA2_PCM_DEVICE},
144 [USECASE_AUDIO_PLAYBACK_OFFLOAD] = {PLAYBACK_OFFLOAD_DEVICE,
145 PLAYBACK_OFFLOAD_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700146 [USECASE_AUDIO_PLAYBACK_TTS] = {MULTIMEDIA2_PCM_DEVICE,
147 MULTIMEDIA2_PCM_DEVICE},
148 [USECASE_AUDIO_PLAYBACK_ULL] = {MULTIMEDIA3_PCM_DEVICE,
149 MULTIMEDIA3_PCM_DEVICE},
150
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700151 [USECASE_AUDIO_RECORD] = {AUDIO_RECORD_PCM_DEVICE,
152 AUDIO_RECORD_PCM_DEVICE},
153 [USECASE_AUDIO_RECORD_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
154 LOWLATENCY_PCM_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700155
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700156 [USECASE_VOICE_CALL] = {VOICE_CALL_PCM_DEVICE,
157 VOICE_CALL_PCM_DEVICE},
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700158 [USECASE_VOICE2_CALL] = {VOICE2_CALL_PCM_DEVICE, VOICE2_CALL_PCM_DEVICE},
159 [USECASE_VOLTE_CALL] = {VOLTE_CALL_PCM_DEVICE, VOLTE_CALL_PCM_DEVICE},
160 [USECASE_QCHAT_CALL] = {QCHAT_CALL_PCM_DEVICE, QCHAT_CALL_PCM_DEVICE},
161 [USECASE_VOWLAN_CALL] = {VOWLAN_CALL_PCM_DEVICE, VOWLAN_CALL_PCM_DEVICE},
vivek mehtaa51fd402016-02-04 19:49:33 -0800162 [USECASE_VOICEMMODE1_CALL] = {VOICEMMODE1_CALL_PCM_DEVICE,
163 VOICEMMODE1_CALL_PCM_DEVICE},
164 [USECASE_VOICEMMODE2_CALL] = {VOICEMMODE2_CALL_PCM_DEVICE,
165 VOICEMMODE2_CALL_PCM_DEVICE},
166
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700167 [USECASE_INCALL_REC_UPLINK] = {AUDIO_RECORD_PCM_DEVICE,
168 AUDIO_RECORD_PCM_DEVICE},
169 [USECASE_INCALL_REC_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
170 AUDIO_RECORD_PCM_DEVICE},
171 [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
172 AUDIO_RECORD_PCM_DEVICE},
Ravi Kumar Alamanda8e6e98f2013-11-05 15:57:39 -0800173 [USECASE_AUDIO_HFP_SCO] = {HFP_PCM_RX, HFP_SCO_RX},
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700174
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700175 [USECASE_AUDIO_SPKR_CALIB_RX] = {SPKR_PROT_CALIB_RX_PCM_DEVICE, -1},
176 [USECASE_AUDIO_SPKR_CALIB_TX] = {-1, SPKR_PROT_CALIB_TX_PCM_DEVICE},
177
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700178 [USECASE_AUDIO_PLAYBACK_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
179 AFE_PROXY_RECORD_PCM_DEVICE},
180 [USECASE_AUDIO_RECORD_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
181 AFE_PROXY_RECORD_PCM_DEVICE},
zhaoyang yin4211fad2015-06-04 21:13:25 +0800182 [USECASE_AUDIO_DSM_FEEDBACK] = {QUAT_MI2S_PCM_DEVICE, QUAT_MI2S_PCM_DEVICE},
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700183
Eric Laurentb23d5282013-05-14 15:27:20 -0700184};
185
186/* Array to store sound devices */
187static const char * const device_table[SND_DEVICE_MAX] = {
188 [SND_DEVICE_NONE] = "none",
189 /* Playback sound devices */
190 [SND_DEVICE_OUT_HANDSET] = "handset",
191 [SND_DEVICE_OUT_SPEAKER] = "speaker",
192 [SND_DEVICE_OUT_SPEAKER_REVERSE] = "speaker-reverse",
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700193 [SND_DEVICE_OUT_SPEAKER_SAFE] = "speaker-safe",
Eric Laurentb23d5282013-05-14 15:27:20 -0700194 [SND_DEVICE_OUT_HEADPHONES] = "headphones",
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500195 [SND_DEVICE_OUT_LINE] = "line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700196 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones",
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700197 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = "speaker-safe-and-headphones",
Eric Laurent744996b2014-10-01 11:40:40 -0500198 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = "speaker-and-line",
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700199 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = "speaker-safe-and-line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700200 [SND_DEVICE_OUT_VOICE_HANDSET] = "voice-handset",
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500201 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = "voice-hac-handset",
Eric Laurentb23d5282013-05-14 15:27:20 -0700202 [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker",
203 [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones",
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500204 [SND_DEVICE_OUT_VOICE_LINE] = "voice-line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700205 [SND_DEVICE_OUT_HDMI] = "hdmi",
206 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi",
207 [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700208 [SND_DEVICE_OUT_BT_SCO_WB] = "bt-sco-headset-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700209 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = "voice-handset-tmus",
210 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones",
211 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones",
212 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700213 [SND_DEVICE_OUT_VOICE_TX] = "voice-tx",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700214 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = "speaker-protected",
215 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = "voice-speaker-protected",
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -0700216 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = "voice-speaker-hfp",
Eric Laurentb23d5282013-05-14 15:27:20 -0700217
218 /* Capture sound devices */
219 [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700220 [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700221 [SND_DEVICE_IN_HANDSET_MIC_NS] = "handset-mic",
222 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = "handset-mic",
223 [SND_DEVICE_IN_HANDSET_DMIC] = "dmic-endfire",
224 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = "dmic-endfire",
225 [SND_DEVICE_IN_HANDSET_DMIC_NS] = "dmic-endfire",
226 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = "dmic-endfire",
227 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = "dmic-endfire",
228
229 [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
230 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "speaker-mic",
231 [SND_DEVICE_IN_SPEAKER_MIC_NS] = "speaker-mic",
232 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = "speaker-mic",
233 [SND_DEVICE_IN_SPEAKER_DMIC] = "speaker-dmic-endfire",
234 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = "speaker-dmic-endfire",
235 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = "speaker-dmic-endfire",
236 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = "speaker-dmic-endfire",
237 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = "speaker-dmic-endfire",
238
239 [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
Eric Laurentcefbbac2014-09-04 13:54:10 -0500240 [SND_DEVICE_IN_HEADSET_MIC_AEC] = "headset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700241
Eric Laurentb23d5282013-05-14 15:27:20 -0700242 [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic",
243 [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700244 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = "bt-sco-mic",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700245 [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700246 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = "bt-sco-mic-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700247 [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700248
249 [SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef",
250 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = "voice-dmic-ef-tmus",
251 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
252 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = "voice-speaker-dmic-ef",
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -0700253 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = "voice-speaker-mic-hfp",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700254 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700255 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
256 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
257 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700258
Eric Laurentb23d5282013-05-14 15:27:20 -0700259 [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700260 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = "voice-rec-mic",
vivek mehta733c1df2016-04-04 15:09:24 -0700261 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700262 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = "voice-rec-dmic-ef",
263 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence",
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700264 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = "headset-mic",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700265
Ricardo Garcia9034bc42016-04-04 07:11:46 -0700266 [SND_DEVICE_IN_UNPROCESSED_MIC] = "unprocessed-mic",
rago90fb9612015-12-02 11:37:53 -0800267 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = "headset-mic",
268
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700269 [SND_DEVICE_IN_VOICE_RX] = "voice-rx",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700270
Prashant Malanic92c5962015-08-11 15:10:18 -0700271 [SND_DEVICE_IN_THREE_MIC] = "three-mic",
272 [SND_DEVICE_IN_QUAD_MIC] = "quad-mic",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700273 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = "vi-feedback",
Prashant Malanic92c5962015-08-11 15:10:18 -0700274 [SND_DEVICE_IN_HANDSET_TMIC] = "three-mic",
275 [SND_DEVICE_IN_HANDSET_QMIC] = "quad-mic",
vivek mehta733c1df2016-04-04 15:09:24 -0700276 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = "three-mic",
277 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = "quad-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700278};
279
280/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700281static int acdb_device_table[SND_DEVICE_MAX] = {
Eric Laurentb23d5282013-05-14 15:27:20 -0700282 [SND_DEVICE_NONE] = -1,
283 [SND_DEVICE_OUT_HANDSET] = 7,
284 [SND_DEVICE_OUT_SPEAKER] = 15,
285 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 15,
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700286 [SND_DEVICE_OUT_SPEAKER_SAFE] = 15,
Eric Laurentb23d5282013-05-14 15:27:20 -0700287 [SND_DEVICE_OUT_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500288 [SND_DEVICE_OUT_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700289 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700290 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500291 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = 77,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700292 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = 77,
Ravi Kumar Alamanda235c3482014-08-21 17:32:44 -0700293 [SND_DEVICE_OUT_VOICE_HANDSET] = ACDB_ID_VOICE_HANDSET,
294 [SND_DEVICE_OUT_VOICE_SPEAKER] = ACDB_ID_VOICE_SPEAKER,
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500295 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = 53,
Eric Laurentb23d5282013-05-14 15:27:20 -0700296 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500297 [SND_DEVICE_OUT_VOICE_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700298 [SND_DEVICE_OUT_HDMI] = 18,
299 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 15,
300 [SND_DEVICE_OUT_BT_SCO] = 22,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700301 [SND_DEVICE_OUT_BT_SCO_WB] = 39,
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700302 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = ACDB_ID_VOICE_HANDSET_TMUS,
Eric Laurentb23d5282013-05-14 15:27:20 -0700303 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
304 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
305 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700306 [SND_DEVICE_OUT_VOICE_TX] = 45,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700307 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = 124,
308 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = 101,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700309 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = ACDB_ID_VOICE_SPEAKER,
Eric Laurentb23d5282013-05-14 15:27:20 -0700310
311 [SND_DEVICE_IN_HANDSET_MIC] = 4,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700312 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 106,
313 [SND_DEVICE_IN_HANDSET_MIC_NS] = 107,
314 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = 108,
315 [SND_DEVICE_IN_HANDSET_DMIC] = 41,
316 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = 109,
317 [SND_DEVICE_IN_HANDSET_DMIC_NS] = 110,
318 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = 111,
319 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = 34,
320
321 [SND_DEVICE_IN_SPEAKER_MIC] = 11,
322 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 112,
323 [SND_DEVICE_IN_SPEAKER_MIC_NS] = 113,
324 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = 114,
325 [SND_DEVICE_IN_SPEAKER_DMIC] = 43,
326 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = 115,
327 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = 116,
328 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = 117,
329 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = 35,
330
rago90fb9612015-12-02 11:37:53 -0800331 [SND_DEVICE_IN_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentcefbbac2014-09-04 13:54:10 -0500332 [SND_DEVICE_IN_HEADSET_MIC_AEC] = ACDB_ID_HEADSET_MIC_AEC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700333
Eric Laurentb23d5282013-05-14 15:27:20 -0700334 [SND_DEVICE_IN_HDMI_MIC] = 4,
335 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700336 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = 21,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700337 [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700338 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = 38,
Eric Laurentb23d5282013-05-14 15:27:20 -0700339 [SND_DEVICE_IN_CAMCORDER_MIC] = 61,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700340
341 [SND_DEVICE_IN_VOICE_DMIC] = 41,
342 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = ACDB_ID_VOICE_DMIC_EF_TMUS,
343 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700344 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = 11,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700345 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 43,
rago90fb9612015-12-02 11:37:53 -0800346 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentb23d5282013-05-14 15:27:20 -0700347 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
348 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
349 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700350
rago90fb9612015-12-02 11:37:53 -0800351 [SND_DEVICE_IN_VOICE_REC_MIC] = ACDB_ID_VOICE_REC_MIC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700352 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = 113,
vivek mehta733c1df2016-04-04 15:09:24 -0700353 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = 112,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700354 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = 35,
355 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 43,
rago90fb9612015-12-02 11:37:53 -0800356 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
357
358 [SND_DEVICE_IN_UNPROCESSED_MIC] = ACDB_ID_VOICE_REC_MIC,
359 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700360
361 [SND_DEVICE_IN_VOICE_RX] = 44,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700362
Prashant Malanic92c5962015-08-11 15:10:18 -0700363 [SND_DEVICE_IN_THREE_MIC] = 46,
364 [SND_DEVICE_IN_QUAD_MIC] = 46,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700365 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = 102,
Prashant Malanic92c5962015-08-11 15:10:18 -0700366 [SND_DEVICE_IN_HANDSET_TMIC] = 125,
367 [SND_DEVICE_IN_HANDSET_QMIC] = 125,
vivek mehta733c1df2016-04-04 15:09:24 -0700368 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = 125, /* override this for new target to 140 */
369 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = 125, /* override this for new target to 140 */
Eric Laurentb23d5282013-05-14 15:27:20 -0700370};
371
Haynes Mathew George98c95622014-06-20 19:14:25 -0700372struct name_to_index {
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700373 char name[100];
374 unsigned int index;
375};
376
377#define TO_NAME_INDEX(X) #X, X
378
Haynes Mathew George98c95622014-06-20 19:14:25 -0700379/* Used to get index from parsed string */
380static const struct name_to_index snd_device_name_index[SND_DEVICE_MAX] = {
381 /* out */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700382 {TO_NAME_INDEX(SND_DEVICE_OUT_HANDSET)},
383 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER)},
384 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_REVERSE)},
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700385 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700386 {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500387 {TO_NAME_INDEX(SND_DEVICE_OUT_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700388 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700389 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES)},
Eric Laurent744996b2014-10-01 11:40:40 -0500390 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_LINE)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700391 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700392 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET)},
393 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700394 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_HFP)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700395 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500396 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700397 {TO_NAME_INDEX(SND_DEVICE_OUT_HDMI)},
398 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HDMI)},
399 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO)},
400 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO_WB)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700401 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET_TMUS)},
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500402 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HAC_HANDSET)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700403 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES)},
404 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES)},
405 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700406
407 /* in */
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700408 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED)},
409 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700410 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700411 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700412 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_NS)},
413 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)},
414 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC)},
415 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC)},
416 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_NS)},
417 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)},
418 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_STEREO)},
419
420 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700421 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700422 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_NS)},
423 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)},
424 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC)},
425 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC)},
426 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS)},
427 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)},
428 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_STEREO)},
429
430 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC)},
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700431 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700432
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700433 {TO_NAME_INDEX(SND_DEVICE_IN_HDMI_MIC)},
434 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700435 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700436 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700437 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700438 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700439
440 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC)},
441 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC_TMUS)},
442 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700443 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700444 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC)},
445 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEADSET_MIC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700446 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC)},
447 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC)},
448 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700449
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700450 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700451 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_NS)},
vivek mehta733c1df2016-04-04 15:09:24 -0700452 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700453 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_STEREO)},
454 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE)},
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700455 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_HEADSET_MIC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700456
rago90fb9612015-12-02 11:37:53 -0800457 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_MIC)},
458 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC)},
459
Prashant Malanic92c5962015-08-11 15:10:18 -0700460 {TO_NAME_INDEX(SND_DEVICE_IN_THREE_MIC)},
461 {TO_NAME_INDEX(SND_DEVICE_IN_QUAD_MIC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700462 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_VI_FEEDBACK)},
Prashant Malanic92c5962015-08-11 15:10:18 -0700463 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC)},
464 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC)},
vivek mehta733c1df2016-04-04 15:09:24 -0700465 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC_AEC)},
466 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC_AEC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700467};
468
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700469static char * backend_tag_table[SND_DEVICE_MAX] = {0};
470static char * hw_interface_table[SND_DEVICE_MAX] = {0};
Haynes Mathew George98c95622014-06-20 19:14:25 -0700471
472static const struct name_to_index usecase_name_index[AUDIO_USECASE_MAX] = {
473 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_DEEP_BUFFER)},
474 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_LOW_LATENCY)},
475 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_MULTI_CH)},
476 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD)},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700477 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_TTS)},
478 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_ULL)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700479 {TO_NAME_INDEX(USECASE_AUDIO_RECORD)},
480 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_LOW_LATENCY)},
481 {TO_NAME_INDEX(USECASE_VOICE_CALL)},
482 {TO_NAME_INDEX(USECASE_VOICE2_CALL)},
483 {TO_NAME_INDEX(USECASE_VOLTE_CALL)},
484 {TO_NAME_INDEX(USECASE_QCHAT_CALL)},
485 {TO_NAME_INDEX(USECASE_VOWLAN_CALL)},
486 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK)},
487 {TO_NAME_INDEX(USECASE_INCALL_REC_DOWNLINK)},
488 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK_AND_DOWNLINK)},
489 {TO_NAME_INDEX(USECASE_AUDIO_HFP_SCO)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700490};
491
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700492#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
493#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
Haynes Mathew George03c40102016-01-29 17:57:48 -0800494#define ULL_PLATFORM_DELAY (7*1000LL)
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700495
Eric Laurentb23d5282013-05-14 15:27:20 -0700496static pthread_once_t check_op_once_ctl = PTHREAD_ONCE_INIT;
497static bool is_tmus = false;
498
499static void check_operator()
500{
501 char value[PROPERTY_VALUE_MAX];
502 int mccmnc;
503 property_get("gsm.sim.operator.numeric",value,"0");
504 mccmnc = atoi(value);
Eric Laurent2bafff12016-03-17 12:17:23 -0700505 ALOGD("%s: tmus mccmnc %d", __func__, mccmnc);
Eric Laurentb23d5282013-05-14 15:27:20 -0700506 switch(mccmnc) {
507 /* TMUS MCC(310), MNC(490, 260, 026) */
508 case 310490:
509 case 310260:
510 case 310026:
sangwon.jeonb891db52013-09-14 17:39:15 +0900511 /* Add new TMUS MNC(800, 660, 580, 310, 270, 250, 240, 230, 220, 210, 200, 160) */
512 case 310800:
513 case 310660:
514 case 310580:
515 case 310310:
516 case 310270:
517 case 310250:
518 case 310240:
519 case 310230:
520 case 310220:
521 case 310210:
522 case 310200:
523 case 310160:
Eric Laurentb23d5282013-05-14 15:27:20 -0700524 is_tmus = true;
525 break;
526 }
527}
528
529bool is_operator_tmus()
530{
531 pthread_once(&check_op_once_ctl, check_operator);
532 return is_tmus;
533}
534
keunhui.park2f7306a2015-07-16 16:48:06 +0900535static char *get_current_operator()
536{
537 struct listnode *node;
538 struct operator_info *info_item;
539 char mccmnc[PROPERTY_VALUE_MAX];
540 char *ret = NULL;
541
542 property_get("gsm.sim.operator.numeric",mccmnc,"0");
543
544 list_for_each(node, &operator_info_list) {
545 info_item = node_to_item(node, struct operator_info, list);
546 if (strstr(info_item->mccmnc, mccmnc) != NULL) {
547 ret = info_item->name;
548 }
549 }
550
551 return ret;
552}
553
554static struct operator_specific_device *get_operator_specific_device(snd_device_t snd_device)
555{
556 struct listnode *node;
557 struct operator_specific_device *ret = NULL;
558 struct operator_specific_device *device_item;
559 char *operator_name;
560
561 operator_name = get_current_operator();
562 if (operator_name == NULL)
563 return ret;
564
565 list_for_each(node, operator_specific_device_table[snd_device]) {
566 device_item = node_to_item(node, struct operator_specific_device, list);
567 if (strcmp(operator_name, device_item->operator) == 0) {
568 ret = device_item;
569 }
570 }
571
572 return ret;
573}
574
575
576static int get_operator_specific_device_acdb_id(snd_device_t snd_device)
577{
578 struct operator_specific_device *device;
579 int ret = acdb_device_table[snd_device];
580
581 device = get_operator_specific_device(snd_device);
582 if (device != NULL)
583 ret = device->acdb_id;
584
585 return ret;
586}
587
588static const char *get_operator_specific_device_mixer_path(snd_device_t snd_device)
589{
590 struct operator_specific_device *device;
591 const char *ret = device_table[snd_device];
592
593 device = get_operator_specific_device(snd_device);
594 if (device != NULL)
595 ret = device->mixer_path;
596
597 return ret;
598}
599
vivek mehta1a9b7c02015-06-25 11:49:38 -0700600bool platform_send_gain_dep_cal(void *platform, int level)
601{
602 bool ret_val = false;
603 struct platform_data *my_data = (struct platform_data *)platform;
604 struct audio_device *adev = my_data->adev;
605 int acdb_dev_id, app_type;
606 int acdb_dev_type = MSM_SNDDEV_CAP_RX;
607 int mode = CAL_MODE_RTAC;
608 struct listnode *node;
609 struct audio_usecase *usecase;
vivek mehta1a9b7c02015-06-25 11:49:38 -0700610
611 if (my_data->acdb_send_gain_dep_cal == NULL) {
612 ALOGE("%s: dlsym error for acdb_send_gain_dep_cal", __func__);
613 return ret_val;
614 }
615
616 if (!voice_is_in_call(adev)) {
617 ALOGV("%s: Not Voice call usecase, apply new cal for level %d",
618 __func__, level);
619 app_type = DEFAULT_APP_TYPE_RX_PATH;
620
621 // find the current active sound device
622 list_for_each(node, &adev->usecase_list) {
623 usecase = node_to_item(node, struct audio_usecase, list);
624
625 if (usecase != NULL &&
626 usecase->type == PCM_PLAYBACK &&
627 (usecase->stream.out->devices == AUDIO_DEVICE_OUT_SPEAKER)) {
628
629 ALOGV("%s: out device is %d", __func__, usecase->out_snd_device);
vivek mehta4cb82982015-07-13 12:05:49 -0700630 if (audio_extn_spkr_prot_is_enabled()) {
631 acdb_dev_id = audio_extn_spkr_prot_get_acdb_id(usecase->out_snd_device);
632 } else {
633 acdb_dev_id = acdb_device_table[usecase->out_snd_device];
634 }
635
vivek mehta1a9b7c02015-06-25 11:49:38 -0700636 if (!my_data->acdb_send_gain_dep_cal(acdb_dev_id, app_type,
637 acdb_dev_type, mode, level)) {
638 // set ret_val true if at least one calibration is set successfully
639 ret_val = true;
640 } else {
641 ALOGE("%s: my_data->acdb_send_gain_dep_cal failed ", __func__);
642 }
643 } else {
644 ALOGW("%s: Usecase list is empty", __func__);
645 }
646 }
647 } else {
648 ALOGW("%s: Voice call in progress .. ignore setting new cal",
649 __func__);
650 }
651 return ret_val;
652}
653
Eric Laurentcefbbac2014-09-04 13:54:10 -0500654void platform_set_echo_reference(struct audio_device *adev, bool enable, audio_devices_t out_device)
Eric Laurentb23d5282013-05-14 15:27:20 -0700655{
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800656 struct platform_data *my_data = (struct platform_data *)adev->platform;
Eric Laurentcefbbac2014-09-04 13:54:10 -0500657 snd_device_t snd_device = SND_DEVICE_NONE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700658
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800659 if (strcmp(my_data->ec_ref_mixer_path, "")) {
660 ALOGV("%s: diabling %s", __func__, my_data->ec_ref_mixer_path);
661 audio_route_reset_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
Eric Laurentcefbbac2014-09-04 13:54:10 -0500662 }
663
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800664 if (enable) {
665 strcpy(my_data->ec_ref_mixer_path, "echo-reference");
666 if (out_device != AUDIO_DEVICE_NONE) {
667 snd_device = platform_get_output_snd_device(adev->platform, out_device);
668 platform_add_backend_name(adev->platform, my_data->ec_ref_mixer_path, snd_device);
669 }
Eric Laurentcefbbac2014-09-04 13:54:10 -0500670
Joe Onorato188b6222016-03-01 11:02:27 -0800671 ALOGV("%s: enabling %s", __func__, my_data->ec_ref_mixer_path);
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800672 audio_route_apply_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
673 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700674}
675
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700676static struct csd_data *open_csd_client(bool i2s_ext_modem)
677{
678 struct csd_data *csd = calloc(1, sizeof(struct csd_data));
679
680 csd->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
681 if (csd->csd_client == NULL) {
682 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
683 goto error;
684 } else {
685 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
686
687 csd->deinit = (deinit_t)dlsym(csd->csd_client,
688 "csd_client_deinit");
689 if (csd->deinit == NULL) {
690 ALOGE("%s: dlsym error %s for csd_client_deinit", __func__,
691 dlerror());
692 goto error;
693 }
694 csd->disable_device = (disable_device_t)dlsym(csd->csd_client,
695 "csd_client_disable_device");
696 if (csd->disable_device == NULL) {
697 ALOGE("%s: dlsym error %s for csd_client_disable_device",
698 __func__, dlerror());
699 goto error;
700 }
701 csd->enable_device_config = (enable_device_config_t)dlsym(csd->csd_client,
702 "csd_client_enable_device_config");
703 if (csd->enable_device_config == NULL) {
704 ALOGE("%s: dlsym error %s for csd_client_enable_device_config",
705 __func__, dlerror());
706 goto error;
707 }
708 csd->enable_device = (enable_device_t)dlsym(csd->csd_client,
709 "csd_client_enable_device");
710 if (csd->enable_device == NULL) {
711 ALOGE("%s: dlsym error %s for csd_client_enable_device",
712 __func__, dlerror());
713 goto error;
714 }
715 csd->start_voice = (start_voice_t)dlsym(csd->csd_client,
716 "csd_client_start_voice");
717 if (csd->start_voice == NULL) {
718 ALOGE("%s: dlsym error %s for csd_client_start_voice",
719 __func__, dlerror());
720 goto error;
721 }
722 csd->stop_voice = (stop_voice_t)dlsym(csd->csd_client,
723 "csd_client_stop_voice");
724 if (csd->stop_voice == NULL) {
725 ALOGE("%s: dlsym error %s for csd_client_stop_voice",
726 __func__, dlerror());
727 goto error;
728 }
729 csd->volume = (volume_t)dlsym(csd->csd_client,
730 "csd_client_volume");
731 if (csd->volume == NULL) {
732 ALOGE("%s: dlsym error %s for csd_client_volume",
733 __func__, dlerror());
734 goto error;
735 }
736 csd->mic_mute = (mic_mute_t)dlsym(csd->csd_client,
737 "csd_client_mic_mute");
738 if (csd->mic_mute == NULL) {
739 ALOGE("%s: dlsym error %s for csd_client_mic_mute",
740 __func__, dlerror());
741 goto error;
742 }
743 csd->slow_talk = (slow_talk_t)dlsym(csd->csd_client,
744 "csd_client_slow_talk");
745 if (csd->slow_talk == NULL) {
746 ALOGE("%s: dlsym error %s for csd_client_slow_talk",
747 __func__, dlerror());
748 goto error;
749 }
750 csd->start_playback = (start_playback_t)dlsym(csd->csd_client,
751 "csd_client_start_playback");
752 if (csd->start_playback == NULL) {
753 ALOGE("%s: dlsym error %s for csd_client_start_playback",
754 __func__, dlerror());
755 goto error;
756 }
757 csd->stop_playback = (stop_playback_t)dlsym(csd->csd_client,
758 "csd_client_stop_playback");
759 if (csd->stop_playback == NULL) {
760 ALOGE("%s: dlsym error %s for csd_client_stop_playback",
761 __func__, dlerror());
762 goto error;
763 }
764 csd->start_record = (start_record_t)dlsym(csd->csd_client,
765 "csd_client_start_record");
766 if (csd->start_record == NULL) {
767 ALOGE("%s: dlsym error %s for csd_client_start_record",
768 __func__, dlerror());
769 goto error;
770 }
771 csd->stop_record = (stop_record_t)dlsym(csd->csd_client,
772 "csd_client_stop_record");
773 if (csd->stop_record == NULL) {
774 ALOGE("%s: dlsym error %s for csd_client_stop_record",
775 __func__, dlerror());
776 goto error;
777 }
778
779 csd->get_sample_rate = (get_sample_rate_t)dlsym(csd->csd_client,
780 "csd_client_get_sample_rate");
781 if (csd->get_sample_rate == NULL) {
782 ALOGE("%s: dlsym error %s for csd_client_get_sample_rate",
783 __func__, dlerror());
784
785 goto error;
786 }
787
788 csd->init = (init_t)dlsym(csd->csd_client, "csd_client_init");
789
790 if (csd->init == NULL) {
791 ALOGE("%s: dlsym error %s for csd_client_init",
792 __func__, dlerror());
793 goto error;
794 } else {
795 csd->init(i2s_ext_modem);
796 }
797 }
798 return csd;
799
800error:
801 free(csd);
802 csd = NULL;
803 return csd;
804}
805
806void close_csd_client(struct csd_data *csd)
807{
808 if (csd != NULL) {
809 csd->deinit();
810 dlclose(csd->csd_client);
811 free(csd);
812 csd = NULL;
813 }
814}
815
816static void platform_csd_init(struct platform_data *my_data)
817{
818#ifdef PLATFORM_MSM8084
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700819 int32_t modems, (*count_modems)(void);
820 const char *name = "libdetectmodem.so";
821 const char *func = "count_modems";
822 const char *error;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700823
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700824 my_data->csd = NULL;
825
826 void *lib = dlopen(name, RTLD_NOW);
827 error = dlerror();
828 if (!lib) {
829 ALOGE("%s: could not find %s: %s", __func__, name, error);
830 return;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700831 }
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700832
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700833 count_modems = NULL;
834 *(void **)(&count_modems) = dlsym(lib, func);
835 error = dlerror();
836 if (!count_modems) {
837 ALOGE("%s: could not find symbol %s in %s: %s",
838 __func__, func, name, error);
839 goto done;
840 }
841
842 modems = count_modems();
843 if (modems < 0) {
844 ALOGE("%s: count_modems failed\n", __func__);
845 goto done;
846 }
847
Eric Laurent2bafff12016-03-17 12:17:23 -0700848 ALOGD("%s: num_modems %d\n", __func__, modems);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700849 if (modems > 0)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700850 my_data->csd = open_csd_client(false /*is_i2s_ext_modem*/);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700851
852done:
853 dlclose(lib);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700854#else
855 my_data->csd = NULL;
856#endif
857}
858
Eric Laurentc6333382015-09-14 12:43:44 -0700859static void set_platform_defaults(struct platform_data * my_data)
Haynes Mathew George98c95622014-06-20 19:14:25 -0700860{
861 int32_t dev;
862 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700863 backend_tag_table[dev] = NULL;
864 hw_interface_table[dev] = NULL;
keunhui.park2f7306a2015-07-16 16:48:06 +0900865 operator_specific_device_table[dev] = NULL;
Haynes Mathew George98c95622014-06-20 19:14:25 -0700866 }
867
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700868 // To overwrite these go to the audio_platform_info.xml file.
869 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("bt-sco");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700870 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("bt-sco");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700871 backend_tag_table[SND_DEVICE_OUT_BT_SCO] = strdup("bt-sco");
872 backend_tag_table[SND_DEVICE_OUT_HDMI] = strdup("hdmi");
873 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("speaker-and-hdmi");
874 backend_tag_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("bt-sco-wb");
875 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("bt-sco-wb");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700876 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("bt-sco-wb");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700877 backend_tag_table[SND_DEVICE_OUT_VOICE_TX] = strdup("afe-proxy");
878 backend_tag_table[SND_DEVICE_IN_VOICE_RX] = strdup("afe-proxy");
Haynes Mathew George98c95622014-06-20 19:14:25 -0700879
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700880 hw_interface_table[SND_DEVICE_OUT_HANDSET] = strdup("SLIMBUS_0_RX");
881 hw_interface_table[SND_DEVICE_OUT_SPEAKER] = strdup("SLIMBUS_0_RX");
882 hw_interface_table[SND_DEVICE_OUT_SPEAKER_REVERSE] = strdup("SLIMBUS_0_RX");
883 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE] = strdup("SLIMBUS_0_RX");
884 hw_interface_table[SND_DEVICE_OUT_HEADPHONES] = strdup("SLIMBUS_0_RX");
885 hw_interface_table[SND_DEVICE_OUT_LINE] = strdup("SLIMBUS_0_RX");
886 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700887 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700888 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700889 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700890 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET] = strdup("SLIMBUS_0_RX");
891 hw_interface_table[SND_DEVICE_OUT_VOICE_HAC_HANDSET] = strdup("SLIMBUS_0_RX");
892 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER] = strdup("SLIMBUS_0_RX");
893 hw_interface_table[SND_DEVICE_OUT_VOICE_HEADPHONES] = strdup("SLIMBUS_0_RX");
894 hw_interface_table[SND_DEVICE_OUT_VOICE_LINE] = strdup("SLIMBUS_0_RX");
895 hw_interface_table[SND_DEVICE_OUT_HDMI] = strdup("HDMI_RX");
896 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("SLIMBUS_0_RX-and-HDMI_RX");
897 hw_interface_table[SND_DEVICE_OUT_BT_SCO] = strdup("SEC_AUX_PCM_RX");
898 hw_interface_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("SEC_AUX_PCM_RX");
899 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = strdup("SLIMBUS_0_RX");
900 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = strdup("SLIMBUS_0_RX");
901 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = strdup("SLIMBUS_0_RX");
902 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = strdup("SLIMBUS_0_RX");
903 hw_interface_table[SND_DEVICE_OUT_VOICE_TX] = strdup("AFE_PCM_RX");
904 hw_interface_table[SND_DEVICE_OUT_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
905 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
Eric Laurentc6333382015-09-14 12:43:44 -0700906
907 my_data->max_mic_count = PLATFORM_DEFAULT_MIC_COUNT;
Haynes Mathew George98c95622014-06-20 19:14:25 -0700908}
909
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +0900910void get_cvd_version(char *cvd_version, struct audio_device *adev)
911{
912 struct mixer_ctl *ctl;
913 int count;
914 int ret = 0;
915
916 ctl = mixer_get_ctl_by_name(adev->mixer, CVD_VERSION_MIXER_CTL);
917 if (!ctl) {
918 ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__, CVD_VERSION_MIXER_CTL);
919 goto done;
920 }
921 mixer_ctl_update(ctl);
922
923 count = mixer_ctl_get_num_values(ctl);
924 if (count > MAX_CVD_VERSION_STRING_SIZE)
925 count = MAX_CVD_VERSION_STRING_SIZE - 1;
926
927 ret = mixer_ctl_get_array(ctl, cvd_version, count);
928 if (ret != 0) {
929 ALOGE("%s: ERROR! mixer_ctl_get_array() failed to get CVD Version", __func__);
930 goto done;
931 }
932
933done:
934 return;
935}
936
Eric Laurentb23d5282013-05-14 15:27:20 -0700937void *platform_init(struct audio_device *adev)
938{
939 char value[PROPERTY_VALUE_MAX];
vivek mehta60ea4152016-02-18 17:10:26 -0800940 struct platform_data *my_data = NULL;
941 int retry_num = 0, snd_card_num = 0, key = 0, ret = 0;
942 bool dual_mic_config = false, use_default_mixer_path = true;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700943 const char *snd_card_name;
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +0900944 char *cvd_version = NULL;
vivek mehta60ea4152016-02-18 17:10:26 -0800945 char *snd_internal_name = NULL;
946 char *tmp = NULL;
947 char mixer_xml_file[MIXER_PATH_MAX_LENGTH]= {0};
vivek mehtade4849c2016-03-03 17:23:38 -0800948 char platform_info_file[MIXER_PATH_MAX_LENGTH]= {0};
949 struct snd_card_split *snd_split_handle = NULL;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700950 my_data = calloc(1, sizeof(struct platform_data));
951
952 my_data->adev = adev;
953
keunhui.park2f7306a2015-07-16 16:48:06 +0900954 list_init(&operator_info_list);
955
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700956 set_platform_defaults(my_data);
957
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700958 while (snd_card_num < MAX_SND_CARD) {
959 adev->mixer = mixer_open(snd_card_num);
sangwoo1b9f4b32013-06-21 18:22:55 -0700960
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700961 while (!adev->mixer && retry_num < RETRY_NUMBER) {
962 usleep(RETRY_US);
963 adev->mixer = mixer_open(snd_card_num);
964 retry_num++;
965 }
966
967 if (!adev->mixer) {
968 ALOGE("%s: Unable to open the mixer card: %d", __func__,
969 snd_card_num);
970 retry_num = 0;
971 snd_card_num++;
972 continue;
973 }
974
975 snd_card_name = mixer_get_name(adev->mixer);
vivek mehtade4849c2016-03-03 17:23:38 -0800976 my_data->hw_info = hw_info_init(snd_card_name);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700977
vivek mehtade4849c2016-03-03 17:23:38 -0800978 audio_extn_set_snd_card_split(snd_card_name);
979 snd_split_handle = audio_extn_get_snd_card_split();
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700980
vivek mehtade4849c2016-03-03 17:23:38 -0800981 /* Get the codec internal name from the sound card and/or form factor
982 * name and form the mixer paths and platfor info file name dynamically.
983 * This is generic way of picking any codec and forma factor name based
984 * mixer and platform info files in future with no code change.
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700985
vivek mehtade4849c2016-03-03 17:23:38 -0800986 * current code extends and looks for any of the exteneded mixer path and
987 * platform info file present based on codec and form factor.
vivek mehta60ea4152016-02-18 17:10:26 -0800988
vivek mehtade4849c2016-03-03 17:23:38 -0800989 * order of picking appropriate file is
990 * <i> mixer_paths_<codec_name>_<form_factor>.xml, if file not present
991 * <ii> mixer_paths_<codec_name>.xml, if file not present
992 * <iii> mixer_paths.xml
993
994 * same order is followed for audio_platform_info.xml as well
995 */
996
997 // need to carryforward old file name
998 if (!strncmp(snd_card_name, TOMTOM_8226_SND_CARD_NAME,
Eric Laurentf9583c32016-03-28 13:50:50 -0700999 min(strlen(TOMTOM_8226_SND_CARD_NAME), strlen(snd_card_name)))) {
vivek mehtade4849c2016-03-03 17:23:38 -08001000 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
vivek mehta60ea4152016-02-18 17:10:26 -08001001 MIXER_XML_BASE_STRING, TOMTOM_MIXER_FILE_SUFFIX );
vivek mehtade4849c2016-03-03 17:23:38 -08001002 } else {
Ed Tamb0b0d572016-03-21 10:45:37 -07001003
vivek mehtade4849c2016-03-03 17:23:38 -08001004 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s_%s.xml",
1005 MIXER_XML_BASE_STRING, snd_split_handle->snd_card,
1006 snd_split_handle->form_factor);
1007
1008 if (F_OK != access(mixer_xml_file, 0)) {
1009 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1010 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1011 MIXER_XML_BASE_STRING, snd_split_handle->snd_card);
1012
1013 if (F_OK != access(mixer_xml_file, 0)) {
1014 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1015 strlcpy(mixer_xml_file, MIXER_XML_DEFAULT_PATH, MIXER_PATH_MAX_LENGTH);
1016 }
1017 }
1018
1019 snprintf(platform_info_file, sizeof(platform_info_file), "%s_%s_%s.xml",
1020 PLATFORM_INFO_XML_BASE_STRING, snd_split_handle->snd_card,
1021 snd_split_handle->form_factor);
1022
1023 if (F_OK != access(platform_info_file, 0)) {
1024 memset(platform_info_file, 0, sizeof(platform_info_file));
1025 snprintf(platform_info_file, sizeof(platform_info_file), "%s_%s.xml",
1026 PLATFORM_INFO_XML_BASE_STRING, snd_split_handle->snd_card);
1027
1028 if (F_OK != access(platform_info_file, 0)) {
1029 memset(platform_info_file, 0, sizeof(platform_info_file));
1030 strlcpy(platform_info_file, PLATFORM_INFO_XML_PATH, MIXER_PATH_MAX_LENGTH);
vivek mehta60ea4152016-02-18 17:10:26 -08001031 }
1032 }
Uday Kishore Pasupuleti11dd2232015-06-24 14:18:01 -07001033 }
1034
vivek mehtade4849c2016-03-03 17:23:38 -08001035 /* Initialize platform specific ids and/or backends*/
1036 platform_info_init(platform_info_file, my_data);
1037
1038 /* validate the sound card name
1039 * my_data->snd_card_name can contain
1040 * <a> complete sound card name, i.e. <device>-<codec>-<form_factor>-snd-card
1041 * example: msm8994-tomtom-mtp-snd-card
1042 * <b> or sub string of the card name, i.e. <device>-<codec>
1043 * example: msm8994-tomtom
Eric Laurentf9583c32016-03-28 13:50:50 -07001044 * snd_card_name is truncated to 32 charaters as per mixer_get_name() implementation
1045 * so use min of my_data->snd_card_name and snd_card_name length for comparison
vivek mehtade4849c2016-03-03 17:23:38 -08001046 */
1047
1048 if (my_data->snd_card_name != NULL &&
Eric Laurentf9583c32016-03-28 13:50:50 -07001049 strncmp(snd_card_name, my_data->snd_card_name,
1050 min(strlen(snd_card_name), strlen(my_data->snd_card_name))) != 0) {
vivek mehtade4849c2016-03-03 17:23:38 -08001051 ALOGI("%s: found valid sound card %s, but not primary sound card %s",
1052 __func__, snd_card_name, my_data->snd_card_name);
1053 retry_num = 0;
1054 snd_card_num++;
1055 hw_info_deinit(my_data->hw_info);
1056 my_data->hw_info = NULL;
1057 continue;
Ed Tam70b5c142016-03-21 19:14:29 -07001058 }
vivek mehtade4849c2016-03-03 17:23:38 -08001059 ALOGI("%s: found sound card %s, primary sound card expeted is %s",
1060 __func__, snd_card_name, my_data->snd_card_name);
vivek mehta60ea4152016-02-18 17:10:26 -08001061
1062 ALOGD("%s: Loading mixer file: %s", __func__, mixer_xml_file);
1063 adev->audio_route = audio_route_init(snd_card_num, mixer_xml_file);
1064
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001065 if (!adev->audio_route) {
1066 ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001067 goto init_failed;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001068 }
1069 adev->snd_card = snd_card_num;
Eric Laurent2bafff12016-03-17 12:17:23 -07001070 ALOGD("%s: Opened sound card:%d", __func__, snd_card_num);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001071 break;
sangwoo1b9f4b32013-06-21 18:22:55 -07001072 }
1073
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001074 if (snd_card_num >= MAX_SND_CARD) {
1075 ALOGE("%s: Unable to find correct sound card, aborting.", __func__);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001076 goto init_failed;
sangwoo1b9f4b32013-06-21 18:22:55 -07001077 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001078
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09001079 //set max volume step for voice call
1080 property_get("ro.config.vc_call_vol_steps", value, TOSTRING(MAX_VOL_INDEX));
1081 my_data->max_vol_index = atoi(value);
1082
vivek mehta65ad12d2015-08-13 18:32:48 -07001083 property_get("persist.audio.dualmic.config",value,"");
1084 if (!strcmp("endfire", value)) {
1085 dual_mic_config = true;
1086 }
1087
Prashant Malanic92c5962015-08-11 15:10:18 -07001088 my_data->source_mic_type = SOURCE_DUAL_MIC;
1089
Eric Laurentb23d5282013-05-14 15:27:20 -07001090 my_data->fluence_in_spkr_mode = false;
1091 my_data->fluence_in_voice_call = false;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001092 my_data->fluence_in_voice_comm = false;
Eric Laurentb23d5282013-05-14 15:27:20 -07001093 my_data->fluence_in_voice_rec = false;
1094
vivek mehta65ad12d2015-08-13 18:32:48 -07001095 property_get("ro.qc.sdk.audio.fluencetype", value, "none");
Prashant Malanic92c5962015-08-11 15:10:18 -07001096 if (!strcmp("fluencepro", value)) {
1097 my_data->fluence_type = FLUENCE_PRO_ENABLE;
vivek mehta65ad12d2015-08-13 18:32:48 -07001098 } else if (!strcmp("fluence", value) || (dual_mic_config)) {
Prashant Malanic92c5962015-08-11 15:10:18 -07001099 my_data->fluence_type = FLUENCE_ENABLE;
1100 } else if (!strcmp("none", value)) {
1101 my_data->fluence_type = FLUENCE_DISABLE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001102 }
1103
Prashant Malanic92c5962015-08-11 15:10:18 -07001104 if (my_data->fluence_type != FLUENCE_DISABLE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001105 property_get("persist.audio.fluence.voicecall",value,"");
1106 if (!strcmp("true", value)) {
1107 my_data->fluence_in_voice_call = true;
1108 }
1109
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001110 property_get("persist.audio.fluence.voicecomm",value,"");
1111 if (!strcmp("true", value)) {
1112 my_data->fluence_in_voice_comm = true;
1113 }
1114
Eric Laurentb23d5282013-05-14 15:27:20 -07001115 property_get("persist.audio.fluence.voicerec",value,"");
1116 if (!strcmp("true", value)) {
1117 my_data->fluence_in_voice_rec = true;
1118 }
1119
1120 property_get("persist.audio.fluence.speaker",value,"");
1121 if (!strcmp("true", value)) {
1122 my_data->fluence_in_spkr_mode = true;
1123 }
1124 }
1125
Prashant Malanic92c5962015-08-11 15:10:18 -07001126 // support max to mono, example if max count is 3, usecase supports Three, dual and mono mic
1127 switch (my_data->max_mic_count) {
1128 case 4:
1129 my_data->source_mic_type |= SOURCE_QUAD_MIC;
1130 case 3:
1131 my_data->source_mic_type |= SOURCE_THREE_MIC;
1132 case 2:
1133 my_data->source_mic_type |= SOURCE_DUAL_MIC;
1134 case 1:
1135 my_data->source_mic_type |= SOURCE_MONO_MIC;
1136 break;
1137 default:
1138 ALOGE("%s: max_mic_count (%d), is not supported, setting to default",
1139 __func__, my_data->max_mic_count);
1140 my_data->source_mic_type = SOURCE_MONO_MIC|SOURCE_DUAL_MIC;
1141 break;
1142 }
1143
1144 ALOGV("%s: Fluence_Type(%d) max_mic_count(%d) mic_type(0x%x) fluence_in_voice_call(%d)"
1145 " fluence_in_voice_comm(%d) fluence_in_voice_rec(%d) fluence_in_spkr_mode(%d) ",
1146 __func__, my_data->fluence_type, my_data->max_mic_count, my_data->source_mic_type,
1147 my_data->fluence_in_voice_call, my_data->fluence_in_voice_comm,
1148 my_data->fluence_in_voice_rec, my_data->fluence_in_spkr_mode);
1149
Eric Laurentb23d5282013-05-14 15:27:20 -07001150 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
1151 if (my_data->acdb_handle == NULL) {
1152 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
1153 } else {
1154 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
1155 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
1156 "acdb_loader_deallocate_ACDB");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001157 if (!my_data->acdb_deallocate)
1158 ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s",
1159 __func__, LIB_ACDB_LOADER);
1160
Eric Laurentb23d5282013-05-14 15:27:20 -07001161 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
1162 "acdb_loader_send_audio_cal");
1163 if (!my_data->acdb_send_audio_cal)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001164 ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s",
Eric Laurentb23d5282013-05-14 15:27:20 -07001165 __func__, LIB_ACDB_LOADER);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001166
Eric Laurentb23d5282013-05-14 15:27:20 -07001167 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
1168 "acdb_loader_send_voice_cal");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001169 if (!my_data->acdb_send_voice_cal)
1170 ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s",
1171 __func__, LIB_ACDB_LOADER);
1172
1173 my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle,
1174 "acdb_loader_reload_vocvoltable");
1175 if (!my_data->acdb_reload_vocvoltable)
1176 ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s",
1177 __func__, LIB_ACDB_LOADER);
vivek mehta1a9b7c02015-06-25 11:49:38 -07001178
1179 my_data->acdb_send_gain_dep_cal = (acdb_send_gain_dep_cal_t)dlsym(my_data->acdb_handle,
1180 "acdb_loader_send_gain_dep_cal");
1181 if (!my_data->acdb_send_gain_dep_cal)
1182 ALOGV("%s: Could not find the symbol acdb_loader_send_gain_dep_cal from %s",
1183 __func__, LIB_ACDB_LOADER);
1184
vivek mehtac698f132016-02-25 18:50:35 -08001185#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996)
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001186 acdb_init_v2_cvd_t acdb_init;
1187 acdb_init = (acdb_init_v2_cvd_t)dlsym(my_data->acdb_handle,
1188 "acdb_loader_init_v2");
1189 if (acdb_init == NULL) {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001190 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__, dlerror());
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001191 goto acdb_init_fail;
1192 }
1193
1194 cvd_version = calloc(1, MAX_CVD_VERSION_STRING_SIZE);
1195 get_cvd_version(cvd_version, adev);
1196 if (!cvd_version)
1197 ALOGE("failed to allocate cvd_version");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001198 else
vivek mehtac698f132016-02-25 18:50:35 -08001199 acdb_init((char *)snd_card_name, cvd_version, 0);
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001200 free(cvd_version);
1201#elif defined (PLATFORM_MSM8084)
1202 acdb_init_v2_t acdb_init;
1203 acdb_init = (acdb_init_v2_t)dlsym(my_data->acdb_handle,
1204 "acdb_loader_init_v2");
1205 if (acdb_init == NULL) {
1206 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__, dlerror());
1207 goto acdb_init_fail;
1208 }
1209 acdb_init((char *)snd_card_name);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001210#else
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001211 acdb_init_t acdb_init;
1212 acdb_init = (acdb_init_t)dlsym(my_data->acdb_handle,
Eric Laurentb23d5282013-05-14 15:27:20 -07001213 "acdb_loader_init_ACDB");
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001214 if (acdb_init == NULL)
Eric Laurentb23d5282013-05-14 15:27:20 -07001215 ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__, dlerror());
1216 else
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001217 acdb_init();
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001218#endif
Eric Laurentb23d5282013-05-14 15:27:20 -07001219 }
1220
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001221acdb_init_fail:
1222
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001223 audio_extn_spkr_prot_init(adev);
Haynes Mathew George98c95622014-06-20 19:14:25 -07001224
Ravi Kumar Alamanda76315572015-04-23 13:13:56 -07001225 audio_extn_hwdep_cal_send(adev->snd_card, my_data->acdb_handle);
1226
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001227 /* load csd client */
1228 platform_csd_init(my_data);
1229
Eric Laurentb23d5282013-05-14 15:27:20 -07001230 return my_data;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001231
1232init_failed:
1233 if (my_data)
1234 free(my_data);
1235 return NULL;
Eric Laurentb23d5282013-05-14 15:27:20 -07001236}
1237
1238void platform_deinit(void *platform)
1239{
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001240 int32_t dev;
keunhui.park2f7306a2015-07-16 16:48:06 +09001241 struct operator_info *info_item;
1242 struct operator_specific_device *device_item;
1243 struct listnode *node;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001244
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001245 struct platform_data *my_data = (struct platform_data *)platform;
1246 close_csd_client(my_data->csd);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001247
vivek mehtade4849c2016-03-03 17:23:38 -08001248 hw_info_deinit(my_data->hw_info);
1249
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001250 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1251 if (backend_tag_table[dev])
1252 free(backend_tag_table[dev]);
1253 if (hw_interface_table[dev])
1254 free(hw_interface_table[dev]);
keunhui.park2f7306a2015-07-16 16:48:06 +09001255 if (operator_specific_device_table[dev]) {
1256 while (!list_empty(operator_specific_device_table[dev])) {
1257 node = list_head(operator_specific_device_table[dev]);
1258 list_remove(node);
1259 device_item = node_to_item(node, struct operator_specific_device, list);
1260 free(device_item->operator);
1261 free(device_item->mixer_path);
1262 free(device_item);
1263 }
1264 free(operator_specific_device_table[dev]);
1265 }
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001266 }
1267
1268 if (my_data->snd_card_name)
1269 free(my_data->snd_card_name);
1270
keunhui.park2f7306a2015-07-16 16:48:06 +09001271 while (!list_empty(&operator_info_list)) {
1272 node = list_head(&operator_info_list);
1273 list_remove(node);
1274 info_item = node_to_item(node, struct operator_info, list);
1275 free(info_item->name);
1276 free(info_item->mccmnc);
1277 free(info_item);
1278 }
1279
Eric Laurentb23d5282013-05-14 15:27:20 -07001280 free(platform);
1281}
1282
1283const char *platform_get_snd_device_name(snd_device_t snd_device)
1284{
keunhui.park2f7306a2015-07-16 16:48:06 +09001285 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1286 if (operator_specific_device_table[snd_device] != NULL) {
1287 return get_operator_specific_device_mixer_path(snd_device);
1288 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001289 return device_table[snd_device];
keunhui.park2f7306a2015-07-16 16:48:06 +09001290 } else
Ravi Kumar Alamanda64026462014-09-15 00:08:58 -07001291 return "none";
Eric Laurentb23d5282013-05-14 15:27:20 -07001292}
1293
vivek mehtade4849c2016-03-03 17:23:38 -08001294int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
1295 char *device_name)
1296{
1297 struct platform_data *my_data = (struct platform_data *)platform;
1298
1299 if (platform == NULL || device_name == NULL) {
1300 ALOGW("%s: something wrong, use legacy get_snd_device name", __func__);
1301 device_name = platform_get_snd_device_name(snd_device);
1302 } else if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1303 if (operator_specific_device_table[snd_device] != NULL) {
1304 strlcpy(device_name, get_operator_specific_device_mixer_path(snd_device),
1305 DEVICE_NAME_MAX_SIZE);
1306 } else {
1307 strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE);
1308 }
1309 hw_info_append_hw_type(my_data->hw_info, snd_device, device_name);
1310 } else {
1311 strlcpy(device_name, "none", DEVICE_NAME_MAX_SIZE);
1312 }
1313
1314 return 0;
1315}
1316
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001317void platform_add_backend_name(void *platform, char *mixer_path,
1318 snd_device_t snd_device)
Eric Laurentb23d5282013-05-14 15:27:20 -07001319{
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001320 struct platform_data *my_data = (struct platform_data *)platform;
1321
Haynes Mathew George98c95622014-06-20 19:14:25 -07001322 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1323 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1324 return;
Ravi Kumar Alamanda1de6e5a2014-06-19 21:55:39 -05001325 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001326
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001327 const char * suffix = backend_tag_table[snd_device];
Haynes Mathew George98c95622014-06-20 19:14:25 -07001328
1329 if (suffix != NULL) {
1330 strcat(mixer_path, " ");
1331 strcat(mixer_path, suffix);
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001332 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001333}
1334
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001335bool platform_check_backends_match(snd_device_t snd_device1, snd_device_t snd_device2)
1336{
1337 bool result = true;
1338
1339 ALOGV("%s: snd_device1 = %s, snd_device2 = %s", __func__,
1340 platform_get_snd_device_name(snd_device1),
1341 platform_get_snd_device_name(snd_device2));
1342
1343 if ((snd_device1 < SND_DEVICE_MIN) || (snd_device1 >= SND_DEVICE_MAX)) {
1344 ALOGE("%s: Invalid snd_device = %s", __func__,
1345 platform_get_snd_device_name(snd_device1));
1346 return false;
1347 }
1348 if ((snd_device2 < SND_DEVICE_MIN) || (snd_device2 >= SND_DEVICE_MAX)) {
1349 ALOGE("%s: Invalid snd_device = %s", __func__,
1350 platform_get_snd_device_name(snd_device2));
1351 return false;
1352 }
1353 const char * be_itf1 = hw_interface_table[snd_device1];
1354 const char * be_itf2 = hw_interface_table[snd_device2];
1355
1356 if (NULL != be_itf1 && NULL != be_itf2) {
Eric Laurente63e61d2015-09-10 12:19:33 -07001357 if ((NULL == strstr(be_itf2, be_itf1)) && (NULL == strstr(be_itf1, be_itf2)))
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001358 result = false;
1359 }
1360
1361 ALOGV("%s: be_itf1 = %s, be_itf2 = %s, match %d", __func__, be_itf1, be_itf2, result);
1362 return result;
1363}
1364
Eric Laurentb23d5282013-05-14 15:27:20 -07001365int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
1366{
1367 int device_id;
1368 if (device_type == PCM_PLAYBACK)
1369 device_id = pcm_device_table[usecase][0];
1370 else
1371 device_id = pcm_device_table[usecase][1];
1372 return device_id;
1373}
1374
Haynes Mathew George98c95622014-06-20 19:14:25 -07001375static int find_index(const struct name_to_index * table, int32_t len,
1376 const char * name)
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001377{
1378 int ret = 0;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001379 int32_t i;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001380
Haynes Mathew George98c95622014-06-20 19:14:25 -07001381 if (table == NULL) {
1382 ALOGE("%s: table is NULL", __func__);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001383 ret = -ENODEV;
1384 goto done;
1385 }
1386
Haynes Mathew George98c95622014-06-20 19:14:25 -07001387 if (name == NULL) {
1388 ALOGE("null key");
1389 ret = -ENODEV;
1390 goto done;
1391 }
1392
1393 for (i=0; i < len; i++) {
1394 if (!strcmp(table[i].name, name)) {
1395 ret = table[i].index;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001396 goto done;
1397 }
1398 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001399 ALOGE("%s: Could not find index for name = %s",
1400 __func__, name);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001401 ret = -ENODEV;
1402done:
1403 return ret;
1404}
1405
Haynes Mathew George98c95622014-06-20 19:14:25 -07001406int platform_get_snd_device_index(char *device_name)
1407{
1408 return find_index(snd_device_name_index, SND_DEVICE_MAX, device_name);
1409}
1410
1411int platform_get_usecase_index(const char *usecase_name)
1412{
1413 return find_index(usecase_name_index, AUDIO_USECASE_MAX, usecase_name);
1414}
1415
keunhui.park2f7306a2015-07-16 16:48:06 +09001416void platform_add_operator_specific_device(snd_device_t snd_device,
1417 const char *operator,
1418 const char *mixer_path,
1419 unsigned int acdb_id)
1420{
1421 struct operator_specific_device *device;
1422
1423 if (operator_specific_device_table[snd_device] == NULL) {
1424 operator_specific_device_table[snd_device] =
1425 (struct listnode *)calloc(1, sizeof(struct listnode));
1426 list_init(operator_specific_device_table[snd_device]);
1427 }
1428
1429 device = (struct operator_specific_device *)calloc(1, sizeof(struct operator_specific_device));
1430
1431 device->operator = strdup(operator);
1432 device->mixer_path = strdup(mixer_path);
1433 device->acdb_id = acdb_id;
1434
1435 list_add_tail(operator_specific_device_table[snd_device], &device->list);
1436
Eric Laurent2bafff12016-03-17 12:17:23 -07001437 ALOGD("%s: device[%s] -> operator[%s] mixer_path[%s] acdb_id[%d]", __func__,
keunhui.park2f7306a2015-07-16 16:48:06 +09001438 platform_get_snd_device_name(snd_device), operator, mixer_path, acdb_id);
1439
1440}
1441
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001442int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
1443{
1444 int ret = 0;
1445
1446 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1447 ALOGE("%s: Invalid snd_device = %d",
1448 __func__, snd_device);
1449 ret = -EINVAL;
1450 goto done;
1451 }
1452
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001453 ALOGV("%s: acdb_device_table[%s]: old = %d new = %d", __func__,
1454 platform_get_snd_device_name(snd_device), acdb_device_table[snd_device], acdb_id);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001455 acdb_device_table[snd_device] = acdb_id;
1456done:
1457 return ret;
1458}
1459
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001460int platform_get_snd_device_acdb_id(snd_device_t snd_device)
1461{
1462 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1463 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1464 return -EINVAL;
1465 }
keunhui.park2f7306a2015-07-16 16:48:06 +09001466
1467 if (operator_specific_device_table[snd_device] != NULL)
1468 return get_operator_specific_device_acdb_id(snd_device);
1469 else
1470 return acdb_device_table[snd_device];
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001471}
1472
Eric Laurentb23d5282013-05-14 15:27:20 -07001473int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
1474{
1475 struct platform_data *my_data = (struct platform_data *)platform;
1476 int acdb_dev_id, acdb_dev_type;
1477
Ravi Kumar Alamandaadf0f3b2015-06-04 02:34:02 -07001478 acdb_dev_id = acdb_device_table[audio_extn_get_spkr_prot_snd_device(snd_device)];
Eric Laurentb23d5282013-05-14 15:27:20 -07001479 if (acdb_dev_id < 0) {
1480 ALOGE("%s: Could not find acdb id for device(%d)",
1481 __func__, snd_device);
1482 return -EINVAL;
1483 }
1484 if (my_data->acdb_send_audio_cal) {
Joe Onorato188b6222016-03-01 11:02:27 -08001485 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Eric Laurentb23d5282013-05-14 15:27:20 -07001486 __func__, snd_device, acdb_dev_id);
1487 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
1488 snd_device < SND_DEVICE_OUT_END)
1489 acdb_dev_type = ACDB_DEV_TYPE_OUT;
1490 else
1491 acdb_dev_type = ACDB_DEV_TYPE_IN;
1492 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
1493 }
1494 return 0;
1495}
1496
1497int platform_switch_voice_call_device_pre(void *platform)
1498{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001499 struct platform_data *my_data = (struct platform_data *)platform;
1500 int ret = 0;
1501
1502 if (my_data->csd != NULL &&
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001503 voice_is_in_call(my_data->adev)) {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001504 /* This must be called before disabling mixer controls on APQ side */
1505 ret = my_data->csd->disable_device();
1506 if (ret < 0) {
1507 ALOGE("%s: csd_client_disable_device, failed, error %d",
1508 __func__, ret);
1509 }
1510 }
1511 return ret;
1512}
1513
1514int platform_switch_voice_call_enable_device_config(void *platform,
1515 snd_device_t out_snd_device,
1516 snd_device_t in_snd_device)
1517{
1518 struct platform_data *my_data = (struct platform_data *)platform;
1519 int acdb_rx_id, acdb_tx_id;
1520 int ret = 0;
1521
1522 if (my_data->csd == NULL)
1523 return ret;
1524
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001525 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1526 audio_extn_spkr_prot_is_enabled())
keunhui.park2f7306a2015-07-16 16:48:06 +09001527 acdb_rx_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_SPEAKER_PROTECTED);
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001528 else
keunhui.park2f7306a2015-07-16 16:48:06 +09001529 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001530
keunhui.park2f7306a2015-07-16 16:48:06 +09001531 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001532
1533 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
1534 ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
1535 if (ret < 0) {
1536 ALOGE("%s: csd_enable_device_config, failed, error %d",
1537 __func__, ret);
1538 }
1539 } else {
1540 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1541 acdb_rx_id, acdb_tx_id);
1542 }
1543
1544 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001545}
1546
1547int platform_switch_voice_call_device_post(void *platform,
1548 snd_device_t out_snd_device,
1549 snd_device_t in_snd_device)
1550{
1551 struct platform_data *my_data = (struct platform_data *)platform;
1552 int acdb_rx_id, acdb_tx_id;
1553
1554 if (my_data->acdb_send_voice_cal == NULL) {
1555 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
1556 } else {
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001557 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1558 audio_extn_spkr_prot_is_enabled())
1559 out_snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED;
1560
keunhui.park2f7306a2015-07-16 16:48:06 +09001561 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
1562 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07001563
1564 if (acdb_rx_id > 0 && acdb_tx_id > 0)
1565 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
1566 else
1567 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1568 acdb_rx_id, acdb_tx_id);
1569 }
1570
1571 return 0;
1572}
1573
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001574int platform_switch_voice_call_usecase_route_post(void *platform,
1575 snd_device_t out_snd_device,
1576 snd_device_t in_snd_device)
1577{
1578 struct platform_data *my_data = (struct platform_data *)platform;
1579 int acdb_rx_id, acdb_tx_id;
1580 int ret = 0;
1581
1582 if (my_data->csd == NULL)
1583 return ret;
1584
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001585 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1586 audio_extn_spkr_prot_is_enabled())
keunhui.park2f7306a2015-07-16 16:48:06 +09001587 acdb_rx_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED);
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001588 else
keunhui.park2f7306a2015-07-16 16:48:06 +09001589 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001590
keunhui.park2f7306a2015-07-16 16:48:06 +09001591 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001592
1593 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
1594 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
1595 my_data->adev->acdb_settings);
1596 if (ret < 0) {
1597 ALOGE("%s: csd_enable_device, failed, error %d", __func__, ret);
1598 }
1599 } else {
1600 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1601 acdb_rx_id, acdb_tx_id);
1602 }
1603
1604 return ret;
1605}
1606
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001607int platform_start_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07001608{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001609 struct platform_data *my_data = (struct platform_data *)platform;
1610 int ret = 0;
1611
1612 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001613 ret = my_data->csd->start_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001614 if (ret < 0) {
1615 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
1616 }
1617 }
1618 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001619}
1620
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001621int platform_stop_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07001622{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001623 struct platform_data *my_data = (struct platform_data *)platform;
1624 int ret = 0;
1625
1626 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001627 ret = my_data->csd->stop_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001628 if (ret < 0) {
1629 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
1630 }
1631 }
1632 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001633}
1634
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001635int platform_get_sample_rate(void *platform, uint32_t *rate)
1636{
1637 struct platform_data *my_data = (struct platform_data *)platform;
1638 int ret = 0;
1639
1640 if (my_data->csd != NULL) {
1641 ret = my_data->csd->get_sample_rate(rate);
1642 if (ret < 0) {
1643 ALOGE("%s: csd_get_sample_rate error %d\n", __func__, ret);
1644 }
1645 }
1646 return ret;
1647}
1648
vivek mehtab6506412015-08-07 16:55:17 -07001649void platform_set_speaker_gain_in_combo(struct audio_device *adev,
1650 snd_device_t snd_device,
1651 bool enable)
1652{
1653 const char* name;
1654 switch (snd_device) {
1655 case SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES:
1656 if (enable)
1657 name = "spkr-gain-in-headphone-combo";
1658 else
1659 name = "speaker-gain-default";
1660 break;
1661 case SND_DEVICE_OUT_SPEAKER_AND_LINE:
1662 if (enable)
1663 name = "spkr-gain-in-line-combo";
1664 else
1665 name = "speaker-gain-default";
1666 break;
1667 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES:
1668 if (enable)
1669 name = "spkr-safe-gain-in-headphone-combo";
1670 else
1671 name = "speaker-safe-gain-default";
1672 break;
1673 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE:
1674 if (enable)
1675 name = "spkr-safe-gain-in-line-combo";
1676 else
1677 name = "speaker-safe-gain-default";
1678 break;
1679 default:
1680 return;
1681 }
1682
1683 audio_route_apply_and_update_path(adev->audio_route, name);
1684}
1685
Eric Laurentb23d5282013-05-14 15:27:20 -07001686int platform_set_voice_volume(void *platform, int volume)
1687{
1688 struct platform_data *my_data = (struct platform_data *)platform;
1689 struct audio_device *adev = my_data->adev;
1690 struct mixer_ctl *ctl;
sangwoo53b2cf02013-07-25 19:18:44 -07001691 const char *mixer_ctl_name = "Voice Rx Gain";
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001692 int vol_index = 0, ret = 0;
1693 uint32_t set_values[ ] = {0,
1694 ALL_SESSION_VSID,
1695 DEFAULT_VOLUME_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07001696
1697 // Voice volume levels are mapped to adsp volume levels as follows.
1698 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
1699 // But this values don't changed in kernel. So, below change is need.
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09001700 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, my_data->max_vol_index);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001701 set_values[0] = vol_index;
Eric Laurentb23d5282013-05-14 15:27:20 -07001702
1703 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1704 if (!ctl) {
1705 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1706 __func__, mixer_ctl_name);
1707 return -EINVAL;
1708 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001709 ALOGV("Setting voice volume index: %d", set_values[0]);
1710 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1711
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001712 if (my_data->csd != NULL) {
1713 ret = my_data->csd->volume(ALL_SESSION_VSID, volume,
1714 DEFAULT_VOLUME_RAMP_DURATION_MS);
1715 if (ret < 0) {
1716 ALOGE("%s: csd_volume error %d", __func__, ret);
1717 }
1718 }
1719 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001720}
1721
1722int platform_set_mic_mute(void *platform, bool state)
1723{
1724 struct platform_data *my_data = (struct platform_data *)platform;
1725 struct audio_device *adev = my_data->adev;
1726 struct mixer_ctl *ctl;
1727 const char *mixer_ctl_name = "Voice Tx Mute";
sangwoo53b2cf02013-07-25 19:18:44 -07001728 int ret = 0;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001729 uint32_t set_values[ ] = {0,
1730 ALL_SESSION_VSID,
1731 DEFAULT_MUTE_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07001732
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09001733 if (adev->mode != AUDIO_MODE_IN_CALL &&
1734 adev->mode != AUDIO_MODE_IN_COMMUNICATION)
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001735 return 0;
1736
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09001737 if (adev->enable_hfp)
1738 mixer_ctl_name = "HFP Tx Mute";
1739
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001740 set_values[0] = state;
1741 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1742 if (!ctl) {
1743 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1744 __func__, mixer_ctl_name);
1745 return -EINVAL;
1746 }
1747 ALOGV("Setting voice mute state: %d", state);
1748 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1749
1750 if (my_data->csd != NULL) {
1751 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state,
1752 DEFAULT_MUTE_RAMP_DURATION_MS);
sangwoo53b2cf02013-07-25 19:18:44 -07001753 if (ret < 0) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001754 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
sangwoo53b2cf02013-07-25 19:18:44 -07001755 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001756 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001757 return ret;
1758}
Eric Laurentb23d5282013-05-14 15:27:20 -07001759
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001760int platform_set_device_mute(void *platform, bool state, char *dir)
1761{
1762 struct platform_data *my_data = (struct platform_data *)platform;
1763 struct audio_device *adev = my_data->adev;
1764 struct mixer_ctl *ctl;
1765 char *mixer_ctl_name = NULL;
1766 int ret = 0;
1767 uint32_t set_values[ ] = {0,
1768 ALL_SESSION_VSID,
1769 0};
1770 if(dir == NULL) {
1771 ALOGE("%s: Invalid direction:%s", __func__, dir);
1772 return -EINVAL;
1773 }
1774
1775 if (!strncmp("rx", dir, sizeof("rx"))) {
1776 mixer_ctl_name = "Voice Rx Device Mute";
1777 } else if (!strncmp("tx", dir, sizeof("tx"))) {
1778 mixer_ctl_name = "Voice Tx Device Mute";
1779 } else {
1780 return -EINVAL;
1781 }
1782
1783 set_values[0] = state;
1784 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1785 if (!ctl) {
1786 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1787 __func__, mixer_ctl_name);
1788 return -EINVAL;
1789 }
1790
1791 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
1792 __func__,state, mixer_ctl_name);
1793 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1794
1795 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001796}
1797
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001798bool platform_can_split_snd_device(snd_device_t snd_device,
1799 int *num_devices,
1800 snd_device_t *new_snd_devices)
1801{
1802 bool status = false;
1803
1804 if (NULL == num_devices || NULL == new_snd_devices) {
1805 ALOGE("%s: NULL pointer ..", __func__);
1806 return false;
1807 }
1808
1809 /*
1810 * If wired headset/headphones/line devices share the same backend
1811 * with speaker/earpiece this routine returns false.
1812 */
1813 if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES &&
1814 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_HEADPHONES)) {
1815 *num_devices = 2;
1816 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
1817 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
1818 status = true;
1819 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_LINE &&
1820 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_LINE)) {
1821 *num_devices = 2;
1822 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
1823 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
1824 status = true;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001825 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES &&
1826 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_HEADPHONES)) {
1827 *num_devices = 2;
1828 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
1829 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
1830 status = true;
1831 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE &&
1832 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_LINE)) {
1833 *num_devices = 2;
1834 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
1835 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
1836 status = true;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001837 }
1838 return status;
1839}
1840
Eric Laurentb23d5282013-05-14 15:27:20 -07001841snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
1842{
1843 struct platform_data *my_data = (struct platform_data *)platform;
1844 struct audio_device *adev = my_data->adev;
1845 audio_mode_t mode = adev->mode;
1846 snd_device_t snd_device = SND_DEVICE_NONE;
1847
1848 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
1849 if (devices == AUDIO_DEVICE_NONE ||
1850 devices & AUDIO_DEVICE_BIT_IN) {
1851 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
1852 goto exit;
1853 }
1854
Eric Laurent1b491552015-09-15 17:52:41 -07001855 if (popcount(devices) == 2) {
1856 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
1857 AUDIO_DEVICE_OUT_SPEAKER) ||
1858 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
1859 AUDIO_DEVICE_OUT_SPEAKER)) {
1860 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
1861 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
1862 AUDIO_DEVICE_OUT_SPEAKER)) {
1863 snd_device = SND_DEVICE_OUT_SPEAKER_AND_LINE;
1864 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
1865 AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
1866 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
1867 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
1868 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES;
1869 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
1870 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
1871 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE;
1872 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
1873 AUDIO_DEVICE_OUT_SPEAKER)) {
1874 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
1875 } else {
1876 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
1877 goto exit;
1878 }
1879 if (snd_device != SND_DEVICE_NONE) {
1880 goto exit;
1881 }
1882 }
1883
1884 if (popcount(devices) != 1) {
1885 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
1886 goto exit;
1887 }
1888
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001889 if (voice_is_in_call(adev) || adev->enable_voicerx) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001890 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05001891 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
1892 devices & AUDIO_DEVICE_OUT_LINE) {
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001893 if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05001894 (adev->voice.tty_mode == TTY_MODE_FULL))
Eric Laurentb23d5282013-05-14 15:27:20 -07001895 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001896 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05001897 (adev->voice.tty_mode == TTY_MODE_VCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07001898 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001899 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05001900 (adev->voice.tty_mode == TTY_MODE_HCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07001901 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05001902 else {
1903 if (devices & AUDIO_DEVICE_OUT_LINE)
1904 snd_device = SND_DEVICE_OUT_VOICE_LINE;
1905 else
1906 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
1907 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001908 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07001909 if (adev->bt_wb_speech_enabled) {
1910 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
1911 } else {
1912 snd_device = SND_DEVICE_OUT_BT_SCO;
1913 }
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07001914 } else if (devices & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07001915 if (!adev->enable_hfp) {
1916 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
1917 } else {
1918 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_HFP;
1919 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001920 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05001921 if(adev->voice.hac)
1922 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
1923 else if (is_operator_tmus())
Eric Laurentb23d5282013-05-14 15:27:20 -07001924 snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS;
1925 else
Eric Laurentb4d368e2014-06-25 10:21:54 -05001926 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07001927 } else if (devices & AUDIO_DEVICE_OUT_TELEPHONY_TX)
1928 snd_device = SND_DEVICE_OUT_VOICE_TX;
1929
Eric Laurentb23d5282013-05-14 15:27:20 -07001930 if (snd_device != SND_DEVICE_NONE) {
1931 goto exit;
1932 }
1933 }
1934
Eric Laurentb23d5282013-05-14 15:27:20 -07001935 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1936 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
1937 snd_device = SND_DEVICE_OUT_HEADPHONES;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05001938 } else if (devices & AUDIO_DEVICE_OUT_LINE) {
1939 snd_device = SND_DEVICE_OUT_LINE;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07001940 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) {
1941 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001942 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07001943 if (my_data->speaker_lr_swap)
Eric Laurentb23d5282013-05-14 15:27:20 -07001944 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
1945 else
1946 snd_device = SND_DEVICE_OUT_SPEAKER;
1947 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07001948 if (adev->bt_wb_speech_enabled) {
1949 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
1950 } else {
1951 snd_device = SND_DEVICE_OUT_BT_SCO;
1952 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001953 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
1954 snd_device = SND_DEVICE_OUT_HDMI ;
1955 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05001956 /*HAC support for voice-ish audio (eg visual voicemail)*/
1957 if(adev->voice.hac)
1958 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
1959 else
1960 snd_device = SND_DEVICE_OUT_HANDSET;
Eric Laurentb23d5282013-05-14 15:27:20 -07001961 } else {
1962 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
1963 }
1964exit:
1965 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
1966 return snd_device;
1967}
1968
1969snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
1970{
1971 struct platform_data *my_data = (struct platform_data *)platform;
1972 struct audio_device *adev = my_data->adev;
1973 audio_source_t source = (adev->active_input == NULL) ?
1974 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
1975
1976 audio_mode_t mode = adev->mode;
1977 audio_devices_t in_device = ((adev->active_input == NULL) ?
1978 AUDIO_DEVICE_NONE : adev->active_input->device)
1979 & ~AUDIO_DEVICE_BIT_IN;
1980 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
1981 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
1982 snd_device_t snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001983 int channel_count = popcount(channel_mask);
Eric Laurentb23d5282013-05-14 15:27:20 -07001984
Prashant Malanic92c5962015-08-11 15:10:18 -07001985 ALOGV("%s: enter: out_device(%#x) in_device(%#x) channel_count (%d) channel_mask (0x%x)",
1986 __func__, out_device, in_device, channel_count, channel_mask);
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001987 if ((out_device != AUDIO_DEVICE_NONE) && voice_is_in_call(adev)) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001988 if (adev->voice.tty_mode != TTY_MODE_OFF) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001989 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05001990 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
1991 out_device & AUDIO_DEVICE_OUT_LINE) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001992 switch (adev->voice.tty_mode) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001993 case TTY_MODE_FULL:
1994 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
1995 break;
1996 case TTY_MODE_VCO:
1997 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
1998 break;
1999 case TTY_MODE_HCO:
2000 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
2001 break;
2002 default:
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002003 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
Eric Laurentb23d5282013-05-14 15:27:20 -07002004 }
2005 goto exit;
2006 }
2007 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002008 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002009 if (my_data->fluence_in_voice_call == false) {
2010 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2011 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002012 if (is_operator_tmus())
2013 snd_device = SND_DEVICE_IN_VOICE_DMIC_TMUS;
Eric Laurentb23d5282013-05-14 15:27:20 -07002014 else
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002015 snd_device = SND_DEVICE_IN_VOICE_DMIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002016 }
2017 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2018 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
2019 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002020 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002021 if (adev->bluetooth_nrec)
2022 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2023 else
2024 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002025 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002026 if (adev->bluetooth_nrec)
2027 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2028 else
2029 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002030 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002031 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Prashant Malanic92c5962015-08-11 15:10:18 -07002032 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
2033 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2034 out_device & AUDIO_DEVICE_OUT_LINE) {
2035 if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
2036 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
2037 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
2038 } else {
2039 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2040 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002041 }
vivek mehtafe121d52015-08-10 23:39:23 -07002042
2043 //select default
2044 if (snd_device == SND_DEVICE_NONE) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002045 if (!adev->enable_hfp) {
2046 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2047 } else {
2048 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP;
2049 platform_set_echo_reference(adev, true, out_device);
2050 }
vivek mehtafe121d52015-08-10 23:39:23 -07002051 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002052 } else if (out_device & AUDIO_DEVICE_OUT_TELEPHONY_TX) {
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002053 snd_device = SND_DEVICE_IN_VOICE_RX;
Prashant Malanic92c5962015-08-11 15:10:18 -07002054 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002055 } else if (source == AUDIO_SOURCE_CAMCORDER) {
2056 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
2057 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2058 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
2059 }
2060 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
2061 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002062 if (my_data->fluence_in_voice_rec && channel_count == 1) {
2063 if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2064 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002065 if (adev->active_input->enable_aec)
2066 snd_device = SND_DEVICE_IN_HANDSET_QMIC_AEC;
2067 else
2068 snd_device = SND_DEVICE_IN_HANDSET_QMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002069 } else if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2070 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002071 if (adev->active_input->enable_aec)
2072 snd_device = SND_DEVICE_IN_HANDSET_TMIC_AEC;
2073 else
2074 snd_device = SND_DEVICE_IN_HANDSET_TMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002075 } else if (((my_data->fluence_type == FLUENCE_PRO_ENABLE) ||
2076 (my_data->fluence_type == FLUENCE_ENABLE)) &&
2077 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002078 if (adev->active_input->enable_aec)
2079 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
2080 else
2081 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
Prashant Malanic92c5962015-08-11 15:10:18 -07002082 }
2083 platform_set_echo_reference(adev, true, out_device);
2084 } else if ((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) &&
2085 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2086 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
2087 } else if (((int)channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
2088 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
2089 snd_device = SND_DEVICE_IN_THREE_MIC;
2090 } else if (((int)channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
2091 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2092 snd_device = SND_DEVICE_IN_QUAD_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002093 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002094 if (snd_device == SND_DEVICE_NONE) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002095 if (adev->active_input->enable_ns)
2096 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
vivek mehta733c1df2016-04-04 15:09:24 -07002097 else if (adev->active_input->enable_aec) {
2098 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC;
2099 platform_set_echo_reference(adev, true, out_device);
2100 } else
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002101 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002102 }
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -07002103 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2104 snd_device = SND_DEVICE_IN_VOICE_REC_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002105 }
rago90fb9612015-12-02 11:37:53 -08002106 } else if (source == AUDIO_SOURCE_UNPROCESSED) {
2107 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2108 snd_device = SND_DEVICE_IN_UNPROCESSED_MIC;
2109 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2110 snd_device = SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC;
2111 }
Eric Laurent50a38ed2015-10-14 18:48:06 -07002112 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION ||
rago90fb9612015-12-02 11:37:53 -08002113 mode == AUDIO_MODE_IN_COMMUNICATION) {
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002114 if (out_device & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE))
Eric Laurentb23d5282013-05-14 15:27:20 -07002115 in_device = AUDIO_DEVICE_IN_BACK_MIC;
2116 if (adev->active_input) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002117 if (adev->active_input->enable_aec &&
2118 adev->active_input->enable_ns) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002119 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002120 if (my_data->fluence_in_spkr_mode &&
2121 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002122 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002123 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002124 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002125 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002126 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002127 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002128 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002129 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002130 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002131 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002132 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002133 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002134 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2135 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002136 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002137 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002138 } else if (adev->active_input->enable_aec) {
2139 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2140 if (my_data->fluence_in_spkr_mode &&
2141 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002142 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002143 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002144 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002145 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002146 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002147 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2148 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002149 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002150 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002151 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002152 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002153 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002154 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2155 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
2156 }
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08002157 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002158 } else if (adev->active_input->enable_ns) {
2159 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2160 if (my_data->fluence_in_spkr_mode &&
2161 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002162 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002163 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002164 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002165 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002166 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002167 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2168 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002169 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002170 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002171 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002172 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002173 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002174 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002175 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002176 }
2177 } else if (source == AUDIO_SOURCE_DEFAULT) {
2178 goto exit;
2179 }
2180
2181
2182 if (snd_device != SND_DEVICE_NONE) {
2183 goto exit;
2184 }
2185
2186 if (in_device != AUDIO_DEVICE_NONE &&
2187 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
2188 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
2189 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002190 if ((my_data->source_mic_type & SOURCE_QUAD_MIC) &&
2191 (int)channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) {
2192 snd_device = SND_DEVICE_IN_QUAD_MIC;
2193 } else if ((my_data->source_mic_type & SOURCE_THREE_MIC) &&
2194 (int)channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) {
2195 snd_device = SND_DEVICE_IN_THREE_MIC;
2196 } else if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2197 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002198 snd_device = SND_DEVICE_IN_HANDSET_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002199 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2200 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002201 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002202 } else {
2203 ALOGE("%s: something wrong (1): source type (%d) channel_count (%d) .."
2204 " channel mask (0x%x) no combination found .. setting to mono", __func__,
2205 my_data->source_mic_type, channel_count, channel_mask);
2206 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2207 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002208 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002209 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2210 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002211 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002212 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2213 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002214 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002215 } else {
2216 ALOGE("%s: something wrong (2): source type (%d) channel_count (%d) .."
2217 " no combination found .. setting to mono", __func__,
2218 my_data->source_mic_type, channel_count);
2219 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
2220 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002221 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2222 snd_device = SND_DEVICE_IN_HEADSET_MIC;
2223 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002224 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002225 if (adev->bluetooth_nrec)
2226 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2227 else
2228 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002229 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002230 if (adev->bluetooth_nrec)
2231 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2232 else
2233 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002234 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002235 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
2236 snd_device = SND_DEVICE_IN_HDMI_MIC;
2237 } else {
2238 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
2239 ALOGW("%s: Using default handset-mic", __func__);
2240 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2241 }
2242 } else {
2243 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
2244 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2245 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2246 snd_device = SND_DEVICE_IN_HEADSET_MIC;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002247 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002248 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002249 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002250 out_device & AUDIO_DEVICE_OUT_LINE) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002251 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2252 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002253 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002254 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2255 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002256 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002257 } else {
2258 ALOGE("%s: something wrong (3): source type (%d) channel_count (%d) .."
2259 " no combination found .. setting to mono", __func__,
2260 my_data->source_mic_type, channel_count);
2261 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
2262 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002263 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002264 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002265 if (adev->bluetooth_nrec)
2266 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2267 else
2268 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002269 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002270 if (adev->bluetooth_nrec)
2271 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2272 else
2273 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002274 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002275 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2276 snd_device = SND_DEVICE_IN_HDMI_MIC;
2277 } else {
2278 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
2279 ALOGW("%s: Using default handset-mic", __func__);
2280 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2281 }
2282 }
2283exit:
2284 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
2285 return snd_device;
2286}
2287
2288int platform_set_hdmi_channels(void *platform, int channel_count)
2289{
2290 struct platform_data *my_data = (struct platform_data *)platform;
2291 struct audio_device *adev = my_data->adev;
2292 struct mixer_ctl *ctl;
2293 const char *channel_cnt_str = NULL;
2294 const char *mixer_ctl_name = "HDMI_RX Channels";
2295 switch (channel_count) {
2296 case 8:
2297 channel_cnt_str = "Eight"; break;
2298 case 7:
2299 channel_cnt_str = "Seven"; break;
2300 case 6:
2301 channel_cnt_str = "Six"; break;
2302 case 5:
2303 channel_cnt_str = "Five"; break;
2304 case 4:
2305 channel_cnt_str = "Four"; break;
2306 case 3:
2307 channel_cnt_str = "Three"; break;
2308 default:
2309 channel_cnt_str = "Two"; break;
2310 }
2311 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2312 if (!ctl) {
2313 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2314 __func__, mixer_ctl_name);
2315 return -EINVAL;
2316 }
2317 ALOGV("HDMI channel count: %s", channel_cnt_str);
2318 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
2319 return 0;
2320}
2321
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002322int platform_edid_get_max_channels(void *platform)
Eric Laurentb23d5282013-05-14 15:27:20 -07002323{
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002324 struct platform_data *my_data = (struct platform_data *)platform;
2325 struct audio_device *adev = my_data->adev;
Eric Laurentb23d5282013-05-14 15:27:20 -07002326 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
2327 char *sad = block;
2328 int num_audio_blocks;
2329 int channel_count;
2330 int max_channels = 0;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002331 int i, ret, count;
Eric Laurentb23d5282013-05-14 15:27:20 -07002332
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002333 struct mixer_ctl *ctl;
2334
2335 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
2336 if (!ctl) {
2337 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2338 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
Eric Laurentb23d5282013-05-14 15:27:20 -07002339 return 0;
2340 }
2341
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002342 mixer_ctl_update(ctl);
2343
2344 count = mixer_ctl_get_num_values(ctl);
Eric Laurentb23d5282013-05-14 15:27:20 -07002345
2346 /* Read SAD blocks, clamping the maximum size for safety */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002347 if (count > (int)sizeof(block))
2348 count = (int)sizeof(block);
Eric Laurentb23d5282013-05-14 15:27:20 -07002349
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002350 ret = mixer_ctl_get_array(ctl, block, count);
2351 if (ret != 0) {
2352 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
2353 return 0;
2354 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002355
2356 /* Calculate the number of SAD blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002357 num_audio_blocks = count / SAD_BLOCK_SIZE;
Eric Laurentb23d5282013-05-14 15:27:20 -07002358
2359 for (i = 0; i < num_audio_blocks; i++) {
2360 /* Only consider LPCM blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002361 if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
2362 sad += 3;
Eric Laurentb23d5282013-05-14 15:27:20 -07002363 continue;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002364 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002365
2366 channel_count = (sad[0] & 0x7) + 1;
2367 if (channel_count > max_channels)
2368 max_channels = channel_count;
2369
2370 /* Advance to next block */
2371 sad += 3;
2372 }
2373
2374 return max_channels;
2375}
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07002376
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002377int platform_set_incall_recording_session_id(void *platform,
2378 uint32_t session_id, int rec_mode)
2379{
2380 int ret = 0;
2381 struct platform_data *my_data = (struct platform_data *)platform;
2382 struct audio_device *adev = my_data->adev;
2383 struct mixer_ctl *ctl;
2384 const char *mixer_ctl_name = "Voc VSID";
2385 int num_ctl_values;
2386 int i;
2387
2388 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2389 if (!ctl) {
2390 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2391 __func__, mixer_ctl_name);
2392 ret = -EINVAL;
2393 } else {
2394 num_ctl_values = mixer_ctl_get_num_values(ctl);
2395 for (i = 0; i < num_ctl_values; i++) {
2396 if (mixer_ctl_set_value(ctl, i, session_id)) {
2397 ALOGV("Error: invalid session_id: %x", session_id);
2398 ret = -EINVAL;
2399 break;
2400 }
2401 }
2402 }
2403
2404 if (my_data->csd != NULL) {
2405 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
2406 if (ret < 0) {
2407 ALOGE("%s: csd_client_start_record failed, error %d",
2408 __func__, ret);
2409 }
2410 }
2411
2412 return ret;
2413}
2414
2415int platform_stop_incall_recording_usecase(void *platform)
2416{
2417 int ret = 0;
2418 struct platform_data *my_data = (struct platform_data *)platform;
2419
2420 if (my_data->csd != NULL) {
2421 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
2422 if (ret < 0) {
2423 ALOGE("%s: csd_client_stop_record failed, error %d",
2424 __func__, ret);
2425 }
2426 }
2427
2428 return ret;
2429}
2430
2431int platform_start_incall_music_usecase(void *platform)
2432{
2433 int ret = 0;
2434 struct platform_data *my_data = (struct platform_data *)platform;
2435
2436 if (my_data->csd != NULL) {
2437 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
2438 if (ret < 0) {
2439 ALOGE("%s: csd_client_start_playback failed, error %d",
2440 __func__, ret);
2441 }
2442 }
2443
2444 return ret;
2445}
2446
2447int platform_stop_incall_music_usecase(void *platform)
2448{
2449 int ret = 0;
2450 struct platform_data *my_data = (struct platform_data *)platform;
2451
2452 if (my_data->csd != NULL) {
2453 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
2454 if (ret < 0) {
2455 ALOGE("%s: csd_client_stop_playback failed, error %d",
2456 __func__, ret);
2457 }
2458 }
2459
2460 return ret;
2461}
2462
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002463int platform_set_parameters(void *platform, struct str_parms *parms)
2464{
2465 struct platform_data *my_data = (struct platform_data *)platform;
keunhui.park2f7306a2015-07-16 16:48:06 +09002466 char value[128];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002467 char *kv_pairs = str_parms_to_str(parms);
2468 int ret = 0, err;
2469
2470 if (kv_pairs == NULL) {
2471 ret = -EINVAL;
2472 ALOGE("%s: key-value pair is NULL",__func__);
2473 goto done;
2474 }
2475
2476 ALOGV("%s: enter: %s", __func__, kv_pairs);
2477
2478 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME,
2479 value, sizeof(value));
2480 if (err >= 0) {
2481 str_parms_del(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME);
2482 my_data->snd_card_name = strdup(value);
2483 ALOGV("%s: sound card name %s", __func__, my_data->snd_card_name);
2484 }
2485
keunhui.park2f7306a2015-07-16 16:48:06 +09002486 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO,
2487 value, sizeof(value));
2488 if (err >= 0) {
2489 struct operator_info *info;
2490 char *str = value;
2491 char *name;
2492
2493 str_parms_del(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO);
2494 info = (struct operator_info *)calloc(1, sizeof(struct operator_info));
2495 name = strtok(str, ";");
2496 info->name = strdup(name);
2497 info->mccmnc = strdup(str + strlen(name) + 1);
2498
2499 list_add_tail(&operator_info_list, &info->list);
Joe Onorato188b6222016-03-01 11:02:27 -08002500 ALOGV("%s: add operator[%s] mccmnc[%s]", __func__, info->name, info->mccmnc);
keunhui.park2f7306a2015-07-16 16:48:06 +09002501 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002502
2503 memset(value, 0, sizeof(value));
Eric Laurentc6333382015-09-14 12:43:44 -07002504 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT,
Prashant Malanic92c5962015-08-11 15:10:18 -07002505 value, sizeof(value));
2506 if (err >= 0) {
Eric Laurentc6333382015-09-14 12:43:44 -07002507 str_parms_del(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT);
Prashant Malanic92c5962015-08-11 15:10:18 -07002508 my_data->max_mic_count = atoi(value);
2509 ALOGV("%s: max_mic_count %s/%d", __func__, value, my_data->max_mic_count);
Prashant Malanic92c5962015-08-11 15:10:18 -07002510 }
2511
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002512done:
2513 ALOGV("%s: exit with code(%d)", __func__, ret);
2514 if (kv_pairs != NULL)
2515 free(kv_pairs);
2516
2517 return ret;
2518}
2519
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07002520/* Delay in Us */
2521int64_t platform_render_latency(audio_usecase_t usecase)
2522{
2523 switch (usecase) {
2524 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
2525 return DEEP_BUFFER_PLATFORM_DELAY;
2526 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
2527 return LOW_LATENCY_PLATFORM_DELAY;
Haynes Mathew George03c40102016-01-29 17:57:48 -08002528 case USECASE_AUDIO_PLAYBACK_ULL:
2529 return ULL_PLATFORM_DELAY;
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07002530 default:
2531 return 0;
2532 }
2533}
Haynes Mathew George98c95622014-06-20 19:14:25 -07002534
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002535int platform_set_snd_device_backend(snd_device_t device, const char *backend_tag,
2536 const char * hw_interface)
Haynes Mathew George98c95622014-06-20 19:14:25 -07002537{
2538 int ret = 0;
2539
2540 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
2541 ALOGE("%s: Invalid snd_device = %d",
2542 __func__, device);
2543 ret = -EINVAL;
2544 goto done;
2545 }
2546
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002547 ALOGV("%s: backend_tag_table[%s]: old = %s new = %s", __func__,
2548 platform_get_snd_device_name(device),
2549 backend_tag_table[device] != NULL ? backend_tag_table[device]: "null", backend_tag);
2550 if (backend_tag_table[device]) {
2551 free(backend_tag_table[device]);
Haynes Mathew George98c95622014-06-20 19:14:25 -07002552 }
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002553 backend_tag_table[device] = strdup(backend_tag);
2554
2555 if (hw_interface != NULL) {
2556 if (hw_interface_table[device])
2557 free(hw_interface_table[device]);
2558 ALOGV("%s: hw_interface_table[%d] = %s", __func__, device, hw_interface);
2559 hw_interface_table[device] = strdup(hw_interface);
2560 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07002561done:
2562 return ret;
2563}
2564
2565int platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t pcm_id)
2566{
2567 int ret = 0;
2568 if ((usecase <= USECASE_INVALID) || (usecase >= AUDIO_USECASE_MAX)) {
2569 ALOGE("%s: invalid usecase case idx %d", __func__, usecase);
2570 ret = -EINVAL;
2571 goto done;
2572 }
2573
2574 if ((type != 0) && (type != 1)) {
2575 ALOGE("%s: invalid usecase type", __func__);
2576 ret = -EINVAL;
2577 }
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002578 ALOGV("%s: pcm_device_table[%d][%d] = %d", __func__, usecase, type, pcm_id);
Haynes Mathew George98c95622014-06-20 19:14:25 -07002579 pcm_device_table[usecase][type] = pcm_id;
2580done:
2581 return ret;
2582}
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002583
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07002584#define DEFAULT_NOMINAL_SPEAKER_GAIN 20
2585int ramp_speaker_gain(struct audio_device *adev, bool ramp_up, int target_ramp_up_gain) {
2586 // backup_gain: gain to try to set in case of an error during ramp
2587 int start_gain, end_gain, step, backup_gain, i;
2588 bool error = false;
2589 const struct mixer_ctl *ctl;
2590 const char *mixer_ctl_name_gain_left = "Left Speaker Gain";
2591 const char *mixer_ctl_name_gain_right = "Right Speaker Gain";
2592 struct mixer_ctl *ctl_left = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_left);
2593 struct mixer_ctl *ctl_right = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_right);
2594 if (!ctl_left || !ctl_right) {
2595 ALOGE("%s: Could not get ctl for mixer cmd - %s or %s, not applying speaker gain ramp",
2596 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
2597 return -EINVAL;
2598 } else if ((mixer_ctl_get_num_values(ctl_left) != 1)
2599 || (mixer_ctl_get_num_values(ctl_right) != 1)) {
2600 ALOGE("%s: Unexpected num values for mixer cmd - %s or %s, not applying speaker gain ramp",
2601 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
2602 return -EINVAL;
2603 }
2604 if (ramp_up) {
2605 start_gain = 0;
2606 end_gain = target_ramp_up_gain > 0 ? target_ramp_up_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
2607 step = +1;
2608 backup_gain = end_gain;
2609 } else {
2610 // using same gain on left and right
2611 const int left_gain = mixer_ctl_get_value(ctl_left, 0);
2612 start_gain = left_gain > 0 ? left_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
2613 end_gain = 0;
2614 step = -1;
2615 backup_gain = start_gain;
2616 }
2617 for (i = start_gain ; i != (end_gain + step) ; i += step) {
2618 //ALOGV("setting speaker gain to %d", i);
2619 if (mixer_ctl_set_value(ctl_left, 0, i)) {
2620 ALOGE("%s: error setting %s to %d during gain ramp",
2621 __func__, mixer_ctl_name_gain_left, i);
2622 error = true;
2623 break;
2624 }
2625 if (mixer_ctl_set_value(ctl_right, 0, i)) {
2626 ALOGE("%s: error setting %s to %d during gain ramp",
2627 __func__, mixer_ctl_name_gain_right, i);
2628 error = true;
2629 break;
2630 }
2631 usleep(1000);
2632 }
2633 if (error) {
2634 // an error occured during the ramp, let's still try to go back to a safe volume
2635 if (mixer_ctl_set_value(ctl_left, 0, backup_gain)) {
2636 ALOGE("%s: error restoring left gain to %d", __func__, backup_gain);
2637 }
2638 if (mixer_ctl_set_value(ctl_right, 0, backup_gain)) {
2639 ALOGE("%s: error restoring right gain to %d", __func__, backup_gain);
2640 }
2641 }
2642 return start_gain;
2643}
2644
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002645int platform_swap_lr_channels(struct audio_device *adev, bool swap_channels)
2646{
2647 // only update if there is active pcm playback on speaker
2648 struct audio_usecase *usecase;
2649 struct listnode *node;
2650 struct platform_data *my_data = (struct platform_data *)adev->platform;
2651
2652 if (my_data->speaker_lr_swap != swap_channels) {
2653 my_data->speaker_lr_swap = swap_channels;
2654
2655 list_for_each(node, &adev->usecase_list) {
2656 usecase = node_to_item(node, struct audio_usecase, list);
2657 if (usecase->type == PCM_PLAYBACK &&
Ravi Kumar Alamanda425e1542015-09-22 09:11:18 -07002658 usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) {
2659 /*
2660 * If acdb tuning is different for SPEAKER_REVERSE, it is must
2661 * to perform device switch to disable the current backend to
2662 * enable it with new acdb data.
2663 */
2664 if (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
2665 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]) {
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07002666 const int initial_skpr_gain = ramp_speaker_gain(adev, false /*ramp_up*/, -1);
Ravi Kumar Alamanda425e1542015-09-22 09:11:18 -07002667 select_devices(adev, usecase->id);
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07002668 if (initial_skpr_gain != -EINVAL) {
2669 ramp_speaker_gain(adev, true /*ramp_up*/, initial_skpr_gain);
2670 }
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002671 } else {
Ravi Kumar Alamanda425e1542015-09-22 09:11:18 -07002672 const char *mixer_path;
2673 if (swap_channels) {
2674 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER_REVERSE);
2675 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
2676 } else {
2677 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER);
2678 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
2679 }
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002680 }
2681 break;
2682 }
2683 }
2684 }
2685 return 0;
2686}