blob: 7563689148a18d8be4ec85656c3bf87e8a2935f0 [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>
Jiyong Park6431fe62017-06-29 15:15:58 +090022#include <pthread.h>
23#include <unistd.h>
Haynes Mathew Georgee6e2d442018-02-22 18:51:56 -080024#include <log/log.h>
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -070025#include <cutils/str_parms.h>
Eric Laurentb23d5282013-05-14 15:27:20 -070026#include <cutils/properties.h>
27#include <audio_hw.h>
28#include <platform_api.h>
vivek mehta0fb11312017-05-15 19:35:32 -070029#include "acdb.h"
Eric Laurentb23d5282013-05-14 15:27:20 -070030#include "platform.h"
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -070031#include "audio_extn.h"
vivek mehta1a9b7c02015-06-25 11:49:38 -070032#include <linux/msm_audio.h>
Thierry Strudel07f96d12018-09-20 13:31:34 -070033#if defined (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845) || (PLATFORM_SDM710) || (PLATFORM_SM8150)
Haynes Mathew George96483a22017-03-28 14:52:47 -070034#include <sound/devdep_params.h>
35#endif
Eric Laurentb23d5282013-05-14 15:27:20 -070036
jasmine cha270b7762018-03-30 15:41:33 +080037#include "maxxaudio.h"
jasmine chac89321b2018-04-10 21:37:01 +080038#include <resolv.h>
39
Jaekyun Seokf62e17d2017-03-08 17:15:28 +090040#define MIXER_XML_DEFAULT_PATH "mixer_paths.xml"
41#define MIXER_XML_BASE_STRING "mixer_paths"
vivek mehta60ea4152016-02-18 17:10:26 -080042#define TOMTOM_8226_SND_CARD_NAME "msm8226-tomtom-snd-card"
43#define TOMTOM_MIXER_FILE_SUFFIX "wcd9330"
44
Eric Laurentb23d5282013-05-14 15:27:20 -070045#define LIB_ACDB_LOADER "libacdbloader.so"
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -070046#define AUDIO_DATA_BLOCK_MIXER_CTL "HDMI EDID"
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +090047#define CVD_VERSION_MIXER_CTL "CVD Version"
Eric Laurentb23d5282013-05-14 15:27:20 -070048
Eric Laurentf9583c32016-03-28 13:50:50 -070049#define min(a, b) ((a) < (b) ? (a) : (b))
Eric Laurentb23d5282013-05-14 15:27:20 -070050
51/*
Eric Laurentb23d5282013-05-14 15:27:20 -070052 * This file will have a maximum of 38 bytes:
53 *
54 * 4 bytes: number of audio blocks
55 * 4 bytes: total length of Short Audio Descriptor (SAD) blocks
56 * Maximum 10 * 3 bytes: SAD blocks
57 */
58#define MAX_SAD_BLOCKS 10
59#define SAD_BLOCK_SIZE 3
60
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +090061#define MAX_CVD_VERSION_STRING_SIZE 100
62
Eric Laurentb23d5282013-05-14 15:27:20 -070063/* EDID format ID for LPCM audio */
64#define EDID_FORMAT_LPCM 1
65
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -070066#define MAX_SND_CARD_NAME_LEN 31
67
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -080068#define DEFAULT_APP_TYPE_RX_PATH 69936
69#define DEFAULT_APP_TYPE_TX_PATH 69938
Haynes Mathew George39c55dc2017-07-11 19:31:23 -070070#define DEFAULT_RX_BACKEND "SLIMBUS_0_RX"
vivek mehta1a9b7c02015-06-25 11:49:38 -070071
keunhui.parkc5aaa0e2015-07-13 10:57:37 +090072#define TOSTRING_(x) #x
73#define TOSTRING(x) TOSTRING_(x)
74
Eric Laurentb23d5282013-05-14 15:27:20 -070075struct audio_block_header
76{
77 int reserved;
78 int length;
79};
80
vivek mehta1a9b7c02015-06-25 11:49:38 -070081enum {
82 CAL_MODE_SEND = 0x1,
83 CAL_MODE_PERSIST = 0x2,
84 CAL_MODE_RTAC = 0x4
85};
86
keunhui.park2f7306a2015-07-16 16:48:06 +090087#define PLATFORM_CONFIG_KEY_OPERATOR_INFO "operator_info"
88
89struct operator_info {
90 struct listnode list;
91 char *name;
92 char *mccmnc;
93};
94
95struct operator_specific_device {
96 struct listnode list;
97 char *operator;
98 char *mixer_path;
99 int acdb_id;
100};
101
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800102#define BE_DAI_NAME_MAX_LENGTH 24
103struct be_dai_name_struct {
104 unsigned int be_id;
105 char be_name[BE_DAI_NAME_MAX_LENGTH];
106};
107
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -0700108struct snd_device_to_mic_map {
109 struct mic_info microphones[AUDIO_MICROPHONE_MAX_COUNT];
110 size_t mic_count;
111};
112
keunhui.park2f7306a2015-07-16 16:48:06 +0900113static struct listnode operator_info_list;
114static struct listnode *operator_specific_device_table[SND_DEVICE_MAX];
115
jasmine chac89321b2018-04-10 21:37:01 +0800116#define AUDIO_PARAMETER_KEY_AUD_CALDATA "cal_data"
117
118typedef struct acdb_audio_cal_cfg {
119 uint32_t persist;
120 uint32_t snd_dev_id;
121 audio_devices_t dev_id;
122 int32_t acdb_dev_id;
123 uint32_t app_type;
124 uint32_t topo_id;
125 uint32_t sampling_rate;
126 uint32_t cal_type;
127 uint32_t module_id;
128 uint32_t param_id;
129} acdb_audio_cal_cfg_t;
130
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700131/* Audio calibration related functions */
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800132typedef void (*acdb_send_audio_cal_v3_t)(int, int, int, int, int);
Eric Laurentb23d5282013-05-14 15:27:20 -0700133
Eric Laurentb23d5282013-05-14 15:27:20 -0700134struct platform_data {
135 struct audio_device *adev;
136 bool fluence_in_spkr_mode;
137 bool fluence_in_voice_call;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700138 bool fluence_in_voice_comm;
Eric Laurentb23d5282013-05-14 15:27:20 -0700139 bool fluence_in_voice_rec;
Prashant Malanic92c5962015-08-11 15:10:18 -0700140 /* 0 = no fluence, 1 = fluence, 2 = fluence pro */
141 int fluence_type;
142 int source_mic_type;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -0700143 bool speaker_lr_swap;
144
Eric Laurentb23d5282013-05-14 15:27:20 -0700145 void *acdb_handle;
Thierry Strudel07f96d12018-09-20 13:31:34 -0700146#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845) || (PLATFORM_SDM710) || (PLATFORM_SM8150)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -0700147 acdb_init_v2_cvd_t acdb_init;
148#elif defined (PLATFORM_MSM8084)
149 acdb_init_v2_t acdb_init;
150#else
151 acdb_init_t acdb_init;
152#endif
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700153 acdb_deallocate_t acdb_deallocate;
154 acdb_send_audio_cal_t acdb_send_audio_cal;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800155 acdb_send_audio_cal_v3_t acdb_send_audio_cal_v3;
jasmine chac89321b2018-04-10 21:37:01 +0800156 acdb_set_audio_cal_t acdb_set_audio_cal;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700157 acdb_send_voice_cal_t acdb_send_voice_cal;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700158 acdb_reload_vocvoltable_t acdb_reload_vocvoltable;
vivek mehta1a9b7c02015-06-25 11:49:38 -0700159 acdb_send_gain_dep_cal_t acdb_send_gain_dep_cal;
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -0700160 acdb_send_custom_top_t acdb_send_custom_top;
161 bool acdb_initialized;
162
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700163 struct csd_data *csd;
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800164 char ec_ref_mixer_path[64];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700165
David Linee3fe402017-03-13 10:00:42 -0700166 codec_backend_cfg_t current_backend_cfg[MAX_CODEC_BACKENDS];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700167 char *snd_card_name;
keunhui.parkc5aaa0e2015-07-13 10:57:37 +0900168 int max_vol_index;
Prashant Malanic92c5962015-08-11 15:10:18 -0700169 int max_mic_count;
vivek mehtade4849c2016-03-03 17:23:38 -0800170
171 void *hw_info;
jiabin8962a4d2018-03-19 18:21:24 -0700172
173 uint32_t declared_mic_count;
174 struct audio_microphone_characteristic_t microphones[AUDIO_MICROPHONE_MAX_COUNT];
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -0700175 struct snd_device_to_mic_map mic_map[SND_DEVICE_MAX];
Eric Laurentb23d5282013-05-14 15:27:20 -0700176};
177
Haynes Mathew George98c95622014-06-20 19:14:25 -0700178static int pcm_device_table[AUDIO_USECASE_MAX][2] = {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700179 [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = {DEEP_BUFFER_PCM_DEVICE,
180 DEEP_BUFFER_PCM_DEVICE},
181 [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
182 LOWLATENCY_PCM_DEVICE},
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800183 [USECASE_AUDIO_PLAYBACK_HIFI] = {MULTIMEDIA2_PCM_DEVICE,
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700184 MULTIMEDIA2_PCM_DEVICE},
185 [USECASE_AUDIO_PLAYBACK_OFFLOAD] = {PLAYBACK_OFFLOAD_DEVICE,
186 PLAYBACK_OFFLOAD_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700187 [USECASE_AUDIO_PLAYBACK_TTS] = {MULTIMEDIA2_PCM_DEVICE,
188 MULTIMEDIA2_PCM_DEVICE},
189 [USECASE_AUDIO_PLAYBACK_ULL] = {MULTIMEDIA3_PCM_DEVICE,
190 MULTIMEDIA3_PCM_DEVICE},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800191 [USECASE_AUDIO_PLAYBACK_MMAP] = {MMAP_PLAYBACK_PCM_DEVICE,
192 MMAP_PLAYBACK_PCM_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700193
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700194 [USECASE_AUDIO_RECORD] = {AUDIO_RECORD_PCM_DEVICE,
195 AUDIO_RECORD_PCM_DEVICE},
196 [USECASE_AUDIO_RECORD_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
197 LOWLATENCY_PCM_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700198
Eric Laurent0e46adf2016-12-16 12:49:24 -0800199 [USECASE_AUDIO_RECORD_MMAP] = {MMAP_RECORD_PCM_DEVICE,
200 MMAP_RECORD_PCM_DEVICE},
Haynes Mathew George569b7482017-05-08 14:44:27 -0700201 [USECASE_AUDIO_RECORD_HIFI] = {MULTIMEDIA2_PCM_DEVICE,
202 MULTIMEDIA2_PCM_DEVICE},
203
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700204 [USECASE_VOICE_CALL] = {VOICE_CALL_PCM_DEVICE,
205 VOICE_CALL_PCM_DEVICE},
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700206 [USECASE_VOICE2_CALL] = {VOICE2_CALL_PCM_DEVICE, VOICE2_CALL_PCM_DEVICE},
207 [USECASE_VOLTE_CALL] = {VOLTE_CALL_PCM_DEVICE, VOLTE_CALL_PCM_DEVICE},
208 [USECASE_QCHAT_CALL] = {QCHAT_CALL_PCM_DEVICE, QCHAT_CALL_PCM_DEVICE},
209 [USECASE_VOWLAN_CALL] = {VOWLAN_CALL_PCM_DEVICE, VOWLAN_CALL_PCM_DEVICE},
vivek mehtaa51fd402016-02-04 19:49:33 -0800210 [USECASE_VOICEMMODE1_CALL] = {VOICEMMODE1_CALL_PCM_DEVICE,
211 VOICEMMODE1_CALL_PCM_DEVICE},
212 [USECASE_VOICEMMODE2_CALL] = {VOICEMMODE2_CALL_PCM_DEVICE,
213 VOICEMMODE2_CALL_PCM_DEVICE},
214
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700215 [USECASE_INCALL_REC_UPLINK] = {AUDIO_RECORD_PCM_DEVICE,
216 AUDIO_RECORD_PCM_DEVICE},
217 [USECASE_INCALL_REC_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
218 AUDIO_RECORD_PCM_DEVICE},
219 [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
220 AUDIO_RECORD_PCM_DEVICE},
Ravi Kumar Alamanda8e6e98f2013-11-05 15:57:39 -0800221 [USECASE_AUDIO_HFP_SCO] = {HFP_PCM_RX, HFP_SCO_RX},
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700222
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700223 [USECASE_AUDIO_SPKR_CALIB_RX] = {SPKR_PROT_CALIB_RX_PCM_DEVICE, -1},
224 [USECASE_AUDIO_SPKR_CALIB_TX] = {-1, SPKR_PROT_CALIB_TX_PCM_DEVICE},
225
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700226 [USECASE_AUDIO_PLAYBACK_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
227 AFE_PROXY_RECORD_PCM_DEVICE},
228 [USECASE_AUDIO_RECORD_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
229 AFE_PROXY_RECORD_PCM_DEVICE},
zhaoyang yin4211fad2015-06-04 21:13:25 +0800230 [USECASE_AUDIO_DSM_FEEDBACK] = {QUAT_MI2S_PCM_DEVICE, QUAT_MI2S_PCM_DEVICE},
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700231
vivek mehtaa68fea62017-06-08 19:04:02 -0700232 [USECASE_AUDIO_PLAYBACK_VOIP] = {AUDIO_PLAYBACK_VOIP_PCM_DEVICE,
233 AUDIO_PLAYBACK_VOIP_PCM_DEVICE},
234 [USECASE_AUDIO_RECORD_VOIP] = {AUDIO_RECORD_VOIP_PCM_DEVICE,
235 AUDIO_RECORD_VOIP_PCM_DEVICE},
Nadav Bar3d72cfc2018-01-07 12:19:24 +0200236
237 [USECASE_INCALL_MUSIC_UPLINK] = {INCALL_MUSIC_UPLINK_PCM_DEVICE,
238 INCALL_MUSIC_UPLINK_PCM_DEVICE},
Eric Laurentb23d5282013-05-14 15:27:20 -0700239};
240
241/* Array to store sound devices */
242static const char * const device_table[SND_DEVICE_MAX] = {
243 [SND_DEVICE_NONE] = "none",
244 /* Playback sound devices */
245 [SND_DEVICE_OUT_HANDSET] = "handset",
246 [SND_DEVICE_OUT_SPEAKER] = "speaker",
247 [SND_DEVICE_OUT_SPEAKER_REVERSE] = "speaker-reverse",
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700248 [SND_DEVICE_OUT_SPEAKER_SAFE] = "speaker-safe",
Eric Laurentb23d5282013-05-14 15:27:20 -0700249 [SND_DEVICE_OUT_HEADPHONES] = "headphones",
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500250 [SND_DEVICE_OUT_LINE] = "line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700251 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones",
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700252 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = "speaker-safe-and-headphones",
Eric Laurent744996b2014-10-01 11:40:40 -0500253 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = "speaker-and-line",
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700254 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = "speaker-safe-and-line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700255 [SND_DEVICE_OUT_VOICE_HANDSET] = "voice-handset",
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500256 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = "voice-hac-handset",
Eric Laurentb23d5282013-05-14 15:27:20 -0700257 [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker",
258 [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones",
yixuanjiang9536e672018-09-06 18:43:36 +0800259 [SND_DEVICE_OUT_VOICE_HEADSET] = "voice-headphones",
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500260 [SND_DEVICE_OUT_VOICE_LINE] = "voice-line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700261 [SND_DEVICE_OUT_HDMI] = "hdmi",
262 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi",
263 [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700264 [SND_DEVICE_OUT_BT_SCO_WB] = "bt-sco-headset-wb",
Aniket Kumar Lata26483012018-01-31 20:21:42 -0800265 [SND_DEVICE_OUT_BT_A2DP] = "bt-a2dp",
266 [SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] = "speaker-and-bt-a2dp",
Aniket Kumar Lata9723a962018-05-16 17:41:55 -0700267 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP] = "speaker-safe-and-bt-a2dp",
Eric Laurentb23d5282013-05-14 15:27:20 -0700268 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = "voice-handset-tmus",
269 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones",
270 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones",
271 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset",
vivek mehtaa6b79742017-03-09 15:40:43 -0800272 [SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = "voice-tty-full-usb",
273 [SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = "voice-tty-vco-usb",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700274 [SND_DEVICE_OUT_VOICE_TX] = "voice-tx",
juyuchen66c4ecf2018-08-06 15:39:34 +0800275 [SND_DEVICE_OUT_VOICE_MUSIC_TX] = "voice-music-tx",
David Linee3fe402017-03-13 10:00:42 -0700276 [SND_DEVICE_OUT_USB_HEADSET] = "usb-headset",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700277 [SND_DEVICE_OUT_VOICE_USB_HEADSET] = "usb-headset",
David Linee3fe402017-03-13 10:00:42 -0700278 [SND_DEVICE_OUT_USB_HEADPHONES] = "usb-headphones",
jasmine cha270b7762018-03-30 15:41:33 +0800279 [SND_DEVICE_OUT_USB_HEADSET_SPEC] = "usb-headset",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700280 [SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = "usb-headphones",
David Linee3fe402017-03-13 10:00:42 -0700281 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = "speaker-and-usb-headphones",
Haynes Mathew George9090bfb2017-05-31 11:44:50 -0700282 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] = "speaker-safe-and-usb-headphones",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700283 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = "speaker-protected",
284 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = "voice-speaker-protected",
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -0700285 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = "voice-speaker-hfp",
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -0800286 [SND_DEVICE_OUT_SPEAKER_AND_BT_SCO] = "speaker-and-bt-sco",
juyuchen5351ea62018-05-16 10:54:37 +0800287 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO] = "speaker-safe-and-bt-sco",
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -0800288 [SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB] = "speaker-and-bt-sco-wb",
juyuchen5351ea62018-05-16 10:54:37 +0800289 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB] = "speaker-safe-and-bt-sco-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700290
291 /* Capture sound devices */
292 [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700293 [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700294 [SND_DEVICE_IN_HANDSET_MIC_NS] = "handset-mic",
295 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = "handset-mic",
296 [SND_DEVICE_IN_HANDSET_DMIC] = "dmic-endfire",
297 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = "dmic-endfire",
298 [SND_DEVICE_IN_HANDSET_DMIC_NS] = "dmic-endfire",
299 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = "dmic-endfire",
300 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = "dmic-endfire",
301
302 [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
303 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "speaker-mic",
304 [SND_DEVICE_IN_SPEAKER_MIC_NS] = "speaker-mic",
305 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = "speaker-mic",
306 [SND_DEVICE_IN_SPEAKER_DMIC] = "speaker-dmic-endfire",
307 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = "speaker-dmic-endfire",
308 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = "speaker-dmic-endfire",
309 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = "speaker-dmic-endfire",
310 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = "speaker-dmic-endfire",
311
312 [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
Eric Laurentcefbbac2014-09-04 13:54:10 -0500313 [SND_DEVICE_IN_HEADSET_MIC_AEC] = "headset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700314
Eric Laurentb23d5282013-05-14 15:27:20 -0700315 [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic",
316 [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700317 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = "bt-sco-mic",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700318 [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700319 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = "bt-sco-mic-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700320 [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700321
322 [SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef",
323 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = "voice-dmic-ef-tmus",
324 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
325 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = "voice-speaker-dmic-ef",
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -0700326 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = "voice-speaker-mic-hfp",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700327 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700328 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
329 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
330 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
vivek mehtaa6b79742017-03-09 15:40:43 -0800331 [SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = "voice-tty-full-usb-mic",
332 [SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = "voice-tty-hco-usb-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700333
Eric Laurentb23d5282013-05-14 15:27:20 -0700334 [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700335 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = "voice-rec-mic",
vivek mehta733c1df2016-04-04 15:09:24 -0700336 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = "voice-rec-mic",
vivek mehtaf3440682016-05-11 14:24:37 -0700337 [SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700338 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = "voice-rec-dmic-ef",
339 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence",
David Linee3fe402017-03-13 10:00:42 -0700340 [SND_DEVICE_IN_USB_HEADSET_MIC] = "usb-headset-mic",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700341 [SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] ="usb-headset-mic",
342 [SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = "usb-headset-mic",
343 [SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = "usb-headset-mic",
344 [SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = "usb-headset-mic",
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700345 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = "headset-mic",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700346
Ricardo Garcia9034bc42016-04-04 07:11:46 -0700347 [SND_DEVICE_IN_UNPROCESSED_MIC] = "unprocessed-mic",
vivek mehta0125e782016-06-16 18:03:11 -0700348 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = "unprocessed-stereo-mic",
349 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = "unprocessed-three-mic",
350 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = "unprocessed-quad-mic",
351 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = "unprocessed-headset-mic",
rago90fb9612015-12-02 11:37:53 -0800352
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700353 [SND_DEVICE_IN_VOICE_RX] = "voice-rx",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700354
Prashant Malanic92c5962015-08-11 15:10:18 -0700355 [SND_DEVICE_IN_THREE_MIC] = "three-mic",
356 [SND_DEVICE_IN_QUAD_MIC] = "quad-mic",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700357 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = "vi-feedback",
Prashant Malanic92c5962015-08-11 15:10:18 -0700358 [SND_DEVICE_IN_HANDSET_TMIC] = "three-mic",
359 [SND_DEVICE_IN_HANDSET_QMIC] = "quad-mic",
vivek mehta733c1df2016-04-04 15:09:24 -0700360 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = "three-mic",
361 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = "quad-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700362};
363
364/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700365static int acdb_device_table[SND_DEVICE_MAX] = {
Eric Laurentb23d5282013-05-14 15:27:20 -0700366 [SND_DEVICE_NONE] = -1,
367 [SND_DEVICE_OUT_HANDSET] = 7,
368 [SND_DEVICE_OUT_SPEAKER] = 15,
369 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 15,
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700370 [SND_DEVICE_OUT_SPEAKER_SAFE] = 15,
Eric Laurentb23d5282013-05-14 15:27:20 -0700371 [SND_DEVICE_OUT_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500372 [SND_DEVICE_OUT_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700373 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700374 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500375 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = 77,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700376 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = 77,
Ravi Kumar Alamanda235c3482014-08-21 17:32:44 -0700377 [SND_DEVICE_OUT_VOICE_HANDSET] = ACDB_ID_VOICE_HANDSET,
378 [SND_DEVICE_OUT_VOICE_SPEAKER] = ACDB_ID_VOICE_SPEAKER,
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500379 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = 53,
Eric Laurentb23d5282013-05-14 15:27:20 -0700380 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
yixuanjiang9536e672018-09-06 18:43:36 +0800381 [SND_DEVICE_OUT_VOICE_HEADSET] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500382 [SND_DEVICE_OUT_VOICE_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700383 [SND_DEVICE_OUT_HDMI] = 18,
384 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 15,
385 [SND_DEVICE_OUT_BT_SCO] = 22,
juyuchen5351ea62018-05-16 10:54:37 +0800386 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO] = 14,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700387 [SND_DEVICE_OUT_BT_SCO_WB] = 39,
juyuchen5351ea62018-05-16 10:54:37 +0800388 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB] = 14,
Aniket Kumar Lata26483012018-01-31 20:21:42 -0800389 [SND_DEVICE_OUT_BT_A2DP] = 20,
390 [SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] = 14,
Aniket Kumar Lata9723a962018-05-16 17:41:55 -0700391 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP] = 14,
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700392 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = ACDB_ID_VOICE_HANDSET_TMUS,
Eric Laurentb23d5282013-05-14 15:27:20 -0700393 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
394 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
395 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
vivek mehtaa6b79742017-03-09 15:40:43 -0800396 [SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = 17,
397 [SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = 17,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700398 [SND_DEVICE_OUT_VOICE_TX] = 45,
juyuchen66c4ecf2018-08-06 15:39:34 +0800399 [SND_DEVICE_OUT_VOICE_MUSIC_TX] = 3,
David Linee3fe402017-03-13 10:00:42 -0700400 [SND_DEVICE_OUT_USB_HEADSET] = 45,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700401 [SND_DEVICE_OUT_VOICE_USB_HEADSET] = 45,
David Linee3fe402017-03-13 10:00:42 -0700402 [SND_DEVICE_OUT_USB_HEADPHONES] = 45,
jasmine cha270b7762018-03-30 15:41:33 +0800403 [SND_DEVICE_OUT_USB_HEADSET_SPEC] = 45,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700404 [SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = 45,
David Linee3fe402017-03-13 10:00:42 -0700405 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = 14,
Haynes Mathew George9090bfb2017-05-31 11:44:50 -0700406 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] = 14,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700407 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = 124,
408 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = 101,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700409 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = ACDB_ID_VOICE_SPEAKER,
Eric Laurentb23d5282013-05-14 15:27:20 -0700410
411 [SND_DEVICE_IN_HANDSET_MIC] = 4,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700412 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 106,
413 [SND_DEVICE_IN_HANDSET_MIC_NS] = 107,
414 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = 108,
415 [SND_DEVICE_IN_HANDSET_DMIC] = 41,
416 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = 109,
417 [SND_DEVICE_IN_HANDSET_DMIC_NS] = 110,
418 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = 111,
419 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = 34,
420
421 [SND_DEVICE_IN_SPEAKER_MIC] = 11,
422 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 112,
423 [SND_DEVICE_IN_SPEAKER_MIC_NS] = 113,
424 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = 114,
425 [SND_DEVICE_IN_SPEAKER_DMIC] = 43,
426 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = 115,
427 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = 116,
428 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = 117,
429 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = 35,
430
rago90fb9612015-12-02 11:37:53 -0800431 [SND_DEVICE_IN_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentcefbbac2014-09-04 13:54:10 -0500432 [SND_DEVICE_IN_HEADSET_MIC_AEC] = ACDB_ID_HEADSET_MIC_AEC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700433
Eric Laurentb23d5282013-05-14 15:27:20 -0700434 [SND_DEVICE_IN_HDMI_MIC] = 4,
435 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700436 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = 21,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700437 [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700438 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = 38,
Eric Laurentb23d5282013-05-14 15:27:20 -0700439 [SND_DEVICE_IN_CAMCORDER_MIC] = 61,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700440
441 [SND_DEVICE_IN_VOICE_DMIC] = 41,
442 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = ACDB_ID_VOICE_DMIC_EF_TMUS,
443 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700444 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = 11,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700445 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 43,
rago90fb9612015-12-02 11:37:53 -0800446 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentb23d5282013-05-14 15:27:20 -0700447 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
448 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
449 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
vivek mehtaa6b79742017-03-09 15:40:43 -0800450 [SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = 16,
451 [SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = 16,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700452
rago90fb9612015-12-02 11:37:53 -0800453 [SND_DEVICE_IN_VOICE_REC_MIC] = ACDB_ID_VOICE_REC_MIC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700454 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = 113,
vivek mehta733c1df2016-04-04 15:09:24 -0700455 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = 112,
vivek mehtaf3440682016-05-11 14:24:37 -0700456 [SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = 114,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700457 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = 35,
458 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 43,
rago90fb9612015-12-02 11:37:53 -0800459 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
460
461 [SND_DEVICE_IN_UNPROCESSED_MIC] = ACDB_ID_VOICE_REC_MIC,
462 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
vivek mehta4ed66e62016-04-15 23:33:34 -0700463 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = 35,
464 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = 125,
465 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = 125,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700466
467 [SND_DEVICE_IN_VOICE_RX] = 44,
David Linee3fe402017-03-13 10:00:42 -0700468 [SND_DEVICE_IN_USB_HEADSET_MIC] = 44,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700469 [SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = 44,
470 [SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = 44,
471 [SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = 44,
472 [SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = 44,
Prashant Malanic92c5962015-08-11 15:10:18 -0700473 [SND_DEVICE_IN_THREE_MIC] = 46,
474 [SND_DEVICE_IN_QUAD_MIC] = 46,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700475 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = 102,
Prashant Malanic92c5962015-08-11 15:10:18 -0700476 [SND_DEVICE_IN_HANDSET_TMIC] = 125,
477 [SND_DEVICE_IN_HANDSET_QMIC] = 125,
vivek mehta733c1df2016-04-04 15:09:24 -0700478 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = 125, /* override this for new target to 140 */
479 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = 125, /* override this for new target to 140 */
Eric Laurentb23d5282013-05-14 15:27:20 -0700480};
481
David Linee3fe402017-03-13 10:00:42 -0700482// Platform specific backend bit width table
483static int backend_bit_width_table[SND_DEVICE_MAX] = {0};
484
Haynes Mathew George98c95622014-06-20 19:14:25 -0700485struct name_to_index {
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700486 char name[100];
487 unsigned int index;
488};
489
490#define TO_NAME_INDEX(X) #X, X
491
Haynes Mathew George98c95622014-06-20 19:14:25 -0700492/* Used to get index from parsed string */
493static const struct name_to_index snd_device_name_index[SND_DEVICE_MAX] = {
494 /* out */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700495 {TO_NAME_INDEX(SND_DEVICE_OUT_HANDSET)},
496 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER)},
497 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_REVERSE)},
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700498 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700499 {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500500 {TO_NAME_INDEX(SND_DEVICE_OUT_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700501 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700502 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES)},
Eric Laurent744996b2014-10-01 11:40:40 -0500503 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_LINE)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700504 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700505 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET)},
506 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700507 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_HFP)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700508 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADPHONES)},
yixuanjiang9536e672018-09-06 18:43:36 +0800509 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADSET)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500510 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700511 {TO_NAME_INDEX(SND_DEVICE_OUT_HDMI)},
512 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HDMI)},
513 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO)},
juyuchen5351ea62018-05-16 10:54:37 +0800514 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700515 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO_WB)},
juyuchen5351ea62018-05-16 10:54:37 +0800516 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB)},
Aniket Kumar Lata26483012018-01-31 20:21:42 -0800517 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_A2DP)},
518 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP)},
Aniket Kumar Lata9723a962018-05-16 17:41:55 -0700519 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700520 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET_TMUS)},
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500521 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HAC_HANDSET)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700522 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES)},
523 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES)},
524 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET)},
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -0800525 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_SCO)},
526 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800527 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_USB)},
528 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_USB)},
David Linee3fe402017-03-13 10:00:42 -0700529 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADSET)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700530 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_USB_HEADSET)},
David Linee3fe402017-03-13 10:00:42 -0700531 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADPHONES)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700532 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_USB_HEADPHONES)},
David Linee3fe402017-03-13 10:00:42 -0700533 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET)},
Haynes Mathew George9090bfb2017-05-31 11:44:50 -0700534 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700535 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED)},
536 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED)},
jasmine cha270b7762018-03-30 15:41:33 +0800537 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADSET_SPEC)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800538
539 /* in */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700540 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700541 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700542 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_NS)},
543 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)},
544 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC)},
545 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC)},
546 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_NS)},
547 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)},
548 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_STEREO)},
549
550 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700551 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700552 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_NS)},
553 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)},
554 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC)},
555 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC)},
556 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS)},
557 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)},
558 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_STEREO)},
559
560 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC)},
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700561 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700562
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700563 {TO_NAME_INDEX(SND_DEVICE_IN_HDMI_MIC)},
564 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700565 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700566 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700567 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700568 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700569
570 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC)},
571 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC_TMUS)},
572 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700573 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700574 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC)},
575 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEADSET_MIC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700576 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC)},
577 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC)},
578 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800579 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC)},
580 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC)},
581
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700582
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700583 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700584 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_NS)},
vivek mehta733c1df2016-04-04 15:09:24 -0700585 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC)},
vivek mehtaf3440682016-05-11 14:24:37 -0700586 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700587 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_STEREO)},
588 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE)},
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700589 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_HEADSET_MIC)},
David Linee3fe402017-03-13 10:00:42 -0700590 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700591 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_USB_HEADSET_MIC)},
592 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC)},
593 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC)},
594 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC_AEC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700595
rago90fb9612015-12-02 11:37:53 -0800596 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_MIC)},
597 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC)},
vivek mehta4ed66e62016-04-15 23:33:34 -0700598 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_STEREO_MIC)},
599 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_THREE_MIC)},
600 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_QUAD_MIC)},
rago90fb9612015-12-02 11:37:53 -0800601
Prashant Malanic92c5962015-08-11 15:10:18 -0700602 {TO_NAME_INDEX(SND_DEVICE_IN_THREE_MIC)},
603 {TO_NAME_INDEX(SND_DEVICE_IN_QUAD_MIC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700604 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_VI_FEEDBACK)},
Prashant Malanic92c5962015-08-11 15:10:18 -0700605 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC)},
606 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC)},
vivek mehta733c1df2016-04-04 15:09:24 -0700607 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC_AEC)},
608 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC_AEC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700609};
610
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700611static char * backend_tag_table[SND_DEVICE_MAX] = {0};
612static char * hw_interface_table[SND_DEVICE_MAX] = {0};
Haynes Mathew George98c95622014-06-20 19:14:25 -0700613
614static const struct name_to_index usecase_name_index[AUDIO_USECASE_MAX] = {
615 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_DEEP_BUFFER)},
616 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_LOW_LATENCY)},
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800617 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_HIFI)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700618 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD)},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700619 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_TTS)},
620 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_ULL)},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800621 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_MMAP)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700622 {TO_NAME_INDEX(USECASE_AUDIO_RECORD)},
623 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_LOW_LATENCY)},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800624 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_MMAP)},
Haynes Mathew George569b7482017-05-08 14:44:27 -0700625 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_HIFI)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700626 {TO_NAME_INDEX(USECASE_VOICE_CALL)},
627 {TO_NAME_INDEX(USECASE_VOICE2_CALL)},
628 {TO_NAME_INDEX(USECASE_VOLTE_CALL)},
629 {TO_NAME_INDEX(USECASE_QCHAT_CALL)},
630 {TO_NAME_INDEX(USECASE_VOWLAN_CALL)},
John Muirf1346ce2016-12-06 00:03:41 -0800631 {TO_NAME_INDEX(USECASE_VOICEMMODE1_CALL)},
632 {TO_NAME_INDEX(USECASE_VOICEMMODE2_CALL)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700633 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK)},
634 {TO_NAME_INDEX(USECASE_INCALL_REC_DOWNLINK)},
635 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK_AND_DOWNLINK)},
636 {TO_NAME_INDEX(USECASE_AUDIO_HFP_SCO)},
John Muirf1346ce2016-12-06 00:03:41 -0800637 {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_RX)},
638 {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_TX)},
639 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_AFE_PROXY)},
640 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_AFE_PROXY)},
641 {TO_NAME_INDEX(USECASE_AUDIO_DSM_FEEDBACK)},
vivek mehtaa68fea62017-06-08 19:04:02 -0700642 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_VOIP)},
643 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_VOIP)},
Nadav Bar3d72cfc2018-01-07 12:19:24 +0200644 {TO_NAME_INDEX(USECASE_INCALL_MUSIC_UPLINK)},
Aniket Kumar Lata99546312018-03-19 21:38:38 -0700645 {TO_NAME_INDEX(USECASE_AUDIO_A2DP_ABR_FEEDBACK)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700646};
647
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800648static const struct name_to_index usecase_type_index[USECASE_TYPE_MAX] = {
649 {TO_NAME_INDEX(PCM_PLAYBACK)},
650 {TO_NAME_INDEX(PCM_CAPTURE)},
651 {TO_NAME_INDEX(VOICE_CALL)},
652 {TO_NAME_INDEX(PCM_HFP_CALL)},
653};
654
655struct app_type_entry {
656 int uc_type;
657 int bit_width;
658 int app_type;
659 int max_rate;
vivek mehtaa68fea62017-06-08 19:04:02 -0700660 char *mode;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800661 struct listnode node; // membership in app_type_entry_list;
662};
663
664static struct listnode app_type_entry_list;
665
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700666#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
667#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
Eric Laurent0e46adf2016-12-16 12:49:24 -0800668#define ULL_PLATFORM_DELAY (3*1000LL)
669#define MMAP_PLATFORM_DELAY (3*1000LL)
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700670
Eric Laurentb23d5282013-05-14 15:27:20 -0700671static pthread_once_t check_op_once_ctl = PTHREAD_ONCE_INIT;
672static bool is_tmus = false;
673
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800674static int init_be_dai_name_table(struct audio_device *adev);
675
Eric Laurentb23d5282013-05-14 15:27:20 -0700676static void check_operator()
677{
678 char value[PROPERTY_VALUE_MAX];
679 int mccmnc;
680 property_get("gsm.sim.operator.numeric",value,"0");
681 mccmnc = atoi(value);
Eric Laurent2bafff12016-03-17 12:17:23 -0700682 ALOGD("%s: tmus mccmnc %d", __func__, mccmnc);
Eric Laurentb23d5282013-05-14 15:27:20 -0700683 switch(mccmnc) {
684 /* TMUS MCC(310), MNC(490, 260, 026) */
685 case 310490:
686 case 310260:
687 case 310026:
sangwon.jeonb891db52013-09-14 17:39:15 +0900688 /* Add new TMUS MNC(800, 660, 580, 310, 270, 250, 240, 230, 220, 210, 200, 160) */
689 case 310800:
690 case 310660:
691 case 310580:
692 case 310310:
693 case 310270:
694 case 310250:
695 case 310240:
696 case 310230:
697 case 310220:
698 case 310210:
699 case 310200:
700 case 310160:
Eric Laurentb23d5282013-05-14 15:27:20 -0700701 is_tmus = true;
702 break;
703 }
704}
705
706bool is_operator_tmus()
707{
708 pthread_once(&check_op_once_ctl, check_operator);
709 return is_tmus;
710}
711
keunhui.park2f7306a2015-07-16 16:48:06 +0900712static char *get_current_operator()
713{
714 struct listnode *node;
715 struct operator_info *info_item;
716 char mccmnc[PROPERTY_VALUE_MAX];
717 char *ret = NULL;
718
Tom Cherry7fea2042016-11-10 18:05:59 -0800719 property_get("gsm.sim.operator.numeric",mccmnc,"00000");
keunhui.park2f7306a2015-07-16 16:48:06 +0900720
721 list_for_each(node, &operator_info_list) {
722 info_item = node_to_item(node, struct operator_info, list);
723 if (strstr(info_item->mccmnc, mccmnc) != NULL) {
724 ret = info_item->name;
725 }
726 }
727
728 return ret;
729}
730
731static struct operator_specific_device *get_operator_specific_device(snd_device_t snd_device)
732{
733 struct listnode *node;
734 struct operator_specific_device *ret = NULL;
735 struct operator_specific_device *device_item;
736 char *operator_name;
737
738 operator_name = get_current_operator();
739 if (operator_name == NULL)
740 return ret;
741
742 list_for_each(node, operator_specific_device_table[snd_device]) {
743 device_item = node_to_item(node, struct operator_specific_device, list);
744 if (strcmp(operator_name, device_item->operator) == 0) {
745 ret = device_item;
746 }
747 }
748
749 return ret;
750}
751
752
753static int get_operator_specific_device_acdb_id(snd_device_t snd_device)
754{
755 struct operator_specific_device *device;
756 int ret = acdb_device_table[snd_device];
757
758 device = get_operator_specific_device(snd_device);
759 if (device != NULL)
760 ret = device->acdb_id;
761
762 return ret;
763}
764
765static const char *get_operator_specific_device_mixer_path(snd_device_t snd_device)
766{
767 struct operator_specific_device *device;
768 const char *ret = device_table[snd_device];
769
770 device = get_operator_specific_device(snd_device);
771 if (device != NULL)
772 ret = device->mixer_path;
773
774 return ret;
775}
776
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800777inline bool platform_supports_app_type_cfg()
778{
Thierry Strudel07f96d12018-09-20 13:31:34 -0700779#if defined (PLATFORM_MSM8998) || (PLATFORM_SDM845) || (PLATFORM_SDM710) || (PLATFORM_SM8150)
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800780 return true;
781#else
782 return false;
783#endif
784}
785
jasmine chac89321b2018-04-10 21:37:01 +0800786static int parse_audiocal_cfg(struct str_parms *parms, acdb_audio_cal_cfg_t *cal)
787{
788 int err;
789 char value[64];
790 int ret = 0;
791
792 if (parms == NULL || cal == NULL)
793 return ret;
794
795 err = str_parms_get_str(parms, "cal_persist", value, sizeof(value));
796 if (err >= 0) {
797 str_parms_del(parms, "cal_persist");
798 cal->persist = (uint32_t)strtoul(value, NULL, 0);
799 ret = ret | 0x1;
800 }
801 err = str_parms_get_str(parms, "cal_apptype", value, sizeof(value));
802 if (err >= 0) {
803 str_parms_del(parms, "cal_apptype");
804 cal->app_type = (uint32_t)strtoul(value, NULL, 0);
805 ret = ret | 0x2;
806 }
807 err = str_parms_get_str(parms, "cal_caltype", value, sizeof(value));
808 if (err >= 0) {
809 str_parms_del(parms, "cal_caltype");
810 cal->cal_type = (uint32_t)strtoul(value, NULL, 0);
811 ret = ret | 0x4;
812 }
813 err = str_parms_get_str(parms, "cal_samplerate", value, sizeof(value));
814 if (err >= 0) {
815 str_parms_del(parms, "cal_samplerate");
816 cal->sampling_rate = (uint32_t)strtoul(value, NULL, 0);
817 ret = ret | 0x8;
818 }
819 err = str_parms_get_str(parms, "cal_devid", value, sizeof(value));
820 if (err >= 0) {
821 str_parms_del(parms, "cal_devid");
822 cal->dev_id = (uint32_t)strtoul(value, NULL, 0);
823 ret = ret | 0x10;
824 }
825 err = str_parms_get_str(parms, "cal_snddevid", value, sizeof(value));
826 if (err >= 0) {
827 str_parms_del(parms, "cal_snddevid");
828 cal->snd_dev_id = (uint32_t)strtoul(value, NULL, 0);
829 ret = ret | 0x20;
830 }
831 err = str_parms_get_str(parms, "cal_topoid", value, sizeof(value));
832 if (err >= 0) {
833 str_parms_del(parms, "cal_topoid");
834 cal->topo_id = (uint32_t)strtoul(value, NULL, 0);
835 ret = ret | 0x40;
836 }
837 err = str_parms_get_str(parms, "cal_moduleid", value, sizeof(value));
838 if (err >= 0) {
839 str_parms_del(parms, "cal_moduleid");
840 cal->module_id = (uint32_t)strtoul(value, NULL, 0);
841 ret = ret | 0x80;
842 }
843 err = str_parms_get_str(parms, "cal_paramid", value, sizeof(value));
844 if (err >= 0) {
845 str_parms_del(parms, "cal_paramid");
846 cal->param_id = (uint32_t)strtoul(value, NULL, 0);
847 ret = ret | 0x100;
848 }
849 return ret;
850}
851
852static void set_audiocal(void *platform, struct str_parms *parms, char *value, int len)
853{
854 struct platform_data *my_data = (struct platform_data *)platform;
855 acdb_audio_cal_cfg_t cal;
856 uint8_t *dptr = NULL;
857 int32_t dlen = 0;
858 int err ,ret;
859
860 if (value == NULL || platform == NULL || parms == NULL) {
861 ALOGE("[%s] received null pointer, failed", __func__);
862 goto done_key_audcal;
863 }
864
865 memset(&cal, 0, sizeof(acdb_audio_cal_cfg_t));
866 /* parse audio calibration keys */
867 ret = parse_audiocal_cfg(parms, &cal);
868
869 /* handle audio calibration data now */
870 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_AUD_CALDATA, value, len);
871 if (err >= 0) {
872 str_parms_del(parms, AUDIO_PARAMETER_KEY_AUD_CALDATA);
873 dlen = strlen(value);
874 if (dlen <= 0) {
875 ALOGE("[%s] null data received", __func__);
876 goto done_key_audcal;
877 }
878 /*
879 The base64 encoded string is always larger than the binary data,
880 so b64_pton will always output less data than provided (around 1/3
881 less than the input data). That's why we can allocate input buffer
882 length and then get function work.
883 */
884 dptr = (uint8_t *)calloc(dlen, sizeof(uint8_t));
885 if (dptr == NULL) {
886 ALOGE("[%s] memory allocation failed for %d", __func__, dlen);
887 goto done_key_audcal;
888 }
889 dlen = b64_pton(value, dptr, dlen);
890 if (dlen <= 0) {
891 ALOGE("[%s] data decoding failed %d", __func__, dlen);
892 goto done_key_audcal;
893 }
894
895 if (cal.dev_id) {
896 if (audio_is_input_device(cal.dev_id)) {
897 cal.snd_dev_id = platform_get_input_snd_device(platform, cal.dev_id);
898 } else {
899 cal.snd_dev_id = platform_get_output_snd_device(platform, cal.dev_id);
900 }
901 }
902 cal.acdb_dev_id = platform_get_snd_device_acdb_id(cal.snd_dev_id);
903 ALOGD("Setting audio calibration for snd_device(%d) acdb_id(%d)",
904 cal.snd_dev_id, cal.acdb_dev_id);
905 if (cal.acdb_dev_id == -EINVAL) {
906 ALOGE("[%s] Invalid acdb_device id %d for snd device id %d",
907 __func__, cal.acdb_dev_id, cal.snd_dev_id);
908 goto done_key_audcal;
909 }
910 if (my_data->acdb_set_audio_cal) {
911 ret = my_data->acdb_set_audio_cal((void *)&cal, (void *)dptr, dlen);
912 }
913 }
914done_key_audcal:
915 if (dptr != NULL)
916 free(dptr);
917}
918
vivek mehta1a9b7c02015-06-25 11:49:38 -0700919bool platform_send_gain_dep_cal(void *platform, int level)
920{
921 bool ret_val = false;
922 struct platform_data *my_data = (struct platform_data *)platform;
923 struct audio_device *adev = my_data->adev;
924 int acdb_dev_id, app_type;
925 int acdb_dev_type = MSM_SNDDEV_CAP_RX;
926 int mode = CAL_MODE_RTAC;
927 struct listnode *node;
928 struct audio_usecase *usecase;
Haynes Mathew George67486e22017-06-26 12:58:38 -0700929 bool valid_uc_type;
930 bool valid_dev;
vivek mehta1a9b7c02015-06-25 11:49:38 -0700931
932 if (my_data->acdb_send_gain_dep_cal == NULL) {
933 ALOGE("%s: dlsym error for acdb_send_gain_dep_cal", __func__);
934 return ret_val;
935 }
936
937 if (!voice_is_in_call(adev)) {
938 ALOGV("%s: Not Voice call usecase, apply new cal for level %d",
939 __func__, level);
vivek mehta1a9b7c02015-06-25 11:49:38 -0700940
941 // find the current active sound device
942 list_for_each(node, &adev->usecase_list) {
943 usecase = node_to_item(node, struct audio_usecase, list);
Haynes Mathew George67486e22017-06-26 12:58:38 -0700944 LOG_ALWAYS_FATAL_IF(usecase == NULL,
945 "unxpected NULL usecase in usecase_list");
946 valid_uc_type = usecase->type == PCM_PLAYBACK;
947 valid_dev = false;
948 if (valid_uc_type) {
949 audio_devices_t dev = usecase->stream.out->devices;
950 valid_dev = (dev == AUDIO_DEVICE_OUT_SPEAKER ||
vivek mehta40125092017-08-21 18:48:51 -0700951 dev == AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Haynes Mathew George67486e22017-06-26 12:58:38 -0700952 dev == AUDIO_DEVICE_OUT_WIRED_HEADSET ||
953 dev == AUDIO_DEVICE_OUT_WIRED_HEADPHONE);
954 }
955 if (valid_dev) {
vivek mehta40125092017-08-21 18:48:51 -0700956 ALOGV("%s: out device is %d", __func__, usecase->out_snd_device);
957 if (platform_supports_app_type_cfg())
958 app_type = usecase->stream.out->app_type_cfg.app_type;
959 else
960 app_type = DEFAULT_APP_TYPE_RX_PATH;
vivek mehta4cb82982015-07-13 12:05:49 -0700961
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -0700962 acdb_dev_id = platform_get_snd_device_acdb_id(usecase->out_snd_device);
vivek mehta40125092017-08-21 18:48:51 -0700963
964 if (!my_data->acdb_send_gain_dep_cal(acdb_dev_id, app_type,
vivek mehta1a9b7c02015-06-25 11:49:38 -0700965 acdb_dev_type, mode, level)) {
966 // set ret_val true if at least one calibration is set successfully
967 ret_val = true;
968 } else {
969 ALOGE("%s: my_data->acdb_send_gain_dep_cal failed ", __func__);
970 }
971 } else {
972 ALOGW("%s: Usecase list is empty", __func__);
973 }
974 }
975 } else {
976 ALOGW("%s: Voice call in progress .. ignore setting new cal",
977 __func__);
978 }
979 return ret_val;
980}
981
Eric Laurentcefbbac2014-09-04 13:54:10 -0500982void platform_set_echo_reference(struct audio_device *adev, bool enable, audio_devices_t out_device)
Eric Laurentb23d5282013-05-14 15:27:20 -0700983{
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800984 struct platform_data *my_data = (struct platform_data *)adev->platform;
Eric Laurentcefbbac2014-09-04 13:54:10 -0500985 snd_device_t snd_device = SND_DEVICE_NONE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700986
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800987 if (strcmp(my_data->ec_ref_mixer_path, "")) {
988 ALOGV("%s: diabling %s", __func__, my_data->ec_ref_mixer_path);
989 audio_route_reset_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
Eric Laurentcefbbac2014-09-04 13:54:10 -0500990 }
991
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800992 if (enable) {
993 strcpy(my_data->ec_ref_mixer_path, "echo-reference");
994 if (out_device != AUDIO_DEVICE_NONE) {
995 snd_device = platform_get_output_snd_device(adev->platform, out_device);
996 platform_add_backend_name(adev->platform, my_data->ec_ref_mixer_path, snd_device);
997 }
Eric Laurentcefbbac2014-09-04 13:54:10 -0500998
Joe Onorato188b6222016-03-01 11:02:27 -0800999 ALOGV("%s: enabling %s", __func__, my_data->ec_ref_mixer_path);
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08001000 audio_route_apply_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
1001 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001002}
1003
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001004static struct csd_data *open_csd_client(bool i2s_ext_modem)
1005{
1006 struct csd_data *csd = calloc(1, sizeof(struct csd_data));
1007
1008 csd->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
1009 if (csd->csd_client == NULL) {
1010 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
1011 goto error;
1012 } else {
1013 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
1014
1015 csd->deinit = (deinit_t)dlsym(csd->csd_client,
1016 "csd_client_deinit");
1017 if (csd->deinit == NULL) {
1018 ALOGE("%s: dlsym error %s for csd_client_deinit", __func__,
1019 dlerror());
1020 goto error;
1021 }
1022 csd->disable_device = (disable_device_t)dlsym(csd->csd_client,
1023 "csd_client_disable_device");
1024 if (csd->disable_device == NULL) {
1025 ALOGE("%s: dlsym error %s for csd_client_disable_device",
1026 __func__, dlerror());
1027 goto error;
1028 }
1029 csd->enable_device_config = (enable_device_config_t)dlsym(csd->csd_client,
1030 "csd_client_enable_device_config");
1031 if (csd->enable_device_config == NULL) {
1032 ALOGE("%s: dlsym error %s for csd_client_enable_device_config",
1033 __func__, dlerror());
1034 goto error;
1035 }
1036 csd->enable_device = (enable_device_t)dlsym(csd->csd_client,
1037 "csd_client_enable_device");
1038 if (csd->enable_device == NULL) {
1039 ALOGE("%s: dlsym error %s for csd_client_enable_device",
1040 __func__, dlerror());
1041 goto error;
1042 }
1043 csd->start_voice = (start_voice_t)dlsym(csd->csd_client,
1044 "csd_client_start_voice");
1045 if (csd->start_voice == NULL) {
1046 ALOGE("%s: dlsym error %s for csd_client_start_voice",
1047 __func__, dlerror());
1048 goto error;
1049 }
1050 csd->stop_voice = (stop_voice_t)dlsym(csd->csd_client,
1051 "csd_client_stop_voice");
1052 if (csd->stop_voice == NULL) {
1053 ALOGE("%s: dlsym error %s for csd_client_stop_voice",
1054 __func__, dlerror());
1055 goto error;
1056 }
1057 csd->volume = (volume_t)dlsym(csd->csd_client,
1058 "csd_client_volume");
1059 if (csd->volume == NULL) {
1060 ALOGE("%s: dlsym error %s for csd_client_volume",
1061 __func__, dlerror());
1062 goto error;
1063 }
1064 csd->mic_mute = (mic_mute_t)dlsym(csd->csd_client,
1065 "csd_client_mic_mute");
1066 if (csd->mic_mute == NULL) {
1067 ALOGE("%s: dlsym error %s for csd_client_mic_mute",
1068 __func__, dlerror());
1069 goto error;
1070 }
1071 csd->slow_talk = (slow_talk_t)dlsym(csd->csd_client,
1072 "csd_client_slow_talk");
1073 if (csd->slow_talk == NULL) {
1074 ALOGE("%s: dlsym error %s for csd_client_slow_talk",
1075 __func__, dlerror());
1076 goto error;
1077 }
1078 csd->start_playback = (start_playback_t)dlsym(csd->csd_client,
1079 "csd_client_start_playback");
1080 if (csd->start_playback == NULL) {
1081 ALOGE("%s: dlsym error %s for csd_client_start_playback",
1082 __func__, dlerror());
1083 goto error;
1084 }
1085 csd->stop_playback = (stop_playback_t)dlsym(csd->csd_client,
1086 "csd_client_stop_playback");
1087 if (csd->stop_playback == NULL) {
1088 ALOGE("%s: dlsym error %s for csd_client_stop_playback",
1089 __func__, dlerror());
1090 goto error;
1091 }
1092 csd->start_record = (start_record_t)dlsym(csd->csd_client,
1093 "csd_client_start_record");
1094 if (csd->start_record == NULL) {
1095 ALOGE("%s: dlsym error %s for csd_client_start_record",
1096 __func__, dlerror());
1097 goto error;
1098 }
1099 csd->stop_record = (stop_record_t)dlsym(csd->csd_client,
1100 "csd_client_stop_record");
1101 if (csd->stop_record == NULL) {
1102 ALOGE("%s: dlsym error %s for csd_client_stop_record",
1103 __func__, dlerror());
1104 goto error;
1105 }
1106
1107 csd->get_sample_rate = (get_sample_rate_t)dlsym(csd->csd_client,
1108 "csd_client_get_sample_rate");
1109 if (csd->get_sample_rate == NULL) {
1110 ALOGE("%s: dlsym error %s for csd_client_get_sample_rate",
1111 __func__, dlerror());
1112
1113 goto error;
1114 }
1115
1116 csd->init = (init_t)dlsym(csd->csd_client, "csd_client_init");
1117
1118 if (csd->init == NULL) {
1119 ALOGE("%s: dlsym error %s for csd_client_init",
1120 __func__, dlerror());
1121 goto error;
1122 } else {
1123 csd->init(i2s_ext_modem);
1124 }
1125 }
1126 return csd;
1127
1128error:
1129 free(csd);
1130 csd = NULL;
1131 return csd;
1132}
1133
1134void close_csd_client(struct csd_data *csd)
1135{
1136 if (csd != NULL) {
1137 csd->deinit();
1138 dlclose(csd->csd_client);
1139 free(csd);
1140 csd = NULL;
1141 }
1142}
1143
1144static void platform_csd_init(struct platform_data *my_data)
1145{
1146#ifdef PLATFORM_MSM8084
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001147 int32_t modems, (*count_modems)(void);
1148 const char *name = "libdetectmodem.so";
1149 const char *func = "count_modems";
1150 const char *error;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001151
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001152 my_data->csd = NULL;
1153
1154 void *lib = dlopen(name, RTLD_NOW);
1155 error = dlerror();
1156 if (!lib) {
1157 ALOGE("%s: could not find %s: %s", __func__, name, error);
1158 return;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001159 }
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001160
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001161 count_modems = NULL;
1162 *(void **)(&count_modems) = dlsym(lib, func);
1163 error = dlerror();
1164 if (!count_modems) {
1165 ALOGE("%s: could not find symbol %s in %s: %s",
1166 __func__, func, name, error);
1167 goto done;
1168 }
1169
1170 modems = count_modems();
1171 if (modems < 0) {
1172 ALOGE("%s: count_modems failed\n", __func__);
1173 goto done;
1174 }
1175
Eric Laurent2bafff12016-03-17 12:17:23 -07001176 ALOGD("%s: num_modems %d\n", __func__, modems);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001177 if (modems > 0)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001178 my_data->csd = open_csd_client(false /*is_i2s_ext_modem*/);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001179
1180done:
1181 dlclose(lib);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001182#else
1183 my_data->csd = NULL;
1184#endif
1185}
1186
Eric Laurentc6333382015-09-14 12:43:44 -07001187static void set_platform_defaults(struct platform_data * my_data)
Haynes Mathew George98c95622014-06-20 19:14:25 -07001188{
1189 int32_t dev;
1190 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001191 backend_tag_table[dev] = NULL;
1192 hw_interface_table[dev] = NULL;
keunhui.park2f7306a2015-07-16 16:48:06 +09001193 operator_specific_device_table[dev] = NULL;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001194 }
1195
David Linee3fe402017-03-13 10:00:42 -07001196 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1197 backend_bit_width_table[dev] = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
1198 }
1199
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001200 // To overwrite these go to the audio_platform_info.xml file.
1201 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("bt-sco");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07001202 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("bt-sco");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001203 backend_tag_table[SND_DEVICE_OUT_BT_SCO] = strdup("bt-sco");
1204 backend_tag_table[SND_DEVICE_OUT_HDMI] = strdup("hdmi");
1205 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("speaker-and-hdmi");
1206 backend_tag_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("bt-sco-wb");
1207 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("bt-sco-wb");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07001208 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("bt-sco-wb");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001209 backend_tag_table[SND_DEVICE_OUT_VOICE_TX] = strdup("afe-proxy");
1210 backend_tag_table[SND_DEVICE_IN_VOICE_RX] = strdup("afe-proxy");
Haynes Mathew George98c95622014-06-20 19:14:25 -07001211
David Linee3fe402017-03-13 10:00:42 -07001212 backend_tag_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("usb-headset");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001213 backend_tag_table[SND_DEVICE_OUT_VOICE_USB_HEADSET] = strdup("usb-headset");
David Linee3fe402017-03-13 10:00:42 -07001214 backend_tag_table[SND_DEVICE_OUT_USB_HEADPHONES] = strdup("usb-headphones");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001215 backend_tag_table[SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = strdup("usb-headphones");
David Linee3fe402017-03-13 10:00:42 -07001216 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] =
1217 strdup("speaker-and-usb-headphones");
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07001218 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] =
1219 strdup("speaker-safe-and-usb-headphones");
juyuchen5351ea62018-05-16 10:54:37 +08001220 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO] =
1221 strdup("speaker-safe-and-bt-sco"),
1222 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB] =
1223 strdup("speaker-safe-and-bt-sco-wb"),
David Linee3fe402017-03-13 10:00:42 -07001224 backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("usb-headset-mic");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001225 backend_tag_table[SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1226 backend_tag_table[SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1227 backend_tag_table[SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1228 backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = strdup("usb-headset-mic");
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001229 backend_tag_table[SND_DEVICE_OUT_BT_A2DP] = strdup("bt-a2dp");
1230 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] = strdup("speaker-and-bt-a2dp");
Aniket Kumar Lata9723a962018-05-16 17:41:55 -07001231 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP] = strdup("speaker-safe-and-bt-a2dp");
jasmine cha270b7762018-03-30 15:41:33 +08001232 backend_tag_table[SND_DEVICE_OUT_USB_HEADSET_SPEC] = strdup("usb-headset");
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001233
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001234 hw_interface_table[SND_DEVICE_OUT_HANDSET] = strdup("SLIMBUS_0_RX");
1235 hw_interface_table[SND_DEVICE_OUT_SPEAKER] = strdup("SLIMBUS_0_RX");
1236 hw_interface_table[SND_DEVICE_OUT_SPEAKER_REVERSE] = strdup("SLIMBUS_0_RX");
1237 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE] = strdup("SLIMBUS_0_RX");
1238 hw_interface_table[SND_DEVICE_OUT_HEADPHONES] = strdup("SLIMBUS_0_RX");
1239 hw_interface_table[SND_DEVICE_OUT_LINE] = strdup("SLIMBUS_0_RX");
1240 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001241 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001242 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001243 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001244 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET] = strdup("SLIMBUS_0_RX");
1245 hw_interface_table[SND_DEVICE_OUT_VOICE_HAC_HANDSET] = strdup("SLIMBUS_0_RX");
1246 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER] = strdup("SLIMBUS_0_RX");
1247 hw_interface_table[SND_DEVICE_OUT_VOICE_HEADPHONES] = strdup("SLIMBUS_0_RX");
yixuanjiang9536e672018-09-06 18:43:36 +08001248 hw_interface_table[SND_DEVICE_OUT_VOICE_HEADSET] = strdup("SLIMBUS_0_RX");
juyuchen66c4ecf2018-08-06 15:39:34 +08001249 hw_interface_table[SND_DEVICE_OUT_VOICE_MUSIC_TX] = strdup("VOICE_PLAYBACK_TX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001250 hw_interface_table[SND_DEVICE_OUT_VOICE_LINE] = strdup("SLIMBUS_0_RX");
1251 hw_interface_table[SND_DEVICE_OUT_HDMI] = strdup("HDMI_RX");
1252 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("SLIMBUS_0_RX-and-HDMI_RX");
1253 hw_interface_table[SND_DEVICE_OUT_BT_SCO] = strdup("SEC_AUX_PCM_RX");
1254 hw_interface_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("SEC_AUX_PCM_RX");
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001255 hw_interface_table[SND_DEVICE_OUT_BT_A2DP] = strdup("SLIMBUS_7_RX");
1256 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] =
1257 strdup("SLIMBUS_0_RX-and-SLIMBUS_7_RX");
Aniket Kumar Lata9723a962018-05-16 17:41:55 -07001258 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP] =
1259 strdup("SLIMBUS_0_RX-and-SLIMBUS_7_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001260 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = strdup("SLIMBUS_0_RX");
1261 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = strdup("SLIMBUS_0_RX");
1262 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = strdup("SLIMBUS_0_RX");
1263 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = strdup("SLIMBUS_0_RX");
David Linee3fe402017-03-13 10:00:42 -07001264 hw_interface_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("USB_AUDIO_RX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001265 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = strdup("USB_AUDIO_RX");
1266 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = strdup("USB_AUDIO_RX");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001267 hw_interface_table[SND_DEVICE_OUT_VOICE_USB_HEADSET] = strdup("USB_AUDIO_RX");
David Linee3fe402017-03-13 10:00:42 -07001268 hw_interface_table[SND_DEVICE_OUT_USB_HEADPHONES] = strdup("USB_AUDIO_RX");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001269 hw_interface_table[SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = strdup("USB_AUDIO_RX");
jasmine cha270b7762018-03-30 15:41:33 +08001270 hw_interface_table[SND_DEVICE_OUT_USB_HEADSET_SPEC] = strdup("USB_AUDIO_RX");
David Linee3fe402017-03-13 10:00:42 -07001271 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 -07001272 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 -07001273 hw_interface_table[SND_DEVICE_OUT_VOICE_TX] = strdup("AFE_PCM_RX");
1274 hw_interface_table[SND_DEVICE_OUT_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
1275 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
jasmine cha52284622018-03-23 17:21:35 +08001276 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = strdup("SLIMBUS_0_RX");
1277 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_BT_SCO] = strdup("SLIMBUS_0_RX-and-SEC_AUX_PCM_RX");
1278 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB] = strdup("SLIMBUS_0_RX-and-SEC_AUX_PCM_RX");
juyuchen5351ea62018-05-16 10:54:37 +08001279 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO] = strdup("QUAT_TDM_RX_0-and-SLIMBUS_7_RX"),
1280 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB] = strdup("QUAT_TDM_RX_0-and-SLIMBUS_7_RX"),
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001281 hw_interface_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1282 hw_interface_table[SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1283 hw_interface_table[SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = strdup("USB_AUDIO_TX");
1284 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1285 hw_interface_table[SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1286 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = strdup("USB_AUDIO_TX");
1287 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = strdup("USB_AUDIO_TX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001288 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001289 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_AEC] = strdup("SLIMBUS_0_TX");
1290 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_NS] = strdup("SLIMBUS_0_TX");
1291 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1292 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC] = strdup("SLIMBUS_0_TX");
1293 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_AEC] = strdup("SLIMBUS_0_TX");
1294 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_NS] = strdup("SLIMBUS_0_TX");
1295 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1296 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001297 hw_interface_table[SND_DEVICE_IN_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001298 hw_interface_table[SND_DEVICE_IN_HEADSET_MIC_AEC] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001299 hw_interface_table[SND_DEVICE_IN_CAMCORDER_MIC] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001300 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC] = strdup("SLIMBUS_0_TX");
1301 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC_NS] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001302 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC_AEC] = strdup("SLIMBUS_0_TX");
1303 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001304 hw_interface_table[SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
1305 hw_interface_table[SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = strdup("SLIMBUS_0_TX");
David Lin93725722017-10-13 14:58:17 -07001306 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_MIC] = strdup("SLIMBUS_0_TX");
1307 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1308 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = strdup("SLIMBUS_0_TX");
1309 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = strdup("SLIMBUS_0_TX");
1310 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001311 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC] = strdup("SLIMBUS_0_TX");
1312 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_AEC] = strdup("SLIMBUS_0_TX");
1313 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_NS] = strdup("SLIMBUS_0_TX");
1314 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1315 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC] = strdup("SLIMBUS_0_TX");
1316 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_AEC] = strdup("SLIMBUS_0_TX");
1317 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_NS] = strdup("SLIMBUS_0_TX");
1318 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001319 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
1320 hw_interface_table[SND_DEVICE_IN_VOICE_DMIC] = strdup("SLIMBUS_0_TX");
1321 hw_interface_table[SND_DEVICE_IN_VOICE_DMIC_TMUS] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001322 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001323 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = strdup("SLIMBUS_0_TX");
1324 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001325 hw_interface_table[SND_DEVICE_IN_VOICE_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001326 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1327 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = strdup("SLIMBUS_0_TX");
1328 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1329 hw_interface_table[SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1330 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("SEC_AUX_PCM_TX");
1331 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("SEC_AUX_PCM_TX");
1332 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("SEC_AUX_PCM_TX");
1333 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("SEC_AUX_PCM_TX");
1334 hw_interface_table[SND_DEVICE_IN_VOICE_RX] = strdup("AFE_PCM_TX");
1335 hw_interface_table[SND_DEVICE_IN_THREE_MIC] = strdup("SLIMBUS_0_TX");
1336 hw_interface_table[SND_DEVICE_IN_QUAD_MIC] = strdup("SLIMBUS_0_TX");
1337 hw_interface_table[SND_DEVICE_IN_HANDSET_TMIC] = strdup("SLIMBUS_0_TX");
1338 hw_interface_table[SND_DEVICE_IN_HANDSET_QMIC] = strdup("SLIMBUS_0_TX");
1339 hw_interface_table[SND_DEVICE_IN_HANDSET_TMIC_AEC] = strdup("SLIMBUS_0_TX");
1340 hw_interface_table[SND_DEVICE_IN_HANDSET_QMIC_AEC] = strdup("SLIMBUS_0_TX");
Eric Laurentc6333382015-09-14 12:43:44 -07001341 my_data->max_mic_count = PLATFORM_DEFAULT_MIC_COUNT;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001342}
1343
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001344void get_cvd_version(char *cvd_version, struct audio_device *adev)
1345{
1346 struct mixer_ctl *ctl;
1347 int count;
1348 int ret = 0;
1349
1350 ctl = mixer_get_ctl_by_name(adev->mixer, CVD_VERSION_MIXER_CTL);
1351 if (!ctl) {
1352 ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__, CVD_VERSION_MIXER_CTL);
1353 goto done;
1354 }
1355 mixer_ctl_update(ctl);
1356
1357 count = mixer_ctl_get_num_values(ctl);
1358 if (count > MAX_CVD_VERSION_STRING_SIZE)
1359 count = MAX_CVD_VERSION_STRING_SIZE - 1;
1360
1361 ret = mixer_ctl_get_array(ctl, cvd_version, count);
1362 if (ret != 0) {
1363 ALOGE("%s: ERROR! mixer_ctl_get_array() failed to get CVD Version", __func__);
1364 goto done;
1365 }
1366
1367done:
1368 return;
1369}
1370
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001371static int platform_acdb_init(void *platform)
1372{
1373 struct platform_data *my_data = (struct platform_data *)platform;
1374 struct audio_device *adev = my_data->adev;
1375
1376 if (!my_data->acdb_init) {
1377 ALOGE("%s: no acdb_init fn provided", __func__);
1378 return -1;
1379 }
1380
1381 if (my_data->acdb_initialized) {
1382 ALOGW("acdb is already initialized");
1383 return 0;
1384 }
1385
Thierry Strudel07f96d12018-09-20 13:31:34 -07001386#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845) || (PLATFORM_SDM710) || (PLATFORM_SM8150)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001387 char *cvd_version = calloc(1, MAX_CVD_VERSION_STRING_SIZE);
1388 if (!cvd_version)
1389 ALOGE("failed to allocate cvd_version");
1390 else {
1391 get_cvd_version(cvd_version, adev);
1392 my_data->acdb_init((char *)my_data->snd_card_name, cvd_version, 0);
1393 free(cvd_version);
1394 }
1395#elif defined (PLATFORM_MSM8084)
1396 my_data->acdb_init((char *)my_data->snd_card_name);
1397#else
1398 my_data->acdb_init();
1399#endif
1400 my_data->acdb_initialized = true;
1401 return 0;
1402}
1403
David Linee3fe402017-03-13 10:00:42 -07001404static void
1405platform_backend_config_init(struct platform_data *pdata)
1406{
1407 int i;
1408
1409 /* initialize backend config */
1410 for (i = 0; i < MAX_CODEC_BACKENDS; i++) {
1411 pdata->current_backend_cfg[i].sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
1412 pdata->current_backend_cfg[i].bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
1413 pdata->current_backend_cfg[i].channels = CODEC_BACKEND_DEFAULT_CHANNELS;
1414
1415 if (i > MAX_RX_CODEC_BACKENDS)
1416 pdata->current_backend_cfg[i].channels = CODEC_BACKEND_DEFAULT_TX_CHANNELS;
1417
1418 pdata->current_backend_cfg[i].bitwidth_mixer_ctl = NULL;
1419 pdata->current_backend_cfg[i].samplerate_mixer_ctl = NULL;
1420 pdata->current_backend_cfg[i].channels_mixer_ctl = NULL;
1421 }
1422
1423 pdata->current_backend_cfg[DEFAULT_CODEC_BACKEND].bitwidth_mixer_ctl =
1424 strdup("SLIM_0_RX Format");
1425 pdata->current_backend_cfg[DEFAULT_CODEC_BACKEND].samplerate_mixer_ctl =
1426 strdup("SLIM_0_RX SampleRate");
1427
1428 pdata->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].bitwidth_mixer_ctl =
1429 strdup("SLIM_0_TX Format");
1430 pdata->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].samplerate_mixer_ctl =
1431 strdup("SLIM_0_TX SampleRate");
1432
1433 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].bitwidth_mixer_ctl =
1434 strdup("USB_AUDIO_TX Format");
1435 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].samplerate_mixer_ctl =
1436 strdup("USB_AUDIO_TX SampleRate");
1437 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].channels_mixer_ctl =
1438 strdup("USB_AUDIO_TX Channels");
1439
Yung Ti Su39a2b8a2018-10-05 15:43:40 +08001440 if (strstr(pdata->snd_card_name, "intcodec")) {
1441 pdata->current_backend_cfg[HEADPHONE_BACKEND].bitwidth_mixer_ctl =
1442 strdup("INT0_MI2S_RX Format");
1443 pdata->current_backend_cfg[HEADPHONE_BACKEND].samplerate_mixer_ctl =
1444 strdup("INT0_MI2S_RX SampleRate");
1445 } else {
1446 pdata->current_backend_cfg[HEADPHONE_BACKEND].bitwidth_mixer_ctl =
1447 strdup("SLIM_6_RX Format");
1448 pdata->current_backend_cfg[HEADPHONE_BACKEND].samplerate_mixer_ctl =
1449 strdup("SLIM_6_RX SampleRate");
1450 }
David Linee3fe402017-03-13 10:00:42 -07001451
1452 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].bitwidth_mixer_ctl =
1453 strdup("USB_AUDIO_RX Format");
1454 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].samplerate_mixer_ctl =
1455 strdup("USB_AUDIO_RX SampleRate");
1456
1457 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].channels = 1;
1458 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].channels_mixer_ctl =
1459 strdup("USB_AUDIO_RX Channels");
1460}
1461
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001462static int
1463platform_backend_app_type_cfg_init(struct platform_data *pdata,
1464 struct mixer *mixer)
1465{
1466 size_t app_type_cfg[128] = {0};
1467 int length, num_app_types = 0;
1468 struct mixer_ctl *ctl = NULL;
1469
1470 const char *mixer_ctl_name = "App Type Config";
1471 ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name);
1472 if (!ctl) {
1473 ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name);
1474 return -1;
1475 }
1476
1477 length = 1; // reserve index 0 for number of app types
1478
1479 struct listnode *node;
1480 struct app_type_entry *entry;
1481 list_for_each(node, &app_type_entry_list) {
1482 entry = node_to_item(node, struct app_type_entry, node);
1483 app_type_cfg[length++] = entry->app_type;
1484 app_type_cfg[length++] = entry->max_rate;
1485 app_type_cfg[length++] = entry->bit_width;
1486 ALOGI("%s add entry %d %d", __func__, entry->app_type, entry->bit_width);
1487 num_app_types += 1;
1488 }
1489
1490 // default for capture
1491 int t;
1492 platform_get_default_app_type_v2(pdata,
1493 PCM_CAPTURE,
1494 &t);
1495 app_type_cfg[length++] = t;
1496 app_type_cfg[length++] = 48000;
1497 app_type_cfg[length++] = 16;
1498 num_app_types += 1;
1499
1500 if (num_app_types) {
1501 app_type_cfg[0] = num_app_types;
1502 if (mixer_ctl_set_array(ctl, app_type_cfg, length) < 0) {
1503 ALOGE("Failed to set app type cfg");
1504 }
1505 }
1506 return 0;
1507}
1508
Xu Han1638fd12018-04-20 12:42:23 -07001509static void configure_flicker_sensor_input(struct mixer *mixer)
1510{
1511 struct mixer_ctl *ctl;
1512 const char* ctl1 = "AIF3_CAP Mixer SLIM TX2";
1513 int setting1 = 1;
1514 const char* ctl2 = "CDC_IF TX2 MUX";
1515 const char* setting2 = "DEC2";
1516 const char* ctl3 = "SLIM_1_TX Channels";
1517 const char* setting3 = "One";
1518 const char* ctl4 = "ADC MUX2";
1519 const char* setting4 = "AMIC";
1520 const char* ctl5 = "AMIC MUX2";
1521 const char* setting5 = "ADC1";
1522 const char* ctl6 = "DEC2 Volume";
1523 int setting6 = 84;
Xu Han07e07402018-05-15 14:19:25 -07001524 const char* ctl7 = "MultiMedia9 Mixer SLIM_1_TX";
Xu Han1638fd12018-04-20 12:42:23 -07001525 int setting7 = 1;
1526 const char* ctl8 = "SLIM_1_TX SampleRate";
1527 const char* setting8 = "KHZ_8";
1528
1529 ctl = mixer_get_ctl_by_name(mixer, ctl1);
1530 mixer_ctl_set_value(ctl, 0, setting1);
1531 ctl = mixer_get_ctl_by_name(mixer, ctl2);
1532 mixer_ctl_set_enum_by_string(ctl, setting2);
1533 ctl = mixer_get_ctl_by_name(mixer, ctl3);
1534 mixer_ctl_set_enum_by_string(ctl, setting3);
1535 ctl = mixer_get_ctl_by_name(mixer, ctl4);
1536 mixer_ctl_set_enum_by_string(ctl, setting4);
1537 ctl = mixer_get_ctl_by_name(mixer, ctl5);
1538 mixer_ctl_set_enum_by_string(ctl, setting5);
1539 ctl = mixer_get_ctl_by_name(mixer, ctl6);
1540 mixer_ctl_set_value(ctl, 0, setting6);
1541 ctl = mixer_get_ctl_by_name(mixer, ctl7);
1542 mixer_ctl_set_value(ctl, 0, setting7);
1543 ctl = mixer_get_ctl_by_name(mixer, ctl8);
1544 mixer_ctl_set_enum_by_string(ctl, setting8);
1545}
1546
Eric Laurentb23d5282013-05-14 15:27:20 -07001547void *platform_init(struct audio_device *adev)
1548{
1549 char value[PROPERTY_VALUE_MAX];
vivek mehta60ea4152016-02-18 17:10:26 -08001550 struct platform_data *my_data = NULL;
1551 int retry_num = 0, snd_card_num = 0, key = 0, ret = 0;
1552 bool dual_mic_config = false, use_default_mixer_path = true;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001553 const char *snd_card_name;
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001554 char *cvd_version = NULL;
vivek mehta60ea4152016-02-18 17:10:26 -08001555 char *snd_internal_name = NULL;
1556 char *tmp = NULL;
1557 char mixer_xml_file[MIXER_PATH_MAX_LENGTH]= {0};
vivek mehtade4849c2016-03-03 17:23:38 -08001558 char platform_info_file[MIXER_PATH_MAX_LENGTH]= {0};
1559 struct snd_card_split *snd_split_handle = NULL;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001560 my_data = calloc(1, sizeof(struct platform_data));
1561
1562 my_data->adev = adev;
1563
keunhui.park2f7306a2015-07-16 16:48:06 +09001564 list_init(&operator_info_list);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001565 list_init(&app_type_entry_list);
keunhui.park2f7306a2015-07-16 16:48:06 +09001566
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001567 set_platform_defaults(my_data);
1568
vivek mehta0fb11312017-05-15 19:35:32 -07001569 // audio_extn_utils_get_snd_card_num does
1570 // - open mixer and get snd card name
1571 // - parse platform info xml file and check for valid snd card name
1572 // - on failure loop through all the active snd card
sangwoo1b9f4b32013-06-21 18:22:55 -07001573
vivek mehta0fb11312017-05-15 19:35:32 -07001574 snd_card_num = audio_extn_utils_get_snd_card_num();
1575 if (-1 == snd_card_num) {
1576 ALOGE("%s: invalid sound card number (-1), bailing out ", __func__);
1577 goto init_failed;
sangwoo1b9f4b32013-06-21 18:22:55 -07001578 }
1579
vivek mehta0fb11312017-05-15 19:35:32 -07001580 adev->mixer = mixer_open(snd_card_num);
1581 snd_card_name = mixer_get_name(adev->mixer);
1582 my_data->hw_info = hw_info_init(snd_card_name);
1583
1584 audio_extn_set_snd_card_split(snd_card_name);
1585 snd_split_handle = audio_extn_get_snd_card_split();
1586
1587 /* Get the codec internal name from the sound card and/or form factor
1588 * name and form the mixer paths and platfor info file name dynamically.
1589 * This is generic way of picking any codec and forma factor name based
1590 * mixer and platform info files in future with no code change.
1591
1592 * current code extends and looks for any of the exteneded mixer path and
1593 * platform info file present based on codec and form factor.
1594
1595 * order of picking appropriate file is
1596 * <i> mixer_paths_<codec_name>_<form_factor>.xml, if file not present
1597 * <ii> mixer_paths_<codec_name>.xml, if file not present
1598 * <iii> mixer_paths.xml
1599
1600 * same order is followed for audio_platform_info.xml as well
1601 */
1602
1603 // need to carryforward old file name
1604 if (!strncmp(snd_card_name, TOMTOM_8226_SND_CARD_NAME,
1605 min(strlen(TOMTOM_8226_SND_CARD_NAME), strlen(snd_card_name)))) {
1606 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1607 MIXER_XML_BASE_STRING, TOMTOM_MIXER_FILE_SUFFIX );
1608 } else {
1609
1610 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s_%s.xml",
1611 MIXER_XML_BASE_STRING, snd_split_handle->snd_card,
1612 snd_split_handle->form_factor);
1613 if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) {
1614 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1615 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1616 MIXER_XML_BASE_STRING, snd_split_handle->snd_card);
1617
1618 if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) {
1619 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1620 strlcpy(mixer_xml_file, MIXER_XML_DEFAULT_PATH, MIXER_PATH_MAX_LENGTH);
1621 audio_extn_utils_resolve_config_file(mixer_xml_file);
1622 }
1623 }
1624 }
1625
1626 audio_extn_utils_get_platform_info(snd_card_name, platform_info_file);
1627
jiabin8962a4d2018-03-19 18:21:24 -07001628 my_data->declared_mic_count = 0;
vivek mehta0fb11312017-05-15 19:35:32 -07001629 /* Initialize platform specific ids and/or backends*/
1630 platform_info_init(platform_info_file, my_data);
1631
1632 ALOGD("%s: Loading mixer file: %s", __func__, mixer_xml_file);
1633 adev->audio_route = audio_route_init(snd_card_num, mixer_xml_file);
1634
1635 if (!adev->audio_route) {
1636 ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
1637 mixer_close(adev->mixer);
1638 adev->mixer = NULL;
1639 hw_info_deinit(my_data->hw_info);
1640 my_data->hw_info = NULL;
1641 goto init_failed;
1642 }
1643 adev->snd_card = snd_card_num;
1644 ALOGD("%s: Opened sound card:%d", __func__, snd_card_num);
1645
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09001646 //set max volume step for voice call
1647 property_get("ro.config.vc_call_vol_steps", value, TOSTRING(MAX_VOL_INDEX));
1648 my_data->max_vol_index = atoi(value);
1649
vivek mehta65ad12d2015-08-13 18:32:48 -07001650 property_get("persist.audio.dualmic.config",value,"");
1651 if (!strcmp("endfire", value)) {
1652 dual_mic_config = true;
1653 }
1654
John Muir9e59a962018-01-10 13:30:00 -08001655 my_data->source_mic_type = 0;
Prashant Malanic92c5962015-08-11 15:10:18 -07001656
Eric Laurentb23d5282013-05-14 15:27:20 -07001657 my_data->fluence_in_spkr_mode = false;
1658 my_data->fluence_in_voice_call = false;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001659 my_data->fluence_in_voice_comm = false;
Eric Laurentb23d5282013-05-14 15:27:20 -07001660 my_data->fluence_in_voice_rec = false;
1661
vivek mehta65ad12d2015-08-13 18:32:48 -07001662 property_get("ro.qc.sdk.audio.fluencetype", value, "none");
Prashant Malanic92c5962015-08-11 15:10:18 -07001663 if (!strcmp("fluencepro", value)) {
1664 my_data->fluence_type = FLUENCE_PRO_ENABLE;
vivek mehta65ad12d2015-08-13 18:32:48 -07001665 } else if (!strcmp("fluence", value) || (dual_mic_config)) {
Prashant Malanic92c5962015-08-11 15:10:18 -07001666 my_data->fluence_type = FLUENCE_ENABLE;
1667 } else if (!strcmp("none", value)) {
1668 my_data->fluence_type = FLUENCE_DISABLE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001669 }
1670
Prashant Malanic92c5962015-08-11 15:10:18 -07001671 if (my_data->fluence_type != FLUENCE_DISABLE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001672 property_get("persist.audio.fluence.voicecall",value,"");
1673 if (!strcmp("true", value)) {
1674 my_data->fluence_in_voice_call = true;
1675 }
1676
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001677 property_get("persist.audio.fluence.voicecomm",value,"");
1678 if (!strcmp("true", value)) {
1679 my_data->fluence_in_voice_comm = true;
1680 }
1681
Eric Laurentb23d5282013-05-14 15:27:20 -07001682 property_get("persist.audio.fluence.voicerec",value,"");
1683 if (!strcmp("true", value)) {
1684 my_data->fluence_in_voice_rec = true;
1685 }
1686
1687 property_get("persist.audio.fluence.speaker",value,"");
1688 if (!strcmp("true", value)) {
1689 my_data->fluence_in_spkr_mode = true;
1690 }
1691 }
1692
Prashant Malanic92c5962015-08-11 15:10:18 -07001693 // support max to mono, example if max count is 3, usecase supports Three, dual and mono mic
1694 switch (my_data->max_mic_count) {
1695 case 4:
1696 my_data->source_mic_type |= SOURCE_QUAD_MIC;
1697 case 3:
1698 my_data->source_mic_type |= SOURCE_THREE_MIC;
1699 case 2:
1700 my_data->source_mic_type |= SOURCE_DUAL_MIC;
1701 case 1:
1702 my_data->source_mic_type |= SOURCE_MONO_MIC;
1703 break;
1704 default:
1705 ALOGE("%s: max_mic_count (%d), is not supported, setting to default",
1706 __func__, my_data->max_mic_count);
1707 my_data->source_mic_type = SOURCE_MONO_MIC|SOURCE_DUAL_MIC;
1708 break;
1709 }
1710
1711 ALOGV("%s: Fluence_Type(%d) max_mic_count(%d) mic_type(0x%x) fluence_in_voice_call(%d)"
1712 " fluence_in_voice_comm(%d) fluence_in_voice_rec(%d) fluence_in_spkr_mode(%d) ",
1713 __func__, my_data->fluence_type, my_data->max_mic_count, my_data->source_mic_type,
1714 my_data->fluence_in_voice_call, my_data->fluence_in_voice_comm,
1715 my_data->fluence_in_voice_rec, my_data->fluence_in_spkr_mode);
1716
Eric Laurentb23d5282013-05-14 15:27:20 -07001717 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
1718 if (my_data->acdb_handle == NULL) {
1719 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
1720 } else {
1721 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
1722 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
1723 "acdb_loader_deallocate_ACDB");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001724 if (!my_data->acdb_deallocate)
1725 ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s",
1726 __func__, LIB_ACDB_LOADER);
1727
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001728 my_data->acdb_send_audio_cal_v3 = (acdb_send_audio_cal_v3_t)dlsym(my_data->acdb_handle,
1729 "acdb_loader_send_audio_cal_v3");
1730 if (!my_data->acdb_send_audio_cal_v3)
1731 ALOGE("%s: Could not find the symbol acdb_send_audio_cal_v3 from %s",
1732 __func__, LIB_ACDB_LOADER);
1733
Eric Laurentb23d5282013-05-14 15:27:20 -07001734 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
1735 "acdb_loader_send_audio_cal");
1736 if (!my_data->acdb_send_audio_cal)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001737 ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s",
Eric Laurentb23d5282013-05-14 15:27:20 -07001738 __func__, LIB_ACDB_LOADER);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001739
Eric Laurentb23d5282013-05-14 15:27:20 -07001740 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
1741 "acdb_loader_send_voice_cal");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001742 if (!my_data->acdb_send_voice_cal)
1743 ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s",
1744 __func__, LIB_ACDB_LOADER);
1745
1746 my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle,
1747 "acdb_loader_reload_vocvoltable");
1748 if (!my_data->acdb_reload_vocvoltable)
1749 ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s",
1750 __func__, LIB_ACDB_LOADER);
vivek mehta1a9b7c02015-06-25 11:49:38 -07001751
1752 my_data->acdb_send_gain_dep_cal = (acdb_send_gain_dep_cal_t)dlsym(my_data->acdb_handle,
1753 "acdb_loader_send_gain_dep_cal");
1754 if (!my_data->acdb_send_gain_dep_cal)
1755 ALOGV("%s: Could not find the symbol acdb_loader_send_gain_dep_cal from %s",
1756 __func__, LIB_ACDB_LOADER);
1757
Xu Han1638fd12018-04-20 12:42:23 -07001758#if defined (FLICKER_SENSOR_INPUT)
1759 configure_flicker_sensor_input(adev->mixer);
1760#endif
1761
Thierry Strudel07f96d12018-09-20 13:31:34 -07001762#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845) || (PLATFORM_SDM710) || (PLATFORM_SM8150)
vivek mehta0fb11312017-05-15 19:35:32 -07001763 acdb_init_v2_cvd_t acdb_init_local;
1764 acdb_init_local = (acdb_init_v2_cvd_t)dlsym(my_data->acdb_handle,
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001765 "acdb_loader_init_v2");
vivek mehta0fb11312017-05-15 19:35:32 -07001766 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001767 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1768 dlerror());
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001769
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001770#elif defined (PLATFORM_MSM8084)
vivek mehta0fb11312017-05-15 19:35:32 -07001771 acdb_init_v2_t acdb_init_local;
1772 acdb_init_local = (acdb_init_v2_t)dlsym(my_data->acdb_handle,
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001773 "acdb_loader_init_v2");
vivek mehta0fb11312017-05-15 19:35:32 -07001774 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001775 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1776 dlerror());
1777
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001778#else
vivek mehta0fb11312017-05-15 19:35:32 -07001779 acdb_init_t acdb_init_local;
1780 acdb_init_local = (acdb_init_t)dlsym(my_data->acdb_handle,
Eric Laurentb23d5282013-05-14 15:27:20 -07001781 "acdb_loader_init_ACDB");
vivek mehta0fb11312017-05-15 19:35:32 -07001782 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001783 ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__,
1784 dlerror());
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001785#endif
vivek mehta0fb11312017-05-15 19:35:32 -07001786 my_data->acdb_init = acdb_init_local;
Eric Laurentb23d5282013-05-14 15:27:20 -07001787
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001788 my_data->acdb_send_custom_top = (acdb_send_custom_top_t)
1789 dlsym(my_data->acdb_handle,
1790 "acdb_loader_send_common_custom_topology");
1791
1792 if (!my_data->acdb_send_custom_top)
1793 ALOGE("%s: Could not find the symbol acdb_get_default_app_type from %s",
1794 __func__, LIB_ACDB_LOADER);
1795
jasmine chac89321b2018-04-10 21:37:01 +08001796 my_data->acdb_set_audio_cal = (acdb_set_audio_cal_t)dlsym(my_data->acdb_handle,
1797 "acdb_loader_set_audio_cal_v2");
1798 if (!my_data->acdb_set_audio_cal)
1799 ALOGE("%s: Could not find the symbol acdb_set_audio_cal_v2 from %s",
1800 __func__, LIB_ACDB_LOADER);
1801
vivek mehta0fb11312017-05-15 19:35:32 -07001802 int result = acdb_init(adev->snd_card);
1803 if (!result) {
1804 my_data->acdb_initialized = true;
1805 ALOGD("ACDB initialized");
1806 } else {
1807 my_data->acdb_initialized = false;
1808 ALOGD("ACDB initialization failed");
1809 }
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001810 }
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001811
David Linee3fe402017-03-13 10:00:42 -07001812 /* init usb */
1813 audio_extn_usb_init(adev);
1814
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001815 /* init a2dp */
1816 audio_extn_a2dp_init(adev);
1817
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001818 audio_extn_spkr_prot_init(adev);
Haynes Mathew George98c95622014-06-20 19:14:25 -07001819
Ravi Kumar Alamanda76315572015-04-23 13:13:56 -07001820 audio_extn_hwdep_cal_send(adev->snd_card, my_data->acdb_handle);
1821
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001822 /* load csd client */
1823 platform_csd_init(my_data);
1824
David Linee3fe402017-03-13 10:00:42 -07001825 platform_backend_config_init(my_data);
1826
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001827 init_be_dai_name_table(adev);
1828
1829 if (platform_supports_app_type_cfg())
1830 platform_backend_app_type_cfg_init(my_data, adev->mixer);
1831
Eric Laurentb23d5282013-05-14 15:27:20 -07001832 return my_data;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001833
1834init_failed:
1835 if (my_data)
1836 free(my_data);
1837 return NULL;
Eric Laurentb23d5282013-05-14 15:27:20 -07001838}
1839
1840void platform_deinit(void *platform)
1841{
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001842 int32_t dev;
keunhui.park2f7306a2015-07-16 16:48:06 +09001843 struct operator_info *info_item;
1844 struct operator_specific_device *device_item;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001845 struct app_type_entry *ap;
keunhui.park2f7306a2015-07-16 16:48:06 +09001846 struct listnode *node;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001847
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001848 struct platform_data *my_data = (struct platform_data *)platform;
1849 close_csd_client(my_data->csd);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001850
David Lin41b4fe42018-07-08 16:14:24 -07001851 audio_extn_spkr_prot_deinit(my_data->adev);
1852
vivek mehtade4849c2016-03-03 17:23:38 -08001853 hw_info_deinit(my_data->hw_info);
1854
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001855 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1856 if (backend_tag_table[dev])
1857 free(backend_tag_table[dev]);
1858 if (hw_interface_table[dev])
1859 free(hw_interface_table[dev]);
keunhui.park2f7306a2015-07-16 16:48:06 +09001860 if (operator_specific_device_table[dev]) {
1861 while (!list_empty(operator_specific_device_table[dev])) {
1862 node = list_head(operator_specific_device_table[dev]);
1863 list_remove(node);
1864 device_item = node_to_item(node, struct operator_specific_device, list);
1865 free(device_item->operator);
1866 free(device_item->mixer_path);
1867 free(device_item);
1868 }
1869 free(operator_specific_device_table[dev]);
1870 }
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001871 }
1872
1873 if (my_data->snd_card_name)
1874 free(my_data->snd_card_name);
1875
keunhui.park2f7306a2015-07-16 16:48:06 +09001876 while (!list_empty(&operator_info_list)) {
1877 node = list_head(&operator_info_list);
1878 list_remove(node);
1879 info_item = node_to_item(node, struct operator_info, list);
1880 free(info_item->name);
1881 free(info_item->mccmnc);
1882 free(info_item);
1883 }
1884
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001885 while (!list_empty(&app_type_entry_list)) {
1886 node = list_head(&app_type_entry_list);
1887 list_remove(node);
1888 ap = node_to_item(node, struct app_type_entry, node);
vivek mehtaa68fea62017-06-08 19:04:02 -07001889 if (ap->mode) free(ap->mode);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001890 free(ap);
1891 }
1892
Kevin Rocarde35d4af2017-05-02 16:55:28 -07001893 mixer_close(my_data->adev->mixer);
Eric Laurentb23d5282013-05-14 15:27:20 -07001894 free(platform);
David Linee3fe402017-03-13 10:00:42 -07001895
1896 /* deinit usb */
1897 audio_extn_usb_deinit();
Eric Laurentb23d5282013-05-14 15:27:20 -07001898}
1899
1900const char *platform_get_snd_device_name(snd_device_t snd_device)
1901{
keunhui.park2f7306a2015-07-16 16:48:06 +09001902 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1903 if (operator_specific_device_table[snd_device] != NULL) {
1904 return get_operator_specific_device_mixer_path(snd_device);
1905 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001906 return device_table[snd_device];
keunhui.park2f7306a2015-07-16 16:48:06 +09001907 } else
Ravi Kumar Alamanda64026462014-09-15 00:08:58 -07001908 return "none";
Eric Laurentb23d5282013-05-14 15:27:20 -07001909}
1910
vivek mehtade4849c2016-03-03 17:23:38 -08001911int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
1912 char *device_name)
1913{
1914 struct platform_data *my_data = (struct platform_data *)platform;
1915
David Benjamin1565f992016-09-21 12:10:34 -04001916 if (platform == NULL) {
vivek mehtade4849c2016-03-03 17:23:38 -08001917 ALOGW("%s: something wrong, use legacy get_snd_device name", __func__);
David Benjamin1565f992016-09-21 12:10:34 -04001918 strlcpy(device_name, platform_get_snd_device_name(snd_device),
1919 DEVICE_NAME_MAX_SIZE);
vivek mehtade4849c2016-03-03 17:23:38 -08001920 } else if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1921 if (operator_specific_device_table[snd_device] != NULL) {
1922 strlcpy(device_name, get_operator_specific_device_mixer_path(snd_device),
1923 DEVICE_NAME_MAX_SIZE);
1924 } else {
1925 strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE);
1926 }
1927 hw_info_append_hw_type(my_data->hw_info, snd_device, device_name);
1928 } else {
1929 strlcpy(device_name, "none", DEVICE_NAME_MAX_SIZE);
Aniket Kumar Lataa158e862018-05-11 17:28:40 -07001930 return -EINVAL;
vivek mehtade4849c2016-03-03 17:23:38 -08001931 }
1932
1933 return 0;
1934}
1935
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001936void platform_add_backend_name(void *platform, char *mixer_path,
1937 snd_device_t snd_device)
Eric Laurentb23d5282013-05-14 15:27:20 -07001938{
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001939 struct platform_data *my_data = (struct platform_data *)platform;
1940
Haynes Mathew George98c95622014-06-20 19:14:25 -07001941 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1942 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1943 return;
Ravi Kumar Alamanda1de6e5a2014-06-19 21:55:39 -05001944 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001945
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001946 const char * suffix = backend_tag_table[snd_device];
Haynes Mathew George98c95622014-06-20 19:14:25 -07001947
1948 if (suffix != NULL) {
1949 strcat(mixer_path, " ");
1950 strcat(mixer_path, suffix);
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001951 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001952}
1953
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001954bool platform_check_backends_match(snd_device_t snd_device1, snd_device_t snd_device2)
1955{
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001956 ALOGV("%s: snd_device1 = %s, snd_device2 = %s", __func__,
1957 platform_get_snd_device_name(snd_device1),
1958 platform_get_snd_device_name(snd_device2));
1959
1960 if ((snd_device1 < SND_DEVICE_MIN) || (snd_device1 >= SND_DEVICE_MAX)) {
1961 ALOGE("%s: Invalid snd_device = %s", __func__,
1962 platform_get_snd_device_name(snd_device1));
1963 return false;
1964 }
1965 if ((snd_device2 < SND_DEVICE_MIN) || (snd_device2 >= SND_DEVICE_MAX)) {
1966 ALOGE("%s: Invalid snd_device = %s", __func__,
1967 platform_get_snd_device_name(snd_device2));
1968 return false;
1969 }
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07001970
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001971 const char * be_itf1 = hw_interface_table[snd_device1];
1972 const char * be_itf2 = hw_interface_table[snd_device2];
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07001973 /*
1974 hw_interface_table has overrides for a snd_device.
1975 if there is no entry for a device, assume DEFAULT_RX_BACKEND
1976 */
1977 if (be_itf1 == NULL) {
1978 be_itf1 = DEFAULT_RX_BACKEND;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001979 }
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07001980 if (be_itf2 == NULL) {
1981 be_itf2 = DEFAULT_RX_BACKEND;
1982 }
1983 ALOGV("%s: be_itf1 = %s, be_itf2 = %s", __func__, be_itf1, be_itf2);
1984 /*
1985 this takes care of finding a device within a combo device pair as well
1986 */
1987 return strstr(be_itf1, be_itf2) != NULL || strstr(be_itf2, be_itf1) != NULL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001988}
1989
Eric Laurentb23d5282013-05-14 15:27:20 -07001990int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
1991{
1992 int device_id;
1993 if (device_type == PCM_PLAYBACK)
1994 device_id = pcm_device_table[usecase][0];
1995 else
1996 device_id = pcm_device_table[usecase][1];
1997 return device_id;
1998}
1999
Haynes Mathew George98c95622014-06-20 19:14:25 -07002000static int find_index(const struct name_to_index * table, int32_t len,
2001 const char * name)
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002002{
2003 int ret = 0;
Haynes Mathew George98c95622014-06-20 19:14:25 -07002004 int32_t i;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002005
Haynes Mathew George98c95622014-06-20 19:14:25 -07002006 if (table == NULL) {
2007 ALOGE("%s: table is NULL", __func__);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002008 ret = -ENODEV;
2009 goto done;
2010 }
2011
Haynes Mathew George98c95622014-06-20 19:14:25 -07002012 if (name == NULL) {
2013 ALOGE("null key");
2014 ret = -ENODEV;
2015 goto done;
2016 }
2017
2018 for (i=0; i < len; i++) {
2019 if (!strcmp(table[i].name, name)) {
2020 ret = table[i].index;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002021 goto done;
2022 }
2023 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07002024 ALOGE("%s: Could not find index for name = %s",
2025 __func__, name);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002026 ret = -ENODEV;
2027done:
2028 return ret;
2029}
2030
Haynes Mathew George98c95622014-06-20 19:14:25 -07002031int platform_get_snd_device_index(char *device_name)
2032{
2033 return find_index(snd_device_name_index, SND_DEVICE_MAX, device_name);
2034}
2035
2036int platform_get_usecase_index(const char *usecase_name)
2037{
2038 return find_index(usecase_name_index, AUDIO_USECASE_MAX, usecase_name);
2039}
2040
keunhui.park2f7306a2015-07-16 16:48:06 +09002041void platform_add_operator_specific_device(snd_device_t snd_device,
2042 const char *operator,
2043 const char *mixer_path,
2044 unsigned int acdb_id)
2045{
2046 struct operator_specific_device *device;
2047
2048 if (operator_specific_device_table[snd_device] == NULL) {
2049 operator_specific_device_table[snd_device] =
2050 (struct listnode *)calloc(1, sizeof(struct listnode));
2051 list_init(operator_specific_device_table[snd_device]);
2052 }
2053
2054 device = (struct operator_specific_device *)calloc(1, sizeof(struct operator_specific_device));
2055
2056 device->operator = strdup(operator);
2057 device->mixer_path = strdup(mixer_path);
2058 device->acdb_id = acdb_id;
2059
2060 list_add_tail(operator_specific_device_table[snd_device], &device->list);
2061
Eric Laurent2bafff12016-03-17 12:17:23 -07002062 ALOGD("%s: device[%s] -> operator[%s] mixer_path[%s] acdb_id[%d]", __func__,
keunhui.park2f7306a2015-07-16 16:48:06 +09002063 platform_get_snd_device_name(snd_device), operator, mixer_path, acdb_id);
2064
2065}
2066
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002067int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
2068{
2069 int ret = 0;
2070
2071 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
2072 ALOGE("%s: Invalid snd_device = %d",
2073 __func__, snd_device);
2074 ret = -EINVAL;
2075 goto done;
2076 }
2077
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002078 ALOGV("%s: acdb_device_table[%s]: old = %d new = %d", __func__,
2079 platform_get_snd_device_name(snd_device), acdb_device_table[snd_device], acdb_id);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002080 acdb_device_table[snd_device] = acdb_id;
2081done:
2082 return ret;
2083}
2084
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07002085int platform_get_snd_device_acdb_id(snd_device_t snd_device)
2086{
2087 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
2088 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
2089 return -EINVAL;
2090 }
keunhui.park2f7306a2015-07-16 16:48:06 +09002091
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002092 /*
2093 * If speaker protection is enabled, function returns supported
2094 * sound device for speaker. Else same sound device is returned.
2095 */
2096 snd_device = audio_extn_get_spkr_prot_snd_device(snd_device);
2097
keunhui.park2f7306a2015-07-16 16:48:06 +09002098 if (operator_specific_device_table[snd_device] != NULL)
2099 return get_operator_specific_device_acdb_id(snd_device);
2100 else
2101 return acdb_device_table[snd_device];
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07002102}
2103
David Linee3fe402017-03-13 10:00:42 -07002104static int platform_get_backend_index(snd_device_t snd_device)
2105{
2106 int32_t port = DEFAULT_CODEC_BACKEND;
2107
2108 if (snd_device >= SND_DEVICE_OUT_BEGIN && snd_device < SND_DEVICE_OUT_END) {
2109 if (backend_tag_table[snd_device] != NULL) {
2110 if (strncmp(backend_tag_table[snd_device], "headphones",
2111 sizeof("headphones")) == 0)
2112 port = HEADPHONE_BACKEND;
2113 else if (strcmp(backend_tag_table[snd_device], "hdmi") == 0)
2114 port = HDMI_RX_BACKEND;
2115 else if ((strcmp(backend_tag_table[snd_device], "usb-headphones") == 0) ||
2116 (strcmp(backend_tag_table[snd_device], "usb-headset") == 0))
2117 port = USB_AUDIO_RX_BACKEND;
2118 }
2119 } else if (snd_device >= SND_DEVICE_IN_BEGIN && snd_device < SND_DEVICE_IN_END) {
2120 port = DEFAULT_CODEC_TX_BACKEND;
2121 if (backend_tag_table[snd_device] != NULL) {
2122 if (strcmp(backend_tag_table[snd_device], "usb-headset-mic") == 0)
2123 port = USB_AUDIO_TX_BACKEND;
2124 else if (strstr(backend_tag_table[snd_device], "bt-sco") != NULL)
2125 port = BT_SCO_TX_BACKEND;
2126 }
2127 } else {
2128 ALOGW("%s:napb: Invalid device - %d ", __func__, snd_device);
2129 }
2130
2131 ALOGV("%s:napb: backend port - %d device - %d ", __func__, port, snd_device);
2132
2133 return port;
2134}
2135
Eric Laurentb23d5282013-05-14 15:27:20 -07002136int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
2137{
2138 struct platform_data *my_data = (struct platform_data *)platform;
2139 int acdb_dev_id, acdb_dev_type;
2140
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002141 if (platform_supports_app_type_cfg()) // use v2 instead
2142 return -ENOSYS;
2143
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002144 acdb_dev_id = platform_get_snd_device_acdb_id(snd_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07002145 if (acdb_dev_id < 0) {
2146 ALOGE("%s: Could not find acdb id for device(%d)",
2147 __func__, snd_device);
2148 return -EINVAL;
2149 }
2150 if (my_data->acdb_send_audio_cal) {
Joe Onorato188b6222016-03-01 11:02:27 -08002151 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Eric Laurentb23d5282013-05-14 15:27:20 -07002152 __func__, snd_device, acdb_dev_id);
2153 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
2154 snd_device < SND_DEVICE_OUT_END)
2155 acdb_dev_type = ACDB_DEV_TYPE_OUT;
2156 else
2157 acdb_dev_type = ACDB_DEV_TYPE_IN;
2158 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
2159 }
2160 return 0;
2161}
2162
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002163int platform_send_audio_calibration_v2(void *platform, struct audio_usecase *usecase,
2164 int app_type, int sample_rate)
2165{
2166 struct platform_data *my_data = (struct platform_data *)platform;
2167 int acdb_dev_id, acdb_dev_type;
vivek mehta7e573672018-03-13 17:41:41 -07002168 int snd_device = usecase->out_snd_device;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002169 int new_snd_device[SND_DEVICE_OUT_END] = {0};
2170 int i, num_devices = 1;
2171
2172 if (!platform_supports_app_type_cfg()) // use v1 instead
2173 return -ENOSYS;
2174
vivek mehta7e573672018-03-13 17:41:41 -07002175 if ((usecase->type == PCM_HFP_CALL) || (usecase->type == PCM_CAPTURE))
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002176 snd_device = usecase->in_snd_device;
2177
2178 // skipped over get_spkr_prot_device
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002179 acdb_dev_id = platform_get_snd_device_acdb_id(snd_device);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002180 if (acdb_dev_id < 0) {
2181 ALOGE("%s: Could not find acdb id for device(%d)",
2182 __func__, snd_device);
2183 return -EINVAL;
2184 }
2185
2186 if (platform_can_split_snd_device(snd_device,
2187 &num_devices, new_snd_device) < 0) {
2188 new_snd_device[0] = snd_device;
2189 }
2190
2191 for (i = 0; i < num_devices; i++) {
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002192 acdb_dev_id = platform_get_snd_device_acdb_id(new_snd_device[i]);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002193 if (acdb_dev_id < 0) {
2194 ALOGE("%s: Could not find acdb id for device(%d)",
2195 __func__, new_snd_device[i]);
2196 return -EINVAL;
2197 }
2198 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
2199 __func__, new_snd_device[i], acdb_dev_id);
2200 if (new_snd_device[i] >= SND_DEVICE_OUT_BEGIN &&
2201 new_snd_device[i] < SND_DEVICE_OUT_END)
2202 acdb_dev_type = ACDB_DEV_TYPE_OUT;
2203 else
2204 acdb_dev_type = ACDB_DEV_TYPE_IN;
2205
2206 if (my_data->acdb_send_audio_cal_v3) {
2207 my_data->acdb_send_audio_cal_v3(acdb_dev_id, acdb_dev_type,
2208 app_type, sample_rate, i);
2209 } else if (my_data->acdb_send_audio_cal) {
2210 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type); // this version differs from internal
2211 }
2212 }
2213
2214 return 0;
2215}
2216
2217
Eric Laurentb23d5282013-05-14 15:27:20 -07002218int platform_switch_voice_call_device_pre(void *platform)
2219{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002220 struct platform_data *my_data = (struct platform_data *)platform;
2221 int ret = 0;
2222
2223 if (my_data->csd != NULL &&
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002224 voice_is_in_call(my_data->adev)) {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002225 /* This must be called before disabling mixer controls on APQ side */
2226 ret = my_data->csd->disable_device();
2227 if (ret < 0) {
2228 ALOGE("%s: csd_client_disable_device, failed, error %d",
2229 __func__, ret);
2230 }
2231 }
2232 return ret;
2233}
2234
2235int platform_switch_voice_call_enable_device_config(void *platform,
2236 snd_device_t out_snd_device,
2237 snd_device_t in_snd_device)
2238{
2239 struct platform_data *my_data = (struct platform_data *)platform;
2240 int acdb_rx_id, acdb_tx_id;
2241 int ret = 0;
2242
2243 if (my_data->csd == NULL)
2244 return ret;
2245
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002246 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
keunhui.park2f7306a2015-07-16 16:48:06 +09002247 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002248
2249 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
2250 ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
2251 if (ret < 0) {
2252 ALOGE("%s: csd_enable_device_config, failed, error %d",
2253 __func__, ret);
2254 }
2255 } else {
2256 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2257 acdb_rx_id, acdb_tx_id);
2258 }
2259
2260 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002261}
2262
2263int platform_switch_voice_call_device_post(void *platform,
2264 snd_device_t out_snd_device,
2265 snd_device_t in_snd_device)
2266{
2267 struct platform_data *my_data = (struct platform_data *)platform;
2268 int acdb_rx_id, acdb_tx_id;
2269
2270 if (my_data->acdb_send_voice_cal == NULL) {
2271 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
2272 } else {
keunhui.park2f7306a2015-07-16 16:48:06 +09002273 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
2274 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07002275
2276 if (acdb_rx_id > 0 && acdb_tx_id > 0)
2277 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
2278 else
2279 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2280 acdb_rx_id, acdb_tx_id);
2281 }
2282
2283 return 0;
2284}
2285
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002286int platform_switch_voice_call_usecase_route_post(void *platform,
2287 snd_device_t out_snd_device,
2288 snd_device_t in_snd_device)
2289{
2290 struct platform_data *my_data = (struct platform_data *)platform;
2291 int acdb_rx_id, acdb_tx_id;
2292 int ret = 0;
2293
2294 if (my_data->csd == NULL)
2295 return ret;
2296
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002297 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
keunhui.park2f7306a2015-07-16 16:48:06 +09002298 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002299
2300 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
2301 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
2302 my_data->adev->acdb_settings);
2303 if (ret < 0) {
2304 ALOGE("%s: csd_enable_device, failed, error %d", __func__, ret);
2305 }
2306 } else {
2307 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2308 acdb_rx_id, acdb_tx_id);
2309 }
2310
2311 return ret;
2312}
2313
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002314int platform_start_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07002315{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002316 struct platform_data *my_data = (struct platform_data *)platform;
2317 int ret = 0;
2318
2319 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002320 ret = my_data->csd->start_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002321 if (ret < 0) {
2322 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
2323 }
2324 }
2325 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002326}
2327
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002328int platform_stop_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07002329{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002330 struct platform_data *my_data = (struct platform_data *)platform;
2331 int ret = 0;
2332
2333 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002334 ret = my_data->csd->stop_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002335 if (ret < 0) {
2336 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
2337 }
2338 }
2339 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002340}
2341
Vignesh Kulothunganb6f0a9c2018-03-22 13:50:22 -07002342int platform_set_mic_break_det(void *platform, bool enable)
2343{
2344 int ret = 0;
2345 struct platform_data *my_data = (struct platform_data *)platform;
2346 struct audio_device *adev = my_data->adev;
2347 const char *mixer_ctl_name = "Voice Mic Break Enable";
2348 struct mixer_ctl *ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2349 if (!ctl) {
2350 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2351 __func__, mixer_ctl_name);
2352 return -EINVAL;
2353 }
2354
2355 ret = mixer_ctl_set_value(ctl, 0, enable);
2356 if(ret)
2357 ALOGE("%s: Failed to set mixer ctl: %s", __func__, mixer_ctl_name);
2358
2359 return ret;
2360}
2361
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002362int platform_get_sample_rate(void *platform, uint32_t *rate)
2363{
2364 struct platform_data *my_data = (struct platform_data *)platform;
2365 int ret = 0;
2366
2367 if (my_data->csd != NULL) {
2368 ret = my_data->csd->get_sample_rate(rate);
2369 if (ret < 0) {
2370 ALOGE("%s: csd_get_sample_rate error %d\n", __func__, ret);
2371 }
2372 }
2373 return ret;
2374}
2375
vivek mehtab6506412015-08-07 16:55:17 -07002376void platform_set_speaker_gain_in_combo(struct audio_device *adev,
2377 snd_device_t snd_device,
2378 bool enable)
2379{
2380 const char* name;
2381 switch (snd_device) {
2382 case SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES:
2383 if (enable)
2384 name = "spkr-gain-in-headphone-combo";
2385 else
2386 name = "speaker-gain-default";
2387 break;
2388 case SND_DEVICE_OUT_SPEAKER_AND_LINE:
2389 if (enable)
2390 name = "spkr-gain-in-line-combo";
2391 else
2392 name = "speaker-gain-default";
2393 break;
2394 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES:
2395 if (enable)
2396 name = "spkr-safe-gain-in-headphone-combo";
2397 else
2398 name = "speaker-safe-gain-default";
2399 break;
2400 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE:
2401 if (enable)
2402 name = "spkr-safe-gain-in-line-combo";
2403 else
2404 name = "speaker-safe-gain-default";
2405 break;
2406 default:
2407 return;
2408 }
2409
2410 audio_route_apply_and_update_path(adev->audio_route, name);
2411}
2412
Eric Laurentb23d5282013-05-14 15:27:20 -07002413int platform_set_voice_volume(void *platform, int volume)
2414{
2415 struct platform_data *my_data = (struct platform_data *)platform;
2416 struct audio_device *adev = my_data->adev;
2417 struct mixer_ctl *ctl;
sangwoo53b2cf02013-07-25 19:18:44 -07002418 const char *mixer_ctl_name = "Voice Rx Gain";
Nadav Barc46d0fa2017-12-24 14:50:37 +02002419 const char *mute_mixer_ctl_name = "Voice Rx Device Mute";
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002420 int vol_index = 0, ret = 0;
2421 uint32_t set_values[ ] = {0,
2422 ALL_SESSION_VSID,
2423 DEFAULT_VOLUME_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07002424
2425 // Voice volume levels are mapped to adsp volume levels as follows.
2426 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
2427 // But this values don't changed in kernel. So, below change is need.
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09002428 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, my_data->max_vol_index);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002429 set_values[0] = vol_index;
Eric Laurentb23d5282013-05-14 15:27:20 -07002430
2431 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2432 if (!ctl) {
2433 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2434 __func__, mixer_ctl_name);
2435 return -EINVAL;
2436 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002437 ALOGV("Setting voice volume index: %d", set_values[0]);
2438 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2439
Nadav Barc46d0fa2017-12-24 14:50:37 +02002440 // Send mute command in case volume index is max since indexes are inverted
2441 // for mixer controls.
2442 if (vol_index == my_data->max_vol_index) {
2443 set_values[0] = 1;
2444 }
2445 else {
2446 set_values[0] = 0;
2447 }
2448
2449 ctl = mixer_get_ctl_by_name(adev->mixer, mute_mixer_ctl_name);
2450 if (!ctl) {
2451 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2452 __func__, mute_mixer_ctl_name);
2453 return -EINVAL;
2454 }
2455 ALOGV("%s: Setting RX Device Mute to: %d", __func__, set_values[0]);
2456 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2457
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002458 if (my_data->csd != NULL) {
2459 ret = my_data->csd->volume(ALL_SESSION_VSID, volume,
2460 DEFAULT_VOLUME_RAMP_DURATION_MS);
2461 if (ret < 0) {
2462 ALOGE("%s: csd_volume error %d", __func__, ret);
2463 }
2464 }
2465 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002466}
2467
2468int platform_set_mic_mute(void *platform, bool state)
2469{
2470 struct platform_data *my_data = (struct platform_data *)platform;
2471 struct audio_device *adev = my_data->adev;
2472 struct mixer_ctl *ctl;
2473 const char *mixer_ctl_name = "Voice Tx Mute";
sangwoo53b2cf02013-07-25 19:18:44 -07002474 int ret = 0;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002475 uint32_t set_values[ ] = {0,
2476 ALL_SESSION_VSID,
2477 DEFAULT_MUTE_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07002478
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09002479 if (adev->mode != AUDIO_MODE_IN_CALL &&
2480 adev->mode != AUDIO_MODE_IN_COMMUNICATION)
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002481 return 0;
2482
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09002483 if (adev->enable_hfp)
2484 mixer_ctl_name = "HFP Tx Mute";
2485
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002486 set_values[0] = state;
2487 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2488 if (!ctl) {
2489 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2490 __func__, mixer_ctl_name);
2491 return -EINVAL;
2492 }
2493 ALOGV("Setting voice mute state: %d", state);
2494 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2495
2496 if (my_data->csd != NULL) {
2497 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state,
2498 DEFAULT_MUTE_RAMP_DURATION_MS);
sangwoo53b2cf02013-07-25 19:18:44 -07002499 if (ret < 0) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002500 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
sangwoo53b2cf02013-07-25 19:18:44 -07002501 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002502 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002503 return ret;
2504}
Eric Laurentb23d5282013-05-14 15:27:20 -07002505
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002506int platform_set_device_mute(void *platform, bool state, char *dir)
2507{
2508 struct platform_data *my_data = (struct platform_data *)platform;
2509 struct audio_device *adev = my_data->adev;
2510 struct mixer_ctl *ctl;
2511 char *mixer_ctl_name = NULL;
2512 int ret = 0;
2513 uint32_t set_values[ ] = {0,
2514 ALL_SESSION_VSID,
2515 0};
2516 if(dir == NULL) {
2517 ALOGE("%s: Invalid direction:%s", __func__, dir);
2518 return -EINVAL;
2519 }
2520
2521 if (!strncmp("rx", dir, sizeof("rx"))) {
2522 mixer_ctl_name = "Voice Rx Device Mute";
2523 } else if (!strncmp("tx", dir, sizeof("tx"))) {
2524 mixer_ctl_name = "Voice Tx Device Mute";
2525 } else {
2526 return -EINVAL;
2527 }
2528
2529 set_values[0] = state;
2530 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2531 if (!ctl) {
2532 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2533 __func__, mixer_ctl_name);
2534 return -EINVAL;
2535 }
2536
2537 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
2538 __func__,state, mixer_ctl_name);
2539 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2540
2541 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002542}
2543
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002544int platform_can_split_snd_device(snd_device_t snd_device,
2545 int *num_devices,
2546 snd_device_t *new_snd_devices)
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002547{
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002548 int ret = -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002549 if (NULL == num_devices || NULL == new_snd_devices) {
2550 ALOGE("%s: NULL pointer ..", __func__);
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002551 return -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002552 }
2553
2554 /*
2555 * If wired headset/headphones/line devices share the same backend
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002556 * with speaker/earpiece this routine returns -EINVAL.
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002557 */
2558 if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES &&
2559 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_HEADPHONES)) {
2560 *num_devices = 2;
2561 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2562 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002563 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002564 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_LINE &&
2565 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_LINE)) {
2566 *num_devices = 2;
2567 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2568 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002569 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002570 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES &&
2571 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_HEADPHONES)) {
2572 *num_devices = 2;
2573 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2574 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002575 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002576 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE &&
2577 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_LINE)) {
2578 *num_devices = 2;
2579 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2580 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002581 ret = 0;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002582 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO &&
2583 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2584 SND_DEVICE_OUT_BT_SCO)) {
2585 *num_devices = 2;
2586 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2587 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO;
2588 ret = 0;
juyuchen5351ea62018-05-16 10:54:37 +08002589 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO &&
2590 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE,
2591 SND_DEVICE_OUT_BT_SCO)) {
2592 *num_devices = 2;
2593 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2594 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO;
2595 ret = 0;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002596 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB &&
2597 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2598 SND_DEVICE_OUT_BT_SCO_WB)) {
2599 *num_devices = 2;
2600 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2601 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO_WB;
2602 ret = 0;
juyuchen5351ea62018-05-16 10:54:37 +08002603 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB &&
2604 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE,
2605 SND_DEVICE_OUT_BT_SCO_WB)) {
2606 *num_devices = 2;
2607 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2608 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO_WB;
2609 ret = 0;
David Linee3fe402017-03-13 10:00:42 -07002610 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET &&
2611 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_USB_HEADSET)) {
2612 *num_devices = 2;
2613 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2614 new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
2615 ret = 0;
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07002616 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET &&
2617 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_USB_HEADSET)) {
2618 *num_devices = 2;
2619 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2620 new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
2621 ret = 0;
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002622 } else if (SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP == snd_device &&
2623 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2624 SND_DEVICE_OUT_BT_A2DP)) {
2625 *num_devices = 2;
2626 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2627 new_snd_devices[1] = SND_DEVICE_OUT_BT_A2DP;
2628 ret = 0;
Aniket Kumar Lata9723a962018-05-16 17:41:55 -07002629 } else if (SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP == snd_device &&
2630 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE,
2631 SND_DEVICE_OUT_BT_A2DP)) {
2632 *num_devices = 2;
2633 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2634 new_snd_devices[1] = SND_DEVICE_OUT_BT_A2DP;
2635 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002636 }
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002637
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002638 return ret;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002639}
2640
Eric Laurentb23d5282013-05-14 15:27:20 -07002641snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
2642{
2643 struct platform_data *my_data = (struct platform_data *)platform;
2644 struct audio_device *adev = my_data->adev;
2645 audio_mode_t mode = adev->mode;
2646 snd_device_t snd_device = SND_DEVICE_NONE;
2647
2648 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
2649 if (devices == AUDIO_DEVICE_NONE ||
2650 devices & AUDIO_DEVICE_BIT_IN) {
2651 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
2652 goto exit;
2653 }
2654
Eric Laurent1b491552015-09-15 17:52:41 -07002655 if (popcount(devices) == 2) {
2656 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2657 AUDIO_DEVICE_OUT_SPEAKER) ||
2658 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2659 AUDIO_DEVICE_OUT_SPEAKER)) {
2660 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
2661 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2662 AUDIO_DEVICE_OUT_SPEAKER)) {
2663 snd_device = SND_DEVICE_OUT_SPEAKER_AND_LINE;
2664 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2665 AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
2666 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2667 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2668 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES;
2669 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2670 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2671 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE;
2672 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
2673 AUDIO_DEVICE_OUT_SPEAKER)) {
2674 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002675 } else if ((devices & AUDIO_DEVICE_OUT_ALL_SCO) &&
2676 ((devices & ~AUDIO_DEVICE_OUT_ALL_SCO) == AUDIO_DEVICE_OUT_SPEAKER)) {
2677 snd_device = adev->bt_wb_speech_enabled ?
2678 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB :
2679 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO;
juyuchen5351ea62018-05-16 10:54:37 +08002680 } else if ((devices & AUDIO_DEVICE_OUT_ALL_SCO) &&
2681 ((devices & ~AUDIO_DEVICE_OUT_ALL_SCO) == AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2682 snd_device = adev->bt_wb_speech_enabled ?
2683 SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB :
2684 SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO;
Eric Laurent99dab492017-06-17 15:19:08 -07002685 } else if ((devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
2686 AUDIO_DEVICE_OUT_SPEAKER)) ||
2687 (devices == (AUDIO_DEVICE_OUT_USB_HEADSET |
2688 AUDIO_DEVICE_OUT_SPEAKER))) {
David Linee3fe402017-03-13 10:00:42 -07002689 snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET;
Eric Laurentd0f7c262017-07-05 09:09:12 -07002690 } else if ((devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
2691 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) ||
2692 (devices == (AUDIO_DEVICE_OUT_USB_HEADSET |
2693 AUDIO_DEVICE_OUT_SPEAKER_SAFE))) {
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07002694 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET;
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002695 } else if ((devices & AUDIO_DEVICE_OUT_SPEAKER) &&
2696 (devices & AUDIO_DEVICE_OUT_ALL_A2DP)) {
2697 snd_device = SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP;
Aniket Kumar Lata9723a962018-05-16 17:41:55 -07002698 } else if ((devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) &&
2699 (devices & AUDIO_DEVICE_OUT_ALL_A2DP)) {
2700 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP;
Eric Laurent1b491552015-09-15 17:52:41 -07002701 } else {
2702 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
2703 goto exit;
2704 }
2705 if (snd_device != SND_DEVICE_NONE) {
2706 goto exit;
2707 }
2708 }
2709
2710 if (popcount(devices) != 1) {
2711 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
2712 goto exit;
2713 }
2714
Madhuri Athota3f6051b2016-10-13 23:25:38 +05302715 if (voice_is_in_call(adev) || adev->enable_voicerx || audio_extn_hfp_is_active(adev)) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002716 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002717 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2718 devices & AUDIO_DEVICE_OUT_LINE) {
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002719 if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002720 (adev->voice.tty_mode == TTY_MODE_FULL))
Eric Laurentb23d5282013-05-14 15:27:20 -07002721 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002722 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002723 (adev->voice.tty_mode == TTY_MODE_VCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002724 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002725 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002726 (adev->voice.tty_mode == TTY_MODE_HCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002727 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002728 else {
2729 if (devices & AUDIO_DEVICE_OUT_LINE)
2730 snd_device = SND_DEVICE_OUT_VOICE_LINE;
yixuanjiang9536e672018-09-06 18:43:36 +08002731 else if (devices & AUDIO_DEVICE_OUT_WIRED_HEADSET)
2732 snd_device = SND_DEVICE_OUT_VOICE_HEADSET;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002733 else
2734 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
2735 }
Eric Laurent99dab492017-06-17 15:19:08 -07002736 } else if (audio_is_usb_out_device(devices)) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002737 if (voice_is_in_call(adev)) {
2738 switch (adev->voice.tty_mode) {
2739 case TTY_MODE_FULL:
2740 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_USB;
2741 break;
2742 case TTY_MODE_VCO:
2743 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_USB;
2744 break;
2745 case TTY_MODE_HCO:
2746 // since Hearing will be on handset\speaker, use existing device
2747 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
2748 break;
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002749 case TTY_MODE_OFF:
2750 break;
vivek mehtaa6b79742017-03-09 15:40:43 -08002751 default:
2752 ALOGE("%s: Invalid TTY mode (%#x)",
2753 __func__, adev->voice.tty_mode);
2754 }
2755 }
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002756 if (snd_device == SND_DEVICE_NONE) {
2757 snd_device = audio_extn_usb_is_capture_supported() ?
2758 SND_DEVICE_OUT_VOICE_USB_HEADSET :
2759 SND_DEVICE_OUT_VOICE_USB_HEADPHONES;
2760 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002761 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002762 if (adev->bt_wb_speech_enabled) {
2763 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2764 } else {
2765 snd_device = SND_DEVICE_OUT_BT_SCO;
2766 }
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002767 } else if (devices & AUDIO_DEVICE_OUT_ALL_A2DP) {
2768 snd_device = SND_DEVICE_OUT_BT_A2DP;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002769 } else if (devices & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002770 if (!adev->enable_hfp) {
2771 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
2772 } else {
2773 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_HFP;
2774 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002775 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002776 if(adev->voice.hac)
2777 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2778 else if (is_operator_tmus())
Eric Laurentb23d5282013-05-14 15:27:20 -07002779 snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS;
2780 else
Eric Laurentb4d368e2014-06-25 10:21:54 -05002781 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002782 } else if (devices & AUDIO_DEVICE_OUT_TELEPHONY_TX)
2783 snd_device = SND_DEVICE_OUT_VOICE_TX;
2784
Eric Laurentb23d5282013-05-14 15:27:20 -07002785 if (snd_device != SND_DEVICE_NONE) {
2786 goto exit;
2787 }
2788 }
2789
Eric Laurentb23d5282013-05-14 15:27:20 -07002790 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2791 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2792 snd_device = SND_DEVICE_OUT_HEADPHONES;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002793 } else if (devices & AUDIO_DEVICE_OUT_LINE) {
2794 snd_device = SND_DEVICE_OUT_LINE;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002795 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) {
2796 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE;
Eric Laurentb23d5282013-05-14 15:27:20 -07002797 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
andysu5b30b062018-04-20 16:34:06 +08002798 /*
2799 * Perform device switch only if acdb tuning is different between SPEAKER & SPEAKER_REVERSE,
2800 * Or there will be a small pause while performing device switch.
2801 */
2802 if (my_data->speaker_lr_swap &&
2803 (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
2804 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]))
Eric Laurentb23d5282013-05-14 15:27:20 -07002805 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
2806 else
2807 snd_device = SND_DEVICE_OUT_SPEAKER;
2808 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002809 if (adev->bt_wb_speech_enabled) {
2810 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2811 } else {
2812 snd_device = SND_DEVICE_OUT_BT_SCO;
2813 }
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002814 } else if (devices & AUDIO_DEVICE_OUT_ALL_A2DP) {
2815 snd_device = SND_DEVICE_OUT_BT_A2DP;
Eric Laurentb23d5282013-05-14 15:27:20 -07002816 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2817 snd_device = SND_DEVICE_OUT_HDMI ;
Eric Laurent99dab492017-06-17 15:19:08 -07002818 } else if (audio_is_usb_out_device(devices)) {
jasmine cha270b7762018-03-30 15:41:33 +08002819 if (audio_extn_ma_supported_usb())
2820 snd_device = SND_DEVICE_OUT_USB_HEADSET_SPEC;
2821 else if (audio_extn_usb_is_capture_supported())
David Linee3fe402017-03-13 10:00:42 -07002822 snd_device = SND_DEVICE_OUT_USB_HEADSET;
2823 else
2824 snd_device = SND_DEVICE_OUT_USB_HEADPHONES;
2825 }else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002826 /*HAC support for voice-ish audio (eg visual voicemail)*/
2827 if(adev->voice.hac)
2828 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2829 else
2830 snd_device = SND_DEVICE_OUT_HANDSET;
Eric Laurentb23d5282013-05-14 15:27:20 -07002831 } else {
2832 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
2833 }
2834exit:
2835 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
2836 return snd_device;
2837}
2838
2839snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
2840{
2841 struct platform_data *my_data = (struct platform_data *)platform;
2842 struct audio_device *adev = my_data->adev;
2843 audio_source_t source = (adev->active_input == NULL) ?
2844 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
2845
2846 audio_mode_t mode = adev->mode;
2847 audio_devices_t in_device = ((adev->active_input == NULL) ?
2848 AUDIO_DEVICE_NONE : adev->active_input->device)
2849 & ~AUDIO_DEVICE_BIT_IN;
2850 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
2851 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
2852 snd_device_t snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002853 int channel_count = popcount(channel_mask);
Eric Laurentb23d5282013-05-14 15:27:20 -07002854
Prashant Malanic92c5962015-08-11 15:10:18 -07002855 ALOGV("%s: enter: out_device(%#x) in_device(%#x) channel_count (%d) channel_mask (0x%x)",
2856 __func__, out_device, in_device, channel_count, channel_mask);
Devin Kimd789e432016-10-26 15:07:27 -07002857 if ((out_device != AUDIO_DEVICE_NONE) && (voice_is_in_call(adev) ||
2858 audio_extn_hfp_is_active(adev))) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002859 if (adev->voice.tty_mode != TTY_MODE_OFF) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002860 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002861 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2862 out_device & AUDIO_DEVICE_OUT_LINE) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002863 switch (adev->voice.tty_mode) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002864 case TTY_MODE_FULL:
2865 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
2866 break;
2867 case TTY_MODE_VCO:
2868 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
2869 break;
2870 case TTY_MODE_HCO:
2871 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
2872 break;
2873 default:
2874 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
2875 }
2876 goto exit;
Eric Laurent99dab492017-06-17 15:19:08 -07002877 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002878 switch (adev->voice.tty_mode) {
2879 case TTY_MODE_FULL:
2880 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC;
2881 break;
2882 case TTY_MODE_VCO:
2883 // since voice will be captured from handset mic, use existing device
2884 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
2885 break;
2886 case TTY_MODE_HCO:
2887 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC;
2888 break;
2889 default:
2890 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
Eric Laurentb23d5282013-05-14 15:27:20 -07002891 }
2892 goto exit;
2893 }
2894 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002895 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002896 if (my_data->fluence_in_voice_call == false) {
2897 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2898 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002899 if (is_operator_tmus())
2900 snd_device = SND_DEVICE_IN_VOICE_DMIC_TMUS;
Eric Laurentb23d5282013-05-14 15:27:20 -07002901 else
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002902 snd_device = SND_DEVICE_IN_VOICE_DMIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002903 }
2904 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2905 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
2906 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002907 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002908 if (adev->bluetooth_nrec)
2909 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2910 else
2911 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002912 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002913 if (adev->bluetooth_nrec)
2914 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2915 else
2916 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002917 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002918 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Prashant Malanic92c5962015-08-11 15:10:18 -07002919 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
2920 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2921 out_device & AUDIO_DEVICE_OUT_LINE) {
2922 if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
2923 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
2924 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
2925 } else {
2926 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2927 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002928 }
vivek mehtafe121d52015-08-10 23:39:23 -07002929
2930 //select default
2931 if (snd_device == SND_DEVICE_NONE) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002932 if (!adev->enable_hfp) {
2933 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2934 } else {
2935 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP;
2936 platform_set_echo_reference(adev, true, out_device);
2937 }
vivek mehtafe121d52015-08-10 23:39:23 -07002938 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002939 } else if (out_device & AUDIO_DEVICE_OUT_TELEPHONY_TX) {
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002940 snd_device = SND_DEVICE_IN_VOICE_RX;
Eric Laurent99dab492017-06-17 15:19:08 -07002941 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
David Lin40b07892017-08-07 15:02:48 -07002942 if (audio_extn_usb_is_capture_supported()) {
2943 snd_device = SND_DEVICE_IN_VOICE_USB_HEADSET_MIC;
2944 } else if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
2945 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
2946 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
2947 } else {
2948 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2949 }
2950 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002951 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002952 } else if (source == AUDIO_SOURCE_CAMCORDER) {
2953 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
2954 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2955 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
2956 }
2957 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
2958 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002959 if (my_data->fluence_in_voice_rec && channel_count == 1) {
2960 if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2961 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002962 if (adev->active_input->enable_aec)
2963 snd_device = SND_DEVICE_IN_HANDSET_QMIC_AEC;
2964 else
2965 snd_device = SND_DEVICE_IN_HANDSET_QMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002966 } else if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2967 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002968 if (adev->active_input->enable_aec)
2969 snd_device = SND_DEVICE_IN_HANDSET_TMIC_AEC;
2970 else
2971 snd_device = SND_DEVICE_IN_HANDSET_TMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002972 } else if (((my_data->fluence_type == FLUENCE_PRO_ENABLE) ||
2973 (my_data->fluence_type == FLUENCE_ENABLE)) &&
2974 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002975 if (adev->active_input->enable_aec)
2976 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
2977 else
2978 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
Prashant Malanic92c5962015-08-11 15:10:18 -07002979 }
2980 platform_set_echo_reference(adev, true, out_device);
2981 } else if ((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) &&
2982 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2983 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002984 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002985 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
2986 snd_device = SND_DEVICE_IN_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002987 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002988 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2989 snd_device = SND_DEVICE_IN_QUAD_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002990 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002991 if (snd_device == SND_DEVICE_NONE) {
vivek mehtaf3440682016-05-11 14:24:37 -07002992 if (adev->active_input->enable_aec) {
2993 if (adev->active_input->enable_ns) {
2994 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS;
2995 } else {
2996 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC;
2997 }
vivek mehta733c1df2016-04-04 15:09:24 -07002998 platform_set_echo_reference(adev, true, out_device);
vivek mehtaf3440682016-05-11 14:24:37 -07002999 } else if (adev->active_input->enable_ns) {
3000 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
3001 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003002 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
vivek mehtaf3440682016-05-11 14:24:37 -07003003 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003004 }
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -07003005 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3006 snd_device = SND_DEVICE_IN_VOICE_REC_HEADSET_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07003007 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07003008 snd_device = SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07003009 }
rago90fb9612015-12-02 11:37:53 -08003010 } else if (source == AUDIO_SOURCE_UNPROCESSED) {
3011 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
vivek mehta4ed66e62016-04-15 23:33:34 -07003012 if (((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) ||
3013 (channel_mask == AUDIO_CHANNEL_IN_STEREO)) &&
3014 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
3015 snd_device = SND_DEVICE_IN_UNPROCESSED_STEREO_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003016 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07003017 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
3018 snd_device = SND_DEVICE_IN_UNPROCESSED_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003019 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07003020 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
3021 snd_device = SND_DEVICE_IN_UNPROCESSED_QUAD_MIC;
3022 } else {
3023 snd_device = SND_DEVICE_IN_UNPROCESSED_MIC;
3024 }
rago90fb9612015-12-02 11:37:53 -08003025 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3026 snd_device = SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07003027 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07003028 snd_device = SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC;
rago90fb9612015-12-02 11:37:53 -08003029 }
Eric Laurent50a38ed2015-10-14 18:48:06 -07003030 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION ||
rago90fb9612015-12-02 11:37:53 -08003031 mode == AUDIO_MODE_IN_COMMUNICATION) {
David Lin40b07892017-08-07 15:02:48 -07003032 if (out_device & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
3033 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
3034 (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE | AUDIO_DEVICE_OUT_USB_HEADSET) &&
3035 !audio_extn_usb_is_capture_supported())) {
Eric Laurentb23d5282013-05-14 15:27:20 -07003036 in_device = AUDIO_DEVICE_IN_BACK_MIC;
David Lin40b07892017-08-07 15:02:48 -07003037 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003038 if (adev->active_input) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003039 if (adev->active_input->enable_aec &&
3040 adev->active_input->enable_ns) {
Eric Laurentb23d5282013-05-14 15:27:20 -07003041 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003042 if (my_data->fluence_in_spkr_mode &&
3043 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003044 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003045 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003046 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003047 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003048 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003049 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003050 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003051 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003052 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003053 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003054 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003055 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05003056 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3057 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Eric Laurent99dab492017-06-17 15:19:08 -07003058 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07003059 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
Eric Laurentb23d5282013-05-14 15:27:20 -07003060 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05003061 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003062 } else if (adev->active_input->enable_aec) {
3063 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
3064 if (my_data->fluence_in_spkr_mode &&
3065 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003066 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003067 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003068 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003069 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003070 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003071 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
3072 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003073 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003074 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003075 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003076 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003077 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05003078 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3079 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Eric Laurent99dab492017-06-17 15:19:08 -07003080 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07003081 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
Eric Laurentcefbbac2014-09-04 13:54:10 -05003082 }
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08003083 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003084 } else if (adev->active_input->enable_ns) {
3085 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
3086 if (my_data->fluence_in_spkr_mode &&
3087 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003088 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003089 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003090 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003091 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003092 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003093 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
3094 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003095 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003096 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003097 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003098 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003099 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003100 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05003101 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003102 }
3103 } else if (source == AUDIO_SOURCE_DEFAULT) {
3104 goto exit;
3105 }
3106
3107
3108 if (snd_device != SND_DEVICE_NONE) {
3109 goto exit;
3110 }
3111
3112 if (in_device != AUDIO_DEVICE_NONE &&
3113 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
3114 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
3115 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003116 if ((my_data->source_mic_type & SOURCE_QUAD_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003117 channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003118 snd_device = SND_DEVICE_IN_QUAD_MIC;
3119 } else if ((my_data->source_mic_type & SOURCE_THREE_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003120 channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003121 snd_device = SND_DEVICE_IN_THREE_MIC;
3122 } else if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
3123 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003124 snd_device = SND_DEVICE_IN_HANDSET_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07003125 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
3126 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003127 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003128 } else {
3129 ALOGE("%s: something wrong (1): source type (%d) channel_count (%d) .."
3130 " channel mask (0x%x) no combination found .. setting to mono", __func__,
3131 my_data->source_mic_type, channel_count, channel_mask);
3132 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3133 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003134 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003135 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
3136 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003137 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07003138 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
3139 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003140 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003141 } else {
3142 ALOGE("%s: something wrong (2): source type (%d) channel_count (%d) .."
3143 " no combination found .. setting to mono", __func__,
3144 my_data->source_mic_type, channel_count);
3145 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
3146 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003147 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3148 snd_device = SND_DEVICE_IN_HEADSET_MIC;
3149 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003150 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003151 if (adev->bluetooth_nrec)
3152 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
3153 else
3154 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003155 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003156 if (adev->bluetooth_nrec)
3157 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
3158 else
3159 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003160 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003161 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
3162 snd_device = SND_DEVICE_IN_HDMI_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07003163 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
David Linee3fe402017-03-13 10:00:42 -07003164 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07003165 } else {
3166 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
3167 ALOGW("%s: Using default handset-mic", __func__);
3168 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3169 }
3170 } else {
3171 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
3172 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3173 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
3174 snd_device = SND_DEVICE_IN_HEADSET_MIC;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003175 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07003176 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003177 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05003178 out_device & AUDIO_DEVICE_OUT_LINE) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003179 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
3180 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003181 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07003182 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
3183 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003184 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003185 } else {
3186 ALOGE("%s: something wrong (3): source type (%d) channel_count (%d) .."
3187 " no combination found .. setting to mono", __func__,
3188 my_data->source_mic_type, channel_count);
3189 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
3190 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003191 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003192 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003193 if (adev->bluetooth_nrec)
3194 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
3195 else
3196 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003197 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003198 if (adev->bluetooth_nrec)
3199 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
3200 else
3201 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003202 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003203 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
3204 snd_device = SND_DEVICE_IN_HDMI_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07003205 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
David Linee3fe402017-03-13 10:00:42 -07003206 if (audio_extn_usb_is_capture_supported())
3207 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
3208 else
3209 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07003210 } else {
3211 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
3212 ALOGW("%s: Using default handset-mic", __func__);
3213 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3214 }
3215 }
3216exit:
3217 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
3218 return snd_device;
3219}
3220
3221int platform_set_hdmi_channels(void *platform, int channel_count)
3222{
3223 struct platform_data *my_data = (struct platform_data *)platform;
3224 struct audio_device *adev = my_data->adev;
3225 struct mixer_ctl *ctl;
3226 const char *channel_cnt_str = NULL;
3227 const char *mixer_ctl_name = "HDMI_RX Channels";
3228 switch (channel_count) {
3229 case 8:
3230 channel_cnt_str = "Eight"; break;
3231 case 7:
3232 channel_cnt_str = "Seven"; break;
3233 case 6:
3234 channel_cnt_str = "Six"; break;
3235 case 5:
3236 channel_cnt_str = "Five"; break;
3237 case 4:
3238 channel_cnt_str = "Four"; break;
3239 case 3:
3240 channel_cnt_str = "Three"; break;
3241 default:
3242 channel_cnt_str = "Two"; break;
3243 }
3244 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3245 if (!ctl) {
3246 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3247 __func__, mixer_ctl_name);
3248 return -EINVAL;
3249 }
3250 ALOGV("HDMI channel count: %s", channel_cnt_str);
3251 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
3252 return 0;
3253}
3254
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003255int platform_edid_get_max_channels(void *platform)
Eric Laurentb23d5282013-05-14 15:27:20 -07003256{
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003257 struct platform_data *my_data = (struct platform_data *)platform;
3258 struct audio_device *adev = my_data->adev;
Eric Laurentb23d5282013-05-14 15:27:20 -07003259 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
3260 char *sad = block;
3261 int num_audio_blocks;
3262 int channel_count;
3263 int max_channels = 0;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003264 int i, ret, count;
Eric Laurentb23d5282013-05-14 15:27:20 -07003265
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003266 struct mixer_ctl *ctl;
3267
3268 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
3269 if (!ctl) {
3270 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3271 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
Eric Laurentb23d5282013-05-14 15:27:20 -07003272 return 0;
3273 }
3274
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003275 mixer_ctl_update(ctl);
3276
3277 count = mixer_ctl_get_num_values(ctl);
Eric Laurentb23d5282013-05-14 15:27:20 -07003278
3279 /* Read SAD blocks, clamping the maximum size for safety */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003280 if (count > (int)sizeof(block))
3281 count = (int)sizeof(block);
Eric Laurentb23d5282013-05-14 15:27:20 -07003282
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003283 ret = mixer_ctl_get_array(ctl, block, count);
3284 if (ret != 0) {
3285 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
3286 return 0;
3287 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003288
3289 /* Calculate the number of SAD blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003290 num_audio_blocks = count / SAD_BLOCK_SIZE;
Eric Laurentb23d5282013-05-14 15:27:20 -07003291
3292 for (i = 0; i < num_audio_blocks; i++) {
3293 /* Only consider LPCM blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003294 if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
3295 sad += 3;
Eric Laurentb23d5282013-05-14 15:27:20 -07003296 continue;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003297 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003298
3299 channel_count = (sad[0] & 0x7) + 1;
3300 if (channel_count > max_channels)
3301 max_channels = channel_count;
3302
3303 /* Advance to next block */
3304 sad += 3;
3305 }
3306
3307 return max_channels;
3308}
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003309
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07003310int platform_set_incall_recording_session_id(void *platform,
3311 uint32_t session_id, int rec_mode)
3312{
3313 int ret = 0;
3314 struct platform_data *my_data = (struct platform_data *)platform;
3315 struct audio_device *adev = my_data->adev;
3316 struct mixer_ctl *ctl;
3317 const char *mixer_ctl_name = "Voc VSID";
3318 int num_ctl_values;
3319 int i;
3320
3321 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3322 if (!ctl) {
3323 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3324 __func__, mixer_ctl_name);
3325 ret = -EINVAL;
3326 } else {
3327 num_ctl_values = mixer_ctl_get_num_values(ctl);
3328 for (i = 0; i < num_ctl_values; i++) {
3329 if (mixer_ctl_set_value(ctl, i, session_id)) {
3330 ALOGV("Error: invalid session_id: %x", session_id);
3331 ret = -EINVAL;
3332 break;
3333 }
3334 }
3335 }
3336
3337 if (my_data->csd != NULL) {
3338 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
3339 if (ret < 0) {
3340 ALOGE("%s: csd_client_start_record failed, error %d",
3341 __func__, ret);
3342 }
3343 }
3344
3345 return ret;
3346}
3347
Arun Mirpuriba2749a2018-04-17 14:32:24 -07003348int platform_set_incall_recording_session_channels(void *platform,
3349 uint32_t channel_count)
3350{
3351 int ret = 0;
3352 struct platform_data *my_data = (struct platform_data *)platform;
3353 struct audio_device *adev = my_data->adev;
3354 const char *mixer_ctl_name = "Voc Rec Config";
3355 int num_ctl_values;
3356 int i;
3357 struct mixer_ctl *ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3358
3359 if (!ctl) {
3360 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3361 __func__, mixer_ctl_name);
3362 ret = -EINVAL;
3363 } else {
3364 num_ctl_values = mixer_ctl_get_num_values(ctl);
3365 for (i = 0; i < num_ctl_values; i++) {
3366 if (mixer_ctl_set_value(ctl, i, channel_count)) {
3367 ALOGE("Error: invalid channel count: %x", channel_count);
3368 ret = -EINVAL;
3369 break;
3370 }
3371 }
3372 }
3373
3374 return ret;
3375}
3376
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07003377int platform_stop_incall_recording_usecase(void *platform)
3378{
3379 int ret = 0;
3380 struct platform_data *my_data = (struct platform_data *)platform;
3381
3382 if (my_data->csd != NULL) {
3383 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
3384 if (ret < 0) {
3385 ALOGE("%s: csd_client_stop_record failed, error %d",
3386 __func__, ret);
3387 }
3388 }
3389
3390 return ret;
3391}
3392
3393int platform_start_incall_music_usecase(void *platform)
3394{
3395 int ret = 0;
3396 struct platform_data *my_data = (struct platform_data *)platform;
3397
3398 if (my_data->csd != NULL) {
3399 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
3400 if (ret < 0) {
3401 ALOGE("%s: csd_client_start_playback failed, error %d",
3402 __func__, ret);
3403 }
3404 }
3405
3406 return ret;
3407}
3408
3409int platform_stop_incall_music_usecase(void *platform)
3410{
3411 int ret = 0;
3412 struct platform_data *my_data = (struct platform_data *)platform;
3413
3414 if (my_data->csd != NULL) {
3415 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
3416 if (ret < 0) {
3417 ALOGE("%s: csd_client_stop_playback failed, error %d",
3418 __func__, ret);
3419 }
3420 }
3421
3422 return ret;
3423}
3424
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003425int platform_set_parameters(void *platform, struct str_parms *parms)
3426{
3427 struct platform_data *my_data = (struct platform_data *)platform;
jasmine chac89321b2018-04-10 21:37:01 +08003428 char *value = NULL;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003429 char *kv_pairs = str_parms_to_str(parms);
jasmine chac89321b2018-04-10 21:37:01 +08003430 int len;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003431 int ret = 0, err;
3432
3433 if (kv_pairs == NULL) {
3434 ret = -EINVAL;
Jasmine Chaa314e192018-05-09 17:46:28 +08003435 ALOGE("%s: key-value pair is NULL", __func__);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003436 goto done;
3437 }
3438
3439 ALOGV("%s: enter: %s", __func__, kv_pairs);
3440
jasmine chac89321b2018-04-10 21:37:01 +08003441 len = strlen(kv_pairs);
Jasmine Chaa314e192018-05-09 17:46:28 +08003442 value = (char*)calloc(len + 1, sizeof(char));
jasmine chac89321b2018-04-10 21:37:01 +08003443 if (value == NULL) {
3444 ret = -ENOMEM;
Jasmine Chaa314e192018-05-09 17:46:28 +08003445 ALOGE("[%s] failed to allocate memory", __func__);
jasmine chac89321b2018-04-10 21:37:01 +08003446 goto done;
3447 }
3448
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003449 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME,
jasmine chac89321b2018-04-10 21:37:01 +08003450 value, len);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003451 if (err >= 0) {
3452 str_parms_del(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME);
3453 my_data->snd_card_name = strdup(value);
3454 ALOGV("%s: sound card name %s", __func__, my_data->snd_card_name);
3455 }
3456
keunhui.park2f7306a2015-07-16 16:48:06 +09003457 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO,
jasmine chac89321b2018-04-10 21:37:01 +08003458 value, len);
keunhui.park2f7306a2015-07-16 16:48:06 +09003459 if (err >= 0) {
3460 struct operator_info *info;
3461 char *str = value;
3462 char *name;
3463
3464 str_parms_del(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO);
3465 info = (struct operator_info *)calloc(1, sizeof(struct operator_info));
3466 name = strtok(str, ";");
3467 info->name = strdup(name);
3468 info->mccmnc = strdup(str + strlen(name) + 1);
3469
3470 list_add_tail(&operator_info_list, &info->list);
Joe Onorato188b6222016-03-01 11:02:27 -08003471 ALOGV("%s: add operator[%s] mccmnc[%s]", __func__, info->name, info->mccmnc);
keunhui.park2f7306a2015-07-16 16:48:06 +09003472 }
Prashant Malanic92c5962015-08-11 15:10:18 -07003473
Jasmine Chaa314e192018-05-09 17:46:28 +08003474 memset(value, 0, len + 1);
Eric Laurentc6333382015-09-14 12:43:44 -07003475 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT,
jasmine chac89321b2018-04-10 21:37:01 +08003476 value, len);
Prashant Malanic92c5962015-08-11 15:10:18 -07003477 if (err >= 0) {
Eric Laurentc6333382015-09-14 12:43:44 -07003478 str_parms_del(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT);
Prashant Malanic92c5962015-08-11 15:10:18 -07003479 my_data->max_mic_count = atoi(value);
3480 ALOGV("%s: max_mic_count %s/%d", __func__, value, my_data->max_mic_count);
Prashant Malanic92c5962015-08-11 15:10:18 -07003481 }
3482
jasmine chac89321b2018-04-10 21:37:01 +08003483 /* handle audio calibration parameters */
3484 set_audiocal(platform, parms, value, len);
3485
vivek mehta90933872017-06-15 18:04:39 -07003486 // to-do: disable setting sidetone gain, will revist this later
3487 // audio_extn_usb_set_sidetone_gain(parms, value, len);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003488done:
3489 ALOGV("%s: exit with code(%d)", __func__, ret);
3490 if (kv_pairs != NULL)
3491 free(kv_pairs);
jasmine chac89321b2018-04-10 21:37:01 +08003492 if (value != NULL)
3493 free(value);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003494
3495 return ret;
3496}
3497
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003498/* Delay in Us */
3499int64_t platform_render_latency(audio_usecase_t usecase)
3500{
3501 switch (usecase) {
3502 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
3503 return DEEP_BUFFER_PLATFORM_DELAY;
3504 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
3505 return LOW_LATENCY_PLATFORM_DELAY;
Haynes Mathew George03c40102016-01-29 17:57:48 -08003506 case USECASE_AUDIO_PLAYBACK_ULL:
3507 return ULL_PLATFORM_DELAY;
Eric Laurent0e46adf2016-12-16 12:49:24 -08003508 case USECASE_AUDIO_PLAYBACK_MMAP:
3509 return MMAP_PLATFORM_DELAY;
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003510 default:
3511 return 0;
3512 }
3513}
Haynes Mathew George98c95622014-06-20 19:14:25 -07003514
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003515int platform_set_snd_device_backend(snd_device_t device, const char *backend_tag,
3516 const char * hw_interface)
Haynes Mathew George98c95622014-06-20 19:14:25 -07003517{
3518 int ret = 0;
3519
3520 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
3521 ALOGE("%s: Invalid snd_device = %d",
3522 __func__, device);
3523 ret = -EINVAL;
3524 goto done;
3525 }
3526
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003527 ALOGV("%s: backend_tag_table[%s]: old = %s new = %s", __func__,
3528 platform_get_snd_device_name(device),
3529 backend_tag_table[device] != NULL ? backend_tag_table[device]: "null", backend_tag);
3530 if (backend_tag_table[device]) {
3531 free(backend_tag_table[device]);
Haynes Mathew George98c95622014-06-20 19:14:25 -07003532 }
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003533 backend_tag_table[device] = strdup(backend_tag);
3534
3535 if (hw_interface != NULL) {
3536 if (hw_interface_table[device])
3537 free(hw_interface_table[device]);
3538 ALOGV("%s: hw_interface_table[%d] = %s", __func__, device, hw_interface);
3539 hw_interface_table[device] = strdup(hw_interface);
3540 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07003541done:
3542 return ret;
3543}
3544
3545int platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t pcm_id)
3546{
3547 int ret = 0;
3548 if ((usecase <= USECASE_INVALID) || (usecase >= AUDIO_USECASE_MAX)) {
3549 ALOGE("%s: invalid usecase case idx %d", __func__, usecase);
3550 ret = -EINVAL;
3551 goto done;
3552 }
3553
3554 if ((type != 0) && (type != 1)) {
3555 ALOGE("%s: invalid usecase type", __func__);
3556 ret = -EINVAL;
3557 }
vivek mehtaa68fea62017-06-08 19:04:02 -07003558 ALOGV("%s: pcm_device_table[%d %s][%d] = %d", __func__, usecase,
3559 use_case_table[usecase],
3560 type, pcm_id);
Haynes Mathew George98c95622014-06-20 19:14:25 -07003561 pcm_device_table[usecase][type] = pcm_id;
3562done:
3563 return ret;
3564}
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003565
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07003566#define DEFAULT_NOMINAL_SPEAKER_GAIN 20
3567int ramp_speaker_gain(struct audio_device *adev, bool ramp_up, int target_ramp_up_gain) {
3568 // backup_gain: gain to try to set in case of an error during ramp
3569 int start_gain, end_gain, step, backup_gain, i;
3570 bool error = false;
3571 const struct mixer_ctl *ctl;
3572 const char *mixer_ctl_name_gain_left = "Left Speaker Gain";
3573 const char *mixer_ctl_name_gain_right = "Right Speaker Gain";
3574 struct mixer_ctl *ctl_left = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_left);
3575 struct mixer_ctl *ctl_right = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_right);
3576 if (!ctl_left || !ctl_right) {
3577 ALOGE("%s: Could not get ctl for mixer cmd - %s or %s, not applying speaker gain ramp",
3578 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
3579 return -EINVAL;
3580 } else if ((mixer_ctl_get_num_values(ctl_left) != 1)
3581 || (mixer_ctl_get_num_values(ctl_right) != 1)) {
3582 ALOGE("%s: Unexpected num values for mixer cmd - %s or %s, not applying speaker gain ramp",
3583 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
3584 return -EINVAL;
3585 }
3586 if (ramp_up) {
3587 start_gain = 0;
3588 end_gain = target_ramp_up_gain > 0 ? target_ramp_up_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
3589 step = +1;
3590 backup_gain = end_gain;
3591 } else {
3592 // using same gain on left and right
3593 const int left_gain = mixer_ctl_get_value(ctl_left, 0);
3594 start_gain = left_gain > 0 ? left_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
3595 end_gain = 0;
3596 step = -1;
3597 backup_gain = start_gain;
3598 }
3599 for (i = start_gain ; i != (end_gain + step) ; i += step) {
3600 //ALOGV("setting speaker gain to %d", i);
3601 if (mixer_ctl_set_value(ctl_left, 0, i)) {
3602 ALOGE("%s: error setting %s to %d during gain ramp",
3603 __func__, mixer_ctl_name_gain_left, i);
3604 error = true;
3605 break;
3606 }
3607 if (mixer_ctl_set_value(ctl_right, 0, i)) {
3608 ALOGE("%s: error setting %s to %d during gain ramp",
3609 __func__, mixer_ctl_name_gain_right, i);
3610 error = true;
3611 break;
3612 }
3613 usleep(1000);
3614 }
3615 if (error) {
3616 // an error occured during the ramp, let's still try to go back to a safe volume
3617 if (mixer_ctl_set_value(ctl_left, 0, backup_gain)) {
3618 ALOGE("%s: error restoring left gain to %d", __func__, backup_gain);
3619 }
3620 if (mixer_ctl_set_value(ctl_right, 0, backup_gain)) {
3621 ALOGE("%s: error restoring right gain to %d", __func__, backup_gain);
3622 }
3623 }
3624 return start_gain;
3625}
3626
vivek mehtae59cfb22017-06-16 15:57:11 -07003627int platform_set_swap_mixer(struct audio_device *adev, bool swap_channels)
3628{
3629 const char *mixer_ctl_name = "Swap channel";
3630 struct mixer_ctl *ctl;
3631 const char *mixer_path;
3632 struct platform_data *my_data = (struct platform_data *)adev->platform;
3633
3634 // forced to set to swap, but device not rotated ... ignore set
3635 if (swap_channels && !my_data->speaker_lr_swap)
3636 return 0;
3637
3638 ALOGV("%s:", __func__);
3639
3640 if (swap_channels) {
3641 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER_REVERSE);
3642 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
3643 } else {
3644 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER);
3645 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
3646 }
3647
3648 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3649 if (!ctl) {
3650 ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name);
3651 return -EINVAL;
3652 }
3653
3654 if (mixer_ctl_set_value(ctl, 0, swap_channels) < 0) {
3655 ALOGE("%s: Could not set reverse cotrol %d",__func__, swap_channels);
3656 return -EINVAL;
3657 }
3658
3659 ALOGV("platfor_force_swap_channel :: Channel orientation ( %s ) ",
3660 swap_channels?"R --> L":"L --> R");
3661
3662 return 0;
3663}
3664
3665int platform_check_and_set_swap_lr_channels(struct audio_device *adev, bool swap_channels)
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003666{
3667 // only update if there is active pcm playback on speaker
3668 struct audio_usecase *usecase;
3669 struct listnode *node;
3670 struct platform_data *my_data = (struct platform_data *)adev->platform;
3671
vivek mehtae59cfb22017-06-16 15:57:11 -07003672 my_data->speaker_lr_swap = swap_channels;
Jean-Michel Trivif7148702016-09-16 18:23:05 -07003673
vivek mehtae59cfb22017-06-16 15:57:11 -07003674 return platform_set_swap_channels(adev, swap_channels);
3675}
Jean-Michel Trivif7148702016-09-16 18:23:05 -07003676
vivek mehtae59cfb22017-06-16 15:57:11 -07003677int platform_set_swap_channels(struct audio_device *adev, bool swap_channels)
3678{
3679 // only update if there is active pcm playback on speaker
3680 struct audio_usecase *usecase;
3681 struct listnode *node;
3682 struct platform_data *my_data = (struct platform_data *)adev->platform;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003683
vivek mehtae59cfb22017-06-16 15:57:11 -07003684 // do not swap channels in audio modes with concurrent capture and playback
3685 // as this may break the echo reference
3686 if ((adev->mode == AUDIO_MODE_IN_COMMUNICATION) || (adev->mode == AUDIO_MODE_IN_CALL)) {
3687 ALOGV("%s: will not swap due to audio mode %d", __func__, adev->mode);
3688 return 0;
3689 }
3690
3691 list_for_each(node, &adev->usecase_list) {
3692 usecase = node_to_item(node, struct audio_usecase, list);
3693 if (usecase->type == PCM_PLAYBACK &&
3694 usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) {
3695 /*
3696 * If acdb tuning is different for SPEAKER_REVERSE, it is must
3697 * to perform device switch to disable the current backend to
3698 * enable it with new acdb data.
3699 */
3700 if (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
3701 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]) {
3702 const int initial_skpr_gain = ramp_speaker_gain(adev, false /*ramp_up*/, -1);
3703 select_devices(adev, usecase->id);
3704 if (initial_skpr_gain != -EINVAL)
3705 ramp_speaker_gain(adev, true /*ramp_up*/, initial_skpr_gain);
3706
3707 } else {
3708 platform_set_swap_mixer(adev, swap_channels);
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003709 }
vivek mehtae59cfb22017-06-16 15:57:11 -07003710 break;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003711 }
3712 }
vivek mehtae59cfb22017-06-16 15:57:11 -07003713
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003714 return 0;
3715}
vivek mehtaa8d7c922016-05-25 14:40:44 -07003716
3717static struct amp_db_and_gain_table tbl_mapping[MAX_VOLUME_CAL_STEPS];
3718static int num_gain_tbl_entry = 0;
3719
3720bool platform_add_gain_level_mapping(struct amp_db_and_gain_table *tbl_entry) {
3721
3722 ALOGV("%s: enter .. add %f %f %d", __func__, tbl_entry->amp, tbl_entry->db, tbl_entry->level);
3723 if (num_gain_tbl_entry == -1) {
3724 ALOGE("%s: num entry beyond valid step levels or corrupted..rejecting custom mapping",
3725 __func__);
3726 return false;
3727 }
3728
3729 if (num_gain_tbl_entry >= MAX_VOLUME_CAL_STEPS) {
3730 ALOGE("%s: max entry reached max[%d] current index[%d] .. rejecting", __func__,
3731 MAX_VOLUME_CAL_STEPS, num_gain_tbl_entry);
3732 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
3733 return false;
3734 }
3735
3736 if (num_gain_tbl_entry > 0 && tbl_mapping[num_gain_tbl_entry - 1].amp >= tbl_entry->amp) {
3737 ALOGE("%s: value not in ascending order .. rejecting custom mapping", __func__);
3738 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
3739 return false;
3740 }
3741
3742 tbl_mapping[num_gain_tbl_entry] = *tbl_entry;
3743 ++num_gain_tbl_entry;
3744
3745 return true;
3746}
3747
3748int platform_get_gain_level_mapping(struct amp_db_and_gain_table *mapping_tbl,
3749 int table_size) {
3750 int itt = 0;
3751 ALOGV("platform_get_gain_level_mapping called ");
3752
3753 if (num_gain_tbl_entry <= 0 || num_gain_tbl_entry > MAX_VOLUME_CAL_STEPS) {
3754 ALOGD("%s: empty or currupted gain_mapping_table", __func__);
3755 return 0;
3756 }
3757
3758 for (; itt < num_gain_tbl_entry && itt <= table_size; itt++) {
3759 mapping_tbl[itt] = tbl_mapping[itt];
3760 ALOGV("%s: added amp[%f] db[%f] level[%d]", __func__,
3761 mapping_tbl[itt].amp, mapping_tbl[itt].db, mapping_tbl[itt].level);
3762 }
3763
3764 return num_gain_tbl_entry;
3765}
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07003766
3767int platform_snd_card_update(void *platform, card_status_t status)
3768{
3769 struct platform_data *my_data = (struct platform_data *)platform;
3770 struct audio_device *adev = my_data->adev;
3771
3772 if (status == CARD_STATUS_ONLINE) {
3773 if (my_data->acdb_send_custom_top)
3774 my_data->acdb_send_custom_top();
3775 }
3776 return 0;
3777}
David Linee3fe402017-03-13 10:00:42 -07003778
3779/*
3780 * configures afe with bit width and Sample Rate
3781 */
Haynes Mathew George65f6b432018-02-27 17:44:55 -08003782int platform_set_backend_cfg(const struct audio_device* adev,
3783 snd_device_t snd_device,
3784 const struct audio_backend_cfg *backend_cfg)
David Linee3fe402017-03-13 10:00:42 -07003785{
3786
3787 int ret = 0;
3788 const int backend_idx = platform_get_backend_index(snd_device);
3789 struct platform_data *my_data = (struct platform_data *)adev->platform;
3790 const unsigned int bit_width = backend_cfg->bit_width;
3791 const unsigned int sample_rate = backend_cfg->sample_rate;
3792 const unsigned int channels = backend_cfg->channels;
3793 const audio_format_t format = backend_cfg->format;
3794 const bool passthrough_enabled = backend_cfg->passthrough_enabled;
3795
3796
3797 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
3798 ", backend_idx %d device (%s)", __func__, bit_width,
3799 sample_rate, channels, backend_idx,
3800 platform_get_snd_device_name(snd_device));
3801
3802 if ((my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl) &&
3803 (bit_width != my_data->current_backend_cfg[backend_idx].bit_width)) {
3804
3805 struct mixer_ctl *ctl = NULL;
3806 ctl = mixer_get_ctl_by_name(adev->mixer,
3807 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
3808 if (!ctl) {
3809 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3810 __func__,
3811 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
3812 return -EINVAL;
3813 }
3814
3815 if (bit_width == 24) {
3816 if (format == AUDIO_FORMAT_PCM_24_BIT_PACKED)
3817 ret = mixer_ctl_set_enum_by_string(ctl, "S24_3LE");
3818 else
3819 ret = mixer_ctl_set_enum_by_string(ctl, "S24_LE");
3820 } else if (bit_width == 32) {
3821 ret = mixer_ctl_set_enum_by_string(ctl, "S32_LE");
3822 } else {
3823 ret = mixer_ctl_set_enum_by_string(ctl, "S16_LE");
3824 }
3825 if ( ret < 0) {
3826 ALOGE("%s:becf: afe: fail for %s mixer set to %d bit for %x format", __func__,
3827 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
3828 } else {
3829 my_data->current_backend_cfg[backend_idx].bit_width = bit_width;
3830 ALOGD("%s:becf: afe: %s mixer set to %d bit for %x format", __func__,
3831 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
3832 }
3833 /* set the ret as 0 and not pass back to upper layer */
3834 ret = 0;
3835 }
3836
3837 if (passthrough_enabled || ((my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl) &&
3838 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate))) {
3839 char *rate_str = NULL;
3840 struct mixer_ctl *ctl = NULL;
3841
3842 switch (sample_rate) {
3843 case 32000:
3844 if (passthrough_enabled) {
3845 rate_str = "KHZ_32";
3846 break;
3847 }
3848 case 8000:
3849 case 11025:
3850 case 16000:
3851 case 22050:
3852 case 48000:
3853 rate_str = "KHZ_48";
3854 break;
3855 case 44100:
3856 rate_str = "KHZ_44P1";
3857 break;
3858 case 64000:
3859 case 96000:
3860 rate_str = "KHZ_96";
3861 break;
3862 case 88200:
3863 rate_str = "KHZ_88P2";
3864 break;
3865 case 176400:
3866 rate_str = "KHZ_176P4";
3867 break;
3868 case 192000:
3869 rate_str = "KHZ_192";
3870 break;
3871 case 352800:
3872 rate_str = "KHZ_352P8";
3873 break;
3874 case 384000:
3875 rate_str = "KHZ_384";
3876 break;
3877 case 144000:
3878 if (passthrough_enabled) {
3879 rate_str = "KHZ_144";
3880 break;
3881 }
3882 default:
3883 rate_str = "KHZ_48";
3884 break;
3885 }
3886
3887 ctl = mixer_get_ctl_by_name(adev->mixer,
3888 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
3889 if(!ctl) {
3890 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3891 __func__,
3892 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
3893 return -EINVAL;
3894 }
3895
3896 ALOGD("%s:becf: afe: %s set to %s", __func__,
3897 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl, rate_str);
3898 mixer_ctl_set_enum_by_string(ctl, rate_str);
3899 my_data->current_backend_cfg[backend_idx].sample_rate = sample_rate;
3900 }
3901 if ((my_data->current_backend_cfg[backend_idx].channels_mixer_ctl) &&
3902 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
3903 struct mixer_ctl *ctl = NULL;
3904 char *channel_cnt_str = NULL;
3905
3906 switch (channels) {
3907 case 8:
3908 channel_cnt_str = "Eight"; break;
3909 case 7:
3910 channel_cnt_str = "Seven"; break;
3911 case 6:
3912 channel_cnt_str = "Six"; break;
3913 case 5:
3914 channel_cnt_str = "Five"; break;
3915 case 4:
3916 channel_cnt_str = "Four"; break;
3917 case 3:
3918 channel_cnt_str = "Three"; break;
3919 case 1:
3920 channel_cnt_str = "One"; break;
3921 case 2:
3922 default:
3923 channel_cnt_str = "Two"; break;
3924 }
3925
3926 ctl = mixer_get_ctl_by_name(adev->mixer,
3927 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
3928 if (!ctl) {
3929 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3930 __func__,
3931 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
3932 return -EINVAL;
3933 }
3934 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
3935 my_data->current_backend_cfg[backend_idx].channels = channels;
3936
3937 // skip EDID configuration for HDMI backend
3938
3939 ALOGD("%s:becf: afe: %s set to %s", __func__,
3940 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl,
3941 channel_cnt_str);
3942 }
3943
3944 // skip set ext_display format mixer control
3945 return ret;
3946}
3947
3948static int platform_get_snd_device_bit_width(snd_device_t snd_device)
3949{
3950 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
3951 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
3952 return CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3953 }
3954
3955 return backend_bit_width_table[snd_device];
3956}
3957
3958/*
3959 * return backend_idx on which voice call is active
3960 */
3961static int platform_get_voice_call_backend(struct audio_device* adev)
3962{
3963 struct audio_usecase *uc = NULL;
3964 struct listnode *node;
3965 snd_device_t out_snd_device = SND_DEVICE_NONE;
3966
3967 int backend_idx = -1;
3968
3969 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
3970 list_for_each(node, &adev->usecase_list) {
3971 uc = node_to_item(node, struct audio_usecase, list);
3972 if (uc && uc->type == VOICE_CALL && uc->stream.out) {
3973 out_snd_device = platform_get_output_snd_device(adev->platform,
3974 uc->stream.out->devices);
3975 backend_idx = platform_get_backend_index(out_snd_device);
3976 break;
3977 }
3978 }
3979 }
3980 return backend_idx;
3981}
3982
3983/*
3984 * goes through all the current usecases and picks the highest
3985 * bitwidth & samplerate
3986 */
3987static bool platform_check_capture_backend_cfg(struct audio_device* adev,
3988 int backend_idx,
3989 struct audio_backend_cfg *backend_cfg)
3990{
3991 bool backend_change = false;
3992 unsigned int bit_width;
3993 unsigned int sample_rate;
3994 unsigned int channels;
3995 struct platform_data *my_data = (struct platform_data *)adev->platform;
3996
3997 bit_width = backend_cfg->bit_width;
3998 sample_rate = backend_cfg->sample_rate;
3999 channels = backend_cfg->channels;
4000
4001 ALOGV("%s:txbecf: afe: Codec selected backend: %d current bit width: %d and "
4002 "sample rate: %d, channels %d",__func__,backend_idx, bit_width,
4003 sample_rate, channels);
4004
4005 // For voice calls use default configuration i.e. 16b/48K, only applicable to
4006 // default backend
4007 // force routing is not required here, caller will do it anyway
4008 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
4009 ALOGW("%s:txbecf: afe: Use default bw and sr for voice/voip calls and "
4010 "for unprocessed/camera source", __func__);
4011 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
4012 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4013 }
4014
4015 if (backend_idx == USB_AUDIO_TX_BACKEND) {
4016 audio_extn_usb_is_config_supported(&bit_width, &sample_rate, &channels, false);
4017 ALOGV("%s:txbecf: afe: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
4018 __func__, bit_width, sample_rate, channels);
4019 }
4020
4021 ALOGV("%s:txbecf: afe: Codec selected backend: %d updated bit width: %d and "
4022 "sample rate: %d", __func__, backend_idx, bit_width, sample_rate);
4023
4024 // Force routing if the expected bitwdith or samplerate
4025 // is not same as current backend comfiguration
4026 if ((bit_width != my_data->current_backend_cfg[backend_idx].bit_width) ||
4027 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate) ||
4028 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
4029 backend_cfg->bit_width = bit_width;
4030 backend_cfg->sample_rate= sample_rate;
4031 backend_cfg->channels = channels;
4032 backend_change = true;
4033 ALOGI("%s:txbecf: afe: Codec backend needs to be updated. new bit width: %d "
4034 "new sample rate: %d new channel: %d",
4035 __func__, backend_cfg->bit_width,
4036 backend_cfg->sample_rate, backend_cfg->channels);
4037 }
4038
4039 return backend_change;
4040}
4041
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004042static void pick_playback_cfg_for_uc(struct audio_device *adev,
4043 struct audio_usecase *usecase,
4044 snd_device_t snd_device,
4045 unsigned int *bit_width,
4046 unsigned int *sample_rate,
4047 unsigned int *channels)
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004048{
4049 int i =0;
4050 struct listnode *node;
4051 list_for_each(node, &adev->usecase_list) {
4052 struct audio_usecase *uc;
4053 uc = node_to_item(node, struct audio_usecase, list);
4054 struct stream_out *out = (struct stream_out*) uc->stream.out;
4055 if (uc->type == PCM_PLAYBACK && out && usecase != uc) {
4056 unsigned int out_channels = audio_channel_count_from_out_mask(out->channel_mask);
4057 ALOGV("%s:napb: (%d) - (%s)id (%d) sr %d bw "
4058 "(%d) ch (%d) device %s", __func__, i++, use_case_table[uc->id],
4059 uc->id, out->sample_rate,
4060 pcm_format_to_bits(out->config.format), out_channels,
4061 platform_get_snd_device_name(uc->out_snd_device));
4062
4063 if (platform_check_backends_match(snd_device, uc->out_snd_device)) {
4064 if (*bit_width < pcm_format_to_bits(out->config.format))
4065 *bit_width = pcm_format_to_bits(out->config.format);
4066 if (*sample_rate < out->sample_rate)
4067 *sample_rate = out->sample_rate;
4068 if (out->sample_rate < OUTPUT_SAMPLING_RATE_44100)
4069 *sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4070 if (*channels < out_channels)
4071 *channels = out_channels;
4072 }
4073 }
4074 }
4075 return;
4076}
4077
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004078static void headset_is_config_supported(unsigned int *bit_width,
4079 unsigned int *sample_rate,
4080 unsigned int *channels) {
4081 switch (*bit_width) {
4082 case 16:
4083 case 24:
4084 break;
4085 default:
4086 *bit_width = 16;
4087 break;
4088 }
4089
4090 if (*sample_rate > 192000) {
4091 *sample_rate = 192000;
4092 }
4093
4094 if (*channels > 2) {
4095 *channels = 2;
4096 }
4097}
4098
David Linee3fe402017-03-13 10:00:42 -07004099static bool platform_check_playback_backend_cfg(struct audio_device* adev,
4100 struct audio_usecase* usecase,
4101 snd_device_t snd_device,
4102 struct audio_backend_cfg *backend_cfg)
4103{
4104 bool backend_change = false;
David Linee3fe402017-03-13 10:00:42 -07004105 unsigned int bit_width;
4106 unsigned int sample_rate;
4107 unsigned int channels;
David Linee3fe402017-03-13 10:00:42 -07004108 int backend_idx = DEFAULT_CODEC_BACKEND;
Haynes Mathew George65f6b432018-02-27 17:44:55 -08004109 unsigned long service_interval = 0; // 0 is invalid
David Linee3fe402017-03-13 10:00:42 -07004110 struct platform_data *my_data = (struct platform_data *)adev->platform;
David Linee3fe402017-03-13 10:00:42 -07004111
4112 if (snd_device == SND_DEVICE_OUT_BT_SCO ||
4113 snd_device == SND_DEVICE_OUT_BT_SCO_WB) {
4114 backend_change = false;
4115 return backend_change;
4116 }
4117
4118 backend_idx = platform_get_backend_index(snd_device);
4119 bit_width = backend_cfg->bit_width;
4120 sample_rate = backend_cfg->sample_rate;
4121 channels = backend_cfg->channels;
4122
4123 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
4124 ", backend_idx %d usecase = %d device (%s)", __func__, bit_width,
4125 sample_rate, channels, backend_idx, usecase->id,
4126 platform_get_snd_device_name(snd_device));
4127
4128 if (backend_idx == platform_get_voice_call_backend(adev)) {
4129 ALOGW("%s:becf: afe:Use default bw and sr for voice/voip calls ",
4130 __func__);
4131 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
4132 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4133 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
4134 } else {
4135 /*
4136 * The backend should be configured at highest bit width and/or
4137 * sample rate amongst all playback usecases.
4138 * If the selected sample rate and/or bit width differ with
4139 * current backend sample rate and/or bit width, then, we set the
4140 * backend re-configuration flag.
4141 *
4142 * Exception: 16 bit playbacks is allowed through 16 bit/48/44.1 khz backend only
4143 */
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004144 pick_playback_cfg_for_uc(adev, usecase, snd_device,
4145 &bit_width,
4146 &sample_rate,
4147 &channels);
David Linee3fe402017-03-13 10:00:42 -07004148 }
4149
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004150 switch (backend_idx) {
4151 case USB_AUDIO_RX_BACKEND:
4152 audio_extn_usb_is_config_supported(&bit_width,
4153 &sample_rate, &channels, true);
Haynes Mathew George65f6b432018-02-27 17:44:55 -08004154 if (platform_get_usb_service_interval(adev->platform, true,
4155 &service_interval) == 0) {
4156 /* overwrite with best altset for this service interval */
4157 int ret =
4158 audio_extn_usb_altset_for_service_interval(true /*playback*/,
4159 service_interval,
4160 &bit_width,
4161 &sample_rate,
4162 &channels);
4163 if (ret < 0) {
4164 ALOGE("Failed to find altset for service interval %lu, skip reconfig",
4165 service_interval);
4166 return false;
4167 }
4168 }
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004169 ALOGV("%s: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
4170 __func__, bit_width, sample_rate, channels);
4171 break;
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004172 case HEADPHONE_BACKEND:
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004173 headset_is_config_supported(&bit_width, &sample_rate, &channels);
4174 break;
4175 case DEFAULT_CODEC_BACKEND:
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004176 default:
4177 bit_width = platform_get_snd_device_bit_width(snd_device);
4178 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4179 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
4180 break;
David Linee3fe402017-03-13 10:00:42 -07004181 }
4182
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004183 ALOGV("%s:becf: afe: Codec selected backend: %d updated bit width: %d and"
4184 "sample rate: %d",
David Linee3fe402017-03-13 10:00:42 -07004185 __func__, backend_idx , bit_width, sample_rate);
4186
4187 // Force routing if the expected bitwdith or samplerate
4188 // is not same as current backend comfiguration
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004189 if (bit_width != my_data->current_backend_cfg[backend_idx].bit_width ||
4190 sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate ||
4191 channels != my_data->current_backend_cfg[backend_idx].channels) {
David Linee3fe402017-03-13 10:00:42 -07004192 backend_cfg->bit_width = bit_width;
4193 backend_cfg->sample_rate = sample_rate;
4194 backend_cfg->channels = channels;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004195 backend_cfg->passthrough_enabled = false;
David Linee3fe402017-03-13 10:00:42 -07004196 backend_change = true;
4197 ALOGV("%s:becf: afe: Codec backend needs to be updated. new bit width: %d"
4198 "new sample rate: %d new channels: %d",
4199 __func__, backend_cfg->bit_width, backend_cfg->sample_rate, backend_cfg->channels);
4200 }
4201
4202 return backend_change;
4203}
4204
4205bool platform_check_and_set_playback_backend_cfg(struct audio_device* adev,
4206 struct audio_usecase *usecase, snd_device_t snd_device)
4207{
4208 int backend_idx = DEFAULT_CODEC_BACKEND;
4209 int new_snd_devices[SND_DEVICE_OUT_END];
4210 int i, num_devices = 1;
4211 bool ret = false;
4212 struct platform_data *my_data = (struct platform_data *)adev->platform;
4213 struct audio_backend_cfg backend_cfg;
4214
4215 backend_idx = platform_get_backend_index(snd_device);
4216
4217 backend_cfg.bit_width = pcm_format_to_bits(usecase->stream.out->config.format);
4218 backend_cfg.sample_rate = usecase->stream.out->sample_rate;
4219 backend_cfg.format = usecase->stream.out->format;
4220 backend_cfg.channels = audio_channel_count_from_out_mask(usecase->stream.out->channel_mask);
4221 /*this is populated by check_codec_backend_cfg hence set default value to false*/
4222 backend_cfg.passthrough_enabled = false;
4223
4224 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
4225 ", backend_idx %d usecase = %d device (%s)", __func__, backend_cfg.bit_width,
4226 backend_cfg.sample_rate, backend_cfg.channels, backend_idx, usecase->id,
4227 platform_get_snd_device_name(snd_device));
4228
4229 if (platform_can_split_snd_device(snd_device, &num_devices, new_snd_devices) < 0)
4230 new_snd_devices[0] = snd_device;
4231
4232 for (i = 0; i < num_devices; i++) {
4233 ALOGV("%s: new_snd_devices[%d] is %d", __func__, i, new_snd_devices[i]);
4234 if ((platform_check_playback_backend_cfg(adev, usecase, new_snd_devices[i],
4235 &backend_cfg))) {
4236 platform_set_backend_cfg(adev, new_snd_devices[i],
4237 &backend_cfg);
4238 ret = true;
4239 }
4240 }
4241 return ret;
4242}
4243
4244bool platform_check_and_set_capture_backend_cfg(struct audio_device* adev,
4245 struct audio_usecase *usecase, snd_device_t snd_device)
4246{
4247 int backend_idx = platform_get_backend_index(snd_device);
4248 int ret = 0;
4249 struct audio_backend_cfg backend_cfg;
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004250 memset(&backend_cfg, 0, sizeof(struct audio_backend_cfg));
David Linee3fe402017-03-13 10:00:42 -07004251
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004252 if (usecase->type == PCM_CAPTURE) {
4253 backend_cfg.format = usecase->stream.in->format;
David Linee3fe402017-03-13 10:00:42 -07004254 backend_cfg.channels = audio_channel_count_from_in_mask(usecase->stream.in->channel_mask);
4255 } else {
4256 backend_cfg.bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
4257 backend_cfg.sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4258 backend_cfg.format = AUDIO_FORMAT_PCM_16_BIT;
4259 backend_cfg.channels = 1;
4260 }
4261
4262 ALOGV("%s:txbecf: afe: bitwidth %d, samplerate %d, channel %d"
4263 ", backend_idx %d usecase = %d device (%s)", __func__,
4264 backend_cfg.bit_width,
4265 backend_cfg.sample_rate,
4266 backend_cfg.channels,
4267 backend_idx, usecase->id,
4268 platform_get_snd_device_name(snd_device));
4269
4270 if (platform_check_capture_backend_cfg(adev, backend_idx, &backend_cfg)) {
4271 ret = platform_set_backend_cfg(adev, snd_device,
4272 &backend_cfg);
4273 if(!ret)
4274 return true;
4275 }
4276
4277 return false;
4278}
4279
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004280static int max_be_dai_names = 0;
4281static const struct be_dai_name_struct *be_dai_name_table;
4282
4283/*
4284 * Retrieves the be_dai_name_table from kernel to enable a mapping
4285 * between sound device hw interfaces and backend IDs. This allows HAL to
4286 * specify the backend a specific calibration is needed for.
4287 */
4288static int init_be_dai_name_table(struct audio_device *adev)
4289{
4290 const char *mixer_ctl_name = "Backend DAI Name Table";
4291 struct mixer_ctl *ctl;
4292 int i, j, ret, size;
4293 bool valid_hw_interface;
4294
4295 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
4296 if (!ctl) {
4297 ALOGE("%s: Could not get ctl for mixer name %s\n",
4298 __func__, mixer_ctl_name);
4299 ret = -EINVAL;
4300 goto done;
4301 }
4302
4303 mixer_ctl_update(ctl);
4304
4305 size = mixer_ctl_get_num_values(ctl);
4306 if (size <= 0){
4307 ALOGE("%s: Failed to get %s size %d\n",
4308 __func__, mixer_ctl_name, size);
4309 ret = -EFAULT;
4310 goto done;
4311 }
4312
vivek mehtaa68fea62017-06-08 19:04:02 -07004313 be_dai_name_table =
4314 (const struct be_dai_name_struct *)calloc(1, size);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004315 if (be_dai_name_table == NULL) {
4316 ALOGE("%s: Failed to allocate memory for %s\n",
4317 __func__, mixer_ctl_name);
4318 ret = -ENOMEM;
4319 goto freeMem;
4320 }
4321
4322 ret = mixer_ctl_get_array(ctl, (void *)be_dai_name_table, size);
4323 if (ret) {
4324 ALOGE("%s: Failed to get %s, ret %d\n",
4325 __func__, mixer_ctl_name, ret);
4326 ret = -EFAULT;
4327 goto freeMem;
4328 }
4329
4330 if (be_dai_name_table != NULL) {
4331 max_be_dai_names = size / sizeof(struct be_dai_name_struct);
4332 ALOGV("%s: Successfully got %s, number of be dais is %d\n",
4333 __func__, mixer_ctl_name, max_be_dai_names);
4334 ret = 0;
4335 } else {
4336 ALOGE("%s: Failed to get %s\n", __func__, mixer_ctl_name);
4337 ret = -EFAULT;
4338 goto freeMem;
4339 }
4340
4341 /*
4342 * Validate all sound devices have a valid backend set to catch
4343 * errors for uncommon sound devices
4344 */
4345 for (i = 0; i < SND_DEVICE_MAX; i++) {
4346 valid_hw_interface = false;
4347
4348 if (hw_interface_table[i] == NULL) {
4349 ALOGW("%s: sound device %s has no hw interface set\n",
4350 __func__, platform_get_snd_device_name(i));
4351 continue;
4352 }
4353
4354 for (j = 0; j < max_be_dai_names; j++) {
4355 if (strcmp(hw_interface_table[i], be_dai_name_table[j].be_name)
4356 == 0) {
4357 valid_hw_interface = true;
4358 break;
4359 }
4360 }
4361 if (!valid_hw_interface)
4362 ALOGD("%s: sound device %s does not have a valid hw interface set "
4363 "(disregard for combo devices) %s\n",
4364 __func__, platform_get_snd_device_name(i),
4365 hw_interface_table[i]);
4366 }
4367
4368 goto done;
4369
4370freeMem:
4371 if (be_dai_name_table) {
4372 free((void *)be_dai_name_table);
4373 be_dai_name_table = NULL;
4374 }
4375
4376done:
4377 return ret;
4378}
4379
4380int platform_get_snd_device_backend_index(snd_device_t device)
4381{
4382 int i, be_dai_id;
4383 const char * hw_interface_name = NULL;
4384
4385 ALOGV("%s: enter with device %d\n", __func__, device);
4386
vivek mehtaa68fea62017-06-08 19:04:02 -07004387 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004388 ALOGE("%s: Invalid snd_device = %d",
4389 __func__, device);
4390 be_dai_id = -EINVAL;
4391 goto done;
4392 }
4393
4394 /* Get string value of necessary backend for device */
4395 hw_interface_name = hw_interface_table[device];
4396 if (hw_interface_name == NULL) {
4397 ALOGE("%s: no hw_interface set for device %d\n", __func__, device);
4398 be_dai_id = -EINVAL;
4399 goto done;
4400 }
4401
4402 /* Check if be dai name table was retrieved successfully */
4403 if (be_dai_name_table == NULL) {
4404 ALOGE("%s: BE DAI Name Table is not present\n", __func__);
4405 be_dai_id = -EFAULT;
4406 goto done;
4407 }
4408
4409 /* Get backend ID for device specified */
4410 for (i = 0; i < max_be_dai_names; i++) {
4411 if (strcmp(hw_interface_name, be_dai_name_table[i].be_name) == 0) {
4412 be_dai_id = be_dai_name_table[i].be_id;
4413 goto done;
4414 }
4415 }
4416 ALOGE("%s: no interface matching name %s\n", __func__, hw_interface_name);
4417 be_dai_id = -EINVAL;
4418 goto done;
4419
4420done:
4421 return be_dai_id;
4422}
4423
4424void platform_check_and_update_copp_sample_rate(void* platform, snd_device_t snd_device,
4425 unsigned int stream_sr, int* sample_rate)
4426{
4427 struct platform_data* my_data = (struct platform_data *)platform;
4428 int backend_idx = platform_get_backend_index(snd_device);
4429 int device_sr = my_data->current_backend_cfg[backend_idx].sample_rate;
4430 /*
4431 *Check if device SR is multiple of 8K or 11.025 Khz
4432 *check if the stream SR is multiple of same base, if yes
4433 *then have copp SR equal to stream SR, this ensures that
4434 *post processing happens at stream SR, else have
4435 *copp SR equal to device SR.
4436 */
4437 if (!(((sample_rate_multiple(device_sr, SAMPLE_RATE_8000)) &&
4438 (sample_rate_multiple(stream_sr, SAMPLE_RATE_8000))) ||
4439 ((sample_rate_multiple(device_sr, SAMPLE_RATE_11025)) &&
4440 (sample_rate_multiple(stream_sr, SAMPLE_RATE_11025))))) {
4441 *sample_rate = device_sr;
4442 } else
4443 *sample_rate = stream_sr;
4444
4445 ALOGI("sn_device %d device sr %d stream sr %d copp sr %d", snd_device, device_sr, stream_sr
4446 , *sample_rate);
4447
4448}
4449
4450// called from info parser
vivek mehtaa68fea62017-06-08 19:04:02 -07004451void platform_add_app_type(const char *uc_type,
4452 const char *mode,
4453 int bw,
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004454 int app_type, int max_rate) {
4455 struct app_type_entry *ap =
4456 (struct app_type_entry *)calloc(1, sizeof(struct app_type_entry));
4457
4458 if (!ap) {
4459 ALOGE("%s failed to allocate mem for app type", __func__);
4460 return;
4461 }
4462
4463 ap->uc_type = -1;
4464 for (int i=0; i<USECASE_TYPE_MAX; i++) {
4465 if (!strcmp(uc_type, usecase_type_index[i].name)) {
4466 ap->uc_type = usecase_type_index[i].index;
4467 break;
4468 }
4469 }
4470
4471 if (ap->uc_type == -1) {
4472 free(ap);
4473 return;
4474 }
4475
vivek mehtaa68fea62017-06-08 19:04:02 -07004476 ALOGI("%s uc %s mode %s bw %d app_type %d max_rate %d",
4477 __func__, uc_type, mode, bw, app_type, max_rate);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004478 ap->bit_width = bw;
4479 ap->app_type = app_type;
4480 ap->max_rate = max_rate;
vivek mehtaa68fea62017-06-08 19:04:02 -07004481 ap->mode = strdup(mode);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004482 list_add_tail(&app_type_entry_list, &ap->node);
4483}
4484
4485
4486int platform_get_default_app_type_v2(void *platform __unused,
4487 usecase_type_t type,
4488 int *app_type )
4489{
4490 if (type == PCM_PLAYBACK)
4491 *app_type = DEFAULT_APP_TYPE_RX_PATH;
4492 else
4493 *app_type = DEFAULT_APP_TYPE_TX_PATH;
4494 return 0;
4495}
4496
vivek mehtaa68fea62017-06-08 19:04:02 -07004497int platform_get_app_type_v2(void *platform,
4498 usecase_type_t uc_type,
4499 const char *mode,
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004500 int bw, int sr __unused,
4501 int *app_type)
4502{
4503 struct listnode *node;
4504 struct app_type_entry *entry;
4505 *app_type = -1;
vivek mehtaa68fea62017-06-08 19:04:02 -07004506
4507 ALOGV("%s find match for uc %d mode %s bw %d rate %d",
4508 __func__, uc_type, mode, bw, sr);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004509 list_for_each(node, &app_type_entry_list) {
4510 entry = node_to_item(node, struct app_type_entry, node);
vivek mehtaa68fea62017-06-08 19:04:02 -07004511 ALOGV("%s uc %d mode %s bw %d app_type %d max_rate %d",
4512 __func__, entry->uc_type, entry->mode, entry->bit_width,
4513 entry->app_type, entry->max_rate);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004514 if (entry->bit_width == bw &&
vivek mehtaa68fea62017-06-08 19:04:02 -07004515 entry->uc_type == uc_type &&
4516 sr <= entry->max_rate &&
4517 entry->mode && !strcmp(mode, entry->mode)) {
4518 ALOGV("%s found match %d", __func__, entry->app_type);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004519 *app_type = entry->app_type;
4520 break;
4521 }
4522 }
4523
4524 if (*app_type == -1) {
vivek mehtaa68fea62017-06-08 19:04:02 -07004525 ALOGV("%s no match found, return default", __func__);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004526 return platform_get_default_app_type_v2(platform, uc_type, app_type);
4527 }
4528 return 0;
4529}
vivek mehta90933872017-06-15 18:04:39 -07004530
4531int platform_set_sidetone(struct audio_device *adev,
4532 snd_device_t out_snd_device,
4533 bool enable, char *str)
4534{
4535 int ret;
4536 if (out_snd_device == SND_DEVICE_OUT_USB_HEADSET ||
4537 out_snd_device == SND_DEVICE_OUT_VOICE_USB_HEADSET) {
4538 ret = audio_extn_usb_enable_sidetone(out_snd_device, enable);
4539 if (ret)
4540 ALOGI("%s: usb device %d does not support device sidetone\n",
4541 __func__, out_snd_device);
4542 } else {
4543 ALOGV("%s: sidetone out device(%d) mixer cmd = %s\n",
4544 __func__, out_snd_device, str);
4545 if (enable)
4546 audio_route_apply_and_update_path(adev->audio_route, str);
4547 else
4548 audio_route_reset_and_update_path(adev->audio_route, str);
4549 }
4550 return 0;
4551}
Haynes Mathew George96483a22017-03-28 14:52:47 -07004552
4553int platform_get_mmap_data_fd(void *platform __unused, int fe_dev __unused, int dir __unused,
4554 int *fd __unused, uint32_t *size __unused)
4555{
Thierry Strudel07f96d12018-09-20 13:31:34 -07004556#if defined (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845) || (PLATFORM_SDM710) || (PLATFORM_SM8150)
Haynes Mathew George96483a22017-03-28 14:52:47 -07004557 struct platform_data *my_data = (struct platform_data *)platform;
4558 struct audio_device *adev = my_data->adev;
4559 int hw_fd = -1;
4560 char dev_name[128];
4561 struct snd_pcm_mmap_fd mmap_fd;
4562 memset(&mmap_fd, 0, sizeof(mmap_fd));
4563 mmap_fd.dir = dir;
4564 snprintf(dev_name, sizeof(dev_name), "/dev/snd/hwC%uD%u",
4565 adev->snd_card, HWDEP_FE_BASE+fe_dev);
4566 hw_fd = open(dev_name, O_RDONLY);
4567 if (hw_fd < 0) {
4568 ALOGE("fe hw dep node open %d/%d failed", adev->snd_card, fe_dev);
4569 return -1;
4570 }
4571 if (ioctl(hw_fd, SNDRV_PCM_IOCTL_MMAP_DATA_FD, &mmap_fd) < 0) {
4572 ALOGE("fe hw dep node ioctl failed");
4573 close(hw_fd);
4574 return -1;
4575 }
4576 *fd = mmap_fd.fd;
4577 *size = mmap_fd.size;
4578 close(hw_fd); // mmap_fd should still be valid
4579 return 0;
4580#else
4581 return -1;
4582#endif
4583}
Mikhail Naganov4ee6e3e2018-03-21 16:28:35 +00004584
4585bool platform_sound_trigger_usecase_needs_event(audio_usecase_t uc_id)
4586{
4587 bool needs_event = false;
4588
4589 switch (uc_id) {
4590 /* concurrent capture usecases which needs event */
4591 case USECASE_AUDIO_RECORD:
4592 case USECASE_AUDIO_RECORD_LOW_LATENCY:
4593 case USECASE_AUDIO_RECORD_MMAP:
4594 case USECASE_AUDIO_RECORD_HIFI:
4595 case USECASE_AUDIO_RECORD_VOIP:
4596 case USECASE_VOICEMMODE1_CALL:
4597 case USECASE_VOICEMMODE2_CALL:
4598 /* concurrent playback usecases that needs event */
4599 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
4600 case USECASE_AUDIO_PLAYBACK_OFFLOAD:
4601 needs_event = true;
4602 break;
4603 default:
4604 ALOGV("%s:usecase_id[%d] no need to raise event.", __func__, uc_id);
4605 }
4606 return needs_event;
4607}
4608
4609bool platform_snd_device_has_speaker(snd_device_t dev) {
4610 int num_devs = 2;
4611 snd_device_t split_devs[2] = {SND_DEVICE_NONE, SND_DEVICE_NONE};
4612 if (platform_can_split_snd_device(dev, &num_devs, split_devs) == 0) {
4613 return platform_snd_device_has_speaker(split_devs[0]) ||
4614 platform_snd_device_has_speaker(split_devs[1]);
4615 }
4616
4617 switch (dev) {
4618 case SND_DEVICE_OUT_SPEAKER:
4619 case SND_DEVICE_OUT_SPEAKER_SAFE:
4620 case SND_DEVICE_OUT_SPEAKER_REVERSE:
4621 case SND_DEVICE_OUT_SPEAKER_PROTECTED:
4622 case SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED:
4623 case SND_DEVICE_OUT_VOICE_SPEAKER_HFP:
4624 return true;
4625 default:
4626 break;
4627 }
4628 return false;
4629}
jiabin8962a4d2018-03-19 18:21:24 -07004630
4631bool platform_set_microphone_characteristic(void *platform,
4632 struct audio_microphone_characteristic_t mic) {
4633 struct platform_data *my_data = (struct platform_data *)platform;
4634 if (my_data->declared_mic_count >= AUDIO_MICROPHONE_MAX_COUNT) {
4635 ALOGE("mic number is more than maximum number");
4636 return false;
4637 }
4638 for (size_t ch = 0; ch < AUDIO_CHANNEL_COUNT_MAX; ch++) {
4639 mic.channel_mapping[ch] = AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED;
4640 }
4641 my_data->microphones[my_data->declared_mic_count++] = mic;
4642 return true;
4643}
4644
4645int platform_get_microphones(void *platform,
4646 struct audio_microphone_characteristic_t *mic_array,
4647 size_t *mic_count) {
4648 struct platform_data *my_data = (struct platform_data *)platform;
4649 if (mic_count == NULL) {
4650 return -EINVAL;
4651 }
4652 if (mic_array == NULL) {
4653 return -EINVAL;
4654 }
4655
4656 if (*mic_count == 0) {
4657 *mic_count = my_data->declared_mic_count;
4658 return 0;
4659 }
4660
4661 size_t max_mic_count = *mic_count;
4662 size_t actual_mic_count = 0;
4663 for (size_t i = 0; i < max_mic_count && i < my_data->declared_mic_count; i++) {
4664 mic_array[i] = my_data->microphones[i];
4665 actual_mic_count++;
4666 }
4667 *mic_count = actual_mic_count;
4668 return 0;
4669}
4670
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004671bool platform_set_microphone_map(void *platform, snd_device_t in_snd_device,
4672 const struct mic_info *info) {
4673 struct platform_data *my_data = (struct platform_data *)platform;
4674 if (in_snd_device < SND_DEVICE_IN_BEGIN || in_snd_device >= SND_DEVICE_IN_END) {
4675 ALOGE("%s: Sound device not valid", __func__);
4676 return false;
4677 }
4678 size_t m_count = my_data->mic_map[in_snd_device].mic_count++;
4679 if (m_count >= AUDIO_MICROPHONE_MAX_COUNT) {
4680 ALOGE("%s: Microphone count is greater than max allowed value", __func__);
4681 my_data->mic_map[in_snd_device].mic_count--;
4682 return false;
4683 }
4684 my_data->mic_map[in_snd_device].microphones[m_count] = *info;
4685 return true;
4686}
4687
4688int platform_get_active_microphones(void *platform, unsigned int channels,
4689 audio_usecase_t uc_id,
jiabin8962a4d2018-03-19 18:21:24 -07004690 struct audio_microphone_characteristic_t *mic_array,
4691 size_t *mic_count) {
4692 struct platform_data *my_data = (struct platform_data *)platform;
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004693 struct audio_usecase *usecase = get_usecase_from_list(my_data->adev, uc_id);
4694 if (mic_count == NULL || mic_array == NULL || usecase == NULL) {
jiabin8962a4d2018-03-19 18:21:24 -07004695 return -EINVAL;
4696 }
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004697 size_t max_mic_count = my_data->declared_mic_count;
jiabin8962a4d2018-03-19 18:21:24 -07004698 size_t actual_mic_count = 0;
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004699
4700 snd_device_t active_input_snd_device =
4701 platform_get_input_snd_device(platform, usecase->stream.in->device);
4702 if (active_input_snd_device == SND_DEVICE_NONE) {
4703 ALOGI("%s: No active microphones found", __func__);
4704 goto end;
4705 }
4706
4707 size_t active_mic_count = my_data->mic_map[active_input_snd_device].mic_count;
4708 struct mic_info *m_info = my_data->mic_map[active_input_snd_device].microphones;
4709
4710 for (size_t i = 0; i < active_mic_count; i++) {
4711 unsigned int channels_for_active_mic = channels;
4712 if (channels_for_active_mic > m_info[i].channel_count) {
4713 channels_for_active_mic = m_info[i].channel_count;
4714 }
4715 for (size_t j = 0; j < max_mic_count; j++) {
4716 if (strcmp(my_data->microphones[j].device_id,
4717 m_info[i].device_id) == 0) {
4718 mic_array[actual_mic_count] = my_data->microphones[j];
4719 for (size_t ch = 0; ch < channels_for_active_mic; ch++) {
4720 mic_array[actual_mic_count].channel_mapping[ch] =
4721 m_info[i].channel_mapping[ch];
4722 }
4723 actual_mic_count++;
4724 break;
jiabin8962a4d2018-03-19 18:21:24 -07004725 }
jiabin8962a4d2018-03-19 18:21:24 -07004726 }
4727 }
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004728end:
jiabin8962a4d2018-03-19 18:21:24 -07004729 *mic_count = actual_mic_count;
4730 return 0;
4731}
Haynes Mathew George65f6b432018-02-27 17:44:55 -08004732
4733int platform_set_usb_service_interval(void *platform,
4734 bool playback,
4735 unsigned long service_interval,
4736 bool *reconfig)
4737{
4738#if defined (USB_SERVICE_INTERVAL_ENABLED)
4739 struct platform_data *_platform = (struct platform_data *)platform;
4740 *reconfig = false;
4741 if (!playback) {
4742 ALOGE("%s not valid for capture", __func__);
4743 return -1;
4744 }
4745 const char *ctl_name = "USB_AUDIO_RX service_interval";
4746 struct mixer_ctl *ctl = mixer_get_ctl_by_name(_platform->adev->mixer,
4747 ctl_name);
4748 if (!ctl) {
4749 ALOGV("%s: could not get mixer %s", __func__, ctl_name);
4750 return -1;
4751 }
4752 if (mixer_ctl_get_value(ctl, 0) != (int)service_interval) {
4753 mixer_ctl_set_value(ctl, 0, service_interval);
4754 *reconfig = true;
4755 }
4756 return 0;
4757#else
4758 *reconfig = false;
4759 (void)platform;
4760 (void)playback;
4761 (void)service_interval;
4762 return -1;
4763#endif
4764}
4765
4766int platform_get_usb_service_interval(void *platform,
4767 bool playback,
4768 unsigned long *service_interval)
4769{
4770#if defined (USB_SERVICE_INTERVAL_ENABLED)
4771 struct platform_data *_platform = (struct platform_data *)platform;
4772 if (!playback) {
4773 ALOGE("%s not valid for capture", __func__);
4774 return -1;
4775 }
4776 const char *ctl_name = "USB_AUDIO_RX service_interval";
4777 struct mixer_ctl *ctl = mixer_get_ctl_by_name(_platform->adev->mixer,
4778 ctl_name);
4779 if (!ctl) {
4780 ALOGV("%s: could not get mixer %s", __func__, ctl_name);
4781 return -1;
4782 }
4783 *service_interval = mixer_ctl_get_value(ctl, 0);
4784 return 0;
4785#else
4786 (void)platform;
4787 (void)playback;
4788 (void)service_interval;
4789 return -1;
4790#endif
4791}
Ashish Jain1c849702018-05-11 20:11:55 +05304792
4793int platform_set_acdb_metainfo_key(void *platform __unused,
4794 char *name __unused,
4795 int key __unused)
4796{
4797 return -ENOSYS;
4798}