blob: 4a4e997875d26169b32d7d372f3434f952586ce4 [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>
yixuanjiang89bd2712018-08-15 17:43:11 +080033#if defined (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845) || (PLATFORM_SDM710)
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;
yixuanjiang89bd2712018-08-15 17:43:11 +0800146#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845) || (PLATFORM_SDM710)
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",
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500259 [SND_DEVICE_OUT_VOICE_LINE] = "voice-line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700260 [SND_DEVICE_OUT_HDMI] = "hdmi",
261 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi",
262 [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700263 [SND_DEVICE_OUT_BT_SCO_WB] = "bt-sco-headset-wb",
Aniket Kumar Lata26483012018-01-31 20:21:42 -0800264 [SND_DEVICE_OUT_BT_A2DP] = "bt-a2dp",
265 [SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] = "speaker-and-bt-a2dp",
Aniket Kumar Lata9723a962018-05-16 17:41:55 -0700266 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP] = "speaker-safe-and-bt-a2dp",
Eric Laurentb23d5282013-05-14 15:27:20 -0700267 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = "voice-handset-tmus",
268 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones",
269 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones",
270 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset",
vivek mehtaa6b79742017-03-09 15:40:43 -0800271 [SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = "voice-tty-full-usb",
272 [SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = "voice-tty-vco-usb",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700273 [SND_DEVICE_OUT_VOICE_TX] = "voice-tx",
juyuchen66c4ecf2018-08-06 15:39:34 +0800274 [SND_DEVICE_OUT_VOICE_MUSIC_TX] = "voice-music-tx",
David Linee3fe402017-03-13 10:00:42 -0700275 [SND_DEVICE_OUT_USB_HEADSET] = "usb-headset",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700276 [SND_DEVICE_OUT_VOICE_USB_HEADSET] = "usb-headset",
David Linee3fe402017-03-13 10:00:42 -0700277 [SND_DEVICE_OUT_USB_HEADPHONES] = "usb-headphones",
jasmine cha270b7762018-03-30 15:41:33 +0800278 [SND_DEVICE_OUT_USB_HEADSET_SPEC] = "usb-headset",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700279 [SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = "usb-headphones",
David Linee3fe402017-03-13 10:00:42 -0700280 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = "speaker-and-usb-headphones",
Haynes Mathew George9090bfb2017-05-31 11:44:50 -0700281 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] = "speaker-safe-and-usb-headphones",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700282 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = "speaker-protected",
283 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = "voice-speaker-protected",
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -0700284 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = "voice-speaker-hfp",
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -0800285 [SND_DEVICE_OUT_SPEAKER_AND_BT_SCO] = "speaker-and-bt-sco",
juyuchen5351ea62018-05-16 10:54:37 +0800286 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO] = "speaker-safe-and-bt-sco",
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -0800287 [SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB] = "speaker-and-bt-sco-wb",
juyuchen5351ea62018-05-16 10:54:37 +0800288 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB] = "speaker-safe-and-bt-sco-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700289
290 /* Capture sound devices */
291 [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700292 [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700293 [SND_DEVICE_IN_HANDSET_MIC_NS] = "handset-mic",
294 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = "handset-mic",
295 [SND_DEVICE_IN_HANDSET_DMIC] = "dmic-endfire",
296 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = "dmic-endfire",
297 [SND_DEVICE_IN_HANDSET_DMIC_NS] = "dmic-endfire",
298 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = "dmic-endfire",
299 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = "dmic-endfire",
300
301 [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
302 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "speaker-mic",
303 [SND_DEVICE_IN_SPEAKER_MIC_NS] = "speaker-mic",
304 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = "speaker-mic",
305 [SND_DEVICE_IN_SPEAKER_DMIC] = "speaker-dmic-endfire",
306 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = "speaker-dmic-endfire",
307 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = "speaker-dmic-endfire",
308 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = "speaker-dmic-endfire",
309 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = "speaker-dmic-endfire",
310
311 [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
Eric Laurentcefbbac2014-09-04 13:54:10 -0500312 [SND_DEVICE_IN_HEADSET_MIC_AEC] = "headset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700313
Eric Laurentb23d5282013-05-14 15:27:20 -0700314 [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic",
315 [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700316 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = "bt-sco-mic",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700317 [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700318 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = "bt-sco-mic-wb",
Eric Laurent57274392018-10-19 17:33:43 -0700319 [SND_DEVICE_IN_CAMCORDER_LANDSCAPE] = "camcorder-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700320
321 [SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef",
322 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = "voice-dmic-ef-tmus",
323 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
324 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = "voice-speaker-dmic-ef",
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -0700325 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = "voice-speaker-mic-hfp",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700326 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700327 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
328 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
329 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
vivek mehtaa6b79742017-03-09 15:40:43 -0800330 [SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = "voice-tty-full-usb-mic",
331 [SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = "voice-tty-hco-usb-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700332
Eric Laurentb23d5282013-05-14 15:27:20 -0700333 [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700334 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = "voice-rec-mic",
vivek mehta733c1df2016-04-04 15:09:24 -0700335 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = "voice-rec-mic",
vivek mehtaf3440682016-05-11 14:24:37 -0700336 [SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700337 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = "voice-rec-dmic-ef",
338 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence",
David Linee3fe402017-03-13 10:00:42 -0700339 [SND_DEVICE_IN_USB_HEADSET_MIC] = "usb-headset-mic",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700340 [SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] ="usb-headset-mic",
341 [SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = "usb-headset-mic",
342 [SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = "usb-headset-mic",
343 [SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = "usb-headset-mic",
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700344 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = "headset-mic",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700345
Ricardo Garcia9034bc42016-04-04 07:11:46 -0700346 [SND_DEVICE_IN_UNPROCESSED_MIC] = "unprocessed-mic",
vivek mehta0125e782016-06-16 18:03:11 -0700347 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = "unprocessed-stereo-mic",
348 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = "unprocessed-three-mic",
349 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = "unprocessed-quad-mic",
350 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = "unprocessed-headset-mic",
rago90fb9612015-12-02 11:37:53 -0800351
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700352 [SND_DEVICE_IN_VOICE_RX] = "voice-rx",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700353
Prashant Malanic92c5962015-08-11 15:10:18 -0700354 [SND_DEVICE_IN_THREE_MIC] = "three-mic",
355 [SND_DEVICE_IN_QUAD_MIC] = "quad-mic",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700356 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = "vi-feedback",
Prashant Malanic92c5962015-08-11 15:10:18 -0700357 [SND_DEVICE_IN_HANDSET_TMIC] = "three-mic",
358 [SND_DEVICE_IN_HANDSET_QMIC] = "quad-mic",
vivek mehta733c1df2016-04-04 15:09:24 -0700359 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = "three-mic",
360 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = "quad-mic",
Eric Laurent57274392018-10-19 17:33:43 -0700361 [SND_DEVICE_IN_CAMCORDER_INVERT_LANDSCAPE] = "camcorder-mic",
362 [SND_DEVICE_IN_CAMCORDER_PORTRAIT] = "camcorder-mic",
363 [SND_DEVICE_IN_CAMCORDER_SELFIE_LANDSCAPE] = "camcorder-mic",
364 [SND_DEVICE_IN_CAMCORDER_SELFIE_INVERT_LANDSCAPE] = "camcorder-mic",
365 [SND_DEVICE_IN_CAMCORDER_SELFIE_PORTRAIT] = "camcorder-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700366};
367
368/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700369static int acdb_device_table[SND_DEVICE_MAX] = {
Eric Laurentb23d5282013-05-14 15:27:20 -0700370 [SND_DEVICE_NONE] = -1,
371 [SND_DEVICE_OUT_HANDSET] = 7,
372 [SND_DEVICE_OUT_SPEAKER] = 15,
373 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 15,
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700374 [SND_DEVICE_OUT_SPEAKER_SAFE] = 15,
Eric Laurentb23d5282013-05-14 15:27:20 -0700375 [SND_DEVICE_OUT_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500376 [SND_DEVICE_OUT_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700377 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700378 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500379 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = 77,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700380 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = 77,
Ravi Kumar Alamanda235c3482014-08-21 17:32:44 -0700381 [SND_DEVICE_OUT_VOICE_HANDSET] = ACDB_ID_VOICE_HANDSET,
382 [SND_DEVICE_OUT_VOICE_SPEAKER] = ACDB_ID_VOICE_SPEAKER,
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500383 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = 53,
Eric Laurentb23d5282013-05-14 15:27:20 -0700384 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500385 [SND_DEVICE_OUT_VOICE_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700386 [SND_DEVICE_OUT_HDMI] = 18,
387 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 15,
388 [SND_DEVICE_OUT_BT_SCO] = 22,
juyuchen5351ea62018-05-16 10:54:37 +0800389 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO] = 14,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700390 [SND_DEVICE_OUT_BT_SCO_WB] = 39,
juyuchen5351ea62018-05-16 10:54:37 +0800391 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB] = 14,
Aniket Kumar Lata26483012018-01-31 20:21:42 -0800392 [SND_DEVICE_OUT_BT_A2DP] = 20,
393 [SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] = 14,
Aniket Kumar Lata9723a962018-05-16 17:41:55 -0700394 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP] = 14,
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700395 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = ACDB_ID_VOICE_HANDSET_TMUS,
Eric Laurentb23d5282013-05-14 15:27:20 -0700396 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
397 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
398 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
vivek mehtaa6b79742017-03-09 15:40:43 -0800399 [SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = 17,
400 [SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = 17,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700401 [SND_DEVICE_OUT_VOICE_TX] = 45,
juyuchen66c4ecf2018-08-06 15:39:34 +0800402 [SND_DEVICE_OUT_VOICE_MUSIC_TX] = 3,
David Linee3fe402017-03-13 10:00:42 -0700403 [SND_DEVICE_OUT_USB_HEADSET] = 45,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700404 [SND_DEVICE_OUT_VOICE_USB_HEADSET] = 45,
David Linee3fe402017-03-13 10:00:42 -0700405 [SND_DEVICE_OUT_USB_HEADPHONES] = 45,
jasmine cha270b7762018-03-30 15:41:33 +0800406 [SND_DEVICE_OUT_USB_HEADSET_SPEC] = 45,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700407 [SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = 45,
David Linee3fe402017-03-13 10:00:42 -0700408 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = 14,
Haynes Mathew George9090bfb2017-05-31 11:44:50 -0700409 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] = 14,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700410 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = 124,
411 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = 101,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700412 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = ACDB_ID_VOICE_SPEAKER,
Eric Laurentb23d5282013-05-14 15:27:20 -0700413
414 [SND_DEVICE_IN_HANDSET_MIC] = 4,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700415 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 106,
416 [SND_DEVICE_IN_HANDSET_MIC_NS] = 107,
417 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = 108,
418 [SND_DEVICE_IN_HANDSET_DMIC] = 41,
419 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = 109,
420 [SND_DEVICE_IN_HANDSET_DMIC_NS] = 110,
421 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = 111,
422 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = 34,
423
424 [SND_DEVICE_IN_SPEAKER_MIC] = 11,
425 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 112,
426 [SND_DEVICE_IN_SPEAKER_MIC_NS] = 113,
427 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = 114,
428 [SND_DEVICE_IN_SPEAKER_DMIC] = 43,
429 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = 115,
430 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = 116,
431 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = 117,
432 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = 35,
433
rago90fb9612015-12-02 11:37:53 -0800434 [SND_DEVICE_IN_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentcefbbac2014-09-04 13:54:10 -0500435 [SND_DEVICE_IN_HEADSET_MIC_AEC] = ACDB_ID_HEADSET_MIC_AEC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700436
Eric Laurentb23d5282013-05-14 15:27:20 -0700437 [SND_DEVICE_IN_HDMI_MIC] = 4,
438 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700439 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = 21,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700440 [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700441 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = 38,
Eric Laurent57274392018-10-19 17:33:43 -0700442 [SND_DEVICE_IN_CAMCORDER_LANDSCAPE] = 61,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700443
444 [SND_DEVICE_IN_VOICE_DMIC] = 41,
445 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = ACDB_ID_VOICE_DMIC_EF_TMUS,
446 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700447 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = 11,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700448 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 43,
rago90fb9612015-12-02 11:37:53 -0800449 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentb23d5282013-05-14 15:27:20 -0700450 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
451 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
452 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
vivek mehtaa6b79742017-03-09 15:40:43 -0800453 [SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = 16,
454 [SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = 16,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700455
rago90fb9612015-12-02 11:37:53 -0800456 [SND_DEVICE_IN_VOICE_REC_MIC] = ACDB_ID_VOICE_REC_MIC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700457 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = 113,
vivek mehta733c1df2016-04-04 15:09:24 -0700458 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = 112,
vivek mehtaf3440682016-05-11 14:24:37 -0700459 [SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = 114,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700460 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = 35,
461 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 43,
rago90fb9612015-12-02 11:37:53 -0800462 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
463
464 [SND_DEVICE_IN_UNPROCESSED_MIC] = ACDB_ID_VOICE_REC_MIC,
465 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
vivek mehta4ed66e62016-04-15 23:33:34 -0700466 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = 35,
467 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = 125,
468 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = 125,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700469
470 [SND_DEVICE_IN_VOICE_RX] = 44,
David Linee3fe402017-03-13 10:00:42 -0700471 [SND_DEVICE_IN_USB_HEADSET_MIC] = 44,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700472 [SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = 44,
473 [SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = 44,
474 [SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = 44,
475 [SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = 44,
Prashant Malanic92c5962015-08-11 15:10:18 -0700476 [SND_DEVICE_IN_THREE_MIC] = 46,
477 [SND_DEVICE_IN_QUAD_MIC] = 46,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700478 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = 102,
Prashant Malanic92c5962015-08-11 15:10:18 -0700479 [SND_DEVICE_IN_HANDSET_TMIC] = 125,
480 [SND_DEVICE_IN_HANDSET_QMIC] = 125,
vivek mehta733c1df2016-04-04 15:09:24 -0700481 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = 125, /* override this for new target to 140 */
482 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = 125, /* override this for new target to 140 */
Eric Laurent57274392018-10-19 17:33:43 -0700483 [SND_DEVICE_IN_CAMCORDER_INVERT_LANDSCAPE] = 61,
484 [SND_DEVICE_IN_CAMCORDER_PORTRAIT] = 61,
485 [SND_DEVICE_IN_CAMCORDER_SELFIE_LANDSCAPE] = 61,
486 [SND_DEVICE_IN_CAMCORDER_SELFIE_INVERT_LANDSCAPE] = 61,
487 [SND_DEVICE_IN_CAMCORDER_SELFIE_PORTRAIT] = 61,
Eric Laurentb23d5282013-05-14 15:27:20 -0700488};
489
David Linee3fe402017-03-13 10:00:42 -0700490// Platform specific backend bit width table
491static int backend_bit_width_table[SND_DEVICE_MAX] = {0};
492
Haynes Mathew George98c95622014-06-20 19:14:25 -0700493struct name_to_index {
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700494 char name[100];
495 unsigned int index;
496};
497
498#define TO_NAME_INDEX(X) #X, X
499
Haynes Mathew George98c95622014-06-20 19:14:25 -0700500/* Used to get index from parsed string */
501static const struct name_to_index snd_device_name_index[SND_DEVICE_MAX] = {
502 /* out */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700503 {TO_NAME_INDEX(SND_DEVICE_OUT_HANDSET)},
504 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER)},
505 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_REVERSE)},
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700506 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700507 {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500508 {TO_NAME_INDEX(SND_DEVICE_OUT_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700509 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700510 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES)},
Eric Laurent744996b2014-10-01 11:40:40 -0500511 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_LINE)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700512 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700513 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET)},
514 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700515 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_HFP)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700516 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500517 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700518 {TO_NAME_INDEX(SND_DEVICE_OUT_HDMI)},
519 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HDMI)},
520 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO)},
juyuchen5351ea62018-05-16 10:54:37 +0800521 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700522 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO_WB)},
juyuchen5351ea62018-05-16 10:54:37 +0800523 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB)},
Aniket Kumar Lata26483012018-01-31 20:21:42 -0800524 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_A2DP)},
525 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP)},
Aniket Kumar Lata9723a962018-05-16 17:41:55 -0700526 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700527 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET_TMUS)},
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500528 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HAC_HANDSET)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700529 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES)},
530 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES)},
531 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET)},
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -0800532 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_SCO)},
533 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800534 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_USB)},
535 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_USB)},
David Linee3fe402017-03-13 10:00:42 -0700536 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADSET)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700537 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_USB_HEADSET)},
David Linee3fe402017-03-13 10:00:42 -0700538 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADPHONES)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700539 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_USB_HEADPHONES)},
David Linee3fe402017-03-13 10:00:42 -0700540 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET)},
Haynes Mathew George9090bfb2017-05-31 11:44:50 -0700541 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700542 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED)},
543 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED)},
jasmine cha270b7762018-03-30 15:41:33 +0800544 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADSET_SPEC)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800545
546 /* in */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700547 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700548 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700549 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_NS)},
550 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)},
551 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC)},
552 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC)},
553 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_NS)},
554 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)},
555 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_STEREO)},
556
557 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700558 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700559 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_NS)},
560 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)},
561 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC)},
562 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC)},
563 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS)},
564 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)},
565 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_STEREO)},
566
567 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC)},
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700568 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700569
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700570 {TO_NAME_INDEX(SND_DEVICE_IN_HDMI_MIC)},
571 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700572 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700573 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700574 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB_NREC)},
Eric Laurent57274392018-10-19 17:33:43 -0700575 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_LANDSCAPE)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700576
577 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC)},
578 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC_TMUS)},
579 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700580 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700581 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC)},
582 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEADSET_MIC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700583 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC)},
584 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC)},
585 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800586 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC)},
587 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC)},
588
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700589
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700590 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700591 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_NS)},
vivek mehta733c1df2016-04-04 15:09:24 -0700592 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC)},
vivek mehtaf3440682016-05-11 14:24:37 -0700593 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700594 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_STEREO)},
595 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE)},
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700596 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_HEADSET_MIC)},
David Linee3fe402017-03-13 10:00:42 -0700597 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700598 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_USB_HEADSET_MIC)},
599 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC)},
600 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC)},
601 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC_AEC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700602
rago90fb9612015-12-02 11:37:53 -0800603 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_MIC)},
604 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC)},
vivek mehta4ed66e62016-04-15 23:33:34 -0700605 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_STEREO_MIC)},
606 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_THREE_MIC)},
607 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_QUAD_MIC)},
rago90fb9612015-12-02 11:37:53 -0800608
Prashant Malanic92c5962015-08-11 15:10:18 -0700609 {TO_NAME_INDEX(SND_DEVICE_IN_THREE_MIC)},
610 {TO_NAME_INDEX(SND_DEVICE_IN_QUAD_MIC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700611 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_VI_FEEDBACK)},
Prashant Malanic92c5962015-08-11 15:10:18 -0700612 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC)},
613 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC)},
vivek mehta733c1df2016-04-04 15:09:24 -0700614 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC_AEC)},
615 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC_AEC)},
Eric Laurent57274392018-10-19 17:33:43 -0700616 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_INVERT_LANDSCAPE)},
617 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_PORTRAIT)},
618 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_SELFIE_LANDSCAPE)},
619 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_SELFIE_INVERT_LANDSCAPE)},
620 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_SELFIE_PORTRAIT)},
621 /* For legacy xml file parsing */
622 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700623};
624
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700625static char * backend_tag_table[SND_DEVICE_MAX] = {0};
626static char * hw_interface_table[SND_DEVICE_MAX] = {0};
Haynes Mathew George98c95622014-06-20 19:14:25 -0700627
628static const struct name_to_index usecase_name_index[AUDIO_USECASE_MAX] = {
629 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_DEEP_BUFFER)},
630 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_LOW_LATENCY)},
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800631 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_HIFI)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700632 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD)},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700633 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_TTS)},
634 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_ULL)},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800635 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_MMAP)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700636 {TO_NAME_INDEX(USECASE_AUDIO_RECORD)},
637 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_LOW_LATENCY)},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800638 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_MMAP)},
Haynes Mathew George569b7482017-05-08 14:44:27 -0700639 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_HIFI)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700640 {TO_NAME_INDEX(USECASE_VOICE_CALL)},
641 {TO_NAME_INDEX(USECASE_VOICE2_CALL)},
642 {TO_NAME_INDEX(USECASE_VOLTE_CALL)},
643 {TO_NAME_INDEX(USECASE_QCHAT_CALL)},
644 {TO_NAME_INDEX(USECASE_VOWLAN_CALL)},
John Muirf1346ce2016-12-06 00:03:41 -0800645 {TO_NAME_INDEX(USECASE_VOICEMMODE1_CALL)},
646 {TO_NAME_INDEX(USECASE_VOICEMMODE2_CALL)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700647 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK)},
648 {TO_NAME_INDEX(USECASE_INCALL_REC_DOWNLINK)},
649 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK_AND_DOWNLINK)},
650 {TO_NAME_INDEX(USECASE_AUDIO_HFP_SCO)},
John Muirf1346ce2016-12-06 00:03:41 -0800651 {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_RX)},
652 {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_TX)},
653 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_AFE_PROXY)},
654 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_AFE_PROXY)},
655 {TO_NAME_INDEX(USECASE_AUDIO_DSM_FEEDBACK)},
vivek mehtaa68fea62017-06-08 19:04:02 -0700656 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_VOIP)},
657 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_VOIP)},
Nadav Bar3d72cfc2018-01-07 12:19:24 +0200658 {TO_NAME_INDEX(USECASE_INCALL_MUSIC_UPLINK)},
Aniket Kumar Lata99546312018-03-19 21:38:38 -0700659 {TO_NAME_INDEX(USECASE_AUDIO_A2DP_ABR_FEEDBACK)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700660};
661
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800662static const struct name_to_index usecase_type_index[USECASE_TYPE_MAX] = {
663 {TO_NAME_INDEX(PCM_PLAYBACK)},
664 {TO_NAME_INDEX(PCM_CAPTURE)},
665 {TO_NAME_INDEX(VOICE_CALL)},
666 {TO_NAME_INDEX(PCM_HFP_CALL)},
667};
668
669struct app_type_entry {
670 int uc_type;
671 int bit_width;
672 int app_type;
673 int max_rate;
vivek mehtaa68fea62017-06-08 19:04:02 -0700674 char *mode;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800675 struct listnode node; // membership in app_type_entry_list;
676};
677
678static struct listnode app_type_entry_list;
679
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700680#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
681#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
Eric Laurent0e46adf2016-12-16 12:49:24 -0800682#define ULL_PLATFORM_DELAY (3*1000LL)
683#define MMAP_PLATFORM_DELAY (3*1000LL)
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700684
Eric Laurentb23d5282013-05-14 15:27:20 -0700685static pthread_once_t check_op_once_ctl = PTHREAD_ONCE_INIT;
686static bool is_tmus = false;
687
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800688static int init_be_dai_name_table(struct audio_device *adev);
689
Eric Laurentb23d5282013-05-14 15:27:20 -0700690static void check_operator()
691{
692 char value[PROPERTY_VALUE_MAX];
693 int mccmnc;
694 property_get("gsm.sim.operator.numeric",value,"0");
695 mccmnc = atoi(value);
Eric Laurent2bafff12016-03-17 12:17:23 -0700696 ALOGD("%s: tmus mccmnc %d", __func__, mccmnc);
Eric Laurentb23d5282013-05-14 15:27:20 -0700697 switch(mccmnc) {
698 /* TMUS MCC(310), MNC(490, 260, 026) */
699 case 310490:
700 case 310260:
701 case 310026:
sangwon.jeonb891db52013-09-14 17:39:15 +0900702 /* Add new TMUS MNC(800, 660, 580, 310, 270, 250, 240, 230, 220, 210, 200, 160) */
703 case 310800:
704 case 310660:
705 case 310580:
706 case 310310:
707 case 310270:
708 case 310250:
709 case 310240:
710 case 310230:
711 case 310220:
712 case 310210:
713 case 310200:
714 case 310160:
Eric Laurentb23d5282013-05-14 15:27:20 -0700715 is_tmus = true;
716 break;
717 }
718}
719
720bool is_operator_tmus()
721{
722 pthread_once(&check_op_once_ctl, check_operator);
723 return is_tmus;
724}
725
keunhui.park2f7306a2015-07-16 16:48:06 +0900726static char *get_current_operator()
727{
728 struct listnode *node;
729 struct operator_info *info_item;
730 char mccmnc[PROPERTY_VALUE_MAX];
731 char *ret = NULL;
732
Tom Cherry7fea2042016-11-10 18:05:59 -0800733 property_get("gsm.sim.operator.numeric",mccmnc,"00000");
keunhui.park2f7306a2015-07-16 16:48:06 +0900734
735 list_for_each(node, &operator_info_list) {
736 info_item = node_to_item(node, struct operator_info, list);
737 if (strstr(info_item->mccmnc, mccmnc) != NULL) {
738 ret = info_item->name;
739 }
740 }
741
742 return ret;
743}
744
745static struct operator_specific_device *get_operator_specific_device(snd_device_t snd_device)
746{
747 struct listnode *node;
748 struct operator_specific_device *ret = NULL;
749 struct operator_specific_device *device_item;
750 char *operator_name;
751
752 operator_name = get_current_operator();
753 if (operator_name == NULL)
754 return ret;
755
756 list_for_each(node, operator_specific_device_table[snd_device]) {
757 device_item = node_to_item(node, struct operator_specific_device, list);
758 if (strcmp(operator_name, device_item->operator) == 0) {
759 ret = device_item;
760 }
761 }
762
763 return ret;
764}
765
766
767static int get_operator_specific_device_acdb_id(snd_device_t snd_device)
768{
769 struct operator_specific_device *device;
770 int ret = acdb_device_table[snd_device];
771
772 device = get_operator_specific_device(snd_device);
773 if (device != NULL)
774 ret = device->acdb_id;
775
776 return ret;
777}
778
779static const char *get_operator_specific_device_mixer_path(snd_device_t snd_device)
780{
781 struct operator_specific_device *device;
782 const char *ret = device_table[snd_device];
783
784 device = get_operator_specific_device(snd_device);
785 if (device != NULL)
786 ret = device->mixer_path;
787
788 return ret;
789}
790
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800791inline bool platform_supports_app_type_cfg()
792{
yixuanjiang89bd2712018-08-15 17:43:11 +0800793#if defined (PLATFORM_MSM8998) || (PLATFORM_SDM845) || (PLATFORM_SDM710)
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800794 return true;
795#else
796 return false;
797#endif
798}
799
jasmine chac89321b2018-04-10 21:37:01 +0800800static int parse_audiocal_cfg(struct str_parms *parms, acdb_audio_cal_cfg_t *cal)
801{
802 int err;
803 char value[64];
804 int ret = 0;
805
806 if (parms == NULL || cal == NULL)
807 return ret;
808
809 err = str_parms_get_str(parms, "cal_persist", value, sizeof(value));
810 if (err >= 0) {
811 str_parms_del(parms, "cal_persist");
812 cal->persist = (uint32_t)strtoul(value, NULL, 0);
813 ret = ret | 0x1;
814 }
815 err = str_parms_get_str(parms, "cal_apptype", value, sizeof(value));
816 if (err >= 0) {
817 str_parms_del(parms, "cal_apptype");
818 cal->app_type = (uint32_t)strtoul(value, NULL, 0);
819 ret = ret | 0x2;
820 }
821 err = str_parms_get_str(parms, "cal_caltype", value, sizeof(value));
822 if (err >= 0) {
823 str_parms_del(parms, "cal_caltype");
824 cal->cal_type = (uint32_t)strtoul(value, NULL, 0);
825 ret = ret | 0x4;
826 }
827 err = str_parms_get_str(parms, "cal_samplerate", value, sizeof(value));
828 if (err >= 0) {
829 str_parms_del(parms, "cal_samplerate");
830 cal->sampling_rate = (uint32_t)strtoul(value, NULL, 0);
831 ret = ret | 0x8;
832 }
833 err = str_parms_get_str(parms, "cal_devid", value, sizeof(value));
834 if (err >= 0) {
835 str_parms_del(parms, "cal_devid");
836 cal->dev_id = (uint32_t)strtoul(value, NULL, 0);
837 ret = ret | 0x10;
838 }
839 err = str_parms_get_str(parms, "cal_snddevid", value, sizeof(value));
840 if (err >= 0) {
841 str_parms_del(parms, "cal_snddevid");
842 cal->snd_dev_id = (uint32_t)strtoul(value, NULL, 0);
843 ret = ret | 0x20;
844 }
845 err = str_parms_get_str(parms, "cal_topoid", value, sizeof(value));
846 if (err >= 0) {
847 str_parms_del(parms, "cal_topoid");
848 cal->topo_id = (uint32_t)strtoul(value, NULL, 0);
849 ret = ret | 0x40;
850 }
851 err = str_parms_get_str(parms, "cal_moduleid", value, sizeof(value));
852 if (err >= 0) {
853 str_parms_del(parms, "cal_moduleid");
854 cal->module_id = (uint32_t)strtoul(value, NULL, 0);
855 ret = ret | 0x80;
856 }
857 err = str_parms_get_str(parms, "cal_paramid", value, sizeof(value));
858 if (err >= 0) {
859 str_parms_del(parms, "cal_paramid");
860 cal->param_id = (uint32_t)strtoul(value, NULL, 0);
861 ret = ret | 0x100;
862 }
863 return ret;
864}
865
866static void set_audiocal(void *platform, struct str_parms *parms, char *value, int len)
867{
868 struct platform_data *my_data = (struct platform_data *)platform;
869 acdb_audio_cal_cfg_t cal;
870 uint8_t *dptr = NULL;
871 int32_t dlen = 0;
872 int err ,ret;
873
874 if (value == NULL || platform == NULL || parms == NULL) {
875 ALOGE("[%s] received null pointer, failed", __func__);
876 goto done_key_audcal;
877 }
878
879 memset(&cal, 0, sizeof(acdb_audio_cal_cfg_t));
880 /* parse audio calibration keys */
881 ret = parse_audiocal_cfg(parms, &cal);
882
883 /* handle audio calibration data now */
884 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_AUD_CALDATA, value, len);
885 if (err >= 0) {
886 str_parms_del(parms, AUDIO_PARAMETER_KEY_AUD_CALDATA);
887 dlen = strlen(value);
888 if (dlen <= 0) {
889 ALOGE("[%s] null data received", __func__);
890 goto done_key_audcal;
891 }
892 /*
893 The base64 encoded string is always larger than the binary data,
894 so b64_pton will always output less data than provided (around 1/3
895 less than the input data). That's why we can allocate input buffer
896 length and then get function work.
897 */
898 dptr = (uint8_t *)calloc(dlen, sizeof(uint8_t));
899 if (dptr == NULL) {
900 ALOGE("[%s] memory allocation failed for %d", __func__, dlen);
901 goto done_key_audcal;
902 }
903 dlen = b64_pton(value, dptr, dlen);
904 if (dlen <= 0) {
905 ALOGE("[%s] data decoding failed %d", __func__, dlen);
906 goto done_key_audcal;
907 }
908
909 if (cal.dev_id) {
910 if (audio_is_input_device(cal.dev_id)) {
911 cal.snd_dev_id = platform_get_input_snd_device(platform, cal.dev_id);
912 } else {
913 cal.snd_dev_id = platform_get_output_snd_device(platform, cal.dev_id);
914 }
915 }
916 cal.acdb_dev_id = platform_get_snd_device_acdb_id(cal.snd_dev_id);
917 ALOGD("Setting audio calibration for snd_device(%d) acdb_id(%d)",
918 cal.snd_dev_id, cal.acdb_dev_id);
919 if (cal.acdb_dev_id == -EINVAL) {
920 ALOGE("[%s] Invalid acdb_device id %d for snd device id %d",
921 __func__, cal.acdb_dev_id, cal.snd_dev_id);
922 goto done_key_audcal;
923 }
924 if (my_data->acdb_set_audio_cal) {
925 ret = my_data->acdb_set_audio_cal((void *)&cal, (void *)dptr, dlen);
926 }
927 }
928done_key_audcal:
929 if (dptr != NULL)
930 free(dptr);
931}
932
vivek mehta1a9b7c02015-06-25 11:49:38 -0700933bool platform_send_gain_dep_cal(void *platform, int level)
934{
935 bool ret_val = false;
936 struct platform_data *my_data = (struct platform_data *)platform;
937 struct audio_device *adev = my_data->adev;
938 int acdb_dev_id, app_type;
939 int acdb_dev_type = MSM_SNDDEV_CAP_RX;
940 int mode = CAL_MODE_RTAC;
941 struct listnode *node;
942 struct audio_usecase *usecase;
Haynes Mathew George67486e22017-06-26 12:58:38 -0700943 bool valid_uc_type;
944 bool valid_dev;
vivek mehta1a9b7c02015-06-25 11:49:38 -0700945
946 if (my_data->acdb_send_gain_dep_cal == NULL) {
947 ALOGE("%s: dlsym error for acdb_send_gain_dep_cal", __func__);
948 return ret_val;
949 }
950
951 if (!voice_is_in_call(adev)) {
952 ALOGV("%s: Not Voice call usecase, apply new cal for level %d",
953 __func__, level);
vivek mehta1a9b7c02015-06-25 11:49:38 -0700954
955 // find the current active sound device
956 list_for_each(node, &adev->usecase_list) {
957 usecase = node_to_item(node, struct audio_usecase, list);
Haynes Mathew George67486e22017-06-26 12:58:38 -0700958 LOG_ALWAYS_FATAL_IF(usecase == NULL,
959 "unxpected NULL usecase in usecase_list");
960 valid_uc_type = usecase->type == PCM_PLAYBACK;
961 valid_dev = false;
962 if (valid_uc_type) {
963 audio_devices_t dev = usecase->stream.out->devices;
964 valid_dev = (dev == AUDIO_DEVICE_OUT_SPEAKER ||
vivek mehta40125092017-08-21 18:48:51 -0700965 dev == AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Haynes Mathew George67486e22017-06-26 12:58:38 -0700966 dev == AUDIO_DEVICE_OUT_WIRED_HEADSET ||
967 dev == AUDIO_DEVICE_OUT_WIRED_HEADPHONE);
968 }
969 if (valid_dev) {
vivek mehta40125092017-08-21 18:48:51 -0700970 ALOGV("%s: out device is %d", __func__, usecase->out_snd_device);
971 if (platform_supports_app_type_cfg())
972 app_type = usecase->stream.out->app_type_cfg.app_type;
973 else
974 app_type = DEFAULT_APP_TYPE_RX_PATH;
vivek mehta4cb82982015-07-13 12:05:49 -0700975
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -0700976 acdb_dev_id = platform_get_snd_device_acdb_id(usecase->out_snd_device);
vivek mehta40125092017-08-21 18:48:51 -0700977
978 if (!my_data->acdb_send_gain_dep_cal(acdb_dev_id, app_type,
vivek mehta1a9b7c02015-06-25 11:49:38 -0700979 acdb_dev_type, mode, level)) {
980 // set ret_val true if at least one calibration is set successfully
981 ret_val = true;
982 } else {
983 ALOGE("%s: my_data->acdb_send_gain_dep_cal failed ", __func__);
984 }
985 } else {
986 ALOGW("%s: Usecase list is empty", __func__);
987 }
988 }
989 } else {
990 ALOGW("%s: Voice call in progress .. ignore setting new cal",
991 __func__);
992 }
993 return ret_val;
994}
995
Eric Laurentcefbbac2014-09-04 13:54:10 -0500996void platform_set_echo_reference(struct audio_device *adev, bool enable, audio_devices_t out_device)
Eric Laurentb23d5282013-05-14 15:27:20 -0700997{
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800998 struct platform_data *my_data = (struct platform_data *)adev->platform;
Eric Laurentcefbbac2014-09-04 13:54:10 -0500999 snd_device_t snd_device = SND_DEVICE_NONE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001000
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08001001 if (strcmp(my_data->ec_ref_mixer_path, "")) {
1002 ALOGV("%s: diabling %s", __func__, my_data->ec_ref_mixer_path);
1003 audio_route_reset_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
Eric Laurentcefbbac2014-09-04 13:54:10 -05001004 }
1005
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08001006 if (enable) {
1007 strcpy(my_data->ec_ref_mixer_path, "echo-reference");
1008 if (out_device != AUDIO_DEVICE_NONE) {
1009 snd_device = platform_get_output_snd_device(adev->platform, out_device);
1010 platform_add_backend_name(adev->platform, my_data->ec_ref_mixer_path, snd_device);
1011 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05001012
Joe Onorato188b6222016-03-01 11:02:27 -08001013 ALOGV("%s: enabling %s", __func__, my_data->ec_ref_mixer_path);
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08001014 audio_route_apply_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
1015 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001016}
1017
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001018static struct csd_data *open_csd_client(bool i2s_ext_modem)
1019{
1020 struct csd_data *csd = calloc(1, sizeof(struct csd_data));
1021
1022 csd->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
1023 if (csd->csd_client == NULL) {
1024 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
1025 goto error;
1026 } else {
1027 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
1028
1029 csd->deinit = (deinit_t)dlsym(csd->csd_client,
1030 "csd_client_deinit");
1031 if (csd->deinit == NULL) {
1032 ALOGE("%s: dlsym error %s for csd_client_deinit", __func__,
1033 dlerror());
1034 goto error;
1035 }
1036 csd->disable_device = (disable_device_t)dlsym(csd->csd_client,
1037 "csd_client_disable_device");
1038 if (csd->disable_device == NULL) {
1039 ALOGE("%s: dlsym error %s for csd_client_disable_device",
1040 __func__, dlerror());
1041 goto error;
1042 }
1043 csd->enable_device_config = (enable_device_config_t)dlsym(csd->csd_client,
1044 "csd_client_enable_device_config");
1045 if (csd->enable_device_config == NULL) {
1046 ALOGE("%s: dlsym error %s for csd_client_enable_device_config",
1047 __func__, dlerror());
1048 goto error;
1049 }
1050 csd->enable_device = (enable_device_t)dlsym(csd->csd_client,
1051 "csd_client_enable_device");
1052 if (csd->enable_device == NULL) {
1053 ALOGE("%s: dlsym error %s for csd_client_enable_device",
1054 __func__, dlerror());
1055 goto error;
1056 }
1057 csd->start_voice = (start_voice_t)dlsym(csd->csd_client,
1058 "csd_client_start_voice");
1059 if (csd->start_voice == NULL) {
1060 ALOGE("%s: dlsym error %s for csd_client_start_voice",
1061 __func__, dlerror());
1062 goto error;
1063 }
1064 csd->stop_voice = (stop_voice_t)dlsym(csd->csd_client,
1065 "csd_client_stop_voice");
1066 if (csd->stop_voice == NULL) {
1067 ALOGE("%s: dlsym error %s for csd_client_stop_voice",
1068 __func__, dlerror());
1069 goto error;
1070 }
1071 csd->volume = (volume_t)dlsym(csd->csd_client,
1072 "csd_client_volume");
1073 if (csd->volume == NULL) {
1074 ALOGE("%s: dlsym error %s for csd_client_volume",
1075 __func__, dlerror());
1076 goto error;
1077 }
1078 csd->mic_mute = (mic_mute_t)dlsym(csd->csd_client,
1079 "csd_client_mic_mute");
1080 if (csd->mic_mute == NULL) {
1081 ALOGE("%s: dlsym error %s for csd_client_mic_mute",
1082 __func__, dlerror());
1083 goto error;
1084 }
1085 csd->slow_talk = (slow_talk_t)dlsym(csd->csd_client,
1086 "csd_client_slow_talk");
1087 if (csd->slow_talk == NULL) {
1088 ALOGE("%s: dlsym error %s for csd_client_slow_talk",
1089 __func__, dlerror());
1090 goto error;
1091 }
1092 csd->start_playback = (start_playback_t)dlsym(csd->csd_client,
1093 "csd_client_start_playback");
1094 if (csd->start_playback == NULL) {
1095 ALOGE("%s: dlsym error %s for csd_client_start_playback",
1096 __func__, dlerror());
1097 goto error;
1098 }
1099 csd->stop_playback = (stop_playback_t)dlsym(csd->csd_client,
1100 "csd_client_stop_playback");
1101 if (csd->stop_playback == NULL) {
1102 ALOGE("%s: dlsym error %s for csd_client_stop_playback",
1103 __func__, dlerror());
1104 goto error;
1105 }
1106 csd->start_record = (start_record_t)dlsym(csd->csd_client,
1107 "csd_client_start_record");
1108 if (csd->start_record == NULL) {
1109 ALOGE("%s: dlsym error %s for csd_client_start_record",
1110 __func__, dlerror());
1111 goto error;
1112 }
1113 csd->stop_record = (stop_record_t)dlsym(csd->csd_client,
1114 "csd_client_stop_record");
1115 if (csd->stop_record == NULL) {
1116 ALOGE("%s: dlsym error %s for csd_client_stop_record",
1117 __func__, dlerror());
1118 goto error;
1119 }
1120
1121 csd->get_sample_rate = (get_sample_rate_t)dlsym(csd->csd_client,
1122 "csd_client_get_sample_rate");
1123 if (csd->get_sample_rate == NULL) {
1124 ALOGE("%s: dlsym error %s for csd_client_get_sample_rate",
1125 __func__, dlerror());
1126
1127 goto error;
1128 }
1129
1130 csd->init = (init_t)dlsym(csd->csd_client, "csd_client_init");
1131
1132 if (csd->init == NULL) {
1133 ALOGE("%s: dlsym error %s for csd_client_init",
1134 __func__, dlerror());
1135 goto error;
1136 } else {
1137 csd->init(i2s_ext_modem);
1138 }
1139 }
1140 return csd;
1141
1142error:
1143 free(csd);
1144 csd = NULL;
1145 return csd;
1146}
1147
1148void close_csd_client(struct csd_data *csd)
1149{
1150 if (csd != NULL) {
1151 csd->deinit();
1152 dlclose(csd->csd_client);
1153 free(csd);
1154 csd = NULL;
1155 }
1156}
1157
1158static void platform_csd_init(struct platform_data *my_data)
1159{
1160#ifdef PLATFORM_MSM8084
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001161 int32_t modems, (*count_modems)(void);
1162 const char *name = "libdetectmodem.so";
1163 const char *func = "count_modems";
1164 const char *error;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001165
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001166 my_data->csd = NULL;
1167
1168 void *lib = dlopen(name, RTLD_NOW);
1169 error = dlerror();
1170 if (!lib) {
1171 ALOGE("%s: could not find %s: %s", __func__, name, error);
1172 return;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001173 }
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001174
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001175 count_modems = NULL;
1176 *(void **)(&count_modems) = dlsym(lib, func);
1177 error = dlerror();
1178 if (!count_modems) {
1179 ALOGE("%s: could not find symbol %s in %s: %s",
1180 __func__, func, name, error);
1181 goto done;
1182 }
1183
1184 modems = count_modems();
1185 if (modems < 0) {
1186 ALOGE("%s: count_modems failed\n", __func__);
1187 goto done;
1188 }
1189
Eric Laurent2bafff12016-03-17 12:17:23 -07001190 ALOGD("%s: num_modems %d\n", __func__, modems);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001191 if (modems > 0)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001192 my_data->csd = open_csd_client(false /*is_i2s_ext_modem*/);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001193
1194done:
1195 dlclose(lib);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001196#else
1197 my_data->csd = NULL;
1198#endif
1199}
1200
Eric Laurentc6333382015-09-14 12:43:44 -07001201static void set_platform_defaults(struct platform_data * my_data)
Haynes Mathew George98c95622014-06-20 19:14:25 -07001202{
1203 int32_t dev;
1204 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001205 backend_tag_table[dev] = NULL;
1206 hw_interface_table[dev] = NULL;
keunhui.park2f7306a2015-07-16 16:48:06 +09001207 operator_specific_device_table[dev] = NULL;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001208 }
1209
David Linee3fe402017-03-13 10:00:42 -07001210 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1211 backend_bit_width_table[dev] = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
1212 }
1213
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001214 // To overwrite these go to the audio_platform_info.xml file.
1215 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("bt-sco");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07001216 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("bt-sco");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001217 backend_tag_table[SND_DEVICE_OUT_BT_SCO] = strdup("bt-sco");
1218 backend_tag_table[SND_DEVICE_OUT_HDMI] = strdup("hdmi");
1219 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("speaker-and-hdmi");
1220 backend_tag_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("bt-sco-wb");
1221 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("bt-sco-wb");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07001222 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("bt-sco-wb");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001223 backend_tag_table[SND_DEVICE_OUT_VOICE_TX] = strdup("afe-proxy");
1224 backend_tag_table[SND_DEVICE_IN_VOICE_RX] = strdup("afe-proxy");
Haynes Mathew George98c95622014-06-20 19:14:25 -07001225
David Linee3fe402017-03-13 10:00:42 -07001226 backend_tag_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("usb-headset");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001227 backend_tag_table[SND_DEVICE_OUT_VOICE_USB_HEADSET] = strdup("usb-headset");
David Linee3fe402017-03-13 10:00:42 -07001228 backend_tag_table[SND_DEVICE_OUT_USB_HEADPHONES] = strdup("usb-headphones");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001229 backend_tag_table[SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = strdup("usb-headphones");
David Linee3fe402017-03-13 10:00:42 -07001230 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] =
1231 strdup("speaker-and-usb-headphones");
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07001232 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] =
1233 strdup("speaker-safe-and-usb-headphones");
juyuchen5351ea62018-05-16 10:54:37 +08001234 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO] =
1235 strdup("speaker-safe-and-bt-sco"),
1236 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB] =
1237 strdup("speaker-safe-and-bt-sco-wb"),
David Linee3fe402017-03-13 10:00:42 -07001238 backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("usb-headset-mic");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001239 backend_tag_table[SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1240 backend_tag_table[SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1241 backend_tag_table[SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1242 backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = strdup("usb-headset-mic");
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001243 backend_tag_table[SND_DEVICE_OUT_BT_A2DP] = strdup("bt-a2dp");
1244 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] = strdup("speaker-and-bt-a2dp");
Aniket Kumar Lata9723a962018-05-16 17:41:55 -07001245 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP] = strdup("speaker-safe-and-bt-a2dp");
jasmine cha270b7762018-03-30 15:41:33 +08001246 backend_tag_table[SND_DEVICE_OUT_USB_HEADSET_SPEC] = strdup("usb-headset");
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001247
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001248 hw_interface_table[SND_DEVICE_OUT_HANDSET] = strdup("SLIMBUS_0_RX");
1249 hw_interface_table[SND_DEVICE_OUT_SPEAKER] = strdup("SLIMBUS_0_RX");
1250 hw_interface_table[SND_DEVICE_OUT_SPEAKER_REVERSE] = strdup("SLIMBUS_0_RX");
1251 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE] = strdup("SLIMBUS_0_RX");
1252 hw_interface_table[SND_DEVICE_OUT_HEADPHONES] = strdup("SLIMBUS_0_RX");
1253 hw_interface_table[SND_DEVICE_OUT_LINE] = strdup("SLIMBUS_0_RX");
1254 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001255 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001256 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001257 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001258 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET] = strdup("SLIMBUS_0_RX");
1259 hw_interface_table[SND_DEVICE_OUT_VOICE_HAC_HANDSET] = strdup("SLIMBUS_0_RX");
1260 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER] = strdup("SLIMBUS_0_RX");
1261 hw_interface_table[SND_DEVICE_OUT_VOICE_HEADPHONES] = strdup("SLIMBUS_0_RX");
juyuchen66c4ecf2018-08-06 15:39:34 +08001262 hw_interface_table[SND_DEVICE_OUT_VOICE_MUSIC_TX] = strdup("VOICE_PLAYBACK_TX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001263 hw_interface_table[SND_DEVICE_OUT_VOICE_LINE] = strdup("SLIMBUS_0_RX");
1264 hw_interface_table[SND_DEVICE_OUT_HDMI] = strdup("HDMI_RX");
1265 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("SLIMBUS_0_RX-and-HDMI_RX");
1266 hw_interface_table[SND_DEVICE_OUT_BT_SCO] = strdup("SEC_AUX_PCM_RX");
1267 hw_interface_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("SEC_AUX_PCM_RX");
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001268 hw_interface_table[SND_DEVICE_OUT_BT_A2DP] = strdup("SLIMBUS_7_RX");
1269 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] =
1270 strdup("SLIMBUS_0_RX-and-SLIMBUS_7_RX");
Aniket Kumar Lata9723a962018-05-16 17:41:55 -07001271 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP] =
1272 strdup("SLIMBUS_0_RX-and-SLIMBUS_7_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001273 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = strdup("SLIMBUS_0_RX");
1274 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = strdup("SLIMBUS_0_RX");
1275 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = strdup("SLIMBUS_0_RX");
1276 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = strdup("SLIMBUS_0_RX");
David Linee3fe402017-03-13 10:00:42 -07001277 hw_interface_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("USB_AUDIO_RX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001278 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = strdup("USB_AUDIO_RX");
1279 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = strdup("USB_AUDIO_RX");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001280 hw_interface_table[SND_DEVICE_OUT_VOICE_USB_HEADSET] = strdup("USB_AUDIO_RX");
David Linee3fe402017-03-13 10:00:42 -07001281 hw_interface_table[SND_DEVICE_OUT_USB_HEADPHONES] = strdup("USB_AUDIO_RX");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001282 hw_interface_table[SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = strdup("USB_AUDIO_RX");
jasmine cha270b7762018-03-30 15:41:33 +08001283 hw_interface_table[SND_DEVICE_OUT_USB_HEADSET_SPEC] = strdup("USB_AUDIO_RX");
David Linee3fe402017-03-13 10:00:42 -07001284 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 -07001285 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 -07001286 hw_interface_table[SND_DEVICE_OUT_VOICE_TX] = strdup("AFE_PCM_RX");
1287 hw_interface_table[SND_DEVICE_OUT_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
1288 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
jasmine cha52284622018-03-23 17:21:35 +08001289 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = strdup("SLIMBUS_0_RX");
1290 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_BT_SCO] = strdup("SLIMBUS_0_RX-and-SEC_AUX_PCM_RX");
1291 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 +08001292 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO] = strdup("QUAT_TDM_RX_0-and-SLIMBUS_7_RX"),
1293 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 -07001294 hw_interface_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1295 hw_interface_table[SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1296 hw_interface_table[SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = strdup("USB_AUDIO_TX");
1297 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1298 hw_interface_table[SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1299 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = strdup("USB_AUDIO_TX");
1300 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = strdup("USB_AUDIO_TX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001301 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001302 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_AEC] = strdup("SLIMBUS_0_TX");
1303 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_NS] = strdup("SLIMBUS_0_TX");
1304 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1305 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC] = strdup("SLIMBUS_0_TX");
1306 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_AEC] = strdup("SLIMBUS_0_TX");
1307 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_NS] = strdup("SLIMBUS_0_TX");
1308 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1309 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001310 hw_interface_table[SND_DEVICE_IN_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001311 hw_interface_table[SND_DEVICE_IN_HEADSET_MIC_AEC] = strdup("SLIMBUS_0_TX");
Eric Laurent57274392018-10-19 17:33:43 -07001312 hw_interface_table[SND_DEVICE_IN_CAMCORDER_LANDSCAPE] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001313 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC] = strdup("SLIMBUS_0_TX");
1314 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC_NS] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001315 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC_AEC] = strdup("SLIMBUS_0_TX");
1316 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001317 hw_interface_table[SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
1318 hw_interface_table[SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = strdup("SLIMBUS_0_TX");
David Lin93725722017-10-13 14:58:17 -07001319 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_MIC] = strdup("SLIMBUS_0_TX");
1320 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1321 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = strdup("SLIMBUS_0_TX");
1322 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = strdup("SLIMBUS_0_TX");
1323 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001324 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC] = strdup("SLIMBUS_0_TX");
1325 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_AEC] = strdup("SLIMBUS_0_TX");
1326 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_NS] = strdup("SLIMBUS_0_TX");
1327 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1328 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC] = strdup("SLIMBUS_0_TX");
1329 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_AEC] = strdup("SLIMBUS_0_TX");
1330 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_NS] = strdup("SLIMBUS_0_TX");
1331 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001332 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
1333 hw_interface_table[SND_DEVICE_IN_VOICE_DMIC] = strdup("SLIMBUS_0_TX");
1334 hw_interface_table[SND_DEVICE_IN_VOICE_DMIC_TMUS] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001335 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001336 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = strdup("SLIMBUS_0_TX");
1337 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001338 hw_interface_table[SND_DEVICE_IN_VOICE_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001339 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1340 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = strdup("SLIMBUS_0_TX");
1341 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1342 hw_interface_table[SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1343 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("SEC_AUX_PCM_TX");
1344 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("SEC_AUX_PCM_TX");
1345 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("SEC_AUX_PCM_TX");
1346 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("SEC_AUX_PCM_TX");
1347 hw_interface_table[SND_DEVICE_IN_VOICE_RX] = strdup("AFE_PCM_TX");
1348 hw_interface_table[SND_DEVICE_IN_THREE_MIC] = strdup("SLIMBUS_0_TX");
1349 hw_interface_table[SND_DEVICE_IN_QUAD_MIC] = strdup("SLIMBUS_0_TX");
1350 hw_interface_table[SND_DEVICE_IN_HANDSET_TMIC] = strdup("SLIMBUS_0_TX");
1351 hw_interface_table[SND_DEVICE_IN_HANDSET_QMIC] = strdup("SLIMBUS_0_TX");
1352 hw_interface_table[SND_DEVICE_IN_HANDSET_TMIC_AEC] = strdup("SLIMBUS_0_TX");
1353 hw_interface_table[SND_DEVICE_IN_HANDSET_QMIC_AEC] = strdup("SLIMBUS_0_TX");
Eric Laurent57274392018-10-19 17:33:43 -07001354 hw_interface_table[SND_DEVICE_IN_CAMCORDER_INVERT_LANDSCAPE] = strdup("SLIMBUS_0_TX");
1355 hw_interface_table[SND_DEVICE_IN_CAMCORDER_PORTRAIT] = strdup("SLIMBUS_0_TX");
1356 hw_interface_table[SND_DEVICE_IN_CAMCORDER_SELFIE_LANDSCAPE] = strdup("SLIMBUS_0_TX");
1357 hw_interface_table[SND_DEVICE_IN_CAMCORDER_SELFIE_INVERT_LANDSCAPE] = strdup("SLIMBUS_0_TX");
1358 hw_interface_table[SND_DEVICE_IN_CAMCORDER_SELFIE_PORTRAIT] = strdup("SLIMBUS_0_TX");
Eric Laurentc6333382015-09-14 12:43:44 -07001359 my_data->max_mic_count = PLATFORM_DEFAULT_MIC_COUNT;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001360}
1361
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001362void get_cvd_version(char *cvd_version, struct audio_device *adev)
1363{
1364 struct mixer_ctl *ctl;
1365 int count;
1366 int ret = 0;
1367
1368 ctl = mixer_get_ctl_by_name(adev->mixer, CVD_VERSION_MIXER_CTL);
1369 if (!ctl) {
1370 ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__, CVD_VERSION_MIXER_CTL);
1371 goto done;
1372 }
1373 mixer_ctl_update(ctl);
1374
1375 count = mixer_ctl_get_num_values(ctl);
1376 if (count > MAX_CVD_VERSION_STRING_SIZE)
1377 count = MAX_CVD_VERSION_STRING_SIZE - 1;
1378
1379 ret = mixer_ctl_get_array(ctl, cvd_version, count);
1380 if (ret != 0) {
1381 ALOGE("%s: ERROR! mixer_ctl_get_array() failed to get CVD Version", __func__);
1382 goto done;
1383 }
1384
1385done:
1386 return;
1387}
1388
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001389static int platform_acdb_init(void *platform)
1390{
1391 struct platform_data *my_data = (struct platform_data *)platform;
1392 struct audio_device *adev = my_data->adev;
1393
1394 if (!my_data->acdb_init) {
1395 ALOGE("%s: no acdb_init fn provided", __func__);
1396 return -1;
1397 }
1398
1399 if (my_data->acdb_initialized) {
1400 ALOGW("acdb is already initialized");
1401 return 0;
1402 }
1403
yixuanjiang89bd2712018-08-15 17:43:11 +08001404#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845) || (PLATFORM_SDM710)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001405 char *cvd_version = calloc(1, MAX_CVD_VERSION_STRING_SIZE);
1406 if (!cvd_version)
1407 ALOGE("failed to allocate cvd_version");
1408 else {
1409 get_cvd_version(cvd_version, adev);
1410 my_data->acdb_init((char *)my_data->snd_card_name, cvd_version, 0);
1411 free(cvd_version);
1412 }
1413#elif defined (PLATFORM_MSM8084)
1414 my_data->acdb_init((char *)my_data->snd_card_name);
1415#else
1416 my_data->acdb_init();
1417#endif
1418 my_data->acdb_initialized = true;
1419 return 0;
1420}
1421
David Linee3fe402017-03-13 10:00:42 -07001422static void
1423platform_backend_config_init(struct platform_data *pdata)
1424{
1425 int i;
1426
1427 /* initialize backend config */
1428 for (i = 0; i < MAX_CODEC_BACKENDS; i++) {
1429 pdata->current_backend_cfg[i].sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
1430 pdata->current_backend_cfg[i].bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
1431 pdata->current_backend_cfg[i].channels = CODEC_BACKEND_DEFAULT_CHANNELS;
1432
1433 if (i > MAX_RX_CODEC_BACKENDS)
1434 pdata->current_backend_cfg[i].channels = CODEC_BACKEND_DEFAULT_TX_CHANNELS;
1435
1436 pdata->current_backend_cfg[i].bitwidth_mixer_ctl = NULL;
1437 pdata->current_backend_cfg[i].samplerate_mixer_ctl = NULL;
1438 pdata->current_backend_cfg[i].channels_mixer_ctl = NULL;
1439 }
1440
1441 pdata->current_backend_cfg[DEFAULT_CODEC_BACKEND].bitwidth_mixer_ctl =
1442 strdup("SLIM_0_RX Format");
1443 pdata->current_backend_cfg[DEFAULT_CODEC_BACKEND].samplerate_mixer_ctl =
1444 strdup("SLIM_0_RX SampleRate");
1445
1446 pdata->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].bitwidth_mixer_ctl =
1447 strdup("SLIM_0_TX Format");
1448 pdata->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].samplerate_mixer_ctl =
1449 strdup("SLIM_0_TX SampleRate");
1450
1451 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].bitwidth_mixer_ctl =
1452 strdup("USB_AUDIO_TX Format");
1453 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].samplerate_mixer_ctl =
1454 strdup("USB_AUDIO_TX SampleRate");
1455 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].channels_mixer_ctl =
1456 strdup("USB_AUDIO_TX Channels");
1457
1458 pdata->current_backend_cfg[HEADPHONE_BACKEND].bitwidth_mixer_ctl =
1459 strdup("SLIM_6_RX Format");
1460 pdata->current_backend_cfg[HEADPHONE_BACKEND].samplerate_mixer_ctl =
1461 strdup("SLIM_6_RX SampleRate");
1462
1463 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].bitwidth_mixer_ctl =
1464 strdup("USB_AUDIO_RX Format");
1465 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].samplerate_mixer_ctl =
1466 strdup("USB_AUDIO_RX SampleRate");
1467
1468 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].channels = 1;
1469 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].channels_mixer_ctl =
1470 strdup("USB_AUDIO_RX Channels");
1471}
1472
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001473static int
1474platform_backend_app_type_cfg_init(struct platform_data *pdata,
1475 struct mixer *mixer)
1476{
1477 size_t app_type_cfg[128] = {0};
1478 int length, num_app_types = 0;
1479 struct mixer_ctl *ctl = NULL;
1480
1481 const char *mixer_ctl_name = "App Type Config";
1482 ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name);
1483 if (!ctl) {
1484 ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name);
1485 return -1;
1486 }
1487
1488 length = 1; // reserve index 0 for number of app types
1489
1490 struct listnode *node;
1491 struct app_type_entry *entry;
1492 list_for_each(node, &app_type_entry_list) {
1493 entry = node_to_item(node, struct app_type_entry, node);
1494 app_type_cfg[length++] = entry->app_type;
1495 app_type_cfg[length++] = entry->max_rate;
1496 app_type_cfg[length++] = entry->bit_width;
1497 ALOGI("%s add entry %d %d", __func__, entry->app_type, entry->bit_width);
1498 num_app_types += 1;
1499 }
1500
1501 // default for capture
1502 int t;
1503 platform_get_default_app_type_v2(pdata,
1504 PCM_CAPTURE,
1505 &t);
1506 app_type_cfg[length++] = t;
1507 app_type_cfg[length++] = 48000;
1508 app_type_cfg[length++] = 16;
1509 num_app_types += 1;
1510
1511 if (num_app_types) {
1512 app_type_cfg[0] = num_app_types;
1513 if (mixer_ctl_set_array(ctl, app_type_cfg, length) < 0) {
1514 ALOGE("Failed to set app type cfg");
1515 }
1516 }
1517 return 0;
1518}
1519
Xu Han1638fd12018-04-20 12:42:23 -07001520static void configure_flicker_sensor_input(struct mixer *mixer)
1521{
1522 struct mixer_ctl *ctl;
1523 const char* ctl1 = "AIF3_CAP Mixer SLIM TX2";
1524 int setting1 = 1;
1525 const char* ctl2 = "CDC_IF TX2 MUX";
1526 const char* setting2 = "DEC2";
1527 const char* ctl3 = "SLIM_1_TX Channels";
1528 const char* setting3 = "One";
1529 const char* ctl4 = "ADC MUX2";
1530 const char* setting4 = "AMIC";
1531 const char* ctl5 = "AMIC MUX2";
1532 const char* setting5 = "ADC1";
1533 const char* ctl6 = "DEC2 Volume";
1534 int setting6 = 84;
Xu Han07e07402018-05-15 14:19:25 -07001535 const char* ctl7 = "MultiMedia9 Mixer SLIM_1_TX";
Xu Han1638fd12018-04-20 12:42:23 -07001536 int setting7 = 1;
1537 const char* ctl8 = "SLIM_1_TX SampleRate";
1538 const char* setting8 = "KHZ_8";
1539
1540 ctl = mixer_get_ctl_by_name(mixer, ctl1);
1541 mixer_ctl_set_value(ctl, 0, setting1);
1542 ctl = mixer_get_ctl_by_name(mixer, ctl2);
1543 mixer_ctl_set_enum_by_string(ctl, setting2);
1544 ctl = mixer_get_ctl_by_name(mixer, ctl3);
1545 mixer_ctl_set_enum_by_string(ctl, setting3);
1546 ctl = mixer_get_ctl_by_name(mixer, ctl4);
1547 mixer_ctl_set_enum_by_string(ctl, setting4);
1548 ctl = mixer_get_ctl_by_name(mixer, ctl5);
1549 mixer_ctl_set_enum_by_string(ctl, setting5);
1550 ctl = mixer_get_ctl_by_name(mixer, ctl6);
1551 mixer_ctl_set_value(ctl, 0, setting6);
1552 ctl = mixer_get_ctl_by_name(mixer, ctl7);
1553 mixer_ctl_set_value(ctl, 0, setting7);
1554 ctl = mixer_get_ctl_by_name(mixer, ctl8);
1555 mixer_ctl_set_enum_by_string(ctl, setting8);
1556}
1557
Eric Laurentb23d5282013-05-14 15:27:20 -07001558void *platform_init(struct audio_device *adev)
1559{
1560 char value[PROPERTY_VALUE_MAX];
vivek mehta60ea4152016-02-18 17:10:26 -08001561 struct platform_data *my_data = NULL;
1562 int retry_num = 0, snd_card_num = 0, key = 0, ret = 0;
1563 bool dual_mic_config = false, use_default_mixer_path = true;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001564 const char *snd_card_name;
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001565 char *cvd_version = NULL;
vivek mehta60ea4152016-02-18 17:10:26 -08001566 char *snd_internal_name = NULL;
1567 char *tmp = NULL;
1568 char mixer_xml_file[MIXER_PATH_MAX_LENGTH]= {0};
vivek mehtade4849c2016-03-03 17:23:38 -08001569 char platform_info_file[MIXER_PATH_MAX_LENGTH]= {0};
1570 struct snd_card_split *snd_split_handle = NULL;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001571 my_data = calloc(1, sizeof(struct platform_data));
1572
1573 my_data->adev = adev;
1574
keunhui.park2f7306a2015-07-16 16:48:06 +09001575 list_init(&operator_info_list);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001576 list_init(&app_type_entry_list);
keunhui.park2f7306a2015-07-16 16:48:06 +09001577
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001578 set_platform_defaults(my_data);
1579
vivek mehta0fb11312017-05-15 19:35:32 -07001580 // audio_extn_utils_get_snd_card_num does
1581 // - open mixer and get snd card name
1582 // - parse platform info xml file and check for valid snd card name
1583 // - on failure loop through all the active snd card
sangwoo1b9f4b32013-06-21 18:22:55 -07001584
vivek mehta0fb11312017-05-15 19:35:32 -07001585 snd_card_num = audio_extn_utils_get_snd_card_num();
1586 if (-1 == snd_card_num) {
1587 ALOGE("%s: invalid sound card number (-1), bailing out ", __func__);
1588 goto init_failed;
sangwoo1b9f4b32013-06-21 18:22:55 -07001589 }
1590
vivek mehta0fb11312017-05-15 19:35:32 -07001591 adev->mixer = mixer_open(snd_card_num);
1592 snd_card_name = mixer_get_name(adev->mixer);
1593 my_data->hw_info = hw_info_init(snd_card_name);
1594
1595 audio_extn_set_snd_card_split(snd_card_name);
1596 snd_split_handle = audio_extn_get_snd_card_split();
1597
1598 /* Get the codec internal name from the sound card and/or form factor
1599 * name and form the mixer paths and platfor info file name dynamically.
1600 * This is generic way of picking any codec and forma factor name based
1601 * mixer and platform info files in future with no code change.
1602
1603 * current code extends and looks for any of the exteneded mixer path and
1604 * platform info file present based on codec and form factor.
1605
1606 * order of picking appropriate file is
1607 * <i> mixer_paths_<codec_name>_<form_factor>.xml, if file not present
1608 * <ii> mixer_paths_<codec_name>.xml, if file not present
1609 * <iii> mixer_paths.xml
1610
1611 * same order is followed for audio_platform_info.xml as well
1612 */
1613
1614 // need to carryforward old file name
1615 if (!strncmp(snd_card_name, TOMTOM_8226_SND_CARD_NAME,
1616 min(strlen(TOMTOM_8226_SND_CARD_NAME), strlen(snd_card_name)))) {
1617 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1618 MIXER_XML_BASE_STRING, TOMTOM_MIXER_FILE_SUFFIX );
1619 } else {
1620
1621 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s_%s.xml",
1622 MIXER_XML_BASE_STRING, snd_split_handle->snd_card,
1623 snd_split_handle->form_factor);
1624 if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) {
1625 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1626 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1627 MIXER_XML_BASE_STRING, snd_split_handle->snd_card);
1628
1629 if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) {
1630 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1631 strlcpy(mixer_xml_file, MIXER_XML_DEFAULT_PATH, MIXER_PATH_MAX_LENGTH);
1632 audio_extn_utils_resolve_config_file(mixer_xml_file);
1633 }
1634 }
1635 }
1636
1637 audio_extn_utils_get_platform_info(snd_card_name, platform_info_file);
1638
jiabin8962a4d2018-03-19 18:21:24 -07001639 my_data->declared_mic_count = 0;
vivek mehta0fb11312017-05-15 19:35:32 -07001640 /* Initialize platform specific ids and/or backends*/
1641 platform_info_init(platform_info_file, my_data);
1642
1643 ALOGD("%s: Loading mixer file: %s", __func__, mixer_xml_file);
1644 adev->audio_route = audio_route_init(snd_card_num, mixer_xml_file);
1645
1646 if (!adev->audio_route) {
1647 ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
1648 mixer_close(adev->mixer);
1649 adev->mixer = NULL;
1650 hw_info_deinit(my_data->hw_info);
1651 my_data->hw_info = NULL;
1652 goto init_failed;
1653 }
1654 adev->snd_card = snd_card_num;
1655 ALOGD("%s: Opened sound card:%d", __func__, snd_card_num);
1656
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09001657 //set max volume step for voice call
1658 property_get("ro.config.vc_call_vol_steps", value, TOSTRING(MAX_VOL_INDEX));
1659 my_data->max_vol_index = atoi(value);
1660
vivek mehta65ad12d2015-08-13 18:32:48 -07001661 property_get("persist.audio.dualmic.config",value,"");
1662 if (!strcmp("endfire", value)) {
1663 dual_mic_config = true;
1664 }
1665
John Muir9e59a962018-01-10 13:30:00 -08001666 my_data->source_mic_type = 0;
Prashant Malanic92c5962015-08-11 15:10:18 -07001667
Eric Laurentb23d5282013-05-14 15:27:20 -07001668 my_data->fluence_in_spkr_mode = false;
1669 my_data->fluence_in_voice_call = false;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001670 my_data->fluence_in_voice_comm = false;
Eric Laurentb23d5282013-05-14 15:27:20 -07001671 my_data->fluence_in_voice_rec = false;
1672
vivek mehta65ad12d2015-08-13 18:32:48 -07001673 property_get("ro.qc.sdk.audio.fluencetype", value, "none");
Prashant Malanic92c5962015-08-11 15:10:18 -07001674 if (!strcmp("fluencepro", value)) {
1675 my_data->fluence_type = FLUENCE_PRO_ENABLE;
vivek mehta65ad12d2015-08-13 18:32:48 -07001676 } else if (!strcmp("fluence", value) || (dual_mic_config)) {
Prashant Malanic92c5962015-08-11 15:10:18 -07001677 my_data->fluence_type = FLUENCE_ENABLE;
1678 } else if (!strcmp("none", value)) {
1679 my_data->fluence_type = FLUENCE_DISABLE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001680 }
1681
Prashant Malanic92c5962015-08-11 15:10:18 -07001682 if (my_data->fluence_type != FLUENCE_DISABLE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001683 property_get("persist.audio.fluence.voicecall",value,"");
1684 if (!strcmp("true", value)) {
1685 my_data->fluence_in_voice_call = true;
1686 }
1687
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001688 property_get("persist.audio.fluence.voicecomm",value,"");
1689 if (!strcmp("true", value)) {
1690 my_data->fluence_in_voice_comm = true;
1691 }
1692
Eric Laurentb23d5282013-05-14 15:27:20 -07001693 property_get("persist.audio.fluence.voicerec",value,"");
1694 if (!strcmp("true", value)) {
1695 my_data->fluence_in_voice_rec = true;
1696 }
1697
1698 property_get("persist.audio.fluence.speaker",value,"");
1699 if (!strcmp("true", value)) {
1700 my_data->fluence_in_spkr_mode = true;
1701 }
1702 }
1703
Prashant Malanic92c5962015-08-11 15:10:18 -07001704 // support max to mono, example if max count is 3, usecase supports Three, dual and mono mic
1705 switch (my_data->max_mic_count) {
1706 case 4:
1707 my_data->source_mic_type |= SOURCE_QUAD_MIC;
1708 case 3:
1709 my_data->source_mic_type |= SOURCE_THREE_MIC;
1710 case 2:
1711 my_data->source_mic_type |= SOURCE_DUAL_MIC;
1712 case 1:
1713 my_data->source_mic_type |= SOURCE_MONO_MIC;
1714 break;
1715 default:
1716 ALOGE("%s: max_mic_count (%d), is not supported, setting to default",
1717 __func__, my_data->max_mic_count);
1718 my_data->source_mic_type = SOURCE_MONO_MIC|SOURCE_DUAL_MIC;
1719 break;
1720 }
1721
1722 ALOGV("%s: Fluence_Type(%d) max_mic_count(%d) mic_type(0x%x) fluence_in_voice_call(%d)"
1723 " fluence_in_voice_comm(%d) fluence_in_voice_rec(%d) fluence_in_spkr_mode(%d) ",
1724 __func__, my_data->fluence_type, my_data->max_mic_count, my_data->source_mic_type,
1725 my_data->fluence_in_voice_call, my_data->fluence_in_voice_comm,
1726 my_data->fluence_in_voice_rec, my_data->fluence_in_spkr_mode);
1727
Eric Laurentb23d5282013-05-14 15:27:20 -07001728 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
1729 if (my_data->acdb_handle == NULL) {
1730 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
1731 } else {
1732 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
1733 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
1734 "acdb_loader_deallocate_ACDB");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001735 if (!my_data->acdb_deallocate)
1736 ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s",
1737 __func__, LIB_ACDB_LOADER);
1738
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001739 my_data->acdb_send_audio_cal_v3 = (acdb_send_audio_cal_v3_t)dlsym(my_data->acdb_handle,
1740 "acdb_loader_send_audio_cal_v3");
1741 if (!my_data->acdb_send_audio_cal_v3)
1742 ALOGE("%s: Could not find the symbol acdb_send_audio_cal_v3 from %s",
1743 __func__, LIB_ACDB_LOADER);
1744
Eric Laurentb23d5282013-05-14 15:27:20 -07001745 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
1746 "acdb_loader_send_audio_cal");
1747 if (!my_data->acdb_send_audio_cal)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001748 ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s",
Eric Laurentb23d5282013-05-14 15:27:20 -07001749 __func__, LIB_ACDB_LOADER);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001750
Eric Laurentb23d5282013-05-14 15:27:20 -07001751 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
1752 "acdb_loader_send_voice_cal");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001753 if (!my_data->acdb_send_voice_cal)
1754 ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s",
1755 __func__, LIB_ACDB_LOADER);
1756
1757 my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle,
1758 "acdb_loader_reload_vocvoltable");
1759 if (!my_data->acdb_reload_vocvoltable)
1760 ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s",
1761 __func__, LIB_ACDB_LOADER);
vivek mehta1a9b7c02015-06-25 11:49:38 -07001762
1763 my_data->acdb_send_gain_dep_cal = (acdb_send_gain_dep_cal_t)dlsym(my_data->acdb_handle,
1764 "acdb_loader_send_gain_dep_cal");
1765 if (!my_data->acdb_send_gain_dep_cal)
1766 ALOGV("%s: Could not find the symbol acdb_loader_send_gain_dep_cal from %s",
1767 __func__, LIB_ACDB_LOADER);
1768
Xu Han1638fd12018-04-20 12:42:23 -07001769#if defined (FLICKER_SENSOR_INPUT)
1770 configure_flicker_sensor_input(adev->mixer);
1771#endif
1772
yixuanjiang89bd2712018-08-15 17:43:11 +08001773#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845) || (PLATFORM_SDM710)
vivek mehta0fb11312017-05-15 19:35:32 -07001774 acdb_init_v2_cvd_t acdb_init_local;
1775 acdb_init_local = (acdb_init_v2_cvd_t)dlsym(my_data->acdb_handle,
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001776 "acdb_loader_init_v2");
vivek mehta0fb11312017-05-15 19:35:32 -07001777 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001778 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1779 dlerror());
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001780
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001781#elif defined (PLATFORM_MSM8084)
vivek mehta0fb11312017-05-15 19:35:32 -07001782 acdb_init_v2_t acdb_init_local;
1783 acdb_init_local = (acdb_init_v2_t)dlsym(my_data->acdb_handle,
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001784 "acdb_loader_init_v2");
vivek mehta0fb11312017-05-15 19:35:32 -07001785 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001786 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1787 dlerror());
1788
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001789#else
vivek mehta0fb11312017-05-15 19:35:32 -07001790 acdb_init_t acdb_init_local;
1791 acdb_init_local = (acdb_init_t)dlsym(my_data->acdb_handle,
Eric Laurentb23d5282013-05-14 15:27:20 -07001792 "acdb_loader_init_ACDB");
vivek mehta0fb11312017-05-15 19:35:32 -07001793 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001794 ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__,
1795 dlerror());
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001796#endif
vivek mehta0fb11312017-05-15 19:35:32 -07001797 my_data->acdb_init = acdb_init_local;
Eric Laurentb23d5282013-05-14 15:27:20 -07001798
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001799 my_data->acdb_send_custom_top = (acdb_send_custom_top_t)
1800 dlsym(my_data->acdb_handle,
1801 "acdb_loader_send_common_custom_topology");
1802
1803 if (!my_data->acdb_send_custom_top)
1804 ALOGE("%s: Could not find the symbol acdb_get_default_app_type from %s",
1805 __func__, LIB_ACDB_LOADER);
1806
jasmine chac89321b2018-04-10 21:37:01 +08001807 my_data->acdb_set_audio_cal = (acdb_set_audio_cal_t)dlsym(my_data->acdb_handle,
1808 "acdb_loader_set_audio_cal_v2");
1809 if (!my_data->acdb_set_audio_cal)
1810 ALOGE("%s: Could not find the symbol acdb_set_audio_cal_v2 from %s",
1811 __func__, LIB_ACDB_LOADER);
1812
vivek mehta0fb11312017-05-15 19:35:32 -07001813 int result = acdb_init(adev->snd_card);
1814 if (!result) {
1815 my_data->acdb_initialized = true;
1816 ALOGD("ACDB initialized");
1817 } else {
1818 my_data->acdb_initialized = false;
1819 ALOGD("ACDB initialization failed");
1820 }
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001821 }
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001822
David Linee3fe402017-03-13 10:00:42 -07001823 /* init usb */
1824 audio_extn_usb_init(adev);
1825
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001826 /* init a2dp */
1827 audio_extn_a2dp_init(adev);
1828
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001829 audio_extn_spkr_prot_init(adev);
Haynes Mathew George98c95622014-06-20 19:14:25 -07001830
Ravi Kumar Alamanda76315572015-04-23 13:13:56 -07001831 audio_extn_hwdep_cal_send(adev->snd_card, my_data->acdb_handle);
1832
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001833 /* load csd client */
1834 platform_csd_init(my_data);
1835
David Linee3fe402017-03-13 10:00:42 -07001836 platform_backend_config_init(my_data);
1837
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001838 init_be_dai_name_table(adev);
1839
1840 if (platform_supports_app_type_cfg())
1841 platform_backend_app_type_cfg_init(my_data, adev->mixer);
1842
Eric Laurentb23d5282013-05-14 15:27:20 -07001843 return my_data;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001844
1845init_failed:
1846 if (my_data)
1847 free(my_data);
1848 return NULL;
Eric Laurentb23d5282013-05-14 15:27:20 -07001849}
1850
1851void platform_deinit(void *platform)
1852{
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001853 int32_t dev;
keunhui.park2f7306a2015-07-16 16:48:06 +09001854 struct operator_info *info_item;
1855 struct operator_specific_device *device_item;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001856 struct app_type_entry *ap;
keunhui.park2f7306a2015-07-16 16:48:06 +09001857 struct listnode *node;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001858
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001859 struct platform_data *my_data = (struct platform_data *)platform;
1860 close_csd_client(my_data->csd);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001861
David Lin41b4fe42018-07-08 16:14:24 -07001862 audio_extn_spkr_prot_deinit(my_data->adev);
1863
vivek mehtade4849c2016-03-03 17:23:38 -08001864 hw_info_deinit(my_data->hw_info);
1865
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001866 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1867 if (backend_tag_table[dev])
1868 free(backend_tag_table[dev]);
1869 if (hw_interface_table[dev])
1870 free(hw_interface_table[dev]);
keunhui.park2f7306a2015-07-16 16:48:06 +09001871 if (operator_specific_device_table[dev]) {
1872 while (!list_empty(operator_specific_device_table[dev])) {
1873 node = list_head(operator_specific_device_table[dev]);
1874 list_remove(node);
1875 device_item = node_to_item(node, struct operator_specific_device, list);
1876 free(device_item->operator);
1877 free(device_item->mixer_path);
1878 free(device_item);
1879 }
1880 free(operator_specific_device_table[dev]);
1881 }
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001882 }
1883
1884 if (my_data->snd_card_name)
1885 free(my_data->snd_card_name);
1886
keunhui.park2f7306a2015-07-16 16:48:06 +09001887 while (!list_empty(&operator_info_list)) {
1888 node = list_head(&operator_info_list);
1889 list_remove(node);
1890 info_item = node_to_item(node, struct operator_info, list);
1891 free(info_item->name);
1892 free(info_item->mccmnc);
1893 free(info_item);
1894 }
1895
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001896 while (!list_empty(&app_type_entry_list)) {
1897 node = list_head(&app_type_entry_list);
1898 list_remove(node);
1899 ap = node_to_item(node, struct app_type_entry, node);
vivek mehtaa68fea62017-06-08 19:04:02 -07001900 if (ap->mode) free(ap->mode);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001901 free(ap);
1902 }
1903
Kevin Rocarde35d4af2017-05-02 16:55:28 -07001904 mixer_close(my_data->adev->mixer);
Eric Laurentb23d5282013-05-14 15:27:20 -07001905 free(platform);
David Linee3fe402017-03-13 10:00:42 -07001906
1907 /* deinit usb */
1908 audio_extn_usb_deinit();
Eric Laurentb23d5282013-05-14 15:27:20 -07001909}
1910
1911const char *platform_get_snd_device_name(snd_device_t snd_device)
1912{
keunhui.park2f7306a2015-07-16 16:48:06 +09001913 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1914 if (operator_specific_device_table[snd_device] != NULL) {
1915 return get_operator_specific_device_mixer_path(snd_device);
1916 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001917 return device_table[snd_device];
keunhui.park2f7306a2015-07-16 16:48:06 +09001918 } else
Ravi Kumar Alamanda64026462014-09-15 00:08:58 -07001919 return "none";
Eric Laurentb23d5282013-05-14 15:27:20 -07001920}
1921
vivek mehtade4849c2016-03-03 17:23:38 -08001922int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
1923 char *device_name)
1924{
1925 struct platform_data *my_data = (struct platform_data *)platform;
1926
David Benjamin1565f992016-09-21 12:10:34 -04001927 if (platform == NULL) {
vivek mehtade4849c2016-03-03 17:23:38 -08001928 ALOGW("%s: something wrong, use legacy get_snd_device name", __func__);
David Benjamin1565f992016-09-21 12:10:34 -04001929 strlcpy(device_name, platform_get_snd_device_name(snd_device),
1930 DEVICE_NAME_MAX_SIZE);
vivek mehtade4849c2016-03-03 17:23:38 -08001931 } else if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1932 if (operator_specific_device_table[snd_device] != NULL) {
1933 strlcpy(device_name, get_operator_specific_device_mixer_path(snd_device),
1934 DEVICE_NAME_MAX_SIZE);
1935 } else {
1936 strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE);
1937 }
1938 hw_info_append_hw_type(my_data->hw_info, snd_device, device_name);
1939 } else {
1940 strlcpy(device_name, "none", DEVICE_NAME_MAX_SIZE);
Aniket Kumar Lataa158e862018-05-11 17:28:40 -07001941 return -EINVAL;
vivek mehtade4849c2016-03-03 17:23:38 -08001942 }
1943
1944 return 0;
1945}
1946
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001947void platform_add_backend_name(void *platform, char *mixer_path,
1948 snd_device_t snd_device)
Eric Laurentb23d5282013-05-14 15:27:20 -07001949{
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001950 struct platform_data *my_data = (struct platform_data *)platform;
1951
Haynes Mathew George98c95622014-06-20 19:14:25 -07001952 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1953 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1954 return;
Ravi Kumar Alamanda1de6e5a2014-06-19 21:55:39 -05001955 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001956
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001957 const char * suffix = backend_tag_table[snd_device];
Haynes Mathew George98c95622014-06-20 19:14:25 -07001958
1959 if (suffix != NULL) {
1960 strcat(mixer_path, " ");
1961 strcat(mixer_path, suffix);
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001962 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001963}
1964
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001965bool platform_check_backends_match(snd_device_t snd_device1, snd_device_t snd_device2)
1966{
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001967 ALOGV("%s: snd_device1 = %s, snd_device2 = %s", __func__,
1968 platform_get_snd_device_name(snd_device1),
1969 platform_get_snd_device_name(snd_device2));
1970
1971 if ((snd_device1 < SND_DEVICE_MIN) || (snd_device1 >= SND_DEVICE_MAX)) {
1972 ALOGE("%s: Invalid snd_device = %s", __func__,
1973 platform_get_snd_device_name(snd_device1));
1974 return false;
1975 }
1976 if ((snd_device2 < SND_DEVICE_MIN) || (snd_device2 >= SND_DEVICE_MAX)) {
1977 ALOGE("%s: Invalid snd_device = %s", __func__,
1978 platform_get_snd_device_name(snd_device2));
1979 return false;
1980 }
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07001981
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001982 const char * be_itf1 = hw_interface_table[snd_device1];
1983 const char * be_itf2 = hw_interface_table[snd_device2];
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07001984 /*
1985 hw_interface_table has overrides for a snd_device.
1986 if there is no entry for a device, assume DEFAULT_RX_BACKEND
1987 */
1988 if (be_itf1 == NULL) {
1989 be_itf1 = DEFAULT_RX_BACKEND;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001990 }
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07001991 if (be_itf2 == NULL) {
1992 be_itf2 = DEFAULT_RX_BACKEND;
1993 }
1994 ALOGV("%s: be_itf1 = %s, be_itf2 = %s", __func__, be_itf1, be_itf2);
1995 /*
1996 this takes care of finding a device within a combo device pair as well
1997 */
1998 return strstr(be_itf1, be_itf2) != NULL || strstr(be_itf2, be_itf1) != NULL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001999}
2000
Eric Laurentb23d5282013-05-14 15:27:20 -07002001int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
2002{
2003 int device_id;
2004 if (device_type == PCM_PLAYBACK)
2005 device_id = pcm_device_table[usecase][0];
2006 else
2007 device_id = pcm_device_table[usecase][1];
2008 return device_id;
2009}
2010
Haynes Mathew George98c95622014-06-20 19:14:25 -07002011static int find_index(const struct name_to_index * table, int32_t len,
2012 const char * name)
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002013{
2014 int ret = 0;
Haynes Mathew George98c95622014-06-20 19:14:25 -07002015 int32_t i;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002016
Haynes Mathew George98c95622014-06-20 19:14:25 -07002017 if (table == NULL) {
2018 ALOGE("%s: table is NULL", __func__);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002019 ret = -ENODEV;
2020 goto done;
2021 }
2022
Haynes Mathew George98c95622014-06-20 19:14:25 -07002023 if (name == NULL) {
2024 ALOGE("null key");
2025 ret = -ENODEV;
2026 goto done;
2027 }
2028
2029 for (i=0; i < len; i++) {
2030 if (!strcmp(table[i].name, name)) {
2031 ret = table[i].index;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002032 goto done;
2033 }
2034 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07002035 ALOGE("%s: Could not find index for name = %s",
2036 __func__, name);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002037 ret = -ENODEV;
2038done:
2039 return ret;
2040}
2041
Haynes Mathew George98c95622014-06-20 19:14:25 -07002042int platform_get_snd_device_index(char *device_name)
2043{
2044 return find_index(snd_device_name_index, SND_DEVICE_MAX, device_name);
2045}
2046
2047int platform_get_usecase_index(const char *usecase_name)
2048{
2049 return find_index(usecase_name_index, AUDIO_USECASE_MAX, usecase_name);
2050}
2051
keunhui.park2f7306a2015-07-16 16:48:06 +09002052void platform_add_operator_specific_device(snd_device_t snd_device,
2053 const char *operator,
2054 const char *mixer_path,
2055 unsigned int acdb_id)
2056{
2057 struct operator_specific_device *device;
2058
2059 if (operator_specific_device_table[snd_device] == NULL) {
2060 operator_specific_device_table[snd_device] =
2061 (struct listnode *)calloc(1, sizeof(struct listnode));
2062 list_init(operator_specific_device_table[snd_device]);
2063 }
2064
2065 device = (struct operator_specific_device *)calloc(1, sizeof(struct operator_specific_device));
2066
2067 device->operator = strdup(operator);
2068 device->mixer_path = strdup(mixer_path);
2069 device->acdb_id = acdb_id;
2070
2071 list_add_tail(operator_specific_device_table[snd_device], &device->list);
2072
Eric Laurent2bafff12016-03-17 12:17:23 -07002073 ALOGD("%s: device[%s] -> operator[%s] mixer_path[%s] acdb_id[%d]", __func__,
keunhui.park2f7306a2015-07-16 16:48:06 +09002074 platform_get_snd_device_name(snd_device), operator, mixer_path, acdb_id);
2075
2076}
2077
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002078int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
2079{
2080 int ret = 0;
2081
2082 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
2083 ALOGE("%s: Invalid snd_device = %d",
2084 __func__, snd_device);
2085 ret = -EINVAL;
2086 goto done;
2087 }
2088
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002089 ALOGV("%s: acdb_device_table[%s]: old = %d new = %d", __func__,
2090 platform_get_snd_device_name(snd_device), acdb_device_table[snd_device], acdb_id);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002091 acdb_device_table[snd_device] = acdb_id;
2092done:
2093 return ret;
2094}
2095
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07002096int platform_get_snd_device_acdb_id(snd_device_t snd_device)
2097{
2098 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
2099 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
2100 return -EINVAL;
2101 }
keunhui.park2f7306a2015-07-16 16:48:06 +09002102
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002103 /*
2104 * If speaker protection is enabled, function returns supported
2105 * sound device for speaker. Else same sound device is returned.
2106 */
2107 snd_device = audio_extn_get_spkr_prot_snd_device(snd_device);
2108
keunhui.park2f7306a2015-07-16 16:48:06 +09002109 if (operator_specific_device_table[snd_device] != NULL)
2110 return get_operator_specific_device_acdb_id(snd_device);
2111 else
2112 return acdb_device_table[snd_device];
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07002113}
2114
David Linee3fe402017-03-13 10:00:42 -07002115static int platform_get_backend_index(snd_device_t snd_device)
2116{
2117 int32_t port = DEFAULT_CODEC_BACKEND;
2118
2119 if (snd_device >= SND_DEVICE_OUT_BEGIN && snd_device < SND_DEVICE_OUT_END) {
2120 if (backend_tag_table[snd_device] != NULL) {
2121 if (strncmp(backend_tag_table[snd_device], "headphones",
2122 sizeof("headphones")) == 0)
2123 port = HEADPHONE_BACKEND;
2124 else if (strcmp(backend_tag_table[snd_device], "hdmi") == 0)
2125 port = HDMI_RX_BACKEND;
2126 else if ((strcmp(backend_tag_table[snd_device], "usb-headphones") == 0) ||
2127 (strcmp(backend_tag_table[snd_device], "usb-headset") == 0))
2128 port = USB_AUDIO_RX_BACKEND;
2129 }
2130 } else if (snd_device >= SND_DEVICE_IN_BEGIN && snd_device < SND_DEVICE_IN_END) {
2131 port = DEFAULT_CODEC_TX_BACKEND;
2132 if (backend_tag_table[snd_device] != NULL) {
2133 if (strcmp(backend_tag_table[snd_device], "usb-headset-mic") == 0)
2134 port = USB_AUDIO_TX_BACKEND;
2135 else if (strstr(backend_tag_table[snd_device], "bt-sco") != NULL)
2136 port = BT_SCO_TX_BACKEND;
2137 }
2138 } else {
2139 ALOGW("%s:napb: Invalid device - %d ", __func__, snd_device);
2140 }
2141
2142 ALOGV("%s:napb: backend port - %d device - %d ", __func__, port, snd_device);
2143
2144 return port;
2145}
2146
Eric Laurentb23d5282013-05-14 15:27:20 -07002147int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
2148{
2149 struct platform_data *my_data = (struct platform_data *)platform;
2150 int acdb_dev_id, acdb_dev_type;
2151
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002152 if (platform_supports_app_type_cfg()) // use v2 instead
2153 return -ENOSYS;
2154
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002155 acdb_dev_id = platform_get_snd_device_acdb_id(snd_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07002156 if (acdb_dev_id < 0) {
2157 ALOGE("%s: Could not find acdb id for device(%d)",
2158 __func__, snd_device);
2159 return -EINVAL;
2160 }
2161 if (my_data->acdb_send_audio_cal) {
Joe Onorato188b6222016-03-01 11:02:27 -08002162 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Eric Laurentb23d5282013-05-14 15:27:20 -07002163 __func__, snd_device, acdb_dev_id);
2164 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
2165 snd_device < SND_DEVICE_OUT_END)
2166 acdb_dev_type = ACDB_DEV_TYPE_OUT;
2167 else
2168 acdb_dev_type = ACDB_DEV_TYPE_IN;
2169 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
2170 }
2171 return 0;
2172}
2173
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002174int platform_send_audio_calibration_v2(void *platform, struct audio_usecase *usecase,
2175 int app_type, int sample_rate)
2176{
2177 struct platform_data *my_data = (struct platform_data *)platform;
2178 int acdb_dev_id, acdb_dev_type;
vivek mehta7e573672018-03-13 17:41:41 -07002179 int snd_device = usecase->out_snd_device;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002180 int new_snd_device[SND_DEVICE_OUT_END] = {0};
2181 int i, num_devices = 1;
2182
2183 if (!platform_supports_app_type_cfg()) // use v1 instead
2184 return -ENOSYS;
2185
vivek mehta7e573672018-03-13 17:41:41 -07002186 if ((usecase->type == PCM_HFP_CALL) || (usecase->type == PCM_CAPTURE))
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002187 snd_device = usecase->in_snd_device;
2188
2189 // skipped over get_spkr_prot_device
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002190 acdb_dev_id = platform_get_snd_device_acdb_id(snd_device);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002191 if (acdb_dev_id < 0) {
2192 ALOGE("%s: Could not find acdb id for device(%d)",
2193 __func__, snd_device);
2194 return -EINVAL;
2195 }
2196
2197 if (platform_can_split_snd_device(snd_device,
2198 &num_devices, new_snd_device) < 0) {
2199 new_snd_device[0] = snd_device;
2200 }
2201
2202 for (i = 0; i < num_devices; i++) {
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002203 acdb_dev_id = platform_get_snd_device_acdb_id(new_snd_device[i]);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002204 if (acdb_dev_id < 0) {
2205 ALOGE("%s: Could not find acdb id for device(%d)",
2206 __func__, new_snd_device[i]);
2207 return -EINVAL;
2208 }
2209 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
2210 __func__, new_snd_device[i], acdb_dev_id);
2211 if (new_snd_device[i] >= SND_DEVICE_OUT_BEGIN &&
2212 new_snd_device[i] < SND_DEVICE_OUT_END)
2213 acdb_dev_type = ACDB_DEV_TYPE_OUT;
2214 else
2215 acdb_dev_type = ACDB_DEV_TYPE_IN;
2216
2217 if (my_data->acdb_send_audio_cal_v3) {
2218 my_data->acdb_send_audio_cal_v3(acdb_dev_id, acdb_dev_type,
2219 app_type, sample_rate, i);
2220 } else if (my_data->acdb_send_audio_cal) {
2221 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type); // this version differs from internal
2222 }
2223 }
2224
2225 return 0;
2226}
2227
2228
Eric Laurentb23d5282013-05-14 15:27:20 -07002229int platform_switch_voice_call_device_pre(void *platform)
2230{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002231 struct platform_data *my_data = (struct platform_data *)platform;
2232 int ret = 0;
2233
2234 if (my_data->csd != NULL &&
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002235 voice_is_in_call(my_data->adev)) {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002236 /* This must be called before disabling mixer controls on APQ side */
2237 ret = my_data->csd->disable_device();
2238 if (ret < 0) {
2239 ALOGE("%s: csd_client_disable_device, failed, error %d",
2240 __func__, ret);
2241 }
2242 }
2243 return ret;
2244}
2245
2246int platform_switch_voice_call_enable_device_config(void *platform,
2247 snd_device_t out_snd_device,
2248 snd_device_t in_snd_device)
2249{
2250 struct platform_data *my_data = (struct platform_data *)platform;
2251 int acdb_rx_id, acdb_tx_id;
2252 int ret = 0;
2253
2254 if (my_data->csd == NULL)
2255 return ret;
2256
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002257 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
keunhui.park2f7306a2015-07-16 16:48:06 +09002258 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002259
2260 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
2261 ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
2262 if (ret < 0) {
2263 ALOGE("%s: csd_enable_device_config, failed, error %d",
2264 __func__, ret);
2265 }
2266 } else {
2267 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2268 acdb_rx_id, acdb_tx_id);
2269 }
2270
2271 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002272}
2273
2274int platform_switch_voice_call_device_post(void *platform,
2275 snd_device_t out_snd_device,
2276 snd_device_t in_snd_device)
2277{
2278 struct platform_data *my_data = (struct platform_data *)platform;
2279 int acdb_rx_id, acdb_tx_id;
2280
2281 if (my_data->acdb_send_voice_cal == NULL) {
2282 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
2283 } else {
keunhui.park2f7306a2015-07-16 16:48:06 +09002284 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
2285 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07002286
2287 if (acdb_rx_id > 0 && acdb_tx_id > 0)
2288 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
2289 else
2290 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2291 acdb_rx_id, acdb_tx_id);
2292 }
2293
2294 return 0;
2295}
2296
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002297int platform_switch_voice_call_usecase_route_post(void *platform,
2298 snd_device_t out_snd_device,
2299 snd_device_t in_snd_device)
2300{
2301 struct platform_data *my_data = (struct platform_data *)platform;
2302 int acdb_rx_id, acdb_tx_id;
2303 int ret = 0;
2304
2305 if (my_data->csd == NULL)
2306 return ret;
2307
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002308 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
keunhui.park2f7306a2015-07-16 16:48:06 +09002309 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002310
2311 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
2312 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
2313 my_data->adev->acdb_settings);
2314 if (ret < 0) {
2315 ALOGE("%s: csd_enable_device, failed, error %d", __func__, ret);
2316 }
2317 } else {
2318 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2319 acdb_rx_id, acdb_tx_id);
2320 }
2321
2322 return ret;
2323}
2324
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002325int platform_start_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07002326{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002327 struct platform_data *my_data = (struct platform_data *)platform;
2328 int ret = 0;
2329
2330 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002331 ret = my_data->csd->start_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002332 if (ret < 0) {
2333 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
2334 }
2335 }
2336 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002337}
2338
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002339int platform_stop_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07002340{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002341 struct platform_data *my_data = (struct platform_data *)platform;
2342 int ret = 0;
2343
2344 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002345 ret = my_data->csd->stop_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002346 if (ret < 0) {
2347 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
2348 }
2349 }
2350 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002351}
2352
Vignesh Kulothunganb6f0a9c2018-03-22 13:50:22 -07002353int platform_set_mic_break_det(void *platform, bool enable)
2354{
2355 int ret = 0;
2356 struct platform_data *my_data = (struct platform_data *)platform;
2357 struct audio_device *adev = my_data->adev;
2358 const char *mixer_ctl_name = "Voice Mic Break Enable";
2359 struct mixer_ctl *ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2360 if (!ctl) {
2361 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2362 __func__, mixer_ctl_name);
2363 return -EINVAL;
2364 }
2365
2366 ret = mixer_ctl_set_value(ctl, 0, enable);
2367 if(ret)
2368 ALOGE("%s: Failed to set mixer ctl: %s", __func__, mixer_ctl_name);
2369
2370 return ret;
2371}
2372
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002373int platform_get_sample_rate(void *platform, uint32_t *rate)
2374{
2375 struct platform_data *my_data = (struct platform_data *)platform;
2376 int ret = 0;
2377
2378 if (my_data->csd != NULL) {
2379 ret = my_data->csd->get_sample_rate(rate);
2380 if (ret < 0) {
2381 ALOGE("%s: csd_get_sample_rate error %d\n", __func__, ret);
2382 }
2383 }
2384 return ret;
2385}
2386
vivek mehtab6506412015-08-07 16:55:17 -07002387void platform_set_speaker_gain_in_combo(struct audio_device *adev,
2388 snd_device_t snd_device,
2389 bool enable)
2390{
2391 const char* name;
2392 switch (snd_device) {
2393 case SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES:
2394 if (enable)
2395 name = "spkr-gain-in-headphone-combo";
2396 else
2397 name = "speaker-gain-default";
2398 break;
2399 case SND_DEVICE_OUT_SPEAKER_AND_LINE:
2400 if (enable)
2401 name = "spkr-gain-in-line-combo";
2402 else
2403 name = "speaker-gain-default";
2404 break;
2405 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES:
2406 if (enable)
2407 name = "spkr-safe-gain-in-headphone-combo";
2408 else
2409 name = "speaker-safe-gain-default";
2410 break;
2411 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE:
2412 if (enable)
2413 name = "spkr-safe-gain-in-line-combo";
2414 else
2415 name = "speaker-safe-gain-default";
2416 break;
2417 default:
2418 return;
2419 }
2420
2421 audio_route_apply_and_update_path(adev->audio_route, name);
2422}
2423
Eric Laurentb23d5282013-05-14 15:27:20 -07002424int platform_set_voice_volume(void *platform, int volume)
2425{
2426 struct platform_data *my_data = (struct platform_data *)platform;
2427 struct audio_device *adev = my_data->adev;
2428 struct mixer_ctl *ctl;
sangwoo53b2cf02013-07-25 19:18:44 -07002429 const char *mixer_ctl_name = "Voice Rx Gain";
Nadav Barc46d0fa2017-12-24 14:50:37 +02002430 const char *mute_mixer_ctl_name = "Voice Rx Device Mute";
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002431 int vol_index = 0, ret = 0;
2432 uint32_t set_values[ ] = {0,
2433 ALL_SESSION_VSID,
2434 DEFAULT_VOLUME_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07002435
2436 // Voice volume levels are mapped to adsp volume levels as follows.
2437 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
2438 // But this values don't changed in kernel. So, below change is need.
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09002439 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, my_data->max_vol_index);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002440 set_values[0] = vol_index;
Eric Laurentb23d5282013-05-14 15:27:20 -07002441
2442 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2443 if (!ctl) {
2444 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2445 __func__, mixer_ctl_name);
2446 return -EINVAL;
2447 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002448 ALOGV("Setting voice volume index: %d", set_values[0]);
2449 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2450
Nadav Barc46d0fa2017-12-24 14:50:37 +02002451 // Send mute command in case volume index is max since indexes are inverted
2452 // for mixer controls.
2453 if (vol_index == my_data->max_vol_index) {
2454 set_values[0] = 1;
2455 }
2456 else {
2457 set_values[0] = 0;
2458 }
2459
2460 ctl = mixer_get_ctl_by_name(adev->mixer, mute_mixer_ctl_name);
2461 if (!ctl) {
2462 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2463 __func__, mute_mixer_ctl_name);
2464 return -EINVAL;
2465 }
2466 ALOGV("%s: Setting RX Device Mute to: %d", __func__, set_values[0]);
2467 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2468
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002469 if (my_data->csd != NULL) {
2470 ret = my_data->csd->volume(ALL_SESSION_VSID, volume,
2471 DEFAULT_VOLUME_RAMP_DURATION_MS);
2472 if (ret < 0) {
2473 ALOGE("%s: csd_volume error %d", __func__, ret);
2474 }
2475 }
2476 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002477}
2478
2479int platform_set_mic_mute(void *platform, bool state)
2480{
2481 struct platform_data *my_data = (struct platform_data *)platform;
2482 struct audio_device *adev = my_data->adev;
2483 struct mixer_ctl *ctl;
2484 const char *mixer_ctl_name = "Voice Tx Mute";
sangwoo53b2cf02013-07-25 19:18:44 -07002485 int ret = 0;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002486 uint32_t set_values[ ] = {0,
2487 ALL_SESSION_VSID,
2488 DEFAULT_MUTE_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07002489
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09002490 if (adev->mode != AUDIO_MODE_IN_CALL &&
2491 adev->mode != AUDIO_MODE_IN_COMMUNICATION)
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002492 return 0;
2493
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09002494 if (adev->enable_hfp)
2495 mixer_ctl_name = "HFP Tx Mute";
2496
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002497 set_values[0] = state;
2498 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2499 if (!ctl) {
2500 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2501 __func__, mixer_ctl_name);
2502 return -EINVAL;
2503 }
2504 ALOGV("Setting voice mute state: %d", state);
2505 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2506
2507 if (my_data->csd != NULL) {
2508 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state,
2509 DEFAULT_MUTE_RAMP_DURATION_MS);
sangwoo53b2cf02013-07-25 19:18:44 -07002510 if (ret < 0) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002511 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
sangwoo53b2cf02013-07-25 19:18:44 -07002512 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002513 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002514 return ret;
2515}
Eric Laurentb23d5282013-05-14 15:27:20 -07002516
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002517int platform_set_device_mute(void *platform, bool state, char *dir)
2518{
2519 struct platform_data *my_data = (struct platform_data *)platform;
2520 struct audio_device *adev = my_data->adev;
2521 struct mixer_ctl *ctl;
2522 char *mixer_ctl_name = NULL;
2523 int ret = 0;
2524 uint32_t set_values[ ] = {0,
2525 ALL_SESSION_VSID,
2526 0};
2527 if(dir == NULL) {
2528 ALOGE("%s: Invalid direction:%s", __func__, dir);
2529 return -EINVAL;
2530 }
2531
2532 if (!strncmp("rx", dir, sizeof("rx"))) {
2533 mixer_ctl_name = "Voice Rx Device Mute";
2534 } else if (!strncmp("tx", dir, sizeof("tx"))) {
2535 mixer_ctl_name = "Voice Tx Device Mute";
2536 } else {
2537 return -EINVAL;
2538 }
2539
2540 set_values[0] = state;
2541 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2542 if (!ctl) {
2543 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2544 __func__, mixer_ctl_name);
2545 return -EINVAL;
2546 }
2547
2548 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
2549 __func__,state, mixer_ctl_name);
2550 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2551
2552 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002553}
2554
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002555int platform_can_split_snd_device(snd_device_t snd_device,
2556 int *num_devices,
2557 snd_device_t *new_snd_devices)
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002558{
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002559 int ret = -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002560 if (NULL == num_devices || NULL == new_snd_devices) {
2561 ALOGE("%s: NULL pointer ..", __func__);
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002562 return -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002563 }
2564
2565 /*
2566 * If wired headset/headphones/line devices share the same backend
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002567 * with speaker/earpiece this routine returns -EINVAL.
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002568 */
2569 if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES &&
2570 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_HEADPHONES)) {
2571 *num_devices = 2;
2572 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2573 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002574 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002575 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_LINE &&
2576 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_LINE)) {
2577 *num_devices = 2;
2578 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2579 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002580 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002581 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES &&
2582 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_HEADPHONES)) {
2583 *num_devices = 2;
2584 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2585 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002586 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002587 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE &&
2588 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_LINE)) {
2589 *num_devices = 2;
2590 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2591 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002592 ret = 0;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002593 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO &&
2594 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2595 SND_DEVICE_OUT_BT_SCO)) {
2596 *num_devices = 2;
2597 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2598 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO;
2599 ret = 0;
juyuchen5351ea62018-05-16 10:54:37 +08002600 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO &&
2601 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE,
2602 SND_DEVICE_OUT_BT_SCO)) {
2603 *num_devices = 2;
2604 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2605 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO;
2606 ret = 0;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002607 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB &&
2608 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2609 SND_DEVICE_OUT_BT_SCO_WB)) {
2610 *num_devices = 2;
2611 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2612 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO_WB;
2613 ret = 0;
juyuchen5351ea62018-05-16 10:54:37 +08002614 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB &&
2615 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE,
2616 SND_DEVICE_OUT_BT_SCO_WB)) {
2617 *num_devices = 2;
2618 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2619 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO_WB;
2620 ret = 0;
David Linee3fe402017-03-13 10:00:42 -07002621 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET &&
2622 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_USB_HEADSET)) {
2623 *num_devices = 2;
2624 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2625 new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
2626 ret = 0;
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07002627 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET &&
2628 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_USB_HEADSET)) {
2629 *num_devices = 2;
2630 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2631 new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
2632 ret = 0;
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002633 } else if (SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP == snd_device &&
2634 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2635 SND_DEVICE_OUT_BT_A2DP)) {
2636 *num_devices = 2;
2637 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2638 new_snd_devices[1] = SND_DEVICE_OUT_BT_A2DP;
2639 ret = 0;
Aniket Kumar Lata9723a962018-05-16 17:41:55 -07002640 } else if (SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP == snd_device &&
2641 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE,
2642 SND_DEVICE_OUT_BT_A2DP)) {
2643 *num_devices = 2;
2644 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2645 new_snd_devices[1] = SND_DEVICE_OUT_BT_A2DP;
2646 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002647 }
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002648
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002649 return ret;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002650}
2651
Eric Laurentb23d5282013-05-14 15:27:20 -07002652snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
2653{
2654 struct platform_data *my_data = (struct platform_data *)platform;
2655 struct audio_device *adev = my_data->adev;
2656 audio_mode_t mode = adev->mode;
2657 snd_device_t snd_device = SND_DEVICE_NONE;
2658
2659 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
2660 if (devices == AUDIO_DEVICE_NONE ||
2661 devices & AUDIO_DEVICE_BIT_IN) {
2662 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
2663 goto exit;
2664 }
2665
Eric Laurent1b491552015-09-15 17:52:41 -07002666 if (popcount(devices) == 2) {
2667 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2668 AUDIO_DEVICE_OUT_SPEAKER) ||
2669 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2670 AUDIO_DEVICE_OUT_SPEAKER)) {
2671 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
2672 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2673 AUDIO_DEVICE_OUT_SPEAKER)) {
2674 snd_device = SND_DEVICE_OUT_SPEAKER_AND_LINE;
2675 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2676 AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
2677 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2678 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2679 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES;
2680 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2681 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2682 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE;
2683 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
2684 AUDIO_DEVICE_OUT_SPEAKER)) {
2685 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002686 } else if ((devices & AUDIO_DEVICE_OUT_ALL_SCO) &&
2687 ((devices & ~AUDIO_DEVICE_OUT_ALL_SCO) == AUDIO_DEVICE_OUT_SPEAKER)) {
2688 snd_device = adev->bt_wb_speech_enabled ?
2689 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB :
2690 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO;
juyuchen5351ea62018-05-16 10:54:37 +08002691 } else if ((devices & AUDIO_DEVICE_OUT_ALL_SCO) &&
2692 ((devices & ~AUDIO_DEVICE_OUT_ALL_SCO) == AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2693 snd_device = adev->bt_wb_speech_enabled ?
2694 SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB :
2695 SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO;
Eric Laurent99dab492017-06-17 15:19:08 -07002696 } else if ((devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
2697 AUDIO_DEVICE_OUT_SPEAKER)) ||
2698 (devices == (AUDIO_DEVICE_OUT_USB_HEADSET |
2699 AUDIO_DEVICE_OUT_SPEAKER))) {
David Linee3fe402017-03-13 10:00:42 -07002700 snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET;
Eric Laurentd0f7c262017-07-05 09:09:12 -07002701 } else if ((devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
2702 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) ||
2703 (devices == (AUDIO_DEVICE_OUT_USB_HEADSET |
2704 AUDIO_DEVICE_OUT_SPEAKER_SAFE))) {
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07002705 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET;
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002706 } else if ((devices & AUDIO_DEVICE_OUT_SPEAKER) &&
2707 (devices & AUDIO_DEVICE_OUT_ALL_A2DP)) {
2708 snd_device = SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP;
Aniket Kumar Lata9723a962018-05-16 17:41:55 -07002709 } else if ((devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) &&
2710 (devices & AUDIO_DEVICE_OUT_ALL_A2DP)) {
2711 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP;
Eric Laurent1b491552015-09-15 17:52:41 -07002712 } else {
2713 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
2714 goto exit;
2715 }
2716 if (snd_device != SND_DEVICE_NONE) {
2717 goto exit;
2718 }
2719 }
2720
2721 if (popcount(devices) != 1) {
2722 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
2723 goto exit;
2724 }
2725
Madhuri Athota3f6051b2016-10-13 23:25:38 +05302726 if (voice_is_in_call(adev) || adev->enable_voicerx || audio_extn_hfp_is_active(adev)) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002727 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002728 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2729 devices & AUDIO_DEVICE_OUT_LINE) {
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002730 if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002731 (adev->voice.tty_mode == TTY_MODE_FULL))
Eric Laurentb23d5282013-05-14 15:27:20 -07002732 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002733 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002734 (adev->voice.tty_mode == TTY_MODE_VCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002735 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002736 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002737 (adev->voice.tty_mode == TTY_MODE_HCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002738 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002739 else {
2740 if (devices & AUDIO_DEVICE_OUT_LINE)
2741 snd_device = SND_DEVICE_OUT_VOICE_LINE;
2742 else
2743 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
2744 }
Eric Laurent99dab492017-06-17 15:19:08 -07002745 } else if (audio_is_usb_out_device(devices)) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002746 if (voice_is_in_call(adev)) {
2747 switch (adev->voice.tty_mode) {
2748 case TTY_MODE_FULL:
2749 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_USB;
2750 break;
2751 case TTY_MODE_VCO:
2752 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_USB;
2753 break;
2754 case TTY_MODE_HCO:
2755 // since Hearing will be on handset\speaker, use existing device
2756 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
2757 break;
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002758 case TTY_MODE_OFF:
2759 break;
vivek mehtaa6b79742017-03-09 15:40:43 -08002760 default:
2761 ALOGE("%s: Invalid TTY mode (%#x)",
2762 __func__, adev->voice.tty_mode);
2763 }
2764 }
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002765 if (snd_device == SND_DEVICE_NONE) {
2766 snd_device = audio_extn_usb_is_capture_supported() ?
2767 SND_DEVICE_OUT_VOICE_USB_HEADSET :
2768 SND_DEVICE_OUT_VOICE_USB_HEADPHONES;
2769 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002770 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002771 if (adev->bt_wb_speech_enabled) {
2772 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2773 } else {
2774 snd_device = SND_DEVICE_OUT_BT_SCO;
2775 }
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002776 } else if (devices & AUDIO_DEVICE_OUT_ALL_A2DP) {
2777 snd_device = SND_DEVICE_OUT_BT_A2DP;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002778 } else if (devices & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002779 if (!adev->enable_hfp) {
2780 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
2781 } else {
2782 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_HFP;
2783 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002784 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002785 if(adev->voice.hac)
2786 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2787 else if (is_operator_tmus())
Eric Laurentb23d5282013-05-14 15:27:20 -07002788 snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS;
2789 else
Eric Laurentb4d368e2014-06-25 10:21:54 -05002790 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002791 } else if (devices & AUDIO_DEVICE_OUT_TELEPHONY_TX)
2792 snd_device = SND_DEVICE_OUT_VOICE_TX;
2793
Eric Laurentb23d5282013-05-14 15:27:20 -07002794 if (snd_device != SND_DEVICE_NONE) {
2795 goto exit;
2796 }
2797 }
2798
Eric Laurentb23d5282013-05-14 15:27:20 -07002799 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2800 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2801 snd_device = SND_DEVICE_OUT_HEADPHONES;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002802 } else if (devices & AUDIO_DEVICE_OUT_LINE) {
2803 snd_device = SND_DEVICE_OUT_LINE;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002804 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) {
2805 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE;
Eric Laurentb23d5282013-05-14 15:27:20 -07002806 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
andysu5b30b062018-04-20 16:34:06 +08002807 /*
2808 * Perform device switch only if acdb tuning is different between SPEAKER & SPEAKER_REVERSE,
2809 * Or there will be a small pause while performing device switch.
2810 */
2811 if (my_data->speaker_lr_swap &&
2812 (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
2813 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]))
Eric Laurentb23d5282013-05-14 15:27:20 -07002814 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
2815 else
2816 snd_device = SND_DEVICE_OUT_SPEAKER;
2817 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002818 if (adev->bt_wb_speech_enabled) {
2819 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2820 } else {
2821 snd_device = SND_DEVICE_OUT_BT_SCO;
2822 }
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002823 } else if (devices & AUDIO_DEVICE_OUT_ALL_A2DP) {
2824 snd_device = SND_DEVICE_OUT_BT_A2DP;
Eric Laurentb23d5282013-05-14 15:27:20 -07002825 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2826 snd_device = SND_DEVICE_OUT_HDMI ;
Eric Laurent99dab492017-06-17 15:19:08 -07002827 } else if (audio_is_usb_out_device(devices)) {
jasmine cha270b7762018-03-30 15:41:33 +08002828 if (audio_extn_ma_supported_usb())
2829 snd_device = SND_DEVICE_OUT_USB_HEADSET_SPEC;
2830 else if (audio_extn_usb_is_capture_supported())
David Linee3fe402017-03-13 10:00:42 -07002831 snd_device = SND_DEVICE_OUT_USB_HEADSET;
2832 else
2833 snd_device = SND_DEVICE_OUT_USB_HEADPHONES;
2834 }else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002835 /*HAC support for voice-ish audio (eg visual voicemail)*/
2836 if(adev->voice.hac)
2837 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2838 else
2839 snd_device = SND_DEVICE_OUT_HANDSET;
Eric Laurentb23d5282013-05-14 15:27:20 -07002840 } else {
2841 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
2842 }
2843exit:
2844 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
2845 return snd_device;
2846}
2847
2848snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
2849{
2850 struct platform_data *my_data = (struct platform_data *)platform;
2851 struct audio_device *adev = my_data->adev;
2852 audio_source_t source = (adev->active_input == NULL) ?
2853 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
2854
2855 audio_mode_t mode = adev->mode;
2856 audio_devices_t in_device = ((adev->active_input == NULL) ?
2857 AUDIO_DEVICE_NONE : adev->active_input->device)
2858 & ~AUDIO_DEVICE_BIT_IN;
2859 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
2860 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
2861 snd_device_t snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002862 int channel_count = popcount(channel_mask);
Eric Laurentb23d5282013-05-14 15:27:20 -07002863
Prashant Malanic92c5962015-08-11 15:10:18 -07002864 ALOGV("%s: enter: out_device(%#x) in_device(%#x) channel_count (%d) channel_mask (0x%x)",
2865 __func__, out_device, in_device, channel_count, channel_mask);
Devin Kimd789e432016-10-26 15:07:27 -07002866 if ((out_device != AUDIO_DEVICE_NONE) && (voice_is_in_call(adev) ||
2867 audio_extn_hfp_is_active(adev))) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002868 if (adev->voice.tty_mode != TTY_MODE_OFF) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002869 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002870 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2871 out_device & AUDIO_DEVICE_OUT_LINE) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002872 switch (adev->voice.tty_mode) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002873 case TTY_MODE_FULL:
2874 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
2875 break;
2876 case TTY_MODE_VCO:
2877 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
2878 break;
2879 case TTY_MODE_HCO:
2880 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
2881 break;
2882 default:
2883 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
2884 }
2885 goto exit;
Eric Laurent99dab492017-06-17 15:19:08 -07002886 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002887 switch (adev->voice.tty_mode) {
2888 case TTY_MODE_FULL:
2889 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC;
2890 break;
2891 case TTY_MODE_VCO:
2892 // since voice will be captured from handset mic, use existing device
2893 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
2894 break;
2895 case TTY_MODE_HCO:
2896 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC;
2897 break;
2898 default:
2899 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
Eric Laurentb23d5282013-05-14 15:27:20 -07002900 }
2901 goto exit;
2902 }
2903 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002904 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002905 if (my_data->fluence_in_voice_call == false) {
2906 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2907 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002908 if (is_operator_tmus())
2909 snd_device = SND_DEVICE_IN_VOICE_DMIC_TMUS;
Eric Laurentb23d5282013-05-14 15:27:20 -07002910 else
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002911 snd_device = SND_DEVICE_IN_VOICE_DMIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002912 }
2913 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2914 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
2915 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002916 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002917 if (adev->bluetooth_nrec)
2918 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2919 else
2920 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002921 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002922 if (adev->bluetooth_nrec)
2923 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2924 else
2925 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002926 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002927 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Prashant Malanic92c5962015-08-11 15:10:18 -07002928 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
2929 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2930 out_device & AUDIO_DEVICE_OUT_LINE) {
2931 if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
2932 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
2933 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
2934 } else {
2935 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2936 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002937 }
vivek mehtafe121d52015-08-10 23:39:23 -07002938
2939 //select default
2940 if (snd_device == SND_DEVICE_NONE) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002941 if (!adev->enable_hfp) {
2942 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2943 } else {
2944 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP;
2945 platform_set_echo_reference(adev, true, out_device);
2946 }
vivek mehtafe121d52015-08-10 23:39:23 -07002947 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002948 } else if (out_device & AUDIO_DEVICE_OUT_TELEPHONY_TX) {
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002949 snd_device = SND_DEVICE_IN_VOICE_RX;
Eric Laurent99dab492017-06-17 15:19:08 -07002950 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
David Lin40b07892017-08-07 15:02:48 -07002951 if (audio_extn_usb_is_capture_supported()) {
2952 snd_device = SND_DEVICE_IN_VOICE_USB_HEADSET_MIC;
2953 } else if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
2954 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
2955 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
2956 } else {
2957 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2958 }
2959 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002960 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002961 } else if (source == AUDIO_SOURCE_CAMCORDER) {
2962 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
2963 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Eric Laurent57274392018-10-19 17:33:43 -07002964 switch (adev->camera_orientation) {
2965 case CAMERA_BACK_LANDSCAPE:
2966 snd_device = SND_DEVICE_IN_CAMCORDER_LANDSCAPE;
2967 break;
2968 case CAMERA_BACK_INVERT_LANDSCAPE:
2969 snd_device = SND_DEVICE_IN_CAMCORDER_INVERT_LANDSCAPE;
2970 break;
2971 case CAMERA_BACK_PORTRAIT:
2972 snd_device = SND_DEVICE_IN_CAMCORDER_PORTRAIT;
2973 break;
2974 case CAMERA_FRONT_LANDSCAPE:
2975 snd_device = SND_DEVICE_IN_CAMCORDER_SELFIE_LANDSCAPE;
2976 break;
2977 case CAMERA_FRONT_INVERT_LANDSCAPE:
2978 snd_device = SND_DEVICE_IN_CAMCORDER_SELFIE_INVERT_LANDSCAPE;
2979 break;
2980 case CAMERA_FRONT_PORTRAIT:
2981 snd_device = SND_DEVICE_IN_CAMCORDER_SELFIE_PORTRAIT;
2982 break;
2983 default:
2984 ALOGW("%s: invalid camera orientation %08x", __func__, adev->camera_orientation);
2985 snd_device = SND_DEVICE_IN_CAMCORDER_LANDSCAPE;
2986 break;
2987 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002988 }
2989 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
2990 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002991 if (my_data->fluence_in_voice_rec && channel_count == 1) {
2992 if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2993 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002994 if (adev->active_input->enable_aec)
2995 snd_device = SND_DEVICE_IN_HANDSET_QMIC_AEC;
2996 else
2997 snd_device = SND_DEVICE_IN_HANDSET_QMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002998 } else if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2999 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07003000 if (adev->active_input->enable_aec)
3001 snd_device = SND_DEVICE_IN_HANDSET_TMIC_AEC;
3002 else
3003 snd_device = SND_DEVICE_IN_HANDSET_TMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003004 } else if (((my_data->fluence_type == FLUENCE_PRO_ENABLE) ||
3005 (my_data->fluence_type == FLUENCE_ENABLE)) &&
3006 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07003007 if (adev->active_input->enable_aec)
3008 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
3009 else
3010 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
Prashant Malanic92c5962015-08-11 15:10:18 -07003011 }
3012 platform_set_echo_reference(adev, true, out_device);
3013 } else if ((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) &&
3014 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
3015 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003016 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003017 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
3018 snd_device = SND_DEVICE_IN_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003019 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003020 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
3021 snd_device = SND_DEVICE_IN_QUAD_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07003022 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003023 if (snd_device == SND_DEVICE_NONE) {
vivek mehtaf3440682016-05-11 14:24:37 -07003024 if (adev->active_input->enable_aec) {
3025 if (adev->active_input->enable_ns) {
3026 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS;
3027 } else {
3028 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC;
3029 }
vivek mehta733c1df2016-04-04 15:09:24 -07003030 platform_set_echo_reference(adev, true, out_device);
vivek mehtaf3440682016-05-11 14:24:37 -07003031 } else if (adev->active_input->enable_ns) {
3032 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
3033 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003034 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
vivek mehtaf3440682016-05-11 14:24:37 -07003035 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003036 }
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -07003037 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3038 snd_device = SND_DEVICE_IN_VOICE_REC_HEADSET_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07003039 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07003040 snd_device = SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07003041 }
rago90fb9612015-12-02 11:37:53 -08003042 } else if (source == AUDIO_SOURCE_UNPROCESSED) {
3043 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
vivek mehta4ed66e62016-04-15 23:33:34 -07003044 if (((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) ||
3045 (channel_mask == AUDIO_CHANNEL_IN_STEREO)) &&
3046 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
3047 snd_device = SND_DEVICE_IN_UNPROCESSED_STEREO_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003048 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07003049 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
3050 snd_device = SND_DEVICE_IN_UNPROCESSED_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003051 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07003052 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
3053 snd_device = SND_DEVICE_IN_UNPROCESSED_QUAD_MIC;
3054 } else {
3055 snd_device = SND_DEVICE_IN_UNPROCESSED_MIC;
3056 }
rago90fb9612015-12-02 11:37:53 -08003057 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3058 snd_device = SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07003059 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07003060 snd_device = SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC;
rago90fb9612015-12-02 11:37:53 -08003061 }
Eric Laurent50a38ed2015-10-14 18:48:06 -07003062 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION ||
rago90fb9612015-12-02 11:37:53 -08003063 mode == AUDIO_MODE_IN_COMMUNICATION) {
David Lin40b07892017-08-07 15:02:48 -07003064 if (out_device & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
3065 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
3066 (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE | AUDIO_DEVICE_OUT_USB_HEADSET) &&
3067 !audio_extn_usb_is_capture_supported())) {
Eric Laurentb23d5282013-05-14 15:27:20 -07003068 in_device = AUDIO_DEVICE_IN_BACK_MIC;
David Lin40b07892017-08-07 15:02:48 -07003069 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003070 if (adev->active_input) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003071 if (adev->active_input->enable_aec &&
3072 adev->active_input->enable_ns) {
Eric Laurentb23d5282013-05-14 15:27:20 -07003073 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003074 if (my_data->fluence_in_spkr_mode &&
3075 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003076 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003077 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003078 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003079 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003080 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003081 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003082 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003083 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003084 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003085 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003086 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003087 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05003088 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3089 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Eric Laurent99dab492017-06-17 15:19:08 -07003090 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07003091 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
Eric Laurentb23d5282013-05-14 15:27:20 -07003092 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05003093 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003094 } else if (adev->active_input->enable_aec) {
3095 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
3096 if (my_data->fluence_in_spkr_mode &&
3097 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003098 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003099 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003100 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003101 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003102 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003103 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
3104 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003105 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003106 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003107 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003108 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003109 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05003110 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3111 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Eric Laurent99dab492017-06-17 15:19:08 -07003112 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07003113 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
Eric Laurentcefbbac2014-09-04 13:54:10 -05003114 }
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08003115 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003116 } else if (adev->active_input->enable_ns) {
3117 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
3118 if (my_data->fluence_in_spkr_mode &&
3119 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003120 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003121 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003122 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003123 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003124 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003125 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
3126 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003127 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003128 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003129 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003130 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003131 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003132 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05003133 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003134 }
3135 } else if (source == AUDIO_SOURCE_DEFAULT) {
3136 goto exit;
3137 }
3138
3139
3140 if (snd_device != SND_DEVICE_NONE) {
3141 goto exit;
3142 }
3143
3144 if (in_device != AUDIO_DEVICE_NONE &&
3145 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
3146 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
3147 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003148 if ((my_data->source_mic_type & SOURCE_QUAD_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003149 channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003150 snd_device = SND_DEVICE_IN_QUAD_MIC;
3151 } else if ((my_data->source_mic_type & SOURCE_THREE_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003152 channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003153 snd_device = SND_DEVICE_IN_THREE_MIC;
3154 } else if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
3155 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003156 snd_device = SND_DEVICE_IN_HANDSET_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07003157 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
3158 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003159 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003160 } else {
3161 ALOGE("%s: something wrong (1): source type (%d) channel_count (%d) .."
3162 " channel mask (0x%x) no combination found .. setting to mono", __func__,
3163 my_data->source_mic_type, channel_count, channel_mask);
3164 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3165 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003166 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003167 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
3168 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003169 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07003170 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
3171 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003172 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003173 } else {
3174 ALOGE("%s: something wrong (2): source type (%d) channel_count (%d) .."
3175 " no combination found .. setting to mono", __func__,
3176 my_data->source_mic_type, channel_count);
3177 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
3178 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003179 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3180 snd_device = SND_DEVICE_IN_HEADSET_MIC;
3181 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003182 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003183 if (adev->bluetooth_nrec)
3184 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
3185 else
3186 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003187 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003188 if (adev->bluetooth_nrec)
3189 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
3190 else
3191 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003192 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003193 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
3194 snd_device = SND_DEVICE_IN_HDMI_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07003195 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
David Linee3fe402017-03-13 10:00:42 -07003196 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07003197 } else {
3198 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
3199 ALOGW("%s: Using default handset-mic", __func__);
3200 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3201 }
3202 } else {
3203 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
3204 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3205 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
3206 snd_device = SND_DEVICE_IN_HEADSET_MIC;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003207 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07003208 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003209 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05003210 out_device & AUDIO_DEVICE_OUT_LINE) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003211 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
3212 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003213 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07003214 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
3215 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003216 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003217 } else {
3218 ALOGE("%s: something wrong (3): source type (%d) channel_count (%d) .."
3219 " no combination found .. setting to mono", __func__,
3220 my_data->source_mic_type, channel_count);
3221 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
3222 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003223 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003224 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003225 if (adev->bluetooth_nrec)
3226 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
3227 else
3228 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003229 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003230 if (adev->bluetooth_nrec)
3231 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
3232 else
3233 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003234 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003235 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
3236 snd_device = SND_DEVICE_IN_HDMI_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07003237 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
David Linee3fe402017-03-13 10:00:42 -07003238 if (audio_extn_usb_is_capture_supported())
3239 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
3240 else
3241 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07003242 } else {
3243 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
3244 ALOGW("%s: Using default handset-mic", __func__);
3245 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3246 }
3247 }
3248exit:
3249 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
3250 return snd_device;
3251}
3252
3253int platform_set_hdmi_channels(void *platform, int channel_count)
3254{
3255 struct platform_data *my_data = (struct platform_data *)platform;
3256 struct audio_device *adev = my_data->adev;
3257 struct mixer_ctl *ctl;
3258 const char *channel_cnt_str = NULL;
3259 const char *mixer_ctl_name = "HDMI_RX Channels";
3260 switch (channel_count) {
3261 case 8:
3262 channel_cnt_str = "Eight"; break;
3263 case 7:
3264 channel_cnt_str = "Seven"; break;
3265 case 6:
3266 channel_cnt_str = "Six"; break;
3267 case 5:
3268 channel_cnt_str = "Five"; break;
3269 case 4:
3270 channel_cnt_str = "Four"; break;
3271 case 3:
3272 channel_cnt_str = "Three"; break;
3273 default:
3274 channel_cnt_str = "Two"; break;
3275 }
3276 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3277 if (!ctl) {
3278 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3279 __func__, mixer_ctl_name);
3280 return -EINVAL;
3281 }
3282 ALOGV("HDMI channel count: %s", channel_cnt_str);
3283 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
3284 return 0;
3285}
3286
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003287int platform_edid_get_max_channels(void *platform)
Eric Laurentb23d5282013-05-14 15:27:20 -07003288{
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003289 struct platform_data *my_data = (struct platform_data *)platform;
3290 struct audio_device *adev = my_data->adev;
Eric Laurentb23d5282013-05-14 15:27:20 -07003291 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
3292 char *sad = block;
3293 int num_audio_blocks;
3294 int channel_count;
3295 int max_channels = 0;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003296 int i, ret, count;
Eric Laurentb23d5282013-05-14 15:27:20 -07003297
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003298 struct mixer_ctl *ctl;
3299
3300 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
3301 if (!ctl) {
3302 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3303 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
Eric Laurentb23d5282013-05-14 15:27:20 -07003304 return 0;
3305 }
3306
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003307 mixer_ctl_update(ctl);
3308
3309 count = mixer_ctl_get_num_values(ctl);
Eric Laurentb23d5282013-05-14 15:27:20 -07003310
3311 /* Read SAD blocks, clamping the maximum size for safety */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003312 if (count > (int)sizeof(block))
3313 count = (int)sizeof(block);
Eric Laurentb23d5282013-05-14 15:27:20 -07003314
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003315 ret = mixer_ctl_get_array(ctl, block, count);
3316 if (ret != 0) {
3317 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
3318 return 0;
3319 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003320
3321 /* Calculate the number of SAD blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003322 num_audio_blocks = count / SAD_BLOCK_SIZE;
Eric Laurentb23d5282013-05-14 15:27:20 -07003323
3324 for (i = 0; i < num_audio_blocks; i++) {
3325 /* Only consider LPCM blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003326 if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
3327 sad += 3;
Eric Laurentb23d5282013-05-14 15:27:20 -07003328 continue;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003329 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003330
3331 channel_count = (sad[0] & 0x7) + 1;
3332 if (channel_count > max_channels)
3333 max_channels = channel_count;
3334
3335 /* Advance to next block */
3336 sad += 3;
3337 }
3338
3339 return max_channels;
3340}
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003341
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07003342int platform_set_incall_recording_session_id(void *platform,
3343 uint32_t session_id, int rec_mode)
3344{
3345 int ret = 0;
3346 struct platform_data *my_data = (struct platform_data *)platform;
3347 struct audio_device *adev = my_data->adev;
3348 struct mixer_ctl *ctl;
3349 const char *mixer_ctl_name = "Voc VSID";
3350 int num_ctl_values;
3351 int i;
3352
3353 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3354 if (!ctl) {
3355 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3356 __func__, mixer_ctl_name);
3357 ret = -EINVAL;
3358 } else {
3359 num_ctl_values = mixer_ctl_get_num_values(ctl);
3360 for (i = 0; i < num_ctl_values; i++) {
3361 if (mixer_ctl_set_value(ctl, i, session_id)) {
3362 ALOGV("Error: invalid session_id: %x", session_id);
3363 ret = -EINVAL;
3364 break;
3365 }
3366 }
3367 }
3368
3369 if (my_data->csd != NULL) {
3370 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
3371 if (ret < 0) {
3372 ALOGE("%s: csd_client_start_record failed, error %d",
3373 __func__, ret);
3374 }
3375 }
3376
3377 return ret;
3378}
3379
Arun Mirpuriba2749a2018-04-17 14:32:24 -07003380int platform_set_incall_recording_session_channels(void *platform,
3381 uint32_t channel_count)
3382{
3383 int ret = 0;
3384 struct platform_data *my_data = (struct platform_data *)platform;
3385 struct audio_device *adev = my_data->adev;
3386 const char *mixer_ctl_name = "Voc Rec Config";
3387 int num_ctl_values;
3388 int i;
3389 struct mixer_ctl *ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3390
3391 if (!ctl) {
3392 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3393 __func__, mixer_ctl_name);
3394 ret = -EINVAL;
3395 } else {
3396 num_ctl_values = mixer_ctl_get_num_values(ctl);
3397 for (i = 0; i < num_ctl_values; i++) {
3398 if (mixer_ctl_set_value(ctl, i, channel_count)) {
3399 ALOGE("Error: invalid channel count: %x", channel_count);
3400 ret = -EINVAL;
3401 break;
3402 }
3403 }
3404 }
3405
3406 return ret;
3407}
3408
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07003409int platform_stop_incall_recording_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_record(ALL_SESSION_VSID);
3416 if (ret < 0) {
3417 ALOGE("%s: csd_client_stop_record failed, error %d",
3418 __func__, ret);
3419 }
3420 }
3421
3422 return ret;
3423}
3424
3425int platform_start_incall_music_usecase(void *platform)
3426{
3427 int ret = 0;
3428 struct platform_data *my_data = (struct platform_data *)platform;
3429
3430 if (my_data->csd != NULL) {
3431 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
3432 if (ret < 0) {
3433 ALOGE("%s: csd_client_start_playback failed, error %d",
3434 __func__, ret);
3435 }
3436 }
3437
3438 return ret;
3439}
3440
3441int platform_stop_incall_music_usecase(void *platform)
3442{
3443 int ret = 0;
3444 struct platform_data *my_data = (struct platform_data *)platform;
3445
3446 if (my_data->csd != NULL) {
3447 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
3448 if (ret < 0) {
3449 ALOGE("%s: csd_client_stop_playback failed, error %d",
3450 __func__, ret);
3451 }
3452 }
3453
3454 return ret;
3455}
3456
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003457int platform_set_parameters(void *platform, struct str_parms *parms)
3458{
3459 struct platform_data *my_data = (struct platform_data *)platform;
jasmine chac89321b2018-04-10 21:37:01 +08003460 char *value = NULL;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003461 char *kv_pairs = str_parms_to_str(parms);
jasmine chac89321b2018-04-10 21:37:01 +08003462 int len;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003463 int ret = 0, err;
3464
3465 if (kv_pairs == NULL) {
3466 ret = -EINVAL;
Jasmine Chaa314e192018-05-09 17:46:28 +08003467 ALOGE("%s: key-value pair is NULL", __func__);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003468 goto done;
3469 }
3470
3471 ALOGV("%s: enter: %s", __func__, kv_pairs);
3472
jasmine chac89321b2018-04-10 21:37:01 +08003473 len = strlen(kv_pairs);
Jasmine Chaa314e192018-05-09 17:46:28 +08003474 value = (char*)calloc(len + 1, sizeof(char));
jasmine chac89321b2018-04-10 21:37:01 +08003475 if (value == NULL) {
3476 ret = -ENOMEM;
Jasmine Chaa314e192018-05-09 17:46:28 +08003477 ALOGE("[%s] failed to allocate memory", __func__);
jasmine chac89321b2018-04-10 21:37:01 +08003478 goto done;
3479 }
3480
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003481 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME,
jasmine chac89321b2018-04-10 21:37:01 +08003482 value, len);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003483 if (err >= 0) {
3484 str_parms_del(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME);
3485 my_data->snd_card_name = strdup(value);
3486 ALOGV("%s: sound card name %s", __func__, my_data->snd_card_name);
3487 }
3488
keunhui.park2f7306a2015-07-16 16:48:06 +09003489 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO,
jasmine chac89321b2018-04-10 21:37:01 +08003490 value, len);
keunhui.park2f7306a2015-07-16 16:48:06 +09003491 if (err >= 0) {
3492 struct operator_info *info;
3493 char *str = value;
3494 char *name;
3495
3496 str_parms_del(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO);
3497 info = (struct operator_info *)calloc(1, sizeof(struct operator_info));
3498 name = strtok(str, ";");
3499 info->name = strdup(name);
3500 info->mccmnc = strdup(str + strlen(name) + 1);
3501
3502 list_add_tail(&operator_info_list, &info->list);
Joe Onorato188b6222016-03-01 11:02:27 -08003503 ALOGV("%s: add operator[%s] mccmnc[%s]", __func__, info->name, info->mccmnc);
keunhui.park2f7306a2015-07-16 16:48:06 +09003504 }
Prashant Malanic92c5962015-08-11 15:10:18 -07003505
Jasmine Chaa314e192018-05-09 17:46:28 +08003506 memset(value, 0, len + 1);
Eric Laurentc6333382015-09-14 12:43:44 -07003507 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT,
jasmine chac89321b2018-04-10 21:37:01 +08003508 value, len);
Prashant Malanic92c5962015-08-11 15:10:18 -07003509 if (err >= 0) {
Eric Laurentc6333382015-09-14 12:43:44 -07003510 str_parms_del(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT);
Prashant Malanic92c5962015-08-11 15:10:18 -07003511 my_data->max_mic_count = atoi(value);
3512 ALOGV("%s: max_mic_count %s/%d", __func__, value, my_data->max_mic_count);
Prashant Malanic92c5962015-08-11 15:10:18 -07003513 }
3514
jasmine chac89321b2018-04-10 21:37:01 +08003515 /* handle audio calibration parameters */
3516 set_audiocal(platform, parms, value, len);
3517
vivek mehta90933872017-06-15 18:04:39 -07003518 // to-do: disable setting sidetone gain, will revist this later
3519 // audio_extn_usb_set_sidetone_gain(parms, value, len);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003520done:
3521 ALOGV("%s: exit with code(%d)", __func__, ret);
3522 if (kv_pairs != NULL)
3523 free(kv_pairs);
jasmine chac89321b2018-04-10 21:37:01 +08003524 if (value != NULL)
3525 free(value);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003526
3527 return ret;
3528}
3529
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003530/* Delay in Us */
3531int64_t platform_render_latency(audio_usecase_t usecase)
3532{
3533 switch (usecase) {
3534 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
3535 return DEEP_BUFFER_PLATFORM_DELAY;
3536 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
3537 return LOW_LATENCY_PLATFORM_DELAY;
Haynes Mathew George03c40102016-01-29 17:57:48 -08003538 case USECASE_AUDIO_PLAYBACK_ULL:
3539 return ULL_PLATFORM_DELAY;
Eric Laurent0e46adf2016-12-16 12:49:24 -08003540 case USECASE_AUDIO_PLAYBACK_MMAP:
3541 return MMAP_PLATFORM_DELAY;
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003542 default:
3543 return 0;
3544 }
3545}
Haynes Mathew George98c95622014-06-20 19:14:25 -07003546
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003547int platform_set_snd_device_backend(snd_device_t device, const char *backend_tag,
3548 const char * hw_interface)
Haynes Mathew George98c95622014-06-20 19:14:25 -07003549{
3550 int ret = 0;
3551
3552 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
3553 ALOGE("%s: Invalid snd_device = %d",
3554 __func__, device);
3555 ret = -EINVAL;
3556 goto done;
3557 }
3558
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003559 ALOGV("%s: backend_tag_table[%s]: old = %s new = %s", __func__,
3560 platform_get_snd_device_name(device),
3561 backend_tag_table[device] != NULL ? backend_tag_table[device]: "null", backend_tag);
3562 if (backend_tag_table[device]) {
3563 free(backend_tag_table[device]);
Haynes Mathew George98c95622014-06-20 19:14:25 -07003564 }
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003565 backend_tag_table[device] = strdup(backend_tag);
3566
3567 if (hw_interface != NULL) {
3568 if (hw_interface_table[device])
3569 free(hw_interface_table[device]);
3570 ALOGV("%s: hw_interface_table[%d] = %s", __func__, device, hw_interface);
3571 hw_interface_table[device] = strdup(hw_interface);
3572 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07003573done:
3574 return ret;
3575}
3576
3577int platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t pcm_id)
3578{
3579 int ret = 0;
3580 if ((usecase <= USECASE_INVALID) || (usecase >= AUDIO_USECASE_MAX)) {
3581 ALOGE("%s: invalid usecase case idx %d", __func__, usecase);
3582 ret = -EINVAL;
3583 goto done;
3584 }
3585
3586 if ((type != 0) && (type != 1)) {
3587 ALOGE("%s: invalid usecase type", __func__);
3588 ret = -EINVAL;
3589 }
vivek mehtaa68fea62017-06-08 19:04:02 -07003590 ALOGV("%s: pcm_device_table[%d %s][%d] = %d", __func__, usecase,
3591 use_case_table[usecase],
3592 type, pcm_id);
Haynes Mathew George98c95622014-06-20 19:14:25 -07003593 pcm_device_table[usecase][type] = pcm_id;
3594done:
3595 return ret;
3596}
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003597
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07003598#define DEFAULT_NOMINAL_SPEAKER_GAIN 20
3599int ramp_speaker_gain(struct audio_device *adev, bool ramp_up, int target_ramp_up_gain) {
3600 // backup_gain: gain to try to set in case of an error during ramp
3601 int start_gain, end_gain, step, backup_gain, i;
3602 bool error = false;
3603 const struct mixer_ctl *ctl;
3604 const char *mixer_ctl_name_gain_left = "Left Speaker Gain";
3605 const char *mixer_ctl_name_gain_right = "Right Speaker Gain";
3606 struct mixer_ctl *ctl_left = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_left);
3607 struct mixer_ctl *ctl_right = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_right);
3608 if (!ctl_left || !ctl_right) {
3609 ALOGE("%s: Could not get ctl for mixer cmd - %s or %s, not applying speaker gain ramp",
3610 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
3611 return -EINVAL;
3612 } else if ((mixer_ctl_get_num_values(ctl_left) != 1)
3613 || (mixer_ctl_get_num_values(ctl_right) != 1)) {
3614 ALOGE("%s: Unexpected num values for mixer cmd - %s or %s, not applying speaker gain ramp",
3615 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
3616 return -EINVAL;
3617 }
3618 if (ramp_up) {
3619 start_gain = 0;
3620 end_gain = target_ramp_up_gain > 0 ? target_ramp_up_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
3621 step = +1;
3622 backup_gain = end_gain;
3623 } else {
3624 // using same gain on left and right
3625 const int left_gain = mixer_ctl_get_value(ctl_left, 0);
3626 start_gain = left_gain > 0 ? left_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
3627 end_gain = 0;
3628 step = -1;
3629 backup_gain = start_gain;
3630 }
3631 for (i = start_gain ; i != (end_gain + step) ; i += step) {
3632 //ALOGV("setting speaker gain to %d", i);
3633 if (mixer_ctl_set_value(ctl_left, 0, i)) {
3634 ALOGE("%s: error setting %s to %d during gain ramp",
3635 __func__, mixer_ctl_name_gain_left, i);
3636 error = true;
3637 break;
3638 }
3639 if (mixer_ctl_set_value(ctl_right, 0, i)) {
3640 ALOGE("%s: error setting %s to %d during gain ramp",
3641 __func__, mixer_ctl_name_gain_right, i);
3642 error = true;
3643 break;
3644 }
3645 usleep(1000);
3646 }
3647 if (error) {
3648 // an error occured during the ramp, let's still try to go back to a safe volume
3649 if (mixer_ctl_set_value(ctl_left, 0, backup_gain)) {
3650 ALOGE("%s: error restoring left gain to %d", __func__, backup_gain);
3651 }
3652 if (mixer_ctl_set_value(ctl_right, 0, backup_gain)) {
3653 ALOGE("%s: error restoring right gain to %d", __func__, backup_gain);
3654 }
3655 }
3656 return start_gain;
3657}
3658
vivek mehtae59cfb22017-06-16 15:57:11 -07003659int platform_set_swap_mixer(struct audio_device *adev, bool swap_channels)
3660{
3661 const char *mixer_ctl_name = "Swap channel";
3662 struct mixer_ctl *ctl;
3663 const char *mixer_path;
3664 struct platform_data *my_data = (struct platform_data *)adev->platform;
3665
3666 // forced to set to swap, but device not rotated ... ignore set
3667 if (swap_channels && !my_data->speaker_lr_swap)
3668 return 0;
3669
3670 ALOGV("%s:", __func__);
3671
3672 if (swap_channels) {
3673 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER_REVERSE);
3674 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
3675 } else {
3676 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER);
3677 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
3678 }
3679
3680 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3681 if (!ctl) {
3682 ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name);
3683 return -EINVAL;
3684 }
3685
3686 if (mixer_ctl_set_value(ctl, 0, swap_channels) < 0) {
3687 ALOGE("%s: Could not set reverse cotrol %d",__func__, swap_channels);
3688 return -EINVAL;
3689 }
3690
3691 ALOGV("platfor_force_swap_channel :: Channel orientation ( %s ) ",
3692 swap_channels?"R --> L":"L --> R");
3693
3694 return 0;
3695}
3696
3697int platform_check_and_set_swap_lr_channels(struct audio_device *adev, bool swap_channels)
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003698{
3699 // only update if there is active pcm playback on speaker
3700 struct audio_usecase *usecase;
3701 struct listnode *node;
3702 struct platform_data *my_data = (struct platform_data *)adev->platform;
3703
vivek mehtae59cfb22017-06-16 15:57:11 -07003704 my_data->speaker_lr_swap = swap_channels;
Jean-Michel Trivif7148702016-09-16 18:23:05 -07003705
vivek mehtae59cfb22017-06-16 15:57:11 -07003706 return platform_set_swap_channels(adev, swap_channels);
3707}
Jean-Michel Trivif7148702016-09-16 18:23:05 -07003708
vivek mehtae59cfb22017-06-16 15:57:11 -07003709int platform_set_swap_channels(struct audio_device *adev, bool swap_channels)
3710{
3711 // only update if there is active pcm playback on speaker
3712 struct audio_usecase *usecase;
3713 struct listnode *node;
3714 struct platform_data *my_data = (struct platform_data *)adev->platform;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003715
vivek mehtae59cfb22017-06-16 15:57:11 -07003716 // do not swap channels in audio modes with concurrent capture and playback
3717 // as this may break the echo reference
3718 if ((adev->mode == AUDIO_MODE_IN_COMMUNICATION) || (adev->mode == AUDIO_MODE_IN_CALL)) {
3719 ALOGV("%s: will not swap due to audio mode %d", __func__, adev->mode);
3720 return 0;
3721 }
3722
3723 list_for_each(node, &adev->usecase_list) {
3724 usecase = node_to_item(node, struct audio_usecase, list);
3725 if (usecase->type == PCM_PLAYBACK &&
3726 usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) {
3727 /*
3728 * If acdb tuning is different for SPEAKER_REVERSE, it is must
3729 * to perform device switch to disable the current backend to
3730 * enable it with new acdb data.
3731 */
3732 if (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
3733 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]) {
3734 const int initial_skpr_gain = ramp_speaker_gain(adev, false /*ramp_up*/, -1);
3735 select_devices(adev, usecase->id);
3736 if (initial_skpr_gain != -EINVAL)
3737 ramp_speaker_gain(adev, true /*ramp_up*/, initial_skpr_gain);
3738
3739 } else {
3740 platform_set_swap_mixer(adev, swap_channels);
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003741 }
vivek mehtae59cfb22017-06-16 15:57:11 -07003742 break;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003743 }
3744 }
vivek mehtae59cfb22017-06-16 15:57:11 -07003745
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003746 return 0;
3747}
vivek mehtaa8d7c922016-05-25 14:40:44 -07003748
3749static struct amp_db_and_gain_table tbl_mapping[MAX_VOLUME_CAL_STEPS];
3750static int num_gain_tbl_entry = 0;
3751
3752bool platform_add_gain_level_mapping(struct amp_db_and_gain_table *tbl_entry) {
3753
3754 ALOGV("%s: enter .. add %f %f %d", __func__, tbl_entry->amp, tbl_entry->db, tbl_entry->level);
3755 if (num_gain_tbl_entry == -1) {
3756 ALOGE("%s: num entry beyond valid step levels or corrupted..rejecting custom mapping",
3757 __func__);
3758 return false;
3759 }
3760
3761 if (num_gain_tbl_entry >= MAX_VOLUME_CAL_STEPS) {
3762 ALOGE("%s: max entry reached max[%d] current index[%d] .. rejecting", __func__,
3763 MAX_VOLUME_CAL_STEPS, num_gain_tbl_entry);
3764 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
3765 return false;
3766 }
3767
3768 if (num_gain_tbl_entry > 0 && tbl_mapping[num_gain_tbl_entry - 1].amp >= tbl_entry->amp) {
3769 ALOGE("%s: value not in ascending order .. rejecting custom mapping", __func__);
3770 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
3771 return false;
3772 }
3773
3774 tbl_mapping[num_gain_tbl_entry] = *tbl_entry;
3775 ++num_gain_tbl_entry;
3776
3777 return true;
3778}
3779
3780int platform_get_gain_level_mapping(struct amp_db_and_gain_table *mapping_tbl,
3781 int table_size) {
3782 int itt = 0;
3783 ALOGV("platform_get_gain_level_mapping called ");
3784
3785 if (num_gain_tbl_entry <= 0 || num_gain_tbl_entry > MAX_VOLUME_CAL_STEPS) {
3786 ALOGD("%s: empty or currupted gain_mapping_table", __func__);
3787 return 0;
3788 }
3789
3790 for (; itt < num_gain_tbl_entry && itt <= table_size; itt++) {
3791 mapping_tbl[itt] = tbl_mapping[itt];
3792 ALOGV("%s: added amp[%f] db[%f] level[%d]", __func__,
3793 mapping_tbl[itt].amp, mapping_tbl[itt].db, mapping_tbl[itt].level);
3794 }
3795
3796 return num_gain_tbl_entry;
3797}
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07003798
3799int platform_snd_card_update(void *platform, card_status_t status)
3800{
3801 struct platform_data *my_data = (struct platform_data *)platform;
3802 struct audio_device *adev = my_data->adev;
3803
3804 if (status == CARD_STATUS_ONLINE) {
3805 if (my_data->acdb_send_custom_top)
3806 my_data->acdb_send_custom_top();
3807 }
3808 return 0;
3809}
David Linee3fe402017-03-13 10:00:42 -07003810
3811/*
3812 * configures afe with bit width and Sample Rate
3813 */
Haynes Mathew George65f6b432018-02-27 17:44:55 -08003814int platform_set_backend_cfg(const struct audio_device* adev,
3815 snd_device_t snd_device,
3816 const struct audio_backend_cfg *backend_cfg)
David Linee3fe402017-03-13 10:00:42 -07003817{
3818
3819 int ret = 0;
3820 const int backend_idx = platform_get_backend_index(snd_device);
3821 struct platform_data *my_data = (struct platform_data *)adev->platform;
3822 const unsigned int bit_width = backend_cfg->bit_width;
3823 const unsigned int sample_rate = backend_cfg->sample_rate;
3824 const unsigned int channels = backend_cfg->channels;
3825 const audio_format_t format = backend_cfg->format;
3826 const bool passthrough_enabled = backend_cfg->passthrough_enabled;
3827
3828
3829 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
3830 ", backend_idx %d device (%s)", __func__, bit_width,
3831 sample_rate, channels, backend_idx,
3832 platform_get_snd_device_name(snd_device));
3833
3834 if ((my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl) &&
3835 (bit_width != my_data->current_backend_cfg[backend_idx].bit_width)) {
3836
3837 struct mixer_ctl *ctl = NULL;
3838 ctl = mixer_get_ctl_by_name(adev->mixer,
3839 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
3840 if (!ctl) {
3841 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3842 __func__,
3843 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
3844 return -EINVAL;
3845 }
3846
3847 if (bit_width == 24) {
3848 if (format == AUDIO_FORMAT_PCM_24_BIT_PACKED)
3849 ret = mixer_ctl_set_enum_by_string(ctl, "S24_3LE");
3850 else
3851 ret = mixer_ctl_set_enum_by_string(ctl, "S24_LE");
3852 } else if (bit_width == 32) {
3853 ret = mixer_ctl_set_enum_by_string(ctl, "S32_LE");
3854 } else {
3855 ret = mixer_ctl_set_enum_by_string(ctl, "S16_LE");
3856 }
3857 if ( ret < 0) {
3858 ALOGE("%s:becf: afe: fail for %s mixer set to %d bit for %x format", __func__,
3859 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
3860 } else {
3861 my_data->current_backend_cfg[backend_idx].bit_width = bit_width;
3862 ALOGD("%s:becf: afe: %s mixer set to %d bit for %x format", __func__,
3863 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
3864 }
3865 /* set the ret as 0 and not pass back to upper layer */
3866 ret = 0;
3867 }
3868
3869 if (passthrough_enabled || ((my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl) &&
3870 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate))) {
3871 char *rate_str = NULL;
3872 struct mixer_ctl *ctl = NULL;
3873
3874 switch (sample_rate) {
3875 case 32000:
3876 if (passthrough_enabled) {
3877 rate_str = "KHZ_32";
3878 break;
3879 }
3880 case 8000:
3881 case 11025:
3882 case 16000:
3883 case 22050:
3884 case 48000:
3885 rate_str = "KHZ_48";
3886 break;
3887 case 44100:
3888 rate_str = "KHZ_44P1";
3889 break;
3890 case 64000:
3891 case 96000:
3892 rate_str = "KHZ_96";
3893 break;
3894 case 88200:
3895 rate_str = "KHZ_88P2";
3896 break;
3897 case 176400:
3898 rate_str = "KHZ_176P4";
3899 break;
3900 case 192000:
3901 rate_str = "KHZ_192";
3902 break;
3903 case 352800:
3904 rate_str = "KHZ_352P8";
3905 break;
3906 case 384000:
3907 rate_str = "KHZ_384";
3908 break;
3909 case 144000:
3910 if (passthrough_enabled) {
3911 rate_str = "KHZ_144";
3912 break;
3913 }
3914 default:
3915 rate_str = "KHZ_48";
3916 break;
3917 }
3918
3919 ctl = mixer_get_ctl_by_name(adev->mixer,
3920 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
3921 if(!ctl) {
3922 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3923 __func__,
3924 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
3925 return -EINVAL;
3926 }
3927
3928 ALOGD("%s:becf: afe: %s set to %s", __func__,
3929 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl, rate_str);
3930 mixer_ctl_set_enum_by_string(ctl, rate_str);
3931 my_data->current_backend_cfg[backend_idx].sample_rate = sample_rate;
3932 }
3933 if ((my_data->current_backend_cfg[backend_idx].channels_mixer_ctl) &&
3934 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
3935 struct mixer_ctl *ctl = NULL;
3936 char *channel_cnt_str = NULL;
3937
3938 switch (channels) {
3939 case 8:
3940 channel_cnt_str = "Eight"; break;
3941 case 7:
3942 channel_cnt_str = "Seven"; break;
3943 case 6:
3944 channel_cnt_str = "Six"; break;
3945 case 5:
3946 channel_cnt_str = "Five"; break;
3947 case 4:
3948 channel_cnt_str = "Four"; break;
3949 case 3:
3950 channel_cnt_str = "Three"; break;
3951 case 1:
3952 channel_cnt_str = "One"; break;
3953 case 2:
3954 default:
3955 channel_cnt_str = "Two"; break;
3956 }
3957
3958 ctl = mixer_get_ctl_by_name(adev->mixer,
3959 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
3960 if (!ctl) {
3961 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3962 __func__,
3963 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
3964 return -EINVAL;
3965 }
3966 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
3967 my_data->current_backend_cfg[backend_idx].channels = channels;
3968
3969 // skip EDID configuration for HDMI backend
3970
3971 ALOGD("%s:becf: afe: %s set to %s", __func__,
3972 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl,
3973 channel_cnt_str);
3974 }
3975
3976 // skip set ext_display format mixer control
3977 return ret;
3978}
3979
3980static int platform_get_snd_device_bit_width(snd_device_t snd_device)
3981{
3982 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
3983 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
3984 return CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3985 }
3986
3987 return backend_bit_width_table[snd_device];
3988}
3989
3990/*
3991 * return backend_idx on which voice call is active
3992 */
3993static int platform_get_voice_call_backend(struct audio_device* adev)
3994{
3995 struct audio_usecase *uc = NULL;
3996 struct listnode *node;
3997 snd_device_t out_snd_device = SND_DEVICE_NONE;
3998
3999 int backend_idx = -1;
4000
4001 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
4002 list_for_each(node, &adev->usecase_list) {
4003 uc = node_to_item(node, struct audio_usecase, list);
4004 if (uc && uc->type == VOICE_CALL && uc->stream.out) {
4005 out_snd_device = platform_get_output_snd_device(adev->platform,
4006 uc->stream.out->devices);
4007 backend_idx = platform_get_backend_index(out_snd_device);
4008 break;
4009 }
4010 }
4011 }
4012 return backend_idx;
4013}
4014
4015/*
4016 * goes through all the current usecases and picks the highest
4017 * bitwidth & samplerate
4018 */
4019static bool platform_check_capture_backend_cfg(struct audio_device* adev,
4020 int backend_idx,
4021 struct audio_backend_cfg *backend_cfg)
4022{
4023 bool backend_change = false;
4024 unsigned int bit_width;
4025 unsigned int sample_rate;
4026 unsigned int channels;
4027 struct platform_data *my_data = (struct platform_data *)adev->platform;
4028
4029 bit_width = backend_cfg->bit_width;
4030 sample_rate = backend_cfg->sample_rate;
4031 channels = backend_cfg->channels;
4032
4033 ALOGV("%s:txbecf: afe: Codec selected backend: %d current bit width: %d and "
4034 "sample rate: %d, channels %d",__func__,backend_idx, bit_width,
4035 sample_rate, channels);
4036
4037 // For voice calls use default configuration i.e. 16b/48K, only applicable to
4038 // default backend
4039 // force routing is not required here, caller will do it anyway
4040 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
4041 ALOGW("%s:txbecf: afe: Use default bw and sr for voice/voip calls and "
4042 "for unprocessed/camera source", __func__);
4043 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
4044 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4045 }
4046
4047 if (backend_idx == USB_AUDIO_TX_BACKEND) {
4048 audio_extn_usb_is_config_supported(&bit_width, &sample_rate, &channels, false);
4049 ALOGV("%s:txbecf: afe: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
4050 __func__, bit_width, sample_rate, channels);
4051 }
4052
4053 ALOGV("%s:txbecf: afe: Codec selected backend: %d updated bit width: %d and "
4054 "sample rate: %d", __func__, backend_idx, bit_width, sample_rate);
4055
4056 // Force routing if the expected bitwdith or samplerate
4057 // is not same as current backend comfiguration
4058 if ((bit_width != my_data->current_backend_cfg[backend_idx].bit_width) ||
4059 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate) ||
4060 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
4061 backend_cfg->bit_width = bit_width;
4062 backend_cfg->sample_rate= sample_rate;
4063 backend_cfg->channels = channels;
4064 backend_change = true;
4065 ALOGI("%s:txbecf: afe: Codec backend needs to be updated. new bit width: %d "
4066 "new sample rate: %d new channel: %d",
4067 __func__, backend_cfg->bit_width,
4068 backend_cfg->sample_rate, backend_cfg->channels);
4069 }
4070
4071 return backend_change;
4072}
4073
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004074static void pick_playback_cfg_for_uc(struct audio_device *adev,
4075 struct audio_usecase *usecase,
4076 snd_device_t snd_device,
4077 unsigned int *bit_width,
4078 unsigned int *sample_rate,
4079 unsigned int *channels)
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004080{
4081 int i =0;
4082 struct listnode *node;
4083 list_for_each(node, &adev->usecase_list) {
4084 struct audio_usecase *uc;
4085 uc = node_to_item(node, struct audio_usecase, list);
4086 struct stream_out *out = (struct stream_out*) uc->stream.out;
4087 if (uc->type == PCM_PLAYBACK && out && usecase != uc) {
4088 unsigned int out_channels = audio_channel_count_from_out_mask(out->channel_mask);
4089 ALOGV("%s:napb: (%d) - (%s)id (%d) sr %d bw "
4090 "(%d) ch (%d) device %s", __func__, i++, use_case_table[uc->id],
4091 uc->id, out->sample_rate,
4092 pcm_format_to_bits(out->config.format), out_channels,
4093 platform_get_snd_device_name(uc->out_snd_device));
4094
4095 if (platform_check_backends_match(snd_device, uc->out_snd_device)) {
4096 if (*bit_width < pcm_format_to_bits(out->config.format))
4097 *bit_width = pcm_format_to_bits(out->config.format);
4098 if (*sample_rate < out->sample_rate)
4099 *sample_rate = out->sample_rate;
4100 if (out->sample_rate < OUTPUT_SAMPLING_RATE_44100)
4101 *sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4102 if (*channels < out_channels)
4103 *channels = out_channels;
4104 }
4105 }
4106 }
4107 return;
4108}
4109
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004110static void headset_is_config_supported(unsigned int *bit_width,
4111 unsigned int *sample_rate,
4112 unsigned int *channels) {
4113 switch (*bit_width) {
4114 case 16:
4115 case 24:
4116 break;
4117 default:
4118 *bit_width = 16;
4119 break;
4120 }
4121
4122 if (*sample_rate > 192000) {
4123 *sample_rate = 192000;
4124 }
4125
4126 if (*channels > 2) {
4127 *channels = 2;
4128 }
4129}
4130
David Linee3fe402017-03-13 10:00:42 -07004131static bool platform_check_playback_backend_cfg(struct audio_device* adev,
4132 struct audio_usecase* usecase,
4133 snd_device_t snd_device,
4134 struct audio_backend_cfg *backend_cfg)
4135{
4136 bool backend_change = false;
David Linee3fe402017-03-13 10:00:42 -07004137 unsigned int bit_width;
4138 unsigned int sample_rate;
4139 unsigned int channels;
David Linee3fe402017-03-13 10:00:42 -07004140 int backend_idx = DEFAULT_CODEC_BACKEND;
Haynes Mathew George65f6b432018-02-27 17:44:55 -08004141 unsigned long service_interval = 0; // 0 is invalid
David Linee3fe402017-03-13 10:00:42 -07004142 struct platform_data *my_data = (struct platform_data *)adev->platform;
David Linee3fe402017-03-13 10:00:42 -07004143
4144 if (snd_device == SND_DEVICE_OUT_BT_SCO ||
4145 snd_device == SND_DEVICE_OUT_BT_SCO_WB) {
4146 backend_change = false;
4147 return backend_change;
4148 }
4149
4150 backend_idx = platform_get_backend_index(snd_device);
4151 bit_width = backend_cfg->bit_width;
4152 sample_rate = backend_cfg->sample_rate;
4153 channels = backend_cfg->channels;
4154
4155 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
4156 ", backend_idx %d usecase = %d device (%s)", __func__, bit_width,
4157 sample_rate, channels, backend_idx, usecase->id,
4158 platform_get_snd_device_name(snd_device));
4159
4160 if (backend_idx == platform_get_voice_call_backend(adev)) {
4161 ALOGW("%s:becf: afe:Use default bw and sr for voice/voip calls ",
4162 __func__);
4163 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
4164 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4165 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
4166 } else {
4167 /*
4168 * The backend should be configured at highest bit width and/or
4169 * sample rate amongst all playback usecases.
4170 * If the selected sample rate and/or bit width differ with
4171 * current backend sample rate and/or bit width, then, we set the
4172 * backend re-configuration flag.
4173 *
4174 * Exception: 16 bit playbacks is allowed through 16 bit/48/44.1 khz backend only
4175 */
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004176 pick_playback_cfg_for_uc(adev, usecase, snd_device,
4177 &bit_width,
4178 &sample_rate,
4179 &channels);
David Linee3fe402017-03-13 10:00:42 -07004180 }
4181
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004182 switch (backend_idx) {
4183 case USB_AUDIO_RX_BACKEND:
4184 audio_extn_usb_is_config_supported(&bit_width,
4185 &sample_rate, &channels, true);
Haynes Mathew George65f6b432018-02-27 17:44:55 -08004186 if (platform_get_usb_service_interval(adev->platform, true,
4187 &service_interval) == 0) {
4188 /* overwrite with best altset for this service interval */
4189 int ret =
4190 audio_extn_usb_altset_for_service_interval(true /*playback*/,
4191 service_interval,
4192 &bit_width,
4193 &sample_rate,
4194 &channels);
4195 if (ret < 0) {
4196 ALOGE("Failed to find altset for service interval %lu, skip reconfig",
4197 service_interval);
4198 return false;
4199 }
4200 }
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004201 ALOGV("%s: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
4202 __func__, bit_width, sample_rate, channels);
4203 break;
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004204 case HEADPHONE_BACKEND:
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004205 headset_is_config_supported(&bit_width, &sample_rate, &channels);
4206 break;
4207 case DEFAULT_CODEC_BACKEND:
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004208 default:
4209 bit_width = platform_get_snd_device_bit_width(snd_device);
4210 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4211 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
4212 break;
David Linee3fe402017-03-13 10:00:42 -07004213 }
4214
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004215 ALOGV("%s:becf: afe: Codec selected backend: %d updated bit width: %d and"
4216 "sample rate: %d",
David Linee3fe402017-03-13 10:00:42 -07004217 __func__, backend_idx , bit_width, sample_rate);
4218
4219 // Force routing if the expected bitwdith or samplerate
4220 // is not same as current backend comfiguration
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004221 if (bit_width != my_data->current_backend_cfg[backend_idx].bit_width ||
4222 sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate ||
4223 channels != my_data->current_backend_cfg[backend_idx].channels) {
David Linee3fe402017-03-13 10:00:42 -07004224 backend_cfg->bit_width = bit_width;
4225 backend_cfg->sample_rate = sample_rate;
4226 backend_cfg->channels = channels;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004227 backend_cfg->passthrough_enabled = false;
David Linee3fe402017-03-13 10:00:42 -07004228 backend_change = true;
4229 ALOGV("%s:becf: afe: Codec backend needs to be updated. new bit width: %d"
4230 "new sample rate: %d new channels: %d",
4231 __func__, backend_cfg->bit_width, backend_cfg->sample_rate, backend_cfg->channels);
4232 }
4233
4234 return backend_change;
4235}
4236
4237bool platform_check_and_set_playback_backend_cfg(struct audio_device* adev,
4238 struct audio_usecase *usecase, snd_device_t snd_device)
4239{
4240 int backend_idx = DEFAULT_CODEC_BACKEND;
4241 int new_snd_devices[SND_DEVICE_OUT_END];
4242 int i, num_devices = 1;
4243 bool ret = false;
4244 struct platform_data *my_data = (struct platform_data *)adev->platform;
4245 struct audio_backend_cfg backend_cfg;
4246
4247 backend_idx = platform_get_backend_index(snd_device);
4248
4249 backend_cfg.bit_width = pcm_format_to_bits(usecase->stream.out->config.format);
4250 backend_cfg.sample_rate = usecase->stream.out->sample_rate;
4251 backend_cfg.format = usecase->stream.out->format;
4252 backend_cfg.channels = audio_channel_count_from_out_mask(usecase->stream.out->channel_mask);
4253 /*this is populated by check_codec_backend_cfg hence set default value to false*/
4254 backend_cfg.passthrough_enabled = false;
4255
4256 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
4257 ", backend_idx %d usecase = %d device (%s)", __func__, backend_cfg.bit_width,
4258 backend_cfg.sample_rate, backend_cfg.channels, backend_idx, usecase->id,
4259 platform_get_snd_device_name(snd_device));
4260
4261 if (platform_can_split_snd_device(snd_device, &num_devices, new_snd_devices) < 0)
4262 new_snd_devices[0] = snd_device;
4263
4264 for (i = 0; i < num_devices; i++) {
4265 ALOGV("%s: new_snd_devices[%d] is %d", __func__, i, new_snd_devices[i]);
4266 if ((platform_check_playback_backend_cfg(adev, usecase, new_snd_devices[i],
4267 &backend_cfg))) {
4268 platform_set_backend_cfg(adev, new_snd_devices[i],
4269 &backend_cfg);
4270 ret = true;
4271 }
4272 }
4273 return ret;
4274}
4275
4276bool platform_check_and_set_capture_backend_cfg(struct audio_device* adev,
4277 struct audio_usecase *usecase, snd_device_t snd_device)
4278{
4279 int backend_idx = platform_get_backend_index(snd_device);
4280 int ret = 0;
4281 struct audio_backend_cfg backend_cfg;
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004282 memset(&backend_cfg, 0, sizeof(struct audio_backend_cfg));
David Linee3fe402017-03-13 10:00:42 -07004283
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004284 if (usecase->type == PCM_CAPTURE) {
4285 backend_cfg.format = usecase->stream.in->format;
David Linee3fe402017-03-13 10:00:42 -07004286 backend_cfg.channels = audio_channel_count_from_in_mask(usecase->stream.in->channel_mask);
4287 } else {
4288 backend_cfg.bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
4289 backend_cfg.sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4290 backend_cfg.format = AUDIO_FORMAT_PCM_16_BIT;
4291 backend_cfg.channels = 1;
4292 }
4293
4294 ALOGV("%s:txbecf: afe: bitwidth %d, samplerate %d, channel %d"
4295 ", backend_idx %d usecase = %d device (%s)", __func__,
4296 backend_cfg.bit_width,
4297 backend_cfg.sample_rate,
4298 backend_cfg.channels,
4299 backend_idx, usecase->id,
4300 platform_get_snd_device_name(snd_device));
4301
4302 if (platform_check_capture_backend_cfg(adev, backend_idx, &backend_cfg)) {
4303 ret = platform_set_backend_cfg(adev, snd_device,
4304 &backend_cfg);
4305 if(!ret)
4306 return true;
4307 }
4308
4309 return false;
4310}
4311
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004312static int max_be_dai_names = 0;
4313static const struct be_dai_name_struct *be_dai_name_table;
4314
4315/*
4316 * Retrieves the be_dai_name_table from kernel to enable a mapping
4317 * between sound device hw interfaces and backend IDs. This allows HAL to
4318 * specify the backend a specific calibration is needed for.
4319 */
4320static int init_be_dai_name_table(struct audio_device *adev)
4321{
4322 const char *mixer_ctl_name = "Backend DAI Name Table";
4323 struct mixer_ctl *ctl;
4324 int i, j, ret, size;
4325 bool valid_hw_interface;
4326
4327 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
4328 if (!ctl) {
4329 ALOGE("%s: Could not get ctl for mixer name %s\n",
4330 __func__, mixer_ctl_name);
4331 ret = -EINVAL;
4332 goto done;
4333 }
4334
4335 mixer_ctl_update(ctl);
4336
4337 size = mixer_ctl_get_num_values(ctl);
4338 if (size <= 0){
4339 ALOGE("%s: Failed to get %s size %d\n",
4340 __func__, mixer_ctl_name, size);
4341 ret = -EFAULT;
4342 goto done;
4343 }
4344
vivek mehtaa68fea62017-06-08 19:04:02 -07004345 be_dai_name_table =
4346 (const struct be_dai_name_struct *)calloc(1, size);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004347 if (be_dai_name_table == NULL) {
4348 ALOGE("%s: Failed to allocate memory for %s\n",
4349 __func__, mixer_ctl_name);
4350 ret = -ENOMEM;
4351 goto freeMem;
4352 }
4353
4354 ret = mixer_ctl_get_array(ctl, (void *)be_dai_name_table, size);
4355 if (ret) {
4356 ALOGE("%s: Failed to get %s, ret %d\n",
4357 __func__, mixer_ctl_name, ret);
4358 ret = -EFAULT;
4359 goto freeMem;
4360 }
4361
4362 if (be_dai_name_table != NULL) {
4363 max_be_dai_names = size / sizeof(struct be_dai_name_struct);
4364 ALOGV("%s: Successfully got %s, number of be dais is %d\n",
4365 __func__, mixer_ctl_name, max_be_dai_names);
4366 ret = 0;
4367 } else {
4368 ALOGE("%s: Failed to get %s\n", __func__, mixer_ctl_name);
4369 ret = -EFAULT;
4370 goto freeMem;
4371 }
4372
4373 /*
4374 * Validate all sound devices have a valid backend set to catch
4375 * errors for uncommon sound devices
4376 */
4377 for (i = 0; i < SND_DEVICE_MAX; i++) {
4378 valid_hw_interface = false;
4379
4380 if (hw_interface_table[i] == NULL) {
4381 ALOGW("%s: sound device %s has no hw interface set\n",
4382 __func__, platform_get_snd_device_name(i));
4383 continue;
4384 }
4385
4386 for (j = 0; j < max_be_dai_names; j++) {
4387 if (strcmp(hw_interface_table[i], be_dai_name_table[j].be_name)
4388 == 0) {
4389 valid_hw_interface = true;
4390 break;
4391 }
4392 }
4393 if (!valid_hw_interface)
4394 ALOGD("%s: sound device %s does not have a valid hw interface set "
4395 "(disregard for combo devices) %s\n",
4396 __func__, platform_get_snd_device_name(i),
4397 hw_interface_table[i]);
4398 }
4399
4400 goto done;
4401
4402freeMem:
4403 if (be_dai_name_table) {
4404 free((void *)be_dai_name_table);
4405 be_dai_name_table = NULL;
4406 }
4407
4408done:
4409 return ret;
4410}
4411
4412int platform_get_snd_device_backend_index(snd_device_t device)
4413{
4414 int i, be_dai_id;
4415 const char * hw_interface_name = NULL;
4416
4417 ALOGV("%s: enter with device %d\n", __func__, device);
4418
vivek mehtaa68fea62017-06-08 19:04:02 -07004419 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004420 ALOGE("%s: Invalid snd_device = %d",
4421 __func__, device);
4422 be_dai_id = -EINVAL;
4423 goto done;
4424 }
4425
4426 /* Get string value of necessary backend for device */
4427 hw_interface_name = hw_interface_table[device];
4428 if (hw_interface_name == NULL) {
4429 ALOGE("%s: no hw_interface set for device %d\n", __func__, device);
4430 be_dai_id = -EINVAL;
4431 goto done;
4432 }
4433
4434 /* Check if be dai name table was retrieved successfully */
4435 if (be_dai_name_table == NULL) {
4436 ALOGE("%s: BE DAI Name Table is not present\n", __func__);
4437 be_dai_id = -EFAULT;
4438 goto done;
4439 }
4440
4441 /* Get backend ID for device specified */
4442 for (i = 0; i < max_be_dai_names; i++) {
4443 if (strcmp(hw_interface_name, be_dai_name_table[i].be_name) == 0) {
4444 be_dai_id = be_dai_name_table[i].be_id;
4445 goto done;
4446 }
4447 }
4448 ALOGE("%s: no interface matching name %s\n", __func__, hw_interface_name);
4449 be_dai_id = -EINVAL;
4450 goto done;
4451
4452done:
4453 return be_dai_id;
4454}
4455
4456void platform_check_and_update_copp_sample_rate(void* platform, snd_device_t snd_device,
4457 unsigned int stream_sr, int* sample_rate)
4458{
4459 struct platform_data* my_data = (struct platform_data *)platform;
4460 int backend_idx = platform_get_backend_index(snd_device);
4461 int device_sr = my_data->current_backend_cfg[backend_idx].sample_rate;
4462 /*
4463 *Check if device SR is multiple of 8K or 11.025 Khz
4464 *check if the stream SR is multiple of same base, if yes
4465 *then have copp SR equal to stream SR, this ensures that
4466 *post processing happens at stream SR, else have
4467 *copp SR equal to device SR.
4468 */
4469 if (!(((sample_rate_multiple(device_sr, SAMPLE_RATE_8000)) &&
4470 (sample_rate_multiple(stream_sr, SAMPLE_RATE_8000))) ||
4471 ((sample_rate_multiple(device_sr, SAMPLE_RATE_11025)) &&
4472 (sample_rate_multiple(stream_sr, SAMPLE_RATE_11025))))) {
4473 *sample_rate = device_sr;
4474 } else
4475 *sample_rate = stream_sr;
4476
4477 ALOGI("sn_device %d device sr %d stream sr %d copp sr %d", snd_device, device_sr, stream_sr
4478 , *sample_rate);
4479
4480}
4481
4482// called from info parser
vivek mehtaa68fea62017-06-08 19:04:02 -07004483void platform_add_app_type(const char *uc_type,
4484 const char *mode,
4485 int bw,
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004486 int app_type, int max_rate) {
4487 struct app_type_entry *ap =
4488 (struct app_type_entry *)calloc(1, sizeof(struct app_type_entry));
4489
4490 if (!ap) {
4491 ALOGE("%s failed to allocate mem for app type", __func__);
4492 return;
4493 }
4494
4495 ap->uc_type = -1;
4496 for (int i=0; i<USECASE_TYPE_MAX; i++) {
4497 if (!strcmp(uc_type, usecase_type_index[i].name)) {
4498 ap->uc_type = usecase_type_index[i].index;
4499 break;
4500 }
4501 }
4502
4503 if (ap->uc_type == -1) {
4504 free(ap);
4505 return;
4506 }
4507
vivek mehtaa68fea62017-06-08 19:04:02 -07004508 ALOGI("%s uc %s mode %s bw %d app_type %d max_rate %d",
4509 __func__, uc_type, mode, bw, app_type, max_rate);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004510 ap->bit_width = bw;
4511 ap->app_type = app_type;
4512 ap->max_rate = max_rate;
vivek mehtaa68fea62017-06-08 19:04:02 -07004513 ap->mode = strdup(mode);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004514 list_add_tail(&app_type_entry_list, &ap->node);
4515}
4516
4517
4518int platform_get_default_app_type_v2(void *platform __unused,
4519 usecase_type_t type,
4520 int *app_type )
4521{
4522 if (type == PCM_PLAYBACK)
4523 *app_type = DEFAULT_APP_TYPE_RX_PATH;
4524 else
4525 *app_type = DEFAULT_APP_TYPE_TX_PATH;
4526 return 0;
4527}
4528
vivek mehtaa68fea62017-06-08 19:04:02 -07004529int platform_get_app_type_v2(void *platform,
4530 usecase_type_t uc_type,
4531 const char *mode,
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004532 int bw, int sr __unused,
4533 int *app_type)
4534{
4535 struct listnode *node;
4536 struct app_type_entry *entry;
4537 *app_type = -1;
vivek mehtaa68fea62017-06-08 19:04:02 -07004538
4539 ALOGV("%s find match for uc %d mode %s bw %d rate %d",
4540 __func__, uc_type, mode, bw, sr);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004541 list_for_each(node, &app_type_entry_list) {
4542 entry = node_to_item(node, struct app_type_entry, node);
vivek mehtaa68fea62017-06-08 19:04:02 -07004543 ALOGV("%s uc %d mode %s bw %d app_type %d max_rate %d",
4544 __func__, entry->uc_type, entry->mode, entry->bit_width,
4545 entry->app_type, entry->max_rate);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004546 if (entry->bit_width == bw &&
vivek mehtaa68fea62017-06-08 19:04:02 -07004547 entry->uc_type == uc_type &&
4548 sr <= entry->max_rate &&
4549 entry->mode && !strcmp(mode, entry->mode)) {
4550 ALOGV("%s found match %d", __func__, entry->app_type);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004551 *app_type = entry->app_type;
4552 break;
4553 }
4554 }
4555
4556 if (*app_type == -1) {
vivek mehtaa68fea62017-06-08 19:04:02 -07004557 ALOGV("%s no match found, return default", __func__);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004558 return platform_get_default_app_type_v2(platform, uc_type, app_type);
4559 }
4560 return 0;
4561}
vivek mehta90933872017-06-15 18:04:39 -07004562
4563int platform_set_sidetone(struct audio_device *adev,
4564 snd_device_t out_snd_device,
4565 bool enable, char *str)
4566{
4567 int ret;
4568 if (out_snd_device == SND_DEVICE_OUT_USB_HEADSET ||
4569 out_snd_device == SND_DEVICE_OUT_VOICE_USB_HEADSET) {
4570 ret = audio_extn_usb_enable_sidetone(out_snd_device, enable);
4571 if (ret)
4572 ALOGI("%s: usb device %d does not support device sidetone\n",
4573 __func__, out_snd_device);
4574 } else {
4575 ALOGV("%s: sidetone out device(%d) mixer cmd = %s\n",
4576 __func__, out_snd_device, str);
4577 if (enable)
4578 audio_route_apply_and_update_path(adev->audio_route, str);
4579 else
4580 audio_route_reset_and_update_path(adev->audio_route, str);
4581 }
4582 return 0;
4583}
Haynes Mathew George96483a22017-03-28 14:52:47 -07004584
4585int platform_get_mmap_data_fd(void *platform __unused, int fe_dev __unused, int dir __unused,
4586 int *fd __unused, uint32_t *size __unused)
4587{
yixuanjiang89bd2712018-08-15 17:43:11 +08004588#if defined (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845) || (PLATFORM_SDM710)
Haynes Mathew George96483a22017-03-28 14:52:47 -07004589 struct platform_data *my_data = (struct platform_data *)platform;
4590 struct audio_device *adev = my_data->adev;
4591 int hw_fd = -1;
4592 char dev_name[128];
4593 struct snd_pcm_mmap_fd mmap_fd;
4594 memset(&mmap_fd, 0, sizeof(mmap_fd));
4595 mmap_fd.dir = dir;
4596 snprintf(dev_name, sizeof(dev_name), "/dev/snd/hwC%uD%u",
4597 adev->snd_card, HWDEP_FE_BASE+fe_dev);
4598 hw_fd = open(dev_name, O_RDONLY);
4599 if (hw_fd < 0) {
4600 ALOGE("fe hw dep node open %d/%d failed", adev->snd_card, fe_dev);
4601 return -1;
4602 }
4603 if (ioctl(hw_fd, SNDRV_PCM_IOCTL_MMAP_DATA_FD, &mmap_fd) < 0) {
4604 ALOGE("fe hw dep node ioctl failed");
4605 close(hw_fd);
4606 return -1;
4607 }
4608 *fd = mmap_fd.fd;
4609 *size = mmap_fd.size;
4610 close(hw_fd); // mmap_fd should still be valid
4611 return 0;
4612#else
4613 return -1;
4614#endif
4615}
Mikhail Naganov4ee6e3e2018-03-21 16:28:35 +00004616
4617bool platform_sound_trigger_usecase_needs_event(audio_usecase_t uc_id)
4618{
4619 bool needs_event = false;
4620
4621 switch (uc_id) {
4622 /* concurrent capture usecases which needs event */
4623 case USECASE_AUDIO_RECORD:
4624 case USECASE_AUDIO_RECORD_LOW_LATENCY:
4625 case USECASE_AUDIO_RECORD_MMAP:
4626 case USECASE_AUDIO_RECORD_HIFI:
4627 case USECASE_AUDIO_RECORD_VOIP:
4628 case USECASE_VOICEMMODE1_CALL:
4629 case USECASE_VOICEMMODE2_CALL:
4630 /* concurrent playback usecases that needs event */
4631 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
4632 case USECASE_AUDIO_PLAYBACK_OFFLOAD:
4633 needs_event = true;
4634 break;
4635 default:
4636 ALOGV("%s:usecase_id[%d] no need to raise event.", __func__, uc_id);
4637 }
4638 return needs_event;
4639}
4640
4641bool platform_snd_device_has_speaker(snd_device_t dev) {
4642 int num_devs = 2;
4643 snd_device_t split_devs[2] = {SND_DEVICE_NONE, SND_DEVICE_NONE};
4644 if (platform_can_split_snd_device(dev, &num_devs, split_devs) == 0) {
4645 return platform_snd_device_has_speaker(split_devs[0]) ||
4646 platform_snd_device_has_speaker(split_devs[1]);
4647 }
4648
4649 switch (dev) {
4650 case SND_DEVICE_OUT_SPEAKER:
4651 case SND_DEVICE_OUT_SPEAKER_SAFE:
4652 case SND_DEVICE_OUT_SPEAKER_REVERSE:
4653 case SND_DEVICE_OUT_SPEAKER_PROTECTED:
4654 case SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED:
4655 case SND_DEVICE_OUT_VOICE_SPEAKER_HFP:
4656 return true;
4657 default:
4658 break;
4659 }
4660 return false;
4661}
jiabin8962a4d2018-03-19 18:21:24 -07004662
4663bool platform_set_microphone_characteristic(void *platform,
4664 struct audio_microphone_characteristic_t mic) {
4665 struct platform_data *my_data = (struct platform_data *)platform;
4666 if (my_data->declared_mic_count >= AUDIO_MICROPHONE_MAX_COUNT) {
4667 ALOGE("mic number is more than maximum number");
4668 return false;
4669 }
4670 for (size_t ch = 0; ch < AUDIO_CHANNEL_COUNT_MAX; ch++) {
4671 mic.channel_mapping[ch] = AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED;
4672 }
4673 my_data->microphones[my_data->declared_mic_count++] = mic;
4674 return true;
4675}
4676
4677int platform_get_microphones(void *platform,
4678 struct audio_microphone_characteristic_t *mic_array,
4679 size_t *mic_count) {
4680 struct platform_data *my_data = (struct platform_data *)platform;
4681 if (mic_count == NULL) {
4682 return -EINVAL;
4683 }
4684 if (mic_array == NULL) {
4685 return -EINVAL;
4686 }
4687
4688 if (*mic_count == 0) {
4689 *mic_count = my_data->declared_mic_count;
4690 return 0;
4691 }
4692
4693 size_t max_mic_count = *mic_count;
4694 size_t actual_mic_count = 0;
4695 for (size_t i = 0; i < max_mic_count && i < my_data->declared_mic_count; i++) {
4696 mic_array[i] = my_data->microphones[i];
4697 actual_mic_count++;
4698 }
4699 *mic_count = actual_mic_count;
4700 return 0;
4701}
4702
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004703bool platform_set_microphone_map(void *platform, snd_device_t in_snd_device,
4704 const struct mic_info *info) {
4705 struct platform_data *my_data = (struct platform_data *)platform;
4706 if (in_snd_device < SND_DEVICE_IN_BEGIN || in_snd_device >= SND_DEVICE_IN_END) {
4707 ALOGE("%s: Sound device not valid", __func__);
4708 return false;
4709 }
4710 size_t m_count = my_data->mic_map[in_snd_device].mic_count++;
4711 if (m_count >= AUDIO_MICROPHONE_MAX_COUNT) {
4712 ALOGE("%s: Microphone count is greater than max allowed value", __func__);
4713 my_data->mic_map[in_snd_device].mic_count--;
4714 return false;
4715 }
4716 my_data->mic_map[in_snd_device].microphones[m_count] = *info;
4717 return true;
4718}
4719
4720int platform_get_active_microphones(void *platform, unsigned int channels,
4721 audio_usecase_t uc_id,
jiabin8962a4d2018-03-19 18:21:24 -07004722 struct audio_microphone_characteristic_t *mic_array,
4723 size_t *mic_count) {
4724 struct platform_data *my_data = (struct platform_data *)platform;
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004725 struct audio_usecase *usecase = get_usecase_from_list(my_data->adev, uc_id);
4726 if (mic_count == NULL || mic_array == NULL || usecase == NULL) {
jiabin8962a4d2018-03-19 18:21:24 -07004727 return -EINVAL;
4728 }
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004729 size_t max_mic_count = my_data->declared_mic_count;
jiabin8962a4d2018-03-19 18:21:24 -07004730 size_t actual_mic_count = 0;
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004731
4732 snd_device_t active_input_snd_device =
4733 platform_get_input_snd_device(platform, usecase->stream.in->device);
4734 if (active_input_snd_device == SND_DEVICE_NONE) {
4735 ALOGI("%s: No active microphones found", __func__);
4736 goto end;
4737 }
4738
4739 size_t active_mic_count = my_data->mic_map[active_input_snd_device].mic_count;
4740 struct mic_info *m_info = my_data->mic_map[active_input_snd_device].microphones;
4741
4742 for (size_t i = 0; i < active_mic_count; i++) {
4743 unsigned int channels_for_active_mic = channels;
4744 if (channels_for_active_mic > m_info[i].channel_count) {
4745 channels_for_active_mic = m_info[i].channel_count;
4746 }
4747 for (size_t j = 0; j < max_mic_count; j++) {
4748 if (strcmp(my_data->microphones[j].device_id,
4749 m_info[i].device_id) == 0) {
4750 mic_array[actual_mic_count] = my_data->microphones[j];
4751 for (size_t ch = 0; ch < channels_for_active_mic; ch++) {
4752 mic_array[actual_mic_count].channel_mapping[ch] =
4753 m_info[i].channel_mapping[ch];
4754 }
4755 actual_mic_count++;
4756 break;
jiabin8962a4d2018-03-19 18:21:24 -07004757 }
jiabin8962a4d2018-03-19 18:21:24 -07004758 }
4759 }
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004760end:
jiabin8962a4d2018-03-19 18:21:24 -07004761 *mic_count = actual_mic_count;
4762 return 0;
4763}
Haynes Mathew George65f6b432018-02-27 17:44:55 -08004764
4765int platform_set_usb_service_interval(void *platform,
4766 bool playback,
4767 unsigned long service_interval,
4768 bool *reconfig)
4769{
4770#if defined (USB_SERVICE_INTERVAL_ENABLED)
4771 struct platform_data *_platform = (struct platform_data *)platform;
4772 *reconfig = false;
4773 if (!playback) {
4774 ALOGE("%s not valid for capture", __func__);
4775 return -1;
4776 }
4777 const char *ctl_name = "USB_AUDIO_RX service_interval";
4778 struct mixer_ctl *ctl = mixer_get_ctl_by_name(_platform->adev->mixer,
4779 ctl_name);
4780 if (!ctl) {
4781 ALOGV("%s: could not get mixer %s", __func__, ctl_name);
4782 return -1;
4783 }
4784 if (mixer_ctl_get_value(ctl, 0) != (int)service_interval) {
4785 mixer_ctl_set_value(ctl, 0, service_interval);
4786 *reconfig = true;
4787 }
4788 return 0;
4789#else
4790 *reconfig = false;
4791 (void)platform;
4792 (void)playback;
4793 (void)service_interval;
4794 return -1;
4795#endif
4796}
4797
4798int platform_get_usb_service_interval(void *platform,
4799 bool playback,
4800 unsigned long *service_interval)
4801{
4802#if defined (USB_SERVICE_INTERVAL_ENABLED)
4803 struct platform_data *_platform = (struct platform_data *)platform;
4804 if (!playback) {
4805 ALOGE("%s not valid for capture", __func__);
4806 return -1;
4807 }
4808 const char *ctl_name = "USB_AUDIO_RX service_interval";
4809 struct mixer_ctl *ctl = mixer_get_ctl_by_name(_platform->adev->mixer,
4810 ctl_name);
4811 if (!ctl) {
4812 ALOGV("%s: could not get mixer %s", __func__, ctl_name);
4813 return -1;
4814 }
4815 *service_interval = mixer_ctl_get_value(ctl, 0);
4816 return 0;
4817#else
4818 (void)platform;
4819 (void)playback;
4820 (void)service_interval;
4821 return -1;
4822#endif
4823}
Ashish Jain1c849702018-05-11 20:11:55 +05304824
4825int platform_set_acdb_metainfo_key(void *platform __unused,
4826 char *name __unused,
4827 int key __unused)
4828{
4829 return -ENOSYS;
4830}