blob: fc4ebe699ffc6a41f95a1eb77e2dfcab108e90b5 [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
Haynes Mathew George39c55dc2017-07-11 19:31:23 -070065#define DEFAULT_RX_BACKEND "SLIMBUS_0_RX"
vivek mehta1a9b7c02015-06-25 11:49:38 -070066
keunhui.parkc5aaa0e2015-07-13 10:57:37 +090067#define TOSTRING_(x) #x
68#define TOSTRING(x) TOSTRING_(x)
69
Eric Laurentb23d5282013-05-14 15:27:20 -070070struct audio_block_header
71{
72 int reserved;
73 int length;
74};
75
vivek mehta1a9b7c02015-06-25 11:49:38 -070076enum {
77 CAL_MODE_SEND = 0x1,
78 CAL_MODE_PERSIST = 0x2,
79 CAL_MODE_RTAC = 0x4
80};
81
keunhui.park2f7306a2015-07-16 16:48:06 +090082#define PLATFORM_CONFIG_KEY_OPERATOR_INFO "operator_info"
83
84struct operator_info {
85 struct listnode list;
86 char *name;
87 char *mccmnc;
88};
89
90struct operator_specific_device {
91 struct listnode list;
92 char *operator;
93 char *mixer_path;
94 int acdb_id;
95};
96
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -080097#define BE_DAI_NAME_MAX_LENGTH 24
98struct be_dai_name_struct {
99 unsigned int be_id;
100 char be_name[BE_DAI_NAME_MAX_LENGTH];
101};
102
keunhui.park2f7306a2015-07-16 16:48:06 +0900103static struct listnode operator_info_list;
104static struct listnode *operator_specific_device_table[SND_DEVICE_MAX];
105
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700106/* Audio calibration related functions */
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800107typedef void (*acdb_send_audio_cal_v3_t)(int, int, int, int, int);
Eric Laurentb23d5282013-05-14 15:27:20 -0700108
Eric Laurentb23d5282013-05-14 15:27:20 -0700109struct platform_data {
110 struct audio_device *adev;
111 bool fluence_in_spkr_mode;
112 bool fluence_in_voice_call;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700113 bool fluence_in_voice_comm;
Eric Laurentb23d5282013-05-14 15:27:20 -0700114 bool fluence_in_voice_rec;
Prashant Malanic92c5962015-08-11 15:10:18 -0700115 /* 0 = no fluence, 1 = fluence, 2 = fluence pro */
116 int fluence_type;
117 int source_mic_type;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -0700118 bool speaker_lr_swap;
119
Eric Laurentb23d5282013-05-14 15:27:20 -0700120 void *acdb_handle;
Thierry Strudel92232b42017-01-26 10:51:48 -0800121#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -0700122 acdb_init_v2_cvd_t acdb_init;
123#elif defined (PLATFORM_MSM8084)
124 acdb_init_v2_t acdb_init;
125#else
126 acdb_init_t acdb_init;
127#endif
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700128 acdb_deallocate_t acdb_deallocate;
129 acdb_send_audio_cal_t acdb_send_audio_cal;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800130 acdb_send_audio_cal_v3_t acdb_send_audio_cal_v3;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700131 acdb_send_voice_cal_t acdb_send_voice_cal;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700132 acdb_reload_vocvoltable_t acdb_reload_vocvoltable;
vivek mehta1a9b7c02015-06-25 11:49:38 -0700133 acdb_send_gain_dep_cal_t acdb_send_gain_dep_cal;
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -0700134 acdb_send_custom_top_t acdb_send_custom_top;
135 bool acdb_initialized;
136
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700137 struct csd_data *csd;
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800138 char ec_ref_mixer_path[64];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700139
David Linee3fe402017-03-13 10:00:42 -0700140 codec_backend_cfg_t current_backend_cfg[MAX_CODEC_BACKENDS];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700141 char *snd_card_name;
keunhui.parkc5aaa0e2015-07-13 10:57:37 +0900142 int max_vol_index;
Prashant Malanic92c5962015-08-11 15:10:18 -0700143 int max_mic_count;
vivek mehtade4849c2016-03-03 17:23:38 -0800144
145 void *hw_info;
Eric Laurentb23d5282013-05-14 15:27:20 -0700146};
147
Haynes Mathew George98c95622014-06-20 19:14:25 -0700148static int pcm_device_table[AUDIO_USECASE_MAX][2] = {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700149 [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = {DEEP_BUFFER_PCM_DEVICE,
150 DEEP_BUFFER_PCM_DEVICE},
151 [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
152 LOWLATENCY_PCM_DEVICE},
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800153 [USECASE_AUDIO_PLAYBACK_HIFI] = {MULTIMEDIA2_PCM_DEVICE,
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700154 MULTIMEDIA2_PCM_DEVICE},
155 [USECASE_AUDIO_PLAYBACK_OFFLOAD] = {PLAYBACK_OFFLOAD_DEVICE,
156 PLAYBACK_OFFLOAD_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700157 [USECASE_AUDIO_PLAYBACK_TTS] = {MULTIMEDIA2_PCM_DEVICE,
158 MULTIMEDIA2_PCM_DEVICE},
159 [USECASE_AUDIO_PLAYBACK_ULL] = {MULTIMEDIA3_PCM_DEVICE,
160 MULTIMEDIA3_PCM_DEVICE},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800161 [USECASE_AUDIO_PLAYBACK_MMAP] = {MMAP_PLAYBACK_PCM_DEVICE,
162 MMAP_PLAYBACK_PCM_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700163
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700164 [USECASE_AUDIO_RECORD] = {AUDIO_RECORD_PCM_DEVICE,
165 AUDIO_RECORD_PCM_DEVICE},
166 [USECASE_AUDIO_RECORD_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
167 LOWLATENCY_PCM_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700168
Eric Laurent0e46adf2016-12-16 12:49:24 -0800169 [USECASE_AUDIO_RECORD_MMAP] = {MMAP_RECORD_PCM_DEVICE,
170 MMAP_RECORD_PCM_DEVICE},
Haynes Mathew George569b7482017-05-08 14:44:27 -0700171 [USECASE_AUDIO_RECORD_HIFI] = {MULTIMEDIA2_PCM_DEVICE,
172 MULTIMEDIA2_PCM_DEVICE},
173
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700174 [USECASE_VOICE_CALL] = {VOICE_CALL_PCM_DEVICE,
175 VOICE_CALL_PCM_DEVICE},
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700176 [USECASE_VOICE2_CALL] = {VOICE2_CALL_PCM_DEVICE, VOICE2_CALL_PCM_DEVICE},
177 [USECASE_VOLTE_CALL] = {VOLTE_CALL_PCM_DEVICE, VOLTE_CALL_PCM_DEVICE},
178 [USECASE_QCHAT_CALL] = {QCHAT_CALL_PCM_DEVICE, QCHAT_CALL_PCM_DEVICE},
179 [USECASE_VOWLAN_CALL] = {VOWLAN_CALL_PCM_DEVICE, VOWLAN_CALL_PCM_DEVICE},
vivek mehtaa51fd402016-02-04 19:49:33 -0800180 [USECASE_VOICEMMODE1_CALL] = {VOICEMMODE1_CALL_PCM_DEVICE,
181 VOICEMMODE1_CALL_PCM_DEVICE},
182 [USECASE_VOICEMMODE2_CALL] = {VOICEMMODE2_CALL_PCM_DEVICE,
183 VOICEMMODE2_CALL_PCM_DEVICE},
184
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700185 [USECASE_INCALL_REC_UPLINK] = {AUDIO_RECORD_PCM_DEVICE,
186 AUDIO_RECORD_PCM_DEVICE},
187 [USECASE_INCALL_REC_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
188 AUDIO_RECORD_PCM_DEVICE},
189 [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
190 AUDIO_RECORD_PCM_DEVICE},
Ravi Kumar Alamanda8e6e98f2013-11-05 15:57:39 -0800191 [USECASE_AUDIO_HFP_SCO] = {HFP_PCM_RX, HFP_SCO_RX},
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700192
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700193 [USECASE_AUDIO_SPKR_CALIB_RX] = {SPKR_PROT_CALIB_RX_PCM_DEVICE, -1},
194 [USECASE_AUDIO_SPKR_CALIB_TX] = {-1, SPKR_PROT_CALIB_TX_PCM_DEVICE},
195
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700196 [USECASE_AUDIO_PLAYBACK_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
197 AFE_PROXY_RECORD_PCM_DEVICE},
198 [USECASE_AUDIO_RECORD_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
199 AFE_PROXY_RECORD_PCM_DEVICE},
zhaoyang yin4211fad2015-06-04 21:13:25 +0800200 [USECASE_AUDIO_DSM_FEEDBACK] = {QUAT_MI2S_PCM_DEVICE, QUAT_MI2S_PCM_DEVICE},
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700201
vivek mehtaa68fea62017-06-08 19:04:02 -0700202 [USECASE_AUDIO_PLAYBACK_VOIP] = {AUDIO_PLAYBACK_VOIP_PCM_DEVICE,
203 AUDIO_PLAYBACK_VOIP_PCM_DEVICE},
204 [USECASE_AUDIO_RECORD_VOIP] = {AUDIO_RECORD_VOIP_PCM_DEVICE,
205 AUDIO_RECORD_VOIP_PCM_DEVICE},
Eric Laurentb23d5282013-05-14 15:27:20 -0700206};
207
208/* Array to store sound devices */
209static const char * const device_table[SND_DEVICE_MAX] = {
210 [SND_DEVICE_NONE] = "none",
211 /* Playback sound devices */
212 [SND_DEVICE_OUT_HANDSET] = "handset",
213 [SND_DEVICE_OUT_SPEAKER] = "speaker",
214 [SND_DEVICE_OUT_SPEAKER_REVERSE] = "speaker-reverse",
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700215 [SND_DEVICE_OUT_SPEAKER_SAFE] = "speaker-safe",
Eric Laurentb23d5282013-05-14 15:27:20 -0700216 [SND_DEVICE_OUT_HEADPHONES] = "headphones",
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500217 [SND_DEVICE_OUT_LINE] = "line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700218 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones",
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700219 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = "speaker-safe-and-headphones",
Eric Laurent744996b2014-10-01 11:40:40 -0500220 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = "speaker-and-line",
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700221 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = "speaker-safe-and-line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700222 [SND_DEVICE_OUT_VOICE_HANDSET] = "voice-handset",
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500223 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = "voice-hac-handset",
Eric Laurentb23d5282013-05-14 15:27:20 -0700224 [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker",
225 [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones",
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500226 [SND_DEVICE_OUT_VOICE_LINE] = "voice-line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700227 [SND_DEVICE_OUT_HDMI] = "hdmi",
228 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi",
229 [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700230 [SND_DEVICE_OUT_BT_SCO_WB] = "bt-sco-headset-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700231 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = "voice-handset-tmus",
232 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones",
233 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones",
234 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset",
vivek mehtaa6b79742017-03-09 15:40:43 -0800235 [SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = "voice-tty-full-usb",
236 [SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = "voice-tty-vco-usb",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700237 [SND_DEVICE_OUT_VOICE_TX] = "voice-tx",
David Linee3fe402017-03-13 10:00:42 -0700238 [SND_DEVICE_OUT_USB_HEADSET] = "usb-headset",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700239 [SND_DEVICE_OUT_VOICE_USB_HEADSET] = "usb-headset",
David Linee3fe402017-03-13 10:00:42 -0700240 [SND_DEVICE_OUT_USB_HEADPHONES] = "usb-headphones",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700241 [SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = "usb-headphones",
David Linee3fe402017-03-13 10:00:42 -0700242 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = "speaker-and-usb-headphones",
Haynes Mathew George9090bfb2017-05-31 11:44:50 -0700243 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] = "speaker-safe-and-usb-headphones",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700244 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = "speaker-protected",
245 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = "voice-speaker-protected",
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -0700246 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = "voice-speaker-hfp",
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -0800247 [SND_DEVICE_OUT_SPEAKER_AND_BT_SCO] = "speaker-and-bt-sco",
248 [SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB] = "speaker-and-bt-sco-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700249
250 /* Capture sound devices */
251 [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700252 [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700253 [SND_DEVICE_IN_HANDSET_MIC_NS] = "handset-mic",
254 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = "handset-mic",
255 [SND_DEVICE_IN_HANDSET_DMIC] = "dmic-endfire",
256 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = "dmic-endfire",
257 [SND_DEVICE_IN_HANDSET_DMIC_NS] = "dmic-endfire",
258 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = "dmic-endfire",
259 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = "dmic-endfire",
260
261 [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
262 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "speaker-mic",
263 [SND_DEVICE_IN_SPEAKER_MIC_NS] = "speaker-mic",
264 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = "speaker-mic",
265 [SND_DEVICE_IN_SPEAKER_DMIC] = "speaker-dmic-endfire",
266 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = "speaker-dmic-endfire",
267 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = "speaker-dmic-endfire",
268 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = "speaker-dmic-endfire",
269 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = "speaker-dmic-endfire",
270
271 [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
Eric Laurentcefbbac2014-09-04 13:54:10 -0500272 [SND_DEVICE_IN_HEADSET_MIC_AEC] = "headset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700273
Eric Laurentb23d5282013-05-14 15:27:20 -0700274 [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic",
275 [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700276 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = "bt-sco-mic",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700277 [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700278 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = "bt-sco-mic-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700279 [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700280
281 [SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef",
282 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = "voice-dmic-ef-tmus",
283 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
284 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = "voice-speaker-dmic-ef",
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -0700285 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = "voice-speaker-mic-hfp",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700286 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700287 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
288 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
289 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
vivek mehtaa6b79742017-03-09 15:40:43 -0800290 [SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = "voice-tty-full-usb-mic",
291 [SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = "voice-tty-hco-usb-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700292
Eric Laurentb23d5282013-05-14 15:27:20 -0700293 [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700294 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = "voice-rec-mic",
vivek mehta733c1df2016-04-04 15:09:24 -0700295 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = "voice-rec-mic",
vivek mehtaf3440682016-05-11 14:24:37 -0700296 [SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700297 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = "voice-rec-dmic-ef",
298 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence",
David Linee3fe402017-03-13 10:00:42 -0700299 [SND_DEVICE_IN_USB_HEADSET_MIC] = "usb-headset-mic",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700300 [SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] ="usb-headset-mic",
301 [SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = "usb-headset-mic",
302 [SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = "usb-headset-mic",
303 [SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = "usb-headset-mic",
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700304 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = "headset-mic",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700305
Ricardo Garcia9034bc42016-04-04 07:11:46 -0700306 [SND_DEVICE_IN_UNPROCESSED_MIC] = "unprocessed-mic",
vivek mehta0125e782016-06-16 18:03:11 -0700307 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = "unprocessed-stereo-mic",
308 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = "unprocessed-three-mic",
309 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = "unprocessed-quad-mic",
310 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = "unprocessed-headset-mic",
rago90fb9612015-12-02 11:37:53 -0800311
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700312 [SND_DEVICE_IN_VOICE_RX] = "voice-rx",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700313
Prashant Malanic92c5962015-08-11 15:10:18 -0700314 [SND_DEVICE_IN_THREE_MIC] = "three-mic",
315 [SND_DEVICE_IN_QUAD_MIC] = "quad-mic",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700316 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = "vi-feedback",
Prashant Malanic92c5962015-08-11 15:10:18 -0700317 [SND_DEVICE_IN_HANDSET_TMIC] = "three-mic",
318 [SND_DEVICE_IN_HANDSET_QMIC] = "quad-mic",
vivek mehta733c1df2016-04-04 15:09:24 -0700319 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = "three-mic",
320 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = "quad-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700321};
322
323/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700324static int acdb_device_table[SND_DEVICE_MAX] = {
Eric Laurentb23d5282013-05-14 15:27:20 -0700325 [SND_DEVICE_NONE] = -1,
326 [SND_DEVICE_OUT_HANDSET] = 7,
327 [SND_DEVICE_OUT_SPEAKER] = 15,
328 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 15,
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700329 [SND_DEVICE_OUT_SPEAKER_SAFE] = 15,
Eric Laurentb23d5282013-05-14 15:27:20 -0700330 [SND_DEVICE_OUT_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500331 [SND_DEVICE_OUT_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700332 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700333 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500334 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = 77,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700335 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = 77,
Ravi Kumar Alamanda235c3482014-08-21 17:32:44 -0700336 [SND_DEVICE_OUT_VOICE_HANDSET] = ACDB_ID_VOICE_HANDSET,
337 [SND_DEVICE_OUT_VOICE_SPEAKER] = ACDB_ID_VOICE_SPEAKER,
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500338 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = 53,
Eric Laurentb23d5282013-05-14 15:27:20 -0700339 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500340 [SND_DEVICE_OUT_VOICE_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700341 [SND_DEVICE_OUT_HDMI] = 18,
342 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 15,
343 [SND_DEVICE_OUT_BT_SCO] = 22,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700344 [SND_DEVICE_OUT_BT_SCO_WB] = 39,
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700345 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = ACDB_ID_VOICE_HANDSET_TMUS,
Eric Laurentb23d5282013-05-14 15:27:20 -0700346 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
347 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
348 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
vivek mehtaa6b79742017-03-09 15:40:43 -0800349 [SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = 17,
350 [SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = 17,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700351 [SND_DEVICE_OUT_VOICE_TX] = 45,
David Linee3fe402017-03-13 10:00:42 -0700352 [SND_DEVICE_OUT_USB_HEADSET] = 45,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700353 [SND_DEVICE_OUT_VOICE_USB_HEADSET] = 45,
David Linee3fe402017-03-13 10:00:42 -0700354 [SND_DEVICE_OUT_USB_HEADPHONES] = 45,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700355 [SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = 45,
David Linee3fe402017-03-13 10:00:42 -0700356 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = 14,
Haynes Mathew George9090bfb2017-05-31 11:44:50 -0700357 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] = 14,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700358 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = 124,
359 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = 101,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700360 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = ACDB_ID_VOICE_SPEAKER,
Eric Laurentb23d5282013-05-14 15:27:20 -0700361
362 [SND_DEVICE_IN_HANDSET_MIC] = 4,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700363 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 106,
364 [SND_DEVICE_IN_HANDSET_MIC_NS] = 107,
365 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = 108,
366 [SND_DEVICE_IN_HANDSET_DMIC] = 41,
367 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = 109,
368 [SND_DEVICE_IN_HANDSET_DMIC_NS] = 110,
369 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = 111,
370 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = 34,
371
372 [SND_DEVICE_IN_SPEAKER_MIC] = 11,
373 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 112,
374 [SND_DEVICE_IN_SPEAKER_MIC_NS] = 113,
375 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = 114,
376 [SND_DEVICE_IN_SPEAKER_DMIC] = 43,
377 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = 115,
378 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = 116,
379 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = 117,
380 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = 35,
381
rago90fb9612015-12-02 11:37:53 -0800382 [SND_DEVICE_IN_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentcefbbac2014-09-04 13:54:10 -0500383 [SND_DEVICE_IN_HEADSET_MIC_AEC] = ACDB_ID_HEADSET_MIC_AEC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700384
Eric Laurentb23d5282013-05-14 15:27:20 -0700385 [SND_DEVICE_IN_HDMI_MIC] = 4,
386 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700387 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = 21,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700388 [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700389 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = 38,
Eric Laurentb23d5282013-05-14 15:27:20 -0700390 [SND_DEVICE_IN_CAMCORDER_MIC] = 61,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700391
392 [SND_DEVICE_IN_VOICE_DMIC] = 41,
393 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = ACDB_ID_VOICE_DMIC_EF_TMUS,
394 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700395 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = 11,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700396 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 43,
rago90fb9612015-12-02 11:37:53 -0800397 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentb23d5282013-05-14 15:27:20 -0700398 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
399 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
400 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
vivek mehtaa6b79742017-03-09 15:40:43 -0800401 [SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = 16,
402 [SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = 16,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700403
rago90fb9612015-12-02 11:37:53 -0800404 [SND_DEVICE_IN_VOICE_REC_MIC] = ACDB_ID_VOICE_REC_MIC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700405 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = 113,
vivek mehta733c1df2016-04-04 15:09:24 -0700406 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = 112,
vivek mehtaf3440682016-05-11 14:24:37 -0700407 [SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = 114,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700408 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = 35,
409 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 43,
rago90fb9612015-12-02 11:37:53 -0800410 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
411
412 [SND_DEVICE_IN_UNPROCESSED_MIC] = ACDB_ID_VOICE_REC_MIC,
413 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
vivek mehta4ed66e62016-04-15 23:33:34 -0700414 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = 35,
415 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = 125,
416 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = 125,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700417
418 [SND_DEVICE_IN_VOICE_RX] = 44,
David Linee3fe402017-03-13 10:00:42 -0700419 [SND_DEVICE_IN_USB_HEADSET_MIC] = 44,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700420 [SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = 44,
421 [SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = 44,
422 [SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = 44,
423 [SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = 44,
Prashant Malanic92c5962015-08-11 15:10:18 -0700424 [SND_DEVICE_IN_THREE_MIC] = 46,
425 [SND_DEVICE_IN_QUAD_MIC] = 46,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700426 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = 102,
Prashant Malanic92c5962015-08-11 15:10:18 -0700427 [SND_DEVICE_IN_HANDSET_TMIC] = 125,
428 [SND_DEVICE_IN_HANDSET_QMIC] = 125,
vivek mehta733c1df2016-04-04 15:09:24 -0700429 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = 125, /* override this for new target to 140 */
430 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = 125, /* override this for new target to 140 */
Eric Laurentb23d5282013-05-14 15:27:20 -0700431};
432
David Linee3fe402017-03-13 10:00:42 -0700433// Platform specific backend bit width table
434static int backend_bit_width_table[SND_DEVICE_MAX] = {0};
435
Haynes Mathew George98c95622014-06-20 19:14:25 -0700436struct name_to_index {
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700437 char name[100];
438 unsigned int index;
439};
440
441#define TO_NAME_INDEX(X) #X, X
442
Haynes Mathew George98c95622014-06-20 19:14:25 -0700443/* Used to get index from parsed string */
444static const struct name_to_index snd_device_name_index[SND_DEVICE_MAX] = {
445 /* out */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700446 {TO_NAME_INDEX(SND_DEVICE_OUT_HANDSET)},
447 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER)},
448 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_REVERSE)},
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700449 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700450 {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500451 {TO_NAME_INDEX(SND_DEVICE_OUT_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700452 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700453 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES)},
Eric Laurent744996b2014-10-01 11:40:40 -0500454 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_LINE)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700455 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700456 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET)},
457 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700458 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_HFP)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700459 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500460 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700461 {TO_NAME_INDEX(SND_DEVICE_OUT_HDMI)},
462 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HDMI)},
463 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO)},
464 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO_WB)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700465 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET_TMUS)},
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500466 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HAC_HANDSET)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700467 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES)},
468 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES)},
469 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET)},
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -0800470 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_SCO)},
471 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800472 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_USB)},
473 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_USB)},
David Linee3fe402017-03-13 10:00:42 -0700474 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADSET)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700475 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_USB_HEADSET)},
David Linee3fe402017-03-13 10:00:42 -0700476 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADPHONES)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700477 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_USB_HEADPHONES)},
David Linee3fe402017-03-13 10:00:42 -0700478 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET)},
Haynes Mathew George9090bfb2017-05-31 11:44:50 -0700479 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700480 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED)},
481 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800482
483 /* in */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700484 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700485 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700486 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_NS)},
487 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)},
488 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC)},
489 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC)},
490 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_NS)},
491 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)},
492 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_STEREO)},
493
494 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700495 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700496 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_NS)},
497 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)},
498 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC)},
499 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC)},
500 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS)},
501 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)},
502 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_STEREO)},
503
504 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC)},
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700505 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700506
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700507 {TO_NAME_INDEX(SND_DEVICE_IN_HDMI_MIC)},
508 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700509 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700510 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700511 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700512 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700513
514 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC)},
515 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC_TMUS)},
516 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700517 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700518 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC)},
519 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEADSET_MIC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700520 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC)},
521 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC)},
522 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800523 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC)},
524 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC)},
525
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700526
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700527 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700528 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_NS)},
vivek mehta733c1df2016-04-04 15:09:24 -0700529 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC)},
vivek mehtaf3440682016-05-11 14:24:37 -0700530 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700531 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_STEREO)},
532 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE)},
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700533 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_HEADSET_MIC)},
David Linee3fe402017-03-13 10:00:42 -0700534 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700535 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_USB_HEADSET_MIC)},
536 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC)},
537 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC)},
538 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC_AEC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700539
rago90fb9612015-12-02 11:37:53 -0800540 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_MIC)},
541 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC)},
vivek mehta4ed66e62016-04-15 23:33:34 -0700542 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_STEREO_MIC)},
543 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_THREE_MIC)},
544 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_QUAD_MIC)},
rago90fb9612015-12-02 11:37:53 -0800545
Prashant Malanic92c5962015-08-11 15:10:18 -0700546 {TO_NAME_INDEX(SND_DEVICE_IN_THREE_MIC)},
547 {TO_NAME_INDEX(SND_DEVICE_IN_QUAD_MIC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700548 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_VI_FEEDBACK)},
Prashant Malanic92c5962015-08-11 15:10:18 -0700549 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC)},
550 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC)},
vivek mehta733c1df2016-04-04 15:09:24 -0700551 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC_AEC)},
552 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC_AEC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700553};
554
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700555static char * backend_tag_table[SND_DEVICE_MAX] = {0};
556static char * hw_interface_table[SND_DEVICE_MAX] = {0};
Haynes Mathew George98c95622014-06-20 19:14:25 -0700557
558static const struct name_to_index usecase_name_index[AUDIO_USECASE_MAX] = {
559 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_DEEP_BUFFER)},
560 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_LOW_LATENCY)},
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800561 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_HIFI)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700562 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD)},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700563 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_TTS)},
564 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_ULL)},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800565 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_MMAP)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700566 {TO_NAME_INDEX(USECASE_AUDIO_RECORD)},
567 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_LOW_LATENCY)},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800568 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_MMAP)},
Haynes Mathew George569b7482017-05-08 14:44:27 -0700569 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_HIFI)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700570 {TO_NAME_INDEX(USECASE_VOICE_CALL)},
571 {TO_NAME_INDEX(USECASE_VOICE2_CALL)},
572 {TO_NAME_INDEX(USECASE_VOLTE_CALL)},
573 {TO_NAME_INDEX(USECASE_QCHAT_CALL)},
574 {TO_NAME_INDEX(USECASE_VOWLAN_CALL)},
John Muirf1346ce2016-12-06 00:03:41 -0800575 {TO_NAME_INDEX(USECASE_VOICEMMODE1_CALL)},
576 {TO_NAME_INDEX(USECASE_VOICEMMODE2_CALL)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700577 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK)},
578 {TO_NAME_INDEX(USECASE_INCALL_REC_DOWNLINK)},
579 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK_AND_DOWNLINK)},
580 {TO_NAME_INDEX(USECASE_AUDIO_HFP_SCO)},
John Muirf1346ce2016-12-06 00:03:41 -0800581 {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_RX)},
582 {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_TX)},
583 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_AFE_PROXY)},
584 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_AFE_PROXY)},
585 {TO_NAME_INDEX(USECASE_AUDIO_DSM_FEEDBACK)},
vivek mehtaa68fea62017-06-08 19:04:02 -0700586 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_VOIP)},
587 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_VOIP)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700588};
589
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800590static const struct name_to_index usecase_type_index[USECASE_TYPE_MAX] = {
591 {TO_NAME_INDEX(PCM_PLAYBACK)},
592 {TO_NAME_INDEX(PCM_CAPTURE)},
593 {TO_NAME_INDEX(VOICE_CALL)},
594 {TO_NAME_INDEX(PCM_HFP_CALL)},
595};
596
597struct app_type_entry {
598 int uc_type;
599 int bit_width;
600 int app_type;
601 int max_rate;
vivek mehtaa68fea62017-06-08 19:04:02 -0700602 char *mode;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800603 struct listnode node; // membership in app_type_entry_list;
604};
605
606static struct listnode app_type_entry_list;
607
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700608#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
609#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
Eric Laurent0e46adf2016-12-16 12:49:24 -0800610#define ULL_PLATFORM_DELAY (3*1000LL)
611#define MMAP_PLATFORM_DELAY (3*1000LL)
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700612
Eric Laurentb23d5282013-05-14 15:27:20 -0700613static pthread_once_t check_op_once_ctl = PTHREAD_ONCE_INIT;
614static bool is_tmus = false;
615
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800616static int init_be_dai_name_table(struct audio_device *adev);
617
Eric Laurentb23d5282013-05-14 15:27:20 -0700618static void check_operator()
619{
620 char value[PROPERTY_VALUE_MAX];
621 int mccmnc;
622 property_get("gsm.sim.operator.numeric",value,"0");
623 mccmnc = atoi(value);
Eric Laurent2bafff12016-03-17 12:17:23 -0700624 ALOGD("%s: tmus mccmnc %d", __func__, mccmnc);
Eric Laurentb23d5282013-05-14 15:27:20 -0700625 switch(mccmnc) {
626 /* TMUS MCC(310), MNC(490, 260, 026) */
627 case 310490:
628 case 310260:
629 case 310026:
sangwon.jeonb891db52013-09-14 17:39:15 +0900630 /* Add new TMUS MNC(800, 660, 580, 310, 270, 250, 240, 230, 220, 210, 200, 160) */
631 case 310800:
632 case 310660:
633 case 310580:
634 case 310310:
635 case 310270:
636 case 310250:
637 case 310240:
638 case 310230:
639 case 310220:
640 case 310210:
641 case 310200:
642 case 310160:
Eric Laurentb23d5282013-05-14 15:27:20 -0700643 is_tmus = true;
644 break;
645 }
646}
647
648bool is_operator_tmus()
649{
650 pthread_once(&check_op_once_ctl, check_operator);
651 return is_tmus;
652}
653
keunhui.park2f7306a2015-07-16 16:48:06 +0900654static char *get_current_operator()
655{
656 struct listnode *node;
657 struct operator_info *info_item;
658 char mccmnc[PROPERTY_VALUE_MAX];
659 char *ret = NULL;
660
Tom Cherry7fea2042016-11-10 18:05:59 -0800661 property_get("gsm.sim.operator.numeric",mccmnc,"00000");
keunhui.park2f7306a2015-07-16 16:48:06 +0900662
663 list_for_each(node, &operator_info_list) {
664 info_item = node_to_item(node, struct operator_info, list);
665 if (strstr(info_item->mccmnc, mccmnc) != NULL) {
666 ret = info_item->name;
667 }
668 }
669
670 return ret;
671}
672
673static struct operator_specific_device *get_operator_specific_device(snd_device_t snd_device)
674{
675 struct listnode *node;
676 struct operator_specific_device *ret = NULL;
677 struct operator_specific_device *device_item;
678 char *operator_name;
679
680 operator_name = get_current_operator();
681 if (operator_name == NULL)
682 return ret;
683
684 list_for_each(node, operator_specific_device_table[snd_device]) {
685 device_item = node_to_item(node, struct operator_specific_device, list);
686 if (strcmp(operator_name, device_item->operator) == 0) {
687 ret = device_item;
688 }
689 }
690
691 return ret;
692}
693
694
695static int get_operator_specific_device_acdb_id(snd_device_t snd_device)
696{
697 struct operator_specific_device *device;
698 int ret = acdb_device_table[snd_device];
699
700 device = get_operator_specific_device(snd_device);
701 if (device != NULL)
702 ret = device->acdb_id;
703
704 return ret;
705}
706
707static const char *get_operator_specific_device_mixer_path(snd_device_t snd_device)
708{
709 struct operator_specific_device *device;
710 const char *ret = device_table[snd_device];
711
712 device = get_operator_specific_device(snd_device);
713 if (device != NULL)
714 ret = device->mixer_path;
715
716 return ret;
717}
718
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800719inline bool platform_supports_app_type_cfg()
720{
721#ifdef PLATFORM_MSM8998
722 return true;
723#else
724 return false;
725#endif
726}
727
vivek mehta1a9b7c02015-06-25 11:49:38 -0700728bool platform_send_gain_dep_cal(void *platform, int level)
729{
730 bool ret_val = false;
731 struct platform_data *my_data = (struct platform_data *)platform;
732 struct audio_device *adev = my_data->adev;
733 int acdb_dev_id, app_type;
734 int acdb_dev_type = MSM_SNDDEV_CAP_RX;
735 int mode = CAL_MODE_RTAC;
736 struct listnode *node;
737 struct audio_usecase *usecase;
Haynes Mathew George67486e22017-06-26 12:58:38 -0700738 bool valid_uc_type;
739 bool valid_dev;
vivek mehta1a9b7c02015-06-25 11:49:38 -0700740
741 if (my_data->acdb_send_gain_dep_cal == NULL) {
742 ALOGE("%s: dlsym error for acdb_send_gain_dep_cal", __func__);
743 return ret_val;
744 }
745
746 if (!voice_is_in_call(adev)) {
747 ALOGV("%s: Not Voice call usecase, apply new cal for level %d",
748 __func__, level);
749 app_type = DEFAULT_APP_TYPE_RX_PATH;
750
751 // find the current active sound device
752 list_for_each(node, &adev->usecase_list) {
753 usecase = node_to_item(node, struct audio_usecase, list);
Haynes Mathew George67486e22017-06-26 12:58:38 -0700754 LOG_ALWAYS_FATAL_IF(usecase == NULL,
755 "unxpected NULL usecase in usecase_list");
756 valid_uc_type = usecase->type == PCM_PLAYBACK;
757 valid_dev = false;
758 if (valid_uc_type) {
759 audio_devices_t dev = usecase->stream.out->devices;
760 valid_dev = (dev == AUDIO_DEVICE_OUT_SPEAKER ||
761 dev == AUDIO_DEVICE_OUT_WIRED_HEADSET ||
762 dev == AUDIO_DEVICE_OUT_WIRED_HEADPHONE);
763 }
764 if (valid_dev) {
vivek mehtaa68fea62017-06-08 19:04:02 -0700765 ALOGV("%s: out device is %d", __func__, usecase->out_snd_device);
766 if (audio_extn_spkr_prot_is_enabled()) {
vivek mehta4cb82982015-07-13 12:05:49 -0700767 acdb_dev_id = audio_extn_spkr_prot_get_acdb_id(usecase->out_snd_device);
vivek mehtaa68fea62017-06-08 19:04:02 -0700768 } else {
769 acdb_dev_id = acdb_device_table[usecase->out_snd_device];
770 }
vivek mehta4cb82982015-07-13 12:05:49 -0700771
vivek mehtaa68fea62017-06-08 19:04:02 -0700772 if (!my_data->acdb_send_gain_dep_cal(acdb_dev_id, app_type,
vivek mehta1a9b7c02015-06-25 11:49:38 -0700773 acdb_dev_type, mode, level)) {
774 // set ret_val true if at least one calibration is set successfully
775 ret_val = true;
776 } else {
777 ALOGE("%s: my_data->acdb_send_gain_dep_cal failed ", __func__);
778 }
779 } else {
780 ALOGW("%s: Usecase list is empty", __func__);
781 }
782 }
783 } else {
784 ALOGW("%s: Voice call in progress .. ignore setting new cal",
785 __func__);
786 }
787 return ret_val;
788}
789
Eric Laurentcefbbac2014-09-04 13:54:10 -0500790void platform_set_echo_reference(struct audio_device *adev, bool enable, audio_devices_t out_device)
Eric Laurentb23d5282013-05-14 15:27:20 -0700791{
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800792 struct platform_data *my_data = (struct platform_data *)adev->platform;
Eric Laurentcefbbac2014-09-04 13:54:10 -0500793 snd_device_t snd_device = SND_DEVICE_NONE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700794
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800795 if (strcmp(my_data->ec_ref_mixer_path, "")) {
796 ALOGV("%s: diabling %s", __func__, my_data->ec_ref_mixer_path);
797 audio_route_reset_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
Eric Laurentcefbbac2014-09-04 13:54:10 -0500798 }
799
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800800 if (enable) {
801 strcpy(my_data->ec_ref_mixer_path, "echo-reference");
802 if (out_device != AUDIO_DEVICE_NONE) {
803 snd_device = platform_get_output_snd_device(adev->platform, out_device);
804 platform_add_backend_name(adev->platform, my_data->ec_ref_mixer_path, snd_device);
805 }
Eric Laurentcefbbac2014-09-04 13:54:10 -0500806
Joe Onorato188b6222016-03-01 11:02:27 -0800807 ALOGV("%s: enabling %s", __func__, my_data->ec_ref_mixer_path);
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800808 audio_route_apply_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
809 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700810}
811
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700812static struct csd_data *open_csd_client(bool i2s_ext_modem)
813{
814 struct csd_data *csd = calloc(1, sizeof(struct csd_data));
815
816 csd->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
817 if (csd->csd_client == NULL) {
818 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
819 goto error;
820 } else {
821 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
822
823 csd->deinit = (deinit_t)dlsym(csd->csd_client,
824 "csd_client_deinit");
825 if (csd->deinit == NULL) {
826 ALOGE("%s: dlsym error %s for csd_client_deinit", __func__,
827 dlerror());
828 goto error;
829 }
830 csd->disable_device = (disable_device_t)dlsym(csd->csd_client,
831 "csd_client_disable_device");
832 if (csd->disable_device == NULL) {
833 ALOGE("%s: dlsym error %s for csd_client_disable_device",
834 __func__, dlerror());
835 goto error;
836 }
837 csd->enable_device_config = (enable_device_config_t)dlsym(csd->csd_client,
838 "csd_client_enable_device_config");
839 if (csd->enable_device_config == NULL) {
840 ALOGE("%s: dlsym error %s for csd_client_enable_device_config",
841 __func__, dlerror());
842 goto error;
843 }
844 csd->enable_device = (enable_device_t)dlsym(csd->csd_client,
845 "csd_client_enable_device");
846 if (csd->enable_device == NULL) {
847 ALOGE("%s: dlsym error %s for csd_client_enable_device",
848 __func__, dlerror());
849 goto error;
850 }
851 csd->start_voice = (start_voice_t)dlsym(csd->csd_client,
852 "csd_client_start_voice");
853 if (csd->start_voice == NULL) {
854 ALOGE("%s: dlsym error %s for csd_client_start_voice",
855 __func__, dlerror());
856 goto error;
857 }
858 csd->stop_voice = (stop_voice_t)dlsym(csd->csd_client,
859 "csd_client_stop_voice");
860 if (csd->stop_voice == NULL) {
861 ALOGE("%s: dlsym error %s for csd_client_stop_voice",
862 __func__, dlerror());
863 goto error;
864 }
865 csd->volume = (volume_t)dlsym(csd->csd_client,
866 "csd_client_volume");
867 if (csd->volume == NULL) {
868 ALOGE("%s: dlsym error %s for csd_client_volume",
869 __func__, dlerror());
870 goto error;
871 }
872 csd->mic_mute = (mic_mute_t)dlsym(csd->csd_client,
873 "csd_client_mic_mute");
874 if (csd->mic_mute == NULL) {
875 ALOGE("%s: dlsym error %s for csd_client_mic_mute",
876 __func__, dlerror());
877 goto error;
878 }
879 csd->slow_talk = (slow_talk_t)dlsym(csd->csd_client,
880 "csd_client_slow_talk");
881 if (csd->slow_talk == NULL) {
882 ALOGE("%s: dlsym error %s for csd_client_slow_talk",
883 __func__, dlerror());
884 goto error;
885 }
886 csd->start_playback = (start_playback_t)dlsym(csd->csd_client,
887 "csd_client_start_playback");
888 if (csd->start_playback == NULL) {
889 ALOGE("%s: dlsym error %s for csd_client_start_playback",
890 __func__, dlerror());
891 goto error;
892 }
893 csd->stop_playback = (stop_playback_t)dlsym(csd->csd_client,
894 "csd_client_stop_playback");
895 if (csd->stop_playback == NULL) {
896 ALOGE("%s: dlsym error %s for csd_client_stop_playback",
897 __func__, dlerror());
898 goto error;
899 }
900 csd->start_record = (start_record_t)dlsym(csd->csd_client,
901 "csd_client_start_record");
902 if (csd->start_record == NULL) {
903 ALOGE("%s: dlsym error %s for csd_client_start_record",
904 __func__, dlerror());
905 goto error;
906 }
907 csd->stop_record = (stop_record_t)dlsym(csd->csd_client,
908 "csd_client_stop_record");
909 if (csd->stop_record == NULL) {
910 ALOGE("%s: dlsym error %s for csd_client_stop_record",
911 __func__, dlerror());
912 goto error;
913 }
914
915 csd->get_sample_rate = (get_sample_rate_t)dlsym(csd->csd_client,
916 "csd_client_get_sample_rate");
917 if (csd->get_sample_rate == NULL) {
918 ALOGE("%s: dlsym error %s for csd_client_get_sample_rate",
919 __func__, dlerror());
920
921 goto error;
922 }
923
924 csd->init = (init_t)dlsym(csd->csd_client, "csd_client_init");
925
926 if (csd->init == NULL) {
927 ALOGE("%s: dlsym error %s for csd_client_init",
928 __func__, dlerror());
929 goto error;
930 } else {
931 csd->init(i2s_ext_modem);
932 }
933 }
934 return csd;
935
936error:
937 free(csd);
938 csd = NULL;
939 return csd;
940}
941
942void close_csd_client(struct csd_data *csd)
943{
944 if (csd != NULL) {
945 csd->deinit();
946 dlclose(csd->csd_client);
947 free(csd);
948 csd = NULL;
949 }
950}
951
952static void platform_csd_init(struct platform_data *my_data)
953{
954#ifdef PLATFORM_MSM8084
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700955 int32_t modems, (*count_modems)(void);
956 const char *name = "libdetectmodem.so";
957 const char *func = "count_modems";
958 const char *error;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700959
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700960 my_data->csd = NULL;
961
962 void *lib = dlopen(name, RTLD_NOW);
963 error = dlerror();
964 if (!lib) {
965 ALOGE("%s: could not find %s: %s", __func__, name, error);
966 return;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700967 }
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700968
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700969 count_modems = NULL;
970 *(void **)(&count_modems) = dlsym(lib, func);
971 error = dlerror();
972 if (!count_modems) {
973 ALOGE("%s: could not find symbol %s in %s: %s",
974 __func__, func, name, error);
975 goto done;
976 }
977
978 modems = count_modems();
979 if (modems < 0) {
980 ALOGE("%s: count_modems failed\n", __func__);
981 goto done;
982 }
983
Eric Laurent2bafff12016-03-17 12:17:23 -0700984 ALOGD("%s: num_modems %d\n", __func__, modems);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700985 if (modems > 0)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700986 my_data->csd = open_csd_client(false /*is_i2s_ext_modem*/);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700987
988done:
989 dlclose(lib);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700990#else
991 my_data->csd = NULL;
992#endif
993}
994
Eric Laurentc6333382015-09-14 12:43:44 -0700995static void set_platform_defaults(struct platform_data * my_data)
Haynes Mathew George98c95622014-06-20 19:14:25 -0700996{
997 int32_t dev;
998 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700999 backend_tag_table[dev] = NULL;
1000 hw_interface_table[dev] = NULL;
keunhui.park2f7306a2015-07-16 16:48:06 +09001001 operator_specific_device_table[dev] = NULL;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001002 }
1003
David Linee3fe402017-03-13 10:00:42 -07001004 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1005 backend_bit_width_table[dev] = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
1006 }
1007
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001008 // To overwrite these go to the audio_platform_info.xml file.
1009 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("bt-sco");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07001010 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("bt-sco");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001011 backend_tag_table[SND_DEVICE_OUT_BT_SCO] = strdup("bt-sco");
1012 backend_tag_table[SND_DEVICE_OUT_HDMI] = strdup("hdmi");
1013 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("speaker-and-hdmi");
1014 backend_tag_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("bt-sco-wb");
1015 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("bt-sco-wb");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07001016 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("bt-sco-wb");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001017 backend_tag_table[SND_DEVICE_OUT_VOICE_TX] = strdup("afe-proxy");
1018 backend_tag_table[SND_DEVICE_IN_VOICE_RX] = strdup("afe-proxy");
Haynes Mathew George98c95622014-06-20 19:14:25 -07001019
David Linee3fe402017-03-13 10:00:42 -07001020 backend_tag_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("usb-headset");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001021 backend_tag_table[SND_DEVICE_OUT_VOICE_USB_HEADSET] = strdup("usb-headset");
David Linee3fe402017-03-13 10:00:42 -07001022 backend_tag_table[SND_DEVICE_OUT_USB_HEADPHONES] = strdup("usb-headphones");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001023 backend_tag_table[SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = strdup("usb-headphones");
David Linee3fe402017-03-13 10:00:42 -07001024 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] =
1025 strdup("speaker-and-usb-headphones");
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07001026 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] =
1027 strdup("speaker-safe-and-usb-headphones");
David Linee3fe402017-03-13 10:00:42 -07001028 backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("usb-headset-mic");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001029 backend_tag_table[SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1030 backend_tag_table[SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1031 backend_tag_table[SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1032 backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = strdup("usb-headset-mic");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001033 hw_interface_table[SND_DEVICE_OUT_HANDSET] = strdup("SLIMBUS_0_RX");
1034 hw_interface_table[SND_DEVICE_OUT_SPEAKER] = strdup("SLIMBUS_0_RX");
1035 hw_interface_table[SND_DEVICE_OUT_SPEAKER_REVERSE] = strdup("SLIMBUS_0_RX");
1036 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE] = strdup("SLIMBUS_0_RX");
1037 hw_interface_table[SND_DEVICE_OUT_HEADPHONES] = strdup("SLIMBUS_0_RX");
1038 hw_interface_table[SND_DEVICE_OUT_LINE] = strdup("SLIMBUS_0_RX");
1039 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001040 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001041 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001042 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001043 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET] = strdup("SLIMBUS_0_RX");
1044 hw_interface_table[SND_DEVICE_OUT_VOICE_HAC_HANDSET] = strdup("SLIMBUS_0_RX");
1045 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER] = strdup("SLIMBUS_0_RX");
1046 hw_interface_table[SND_DEVICE_OUT_VOICE_HEADPHONES] = strdup("SLIMBUS_0_RX");
1047 hw_interface_table[SND_DEVICE_OUT_VOICE_LINE] = strdup("SLIMBUS_0_RX");
1048 hw_interface_table[SND_DEVICE_OUT_HDMI] = strdup("HDMI_RX");
1049 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("SLIMBUS_0_RX-and-HDMI_RX");
1050 hw_interface_table[SND_DEVICE_OUT_BT_SCO] = strdup("SEC_AUX_PCM_RX");
1051 hw_interface_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("SEC_AUX_PCM_RX");
1052 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = strdup("SLIMBUS_0_RX");
1053 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = strdup("SLIMBUS_0_RX");
1054 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = strdup("SLIMBUS_0_RX");
1055 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = strdup("SLIMBUS_0_RX");
David Linee3fe402017-03-13 10:00:42 -07001056 hw_interface_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("USB_AUDIO_RX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001057 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = strdup("USB_AUDIO_RX");
1058 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = strdup("USB_AUDIO_RX");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001059 hw_interface_table[SND_DEVICE_OUT_VOICE_USB_HEADSET] = strdup("USB_AUDIO_RX");
David Linee3fe402017-03-13 10:00:42 -07001060 hw_interface_table[SND_DEVICE_OUT_USB_HEADPHONES] = strdup("USB_AUDIO_RX");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001061 hw_interface_table[SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = strdup("USB_AUDIO_RX");
David Linee3fe402017-03-13 10:00:42 -07001062 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 -07001063 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 -07001064 hw_interface_table[SND_DEVICE_OUT_VOICE_TX] = strdup("AFE_PCM_RX");
1065 hw_interface_table[SND_DEVICE_OUT_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
1066 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001067 hw_interface_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1068 hw_interface_table[SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1069 hw_interface_table[SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = strdup("USB_AUDIO_TX");
1070 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1071 hw_interface_table[SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1072 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = strdup("USB_AUDIO_TX");
1073 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = strdup("USB_AUDIO_TX");
1074 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC] = strdup("SLIMBUS_0_TX");
1075 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC] = strdup("SLIMBUS_0_TX");
1076 hw_interface_table[SND_DEVICE_IN_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1077 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_MIC] = strdup("SLIMBUS_0_TX");
1078 hw_interface_table[SND_DEVICE_IN_CAMCORDER_MIC] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001079 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC] = strdup("SLIMBUS_0_TX");
1080 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC_NS] = strdup("SLIMBUS_0_TX");
1081 hw_interface_table[SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
1082 hw_interface_table[SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = strdup("SLIMBUS_0_TX");
1083 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC] = strdup("SLIMBUS_0_TX");
1084 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_AEC] = strdup("SLIMBUS_0_TX");
1085 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_NS] = strdup("SLIMBUS_0_TX");
1086 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1087 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC] = strdup("SLIMBUS_0_TX");
1088 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_AEC] = strdup("SLIMBUS_0_TX");
1089 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_NS] = strdup("SLIMBUS_0_TX");
1090 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1091 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_MIC] = strdup("SLIMBUS_0_TX");
1092 hw_interface_table[SND_DEVICE_IN_VOICE_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
Eric Laurentc6333382015-09-14 12:43:44 -07001093 my_data->max_mic_count = PLATFORM_DEFAULT_MIC_COUNT;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001094}
1095
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001096void get_cvd_version(char *cvd_version, struct audio_device *adev)
1097{
1098 struct mixer_ctl *ctl;
1099 int count;
1100 int ret = 0;
1101
1102 ctl = mixer_get_ctl_by_name(adev->mixer, CVD_VERSION_MIXER_CTL);
1103 if (!ctl) {
1104 ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__, CVD_VERSION_MIXER_CTL);
1105 goto done;
1106 }
1107 mixer_ctl_update(ctl);
1108
1109 count = mixer_ctl_get_num_values(ctl);
1110 if (count > MAX_CVD_VERSION_STRING_SIZE)
1111 count = MAX_CVD_VERSION_STRING_SIZE - 1;
1112
1113 ret = mixer_ctl_get_array(ctl, cvd_version, count);
1114 if (ret != 0) {
1115 ALOGE("%s: ERROR! mixer_ctl_get_array() failed to get CVD Version", __func__);
1116 goto done;
1117 }
1118
1119done:
1120 return;
1121}
1122
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001123static int platform_acdb_init(void *platform)
1124{
1125 struct platform_data *my_data = (struct platform_data *)platform;
1126 struct audio_device *adev = my_data->adev;
1127
1128 if (!my_data->acdb_init) {
1129 ALOGE("%s: no acdb_init fn provided", __func__);
1130 return -1;
1131 }
1132
1133 if (my_data->acdb_initialized) {
1134 ALOGW("acdb is already initialized");
1135 return 0;
1136 }
1137
Thierry Strudel92232b42017-01-26 10:51:48 -08001138#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001139 char *cvd_version = calloc(1, MAX_CVD_VERSION_STRING_SIZE);
1140 if (!cvd_version)
1141 ALOGE("failed to allocate cvd_version");
1142 else {
1143 get_cvd_version(cvd_version, adev);
1144 my_data->acdb_init((char *)my_data->snd_card_name, cvd_version, 0);
1145 free(cvd_version);
1146 }
1147#elif defined (PLATFORM_MSM8084)
1148 my_data->acdb_init((char *)my_data->snd_card_name);
1149#else
1150 my_data->acdb_init();
1151#endif
1152 my_data->acdb_initialized = true;
1153 return 0;
1154}
1155
David Linee3fe402017-03-13 10:00:42 -07001156static void
1157platform_backend_config_init(struct platform_data *pdata)
1158{
1159 int i;
1160
1161 /* initialize backend config */
1162 for (i = 0; i < MAX_CODEC_BACKENDS; i++) {
1163 pdata->current_backend_cfg[i].sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
1164 pdata->current_backend_cfg[i].bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
1165 pdata->current_backend_cfg[i].channels = CODEC_BACKEND_DEFAULT_CHANNELS;
1166
1167 if (i > MAX_RX_CODEC_BACKENDS)
1168 pdata->current_backend_cfg[i].channels = CODEC_BACKEND_DEFAULT_TX_CHANNELS;
1169
1170 pdata->current_backend_cfg[i].bitwidth_mixer_ctl = NULL;
1171 pdata->current_backend_cfg[i].samplerate_mixer_ctl = NULL;
1172 pdata->current_backend_cfg[i].channels_mixer_ctl = NULL;
1173 }
1174
1175 pdata->current_backend_cfg[DEFAULT_CODEC_BACKEND].bitwidth_mixer_ctl =
1176 strdup("SLIM_0_RX Format");
1177 pdata->current_backend_cfg[DEFAULT_CODEC_BACKEND].samplerate_mixer_ctl =
1178 strdup("SLIM_0_RX SampleRate");
1179
1180 pdata->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].bitwidth_mixer_ctl =
1181 strdup("SLIM_0_TX Format");
1182 pdata->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].samplerate_mixer_ctl =
1183 strdup("SLIM_0_TX SampleRate");
1184
1185 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].bitwidth_mixer_ctl =
1186 strdup("USB_AUDIO_TX Format");
1187 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].samplerate_mixer_ctl =
1188 strdup("USB_AUDIO_TX SampleRate");
1189 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].channels_mixer_ctl =
1190 strdup("USB_AUDIO_TX Channels");
1191
1192 pdata->current_backend_cfg[HEADPHONE_BACKEND].bitwidth_mixer_ctl =
1193 strdup("SLIM_6_RX Format");
1194 pdata->current_backend_cfg[HEADPHONE_BACKEND].samplerate_mixer_ctl =
1195 strdup("SLIM_6_RX SampleRate");
1196
1197 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].bitwidth_mixer_ctl =
1198 strdup("USB_AUDIO_RX Format");
1199 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].samplerate_mixer_ctl =
1200 strdup("USB_AUDIO_RX SampleRate");
1201
1202 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].channels = 1;
1203 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].channels_mixer_ctl =
1204 strdup("USB_AUDIO_RX Channels");
1205}
1206
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001207static int
1208platform_backend_app_type_cfg_init(struct platform_data *pdata,
1209 struct mixer *mixer)
1210{
1211 size_t app_type_cfg[128] = {0};
1212 int length, num_app_types = 0;
1213 struct mixer_ctl *ctl = NULL;
1214
1215 const char *mixer_ctl_name = "App Type Config";
1216 ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name);
1217 if (!ctl) {
1218 ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name);
1219 return -1;
1220 }
1221
1222 length = 1; // reserve index 0 for number of app types
1223
1224 struct listnode *node;
1225 struct app_type_entry *entry;
1226 list_for_each(node, &app_type_entry_list) {
1227 entry = node_to_item(node, struct app_type_entry, node);
1228 app_type_cfg[length++] = entry->app_type;
1229 app_type_cfg[length++] = entry->max_rate;
1230 app_type_cfg[length++] = entry->bit_width;
1231 ALOGI("%s add entry %d %d", __func__, entry->app_type, entry->bit_width);
1232 num_app_types += 1;
1233 }
1234
1235 // default for capture
1236 int t;
1237 platform_get_default_app_type_v2(pdata,
1238 PCM_CAPTURE,
1239 &t);
1240 app_type_cfg[length++] = t;
1241 app_type_cfg[length++] = 48000;
1242 app_type_cfg[length++] = 16;
1243 num_app_types += 1;
1244
1245 if (num_app_types) {
1246 app_type_cfg[0] = num_app_types;
1247 if (mixer_ctl_set_array(ctl, app_type_cfg, length) < 0) {
1248 ALOGE("Failed to set app type cfg");
1249 }
1250 }
1251 return 0;
1252}
1253
Eric Laurentb23d5282013-05-14 15:27:20 -07001254void *platform_init(struct audio_device *adev)
1255{
1256 char value[PROPERTY_VALUE_MAX];
vivek mehta60ea4152016-02-18 17:10:26 -08001257 struct platform_data *my_data = NULL;
1258 int retry_num = 0, snd_card_num = 0, key = 0, ret = 0;
1259 bool dual_mic_config = false, use_default_mixer_path = true;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001260 const char *snd_card_name;
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001261 char *cvd_version = NULL;
vivek mehta60ea4152016-02-18 17:10:26 -08001262 char *snd_internal_name = NULL;
1263 char *tmp = NULL;
1264 char mixer_xml_file[MIXER_PATH_MAX_LENGTH]= {0};
vivek mehtade4849c2016-03-03 17:23:38 -08001265 char platform_info_file[MIXER_PATH_MAX_LENGTH]= {0};
1266 struct snd_card_split *snd_split_handle = NULL;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001267 my_data = calloc(1, sizeof(struct platform_data));
1268
1269 my_data->adev = adev;
1270
keunhui.park2f7306a2015-07-16 16:48:06 +09001271 list_init(&operator_info_list);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001272 list_init(&app_type_entry_list);
keunhui.park2f7306a2015-07-16 16:48:06 +09001273
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001274 set_platform_defaults(my_data);
1275
vivek mehta0fb11312017-05-15 19:35:32 -07001276 // audio_extn_utils_get_snd_card_num does
1277 // - open mixer and get snd card name
1278 // - parse platform info xml file and check for valid snd card name
1279 // - on failure loop through all the active snd card
sangwoo1b9f4b32013-06-21 18:22:55 -07001280
vivek mehta0fb11312017-05-15 19:35:32 -07001281 snd_card_num = audio_extn_utils_get_snd_card_num();
1282 if (-1 == snd_card_num) {
1283 ALOGE("%s: invalid sound card number (-1), bailing out ", __func__);
1284 goto init_failed;
sangwoo1b9f4b32013-06-21 18:22:55 -07001285 }
1286
vivek mehta0fb11312017-05-15 19:35:32 -07001287 adev->mixer = mixer_open(snd_card_num);
1288 snd_card_name = mixer_get_name(adev->mixer);
1289 my_data->hw_info = hw_info_init(snd_card_name);
1290
1291 audio_extn_set_snd_card_split(snd_card_name);
1292 snd_split_handle = audio_extn_get_snd_card_split();
1293
1294 /* Get the codec internal name from the sound card and/or form factor
1295 * name and form the mixer paths and platfor info file name dynamically.
1296 * This is generic way of picking any codec and forma factor name based
1297 * mixer and platform info files in future with no code change.
1298
1299 * current code extends and looks for any of the exteneded mixer path and
1300 * platform info file present based on codec and form factor.
1301
1302 * order of picking appropriate file is
1303 * <i> mixer_paths_<codec_name>_<form_factor>.xml, if file not present
1304 * <ii> mixer_paths_<codec_name>.xml, if file not present
1305 * <iii> mixer_paths.xml
1306
1307 * same order is followed for audio_platform_info.xml as well
1308 */
1309
1310 // need to carryforward old file name
1311 if (!strncmp(snd_card_name, TOMTOM_8226_SND_CARD_NAME,
1312 min(strlen(TOMTOM_8226_SND_CARD_NAME), strlen(snd_card_name)))) {
1313 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1314 MIXER_XML_BASE_STRING, TOMTOM_MIXER_FILE_SUFFIX );
1315 } else {
1316
1317 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s_%s.xml",
1318 MIXER_XML_BASE_STRING, snd_split_handle->snd_card,
1319 snd_split_handle->form_factor);
1320 if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) {
1321 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1322 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1323 MIXER_XML_BASE_STRING, snd_split_handle->snd_card);
1324
1325 if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) {
1326 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1327 strlcpy(mixer_xml_file, MIXER_XML_DEFAULT_PATH, MIXER_PATH_MAX_LENGTH);
1328 audio_extn_utils_resolve_config_file(mixer_xml_file);
1329 }
1330 }
1331 }
1332
1333 audio_extn_utils_get_platform_info(snd_card_name, platform_info_file);
1334
1335 /* Initialize platform specific ids and/or backends*/
1336 platform_info_init(platform_info_file, my_data);
1337
1338 ALOGD("%s: Loading mixer file: %s", __func__, mixer_xml_file);
1339 adev->audio_route = audio_route_init(snd_card_num, mixer_xml_file);
1340
1341 if (!adev->audio_route) {
1342 ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
1343 mixer_close(adev->mixer);
1344 adev->mixer = NULL;
1345 hw_info_deinit(my_data->hw_info);
1346 my_data->hw_info = NULL;
1347 goto init_failed;
1348 }
1349 adev->snd_card = snd_card_num;
1350 ALOGD("%s: Opened sound card:%d", __func__, snd_card_num);
1351
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09001352 //set max volume step for voice call
1353 property_get("ro.config.vc_call_vol_steps", value, TOSTRING(MAX_VOL_INDEX));
1354 my_data->max_vol_index = atoi(value);
1355
vivek mehta65ad12d2015-08-13 18:32:48 -07001356 property_get("persist.audio.dualmic.config",value,"");
1357 if (!strcmp("endfire", value)) {
1358 dual_mic_config = true;
1359 }
1360
Prashant Malanic92c5962015-08-11 15:10:18 -07001361 my_data->source_mic_type = SOURCE_DUAL_MIC;
1362
Eric Laurentb23d5282013-05-14 15:27:20 -07001363 my_data->fluence_in_spkr_mode = false;
1364 my_data->fluence_in_voice_call = false;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001365 my_data->fluence_in_voice_comm = false;
Eric Laurentb23d5282013-05-14 15:27:20 -07001366 my_data->fluence_in_voice_rec = false;
1367
vivek mehta65ad12d2015-08-13 18:32:48 -07001368 property_get("ro.qc.sdk.audio.fluencetype", value, "none");
Prashant Malanic92c5962015-08-11 15:10:18 -07001369 if (!strcmp("fluencepro", value)) {
1370 my_data->fluence_type = FLUENCE_PRO_ENABLE;
vivek mehta65ad12d2015-08-13 18:32:48 -07001371 } else if (!strcmp("fluence", value) || (dual_mic_config)) {
Prashant Malanic92c5962015-08-11 15:10:18 -07001372 my_data->fluence_type = FLUENCE_ENABLE;
1373 } else if (!strcmp("none", value)) {
1374 my_data->fluence_type = FLUENCE_DISABLE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001375 }
1376
Prashant Malanic92c5962015-08-11 15:10:18 -07001377 if (my_data->fluence_type != FLUENCE_DISABLE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001378 property_get("persist.audio.fluence.voicecall",value,"");
1379 if (!strcmp("true", value)) {
1380 my_data->fluence_in_voice_call = true;
1381 }
1382
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001383 property_get("persist.audio.fluence.voicecomm",value,"");
1384 if (!strcmp("true", value)) {
1385 my_data->fluence_in_voice_comm = true;
1386 }
1387
Eric Laurentb23d5282013-05-14 15:27:20 -07001388 property_get("persist.audio.fluence.voicerec",value,"");
1389 if (!strcmp("true", value)) {
1390 my_data->fluence_in_voice_rec = true;
1391 }
1392
1393 property_get("persist.audio.fluence.speaker",value,"");
1394 if (!strcmp("true", value)) {
1395 my_data->fluence_in_spkr_mode = true;
1396 }
1397 }
1398
Prashant Malanic92c5962015-08-11 15:10:18 -07001399 // support max to mono, example if max count is 3, usecase supports Three, dual and mono mic
1400 switch (my_data->max_mic_count) {
1401 case 4:
1402 my_data->source_mic_type |= SOURCE_QUAD_MIC;
1403 case 3:
1404 my_data->source_mic_type |= SOURCE_THREE_MIC;
1405 case 2:
1406 my_data->source_mic_type |= SOURCE_DUAL_MIC;
1407 case 1:
1408 my_data->source_mic_type |= SOURCE_MONO_MIC;
1409 break;
1410 default:
1411 ALOGE("%s: max_mic_count (%d), is not supported, setting to default",
1412 __func__, my_data->max_mic_count);
1413 my_data->source_mic_type = SOURCE_MONO_MIC|SOURCE_DUAL_MIC;
1414 break;
1415 }
1416
1417 ALOGV("%s: Fluence_Type(%d) max_mic_count(%d) mic_type(0x%x) fluence_in_voice_call(%d)"
1418 " fluence_in_voice_comm(%d) fluence_in_voice_rec(%d) fluence_in_spkr_mode(%d) ",
1419 __func__, my_data->fluence_type, my_data->max_mic_count, my_data->source_mic_type,
1420 my_data->fluence_in_voice_call, my_data->fluence_in_voice_comm,
1421 my_data->fluence_in_voice_rec, my_data->fluence_in_spkr_mode);
1422
Eric Laurentb23d5282013-05-14 15:27:20 -07001423 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
1424 if (my_data->acdb_handle == NULL) {
1425 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
1426 } else {
1427 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
1428 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
1429 "acdb_loader_deallocate_ACDB");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001430 if (!my_data->acdb_deallocate)
1431 ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s",
1432 __func__, LIB_ACDB_LOADER);
1433
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001434 my_data->acdb_send_audio_cal_v3 = (acdb_send_audio_cal_v3_t)dlsym(my_data->acdb_handle,
1435 "acdb_loader_send_audio_cal_v3");
1436 if (!my_data->acdb_send_audio_cal_v3)
1437 ALOGE("%s: Could not find the symbol acdb_send_audio_cal_v3 from %s",
1438 __func__, LIB_ACDB_LOADER);
1439
Eric Laurentb23d5282013-05-14 15:27:20 -07001440 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
1441 "acdb_loader_send_audio_cal");
1442 if (!my_data->acdb_send_audio_cal)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001443 ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s",
Eric Laurentb23d5282013-05-14 15:27:20 -07001444 __func__, LIB_ACDB_LOADER);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001445
Eric Laurentb23d5282013-05-14 15:27:20 -07001446 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
1447 "acdb_loader_send_voice_cal");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001448 if (!my_data->acdb_send_voice_cal)
1449 ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s",
1450 __func__, LIB_ACDB_LOADER);
1451
1452 my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle,
1453 "acdb_loader_reload_vocvoltable");
1454 if (!my_data->acdb_reload_vocvoltable)
1455 ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s",
1456 __func__, LIB_ACDB_LOADER);
vivek mehta1a9b7c02015-06-25 11:49:38 -07001457
1458 my_data->acdb_send_gain_dep_cal = (acdb_send_gain_dep_cal_t)dlsym(my_data->acdb_handle,
1459 "acdb_loader_send_gain_dep_cal");
1460 if (!my_data->acdb_send_gain_dep_cal)
1461 ALOGV("%s: Could not find the symbol acdb_loader_send_gain_dep_cal from %s",
1462 __func__, LIB_ACDB_LOADER);
1463
Thierry Strudel92232b42017-01-26 10:51:48 -08001464#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998)
vivek mehta0fb11312017-05-15 19:35:32 -07001465 acdb_init_v2_cvd_t acdb_init_local;
1466 acdb_init_local = (acdb_init_v2_cvd_t)dlsym(my_data->acdb_handle,
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001467 "acdb_loader_init_v2");
vivek mehta0fb11312017-05-15 19:35:32 -07001468 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001469 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1470 dlerror());
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001471
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001472#elif defined (PLATFORM_MSM8084)
vivek mehta0fb11312017-05-15 19:35:32 -07001473 acdb_init_v2_t acdb_init_local;
1474 acdb_init_local = (acdb_init_v2_t)dlsym(my_data->acdb_handle,
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001475 "acdb_loader_init_v2");
vivek mehta0fb11312017-05-15 19:35:32 -07001476 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001477 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1478 dlerror());
1479
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001480#else
vivek mehta0fb11312017-05-15 19:35:32 -07001481 acdb_init_t acdb_init_local;
1482 acdb_init_local = (acdb_init_t)dlsym(my_data->acdb_handle,
Eric Laurentb23d5282013-05-14 15:27:20 -07001483 "acdb_loader_init_ACDB");
vivek mehta0fb11312017-05-15 19:35:32 -07001484 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001485 ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__,
1486 dlerror());
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001487#endif
vivek mehta0fb11312017-05-15 19:35:32 -07001488 my_data->acdb_init = acdb_init_local;
Eric Laurentb23d5282013-05-14 15:27:20 -07001489
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001490 my_data->acdb_send_custom_top = (acdb_send_custom_top_t)
1491 dlsym(my_data->acdb_handle,
1492 "acdb_loader_send_common_custom_topology");
1493
1494 if (!my_data->acdb_send_custom_top)
1495 ALOGE("%s: Could not find the symbol acdb_get_default_app_type from %s",
1496 __func__, LIB_ACDB_LOADER);
1497
vivek mehta0fb11312017-05-15 19:35:32 -07001498 int result = acdb_init(adev->snd_card);
1499 if (!result) {
1500 my_data->acdb_initialized = true;
1501 ALOGD("ACDB initialized");
1502 } else {
1503 my_data->acdb_initialized = false;
1504 ALOGD("ACDB initialization failed");
1505 }
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001506 }
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001507
David Linee3fe402017-03-13 10:00:42 -07001508 /* init usb */
1509 audio_extn_usb_init(adev);
1510
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001511 audio_extn_spkr_prot_init(adev);
Haynes Mathew George98c95622014-06-20 19:14:25 -07001512
Ravi Kumar Alamanda76315572015-04-23 13:13:56 -07001513 audio_extn_hwdep_cal_send(adev->snd_card, my_data->acdb_handle);
1514
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001515 /* load csd client */
1516 platform_csd_init(my_data);
1517
David Linee3fe402017-03-13 10:00:42 -07001518 platform_backend_config_init(my_data);
1519
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001520 init_be_dai_name_table(adev);
1521
1522 if (platform_supports_app_type_cfg())
1523 platform_backend_app_type_cfg_init(my_data, adev->mixer);
1524
Eric Laurentb23d5282013-05-14 15:27:20 -07001525 return my_data;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001526
1527init_failed:
1528 if (my_data)
1529 free(my_data);
1530 return NULL;
Eric Laurentb23d5282013-05-14 15:27:20 -07001531}
1532
1533void platform_deinit(void *platform)
1534{
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001535 int32_t dev;
keunhui.park2f7306a2015-07-16 16:48:06 +09001536 struct operator_info *info_item;
1537 struct operator_specific_device *device_item;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001538 struct app_type_entry *ap;
keunhui.park2f7306a2015-07-16 16:48:06 +09001539 struct listnode *node;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001540
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001541 struct platform_data *my_data = (struct platform_data *)platform;
1542 close_csd_client(my_data->csd);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001543
vivek mehtade4849c2016-03-03 17:23:38 -08001544 hw_info_deinit(my_data->hw_info);
1545
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001546 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1547 if (backend_tag_table[dev])
1548 free(backend_tag_table[dev]);
1549 if (hw_interface_table[dev])
1550 free(hw_interface_table[dev]);
keunhui.park2f7306a2015-07-16 16:48:06 +09001551 if (operator_specific_device_table[dev]) {
1552 while (!list_empty(operator_specific_device_table[dev])) {
1553 node = list_head(operator_specific_device_table[dev]);
1554 list_remove(node);
1555 device_item = node_to_item(node, struct operator_specific_device, list);
1556 free(device_item->operator);
1557 free(device_item->mixer_path);
1558 free(device_item);
1559 }
1560 free(operator_specific_device_table[dev]);
1561 }
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001562 }
1563
1564 if (my_data->snd_card_name)
1565 free(my_data->snd_card_name);
1566
keunhui.park2f7306a2015-07-16 16:48:06 +09001567 while (!list_empty(&operator_info_list)) {
1568 node = list_head(&operator_info_list);
1569 list_remove(node);
1570 info_item = node_to_item(node, struct operator_info, list);
1571 free(info_item->name);
1572 free(info_item->mccmnc);
1573 free(info_item);
1574 }
1575
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001576 while (!list_empty(&app_type_entry_list)) {
1577 node = list_head(&app_type_entry_list);
1578 list_remove(node);
1579 ap = node_to_item(node, struct app_type_entry, node);
vivek mehtaa68fea62017-06-08 19:04:02 -07001580 if (ap->mode) free(ap->mode);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001581 free(ap);
1582 }
1583
Kevin Rocarde35d4af2017-05-02 16:55:28 -07001584 mixer_close(my_data->adev->mixer);
Eric Laurentb23d5282013-05-14 15:27:20 -07001585 free(platform);
David Linee3fe402017-03-13 10:00:42 -07001586
1587 /* deinit usb */
1588 audio_extn_usb_deinit();
Eric Laurentb23d5282013-05-14 15:27:20 -07001589}
1590
1591const char *platform_get_snd_device_name(snd_device_t snd_device)
1592{
keunhui.park2f7306a2015-07-16 16:48:06 +09001593 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1594 if (operator_specific_device_table[snd_device] != NULL) {
1595 return get_operator_specific_device_mixer_path(snd_device);
1596 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001597 return device_table[snd_device];
keunhui.park2f7306a2015-07-16 16:48:06 +09001598 } else
Ravi Kumar Alamanda64026462014-09-15 00:08:58 -07001599 return "none";
Eric Laurentb23d5282013-05-14 15:27:20 -07001600}
1601
vivek mehtade4849c2016-03-03 17:23:38 -08001602int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
1603 char *device_name)
1604{
1605 struct platform_data *my_data = (struct platform_data *)platform;
1606
David Benjamin1565f992016-09-21 12:10:34 -04001607 if (platform == NULL) {
vivek mehtade4849c2016-03-03 17:23:38 -08001608 ALOGW("%s: something wrong, use legacy get_snd_device name", __func__);
David Benjamin1565f992016-09-21 12:10:34 -04001609 strlcpy(device_name, platform_get_snd_device_name(snd_device),
1610 DEVICE_NAME_MAX_SIZE);
vivek mehtade4849c2016-03-03 17:23:38 -08001611 } else if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1612 if (operator_specific_device_table[snd_device] != NULL) {
1613 strlcpy(device_name, get_operator_specific_device_mixer_path(snd_device),
1614 DEVICE_NAME_MAX_SIZE);
1615 } else {
1616 strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE);
1617 }
1618 hw_info_append_hw_type(my_data->hw_info, snd_device, device_name);
1619 } else {
1620 strlcpy(device_name, "none", DEVICE_NAME_MAX_SIZE);
1621 }
1622
1623 return 0;
1624}
1625
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001626void platform_add_backend_name(void *platform, char *mixer_path,
1627 snd_device_t snd_device)
Eric Laurentb23d5282013-05-14 15:27:20 -07001628{
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001629 struct platform_data *my_data = (struct platform_data *)platform;
1630
Haynes Mathew George98c95622014-06-20 19:14:25 -07001631 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1632 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1633 return;
Ravi Kumar Alamanda1de6e5a2014-06-19 21:55:39 -05001634 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001635
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001636 const char * suffix = backend_tag_table[snd_device];
Haynes Mathew George98c95622014-06-20 19:14:25 -07001637
1638 if (suffix != NULL) {
1639 strcat(mixer_path, " ");
1640 strcat(mixer_path, suffix);
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001641 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001642}
1643
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001644bool platform_check_backends_match(snd_device_t snd_device1, snd_device_t snd_device2)
1645{
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001646 ALOGV("%s: snd_device1 = %s, snd_device2 = %s", __func__,
1647 platform_get_snd_device_name(snd_device1),
1648 platform_get_snd_device_name(snd_device2));
1649
1650 if ((snd_device1 < SND_DEVICE_MIN) || (snd_device1 >= SND_DEVICE_MAX)) {
1651 ALOGE("%s: Invalid snd_device = %s", __func__,
1652 platform_get_snd_device_name(snd_device1));
1653 return false;
1654 }
1655 if ((snd_device2 < SND_DEVICE_MIN) || (snd_device2 >= SND_DEVICE_MAX)) {
1656 ALOGE("%s: Invalid snd_device = %s", __func__,
1657 platform_get_snd_device_name(snd_device2));
1658 return false;
1659 }
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07001660
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001661 const char * be_itf1 = hw_interface_table[snd_device1];
1662 const char * be_itf2 = hw_interface_table[snd_device2];
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07001663 /*
1664 hw_interface_table has overrides for a snd_device.
1665 if there is no entry for a device, assume DEFAULT_RX_BACKEND
1666 */
1667 if (be_itf1 == NULL) {
1668 be_itf1 = DEFAULT_RX_BACKEND;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001669 }
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07001670 if (be_itf2 == NULL) {
1671 be_itf2 = DEFAULT_RX_BACKEND;
1672 }
1673 ALOGV("%s: be_itf1 = %s, be_itf2 = %s", __func__, be_itf1, be_itf2);
1674 /*
1675 this takes care of finding a device within a combo device pair as well
1676 */
1677 return strstr(be_itf1, be_itf2) != NULL || strstr(be_itf2, be_itf1) != NULL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001678}
1679
Eric Laurentb23d5282013-05-14 15:27:20 -07001680int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
1681{
1682 int device_id;
1683 if (device_type == PCM_PLAYBACK)
1684 device_id = pcm_device_table[usecase][0];
1685 else
1686 device_id = pcm_device_table[usecase][1];
1687 return device_id;
1688}
1689
Haynes Mathew George98c95622014-06-20 19:14:25 -07001690static int find_index(const struct name_to_index * table, int32_t len,
1691 const char * name)
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001692{
1693 int ret = 0;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001694 int32_t i;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001695
Haynes Mathew George98c95622014-06-20 19:14:25 -07001696 if (table == NULL) {
1697 ALOGE("%s: table is NULL", __func__);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001698 ret = -ENODEV;
1699 goto done;
1700 }
1701
Haynes Mathew George98c95622014-06-20 19:14:25 -07001702 if (name == NULL) {
1703 ALOGE("null key");
1704 ret = -ENODEV;
1705 goto done;
1706 }
1707
1708 for (i=0; i < len; i++) {
1709 if (!strcmp(table[i].name, name)) {
1710 ret = table[i].index;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001711 goto done;
1712 }
1713 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001714 ALOGE("%s: Could not find index for name = %s",
1715 __func__, name);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001716 ret = -ENODEV;
1717done:
1718 return ret;
1719}
1720
Haynes Mathew George98c95622014-06-20 19:14:25 -07001721int platform_get_snd_device_index(char *device_name)
1722{
1723 return find_index(snd_device_name_index, SND_DEVICE_MAX, device_name);
1724}
1725
1726int platform_get_usecase_index(const char *usecase_name)
1727{
1728 return find_index(usecase_name_index, AUDIO_USECASE_MAX, usecase_name);
1729}
1730
keunhui.park2f7306a2015-07-16 16:48:06 +09001731void platform_add_operator_specific_device(snd_device_t snd_device,
1732 const char *operator,
1733 const char *mixer_path,
1734 unsigned int acdb_id)
1735{
1736 struct operator_specific_device *device;
1737
1738 if (operator_specific_device_table[snd_device] == NULL) {
1739 operator_specific_device_table[snd_device] =
1740 (struct listnode *)calloc(1, sizeof(struct listnode));
1741 list_init(operator_specific_device_table[snd_device]);
1742 }
1743
1744 device = (struct operator_specific_device *)calloc(1, sizeof(struct operator_specific_device));
1745
1746 device->operator = strdup(operator);
1747 device->mixer_path = strdup(mixer_path);
1748 device->acdb_id = acdb_id;
1749
1750 list_add_tail(operator_specific_device_table[snd_device], &device->list);
1751
Eric Laurent2bafff12016-03-17 12:17:23 -07001752 ALOGD("%s: device[%s] -> operator[%s] mixer_path[%s] acdb_id[%d]", __func__,
keunhui.park2f7306a2015-07-16 16:48:06 +09001753 platform_get_snd_device_name(snd_device), operator, mixer_path, acdb_id);
1754
1755}
1756
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001757int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
1758{
1759 int ret = 0;
1760
1761 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1762 ALOGE("%s: Invalid snd_device = %d",
1763 __func__, snd_device);
1764 ret = -EINVAL;
1765 goto done;
1766 }
1767
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001768 ALOGV("%s: acdb_device_table[%s]: old = %d new = %d", __func__,
1769 platform_get_snd_device_name(snd_device), acdb_device_table[snd_device], acdb_id);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001770 acdb_device_table[snd_device] = acdb_id;
1771done:
1772 return ret;
1773}
1774
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001775int platform_get_snd_device_acdb_id(snd_device_t snd_device)
1776{
1777 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1778 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1779 return -EINVAL;
1780 }
keunhui.park2f7306a2015-07-16 16:48:06 +09001781
1782 if (operator_specific_device_table[snd_device] != NULL)
1783 return get_operator_specific_device_acdb_id(snd_device);
1784 else
1785 return acdb_device_table[snd_device];
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001786}
1787
David Linee3fe402017-03-13 10:00:42 -07001788static int platform_get_backend_index(snd_device_t snd_device)
1789{
1790 int32_t port = DEFAULT_CODEC_BACKEND;
1791
1792 if (snd_device >= SND_DEVICE_OUT_BEGIN && snd_device < SND_DEVICE_OUT_END) {
1793 if (backend_tag_table[snd_device] != NULL) {
1794 if (strncmp(backend_tag_table[snd_device], "headphones",
1795 sizeof("headphones")) == 0)
1796 port = HEADPHONE_BACKEND;
1797 else if (strcmp(backend_tag_table[snd_device], "hdmi") == 0)
1798 port = HDMI_RX_BACKEND;
1799 else if ((strcmp(backend_tag_table[snd_device], "usb-headphones") == 0) ||
1800 (strcmp(backend_tag_table[snd_device], "usb-headset") == 0))
1801 port = USB_AUDIO_RX_BACKEND;
1802 }
1803 } else if (snd_device >= SND_DEVICE_IN_BEGIN && snd_device < SND_DEVICE_IN_END) {
1804 port = DEFAULT_CODEC_TX_BACKEND;
1805 if (backend_tag_table[snd_device] != NULL) {
1806 if (strcmp(backend_tag_table[snd_device], "usb-headset-mic") == 0)
1807 port = USB_AUDIO_TX_BACKEND;
1808 else if (strstr(backend_tag_table[snd_device], "bt-sco") != NULL)
1809 port = BT_SCO_TX_BACKEND;
1810 }
1811 } else {
1812 ALOGW("%s:napb: Invalid device - %d ", __func__, snd_device);
1813 }
1814
1815 ALOGV("%s:napb: backend port - %d device - %d ", __func__, port, snd_device);
1816
1817 return port;
1818}
1819
Eric Laurentb23d5282013-05-14 15:27:20 -07001820int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
1821{
1822 struct platform_data *my_data = (struct platform_data *)platform;
1823 int acdb_dev_id, acdb_dev_type;
1824
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001825 if (platform_supports_app_type_cfg()) // use v2 instead
1826 return -ENOSYS;
1827
Ravi Kumar Alamandaadf0f3b2015-06-04 02:34:02 -07001828 acdb_dev_id = acdb_device_table[audio_extn_get_spkr_prot_snd_device(snd_device)];
Eric Laurentb23d5282013-05-14 15:27:20 -07001829 if (acdb_dev_id < 0) {
1830 ALOGE("%s: Could not find acdb id for device(%d)",
1831 __func__, snd_device);
1832 return -EINVAL;
1833 }
1834 if (my_data->acdb_send_audio_cal) {
Joe Onorato188b6222016-03-01 11:02:27 -08001835 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Eric Laurentb23d5282013-05-14 15:27:20 -07001836 __func__, snd_device, acdb_dev_id);
1837 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
1838 snd_device < SND_DEVICE_OUT_END)
1839 acdb_dev_type = ACDB_DEV_TYPE_OUT;
1840 else
1841 acdb_dev_type = ACDB_DEV_TYPE_IN;
1842 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
1843 }
1844 return 0;
1845}
1846
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001847int platform_send_audio_calibration_v2(void *platform, struct audio_usecase *usecase,
1848 int app_type, int sample_rate)
1849{
1850 struct platform_data *my_data = (struct platform_data *)platform;
1851 int acdb_dev_id, acdb_dev_type;
1852 int snd_device = SND_DEVICE_OUT_SPEAKER;
1853 int new_snd_device[SND_DEVICE_OUT_END] = {0};
1854 int i, num_devices = 1;
1855
1856 if (!platform_supports_app_type_cfg()) // use v1 instead
1857 return -ENOSYS;
1858
1859 if (usecase->type == PCM_PLAYBACK)
1860 snd_device = usecase->out_snd_device;
1861 else if (usecase->type == PCM_CAPTURE)
1862 snd_device = usecase->in_snd_device;
1863
1864 // skipped over get_spkr_prot_device
1865 acdb_dev_id = acdb_device_table[snd_device];
1866 if (acdb_dev_id < 0) {
1867 ALOGE("%s: Could not find acdb id for device(%d)",
1868 __func__, snd_device);
1869 return -EINVAL;
1870 }
1871
1872 if (platform_can_split_snd_device(snd_device,
1873 &num_devices, new_snd_device) < 0) {
1874 new_snd_device[0] = snd_device;
1875 }
1876
1877 for (i = 0; i < num_devices; i++) {
1878 acdb_dev_id = acdb_device_table[new_snd_device[i]];
1879 if (acdb_dev_id < 0) {
1880 ALOGE("%s: Could not find acdb id for device(%d)",
1881 __func__, new_snd_device[i]);
1882 return -EINVAL;
1883 }
1884 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
1885 __func__, new_snd_device[i], acdb_dev_id);
1886 if (new_snd_device[i] >= SND_DEVICE_OUT_BEGIN &&
1887 new_snd_device[i] < SND_DEVICE_OUT_END)
1888 acdb_dev_type = ACDB_DEV_TYPE_OUT;
1889 else
1890 acdb_dev_type = ACDB_DEV_TYPE_IN;
1891
1892 if (my_data->acdb_send_audio_cal_v3) {
1893 my_data->acdb_send_audio_cal_v3(acdb_dev_id, acdb_dev_type,
1894 app_type, sample_rate, i);
1895 } else if (my_data->acdb_send_audio_cal) {
1896 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type); // this version differs from internal
1897 }
1898 }
1899
1900 return 0;
1901}
1902
1903
Eric Laurentb23d5282013-05-14 15:27:20 -07001904int platform_switch_voice_call_device_pre(void *platform)
1905{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001906 struct platform_data *my_data = (struct platform_data *)platform;
1907 int ret = 0;
1908
1909 if (my_data->csd != NULL &&
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001910 voice_is_in_call(my_data->adev)) {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001911 /* This must be called before disabling mixer controls on APQ side */
1912 ret = my_data->csd->disable_device();
1913 if (ret < 0) {
1914 ALOGE("%s: csd_client_disable_device, failed, error %d",
1915 __func__, ret);
1916 }
1917 }
1918 return ret;
1919}
1920
1921int platform_switch_voice_call_enable_device_config(void *platform,
1922 snd_device_t out_snd_device,
1923 snd_device_t in_snd_device)
1924{
1925 struct platform_data *my_data = (struct platform_data *)platform;
1926 int acdb_rx_id, acdb_tx_id;
1927 int ret = 0;
1928
1929 if (my_data->csd == NULL)
1930 return ret;
1931
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001932 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1933 audio_extn_spkr_prot_is_enabled())
keunhui.park2f7306a2015-07-16 16:48:06 +09001934 acdb_rx_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_SPEAKER_PROTECTED);
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001935 else
keunhui.park2f7306a2015-07-16 16:48:06 +09001936 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001937
keunhui.park2f7306a2015-07-16 16:48:06 +09001938 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001939
1940 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
1941 ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
1942 if (ret < 0) {
1943 ALOGE("%s: csd_enable_device_config, failed, error %d",
1944 __func__, ret);
1945 }
1946 } else {
1947 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1948 acdb_rx_id, acdb_tx_id);
1949 }
1950
1951 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001952}
1953
1954int platform_switch_voice_call_device_post(void *platform,
1955 snd_device_t out_snd_device,
1956 snd_device_t in_snd_device)
1957{
1958 struct platform_data *my_data = (struct platform_data *)platform;
1959 int acdb_rx_id, acdb_tx_id;
1960
1961 if (my_data->acdb_send_voice_cal == NULL) {
1962 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
1963 } else {
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001964 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1965 audio_extn_spkr_prot_is_enabled())
1966 out_snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED;
1967
keunhui.park2f7306a2015-07-16 16:48:06 +09001968 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
1969 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07001970
1971 if (acdb_rx_id > 0 && acdb_tx_id > 0)
1972 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
1973 else
1974 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1975 acdb_rx_id, acdb_tx_id);
1976 }
1977
1978 return 0;
1979}
1980
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001981int platform_switch_voice_call_usecase_route_post(void *platform,
1982 snd_device_t out_snd_device,
1983 snd_device_t in_snd_device)
1984{
1985 struct platform_data *my_data = (struct platform_data *)platform;
1986 int acdb_rx_id, acdb_tx_id;
1987 int ret = 0;
1988
1989 if (my_data->csd == NULL)
1990 return ret;
1991
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001992 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1993 audio_extn_spkr_prot_is_enabled())
keunhui.park2f7306a2015-07-16 16:48:06 +09001994 acdb_rx_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED);
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001995 else
keunhui.park2f7306a2015-07-16 16:48:06 +09001996 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001997
keunhui.park2f7306a2015-07-16 16:48:06 +09001998 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001999
2000 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
2001 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
2002 my_data->adev->acdb_settings);
2003 if (ret < 0) {
2004 ALOGE("%s: csd_enable_device, failed, error %d", __func__, ret);
2005 }
2006 } else {
2007 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2008 acdb_rx_id, acdb_tx_id);
2009 }
2010
2011 return ret;
2012}
2013
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002014int platform_start_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07002015{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002016 struct platform_data *my_data = (struct platform_data *)platform;
2017 int ret = 0;
2018
2019 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002020 ret = my_data->csd->start_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002021 if (ret < 0) {
2022 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
2023 }
2024 }
2025 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002026}
2027
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002028int platform_stop_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07002029{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002030 struct platform_data *my_data = (struct platform_data *)platform;
2031 int ret = 0;
2032
2033 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002034 ret = my_data->csd->stop_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002035 if (ret < 0) {
2036 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
2037 }
2038 }
2039 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002040}
2041
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002042int platform_get_sample_rate(void *platform, uint32_t *rate)
2043{
2044 struct platform_data *my_data = (struct platform_data *)platform;
2045 int ret = 0;
2046
2047 if (my_data->csd != NULL) {
2048 ret = my_data->csd->get_sample_rate(rate);
2049 if (ret < 0) {
2050 ALOGE("%s: csd_get_sample_rate error %d\n", __func__, ret);
2051 }
2052 }
2053 return ret;
2054}
2055
vivek mehtab6506412015-08-07 16:55:17 -07002056void platform_set_speaker_gain_in_combo(struct audio_device *adev,
2057 snd_device_t snd_device,
2058 bool enable)
2059{
2060 const char* name;
2061 switch (snd_device) {
2062 case SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES:
2063 if (enable)
2064 name = "spkr-gain-in-headphone-combo";
2065 else
2066 name = "speaker-gain-default";
2067 break;
2068 case SND_DEVICE_OUT_SPEAKER_AND_LINE:
2069 if (enable)
2070 name = "spkr-gain-in-line-combo";
2071 else
2072 name = "speaker-gain-default";
2073 break;
2074 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES:
2075 if (enable)
2076 name = "spkr-safe-gain-in-headphone-combo";
2077 else
2078 name = "speaker-safe-gain-default";
2079 break;
2080 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE:
2081 if (enable)
2082 name = "spkr-safe-gain-in-line-combo";
2083 else
2084 name = "speaker-safe-gain-default";
2085 break;
2086 default:
2087 return;
2088 }
2089
2090 audio_route_apply_and_update_path(adev->audio_route, name);
2091}
2092
Eric Laurentb23d5282013-05-14 15:27:20 -07002093int platform_set_voice_volume(void *platform, int volume)
2094{
2095 struct platform_data *my_data = (struct platform_data *)platform;
2096 struct audio_device *adev = my_data->adev;
2097 struct mixer_ctl *ctl;
sangwoo53b2cf02013-07-25 19:18:44 -07002098 const char *mixer_ctl_name = "Voice Rx Gain";
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002099 int vol_index = 0, ret = 0;
2100 uint32_t set_values[ ] = {0,
2101 ALL_SESSION_VSID,
2102 DEFAULT_VOLUME_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07002103
2104 // Voice volume levels are mapped to adsp volume levels as follows.
2105 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
2106 // But this values don't changed in kernel. So, below change is need.
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09002107 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, my_data->max_vol_index);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002108 set_values[0] = vol_index;
Eric Laurentb23d5282013-05-14 15:27:20 -07002109
2110 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2111 if (!ctl) {
2112 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2113 __func__, mixer_ctl_name);
2114 return -EINVAL;
2115 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002116 ALOGV("Setting voice volume index: %d", set_values[0]);
2117 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2118
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002119 if (my_data->csd != NULL) {
2120 ret = my_data->csd->volume(ALL_SESSION_VSID, volume,
2121 DEFAULT_VOLUME_RAMP_DURATION_MS);
2122 if (ret < 0) {
2123 ALOGE("%s: csd_volume error %d", __func__, ret);
2124 }
2125 }
2126 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002127}
2128
2129int platform_set_mic_mute(void *platform, bool state)
2130{
2131 struct platform_data *my_data = (struct platform_data *)platform;
2132 struct audio_device *adev = my_data->adev;
2133 struct mixer_ctl *ctl;
2134 const char *mixer_ctl_name = "Voice Tx Mute";
sangwoo53b2cf02013-07-25 19:18:44 -07002135 int ret = 0;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002136 uint32_t set_values[ ] = {0,
2137 ALL_SESSION_VSID,
2138 DEFAULT_MUTE_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07002139
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09002140 if (adev->mode != AUDIO_MODE_IN_CALL &&
2141 adev->mode != AUDIO_MODE_IN_COMMUNICATION)
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002142 return 0;
2143
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09002144 if (adev->enable_hfp)
2145 mixer_ctl_name = "HFP Tx Mute";
2146
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002147 set_values[0] = state;
2148 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2149 if (!ctl) {
2150 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2151 __func__, mixer_ctl_name);
2152 return -EINVAL;
2153 }
2154 ALOGV("Setting voice mute state: %d", state);
2155 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2156
2157 if (my_data->csd != NULL) {
2158 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state,
2159 DEFAULT_MUTE_RAMP_DURATION_MS);
sangwoo53b2cf02013-07-25 19:18:44 -07002160 if (ret < 0) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002161 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
sangwoo53b2cf02013-07-25 19:18:44 -07002162 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002163 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002164 return ret;
2165}
Eric Laurentb23d5282013-05-14 15:27:20 -07002166
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002167int platform_set_device_mute(void *platform, bool state, char *dir)
2168{
2169 struct platform_data *my_data = (struct platform_data *)platform;
2170 struct audio_device *adev = my_data->adev;
2171 struct mixer_ctl *ctl;
2172 char *mixer_ctl_name = NULL;
2173 int ret = 0;
2174 uint32_t set_values[ ] = {0,
2175 ALL_SESSION_VSID,
2176 0};
2177 if(dir == NULL) {
2178 ALOGE("%s: Invalid direction:%s", __func__, dir);
2179 return -EINVAL;
2180 }
2181
2182 if (!strncmp("rx", dir, sizeof("rx"))) {
2183 mixer_ctl_name = "Voice Rx Device Mute";
2184 } else if (!strncmp("tx", dir, sizeof("tx"))) {
2185 mixer_ctl_name = "Voice Tx Device Mute";
2186 } else {
2187 return -EINVAL;
2188 }
2189
2190 set_values[0] = state;
2191 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2192 if (!ctl) {
2193 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2194 __func__, mixer_ctl_name);
2195 return -EINVAL;
2196 }
2197
2198 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
2199 __func__,state, mixer_ctl_name);
2200 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2201
2202 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002203}
2204
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002205int platform_can_split_snd_device(snd_device_t snd_device,
2206 int *num_devices,
2207 snd_device_t *new_snd_devices)
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002208{
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002209 int ret = -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002210 if (NULL == num_devices || NULL == new_snd_devices) {
2211 ALOGE("%s: NULL pointer ..", __func__);
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002212 return -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002213 }
2214
2215 /*
2216 * If wired headset/headphones/line devices share the same backend
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002217 * with speaker/earpiece this routine returns -EINVAL.
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002218 */
2219 if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES &&
2220 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_HEADPHONES)) {
2221 *num_devices = 2;
2222 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2223 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002224 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002225 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_LINE &&
2226 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_LINE)) {
2227 *num_devices = 2;
2228 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2229 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002230 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002231 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES &&
2232 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_HEADPHONES)) {
2233 *num_devices = 2;
2234 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2235 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002236 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002237 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE &&
2238 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_LINE)) {
2239 *num_devices = 2;
2240 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2241 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002242 ret = 0;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002243 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO &&
2244 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2245 SND_DEVICE_OUT_BT_SCO)) {
2246 *num_devices = 2;
2247 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2248 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO;
2249 ret = 0;
2250 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB &&
2251 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2252 SND_DEVICE_OUT_BT_SCO_WB)) {
2253 *num_devices = 2;
2254 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2255 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO_WB;
2256 ret = 0;
David Linee3fe402017-03-13 10:00:42 -07002257 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET &&
2258 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_USB_HEADSET)) {
2259 *num_devices = 2;
2260 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2261 new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
2262 ret = 0;
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07002263 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET &&
2264 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_USB_HEADSET)) {
2265 *num_devices = 2;
2266 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2267 new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
2268 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002269 }
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002270 return ret;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002271}
2272
Eric Laurentb23d5282013-05-14 15:27:20 -07002273snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
2274{
2275 struct platform_data *my_data = (struct platform_data *)platform;
2276 struct audio_device *adev = my_data->adev;
2277 audio_mode_t mode = adev->mode;
2278 snd_device_t snd_device = SND_DEVICE_NONE;
2279
2280 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
2281 if (devices == AUDIO_DEVICE_NONE ||
2282 devices & AUDIO_DEVICE_BIT_IN) {
2283 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
2284 goto exit;
2285 }
2286
Eric Laurent1b491552015-09-15 17:52:41 -07002287 if (popcount(devices) == 2) {
2288 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2289 AUDIO_DEVICE_OUT_SPEAKER) ||
2290 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2291 AUDIO_DEVICE_OUT_SPEAKER)) {
2292 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
2293 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2294 AUDIO_DEVICE_OUT_SPEAKER)) {
2295 snd_device = SND_DEVICE_OUT_SPEAKER_AND_LINE;
2296 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2297 AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
2298 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2299 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2300 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES;
2301 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2302 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2303 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE;
2304 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
2305 AUDIO_DEVICE_OUT_SPEAKER)) {
2306 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002307 } else if ((devices & AUDIO_DEVICE_OUT_ALL_SCO) &&
2308 ((devices & ~AUDIO_DEVICE_OUT_ALL_SCO) == AUDIO_DEVICE_OUT_SPEAKER)) {
2309 snd_device = adev->bt_wb_speech_enabled ?
2310 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB :
2311 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO;
Eric Laurent99dab492017-06-17 15:19:08 -07002312 } else if ((devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
2313 AUDIO_DEVICE_OUT_SPEAKER)) ||
2314 (devices == (AUDIO_DEVICE_OUT_USB_HEADSET |
2315 AUDIO_DEVICE_OUT_SPEAKER))) {
David Linee3fe402017-03-13 10:00:42 -07002316 snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET;
Eric Laurentd0f7c262017-07-05 09:09:12 -07002317 } else if ((devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
2318 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) ||
2319 (devices == (AUDIO_DEVICE_OUT_USB_HEADSET |
2320 AUDIO_DEVICE_OUT_SPEAKER_SAFE))) {
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07002321 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET;
Eric Laurent1b491552015-09-15 17:52:41 -07002322 } else {
2323 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
2324 goto exit;
2325 }
2326 if (snd_device != SND_DEVICE_NONE) {
2327 goto exit;
2328 }
2329 }
2330
2331 if (popcount(devices) != 1) {
2332 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
2333 goto exit;
2334 }
2335
Madhuri Athota3f6051b2016-10-13 23:25:38 +05302336 if (voice_is_in_call(adev) || adev->enable_voicerx || audio_extn_hfp_is_active(adev)) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002337 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002338 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2339 devices & AUDIO_DEVICE_OUT_LINE) {
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002340 if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002341 (adev->voice.tty_mode == TTY_MODE_FULL))
Eric Laurentb23d5282013-05-14 15:27:20 -07002342 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002343 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002344 (adev->voice.tty_mode == TTY_MODE_VCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002345 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002346 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002347 (adev->voice.tty_mode == TTY_MODE_HCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002348 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002349 else {
2350 if (devices & AUDIO_DEVICE_OUT_LINE)
2351 snd_device = SND_DEVICE_OUT_VOICE_LINE;
2352 else
2353 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
2354 }
Eric Laurent99dab492017-06-17 15:19:08 -07002355 } else if (audio_is_usb_out_device(devices)) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002356 if (voice_is_in_call(adev)) {
2357 switch (adev->voice.tty_mode) {
2358 case TTY_MODE_FULL:
2359 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_USB;
2360 break;
2361 case TTY_MODE_VCO:
2362 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_USB;
2363 break;
2364 case TTY_MODE_HCO:
2365 // since Hearing will be on handset\speaker, use existing device
2366 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
2367 break;
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002368 case TTY_MODE_OFF:
2369 break;
vivek mehtaa6b79742017-03-09 15:40:43 -08002370 default:
2371 ALOGE("%s: Invalid TTY mode (%#x)",
2372 __func__, adev->voice.tty_mode);
2373 }
2374 }
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002375 if (snd_device == SND_DEVICE_NONE) {
2376 snd_device = audio_extn_usb_is_capture_supported() ?
2377 SND_DEVICE_OUT_VOICE_USB_HEADSET :
2378 SND_DEVICE_OUT_VOICE_USB_HEADPHONES;
2379 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002380 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002381 if (adev->bt_wb_speech_enabled) {
2382 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2383 } else {
2384 snd_device = SND_DEVICE_OUT_BT_SCO;
2385 }
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002386 } else if (devices & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002387 if (!adev->enable_hfp) {
2388 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
2389 } else {
2390 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_HFP;
2391 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002392 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002393 if(adev->voice.hac)
2394 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2395 else if (is_operator_tmus())
Eric Laurentb23d5282013-05-14 15:27:20 -07002396 snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS;
2397 else
Eric Laurentb4d368e2014-06-25 10:21:54 -05002398 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002399 } else if (devices & AUDIO_DEVICE_OUT_TELEPHONY_TX)
2400 snd_device = SND_DEVICE_OUT_VOICE_TX;
2401
Eric Laurentb23d5282013-05-14 15:27:20 -07002402 if (snd_device != SND_DEVICE_NONE) {
2403 goto exit;
2404 }
2405 }
2406
Eric Laurentb23d5282013-05-14 15:27:20 -07002407 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2408 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2409 snd_device = SND_DEVICE_OUT_HEADPHONES;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002410 } else if (devices & AUDIO_DEVICE_OUT_LINE) {
2411 snd_device = SND_DEVICE_OUT_LINE;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002412 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) {
2413 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE;
Eric Laurentb23d5282013-05-14 15:27:20 -07002414 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002415 if (my_data->speaker_lr_swap)
Eric Laurentb23d5282013-05-14 15:27:20 -07002416 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
2417 else
2418 snd_device = SND_DEVICE_OUT_SPEAKER;
2419 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002420 if (adev->bt_wb_speech_enabled) {
2421 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2422 } else {
2423 snd_device = SND_DEVICE_OUT_BT_SCO;
2424 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002425 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2426 snd_device = SND_DEVICE_OUT_HDMI ;
Eric Laurent99dab492017-06-17 15:19:08 -07002427 } else if (audio_is_usb_out_device(devices)) {
David Linee3fe402017-03-13 10:00:42 -07002428 if (audio_extn_usb_is_capture_supported())
2429 snd_device = SND_DEVICE_OUT_USB_HEADSET;
2430 else
2431 snd_device = SND_DEVICE_OUT_USB_HEADPHONES;
2432 }else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002433 /*HAC support for voice-ish audio (eg visual voicemail)*/
2434 if(adev->voice.hac)
2435 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2436 else
2437 snd_device = SND_DEVICE_OUT_HANDSET;
Eric Laurentb23d5282013-05-14 15:27:20 -07002438 } else {
2439 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
2440 }
2441exit:
2442 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
2443 return snd_device;
2444}
2445
2446snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
2447{
2448 struct platform_data *my_data = (struct platform_data *)platform;
2449 struct audio_device *adev = my_data->adev;
2450 audio_source_t source = (adev->active_input == NULL) ?
2451 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
2452
2453 audio_mode_t mode = adev->mode;
2454 audio_devices_t in_device = ((adev->active_input == NULL) ?
2455 AUDIO_DEVICE_NONE : adev->active_input->device)
2456 & ~AUDIO_DEVICE_BIT_IN;
2457 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
2458 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
2459 snd_device_t snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002460 int channel_count = popcount(channel_mask);
Eric Laurentb23d5282013-05-14 15:27:20 -07002461
Prashant Malanic92c5962015-08-11 15:10:18 -07002462 ALOGV("%s: enter: out_device(%#x) in_device(%#x) channel_count (%d) channel_mask (0x%x)",
2463 __func__, out_device, in_device, channel_count, channel_mask);
Devin Kimd789e432016-10-26 15:07:27 -07002464 if ((out_device != AUDIO_DEVICE_NONE) && (voice_is_in_call(adev) ||
2465 audio_extn_hfp_is_active(adev))) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002466 if (adev->voice.tty_mode != TTY_MODE_OFF) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002467 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002468 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2469 out_device & AUDIO_DEVICE_OUT_LINE) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002470 switch (adev->voice.tty_mode) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002471 case TTY_MODE_FULL:
2472 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
2473 break;
2474 case TTY_MODE_VCO:
2475 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
2476 break;
2477 case TTY_MODE_HCO:
2478 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
2479 break;
2480 default:
2481 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
2482 }
2483 goto exit;
Eric Laurent99dab492017-06-17 15:19:08 -07002484 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002485 switch (adev->voice.tty_mode) {
2486 case TTY_MODE_FULL:
2487 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC;
2488 break;
2489 case TTY_MODE_VCO:
2490 // since voice will be captured from handset mic, use existing device
2491 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
2492 break;
2493 case TTY_MODE_HCO:
2494 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC;
2495 break;
2496 default:
2497 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
Eric Laurentb23d5282013-05-14 15:27:20 -07002498 }
2499 goto exit;
2500 }
2501 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002502 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002503 if (my_data->fluence_in_voice_call == false) {
2504 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2505 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002506 if (is_operator_tmus())
2507 snd_device = SND_DEVICE_IN_VOICE_DMIC_TMUS;
Eric Laurentb23d5282013-05-14 15:27:20 -07002508 else
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002509 snd_device = SND_DEVICE_IN_VOICE_DMIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002510 }
2511 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2512 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
2513 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002514 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002515 if (adev->bluetooth_nrec)
2516 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2517 else
2518 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002519 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002520 if (adev->bluetooth_nrec)
2521 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2522 else
2523 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002524 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002525 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Prashant Malanic92c5962015-08-11 15:10:18 -07002526 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
2527 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2528 out_device & AUDIO_DEVICE_OUT_LINE) {
2529 if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
2530 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
2531 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
2532 } else {
2533 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2534 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002535 }
vivek mehtafe121d52015-08-10 23:39:23 -07002536
2537 //select default
2538 if (snd_device == SND_DEVICE_NONE) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002539 if (!adev->enable_hfp) {
2540 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2541 } else {
2542 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP;
2543 platform_set_echo_reference(adev, true, out_device);
2544 }
vivek mehtafe121d52015-08-10 23:39:23 -07002545 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002546 } else if (out_device & AUDIO_DEVICE_OUT_TELEPHONY_TX) {
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002547 snd_device = SND_DEVICE_IN_VOICE_RX;
Eric Laurent99dab492017-06-17 15:19:08 -07002548 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002549 if (audio_extn_usb_is_capture_supported()) {
2550 snd_device = SND_DEVICE_IN_VOICE_USB_HEADSET_MIC;
2551 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002552 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002553 } else if (source == AUDIO_SOURCE_CAMCORDER) {
2554 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
2555 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2556 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
2557 }
2558 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
2559 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002560 if (my_data->fluence_in_voice_rec && channel_count == 1) {
2561 if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2562 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002563 if (adev->active_input->enable_aec)
2564 snd_device = SND_DEVICE_IN_HANDSET_QMIC_AEC;
2565 else
2566 snd_device = SND_DEVICE_IN_HANDSET_QMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002567 } else if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2568 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002569 if (adev->active_input->enable_aec)
2570 snd_device = SND_DEVICE_IN_HANDSET_TMIC_AEC;
2571 else
2572 snd_device = SND_DEVICE_IN_HANDSET_TMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002573 } else if (((my_data->fluence_type == FLUENCE_PRO_ENABLE) ||
2574 (my_data->fluence_type == FLUENCE_ENABLE)) &&
2575 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002576 if (adev->active_input->enable_aec)
2577 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
2578 else
2579 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
Prashant Malanic92c5962015-08-11 15:10:18 -07002580 }
2581 platform_set_echo_reference(adev, true, out_device);
2582 } else if ((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) &&
2583 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2584 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002585 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002586 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
2587 snd_device = SND_DEVICE_IN_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002588 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002589 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2590 snd_device = SND_DEVICE_IN_QUAD_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002591 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002592 if (snd_device == SND_DEVICE_NONE) {
vivek mehtaf3440682016-05-11 14:24:37 -07002593 if (adev->active_input->enable_aec) {
2594 if (adev->active_input->enable_ns) {
2595 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS;
2596 } else {
2597 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC;
2598 }
vivek mehta733c1df2016-04-04 15:09:24 -07002599 platform_set_echo_reference(adev, true, out_device);
vivek mehtaf3440682016-05-11 14:24:37 -07002600 } else if (adev->active_input->enable_ns) {
2601 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
2602 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002603 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
vivek mehtaf3440682016-05-11 14:24:37 -07002604 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002605 }
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -07002606 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2607 snd_device = SND_DEVICE_IN_VOICE_REC_HEADSET_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07002608 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002609 snd_device = SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002610 }
rago90fb9612015-12-02 11:37:53 -08002611 } else if (source == AUDIO_SOURCE_UNPROCESSED) {
2612 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
vivek mehta4ed66e62016-04-15 23:33:34 -07002613 if (((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) ||
2614 (channel_mask == AUDIO_CHANNEL_IN_STEREO)) &&
2615 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2616 snd_device = SND_DEVICE_IN_UNPROCESSED_STEREO_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002617 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07002618 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
2619 snd_device = SND_DEVICE_IN_UNPROCESSED_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002620 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07002621 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2622 snd_device = SND_DEVICE_IN_UNPROCESSED_QUAD_MIC;
2623 } else {
2624 snd_device = SND_DEVICE_IN_UNPROCESSED_MIC;
2625 }
rago90fb9612015-12-02 11:37:53 -08002626 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2627 snd_device = SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07002628 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002629 snd_device = SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC;
rago90fb9612015-12-02 11:37:53 -08002630 }
Eric Laurent50a38ed2015-10-14 18:48:06 -07002631 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION ||
rago90fb9612015-12-02 11:37:53 -08002632 mode == AUDIO_MODE_IN_COMMUNICATION) {
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002633 if (out_device & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE))
Eric Laurentb23d5282013-05-14 15:27:20 -07002634 in_device = AUDIO_DEVICE_IN_BACK_MIC;
2635 if (adev->active_input) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002636 if (adev->active_input->enable_aec &&
2637 adev->active_input->enable_ns) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002638 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002639 if (my_data->fluence_in_spkr_mode &&
2640 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_SPEAKER_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_SPEAKER_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002645 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002646 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002647 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002648 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002649 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002650 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002651 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002652 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002653 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2654 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Eric Laurent99dab492017-06-17 15:19:08 -07002655 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002656 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002657 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002658 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002659 } else if (adev->active_input->enable_aec) {
2660 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2661 if (my_data->fluence_in_spkr_mode &&
2662 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_SPEAKER_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_SPEAKER_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002667 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002668 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2669 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002670 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002671 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002672 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002673 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002674 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002675 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2676 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Eric Laurent99dab492017-06-17 15:19:08 -07002677 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002678 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
Eric Laurentcefbbac2014-09-04 13:54:10 -05002679 }
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08002680 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002681 } else if (adev->active_input->enable_ns) {
2682 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2683 if (my_data->fluence_in_spkr_mode &&
2684 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_SPEAKER_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_SPEAKER_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002689 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002690 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2691 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002692 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002693 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002694 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002695 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002696 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002697 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002698 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002699 }
2700 } else if (source == AUDIO_SOURCE_DEFAULT) {
2701 goto exit;
2702 }
2703
2704
2705 if (snd_device != SND_DEVICE_NONE) {
2706 goto exit;
2707 }
2708
2709 if (in_device != AUDIO_DEVICE_NONE &&
2710 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
2711 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
2712 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002713 if ((my_data->source_mic_type & SOURCE_QUAD_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002714 channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002715 snd_device = SND_DEVICE_IN_QUAD_MIC;
2716 } else if ((my_data->source_mic_type & SOURCE_THREE_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002717 channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002718 snd_device = SND_DEVICE_IN_THREE_MIC;
2719 } else if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2720 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002721 snd_device = SND_DEVICE_IN_HANDSET_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002722 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2723 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002724 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002725 } else {
2726 ALOGE("%s: something wrong (1): source type (%d) channel_count (%d) .."
2727 " channel mask (0x%x) no combination found .. setting to mono", __func__,
2728 my_data->source_mic_type, channel_count, channel_mask);
2729 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2730 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002731 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002732 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2733 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002734 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002735 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2736 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002737 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002738 } else {
2739 ALOGE("%s: something wrong (2): source type (%d) channel_count (%d) .."
2740 " no combination found .. setting to mono", __func__,
2741 my_data->source_mic_type, channel_count);
2742 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
2743 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002744 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2745 snd_device = SND_DEVICE_IN_HEADSET_MIC;
2746 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002747 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002748 if (adev->bluetooth_nrec)
2749 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2750 else
2751 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002752 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002753 if (adev->bluetooth_nrec)
2754 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2755 else
2756 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002757 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002758 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
2759 snd_device = SND_DEVICE_IN_HDMI_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07002760 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
David Linee3fe402017-03-13 10:00:42 -07002761 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002762 } else {
2763 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
2764 ALOGW("%s: Using default handset-mic", __func__);
2765 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2766 }
2767 } else {
2768 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
2769 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2770 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2771 snd_device = SND_DEVICE_IN_HEADSET_MIC;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002772 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002773 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002774 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002775 out_device & AUDIO_DEVICE_OUT_LINE) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002776 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2777 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002778 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002779 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2780 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002781 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002782 } else {
2783 ALOGE("%s: something wrong (3): source type (%d) channel_count (%d) .."
2784 " no combination found .. setting to mono", __func__,
2785 my_data->source_mic_type, channel_count);
2786 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
2787 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002788 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002789 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002790 if (adev->bluetooth_nrec)
2791 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2792 else
2793 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002794 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002795 if (adev->bluetooth_nrec)
2796 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2797 else
2798 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002799 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002800 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2801 snd_device = SND_DEVICE_IN_HDMI_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07002802 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
David Linee3fe402017-03-13 10:00:42 -07002803 if (audio_extn_usb_is_capture_supported())
2804 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
2805 else
2806 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002807 } else {
2808 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
2809 ALOGW("%s: Using default handset-mic", __func__);
2810 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2811 }
2812 }
2813exit:
2814 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
2815 return snd_device;
2816}
2817
2818int platform_set_hdmi_channels(void *platform, int channel_count)
2819{
2820 struct platform_data *my_data = (struct platform_data *)platform;
2821 struct audio_device *adev = my_data->adev;
2822 struct mixer_ctl *ctl;
2823 const char *channel_cnt_str = NULL;
2824 const char *mixer_ctl_name = "HDMI_RX Channels";
2825 switch (channel_count) {
2826 case 8:
2827 channel_cnt_str = "Eight"; break;
2828 case 7:
2829 channel_cnt_str = "Seven"; break;
2830 case 6:
2831 channel_cnt_str = "Six"; break;
2832 case 5:
2833 channel_cnt_str = "Five"; break;
2834 case 4:
2835 channel_cnt_str = "Four"; break;
2836 case 3:
2837 channel_cnt_str = "Three"; break;
2838 default:
2839 channel_cnt_str = "Two"; break;
2840 }
2841 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2842 if (!ctl) {
2843 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2844 __func__, mixer_ctl_name);
2845 return -EINVAL;
2846 }
2847 ALOGV("HDMI channel count: %s", channel_cnt_str);
2848 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
2849 return 0;
2850}
2851
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002852int platform_edid_get_max_channels(void *platform)
Eric Laurentb23d5282013-05-14 15:27:20 -07002853{
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002854 struct platform_data *my_data = (struct platform_data *)platform;
2855 struct audio_device *adev = my_data->adev;
Eric Laurentb23d5282013-05-14 15:27:20 -07002856 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
2857 char *sad = block;
2858 int num_audio_blocks;
2859 int channel_count;
2860 int max_channels = 0;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002861 int i, ret, count;
Eric Laurentb23d5282013-05-14 15:27:20 -07002862
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002863 struct mixer_ctl *ctl;
2864
2865 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
2866 if (!ctl) {
2867 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2868 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
Eric Laurentb23d5282013-05-14 15:27:20 -07002869 return 0;
2870 }
2871
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002872 mixer_ctl_update(ctl);
2873
2874 count = mixer_ctl_get_num_values(ctl);
Eric Laurentb23d5282013-05-14 15:27:20 -07002875
2876 /* Read SAD blocks, clamping the maximum size for safety */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002877 if (count > (int)sizeof(block))
2878 count = (int)sizeof(block);
Eric Laurentb23d5282013-05-14 15:27:20 -07002879
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002880 ret = mixer_ctl_get_array(ctl, block, count);
2881 if (ret != 0) {
2882 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
2883 return 0;
2884 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002885
2886 /* Calculate the number of SAD blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002887 num_audio_blocks = count / SAD_BLOCK_SIZE;
Eric Laurentb23d5282013-05-14 15:27:20 -07002888
2889 for (i = 0; i < num_audio_blocks; i++) {
2890 /* Only consider LPCM blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002891 if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
2892 sad += 3;
Eric Laurentb23d5282013-05-14 15:27:20 -07002893 continue;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002894 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002895
2896 channel_count = (sad[0] & 0x7) + 1;
2897 if (channel_count > max_channels)
2898 max_channels = channel_count;
2899
2900 /* Advance to next block */
2901 sad += 3;
2902 }
2903
2904 return max_channels;
2905}
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07002906
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002907int platform_set_incall_recording_session_id(void *platform,
2908 uint32_t session_id, int rec_mode)
2909{
2910 int ret = 0;
2911 struct platform_data *my_data = (struct platform_data *)platform;
2912 struct audio_device *adev = my_data->adev;
2913 struct mixer_ctl *ctl;
2914 const char *mixer_ctl_name = "Voc VSID";
2915 int num_ctl_values;
2916 int i;
2917
2918 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2919 if (!ctl) {
2920 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2921 __func__, mixer_ctl_name);
2922 ret = -EINVAL;
2923 } else {
2924 num_ctl_values = mixer_ctl_get_num_values(ctl);
2925 for (i = 0; i < num_ctl_values; i++) {
2926 if (mixer_ctl_set_value(ctl, i, session_id)) {
2927 ALOGV("Error: invalid session_id: %x", session_id);
2928 ret = -EINVAL;
2929 break;
2930 }
2931 }
2932 }
2933
2934 if (my_data->csd != NULL) {
2935 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
2936 if (ret < 0) {
2937 ALOGE("%s: csd_client_start_record failed, error %d",
2938 __func__, ret);
2939 }
2940 }
2941
2942 return ret;
2943}
2944
2945int platform_stop_incall_recording_usecase(void *platform)
2946{
2947 int ret = 0;
2948 struct platform_data *my_data = (struct platform_data *)platform;
2949
2950 if (my_data->csd != NULL) {
2951 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
2952 if (ret < 0) {
2953 ALOGE("%s: csd_client_stop_record failed, error %d",
2954 __func__, ret);
2955 }
2956 }
2957
2958 return ret;
2959}
2960
2961int platform_start_incall_music_usecase(void *platform)
2962{
2963 int ret = 0;
2964 struct platform_data *my_data = (struct platform_data *)platform;
2965
2966 if (my_data->csd != NULL) {
2967 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
2968 if (ret < 0) {
2969 ALOGE("%s: csd_client_start_playback failed, error %d",
2970 __func__, ret);
2971 }
2972 }
2973
2974 return ret;
2975}
2976
2977int platform_stop_incall_music_usecase(void *platform)
2978{
2979 int ret = 0;
2980 struct platform_data *my_data = (struct platform_data *)platform;
2981
2982 if (my_data->csd != NULL) {
2983 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
2984 if (ret < 0) {
2985 ALOGE("%s: csd_client_stop_playback failed, error %d",
2986 __func__, ret);
2987 }
2988 }
2989
2990 return ret;
2991}
2992
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002993int platform_set_parameters(void *platform, struct str_parms *parms)
2994{
2995 struct platform_data *my_data = (struct platform_data *)platform;
keunhui.park2f7306a2015-07-16 16:48:06 +09002996 char value[128];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002997 char *kv_pairs = str_parms_to_str(parms);
2998 int ret = 0, err;
2999
3000 if (kv_pairs == NULL) {
3001 ret = -EINVAL;
3002 ALOGE("%s: key-value pair is NULL",__func__);
3003 goto done;
3004 }
3005
3006 ALOGV("%s: enter: %s", __func__, kv_pairs);
3007
3008 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME,
3009 value, sizeof(value));
3010 if (err >= 0) {
3011 str_parms_del(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME);
3012 my_data->snd_card_name = strdup(value);
3013 ALOGV("%s: sound card name %s", __func__, my_data->snd_card_name);
3014 }
3015
keunhui.park2f7306a2015-07-16 16:48:06 +09003016 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO,
3017 value, sizeof(value));
3018 if (err >= 0) {
3019 struct operator_info *info;
3020 char *str = value;
3021 char *name;
3022
3023 str_parms_del(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO);
3024 info = (struct operator_info *)calloc(1, sizeof(struct operator_info));
3025 name = strtok(str, ";");
3026 info->name = strdup(name);
3027 info->mccmnc = strdup(str + strlen(name) + 1);
3028
3029 list_add_tail(&operator_info_list, &info->list);
Joe Onorato188b6222016-03-01 11:02:27 -08003030 ALOGV("%s: add operator[%s] mccmnc[%s]", __func__, info->name, info->mccmnc);
keunhui.park2f7306a2015-07-16 16:48:06 +09003031 }
Prashant Malanic92c5962015-08-11 15:10:18 -07003032
3033 memset(value, 0, sizeof(value));
Eric Laurentc6333382015-09-14 12:43:44 -07003034 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT,
Prashant Malanic92c5962015-08-11 15:10:18 -07003035 value, sizeof(value));
3036 if (err >= 0) {
Eric Laurentc6333382015-09-14 12:43:44 -07003037 str_parms_del(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT);
Prashant Malanic92c5962015-08-11 15:10:18 -07003038 my_data->max_mic_count = atoi(value);
3039 ALOGV("%s: max_mic_count %s/%d", __func__, value, my_data->max_mic_count);
Prashant Malanic92c5962015-08-11 15:10:18 -07003040 }
3041
vivek mehta90933872017-06-15 18:04:39 -07003042 // to-do: disable setting sidetone gain, will revist this later
3043 // audio_extn_usb_set_sidetone_gain(parms, value, len);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003044done:
3045 ALOGV("%s: exit with code(%d)", __func__, ret);
3046 if (kv_pairs != NULL)
3047 free(kv_pairs);
3048
3049 return ret;
3050}
3051
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003052/* Delay in Us */
3053int64_t platform_render_latency(audio_usecase_t usecase)
3054{
3055 switch (usecase) {
3056 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
3057 return DEEP_BUFFER_PLATFORM_DELAY;
3058 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
3059 return LOW_LATENCY_PLATFORM_DELAY;
Haynes Mathew George03c40102016-01-29 17:57:48 -08003060 case USECASE_AUDIO_PLAYBACK_ULL:
3061 return ULL_PLATFORM_DELAY;
Eric Laurent0e46adf2016-12-16 12:49:24 -08003062 case USECASE_AUDIO_PLAYBACK_MMAP:
3063 return MMAP_PLATFORM_DELAY;
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003064 default:
3065 return 0;
3066 }
3067}
Haynes Mathew George98c95622014-06-20 19:14:25 -07003068
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003069int platform_set_snd_device_backend(snd_device_t device, const char *backend_tag,
3070 const char * hw_interface)
Haynes Mathew George98c95622014-06-20 19:14:25 -07003071{
3072 int ret = 0;
3073
3074 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
3075 ALOGE("%s: Invalid snd_device = %d",
3076 __func__, device);
3077 ret = -EINVAL;
3078 goto done;
3079 }
3080
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003081 ALOGV("%s: backend_tag_table[%s]: old = %s new = %s", __func__,
3082 platform_get_snd_device_name(device),
3083 backend_tag_table[device] != NULL ? backend_tag_table[device]: "null", backend_tag);
3084 if (backend_tag_table[device]) {
3085 free(backend_tag_table[device]);
Haynes Mathew George98c95622014-06-20 19:14:25 -07003086 }
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003087 backend_tag_table[device] = strdup(backend_tag);
3088
3089 if (hw_interface != NULL) {
3090 if (hw_interface_table[device])
3091 free(hw_interface_table[device]);
3092 ALOGV("%s: hw_interface_table[%d] = %s", __func__, device, hw_interface);
3093 hw_interface_table[device] = strdup(hw_interface);
3094 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07003095done:
3096 return ret;
3097}
3098
3099int platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t pcm_id)
3100{
3101 int ret = 0;
3102 if ((usecase <= USECASE_INVALID) || (usecase >= AUDIO_USECASE_MAX)) {
3103 ALOGE("%s: invalid usecase case idx %d", __func__, usecase);
3104 ret = -EINVAL;
3105 goto done;
3106 }
3107
3108 if ((type != 0) && (type != 1)) {
3109 ALOGE("%s: invalid usecase type", __func__);
3110 ret = -EINVAL;
3111 }
vivek mehtaa68fea62017-06-08 19:04:02 -07003112 ALOGV("%s: pcm_device_table[%d %s][%d] = %d", __func__, usecase,
3113 use_case_table[usecase],
3114 type, pcm_id);
Haynes Mathew George98c95622014-06-20 19:14:25 -07003115 pcm_device_table[usecase][type] = pcm_id;
3116done:
3117 return ret;
3118}
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003119
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07003120#define DEFAULT_NOMINAL_SPEAKER_GAIN 20
3121int ramp_speaker_gain(struct audio_device *adev, bool ramp_up, int target_ramp_up_gain) {
3122 // backup_gain: gain to try to set in case of an error during ramp
3123 int start_gain, end_gain, step, backup_gain, i;
3124 bool error = false;
3125 const struct mixer_ctl *ctl;
3126 const char *mixer_ctl_name_gain_left = "Left Speaker Gain";
3127 const char *mixer_ctl_name_gain_right = "Right Speaker Gain";
3128 struct mixer_ctl *ctl_left = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_left);
3129 struct mixer_ctl *ctl_right = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_right);
3130 if (!ctl_left || !ctl_right) {
3131 ALOGE("%s: Could not get ctl for mixer cmd - %s or %s, not applying speaker gain ramp",
3132 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
3133 return -EINVAL;
3134 } else if ((mixer_ctl_get_num_values(ctl_left) != 1)
3135 || (mixer_ctl_get_num_values(ctl_right) != 1)) {
3136 ALOGE("%s: Unexpected num values for mixer cmd - %s or %s, not applying speaker gain ramp",
3137 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
3138 return -EINVAL;
3139 }
3140 if (ramp_up) {
3141 start_gain = 0;
3142 end_gain = target_ramp_up_gain > 0 ? target_ramp_up_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
3143 step = +1;
3144 backup_gain = end_gain;
3145 } else {
3146 // using same gain on left and right
3147 const int left_gain = mixer_ctl_get_value(ctl_left, 0);
3148 start_gain = left_gain > 0 ? left_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
3149 end_gain = 0;
3150 step = -1;
3151 backup_gain = start_gain;
3152 }
3153 for (i = start_gain ; i != (end_gain + step) ; i += step) {
3154 //ALOGV("setting speaker gain to %d", i);
3155 if (mixer_ctl_set_value(ctl_left, 0, i)) {
3156 ALOGE("%s: error setting %s to %d during gain ramp",
3157 __func__, mixer_ctl_name_gain_left, i);
3158 error = true;
3159 break;
3160 }
3161 if (mixer_ctl_set_value(ctl_right, 0, i)) {
3162 ALOGE("%s: error setting %s to %d during gain ramp",
3163 __func__, mixer_ctl_name_gain_right, i);
3164 error = true;
3165 break;
3166 }
3167 usleep(1000);
3168 }
3169 if (error) {
3170 // an error occured during the ramp, let's still try to go back to a safe volume
3171 if (mixer_ctl_set_value(ctl_left, 0, backup_gain)) {
3172 ALOGE("%s: error restoring left gain to %d", __func__, backup_gain);
3173 }
3174 if (mixer_ctl_set_value(ctl_right, 0, backup_gain)) {
3175 ALOGE("%s: error restoring right gain to %d", __func__, backup_gain);
3176 }
3177 }
3178 return start_gain;
3179}
3180
vivek mehtae59cfb22017-06-16 15:57:11 -07003181int platform_set_swap_mixer(struct audio_device *adev, bool swap_channels)
3182{
3183 const char *mixer_ctl_name = "Swap channel";
3184 struct mixer_ctl *ctl;
3185 const char *mixer_path;
3186 struct platform_data *my_data = (struct platform_data *)adev->platform;
3187
3188 // forced to set to swap, but device not rotated ... ignore set
3189 if (swap_channels && !my_data->speaker_lr_swap)
3190 return 0;
3191
3192 ALOGV("%s:", __func__);
3193
3194 if (swap_channels) {
3195 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER_REVERSE);
3196 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
3197 } else {
3198 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER);
3199 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
3200 }
3201
3202 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3203 if (!ctl) {
3204 ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name);
3205 return -EINVAL;
3206 }
3207
3208 if (mixer_ctl_set_value(ctl, 0, swap_channels) < 0) {
3209 ALOGE("%s: Could not set reverse cotrol %d",__func__, swap_channels);
3210 return -EINVAL;
3211 }
3212
3213 ALOGV("platfor_force_swap_channel :: Channel orientation ( %s ) ",
3214 swap_channels?"R --> L":"L --> R");
3215
3216 return 0;
3217}
3218
3219int platform_check_and_set_swap_lr_channels(struct audio_device *adev, bool swap_channels)
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003220{
3221 // only update if there is active pcm playback on speaker
3222 struct audio_usecase *usecase;
3223 struct listnode *node;
3224 struct platform_data *my_data = (struct platform_data *)adev->platform;
3225
vivek mehtae59cfb22017-06-16 15:57:11 -07003226 my_data->speaker_lr_swap = swap_channels;
Jean-Michel Trivif7148702016-09-16 18:23:05 -07003227
vivek mehtae59cfb22017-06-16 15:57:11 -07003228 return platform_set_swap_channels(adev, swap_channels);
3229}
Jean-Michel Trivif7148702016-09-16 18:23:05 -07003230
vivek mehtae59cfb22017-06-16 15:57:11 -07003231int platform_set_swap_channels(struct audio_device *adev, bool swap_channels)
3232{
3233 // only update if there is active pcm playback on speaker
3234 struct audio_usecase *usecase;
3235 struct listnode *node;
3236 struct platform_data *my_data = (struct platform_data *)adev->platform;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003237
vivek mehtae59cfb22017-06-16 15:57:11 -07003238 // do not swap channels in audio modes with concurrent capture and playback
3239 // as this may break the echo reference
3240 if ((adev->mode == AUDIO_MODE_IN_COMMUNICATION) || (adev->mode == AUDIO_MODE_IN_CALL)) {
3241 ALOGV("%s: will not swap due to audio mode %d", __func__, adev->mode);
3242 return 0;
3243 }
3244
3245 list_for_each(node, &adev->usecase_list) {
3246 usecase = node_to_item(node, struct audio_usecase, list);
3247 if (usecase->type == PCM_PLAYBACK &&
3248 usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) {
3249 /*
3250 * If acdb tuning is different for SPEAKER_REVERSE, it is must
3251 * to perform device switch to disable the current backend to
3252 * enable it with new acdb data.
3253 */
3254 if (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
3255 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]) {
3256 const int initial_skpr_gain = ramp_speaker_gain(adev, false /*ramp_up*/, -1);
3257 select_devices(adev, usecase->id);
3258 if (initial_skpr_gain != -EINVAL)
3259 ramp_speaker_gain(adev, true /*ramp_up*/, initial_skpr_gain);
3260
3261 } else {
3262 platform_set_swap_mixer(adev, swap_channels);
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003263 }
vivek mehtae59cfb22017-06-16 15:57:11 -07003264 break;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003265 }
3266 }
vivek mehtae59cfb22017-06-16 15:57:11 -07003267
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003268 return 0;
3269}
vivek mehtaa8d7c922016-05-25 14:40:44 -07003270
3271static struct amp_db_and_gain_table tbl_mapping[MAX_VOLUME_CAL_STEPS];
3272static int num_gain_tbl_entry = 0;
3273
3274bool platform_add_gain_level_mapping(struct amp_db_and_gain_table *tbl_entry) {
3275
3276 ALOGV("%s: enter .. add %f %f %d", __func__, tbl_entry->amp, tbl_entry->db, tbl_entry->level);
3277 if (num_gain_tbl_entry == -1) {
3278 ALOGE("%s: num entry beyond valid step levels or corrupted..rejecting custom mapping",
3279 __func__);
3280 return false;
3281 }
3282
3283 if (num_gain_tbl_entry >= MAX_VOLUME_CAL_STEPS) {
3284 ALOGE("%s: max entry reached max[%d] current index[%d] .. rejecting", __func__,
3285 MAX_VOLUME_CAL_STEPS, num_gain_tbl_entry);
3286 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
3287 return false;
3288 }
3289
3290 if (num_gain_tbl_entry > 0 && tbl_mapping[num_gain_tbl_entry - 1].amp >= tbl_entry->amp) {
3291 ALOGE("%s: value not in ascending order .. rejecting custom mapping", __func__);
3292 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
3293 return false;
3294 }
3295
3296 tbl_mapping[num_gain_tbl_entry] = *tbl_entry;
3297 ++num_gain_tbl_entry;
3298
3299 return true;
3300}
3301
3302int platform_get_gain_level_mapping(struct amp_db_and_gain_table *mapping_tbl,
3303 int table_size) {
3304 int itt = 0;
3305 ALOGV("platform_get_gain_level_mapping called ");
3306
3307 if (num_gain_tbl_entry <= 0 || num_gain_tbl_entry > MAX_VOLUME_CAL_STEPS) {
3308 ALOGD("%s: empty or currupted gain_mapping_table", __func__);
3309 return 0;
3310 }
3311
3312 for (; itt < num_gain_tbl_entry && itt <= table_size; itt++) {
3313 mapping_tbl[itt] = tbl_mapping[itt];
3314 ALOGV("%s: added amp[%f] db[%f] level[%d]", __func__,
3315 mapping_tbl[itt].amp, mapping_tbl[itt].db, mapping_tbl[itt].level);
3316 }
3317
3318 return num_gain_tbl_entry;
3319}
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07003320
3321int platform_snd_card_update(void *platform, card_status_t status)
3322{
3323 struct platform_data *my_data = (struct platform_data *)platform;
3324 struct audio_device *adev = my_data->adev;
3325
3326 if (status == CARD_STATUS_ONLINE) {
3327 if (my_data->acdb_send_custom_top)
3328 my_data->acdb_send_custom_top();
3329 }
3330 return 0;
3331}
David Linee3fe402017-03-13 10:00:42 -07003332
3333/*
3334 * configures afe with bit width and Sample Rate
3335 */
3336static int platform_set_backend_cfg(const struct audio_device* adev,
3337 snd_device_t snd_device,
3338 const struct audio_backend_cfg *backend_cfg)
3339{
3340
3341 int ret = 0;
3342 const int backend_idx = platform_get_backend_index(snd_device);
3343 struct platform_data *my_data = (struct platform_data *)adev->platform;
3344 const unsigned int bit_width = backend_cfg->bit_width;
3345 const unsigned int sample_rate = backend_cfg->sample_rate;
3346 const unsigned int channels = backend_cfg->channels;
3347 const audio_format_t format = backend_cfg->format;
3348 const bool passthrough_enabled = backend_cfg->passthrough_enabled;
3349
3350
3351 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
3352 ", backend_idx %d device (%s)", __func__, bit_width,
3353 sample_rate, channels, backend_idx,
3354 platform_get_snd_device_name(snd_device));
3355
3356 if ((my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl) &&
3357 (bit_width != my_data->current_backend_cfg[backend_idx].bit_width)) {
3358
3359 struct mixer_ctl *ctl = NULL;
3360 ctl = mixer_get_ctl_by_name(adev->mixer,
3361 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
3362 if (!ctl) {
3363 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3364 __func__,
3365 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
3366 return -EINVAL;
3367 }
3368
3369 if (bit_width == 24) {
3370 if (format == AUDIO_FORMAT_PCM_24_BIT_PACKED)
3371 ret = mixer_ctl_set_enum_by_string(ctl, "S24_3LE");
3372 else
3373 ret = mixer_ctl_set_enum_by_string(ctl, "S24_LE");
3374 } else if (bit_width == 32) {
3375 ret = mixer_ctl_set_enum_by_string(ctl, "S32_LE");
3376 } else {
3377 ret = mixer_ctl_set_enum_by_string(ctl, "S16_LE");
3378 }
3379 if ( ret < 0) {
3380 ALOGE("%s:becf: afe: fail for %s mixer set to %d bit for %x format", __func__,
3381 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
3382 } else {
3383 my_data->current_backend_cfg[backend_idx].bit_width = bit_width;
3384 ALOGD("%s:becf: afe: %s mixer set to %d bit for %x format", __func__,
3385 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
3386 }
3387 /* set the ret as 0 and not pass back to upper layer */
3388 ret = 0;
3389 }
3390
3391 if (passthrough_enabled || ((my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl) &&
3392 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate))) {
3393 char *rate_str = NULL;
3394 struct mixer_ctl *ctl = NULL;
3395
3396 switch (sample_rate) {
3397 case 32000:
3398 if (passthrough_enabled) {
3399 rate_str = "KHZ_32";
3400 break;
3401 }
3402 case 8000:
3403 case 11025:
3404 case 16000:
3405 case 22050:
3406 case 48000:
3407 rate_str = "KHZ_48";
3408 break;
3409 case 44100:
3410 rate_str = "KHZ_44P1";
3411 break;
3412 case 64000:
3413 case 96000:
3414 rate_str = "KHZ_96";
3415 break;
3416 case 88200:
3417 rate_str = "KHZ_88P2";
3418 break;
3419 case 176400:
3420 rate_str = "KHZ_176P4";
3421 break;
3422 case 192000:
3423 rate_str = "KHZ_192";
3424 break;
3425 case 352800:
3426 rate_str = "KHZ_352P8";
3427 break;
3428 case 384000:
3429 rate_str = "KHZ_384";
3430 break;
3431 case 144000:
3432 if (passthrough_enabled) {
3433 rate_str = "KHZ_144";
3434 break;
3435 }
3436 default:
3437 rate_str = "KHZ_48";
3438 break;
3439 }
3440
3441 ctl = mixer_get_ctl_by_name(adev->mixer,
3442 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
3443 if(!ctl) {
3444 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3445 __func__,
3446 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
3447 return -EINVAL;
3448 }
3449
3450 ALOGD("%s:becf: afe: %s set to %s", __func__,
3451 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl, rate_str);
3452 mixer_ctl_set_enum_by_string(ctl, rate_str);
3453 my_data->current_backend_cfg[backend_idx].sample_rate = sample_rate;
3454 }
3455 if ((my_data->current_backend_cfg[backend_idx].channels_mixer_ctl) &&
3456 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
3457 struct mixer_ctl *ctl = NULL;
3458 char *channel_cnt_str = NULL;
3459
3460 switch (channels) {
3461 case 8:
3462 channel_cnt_str = "Eight"; break;
3463 case 7:
3464 channel_cnt_str = "Seven"; break;
3465 case 6:
3466 channel_cnt_str = "Six"; break;
3467 case 5:
3468 channel_cnt_str = "Five"; break;
3469 case 4:
3470 channel_cnt_str = "Four"; break;
3471 case 3:
3472 channel_cnt_str = "Three"; break;
3473 case 1:
3474 channel_cnt_str = "One"; break;
3475 case 2:
3476 default:
3477 channel_cnt_str = "Two"; break;
3478 }
3479
3480 ctl = mixer_get_ctl_by_name(adev->mixer,
3481 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
3482 if (!ctl) {
3483 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3484 __func__,
3485 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
3486 return -EINVAL;
3487 }
3488 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
3489 my_data->current_backend_cfg[backend_idx].channels = channels;
3490
3491 // skip EDID configuration for HDMI backend
3492
3493 ALOGD("%s:becf: afe: %s set to %s", __func__,
3494 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl,
3495 channel_cnt_str);
3496 }
3497
3498 // skip set ext_display format mixer control
3499 return ret;
3500}
3501
3502static int platform_get_snd_device_bit_width(snd_device_t snd_device)
3503{
3504 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
3505 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
3506 return CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3507 }
3508
3509 return backend_bit_width_table[snd_device];
3510}
3511
3512/*
3513 * return backend_idx on which voice call is active
3514 */
3515static int platform_get_voice_call_backend(struct audio_device* adev)
3516{
3517 struct audio_usecase *uc = NULL;
3518 struct listnode *node;
3519 snd_device_t out_snd_device = SND_DEVICE_NONE;
3520
3521 int backend_idx = -1;
3522
3523 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
3524 list_for_each(node, &adev->usecase_list) {
3525 uc = node_to_item(node, struct audio_usecase, list);
3526 if (uc && uc->type == VOICE_CALL && uc->stream.out) {
3527 out_snd_device = platform_get_output_snd_device(adev->platform,
3528 uc->stream.out->devices);
3529 backend_idx = platform_get_backend_index(out_snd_device);
3530 break;
3531 }
3532 }
3533 }
3534 return backend_idx;
3535}
3536
3537/*
3538 * goes through all the current usecases and picks the highest
3539 * bitwidth & samplerate
3540 */
3541static bool platform_check_capture_backend_cfg(struct audio_device* adev,
3542 int backend_idx,
3543 struct audio_backend_cfg *backend_cfg)
3544{
3545 bool backend_change = false;
3546 unsigned int bit_width;
3547 unsigned int sample_rate;
3548 unsigned int channels;
3549 struct platform_data *my_data = (struct platform_data *)adev->platform;
3550
3551 bit_width = backend_cfg->bit_width;
3552 sample_rate = backend_cfg->sample_rate;
3553 channels = backend_cfg->channels;
3554
3555 ALOGV("%s:txbecf: afe: Codec selected backend: %d current bit width: %d and "
3556 "sample rate: %d, channels %d",__func__,backend_idx, bit_width,
3557 sample_rate, channels);
3558
3559 // For voice calls use default configuration i.e. 16b/48K, only applicable to
3560 // default backend
3561 // force routing is not required here, caller will do it anyway
3562 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
3563 ALOGW("%s:txbecf: afe: Use default bw and sr for voice/voip calls and "
3564 "for unprocessed/camera source", __func__);
3565 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3566 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3567 }
3568
3569 if (backend_idx == USB_AUDIO_TX_BACKEND) {
3570 audio_extn_usb_is_config_supported(&bit_width, &sample_rate, &channels, false);
3571 ALOGV("%s:txbecf: afe: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
3572 __func__, bit_width, sample_rate, channels);
3573 }
3574
3575 ALOGV("%s:txbecf: afe: Codec selected backend: %d updated bit width: %d and "
3576 "sample rate: %d", __func__, backend_idx, bit_width, sample_rate);
3577
3578 // Force routing if the expected bitwdith or samplerate
3579 // is not same as current backend comfiguration
3580 if ((bit_width != my_data->current_backend_cfg[backend_idx].bit_width) ||
3581 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate) ||
3582 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
3583 backend_cfg->bit_width = bit_width;
3584 backend_cfg->sample_rate= sample_rate;
3585 backend_cfg->channels = channels;
3586 backend_change = true;
3587 ALOGI("%s:txbecf: afe: Codec backend needs to be updated. new bit width: %d "
3588 "new sample rate: %d new channel: %d",
3589 __func__, backend_cfg->bit_width,
3590 backend_cfg->sample_rate, backend_cfg->channels);
3591 }
3592
3593 return backend_change;
3594}
3595
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003596static void pick_playback_cfg_for_uc(struct audio_device *adev,
3597 struct audio_usecase *usecase,
3598 snd_device_t snd_device,
3599 unsigned int *bit_width,
3600 unsigned int *sample_rate,
3601 unsigned int *channels)
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003602{
3603 int i =0;
3604 struct listnode *node;
3605 list_for_each(node, &adev->usecase_list) {
3606 struct audio_usecase *uc;
3607 uc = node_to_item(node, struct audio_usecase, list);
3608 struct stream_out *out = (struct stream_out*) uc->stream.out;
3609 if (uc->type == PCM_PLAYBACK && out && usecase != uc) {
3610 unsigned int out_channels = audio_channel_count_from_out_mask(out->channel_mask);
3611 ALOGV("%s:napb: (%d) - (%s)id (%d) sr %d bw "
3612 "(%d) ch (%d) device %s", __func__, i++, use_case_table[uc->id],
3613 uc->id, out->sample_rate,
3614 pcm_format_to_bits(out->config.format), out_channels,
3615 platform_get_snd_device_name(uc->out_snd_device));
3616
3617 if (platform_check_backends_match(snd_device, uc->out_snd_device)) {
3618 if (*bit_width < pcm_format_to_bits(out->config.format))
3619 *bit_width = pcm_format_to_bits(out->config.format);
3620 if (*sample_rate < out->sample_rate)
3621 *sample_rate = out->sample_rate;
3622 if (out->sample_rate < OUTPUT_SAMPLING_RATE_44100)
3623 *sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3624 if (*channels < out_channels)
3625 *channels = out_channels;
3626 }
3627 }
3628 }
3629 return;
3630}
3631
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003632static void headset_is_config_supported(unsigned int *bit_width,
3633 unsigned int *sample_rate,
3634 unsigned int *channels) {
3635 switch (*bit_width) {
3636 case 16:
3637 case 24:
3638 break;
3639 default:
3640 *bit_width = 16;
3641 break;
3642 }
3643
3644 if (*sample_rate > 192000) {
3645 *sample_rate = 192000;
3646 }
3647
3648 if (*channels > 2) {
3649 *channels = 2;
3650 }
3651}
3652
David Linee3fe402017-03-13 10:00:42 -07003653static bool platform_check_playback_backend_cfg(struct audio_device* adev,
3654 struct audio_usecase* usecase,
3655 snd_device_t snd_device,
3656 struct audio_backend_cfg *backend_cfg)
3657{
3658 bool backend_change = false;
David Linee3fe402017-03-13 10:00:42 -07003659 unsigned int bit_width;
3660 unsigned int sample_rate;
3661 unsigned int channels;
David Linee3fe402017-03-13 10:00:42 -07003662 int backend_idx = DEFAULT_CODEC_BACKEND;
3663 struct platform_data *my_data = (struct platform_data *)adev->platform;
David Linee3fe402017-03-13 10:00:42 -07003664
3665 if (snd_device == SND_DEVICE_OUT_BT_SCO ||
3666 snd_device == SND_DEVICE_OUT_BT_SCO_WB) {
3667 backend_change = false;
3668 return backend_change;
3669 }
3670
3671 backend_idx = platform_get_backend_index(snd_device);
3672 bit_width = backend_cfg->bit_width;
3673 sample_rate = backend_cfg->sample_rate;
3674 channels = backend_cfg->channels;
3675
3676 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
3677 ", backend_idx %d usecase = %d device (%s)", __func__, bit_width,
3678 sample_rate, channels, backend_idx, usecase->id,
3679 platform_get_snd_device_name(snd_device));
3680
3681 if (backend_idx == platform_get_voice_call_backend(adev)) {
3682 ALOGW("%s:becf: afe:Use default bw and sr for voice/voip calls ",
3683 __func__);
3684 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3685 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3686 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
3687 } else {
3688 /*
3689 * The backend should be configured at highest bit width and/or
3690 * sample rate amongst all playback usecases.
3691 * If the selected sample rate and/or bit width differ with
3692 * current backend sample rate and/or bit width, then, we set the
3693 * backend re-configuration flag.
3694 *
3695 * Exception: 16 bit playbacks is allowed through 16 bit/48/44.1 khz backend only
3696 */
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003697 pick_playback_cfg_for_uc(adev, usecase, snd_device,
3698 &bit_width,
3699 &sample_rate,
3700 &channels);
David Linee3fe402017-03-13 10:00:42 -07003701 }
3702
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003703 switch (backend_idx) {
3704 case USB_AUDIO_RX_BACKEND:
3705 audio_extn_usb_is_config_supported(&bit_width,
3706 &sample_rate, &channels, true);
3707 ALOGV("%s: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
3708 __func__, bit_width, sample_rate, channels);
3709 break;
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003710 case HEADPHONE_BACKEND:
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003711 headset_is_config_supported(&bit_width, &sample_rate, &channels);
3712 break;
3713 case DEFAULT_CODEC_BACKEND:
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003714 default:
3715 bit_width = platform_get_snd_device_bit_width(snd_device);
3716 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3717 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
3718 break;
David Linee3fe402017-03-13 10:00:42 -07003719 }
3720
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003721 ALOGV("%s:becf: afe: Codec selected backend: %d updated bit width: %d and"
3722 "sample rate: %d",
David Linee3fe402017-03-13 10:00:42 -07003723 __func__, backend_idx , bit_width, sample_rate);
3724
3725 // Force routing if the expected bitwdith or samplerate
3726 // is not same as current backend comfiguration
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003727 if (bit_width != my_data->current_backend_cfg[backend_idx].bit_width ||
3728 sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate ||
3729 channels != my_data->current_backend_cfg[backend_idx].channels) {
David Linee3fe402017-03-13 10:00:42 -07003730 backend_cfg->bit_width = bit_width;
3731 backend_cfg->sample_rate = sample_rate;
3732 backend_cfg->channels = channels;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003733 backend_cfg->passthrough_enabled = false;
David Linee3fe402017-03-13 10:00:42 -07003734 backend_change = true;
3735 ALOGV("%s:becf: afe: Codec backend needs to be updated. new bit width: %d"
3736 "new sample rate: %d new channels: %d",
3737 __func__, backend_cfg->bit_width, backend_cfg->sample_rate, backend_cfg->channels);
3738 }
3739
3740 return backend_change;
3741}
3742
3743bool platform_check_and_set_playback_backend_cfg(struct audio_device* adev,
3744 struct audio_usecase *usecase, snd_device_t snd_device)
3745{
3746 int backend_idx = DEFAULT_CODEC_BACKEND;
3747 int new_snd_devices[SND_DEVICE_OUT_END];
3748 int i, num_devices = 1;
3749 bool ret = false;
3750 struct platform_data *my_data = (struct platform_data *)adev->platform;
3751 struct audio_backend_cfg backend_cfg;
3752
3753 backend_idx = platform_get_backend_index(snd_device);
3754
3755 backend_cfg.bit_width = pcm_format_to_bits(usecase->stream.out->config.format);
3756 backend_cfg.sample_rate = usecase->stream.out->sample_rate;
3757 backend_cfg.format = usecase->stream.out->format;
3758 backend_cfg.channels = audio_channel_count_from_out_mask(usecase->stream.out->channel_mask);
3759 /*this is populated by check_codec_backend_cfg hence set default value to false*/
3760 backend_cfg.passthrough_enabled = false;
3761
3762 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
3763 ", backend_idx %d usecase = %d device (%s)", __func__, backend_cfg.bit_width,
3764 backend_cfg.sample_rate, backend_cfg.channels, backend_idx, usecase->id,
3765 platform_get_snd_device_name(snd_device));
3766
3767 if (platform_can_split_snd_device(snd_device, &num_devices, new_snd_devices) < 0)
3768 new_snd_devices[0] = snd_device;
3769
3770 for (i = 0; i < num_devices; i++) {
3771 ALOGV("%s: new_snd_devices[%d] is %d", __func__, i, new_snd_devices[i]);
3772 if ((platform_check_playback_backend_cfg(adev, usecase, new_snd_devices[i],
3773 &backend_cfg))) {
3774 platform_set_backend_cfg(adev, new_snd_devices[i],
3775 &backend_cfg);
3776 ret = true;
3777 }
3778 }
3779 return ret;
3780}
3781
3782bool platform_check_and_set_capture_backend_cfg(struct audio_device* adev,
3783 struct audio_usecase *usecase, snd_device_t snd_device)
3784{
3785 int backend_idx = platform_get_backend_index(snd_device);
3786 int ret = 0;
3787 struct audio_backend_cfg backend_cfg;
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003788 memset(&backend_cfg, 0, sizeof(struct audio_backend_cfg));
David Linee3fe402017-03-13 10:00:42 -07003789
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003790 if (usecase->type == PCM_CAPTURE) {
3791 backend_cfg.format = usecase->stream.in->format;
David Linee3fe402017-03-13 10:00:42 -07003792 backend_cfg.channels = audio_channel_count_from_in_mask(usecase->stream.in->channel_mask);
3793 } else {
3794 backend_cfg.bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3795 backend_cfg.sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3796 backend_cfg.format = AUDIO_FORMAT_PCM_16_BIT;
3797 backend_cfg.channels = 1;
3798 }
3799
3800 ALOGV("%s:txbecf: afe: bitwidth %d, samplerate %d, channel %d"
3801 ", backend_idx %d usecase = %d device (%s)", __func__,
3802 backend_cfg.bit_width,
3803 backend_cfg.sample_rate,
3804 backend_cfg.channels,
3805 backend_idx, usecase->id,
3806 platform_get_snd_device_name(snd_device));
3807
3808 if (platform_check_capture_backend_cfg(adev, backend_idx, &backend_cfg)) {
3809 ret = platform_set_backend_cfg(adev, snd_device,
3810 &backend_cfg);
3811 if(!ret)
3812 return true;
3813 }
3814
3815 return false;
3816}
3817
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003818static int max_be_dai_names = 0;
3819static const struct be_dai_name_struct *be_dai_name_table;
3820
3821/*
3822 * Retrieves the be_dai_name_table from kernel to enable a mapping
3823 * between sound device hw interfaces and backend IDs. This allows HAL to
3824 * specify the backend a specific calibration is needed for.
3825 */
3826static int init_be_dai_name_table(struct audio_device *adev)
3827{
3828 const char *mixer_ctl_name = "Backend DAI Name Table";
3829 struct mixer_ctl *ctl;
3830 int i, j, ret, size;
3831 bool valid_hw_interface;
3832
3833 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3834 if (!ctl) {
3835 ALOGE("%s: Could not get ctl for mixer name %s\n",
3836 __func__, mixer_ctl_name);
3837 ret = -EINVAL;
3838 goto done;
3839 }
3840
3841 mixer_ctl_update(ctl);
3842
3843 size = mixer_ctl_get_num_values(ctl);
3844 if (size <= 0){
3845 ALOGE("%s: Failed to get %s size %d\n",
3846 __func__, mixer_ctl_name, size);
3847 ret = -EFAULT;
3848 goto done;
3849 }
3850
vivek mehtaa68fea62017-06-08 19:04:02 -07003851 be_dai_name_table =
3852 (const struct be_dai_name_struct *)calloc(1, size);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003853 if (be_dai_name_table == NULL) {
3854 ALOGE("%s: Failed to allocate memory for %s\n",
3855 __func__, mixer_ctl_name);
3856 ret = -ENOMEM;
3857 goto freeMem;
3858 }
3859
3860 ret = mixer_ctl_get_array(ctl, (void *)be_dai_name_table, size);
3861 if (ret) {
3862 ALOGE("%s: Failed to get %s, ret %d\n",
3863 __func__, mixer_ctl_name, ret);
3864 ret = -EFAULT;
3865 goto freeMem;
3866 }
3867
3868 if (be_dai_name_table != NULL) {
3869 max_be_dai_names = size / sizeof(struct be_dai_name_struct);
3870 ALOGV("%s: Successfully got %s, number of be dais is %d\n",
3871 __func__, mixer_ctl_name, max_be_dai_names);
3872 ret = 0;
3873 } else {
3874 ALOGE("%s: Failed to get %s\n", __func__, mixer_ctl_name);
3875 ret = -EFAULT;
3876 goto freeMem;
3877 }
3878
3879 /*
3880 * Validate all sound devices have a valid backend set to catch
3881 * errors for uncommon sound devices
3882 */
3883 for (i = 0; i < SND_DEVICE_MAX; i++) {
3884 valid_hw_interface = false;
3885
3886 if (hw_interface_table[i] == NULL) {
3887 ALOGW("%s: sound device %s has no hw interface set\n",
3888 __func__, platform_get_snd_device_name(i));
3889 continue;
3890 }
3891
3892 for (j = 0; j < max_be_dai_names; j++) {
3893 if (strcmp(hw_interface_table[i], be_dai_name_table[j].be_name)
3894 == 0) {
3895 valid_hw_interface = true;
3896 break;
3897 }
3898 }
3899 if (!valid_hw_interface)
3900 ALOGD("%s: sound device %s does not have a valid hw interface set "
3901 "(disregard for combo devices) %s\n",
3902 __func__, platform_get_snd_device_name(i),
3903 hw_interface_table[i]);
3904 }
3905
3906 goto done;
3907
3908freeMem:
3909 if (be_dai_name_table) {
3910 free((void *)be_dai_name_table);
3911 be_dai_name_table = NULL;
3912 }
3913
3914done:
3915 return ret;
3916}
3917
3918int platform_get_snd_device_backend_index(snd_device_t device)
3919{
3920 int i, be_dai_id;
3921 const char * hw_interface_name = NULL;
3922
3923 ALOGV("%s: enter with device %d\n", __func__, device);
3924
vivek mehtaa68fea62017-06-08 19:04:02 -07003925 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003926 ALOGE("%s: Invalid snd_device = %d",
3927 __func__, device);
3928 be_dai_id = -EINVAL;
3929 goto done;
3930 }
3931
3932 /* Get string value of necessary backend for device */
3933 hw_interface_name = hw_interface_table[device];
3934 if (hw_interface_name == NULL) {
3935 ALOGE("%s: no hw_interface set for device %d\n", __func__, device);
3936 be_dai_id = -EINVAL;
3937 goto done;
3938 }
3939
3940 /* Check if be dai name table was retrieved successfully */
3941 if (be_dai_name_table == NULL) {
3942 ALOGE("%s: BE DAI Name Table is not present\n", __func__);
3943 be_dai_id = -EFAULT;
3944 goto done;
3945 }
3946
3947 /* Get backend ID for device specified */
3948 for (i = 0; i < max_be_dai_names; i++) {
3949 if (strcmp(hw_interface_name, be_dai_name_table[i].be_name) == 0) {
3950 be_dai_id = be_dai_name_table[i].be_id;
3951 goto done;
3952 }
3953 }
3954 ALOGE("%s: no interface matching name %s\n", __func__, hw_interface_name);
3955 be_dai_id = -EINVAL;
3956 goto done;
3957
3958done:
3959 return be_dai_id;
3960}
3961
3962void platform_check_and_update_copp_sample_rate(void* platform, snd_device_t snd_device,
3963 unsigned int stream_sr, int* sample_rate)
3964{
3965 struct platform_data* my_data = (struct platform_data *)platform;
3966 int backend_idx = platform_get_backend_index(snd_device);
3967 int device_sr = my_data->current_backend_cfg[backend_idx].sample_rate;
3968 /*
3969 *Check if device SR is multiple of 8K or 11.025 Khz
3970 *check if the stream SR is multiple of same base, if yes
3971 *then have copp SR equal to stream SR, this ensures that
3972 *post processing happens at stream SR, else have
3973 *copp SR equal to device SR.
3974 */
3975 if (!(((sample_rate_multiple(device_sr, SAMPLE_RATE_8000)) &&
3976 (sample_rate_multiple(stream_sr, SAMPLE_RATE_8000))) ||
3977 ((sample_rate_multiple(device_sr, SAMPLE_RATE_11025)) &&
3978 (sample_rate_multiple(stream_sr, SAMPLE_RATE_11025))))) {
3979 *sample_rate = device_sr;
3980 } else
3981 *sample_rate = stream_sr;
3982
3983 ALOGI("sn_device %d device sr %d stream sr %d copp sr %d", snd_device, device_sr, stream_sr
3984 , *sample_rate);
3985
3986}
3987
3988// called from info parser
vivek mehtaa68fea62017-06-08 19:04:02 -07003989void platform_add_app_type(const char *uc_type,
3990 const char *mode,
3991 int bw,
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003992 int app_type, int max_rate) {
3993 struct app_type_entry *ap =
3994 (struct app_type_entry *)calloc(1, sizeof(struct app_type_entry));
3995
3996 if (!ap) {
3997 ALOGE("%s failed to allocate mem for app type", __func__);
3998 return;
3999 }
4000
4001 ap->uc_type = -1;
4002 for (int i=0; i<USECASE_TYPE_MAX; i++) {
4003 if (!strcmp(uc_type, usecase_type_index[i].name)) {
4004 ap->uc_type = usecase_type_index[i].index;
4005 break;
4006 }
4007 }
4008
4009 if (ap->uc_type == -1) {
4010 free(ap);
4011 return;
4012 }
4013
vivek mehtaa68fea62017-06-08 19:04:02 -07004014 ALOGI("%s uc %s mode %s bw %d app_type %d max_rate %d",
4015 __func__, uc_type, mode, bw, app_type, max_rate);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004016 ap->bit_width = bw;
4017 ap->app_type = app_type;
4018 ap->max_rate = max_rate;
vivek mehtaa68fea62017-06-08 19:04:02 -07004019 ap->mode = strdup(mode);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004020 list_add_tail(&app_type_entry_list, &ap->node);
4021}
4022
4023
4024int platform_get_default_app_type_v2(void *platform __unused,
4025 usecase_type_t type,
4026 int *app_type )
4027{
4028 if (type == PCM_PLAYBACK)
4029 *app_type = DEFAULT_APP_TYPE_RX_PATH;
4030 else
4031 *app_type = DEFAULT_APP_TYPE_TX_PATH;
4032 return 0;
4033}
4034
vivek mehtaa68fea62017-06-08 19:04:02 -07004035int platform_get_app_type_v2(void *platform,
4036 usecase_type_t uc_type,
4037 const char *mode,
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004038 int bw, int sr __unused,
4039 int *app_type)
4040{
4041 struct listnode *node;
4042 struct app_type_entry *entry;
4043 *app_type = -1;
vivek mehtaa68fea62017-06-08 19:04:02 -07004044
4045 ALOGV("%s find match for uc %d mode %s bw %d rate %d",
4046 __func__, uc_type, mode, bw, sr);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004047 list_for_each(node, &app_type_entry_list) {
4048 entry = node_to_item(node, struct app_type_entry, node);
vivek mehtaa68fea62017-06-08 19:04:02 -07004049 ALOGV("%s uc %d mode %s bw %d app_type %d max_rate %d",
4050 __func__, entry->uc_type, entry->mode, entry->bit_width,
4051 entry->app_type, entry->max_rate);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004052 if (entry->bit_width == bw &&
vivek mehtaa68fea62017-06-08 19:04:02 -07004053 entry->uc_type == uc_type &&
4054 sr <= entry->max_rate &&
4055 entry->mode && !strcmp(mode, entry->mode)) {
4056 ALOGV("%s found match %d", __func__, entry->app_type);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004057 *app_type = entry->app_type;
4058 break;
4059 }
4060 }
4061
4062 if (*app_type == -1) {
vivek mehtaa68fea62017-06-08 19:04:02 -07004063 ALOGV("%s no match found, return default", __func__);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004064 return platform_get_default_app_type_v2(platform, uc_type, app_type);
4065 }
4066 return 0;
4067}
vivek mehta90933872017-06-15 18:04:39 -07004068
4069int platform_set_sidetone(struct audio_device *adev,
4070 snd_device_t out_snd_device,
4071 bool enable, char *str)
4072{
4073 int ret;
4074 if (out_snd_device == SND_DEVICE_OUT_USB_HEADSET ||
4075 out_snd_device == SND_DEVICE_OUT_VOICE_USB_HEADSET) {
4076 ret = audio_extn_usb_enable_sidetone(out_snd_device, enable);
4077 if (ret)
4078 ALOGI("%s: usb device %d does not support device sidetone\n",
4079 __func__, out_snd_device);
4080 } else {
4081 ALOGV("%s: sidetone out device(%d) mixer cmd = %s\n",
4082 __func__, out_snd_device, str);
4083 if (enable)
4084 audio_route_apply_and_update_path(adev->audio_route, str);
4085 else
4086 audio_route_reset_and_update_path(adev->audio_route, str);
4087 }
4088 return 0;
4089}
Haynes Mathew George96483a22017-03-28 14:52:47 -07004090
4091int platform_get_mmap_data_fd(void *platform __unused, int fe_dev __unused, int dir __unused,
4092 int *fd __unused, uint32_t *size __unused)
4093{
4094#if defined (PLATFORM_MSM8996) || (PLATFORM_MSM8998)
4095 struct platform_data *my_data = (struct platform_data *)platform;
4096 struct audio_device *adev = my_data->adev;
4097 int hw_fd = -1;
4098 char dev_name[128];
4099 struct snd_pcm_mmap_fd mmap_fd;
4100 memset(&mmap_fd, 0, sizeof(mmap_fd));
4101 mmap_fd.dir = dir;
4102 snprintf(dev_name, sizeof(dev_name), "/dev/snd/hwC%uD%u",
4103 adev->snd_card, HWDEP_FE_BASE+fe_dev);
4104 hw_fd = open(dev_name, O_RDONLY);
4105 if (hw_fd < 0) {
4106 ALOGE("fe hw dep node open %d/%d failed", adev->snd_card, fe_dev);
4107 return -1;
4108 }
4109 if (ioctl(hw_fd, SNDRV_PCM_IOCTL_MMAP_DATA_FD, &mmap_fd) < 0) {
4110 ALOGE("fe hw dep node ioctl failed");
4111 close(hw_fd);
4112 return -1;
4113 }
4114 *fd = mmap_fd.fd;
4115 *size = mmap_fd.size;
4116 close(hw_fd); // mmap_fd should still be valid
4117 return 0;
4118#else
4119 return -1;
4120#endif
4121}