blob: 5acf86f5e7ac16cbf0a240bb2523b3d300d701e3 [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",
vivek mehta4ed66e62016-04-15 23:33:34 -0700267 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = "voice-rec-dmic-ef",
268 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = "three-mic",
269 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = "quad-mic",
rago90fb9612015-12-02 11:37:53 -0800270 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = "headset-mic",
271
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700272 [SND_DEVICE_IN_VOICE_RX] = "voice-rx",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700273
Prashant Malanic92c5962015-08-11 15:10:18 -0700274 [SND_DEVICE_IN_THREE_MIC] = "three-mic",
275 [SND_DEVICE_IN_QUAD_MIC] = "quad-mic",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700276 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = "vi-feedback",
Prashant Malanic92c5962015-08-11 15:10:18 -0700277 [SND_DEVICE_IN_HANDSET_TMIC] = "three-mic",
278 [SND_DEVICE_IN_HANDSET_QMIC] = "quad-mic",
vivek mehta733c1df2016-04-04 15:09:24 -0700279 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = "three-mic",
280 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = "quad-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700281};
282
283/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700284static int acdb_device_table[SND_DEVICE_MAX] = {
Eric Laurentb23d5282013-05-14 15:27:20 -0700285 [SND_DEVICE_NONE] = -1,
286 [SND_DEVICE_OUT_HANDSET] = 7,
287 [SND_DEVICE_OUT_SPEAKER] = 15,
288 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 15,
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700289 [SND_DEVICE_OUT_SPEAKER_SAFE] = 15,
Eric Laurentb23d5282013-05-14 15:27:20 -0700290 [SND_DEVICE_OUT_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500291 [SND_DEVICE_OUT_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700292 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700293 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500294 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = 77,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700295 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = 77,
Ravi Kumar Alamanda235c3482014-08-21 17:32:44 -0700296 [SND_DEVICE_OUT_VOICE_HANDSET] = ACDB_ID_VOICE_HANDSET,
297 [SND_DEVICE_OUT_VOICE_SPEAKER] = ACDB_ID_VOICE_SPEAKER,
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500298 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = 53,
Eric Laurentb23d5282013-05-14 15:27:20 -0700299 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500300 [SND_DEVICE_OUT_VOICE_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700301 [SND_DEVICE_OUT_HDMI] = 18,
302 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 15,
303 [SND_DEVICE_OUT_BT_SCO] = 22,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700304 [SND_DEVICE_OUT_BT_SCO_WB] = 39,
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700305 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = ACDB_ID_VOICE_HANDSET_TMUS,
Eric Laurentb23d5282013-05-14 15:27:20 -0700306 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
307 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
308 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700309 [SND_DEVICE_OUT_VOICE_TX] = 45,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700310 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = 124,
311 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = 101,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700312 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = ACDB_ID_VOICE_SPEAKER,
Eric Laurentb23d5282013-05-14 15:27:20 -0700313
314 [SND_DEVICE_IN_HANDSET_MIC] = 4,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700315 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 106,
316 [SND_DEVICE_IN_HANDSET_MIC_NS] = 107,
317 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = 108,
318 [SND_DEVICE_IN_HANDSET_DMIC] = 41,
319 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = 109,
320 [SND_DEVICE_IN_HANDSET_DMIC_NS] = 110,
321 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = 111,
322 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = 34,
323
324 [SND_DEVICE_IN_SPEAKER_MIC] = 11,
325 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 112,
326 [SND_DEVICE_IN_SPEAKER_MIC_NS] = 113,
327 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = 114,
328 [SND_DEVICE_IN_SPEAKER_DMIC] = 43,
329 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = 115,
330 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = 116,
331 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = 117,
332 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = 35,
333
rago90fb9612015-12-02 11:37:53 -0800334 [SND_DEVICE_IN_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentcefbbac2014-09-04 13:54:10 -0500335 [SND_DEVICE_IN_HEADSET_MIC_AEC] = ACDB_ID_HEADSET_MIC_AEC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700336
Eric Laurentb23d5282013-05-14 15:27:20 -0700337 [SND_DEVICE_IN_HDMI_MIC] = 4,
338 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700339 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = 21,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700340 [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700341 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = 38,
Eric Laurentb23d5282013-05-14 15:27:20 -0700342 [SND_DEVICE_IN_CAMCORDER_MIC] = 61,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700343
344 [SND_DEVICE_IN_VOICE_DMIC] = 41,
345 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = ACDB_ID_VOICE_DMIC_EF_TMUS,
346 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700347 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = 11,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700348 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 43,
rago90fb9612015-12-02 11:37:53 -0800349 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentb23d5282013-05-14 15:27:20 -0700350 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
351 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
352 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700353
rago90fb9612015-12-02 11:37:53 -0800354 [SND_DEVICE_IN_VOICE_REC_MIC] = ACDB_ID_VOICE_REC_MIC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700355 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = 113,
vivek mehta733c1df2016-04-04 15:09:24 -0700356 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = 112,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700357 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = 35,
358 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 43,
rago90fb9612015-12-02 11:37:53 -0800359 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
360
361 [SND_DEVICE_IN_UNPROCESSED_MIC] = ACDB_ID_VOICE_REC_MIC,
362 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
vivek mehta4ed66e62016-04-15 23:33:34 -0700363 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = 35,
364 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = 125,
365 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = 125,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700366
367 [SND_DEVICE_IN_VOICE_RX] = 44,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700368
Prashant Malanic92c5962015-08-11 15:10:18 -0700369 [SND_DEVICE_IN_THREE_MIC] = 46,
370 [SND_DEVICE_IN_QUAD_MIC] = 46,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700371 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = 102,
Prashant Malanic92c5962015-08-11 15:10:18 -0700372 [SND_DEVICE_IN_HANDSET_TMIC] = 125,
373 [SND_DEVICE_IN_HANDSET_QMIC] = 125,
vivek mehta733c1df2016-04-04 15:09:24 -0700374 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = 125, /* override this for new target to 140 */
375 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = 125, /* override this for new target to 140 */
Eric Laurentb23d5282013-05-14 15:27:20 -0700376};
377
Haynes Mathew George98c95622014-06-20 19:14:25 -0700378struct name_to_index {
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700379 char name[100];
380 unsigned int index;
381};
382
383#define TO_NAME_INDEX(X) #X, X
384
Haynes Mathew George98c95622014-06-20 19:14:25 -0700385/* Used to get index from parsed string */
386static const struct name_to_index snd_device_name_index[SND_DEVICE_MAX] = {
387 /* out */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700388 {TO_NAME_INDEX(SND_DEVICE_OUT_HANDSET)},
389 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER)},
390 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_REVERSE)},
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700391 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700392 {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500393 {TO_NAME_INDEX(SND_DEVICE_OUT_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700394 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700395 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES)},
Eric Laurent744996b2014-10-01 11:40:40 -0500396 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_LINE)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700397 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700398 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET)},
399 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700400 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_HFP)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700401 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500402 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700403 {TO_NAME_INDEX(SND_DEVICE_OUT_HDMI)},
404 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HDMI)},
405 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO)},
406 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO_WB)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700407 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET_TMUS)},
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500408 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HAC_HANDSET)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700409 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES)},
410 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES)},
411 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700412
413 /* in */
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700414 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED)},
415 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700416 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700417 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700418 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_NS)},
419 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)},
420 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC)},
421 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC)},
422 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_NS)},
423 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)},
424 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_STEREO)},
425
426 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700427 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700428 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_NS)},
429 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)},
430 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC)},
431 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC)},
432 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS)},
433 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)},
434 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_STEREO)},
435
436 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC)},
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700437 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700438
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700439 {TO_NAME_INDEX(SND_DEVICE_IN_HDMI_MIC)},
440 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700441 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700442 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700443 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700444 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700445
446 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC)},
447 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC_TMUS)},
448 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700449 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700450 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC)},
451 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEADSET_MIC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700452 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC)},
453 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC)},
454 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700455
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700456 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700457 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_NS)},
vivek mehta733c1df2016-04-04 15:09:24 -0700458 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700459 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_STEREO)},
460 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE)},
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700461 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_HEADSET_MIC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700462
rago90fb9612015-12-02 11:37:53 -0800463 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_MIC)},
464 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC)},
vivek mehta4ed66e62016-04-15 23:33:34 -0700465 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_STEREO_MIC)},
466 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_THREE_MIC)},
467 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_QUAD_MIC)},
rago90fb9612015-12-02 11:37:53 -0800468
Prashant Malanic92c5962015-08-11 15:10:18 -0700469 {TO_NAME_INDEX(SND_DEVICE_IN_THREE_MIC)},
470 {TO_NAME_INDEX(SND_DEVICE_IN_QUAD_MIC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700471 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_VI_FEEDBACK)},
Prashant Malanic92c5962015-08-11 15:10:18 -0700472 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC)},
473 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC)},
vivek mehta733c1df2016-04-04 15:09:24 -0700474 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC_AEC)},
475 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC_AEC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700476};
477
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700478static char * backend_tag_table[SND_DEVICE_MAX] = {0};
479static char * hw_interface_table[SND_DEVICE_MAX] = {0};
Haynes Mathew George98c95622014-06-20 19:14:25 -0700480
481static const struct name_to_index usecase_name_index[AUDIO_USECASE_MAX] = {
482 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_DEEP_BUFFER)},
483 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_LOW_LATENCY)},
484 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_MULTI_CH)},
485 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD)},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700486 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_TTS)},
487 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_ULL)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700488 {TO_NAME_INDEX(USECASE_AUDIO_RECORD)},
489 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_LOW_LATENCY)},
490 {TO_NAME_INDEX(USECASE_VOICE_CALL)},
491 {TO_NAME_INDEX(USECASE_VOICE2_CALL)},
492 {TO_NAME_INDEX(USECASE_VOLTE_CALL)},
493 {TO_NAME_INDEX(USECASE_QCHAT_CALL)},
494 {TO_NAME_INDEX(USECASE_VOWLAN_CALL)},
495 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK)},
496 {TO_NAME_INDEX(USECASE_INCALL_REC_DOWNLINK)},
497 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK_AND_DOWNLINK)},
498 {TO_NAME_INDEX(USECASE_AUDIO_HFP_SCO)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700499};
500
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700501#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
502#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
Haynes Mathew George03c40102016-01-29 17:57:48 -0800503#define ULL_PLATFORM_DELAY (7*1000LL)
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700504
Eric Laurentb23d5282013-05-14 15:27:20 -0700505static pthread_once_t check_op_once_ctl = PTHREAD_ONCE_INIT;
506static bool is_tmus = false;
507
508static void check_operator()
509{
510 char value[PROPERTY_VALUE_MAX];
511 int mccmnc;
512 property_get("gsm.sim.operator.numeric",value,"0");
513 mccmnc = atoi(value);
Eric Laurent2bafff12016-03-17 12:17:23 -0700514 ALOGD("%s: tmus mccmnc %d", __func__, mccmnc);
Eric Laurentb23d5282013-05-14 15:27:20 -0700515 switch(mccmnc) {
516 /* TMUS MCC(310), MNC(490, 260, 026) */
517 case 310490:
518 case 310260:
519 case 310026:
sangwon.jeonb891db52013-09-14 17:39:15 +0900520 /* Add new TMUS MNC(800, 660, 580, 310, 270, 250, 240, 230, 220, 210, 200, 160) */
521 case 310800:
522 case 310660:
523 case 310580:
524 case 310310:
525 case 310270:
526 case 310250:
527 case 310240:
528 case 310230:
529 case 310220:
530 case 310210:
531 case 310200:
532 case 310160:
Eric Laurentb23d5282013-05-14 15:27:20 -0700533 is_tmus = true;
534 break;
535 }
536}
537
538bool is_operator_tmus()
539{
540 pthread_once(&check_op_once_ctl, check_operator);
541 return is_tmus;
542}
543
keunhui.park2f7306a2015-07-16 16:48:06 +0900544static char *get_current_operator()
545{
546 struct listnode *node;
547 struct operator_info *info_item;
548 char mccmnc[PROPERTY_VALUE_MAX];
549 char *ret = NULL;
550
551 property_get("gsm.sim.operator.numeric",mccmnc,"0");
552
553 list_for_each(node, &operator_info_list) {
554 info_item = node_to_item(node, struct operator_info, list);
555 if (strstr(info_item->mccmnc, mccmnc) != NULL) {
556 ret = info_item->name;
557 }
558 }
559
560 return ret;
561}
562
563static struct operator_specific_device *get_operator_specific_device(snd_device_t snd_device)
564{
565 struct listnode *node;
566 struct operator_specific_device *ret = NULL;
567 struct operator_specific_device *device_item;
568 char *operator_name;
569
570 operator_name = get_current_operator();
571 if (operator_name == NULL)
572 return ret;
573
574 list_for_each(node, operator_specific_device_table[snd_device]) {
575 device_item = node_to_item(node, struct operator_specific_device, list);
576 if (strcmp(operator_name, device_item->operator) == 0) {
577 ret = device_item;
578 }
579 }
580
581 return ret;
582}
583
584
585static int get_operator_specific_device_acdb_id(snd_device_t snd_device)
586{
587 struct operator_specific_device *device;
588 int ret = acdb_device_table[snd_device];
589
590 device = get_operator_specific_device(snd_device);
591 if (device != NULL)
592 ret = device->acdb_id;
593
594 return ret;
595}
596
597static const char *get_operator_specific_device_mixer_path(snd_device_t snd_device)
598{
599 struct operator_specific_device *device;
600 const char *ret = device_table[snd_device];
601
602 device = get_operator_specific_device(snd_device);
603 if (device != NULL)
604 ret = device->mixer_path;
605
606 return ret;
607}
608
vivek mehta1a9b7c02015-06-25 11:49:38 -0700609bool platform_send_gain_dep_cal(void *platform, int level)
610{
611 bool ret_val = false;
612 struct platform_data *my_data = (struct platform_data *)platform;
613 struct audio_device *adev = my_data->adev;
614 int acdb_dev_id, app_type;
615 int acdb_dev_type = MSM_SNDDEV_CAP_RX;
616 int mode = CAL_MODE_RTAC;
617 struct listnode *node;
618 struct audio_usecase *usecase;
vivek mehta1a9b7c02015-06-25 11:49:38 -0700619
620 if (my_data->acdb_send_gain_dep_cal == NULL) {
621 ALOGE("%s: dlsym error for acdb_send_gain_dep_cal", __func__);
622 return ret_val;
623 }
624
625 if (!voice_is_in_call(adev)) {
626 ALOGV("%s: Not Voice call usecase, apply new cal for level %d",
627 __func__, level);
628 app_type = DEFAULT_APP_TYPE_RX_PATH;
629
630 // find the current active sound device
631 list_for_each(node, &adev->usecase_list) {
632 usecase = node_to_item(node, struct audio_usecase, list);
633
634 if (usecase != NULL &&
635 usecase->type == PCM_PLAYBACK &&
636 (usecase->stream.out->devices == AUDIO_DEVICE_OUT_SPEAKER)) {
637
638 ALOGV("%s: out device is %d", __func__, usecase->out_snd_device);
vivek mehta4cb82982015-07-13 12:05:49 -0700639 if (audio_extn_spkr_prot_is_enabled()) {
640 acdb_dev_id = audio_extn_spkr_prot_get_acdb_id(usecase->out_snd_device);
641 } else {
642 acdb_dev_id = acdb_device_table[usecase->out_snd_device];
643 }
644
vivek mehta1a9b7c02015-06-25 11:49:38 -0700645 if (!my_data->acdb_send_gain_dep_cal(acdb_dev_id, app_type,
646 acdb_dev_type, mode, level)) {
647 // set ret_val true if at least one calibration is set successfully
648 ret_val = true;
649 } else {
650 ALOGE("%s: my_data->acdb_send_gain_dep_cal failed ", __func__);
651 }
652 } else {
653 ALOGW("%s: Usecase list is empty", __func__);
654 }
655 }
656 } else {
657 ALOGW("%s: Voice call in progress .. ignore setting new cal",
658 __func__);
659 }
660 return ret_val;
661}
662
Eric Laurentcefbbac2014-09-04 13:54:10 -0500663void platform_set_echo_reference(struct audio_device *adev, bool enable, audio_devices_t out_device)
Eric Laurentb23d5282013-05-14 15:27:20 -0700664{
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800665 struct platform_data *my_data = (struct platform_data *)adev->platform;
Eric Laurentcefbbac2014-09-04 13:54:10 -0500666 snd_device_t snd_device = SND_DEVICE_NONE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700667
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800668 if (strcmp(my_data->ec_ref_mixer_path, "")) {
669 ALOGV("%s: diabling %s", __func__, my_data->ec_ref_mixer_path);
670 audio_route_reset_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
Eric Laurentcefbbac2014-09-04 13:54:10 -0500671 }
672
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800673 if (enable) {
674 strcpy(my_data->ec_ref_mixer_path, "echo-reference");
675 if (out_device != AUDIO_DEVICE_NONE) {
676 snd_device = platform_get_output_snd_device(adev->platform, out_device);
677 platform_add_backend_name(adev->platform, my_data->ec_ref_mixer_path, snd_device);
678 }
Eric Laurentcefbbac2014-09-04 13:54:10 -0500679
Joe Onorato188b6222016-03-01 11:02:27 -0800680 ALOGV("%s: enabling %s", __func__, my_data->ec_ref_mixer_path);
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800681 audio_route_apply_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
682 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700683}
684
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700685static struct csd_data *open_csd_client(bool i2s_ext_modem)
686{
687 struct csd_data *csd = calloc(1, sizeof(struct csd_data));
688
689 csd->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
690 if (csd->csd_client == NULL) {
691 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
692 goto error;
693 } else {
694 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
695
696 csd->deinit = (deinit_t)dlsym(csd->csd_client,
697 "csd_client_deinit");
698 if (csd->deinit == NULL) {
699 ALOGE("%s: dlsym error %s for csd_client_deinit", __func__,
700 dlerror());
701 goto error;
702 }
703 csd->disable_device = (disable_device_t)dlsym(csd->csd_client,
704 "csd_client_disable_device");
705 if (csd->disable_device == NULL) {
706 ALOGE("%s: dlsym error %s for csd_client_disable_device",
707 __func__, dlerror());
708 goto error;
709 }
710 csd->enable_device_config = (enable_device_config_t)dlsym(csd->csd_client,
711 "csd_client_enable_device_config");
712 if (csd->enable_device_config == NULL) {
713 ALOGE("%s: dlsym error %s for csd_client_enable_device_config",
714 __func__, dlerror());
715 goto error;
716 }
717 csd->enable_device = (enable_device_t)dlsym(csd->csd_client,
718 "csd_client_enable_device");
719 if (csd->enable_device == NULL) {
720 ALOGE("%s: dlsym error %s for csd_client_enable_device",
721 __func__, dlerror());
722 goto error;
723 }
724 csd->start_voice = (start_voice_t)dlsym(csd->csd_client,
725 "csd_client_start_voice");
726 if (csd->start_voice == NULL) {
727 ALOGE("%s: dlsym error %s for csd_client_start_voice",
728 __func__, dlerror());
729 goto error;
730 }
731 csd->stop_voice = (stop_voice_t)dlsym(csd->csd_client,
732 "csd_client_stop_voice");
733 if (csd->stop_voice == NULL) {
734 ALOGE("%s: dlsym error %s for csd_client_stop_voice",
735 __func__, dlerror());
736 goto error;
737 }
738 csd->volume = (volume_t)dlsym(csd->csd_client,
739 "csd_client_volume");
740 if (csd->volume == NULL) {
741 ALOGE("%s: dlsym error %s for csd_client_volume",
742 __func__, dlerror());
743 goto error;
744 }
745 csd->mic_mute = (mic_mute_t)dlsym(csd->csd_client,
746 "csd_client_mic_mute");
747 if (csd->mic_mute == NULL) {
748 ALOGE("%s: dlsym error %s for csd_client_mic_mute",
749 __func__, dlerror());
750 goto error;
751 }
752 csd->slow_talk = (slow_talk_t)dlsym(csd->csd_client,
753 "csd_client_slow_talk");
754 if (csd->slow_talk == NULL) {
755 ALOGE("%s: dlsym error %s for csd_client_slow_talk",
756 __func__, dlerror());
757 goto error;
758 }
759 csd->start_playback = (start_playback_t)dlsym(csd->csd_client,
760 "csd_client_start_playback");
761 if (csd->start_playback == NULL) {
762 ALOGE("%s: dlsym error %s for csd_client_start_playback",
763 __func__, dlerror());
764 goto error;
765 }
766 csd->stop_playback = (stop_playback_t)dlsym(csd->csd_client,
767 "csd_client_stop_playback");
768 if (csd->stop_playback == NULL) {
769 ALOGE("%s: dlsym error %s for csd_client_stop_playback",
770 __func__, dlerror());
771 goto error;
772 }
773 csd->start_record = (start_record_t)dlsym(csd->csd_client,
774 "csd_client_start_record");
775 if (csd->start_record == NULL) {
776 ALOGE("%s: dlsym error %s for csd_client_start_record",
777 __func__, dlerror());
778 goto error;
779 }
780 csd->stop_record = (stop_record_t)dlsym(csd->csd_client,
781 "csd_client_stop_record");
782 if (csd->stop_record == NULL) {
783 ALOGE("%s: dlsym error %s for csd_client_stop_record",
784 __func__, dlerror());
785 goto error;
786 }
787
788 csd->get_sample_rate = (get_sample_rate_t)dlsym(csd->csd_client,
789 "csd_client_get_sample_rate");
790 if (csd->get_sample_rate == NULL) {
791 ALOGE("%s: dlsym error %s for csd_client_get_sample_rate",
792 __func__, dlerror());
793
794 goto error;
795 }
796
797 csd->init = (init_t)dlsym(csd->csd_client, "csd_client_init");
798
799 if (csd->init == NULL) {
800 ALOGE("%s: dlsym error %s for csd_client_init",
801 __func__, dlerror());
802 goto error;
803 } else {
804 csd->init(i2s_ext_modem);
805 }
806 }
807 return csd;
808
809error:
810 free(csd);
811 csd = NULL;
812 return csd;
813}
814
815void close_csd_client(struct csd_data *csd)
816{
817 if (csd != NULL) {
818 csd->deinit();
819 dlclose(csd->csd_client);
820 free(csd);
821 csd = NULL;
822 }
823}
824
825static void platform_csd_init(struct platform_data *my_data)
826{
827#ifdef PLATFORM_MSM8084
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700828 int32_t modems, (*count_modems)(void);
829 const char *name = "libdetectmodem.so";
830 const char *func = "count_modems";
831 const char *error;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700832
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700833 my_data->csd = NULL;
834
835 void *lib = dlopen(name, RTLD_NOW);
836 error = dlerror();
837 if (!lib) {
838 ALOGE("%s: could not find %s: %s", __func__, name, error);
839 return;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700840 }
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700841
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700842 count_modems = NULL;
843 *(void **)(&count_modems) = dlsym(lib, func);
844 error = dlerror();
845 if (!count_modems) {
846 ALOGE("%s: could not find symbol %s in %s: %s",
847 __func__, func, name, error);
848 goto done;
849 }
850
851 modems = count_modems();
852 if (modems < 0) {
853 ALOGE("%s: count_modems failed\n", __func__);
854 goto done;
855 }
856
Eric Laurent2bafff12016-03-17 12:17:23 -0700857 ALOGD("%s: num_modems %d\n", __func__, modems);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700858 if (modems > 0)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700859 my_data->csd = open_csd_client(false /*is_i2s_ext_modem*/);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700860
861done:
862 dlclose(lib);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700863#else
864 my_data->csd = NULL;
865#endif
866}
867
Eric Laurentc6333382015-09-14 12:43:44 -0700868static void set_platform_defaults(struct platform_data * my_data)
Haynes Mathew George98c95622014-06-20 19:14:25 -0700869{
870 int32_t dev;
871 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700872 backend_tag_table[dev] = NULL;
873 hw_interface_table[dev] = NULL;
keunhui.park2f7306a2015-07-16 16:48:06 +0900874 operator_specific_device_table[dev] = NULL;
Haynes Mathew George98c95622014-06-20 19:14:25 -0700875 }
876
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700877 // To overwrite these go to the audio_platform_info.xml file.
878 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("bt-sco");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700879 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("bt-sco");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700880 backend_tag_table[SND_DEVICE_OUT_BT_SCO] = strdup("bt-sco");
881 backend_tag_table[SND_DEVICE_OUT_HDMI] = strdup("hdmi");
882 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("speaker-and-hdmi");
883 backend_tag_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("bt-sco-wb");
884 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("bt-sco-wb");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700885 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("bt-sco-wb");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700886 backend_tag_table[SND_DEVICE_OUT_VOICE_TX] = strdup("afe-proxy");
887 backend_tag_table[SND_DEVICE_IN_VOICE_RX] = strdup("afe-proxy");
Haynes Mathew George98c95622014-06-20 19:14:25 -0700888
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700889 hw_interface_table[SND_DEVICE_OUT_HANDSET] = strdup("SLIMBUS_0_RX");
890 hw_interface_table[SND_DEVICE_OUT_SPEAKER] = strdup("SLIMBUS_0_RX");
891 hw_interface_table[SND_DEVICE_OUT_SPEAKER_REVERSE] = strdup("SLIMBUS_0_RX");
892 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE] = strdup("SLIMBUS_0_RX");
893 hw_interface_table[SND_DEVICE_OUT_HEADPHONES] = strdup("SLIMBUS_0_RX");
894 hw_interface_table[SND_DEVICE_OUT_LINE] = strdup("SLIMBUS_0_RX");
895 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700896 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700897 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700898 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700899 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET] = strdup("SLIMBUS_0_RX");
900 hw_interface_table[SND_DEVICE_OUT_VOICE_HAC_HANDSET] = strdup("SLIMBUS_0_RX");
901 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER] = strdup("SLIMBUS_0_RX");
902 hw_interface_table[SND_DEVICE_OUT_VOICE_HEADPHONES] = strdup("SLIMBUS_0_RX");
903 hw_interface_table[SND_DEVICE_OUT_VOICE_LINE] = strdup("SLIMBUS_0_RX");
904 hw_interface_table[SND_DEVICE_OUT_HDMI] = strdup("HDMI_RX");
905 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("SLIMBUS_0_RX-and-HDMI_RX");
906 hw_interface_table[SND_DEVICE_OUT_BT_SCO] = strdup("SEC_AUX_PCM_RX");
907 hw_interface_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("SEC_AUX_PCM_RX");
908 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = strdup("SLIMBUS_0_RX");
909 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = strdup("SLIMBUS_0_RX");
910 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = strdup("SLIMBUS_0_RX");
911 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = strdup("SLIMBUS_0_RX");
912 hw_interface_table[SND_DEVICE_OUT_VOICE_TX] = strdup("AFE_PCM_RX");
913 hw_interface_table[SND_DEVICE_OUT_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
914 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
Eric Laurentc6333382015-09-14 12:43:44 -0700915
916 my_data->max_mic_count = PLATFORM_DEFAULT_MIC_COUNT;
Haynes Mathew George98c95622014-06-20 19:14:25 -0700917}
918
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +0900919void get_cvd_version(char *cvd_version, struct audio_device *adev)
920{
921 struct mixer_ctl *ctl;
922 int count;
923 int ret = 0;
924
925 ctl = mixer_get_ctl_by_name(adev->mixer, CVD_VERSION_MIXER_CTL);
926 if (!ctl) {
927 ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__, CVD_VERSION_MIXER_CTL);
928 goto done;
929 }
930 mixer_ctl_update(ctl);
931
932 count = mixer_ctl_get_num_values(ctl);
933 if (count > MAX_CVD_VERSION_STRING_SIZE)
934 count = MAX_CVD_VERSION_STRING_SIZE - 1;
935
936 ret = mixer_ctl_get_array(ctl, cvd_version, count);
937 if (ret != 0) {
938 ALOGE("%s: ERROR! mixer_ctl_get_array() failed to get CVD Version", __func__);
939 goto done;
940 }
941
942done:
943 return;
944}
945
Eric Laurentb23d5282013-05-14 15:27:20 -0700946void *platform_init(struct audio_device *adev)
947{
948 char value[PROPERTY_VALUE_MAX];
vivek mehta60ea4152016-02-18 17:10:26 -0800949 struct platform_data *my_data = NULL;
950 int retry_num = 0, snd_card_num = 0, key = 0, ret = 0;
951 bool dual_mic_config = false, use_default_mixer_path = true;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700952 const char *snd_card_name;
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +0900953 char *cvd_version = NULL;
vivek mehta60ea4152016-02-18 17:10:26 -0800954 char *snd_internal_name = NULL;
955 char *tmp = NULL;
956 char mixer_xml_file[MIXER_PATH_MAX_LENGTH]= {0};
vivek mehtade4849c2016-03-03 17:23:38 -0800957 char platform_info_file[MIXER_PATH_MAX_LENGTH]= {0};
958 struct snd_card_split *snd_split_handle = NULL;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700959 my_data = calloc(1, sizeof(struct platform_data));
960
961 my_data->adev = adev;
962
keunhui.park2f7306a2015-07-16 16:48:06 +0900963 list_init(&operator_info_list);
964
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700965 set_platform_defaults(my_data);
966
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700967 while (snd_card_num < MAX_SND_CARD) {
968 adev->mixer = mixer_open(snd_card_num);
sangwoo1b9f4b32013-06-21 18:22:55 -0700969
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700970 while (!adev->mixer && retry_num < RETRY_NUMBER) {
971 usleep(RETRY_US);
972 adev->mixer = mixer_open(snd_card_num);
973 retry_num++;
974 }
975
976 if (!adev->mixer) {
977 ALOGE("%s: Unable to open the mixer card: %d", __func__,
978 snd_card_num);
979 retry_num = 0;
980 snd_card_num++;
981 continue;
982 }
983
984 snd_card_name = mixer_get_name(adev->mixer);
vivek mehtade4849c2016-03-03 17:23:38 -0800985 my_data->hw_info = hw_info_init(snd_card_name);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700986
vivek mehtade4849c2016-03-03 17:23:38 -0800987 audio_extn_set_snd_card_split(snd_card_name);
988 snd_split_handle = audio_extn_get_snd_card_split();
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700989
vivek mehtade4849c2016-03-03 17:23:38 -0800990 /* Get the codec internal name from the sound card and/or form factor
991 * name and form the mixer paths and platfor info file name dynamically.
992 * This is generic way of picking any codec and forma factor name based
993 * mixer and platform info files in future with no code change.
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700994
vivek mehtade4849c2016-03-03 17:23:38 -0800995 * current code extends and looks for any of the exteneded mixer path and
996 * platform info file present based on codec and form factor.
vivek mehta60ea4152016-02-18 17:10:26 -0800997
vivek mehtade4849c2016-03-03 17:23:38 -0800998 * order of picking appropriate file is
999 * <i> mixer_paths_<codec_name>_<form_factor>.xml, if file not present
1000 * <ii> mixer_paths_<codec_name>.xml, if file not present
1001 * <iii> mixer_paths.xml
1002
1003 * same order is followed for audio_platform_info.xml as well
1004 */
1005
1006 // need to carryforward old file name
1007 if (!strncmp(snd_card_name, TOMTOM_8226_SND_CARD_NAME,
Eric Laurentf9583c32016-03-28 13:50:50 -07001008 min(strlen(TOMTOM_8226_SND_CARD_NAME), strlen(snd_card_name)))) {
vivek mehtade4849c2016-03-03 17:23:38 -08001009 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
vivek mehta60ea4152016-02-18 17:10:26 -08001010 MIXER_XML_BASE_STRING, TOMTOM_MIXER_FILE_SUFFIX );
vivek mehtade4849c2016-03-03 17:23:38 -08001011 } else {
Ed Tamb0b0d572016-03-21 10:45:37 -07001012
vivek mehtade4849c2016-03-03 17:23:38 -08001013 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s_%s.xml",
1014 MIXER_XML_BASE_STRING, snd_split_handle->snd_card,
1015 snd_split_handle->form_factor);
1016
1017 if (F_OK != access(mixer_xml_file, 0)) {
1018 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1019 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1020 MIXER_XML_BASE_STRING, snd_split_handle->snd_card);
1021
1022 if (F_OK != access(mixer_xml_file, 0)) {
1023 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1024 strlcpy(mixer_xml_file, MIXER_XML_DEFAULT_PATH, MIXER_PATH_MAX_LENGTH);
1025 }
1026 }
1027
1028 snprintf(platform_info_file, sizeof(platform_info_file), "%s_%s_%s.xml",
1029 PLATFORM_INFO_XML_BASE_STRING, snd_split_handle->snd_card,
1030 snd_split_handle->form_factor);
1031
1032 if (F_OK != access(platform_info_file, 0)) {
1033 memset(platform_info_file, 0, sizeof(platform_info_file));
1034 snprintf(platform_info_file, sizeof(platform_info_file), "%s_%s.xml",
1035 PLATFORM_INFO_XML_BASE_STRING, snd_split_handle->snd_card);
1036
1037 if (F_OK != access(platform_info_file, 0)) {
1038 memset(platform_info_file, 0, sizeof(platform_info_file));
1039 strlcpy(platform_info_file, PLATFORM_INFO_XML_PATH, MIXER_PATH_MAX_LENGTH);
vivek mehta60ea4152016-02-18 17:10:26 -08001040 }
1041 }
Uday Kishore Pasupuleti11dd2232015-06-24 14:18:01 -07001042 }
1043
vivek mehtade4849c2016-03-03 17:23:38 -08001044 /* Initialize platform specific ids and/or backends*/
1045 platform_info_init(platform_info_file, my_data);
1046
1047 /* validate the sound card name
1048 * my_data->snd_card_name can contain
1049 * <a> complete sound card name, i.e. <device>-<codec>-<form_factor>-snd-card
1050 * example: msm8994-tomtom-mtp-snd-card
1051 * <b> or sub string of the card name, i.e. <device>-<codec>
1052 * example: msm8994-tomtom
Eric Laurentf9583c32016-03-28 13:50:50 -07001053 * snd_card_name is truncated to 32 charaters as per mixer_get_name() implementation
1054 * so use min of my_data->snd_card_name and snd_card_name length for comparison
vivek mehtade4849c2016-03-03 17:23:38 -08001055 */
1056
1057 if (my_data->snd_card_name != NULL &&
Eric Laurentf9583c32016-03-28 13:50:50 -07001058 strncmp(snd_card_name, my_data->snd_card_name,
1059 min(strlen(snd_card_name), strlen(my_data->snd_card_name))) != 0) {
vivek mehtade4849c2016-03-03 17:23:38 -08001060 ALOGI("%s: found valid sound card %s, but not primary sound card %s",
1061 __func__, snd_card_name, my_data->snd_card_name);
1062 retry_num = 0;
1063 snd_card_num++;
1064 hw_info_deinit(my_data->hw_info);
1065 my_data->hw_info = NULL;
1066 continue;
Ed Tam70b5c142016-03-21 19:14:29 -07001067 }
vivek mehtade4849c2016-03-03 17:23:38 -08001068 ALOGI("%s: found sound card %s, primary sound card expeted is %s",
1069 __func__, snd_card_name, my_data->snd_card_name);
vivek mehta60ea4152016-02-18 17:10:26 -08001070
1071 ALOGD("%s: Loading mixer file: %s", __func__, mixer_xml_file);
1072 adev->audio_route = audio_route_init(snd_card_num, mixer_xml_file);
1073
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001074 if (!adev->audio_route) {
1075 ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001076 goto init_failed;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001077 }
1078 adev->snd_card = snd_card_num;
Eric Laurent2bafff12016-03-17 12:17:23 -07001079 ALOGD("%s: Opened sound card:%d", __func__, snd_card_num);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001080 break;
sangwoo1b9f4b32013-06-21 18:22:55 -07001081 }
1082
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001083 if (snd_card_num >= MAX_SND_CARD) {
1084 ALOGE("%s: Unable to find correct sound card, aborting.", __func__);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001085 goto init_failed;
sangwoo1b9f4b32013-06-21 18:22:55 -07001086 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001087
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09001088 //set max volume step for voice call
1089 property_get("ro.config.vc_call_vol_steps", value, TOSTRING(MAX_VOL_INDEX));
1090 my_data->max_vol_index = atoi(value);
1091
vivek mehta65ad12d2015-08-13 18:32:48 -07001092 property_get("persist.audio.dualmic.config",value,"");
1093 if (!strcmp("endfire", value)) {
1094 dual_mic_config = true;
1095 }
1096
Prashant Malanic92c5962015-08-11 15:10:18 -07001097 my_data->source_mic_type = SOURCE_DUAL_MIC;
1098
Eric Laurentb23d5282013-05-14 15:27:20 -07001099 my_data->fluence_in_spkr_mode = false;
1100 my_data->fluence_in_voice_call = false;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001101 my_data->fluence_in_voice_comm = false;
Eric Laurentb23d5282013-05-14 15:27:20 -07001102 my_data->fluence_in_voice_rec = false;
1103
vivek mehta65ad12d2015-08-13 18:32:48 -07001104 property_get("ro.qc.sdk.audio.fluencetype", value, "none");
Prashant Malanic92c5962015-08-11 15:10:18 -07001105 if (!strcmp("fluencepro", value)) {
1106 my_data->fluence_type = FLUENCE_PRO_ENABLE;
vivek mehta65ad12d2015-08-13 18:32:48 -07001107 } else if (!strcmp("fluence", value) || (dual_mic_config)) {
Prashant Malanic92c5962015-08-11 15:10:18 -07001108 my_data->fluence_type = FLUENCE_ENABLE;
1109 } else if (!strcmp("none", value)) {
1110 my_data->fluence_type = FLUENCE_DISABLE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001111 }
1112
Prashant Malanic92c5962015-08-11 15:10:18 -07001113 if (my_data->fluence_type != FLUENCE_DISABLE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001114 property_get("persist.audio.fluence.voicecall",value,"");
1115 if (!strcmp("true", value)) {
1116 my_data->fluence_in_voice_call = true;
1117 }
1118
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001119 property_get("persist.audio.fluence.voicecomm",value,"");
1120 if (!strcmp("true", value)) {
1121 my_data->fluence_in_voice_comm = true;
1122 }
1123
Eric Laurentb23d5282013-05-14 15:27:20 -07001124 property_get("persist.audio.fluence.voicerec",value,"");
1125 if (!strcmp("true", value)) {
1126 my_data->fluence_in_voice_rec = true;
1127 }
1128
1129 property_get("persist.audio.fluence.speaker",value,"");
1130 if (!strcmp("true", value)) {
1131 my_data->fluence_in_spkr_mode = true;
1132 }
1133 }
1134
Prashant Malanic92c5962015-08-11 15:10:18 -07001135 // support max to mono, example if max count is 3, usecase supports Three, dual and mono mic
1136 switch (my_data->max_mic_count) {
1137 case 4:
1138 my_data->source_mic_type |= SOURCE_QUAD_MIC;
1139 case 3:
1140 my_data->source_mic_type |= SOURCE_THREE_MIC;
1141 case 2:
1142 my_data->source_mic_type |= SOURCE_DUAL_MIC;
1143 case 1:
1144 my_data->source_mic_type |= SOURCE_MONO_MIC;
1145 break;
1146 default:
1147 ALOGE("%s: max_mic_count (%d), is not supported, setting to default",
1148 __func__, my_data->max_mic_count);
1149 my_data->source_mic_type = SOURCE_MONO_MIC|SOURCE_DUAL_MIC;
1150 break;
1151 }
1152
1153 ALOGV("%s: Fluence_Type(%d) max_mic_count(%d) mic_type(0x%x) fluence_in_voice_call(%d)"
1154 " fluence_in_voice_comm(%d) fluence_in_voice_rec(%d) fluence_in_spkr_mode(%d) ",
1155 __func__, my_data->fluence_type, my_data->max_mic_count, my_data->source_mic_type,
1156 my_data->fluence_in_voice_call, my_data->fluence_in_voice_comm,
1157 my_data->fluence_in_voice_rec, my_data->fluence_in_spkr_mode);
1158
Eric Laurentb23d5282013-05-14 15:27:20 -07001159 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
1160 if (my_data->acdb_handle == NULL) {
1161 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
1162 } else {
1163 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
1164 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
1165 "acdb_loader_deallocate_ACDB");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001166 if (!my_data->acdb_deallocate)
1167 ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s",
1168 __func__, LIB_ACDB_LOADER);
1169
Eric Laurentb23d5282013-05-14 15:27:20 -07001170 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
1171 "acdb_loader_send_audio_cal");
1172 if (!my_data->acdb_send_audio_cal)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001173 ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s",
Eric Laurentb23d5282013-05-14 15:27:20 -07001174 __func__, LIB_ACDB_LOADER);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001175
Eric Laurentb23d5282013-05-14 15:27:20 -07001176 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
1177 "acdb_loader_send_voice_cal");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001178 if (!my_data->acdb_send_voice_cal)
1179 ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s",
1180 __func__, LIB_ACDB_LOADER);
1181
1182 my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle,
1183 "acdb_loader_reload_vocvoltable");
1184 if (!my_data->acdb_reload_vocvoltable)
1185 ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s",
1186 __func__, LIB_ACDB_LOADER);
vivek mehta1a9b7c02015-06-25 11:49:38 -07001187
1188 my_data->acdb_send_gain_dep_cal = (acdb_send_gain_dep_cal_t)dlsym(my_data->acdb_handle,
1189 "acdb_loader_send_gain_dep_cal");
1190 if (!my_data->acdb_send_gain_dep_cal)
1191 ALOGV("%s: Could not find the symbol acdb_loader_send_gain_dep_cal from %s",
1192 __func__, LIB_ACDB_LOADER);
1193
vivek mehtac698f132016-02-25 18:50:35 -08001194#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996)
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001195 acdb_init_v2_cvd_t acdb_init;
1196 acdb_init = (acdb_init_v2_cvd_t)dlsym(my_data->acdb_handle,
1197 "acdb_loader_init_v2");
1198 if (acdb_init == NULL) {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001199 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__, dlerror());
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001200 goto acdb_init_fail;
1201 }
1202
1203 cvd_version = calloc(1, MAX_CVD_VERSION_STRING_SIZE);
1204 get_cvd_version(cvd_version, adev);
1205 if (!cvd_version)
1206 ALOGE("failed to allocate cvd_version");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001207 else
vivek mehtac698f132016-02-25 18:50:35 -08001208 acdb_init((char *)snd_card_name, cvd_version, 0);
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001209 free(cvd_version);
1210#elif defined (PLATFORM_MSM8084)
1211 acdb_init_v2_t acdb_init;
1212 acdb_init = (acdb_init_v2_t)dlsym(my_data->acdb_handle,
1213 "acdb_loader_init_v2");
1214 if (acdb_init == NULL) {
1215 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__, dlerror());
1216 goto acdb_init_fail;
1217 }
1218 acdb_init((char *)snd_card_name);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001219#else
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001220 acdb_init_t acdb_init;
1221 acdb_init = (acdb_init_t)dlsym(my_data->acdb_handle,
Eric Laurentb23d5282013-05-14 15:27:20 -07001222 "acdb_loader_init_ACDB");
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001223 if (acdb_init == NULL)
Eric Laurentb23d5282013-05-14 15:27:20 -07001224 ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__, dlerror());
1225 else
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001226 acdb_init();
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001227#endif
Eric Laurentb23d5282013-05-14 15:27:20 -07001228 }
1229
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001230acdb_init_fail:
1231
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001232 audio_extn_spkr_prot_init(adev);
Haynes Mathew George98c95622014-06-20 19:14:25 -07001233
Ravi Kumar Alamanda76315572015-04-23 13:13:56 -07001234 audio_extn_hwdep_cal_send(adev->snd_card, my_data->acdb_handle);
1235
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001236 /* load csd client */
1237 platform_csd_init(my_data);
1238
Eric Laurentb23d5282013-05-14 15:27:20 -07001239 return my_data;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001240
1241init_failed:
1242 if (my_data)
1243 free(my_data);
1244 return NULL;
Eric Laurentb23d5282013-05-14 15:27:20 -07001245}
1246
1247void platform_deinit(void *platform)
1248{
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001249 int32_t dev;
keunhui.park2f7306a2015-07-16 16:48:06 +09001250 struct operator_info *info_item;
1251 struct operator_specific_device *device_item;
1252 struct listnode *node;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001253
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001254 struct platform_data *my_data = (struct platform_data *)platform;
1255 close_csd_client(my_data->csd);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001256
vivek mehtade4849c2016-03-03 17:23:38 -08001257 hw_info_deinit(my_data->hw_info);
1258
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001259 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1260 if (backend_tag_table[dev])
1261 free(backend_tag_table[dev]);
1262 if (hw_interface_table[dev])
1263 free(hw_interface_table[dev]);
keunhui.park2f7306a2015-07-16 16:48:06 +09001264 if (operator_specific_device_table[dev]) {
1265 while (!list_empty(operator_specific_device_table[dev])) {
1266 node = list_head(operator_specific_device_table[dev]);
1267 list_remove(node);
1268 device_item = node_to_item(node, struct operator_specific_device, list);
1269 free(device_item->operator);
1270 free(device_item->mixer_path);
1271 free(device_item);
1272 }
1273 free(operator_specific_device_table[dev]);
1274 }
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001275 }
1276
1277 if (my_data->snd_card_name)
1278 free(my_data->snd_card_name);
1279
keunhui.park2f7306a2015-07-16 16:48:06 +09001280 while (!list_empty(&operator_info_list)) {
1281 node = list_head(&operator_info_list);
1282 list_remove(node);
1283 info_item = node_to_item(node, struct operator_info, list);
1284 free(info_item->name);
1285 free(info_item->mccmnc);
1286 free(info_item);
1287 }
1288
Eric Laurentb23d5282013-05-14 15:27:20 -07001289 free(platform);
1290}
1291
1292const char *platform_get_snd_device_name(snd_device_t snd_device)
1293{
keunhui.park2f7306a2015-07-16 16:48:06 +09001294 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1295 if (operator_specific_device_table[snd_device] != NULL) {
1296 return get_operator_specific_device_mixer_path(snd_device);
1297 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001298 return device_table[snd_device];
keunhui.park2f7306a2015-07-16 16:48:06 +09001299 } else
Ravi Kumar Alamanda64026462014-09-15 00:08:58 -07001300 return "none";
Eric Laurentb23d5282013-05-14 15:27:20 -07001301}
1302
vivek mehtade4849c2016-03-03 17:23:38 -08001303int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
1304 char *device_name)
1305{
1306 struct platform_data *my_data = (struct platform_data *)platform;
1307
1308 if (platform == NULL || device_name == NULL) {
1309 ALOGW("%s: something wrong, use legacy get_snd_device name", __func__);
1310 device_name = platform_get_snd_device_name(snd_device);
1311 } else if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1312 if (operator_specific_device_table[snd_device] != NULL) {
1313 strlcpy(device_name, get_operator_specific_device_mixer_path(snd_device),
1314 DEVICE_NAME_MAX_SIZE);
1315 } else {
1316 strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE);
1317 }
1318 hw_info_append_hw_type(my_data->hw_info, snd_device, device_name);
1319 } else {
1320 strlcpy(device_name, "none", DEVICE_NAME_MAX_SIZE);
1321 }
1322
1323 return 0;
1324}
1325
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001326void platform_add_backend_name(void *platform, char *mixer_path,
1327 snd_device_t snd_device)
Eric Laurentb23d5282013-05-14 15:27:20 -07001328{
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001329 struct platform_data *my_data = (struct platform_data *)platform;
1330
Haynes Mathew George98c95622014-06-20 19:14:25 -07001331 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1332 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1333 return;
Ravi Kumar Alamanda1de6e5a2014-06-19 21:55:39 -05001334 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001335
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001336 const char * suffix = backend_tag_table[snd_device];
Haynes Mathew George98c95622014-06-20 19:14:25 -07001337
1338 if (suffix != NULL) {
1339 strcat(mixer_path, " ");
1340 strcat(mixer_path, suffix);
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001341 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001342}
1343
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001344bool platform_check_backends_match(snd_device_t snd_device1, snd_device_t snd_device2)
1345{
1346 bool result = true;
1347
1348 ALOGV("%s: snd_device1 = %s, snd_device2 = %s", __func__,
1349 platform_get_snd_device_name(snd_device1),
1350 platform_get_snd_device_name(snd_device2));
1351
1352 if ((snd_device1 < SND_DEVICE_MIN) || (snd_device1 >= SND_DEVICE_MAX)) {
1353 ALOGE("%s: Invalid snd_device = %s", __func__,
1354 platform_get_snd_device_name(snd_device1));
1355 return false;
1356 }
1357 if ((snd_device2 < SND_DEVICE_MIN) || (snd_device2 >= SND_DEVICE_MAX)) {
1358 ALOGE("%s: Invalid snd_device = %s", __func__,
1359 platform_get_snd_device_name(snd_device2));
1360 return false;
1361 }
1362 const char * be_itf1 = hw_interface_table[snd_device1];
1363 const char * be_itf2 = hw_interface_table[snd_device2];
1364
1365 if (NULL != be_itf1 && NULL != be_itf2) {
Eric Laurente63e61d2015-09-10 12:19:33 -07001366 if ((NULL == strstr(be_itf2, be_itf1)) && (NULL == strstr(be_itf1, be_itf2)))
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001367 result = false;
1368 }
1369
1370 ALOGV("%s: be_itf1 = %s, be_itf2 = %s, match %d", __func__, be_itf1, be_itf2, result);
1371 return result;
1372}
1373
Eric Laurentb23d5282013-05-14 15:27:20 -07001374int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
1375{
1376 int device_id;
1377 if (device_type == PCM_PLAYBACK)
1378 device_id = pcm_device_table[usecase][0];
1379 else
1380 device_id = pcm_device_table[usecase][1];
1381 return device_id;
1382}
1383
Haynes Mathew George98c95622014-06-20 19:14:25 -07001384static int find_index(const struct name_to_index * table, int32_t len,
1385 const char * name)
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001386{
1387 int ret = 0;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001388 int32_t i;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001389
Haynes Mathew George98c95622014-06-20 19:14:25 -07001390 if (table == NULL) {
1391 ALOGE("%s: table is NULL", __func__);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001392 ret = -ENODEV;
1393 goto done;
1394 }
1395
Haynes Mathew George98c95622014-06-20 19:14:25 -07001396 if (name == NULL) {
1397 ALOGE("null key");
1398 ret = -ENODEV;
1399 goto done;
1400 }
1401
1402 for (i=0; i < len; i++) {
1403 if (!strcmp(table[i].name, name)) {
1404 ret = table[i].index;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001405 goto done;
1406 }
1407 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001408 ALOGE("%s: Could not find index for name = %s",
1409 __func__, name);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001410 ret = -ENODEV;
1411done:
1412 return ret;
1413}
1414
Haynes Mathew George98c95622014-06-20 19:14:25 -07001415int platform_get_snd_device_index(char *device_name)
1416{
1417 return find_index(snd_device_name_index, SND_DEVICE_MAX, device_name);
1418}
1419
1420int platform_get_usecase_index(const char *usecase_name)
1421{
1422 return find_index(usecase_name_index, AUDIO_USECASE_MAX, usecase_name);
1423}
1424
keunhui.park2f7306a2015-07-16 16:48:06 +09001425void platform_add_operator_specific_device(snd_device_t snd_device,
1426 const char *operator,
1427 const char *mixer_path,
1428 unsigned int acdb_id)
1429{
1430 struct operator_specific_device *device;
1431
1432 if (operator_specific_device_table[snd_device] == NULL) {
1433 operator_specific_device_table[snd_device] =
1434 (struct listnode *)calloc(1, sizeof(struct listnode));
1435 list_init(operator_specific_device_table[snd_device]);
1436 }
1437
1438 device = (struct operator_specific_device *)calloc(1, sizeof(struct operator_specific_device));
1439
1440 device->operator = strdup(operator);
1441 device->mixer_path = strdup(mixer_path);
1442 device->acdb_id = acdb_id;
1443
1444 list_add_tail(operator_specific_device_table[snd_device], &device->list);
1445
Eric Laurent2bafff12016-03-17 12:17:23 -07001446 ALOGD("%s: device[%s] -> operator[%s] mixer_path[%s] acdb_id[%d]", __func__,
keunhui.park2f7306a2015-07-16 16:48:06 +09001447 platform_get_snd_device_name(snd_device), operator, mixer_path, acdb_id);
1448
1449}
1450
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001451int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
1452{
1453 int ret = 0;
1454
1455 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1456 ALOGE("%s: Invalid snd_device = %d",
1457 __func__, snd_device);
1458 ret = -EINVAL;
1459 goto done;
1460 }
1461
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001462 ALOGV("%s: acdb_device_table[%s]: old = %d new = %d", __func__,
1463 platform_get_snd_device_name(snd_device), acdb_device_table[snd_device], acdb_id);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001464 acdb_device_table[snd_device] = acdb_id;
1465done:
1466 return ret;
1467}
1468
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001469int platform_get_snd_device_acdb_id(snd_device_t snd_device)
1470{
1471 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1472 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1473 return -EINVAL;
1474 }
keunhui.park2f7306a2015-07-16 16:48:06 +09001475
1476 if (operator_specific_device_table[snd_device] != NULL)
1477 return get_operator_specific_device_acdb_id(snd_device);
1478 else
1479 return acdb_device_table[snd_device];
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001480}
1481
Eric Laurentb23d5282013-05-14 15:27:20 -07001482int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
1483{
1484 struct platform_data *my_data = (struct platform_data *)platform;
1485 int acdb_dev_id, acdb_dev_type;
1486
Ravi Kumar Alamandaadf0f3b2015-06-04 02:34:02 -07001487 acdb_dev_id = acdb_device_table[audio_extn_get_spkr_prot_snd_device(snd_device)];
Eric Laurentb23d5282013-05-14 15:27:20 -07001488 if (acdb_dev_id < 0) {
1489 ALOGE("%s: Could not find acdb id for device(%d)",
1490 __func__, snd_device);
1491 return -EINVAL;
1492 }
1493 if (my_data->acdb_send_audio_cal) {
Joe Onorato188b6222016-03-01 11:02:27 -08001494 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Eric Laurentb23d5282013-05-14 15:27:20 -07001495 __func__, snd_device, acdb_dev_id);
1496 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
1497 snd_device < SND_DEVICE_OUT_END)
1498 acdb_dev_type = ACDB_DEV_TYPE_OUT;
1499 else
1500 acdb_dev_type = ACDB_DEV_TYPE_IN;
1501 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
1502 }
1503 return 0;
1504}
1505
1506int platform_switch_voice_call_device_pre(void *platform)
1507{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001508 struct platform_data *my_data = (struct platform_data *)platform;
1509 int ret = 0;
1510
1511 if (my_data->csd != NULL &&
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001512 voice_is_in_call(my_data->adev)) {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001513 /* This must be called before disabling mixer controls on APQ side */
1514 ret = my_data->csd->disable_device();
1515 if (ret < 0) {
1516 ALOGE("%s: csd_client_disable_device, failed, error %d",
1517 __func__, ret);
1518 }
1519 }
1520 return ret;
1521}
1522
1523int platform_switch_voice_call_enable_device_config(void *platform,
1524 snd_device_t out_snd_device,
1525 snd_device_t in_snd_device)
1526{
1527 struct platform_data *my_data = (struct platform_data *)platform;
1528 int acdb_rx_id, acdb_tx_id;
1529 int ret = 0;
1530
1531 if (my_data->csd == NULL)
1532 return ret;
1533
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001534 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1535 audio_extn_spkr_prot_is_enabled())
keunhui.park2f7306a2015-07-16 16:48:06 +09001536 acdb_rx_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_SPEAKER_PROTECTED);
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001537 else
keunhui.park2f7306a2015-07-16 16:48:06 +09001538 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001539
keunhui.park2f7306a2015-07-16 16:48:06 +09001540 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001541
1542 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
1543 ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
1544 if (ret < 0) {
1545 ALOGE("%s: csd_enable_device_config, failed, error %d",
1546 __func__, ret);
1547 }
1548 } else {
1549 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1550 acdb_rx_id, acdb_tx_id);
1551 }
1552
1553 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001554}
1555
1556int platform_switch_voice_call_device_post(void *platform,
1557 snd_device_t out_snd_device,
1558 snd_device_t in_snd_device)
1559{
1560 struct platform_data *my_data = (struct platform_data *)platform;
1561 int acdb_rx_id, acdb_tx_id;
1562
1563 if (my_data->acdb_send_voice_cal == NULL) {
1564 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
1565 } else {
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001566 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1567 audio_extn_spkr_prot_is_enabled())
1568 out_snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED;
1569
keunhui.park2f7306a2015-07-16 16:48:06 +09001570 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
1571 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07001572
1573 if (acdb_rx_id > 0 && acdb_tx_id > 0)
1574 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
1575 else
1576 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1577 acdb_rx_id, acdb_tx_id);
1578 }
1579
1580 return 0;
1581}
1582
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001583int platform_switch_voice_call_usecase_route_post(void *platform,
1584 snd_device_t out_snd_device,
1585 snd_device_t in_snd_device)
1586{
1587 struct platform_data *my_data = (struct platform_data *)platform;
1588 int acdb_rx_id, acdb_tx_id;
1589 int ret = 0;
1590
1591 if (my_data->csd == NULL)
1592 return ret;
1593
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001594 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1595 audio_extn_spkr_prot_is_enabled())
keunhui.park2f7306a2015-07-16 16:48:06 +09001596 acdb_rx_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED);
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001597 else
keunhui.park2f7306a2015-07-16 16:48:06 +09001598 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001599
keunhui.park2f7306a2015-07-16 16:48:06 +09001600 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001601
1602 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
1603 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
1604 my_data->adev->acdb_settings);
1605 if (ret < 0) {
1606 ALOGE("%s: csd_enable_device, failed, error %d", __func__, ret);
1607 }
1608 } else {
1609 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1610 acdb_rx_id, acdb_tx_id);
1611 }
1612
1613 return ret;
1614}
1615
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001616int platform_start_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07001617{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001618 struct platform_data *my_data = (struct platform_data *)platform;
1619 int ret = 0;
1620
1621 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001622 ret = my_data->csd->start_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001623 if (ret < 0) {
1624 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
1625 }
1626 }
1627 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001628}
1629
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001630int platform_stop_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07001631{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001632 struct platform_data *my_data = (struct platform_data *)platform;
1633 int ret = 0;
1634
1635 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001636 ret = my_data->csd->stop_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001637 if (ret < 0) {
1638 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
1639 }
1640 }
1641 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001642}
1643
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001644int platform_get_sample_rate(void *platform, uint32_t *rate)
1645{
1646 struct platform_data *my_data = (struct platform_data *)platform;
1647 int ret = 0;
1648
1649 if (my_data->csd != NULL) {
1650 ret = my_data->csd->get_sample_rate(rate);
1651 if (ret < 0) {
1652 ALOGE("%s: csd_get_sample_rate error %d\n", __func__, ret);
1653 }
1654 }
1655 return ret;
1656}
1657
vivek mehtab6506412015-08-07 16:55:17 -07001658void platform_set_speaker_gain_in_combo(struct audio_device *adev,
1659 snd_device_t snd_device,
1660 bool enable)
1661{
1662 const char* name;
1663 switch (snd_device) {
1664 case SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES:
1665 if (enable)
1666 name = "spkr-gain-in-headphone-combo";
1667 else
1668 name = "speaker-gain-default";
1669 break;
1670 case SND_DEVICE_OUT_SPEAKER_AND_LINE:
1671 if (enable)
1672 name = "spkr-gain-in-line-combo";
1673 else
1674 name = "speaker-gain-default";
1675 break;
1676 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES:
1677 if (enable)
1678 name = "spkr-safe-gain-in-headphone-combo";
1679 else
1680 name = "speaker-safe-gain-default";
1681 break;
1682 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE:
1683 if (enable)
1684 name = "spkr-safe-gain-in-line-combo";
1685 else
1686 name = "speaker-safe-gain-default";
1687 break;
1688 default:
1689 return;
1690 }
1691
1692 audio_route_apply_and_update_path(adev->audio_route, name);
1693}
1694
Eric Laurentb23d5282013-05-14 15:27:20 -07001695int platform_set_voice_volume(void *platform, int volume)
1696{
1697 struct platform_data *my_data = (struct platform_data *)platform;
1698 struct audio_device *adev = my_data->adev;
1699 struct mixer_ctl *ctl;
sangwoo53b2cf02013-07-25 19:18:44 -07001700 const char *mixer_ctl_name = "Voice Rx Gain";
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001701 int vol_index = 0, ret = 0;
1702 uint32_t set_values[ ] = {0,
1703 ALL_SESSION_VSID,
1704 DEFAULT_VOLUME_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07001705
1706 // Voice volume levels are mapped to adsp volume levels as follows.
1707 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
1708 // But this values don't changed in kernel. So, below change is need.
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09001709 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, my_data->max_vol_index);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001710 set_values[0] = vol_index;
Eric Laurentb23d5282013-05-14 15:27:20 -07001711
1712 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1713 if (!ctl) {
1714 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1715 __func__, mixer_ctl_name);
1716 return -EINVAL;
1717 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001718 ALOGV("Setting voice volume index: %d", set_values[0]);
1719 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1720
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001721 if (my_data->csd != NULL) {
1722 ret = my_data->csd->volume(ALL_SESSION_VSID, volume,
1723 DEFAULT_VOLUME_RAMP_DURATION_MS);
1724 if (ret < 0) {
1725 ALOGE("%s: csd_volume error %d", __func__, ret);
1726 }
1727 }
1728 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001729}
1730
1731int platform_set_mic_mute(void *platform, bool state)
1732{
1733 struct platform_data *my_data = (struct platform_data *)platform;
1734 struct audio_device *adev = my_data->adev;
1735 struct mixer_ctl *ctl;
1736 const char *mixer_ctl_name = "Voice Tx Mute";
sangwoo53b2cf02013-07-25 19:18:44 -07001737 int ret = 0;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001738 uint32_t set_values[ ] = {0,
1739 ALL_SESSION_VSID,
1740 DEFAULT_MUTE_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07001741
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09001742 if (adev->mode != AUDIO_MODE_IN_CALL &&
1743 adev->mode != AUDIO_MODE_IN_COMMUNICATION)
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001744 return 0;
1745
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09001746 if (adev->enable_hfp)
1747 mixer_ctl_name = "HFP Tx Mute";
1748
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001749 set_values[0] = state;
1750 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1751 if (!ctl) {
1752 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1753 __func__, mixer_ctl_name);
1754 return -EINVAL;
1755 }
1756 ALOGV("Setting voice mute state: %d", state);
1757 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1758
1759 if (my_data->csd != NULL) {
1760 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state,
1761 DEFAULT_MUTE_RAMP_DURATION_MS);
sangwoo53b2cf02013-07-25 19:18:44 -07001762 if (ret < 0) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001763 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
sangwoo53b2cf02013-07-25 19:18:44 -07001764 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001765 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001766 return ret;
1767}
Eric Laurentb23d5282013-05-14 15:27:20 -07001768
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001769int platform_set_device_mute(void *platform, bool state, char *dir)
1770{
1771 struct platform_data *my_data = (struct platform_data *)platform;
1772 struct audio_device *adev = my_data->adev;
1773 struct mixer_ctl *ctl;
1774 char *mixer_ctl_name = NULL;
1775 int ret = 0;
1776 uint32_t set_values[ ] = {0,
1777 ALL_SESSION_VSID,
1778 0};
1779 if(dir == NULL) {
1780 ALOGE("%s: Invalid direction:%s", __func__, dir);
1781 return -EINVAL;
1782 }
1783
1784 if (!strncmp("rx", dir, sizeof("rx"))) {
1785 mixer_ctl_name = "Voice Rx Device Mute";
1786 } else if (!strncmp("tx", dir, sizeof("tx"))) {
1787 mixer_ctl_name = "Voice Tx Device Mute";
1788 } else {
1789 return -EINVAL;
1790 }
1791
1792 set_values[0] = state;
1793 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1794 if (!ctl) {
1795 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1796 __func__, mixer_ctl_name);
1797 return -EINVAL;
1798 }
1799
1800 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
1801 __func__,state, mixer_ctl_name);
1802 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1803
1804 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001805}
1806
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001807bool platform_can_split_snd_device(snd_device_t snd_device,
1808 int *num_devices,
1809 snd_device_t *new_snd_devices)
1810{
1811 bool status = false;
1812
1813 if (NULL == num_devices || NULL == new_snd_devices) {
1814 ALOGE("%s: NULL pointer ..", __func__);
1815 return false;
1816 }
1817
1818 /*
1819 * If wired headset/headphones/line devices share the same backend
1820 * with speaker/earpiece this routine returns false.
1821 */
1822 if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES &&
1823 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_HEADPHONES)) {
1824 *num_devices = 2;
1825 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
1826 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
1827 status = true;
1828 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_LINE &&
1829 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_LINE)) {
1830 *num_devices = 2;
1831 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
1832 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
1833 status = true;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001834 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES &&
1835 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_HEADPHONES)) {
1836 *num_devices = 2;
1837 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
1838 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
1839 status = true;
1840 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE &&
1841 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_LINE)) {
1842 *num_devices = 2;
1843 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
1844 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
1845 status = true;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001846 }
1847 return status;
1848}
1849
Eric Laurentb23d5282013-05-14 15:27:20 -07001850snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
1851{
1852 struct platform_data *my_data = (struct platform_data *)platform;
1853 struct audio_device *adev = my_data->adev;
1854 audio_mode_t mode = adev->mode;
1855 snd_device_t snd_device = SND_DEVICE_NONE;
1856
1857 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
1858 if (devices == AUDIO_DEVICE_NONE ||
1859 devices & AUDIO_DEVICE_BIT_IN) {
1860 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
1861 goto exit;
1862 }
1863
Eric Laurent1b491552015-09-15 17:52:41 -07001864 if (popcount(devices) == 2) {
1865 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
1866 AUDIO_DEVICE_OUT_SPEAKER) ||
1867 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
1868 AUDIO_DEVICE_OUT_SPEAKER)) {
1869 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
1870 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
1871 AUDIO_DEVICE_OUT_SPEAKER)) {
1872 snd_device = SND_DEVICE_OUT_SPEAKER_AND_LINE;
1873 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
1874 AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
1875 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
1876 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
1877 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES;
1878 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
1879 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
1880 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE;
1881 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
1882 AUDIO_DEVICE_OUT_SPEAKER)) {
1883 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
1884 } else {
1885 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
1886 goto exit;
1887 }
1888 if (snd_device != SND_DEVICE_NONE) {
1889 goto exit;
1890 }
1891 }
1892
1893 if (popcount(devices) != 1) {
1894 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
1895 goto exit;
1896 }
1897
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001898 if (voice_is_in_call(adev) || adev->enable_voicerx) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001899 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05001900 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
1901 devices & AUDIO_DEVICE_OUT_LINE) {
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001902 if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05001903 (adev->voice.tty_mode == TTY_MODE_FULL))
Eric Laurentb23d5282013-05-14 15:27:20 -07001904 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001905 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05001906 (adev->voice.tty_mode == TTY_MODE_VCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07001907 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001908 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05001909 (adev->voice.tty_mode == TTY_MODE_HCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07001910 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05001911 else {
1912 if (devices & AUDIO_DEVICE_OUT_LINE)
1913 snd_device = SND_DEVICE_OUT_VOICE_LINE;
1914 else
1915 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
1916 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001917 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07001918 if (adev->bt_wb_speech_enabled) {
1919 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
1920 } else {
1921 snd_device = SND_DEVICE_OUT_BT_SCO;
1922 }
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07001923 } else if (devices & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07001924 if (!adev->enable_hfp) {
1925 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
1926 } else {
1927 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_HFP;
1928 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001929 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05001930 if(adev->voice.hac)
1931 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
1932 else if (is_operator_tmus())
Eric Laurentb23d5282013-05-14 15:27:20 -07001933 snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS;
1934 else
Eric Laurentb4d368e2014-06-25 10:21:54 -05001935 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07001936 } else if (devices & AUDIO_DEVICE_OUT_TELEPHONY_TX)
1937 snd_device = SND_DEVICE_OUT_VOICE_TX;
1938
Eric Laurentb23d5282013-05-14 15:27:20 -07001939 if (snd_device != SND_DEVICE_NONE) {
1940 goto exit;
1941 }
1942 }
1943
Eric Laurentb23d5282013-05-14 15:27:20 -07001944 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1945 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
1946 snd_device = SND_DEVICE_OUT_HEADPHONES;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05001947 } else if (devices & AUDIO_DEVICE_OUT_LINE) {
1948 snd_device = SND_DEVICE_OUT_LINE;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07001949 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) {
1950 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001951 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07001952 if (my_data->speaker_lr_swap)
Eric Laurentb23d5282013-05-14 15:27:20 -07001953 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
1954 else
1955 snd_device = SND_DEVICE_OUT_SPEAKER;
1956 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07001957 if (adev->bt_wb_speech_enabled) {
1958 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
1959 } else {
1960 snd_device = SND_DEVICE_OUT_BT_SCO;
1961 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001962 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
1963 snd_device = SND_DEVICE_OUT_HDMI ;
1964 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05001965 /*HAC support for voice-ish audio (eg visual voicemail)*/
1966 if(adev->voice.hac)
1967 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
1968 else
1969 snd_device = SND_DEVICE_OUT_HANDSET;
Eric Laurentb23d5282013-05-14 15:27:20 -07001970 } else {
1971 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
1972 }
1973exit:
1974 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
1975 return snd_device;
1976}
1977
1978snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
1979{
1980 struct platform_data *my_data = (struct platform_data *)platform;
1981 struct audio_device *adev = my_data->adev;
1982 audio_source_t source = (adev->active_input == NULL) ?
1983 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
1984
1985 audio_mode_t mode = adev->mode;
1986 audio_devices_t in_device = ((adev->active_input == NULL) ?
1987 AUDIO_DEVICE_NONE : adev->active_input->device)
1988 & ~AUDIO_DEVICE_BIT_IN;
1989 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
1990 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
1991 snd_device_t snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001992 int channel_count = popcount(channel_mask);
Eric Laurentb23d5282013-05-14 15:27:20 -07001993
Prashant Malanic92c5962015-08-11 15:10:18 -07001994 ALOGV("%s: enter: out_device(%#x) in_device(%#x) channel_count (%d) channel_mask (0x%x)",
1995 __func__, out_device, in_device, channel_count, channel_mask);
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001996 if ((out_device != AUDIO_DEVICE_NONE) && voice_is_in_call(adev)) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001997 if (adev->voice.tty_mode != TTY_MODE_OFF) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001998 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05001999 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2000 out_device & AUDIO_DEVICE_OUT_LINE) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002001 switch (adev->voice.tty_mode) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002002 case TTY_MODE_FULL:
2003 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
2004 break;
2005 case TTY_MODE_VCO:
2006 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
2007 break;
2008 case TTY_MODE_HCO:
2009 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
2010 break;
2011 default:
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002012 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
Eric Laurentb23d5282013-05-14 15:27:20 -07002013 }
2014 goto exit;
2015 }
2016 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002017 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002018 if (my_data->fluence_in_voice_call == false) {
2019 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2020 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002021 if (is_operator_tmus())
2022 snd_device = SND_DEVICE_IN_VOICE_DMIC_TMUS;
Eric Laurentb23d5282013-05-14 15:27:20 -07002023 else
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002024 snd_device = SND_DEVICE_IN_VOICE_DMIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002025 }
2026 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2027 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
2028 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002029 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002030 if (adev->bluetooth_nrec)
2031 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2032 else
2033 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002034 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002035 if (adev->bluetooth_nrec)
2036 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2037 else
2038 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002039 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002040 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Prashant Malanic92c5962015-08-11 15:10:18 -07002041 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
2042 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2043 out_device & AUDIO_DEVICE_OUT_LINE) {
2044 if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
2045 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
2046 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
2047 } else {
2048 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2049 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002050 }
vivek mehtafe121d52015-08-10 23:39:23 -07002051
2052 //select default
2053 if (snd_device == SND_DEVICE_NONE) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002054 if (!adev->enable_hfp) {
2055 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2056 } else {
2057 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP;
2058 platform_set_echo_reference(adev, true, out_device);
2059 }
vivek mehtafe121d52015-08-10 23:39:23 -07002060 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002061 } else if (out_device & AUDIO_DEVICE_OUT_TELEPHONY_TX) {
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002062 snd_device = SND_DEVICE_IN_VOICE_RX;
Prashant Malanic92c5962015-08-11 15:10:18 -07002063 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002064 } else if (source == AUDIO_SOURCE_CAMCORDER) {
2065 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
2066 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2067 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
2068 }
2069 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
2070 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002071 if (my_data->fluence_in_voice_rec && channel_count == 1) {
2072 if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2073 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002074 if (adev->active_input->enable_aec)
2075 snd_device = SND_DEVICE_IN_HANDSET_QMIC_AEC;
2076 else
2077 snd_device = SND_DEVICE_IN_HANDSET_QMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002078 } else if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2079 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002080 if (adev->active_input->enable_aec)
2081 snd_device = SND_DEVICE_IN_HANDSET_TMIC_AEC;
2082 else
2083 snd_device = SND_DEVICE_IN_HANDSET_TMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002084 } else if (((my_data->fluence_type == FLUENCE_PRO_ENABLE) ||
2085 (my_data->fluence_type == FLUENCE_ENABLE)) &&
2086 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002087 if (adev->active_input->enable_aec)
2088 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
2089 else
2090 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
Prashant Malanic92c5962015-08-11 15:10:18 -07002091 }
2092 platform_set_echo_reference(adev, true, out_device);
2093 } else if ((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) &&
2094 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2095 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
2096 } else if (((int)channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
2097 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
2098 snd_device = SND_DEVICE_IN_THREE_MIC;
2099 } else if (((int)channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
2100 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2101 snd_device = SND_DEVICE_IN_QUAD_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002102 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002103 if (snd_device == SND_DEVICE_NONE) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002104 if (adev->active_input->enable_ns)
2105 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
vivek mehta733c1df2016-04-04 15:09:24 -07002106 else if (adev->active_input->enable_aec) {
2107 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC;
2108 platform_set_echo_reference(adev, true, out_device);
2109 } else
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002110 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002111 }
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -07002112 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2113 snd_device = SND_DEVICE_IN_VOICE_REC_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002114 }
rago90fb9612015-12-02 11:37:53 -08002115 } else if (source == AUDIO_SOURCE_UNPROCESSED) {
2116 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
vivek mehta4ed66e62016-04-15 23:33:34 -07002117 if (((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) ||
2118 (channel_mask == AUDIO_CHANNEL_IN_STEREO)) &&
2119 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2120 snd_device = SND_DEVICE_IN_UNPROCESSED_STEREO_MIC;
2121 } else if (((int)channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
2122 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
2123 snd_device = SND_DEVICE_IN_UNPROCESSED_THREE_MIC;
2124 } else if (((int)channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
2125 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2126 snd_device = SND_DEVICE_IN_UNPROCESSED_QUAD_MIC;
2127 } else {
2128 snd_device = SND_DEVICE_IN_UNPROCESSED_MIC;
2129 }
rago90fb9612015-12-02 11:37:53 -08002130 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2131 snd_device = SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC;
2132 }
Eric Laurent50a38ed2015-10-14 18:48:06 -07002133 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION ||
rago90fb9612015-12-02 11:37:53 -08002134 mode == AUDIO_MODE_IN_COMMUNICATION) {
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002135 if (out_device & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE))
Eric Laurentb23d5282013-05-14 15:27:20 -07002136 in_device = AUDIO_DEVICE_IN_BACK_MIC;
2137 if (adev->active_input) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002138 if (adev->active_input->enable_aec &&
2139 adev->active_input->enable_ns) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002140 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002141 if (my_data->fluence_in_spkr_mode &&
2142 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002143 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002144 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002145 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002146 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002147 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002148 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002149 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002150 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002151 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002152 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002153 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002154 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002155 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2156 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002157 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002158 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002159 } else if (adev->active_input->enable_aec) {
2160 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2161 if (my_data->fluence_in_spkr_mode &&
2162 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002163 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002164 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002165 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002166 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002167 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002168 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2169 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002170 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002171 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002172 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002173 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002174 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002175 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2176 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
2177 }
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08002178 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002179 } else if (adev->active_input->enable_ns) {
2180 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2181 if (my_data->fluence_in_spkr_mode &&
2182 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002183 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002184 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002185 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002186 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002187 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002188 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2189 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002190 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002191 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002192 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002193 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002194 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002195 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002196 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002197 }
2198 } else if (source == AUDIO_SOURCE_DEFAULT) {
2199 goto exit;
2200 }
2201
2202
2203 if (snd_device != SND_DEVICE_NONE) {
2204 goto exit;
2205 }
2206
2207 if (in_device != AUDIO_DEVICE_NONE &&
2208 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
2209 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
2210 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002211 if ((my_data->source_mic_type & SOURCE_QUAD_MIC) &&
2212 (int)channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) {
2213 snd_device = SND_DEVICE_IN_QUAD_MIC;
2214 } else if ((my_data->source_mic_type & SOURCE_THREE_MIC) &&
2215 (int)channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) {
2216 snd_device = SND_DEVICE_IN_THREE_MIC;
2217 } else if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2218 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002219 snd_device = SND_DEVICE_IN_HANDSET_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002220 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2221 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002222 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002223 } else {
2224 ALOGE("%s: something wrong (1): source type (%d) channel_count (%d) .."
2225 " channel mask (0x%x) no combination found .. setting to mono", __func__,
2226 my_data->source_mic_type, channel_count, channel_mask);
2227 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2228 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002229 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002230 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2231 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002232 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002233 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2234 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002235 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002236 } else {
2237 ALOGE("%s: something wrong (2): source type (%d) channel_count (%d) .."
2238 " no combination found .. setting to mono", __func__,
2239 my_data->source_mic_type, channel_count);
2240 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
2241 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002242 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2243 snd_device = SND_DEVICE_IN_HEADSET_MIC;
2244 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002245 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002246 if (adev->bluetooth_nrec)
2247 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2248 else
2249 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002250 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002251 if (adev->bluetooth_nrec)
2252 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2253 else
2254 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002255 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002256 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
2257 snd_device = SND_DEVICE_IN_HDMI_MIC;
2258 } else {
2259 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
2260 ALOGW("%s: Using default handset-mic", __func__);
2261 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2262 }
2263 } else {
2264 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
2265 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2266 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2267 snd_device = SND_DEVICE_IN_HEADSET_MIC;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002268 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002269 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002270 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002271 out_device & AUDIO_DEVICE_OUT_LINE) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002272 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2273 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002274 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002275 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2276 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002277 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002278 } else {
2279 ALOGE("%s: something wrong (3): source type (%d) channel_count (%d) .."
2280 " no combination found .. setting to mono", __func__,
2281 my_data->source_mic_type, channel_count);
2282 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
2283 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002284 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002285 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002286 if (adev->bluetooth_nrec)
2287 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2288 else
2289 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002290 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002291 if (adev->bluetooth_nrec)
2292 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2293 else
2294 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002295 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002296 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2297 snd_device = SND_DEVICE_IN_HDMI_MIC;
2298 } else {
2299 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
2300 ALOGW("%s: Using default handset-mic", __func__);
2301 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2302 }
2303 }
2304exit:
2305 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
2306 return snd_device;
2307}
2308
2309int platform_set_hdmi_channels(void *platform, int channel_count)
2310{
2311 struct platform_data *my_data = (struct platform_data *)platform;
2312 struct audio_device *adev = my_data->adev;
2313 struct mixer_ctl *ctl;
2314 const char *channel_cnt_str = NULL;
2315 const char *mixer_ctl_name = "HDMI_RX Channels";
2316 switch (channel_count) {
2317 case 8:
2318 channel_cnt_str = "Eight"; break;
2319 case 7:
2320 channel_cnt_str = "Seven"; break;
2321 case 6:
2322 channel_cnt_str = "Six"; break;
2323 case 5:
2324 channel_cnt_str = "Five"; break;
2325 case 4:
2326 channel_cnt_str = "Four"; break;
2327 case 3:
2328 channel_cnt_str = "Three"; break;
2329 default:
2330 channel_cnt_str = "Two"; break;
2331 }
2332 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2333 if (!ctl) {
2334 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2335 __func__, mixer_ctl_name);
2336 return -EINVAL;
2337 }
2338 ALOGV("HDMI channel count: %s", channel_cnt_str);
2339 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
2340 return 0;
2341}
2342
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002343int platform_edid_get_max_channels(void *platform)
Eric Laurentb23d5282013-05-14 15:27:20 -07002344{
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002345 struct platform_data *my_data = (struct platform_data *)platform;
2346 struct audio_device *adev = my_data->adev;
Eric Laurentb23d5282013-05-14 15:27:20 -07002347 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
2348 char *sad = block;
2349 int num_audio_blocks;
2350 int channel_count;
2351 int max_channels = 0;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002352 int i, ret, count;
Eric Laurentb23d5282013-05-14 15:27:20 -07002353
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002354 struct mixer_ctl *ctl;
2355
2356 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
2357 if (!ctl) {
2358 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2359 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
Eric Laurentb23d5282013-05-14 15:27:20 -07002360 return 0;
2361 }
2362
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002363 mixer_ctl_update(ctl);
2364
2365 count = mixer_ctl_get_num_values(ctl);
Eric Laurentb23d5282013-05-14 15:27:20 -07002366
2367 /* Read SAD blocks, clamping the maximum size for safety */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002368 if (count > (int)sizeof(block))
2369 count = (int)sizeof(block);
Eric Laurentb23d5282013-05-14 15:27:20 -07002370
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002371 ret = mixer_ctl_get_array(ctl, block, count);
2372 if (ret != 0) {
2373 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
2374 return 0;
2375 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002376
2377 /* Calculate the number of SAD blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002378 num_audio_blocks = count / SAD_BLOCK_SIZE;
Eric Laurentb23d5282013-05-14 15:27:20 -07002379
2380 for (i = 0; i < num_audio_blocks; i++) {
2381 /* Only consider LPCM blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002382 if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
2383 sad += 3;
Eric Laurentb23d5282013-05-14 15:27:20 -07002384 continue;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002385 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002386
2387 channel_count = (sad[0] & 0x7) + 1;
2388 if (channel_count > max_channels)
2389 max_channels = channel_count;
2390
2391 /* Advance to next block */
2392 sad += 3;
2393 }
2394
2395 return max_channels;
2396}
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07002397
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002398int platform_set_incall_recording_session_id(void *platform,
2399 uint32_t session_id, int rec_mode)
2400{
2401 int ret = 0;
2402 struct platform_data *my_data = (struct platform_data *)platform;
2403 struct audio_device *adev = my_data->adev;
2404 struct mixer_ctl *ctl;
2405 const char *mixer_ctl_name = "Voc VSID";
2406 int num_ctl_values;
2407 int i;
2408
2409 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2410 if (!ctl) {
2411 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2412 __func__, mixer_ctl_name);
2413 ret = -EINVAL;
2414 } else {
2415 num_ctl_values = mixer_ctl_get_num_values(ctl);
2416 for (i = 0; i < num_ctl_values; i++) {
2417 if (mixer_ctl_set_value(ctl, i, session_id)) {
2418 ALOGV("Error: invalid session_id: %x", session_id);
2419 ret = -EINVAL;
2420 break;
2421 }
2422 }
2423 }
2424
2425 if (my_data->csd != NULL) {
2426 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
2427 if (ret < 0) {
2428 ALOGE("%s: csd_client_start_record failed, error %d",
2429 __func__, ret);
2430 }
2431 }
2432
2433 return ret;
2434}
2435
2436int platform_stop_incall_recording_usecase(void *platform)
2437{
2438 int ret = 0;
2439 struct platform_data *my_data = (struct platform_data *)platform;
2440
2441 if (my_data->csd != NULL) {
2442 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
2443 if (ret < 0) {
2444 ALOGE("%s: csd_client_stop_record failed, error %d",
2445 __func__, ret);
2446 }
2447 }
2448
2449 return ret;
2450}
2451
2452int platform_start_incall_music_usecase(void *platform)
2453{
2454 int ret = 0;
2455 struct platform_data *my_data = (struct platform_data *)platform;
2456
2457 if (my_data->csd != NULL) {
2458 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
2459 if (ret < 0) {
2460 ALOGE("%s: csd_client_start_playback failed, error %d",
2461 __func__, ret);
2462 }
2463 }
2464
2465 return ret;
2466}
2467
2468int platform_stop_incall_music_usecase(void *platform)
2469{
2470 int ret = 0;
2471 struct platform_data *my_data = (struct platform_data *)platform;
2472
2473 if (my_data->csd != NULL) {
2474 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
2475 if (ret < 0) {
2476 ALOGE("%s: csd_client_stop_playback failed, error %d",
2477 __func__, ret);
2478 }
2479 }
2480
2481 return ret;
2482}
2483
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002484int platform_set_parameters(void *platform, struct str_parms *parms)
2485{
2486 struct platform_data *my_data = (struct platform_data *)platform;
keunhui.park2f7306a2015-07-16 16:48:06 +09002487 char value[128];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002488 char *kv_pairs = str_parms_to_str(parms);
2489 int ret = 0, err;
2490
2491 if (kv_pairs == NULL) {
2492 ret = -EINVAL;
2493 ALOGE("%s: key-value pair is NULL",__func__);
2494 goto done;
2495 }
2496
2497 ALOGV("%s: enter: %s", __func__, kv_pairs);
2498
2499 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME,
2500 value, sizeof(value));
2501 if (err >= 0) {
2502 str_parms_del(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME);
2503 my_data->snd_card_name = strdup(value);
2504 ALOGV("%s: sound card name %s", __func__, my_data->snd_card_name);
2505 }
2506
keunhui.park2f7306a2015-07-16 16:48:06 +09002507 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO,
2508 value, sizeof(value));
2509 if (err >= 0) {
2510 struct operator_info *info;
2511 char *str = value;
2512 char *name;
2513
2514 str_parms_del(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO);
2515 info = (struct operator_info *)calloc(1, sizeof(struct operator_info));
2516 name = strtok(str, ";");
2517 info->name = strdup(name);
2518 info->mccmnc = strdup(str + strlen(name) + 1);
2519
2520 list_add_tail(&operator_info_list, &info->list);
Joe Onorato188b6222016-03-01 11:02:27 -08002521 ALOGV("%s: add operator[%s] mccmnc[%s]", __func__, info->name, info->mccmnc);
keunhui.park2f7306a2015-07-16 16:48:06 +09002522 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002523
2524 memset(value, 0, sizeof(value));
Eric Laurentc6333382015-09-14 12:43:44 -07002525 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT,
Prashant Malanic92c5962015-08-11 15:10:18 -07002526 value, sizeof(value));
2527 if (err >= 0) {
Eric Laurentc6333382015-09-14 12:43:44 -07002528 str_parms_del(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT);
Prashant Malanic92c5962015-08-11 15:10:18 -07002529 my_data->max_mic_count = atoi(value);
2530 ALOGV("%s: max_mic_count %s/%d", __func__, value, my_data->max_mic_count);
Prashant Malanic92c5962015-08-11 15:10:18 -07002531 }
2532
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002533done:
2534 ALOGV("%s: exit with code(%d)", __func__, ret);
2535 if (kv_pairs != NULL)
2536 free(kv_pairs);
2537
2538 return ret;
2539}
2540
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07002541/* Delay in Us */
2542int64_t platform_render_latency(audio_usecase_t usecase)
2543{
2544 switch (usecase) {
2545 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
2546 return DEEP_BUFFER_PLATFORM_DELAY;
2547 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
2548 return LOW_LATENCY_PLATFORM_DELAY;
Haynes Mathew George03c40102016-01-29 17:57:48 -08002549 case USECASE_AUDIO_PLAYBACK_ULL:
2550 return ULL_PLATFORM_DELAY;
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07002551 default:
2552 return 0;
2553 }
2554}
Haynes Mathew George98c95622014-06-20 19:14:25 -07002555
vivek mehta4ed66e62016-04-15 23:33:34 -07002556bool platform_check_and_set_capture_backend_cfg(struct audio_device* adev,
2557 struct audio_usecase *usecase, snd_device_t snd_device)
2558{
2559 enum pcm_format in_pcm_format = PCM_FORMAT_S16_LE;
2560
2561 if (adev && adev->active_input)
2562 in_pcm_format = adev->active_input->config.format;
2563
2564 // allow 24 bit recording only if voice call is not active
2565 if (!voice_is_in_call(adev) &&
2566 adev->mode != AUDIO_MODE_IN_COMMUNICATION &&
2567 in_pcm_format == PCM_FORMAT_S24_LE) {
2568 audio_route_apply_and_update_path(adev->audio_route, "set-capture-format-24le");
2569 } else {
2570 audio_route_apply_and_update_path(adev->audio_route, "set-capture-format-default");
2571 }
2572
2573 return true;
2574}
2575
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002576int platform_set_snd_device_backend(snd_device_t device, const char *backend_tag,
2577 const char * hw_interface)
Haynes Mathew George98c95622014-06-20 19:14:25 -07002578{
2579 int ret = 0;
2580
2581 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
2582 ALOGE("%s: Invalid snd_device = %d",
2583 __func__, device);
2584 ret = -EINVAL;
2585 goto done;
2586 }
2587
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002588 ALOGV("%s: backend_tag_table[%s]: old = %s new = %s", __func__,
2589 platform_get_snd_device_name(device),
2590 backend_tag_table[device] != NULL ? backend_tag_table[device]: "null", backend_tag);
2591 if (backend_tag_table[device]) {
2592 free(backend_tag_table[device]);
Haynes Mathew George98c95622014-06-20 19:14:25 -07002593 }
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002594 backend_tag_table[device] = strdup(backend_tag);
2595
2596 if (hw_interface != NULL) {
2597 if (hw_interface_table[device])
2598 free(hw_interface_table[device]);
2599 ALOGV("%s: hw_interface_table[%d] = %s", __func__, device, hw_interface);
2600 hw_interface_table[device] = strdup(hw_interface);
2601 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07002602done:
2603 return ret;
2604}
2605
2606int platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t pcm_id)
2607{
2608 int ret = 0;
2609 if ((usecase <= USECASE_INVALID) || (usecase >= AUDIO_USECASE_MAX)) {
2610 ALOGE("%s: invalid usecase case idx %d", __func__, usecase);
2611 ret = -EINVAL;
2612 goto done;
2613 }
2614
2615 if ((type != 0) && (type != 1)) {
2616 ALOGE("%s: invalid usecase type", __func__);
2617 ret = -EINVAL;
2618 }
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002619 ALOGV("%s: pcm_device_table[%d][%d] = %d", __func__, usecase, type, pcm_id);
Haynes Mathew George98c95622014-06-20 19:14:25 -07002620 pcm_device_table[usecase][type] = pcm_id;
2621done:
2622 return ret;
2623}
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002624
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07002625#define DEFAULT_NOMINAL_SPEAKER_GAIN 20
2626int ramp_speaker_gain(struct audio_device *adev, bool ramp_up, int target_ramp_up_gain) {
2627 // backup_gain: gain to try to set in case of an error during ramp
2628 int start_gain, end_gain, step, backup_gain, i;
2629 bool error = false;
2630 const struct mixer_ctl *ctl;
2631 const char *mixer_ctl_name_gain_left = "Left Speaker Gain";
2632 const char *mixer_ctl_name_gain_right = "Right Speaker Gain";
2633 struct mixer_ctl *ctl_left = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_left);
2634 struct mixer_ctl *ctl_right = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_right);
2635 if (!ctl_left || !ctl_right) {
2636 ALOGE("%s: Could not get ctl for mixer cmd - %s or %s, not applying speaker gain ramp",
2637 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
2638 return -EINVAL;
2639 } else if ((mixer_ctl_get_num_values(ctl_left) != 1)
2640 || (mixer_ctl_get_num_values(ctl_right) != 1)) {
2641 ALOGE("%s: Unexpected num values for mixer cmd - %s or %s, not applying speaker gain ramp",
2642 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
2643 return -EINVAL;
2644 }
2645 if (ramp_up) {
2646 start_gain = 0;
2647 end_gain = target_ramp_up_gain > 0 ? target_ramp_up_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
2648 step = +1;
2649 backup_gain = end_gain;
2650 } else {
2651 // using same gain on left and right
2652 const int left_gain = mixer_ctl_get_value(ctl_left, 0);
2653 start_gain = left_gain > 0 ? left_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
2654 end_gain = 0;
2655 step = -1;
2656 backup_gain = start_gain;
2657 }
2658 for (i = start_gain ; i != (end_gain + step) ; i += step) {
2659 //ALOGV("setting speaker gain to %d", i);
2660 if (mixer_ctl_set_value(ctl_left, 0, i)) {
2661 ALOGE("%s: error setting %s to %d during gain ramp",
2662 __func__, mixer_ctl_name_gain_left, i);
2663 error = true;
2664 break;
2665 }
2666 if (mixer_ctl_set_value(ctl_right, 0, i)) {
2667 ALOGE("%s: error setting %s to %d during gain ramp",
2668 __func__, mixer_ctl_name_gain_right, i);
2669 error = true;
2670 break;
2671 }
2672 usleep(1000);
2673 }
2674 if (error) {
2675 // an error occured during the ramp, let's still try to go back to a safe volume
2676 if (mixer_ctl_set_value(ctl_left, 0, backup_gain)) {
2677 ALOGE("%s: error restoring left gain to %d", __func__, backup_gain);
2678 }
2679 if (mixer_ctl_set_value(ctl_right, 0, backup_gain)) {
2680 ALOGE("%s: error restoring right gain to %d", __func__, backup_gain);
2681 }
2682 }
2683 return start_gain;
2684}
2685
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002686int platform_swap_lr_channels(struct audio_device *adev, bool swap_channels)
2687{
2688 // only update if there is active pcm playback on speaker
2689 struct audio_usecase *usecase;
2690 struct listnode *node;
2691 struct platform_data *my_data = (struct platform_data *)adev->platform;
2692
2693 if (my_data->speaker_lr_swap != swap_channels) {
2694 my_data->speaker_lr_swap = swap_channels;
2695
2696 list_for_each(node, &adev->usecase_list) {
2697 usecase = node_to_item(node, struct audio_usecase, list);
2698 if (usecase->type == PCM_PLAYBACK &&
Ravi Kumar Alamanda425e1542015-09-22 09:11:18 -07002699 usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) {
2700 /*
2701 * If acdb tuning is different for SPEAKER_REVERSE, it is must
2702 * to perform device switch to disable the current backend to
2703 * enable it with new acdb data.
2704 */
2705 if (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
2706 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]) {
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07002707 const int initial_skpr_gain = ramp_speaker_gain(adev, false /*ramp_up*/, -1);
Ravi Kumar Alamanda425e1542015-09-22 09:11:18 -07002708 select_devices(adev, usecase->id);
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07002709 if (initial_skpr_gain != -EINVAL) {
2710 ramp_speaker_gain(adev, true /*ramp_up*/, initial_skpr_gain);
2711 }
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002712 } else {
Ravi Kumar Alamanda425e1542015-09-22 09:11:18 -07002713 const char *mixer_path;
2714 if (swap_channels) {
2715 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER_REVERSE);
2716 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
2717 } else {
2718 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER);
2719 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
2720 }
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002721 }
2722 break;
2723 }
2724 }
2725 }
2726 return 0;
2727}