blob: b14e83168c08c7ebde9d59d4557b8368827282e1 [file] [log] [blame]
Eric Laurentb23d5282013-05-14 15:27:20 -07001/*
vivek mehtaa6b79742017-03-09 15:40:43 -08002 * Copyright (C) 2013-2017 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>
vivek mehta0fb11312017-05-15 19:35:32 -070027#include "acdb.h"
Eric Laurentb23d5282013-05-14 15:27:20 -070028#include "platform.h"
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -070029#include "audio_extn.h"
vivek mehta1a9b7c02015-06-25 11:49:38 -070030#include <linux/msm_audio.h>
Haynes Mathew George96483a22017-03-28 14:52:47 -070031#if defined (PLATFORM_MSM8996) || (PLATFORM_MSM8998)
32#include <sound/devdep_params.h>
33#endif
Eric Laurentb23d5282013-05-14 15:27:20 -070034
Jaekyun Seokf62e17d2017-03-08 17:15:28 +090035#define MIXER_XML_DEFAULT_PATH "mixer_paths.xml"
36#define MIXER_XML_BASE_STRING "mixer_paths"
vivek mehta60ea4152016-02-18 17:10:26 -080037#define TOMTOM_8226_SND_CARD_NAME "msm8226-tomtom-snd-card"
38#define TOMTOM_MIXER_FILE_SUFFIX "wcd9330"
39
Eric Laurentb23d5282013-05-14 15:27:20 -070040#define LIB_ACDB_LOADER "libacdbloader.so"
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -070041#define AUDIO_DATA_BLOCK_MIXER_CTL "HDMI EDID"
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +090042#define CVD_VERSION_MIXER_CTL "CVD Version"
Eric Laurentb23d5282013-05-14 15:27:20 -070043
Eric Laurentf9583c32016-03-28 13:50:50 -070044#define min(a, b) ((a) < (b) ? (a) : (b))
Eric Laurentb23d5282013-05-14 15:27:20 -070045
46/*
Eric Laurentb23d5282013-05-14 15:27:20 -070047 * This file will have a maximum of 38 bytes:
48 *
49 * 4 bytes: number of audio blocks
50 * 4 bytes: total length of Short Audio Descriptor (SAD) blocks
51 * Maximum 10 * 3 bytes: SAD blocks
52 */
53#define MAX_SAD_BLOCKS 10
54#define SAD_BLOCK_SIZE 3
55
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +090056#define MAX_CVD_VERSION_STRING_SIZE 100
57
Eric Laurentb23d5282013-05-14 15:27:20 -070058/* EDID format ID for LPCM audio */
59#define EDID_FORMAT_LPCM 1
60
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -070061#define MAX_SND_CARD_NAME_LEN 31
62
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -080063#define DEFAULT_APP_TYPE_RX_PATH 69936
64#define DEFAULT_APP_TYPE_TX_PATH 69938
vivek mehta1a9b7c02015-06-25 11:49:38 -070065
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
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -080096#define BE_DAI_NAME_MAX_LENGTH 24
97struct be_dai_name_struct {
98 unsigned int be_id;
99 char be_name[BE_DAI_NAME_MAX_LENGTH];
100};
101
keunhui.park2f7306a2015-07-16 16:48:06 +0900102static struct listnode operator_info_list;
103static struct listnode *operator_specific_device_table[SND_DEVICE_MAX];
104
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700105/* Audio calibration related functions */
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800106typedef void (*acdb_send_audio_cal_v3_t)(int, int, int, int, int);
Eric Laurentb23d5282013-05-14 15:27:20 -0700107
Eric Laurentb23d5282013-05-14 15:27:20 -0700108struct platform_data {
109 struct audio_device *adev;
110 bool fluence_in_spkr_mode;
111 bool fluence_in_voice_call;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700112 bool fluence_in_voice_comm;
Eric Laurentb23d5282013-05-14 15:27:20 -0700113 bool fluence_in_voice_rec;
Prashant Malanic92c5962015-08-11 15:10:18 -0700114 /* 0 = no fluence, 1 = fluence, 2 = fluence pro */
115 int fluence_type;
116 int source_mic_type;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -0700117 bool speaker_lr_swap;
118
Eric Laurentb23d5282013-05-14 15:27:20 -0700119 void *acdb_handle;
Thierry Strudel92232b42017-01-26 10:51:48 -0800120#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -0700121 acdb_init_v2_cvd_t acdb_init;
122#elif defined (PLATFORM_MSM8084)
123 acdb_init_v2_t acdb_init;
124#else
125 acdb_init_t acdb_init;
126#endif
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700127 acdb_deallocate_t acdb_deallocate;
128 acdb_send_audio_cal_t acdb_send_audio_cal;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800129 acdb_send_audio_cal_v3_t acdb_send_audio_cal_v3;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700130 acdb_send_voice_cal_t acdb_send_voice_cal;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700131 acdb_reload_vocvoltable_t acdb_reload_vocvoltable;
vivek mehta1a9b7c02015-06-25 11:49:38 -0700132 acdb_send_gain_dep_cal_t acdb_send_gain_dep_cal;
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -0700133 acdb_send_custom_top_t acdb_send_custom_top;
134 bool acdb_initialized;
135
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700136 struct csd_data *csd;
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800137 char ec_ref_mixer_path[64];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700138
David Linee3fe402017-03-13 10:00:42 -0700139 codec_backend_cfg_t current_backend_cfg[MAX_CODEC_BACKENDS];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700140 char *snd_card_name;
keunhui.parkc5aaa0e2015-07-13 10:57:37 +0900141 int max_vol_index;
Prashant Malanic92c5962015-08-11 15:10:18 -0700142 int max_mic_count;
vivek mehtade4849c2016-03-03 17:23:38 -0800143
144 void *hw_info;
Eric Laurentb23d5282013-05-14 15:27:20 -0700145};
146
Haynes Mathew George98c95622014-06-20 19:14:25 -0700147static int pcm_device_table[AUDIO_USECASE_MAX][2] = {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700148 [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = {DEEP_BUFFER_PCM_DEVICE,
149 DEEP_BUFFER_PCM_DEVICE},
150 [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
151 LOWLATENCY_PCM_DEVICE},
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800152 [USECASE_AUDIO_PLAYBACK_HIFI] = {MULTIMEDIA2_PCM_DEVICE,
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700153 MULTIMEDIA2_PCM_DEVICE},
154 [USECASE_AUDIO_PLAYBACK_OFFLOAD] = {PLAYBACK_OFFLOAD_DEVICE,
155 PLAYBACK_OFFLOAD_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700156 [USECASE_AUDIO_PLAYBACK_TTS] = {MULTIMEDIA2_PCM_DEVICE,
157 MULTIMEDIA2_PCM_DEVICE},
158 [USECASE_AUDIO_PLAYBACK_ULL] = {MULTIMEDIA3_PCM_DEVICE,
159 MULTIMEDIA3_PCM_DEVICE},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800160 [USECASE_AUDIO_PLAYBACK_MMAP] = {MMAP_PLAYBACK_PCM_DEVICE,
161 MMAP_PLAYBACK_PCM_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700162
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700163 [USECASE_AUDIO_RECORD] = {AUDIO_RECORD_PCM_DEVICE,
164 AUDIO_RECORD_PCM_DEVICE},
165 [USECASE_AUDIO_RECORD_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
166 LOWLATENCY_PCM_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700167
Eric Laurent0e46adf2016-12-16 12:49:24 -0800168 [USECASE_AUDIO_RECORD_MMAP] = {MMAP_RECORD_PCM_DEVICE,
169 MMAP_RECORD_PCM_DEVICE},
Haynes Mathew George569b7482017-05-08 14:44:27 -0700170 [USECASE_AUDIO_RECORD_HIFI] = {MULTIMEDIA2_PCM_DEVICE,
171 MULTIMEDIA2_PCM_DEVICE},
172
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700173 [USECASE_VOICE_CALL] = {VOICE_CALL_PCM_DEVICE,
174 VOICE_CALL_PCM_DEVICE},
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700175 [USECASE_VOICE2_CALL] = {VOICE2_CALL_PCM_DEVICE, VOICE2_CALL_PCM_DEVICE},
176 [USECASE_VOLTE_CALL] = {VOLTE_CALL_PCM_DEVICE, VOLTE_CALL_PCM_DEVICE},
177 [USECASE_QCHAT_CALL] = {QCHAT_CALL_PCM_DEVICE, QCHAT_CALL_PCM_DEVICE},
178 [USECASE_VOWLAN_CALL] = {VOWLAN_CALL_PCM_DEVICE, VOWLAN_CALL_PCM_DEVICE},
vivek mehtaa51fd402016-02-04 19:49:33 -0800179 [USECASE_VOICEMMODE1_CALL] = {VOICEMMODE1_CALL_PCM_DEVICE,
180 VOICEMMODE1_CALL_PCM_DEVICE},
181 [USECASE_VOICEMMODE2_CALL] = {VOICEMMODE2_CALL_PCM_DEVICE,
182 VOICEMMODE2_CALL_PCM_DEVICE},
183
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700184 [USECASE_INCALL_REC_UPLINK] = {AUDIO_RECORD_PCM_DEVICE,
185 AUDIO_RECORD_PCM_DEVICE},
186 [USECASE_INCALL_REC_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
187 AUDIO_RECORD_PCM_DEVICE},
188 [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
189 AUDIO_RECORD_PCM_DEVICE},
Ravi Kumar Alamanda8e6e98f2013-11-05 15:57:39 -0800190 [USECASE_AUDIO_HFP_SCO] = {HFP_PCM_RX, HFP_SCO_RX},
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700191
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700192 [USECASE_AUDIO_SPKR_CALIB_RX] = {SPKR_PROT_CALIB_RX_PCM_DEVICE, -1},
193 [USECASE_AUDIO_SPKR_CALIB_TX] = {-1, SPKR_PROT_CALIB_TX_PCM_DEVICE},
194
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700195 [USECASE_AUDIO_PLAYBACK_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
196 AFE_PROXY_RECORD_PCM_DEVICE},
197 [USECASE_AUDIO_RECORD_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
198 AFE_PROXY_RECORD_PCM_DEVICE},
zhaoyang yin4211fad2015-06-04 21:13:25 +0800199 [USECASE_AUDIO_DSM_FEEDBACK] = {QUAT_MI2S_PCM_DEVICE, QUAT_MI2S_PCM_DEVICE},
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700200
vivek mehtaa68fea62017-06-08 19:04:02 -0700201 [USECASE_AUDIO_PLAYBACK_VOIP] = {AUDIO_PLAYBACK_VOIP_PCM_DEVICE,
202 AUDIO_PLAYBACK_VOIP_PCM_DEVICE},
203 [USECASE_AUDIO_RECORD_VOIP] = {AUDIO_RECORD_VOIP_PCM_DEVICE,
204 AUDIO_RECORD_VOIP_PCM_DEVICE},
Eric Laurentb23d5282013-05-14 15:27:20 -0700205};
206
207/* Array to store sound devices */
208static const char * const device_table[SND_DEVICE_MAX] = {
209 [SND_DEVICE_NONE] = "none",
210 /* Playback sound devices */
211 [SND_DEVICE_OUT_HANDSET] = "handset",
212 [SND_DEVICE_OUT_SPEAKER] = "speaker",
213 [SND_DEVICE_OUT_SPEAKER_REVERSE] = "speaker-reverse",
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700214 [SND_DEVICE_OUT_SPEAKER_SAFE] = "speaker-safe",
Eric Laurentb23d5282013-05-14 15:27:20 -0700215 [SND_DEVICE_OUT_HEADPHONES] = "headphones",
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500216 [SND_DEVICE_OUT_LINE] = "line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700217 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones",
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700218 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = "speaker-safe-and-headphones",
Eric Laurent744996b2014-10-01 11:40:40 -0500219 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = "speaker-and-line",
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700220 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = "speaker-safe-and-line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700221 [SND_DEVICE_OUT_VOICE_HANDSET] = "voice-handset",
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500222 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = "voice-hac-handset",
Eric Laurentb23d5282013-05-14 15:27:20 -0700223 [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker",
224 [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones",
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500225 [SND_DEVICE_OUT_VOICE_LINE] = "voice-line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700226 [SND_DEVICE_OUT_HDMI] = "hdmi",
227 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi",
228 [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700229 [SND_DEVICE_OUT_BT_SCO_WB] = "bt-sco-headset-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700230 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = "voice-handset-tmus",
231 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones",
232 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones",
233 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset",
vivek mehtaa6b79742017-03-09 15:40:43 -0800234 [SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = "voice-tty-full-usb",
235 [SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = "voice-tty-vco-usb",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700236 [SND_DEVICE_OUT_VOICE_TX] = "voice-tx",
David Linee3fe402017-03-13 10:00:42 -0700237 [SND_DEVICE_OUT_USB_HEADSET] = "usb-headset",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700238 [SND_DEVICE_OUT_VOICE_USB_HEADSET] = "usb-headset",
David Linee3fe402017-03-13 10:00:42 -0700239 [SND_DEVICE_OUT_USB_HEADPHONES] = "usb-headphones",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700240 [SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = "usb-headphones",
David Linee3fe402017-03-13 10:00:42 -0700241 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = "speaker-and-usb-headphones",
Haynes Mathew George9090bfb2017-05-31 11:44:50 -0700242 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] = "speaker-safe-and-usb-headphones",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700243 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = "speaker-protected",
244 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = "voice-speaker-protected",
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -0700245 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = "voice-speaker-hfp",
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -0800246 [SND_DEVICE_OUT_SPEAKER_AND_BT_SCO] = "speaker-and-bt-sco",
247 [SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB] = "speaker-and-bt-sco-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700248
249 /* Capture sound devices */
250 [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700251 [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700252 [SND_DEVICE_IN_HANDSET_MIC_NS] = "handset-mic",
253 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = "handset-mic",
254 [SND_DEVICE_IN_HANDSET_DMIC] = "dmic-endfire",
255 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = "dmic-endfire",
256 [SND_DEVICE_IN_HANDSET_DMIC_NS] = "dmic-endfire",
257 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = "dmic-endfire",
258 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = "dmic-endfire",
259
260 [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
261 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "speaker-mic",
262 [SND_DEVICE_IN_SPEAKER_MIC_NS] = "speaker-mic",
263 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = "speaker-mic",
264 [SND_DEVICE_IN_SPEAKER_DMIC] = "speaker-dmic-endfire",
265 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = "speaker-dmic-endfire",
266 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = "speaker-dmic-endfire",
267 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = "speaker-dmic-endfire",
268 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = "speaker-dmic-endfire",
269
270 [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
Eric Laurentcefbbac2014-09-04 13:54:10 -0500271 [SND_DEVICE_IN_HEADSET_MIC_AEC] = "headset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700272
Eric Laurentb23d5282013-05-14 15:27:20 -0700273 [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic",
274 [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700275 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = "bt-sco-mic",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700276 [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700277 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = "bt-sco-mic-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700278 [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700279
280 [SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef",
281 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = "voice-dmic-ef-tmus",
282 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
283 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = "voice-speaker-dmic-ef",
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -0700284 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = "voice-speaker-mic-hfp",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700285 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700286 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
287 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
288 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
vivek mehtaa6b79742017-03-09 15:40:43 -0800289 [SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = "voice-tty-full-usb-mic",
290 [SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = "voice-tty-hco-usb-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700291
Eric Laurentb23d5282013-05-14 15:27:20 -0700292 [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700293 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = "voice-rec-mic",
vivek mehta733c1df2016-04-04 15:09:24 -0700294 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = "voice-rec-mic",
vivek mehtaf3440682016-05-11 14:24:37 -0700295 [SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700296 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = "voice-rec-dmic-ef",
297 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence",
David Linee3fe402017-03-13 10:00:42 -0700298 [SND_DEVICE_IN_USB_HEADSET_MIC] = "usb-headset-mic",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700299 [SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] ="usb-headset-mic",
300 [SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = "usb-headset-mic",
301 [SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = "usb-headset-mic",
302 [SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = "usb-headset-mic",
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700303 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = "headset-mic",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700304
Ricardo Garcia9034bc42016-04-04 07:11:46 -0700305 [SND_DEVICE_IN_UNPROCESSED_MIC] = "unprocessed-mic",
vivek mehta0125e782016-06-16 18:03:11 -0700306 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = "unprocessed-stereo-mic",
307 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = "unprocessed-three-mic",
308 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = "unprocessed-quad-mic",
309 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = "unprocessed-headset-mic",
rago90fb9612015-12-02 11:37:53 -0800310
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700311 [SND_DEVICE_IN_VOICE_RX] = "voice-rx",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700312
Prashant Malanic92c5962015-08-11 15:10:18 -0700313 [SND_DEVICE_IN_THREE_MIC] = "three-mic",
314 [SND_DEVICE_IN_QUAD_MIC] = "quad-mic",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700315 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = "vi-feedback",
Prashant Malanic92c5962015-08-11 15:10:18 -0700316 [SND_DEVICE_IN_HANDSET_TMIC] = "three-mic",
317 [SND_DEVICE_IN_HANDSET_QMIC] = "quad-mic",
vivek mehta733c1df2016-04-04 15:09:24 -0700318 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = "three-mic",
319 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = "quad-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700320};
321
322/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700323static int acdb_device_table[SND_DEVICE_MAX] = {
Eric Laurentb23d5282013-05-14 15:27:20 -0700324 [SND_DEVICE_NONE] = -1,
325 [SND_DEVICE_OUT_HANDSET] = 7,
326 [SND_DEVICE_OUT_SPEAKER] = 15,
327 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 15,
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700328 [SND_DEVICE_OUT_SPEAKER_SAFE] = 15,
Eric Laurentb23d5282013-05-14 15:27:20 -0700329 [SND_DEVICE_OUT_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500330 [SND_DEVICE_OUT_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700331 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700332 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500333 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = 77,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700334 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = 77,
Ravi Kumar Alamanda235c3482014-08-21 17:32:44 -0700335 [SND_DEVICE_OUT_VOICE_HANDSET] = ACDB_ID_VOICE_HANDSET,
336 [SND_DEVICE_OUT_VOICE_SPEAKER] = ACDB_ID_VOICE_SPEAKER,
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500337 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = 53,
Eric Laurentb23d5282013-05-14 15:27:20 -0700338 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500339 [SND_DEVICE_OUT_VOICE_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700340 [SND_DEVICE_OUT_HDMI] = 18,
341 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 15,
342 [SND_DEVICE_OUT_BT_SCO] = 22,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700343 [SND_DEVICE_OUT_BT_SCO_WB] = 39,
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700344 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = ACDB_ID_VOICE_HANDSET_TMUS,
Eric Laurentb23d5282013-05-14 15:27:20 -0700345 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
346 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
347 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
vivek mehtaa6b79742017-03-09 15:40:43 -0800348 [SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = 17,
349 [SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = 17,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700350 [SND_DEVICE_OUT_VOICE_TX] = 45,
David Linee3fe402017-03-13 10:00:42 -0700351 [SND_DEVICE_OUT_USB_HEADSET] = 45,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700352 [SND_DEVICE_OUT_VOICE_USB_HEADSET] = 45,
David Linee3fe402017-03-13 10:00:42 -0700353 [SND_DEVICE_OUT_USB_HEADPHONES] = 45,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700354 [SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = 45,
David Linee3fe402017-03-13 10:00:42 -0700355 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = 14,
Haynes Mathew George9090bfb2017-05-31 11:44:50 -0700356 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] = 14,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700357 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = 124,
358 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = 101,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700359 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = ACDB_ID_VOICE_SPEAKER,
Eric Laurentb23d5282013-05-14 15:27:20 -0700360
361 [SND_DEVICE_IN_HANDSET_MIC] = 4,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700362 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 106,
363 [SND_DEVICE_IN_HANDSET_MIC_NS] = 107,
364 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = 108,
365 [SND_DEVICE_IN_HANDSET_DMIC] = 41,
366 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = 109,
367 [SND_DEVICE_IN_HANDSET_DMIC_NS] = 110,
368 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = 111,
369 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = 34,
370
371 [SND_DEVICE_IN_SPEAKER_MIC] = 11,
372 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 112,
373 [SND_DEVICE_IN_SPEAKER_MIC_NS] = 113,
374 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = 114,
375 [SND_DEVICE_IN_SPEAKER_DMIC] = 43,
376 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = 115,
377 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = 116,
378 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = 117,
379 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = 35,
380
rago90fb9612015-12-02 11:37:53 -0800381 [SND_DEVICE_IN_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentcefbbac2014-09-04 13:54:10 -0500382 [SND_DEVICE_IN_HEADSET_MIC_AEC] = ACDB_ID_HEADSET_MIC_AEC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700383
Eric Laurentb23d5282013-05-14 15:27:20 -0700384 [SND_DEVICE_IN_HDMI_MIC] = 4,
385 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700386 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = 21,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700387 [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700388 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = 38,
Eric Laurentb23d5282013-05-14 15:27:20 -0700389 [SND_DEVICE_IN_CAMCORDER_MIC] = 61,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700390
391 [SND_DEVICE_IN_VOICE_DMIC] = 41,
392 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = ACDB_ID_VOICE_DMIC_EF_TMUS,
393 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700394 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = 11,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700395 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 43,
rago90fb9612015-12-02 11:37:53 -0800396 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentb23d5282013-05-14 15:27:20 -0700397 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
398 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
399 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
vivek mehtaa6b79742017-03-09 15:40:43 -0800400 [SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = 16,
401 [SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = 16,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700402
rago90fb9612015-12-02 11:37:53 -0800403 [SND_DEVICE_IN_VOICE_REC_MIC] = ACDB_ID_VOICE_REC_MIC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700404 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = 113,
vivek mehta733c1df2016-04-04 15:09:24 -0700405 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = 112,
vivek mehtaf3440682016-05-11 14:24:37 -0700406 [SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = 114,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700407 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = 35,
408 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 43,
rago90fb9612015-12-02 11:37:53 -0800409 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
410
411 [SND_DEVICE_IN_UNPROCESSED_MIC] = ACDB_ID_VOICE_REC_MIC,
412 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
vivek mehta4ed66e62016-04-15 23:33:34 -0700413 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = 35,
414 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = 125,
415 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = 125,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700416
417 [SND_DEVICE_IN_VOICE_RX] = 44,
David Linee3fe402017-03-13 10:00:42 -0700418 [SND_DEVICE_IN_USB_HEADSET_MIC] = 44,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700419 [SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = 44,
420 [SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = 44,
421 [SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = 44,
422 [SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = 44,
Prashant Malanic92c5962015-08-11 15:10:18 -0700423 [SND_DEVICE_IN_THREE_MIC] = 46,
424 [SND_DEVICE_IN_QUAD_MIC] = 46,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700425 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = 102,
Prashant Malanic92c5962015-08-11 15:10:18 -0700426 [SND_DEVICE_IN_HANDSET_TMIC] = 125,
427 [SND_DEVICE_IN_HANDSET_QMIC] = 125,
vivek mehta733c1df2016-04-04 15:09:24 -0700428 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = 125, /* override this for new target to 140 */
429 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = 125, /* override this for new target to 140 */
Eric Laurentb23d5282013-05-14 15:27:20 -0700430};
431
David Linee3fe402017-03-13 10:00:42 -0700432// Platform specific backend bit width table
433static int backend_bit_width_table[SND_DEVICE_MAX] = {0};
434
Haynes Mathew George98c95622014-06-20 19:14:25 -0700435struct name_to_index {
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700436 char name[100];
437 unsigned int index;
438};
439
440#define TO_NAME_INDEX(X) #X, X
441
Haynes Mathew George98c95622014-06-20 19:14:25 -0700442/* Used to get index from parsed string */
443static const struct name_to_index snd_device_name_index[SND_DEVICE_MAX] = {
444 /* out */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700445 {TO_NAME_INDEX(SND_DEVICE_OUT_HANDSET)},
446 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER)},
447 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_REVERSE)},
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700448 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700449 {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500450 {TO_NAME_INDEX(SND_DEVICE_OUT_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700451 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700452 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES)},
Eric Laurent744996b2014-10-01 11:40:40 -0500453 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_LINE)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700454 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700455 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET)},
456 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700457 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_HFP)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700458 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500459 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700460 {TO_NAME_INDEX(SND_DEVICE_OUT_HDMI)},
461 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HDMI)},
462 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO)},
463 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO_WB)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700464 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET_TMUS)},
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500465 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HAC_HANDSET)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700466 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES)},
467 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES)},
468 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET)},
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -0800469 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_SCO)},
470 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800471 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_USB)},
472 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_USB)},
David Linee3fe402017-03-13 10:00:42 -0700473 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADSET)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700474 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_USB_HEADSET)},
David Linee3fe402017-03-13 10:00:42 -0700475 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADPHONES)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700476 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_USB_HEADPHONES)},
David Linee3fe402017-03-13 10:00:42 -0700477 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET)},
Haynes Mathew George9090bfb2017-05-31 11:44:50 -0700478 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700479 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED)},
480 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800481
482 /* in */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700483 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700484 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700485 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_NS)},
486 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)},
487 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC)},
488 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC)},
489 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_NS)},
490 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)},
491 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_STEREO)},
492
493 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700494 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700495 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_NS)},
496 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)},
497 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC)},
498 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC)},
499 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS)},
500 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)},
501 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_STEREO)},
502
503 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC)},
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700504 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700505
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700506 {TO_NAME_INDEX(SND_DEVICE_IN_HDMI_MIC)},
507 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700508 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700509 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700510 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700511 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700512
513 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC)},
514 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC_TMUS)},
515 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700516 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700517 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC)},
518 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEADSET_MIC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700519 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC)},
520 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC)},
521 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800522 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC)},
523 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC)},
524
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700525
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700526 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700527 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_NS)},
vivek mehta733c1df2016-04-04 15:09:24 -0700528 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC)},
vivek mehtaf3440682016-05-11 14:24:37 -0700529 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700530 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_STEREO)},
531 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE)},
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700532 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_HEADSET_MIC)},
David Linee3fe402017-03-13 10:00:42 -0700533 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700534 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_USB_HEADSET_MIC)},
535 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC)},
536 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC)},
537 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC_AEC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700538
rago90fb9612015-12-02 11:37:53 -0800539 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_MIC)},
540 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC)},
vivek mehta4ed66e62016-04-15 23:33:34 -0700541 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_STEREO_MIC)},
542 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_THREE_MIC)},
543 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_QUAD_MIC)},
rago90fb9612015-12-02 11:37:53 -0800544
Prashant Malanic92c5962015-08-11 15:10:18 -0700545 {TO_NAME_INDEX(SND_DEVICE_IN_THREE_MIC)},
546 {TO_NAME_INDEX(SND_DEVICE_IN_QUAD_MIC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700547 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_VI_FEEDBACK)},
Prashant Malanic92c5962015-08-11 15:10:18 -0700548 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC)},
549 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC)},
vivek mehta733c1df2016-04-04 15:09:24 -0700550 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC_AEC)},
551 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC_AEC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700552};
553
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700554static char * backend_tag_table[SND_DEVICE_MAX] = {0};
555static char * hw_interface_table[SND_DEVICE_MAX] = {0};
Haynes Mathew George98c95622014-06-20 19:14:25 -0700556
557static const struct name_to_index usecase_name_index[AUDIO_USECASE_MAX] = {
558 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_DEEP_BUFFER)},
559 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_LOW_LATENCY)},
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800560 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_HIFI)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700561 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD)},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700562 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_TTS)},
563 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_ULL)},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800564 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_MMAP)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700565 {TO_NAME_INDEX(USECASE_AUDIO_RECORD)},
566 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_LOW_LATENCY)},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800567 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_MMAP)},
Haynes Mathew George569b7482017-05-08 14:44:27 -0700568 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_HIFI)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700569 {TO_NAME_INDEX(USECASE_VOICE_CALL)},
570 {TO_NAME_INDEX(USECASE_VOICE2_CALL)},
571 {TO_NAME_INDEX(USECASE_VOLTE_CALL)},
572 {TO_NAME_INDEX(USECASE_QCHAT_CALL)},
573 {TO_NAME_INDEX(USECASE_VOWLAN_CALL)},
John Muirf1346ce2016-12-06 00:03:41 -0800574 {TO_NAME_INDEX(USECASE_VOICEMMODE1_CALL)},
575 {TO_NAME_INDEX(USECASE_VOICEMMODE2_CALL)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700576 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK)},
577 {TO_NAME_INDEX(USECASE_INCALL_REC_DOWNLINK)},
578 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK_AND_DOWNLINK)},
579 {TO_NAME_INDEX(USECASE_AUDIO_HFP_SCO)},
John Muirf1346ce2016-12-06 00:03:41 -0800580 {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_RX)},
581 {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_TX)},
582 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_AFE_PROXY)},
583 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_AFE_PROXY)},
584 {TO_NAME_INDEX(USECASE_AUDIO_DSM_FEEDBACK)},
vivek mehtaa68fea62017-06-08 19:04:02 -0700585 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_VOIP)},
586 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_VOIP)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700587};
588
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800589static const struct name_to_index usecase_type_index[USECASE_TYPE_MAX] = {
590 {TO_NAME_INDEX(PCM_PLAYBACK)},
591 {TO_NAME_INDEX(PCM_CAPTURE)},
592 {TO_NAME_INDEX(VOICE_CALL)},
593 {TO_NAME_INDEX(PCM_HFP_CALL)},
594};
595
596struct app_type_entry {
597 int uc_type;
598 int bit_width;
599 int app_type;
600 int max_rate;
vivek mehtaa68fea62017-06-08 19:04:02 -0700601 char *mode;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800602 struct listnode node; // membership in app_type_entry_list;
603};
604
605static struct listnode app_type_entry_list;
606
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700607#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
608#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
Eric Laurent0e46adf2016-12-16 12:49:24 -0800609#define ULL_PLATFORM_DELAY (3*1000LL)
610#define MMAP_PLATFORM_DELAY (3*1000LL)
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700611
Eric Laurentb23d5282013-05-14 15:27:20 -0700612static pthread_once_t check_op_once_ctl = PTHREAD_ONCE_INIT;
613static bool is_tmus = false;
614
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800615static int init_be_dai_name_table(struct audio_device *adev);
616
Eric Laurentb23d5282013-05-14 15:27:20 -0700617static void check_operator()
618{
619 char value[PROPERTY_VALUE_MAX];
620 int mccmnc;
621 property_get("gsm.sim.operator.numeric",value,"0");
622 mccmnc = atoi(value);
Eric Laurent2bafff12016-03-17 12:17:23 -0700623 ALOGD("%s: tmus mccmnc %d", __func__, mccmnc);
Eric Laurentb23d5282013-05-14 15:27:20 -0700624 switch(mccmnc) {
625 /* TMUS MCC(310), MNC(490, 260, 026) */
626 case 310490:
627 case 310260:
628 case 310026:
sangwon.jeonb891db52013-09-14 17:39:15 +0900629 /* Add new TMUS MNC(800, 660, 580, 310, 270, 250, 240, 230, 220, 210, 200, 160) */
630 case 310800:
631 case 310660:
632 case 310580:
633 case 310310:
634 case 310270:
635 case 310250:
636 case 310240:
637 case 310230:
638 case 310220:
639 case 310210:
640 case 310200:
641 case 310160:
Eric Laurentb23d5282013-05-14 15:27:20 -0700642 is_tmus = true;
643 break;
644 }
645}
646
647bool is_operator_tmus()
648{
649 pthread_once(&check_op_once_ctl, check_operator);
650 return is_tmus;
651}
652
keunhui.park2f7306a2015-07-16 16:48:06 +0900653static char *get_current_operator()
654{
655 struct listnode *node;
656 struct operator_info *info_item;
657 char mccmnc[PROPERTY_VALUE_MAX];
658 char *ret = NULL;
659
Tom Cherry7fea2042016-11-10 18:05:59 -0800660 property_get("gsm.sim.operator.numeric",mccmnc,"00000");
keunhui.park2f7306a2015-07-16 16:48:06 +0900661
662 list_for_each(node, &operator_info_list) {
663 info_item = node_to_item(node, struct operator_info, list);
664 if (strstr(info_item->mccmnc, mccmnc) != NULL) {
665 ret = info_item->name;
666 }
667 }
668
669 return ret;
670}
671
672static struct operator_specific_device *get_operator_specific_device(snd_device_t snd_device)
673{
674 struct listnode *node;
675 struct operator_specific_device *ret = NULL;
676 struct operator_specific_device *device_item;
677 char *operator_name;
678
679 operator_name = get_current_operator();
680 if (operator_name == NULL)
681 return ret;
682
683 list_for_each(node, operator_specific_device_table[snd_device]) {
684 device_item = node_to_item(node, struct operator_specific_device, list);
685 if (strcmp(operator_name, device_item->operator) == 0) {
686 ret = device_item;
687 }
688 }
689
690 return ret;
691}
692
693
694static int get_operator_specific_device_acdb_id(snd_device_t snd_device)
695{
696 struct operator_specific_device *device;
697 int ret = acdb_device_table[snd_device];
698
699 device = get_operator_specific_device(snd_device);
700 if (device != NULL)
701 ret = device->acdb_id;
702
703 return ret;
704}
705
706static const char *get_operator_specific_device_mixer_path(snd_device_t snd_device)
707{
708 struct operator_specific_device *device;
709 const char *ret = device_table[snd_device];
710
711 device = get_operator_specific_device(snd_device);
712 if (device != NULL)
713 ret = device->mixer_path;
714
715 return ret;
716}
717
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800718inline bool platform_supports_app_type_cfg()
719{
720#ifdef PLATFORM_MSM8998
721 return true;
722#else
723 return false;
724#endif
725}
726
vivek mehta1a9b7c02015-06-25 11:49:38 -0700727bool platform_send_gain_dep_cal(void *platform, int level)
728{
729 bool ret_val = false;
730 struct platform_data *my_data = (struct platform_data *)platform;
731 struct audio_device *adev = my_data->adev;
732 int acdb_dev_id, app_type;
733 int acdb_dev_type = MSM_SNDDEV_CAP_RX;
734 int mode = CAL_MODE_RTAC;
735 struct listnode *node;
736 struct audio_usecase *usecase;
Haynes Mathew George67486e22017-06-26 12:58:38 -0700737 bool valid_uc_type;
738 bool valid_dev;
vivek mehta1a9b7c02015-06-25 11:49:38 -0700739
740 if (my_data->acdb_send_gain_dep_cal == NULL) {
741 ALOGE("%s: dlsym error for acdb_send_gain_dep_cal", __func__);
742 return ret_val;
743 }
744
745 if (!voice_is_in_call(adev)) {
746 ALOGV("%s: Not Voice call usecase, apply new cal for level %d",
747 __func__, level);
748 app_type = DEFAULT_APP_TYPE_RX_PATH;
749
750 // find the current active sound device
751 list_for_each(node, &adev->usecase_list) {
752 usecase = node_to_item(node, struct audio_usecase, list);
Haynes Mathew George67486e22017-06-26 12:58:38 -0700753 LOG_ALWAYS_FATAL_IF(usecase == NULL,
754 "unxpected NULL usecase in usecase_list");
755 valid_uc_type = usecase->type == PCM_PLAYBACK;
756 valid_dev = false;
757 if (valid_uc_type) {
758 audio_devices_t dev = usecase->stream.out->devices;
759 valid_dev = (dev == AUDIO_DEVICE_OUT_SPEAKER ||
760 dev == AUDIO_DEVICE_OUT_WIRED_HEADSET ||
761 dev == AUDIO_DEVICE_OUT_WIRED_HEADPHONE);
762 }
763 if (valid_dev) {
vivek mehtaa68fea62017-06-08 19:04:02 -0700764 ALOGV("%s: out device is %d", __func__, usecase->out_snd_device);
765 if (audio_extn_spkr_prot_is_enabled()) {
vivek mehta4cb82982015-07-13 12:05:49 -0700766 acdb_dev_id = audio_extn_spkr_prot_get_acdb_id(usecase->out_snd_device);
vivek mehtaa68fea62017-06-08 19:04:02 -0700767 } else {
768 acdb_dev_id = acdb_device_table[usecase->out_snd_device];
769 }
vivek mehta4cb82982015-07-13 12:05:49 -0700770
vivek mehtaa68fea62017-06-08 19:04:02 -0700771 if (!my_data->acdb_send_gain_dep_cal(acdb_dev_id, app_type,
vivek mehta1a9b7c02015-06-25 11:49:38 -0700772 acdb_dev_type, mode, level)) {
773 // set ret_val true if at least one calibration is set successfully
774 ret_val = true;
775 } else {
776 ALOGE("%s: my_data->acdb_send_gain_dep_cal failed ", __func__);
777 }
778 } else {
779 ALOGW("%s: Usecase list is empty", __func__);
780 }
781 }
782 } else {
783 ALOGW("%s: Voice call in progress .. ignore setting new cal",
784 __func__);
785 }
786 return ret_val;
787}
788
Eric Laurentcefbbac2014-09-04 13:54:10 -0500789void platform_set_echo_reference(struct audio_device *adev, bool enable, audio_devices_t out_device)
Eric Laurentb23d5282013-05-14 15:27:20 -0700790{
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800791 struct platform_data *my_data = (struct platform_data *)adev->platform;
Eric Laurentcefbbac2014-09-04 13:54:10 -0500792 snd_device_t snd_device = SND_DEVICE_NONE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700793
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800794 if (strcmp(my_data->ec_ref_mixer_path, "")) {
795 ALOGV("%s: diabling %s", __func__, my_data->ec_ref_mixer_path);
796 audio_route_reset_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
Eric Laurentcefbbac2014-09-04 13:54:10 -0500797 }
798
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800799 if (enable) {
800 strcpy(my_data->ec_ref_mixer_path, "echo-reference");
801 if (out_device != AUDIO_DEVICE_NONE) {
802 snd_device = platform_get_output_snd_device(adev->platform, out_device);
803 platform_add_backend_name(adev->platform, my_data->ec_ref_mixer_path, snd_device);
804 }
Eric Laurentcefbbac2014-09-04 13:54:10 -0500805
Joe Onorato188b6222016-03-01 11:02:27 -0800806 ALOGV("%s: enabling %s", __func__, my_data->ec_ref_mixer_path);
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800807 audio_route_apply_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
808 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700809}
810
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700811static struct csd_data *open_csd_client(bool i2s_ext_modem)
812{
813 struct csd_data *csd = calloc(1, sizeof(struct csd_data));
814
815 csd->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
816 if (csd->csd_client == NULL) {
817 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
818 goto error;
819 } else {
820 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
821
822 csd->deinit = (deinit_t)dlsym(csd->csd_client,
823 "csd_client_deinit");
824 if (csd->deinit == NULL) {
825 ALOGE("%s: dlsym error %s for csd_client_deinit", __func__,
826 dlerror());
827 goto error;
828 }
829 csd->disable_device = (disable_device_t)dlsym(csd->csd_client,
830 "csd_client_disable_device");
831 if (csd->disable_device == NULL) {
832 ALOGE("%s: dlsym error %s for csd_client_disable_device",
833 __func__, dlerror());
834 goto error;
835 }
836 csd->enable_device_config = (enable_device_config_t)dlsym(csd->csd_client,
837 "csd_client_enable_device_config");
838 if (csd->enable_device_config == NULL) {
839 ALOGE("%s: dlsym error %s for csd_client_enable_device_config",
840 __func__, dlerror());
841 goto error;
842 }
843 csd->enable_device = (enable_device_t)dlsym(csd->csd_client,
844 "csd_client_enable_device");
845 if (csd->enable_device == NULL) {
846 ALOGE("%s: dlsym error %s for csd_client_enable_device",
847 __func__, dlerror());
848 goto error;
849 }
850 csd->start_voice = (start_voice_t)dlsym(csd->csd_client,
851 "csd_client_start_voice");
852 if (csd->start_voice == NULL) {
853 ALOGE("%s: dlsym error %s for csd_client_start_voice",
854 __func__, dlerror());
855 goto error;
856 }
857 csd->stop_voice = (stop_voice_t)dlsym(csd->csd_client,
858 "csd_client_stop_voice");
859 if (csd->stop_voice == NULL) {
860 ALOGE("%s: dlsym error %s for csd_client_stop_voice",
861 __func__, dlerror());
862 goto error;
863 }
864 csd->volume = (volume_t)dlsym(csd->csd_client,
865 "csd_client_volume");
866 if (csd->volume == NULL) {
867 ALOGE("%s: dlsym error %s for csd_client_volume",
868 __func__, dlerror());
869 goto error;
870 }
871 csd->mic_mute = (mic_mute_t)dlsym(csd->csd_client,
872 "csd_client_mic_mute");
873 if (csd->mic_mute == NULL) {
874 ALOGE("%s: dlsym error %s for csd_client_mic_mute",
875 __func__, dlerror());
876 goto error;
877 }
878 csd->slow_talk = (slow_talk_t)dlsym(csd->csd_client,
879 "csd_client_slow_talk");
880 if (csd->slow_talk == NULL) {
881 ALOGE("%s: dlsym error %s for csd_client_slow_talk",
882 __func__, dlerror());
883 goto error;
884 }
885 csd->start_playback = (start_playback_t)dlsym(csd->csd_client,
886 "csd_client_start_playback");
887 if (csd->start_playback == NULL) {
888 ALOGE("%s: dlsym error %s for csd_client_start_playback",
889 __func__, dlerror());
890 goto error;
891 }
892 csd->stop_playback = (stop_playback_t)dlsym(csd->csd_client,
893 "csd_client_stop_playback");
894 if (csd->stop_playback == NULL) {
895 ALOGE("%s: dlsym error %s for csd_client_stop_playback",
896 __func__, dlerror());
897 goto error;
898 }
899 csd->start_record = (start_record_t)dlsym(csd->csd_client,
900 "csd_client_start_record");
901 if (csd->start_record == NULL) {
902 ALOGE("%s: dlsym error %s for csd_client_start_record",
903 __func__, dlerror());
904 goto error;
905 }
906 csd->stop_record = (stop_record_t)dlsym(csd->csd_client,
907 "csd_client_stop_record");
908 if (csd->stop_record == NULL) {
909 ALOGE("%s: dlsym error %s for csd_client_stop_record",
910 __func__, dlerror());
911 goto error;
912 }
913
914 csd->get_sample_rate = (get_sample_rate_t)dlsym(csd->csd_client,
915 "csd_client_get_sample_rate");
916 if (csd->get_sample_rate == NULL) {
917 ALOGE("%s: dlsym error %s for csd_client_get_sample_rate",
918 __func__, dlerror());
919
920 goto error;
921 }
922
923 csd->init = (init_t)dlsym(csd->csd_client, "csd_client_init");
924
925 if (csd->init == NULL) {
926 ALOGE("%s: dlsym error %s for csd_client_init",
927 __func__, dlerror());
928 goto error;
929 } else {
930 csd->init(i2s_ext_modem);
931 }
932 }
933 return csd;
934
935error:
936 free(csd);
937 csd = NULL;
938 return csd;
939}
940
941void close_csd_client(struct csd_data *csd)
942{
943 if (csd != NULL) {
944 csd->deinit();
945 dlclose(csd->csd_client);
946 free(csd);
947 csd = NULL;
948 }
949}
950
951static void platform_csd_init(struct platform_data *my_data)
952{
953#ifdef PLATFORM_MSM8084
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700954 int32_t modems, (*count_modems)(void);
955 const char *name = "libdetectmodem.so";
956 const char *func = "count_modems";
957 const char *error;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700958
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700959 my_data->csd = NULL;
960
961 void *lib = dlopen(name, RTLD_NOW);
962 error = dlerror();
963 if (!lib) {
964 ALOGE("%s: could not find %s: %s", __func__, name, error);
965 return;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700966 }
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700967
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700968 count_modems = NULL;
969 *(void **)(&count_modems) = dlsym(lib, func);
970 error = dlerror();
971 if (!count_modems) {
972 ALOGE("%s: could not find symbol %s in %s: %s",
973 __func__, func, name, error);
974 goto done;
975 }
976
977 modems = count_modems();
978 if (modems < 0) {
979 ALOGE("%s: count_modems failed\n", __func__);
980 goto done;
981 }
982
Eric Laurent2bafff12016-03-17 12:17:23 -0700983 ALOGD("%s: num_modems %d\n", __func__, modems);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700984 if (modems > 0)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700985 my_data->csd = open_csd_client(false /*is_i2s_ext_modem*/);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700986
987done:
988 dlclose(lib);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700989#else
990 my_data->csd = NULL;
991#endif
992}
993
Eric Laurentc6333382015-09-14 12:43:44 -0700994static void set_platform_defaults(struct platform_data * my_data)
Haynes Mathew George98c95622014-06-20 19:14:25 -0700995{
996 int32_t dev;
997 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700998 backend_tag_table[dev] = NULL;
999 hw_interface_table[dev] = NULL;
keunhui.park2f7306a2015-07-16 16:48:06 +09001000 operator_specific_device_table[dev] = NULL;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001001 }
1002
David Linee3fe402017-03-13 10:00:42 -07001003 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1004 backend_bit_width_table[dev] = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
1005 }
1006
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001007 // To overwrite these go to the audio_platform_info.xml file.
1008 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("bt-sco");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07001009 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("bt-sco");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001010 backend_tag_table[SND_DEVICE_OUT_BT_SCO] = strdup("bt-sco");
1011 backend_tag_table[SND_DEVICE_OUT_HDMI] = strdup("hdmi");
1012 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("speaker-and-hdmi");
1013 backend_tag_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("bt-sco-wb");
1014 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("bt-sco-wb");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07001015 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("bt-sco-wb");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001016 backend_tag_table[SND_DEVICE_OUT_VOICE_TX] = strdup("afe-proxy");
1017 backend_tag_table[SND_DEVICE_IN_VOICE_RX] = strdup("afe-proxy");
Haynes Mathew George98c95622014-06-20 19:14:25 -07001018
David Linee3fe402017-03-13 10:00:42 -07001019 backend_tag_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("usb-headset");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001020 backend_tag_table[SND_DEVICE_OUT_VOICE_USB_HEADSET] = strdup("usb-headset");
David Linee3fe402017-03-13 10:00:42 -07001021 backend_tag_table[SND_DEVICE_OUT_USB_HEADPHONES] = strdup("usb-headphones");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001022 backend_tag_table[SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = strdup("usb-headphones");
David Linee3fe402017-03-13 10:00:42 -07001023 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] =
1024 strdup("speaker-and-usb-headphones");
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07001025 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] =
1026 strdup("speaker-safe-and-usb-headphones");
David Linee3fe402017-03-13 10:00:42 -07001027 backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("usb-headset-mic");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001028 backend_tag_table[SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1029 backend_tag_table[SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1030 backend_tag_table[SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1031 backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = strdup("usb-headset-mic");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001032 hw_interface_table[SND_DEVICE_OUT_HANDSET] = strdup("SLIMBUS_0_RX");
1033 hw_interface_table[SND_DEVICE_OUT_SPEAKER] = strdup("SLIMBUS_0_RX");
1034 hw_interface_table[SND_DEVICE_OUT_SPEAKER_REVERSE] = strdup("SLIMBUS_0_RX");
1035 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE] = strdup("SLIMBUS_0_RX");
1036 hw_interface_table[SND_DEVICE_OUT_HEADPHONES] = strdup("SLIMBUS_0_RX");
1037 hw_interface_table[SND_DEVICE_OUT_LINE] = strdup("SLIMBUS_0_RX");
1038 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001039 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001040 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001041 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001042 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET] = strdup("SLIMBUS_0_RX");
1043 hw_interface_table[SND_DEVICE_OUT_VOICE_HAC_HANDSET] = strdup("SLIMBUS_0_RX");
1044 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER] = strdup("SLIMBUS_0_RX");
1045 hw_interface_table[SND_DEVICE_OUT_VOICE_HEADPHONES] = strdup("SLIMBUS_0_RX");
1046 hw_interface_table[SND_DEVICE_OUT_VOICE_LINE] = strdup("SLIMBUS_0_RX");
1047 hw_interface_table[SND_DEVICE_OUT_HDMI] = strdup("HDMI_RX");
1048 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("SLIMBUS_0_RX-and-HDMI_RX");
1049 hw_interface_table[SND_DEVICE_OUT_BT_SCO] = strdup("SEC_AUX_PCM_RX");
1050 hw_interface_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("SEC_AUX_PCM_RX");
1051 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = strdup("SLIMBUS_0_RX");
1052 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = strdup("SLIMBUS_0_RX");
1053 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = strdup("SLIMBUS_0_RX");
1054 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = strdup("SLIMBUS_0_RX");
David Linee3fe402017-03-13 10:00:42 -07001055 hw_interface_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("USB_AUDIO_RX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001056 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = strdup("USB_AUDIO_RX");
1057 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = strdup("USB_AUDIO_RX");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001058 hw_interface_table[SND_DEVICE_OUT_VOICE_USB_HEADSET] = strdup("USB_AUDIO_RX");
David Linee3fe402017-03-13 10:00:42 -07001059 hw_interface_table[SND_DEVICE_OUT_USB_HEADPHONES] = strdup("USB_AUDIO_RX");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001060 hw_interface_table[SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = strdup("USB_AUDIO_RX");
David Linee3fe402017-03-13 10:00:42 -07001061 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = strdup("SLIMBUS_0_RX-and-USB_AUDIO_RX");
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07001062 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] = strdup("SLIMBUS_0_RX-and-USB_AUDIO_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001063 hw_interface_table[SND_DEVICE_OUT_VOICE_TX] = strdup("AFE_PCM_RX");
1064 hw_interface_table[SND_DEVICE_OUT_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
1065 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001066 hw_interface_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1067 hw_interface_table[SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1068 hw_interface_table[SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = strdup("USB_AUDIO_TX");
1069 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1070 hw_interface_table[SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1071 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = strdup("USB_AUDIO_TX");
1072 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = strdup("USB_AUDIO_TX");
1073 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC] = strdup("SLIMBUS_0_TX");
1074 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC] = strdup("SLIMBUS_0_TX");
1075 hw_interface_table[SND_DEVICE_IN_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1076 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_MIC] = strdup("SLIMBUS_0_TX");
1077 hw_interface_table[SND_DEVICE_IN_CAMCORDER_MIC] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001078 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC] = strdup("SLIMBUS_0_TX");
1079 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC_NS] = strdup("SLIMBUS_0_TX");
1080 hw_interface_table[SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
1081 hw_interface_table[SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = strdup("SLIMBUS_0_TX");
1082 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC] = strdup("SLIMBUS_0_TX");
1083 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_AEC] = strdup("SLIMBUS_0_TX");
1084 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_NS] = strdup("SLIMBUS_0_TX");
1085 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1086 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC] = strdup("SLIMBUS_0_TX");
1087 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_AEC] = strdup("SLIMBUS_0_TX");
1088 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_NS] = strdup("SLIMBUS_0_TX");
1089 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1090 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_MIC] = strdup("SLIMBUS_0_TX");
1091 hw_interface_table[SND_DEVICE_IN_VOICE_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
Eric Laurentc6333382015-09-14 12:43:44 -07001092 my_data->max_mic_count = PLATFORM_DEFAULT_MIC_COUNT;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001093}
1094
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001095void get_cvd_version(char *cvd_version, struct audio_device *adev)
1096{
1097 struct mixer_ctl *ctl;
1098 int count;
1099 int ret = 0;
1100
1101 ctl = mixer_get_ctl_by_name(adev->mixer, CVD_VERSION_MIXER_CTL);
1102 if (!ctl) {
1103 ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__, CVD_VERSION_MIXER_CTL);
1104 goto done;
1105 }
1106 mixer_ctl_update(ctl);
1107
1108 count = mixer_ctl_get_num_values(ctl);
1109 if (count > MAX_CVD_VERSION_STRING_SIZE)
1110 count = MAX_CVD_VERSION_STRING_SIZE - 1;
1111
1112 ret = mixer_ctl_get_array(ctl, cvd_version, count);
1113 if (ret != 0) {
1114 ALOGE("%s: ERROR! mixer_ctl_get_array() failed to get CVD Version", __func__);
1115 goto done;
1116 }
1117
1118done:
1119 return;
1120}
1121
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001122static int platform_acdb_init(void *platform)
1123{
1124 struct platform_data *my_data = (struct platform_data *)platform;
1125 struct audio_device *adev = my_data->adev;
1126
1127 if (!my_data->acdb_init) {
1128 ALOGE("%s: no acdb_init fn provided", __func__);
1129 return -1;
1130 }
1131
1132 if (my_data->acdb_initialized) {
1133 ALOGW("acdb is already initialized");
1134 return 0;
1135 }
1136
Thierry Strudel92232b42017-01-26 10:51:48 -08001137#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001138 char *cvd_version = calloc(1, MAX_CVD_VERSION_STRING_SIZE);
1139 if (!cvd_version)
1140 ALOGE("failed to allocate cvd_version");
1141 else {
1142 get_cvd_version(cvd_version, adev);
1143 my_data->acdb_init((char *)my_data->snd_card_name, cvd_version, 0);
1144 free(cvd_version);
1145 }
1146#elif defined (PLATFORM_MSM8084)
1147 my_data->acdb_init((char *)my_data->snd_card_name);
1148#else
1149 my_data->acdb_init();
1150#endif
1151 my_data->acdb_initialized = true;
1152 return 0;
1153}
1154
David Linee3fe402017-03-13 10:00:42 -07001155static void
1156platform_backend_config_init(struct platform_data *pdata)
1157{
1158 int i;
1159
1160 /* initialize backend config */
1161 for (i = 0; i < MAX_CODEC_BACKENDS; i++) {
1162 pdata->current_backend_cfg[i].sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
1163 pdata->current_backend_cfg[i].bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
1164 pdata->current_backend_cfg[i].channels = CODEC_BACKEND_DEFAULT_CHANNELS;
1165
1166 if (i > MAX_RX_CODEC_BACKENDS)
1167 pdata->current_backend_cfg[i].channels = CODEC_BACKEND_DEFAULT_TX_CHANNELS;
1168
1169 pdata->current_backend_cfg[i].bitwidth_mixer_ctl = NULL;
1170 pdata->current_backend_cfg[i].samplerate_mixer_ctl = NULL;
1171 pdata->current_backend_cfg[i].channels_mixer_ctl = NULL;
1172 }
1173
1174 pdata->current_backend_cfg[DEFAULT_CODEC_BACKEND].bitwidth_mixer_ctl =
1175 strdup("SLIM_0_RX Format");
1176 pdata->current_backend_cfg[DEFAULT_CODEC_BACKEND].samplerate_mixer_ctl =
1177 strdup("SLIM_0_RX SampleRate");
1178
1179 pdata->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].bitwidth_mixer_ctl =
1180 strdup("SLIM_0_TX Format");
1181 pdata->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].samplerate_mixer_ctl =
1182 strdup("SLIM_0_TX SampleRate");
1183
1184 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].bitwidth_mixer_ctl =
1185 strdup("USB_AUDIO_TX Format");
1186 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].samplerate_mixer_ctl =
1187 strdup("USB_AUDIO_TX SampleRate");
1188 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].channels_mixer_ctl =
1189 strdup("USB_AUDIO_TX Channels");
1190
1191 pdata->current_backend_cfg[HEADPHONE_BACKEND].bitwidth_mixer_ctl =
1192 strdup("SLIM_6_RX Format");
1193 pdata->current_backend_cfg[HEADPHONE_BACKEND].samplerate_mixer_ctl =
1194 strdup("SLIM_6_RX SampleRate");
1195
1196 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].bitwidth_mixer_ctl =
1197 strdup("USB_AUDIO_RX Format");
1198 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].samplerate_mixer_ctl =
1199 strdup("USB_AUDIO_RX SampleRate");
1200
1201 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].channels = 1;
1202 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].channels_mixer_ctl =
1203 strdup("USB_AUDIO_RX Channels");
1204}
1205
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001206static int
1207platform_backend_app_type_cfg_init(struct platform_data *pdata,
1208 struct mixer *mixer)
1209{
1210 size_t app_type_cfg[128] = {0};
1211 int length, num_app_types = 0;
1212 struct mixer_ctl *ctl = NULL;
1213
1214 const char *mixer_ctl_name = "App Type Config";
1215 ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name);
1216 if (!ctl) {
1217 ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name);
1218 return -1;
1219 }
1220
1221 length = 1; // reserve index 0 for number of app types
1222
1223 struct listnode *node;
1224 struct app_type_entry *entry;
1225 list_for_each(node, &app_type_entry_list) {
1226 entry = node_to_item(node, struct app_type_entry, node);
1227 app_type_cfg[length++] = entry->app_type;
1228 app_type_cfg[length++] = entry->max_rate;
1229 app_type_cfg[length++] = entry->bit_width;
1230 ALOGI("%s add entry %d %d", __func__, entry->app_type, entry->bit_width);
1231 num_app_types += 1;
1232 }
1233
1234 // default for capture
1235 int t;
1236 platform_get_default_app_type_v2(pdata,
1237 PCM_CAPTURE,
1238 &t);
1239 app_type_cfg[length++] = t;
1240 app_type_cfg[length++] = 48000;
1241 app_type_cfg[length++] = 16;
1242 num_app_types += 1;
1243
1244 if (num_app_types) {
1245 app_type_cfg[0] = num_app_types;
1246 if (mixer_ctl_set_array(ctl, app_type_cfg, length) < 0) {
1247 ALOGE("Failed to set app type cfg");
1248 }
1249 }
1250 return 0;
1251}
1252
Eric Laurentb23d5282013-05-14 15:27:20 -07001253void *platform_init(struct audio_device *adev)
1254{
1255 char value[PROPERTY_VALUE_MAX];
vivek mehta60ea4152016-02-18 17:10:26 -08001256 struct platform_data *my_data = NULL;
1257 int retry_num = 0, snd_card_num = 0, key = 0, ret = 0;
1258 bool dual_mic_config = false, use_default_mixer_path = true;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001259 const char *snd_card_name;
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001260 char *cvd_version = NULL;
vivek mehta60ea4152016-02-18 17:10:26 -08001261 char *snd_internal_name = NULL;
1262 char *tmp = NULL;
1263 char mixer_xml_file[MIXER_PATH_MAX_LENGTH]= {0};
vivek mehtade4849c2016-03-03 17:23:38 -08001264 char platform_info_file[MIXER_PATH_MAX_LENGTH]= {0};
1265 struct snd_card_split *snd_split_handle = NULL;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001266 my_data = calloc(1, sizeof(struct platform_data));
1267
1268 my_data->adev = adev;
1269
keunhui.park2f7306a2015-07-16 16:48:06 +09001270 list_init(&operator_info_list);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001271 list_init(&app_type_entry_list);
keunhui.park2f7306a2015-07-16 16:48:06 +09001272
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001273 set_platform_defaults(my_data);
1274
vivek mehta0fb11312017-05-15 19:35:32 -07001275 // audio_extn_utils_get_snd_card_num does
1276 // - open mixer and get snd card name
1277 // - parse platform info xml file and check for valid snd card name
1278 // - on failure loop through all the active snd card
sangwoo1b9f4b32013-06-21 18:22:55 -07001279
vivek mehta0fb11312017-05-15 19:35:32 -07001280 snd_card_num = audio_extn_utils_get_snd_card_num();
1281 if (-1 == snd_card_num) {
1282 ALOGE("%s: invalid sound card number (-1), bailing out ", __func__);
1283 goto init_failed;
sangwoo1b9f4b32013-06-21 18:22:55 -07001284 }
1285
vivek mehta0fb11312017-05-15 19:35:32 -07001286 adev->mixer = mixer_open(snd_card_num);
1287 snd_card_name = mixer_get_name(adev->mixer);
1288 my_data->hw_info = hw_info_init(snd_card_name);
1289
1290 audio_extn_set_snd_card_split(snd_card_name);
1291 snd_split_handle = audio_extn_get_snd_card_split();
1292
1293 /* Get the codec internal name from the sound card and/or form factor
1294 * name and form the mixer paths and platfor info file name dynamically.
1295 * This is generic way of picking any codec and forma factor name based
1296 * mixer and platform info files in future with no code change.
1297
1298 * current code extends and looks for any of the exteneded mixer path and
1299 * platform info file present based on codec and form factor.
1300
1301 * order of picking appropriate file is
1302 * <i> mixer_paths_<codec_name>_<form_factor>.xml, if file not present
1303 * <ii> mixer_paths_<codec_name>.xml, if file not present
1304 * <iii> mixer_paths.xml
1305
1306 * same order is followed for audio_platform_info.xml as well
1307 */
1308
1309 // need to carryforward old file name
1310 if (!strncmp(snd_card_name, TOMTOM_8226_SND_CARD_NAME,
1311 min(strlen(TOMTOM_8226_SND_CARD_NAME), strlen(snd_card_name)))) {
1312 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1313 MIXER_XML_BASE_STRING, TOMTOM_MIXER_FILE_SUFFIX );
1314 } else {
1315
1316 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s_%s.xml",
1317 MIXER_XML_BASE_STRING, snd_split_handle->snd_card,
1318 snd_split_handle->form_factor);
1319 if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) {
1320 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1321 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1322 MIXER_XML_BASE_STRING, snd_split_handle->snd_card);
1323
1324 if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) {
1325 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1326 strlcpy(mixer_xml_file, MIXER_XML_DEFAULT_PATH, MIXER_PATH_MAX_LENGTH);
1327 audio_extn_utils_resolve_config_file(mixer_xml_file);
1328 }
1329 }
1330 }
1331
1332 audio_extn_utils_get_platform_info(snd_card_name, platform_info_file);
1333
1334 /* Initialize platform specific ids and/or backends*/
1335 platform_info_init(platform_info_file, my_data);
1336
1337 ALOGD("%s: Loading mixer file: %s", __func__, mixer_xml_file);
1338 adev->audio_route = audio_route_init(snd_card_num, mixer_xml_file);
1339
1340 if (!adev->audio_route) {
1341 ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
1342 mixer_close(adev->mixer);
1343 adev->mixer = NULL;
1344 hw_info_deinit(my_data->hw_info);
1345 my_data->hw_info = NULL;
1346 goto init_failed;
1347 }
1348 adev->snd_card = snd_card_num;
1349 ALOGD("%s: Opened sound card:%d", __func__, snd_card_num);
1350
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09001351 //set max volume step for voice call
1352 property_get("ro.config.vc_call_vol_steps", value, TOSTRING(MAX_VOL_INDEX));
1353 my_data->max_vol_index = atoi(value);
1354
vivek mehta65ad12d2015-08-13 18:32:48 -07001355 property_get("persist.audio.dualmic.config",value,"");
1356 if (!strcmp("endfire", value)) {
1357 dual_mic_config = true;
1358 }
1359
Prashant Malanic92c5962015-08-11 15:10:18 -07001360 my_data->source_mic_type = SOURCE_DUAL_MIC;
1361
Eric Laurentb23d5282013-05-14 15:27:20 -07001362 my_data->fluence_in_spkr_mode = false;
1363 my_data->fluence_in_voice_call = false;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001364 my_data->fluence_in_voice_comm = false;
Eric Laurentb23d5282013-05-14 15:27:20 -07001365 my_data->fluence_in_voice_rec = false;
1366
vivek mehta65ad12d2015-08-13 18:32:48 -07001367 property_get("ro.qc.sdk.audio.fluencetype", value, "none");
Prashant Malanic92c5962015-08-11 15:10:18 -07001368 if (!strcmp("fluencepro", value)) {
1369 my_data->fluence_type = FLUENCE_PRO_ENABLE;
vivek mehta65ad12d2015-08-13 18:32:48 -07001370 } else if (!strcmp("fluence", value) || (dual_mic_config)) {
Prashant Malanic92c5962015-08-11 15:10:18 -07001371 my_data->fluence_type = FLUENCE_ENABLE;
1372 } else if (!strcmp("none", value)) {
1373 my_data->fluence_type = FLUENCE_DISABLE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001374 }
1375
Prashant Malanic92c5962015-08-11 15:10:18 -07001376 if (my_data->fluence_type != FLUENCE_DISABLE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001377 property_get("persist.audio.fluence.voicecall",value,"");
1378 if (!strcmp("true", value)) {
1379 my_data->fluence_in_voice_call = true;
1380 }
1381
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001382 property_get("persist.audio.fluence.voicecomm",value,"");
1383 if (!strcmp("true", value)) {
1384 my_data->fluence_in_voice_comm = true;
1385 }
1386
Eric Laurentb23d5282013-05-14 15:27:20 -07001387 property_get("persist.audio.fluence.voicerec",value,"");
1388 if (!strcmp("true", value)) {
1389 my_data->fluence_in_voice_rec = true;
1390 }
1391
1392 property_get("persist.audio.fluence.speaker",value,"");
1393 if (!strcmp("true", value)) {
1394 my_data->fluence_in_spkr_mode = true;
1395 }
1396 }
1397
Prashant Malanic92c5962015-08-11 15:10:18 -07001398 // support max to mono, example if max count is 3, usecase supports Three, dual and mono mic
1399 switch (my_data->max_mic_count) {
1400 case 4:
1401 my_data->source_mic_type |= SOURCE_QUAD_MIC;
1402 case 3:
1403 my_data->source_mic_type |= SOURCE_THREE_MIC;
1404 case 2:
1405 my_data->source_mic_type |= SOURCE_DUAL_MIC;
1406 case 1:
1407 my_data->source_mic_type |= SOURCE_MONO_MIC;
1408 break;
1409 default:
1410 ALOGE("%s: max_mic_count (%d), is not supported, setting to default",
1411 __func__, my_data->max_mic_count);
1412 my_data->source_mic_type = SOURCE_MONO_MIC|SOURCE_DUAL_MIC;
1413 break;
1414 }
1415
1416 ALOGV("%s: Fluence_Type(%d) max_mic_count(%d) mic_type(0x%x) fluence_in_voice_call(%d)"
1417 " fluence_in_voice_comm(%d) fluence_in_voice_rec(%d) fluence_in_spkr_mode(%d) ",
1418 __func__, my_data->fluence_type, my_data->max_mic_count, my_data->source_mic_type,
1419 my_data->fluence_in_voice_call, my_data->fluence_in_voice_comm,
1420 my_data->fluence_in_voice_rec, my_data->fluence_in_spkr_mode);
1421
Eric Laurentb23d5282013-05-14 15:27:20 -07001422 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
1423 if (my_data->acdb_handle == NULL) {
1424 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
1425 } else {
1426 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
1427 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
1428 "acdb_loader_deallocate_ACDB");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001429 if (!my_data->acdb_deallocate)
1430 ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s",
1431 __func__, LIB_ACDB_LOADER);
1432
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001433 my_data->acdb_send_audio_cal_v3 = (acdb_send_audio_cal_v3_t)dlsym(my_data->acdb_handle,
1434 "acdb_loader_send_audio_cal_v3");
1435 if (!my_data->acdb_send_audio_cal_v3)
1436 ALOGE("%s: Could not find the symbol acdb_send_audio_cal_v3 from %s",
1437 __func__, LIB_ACDB_LOADER);
1438
Eric Laurentb23d5282013-05-14 15:27:20 -07001439 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
1440 "acdb_loader_send_audio_cal");
1441 if (!my_data->acdb_send_audio_cal)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001442 ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s",
Eric Laurentb23d5282013-05-14 15:27:20 -07001443 __func__, LIB_ACDB_LOADER);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001444
Eric Laurentb23d5282013-05-14 15:27:20 -07001445 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
1446 "acdb_loader_send_voice_cal");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001447 if (!my_data->acdb_send_voice_cal)
1448 ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s",
1449 __func__, LIB_ACDB_LOADER);
1450
1451 my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle,
1452 "acdb_loader_reload_vocvoltable");
1453 if (!my_data->acdb_reload_vocvoltable)
1454 ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s",
1455 __func__, LIB_ACDB_LOADER);
vivek mehta1a9b7c02015-06-25 11:49:38 -07001456
1457 my_data->acdb_send_gain_dep_cal = (acdb_send_gain_dep_cal_t)dlsym(my_data->acdb_handle,
1458 "acdb_loader_send_gain_dep_cal");
1459 if (!my_data->acdb_send_gain_dep_cal)
1460 ALOGV("%s: Could not find the symbol acdb_loader_send_gain_dep_cal from %s",
1461 __func__, LIB_ACDB_LOADER);
1462
Thierry Strudel92232b42017-01-26 10:51:48 -08001463#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998)
vivek mehta0fb11312017-05-15 19:35:32 -07001464 acdb_init_v2_cvd_t acdb_init_local;
1465 acdb_init_local = (acdb_init_v2_cvd_t)dlsym(my_data->acdb_handle,
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001466 "acdb_loader_init_v2");
vivek mehta0fb11312017-05-15 19:35:32 -07001467 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001468 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1469 dlerror());
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001470
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001471#elif defined (PLATFORM_MSM8084)
vivek mehta0fb11312017-05-15 19:35:32 -07001472 acdb_init_v2_t acdb_init_local;
1473 acdb_init_local = (acdb_init_v2_t)dlsym(my_data->acdb_handle,
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001474 "acdb_loader_init_v2");
vivek mehta0fb11312017-05-15 19:35:32 -07001475 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001476 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1477 dlerror());
1478
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001479#else
vivek mehta0fb11312017-05-15 19:35:32 -07001480 acdb_init_t acdb_init_local;
1481 acdb_init_local = (acdb_init_t)dlsym(my_data->acdb_handle,
Eric Laurentb23d5282013-05-14 15:27:20 -07001482 "acdb_loader_init_ACDB");
vivek mehta0fb11312017-05-15 19:35:32 -07001483 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001484 ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__,
1485 dlerror());
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001486#endif
vivek mehta0fb11312017-05-15 19:35:32 -07001487 my_data->acdb_init = acdb_init_local;
Eric Laurentb23d5282013-05-14 15:27:20 -07001488
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001489 my_data->acdb_send_custom_top = (acdb_send_custom_top_t)
1490 dlsym(my_data->acdb_handle,
1491 "acdb_loader_send_common_custom_topology");
1492
1493 if (!my_data->acdb_send_custom_top)
1494 ALOGE("%s: Could not find the symbol acdb_get_default_app_type from %s",
1495 __func__, LIB_ACDB_LOADER);
1496
vivek mehta0fb11312017-05-15 19:35:32 -07001497 int result = acdb_init(adev->snd_card);
1498 if (!result) {
1499 my_data->acdb_initialized = true;
1500 ALOGD("ACDB initialized");
1501 } else {
1502 my_data->acdb_initialized = false;
1503 ALOGD("ACDB initialization failed");
1504 }
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001505 }
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001506
David Linee3fe402017-03-13 10:00:42 -07001507 /* init usb */
1508 audio_extn_usb_init(adev);
1509
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001510 audio_extn_spkr_prot_init(adev);
Haynes Mathew George98c95622014-06-20 19:14:25 -07001511
Ravi Kumar Alamanda76315572015-04-23 13:13:56 -07001512 audio_extn_hwdep_cal_send(adev->snd_card, my_data->acdb_handle);
1513
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001514 /* load csd client */
1515 platform_csd_init(my_data);
1516
David Linee3fe402017-03-13 10:00:42 -07001517 platform_backend_config_init(my_data);
1518
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001519 init_be_dai_name_table(adev);
1520
1521 if (platform_supports_app_type_cfg())
1522 platform_backend_app_type_cfg_init(my_data, adev->mixer);
1523
Eric Laurentb23d5282013-05-14 15:27:20 -07001524 return my_data;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001525
1526init_failed:
1527 if (my_data)
1528 free(my_data);
1529 return NULL;
Eric Laurentb23d5282013-05-14 15:27:20 -07001530}
1531
1532void platform_deinit(void *platform)
1533{
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001534 int32_t dev;
keunhui.park2f7306a2015-07-16 16:48:06 +09001535 struct operator_info *info_item;
1536 struct operator_specific_device *device_item;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001537 struct app_type_entry *ap;
keunhui.park2f7306a2015-07-16 16:48:06 +09001538 struct listnode *node;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001539
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001540 struct platform_data *my_data = (struct platform_data *)platform;
1541 close_csd_client(my_data->csd);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001542
vivek mehtade4849c2016-03-03 17:23:38 -08001543 hw_info_deinit(my_data->hw_info);
1544
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001545 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1546 if (backend_tag_table[dev])
1547 free(backend_tag_table[dev]);
1548 if (hw_interface_table[dev])
1549 free(hw_interface_table[dev]);
keunhui.park2f7306a2015-07-16 16:48:06 +09001550 if (operator_specific_device_table[dev]) {
1551 while (!list_empty(operator_specific_device_table[dev])) {
1552 node = list_head(operator_specific_device_table[dev]);
1553 list_remove(node);
1554 device_item = node_to_item(node, struct operator_specific_device, list);
1555 free(device_item->operator);
1556 free(device_item->mixer_path);
1557 free(device_item);
1558 }
1559 free(operator_specific_device_table[dev]);
1560 }
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001561 }
1562
1563 if (my_data->snd_card_name)
1564 free(my_data->snd_card_name);
1565
keunhui.park2f7306a2015-07-16 16:48:06 +09001566 while (!list_empty(&operator_info_list)) {
1567 node = list_head(&operator_info_list);
1568 list_remove(node);
1569 info_item = node_to_item(node, struct operator_info, list);
1570 free(info_item->name);
1571 free(info_item->mccmnc);
1572 free(info_item);
1573 }
1574
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001575 while (!list_empty(&app_type_entry_list)) {
1576 node = list_head(&app_type_entry_list);
1577 list_remove(node);
1578 ap = node_to_item(node, struct app_type_entry, node);
vivek mehtaa68fea62017-06-08 19:04:02 -07001579 if (ap->mode) free(ap->mode);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001580 free(ap);
1581 }
1582
Kevin Rocarde35d4af2017-05-02 16:55:28 -07001583 mixer_close(my_data->adev->mixer);
Eric Laurentb23d5282013-05-14 15:27:20 -07001584 free(platform);
David Linee3fe402017-03-13 10:00:42 -07001585
1586 /* deinit usb */
1587 audio_extn_usb_deinit();
Eric Laurentb23d5282013-05-14 15:27:20 -07001588}
1589
1590const char *platform_get_snd_device_name(snd_device_t snd_device)
1591{
keunhui.park2f7306a2015-07-16 16:48:06 +09001592 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1593 if (operator_specific_device_table[snd_device] != NULL) {
1594 return get_operator_specific_device_mixer_path(snd_device);
1595 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001596 return device_table[snd_device];
keunhui.park2f7306a2015-07-16 16:48:06 +09001597 } else
Ravi Kumar Alamanda64026462014-09-15 00:08:58 -07001598 return "none";
Eric Laurentb23d5282013-05-14 15:27:20 -07001599}
1600
vivek mehtade4849c2016-03-03 17:23:38 -08001601int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
1602 char *device_name)
1603{
1604 struct platform_data *my_data = (struct platform_data *)platform;
1605
David Benjamin1565f992016-09-21 12:10:34 -04001606 if (platform == NULL) {
vivek mehtade4849c2016-03-03 17:23:38 -08001607 ALOGW("%s: something wrong, use legacy get_snd_device name", __func__);
David Benjamin1565f992016-09-21 12:10:34 -04001608 strlcpy(device_name, platform_get_snd_device_name(snd_device),
1609 DEVICE_NAME_MAX_SIZE);
vivek mehtade4849c2016-03-03 17:23:38 -08001610 } else if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1611 if (operator_specific_device_table[snd_device] != NULL) {
1612 strlcpy(device_name, get_operator_specific_device_mixer_path(snd_device),
1613 DEVICE_NAME_MAX_SIZE);
1614 } else {
1615 strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE);
1616 }
1617 hw_info_append_hw_type(my_data->hw_info, snd_device, device_name);
1618 } else {
1619 strlcpy(device_name, "none", DEVICE_NAME_MAX_SIZE);
1620 }
1621
1622 return 0;
1623}
1624
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001625void platform_add_backend_name(void *platform, char *mixer_path,
1626 snd_device_t snd_device)
Eric Laurentb23d5282013-05-14 15:27:20 -07001627{
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001628 struct platform_data *my_data = (struct platform_data *)platform;
1629
Haynes Mathew George98c95622014-06-20 19:14:25 -07001630 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1631 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1632 return;
Ravi Kumar Alamanda1de6e5a2014-06-19 21:55:39 -05001633 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001634
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001635 const char * suffix = backend_tag_table[snd_device];
Haynes Mathew George98c95622014-06-20 19:14:25 -07001636
1637 if (suffix != NULL) {
1638 strcat(mixer_path, " ");
1639 strcat(mixer_path, suffix);
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001640 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001641}
1642
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001643bool platform_check_backends_match(snd_device_t snd_device1, snd_device_t snd_device2)
1644{
1645 bool result = true;
1646
1647 ALOGV("%s: snd_device1 = %s, snd_device2 = %s", __func__,
1648 platform_get_snd_device_name(snd_device1),
1649 platform_get_snd_device_name(snd_device2));
1650
1651 if ((snd_device1 < SND_DEVICE_MIN) || (snd_device1 >= SND_DEVICE_MAX)) {
1652 ALOGE("%s: Invalid snd_device = %s", __func__,
1653 platform_get_snd_device_name(snd_device1));
1654 return false;
1655 }
1656 if ((snd_device2 < SND_DEVICE_MIN) || (snd_device2 >= SND_DEVICE_MAX)) {
1657 ALOGE("%s: Invalid snd_device = %s", __func__,
1658 platform_get_snd_device_name(snd_device2));
1659 return false;
1660 }
1661 const char * be_itf1 = hw_interface_table[snd_device1];
1662 const char * be_itf2 = hw_interface_table[snd_device2];
1663
1664 if (NULL != be_itf1 && NULL != be_itf2) {
Eric Laurente63e61d2015-09-10 12:19:33 -07001665 if ((NULL == strstr(be_itf2, be_itf1)) && (NULL == strstr(be_itf1, be_itf2)))
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001666 result = false;
1667 }
1668
1669 ALOGV("%s: be_itf1 = %s, be_itf2 = %s, match %d", __func__, be_itf1, be_itf2, result);
1670 return result;
1671}
1672
Eric Laurentb23d5282013-05-14 15:27:20 -07001673int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
1674{
1675 int device_id;
1676 if (device_type == PCM_PLAYBACK)
1677 device_id = pcm_device_table[usecase][0];
1678 else
1679 device_id = pcm_device_table[usecase][1];
1680 return device_id;
1681}
1682
Haynes Mathew George98c95622014-06-20 19:14:25 -07001683static int find_index(const struct name_to_index * table, int32_t len,
1684 const char * name)
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001685{
1686 int ret = 0;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001687 int32_t i;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001688
Haynes Mathew George98c95622014-06-20 19:14:25 -07001689 if (table == NULL) {
1690 ALOGE("%s: table is NULL", __func__);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001691 ret = -ENODEV;
1692 goto done;
1693 }
1694
Haynes Mathew George98c95622014-06-20 19:14:25 -07001695 if (name == NULL) {
1696 ALOGE("null key");
1697 ret = -ENODEV;
1698 goto done;
1699 }
1700
1701 for (i=0; i < len; i++) {
1702 if (!strcmp(table[i].name, name)) {
1703 ret = table[i].index;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001704 goto done;
1705 }
1706 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001707 ALOGE("%s: Could not find index for name = %s",
1708 __func__, name);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001709 ret = -ENODEV;
1710done:
1711 return ret;
1712}
1713
Haynes Mathew George98c95622014-06-20 19:14:25 -07001714int platform_get_snd_device_index(char *device_name)
1715{
1716 return find_index(snd_device_name_index, SND_DEVICE_MAX, device_name);
1717}
1718
1719int platform_get_usecase_index(const char *usecase_name)
1720{
1721 return find_index(usecase_name_index, AUDIO_USECASE_MAX, usecase_name);
1722}
1723
keunhui.park2f7306a2015-07-16 16:48:06 +09001724void platform_add_operator_specific_device(snd_device_t snd_device,
1725 const char *operator,
1726 const char *mixer_path,
1727 unsigned int acdb_id)
1728{
1729 struct operator_specific_device *device;
1730
1731 if (operator_specific_device_table[snd_device] == NULL) {
1732 operator_specific_device_table[snd_device] =
1733 (struct listnode *)calloc(1, sizeof(struct listnode));
1734 list_init(operator_specific_device_table[snd_device]);
1735 }
1736
1737 device = (struct operator_specific_device *)calloc(1, sizeof(struct operator_specific_device));
1738
1739 device->operator = strdup(operator);
1740 device->mixer_path = strdup(mixer_path);
1741 device->acdb_id = acdb_id;
1742
1743 list_add_tail(operator_specific_device_table[snd_device], &device->list);
1744
Eric Laurent2bafff12016-03-17 12:17:23 -07001745 ALOGD("%s: device[%s] -> operator[%s] mixer_path[%s] acdb_id[%d]", __func__,
keunhui.park2f7306a2015-07-16 16:48:06 +09001746 platform_get_snd_device_name(snd_device), operator, mixer_path, acdb_id);
1747
1748}
1749
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001750int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
1751{
1752 int ret = 0;
1753
1754 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1755 ALOGE("%s: Invalid snd_device = %d",
1756 __func__, snd_device);
1757 ret = -EINVAL;
1758 goto done;
1759 }
1760
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001761 ALOGV("%s: acdb_device_table[%s]: old = %d new = %d", __func__,
1762 platform_get_snd_device_name(snd_device), acdb_device_table[snd_device], acdb_id);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001763 acdb_device_table[snd_device] = acdb_id;
1764done:
1765 return ret;
1766}
1767
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001768int platform_get_snd_device_acdb_id(snd_device_t snd_device)
1769{
1770 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1771 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1772 return -EINVAL;
1773 }
keunhui.park2f7306a2015-07-16 16:48:06 +09001774
1775 if (operator_specific_device_table[snd_device] != NULL)
1776 return get_operator_specific_device_acdb_id(snd_device);
1777 else
1778 return acdb_device_table[snd_device];
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001779}
1780
David Linee3fe402017-03-13 10:00:42 -07001781static int platform_get_backend_index(snd_device_t snd_device)
1782{
1783 int32_t port = DEFAULT_CODEC_BACKEND;
1784
1785 if (snd_device >= SND_DEVICE_OUT_BEGIN && snd_device < SND_DEVICE_OUT_END) {
1786 if (backend_tag_table[snd_device] != NULL) {
1787 if (strncmp(backend_tag_table[snd_device], "headphones",
1788 sizeof("headphones")) == 0)
1789 port = HEADPHONE_BACKEND;
1790 else if (strcmp(backend_tag_table[snd_device], "hdmi") == 0)
1791 port = HDMI_RX_BACKEND;
1792 else if ((strcmp(backend_tag_table[snd_device], "usb-headphones") == 0) ||
1793 (strcmp(backend_tag_table[snd_device], "usb-headset") == 0))
1794 port = USB_AUDIO_RX_BACKEND;
1795 }
1796 } else if (snd_device >= SND_DEVICE_IN_BEGIN && snd_device < SND_DEVICE_IN_END) {
1797 port = DEFAULT_CODEC_TX_BACKEND;
1798 if (backend_tag_table[snd_device] != NULL) {
1799 if (strcmp(backend_tag_table[snd_device], "usb-headset-mic") == 0)
1800 port = USB_AUDIO_TX_BACKEND;
1801 else if (strstr(backend_tag_table[snd_device], "bt-sco") != NULL)
1802 port = BT_SCO_TX_BACKEND;
1803 }
1804 } else {
1805 ALOGW("%s:napb: Invalid device - %d ", __func__, snd_device);
1806 }
1807
1808 ALOGV("%s:napb: backend port - %d device - %d ", __func__, port, snd_device);
1809
1810 return port;
1811}
1812
Eric Laurentb23d5282013-05-14 15:27:20 -07001813int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
1814{
1815 struct platform_data *my_data = (struct platform_data *)platform;
1816 int acdb_dev_id, acdb_dev_type;
1817
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001818 if (platform_supports_app_type_cfg()) // use v2 instead
1819 return -ENOSYS;
1820
Ravi Kumar Alamandaadf0f3b2015-06-04 02:34:02 -07001821 acdb_dev_id = acdb_device_table[audio_extn_get_spkr_prot_snd_device(snd_device)];
Eric Laurentb23d5282013-05-14 15:27:20 -07001822 if (acdb_dev_id < 0) {
1823 ALOGE("%s: Could not find acdb id for device(%d)",
1824 __func__, snd_device);
1825 return -EINVAL;
1826 }
1827 if (my_data->acdb_send_audio_cal) {
Joe Onorato188b6222016-03-01 11:02:27 -08001828 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Eric Laurentb23d5282013-05-14 15:27:20 -07001829 __func__, snd_device, acdb_dev_id);
1830 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
1831 snd_device < SND_DEVICE_OUT_END)
1832 acdb_dev_type = ACDB_DEV_TYPE_OUT;
1833 else
1834 acdb_dev_type = ACDB_DEV_TYPE_IN;
1835 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
1836 }
1837 return 0;
1838}
1839
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001840int platform_send_audio_calibration_v2(void *platform, struct audio_usecase *usecase,
1841 int app_type, int sample_rate)
1842{
1843 struct platform_data *my_data = (struct platform_data *)platform;
1844 int acdb_dev_id, acdb_dev_type;
1845 int snd_device = SND_DEVICE_OUT_SPEAKER;
1846 int new_snd_device[SND_DEVICE_OUT_END] = {0};
1847 int i, num_devices = 1;
1848
1849 if (!platform_supports_app_type_cfg()) // use v1 instead
1850 return -ENOSYS;
1851
1852 if (usecase->type == PCM_PLAYBACK)
1853 snd_device = usecase->out_snd_device;
1854 else if (usecase->type == PCM_CAPTURE)
1855 snd_device = usecase->in_snd_device;
1856
1857 // skipped over get_spkr_prot_device
1858 acdb_dev_id = acdb_device_table[snd_device];
1859 if (acdb_dev_id < 0) {
1860 ALOGE("%s: Could not find acdb id for device(%d)",
1861 __func__, snd_device);
1862 return -EINVAL;
1863 }
1864
1865 if (platform_can_split_snd_device(snd_device,
1866 &num_devices, new_snd_device) < 0) {
1867 new_snd_device[0] = snd_device;
1868 }
1869
1870 for (i = 0; i < num_devices; i++) {
1871 acdb_dev_id = acdb_device_table[new_snd_device[i]];
1872 if (acdb_dev_id < 0) {
1873 ALOGE("%s: Could not find acdb id for device(%d)",
1874 __func__, new_snd_device[i]);
1875 return -EINVAL;
1876 }
1877 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
1878 __func__, new_snd_device[i], acdb_dev_id);
1879 if (new_snd_device[i] >= SND_DEVICE_OUT_BEGIN &&
1880 new_snd_device[i] < SND_DEVICE_OUT_END)
1881 acdb_dev_type = ACDB_DEV_TYPE_OUT;
1882 else
1883 acdb_dev_type = ACDB_DEV_TYPE_IN;
1884
1885 if (my_data->acdb_send_audio_cal_v3) {
1886 my_data->acdb_send_audio_cal_v3(acdb_dev_id, acdb_dev_type,
1887 app_type, sample_rate, i);
1888 } else if (my_data->acdb_send_audio_cal) {
1889 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type); // this version differs from internal
1890 }
1891 }
1892
1893 return 0;
1894}
1895
1896
Eric Laurentb23d5282013-05-14 15:27:20 -07001897int platform_switch_voice_call_device_pre(void *platform)
1898{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001899 struct platform_data *my_data = (struct platform_data *)platform;
1900 int ret = 0;
1901
1902 if (my_data->csd != NULL &&
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001903 voice_is_in_call(my_data->adev)) {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001904 /* This must be called before disabling mixer controls on APQ side */
1905 ret = my_data->csd->disable_device();
1906 if (ret < 0) {
1907 ALOGE("%s: csd_client_disable_device, failed, error %d",
1908 __func__, ret);
1909 }
1910 }
1911 return ret;
1912}
1913
1914int platform_switch_voice_call_enable_device_config(void *platform,
1915 snd_device_t out_snd_device,
1916 snd_device_t in_snd_device)
1917{
1918 struct platform_data *my_data = (struct platform_data *)platform;
1919 int acdb_rx_id, acdb_tx_id;
1920 int ret = 0;
1921
1922 if (my_data->csd == NULL)
1923 return ret;
1924
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001925 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1926 audio_extn_spkr_prot_is_enabled())
keunhui.park2f7306a2015-07-16 16:48:06 +09001927 acdb_rx_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_SPEAKER_PROTECTED);
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001928 else
keunhui.park2f7306a2015-07-16 16:48:06 +09001929 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001930
keunhui.park2f7306a2015-07-16 16:48:06 +09001931 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001932
1933 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
1934 ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
1935 if (ret < 0) {
1936 ALOGE("%s: csd_enable_device_config, failed, error %d",
1937 __func__, ret);
1938 }
1939 } else {
1940 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1941 acdb_rx_id, acdb_tx_id);
1942 }
1943
1944 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001945}
1946
1947int platform_switch_voice_call_device_post(void *platform,
1948 snd_device_t out_snd_device,
1949 snd_device_t in_snd_device)
1950{
1951 struct platform_data *my_data = (struct platform_data *)platform;
1952 int acdb_rx_id, acdb_tx_id;
1953
1954 if (my_data->acdb_send_voice_cal == NULL) {
1955 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
1956 } else {
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001957 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1958 audio_extn_spkr_prot_is_enabled())
1959 out_snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED;
1960
keunhui.park2f7306a2015-07-16 16:48:06 +09001961 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
1962 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07001963
1964 if (acdb_rx_id > 0 && acdb_tx_id > 0)
1965 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
1966 else
1967 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1968 acdb_rx_id, acdb_tx_id);
1969 }
1970
1971 return 0;
1972}
1973
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001974int platform_switch_voice_call_usecase_route_post(void *platform,
1975 snd_device_t out_snd_device,
1976 snd_device_t in_snd_device)
1977{
1978 struct platform_data *my_data = (struct platform_data *)platform;
1979 int acdb_rx_id, acdb_tx_id;
1980 int ret = 0;
1981
1982 if (my_data->csd == NULL)
1983 return ret;
1984
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001985 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1986 audio_extn_spkr_prot_is_enabled())
keunhui.park2f7306a2015-07-16 16:48:06 +09001987 acdb_rx_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED);
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001988 else
keunhui.park2f7306a2015-07-16 16:48:06 +09001989 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001990
keunhui.park2f7306a2015-07-16 16:48:06 +09001991 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001992
1993 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
1994 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
1995 my_data->adev->acdb_settings);
1996 if (ret < 0) {
1997 ALOGE("%s: csd_enable_device, failed, error %d", __func__, ret);
1998 }
1999 } else {
2000 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2001 acdb_rx_id, acdb_tx_id);
2002 }
2003
2004 return ret;
2005}
2006
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002007int platform_start_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07002008{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002009 struct platform_data *my_data = (struct platform_data *)platform;
2010 int ret = 0;
2011
2012 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002013 ret = my_data->csd->start_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002014 if (ret < 0) {
2015 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
2016 }
2017 }
2018 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002019}
2020
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002021int platform_stop_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07002022{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002023 struct platform_data *my_data = (struct platform_data *)platform;
2024 int ret = 0;
2025
2026 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002027 ret = my_data->csd->stop_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002028 if (ret < 0) {
2029 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
2030 }
2031 }
2032 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002033}
2034
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002035int platform_get_sample_rate(void *platform, uint32_t *rate)
2036{
2037 struct platform_data *my_data = (struct platform_data *)platform;
2038 int ret = 0;
2039
2040 if (my_data->csd != NULL) {
2041 ret = my_data->csd->get_sample_rate(rate);
2042 if (ret < 0) {
2043 ALOGE("%s: csd_get_sample_rate error %d\n", __func__, ret);
2044 }
2045 }
2046 return ret;
2047}
2048
vivek mehtab6506412015-08-07 16:55:17 -07002049void platform_set_speaker_gain_in_combo(struct audio_device *adev,
2050 snd_device_t snd_device,
2051 bool enable)
2052{
2053 const char* name;
2054 switch (snd_device) {
2055 case SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES:
2056 if (enable)
2057 name = "spkr-gain-in-headphone-combo";
2058 else
2059 name = "speaker-gain-default";
2060 break;
2061 case SND_DEVICE_OUT_SPEAKER_AND_LINE:
2062 if (enable)
2063 name = "spkr-gain-in-line-combo";
2064 else
2065 name = "speaker-gain-default";
2066 break;
2067 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES:
2068 if (enable)
2069 name = "spkr-safe-gain-in-headphone-combo";
2070 else
2071 name = "speaker-safe-gain-default";
2072 break;
2073 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE:
2074 if (enable)
2075 name = "spkr-safe-gain-in-line-combo";
2076 else
2077 name = "speaker-safe-gain-default";
2078 break;
2079 default:
2080 return;
2081 }
2082
2083 audio_route_apply_and_update_path(adev->audio_route, name);
2084}
2085
Eric Laurentb23d5282013-05-14 15:27:20 -07002086int platform_set_voice_volume(void *platform, int volume)
2087{
2088 struct platform_data *my_data = (struct platform_data *)platform;
2089 struct audio_device *adev = my_data->adev;
2090 struct mixer_ctl *ctl;
sangwoo53b2cf02013-07-25 19:18:44 -07002091 const char *mixer_ctl_name = "Voice Rx Gain";
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002092 int vol_index = 0, ret = 0;
2093 uint32_t set_values[ ] = {0,
2094 ALL_SESSION_VSID,
2095 DEFAULT_VOLUME_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07002096
2097 // Voice volume levels are mapped to adsp volume levels as follows.
2098 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
2099 // But this values don't changed in kernel. So, below change is need.
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09002100 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, my_data->max_vol_index);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002101 set_values[0] = vol_index;
Eric Laurentb23d5282013-05-14 15:27:20 -07002102
2103 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2104 if (!ctl) {
2105 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2106 __func__, mixer_ctl_name);
2107 return -EINVAL;
2108 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002109 ALOGV("Setting voice volume index: %d", set_values[0]);
2110 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2111
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002112 if (my_data->csd != NULL) {
2113 ret = my_data->csd->volume(ALL_SESSION_VSID, volume,
2114 DEFAULT_VOLUME_RAMP_DURATION_MS);
2115 if (ret < 0) {
2116 ALOGE("%s: csd_volume error %d", __func__, ret);
2117 }
2118 }
2119 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002120}
2121
2122int platform_set_mic_mute(void *platform, bool state)
2123{
2124 struct platform_data *my_data = (struct platform_data *)platform;
2125 struct audio_device *adev = my_data->adev;
2126 struct mixer_ctl *ctl;
2127 const char *mixer_ctl_name = "Voice Tx Mute";
sangwoo53b2cf02013-07-25 19:18:44 -07002128 int ret = 0;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002129 uint32_t set_values[ ] = {0,
2130 ALL_SESSION_VSID,
2131 DEFAULT_MUTE_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07002132
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09002133 if (adev->mode != AUDIO_MODE_IN_CALL &&
2134 adev->mode != AUDIO_MODE_IN_COMMUNICATION)
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002135 return 0;
2136
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09002137 if (adev->enable_hfp)
2138 mixer_ctl_name = "HFP Tx Mute";
2139
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002140 set_values[0] = state;
2141 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2142 if (!ctl) {
2143 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2144 __func__, mixer_ctl_name);
2145 return -EINVAL;
2146 }
2147 ALOGV("Setting voice mute state: %d", state);
2148 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2149
2150 if (my_data->csd != NULL) {
2151 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state,
2152 DEFAULT_MUTE_RAMP_DURATION_MS);
sangwoo53b2cf02013-07-25 19:18:44 -07002153 if (ret < 0) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002154 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
sangwoo53b2cf02013-07-25 19:18:44 -07002155 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002156 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002157 return ret;
2158}
Eric Laurentb23d5282013-05-14 15:27:20 -07002159
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002160int platform_set_device_mute(void *platform, bool state, char *dir)
2161{
2162 struct platform_data *my_data = (struct platform_data *)platform;
2163 struct audio_device *adev = my_data->adev;
2164 struct mixer_ctl *ctl;
2165 char *mixer_ctl_name = NULL;
2166 int ret = 0;
2167 uint32_t set_values[ ] = {0,
2168 ALL_SESSION_VSID,
2169 0};
2170 if(dir == NULL) {
2171 ALOGE("%s: Invalid direction:%s", __func__, dir);
2172 return -EINVAL;
2173 }
2174
2175 if (!strncmp("rx", dir, sizeof("rx"))) {
2176 mixer_ctl_name = "Voice Rx Device Mute";
2177 } else if (!strncmp("tx", dir, sizeof("tx"))) {
2178 mixer_ctl_name = "Voice Tx Device Mute";
2179 } else {
2180 return -EINVAL;
2181 }
2182
2183 set_values[0] = state;
2184 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2185 if (!ctl) {
2186 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2187 __func__, mixer_ctl_name);
2188 return -EINVAL;
2189 }
2190
2191 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
2192 __func__,state, mixer_ctl_name);
2193 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2194
2195 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002196}
2197
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002198int platform_can_split_snd_device(snd_device_t snd_device,
2199 int *num_devices,
2200 snd_device_t *new_snd_devices)
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002201{
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002202 int ret = -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002203 if (NULL == num_devices || NULL == new_snd_devices) {
2204 ALOGE("%s: NULL pointer ..", __func__);
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002205 return -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002206 }
2207
2208 /*
2209 * If wired headset/headphones/line devices share the same backend
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002210 * with speaker/earpiece this routine returns -EINVAL.
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002211 */
2212 if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES &&
2213 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_HEADPHONES)) {
2214 *num_devices = 2;
2215 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2216 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002217 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002218 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_LINE &&
2219 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_LINE)) {
2220 *num_devices = 2;
2221 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2222 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002223 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002224 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES &&
2225 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_HEADPHONES)) {
2226 *num_devices = 2;
2227 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2228 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002229 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002230 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE &&
2231 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_LINE)) {
2232 *num_devices = 2;
2233 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2234 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002235 ret = 0;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002236 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO &&
2237 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2238 SND_DEVICE_OUT_BT_SCO)) {
2239 *num_devices = 2;
2240 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2241 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO;
2242 ret = 0;
2243 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB &&
2244 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2245 SND_DEVICE_OUT_BT_SCO_WB)) {
2246 *num_devices = 2;
2247 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2248 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO_WB;
2249 ret = 0;
David Linee3fe402017-03-13 10:00:42 -07002250 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET &&
2251 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_USB_HEADSET)) {
2252 *num_devices = 2;
2253 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2254 new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
2255 ret = 0;
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07002256 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET &&
2257 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_USB_HEADSET)) {
2258 *num_devices = 2;
2259 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2260 new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
2261 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002262 }
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002263 return ret;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002264}
2265
Eric Laurentb23d5282013-05-14 15:27:20 -07002266snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
2267{
2268 struct platform_data *my_data = (struct platform_data *)platform;
2269 struct audio_device *adev = my_data->adev;
2270 audio_mode_t mode = adev->mode;
2271 snd_device_t snd_device = SND_DEVICE_NONE;
2272
2273 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
2274 if (devices == AUDIO_DEVICE_NONE ||
2275 devices & AUDIO_DEVICE_BIT_IN) {
2276 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
2277 goto exit;
2278 }
2279
Eric Laurent1b491552015-09-15 17:52:41 -07002280 if (popcount(devices) == 2) {
2281 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2282 AUDIO_DEVICE_OUT_SPEAKER) ||
2283 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2284 AUDIO_DEVICE_OUT_SPEAKER)) {
2285 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
2286 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2287 AUDIO_DEVICE_OUT_SPEAKER)) {
2288 snd_device = SND_DEVICE_OUT_SPEAKER_AND_LINE;
2289 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2290 AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
2291 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2292 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2293 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES;
2294 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2295 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2296 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE;
2297 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
2298 AUDIO_DEVICE_OUT_SPEAKER)) {
2299 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002300 } else if ((devices & AUDIO_DEVICE_OUT_ALL_SCO) &&
2301 ((devices & ~AUDIO_DEVICE_OUT_ALL_SCO) == AUDIO_DEVICE_OUT_SPEAKER)) {
2302 snd_device = adev->bt_wb_speech_enabled ?
2303 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB :
2304 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO;
Eric Laurent99dab492017-06-17 15:19:08 -07002305 } else if ((devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
2306 AUDIO_DEVICE_OUT_SPEAKER)) ||
2307 (devices == (AUDIO_DEVICE_OUT_USB_HEADSET |
2308 AUDIO_DEVICE_OUT_SPEAKER))) {
David Linee3fe402017-03-13 10:00:42 -07002309 snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET;
Eric Laurentd0f7c262017-07-05 09:09:12 -07002310 } else if ((devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
2311 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) ||
2312 (devices == (AUDIO_DEVICE_OUT_USB_HEADSET |
2313 AUDIO_DEVICE_OUT_SPEAKER_SAFE))) {
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07002314 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET;
Eric Laurent1b491552015-09-15 17:52:41 -07002315 } else {
2316 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
2317 goto exit;
2318 }
2319 if (snd_device != SND_DEVICE_NONE) {
2320 goto exit;
2321 }
2322 }
2323
2324 if (popcount(devices) != 1) {
2325 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
2326 goto exit;
2327 }
2328
Madhuri Athota3f6051b2016-10-13 23:25:38 +05302329 if (voice_is_in_call(adev) || adev->enable_voicerx || audio_extn_hfp_is_active(adev)) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002330 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002331 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2332 devices & AUDIO_DEVICE_OUT_LINE) {
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002333 if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002334 (adev->voice.tty_mode == TTY_MODE_FULL))
Eric Laurentb23d5282013-05-14 15:27:20 -07002335 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002336 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002337 (adev->voice.tty_mode == TTY_MODE_VCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002338 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002339 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002340 (adev->voice.tty_mode == TTY_MODE_HCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002341 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002342 else {
2343 if (devices & AUDIO_DEVICE_OUT_LINE)
2344 snd_device = SND_DEVICE_OUT_VOICE_LINE;
2345 else
2346 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
2347 }
Eric Laurent99dab492017-06-17 15:19:08 -07002348 } else if (audio_is_usb_out_device(devices)) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002349 if (voice_is_in_call(adev)) {
2350 switch (adev->voice.tty_mode) {
2351 case TTY_MODE_FULL:
2352 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_USB;
2353 break;
2354 case TTY_MODE_VCO:
2355 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_USB;
2356 break;
2357 case TTY_MODE_HCO:
2358 // since Hearing will be on handset\speaker, use existing device
2359 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
2360 break;
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002361 case TTY_MODE_OFF:
2362 break;
vivek mehtaa6b79742017-03-09 15:40:43 -08002363 default:
2364 ALOGE("%s: Invalid TTY mode (%#x)",
2365 __func__, adev->voice.tty_mode);
2366 }
2367 }
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002368 if (snd_device == SND_DEVICE_NONE) {
2369 snd_device = audio_extn_usb_is_capture_supported() ?
2370 SND_DEVICE_OUT_VOICE_USB_HEADSET :
2371 SND_DEVICE_OUT_VOICE_USB_HEADPHONES;
2372 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002373 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002374 if (adev->bt_wb_speech_enabled) {
2375 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2376 } else {
2377 snd_device = SND_DEVICE_OUT_BT_SCO;
2378 }
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002379 } else if (devices & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002380 if (!adev->enable_hfp) {
2381 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
2382 } else {
2383 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_HFP;
2384 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002385 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002386 if(adev->voice.hac)
2387 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2388 else if (is_operator_tmus())
Eric Laurentb23d5282013-05-14 15:27:20 -07002389 snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS;
2390 else
Eric Laurentb4d368e2014-06-25 10:21:54 -05002391 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002392 } else if (devices & AUDIO_DEVICE_OUT_TELEPHONY_TX)
2393 snd_device = SND_DEVICE_OUT_VOICE_TX;
2394
Eric Laurentb23d5282013-05-14 15:27:20 -07002395 if (snd_device != SND_DEVICE_NONE) {
2396 goto exit;
2397 }
2398 }
2399
Eric Laurentb23d5282013-05-14 15:27:20 -07002400 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2401 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2402 snd_device = SND_DEVICE_OUT_HEADPHONES;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002403 } else if (devices & AUDIO_DEVICE_OUT_LINE) {
2404 snd_device = SND_DEVICE_OUT_LINE;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002405 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) {
2406 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE;
Eric Laurentb23d5282013-05-14 15:27:20 -07002407 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002408 if (my_data->speaker_lr_swap)
Eric Laurentb23d5282013-05-14 15:27:20 -07002409 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
2410 else
2411 snd_device = SND_DEVICE_OUT_SPEAKER;
2412 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002413 if (adev->bt_wb_speech_enabled) {
2414 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2415 } else {
2416 snd_device = SND_DEVICE_OUT_BT_SCO;
2417 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002418 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2419 snd_device = SND_DEVICE_OUT_HDMI ;
Eric Laurent99dab492017-06-17 15:19:08 -07002420 } else if (audio_is_usb_out_device(devices)) {
David Linee3fe402017-03-13 10:00:42 -07002421 if (audio_extn_usb_is_capture_supported())
2422 snd_device = SND_DEVICE_OUT_USB_HEADSET;
2423 else
2424 snd_device = SND_DEVICE_OUT_USB_HEADPHONES;
2425 }else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002426 /*HAC support for voice-ish audio (eg visual voicemail)*/
2427 if(adev->voice.hac)
2428 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2429 else
2430 snd_device = SND_DEVICE_OUT_HANDSET;
Eric Laurentb23d5282013-05-14 15:27:20 -07002431 } else {
2432 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
2433 }
2434exit:
2435 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
2436 return snd_device;
2437}
2438
2439snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
2440{
2441 struct platform_data *my_data = (struct platform_data *)platform;
2442 struct audio_device *adev = my_data->adev;
2443 audio_source_t source = (adev->active_input == NULL) ?
2444 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
2445
2446 audio_mode_t mode = adev->mode;
2447 audio_devices_t in_device = ((adev->active_input == NULL) ?
2448 AUDIO_DEVICE_NONE : adev->active_input->device)
2449 & ~AUDIO_DEVICE_BIT_IN;
2450 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
2451 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
2452 snd_device_t snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002453 int channel_count = popcount(channel_mask);
Eric Laurentb23d5282013-05-14 15:27:20 -07002454
Prashant Malanic92c5962015-08-11 15:10:18 -07002455 ALOGV("%s: enter: out_device(%#x) in_device(%#x) channel_count (%d) channel_mask (0x%x)",
2456 __func__, out_device, in_device, channel_count, channel_mask);
Devin Kimd789e432016-10-26 15:07:27 -07002457 if ((out_device != AUDIO_DEVICE_NONE) && (voice_is_in_call(adev) ||
2458 audio_extn_hfp_is_active(adev))) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002459 if (adev->voice.tty_mode != TTY_MODE_OFF) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002460 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002461 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2462 out_device & AUDIO_DEVICE_OUT_LINE) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002463 switch (adev->voice.tty_mode) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002464 case TTY_MODE_FULL:
2465 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
2466 break;
2467 case TTY_MODE_VCO:
2468 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
2469 break;
2470 case TTY_MODE_HCO:
2471 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
2472 break;
2473 default:
2474 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
2475 }
2476 goto exit;
Eric Laurent99dab492017-06-17 15:19:08 -07002477 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002478 switch (adev->voice.tty_mode) {
2479 case TTY_MODE_FULL:
2480 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC;
2481 break;
2482 case TTY_MODE_VCO:
2483 // since voice will be captured from handset mic, use existing device
2484 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
2485 break;
2486 case TTY_MODE_HCO:
2487 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC;
2488 break;
2489 default:
2490 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
Eric Laurentb23d5282013-05-14 15:27:20 -07002491 }
2492 goto exit;
2493 }
2494 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002495 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002496 if (my_data->fluence_in_voice_call == false) {
2497 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2498 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002499 if (is_operator_tmus())
2500 snd_device = SND_DEVICE_IN_VOICE_DMIC_TMUS;
Eric Laurentb23d5282013-05-14 15:27:20 -07002501 else
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002502 snd_device = SND_DEVICE_IN_VOICE_DMIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002503 }
2504 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2505 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
2506 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002507 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002508 if (adev->bluetooth_nrec)
2509 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2510 else
2511 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002512 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002513 if (adev->bluetooth_nrec)
2514 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2515 else
2516 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002517 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002518 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Prashant Malanic92c5962015-08-11 15:10:18 -07002519 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
2520 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2521 out_device & AUDIO_DEVICE_OUT_LINE) {
2522 if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
2523 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
2524 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
2525 } else {
2526 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2527 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002528 }
vivek mehtafe121d52015-08-10 23:39:23 -07002529
2530 //select default
2531 if (snd_device == SND_DEVICE_NONE) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002532 if (!adev->enable_hfp) {
2533 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2534 } else {
2535 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP;
2536 platform_set_echo_reference(adev, true, out_device);
2537 }
vivek mehtafe121d52015-08-10 23:39:23 -07002538 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002539 } else if (out_device & AUDIO_DEVICE_OUT_TELEPHONY_TX) {
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002540 snd_device = SND_DEVICE_IN_VOICE_RX;
Eric Laurent99dab492017-06-17 15:19:08 -07002541 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002542 if (audio_extn_usb_is_capture_supported()) {
2543 snd_device = SND_DEVICE_IN_VOICE_USB_HEADSET_MIC;
2544 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002545 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002546 } else if (source == AUDIO_SOURCE_CAMCORDER) {
2547 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
2548 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2549 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
2550 }
2551 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
2552 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002553 if (my_data->fluence_in_voice_rec && channel_count == 1) {
2554 if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2555 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002556 if (adev->active_input->enable_aec)
2557 snd_device = SND_DEVICE_IN_HANDSET_QMIC_AEC;
2558 else
2559 snd_device = SND_DEVICE_IN_HANDSET_QMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002560 } else if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2561 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002562 if (adev->active_input->enable_aec)
2563 snd_device = SND_DEVICE_IN_HANDSET_TMIC_AEC;
2564 else
2565 snd_device = SND_DEVICE_IN_HANDSET_TMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002566 } else if (((my_data->fluence_type == FLUENCE_PRO_ENABLE) ||
2567 (my_data->fluence_type == FLUENCE_ENABLE)) &&
2568 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002569 if (adev->active_input->enable_aec)
2570 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
2571 else
2572 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
Prashant Malanic92c5962015-08-11 15:10:18 -07002573 }
2574 platform_set_echo_reference(adev, true, out_device);
2575 } else if ((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) &&
2576 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2577 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002578 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002579 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
2580 snd_device = SND_DEVICE_IN_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002581 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002582 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2583 snd_device = SND_DEVICE_IN_QUAD_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002584 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002585 if (snd_device == SND_DEVICE_NONE) {
vivek mehtaf3440682016-05-11 14:24:37 -07002586 if (adev->active_input->enable_aec) {
2587 if (adev->active_input->enable_ns) {
2588 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS;
2589 } else {
2590 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC;
2591 }
vivek mehta733c1df2016-04-04 15:09:24 -07002592 platform_set_echo_reference(adev, true, out_device);
vivek mehtaf3440682016-05-11 14:24:37 -07002593 } else if (adev->active_input->enable_ns) {
2594 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
2595 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002596 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
vivek mehtaf3440682016-05-11 14:24:37 -07002597 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002598 }
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -07002599 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2600 snd_device = SND_DEVICE_IN_VOICE_REC_HEADSET_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07002601 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002602 snd_device = SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002603 }
rago90fb9612015-12-02 11:37:53 -08002604 } else if (source == AUDIO_SOURCE_UNPROCESSED) {
2605 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
vivek mehta4ed66e62016-04-15 23:33:34 -07002606 if (((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) ||
2607 (channel_mask == AUDIO_CHANNEL_IN_STEREO)) &&
2608 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2609 snd_device = SND_DEVICE_IN_UNPROCESSED_STEREO_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002610 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07002611 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
2612 snd_device = SND_DEVICE_IN_UNPROCESSED_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002613 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07002614 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2615 snd_device = SND_DEVICE_IN_UNPROCESSED_QUAD_MIC;
2616 } else {
2617 snd_device = SND_DEVICE_IN_UNPROCESSED_MIC;
2618 }
rago90fb9612015-12-02 11:37:53 -08002619 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2620 snd_device = SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07002621 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002622 snd_device = SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC;
rago90fb9612015-12-02 11:37:53 -08002623 }
Eric Laurent50a38ed2015-10-14 18:48:06 -07002624 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION ||
rago90fb9612015-12-02 11:37:53 -08002625 mode == AUDIO_MODE_IN_COMMUNICATION) {
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002626 if (out_device & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE))
Eric Laurentb23d5282013-05-14 15:27:20 -07002627 in_device = AUDIO_DEVICE_IN_BACK_MIC;
2628 if (adev->active_input) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002629 if (adev->active_input->enable_aec &&
2630 adev->active_input->enable_ns) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002631 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002632 if (my_data->fluence_in_spkr_mode &&
2633 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002634 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002635 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002636 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002637 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002638 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002639 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002640 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002641 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002642 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002643 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002644 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002645 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002646 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2647 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Eric Laurent99dab492017-06-17 15:19:08 -07002648 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002649 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002650 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002651 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002652 } else if (adev->active_input->enable_aec) {
2653 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2654 if (my_data->fluence_in_spkr_mode &&
2655 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002656 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002657 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002658 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002659 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002660 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002661 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2662 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002663 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002664 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002665 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002666 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002667 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002668 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2669 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Eric Laurent99dab492017-06-17 15:19:08 -07002670 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002671 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
Eric Laurentcefbbac2014-09-04 13:54:10 -05002672 }
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08002673 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002674 } else if (adev->active_input->enable_ns) {
2675 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2676 if (my_data->fluence_in_spkr_mode &&
2677 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002678 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002679 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002680 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002681 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002682 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002683 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2684 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002685 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002686 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002687 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002688 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002689 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002690 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002691 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002692 }
2693 } else if (source == AUDIO_SOURCE_DEFAULT) {
2694 goto exit;
2695 }
2696
2697
2698 if (snd_device != SND_DEVICE_NONE) {
2699 goto exit;
2700 }
2701
2702 if (in_device != AUDIO_DEVICE_NONE &&
2703 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
2704 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
2705 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002706 if ((my_data->source_mic_type & SOURCE_QUAD_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002707 channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002708 snd_device = SND_DEVICE_IN_QUAD_MIC;
2709 } else if ((my_data->source_mic_type & SOURCE_THREE_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002710 channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002711 snd_device = SND_DEVICE_IN_THREE_MIC;
2712 } else if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2713 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002714 snd_device = SND_DEVICE_IN_HANDSET_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002715 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2716 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002717 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002718 } else {
2719 ALOGE("%s: something wrong (1): source type (%d) channel_count (%d) .."
2720 " channel mask (0x%x) no combination found .. setting to mono", __func__,
2721 my_data->source_mic_type, channel_count, channel_mask);
2722 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2723 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002724 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002725 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2726 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002727 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002728 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2729 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002730 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002731 } else {
2732 ALOGE("%s: something wrong (2): source type (%d) channel_count (%d) .."
2733 " no combination found .. setting to mono", __func__,
2734 my_data->source_mic_type, channel_count);
2735 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
2736 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002737 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2738 snd_device = SND_DEVICE_IN_HEADSET_MIC;
2739 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002740 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002741 if (adev->bluetooth_nrec)
2742 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2743 else
2744 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002745 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002746 if (adev->bluetooth_nrec)
2747 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2748 else
2749 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002750 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002751 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
2752 snd_device = SND_DEVICE_IN_HDMI_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07002753 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
David Linee3fe402017-03-13 10:00:42 -07002754 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002755 } else {
2756 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
2757 ALOGW("%s: Using default handset-mic", __func__);
2758 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2759 }
2760 } else {
2761 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
2762 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2763 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2764 snd_device = SND_DEVICE_IN_HEADSET_MIC;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002765 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002766 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002767 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002768 out_device & AUDIO_DEVICE_OUT_LINE) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002769 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2770 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002771 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002772 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2773 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002774 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002775 } else {
2776 ALOGE("%s: something wrong (3): source type (%d) channel_count (%d) .."
2777 " no combination found .. setting to mono", __func__,
2778 my_data->source_mic_type, channel_count);
2779 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
2780 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002781 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002782 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002783 if (adev->bluetooth_nrec)
2784 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2785 else
2786 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002787 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002788 if (adev->bluetooth_nrec)
2789 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2790 else
2791 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002792 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002793 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2794 snd_device = SND_DEVICE_IN_HDMI_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07002795 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
David Linee3fe402017-03-13 10:00:42 -07002796 if (audio_extn_usb_is_capture_supported())
2797 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
2798 else
2799 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002800 } else {
2801 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
2802 ALOGW("%s: Using default handset-mic", __func__);
2803 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2804 }
2805 }
2806exit:
2807 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
2808 return snd_device;
2809}
2810
2811int platform_set_hdmi_channels(void *platform, int channel_count)
2812{
2813 struct platform_data *my_data = (struct platform_data *)platform;
2814 struct audio_device *adev = my_data->adev;
2815 struct mixer_ctl *ctl;
2816 const char *channel_cnt_str = NULL;
2817 const char *mixer_ctl_name = "HDMI_RX Channels";
2818 switch (channel_count) {
2819 case 8:
2820 channel_cnt_str = "Eight"; break;
2821 case 7:
2822 channel_cnt_str = "Seven"; break;
2823 case 6:
2824 channel_cnt_str = "Six"; break;
2825 case 5:
2826 channel_cnt_str = "Five"; break;
2827 case 4:
2828 channel_cnt_str = "Four"; break;
2829 case 3:
2830 channel_cnt_str = "Three"; break;
2831 default:
2832 channel_cnt_str = "Two"; break;
2833 }
2834 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2835 if (!ctl) {
2836 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2837 __func__, mixer_ctl_name);
2838 return -EINVAL;
2839 }
2840 ALOGV("HDMI channel count: %s", channel_cnt_str);
2841 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
2842 return 0;
2843}
2844
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002845int platform_edid_get_max_channels(void *platform)
Eric Laurentb23d5282013-05-14 15:27:20 -07002846{
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002847 struct platform_data *my_data = (struct platform_data *)platform;
2848 struct audio_device *adev = my_data->adev;
Eric Laurentb23d5282013-05-14 15:27:20 -07002849 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
2850 char *sad = block;
2851 int num_audio_blocks;
2852 int channel_count;
2853 int max_channels = 0;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002854 int i, ret, count;
Eric Laurentb23d5282013-05-14 15:27:20 -07002855
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002856 struct mixer_ctl *ctl;
2857
2858 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
2859 if (!ctl) {
2860 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2861 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
Eric Laurentb23d5282013-05-14 15:27:20 -07002862 return 0;
2863 }
2864
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002865 mixer_ctl_update(ctl);
2866
2867 count = mixer_ctl_get_num_values(ctl);
Eric Laurentb23d5282013-05-14 15:27:20 -07002868
2869 /* Read SAD blocks, clamping the maximum size for safety */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002870 if (count > (int)sizeof(block))
2871 count = (int)sizeof(block);
Eric Laurentb23d5282013-05-14 15:27:20 -07002872
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002873 ret = mixer_ctl_get_array(ctl, block, count);
2874 if (ret != 0) {
2875 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
2876 return 0;
2877 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002878
2879 /* Calculate the number of SAD blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002880 num_audio_blocks = count / SAD_BLOCK_SIZE;
Eric Laurentb23d5282013-05-14 15:27:20 -07002881
2882 for (i = 0; i < num_audio_blocks; i++) {
2883 /* Only consider LPCM blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002884 if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
2885 sad += 3;
Eric Laurentb23d5282013-05-14 15:27:20 -07002886 continue;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002887 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002888
2889 channel_count = (sad[0] & 0x7) + 1;
2890 if (channel_count > max_channels)
2891 max_channels = channel_count;
2892
2893 /* Advance to next block */
2894 sad += 3;
2895 }
2896
2897 return max_channels;
2898}
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07002899
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002900int platform_set_incall_recording_session_id(void *platform,
2901 uint32_t session_id, int rec_mode)
2902{
2903 int ret = 0;
2904 struct platform_data *my_data = (struct platform_data *)platform;
2905 struct audio_device *adev = my_data->adev;
2906 struct mixer_ctl *ctl;
2907 const char *mixer_ctl_name = "Voc VSID";
2908 int num_ctl_values;
2909 int i;
2910
2911 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2912 if (!ctl) {
2913 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2914 __func__, mixer_ctl_name);
2915 ret = -EINVAL;
2916 } else {
2917 num_ctl_values = mixer_ctl_get_num_values(ctl);
2918 for (i = 0; i < num_ctl_values; i++) {
2919 if (mixer_ctl_set_value(ctl, i, session_id)) {
2920 ALOGV("Error: invalid session_id: %x", session_id);
2921 ret = -EINVAL;
2922 break;
2923 }
2924 }
2925 }
2926
2927 if (my_data->csd != NULL) {
2928 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
2929 if (ret < 0) {
2930 ALOGE("%s: csd_client_start_record failed, error %d",
2931 __func__, ret);
2932 }
2933 }
2934
2935 return ret;
2936}
2937
2938int platform_stop_incall_recording_usecase(void *platform)
2939{
2940 int ret = 0;
2941 struct platform_data *my_data = (struct platform_data *)platform;
2942
2943 if (my_data->csd != NULL) {
2944 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
2945 if (ret < 0) {
2946 ALOGE("%s: csd_client_stop_record failed, error %d",
2947 __func__, ret);
2948 }
2949 }
2950
2951 return ret;
2952}
2953
2954int platform_start_incall_music_usecase(void *platform)
2955{
2956 int ret = 0;
2957 struct platform_data *my_data = (struct platform_data *)platform;
2958
2959 if (my_data->csd != NULL) {
2960 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
2961 if (ret < 0) {
2962 ALOGE("%s: csd_client_start_playback failed, error %d",
2963 __func__, ret);
2964 }
2965 }
2966
2967 return ret;
2968}
2969
2970int platform_stop_incall_music_usecase(void *platform)
2971{
2972 int ret = 0;
2973 struct platform_data *my_data = (struct platform_data *)platform;
2974
2975 if (my_data->csd != NULL) {
2976 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
2977 if (ret < 0) {
2978 ALOGE("%s: csd_client_stop_playback failed, error %d",
2979 __func__, ret);
2980 }
2981 }
2982
2983 return ret;
2984}
2985
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002986int platform_set_parameters(void *platform, struct str_parms *parms)
2987{
2988 struct platform_data *my_data = (struct platform_data *)platform;
keunhui.park2f7306a2015-07-16 16:48:06 +09002989 char value[128];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002990 char *kv_pairs = str_parms_to_str(parms);
2991 int ret = 0, err;
2992
2993 if (kv_pairs == NULL) {
2994 ret = -EINVAL;
2995 ALOGE("%s: key-value pair is NULL",__func__);
2996 goto done;
2997 }
2998
2999 ALOGV("%s: enter: %s", __func__, kv_pairs);
3000
3001 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME,
3002 value, sizeof(value));
3003 if (err >= 0) {
3004 str_parms_del(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME);
3005 my_data->snd_card_name = strdup(value);
3006 ALOGV("%s: sound card name %s", __func__, my_data->snd_card_name);
3007 }
3008
keunhui.park2f7306a2015-07-16 16:48:06 +09003009 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO,
3010 value, sizeof(value));
3011 if (err >= 0) {
3012 struct operator_info *info;
3013 char *str = value;
3014 char *name;
3015
3016 str_parms_del(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO);
3017 info = (struct operator_info *)calloc(1, sizeof(struct operator_info));
3018 name = strtok(str, ";");
3019 info->name = strdup(name);
3020 info->mccmnc = strdup(str + strlen(name) + 1);
3021
3022 list_add_tail(&operator_info_list, &info->list);
Joe Onorato188b6222016-03-01 11:02:27 -08003023 ALOGV("%s: add operator[%s] mccmnc[%s]", __func__, info->name, info->mccmnc);
keunhui.park2f7306a2015-07-16 16:48:06 +09003024 }
Prashant Malanic92c5962015-08-11 15:10:18 -07003025
3026 memset(value, 0, sizeof(value));
Eric Laurentc6333382015-09-14 12:43:44 -07003027 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT,
Prashant Malanic92c5962015-08-11 15:10:18 -07003028 value, sizeof(value));
3029 if (err >= 0) {
Eric Laurentc6333382015-09-14 12:43:44 -07003030 str_parms_del(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT);
Prashant Malanic92c5962015-08-11 15:10:18 -07003031 my_data->max_mic_count = atoi(value);
3032 ALOGV("%s: max_mic_count %s/%d", __func__, value, my_data->max_mic_count);
Prashant Malanic92c5962015-08-11 15:10:18 -07003033 }
3034
vivek mehta90933872017-06-15 18:04:39 -07003035 // to-do: disable setting sidetone gain, will revist this later
3036 // audio_extn_usb_set_sidetone_gain(parms, value, len);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003037done:
3038 ALOGV("%s: exit with code(%d)", __func__, ret);
3039 if (kv_pairs != NULL)
3040 free(kv_pairs);
3041
3042 return ret;
3043}
3044
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003045/* Delay in Us */
3046int64_t platform_render_latency(audio_usecase_t usecase)
3047{
3048 switch (usecase) {
3049 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
3050 return DEEP_BUFFER_PLATFORM_DELAY;
3051 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
3052 return LOW_LATENCY_PLATFORM_DELAY;
Haynes Mathew George03c40102016-01-29 17:57:48 -08003053 case USECASE_AUDIO_PLAYBACK_ULL:
3054 return ULL_PLATFORM_DELAY;
Eric Laurent0e46adf2016-12-16 12:49:24 -08003055 case USECASE_AUDIO_PLAYBACK_MMAP:
3056 return MMAP_PLATFORM_DELAY;
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003057 default:
3058 return 0;
3059 }
3060}
Haynes Mathew George98c95622014-06-20 19:14:25 -07003061
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003062int platform_set_snd_device_backend(snd_device_t device, const char *backend_tag,
3063 const char * hw_interface)
Haynes Mathew George98c95622014-06-20 19:14:25 -07003064{
3065 int ret = 0;
3066
3067 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
3068 ALOGE("%s: Invalid snd_device = %d",
3069 __func__, device);
3070 ret = -EINVAL;
3071 goto done;
3072 }
3073
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003074 ALOGV("%s: backend_tag_table[%s]: old = %s new = %s", __func__,
3075 platform_get_snd_device_name(device),
3076 backend_tag_table[device] != NULL ? backend_tag_table[device]: "null", backend_tag);
3077 if (backend_tag_table[device]) {
3078 free(backend_tag_table[device]);
Haynes Mathew George98c95622014-06-20 19:14:25 -07003079 }
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003080 backend_tag_table[device] = strdup(backend_tag);
3081
3082 if (hw_interface != NULL) {
3083 if (hw_interface_table[device])
3084 free(hw_interface_table[device]);
3085 ALOGV("%s: hw_interface_table[%d] = %s", __func__, device, hw_interface);
3086 hw_interface_table[device] = strdup(hw_interface);
3087 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07003088done:
3089 return ret;
3090}
3091
3092int platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t pcm_id)
3093{
3094 int ret = 0;
3095 if ((usecase <= USECASE_INVALID) || (usecase >= AUDIO_USECASE_MAX)) {
3096 ALOGE("%s: invalid usecase case idx %d", __func__, usecase);
3097 ret = -EINVAL;
3098 goto done;
3099 }
3100
3101 if ((type != 0) && (type != 1)) {
3102 ALOGE("%s: invalid usecase type", __func__);
3103 ret = -EINVAL;
3104 }
vivek mehtaa68fea62017-06-08 19:04:02 -07003105 ALOGV("%s: pcm_device_table[%d %s][%d] = %d", __func__, usecase,
3106 use_case_table[usecase],
3107 type, pcm_id);
Haynes Mathew George98c95622014-06-20 19:14:25 -07003108 pcm_device_table[usecase][type] = pcm_id;
3109done:
3110 return ret;
3111}
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003112
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07003113#define DEFAULT_NOMINAL_SPEAKER_GAIN 20
3114int ramp_speaker_gain(struct audio_device *adev, bool ramp_up, int target_ramp_up_gain) {
3115 // backup_gain: gain to try to set in case of an error during ramp
3116 int start_gain, end_gain, step, backup_gain, i;
3117 bool error = false;
3118 const struct mixer_ctl *ctl;
3119 const char *mixer_ctl_name_gain_left = "Left Speaker Gain";
3120 const char *mixer_ctl_name_gain_right = "Right Speaker Gain";
3121 struct mixer_ctl *ctl_left = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_left);
3122 struct mixer_ctl *ctl_right = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_right);
3123 if (!ctl_left || !ctl_right) {
3124 ALOGE("%s: Could not get ctl for mixer cmd - %s or %s, not applying speaker gain ramp",
3125 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
3126 return -EINVAL;
3127 } else if ((mixer_ctl_get_num_values(ctl_left) != 1)
3128 || (mixer_ctl_get_num_values(ctl_right) != 1)) {
3129 ALOGE("%s: Unexpected num values for mixer cmd - %s or %s, not applying speaker gain ramp",
3130 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
3131 return -EINVAL;
3132 }
3133 if (ramp_up) {
3134 start_gain = 0;
3135 end_gain = target_ramp_up_gain > 0 ? target_ramp_up_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
3136 step = +1;
3137 backup_gain = end_gain;
3138 } else {
3139 // using same gain on left and right
3140 const int left_gain = mixer_ctl_get_value(ctl_left, 0);
3141 start_gain = left_gain > 0 ? left_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
3142 end_gain = 0;
3143 step = -1;
3144 backup_gain = start_gain;
3145 }
3146 for (i = start_gain ; i != (end_gain + step) ; i += step) {
3147 //ALOGV("setting speaker gain to %d", i);
3148 if (mixer_ctl_set_value(ctl_left, 0, i)) {
3149 ALOGE("%s: error setting %s to %d during gain ramp",
3150 __func__, mixer_ctl_name_gain_left, i);
3151 error = true;
3152 break;
3153 }
3154 if (mixer_ctl_set_value(ctl_right, 0, i)) {
3155 ALOGE("%s: error setting %s to %d during gain ramp",
3156 __func__, mixer_ctl_name_gain_right, i);
3157 error = true;
3158 break;
3159 }
3160 usleep(1000);
3161 }
3162 if (error) {
3163 // an error occured during the ramp, let's still try to go back to a safe volume
3164 if (mixer_ctl_set_value(ctl_left, 0, backup_gain)) {
3165 ALOGE("%s: error restoring left gain to %d", __func__, backup_gain);
3166 }
3167 if (mixer_ctl_set_value(ctl_right, 0, backup_gain)) {
3168 ALOGE("%s: error restoring right gain to %d", __func__, backup_gain);
3169 }
3170 }
3171 return start_gain;
3172}
3173
vivek mehtae59cfb22017-06-16 15:57:11 -07003174int platform_set_swap_mixer(struct audio_device *adev, bool swap_channels)
3175{
3176 const char *mixer_ctl_name = "Swap channel";
3177 struct mixer_ctl *ctl;
3178 const char *mixer_path;
3179 struct platform_data *my_data = (struct platform_data *)adev->platform;
3180
3181 // forced to set to swap, but device not rotated ... ignore set
3182 if (swap_channels && !my_data->speaker_lr_swap)
3183 return 0;
3184
3185 ALOGV("%s:", __func__);
3186
3187 if (swap_channels) {
3188 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER_REVERSE);
3189 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
3190 } else {
3191 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER);
3192 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
3193 }
3194
3195 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3196 if (!ctl) {
3197 ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name);
3198 return -EINVAL;
3199 }
3200
3201 if (mixer_ctl_set_value(ctl, 0, swap_channels) < 0) {
3202 ALOGE("%s: Could not set reverse cotrol %d",__func__, swap_channels);
3203 return -EINVAL;
3204 }
3205
3206 ALOGV("platfor_force_swap_channel :: Channel orientation ( %s ) ",
3207 swap_channels?"R --> L":"L --> R");
3208
3209 return 0;
3210}
3211
3212int platform_check_and_set_swap_lr_channels(struct audio_device *adev, bool swap_channels)
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003213{
3214 // only update if there is active pcm playback on speaker
3215 struct audio_usecase *usecase;
3216 struct listnode *node;
3217 struct platform_data *my_data = (struct platform_data *)adev->platform;
3218
vivek mehtae59cfb22017-06-16 15:57:11 -07003219 my_data->speaker_lr_swap = swap_channels;
Jean-Michel Trivif7148702016-09-16 18:23:05 -07003220
vivek mehtae59cfb22017-06-16 15:57:11 -07003221 return platform_set_swap_channels(adev, swap_channels);
3222}
Jean-Michel Trivif7148702016-09-16 18:23:05 -07003223
vivek mehtae59cfb22017-06-16 15:57:11 -07003224int platform_set_swap_channels(struct audio_device *adev, bool swap_channels)
3225{
3226 // only update if there is active pcm playback on speaker
3227 struct audio_usecase *usecase;
3228 struct listnode *node;
3229 struct platform_data *my_data = (struct platform_data *)adev->platform;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003230
vivek mehtae59cfb22017-06-16 15:57:11 -07003231 // do not swap channels in audio modes with concurrent capture and playback
3232 // as this may break the echo reference
3233 if ((adev->mode == AUDIO_MODE_IN_COMMUNICATION) || (adev->mode == AUDIO_MODE_IN_CALL)) {
3234 ALOGV("%s: will not swap due to audio mode %d", __func__, adev->mode);
3235 return 0;
3236 }
3237
3238 list_for_each(node, &adev->usecase_list) {
3239 usecase = node_to_item(node, struct audio_usecase, list);
3240 if (usecase->type == PCM_PLAYBACK &&
3241 usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) {
3242 /*
3243 * If acdb tuning is different for SPEAKER_REVERSE, it is must
3244 * to perform device switch to disable the current backend to
3245 * enable it with new acdb data.
3246 */
3247 if (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
3248 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]) {
3249 const int initial_skpr_gain = ramp_speaker_gain(adev, false /*ramp_up*/, -1);
3250 select_devices(adev, usecase->id);
3251 if (initial_skpr_gain != -EINVAL)
3252 ramp_speaker_gain(adev, true /*ramp_up*/, initial_skpr_gain);
3253
3254 } else {
3255 platform_set_swap_mixer(adev, swap_channels);
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003256 }
vivek mehtae59cfb22017-06-16 15:57:11 -07003257 break;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003258 }
3259 }
vivek mehtae59cfb22017-06-16 15:57:11 -07003260
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003261 return 0;
3262}
vivek mehtaa8d7c922016-05-25 14:40:44 -07003263
3264static struct amp_db_and_gain_table tbl_mapping[MAX_VOLUME_CAL_STEPS];
3265static int num_gain_tbl_entry = 0;
3266
3267bool platform_add_gain_level_mapping(struct amp_db_and_gain_table *tbl_entry) {
3268
3269 ALOGV("%s: enter .. add %f %f %d", __func__, tbl_entry->amp, tbl_entry->db, tbl_entry->level);
3270 if (num_gain_tbl_entry == -1) {
3271 ALOGE("%s: num entry beyond valid step levels or corrupted..rejecting custom mapping",
3272 __func__);
3273 return false;
3274 }
3275
3276 if (num_gain_tbl_entry >= MAX_VOLUME_CAL_STEPS) {
3277 ALOGE("%s: max entry reached max[%d] current index[%d] .. rejecting", __func__,
3278 MAX_VOLUME_CAL_STEPS, num_gain_tbl_entry);
3279 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
3280 return false;
3281 }
3282
3283 if (num_gain_tbl_entry > 0 && tbl_mapping[num_gain_tbl_entry - 1].amp >= tbl_entry->amp) {
3284 ALOGE("%s: value not in ascending order .. rejecting custom mapping", __func__);
3285 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
3286 return false;
3287 }
3288
3289 tbl_mapping[num_gain_tbl_entry] = *tbl_entry;
3290 ++num_gain_tbl_entry;
3291
3292 return true;
3293}
3294
3295int platform_get_gain_level_mapping(struct amp_db_and_gain_table *mapping_tbl,
3296 int table_size) {
3297 int itt = 0;
3298 ALOGV("platform_get_gain_level_mapping called ");
3299
3300 if (num_gain_tbl_entry <= 0 || num_gain_tbl_entry > MAX_VOLUME_CAL_STEPS) {
3301 ALOGD("%s: empty or currupted gain_mapping_table", __func__);
3302 return 0;
3303 }
3304
3305 for (; itt < num_gain_tbl_entry && itt <= table_size; itt++) {
3306 mapping_tbl[itt] = tbl_mapping[itt];
3307 ALOGV("%s: added amp[%f] db[%f] level[%d]", __func__,
3308 mapping_tbl[itt].amp, mapping_tbl[itt].db, mapping_tbl[itt].level);
3309 }
3310
3311 return num_gain_tbl_entry;
3312}
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07003313
3314int platform_snd_card_update(void *platform, card_status_t status)
3315{
3316 struct platform_data *my_data = (struct platform_data *)platform;
3317 struct audio_device *adev = my_data->adev;
3318
3319 if (status == CARD_STATUS_ONLINE) {
3320 if (my_data->acdb_send_custom_top)
3321 my_data->acdb_send_custom_top();
3322 }
3323 return 0;
3324}
David Linee3fe402017-03-13 10:00:42 -07003325
3326/*
3327 * configures afe with bit width and Sample Rate
3328 */
3329static int platform_set_backend_cfg(const struct audio_device* adev,
3330 snd_device_t snd_device,
3331 const struct audio_backend_cfg *backend_cfg)
3332{
3333
3334 int ret = 0;
3335 const int backend_idx = platform_get_backend_index(snd_device);
3336 struct platform_data *my_data = (struct platform_data *)adev->platform;
3337 const unsigned int bit_width = backend_cfg->bit_width;
3338 const unsigned int sample_rate = backend_cfg->sample_rate;
3339 const unsigned int channels = backend_cfg->channels;
3340 const audio_format_t format = backend_cfg->format;
3341 const bool passthrough_enabled = backend_cfg->passthrough_enabled;
3342
3343
3344 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
3345 ", backend_idx %d device (%s)", __func__, bit_width,
3346 sample_rate, channels, backend_idx,
3347 platform_get_snd_device_name(snd_device));
3348
3349 if ((my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl) &&
3350 (bit_width != my_data->current_backend_cfg[backend_idx].bit_width)) {
3351
3352 struct mixer_ctl *ctl = NULL;
3353 ctl = mixer_get_ctl_by_name(adev->mixer,
3354 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
3355 if (!ctl) {
3356 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3357 __func__,
3358 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
3359 return -EINVAL;
3360 }
3361
3362 if (bit_width == 24) {
3363 if (format == AUDIO_FORMAT_PCM_24_BIT_PACKED)
3364 ret = mixer_ctl_set_enum_by_string(ctl, "S24_3LE");
3365 else
3366 ret = mixer_ctl_set_enum_by_string(ctl, "S24_LE");
3367 } else if (bit_width == 32) {
3368 ret = mixer_ctl_set_enum_by_string(ctl, "S32_LE");
3369 } else {
3370 ret = mixer_ctl_set_enum_by_string(ctl, "S16_LE");
3371 }
3372 if ( ret < 0) {
3373 ALOGE("%s:becf: afe: fail for %s mixer set to %d bit for %x format", __func__,
3374 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
3375 } else {
3376 my_data->current_backend_cfg[backend_idx].bit_width = bit_width;
3377 ALOGD("%s:becf: afe: %s mixer set to %d bit for %x format", __func__,
3378 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
3379 }
3380 /* set the ret as 0 and not pass back to upper layer */
3381 ret = 0;
3382 }
3383
3384 if (passthrough_enabled || ((my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl) &&
3385 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate))) {
3386 char *rate_str = NULL;
3387 struct mixer_ctl *ctl = NULL;
3388
3389 switch (sample_rate) {
3390 case 32000:
3391 if (passthrough_enabled) {
3392 rate_str = "KHZ_32";
3393 break;
3394 }
3395 case 8000:
3396 case 11025:
3397 case 16000:
3398 case 22050:
3399 case 48000:
3400 rate_str = "KHZ_48";
3401 break;
3402 case 44100:
3403 rate_str = "KHZ_44P1";
3404 break;
3405 case 64000:
3406 case 96000:
3407 rate_str = "KHZ_96";
3408 break;
3409 case 88200:
3410 rate_str = "KHZ_88P2";
3411 break;
3412 case 176400:
3413 rate_str = "KHZ_176P4";
3414 break;
3415 case 192000:
3416 rate_str = "KHZ_192";
3417 break;
3418 case 352800:
3419 rate_str = "KHZ_352P8";
3420 break;
3421 case 384000:
3422 rate_str = "KHZ_384";
3423 break;
3424 case 144000:
3425 if (passthrough_enabled) {
3426 rate_str = "KHZ_144";
3427 break;
3428 }
3429 default:
3430 rate_str = "KHZ_48";
3431 break;
3432 }
3433
3434 ctl = mixer_get_ctl_by_name(adev->mixer,
3435 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
3436 if(!ctl) {
3437 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3438 __func__,
3439 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
3440 return -EINVAL;
3441 }
3442
3443 ALOGD("%s:becf: afe: %s set to %s", __func__,
3444 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl, rate_str);
3445 mixer_ctl_set_enum_by_string(ctl, rate_str);
3446 my_data->current_backend_cfg[backend_idx].sample_rate = sample_rate;
3447 }
3448 if ((my_data->current_backend_cfg[backend_idx].channels_mixer_ctl) &&
3449 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
3450 struct mixer_ctl *ctl = NULL;
3451 char *channel_cnt_str = NULL;
3452
3453 switch (channels) {
3454 case 8:
3455 channel_cnt_str = "Eight"; break;
3456 case 7:
3457 channel_cnt_str = "Seven"; break;
3458 case 6:
3459 channel_cnt_str = "Six"; break;
3460 case 5:
3461 channel_cnt_str = "Five"; break;
3462 case 4:
3463 channel_cnt_str = "Four"; break;
3464 case 3:
3465 channel_cnt_str = "Three"; break;
3466 case 1:
3467 channel_cnt_str = "One"; break;
3468 case 2:
3469 default:
3470 channel_cnt_str = "Two"; break;
3471 }
3472
3473 ctl = mixer_get_ctl_by_name(adev->mixer,
3474 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
3475 if (!ctl) {
3476 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3477 __func__,
3478 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
3479 return -EINVAL;
3480 }
3481 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
3482 my_data->current_backend_cfg[backend_idx].channels = channels;
3483
3484 // skip EDID configuration for HDMI backend
3485
3486 ALOGD("%s:becf: afe: %s set to %s", __func__,
3487 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl,
3488 channel_cnt_str);
3489 }
3490
3491 // skip set ext_display format mixer control
3492 return ret;
3493}
3494
3495static int platform_get_snd_device_bit_width(snd_device_t snd_device)
3496{
3497 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
3498 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
3499 return CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3500 }
3501
3502 return backend_bit_width_table[snd_device];
3503}
3504
3505/*
3506 * return backend_idx on which voice call is active
3507 */
3508static int platform_get_voice_call_backend(struct audio_device* adev)
3509{
3510 struct audio_usecase *uc = NULL;
3511 struct listnode *node;
3512 snd_device_t out_snd_device = SND_DEVICE_NONE;
3513
3514 int backend_idx = -1;
3515
3516 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
3517 list_for_each(node, &adev->usecase_list) {
3518 uc = node_to_item(node, struct audio_usecase, list);
3519 if (uc && uc->type == VOICE_CALL && uc->stream.out) {
3520 out_snd_device = platform_get_output_snd_device(adev->platform,
3521 uc->stream.out->devices);
3522 backend_idx = platform_get_backend_index(out_snd_device);
3523 break;
3524 }
3525 }
3526 }
3527 return backend_idx;
3528}
3529
3530/*
3531 * goes through all the current usecases and picks the highest
3532 * bitwidth & samplerate
3533 */
3534static bool platform_check_capture_backend_cfg(struct audio_device* adev,
3535 int backend_idx,
3536 struct audio_backend_cfg *backend_cfg)
3537{
3538 bool backend_change = false;
3539 unsigned int bit_width;
3540 unsigned int sample_rate;
3541 unsigned int channels;
3542 struct platform_data *my_data = (struct platform_data *)adev->platform;
3543
3544 bit_width = backend_cfg->bit_width;
3545 sample_rate = backend_cfg->sample_rate;
3546 channels = backend_cfg->channels;
3547
3548 ALOGV("%s:txbecf: afe: Codec selected backend: %d current bit width: %d and "
3549 "sample rate: %d, channels %d",__func__,backend_idx, bit_width,
3550 sample_rate, channels);
3551
3552 // For voice calls use default configuration i.e. 16b/48K, only applicable to
3553 // default backend
3554 // force routing is not required here, caller will do it anyway
3555 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
3556 ALOGW("%s:txbecf: afe: Use default bw and sr for voice/voip calls and "
3557 "for unprocessed/camera source", __func__);
3558 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3559 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3560 }
3561
3562 if (backend_idx == USB_AUDIO_TX_BACKEND) {
3563 audio_extn_usb_is_config_supported(&bit_width, &sample_rate, &channels, false);
3564 ALOGV("%s:txbecf: afe: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
3565 __func__, bit_width, sample_rate, channels);
3566 }
3567
3568 ALOGV("%s:txbecf: afe: Codec selected backend: %d updated bit width: %d and "
3569 "sample rate: %d", __func__, backend_idx, bit_width, sample_rate);
3570
3571 // Force routing if the expected bitwdith or samplerate
3572 // is not same as current backend comfiguration
3573 if ((bit_width != my_data->current_backend_cfg[backend_idx].bit_width) ||
3574 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate) ||
3575 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
3576 backend_cfg->bit_width = bit_width;
3577 backend_cfg->sample_rate= sample_rate;
3578 backend_cfg->channels = channels;
3579 backend_change = true;
3580 ALOGI("%s:txbecf: afe: Codec backend needs to be updated. new bit width: %d "
3581 "new sample rate: %d new channel: %d",
3582 __func__, backend_cfg->bit_width,
3583 backend_cfg->sample_rate, backend_cfg->channels);
3584 }
3585
3586 return backend_change;
3587}
3588
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003589static void pick_playback_cfg_for_uc(struct audio_device *adev,
3590 struct audio_usecase *usecase,
3591 snd_device_t snd_device,
3592 unsigned int *bit_width,
3593 unsigned int *sample_rate,
3594 unsigned int *channels)
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003595{
3596 int i =0;
3597 struct listnode *node;
3598 list_for_each(node, &adev->usecase_list) {
3599 struct audio_usecase *uc;
3600 uc = node_to_item(node, struct audio_usecase, list);
3601 struct stream_out *out = (struct stream_out*) uc->stream.out;
3602 if (uc->type == PCM_PLAYBACK && out && usecase != uc) {
3603 unsigned int out_channels = audio_channel_count_from_out_mask(out->channel_mask);
3604 ALOGV("%s:napb: (%d) - (%s)id (%d) sr %d bw "
3605 "(%d) ch (%d) device %s", __func__, i++, use_case_table[uc->id],
3606 uc->id, out->sample_rate,
3607 pcm_format_to_bits(out->config.format), out_channels,
3608 platform_get_snd_device_name(uc->out_snd_device));
3609
3610 if (platform_check_backends_match(snd_device, uc->out_snd_device)) {
3611 if (*bit_width < pcm_format_to_bits(out->config.format))
3612 *bit_width = pcm_format_to_bits(out->config.format);
3613 if (*sample_rate < out->sample_rate)
3614 *sample_rate = out->sample_rate;
3615 if (out->sample_rate < OUTPUT_SAMPLING_RATE_44100)
3616 *sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3617 if (*channels < out_channels)
3618 *channels = out_channels;
3619 }
3620 }
3621 }
3622 return;
3623}
3624
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003625static void headset_is_config_supported(unsigned int *bit_width,
3626 unsigned int *sample_rate,
3627 unsigned int *channels) {
3628 switch (*bit_width) {
3629 case 16:
3630 case 24:
3631 break;
3632 default:
3633 *bit_width = 16;
3634 break;
3635 }
3636
3637 if (*sample_rate > 192000) {
3638 *sample_rate = 192000;
3639 }
3640
3641 if (*channels > 2) {
3642 *channels = 2;
3643 }
3644}
3645
David Linee3fe402017-03-13 10:00:42 -07003646static bool platform_check_playback_backend_cfg(struct audio_device* adev,
3647 struct audio_usecase* usecase,
3648 snd_device_t snd_device,
3649 struct audio_backend_cfg *backend_cfg)
3650{
3651 bool backend_change = false;
David Linee3fe402017-03-13 10:00:42 -07003652 unsigned int bit_width;
3653 unsigned int sample_rate;
3654 unsigned int channels;
David Linee3fe402017-03-13 10:00:42 -07003655 int backend_idx = DEFAULT_CODEC_BACKEND;
3656 struct platform_data *my_data = (struct platform_data *)adev->platform;
David Linee3fe402017-03-13 10:00:42 -07003657
3658 if (snd_device == SND_DEVICE_OUT_BT_SCO ||
3659 snd_device == SND_DEVICE_OUT_BT_SCO_WB) {
3660 backend_change = false;
3661 return backend_change;
3662 }
3663
3664 backend_idx = platform_get_backend_index(snd_device);
3665 bit_width = backend_cfg->bit_width;
3666 sample_rate = backend_cfg->sample_rate;
3667 channels = backend_cfg->channels;
3668
3669 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
3670 ", backend_idx %d usecase = %d device (%s)", __func__, bit_width,
3671 sample_rate, channels, backend_idx, usecase->id,
3672 platform_get_snd_device_name(snd_device));
3673
3674 if (backend_idx == platform_get_voice_call_backend(adev)) {
3675 ALOGW("%s:becf: afe:Use default bw and sr for voice/voip calls ",
3676 __func__);
3677 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3678 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3679 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
3680 } else {
3681 /*
3682 * The backend should be configured at highest bit width and/or
3683 * sample rate amongst all playback usecases.
3684 * If the selected sample rate and/or bit width differ with
3685 * current backend sample rate and/or bit width, then, we set the
3686 * backend re-configuration flag.
3687 *
3688 * Exception: 16 bit playbacks is allowed through 16 bit/48/44.1 khz backend only
3689 */
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003690 pick_playback_cfg_for_uc(adev, usecase, snd_device,
3691 &bit_width,
3692 &sample_rate,
3693 &channels);
David Linee3fe402017-03-13 10:00:42 -07003694 }
3695
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003696 switch (backend_idx) {
3697 case USB_AUDIO_RX_BACKEND:
3698 audio_extn_usb_is_config_supported(&bit_width,
3699 &sample_rate, &channels, true);
3700 ALOGV("%s: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
3701 __func__, bit_width, sample_rate, channels);
3702 break;
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003703 case HEADPHONE_BACKEND:
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003704 headset_is_config_supported(&bit_width, &sample_rate, &channels);
3705 break;
3706 case DEFAULT_CODEC_BACKEND:
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003707 default:
3708 bit_width = platform_get_snd_device_bit_width(snd_device);
3709 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3710 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
3711 break;
David Linee3fe402017-03-13 10:00:42 -07003712 }
3713
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003714 ALOGV("%s:becf: afe: Codec selected backend: %d updated bit width: %d and"
3715 "sample rate: %d",
David Linee3fe402017-03-13 10:00:42 -07003716 __func__, backend_idx , bit_width, sample_rate);
3717
3718 // Force routing if the expected bitwdith or samplerate
3719 // is not same as current backend comfiguration
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003720 if (bit_width != my_data->current_backend_cfg[backend_idx].bit_width ||
3721 sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate ||
3722 channels != my_data->current_backend_cfg[backend_idx].channels) {
David Linee3fe402017-03-13 10:00:42 -07003723 backend_cfg->bit_width = bit_width;
3724 backend_cfg->sample_rate = sample_rate;
3725 backend_cfg->channels = channels;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003726 backend_cfg->passthrough_enabled = false;
David Linee3fe402017-03-13 10:00:42 -07003727 backend_change = true;
3728 ALOGV("%s:becf: afe: Codec backend needs to be updated. new bit width: %d"
3729 "new sample rate: %d new channels: %d",
3730 __func__, backend_cfg->bit_width, backend_cfg->sample_rate, backend_cfg->channels);
3731 }
3732
3733 return backend_change;
3734}
3735
3736bool platform_check_and_set_playback_backend_cfg(struct audio_device* adev,
3737 struct audio_usecase *usecase, snd_device_t snd_device)
3738{
3739 int backend_idx = DEFAULT_CODEC_BACKEND;
3740 int new_snd_devices[SND_DEVICE_OUT_END];
3741 int i, num_devices = 1;
3742 bool ret = false;
3743 struct platform_data *my_data = (struct platform_data *)adev->platform;
3744 struct audio_backend_cfg backend_cfg;
3745
3746 backend_idx = platform_get_backend_index(snd_device);
3747
3748 backend_cfg.bit_width = pcm_format_to_bits(usecase->stream.out->config.format);
3749 backend_cfg.sample_rate = usecase->stream.out->sample_rate;
3750 backend_cfg.format = usecase->stream.out->format;
3751 backend_cfg.channels = audio_channel_count_from_out_mask(usecase->stream.out->channel_mask);
3752 /*this is populated by check_codec_backend_cfg hence set default value to false*/
3753 backend_cfg.passthrough_enabled = false;
3754
3755 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
3756 ", backend_idx %d usecase = %d device (%s)", __func__, backend_cfg.bit_width,
3757 backend_cfg.sample_rate, backend_cfg.channels, backend_idx, usecase->id,
3758 platform_get_snd_device_name(snd_device));
3759
3760 if (platform_can_split_snd_device(snd_device, &num_devices, new_snd_devices) < 0)
3761 new_snd_devices[0] = snd_device;
3762
3763 for (i = 0; i < num_devices; i++) {
3764 ALOGV("%s: new_snd_devices[%d] is %d", __func__, i, new_snd_devices[i]);
3765 if ((platform_check_playback_backend_cfg(adev, usecase, new_snd_devices[i],
3766 &backend_cfg))) {
3767 platform_set_backend_cfg(adev, new_snd_devices[i],
3768 &backend_cfg);
3769 ret = true;
3770 }
3771 }
3772 return ret;
3773}
3774
3775bool platform_check_and_set_capture_backend_cfg(struct audio_device* adev,
3776 struct audio_usecase *usecase, snd_device_t snd_device)
3777{
3778 int backend_idx = platform_get_backend_index(snd_device);
3779 int ret = 0;
3780 struct audio_backend_cfg backend_cfg;
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003781 memset(&backend_cfg, 0, sizeof(struct audio_backend_cfg));
David Linee3fe402017-03-13 10:00:42 -07003782
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003783 if (usecase->type == PCM_CAPTURE) {
3784 backend_cfg.format = usecase->stream.in->format;
David Linee3fe402017-03-13 10:00:42 -07003785 backend_cfg.channels = audio_channel_count_from_in_mask(usecase->stream.in->channel_mask);
3786 } else {
3787 backend_cfg.bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3788 backend_cfg.sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3789 backend_cfg.format = AUDIO_FORMAT_PCM_16_BIT;
3790 backend_cfg.channels = 1;
3791 }
3792
3793 ALOGV("%s:txbecf: afe: bitwidth %d, samplerate %d, channel %d"
3794 ", backend_idx %d usecase = %d device (%s)", __func__,
3795 backend_cfg.bit_width,
3796 backend_cfg.sample_rate,
3797 backend_cfg.channels,
3798 backend_idx, usecase->id,
3799 platform_get_snd_device_name(snd_device));
3800
3801 if (platform_check_capture_backend_cfg(adev, backend_idx, &backend_cfg)) {
3802 ret = platform_set_backend_cfg(adev, snd_device,
3803 &backend_cfg);
3804 if(!ret)
3805 return true;
3806 }
3807
3808 return false;
3809}
3810
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003811static int max_be_dai_names = 0;
3812static const struct be_dai_name_struct *be_dai_name_table;
3813
3814/*
3815 * Retrieves the be_dai_name_table from kernel to enable a mapping
3816 * between sound device hw interfaces and backend IDs. This allows HAL to
3817 * specify the backend a specific calibration is needed for.
3818 */
3819static int init_be_dai_name_table(struct audio_device *adev)
3820{
3821 const char *mixer_ctl_name = "Backend DAI Name Table";
3822 struct mixer_ctl *ctl;
3823 int i, j, ret, size;
3824 bool valid_hw_interface;
3825
3826 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3827 if (!ctl) {
3828 ALOGE("%s: Could not get ctl for mixer name %s\n",
3829 __func__, mixer_ctl_name);
3830 ret = -EINVAL;
3831 goto done;
3832 }
3833
3834 mixer_ctl_update(ctl);
3835
3836 size = mixer_ctl_get_num_values(ctl);
3837 if (size <= 0){
3838 ALOGE("%s: Failed to get %s size %d\n",
3839 __func__, mixer_ctl_name, size);
3840 ret = -EFAULT;
3841 goto done;
3842 }
3843
vivek mehtaa68fea62017-06-08 19:04:02 -07003844 be_dai_name_table =
3845 (const struct be_dai_name_struct *)calloc(1, size);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003846 if (be_dai_name_table == NULL) {
3847 ALOGE("%s: Failed to allocate memory for %s\n",
3848 __func__, mixer_ctl_name);
3849 ret = -ENOMEM;
3850 goto freeMem;
3851 }
3852
3853 ret = mixer_ctl_get_array(ctl, (void *)be_dai_name_table, size);
3854 if (ret) {
3855 ALOGE("%s: Failed to get %s, ret %d\n",
3856 __func__, mixer_ctl_name, ret);
3857 ret = -EFAULT;
3858 goto freeMem;
3859 }
3860
3861 if (be_dai_name_table != NULL) {
3862 max_be_dai_names = size / sizeof(struct be_dai_name_struct);
3863 ALOGV("%s: Successfully got %s, number of be dais is %d\n",
3864 __func__, mixer_ctl_name, max_be_dai_names);
3865 ret = 0;
3866 } else {
3867 ALOGE("%s: Failed to get %s\n", __func__, mixer_ctl_name);
3868 ret = -EFAULT;
3869 goto freeMem;
3870 }
3871
3872 /*
3873 * Validate all sound devices have a valid backend set to catch
3874 * errors for uncommon sound devices
3875 */
3876 for (i = 0; i < SND_DEVICE_MAX; i++) {
3877 valid_hw_interface = false;
3878
3879 if (hw_interface_table[i] == NULL) {
3880 ALOGW("%s: sound device %s has no hw interface set\n",
3881 __func__, platform_get_snd_device_name(i));
3882 continue;
3883 }
3884
3885 for (j = 0; j < max_be_dai_names; j++) {
3886 if (strcmp(hw_interface_table[i], be_dai_name_table[j].be_name)
3887 == 0) {
3888 valid_hw_interface = true;
3889 break;
3890 }
3891 }
3892 if (!valid_hw_interface)
3893 ALOGD("%s: sound device %s does not have a valid hw interface set "
3894 "(disregard for combo devices) %s\n",
3895 __func__, platform_get_snd_device_name(i),
3896 hw_interface_table[i]);
3897 }
3898
3899 goto done;
3900
3901freeMem:
3902 if (be_dai_name_table) {
3903 free((void *)be_dai_name_table);
3904 be_dai_name_table = NULL;
3905 }
3906
3907done:
3908 return ret;
3909}
3910
3911int platform_get_snd_device_backend_index(snd_device_t device)
3912{
3913 int i, be_dai_id;
3914 const char * hw_interface_name = NULL;
3915
3916 ALOGV("%s: enter with device %d\n", __func__, device);
3917
vivek mehtaa68fea62017-06-08 19:04:02 -07003918 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003919 ALOGE("%s: Invalid snd_device = %d",
3920 __func__, device);
3921 be_dai_id = -EINVAL;
3922 goto done;
3923 }
3924
3925 /* Get string value of necessary backend for device */
3926 hw_interface_name = hw_interface_table[device];
3927 if (hw_interface_name == NULL) {
3928 ALOGE("%s: no hw_interface set for device %d\n", __func__, device);
3929 be_dai_id = -EINVAL;
3930 goto done;
3931 }
3932
3933 /* Check if be dai name table was retrieved successfully */
3934 if (be_dai_name_table == NULL) {
3935 ALOGE("%s: BE DAI Name Table is not present\n", __func__);
3936 be_dai_id = -EFAULT;
3937 goto done;
3938 }
3939
3940 /* Get backend ID for device specified */
3941 for (i = 0; i < max_be_dai_names; i++) {
3942 if (strcmp(hw_interface_name, be_dai_name_table[i].be_name) == 0) {
3943 be_dai_id = be_dai_name_table[i].be_id;
3944 goto done;
3945 }
3946 }
3947 ALOGE("%s: no interface matching name %s\n", __func__, hw_interface_name);
3948 be_dai_id = -EINVAL;
3949 goto done;
3950
3951done:
3952 return be_dai_id;
3953}
3954
3955void platform_check_and_update_copp_sample_rate(void* platform, snd_device_t snd_device,
3956 unsigned int stream_sr, int* sample_rate)
3957{
3958 struct platform_data* my_data = (struct platform_data *)platform;
3959 int backend_idx = platform_get_backend_index(snd_device);
3960 int device_sr = my_data->current_backend_cfg[backend_idx].sample_rate;
3961 /*
3962 *Check if device SR is multiple of 8K or 11.025 Khz
3963 *check if the stream SR is multiple of same base, if yes
3964 *then have copp SR equal to stream SR, this ensures that
3965 *post processing happens at stream SR, else have
3966 *copp SR equal to device SR.
3967 */
3968 if (!(((sample_rate_multiple(device_sr, SAMPLE_RATE_8000)) &&
3969 (sample_rate_multiple(stream_sr, SAMPLE_RATE_8000))) ||
3970 ((sample_rate_multiple(device_sr, SAMPLE_RATE_11025)) &&
3971 (sample_rate_multiple(stream_sr, SAMPLE_RATE_11025))))) {
3972 *sample_rate = device_sr;
3973 } else
3974 *sample_rate = stream_sr;
3975
3976 ALOGI("sn_device %d device sr %d stream sr %d copp sr %d", snd_device, device_sr, stream_sr
3977 , *sample_rate);
3978
3979}
3980
3981// called from info parser
vivek mehtaa68fea62017-06-08 19:04:02 -07003982void platform_add_app_type(const char *uc_type,
3983 const char *mode,
3984 int bw,
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003985 int app_type, int max_rate) {
3986 struct app_type_entry *ap =
3987 (struct app_type_entry *)calloc(1, sizeof(struct app_type_entry));
3988
3989 if (!ap) {
3990 ALOGE("%s failed to allocate mem for app type", __func__);
3991 return;
3992 }
3993
3994 ap->uc_type = -1;
3995 for (int i=0; i<USECASE_TYPE_MAX; i++) {
3996 if (!strcmp(uc_type, usecase_type_index[i].name)) {
3997 ap->uc_type = usecase_type_index[i].index;
3998 break;
3999 }
4000 }
4001
4002 if (ap->uc_type == -1) {
4003 free(ap);
4004 return;
4005 }
4006
vivek mehtaa68fea62017-06-08 19:04:02 -07004007 ALOGI("%s uc %s mode %s bw %d app_type %d max_rate %d",
4008 __func__, uc_type, mode, bw, app_type, max_rate);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004009 ap->bit_width = bw;
4010 ap->app_type = app_type;
4011 ap->max_rate = max_rate;
vivek mehtaa68fea62017-06-08 19:04:02 -07004012 ap->mode = strdup(mode);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004013 list_add_tail(&app_type_entry_list, &ap->node);
4014}
4015
4016
4017int platform_get_default_app_type_v2(void *platform __unused,
4018 usecase_type_t type,
4019 int *app_type )
4020{
4021 if (type == PCM_PLAYBACK)
4022 *app_type = DEFAULT_APP_TYPE_RX_PATH;
4023 else
4024 *app_type = DEFAULT_APP_TYPE_TX_PATH;
4025 return 0;
4026}
4027
vivek mehtaa68fea62017-06-08 19:04:02 -07004028int platform_get_app_type_v2(void *platform,
4029 usecase_type_t uc_type,
4030 const char *mode,
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004031 int bw, int sr __unused,
4032 int *app_type)
4033{
4034 struct listnode *node;
4035 struct app_type_entry *entry;
4036 *app_type = -1;
vivek mehtaa68fea62017-06-08 19:04:02 -07004037
4038 ALOGV("%s find match for uc %d mode %s bw %d rate %d",
4039 __func__, uc_type, mode, bw, sr);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004040 list_for_each(node, &app_type_entry_list) {
4041 entry = node_to_item(node, struct app_type_entry, node);
vivek mehtaa68fea62017-06-08 19:04:02 -07004042 ALOGV("%s uc %d mode %s bw %d app_type %d max_rate %d",
4043 __func__, entry->uc_type, entry->mode, entry->bit_width,
4044 entry->app_type, entry->max_rate);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004045 if (entry->bit_width == bw &&
vivek mehtaa68fea62017-06-08 19:04:02 -07004046 entry->uc_type == uc_type &&
4047 sr <= entry->max_rate &&
4048 entry->mode && !strcmp(mode, entry->mode)) {
4049 ALOGV("%s found match %d", __func__, entry->app_type);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004050 *app_type = entry->app_type;
4051 break;
4052 }
4053 }
4054
4055 if (*app_type == -1) {
vivek mehtaa68fea62017-06-08 19:04:02 -07004056 ALOGV("%s no match found, return default", __func__);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004057 return platform_get_default_app_type_v2(platform, uc_type, app_type);
4058 }
4059 return 0;
4060}
vivek mehta90933872017-06-15 18:04:39 -07004061
4062int platform_set_sidetone(struct audio_device *adev,
4063 snd_device_t out_snd_device,
4064 bool enable, char *str)
4065{
4066 int ret;
4067 if (out_snd_device == SND_DEVICE_OUT_USB_HEADSET ||
4068 out_snd_device == SND_DEVICE_OUT_VOICE_USB_HEADSET) {
4069 ret = audio_extn_usb_enable_sidetone(out_snd_device, enable);
4070 if (ret)
4071 ALOGI("%s: usb device %d does not support device sidetone\n",
4072 __func__, out_snd_device);
4073 } else {
4074 ALOGV("%s: sidetone out device(%d) mixer cmd = %s\n",
4075 __func__, out_snd_device, str);
4076 if (enable)
4077 audio_route_apply_and_update_path(adev->audio_route, str);
4078 else
4079 audio_route_reset_and_update_path(adev->audio_route, str);
4080 }
4081 return 0;
4082}
Haynes Mathew George96483a22017-03-28 14:52:47 -07004083
4084int platform_get_mmap_data_fd(void *platform __unused, int fe_dev __unused, int dir __unused,
4085 int *fd __unused, uint32_t *size __unused)
4086{
4087#if defined (PLATFORM_MSM8996) || (PLATFORM_MSM8998)
4088 struct platform_data *my_data = (struct platform_data *)platform;
4089 struct audio_device *adev = my_data->adev;
4090 int hw_fd = -1;
4091 char dev_name[128];
4092 struct snd_pcm_mmap_fd mmap_fd;
4093 memset(&mmap_fd, 0, sizeof(mmap_fd));
4094 mmap_fd.dir = dir;
4095 snprintf(dev_name, sizeof(dev_name), "/dev/snd/hwC%uD%u",
4096 adev->snd_card, HWDEP_FE_BASE+fe_dev);
4097 hw_fd = open(dev_name, O_RDONLY);
4098 if (hw_fd < 0) {
4099 ALOGE("fe hw dep node open %d/%d failed", adev->snd_card, fe_dev);
4100 return -1;
4101 }
4102 if (ioctl(hw_fd, SNDRV_PCM_IOCTL_MMAP_DATA_FD, &mmap_fd) < 0) {
4103 ALOGE("fe hw dep node ioctl failed");
4104 close(hw_fd);
4105 return -1;
4106 }
4107 *fd = mmap_fd.fd;
4108 *size = mmap_fd.size;
4109 close(hw_fd); // mmap_fd should still be valid
4110 return 0;
4111#else
4112 return -1;
4113#endif
4114}