blob: 220ccbb34fa88e9a53ede32cc6feed31de04364a [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",
vivek mehtaf3440682016-05-11 14:24:37 -0700262 [SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700263 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = "voice-rec-dmic-ef",
264 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence",
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700265 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = "headset-mic",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700266
Ricardo Garcia9034bc42016-04-04 07:11:46 -0700267 [SND_DEVICE_IN_UNPROCESSED_MIC] = "unprocessed-mic",
vivek mehta4ed66e62016-04-15 23:33:34 -0700268 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = "voice-rec-dmic-ef",
269 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = "three-mic",
270 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = "quad-mic",
rago90fb9612015-12-02 11:37:53 -0800271 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = "headset-mic",
272
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700273 [SND_DEVICE_IN_VOICE_RX] = "voice-rx",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700274
Prashant Malanic92c5962015-08-11 15:10:18 -0700275 [SND_DEVICE_IN_THREE_MIC] = "three-mic",
276 [SND_DEVICE_IN_QUAD_MIC] = "quad-mic",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700277 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = "vi-feedback",
Prashant Malanic92c5962015-08-11 15:10:18 -0700278 [SND_DEVICE_IN_HANDSET_TMIC] = "three-mic",
279 [SND_DEVICE_IN_HANDSET_QMIC] = "quad-mic",
vivek mehta733c1df2016-04-04 15:09:24 -0700280 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = "three-mic",
281 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = "quad-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700282};
283
284/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700285static int acdb_device_table[SND_DEVICE_MAX] = {
Eric Laurentb23d5282013-05-14 15:27:20 -0700286 [SND_DEVICE_NONE] = -1,
287 [SND_DEVICE_OUT_HANDSET] = 7,
288 [SND_DEVICE_OUT_SPEAKER] = 15,
289 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 15,
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700290 [SND_DEVICE_OUT_SPEAKER_SAFE] = 15,
Eric Laurentb23d5282013-05-14 15:27:20 -0700291 [SND_DEVICE_OUT_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500292 [SND_DEVICE_OUT_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700293 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700294 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500295 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = 77,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700296 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = 77,
Ravi Kumar Alamanda235c3482014-08-21 17:32:44 -0700297 [SND_DEVICE_OUT_VOICE_HANDSET] = ACDB_ID_VOICE_HANDSET,
298 [SND_DEVICE_OUT_VOICE_SPEAKER] = ACDB_ID_VOICE_SPEAKER,
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500299 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = 53,
Eric Laurentb23d5282013-05-14 15:27:20 -0700300 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500301 [SND_DEVICE_OUT_VOICE_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700302 [SND_DEVICE_OUT_HDMI] = 18,
303 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 15,
304 [SND_DEVICE_OUT_BT_SCO] = 22,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700305 [SND_DEVICE_OUT_BT_SCO_WB] = 39,
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700306 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = ACDB_ID_VOICE_HANDSET_TMUS,
Eric Laurentb23d5282013-05-14 15:27:20 -0700307 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
308 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
309 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700310 [SND_DEVICE_OUT_VOICE_TX] = 45,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700311 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = 124,
312 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = 101,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700313 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = ACDB_ID_VOICE_SPEAKER,
Eric Laurentb23d5282013-05-14 15:27:20 -0700314
315 [SND_DEVICE_IN_HANDSET_MIC] = 4,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700316 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 106,
317 [SND_DEVICE_IN_HANDSET_MIC_NS] = 107,
318 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = 108,
319 [SND_DEVICE_IN_HANDSET_DMIC] = 41,
320 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = 109,
321 [SND_DEVICE_IN_HANDSET_DMIC_NS] = 110,
322 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = 111,
323 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = 34,
324
325 [SND_DEVICE_IN_SPEAKER_MIC] = 11,
326 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 112,
327 [SND_DEVICE_IN_SPEAKER_MIC_NS] = 113,
328 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = 114,
329 [SND_DEVICE_IN_SPEAKER_DMIC] = 43,
330 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = 115,
331 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = 116,
332 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = 117,
333 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = 35,
334
rago90fb9612015-12-02 11:37:53 -0800335 [SND_DEVICE_IN_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentcefbbac2014-09-04 13:54:10 -0500336 [SND_DEVICE_IN_HEADSET_MIC_AEC] = ACDB_ID_HEADSET_MIC_AEC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700337
Eric Laurentb23d5282013-05-14 15:27:20 -0700338 [SND_DEVICE_IN_HDMI_MIC] = 4,
339 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700340 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = 21,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700341 [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700342 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = 38,
Eric Laurentb23d5282013-05-14 15:27:20 -0700343 [SND_DEVICE_IN_CAMCORDER_MIC] = 61,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700344
345 [SND_DEVICE_IN_VOICE_DMIC] = 41,
346 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = ACDB_ID_VOICE_DMIC_EF_TMUS,
347 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700348 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = 11,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700349 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 43,
rago90fb9612015-12-02 11:37:53 -0800350 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentb23d5282013-05-14 15:27:20 -0700351 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
352 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
353 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700354
rago90fb9612015-12-02 11:37:53 -0800355 [SND_DEVICE_IN_VOICE_REC_MIC] = ACDB_ID_VOICE_REC_MIC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700356 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = 113,
vivek mehta733c1df2016-04-04 15:09:24 -0700357 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = 112,
vivek mehtaf3440682016-05-11 14:24:37 -0700358 [SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = 114,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700359 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = 35,
360 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 43,
rago90fb9612015-12-02 11:37:53 -0800361 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
362
363 [SND_DEVICE_IN_UNPROCESSED_MIC] = ACDB_ID_VOICE_REC_MIC,
364 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
vivek mehta4ed66e62016-04-15 23:33:34 -0700365 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = 35,
366 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = 125,
367 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = 125,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700368
369 [SND_DEVICE_IN_VOICE_RX] = 44,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700370
Prashant Malanic92c5962015-08-11 15:10:18 -0700371 [SND_DEVICE_IN_THREE_MIC] = 46,
372 [SND_DEVICE_IN_QUAD_MIC] = 46,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700373 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = 102,
Prashant Malanic92c5962015-08-11 15:10:18 -0700374 [SND_DEVICE_IN_HANDSET_TMIC] = 125,
375 [SND_DEVICE_IN_HANDSET_QMIC] = 125,
vivek mehta733c1df2016-04-04 15:09:24 -0700376 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = 125, /* override this for new target to 140 */
377 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = 125, /* override this for new target to 140 */
Eric Laurentb23d5282013-05-14 15:27:20 -0700378};
379
Haynes Mathew George98c95622014-06-20 19:14:25 -0700380struct name_to_index {
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700381 char name[100];
382 unsigned int index;
383};
384
385#define TO_NAME_INDEX(X) #X, X
386
Haynes Mathew George98c95622014-06-20 19:14:25 -0700387/* Used to get index from parsed string */
388static const struct name_to_index snd_device_name_index[SND_DEVICE_MAX] = {
389 /* out */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700390 {TO_NAME_INDEX(SND_DEVICE_OUT_HANDSET)},
391 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER)},
392 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_REVERSE)},
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700393 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700394 {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500395 {TO_NAME_INDEX(SND_DEVICE_OUT_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700396 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700397 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES)},
Eric Laurent744996b2014-10-01 11:40:40 -0500398 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_LINE)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700399 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700400 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET)},
401 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700402 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_HFP)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700403 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500404 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700405 {TO_NAME_INDEX(SND_DEVICE_OUT_HDMI)},
406 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HDMI)},
407 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO)},
408 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO_WB)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700409 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET_TMUS)},
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500410 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HAC_HANDSET)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700411 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES)},
412 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES)},
413 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700414
415 /* in */
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700416 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED)},
417 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700418 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700419 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700420 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_NS)},
421 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)},
422 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC)},
423 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC)},
424 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_NS)},
425 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)},
426 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_STEREO)},
427
428 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700429 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700430 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_NS)},
431 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)},
432 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC)},
433 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC)},
434 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS)},
435 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)},
436 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_STEREO)},
437
438 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC)},
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700439 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700440
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700441 {TO_NAME_INDEX(SND_DEVICE_IN_HDMI_MIC)},
442 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700443 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700444 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700445 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700446 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700447
448 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC)},
449 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC_TMUS)},
450 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700451 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700452 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC)},
453 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEADSET_MIC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700454 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC)},
455 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC)},
456 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700457
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700458 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700459 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_NS)},
vivek mehta733c1df2016-04-04 15:09:24 -0700460 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC)},
vivek mehtaf3440682016-05-11 14:24:37 -0700461 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700462 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_STEREO)},
463 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE)},
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700464 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_HEADSET_MIC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700465
rago90fb9612015-12-02 11:37:53 -0800466 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_MIC)},
467 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC)},
vivek mehta4ed66e62016-04-15 23:33:34 -0700468 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_STEREO_MIC)},
469 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_THREE_MIC)},
470 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_QUAD_MIC)},
rago90fb9612015-12-02 11:37:53 -0800471
Prashant Malanic92c5962015-08-11 15:10:18 -0700472 {TO_NAME_INDEX(SND_DEVICE_IN_THREE_MIC)},
473 {TO_NAME_INDEX(SND_DEVICE_IN_QUAD_MIC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700474 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_VI_FEEDBACK)},
Prashant Malanic92c5962015-08-11 15:10:18 -0700475 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC)},
476 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC)},
vivek mehta733c1df2016-04-04 15:09:24 -0700477 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC_AEC)},
478 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC_AEC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700479};
480
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700481static char * backend_tag_table[SND_DEVICE_MAX] = {0};
482static char * hw_interface_table[SND_DEVICE_MAX] = {0};
Haynes Mathew George98c95622014-06-20 19:14:25 -0700483
484static const struct name_to_index usecase_name_index[AUDIO_USECASE_MAX] = {
485 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_DEEP_BUFFER)},
486 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_LOW_LATENCY)},
487 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_MULTI_CH)},
488 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD)},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700489 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_TTS)},
490 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_ULL)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700491 {TO_NAME_INDEX(USECASE_AUDIO_RECORD)},
492 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_LOW_LATENCY)},
493 {TO_NAME_INDEX(USECASE_VOICE_CALL)},
494 {TO_NAME_INDEX(USECASE_VOICE2_CALL)},
495 {TO_NAME_INDEX(USECASE_VOLTE_CALL)},
496 {TO_NAME_INDEX(USECASE_QCHAT_CALL)},
497 {TO_NAME_INDEX(USECASE_VOWLAN_CALL)},
498 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK)},
499 {TO_NAME_INDEX(USECASE_INCALL_REC_DOWNLINK)},
500 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK_AND_DOWNLINK)},
501 {TO_NAME_INDEX(USECASE_AUDIO_HFP_SCO)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700502};
503
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700504#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
505#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
Haynes Mathew George03c40102016-01-29 17:57:48 -0800506#define ULL_PLATFORM_DELAY (7*1000LL)
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700507
Eric Laurentb23d5282013-05-14 15:27:20 -0700508static pthread_once_t check_op_once_ctl = PTHREAD_ONCE_INIT;
509static bool is_tmus = false;
510
511static void check_operator()
512{
513 char value[PROPERTY_VALUE_MAX];
514 int mccmnc;
515 property_get("gsm.sim.operator.numeric",value,"0");
516 mccmnc = atoi(value);
Eric Laurent2bafff12016-03-17 12:17:23 -0700517 ALOGD("%s: tmus mccmnc %d", __func__, mccmnc);
Eric Laurentb23d5282013-05-14 15:27:20 -0700518 switch(mccmnc) {
519 /* TMUS MCC(310), MNC(490, 260, 026) */
520 case 310490:
521 case 310260:
522 case 310026:
sangwon.jeonb891db52013-09-14 17:39:15 +0900523 /* Add new TMUS MNC(800, 660, 580, 310, 270, 250, 240, 230, 220, 210, 200, 160) */
524 case 310800:
525 case 310660:
526 case 310580:
527 case 310310:
528 case 310270:
529 case 310250:
530 case 310240:
531 case 310230:
532 case 310220:
533 case 310210:
534 case 310200:
535 case 310160:
Eric Laurentb23d5282013-05-14 15:27:20 -0700536 is_tmus = true;
537 break;
538 }
539}
540
541bool is_operator_tmus()
542{
543 pthread_once(&check_op_once_ctl, check_operator);
544 return is_tmus;
545}
546
keunhui.park2f7306a2015-07-16 16:48:06 +0900547static char *get_current_operator()
548{
549 struct listnode *node;
550 struct operator_info *info_item;
551 char mccmnc[PROPERTY_VALUE_MAX];
552 char *ret = NULL;
553
554 property_get("gsm.sim.operator.numeric",mccmnc,"0");
555
556 list_for_each(node, &operator_info_list) {
557 info_item = node_to_item(node, struct operator_info, list);
558 if (strstr(info_item->mccmnc, mccmnc) != NULL) {
559 ret = info_item->name;
560 }
561 }
562
563 return ret;
564}
565
566static struct operator_specific_device *get_operator_specific_device(snd_device_t snd_device)
567{
568 struct listnode *node;
569 struct operator_specific_device *ret = NULL;
570 struct operator_specific_device *device_item;
571 char *operator_name;
572
573 operator_name = get_current_operator();
574 if (operator_name == NULL)
575 return ret;
576
577 list_for_each(node, operator_specific_device_table[snd_device]) {
578 device_item = node_to_item(node, struct operator_specific_device, list);
579 if (strcmp(operator_name, device_item->operator) == 0) {
580 ret = device_item;
581 }
582 }
583
584 return ret;
585}
586
587
588static int get_operator_specific_device_acdb_id(snd_device_t snd_device)
589{
590 struct operator_specific_device *device;
591 int ret = acdb_device_table[snd_device];
592
593 device = get_operator_specific_device(snd_device);
594 if (device != NULL)
595 ret = device->acdb_id;
596
597 return ret;
598}
599
600static const char *get_operator_specific_device_mixer_path(snd_device_t snd_device)
601{
602 struct operator_specific_device *device;
603 const char *ret = device_table[snd_device];
604
605 device = get_operator_specific_device(snd_device);
606 if (device != NULL)
607 ret = device->mixer_path;
608
609 return ret;
610}
611
vivek mehta1a9b7c02015-06-25 11:49:38 -0700612bool platform_send_gain_dep_cal(void *platform, int level)
613{
614 bool ret_val = false;
615 struct platform_data *my_data = (struct platform_data *)platform;
616 struct audio_device *adev = my_data->adev;
617 int acdb_dev_id, app_type;
618 int acdb_dev_type = MSM_SNDDEV_CAP_RX;
619 int mode = CAL_MODE_RTAC;
620 struct listnode *node;
621 struct audio_usecase *usecase;
vivek mehta1a9b7c02015-06-25 11:49:38 -0700622
623 if (my_data->acdb_send_gain_dep_cal == NULL) {
624 ALOGE("%s: dlsym error for acdb_send_gain_dep_cal", __func__);
625 return ret_val;
626 }
627
628 if (!voice_is_in_call(adev)) {
629 ALOGV("%s: Not Voice call usecase, apply new cal for level %d",
630 __func__, level);
631 app_type = DEFAULT_APP_TYPE_RX_PATH;
632
633 // find the current active sound device
634 list_for_each(node, &adev->usecase_list) {
635 usecase = node_to_item(node, struct audio_usecase, list);
636
637 if (usecase != NULL &&
638 usecase->type == PCM_PLAYBACK &&
639 (usecase->stream.out->devices == AUDIO_DEVICE_OUT_SPEAKER)) {
640
641 ALOGV("%s: out device is %d", __func__, usecase->out_snd_device);
vivek mehta4cb82982015-07-13 12:05:49 -0700642 if (audio_extn_spkr_prot_is_enabled()) {
643 acdb_dev_id = audio_extn_spkr_prot_get_acdb_id(usecase->out_snd_device);
644 } else {
645 acdb_dev_id = acdb_device_table[usecase->out_snd_device];
646 }
647
vivek mehta1a9b7c02015-06-25 11:49:38 -0700648 if (!my_data->acdb_send_gain_dep_cal(acdb_dev_id, app_type,
649 acdb_dev_type, mode, level)) {
650 // set ret_val true if at least one calibration is set successfully
651 ret_val = true;
652 } else {
653 ALOGE("%s: my_data->acdb_send_gain_dep_cal failed ", __func__);
654 }
655 } else {
656 ALOGW("%s: Usecase list is empty", __func__);
657 }
658 }
659 } else {
660 ALOGW("%s: Voice call in progress .. ignore setting new cal",
661 __func__);
662 }
663 return ret_val;
664}
665
Eric Laurentcefbbac2014-09-04 13:54:10 -0500666void platform_set_echo_reference(struct audio_device *adev, bool enable, audio_devices_t out_device)
Eric Laurentb23d5282013-05-14 15:27:20 -0700667{
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800668 struct platform_data *my_data = (struct platform_data *)adev->platform;
Eric Laurentcefbbac2014-09-04 13:54:10 -0500669 snd_device_t snd_device = SND_DEVICE_NONE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700670
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800671 if (strcmp(my_data->ec_ref_mixer_path, "")) {
672 ALOGV("%s: diabling %s", __func__, my_data->ec_ref_mixer_path);
673 audio_route_reset_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
Eric Laurentcefbbac2014-09-04 13:54:10 -0500674 }
675
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800676 if (enable) {
677 strcpy(my_data->ec_ref_mixer_path, "echo-reference");
678 if (out_device != AUDIO_DEVICE_NONE) {
679 snd_device = platform_get_output_snd_device(adev->platform, out_device);
680 platform_add_backend_name(adev->platform, my_data->ec_ref_mixer_path, snd_device);
681 }
Eric Laurentcefbbac2014-09-04 13:54:10 -0500682
Joe Onorato188b6222016-03-01 11:02:27 -0800683 ALOGV("%s: enabling %s", __func__, my_data->ec_ref_mixer_path);
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800684 audio_route_apply_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
685 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700686}
687
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700688static struct csd_data *open_csd_client(bool i2s_ext_modem)
689{
690 struct csd_data *csd = calloc(1, sizeof(struct csd_data));
691
692 csd->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
693 if (csd->csd_client == NULL) {
694 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
695 goto error;
696 } else {
697 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
698
699 csd->deinit = (deinit_t)dlsym(csd->csd_client,
700 "csd_client_deinit");
701 if (csd->deinit == NULL) {
702 ALOGE("%s: dlsym error %s for csd_client_deinit", __func__,
703 dlerror());
704 goto error;
705 }
706 csd->disable_device = (disable_device_t)dlsym(csd->csd_client,
707 "csd_client_disable_device");
708 if (csd->disable_device == NULL) {
709 ALOGE("%s: dlsym error %s for csd_client_disable_device",
710 __func__, dlerror());
711 goto error;
712 }
713 csd->enable_device_config = (enable_device_config_t)dlsym(csd->csd_client,
714 "csd_client_enable_device_config");
715 if (csd->enable_device_config == NULL) {
716 ALOGE("%s: dlsym error %s for csd_client_enable_device_config",
717 __func__, dlerror());
718 goto error;
719 }
720 csd->enable_device = (enable_device_t)dlsym(csd->csd_client,
721 "csd_client_enable_device");
722 if (csd->enable_device == NULL) {
723 ALOGE("%s: dlsym error %s for csd_client_enable_device",
724 __func__, dlerror());
725 goto error;
726 }
727 csd->start_voice = (start_voice_t)dlsym(csd->csd_client,
728 "csd_client_start_voice");
729 if (csd->start_voice == NULL) {
730 ALOGE("%s: dlsym error %s for csd_client_start_voice",
731 __func__, dlerror());
732 goto error;
733 }
734 csd->stop_voice = (stop_voice_t)dlsym(csd->csd_client,
735 "csd_client_stop_voice");
736 if (csd->stop_voice == NULL) {
737 ALOGE("%s: dlsym error %s for csd_client_stop_voice",
738 __func__, dlerror());
739 goto error;
740 }
741 csd->volume = (volume_t)dlsym(csd->csd_client,
742 "csd_client_volume");
743 if (csd->volume == NULL) {
744 ALOGE("%s: dlsym error %s for csd_client_volume",
745 __func__, dlerror());
746 goto error;
747 }
748 csd->mic_mute = (mic_mute_t)dlsym(csd->csd_client,
749 "csd_client_mic_mute");
750 if (csd->mic_mute == NULL) {
751 ALOGE("%s: dlsym error %s for csd_client_mic_mute",
752 __func__, dlerror());
753 goto error;
754 }
755 csd->slow_talk = (slow_talk_t)dlsym(csd->csd_client,
756 "csd_client_slow_talk");
757 if (csd->slow_talk == NULL) {
758 ALOGE("%s: dlsym error %s for csd_client_slow_talk",
759 __func__, dlerror());
760 goto error;
761 }
762 csd->start_playback = (start_playback_t)dlsym(csd->csd_client,
763 "csd_client_start_playback");
764 if (csd->start_playback == NULL) {
765 ALOGE("%s: dlsym error %s for csd_client_start_playback",
766 __func__, dlerror());
767 goto error;
768 }
769 csd->stop_playback = (stop_playback_t)dlsym(csd->csd_client,
770 "csd_client_stop_playback");
771 if (csd->stop_playback == NULL) {
772 ALOGE("%s: dlsym error %s for csd_client_stop_playback",
773 __func__, dlerror());
774 goto error;
775 }
776 csd->start_record = (start_record_t)dlsym(csd->csd_client,
777 "csd_client_start_record");
778 if (csd->start_record == NULL) {
779 ALOGE("%s: dlsym error %s for csd_client_start_record",
780 __func__, dlerror());
781 goto error;
782 }
783 csd->stop_record = (stop_record_t)dlsym(csd->csd_client,
784 "csd_client_stop_record");
785 if (csd->stop_record == NULL) {
786 ALOGE("%s: dlsym error %s for csd_client_stop_record",
787 __func__, dlerror());
788 goto error;
789 }
790
791 csd->get_sample_rate = (get_sample_rate_t)dlsym(csd->csd_client,
792 "csd_client_get_sample_rate");
793 if (csd->get_sample_rate == NULL) {
794 ALOGE("%s: dlsym error %s for csd_client_get_sample_rate",
795 __func__, dlerror());
796
797 goto error;
798 }
799
800 csd->init = (init_t)dlsym(csd->csd_client, "csd_client_init");
801
802 if (csd->init == NULL) {
803 ALOGE("%s: dlsym error %s for csd_client_init",
804 __func__, dlerror());
805 goto error;
806 } else {
807 csd->init(i2s_ext_modem);
808 }
809 }
810 return csd;
811
812error:
813 free(csd);
814 csd = NULL;
815 return csd;
816}
817
818void close_csd_client(struct csd_data *csd)
819{
820 if (csd != NULL) {
821 csd->deinit();
822 dlclose(csd->csd_client);
823 free(csd);
824 csd = NULL;
825 }
826}
827
828static void platform_csd_init(struct platform_data *my_data)
829{
830#ifdef PLATFORM_MSM8084
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700831 int32_t modems, (*count_modems)(void);
832 const char *name = "libdetectmodem.so";
833 const char *func = "count_modems";
834 const char *error;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700835
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700836 my_data->csd = NULL;
837
838 void *lib = dlopen(name, RTLD_NOW);
839 error = dlerror();
840 if (!lib) {
841 ALOGE("%s: could not find %s: %s", __func__, name, error);
842 return;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700843 }
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700844
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700845 count_modems = NULL;
846 *(void **)(&count_modems) = dlsym(lib, func);
847 error = dlerror();
848 if (!count_modems) {
849 ALOGE("%s: could not find symbol %s in %s: %s",
850 __func__, func, name, error);
851 goto done;
852 }
853
854 modems = count_modems();
855 if (modems < 0) {
856 ALOGE("%s: count_modems failed\n", __func__);
857 goto done;
858 }
859
Eric Laurent2bafff12016-03-17 12:17:23 -0700860 ALOGD("%s: num_modems %d\n", __func__, modems);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700861 if (modems > 0)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700862 my_data->csd = open_csd_client(false /*is_i2s_ext_modem*/);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700863
864done:
865 dlclose(lib);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700866#else
867 my_data->csd = NULL;
868#endif
869}
870
Eric Laurentc6333382015-09-14 12:43:44 -0700871static void set_platform_defaults(struct platform_data * my_data)
Haynes Mathew George98c95622014-06-20 19:14:25 -0700872{
873 int32_t dev;
874 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700875 backend_tag_table[dev] = NULL;
876 hw_interface_table[dev] = NULL;
keunhui.park2f7306a2015-07-16 16:48:06 +0900877 operator_specific_device_table[dev] = NULL;
Haynes Mathew George98c95622014-06-20 19:14:25 -0700878 }
879
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700880 // To overwrite these go to the audio_platform_info.xml file.
881 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("bt-sco");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700882 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("bt-sco");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700883 backend_tag_table[SND_DEVICE_OUT_BT_SCO] = strdup("bt-sco");
884 backend_tag_table[SND_DEVICE_OUT_HDMI] = strdup("hdmi");
885 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("speaker-and-hdmi");
886 backend_tag_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("bt-sco-wb");
887 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("bt-sco-wb");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700888 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("bt-sco-wb");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700889 backend_tag_table[SND_DEVICE_OUT_VOICE_TX] = strdup("afe-proxy");
890 backend_tag_table[SND_DEVICE_IN_VOICE_RX] = strdup("afe-proxy");
Haynes Mathew George98c95622014-06-20 19:14:25 -0700891
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700892 hw_interface_table[SND_DEVICE_OUT_HANDSET] = strdup("SLIMBUS_0_RX");
893 hw_interface_table[SND_DEVICE_OUT_SPEAKER] = strdup("SLIMBUS_0_RX");
894 hw_interface_table[SND_DEVICE_OUT_SPEAKER_REVERSE] = strdup("SLIMBUS_0_RX");
895 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE] = strdup("SLIMBUS_0_RX");
896 hw_interface_table[SND_DEVICE_OUT_HEADPHONES] = strdup("SLIMBUS_0_RX");
897 hw_interface_table[SND_DEVICE_OUT_LINE] = strdup("SLIMBUS_0_RX");
898 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700899 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700900 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700901 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700902 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET] = strdup("SLIMBUS_0_RX");
903 hw_interface_table[SND_DEVICE_OUT_VOICE_HAC_HANDSET] = strdup("SLIMBUS_0_RX");
904 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER] = strdup("SLIMBUS_0_RX");
905 hw_interface_table[SND_DEVICE_OUT_VOICE_HEADPHONES] = strdup("SLIMBUS_0_RX");
906 hw_interface_table[SND_DEVICE_OUT_VOICE_LINE] = strdup("SLIMBUS_0_RX");
907 hw_interface_table[SND_DEVICE_OUT_HDMI] = strdup("HDMI_RX");
908 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("SLIMBUS_0_RX-and-HDMI_RX");
909 hw_interface_table[SND_DEVICE_OUT_BT_SCO] = strdup("SEC_AUX_PCM_RX");
910 hw_interface_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("SEC_AUX_PCM_RX");
911 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = strdup("SLIMBUS_0_RX");
912 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = strdup("SLIMBUS_0_RX");
913 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = strdup("SLIMBUS_0_RX");
914 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = strdup("SLIMBUS_0_RX");
915 hw_interface_table[SND_DEVICE_OUT_VOICE_TX] = strdup("AFE_PCM_RX");
916 hw_interface_table[SND_DEVICE_OUT_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
917 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
Eric Laurentc6333382015-09-14 12:43:44 -0700918
919 my_data->max_mic_count = PLATFORM_DEFAULT_MIC_COUNT;
Haynes Mathew George98c95622014-06-20 19:14:25 -0700920}
921
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +0900922void get_cvd_version(char *cvd_version, struct audio_device *adev)
923{
924 struct mixer_ctl *ctl;
925 int count;
926 int ret = 0;
927
928 ctl = mixer_get_ctl_by_name(adev->mixer, CVD_VERSION_MIXER_CTL);
929 if (!ctl) {
930 ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__, CVD_VERSION_MIXER_CTL);
931 goto done;
932 }
933 mixer_ctl_update(ctl);
934
935 count = mixer_ctl_get_num_values(ctl);
936 if (count > MAX_CVD_VERSION_STRING_SIZE)
937 count = MAX_CVD_VERSION_STRING_SIZE - 1;
938
939 ret = mixer_ctl_get_array(ctl, cvd_version, count);
940 if (ret != 0) {
941 ALOGE("%s: ERROR! mixer_ctl_get_array() failed to get CVD Version", __func__);
942 goto done;
943 }
944
945done:
946 return;
947}
948
Eric Laurentb23d5282013-05-14 15:27:20 -0700949void *platform_init(struct audio_device *adev)
950{
951 char value[PROPERTY_VALUE_MAX];
vivek mehta60ea4152016-02-18 17:10:26 -0800952 struct platform_data *my_data = NULL;
953 int retry_num = 0, snd_card_num = 0, key = 0, ret = 0;
954 bool dual_mic_config = false, use_default_mixer_path = true;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700955 const char *snd_card_name;
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +0900956 char *cvd_version = NULL;
vivek mehta60ea4152016-02-18 17:10:26 -0800957 char *snd_internal_name = NULL;
958 char *tmp = NULL;
959 char mixer_xml_file[MIXER_PATH_MAX_LENGTH]= {0};
vivek mehtade4849c2016-03-03 17:23:38 -0800960 char platform_info_file[MIXER_PATH_MAX_LENGTH]= {0};
961 struct snd_card_split *snd_split_handle = NULL;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700962 my_data = calloc(1, sizeof(struct platform_data));
963
964 my_data->adev = adev;
965
keunhui.park2f7306a2015-07-16 16:48:06 +0900966 list_init(&operator_info_list);
967
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700968 set_platform_defaults(my_data);
969
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700970 while (snd_card_num < MAX_SND_CARD) {
971 adev->mixer = mixer_open(snd_card_num);
sangwoo1b9f4b32013-06-21 18:22:55 -0700972
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700973 while (!adev->mixer && retry_num < RETRY_NUMBER) {
974 usleep(RETRY_US);
975 adev->mixer = mixer_open(snd_card_num);
976 retry_num++;
977 }
978
979 if (!adev->mixer) {
980 ALOGE("%s: Unable to open the mixer card: %d", __func__,
981 snd_card_num);
982 retry_num = 0;
983 snd_card_num++;
984 continue;
985 }
986
987 snd_card_name = mixer_get_name(adev->mixer);
vivek mehtade4849c2016-03-03 17:23:38 -0800988 my_data->hw_info = hw_info_init(snd_card_name);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700989
vivek mehtade4849c2016-03-03 17:23:38 -0800990 audio_extn_set_snd_card_split(snd_card_name);
991 snd_split_handle = audio_extn_get_snd_card_split();
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700992
vivek mehtade4849c2016-03-03 17:23:38 -0800993 /* Get the codec internal name from the sound card and/or form factor
994 * name and form the mixer paths and platfor info file name dynamically.
995 * This is generic way of picking any codec and forma factor name based
996 * mixer and platform info files in future with no code change.
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700997
vivek mehtade4849c2016-03-03 17:23:38 -0800998 * current code extends and looks for any of the exteneded mixer path and
999 * platform info file present based on codec and form factor.
vivek mehta60ea4152016-02-18 17:10:26 -08001000
vivek mehtade4849c2016-03-03 17:23:38 -08001001 * order of picking appropriate file is
1002 * <i> mixer_paths_<codec_name>_<form_factor>.xml, if file not present
1003 * <ii> mixer_paths_<codec_name>.xml, if file not present
1004 * <iii> mixer_paths.xml
1005
1006 * same order is followed for audio_platform_info.xml as well
1007 */
1008
1009 // need to carryforward old file name
1010 if (!strncmp(snd_card_name, TOMTOM_8226_SND_CARD_NAME,
Eric Laurentf9583c32016-03-28 13:50:50 -07001011 min(strlen(TOMTOM_8226_SND_CARD_NAME), strlen(snd_card_name)))) {
vivek mehtade4849c2016-03-03 17:23:38 -08001012 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
vivek mehta60ea4152016-02-18 17:10:26 -08001013 MIXER_XML_BASE_STRING, TOMTOM_MIXER_FILE_SUFFIX );
vivek mehtade4849c2016-03-03 17:23:38 -08001014 } else {
Ed Tamb0b0d572016-03-21 10:45:37 -07001015
vivek mehtade4849c2016-03-03 17:23:38 -08001016 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s_%s.xml",
1017 MIXER_XML_BASE_STRING, snd_split_handle->snd_card,
1018 snd_split_handle->form_factor);
1019
1020 if (F_OK != access(mixer_xml_file, 0)) {
1021 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1022 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1023 MIXER_XML_BASE_STRING, snd_split_handle->snd_card);
1024
1025 if (F_OK != access(mixer_xml_file, 0)) {
1026 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1027 strlcpy(mixer_xml_file, MIXER_XML_DEFAULT_PATH, MIXER_PATH_MAX_LENGTH);
1028 }
1029 }
1030
1031 snprintf(platform_info_file, sizeof(platform_info_file), "%s_%s_%s.xml",
1032 PLATFORM_INFO_XML_BASE_STRING, snd_split_handle->snd_card,
1033 snd_split_handle->form_factor);
1034
1035 if (F_OK != access(platform_info_file, 0)) {
1036 memset(platform_info_file, 0, sizeof(platform_info_file));
1037 snprintf(platform_info_file, sizeof(platform_info_file), "%s_%s.xml",
1038 PLATFORM_INFO_XML_BASE_STRING, snd_split_handle->snd_card);
1039
1040 if (F_OK != access(platform_info_file, 0)) {
1041 memset(platform_info_file, 0, sizeof(platform_info_file));
1042 strlcpy(platform_info_file, PLATFORM_INFO_XML_PATH, MIXER_PATH_MAX_LENGTH);
vivek mehta60ea4152016-02-18 17:10:26 -08001043 }
1044 }
Uday Kishore Pasupuleti11dd2232015-06-24 14:18:01 -07001045 }
1046
vivek mehtade4849c2016-03-03 17:23:38 -08001047 /* Initialize platform specific ids and/or backends*/
1048 platform_info_init(platform_info_file, my_data);
1049
1050 /* validate the sound card name
1051 * my_data->snd_card_name can contain
1052 * <a> complete sound card name, i.e. <device>-<codec>-<form_factor>-snd-card
1053 * example: msm8994-tomtom-mtp-snd-card
1054 * <b> or sub string of the card name, i.e. <device>-<codec>
1055 * example: msm8994-tomtom
Eric Laurentf9583c32016-03-28 13:50:50 -07001056 * snd_card_name is truncated to 32 charaters as per mixer_get_name() implementation
1057 * so use min of my_data->snd_card_name and snd_card_name length for comparison
vivek mehtade4849c2016-03-03 17:23:38 -08001058 */
1059
1060 if (my_data->snd_card_name != NULL &&
Eric Laurentf9583c32016-03-28 13:50:50 -07001061 strncmp(snd_card_name, my_data->snd_card_name,
1062 min(strlen(snd_card_name), strlen(my_data->snd_card_name))) != 0) {
vivek mehtade4849c2016-03-03 17:23:38 -08001063 ALOGI("%s: found valid sound card %s, but not primary sound card %s",
1064 __func__, snd_card_name, my_data->snd_card_name);
1065 retry_num = 0;
1066 snd_card_num++;
1067 hw_info_deinit(my_data->hw_info);
1068 my_data->hw_info = NULL;
1069 continue;
Ed Tam70b5c142016-03-21 19:14:29 -07001070 }
vivek mehtade4849c2016-03-03 17:23:38 -08001071 ALOGI("%s: found sound card %s, primary sound card expeted is %s",
1072 __func__, snd_card_name, my_data->snd_card_name);
vivek mehta60ea4152016-02-18 17:10:26 -08001073
1074 ALOGD("%s: Loading mixer file: %s", __func__, mixer_xml_file);
1075 adev->audio_route = audio_route_init(snd_card_num, mixer_xml_file);
1076
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001077 if (!adev->audio_route) {
1078 ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001079 goto init_failed;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001080 }
1081 adev->snd_card = snd_card_num;
Eric Laurent2bafff12016-03-17 12:17:23 -07001082 ALOGD("%s: Opened sound card:%d", __func__, snd_card_num);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001083 break;
sangwoo1b9f4b32013-06-21 18:22:55 -07001084 }
1085
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001086 if (snd_card_num >= MAX_SND_CARD) {
1087 ALOGE("%s: Unable to find correct sound card, aborting.", __func__);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001088 goto init_failed;
sangwoo1b9f4b32013-06-21 18:22:55 -07001089 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001090
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09001091 //set max volume step for voice call
1092 property_get("ro.config.vc_call_vol_steps", value, TOSTRING(MAX_VOL_INDEX));
1093 my_data->max_vol_index = atoi(value);
1094
vivek mehta65ad12d2015-08-13 18:32:48 -07001095 property_get("persist.audio.dualmic.config",value,"");
1096 if (!strcmp("endfire", value)) {
1097 dual_mic_config = true;
1098 }
1099
Prashant Malanic92c5962015-08-11 15:10:18 -07001100 my_data->source_mic_type = SOURCE_DUAL_MIC;
1101
Eric Laurentb23d5282013-05-14 15:27:20 -07001102 my_data->fluence_in_spkr_mode = false;
1103 my_data->fluence_in_voice_call = false;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001104 my_data->fluence_in_voice_comm = false;
Eric Laurentb23d5282013-05-14 15:27:20 -07001105 my_data->fluence_in_voice_rec = false;
1106
vivek mehta65ad12d2015-08-13 18:32:48 -07001107 property_get("ro.qc.sdk.audio.fluencetype", value, "none");
Prashant Malanic92c5962015-08-11 15:10:18 -07001108 if (!strcmp("fluencepro", value)) {
1109 my_data->fluence_type = FLUENCE_PRO_ENABLE;
vivek mehta65ad12d2015-08-13 18:32:48 -07001110 } else if (!strcmp("fluence", value) || (dual_mic_config)) {
Prashant Malanic92c5962015-08-11 15:10:18 -07001111 my_data->fluence_type = FLUENCE_ENABLE;
1112 } else if (!strcmp("none", value)) {
1113 my_data->fluence_type = FLUENCE_DISABLE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001114 }
1115
Prashant Malanic92c5962015-08-11 15:10:18 -07001116 if (my_data->fluence_type != FLUENCE_DISABLE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001117 property_get("persist.audio.fluence.voicecall",value,"");
1118 if (!strcmp("true", value)) {
1119 my_data->fluence_in_voice_call = true;
1120 }
1121
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001122 property_get("persist.audio.fluence.voicecomm",value,"");
1123 if (!strcmp("true", value)) {
1124 my_data->fluence_in_voice_comm = true;
1125 }
1126
Eric Laurentb23d5282013-05-14 15:27:20 -07001127 property_get("persist.audio.fluence.voicerec",value,"");
1128 if (!strcmp("true", value)) {
1129 my_data->fluence_in_voice_rec = true;
1130 }
1131
1132 property_get("persist.audio.fluence.speaker",value,"");
1133 if (!strcmp("true", value)) {
1134 my_data->fluence_in_spkr_mode = true;
1135 }
1136 }
1137
Prashant Malanic92c5962015-08-11 15:10:18 -07001138 // support max to mono, example if max count is 3, usecase supports Three, dual and mono mic
1139 switch (my_data->max_mic_count) {
1140 case 4:
1141 my_data->source_mic_type |= SOURCE_QUAD_MIC;
1142 case 3:
1143 my_data->source_mic_type |= SOURCE_THREE_MIC;
1144 case 2:
1145 my_data->source_mic_type |= SOURCE_DUAL_MIC;
1146 case 1:
1147 my_data->source_mic_type |= SOURCE_MONO_MIC;
1148 break;
1149 default:
1150 ALOGE("%s: max_mic_count (%d), is not supported, setting to default",
1151 __func__, my_data->max_mic_count);
1152 my_data->source_mic_type = SOURCE_MONO_MIC|SOURCE_DUAL_MIC;
1153 break;
1154 }
1155
1156 ALOGV("%s: Fluence_Type(%d) max_mic_count(%d) mic_type(0x%x) fluence_in_voice_call(%d)"
1157 " fluence_in_voice_comm(%d) fluence_in_voice_rec(%d) fluence_in_spkr_mode(%d) ",
1158 __func__, my_data->fluence_type, my_data->max_mic_count, my_data->source_mic_type,
1159 my_data->fluence_in_voice_call, my_data->fluence_in_voice_comm,
1160 my_data->fluence_in_voice_rec, my_data->fluence_in_spkr_mode);
1161
Eric Laurentb23d5282013-05-14 15:27:20 -07001162 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
1163 if (my_data->acdb_handle == NULL) {
1164 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
1165 } else {
1166 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
1167 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
1168 "acdb_loader_deallocate_ACDB");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001169 if (!my_data->acdb_deallocate)
1170 ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s",
1171 __func__, LIB_ACDB_LOADER);
1172
Eric Laurentb23d5282013-05-14 15:27:20 -07001173 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
1174 "acdb_loader_send_audio_cal");
1175 if (!my_data->acdb_send_audio_cal)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001176 ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s",
Eric Laurentb23d5282013-05-14 15:27:20 -07001177 __func__, LIB_ACDB_LOADER);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001178
Eric Laurentb23d5282013-05-14 15:27:20 -07001179 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
1180 "acdb_loader_send_voice_cal");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001181 if (!my_data->acdb_send_voice_cal)
1182 ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s",
1183 __func__, LIB_ACDB_LOADER);
1184
1185 my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle,
1186 "acdb_loader_reload_vocvoltable");
1187 if (!my_data->acdb_reload_vocvoltable)
1188 ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s",
1189 __func__, LIB_ACDB_LOADER);
vivek mehta1a9b7c02015-06-25 11:49:38 -07001190
1191 my_data->acdb_send_gain_dep_cal = (acdb_send_gain_dep_cal_t)dlsym(my_data->acdb_handle,
1192 "acdb_loader_send_gain_dep_cal");
1193 if (!my_data->acdb_send_gain_dep_cal)
1194 ALOGV("%s: Could not find the symbol acdb_loader_send_gain_dep_cal from %s",
1195 __func__, LIB_ACDB_LOADER);
1196
vivek mehtac698f132016-02-25 18:50:35 -08001197#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996)
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001198 acdb_init_v2_cvd_t acdb_init;
1199 acdb_init = (acdb_init_v2_cvd_t)dlsym(my_data->acdb_handle,
1200 "acdb_loader_init_v2");
1201 if (acdb_init == NULL) {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001202 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__, dlerror());
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001203 goto acdb_init_fail;
1204 }
1205
1206 cvd_version = calloc(1, MAX_CVD_VERSION_STRING_SIZE);
1207 get_cvd_version(cvd_version, adev);
1208 if (!cvd_version)
1209 ALOGE("failed to allocate cvd_version");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001210 else
vivek mehtac698f132016-02-25 18:50:35 -08001211 acdb_init((char *)snd_card_name, cvd_version, 0);
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001212 free(cvd_version);
1213#elif defined (PLATFORM_MSM8084)
1214 acdb_init_v2_t acdb_init;
1215 acdb_init = (acdb_init_v2_t)dlsym(my_data->acdb_handle,
1216 "acdb_loader_init_v2");
1217 if (acdb_init == NULL) {
1218 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__, dlerror());
1219 goto acdb_init_fail;
1220 }
1221 acdb_init((char *)snd_card_name);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001222#else
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001223 acdb_init_t acdb_init;
1224 acdb_init = (acdb_init_t)dlsym(my_data->acdb_handle,
Eric Laurentb23d5282013-05-14 15:27:20 -07001225 "acdb_loader_init_ACDB");
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001226 if (acdb_init == NULL)
Eric Laurentb23d5282013-05-14 15:27:20 -07001227 ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__, dlerror());
1228 else
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001229 acdb_init();
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001230#endif
Eric Laurentb23d5282013-05-14 15:27:20 -07001231 }
1232
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001233acdb_init_fail:
1234
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001235 audio_extn_spkr_prot_init(adev);
Haynes Mathew George98c95622014-06-20 19:14:25 -07001236
Ravi Kumar Alamanda76315572015-04-23 13:13:56 -07001237 audio_extn_hwdep_cal_send(adev->snd_card, my_data->acdb_handle);
1238
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001239 /* load csd client */
1240 platform_csd_init(my_data);
1241
Eric Laurentb23d5282013-05-14 15:27:20 -07001242 return my_data;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001243
1244init_failed:
1245 if (my_data)
1246 free(my_data);
1247 return NULL;
Eric Laurentb23d5282013-05-14 15:27:20 -07001248}
1249
1250void platform_deinit(void *platform)
1251{
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001252 int32_t dev;
keunhui.park2f7306a2015-07-16 16:48:06 +09001253 struct operator_info *info_item;
1254 struct operator_specific_device *device_item;
1255 struct listnode *node;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001256
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001257 struct platform_data *my_data = (struct platform_data *)platform;
1258 close_csd_client(my_data->csd);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001259
vivek mehtade4849c2016-03-03 17:23:38 -08001260 hw_info_deinit(my_data->hw_info);
1261
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001262 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1263 if (backend_tag_table[dev])
1264 free(backend_tag_table[dev]);
1265 if (hw_interface_table[dev])
1266 free(hw_interface_table[dev]);
keunhui.park2f7306a2015-07-16 16:48:06 +09001267 if (operator_specific_device_table[dev]) {
1268 while (!list_empty(operator_specific_device_table[dev])) {
1269 node = list_head(operator_specific_device_table[dev]);
1270 list_remove(node);
1271 device_item = node_to_item(node, struct operator_specific_device, list);
1272 free(device_item->operator);
1273 free(device_item->mixer_path);
1274 free(device_item);
1275 }
1276 free(operator_specific_device_table[dev]);
1277 }
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001278 }
1279
1280 if (my_data->snd_card_name)
1281 free(my_data->snd_card_name);
1282
keunhui.park2f7306a2015-07-16 16:48:06 +09001283 while (!list_empty(&operator_info_list)) {
1284 node = list_head(&operator_info_list);
1285 list_remove(node);
1286 info_item = node_to_item(node, struct operator_info, list);
1287 free(info_item->name);
1288 free(info_item->mccmnc);
1289 free(info_item);
1290 }
1291
Eric Laurentb23d5282013-05-14 15:27:20 -07001292 free(platform);
1293}
1294
1295const char *platform_get_snd_device_name(snd_device_t snd_device)
1296{
keunhui.park2f7306a2015-07-16 16:48:06 +09001297 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1298 if (operator_specific_device_table[snd_device] != NULL) {
1299 return get_operator_specific_device_mixer_path(snd_device);
1300 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001301 return device_table[snd_device];
keunhui.park2f7306a2015-07-16 16:48:06 +09001302 } else
Ravi Kumar Alamanda64026462014-09-15 00:08:58 -07001303 return "none";
Eric Laurentb23d5282013-05-14 15:27:20 -07001304}
1305
vivek mehtade4849c2016-03-03 17:23:38 -08001306int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
1307 char *device_name)
1308{
1309 struct platform_data *my_data = (struct platform_data *)platform;
1310
1311 if (platform == NULL || device_name == NULL) {
1312 ALOGW("%s: something wrong, use legacy get_snd_device name", __func__);
1313 device_name = platform_get_snd_device_name(snd_device);
1314 } else if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1315 if (operator_specific_device_table[snd_device] != NULL) {
1316 strlcpy(device_name, get_operator_specific_device_mixer_path(snd_device),
1317 DEVICE_NAME_MAX_SIZE);
1318 } else {
1319 strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE);
1320 }
1321 hw_info_append_hw_type(my_data->hw_info, snd_device, device_name);
1322 } else {
1323 strlcpy(device_name, "none", DEVICE_NAME_MAX_SIZE);
1324 }
1325
1326 return 0;
1327}
1328
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001329void platform_add_backend_name(void *platform, char *mixer_path,
1330 snd_device_t snd_device)
Eric Laurentb23d5282013-05-14 15:27:20 -07001331{
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001332 struct platform_data *my_data = (struct platform_data *)platform;
1333
Haynes Mathew George98c95622014-06-20 19:14:25 -07001334 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1335 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1336 return;
Ravi Kumar Alamanda1de6e5a2014-06-19 21:55:39 -05001337 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001338
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001339 const char * suffix = backend_tag_table[snd_device];
Haynes Mathew George98c95622014-06-20 19:14:25 -07001340
1341 if (suffix != NULL) {
1342 strcat(mixer_path, " ");
1343 strcat(mixer_path, suffix);
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001344 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001345}
1346
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001347bool platform_check_backends_match(snd_device_t snd_device1, snd_device_t snd_device2)
1348{
1349 bool result = true;
1350
1351 ALOGV("%s: snd_device1 = %s, snd_device2 = %s", __func__,
1352 platform_get_snd_device_name(snd_device1),
1353 platform_get_snd_device_name(snd_device2));
1354
1355 if ((snd_device1 < SND_DEVICE_MIN) || (snd_device1 >= SND_DEVICE_MAX)) {
1356 ALOGE("%s: Invalid snd_device = %s", __func__,
1357 platform_get_snd_device_name(snd_device1));
1358 return false;
1359 }
1360 if ((snd_device2 < SND_DEVICE_MIN) || (snd_device2 >= SND_DEVICE_MAX)) {
1361 ALOGE("%s: Invalid snd_device = %s", __func__,
1362 platform_get_snd_device_name(snd_device2));
1363 return false;
1364 }
1365 const char * be_itf1 = hw_interface_table[snd_device1];
1366 const char * be_itf2 = hw_interface_table[snd_device2];
1367
1368 if (NULL != be_itf1 && NULL != be_itf2) {
Eric Laurente63e61d2015-09-10 12:19:33 -07001369 if ((NULL == strstr(be_itf2, be_itf1)) && (NULL == strstr(be_itf1, be_itf2)))
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001370 result = false;
1371 }
1372
1373 ALOGV("%s: be_itf1 = %s, be_itf2 = %s, match %d", __func__, be_itf1, be_itf2, result);
1374 return result;
1375}
1376
Eric Laurentb23d5282013-05-14 15:27:20 -07001377int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
1378{
1379 int device_id;
1380 if (device_type == PCM_PLAYBACK)
1381 device_id = pcm_device_table[usecase][0];
1382 else
1383 device_id = pcm_device_table[usecase][1];
1384 return device_id;
1385}
1386
Haynes Mathew George98c95622014-06-20 19:14:25 -07001387static int find_index(const struct name_to_index * table, int32_t len,
1388 const char * name)
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001389{
1390 int ret = 0;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001391 int32_t i;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001392
Haynes Mathew George98c95622014-06-20 19:14:25 -07001393 if (table == NULL) {
1394 ALOGE("%s: table is NULL", __func__);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001395 ret = -ENODEV;
1396 goto done;
1397 }
1398
Haynes Mathew George98c95622014-06-20 19:14:25 -07001399 if (name == NULL) {
1400 ALOGE("null key");
1401 ret = -ENODEV;
1402 goto done;
1403 }
1404
1405 for (i=0; i < len; i++) {
1406 if (!strcmp(table[i].name, name)) {
1407 ret = table[i].index;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001408 goto done;
1409 }
1410 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001411 ALOGE("%s: Could not find index for name = %s",
1412 __func__, name);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001413 ret = -ENODEV;
1414done:
1415 return ret;
1416}
1417
Haynes Mathew George98c95622014-06-20 19:14:25 -07001418int platform_get_snd_device_index(char *device_name)
1419{
1420 return find_index(snd_device_name_index, SND_DEVICE_MAX, device_name);
1421}
1422
1423int platform_get_usecase_index(const char *usecase_name)
1424{
1425 return find_index(usecase_name_index, AUDIO_USECASE_MAX, usecase_name);
1426}
1427
keunhui.park2f7306a2015-07-16 16:48:06 +09001428void platform_add_operator_specific_device(snd_device_t snd_device,
1429 const char *operator,
1430 const char *mixer_path,
1431 unsigned int acdb_id)
1432{
1433 struct operator_specific_device *device;
1434
1435 if (operator_specific_device_table[snd_device] == NULL) {
1436 operator_specific_device_table[snd_device] =
1437 (struct listnode *)calloc(1, sizeof(struct listnode));
1438 list_init(operator_specific_device_table[snd_device]);
1439 }
1440
1441 device = (struct operator_specific_device *)calloc(1, sizeof(struct operator_specific_device));
1442
1443 device->operator = strdup(operator);
1444 device->mixer_path = strdup(mixer_path);
1445 device->acdb_id = acdb_id;
1446
1447 list_add_tail(operator_specific_device_table[snd_device], &device->list);
1448
Eric Laurent2bafff12016-03-17 12:17:23 -07001449 ALOGD("%s: device[%s] -> operator[%s] mixer_path[%s] acdb_id[%d]", __func__,
keunhui.park2f7306a2015-07-16 16:48:06 +09001450 platform_get_snd_device_name(snd_device), operator, mixer_path, acdb_id);
1451
1452}
1453
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001454int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
1455{
1456 int ret = 0;
1457
1458 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1459 ALOGE("%s: Invalid snd_device = %d",
1460 __func__, snd_device);
1461 ret = -EINVAL;
1462 goto done;
1463 }
1464
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001465 ALOGV("%s: acdb_device_table[%s]: old = %d new = %d", __func__,
1466 platform_get_snd_device_name(snd_device), acdb_device_table[snd_device], acdb_id);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001467 acdb_device_table[snd_device] = acdb_id;
1468done:
1469 return ret;
1470}
1471
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001472int platform_get_snd_device_acdb_id(snd_device_t snd_device)
1473{
1474 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1475 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1476 return -EINVAL;
1477 }
keunhui.park2f7306a2015-07-16 16:48:06 +09001478
1479 if (operator_specific_device_table[snd_device] != NULL)
1480 return get_operator_specific_device_acdb_id(snd_device);
1481 else
1482 return acdb_device_table[snd_device];
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001483}
1484
Eric Laurentb23d5282013-05-14 15:27:20 -07001485int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
1486{
1487 struct platform_data *my_data = (struct platform_data *)platform;
1488 int acdb_dev_id, acdb_dev_type;
1489
Ravi Kumar Alamandaadf0f3b2015-06-04 02:34:02 -07001490 acdb_dev_id = acdb_device_table[audio_extn_get_spkr_prot_snd_device(snd_device)];
Eric Laurentb23d5282013-05-14 15:27:20 -07001491 if (acdb_dev_id < 0) {
1492 ALOGE("%s: Could not find acdb id for device(%d)",
1493 __func__, snd_device);
1494 return -EINVAL;
1495 }
1496 if (my_data->acdb_send_audio_cal) {
Joe Onorato188b6222016-03-01 11:02:27 -08001497 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Eric Laurentb23d5282013-05-14 15:27:20 -07001498 __func__, snd_device, acdb_dev_id);
1499 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
1500 snd_device < SND_DEVICE_OUT_END)
1501 acdb_dev_type = ACDB_DEV_TYPE_OUT;
1502 else
1503 acdb_dev_type = ACDB_DEV_TYPE_IN;
1504 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
1505 }
1506 return 0;
1507}
1508
1509int platform_switch_voice_call_device_pre(void *platform)
1510{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001511 struct platform_data *my_data = (struct platform_data *)platform;
1512 int ret = 0;
1513
1514 if (my_data->csd != NULL &&
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001515 voice_is_in_call(my_data->adev)) {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001516 /* This must be called before disabling mixer controls on APQ side */
1517 ret = my_data->csd->disable_device();
1518 if (ret < 0) {
1519 ALOGE("%s: csd_client_disable_device, failed, error %d",
1520 __func__, ret);
1521 }
1522 }
1523 return ret;
1524}
1525
1526int platform_switch_voice_call_enable_device_config(void *platform,
1527 snd_device_t out_snd_device,
1528 snd_device_t in_snd_device)
1529{
1530 struct platform_data *my_data = (struct platform_data *)platform;
1531 int acdb_rx_id, acdb_tx_id;
1532 int ret = 0;
1533
1534 if (my_data->csd == NULL)
1535 return ret;
1536
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001537 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1538 audio_extn_spkr_prot_is_enabled())
keunhui.park2f7306a2015-07-16 16:48:06 +09001539 acdb_rx_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_SPEAKER_PROTECTED);
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001540 else
keunhui.park2f7306a2015-07-16 16:48:06 +09001541 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001542
keunhui.park2f7306a2015-07-16 16:48:06 +09001543 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001544
1545 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
1546 ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
1547 if (ret < 0) {
1548 ALOGE("%s: csd_enable_device_config, failed, error %d",
1549 __func__, ret);
1550 }
1551 } else {
1552 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1553 acdb_rx_id, acdb_tx_id);
1554 }
1555
1556 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001557}
1558
1559int platform_switch_voice_call_device_post(void *platform,
1560 snd_device_t out_snd_device,
1561 snd_device_t in_snd_device)
1562{
1563 struct platform_data *my_data = (struct platform_data *)platform;
1564 int acdb_rx_id, acdb_tx_id;
1565
1566 if (my_data->acdb_send_voice_cal == NULL) {
1567 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
1568 } else {
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001569 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1570 audio_extn_spkr_prot_is_enabled())
1571 out_snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED;
1572
keunhui.park2f7306a2015-07-16 16:48:06 +09001573 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
1574 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07001575
1576 if (acdb_rx_id > 0 && acdb_tx_id > 0)
1577 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
1578 else
1579 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1580 acdb_rx_id, acdb_tx_id);
1581 }
1582
1583 return 0;
1584}
1585
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001586int platform_switch_voice_call_usecase_route_post(void *platform,
1587 snd_device_t out_snd_device,
1588 snd_device_t in_snd_device)
1589{
1590 struct platform_data *my_data = (struct platform_data *)platform;
1591 int acdb_rx_id, acdb_tx_id;
1592 int ret = 0;
1593
1594 if (my_data->csd == NULL)
1595 return ret;
1596
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001597 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1598 audio_extn_spkr_prot_is_enabled())
keunhui.park2f7306a2015-07-16 16:48:06 +09001599 acdb_rx_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED);
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001600 else
keunhui.park2f7306a2015-07-16 16:48:06 +09001601 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001602
keunhui.park2f7306a2015-07-16 16:48:06 +09001603 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001604
1605 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
1606 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
1607 my_data->adev->acdb_settings);
1608 if (ret < 0) {
1609 ALOGE("%s: csd_enable_device, failed, error %d", __func__, ret);
1610 }
1611 } else {
1612 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1613 acdb_rx_id, acdb_tx_id);
1614 }
1615
1616 return ret;
1617}
1618
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001619int platform_start_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07001620{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001621 struct platform_data *my_data = (struct platform_data *)platform;
1622 int ret = 0;
1623
1624 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001625 ret = my_data->csd->start_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001626 if (ret < 0) {
1627 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
1628 }
1629 }
1630 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001631}
1632
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001633int platform_stop_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07001634{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001635 struct platform_data *my_data = (struct platform_data *)platform;
1636 int ret = 0;
1637
1638 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001639 ret = my_data->csd->stop_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001640 if (ret < 0) {
1641 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
1642 }
1643 }
1644 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001645}
1646
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001647int platform_get_sample_rate(void *platform, uint32_t *rate)
1648{
1649 struct platform_data *my_data = (struct platform_data *)platform;
1650 int ret = 0;
1651
1652 if (my_data->csd != NULL) {
1653 ret = my_data->csd->get_sample_rate(rate);
1654 if (ret < 0) {
1655 ALOGE("%s: csd_get_sample_rate error %d\n", __func__, ret);
1656 }
1657 }
1658 return ret;
1659}
1660
vivek mehtab6506412015-08-07 16:55:17 -07001661void platform_set_speaker_gain_in_combo(struct audio_device *adev,
1662 snd_device_t snd_device,
1663 bool enable)
1664{
1665 const char* name;
1666 switch (snd_device) {
1667 case SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES:
1668 if (enable)
1669 name = "spkr-gain-in-headphone-combo";
1670 else
1671 name = "speaker-gain-default";
1672 break;
1673 case SND_DEVICE_OUT_SPEAKER_AND_LINE:
1674 if (enable)
1675 name = "spkr-gain-in-line-combo";
1676 else
1677 name = "speaker-gain-default";
1678 break;
1679 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES:
1680 if (enable)
1681 name = "spkr-safe-gain-in-headphone-combo";
1682 else
1683 name = "speaker-safe-gain-default";
1684 break;
1685 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE:
1686 if (enable)
1687 name = "spkr-safe-gain-in-line-combo";
1688 else
1689 name = "speaker-safe-gain-default";
1690 break;
1691 default:
1692 return;
1693 }
1694
1695 audio_route_apply_and_update_path(adev->audio_route, name);
1696}
1697
Eric Laurentb23d5282013-05-14 15:27:20 -07001698int platform_set_voice_volume(void *platform, int volume)
1699{
1700 struct platform_data *my_data = (struct platform_data *)platform;
1701 struct audio_device *adev = my_data->adev;
1702 struct mixer_ctl *ctl;
sangwoo53b2cf02013-07-25 19:18:44 -07001703 const char *mixer_ctl_name = "Voice Rx Gain";
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001704 int vol_index = 0, ret = 0;
1705 uint32_t set_values[ ] = {0,
1706 ALL_SESSION_VSID,
1707 DEFAULT_VOLUME_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07001708
1709 // Voice volume levels are mapped to adsp volume levels as follows.
1710 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
1711 // But this values don't changed in kernel. So, below change is need.
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09001712 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, my_data->max_vol_index);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001713 set_values[0] = vol_index;
Eric Laurentb23d5282013-05-14 15:27:20 -07001714
1715 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1716 if (!ctl) {
1717 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1718 __func__, mixer_ctl_name);
1719 return -EINVAL;
1720 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001721 ALOGV("Setting voice volume index: %d", set_values[0]);
1722 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1723
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001724 if (my_data->csd != NULL) {
1725 ret = my_data->csd->volume(ALL_SESSION_VSID, volume,
1726 DEFAULT_VOLUME_RAMP_DURATION_MS);
1727 if (ret < 0) {
1728 ALOGE("%s: csd_volume error %d", __func__, ret);
1729 }
1730 }
1731 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001732}
1733
1734int platform_set_mic_mute(void *platform, bool state)
1735{
1736 struct platform_data *my_data = (struct platform_data *)platform;
1737 struct audio_device *adev = my_data->adev;
1738 struct mixer_ctl *ctl;
1739 const char *mixer_ctl_name = "Voice Tx Mute";
sangwoo53b2cf02013-07-25 19:18:44 -07001740 int ret = 0;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001741 uint32_t set_values[ ] = {0,
1742 ALL_SESSION_VSID,
1743 DEFAULT_MUTE_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07001744
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09001745 if (adev->mode != AUDIO_MODE_IN_CALL &&
1746 adev->mode != AUDIO_MODE_IN_COMMUNICATION)
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001747 return 0;
1748
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09001749 if (adev->enable_hfp)
1750 mixer_ctl_name = "HFP Tx Mute";
1751
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001752 set_values[0] = state;
1753 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1754 if (!ctl) {
1755 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1756 __func__, mixer_ctl_name);
1757 return -EINVAL;
1758 }
1759 ALOGV("Setting voice mute state: %d", state);
1760 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1761
1762 if (my_data->csd != NULL) {
1763 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state,
1764 DEFAULT_MUTE_RAMP_DURATION_MS);
sangwoo53b2cf02013-07-25 19:18:44 -07001765 if (ret < 0) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001766 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
sangwoo53b2cf02013-07-25 19:18:44 -07001767 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001768 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001769 return ret;
1770}
Eric Laurentb23d5282013-05-14 15:27:20 -07001771
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001772int platform_set_device_mute(void *platform, bool state, char *dir)
1773{
1774 struct platform_data *my_data = (struct platform_data *)platform;
1775 struct audio_device *adev = my_data->adev;
1776 struct mixer_ctl *ctl;
1777 char *mixer_ctl_name = NULL;
1778 int ret = 0;
1779 uint32_t set_values[ ] = {0,
1780 ALL_SESSION_VSID,
1781 0};
1782 if(dir == NULL) {
1783 ALOGE("%s: Invalid direction:%s", __func__, dir);
1784 return -EINVAL;
1785 }
1786
1787 if (!strncmp("rx", dir, sizeof("rx"))) {
1788 mixer_ctl_name = "Voice Rx Device Mute";
1789 } else if (!strncmp("tx", dir, sizeof("tx"))) {
1790 mixer_ctl_name = "Voice Tx Device Mute";
1791 } else {
1792 return -EINVAL;
1793 }
1794
1795 set_values[0] = state;
1796 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1797 if (!ctl) {
1798 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1799 __func__, mixer_ctl_name);
1800 return -EINVAL;
1801 }
1802
1803 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
1804 __func__,state, mixer_ctl_name);
1805 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1806
1807 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001808}
1809
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001810bool platform_can_split_snd_device(snd_device_t snd_device,
1811 int *num_devices,
1812 snd_device_t *new_snd_devices)
1813{
1814 bool status = false;
1815
1816 if (NULL == num_devices || NULL == new_snd_devices) {
1817 ALOGE("%s: NULL pointer ..", __func__);
1818 return false;
1819 }
1820
1821 /*
1822 * If wired headset/headphones/line devices share the same backend
1823 * with speaker/earpiece this routine returns false.
1824 */
1825 if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES &&
1826 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_HEADPHONES)) {
1827 *num_devices = 2;
1828 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
1829 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
1830 status = true;
1831 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_LINE &&
1832 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_LINE)) {
1833 *num_devices = 2;
1834 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
1835 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
1836 status = true;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001837 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES &&
1838 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_HEADPHONES)) {
1839 *num_devices = 2;
1840 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
1841 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
1842 status = true;
1843 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE &&
1844 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_LINE)) {
1845 *num_devices = 2;
1846 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
1847 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
1848 status = true;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001849 }
1850 return status;
1851}
1852
Eric Laurentb23d5282013-05-14 15:27:20 -07001853snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
1854{
1855 struct platform_data *my_data = (struct platform_data *)platform;
1856 struct audio_device *adev = my_data->adev;
1857 audio_mode_t mode = adev->mode;
1858 snd_device_t snd_device = SND_DEVICE_NONE;
1859
1860 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
1861 if (devices == AUDIO_DEVICE_NONE ||
1862 devices & AUDIO_DEVICE_BIT_IN) {
1863 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
1864 goto exit;
1865 }
1866
Eric Laurent1b491552015-09-15 17:52:41 -07001867 if (popcount(devices) == 2) {
1868 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
1869 AUDIO_DEVICE_OUT_SPEAKER) ||
1870 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
1871 AUDIO_DEVICE_OUT_SPEAKER)) {
1872 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
1873 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
1874 AUDIO_DEVICE_OUT_SPEAKER)) {
1875 snd_device = SND_DEVICE_OUT_SPEAKER_AND_LINE;
1876 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
1877 AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
1878 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
1879 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
1880 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES;
1881 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
1882 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
1883 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE;
1884 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
1885 AUDIO_DEVICE_OUT_SPEAKER)) {
1886 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
1887 } else {
1888 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
1889 goto exit;
1890 }
1891 if (snd_device != SND_DEVICE_NONE) {
1892 goto exit;
1893 }
1894 }
1895
1896 if (popcount(devices) != 1) {
1897 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
1898 goto exit;
1899 }
1900
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001901 if (voice_is_in_call(adev) || adev->enable_voicerx) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001902 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05001903 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
1904 devices & AUDIO_DEVICE_OUT_LINE) {
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001905 if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05001906 (adev->voice.tty_mode == TTY_MODE_FULL))
Eric Laurentb23d5282013-05-14 15:27:20 -07001907 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_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_VCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07001910 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001911 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05001912 (adev->voice.tty_mode == TTY_MODE_HCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07001913 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05001914 else {
1915 if (devices & AUDIO_DEVICE_OUT_LINE)
1916 snd_device = SND_DEVICE_OUT_VOICE_LINE;
1917 else
1918 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
1919 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001920 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07001921 if (adev->bt_wb_speech_enabled) {
1922 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
1923 } else {
1924 snd_device = SND_DEVICE_OUT_BT_SCO;
1925 }
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07001926 } else if (devices & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07001927 if (!adev->enable_hfp) {
1928 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
1929 } else {
1930 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_HFP;
1931 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001932 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05001933 if(adev->voice.hac)
1934 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
1935 else if (is_operator_tmus())
Eric Laurentb23d5282013-05-14 15:27:20 -07001936 snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS;
1937 else
Eric Laurentb4d368e2014-06-25 10:21:54 -05001938 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07001939 } else if (devices & AUDIO_DEVICE_OUT_TELEPHONY_TX)
1940 snd_device = SND_DEVICE_OUT_VOICE_TX;
1941
Eric Laurentb23d5282013-05-14 15:27:20 -07001942 if (snd_device != SND_DEVICE_NONE) {
1943 goto exit;
1944 }
1945 }
1946
Eric Laurentb23d5282013-05-14 15:27:20 -07001947 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1948 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
1949 snd_device = SND_DEVICE_OUT_HEADPHONES;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05001950 } else if (devices & AUDIO_DEVICE_OUT_LINE) {
1951 snd_device = SND_DEVICE_OUT_LINE;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07001952 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) {
1953 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001954 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07001955 if (my_data->speaker_lr_swap)
Eric Laurentb23d5282013-05-14 15:27:20 -07001956 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
1957 else
1958 snd_device = SND_DEVICE_OUT_SPEAKER;
1959 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07001960 if (adev->bt_wb_speech_enabled) {
1961 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
1962 } else {
1963 snd_device = SND_DEVICE_OUT_BT_SCO;
1964 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001965 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
1966 snd_device = SND_DEVICE_OUT_HDMI ;
1967 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05001968 /*HAC support for voice-ish audio (eg visual voicemail)*/
1969 if(adev->voice.hac)
1970 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
1971 else
1972 snd_device = SND_DEVICE_OUT_HANDSET;
Eric Laurentb23d5282013-05-14 15:27:20 -07001973 } else {
1974 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
1975 }
1976exit:
1977 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
1978 return snd_device;
1979}
1980
1981snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
1982{
1983 struct platform_data *my_data = (struct platform_data *)platform;
1984 struct audio_device *adev = my_data->adev;
1985 audio_source_t source = (adev->active_input == NULL) ?
1986 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
1987
1988 audio_mode_t mode = adev->mode;
1989 audio_devices_t in_device = ((adev->active_input == NULL) ?
1990 AUDIO_DEVICE_NONE : adev->active_input->device)
1991 & ~AUDIO_DEVICE_BIT_IN;
1992 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
1993 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
1994 snd_device_t snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001995 int channel_count = popcount(channel_mask);
Eric Laurentb23d5282013-05-14 15:27:20 -07001996
Prashant Malanic92c5962015-08-11 15:10:18 -07001997 ALOGV("%s: enter: out_device(%#x) in_device(%#x) channel_count (%d) channel_mask (0x%x)",
1998 __func__, out_device, in_device, channel_count, channel_mask);
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001999 if ((out_device != AUDIO_DEVICE_NONE) && voice_is_in_call(adev)) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002000 if (adev->voice.tty_mode != TTY_MODE_OFF) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002001 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002002 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2003 out_device & AUDIO_DEVICE_OUT_LINE) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002004 switch (adev->voice.tty_mode) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002005 case TTY_MODE_FULL:
2006 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
2007 break;
2008 case TTY_MODE_VCO:
2009 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
2010 break;
2011 case TTY_MODE_HCO:
2012 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
2013 break;
2014 default:
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002015 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
Eric Laurentb23d5282013-05-14 15:27:20 -07002016 }
2017 goto exit;
2018 }
2019 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002020 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002021 if (my_data->fluence_in_voice_call == false) {
2022 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2023 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002024 if (is_operator_tmus())
2025 snd_device = SND_DEVICE_IN_VOICE_DMIC_TMUS;
Eric Laurentb23d5282013-05-14 15:27:20 -07002026 else
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002027 snd_device = SND_DEVICE_IN_VOICE_DMIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002028 }
2029 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2030 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
2031 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002032 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002033 if (adev->bluetooth_nrec)
2034 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2035 else
2036 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002037 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002038 if (adev->bluetooth_nrec)
2039 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2040 else
2041 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002042 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002043 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Prashant Malanic92c5962015-08-11 15:10:18 -07002044 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
2045 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2046 out_device & AUDIO_DEVICE_OUT_LINE) {
2047 if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
2048 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
2049 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
2050 } else {
2051 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2052 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002053 }
vivek mehtafe121d52015-08-10 23:39:23 -07002054
2055 //select default
2056 if (snd_device == SND_DEVICE_NONE) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002057 if (!adev->enable_hfp) {
2058 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2059 } else {
2060 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP;
2061 platform_set_echo_reference(adev, true, out_device);
2062 }
vivek mehtafe121d52015-08-10 23:39:23 -07002063 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002064 } else if (out_device & AUDIO_DEVICE_OUT_TELEPHONY_TX) {
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002065 snd_device = SND_DEVICE_IN_VOICE_RX;
Prashant Malanic92c5962015-08-11 15:10:18 -07002066 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002067 } else if (source == AUDIO_SOURCE_CAMCORDER) {
2068 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
2069 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2070 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
2071 }
2072 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
2073 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002074 if (my_data->fluence_in_voice_rec && channel_count == 1) {
2075 if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2076 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002077 if (adev->active_input->enable_aec)
2078 snd_device = SND_DEVICE_IN_HANDSET_QMIC_AEC;
2079 else
2080 snd_device = SND_DEVICE_IN_HANDSET_QMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002081 } else if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2082 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002083 if (adev->active_input->enable_aec)
2084 snd_device = SND_DEVICE_IN_HANDSET_TMIC_AEC;
2085 else
2086 snd_device = SND_DEVICE_IN_HANDSET_TMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002087 } else if (((my_data->fluence_type == FLUENCE_PRO_ENABLE) ||
2088 (my_data->fluence_type == FLUENCE_ENABLE)) &&
2089 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002090 if (adev->active_input->enable_aec)
2091 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
2092 else
2093 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
Prashant Malanic92c5962015-08-11 15:10:18 -07002094 }
2095 platform_set_echo_reference(adev, true, out_device);
2096 } else if ((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) &&
2097 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2098 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
2099 } else if (((int)channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
2100 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
2101 snd_device = SND_DEVICE_IN_THREE_MIC;
2102 } else if (((int)channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
2103 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2104 snd_device = SND_DEVICE_IN_QUAD_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002105 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002106 if (snd_device == SND_DEVICE_NONE) {
vivek mehtaf3440682016-05-11 14:24:37 -07002107 if (adev->active_input->enable_aec) {
2108 if (adev->active_input->enable_ns) {
2109 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS;
2110 } else {
2111 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC;
2112 }
vivek mehta733c1df2016-04-04 15:09:24 -07002113 platform_set_echo_reference(adev, true, out_device);
vivek mehtaf3440682016-05-11 14:24:37 -07002114 } else if (adev->active_input->enable_ns) {
2115 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
2116 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002117 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
vivek mehtaf3440682016-05-11 14:24:37 -07002118 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002119 }
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -07002120 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2121 snd_device = SND_DEVICE_IN_VOICE_REC_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002122 }
rago90fb9612015-12-02 11:37:53 -08002123 } else if (source == AUDIO_SOURCE_UNPROCESSED) {
2124 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
vivek mehta4ed66e62016-04-15 23:33:34 -07002125 if (((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) ||
2126 (channel_mask == AUDIO_CHANNEL_IN_STEREO)) &&
2127 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2128 snd_device = SND_DEVICE_IN_UNPROCESSED_STEREO_MIC;
2129 } else if (((int)channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
2130 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
2131 snd_device = SND_DEVICE_IN_UNPROCESSED_THREE_MIC;
2132 } else if (((int)channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
2133 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2134 snd_device = SND_DEVICE_IN_UNPROCESSED_QUAD_MIC;
2135 } else {
2136 snd_device = SND_DEVICE_IN_UNPROCESSED_MIC;
2137 }
rago90fb9612015-12-02 11:37:53 -08002138 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2139 snd_device = SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC;
2140 }
Eric Laurent50a38ed2015-10-14 18:48:06 -07002141 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION ||
rago90fb9612015-12-02 11:37:53 -08002142 mode == AUDIO_MODE_IN_COMMUNICATION) {
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002143 if (out_device & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE))
Eric Laurentb23d5282013-05-14 15:27:20 -07002144 in_device = AUDIO_DEVICE_IN_BACK_MIC;
2145 if (adev->active_input) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002146 if (adev->active_input->enable_aec &&
2147 adev->active_input->enable_ns) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002148 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002149 if (my_data->fluence_in_spkr_mode &&
2150 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002151 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002152 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002153 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002154 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002155 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002156 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002157 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002158 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002159 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002160 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002161 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002162 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002163 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2164 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002165 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002166 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002167 } else if (adev->active_input->enable_aec) {
2168 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2169 if (my_data->fluence_in_spkr_mode &&
2170 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002171 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002172 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002173 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002174 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002175 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002176 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2177 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002178 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002179 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002180 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002181 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002182 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002183 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2184 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
2185 }
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08002186 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002187 } else if (adev->active_input->enable_ns) {
2188 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2189 if (my_data->fluence_in_spkr_mode &&
2190 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002191 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002192 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002193 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002194 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002195 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002196 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2197 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002198 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002199 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002200 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002201 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002202 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002203 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002204 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002205 }
2206 } else if (source == AUDIO_SOURCE_DEFAULT) {
2207 goto exit;
2208 }
2209
2210
2211 if (snd_device != SND_DEVICE_NONE) {
2212 goto exit;
2213 }
2214
2215 if (in_device != AUDIO_DEVICE_NONE &&
2216 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
2217 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
2218 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002219 if ((my_data->source_mic_type & SOURCE_QUAD_MIC) &&
2220 (int)channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) {
2221 snd_device = SND_DEVICE_IN_QUAD_MIC;
2222 } else if ((my_data->source_mic_type & SOURCE_THREE_MIC) &&
2223 (int)channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) {
2224 snd_device = SND_DEVICE_IN_THREE_MIC;
2225 } else if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2226 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002227 snd_device = SND_DEVICE_IN_HANDSET_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002228 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2229 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002230 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002231 } else {
2232 ALOGE("%s: something wrong (1): source type (%d) channel_count (%d) .."
2233 " channel mask (0x%x) no combination found .. setting to mono", __func__,
2234 my_data->source_mic_type, channel_count, channel_mask);
2235 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2236 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002237 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002238 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2239 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002240 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002241 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2242 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002243 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002244 } else {
2245 ALOGE("%s: something wrong (2): source type (%d) channel_count (%d) .."
2246 " no combination found .. setting to mono", __func__,
2247 my_data->source_mic_type, channel_count);
2248 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
2249 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002250 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2251 snd_device = SND_DEVICE_IN_HEADSET_MIC;
2252 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002253 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002254 if (adev->bluetooth_nrec)
2255 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2256 else
2257 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002258 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002259 if (adev->bluetooth_nrec)
2260 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2261 else
2262 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002263 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002264 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
2265 snd_device = SND_DEVICE_IN_HDMI_MIC;
2266 } else {
2267 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
2268 ALOGW("%s: Using default handset-mic", __func__);
2269 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2270 }
2271 } else {
2272 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
2273 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2274 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2275 snd_device = SND_DEVICE_IN_HEADSET_MIC;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002276 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002277 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002278 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002279 out_device & AUDIO_DEVICE_OUT_LINE) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002280 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2281 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002282 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002283 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2284 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002285 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002286 } else {
2287 ALOGE("%s: something wrong (3): source type (%d) channel_count (%d) .."
2288 " no combination found .. setting to mono", __func__,
2289 my_data->source_mic_type, channel_count);
2290 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
2291 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002292 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002293 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002294 if (adev->bluetooth_nrec)
2295 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2296 else
2297 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002298 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002299 if (adev->bluetooth_nrec)
2300 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2301 else
2302 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002303 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002304 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2305 snd_device = SND_DEVICE_IN_HDMI_MIC;
2306 } else {
2307 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
2308 ALOGW("%s: Using default handset-mic", __func__);
2309 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2310 }
2311 }
2312exit:
2313 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
2314 return snd_device;
2315}
2316
2317int platform_set_hdmi_channels(void *platform, int channel_count)
2318{
2319 struct platform_data *my_data = (struct platform_data *)platform;
2320 struct audio_device *adev = my_data->adev;
2321 struct mixer_ctl *ctl;
2322 const char *channel_cnt_str = NULL;
2323 const char *mixer_ctl_name = "HDMI_RX Channels";
2324 switch (channel_count) {
2325 case 8:
2326 channel_cnt_str = "Eight"; break;
2327 case 7:
2328 channel_cnt_str = "Seven"; break;
2329 case 6:
2330 channel_cnt_str = "Six"; break;
2331 case 5:
2332 channel_cnt_str = "Five"; break;
2333 case 4:
2334 channel_cnt_str = "Four"; break;
2335 case 3:
2336 channel_cnt_str = "Three"; break;
2337 default:
2338 channel_cnt_str = "Two"; break;
2339 }
2340 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2341 if (!ctl) {
2342 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2343 __func__, mixer_ctl_name);
2344 return -EINVAL;
2345 }
2346 ALOGV("HDMI channel count: %s", channel_cnt_str);
2347 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
2348 return 0;
2349}
2350
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002351int platform_edid_get_max_channels(void *platform)
Eric Laurentb23d5282013-05-14 15:27:20 -07002352{
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002353 struct platform_data *my_data = (struct platform_data *)platform;
2354 struct audio_device *adev = my_data->adev;
Eric Laurentb23d5282013-05-14 15:27:20 -07002355 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
2356 char *sad = block;
2357 int num_audio_blocks;
2358 int channel_count;
2359 int max_channels = 0;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002360 int i, ret, count;
Eric Laurentb23d5282013-05-14 15:27:20 -07002361
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002362 struct mixer_ctl *ctl;
2363
2364 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
2365 if (!ctl) {
2366 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2367 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
Eric Laurentb23d5282013-05-14 15:27:20 -07002368 return 0;
2369 }
2370
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002371 mixer_ctl_update(ctl);
2372
2373 count = mixer_ctl_get_num_values(ctl);
Eric Laurentb23d5282013-05-14 15:27:20 -07002374
2375 /* Read SAD blocks, clamping the maximum size for safety */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002376 if (count > (int)sizeof(block))
2377 count = (int)sizeof(block);
Eric Laurentb23d5282013-05-14 15:27:20 -07002378
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002379 ret = mixer_ctl_get_array(ctl, block, count);
2380 if (ret != 0) {
2381 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
2382 return 0;
2383 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002384
2385 /* Calculate the number of SAD blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002386 num_audio_blocks = count / SAD_BLOCK_SIZE;
Eric Laurentb23d5282013-05-14 15:27:20 -07002387
2388 for (i = 0; i < num_audio_blocks; i++) {
2389 /* Only consider LPCM blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002390 if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
2391 sad += 3;
Eric Laurentb23d5282013-05-14 15:27:20 -07002392 continue;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002393 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002394
2395 channel_count = (sad[0] & 0x7) + 1;
2396 if (channel_count > max_channels)
2397 max_channels = channel_count;
2398
2399 /* Advance to next block */
2400 sad += 3;
2401 }
2402
2403 return max_channels;
2404}
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07002405
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002406int platform_set_incall_recording_session_id(void *platform,
2407 uint32_t session_id, int rec_mode)
2408{
2409 int ret = 0;
2410 struct platform_data *my_data = (struct platform_data *)platform;
2411 struct audio_device *adev = my_data->adev;
2412 struct mixer_ctl *ctl;
2413 const char *mixer_ctl_name = "Voc VSID";
2414 int num_ctl_values;
2415 int i;
2416
2417 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2418 if (!ctl) {
2419 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2420 __func__, mixer_ctl_name);
2421 ret = -EINVAL;
2422 } else {
2423 num_ctl_values = mixer_ctl_get_num_values(ctl);
2424 for (i = 0; i < num_ctl_values; i++) {
2425 if (mixer_ctl_set_value(ctl, i, session_id)) {
2426 ALOGV("Error: invalid session_id: %x", session_id);
2427 ret = -EINVAL;
2428 break;
2429 }
2430 }
2431 }
2432
2433 if (my_data->csd != NULL) {
2434 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
2435 if (ret < 0) {
2436 ALOGE("%s: csd_client_start_record failed, error %d",
2437 __func__, ret);
2438 }
2439 }
2440
2441 return ret;
2442}
2443
2444int platform_stop_incall_recording_usecase(void *platform)
2445{
2446 int ret = 0;
2447 struct platform_data *my_data = (struct platform_data *)platform;
2448
2449 if (my_data->csd != NULL) {
2450 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
2451 if (ret < 0) {
2452 ALOGE("%s: csd_client_stop_record failed, error %d",
2453 __func__, ret);
2454 }
2455 }
2456
2457 return ret;
2458}
2459
2460int platform_start_incall_music_usecase(void *platform)
2461{
2462 int ret = 0;
2463 struct platform_data *my_data = (struct platform_data *)platform;
2464
2465 if (my_data->csd != NULL) {
2466 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
2467 if (ret < 0) {
2468 ALOGE("%s: csd_client_start_playback failed, error %d",
2469 __func__, ret);
2470 }
2471 }
2472
2473 return ret;
2474}
2475
2476int platform_stop_incall_music_usecase(void *platform)
2477{
2478 int ret = 0;
2479 struct platform_data *my_data = (struct platform_data *)platform;
2480
2481 if (my_data->csd != NULL) {
2482 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
2483 if (ret < 0) {
2484 ALOGE("%s: csd_client_stop_playback failed, error %d",
2485 __func__, ret);
2486 }
2487 }
2488
2489 return ret;
2490}
2491
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002492int platform_set_parameters(void *platform, struct str_parms *parms)
2493{
2494 struct platform_data *my_data = (struct platform_data *)platform;
keunhui.park2f7306a2015-07-16 16:48:06 +09002495 char value[128];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002496 char *kv_pairs = str_parms_to_str(parms);
2497 int ret = 0, err;
2498
2499 if (kv_pairs == NULL) {
2500 ret = -EINVAL;
2501 ALOGE("%s: key-value pair is NULL",__func__);
2502 goto done;
2503 }
2504
2505 ALOGV("%s: enter: %s", __func__, kv_pairs);
2506
2507 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME,
2508 value, sizeof(value));
2509 if (err >= 0) {
2510 str_parms_del(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME);
2511 my_data->snd_card_name = strdup(value);
2512 ALOGV("%s: sound card name %s", __func__, my_data->snd_card_name);
2513 }
2514
keunhui.park2f7306a2015-07-16 16:48:06 +09002515 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO,
2516 value, sizeof(value));
2517 if (err >= 0) {
2518 struct operator_info *info;
2519 char *str = value;
2520 char *name;
2521
2522 str_parms_del(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO);
2523 info = (struct operator_info *)calloc(1, sizeof(struct operator_info));
2524 name = strtok(str, ";");
2525 info->name = strdup(name);
2526 info->mccmnc = strdup(str + strlen(name) + 1);
2527
2528 list_add_tail(&operator_info_list, &info->list);
Joe Onorato188b6222016-03-01 11:02:27 -08002529 ALOGV("%s: add operator[%s] mccmnc[%s]", __func__, info->name, info->mccmnc);
keunhui.park2f7306a2015-07-16 16:48:06 +09002530 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002531
2532 memset(value, 0, sizeof(value));
Eric Laurentc6333382015-09-14 12:43:44 -07002533 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT,
Prashant Malanic92c5962015-08-11 15:10:18 -07002534 value, sizeof(value));
2535 if (err >= 0) {
Eric Laurentc6333382015-09-14 12:43:44 -07002536 str_parms_del(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT);
Prashant Malanic92c5962015-08-11 15:10:18 -07002537 my_data->max_mic_count = atoi(value);
2538 ALOGV("%s: max_mic_count %s/%d", __func__, value, my_data->max_mic_count);
Prashant Malanic92c5962015-08-11 15:10:18 -07002539 }
2540
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002541done:
2542 ALOGV("%s: exit with code(%d)", __func__, ret);
2543 if (kv_pairs != NULL)
2544 free(kv_pairs);
2545
2546 return ret;
2547}
2548
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07002549/* Delay in Us */
2550int64_t platform_render_latency(audio_usecase_t usecase)
2551{
2552 switch (usecase) {
2553 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
2554 return DEEP_BUFFER_PLATFORM_DELAY;
2555 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
2556 return LOW_LATENCY_PLATFORM_DELAY;
Haynes Mathew George03c40102016-01-29 17:57:48 -08002557 case USECASE_AUDIO_PLAYBACK_ULL:
2558 return ULL_PLATFORM_DELAY;
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07002559 default:
2560 return 0;
2561 }
2562}
Haynes Mathew George98c95622014-06-20 19:14:25 -07002563
vivek mehta4ed66e62016-04-15 23:33:34 -07002564bool platform_check_and_set_capture_backend_cfg(struct audio_device* adev,
2565 struct audio_usecase *usecase, snd_device_t snd_device)
2566{
2567 enum pcm_format in_pcm_format = PCM_FORMAT_S16_LE;
2568
2569 if (adev && adev->active_input)
2570 in_pcm_format = adev->active_input->config.format;
2571
2572 // allow 24 bit recording only if voice call is not active
2573 if (!voice_is_in_call(adev) &&
2574 adev->mode != AUDIO_MODE_IN_COMMUNICATION &&
2575 in_pcm_format == PCM_FORMAT_S24_LE) {
2576 audio_route_apply_and_update_path(adev->audio_route, "set-capture-format-24le");
2577 } else {
2578 audio_route_apply_and_update_path(adev->audio_route, "set-capture-format-default");
2579 }
2580
2581 return true;
2582}
2583
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002584int platform_set_snd_device_backend(snd_device_t device, const char *backend_tag,
2585 const char * hw_interface)
Haynes Mathew George98c95622014-06-20 19:14:25 -07002586{
2587 int ret = 0;
2588
2589 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
2590 ALOGE("%s: Invalid snd_device = %d",
2591 __func__, device);
2592 ret = -EINVAL;
2593 goto done;
2594 }
2595
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002596 ALOGV("%s: backend_tag_table[%s]: old = %s new = %s", __func__,
2597 platform_get_snd_device_name(device),
2598 backend_tag_table[device] != NULL ? backend_tag_table[device]: "null", backend_tag);
2599 if (backend_tag_table[device]) {
2600 free(backend_tag_table[device]);
Haynes Mathew George98c95622014-06-20 19:14:25 -07002601 }
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002602 backend_tag_table[device] = strdup(backend_tag);
2603
2604 if (hw_interface != NULL) {
2605 if (hw_interface_table[device])
2606 free(hw_interface_table[device]);
2607 ALOGV("%s: hw_interface_table[%d] = %s", __func__, device, hw_interface);
2608 hw_interface_table[device] = strdup(hw_interface);
2609 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07002610done:
2611 return ret;
2612}
2613
2614int platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t pcm_id)
2615{
2616 int ret = 0;
2617 if ((usecase <= USECASE_INVALID) || (usecase >= AUDIO_USECASE_MAX)) {
2618 ALOGE("%s: invalid usecase case idx %d", __func__, usecase);
2619 ret = -EINVAL;
2620 goto done;
2621 }
2622
2623 if ((type != 0) && (type != 1)) {
2624 ALOGE("%s: invalid usecase type", __func__);
2625 ret = -EINVAL;
2626 }
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002627 ALOGV("%s: pcm_device_table[%d][%d] = %d", __func__, usecase, type, pcm_id);
Haynes Mathew George98c95622014-06-20 19:14:25 -07002628 pcm_device_table[usecase][type] = pcm_id;
2629done:
2630 return ret;
2631}
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002632
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07002633#define DEFAULT_NOMINAL_SPEAKER_GAIN 20
2634int ramp_speaker_gain(struct audio_device *adev, bool ramp_up, int target_ramp_up_gain) {
2635 // backup_gain: gain to try to set in case of an error during ramp
2636 int start_gain, end_gain, step, backup_gain, i;
2637 bool error = false;
2638 const struct mixer_ctl *ctl;
2639 const char *mixer_ctl_name_gain_left = "Left Speaker Gain";
2640 const char *mixer_ctl_name_gain_right = "Right Speaker Gain";
2641 struct mixer_ctl *ctl_left = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_left);
2642 struct mixer_ctl *ctl_right = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_right);
2643 if (!ctl_left || !ctl_right) {
2644 ALOGE("%s: Could not get ctl for mixer cmd - %s or %s, not applying speaker gain ramp",
2645 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
2646 return -EINVAL;
2647 } else if ((mixer_ctl_get_num_values(ctl_left) != 1)
2648 || (mixer_ctl_get_num_values(ctl_right) != 1)) {
2649 ALOGE("%s: Unexpected num values for mixer cmd - %s or %s, not applying speaker gain ramp",
2650 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
2651 return -EINVAL;
2652 }
2653 if (ramp_up) {
2654 start_gain = 0;
2655 end_gain = target_ramp_up_gain > 0 ? target_ramp_up_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
2656 step = +1;
2657 backup_gain = end_gain;
2658 } else {
2659 // using same gain on left and right
2660 const int left_gain = mixer_ctl_get_value(ctl_left, 0);
2661 start_gain = left_gain > 0 ? left_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
2662 end_gain = 0;
2663 step = -1;
2664 backup_gain = start_gain;
2665 }
2666 for (i = start_gain ; i != (end_gain + step) ; i += step) {
2667 //ALOGV("setting speaker gain to %d", i);
2668 if (mixer_ctl_set_value(ctl_left, 0, i)) {
2669 ALOGE("%s: error setting %s to %d during gain ramp",
2670 __func__, mixer_ctl_name_gain_left, i);
2671 error = true;
2672 break;
2673 }
2674 if (mixer_ctl_set_value(ctl_right, 0, i)) {
2675 ALOGE("%s: error setting %s to %d during gain ramp",
2676 __func__, mixer_ctl_name_gain_right, i);
2677 error = true;
2678 break;
2679 }
2680 usleep(1000);
2681 }
2682 if (error) {
2683 // an error occured during the ramp, let's still try to go back to a safe volume
2684 if (mixer_ctl_set_value(ctl_left, 0, backup_gain)) {
2685 ALOGE("%s: error restoring left gain to %d", __func__, backup_gain);
2686 }
2687 if (mixer_ctl_set_value(ctl_right, 0, backup_gain)) {
2688 ALOGE("%s: error restoring right gain to %d", __func__, backup_gain);
2689 }
2690 }
2691 return start_gain;
2692}
2693
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002694int platform_swap_lr_channels(struct audio_device *adev, bool swap_channels)
2695{
2696 // only update if there is active pcm playback on speaker
2697 struct audio_usecase *usecase;
2698 struct listnode *node;
2699 struct platform_data *my_data = (struct platform_data *)adev->platform;
2700
2701 if (my_data->speaker_lr_swap != swap_channels) {
2702 my_data->speaker_lr_swap = swap_channels;
2703
2704 list_for_each(node, &adev->usecase_list) {
2705 usecase = node_to_item(node, struct audio_usecase, list);
2706 if (usecase->type == PCM_PLAYBACK &&
Ravi Kumar Alamanda425e1542015-09-22 09:11:18 -07002707 usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) {
2708 /*
2709 * If acdb tuning is different for SPEAKER_REVERSE, it is must
2710 * to perform device switch to disable the current backend to
2711 * enable it with new acdb data.
2712 */
2713 if (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
2714 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]) {
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07002715 const int initial_skpr_gain = ramp_speaker_gain(adev, false /*ramp_up*/, -1);
Ravi Kumar Alamanda425e1542015-09-22 09:11:18 -07002716 select_devices(adev, usecase->id);
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07002717 if (initial_skpr_gain != -EINVAL) {
2718 ramp_speaker_gain(adev, true /*ramp_up*/, initial_skpr_gain);
2719 }
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002720 } else {
Ravi Kumar Alamanda425e1542015-09-22 09:11:18 -07002721 const char *mixer_path;
2722 if (swap_channels) {
2723 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER_REVERSE);
2724 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
2725 } else {
2726 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER);
2727 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
2728 }
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002729 }
2730 break;
2731 }
2732 }
2733 }
2734 return 0;
2735}