blob: 450e31cc60963fbb9fd6478cb9776c134aa8143d [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>
Alexey Polyudove920d4b2017-09-15 17:09:07 -070033#if defined (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845)
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;
Alexey Polyudove920d4b2017-09-15 17:09:07 -0700146#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845)
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",
Eric Laurentb23d5282013-05-14 15:27:20 -0700266 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = "voice-handset-tmus",
267 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones",
268 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones",
269 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset",
vivek mehtaa6b79742017-03-09 15:40:43 -0800270 [SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = "voice-tty-full-usb",
271 [SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = "voice-tty-vco-usb",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700272 [SND_DEVICE_OUT_VOICE_TX] = "voice-tx",
David Linee3fe402017-03-13 10:00:42 -0700273 [SND_DEVICE_OUT_USB_HEADSET] = "usb-headset",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700274 [SND_DEVICE_OUT_VOICE_USB_HEADSET] = "usb-headset",
David Linee3fe402017-03-13 10:00:42 -0700275 [SND_DEVICE_OUT_USB_HEADPHONES] = "usb-headphones",
jasmine cha270b7762018-03-30 15:41:33 +0800276 [SND_DEVICE_OUT_USB_HEADSET_SPEC] = "usb-headset",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700277 [SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = "usb-headphones",
David Linee3fe402017-03-13 10:00:42 -0700278 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = "speaker-and-usb-headphones",
Haynes Mathew George9090bfb2017-05-31 11:44:50 -0700279 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] = "speaker-safe-and-usb-headphones",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700280 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = "speaker-protected",
281 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = "voice-speaker-protected",
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -0700282 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = "voice-speaker-hfp",
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -0800283 [SND_DEVICE_OUT_SPEAKER_AND_BT_SCO] = "speaker-and-bt-sco",
284 [SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB] = "speaker-and-bt-sco-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700285
286 /* Capture sound devices */
287 [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700288 [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700289 [SND_DEVICE_IN_HANDSET_MIC_NS] = "handset-mic",
290 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = "handset-mic",
291 [SND_DEVICE_IN_HANDSET_DMIC] = "dmic-endfire",
292 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = "dmic-endfire",
293 [SND_DEVICE_IN_HANDSET_DMIC_NS] = "dmic-endfire",
294 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = "dmic-endfire",
295 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = "dmic-endfire",
296
297 [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
298 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "speaker-mic",
299 [SND_DEVICE_IN_SPEAKER_MIC_NS] = "speaker-mic",
300 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = "speaker-mic",
301 [SND_DEVICE_IN_SPEAKER_DMIC] = "speaker-dmic-endfire",
302 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = "speaker-dmic-endfire",
303 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = "speaker-dmic-endfire",
304 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = "speaker-dmic-endfire",
305 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = "speaker-dmic-endfire",
306
307 [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
Eric Laurentcefbbac2014-09-04 13:54:10 -0500308 [SND_DEVICE_IN_HEADSET_MIC_AEC] = "headset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700309
Eric Laurentb23d5282013-05-14 15:27:20 -0700310 [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic",
311 [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700312 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = "bt-sco-mic",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700313 [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700314 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = "bt-sco-mic-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700315 [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700316
317 [SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef",
318 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = "voice-dmic-ef-tmus",
319 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
320 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = "voice-speaker-dmic-ef",
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -0700321 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = "voice-speaker-mic-hfp",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700322 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700323 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
324 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
325 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
vivek mehtaa6b79742017-03-09 15:40:43 -0800326 [SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = "voice-tty-full-usb-mic",
327 [SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = "voice-tty-hco-usb-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700328
Eric Laurentb23d5282013-05-14 15:27:20 -0700329 [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700330 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = "voice-rec-mic",
vivek mehta733c1df2016-04-04 15:09:24 -0700331 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = "voice-rec-mic",
vivek mehtaf3440682016-05-11 14:24:37 -0700332 [SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700333 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = "voice-rec-dmic-ef",
334 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence",
David Linee3fe402017-03-13 10:00:42 -0700335 [SND_DEVICE_IN_USB_HEADSET_MIC] = "usb-headset-mic",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700336 [SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] ="usb-headset-mic",
337 [SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = "usb-headset-mic",
338 [SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = "usb-headset-mic",
339 [SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = "usb-headset-mic",
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700340 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = "headset-mic",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700341
Ricardo Garcia9034bc42016-04-04 07:11:46 -0700342 [SND_DEVICE_IN_UNPROCESSED_MIC] = "unprocessed-mic",
vivek mehta0125e782016-06-16 18:03:11 -0700343 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = "unprocessed-stereo-mic",
344 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = "unprocessed-three-mic",
345 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = "unprocessed-quad-mic",
346 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = "unprocessed-headset-mic",
rago90fb9612015-12-02 11:37:53 -0800347
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700348 [SND_DEVICE_IN_VOICE_RX] = "voice-rx",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700349
Prashant Malanic92c5962015-08-11 15:10:18 -0700350 [SND_DEVICE_IN_THREE_MIC] = "three-mic",
351 [SND_DEVICE_IN_QUAD_MIC] = "quad-mic",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700352 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = "vi-feedback",
Prashant Malanic92c5962015-08-11 15:10:18 -0700353 [SND_DEVICE_IN_HANDSET_TMIC] = "three-mic",
354 [SND_DEVICE_IN_HANDSET_QMIC] = "quad-mic",
vivek mehta733c1df2016-04-04 15:09:24 -0700355 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = "three-mic",
356 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = "quad-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700357};
358
359/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700360static int acdb_device_table[SND_DEVICE_MAX] = {
Eric Laurentb23d5282013-05-14 15:27:20 -0700361 [SND_DEVICE_NONE] = -1,
362 [SND_DEVICE_OUT_HANDSET] = 7,
363 [SND_DEVICE_OUT_SPEAKER] = 15,
364 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 15,
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700365 [SND_DEVICE_OUT_SPEAKER_SAFE] = 15,
Eric Laurentb23d5282013-05-14 15:27:20 -0700366 [SND_DEVICE_OUT_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500367 [SND_DEVICE_OUT_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700368 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700369 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500370 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = 77,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700371 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = 77,
Ravi Kumar Alamanda235c3482014-08-21 17:32:44 -0700372 [SND_DEVICE_OUT_VOICE_HANDSET] = ACDB_ID_VOICE_HANDSET,
373 [SND_DEVICE_OUT_VOICE_SPEAKER] = ACDB_ID_VOICE_SPEAKER,
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500374 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = 53,
Eric Laurentb23d5282013-05-14 15:27:20 -0700375 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500376 [SND_DEVICE_OUT_VOICE_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700377 [SND_DEVICE_OUT_HDMI] = 18,
378 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 15,
379 [SND_DEVICE_OUT_BT_SCO] = 22,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700380 [SND_DEVICE_OUT_BT_SCO_WB] = 39,
Aniket Kumar Lata26483012018-01-31 20:21:42 -0800381 [SND_DEVICE_OUT_BT_A2DP] = 20,
382 [SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] = 14,
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700383 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = ACDB_ID_VOICE_HANDSET_TMUS,
Eric Laurentb23d5282013-05-14 15:27:20 -0700384 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
385 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
386 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
vivek mehtaa6b79742017-03-09 15:40:43 -0800387 [SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = 17,
388 [SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = 17,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700389 [SND_DEVICE_OUT_VOICE_TX] = 45,
David Linee3fe402017-03-13 10:00:42 -0700390 [SND_DEVICE_OUT_USB_HEADSET] = 45,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700391 [SND_DEVICE_OUT_VOICE_USB_HEADSET] = 45,
David Linee3fe402017-03-13 10:00:42 -0700392 [SND_DEVICE_OUT_USB_HEADPHONES] = 45,
jasmine cha270b7762018-03-30 15:41:33 +0800393 [SND_DEVICE_OUT_USB_HEADSET_SPEC] = 45,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700394 [SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = 45,
David Linee3fe402017-03-13 10:00:42 -0700395 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = 14,
Haynes Mathew George9090bfb2017-05-31 11:44:50 -0700396 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] = 14,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700397 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = 124,
398 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = 101,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700399 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = ACDB_ID_VOICE_SPEAKER,
Eric Laurentb23d5282013-05-14 15:27:20 -0700400
401 [SND_DEVICE_IN_HANDSET_MIC] = 4,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700402 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 106,
403 [SND_DEVICE_IN_HANDSET_MIC_NS] = 107,
404 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = 108,
405 [SND_DEVICE_IN_HANDSET_DMIC] = 41,
406 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = 109,
407 [SND_DEVICE_IN_HANDSET_DMIC_NS] = 110,
408 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = 111,
409 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = 34,
410
411 [SND_DEVICE_IN_SPEAKER_MIC] = 11,
412 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 112,
413 [SND_DEVICE_IN_SPEAKER_MIC_NS] = 113,
414 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = 114,
415 [SND_DEVICE_IN_SPEAKER_DMIC] = 43,
416 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = 115,
417 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = 116,
418 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = 117,
419 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = 35,
420
rago90fb9612015-12-02 11:37:53 -0800421 [SND_DEVICE_IN_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentcefbbac2014-09-04 13:54:10 -0500422 [SND_DEVICE_IN_HEADSET_MIC_AEC] = ACDB_ID_HEADSET_MIC_AEC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700423
Eric Laurentb23d5282013-05-14 15:27:20 -0700424 [SND_DEVICE_IN_HDMI_MIC] = 4,
425 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700426 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = 21,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700427 [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700428 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = 38,
Eric Laurentb23d5282013-05-14 15:27:20 -0700429 [SND_DEVICE_IN_CAMCORDER_MIC] = 61,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700430
431 [SND_DEVICE_IN_VOICE_DMIC] = 41,
432 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = ACDB_ID_VOICE_DMIC_EF_TMUS,
433 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700434 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = 11,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700435 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 43,
rago90fb9612015-12-02 11:37:53 -0800436 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentb23d5282013-05-14 15:27:20 -0700437 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
438 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
439 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
vivek mehtaa6b79742017-03-09 15:40:43 -0800440 [SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = 16,
441 [SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = 16,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700442
rago90fb9612015-12-02 11:37:53 -0800443 [SND_DEVICE_IN_VOICE_REC_MIC] = ACDB_ID_VOICE_REC_MIC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700444 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = 113,
vivek mehta733c1df2016-04-04 15:09:24 -0700445 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = 112,
vivek mehtaf3440682016-05-11 14:24:37 -0700446 [SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = 114,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700447 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = 35,
448 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 43,
rago90fb9612015-12-02 11:37:53 -0800449 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
450
451 [SND_DEVICE_IN_UNPROCESSED_MIC] = ACDB_ID_VOICE_REC_MIC,
452 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
vivek mehta4ed66e62016-04-15 23:33:34 -0700453 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = 35,
454 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = 125,
455 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = 125,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700456
457 [SND_DEVICE_IN_VOICE_RX] = 44,
David Linee3fe402017-03-13 10:00:42 -0700458 [SND_DEVICE_IN_USB_HEADSET_MIC] = 44,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700459 [SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = 44,
460 [SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = 44,
461 [SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = 44,
462 [SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = 44,
Prashant Malanic92c5962015-08-11 15:10:18 -0700463 [SND_DEVICE_IN_THREE_MIC] = 46,
464 [SND_DEVICE_IN_QUAD_MIC] = 46,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700465 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = 102,
Prashant Malanic92c5962015-08-11 15:10:18 -0700466 [SND_DEVICE_IN_HANDSET_TMIC] = 125,
467 [SND_DEVICE_IN_HANDSET_QMIC] = 125,
vivek mehta733c1df2016-04-04 15:09:24 -0700468 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = 125, /* override this for new target to 140 */
469 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = 125, /* override this for new target to 140 */
Eric Laurentb23d5282013-05-14 15:27:20 -0700470};
471
David Linee3fe402017-03-13 10:00:42 -0700472// Platform specific backend bit width table
473static int backend_bit_width_table[SND_DEVICE_MAX] = {0};
474
Haynes Mathew George98c95622014-06-20 19:14:25 -0700475struct name_to_index {
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700476 char name[100];
477 unsigned int index;
478};
479
480#define TO_NAME_INDEX(X) #X, X
481
Haynes Mathew George98c95622014-06-20 19:14:25 -0700482/* Used to get index from parsed string */
483static const struct name_to_index snd_device_name_index[SND_DEVICE_MAX] = {
484 /* out */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700485 {TO_NAME_INDEX(SND_DEVICE_OUT_HANDSET)},
486 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER)},
487 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_REVERSE)},
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700488 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700489 {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500490 {TO_NAME_INDEX(SND_DEVICE_OUT_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700491 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700492 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES)},
Eric Laurent744996b2014-10-01 11:40:40 -0500493 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_LINE)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700494 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700495 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET)},
496 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700497 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_HFP)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700498 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500499 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700500 {TO_NAME_INDEX(SND_DEVICE_OUT_HDMI)},
501 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HDMI)},
502 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO)},
503 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO_WB)},
Aniket Kumar Lata26483012018-01-31 20:21:42 -0800504 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_A2DP)},
505 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700506 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET_TMUS)},
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500507 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HAC_HANDSET)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700508 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES)},
509 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES)},
510 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET)},
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -0800511 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_SCO)},
512 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800513 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_USB)},
514 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_USB)},
David Linee3fe402017-03-13 10:00:42 -0700515 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADSET)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700516 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_USB_HEADSET)},
David Linee3fe402017-03-13 10:00:42 -0700517 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADPHONES)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700518 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_USB_HEADPHONES)},
David Linee3fe402017-03-13 10:00:42 -0700519 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET)},
Haynes Mathew George9090bfb2017-05-31 11:44:50 -0700520 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700521 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED)},
522 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED)},
jasmine cha270b7762018-03-30 15:41:33 +0800523 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADSET_SPEC)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800524
525 /* in */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700526 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700527 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700528 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_NS)},
529 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)},
530 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC)},
531 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC)},
532 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_NS)},
533 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)},
534 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_STEREO)},
535
536 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700537 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700538 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_NS)},
539 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)},
540 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC)},
541 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC)},
542 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS)},
543 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)},
544 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_STEREO)},
545
546 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC)},
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700547 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700548
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700549 {TO_NAME_INDEX(SND_DEVICE_IN_HDMI_MIC)},
550 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700551 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700552 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700553 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700554 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700555
556 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC)},
557 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC_TMUS)},
558 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700559 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700560 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC)},
561 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEADSET_MIC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700562 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC)},
563 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC)},
564 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800565 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC)},
566 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC)},
567
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700568
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700569 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700570 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_NS)},
vivek mehta733c1df2016-04-04 15:09:24 -0700571 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC)},
vivek mehtaf3440682016-05-11 14:24:37 -0700572 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700573 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_STEREO)},
574 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE)},
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700575 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_HEADSET_MIC)},
David Linee3fe402017-03-13 10:00:42 -0700576 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700577 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_USB_HEADSET_MIC)},
578 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC)},
579 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC)},
580 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC_AEC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700581
rago90fb9612015-12-02 11:37:53 -0800582 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_MIC)},
583 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC)},
vivek mehta4ed66e62016-04-15 23:33:34 -0700584 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_STEREO_MIC)},
585 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_THREE_MIC)},
586 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_QUAD_MIC)},
rago90fb9612015-12-02 11:37:53 -0800587
Prashant Malanic92c5962015-08-11 15:10:18 -0700588 {TO_NAME_INDEX(SND_DEVICE_IN_THREE_MIC)},
589 {TO_NAME_INDEX(SND_DEVICE_IN_QUAD_MIC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700590 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_VI_FEEDBACK)},
Prashant Malanic92c5962015-08-11 15:10:18 -0700591 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC)},
592 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC)},
vivek mehta733c1df2016-04-04 15:09:24 -0700593 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC_AEC)},
594 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC_AEC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700595};
596
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700597static char * backend_tag_table[SND_DEVICE_MAX] = {0};
598static char * hw_interface_table[SND_DEVICE_MAX] = {0};
Haynes Mathew George98c95622014-06-20 19:14:25 -0700599
600static const struct name_to_index usecase_name_index[AUDIO_USECASE_MAX] = {
601 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_DEEP_BUFFER)},
602 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_LOW_LATENCY)},
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800603 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_HIFI)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700604 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD)},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700605 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_TTS)},
606 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_ULL)},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800607 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_MMAP)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700608 {TO_NAME_INDEX(USECASE_AUDIO_RECORD)},
609 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_LOW_LATENCY)},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800610 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_MMAP)},
Haynes Mathew George569b7482017-05-08 14:44:27 -0700611 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_HIFI)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700612 {TO_NAME_INDEX(USECASE_VOICE_CALL)},
613 {TO_NAME_INDEX(USECASE_VOICE2_CALL)},
614 {TO_NAME_INDEX(USECASE_VOLTE_CALL)},
615 {TO_NAME_INDEX(USECASE_QCHAT_CALL)},
616 {TO_NAME_INDEX(USECASE_VOWLAN_CALL)},
John Muirf1346ce2016-12-06 00:03:41 -0800617 {TO_NAME_INDEX(USECASE_VOICEMMODE1_CALL)},
618 {TO_NAME_INDEX(USECASE_VOICEMMODE2_CALL)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700619 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK)},
620 {TO_NAME_INDEX(USECASE_INCALL_REC_DOWNLINK)},
621 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK_AND_DOWNLINK)},
622 {TO_NAME_INDEX(USECASE_AUDIO_HFP_SCO)},
John Muirf1346ce2016-12-06 00:03:41 -0800623 {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_RX)},
624 {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_TX)},
625 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_AFE_PROXY)},
626 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_AFE_PROXY)},
627 {TO_NAME_INDEX(USECASE_AUDIO_DSM_FEEDBACK)},
vivek mehtaa68fea62017-06-08 19:04:02 -0700628 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_VOIP)},
629 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_VOIP)},
Nadav Bar3d72cfc2018-01-07 12:19:24 +0200630 {TO_NAME_INDEX(USECASE_INCALL_MUSIC_UPLINK)},
Aniket Kumar Lata99546312018-03-19 21:38:38 -0700631 {TO_NAME_INDEX(USECASE_AUDIO_A2DP_ABR_FEEDBACK)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700632};
633
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800634static const struct name_to_index usecase_type_index[USECASE_TYPE_MAX] = {
635 {TO_NAME_INDEX(PCM_PLAYBACK)},
636 {TO_NAME_INDEX(PCM_CAPTURE)},
637 {TO_NAME_INDEX(VOICE_CALL)},
638 {TO_NAME_INDEX(PCM_HFP_CALL)},
639};
640
641struct app_type_entry {
642 int uc_type;
643 int bit_width;
644 int app_type;
645 int max_rate;
vivek mehtaa68fea62017-06-08 19:04:02 -0700646 char *mode;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800647 struct listnode node; // membership in app_type_entry_list;
648};
649
650static struct listnode app_type_entry_list;
651
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700652#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
653#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
Eric Laurent0e46adf2016-12-16 12:49:24 -0800654#define ULL_PLATFORM_DELAY (3*1000LL)
655#define MMAP_PLATFORM_DELAY (3*1000LL)
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700656
Eric Laurentb23d5282013-05-14 15:27:20 -0700657static pthread_once_t check_op_once_ctl = PTHREAD_ONCE_INIT;
658static bool is_tmus = false;
659
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800660static int init_be_dai_name_table(struct audio_device *adev);
661
Eric Laurentb23d5282013-05-14 15:27:20 -0700662static void check_operator()
663{
664 char value[PROPERTY_VALUE_MAX];
665 int mccmnc;
666 property_get("gsm.sim.operator.numeric",value,"0");
667 mccmnc = atoi(value);
Eric Laurent2bafff12016-03-17 12:17:23 -0700668 ALOGD("%s: tmus mccmnc %d", __func__, mccmnc);
Eric Laurentb23d5282013-05-14 15:27:20 -0700669 switch(mccmnc) {
670 /* TMUS MCC(310), MNC(490, 260, 026) */
671 case 310490:
672 case 310260:
673 case 310026:
sangwon.jeonb891db52013-09-14 17:39:15 +0900674 /* Add new TMUS MNC(800, 660, 580, 310, 270, 250, 240, 230, 220, 210, 200, 160) */
675 case 310800:
676 case 310660:
677 case 310580:
678 case 310310:
679 case 310270:
680 case 310250:
681 case 310240:
682 case 310230:
683 case 310220:
684 case 310210:
685 case 310200:
686 case 310160:
Eric Laurentb23d5282013-05-14 15:27:20 -0700687 is_tmus = true;
688 break;
689 }
690}
691
692bool is_operator_tmus()
693{
694 pthread_once(&check_op_once_ctl, check_operator);
695 return is_tmus;
696}
697
keunhui.park2f7306a2015-07-16 16:48:06 +0900698static char *get_current_operator()
699{
700 struct listnode *node;
701 struct operator_info *info_item;
702 char mccmnc[PROPERTY_VALUE_MAX];
703 char *ret = NULL;
704
Tom Cherry7fea2042016-11-10 18:05:59 -0800705 property_get("gsm.sim.operator.numeric",mccmnc,"00000");
keunhui.park2f7306a2015-07-16 16:48:06 +0900706
707 list_for_each(node, &operator_info_list) {
708 info_item = node_to_item(node, struct operator_info, list);
709 if (strstr(info_item->mccmnc, mccmnc) != NULL) {
710 ret = info_item->name;
711 }
712 }
713
714 return ret;
715}
716
717static struct operator_specific_device *get_operator_specific_device(snd_device_t snd_device)
718{
719 struct listnode *node;
720 struct operator_specific_device *ret = NULL;
721 struct operator_specific_device *device_item;
722 char *operator_name;
723
724 operator_name = get_current_operator();
725 if (operator_name == NULL)
726 return ret;
727
728 list_for_each(node, operator_specific_device_table[snd_device]) {
729 device_item = node_to_item(node, struct operator_specific_device, list);
730 if (strcmp(operator_name, device_item->operator) == 0) {
731 ret = device_item;
732 }
733 }
734
735 return ret;
736}
737
738
739static int get_operator_specific_device_acdb_id(snd_device_t snd_device)
740{
741 struct operator_specific_device *device;
742 int ret = acdb_device_table[snd_device];
743
744 device = get_operator_specific_device(snd_device);
745 if (device != NULL)
746 ret = device->acdb_id;
747
748 return ret;
749}
750
751static const char *get_operator_specific_device_mixer_path(snd_device_t snd_device)
752{
753 struct operator_specific_device *device;
754 const char *ret = device_table[snd_device];
755
756 device = get_operator_specific_device(snd_device);
757 if (device != NULL)
758 ret = device->mixer_path;
759
760 return ret;
761}
762
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800763inline bool platform_supports_app_type_cfg()
764{
Alexey Polyudove920d4b2017-09-15 17:09:07 -0700765#if defined (PLATFORM_MSM8998) || (PLATFORM_SDM845)
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800766 return true;
767#else
768 return false;
769#endif
770}
771
jasmine chac89321b2018-04-10 21:37:01 +0800772static int parse_audiocal_cfg(struct str_parms *parms, acdb_audio_cal_cfg_t *cal)
773{
774 int err;
775 char value[64];
776 int ret = 0;
777
778 if (parms == NULL || cal == NULL)
779 return ret;
780
781 err = str_parms_get_str(parms, "cal_persist", value, sizeof(value));
782 if (err >= 0) {
783 str_parms_del(parms, "cal_persist");
784 cal->persist = (uint32_t)strtoul(value, NULL, 0);
785 ret = ret | 0x1;
786 }
787 err = str_parms_get_str(parms, "cal_apptype", value, sizeof(value));
788 if (err >= 0) {
789 str_parms_del(parms, "cal_apptype");
790 cal->app_type = (uint32_t)strtoul(value, NULL, 0);
791 ret = ret | 0x2;
792 }
793 err = str_parms_get_str(parms, "cal_caltype", value, sizeof(value));
794 if (err >= 0) {
795 str_parms_del(parms, "cal_caltype");
796 cal->cal_type = (uint32_t)strtoul(value, NULL, 0);
797 ret = ret | 0x4;
798 }
799 err = str_parms_get_str(parms, "cal_samplerate", value, sizeof(value));
800 if (err >= 0) {
801 str_parms_del(parms, "cal_samplerate");
802 cal->sampling_rate = (uint32_t)strtoul(value, NULL, 0);
803 ret = ret | 0x8;
804 }
805 err = str_parms_get_str(parms, "cal_devid", value, sizeof(value));
806 if (err >= 0) {
807 str_parms_del(parms, "cal_devid");
808 cal->dev_id = (uint32_t)strtoul(value, NULL, 0);
809 ret = ret | 0x10;
810 }
811 err = str_parms_get_str(parms, "cal_snddevid", value, sizeof(value));
812 if (err >= 0) {
813 str_parms_del(parms, "cal_snddevid");
814 cal->snd_dev_id = (uint32_t)strtoul(value, NULL, 0);
815 ret = ret | 0x20;
816 }
817 err = str_parms_get_str(parms, "cal_topoid", value, sizeof(value));
818 if (err >= 0) {
819 str_parms_del(parms, "cal_topoid");
820 cal->topo_id = (uint32_t)strtoul(value, NULL, 0);
821 ret = ret | 0x40;
822 }
823 err = str_parms_get_str(parms, "cal_moduleid", value, sizeof(value));
824 if (err >= 0) {
825 str_parms_del(parms, "cal_moduleid");
826 cal->module_id = (uint32_t)strtoul(value, NULL, 0);
827 ret = ret | 0x80;
828 }
829 err = str_parms_get_str(parms, "cal_paramid", value, sizeof(value));
830 if (err >= 0) {
831 str_parms_del(parms, "cal_paramid");
832 cal->param_id = (uint32_t)strtoul(value, NULL, 0);
833 ret = ret | 0x100;
834 }
835 return ret;
836}
837
838static void set_audiocal(void *platform, struct str_parms *parms, char *value, int len)
839{
840 struct platform_data *my_data = (struct platform_data *)platform;
841 acdb_audio_cal_cfg_t cal;
842 uint8_t *dptr = NULL;
843 int32_t dlen = 0;
844 int err ,ret;
845
846 if (value == NULL || platform == NULL || parms == NULL) {
847 ALOGE("[%s] received null pointer, failed", __func__);
848 goto done_key_audcal;
849 }
850
851 memset(&cal, 0, sizeof(acdb_audio_cal_cfg_t));
852 /* parse audio calibration keys */
853 ret = parse_audiocal_cfg(parms, &cal);
854
855 /* handle audio calibration data now */
856 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_AUD_CALDATA, value, len);
857 if (err >= 0) {
858 str_parms_del(parms, AUDIO_PARAMETER_KEY_AUD_CALDATA);
859 dlen = strlen(value);
860 if (dlen <= 0) {
861 ALOGE("[%s] null data received", __func__);
862 goto done_key_audcal;
863 }
864 /*
865 The base64 encoded string is always larger than the binary data,
866 so b64_pton will always output less data than provided (around 1/3
867 less than the input data). That's why we can allocate input buffer
868 length and then get function work.
869 */
870 dptr = (uint8_t *)calloc(dlen, sizeof(uint8_t));
871 if (dptr == NULL) {
872 ALOGE("[%s] memory allocation failed for %d", __func__, dlen);
873 goto done_key_audcal;
874 }
875 dlen = b64_pton(value, dptr, dlen);
876 if (dlen <= 0) {
877 ALOGE("[%s] data decoding failed %d", __func__, dlen);
878 goto done_key_audcal;
879 }
880
881 if (cal.dev_id) {
882 if (audio_is_input_device(cal.dev_id)) {
883 cal.snd_dev_id = platform_get_input_snd_device(platform, cal.dev_id);
884 } else {
885 cal.snd_dev_id = platform_get_output_snd_device(platform, cal.dev_id);
886 }
887 }
888 cal.acdb_dev_id = platform_get_snd_device_acdb_id(cal.snd_dev_id);
889 ALOGD("Setting audio calibration for snd_device(%d) acdb_id(%d)",
890 cal.snd_dev_id, cal.acdb_dev_id);
891 if (cal.acdb_dev_id == -EINVAL) {
892 ALOGE("[%s] Invalid acdb_device id %d for snd device id %d",
893 __func__, cal.acdb_dev_id, cal.snd_dev_id);
894 goto done_key_audcal;
895 }
896 if (my_data->acdb_set_audio_cal) {
897 ret = my_data->acdb_set_audio_cal((void *)&cal, (void *)dptr, dlen);
898 }
899 }
900done_key_audcal:
901 if (dptr != NULL)
902 free(dptr);
903}
904
vivek mehta1a9b7c02015-06-25 11:49:38 -0700905bool platform_send_gain_dep_cal(void *platform, int level)
906{
907 bool ret_val = false;
908 struct platform_data *my_data = (struct platform_data *)platform;
909 struct audio_device *adev = my_data->adev;
910 int acdb_dev_id, app_type;
911 int acdb_dev_type = MSM_SNDDEV_CAP_RX;
912 int mode = CAL_MODE_RTAC;
913 struct listnode *node;
914 struct audio_usecase *usecase;
Haynes Mathew George67486e22017-06-26 12:58:38 -0700915 bool valid_uc_type;
916 bool valid_dev;
vivek mehta1a9b7c02015-06-25 11:49:38 -0700917
918 if (my_data->acdb_send_gain_dep_cal == NULL) {
919 ALOGE("%s: dlsym error for acdb_send_gain_dep_cal", __func__);
920 return ret_val;
921 }
922
923 if (!voice_is_in_call(adev)) {
924 ALOGV("%s: Not Voice call usecase, apply new cal for level %d",
925 __func__, level);
vivek mehta1a9b7c02015-06-25 11:49:38 -0700926
927 // find the current active sound device
928 list_for_each(node, &adev->usecase_list) {
929 usecase = node_to_item(node, struct audio_usecase, list);
Haynes Mathew George67486e22017-06-26 12:58:38 -0700930 LOG_ALWAYS_FATAL_IF(usecase == NULL,
931 "unxpected NULL usecase in usecase_list");
932 valid_uc_type = usecase->type == PCM_PLAYBACK;
933 valid_dev = false;
934 if (valid_uc_type) {
935 audio_devices_t dev = usecase->stream.out->devices;
936 valid_dev = (dev == AUDIO_DEVICE_OUT_SPEAKER ||
vivek mehta40125092017-08-21 18:48:51 -0700937 dev == AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Haynes Mathew George67486e22017-06-26 12:58:38 -0700938 dev == AUDIO_DEVICE_OUT_WIRED_HEADSET ||
939 dev == AUDIO_DEVICE_OUT_WIRED_HEADPHONE);
940 }
941 if (valid_dev) {
vivek mehta40125092017-08-21 18:48:51 -0700942 ALOGV("%s: out device is %d", __func__, usecase->out_snd_device);
943 if (platform_supports_app_type_cfg())
944 app_type = usecase->stream.out->app_type_cfg.app_type;
945 else
946 app_type = DEFAULT_APP_TYPE_RX_PATH;
vivek mehta4cb82982015-07-13 12:05:49 -0700947
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -0700948 acdb_dev_id = platform_get_snd_device_acdb_id(usecase->out_snd_device);
vivek mehta40125092017-08-21 18:48:51 -0700949
950 if (!my_data->acdb_send_gain_dep_cal(acdb_dev_id, app_type,
vivek mehta1a9b7c02015-06-25 11:49:38 -0700951 acdb_dev_type, mode, level)) {
952 // set ret_val true if at least one calibration is set successfully
953 ret_val = true;
954 } else {
955 ALOGE("%s: my_data->acdb_send_gain_dep_cal failed ", __func__);
956 }
957 } else {
958 ALOGW("%s: Usecase list is empty", __func__);
959 }
960 }
961 } else {
962 ALOGW("%s: Voice call in progress .. ignore setting new cal",
963 __func__);
964 }
965 return ret_val;
966}
967
Eric Laurentcefbbac2014-09-04 13:54:10 -0500968void platform_set_echo_reference(struct audio_device *adev, bool enable, audio_devices_t out_device)
Eric Laurentb23d5282013-05-14 15:27:20 -0700969{
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800970 struct platform_data *my_data = (struct platform_data *)adev->platform;
Eric Laurentcefbbac2014-09-04 13:54:10 -0500971 snd_device_t snd_device = SND_DEVICE_NONE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700972
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800973 if (strcmp(my_data->ec_ref_mixer_path, "")) {
974 ALOGV("%s: diabling %s", __func__, my_data->ec_ref_mixer_path);
975 audio_route_reset_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
Eric Laurentcefbbac2014-09-04 13:54:10 -0500976 }
977
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800978 if (enable) {
979 strcpy(my_data->ec_ref_mixer_path, "echo-reference");
980 if (out_device != AUDIO_DEVICE_NONE) {
981 snd_device = platform_get_output_snd_device(adev->platform, out_device);
982 platform_add_backend_name(adev->platform, my_data->ec_ref_mixer_path, snd_device);
983 }
Eric Laurentcefbbac2014-09-04 13:54:10 -0500984
Joe Onorato188b6222016-03-01 11:02:27 -0800985 ALOGV("%s: enabling %s", __func__, my_data->ec_ref_mixer_path);
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800986 audio_route_apply_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
987 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700988}
989
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700990static struct csd_data *open_csd_client(bool i2s_ext_modem)
991{
992 struct csd_data *csd = calloc(1, sizeof(struct csd_data));
993
994 csd->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
995 if (csd->csd_client == NULL) {
996 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
997 goto error;
998 } else {
999 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
1000
1001 csd->deinit = (deinit_t)dlsym(csd->csd_client,
1002 "csd_client_deinit");
1003 if (csd->deinit == NULL) {
1004 ALOGE("%s: dlsym error %s for csd_client_deinit", __func__,
1005 dlerror());
1006 goto error;
1007 }
1008 csd->disable_device = (disable_device_t)dlsym(csd->csd_client,
1009 "csd_client_disable_device");
1010 if (csd->disable_device == NULL) {
1011 ALOGE("%s: dlsym error %s for csd_client_disable_device",
1012 __func__, dlerror());
1013 goto error;
1014 }
1015 csd->enable_device_config = (enable_device_config_t)dlsym(csd->csd_client,
1016 "csd_client_enable_device_config");
1017 if (csd->enable_device_config == NULL) {
1018 ALOGE("%s: dlsym error %s for csd_client_enable_device_config",
1019 __func__, dlerror());
1020 goto error;
1021 }
1022 csd->enable_device = (enable_device_t)dlsym(csd->csd_client,
1023 "csd_client_enable_device");
1024 if (csd->enable_device == NULL) {
1025 ALOGE("%s: dlsym error %s for csd_client_enable_device",
1026 __func__, dlerror());
1027 goto error;
1028 }
1029 csd->start_voice = (start_voice_t)dlsym(csd->csd_client,
1030 "csd_client_start_voice");
1031 if (csd->start_voice == NULL) {
1032 ALOGE("%s: dlsym error %s for csd_client_start_voice",
1033 __func__, dlerror());
1034 goto error;
1035 }
1036 csd->stop_voice = (stop_voice_t)dlsym(csd->csd_client,
1037 "csd_client_stop_voice");
1038 if (csd->stop_voice == NULL) {
1039 ALOGE("%s: dlsym error %s for csd_client_stop_voice",
1040 __func__, dlerror());
1041 goto error;
1042 }
1043 csd->volume = (volume_t)dlsym(csd->csd_client,
1044 "csd_client_volume");
1045 if (csd->volume == NULL) {
1046 ALOGE("%s: dlsym error %s for csd_client_volume",
1047 __func__, dlerror());
1048 goto error;
1049 }
1050 csd->mic_mute = (mic_mute_t)dlsym(csd->csd_client,
1051 "csd_client_mic_mute");
1052 if (csd->mic_mute == NULL) {
1053 ALOGE("%s: dlsym error %s for csd_client_mic_mute",
1054 __func__, dlerror());
1055 goto error;
1056 }
1057 csd->slow_talk = (slow_talk_t)dlsym(csd->csd_client,
1058 "csd_client_slow_talk");
1059 if (csd->slow_talk == NULL) {
1060 ALOGE("%s: dlsym error %s for csd_client_slow_talk",
1061 __func__, dlerror());
1062 goto error;
1063 }
1064 csd->start_playback = (start_playback_t)dlsym(csd->csd_client,
1065 "csd_client_start_playback");
1066 if (csd->start_playback == NULL) {
1067 ALOGE("%s: dlsym error %s for csd_client_start_playback",
1068 __func__, dlerror());
1069 goto error;
1070 }
1071 csd->stop_playback = (stop_playback_t)dlsym(csd->csd_client,
1072 "csd_client_stop_playback");
1073 if (csd->stop_playback == NULL) {
1074 ALOGE("%s: dlsym error %s for csd_client_stop_playback",
1075 __func__, dlerror());
1076 goto error;
1077 }
1078 csd->start_record = (start_record_t)dlsym(csd->csd_client,
1079 "csd_client_start_record");
1080 if (csd->start_record == NULL) {
1081 ALOGE("%s: dlsym error %s for csd_client_start_record",
1082 __func__, dlerror());
1083 goto error;
1084 }
1085 csd->stop_record = (stop_record_t)dlsym(csd->csd_client,
1086 "csd_client_stop_record");
1087 if (csd->stop_record == NULL) {
1088 ALOGE("%s: dlsym error %s for csd_client_stop_record",
1089 __func__, dlerror());
1090 goto error;
1091 }
1092
1093 csd->get_sample_rate = (get_sample_rate_t)dlsym(csd->csd_client,
1094 "csd_client_get_sample_rate");
1095 if (csd->get_sample_rate == NULL) {
1096 ALOGE("%s: dlsym error %s for csd_client_get_sample_rate",
1097 __func__, dlerror());
1098
1099 goto error;
1100 }
1101
1102 csd->init = (init_t)dlsym(csd->csd_client, "csd_client_init");
1103
1104 if (csd->init == NULL) {
1105 ALOGE("%s: dlsym error %s for csd_client_init",
1106 __func__, dlerror());
1107 goto error;
1108 } else {
1109 csd->init(i2s_ext_modem);
1110 }
1111 }
1112 return csd;
1113
1114error:
1115 free(csd);
1116 csd = NULL;
1117 return csd;
1118}
1119
1120void close_csd_client(struct csd_data *csd)
1121{
1122 if (csd != NULL) {
1123 csd->deinit();
1124 dlclose(csd->csd_client);
1125 free(csd);
1126 csd = NULL;
1127 }
1128}
1129
1130static void platform_csd_init(struct platform_data *my_data)
1131{
1132#ifdef PLATFORM_MSM8084
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001133 int32_t modems, (*count_modems)(void);
1134 const char *name = "libdetectmodem.so";
1135 const char *func = "count_modems";
1136 const char *error;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001137
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001138 my_data->csd = NULL;
1139
1140 void *lib = dlopen(name, RTLD_NOW);
1141 error = dlerror();
1142 if (!lib) {
1143 ALOGE("%s: could not find %s: %s", __func__, name, error);
1144 return;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001145 }
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001146
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001147 count_modems = NULL;
1148 *(void **)(&count_modems) = dlsym(lib, func);
1149 error = dlerror();
1150 if (!count_modems) {
1151 ALOGE("%s: could not find symbol %s in %s: %s",
1152 __func__, func, name, error);
1153 goto done;
1154 }
1155
1156 modems = count_modems();
1157 if (modems < 0) {
1158 ALOGE("%s: count_modems failed\n", __func__);
1159 goto done;
1160 }
1161
Eric Laurent2bafff12016-03-17 12:17:23 -07001162 ALOGD("%s: num_modems %d\n", __func__, modems);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001163 if (modems > 0)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001164 my_data->csd = open_csd_client(false /*is_i2s_ext_modem*/);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001165
1166done:
1167 dlclose(lib);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001168#else
1169 my_data->csd = NULL;
1170#endif
1171}
1172
Eric Laurentc6333382015-09-14 12:43:44 -07001173static void set_platform_defaults(struct platform_data * my_data)
Haynes Mathew George98c95622014-06-20 19:14:25 -07001174{
1175 int32_t dev;
1176 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001177 backend_tag_table[dev] = NULL;
1178 hw_interface_table[dev] = NULL;
keunhui.park2f7306a2015-07-16 16:48:06 +09001179 operator_specific_device_table[dev] = NULL;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001180 }
1181
David Linee3fe402017-03-13 10:00:42 -07001182 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1183 backend_bit_width_table[dev] = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
1184 }
1185
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001186 // To overwrite these go to the audio_platform_info.xml file.
1187 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("bt-sco");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07001188 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("bt-sco");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001189 backend_tag_table[SND_DEVICE_OUT_BT_SCO] = strdup("bt-sco");
1190 backend_tag_table[SND_DEVICE_OUT_HDMI] = strdup("hdmi");
1191 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("speaker-and-hdmi");
1192 backend_tag_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("bt-sco-wb");
1193 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("bt-sco-wb");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07001194 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("bt-sco-wb");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001195 backend_tag_table[SND_DEVICE_OUT_VOICE_TX] = strdup("afe-proxy");
1196 backend_tag_table[SND_DEVICE_IN_VOICE_RX] = strdup("afe-proxy");
Haynes Mathew George98c95622014-06-20 19:14:25 -07001197
David Linee3fe402017-03-13 10:00:42 -07001198 backend_tag_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("usb-headset");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001199 backend_tag_table[SND_DEVICE_OUT_VOICE_USB_HEADSET] = strdup("usb-headset");
David Linee3fe402017-03-13 10:00:42 -07001200 backend_tag_table[SND_DEVICE_OUT_USB_HEADPHONES] = strdup("usb-headphones");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001201 backend_tag_table[SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = strdup("usb-headphones");
David Linee3fe402017-03-13 10:00:42 -07001202 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] =
1203 strdup("speaker-and-usb-headphones");
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07001204 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] =
1205 strdup("speaker-safe-and-usb-headphones");
David Linee3fe402017-03-13 10:00:42 -07001206 backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("usb-headset-mic");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001207 backend_tag_table[SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1208 backend_tag_table[SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1209 backend_tag_table[SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1210 backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = strdup("usb-headset-mic");
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001211 backend_tag_table[SND_DEVICE_OUT_BT_A2DP] = strdup("bt-a2dp");
1212 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] = strdup("speaker-and-bt-a2dp");
jasmine cha270b7762018-03-30 15:41:33 +08001213 backend_tag_table[SND_DEVICE_OUT_USB_HEADSET_SPEC] = strdup("usb-headset");
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001214
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001215 hw_interface_table[SND_DEVICE_OUT_HANDSET] = strdup("SLIMBUS_0_RX");
1216 hw_interface_table[SND_DEVICE_OUT_SPEAKER] = strdup("SLIMBUS_0_RX");
1217 hw_interface_table[SND_DEVICE_OUT_SPEAKER_REVERSE] = strdup("SLIMBUS_0_RX");
1218 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE] = strdup("SLIMBUS_0_RX");
1219 hw_interface_table[SND_DEVICE_OUT_HEADPHONES] = strdup("SLIMBUS_0_RX");
1220 hw_interface_table[SND_DEVICE_OUT_LINE] = strdup("SLIMBUS_0_RX");
1221 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001222 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001223 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001224 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001225 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET] = strdup("SLIMBUS_0_RX");
1226 hw_interface_table[SND_DEVICE_OUT_VOICE_HAC_HANDSET] = strdup("SLIMBUS_0_RX");
1227 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER] = strdup("SLIMBUS_0_RX");
1228 hw_interface_table[SND_DEVICE_OUT_VOICE_HEADPHONES] = strdup("SLIMBUS_0_RX");
1229 hw_interface_table[SND_DEVICE_OUT_VOICE_LINE] = strdup("SLIMBUS_0_RX");
1230 hw_interface_table[SND_DEVICE_OUT_HDMI] = strdup("HDMI_RX");
1231 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("SLIMBUS_0_RX-and-HDMI_RX");
1232 hw_interface_table[SND_DEVICE_OUT_BT_SCO] = strdup("SEC_AUX_PCM_RX");
1233 hw_interface_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("SEC_AUX_PCM_RX");
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001234 hw_interface_table[SND_DEVICE_OUT_BT_A2DP] = strdup("SLIMBUS_7_RX");
1235 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] =
1236 strdup("SLIMBUS_0_RX-and-SLIMBUS_7_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001237 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = strdup("SLIMBUS_0_RX");
1238 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = strdup("SLIMBUS_0_RX");
1239 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = strdup("SLIMBUS_0_RX");
1240 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = strdup("SLIMBUS_0_RX");
David Linee3fe402017-03-13 10:00:42 -07001241 hw_interface_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("USB_AUDIO_RX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001242 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = strdup("USB_AUDIO_RX");
1243 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = strdup("USB_AUDIO_RX");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001244 hw_interface_table[SND_DEVICE_OUT_VOICE_USB_HEADSET] = strdup("USB_AUDIO_RX");
David Linee3fe402017-03-13 10:00:42 -07001245 hw_interface_table[SND_DEVICE_OUT_USB_HEADPHONES] = strdup("USB_AUDIO_RX");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001246 hw_interface_table[SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = strdup("USB_AUDIO_RX");
jasmine cha270b7762018-03-30 15:41:33 +08001247 hw_interface_table[SND_DEVICE_OUT_USB_HEADSET_SPEC] = strdup("USB_AUDIO_RX");
David Linee3fe402017-03-13 10:00:42 -07001248 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 -07001249 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 -07001250 hw_interface_table[SND_DEVICE_OUT_VOICE_TX] = strdup("AFE_PCM_RX");
1251 hw_interface_table[SND_DEVICE_OUT_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
1252 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
jasmine cha52284622018-03-23 17:21:35 +08001253 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = strdup("SLIMBUS_0_RX");
1254 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_BT_SCO] = strdup("SLIMBUS_0_RX-and-SEC_AUX_PCM_RX");
1255 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB] = strdup("SLIMBUS_0_RX-and-SEC_AUX_PCM_RX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001256 hw_interface_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1257 hw_interface_table[SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1258 hw_interface_table[SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = strdup("USB_AUDIO_TX");
1259 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1260 hw_interface_table[SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1261 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = strdup("USB_AUDIO_TX");
1262 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = strdup("USB_AUDIO_TX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001263 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001264 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_AEC] = strdup("SLIMBUS_0_TX");
1265 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_NS] = strdup("SLIMBUS_0_TX");
1266 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1267 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC] = strdup("SLIMBUS_0_TX");
1268 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_AEC] = strdup("SLIMBUS_0_TX");
1269 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_NS] = strdup("SLIMBUS_0_TX");
1270 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1271 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001272 hw_interface_table[SND_DEVICE_IN_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001273 hw_interface_table[SND_DEVICE_IN_HEADSET_MIC_AEC] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001274 hw_interface_table[SND_DEVICE_IN_CAMCORDER_MIC] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001275 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC] = strdup("SLIMBUS_0_TX");
1276 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC_NS] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001277 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC_AEC] = strdup("SLIMBUS_0_TX");
1278 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001279 hw_interface_table[SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
1280 hw_interface_table[SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = strdup("SLIMBUS_0_TX");
David Lin93725722017-10-13 14:58:17 -07001281 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_MIC] = strdup("SLIMBUS_0_TX");
1282 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1283 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = strdup("SLIMBUS_0_TX");
1284 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = strdup("SLIMBUS_0_TX");
1285 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001286 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC] = strdup("SLIMBUS_0_TX");
1287 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_AEC] = strdup("SLIMBUS_0_TX");
1288 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_NS] = strdup("SLIMBUS_0_TX");
1289 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1290 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC] = strdup("SLIMBUS_0_TX");
1291 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_AEC] = strdup("SLIMBUS_0_TX");
1292 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_NS] = strdup("SLIMBUS_0_TX");
1293 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001294 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
1295 hw_interface_table[SND_DEVICE_IN_VOICE_DMIC] = strdup("SLIMBUS_0_TX");
1296 hw_interface_table[SND_DEVICE_IN_VOICE_DMIC_TMUS] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001297 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001298 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = strdup("SLIMBUS_0_TX");
1299 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001300 hw_interface_table[SND_DEVICE_IN_VOICE_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001301 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1302 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = strdup("SLIMBUS_0_TX");
1303 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1304 hw_interface_table[SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1305 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("SEC_AUX_PCM_TX");
1306 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("SEC_AUX_PCM_TX");
1307 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("SEC_AUX_PCM_TX");
1308 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("SEC_AUX_PCM_TX");
1309 hw_interface_table[SND_DEVICE_IN_VOICE_RX] = strdup("AFE_PCM_TX");
1310 hw_interface_table[SND_DEVICE_IN_THREE_MIC] = strdup("SLIMBUS_0_TX");
1311 hw_interface_table[SND_DEVICE_IN_QUAD_MIC] = strdup("SLIMBUS_0_TX");
1312 hw_interface_table[SND_DEVICE_IN_HANDSET_TMIC] = strdup("SLIMBUS_0_TX");
1313 hw_interface_table[SND_DEVICE_IN_HANDSET_QMIC] = strdup("SLIMBUS_0_TX");
1314 hw_interface_table[SND_DEVICE_IN_HANDSET_TMIC_AEC] = strdup("SLIMBUS_0_TX");
1315 hw_interface_table[SND_DEVICE_IN_HANDSET_QMIC_AEC] = strdup("SLIMBUS_0_TX");
Eric Laurentc6333382015-09-14 12:43:44 -07001316 my_data->max_mic_count = PLATFORM_DEFAULT_MIC_COUNT;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001317}
1318
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001319void get_cvd_version(char *cvd_version, struct audio_device *adev)
1320{
1321 struct mixer_ctl *ctl;
1322 int count;
1323 int ret = 0;
1324
1325 ctl = mixer_get_ctl_by_name(adev->mixer, CVD_VERSION_MIXER_CTL);
1326 if (!ctl) {
1327 ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__, CVD_VERSION_MIXER_CTL);
1328 goto done;
1329 }
1330 mixer_ctl_update(ctl);
1331
1332 count = mixer_ctl_get_num_values(ctl);
1333 if (count > MAX_CVD_VERSION_STRING_SIZE)
1334 count = MAX_CVD_VERSION_STRING_SIZE - 1;
1335
1336 ret = mixer_ctl_get_array(ctl, cvd_version, count);
1337 if (ret != 0) {
1338 ALOGE("%s: ERROR! mixer_ctl_get_array() failed to get CVD Version", __func__);
1339 goto done;
1340 }
1341
1342done:
1343 return;
1344}
1345
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001346static int platform_acdb_init(void *platform)
1347{
1348 struct platform_data *my_data = (struct platform_data *)platform;
1349 struct audio_device *adev = my_data->adev;
1350
1351 if (!my_data->acdb_init) {
1352 ALOGE("%s: no acdb_init fn provided", __func__);
1353 return -1;
1354 }
1355
1356 if (my_data->acdb_initialized) {
1357 ALOGW("acdb is already initialized");
1358 return 0;
1359 }
1360
Alexey Polyudove920d4b2017-09-15 17:09:07 -07001361#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001362 char *cvd_version = calloc(1, MAX_CVD_VERSION_STRING_SIZE);
1363 if (!cvd_version)
1364 ALOGE("failed to allocate cvd_version");
1365 else {
1366 get_cvd_version(cvd_version, adev);
1367 my_data->acdb_init((char *)my_data->snd_card_name, cvd_version, 0);
1368 free(cvd_version);
1369 }
1370#elif defined (PLATFORM_MSM8084)
1371 my_data->acdb_init((char *)my_data->snd_card_name);
1372#else
1373 my_data->acdb_init();
1374#endif
1375 my_data->acdb_initialized = true;
1376 return 0;
1377}
1378
David Linee3fe402017-03-13 10:00:42 -07001379static void
1380platform_backend_config_init(struct platform_data *pdata)
1381{
1382 int i;
1383
1384 /* initialize backend config */
1385 for (i = 0; i < MAX_CODEC_BACKENDS; i++) {
1386 pdata->current_backend_cfg[i].sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
1387 pdata->current_backend_cfg[i].bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
1388 pdata->current_backend_cfg[i].channels = CODEC_BACKEND_DEFAULT_CHANNELS;
1389
1390 if (i > MAX_RX_CODEC_BACKENDS)
1391 pdata->current_backend_cfg[i].channels = CODEC_BACKEND_DEFAULT_TX_CHANNELS;
1392
1393 pdata->current_backend_cfg[i].bitwidth_mixer_ctl = NULL;
1394 pdata->current_backend_cfg[i].samplerate_mixer_ctl = NULL;
1395 pdata->current_backend_cfg[i].channels_mixer_ctl = NULL;
1396 }
1397
1398 pdata->current_backend_cfg[DEFAULT_CODEC_BACKEND].bitwidth_mixer_ctl =
1399 strdup("SLIM_0_RX Format");
1400 pdata->current_backend_cfg[DEFAULT_CODEC_BACKEND].samplerate_mixer_ctl =
1401 strdup("SLIM_0_RX SampleRate");
1402
1403 pdata->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].bitwidth_mixer_ctl =
1404 strdup("SLIM_0_TX Format");
1405 pdata->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].samplerate_mixer_ctl =
1406 strdup("SLIM_0_TX SampleRate");
1407
1408 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].bitwidth_mixer_ctl =
1409 strdup("USB_AUDIO_TX Format");
1410 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].samplerate_mixer_ctl =
1411 strdup("USB_AUDIO_TX SampleRate");
1412 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].channels_mixer_ctl =
1413 strdup("USB_AUDIO_TX Channels");
1414
1415 pdata->current_backend_cfg[HEADPHONE_BACKEND].bitwidth_mixer_ctl =
1416 strdup("SLIM_6_RX Format");
1417 pdata->current_backend_cfg[HEADPHONE_BACKEND].samplerate_mixer_ctl =
1418 strdup("SLIM_6_RX SampleRate");
1419
1420 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].bitwidth_mixer_ctl =
1421 strdup("USB_AUDIO_RX Format");
1422 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].samplerate_mixer_ctl =
1423 strdup("USB_AUDIO_RX SampleRate");
1424
1425 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].channels = 1;
1426 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].channels_mixer_ctl =
1427 strdup("USB_AUDIO_RX Channels");
1428}
1429
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001430static int
1431platform_backend_app_type_cfg_init(struct platform_data *pdata,
1432 struct mixer *mixer)
1433{
1434 size_t app_type_cfg[128] = {0};
1435 int length, num_app_types = 0;
1436 struct mixer_ctl *ctl = NULL;
1437
1438 const char *mixer_ctl_name = "App Type Config";
1439 ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name);
1440 if (!ctl) {
1441 ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name);
1442 return -1;
1443 }
1444
1445 length = 1; // reserve index 0 for number of app types
1446
1447 struct listnode *node;
1448 struct app_type_entry *entry;
1449 list_for_each(node, &app_type_entry_list) {
1450 entry = node_to_item(node, struct app_type_entry, node);
1451 app_type_cfg[length++] = entry->app_type;
1452 app_type_cfg[length++] = entry->max_rate;
1453 app_type_cfg[length++] = entry->bit_width;
1454 ALOGI("%s add entry %d %d", __func__, entry->app_type, entry->bit_width);
1455 num_app_types += 1;
1456 }
1457
1458 // default for capture
1459 int t;
1460 platform_get_default_app_type_v2(pdata,
1461 PCM_CAPTURE,
1462 &t);
1463 app_type_cfg[length++] = t;
1464 app_type_cfg[length++] = 48000;
1465 app_type_cfg[length++] = 16;
1466 num_app_types += 1;
1467
1468 if (num_app_types) {
1469 app_type_cfg[0] = num_app_types;
1470 if (mixer_ctl_set_array(ctl, app_type_cfg, length) < 0) {
1471 ALOGE("Failed to set app type cfg");
1472 }
1473 }
1474 return 0;
1475}
1476
Xu Han1638fd12018-04-20 12:42:23 -07001477static void configure_flicker_sensor_input(struct mixer *mixer)
1478{
1479 struct mixer_ctl *ctl;
1480 const char* ctl1 = "AIF3_CAP Mixer SLIM TX2";
1481 int setting1 = 1;
1482 const char* ctl2 = "CDC_IF TX2 MUX";
1483 const char* setting2 = "DEC2";
1484 const char* ctl3 = "SLIM_1_TX Channels";
1485 const char* setting3 = "One";
1486 const char* ctl4 = "ADC MUX2";
1487 const char* setting4 = "AMIC";
1488 const char* ctl5 = "AMIC MUX2";
1489 const char* setting5 = "ADC1";
1490 const char* ctl6 = "DEC2 Volume";
1491 int setting6 = 84;
1492 const char* ctl7 = "MultiMedia2 Mixer SLIM_1_TX";
1493 int setting7 = 1;
1494 const char* ctl8 = "SLIM_1_TX SampleRate";
1495 const char* setting8 = "KHZ_8";
1496
1497 ctl = mixer_get_ctl_by_name(mixer, ctl1);
1498 mixer_ctl_set_value(ctl, 0, setting1);
1499 ctl = mixer_get_ctl_by_name(mixer, ctl2);
1500 mixer_ctl_set_enum_by_string(ctl, setting2);
1501 ctl = mixer_get_ctl_by_name(mixer, ctl3);
1502 mixer_ctl_set_enum_by_string(ctl, setting3);
1503 ctl = mixer_get_ctl_by_name(mixer, ctl4);
1504 mixer_ctl_set_enum_by_string(ctl, setting4);
1505 ctl = mixer_get_ctl_by_name(mixer, ctl5);
1506 mixer_ctl_set_enum_by_string(ctl, setting5);
1507 ctl = mixer_get_ctl_by_name(mixer, ctl6);
1508 mixer_ctl_set_value(ctl, 0, setting6);
1509 ctl = mixer_get_ctl_by_name(mixer, ctl7);
1510 mixer_ctl_set_value(ctl, 0, setting7);
1511 ctl = mixer_get_ctl_by_name(mixer, ctl8);
1512 mixer_ctl_set_enum_by_string(ctl, setting8);
1513}
1514
Eric Laurentb23d5282013-05-14 15:27:20 -07001515void *platform_init(struct audio_device *adev)
1516{
1517 char value[PROPERTY_VALUE_MAX];
vivek mehta60ea4152016-02-18 17:10:26 -08001518 struct platform_data *my_data = NULL;
1519 int retry_num = 0, snd_card_num = 0, key = 0, ret = 0;
1520 bool dual_mic_config = false, use_default_mixer_path = true;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001521 const char *snd_card_name;
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001522 char *cvd_version = NULL;
vivek mehta60ea4152016-02-18 17:10:26 -08001523 char *snd_internal_name = NULL;
1524 char *tmp = NULL;
1525 char mixer_xml_file[MIXER_PATH_MAX_LENGTH]= {0};
vivek mehtade4849c2016-03-03 17:23:38 -08001526 char platform_info_file[MIXER_PATH_MAX_LENGTH]= {0};
1527 struct snd_card_split *snd_split_handle = NULL;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001528 my_data = calloc(1, sizeof(struct platform_data));
1529
1530 my_data->adev = adev;
1531
keunhui.park2f7306a2015-07-16 16:48:06 +09001532 list_init(&operator_info_list);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001533 list_init(&app_type_entry_list);
keunhui.park2f7306a2015-07-16 16:48:06 +09001534
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001535 set_platform_defaults(my_data);
1536
vivek mehta0fb11312017-05-15 19:35:32 -07001537 // audio_extn_utils_get_snd_card_num does
1538 // - open mixer and get snd card name
1539 // - parse platform info xml file and check for valid snd card name
1540 // - on failure loop through all the active snd card
sangwoo1b9f4b32013-06-21 18:22:55 -07001541
vivek mehta0fb11312017-05-15 19:35:32 -07001542 snd_card_num = audio_extn_utils_get_snd_card_num();
1543 if (-1 == snd_card_num) {
1544 ALOGE("%s: invalid sound card number (-1), bailing out ", __func__);
1545 goto init_failed;
sangwoo1b9f4b32013-06-21 18:22:55 -07001546 }
1547
vivek mehta0fb11312017-05-15 19:35:32 -07001548 adev->mixer = mixer_open(snd_card_num);
1549 snd_card_name = mixer_get_name(adev->mixer);
1550 my_data->hw_info = hw_info_init(snd_card_name);
1551
1552 audio_extn_set_snd_card_split(snd_card_name);
1553 snd_split_handle = audio_extn_get_snd_card_split();
1554
1555 /* Get the codec internal name from the sound card and/or form factor
1556 * name and form the mixer paths and platfor info file name dynamically.
1557 * This is generic way of picking any codec and forma factor name based
1558 * mixer and platform info files in future with no code change.
1559
1560 * current code extends and looks for any of the exteneded mixer path and
1561 * platform info file present based on codec and form factor.
1562
1563 * order of picking appropriate file is
1564 * <i> mixer_paths_<codec_name>_<form_factor>.xml, if file not present
1565 * <ii> mixer_paths_<codec_name>.xml, if file not present
1566 * <iii> mixer_paths.xml
1567
1568 * same order is followed for audio_platform_info.xml as well
1569 */
1570
1571 // need to carryforward old file name
1572 if (!strncmp(snd_card_name, TOMTOM_8226_SND_CARD_NAME,
1573 min(strlen(TOMTOM_8226_SND_CARD_NAME), strlen(snd_card_name)))) {
1574 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1575 MIXER_XML_BASE_STRING, TOMTOM_MIXER_FILE_SUFFIX );
1576 } else {
1577
1578 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s_%s.xml",
1579 MIXER_XML_BASE_STRING, snd_split_handle->snd_card,
1580 snd_split_handle->form_factor);
1581 if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) {
1582 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1583 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1584 MIXER_XML_BASE_STRING, snd_split_handle->snd_card);
1585
1586 if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) {
1587 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1588 strlcpy(mixer_xml_file, MIXER_XML_DEFAULT_PATH, MIXER_PATH_MAX_LENGTH);
1589 audio_extn_utils_resolve_config_file(mixer_xml_file);
1590 }
1591 }
1592 }
1593
1594 audio_extn_utils_get_platform_info(snd_card_name, platform_info_file);
1595
jiabin8962a4d2018-03-19 18:21:24 -07001596 my_data->declared_mic_count = 0;
vivek mehta0fb11312017-05-15 19:35:32 -07001597 /* Initialize platform specific ids and/or backends*/
1598 platform_info_init(platform_info_file, my_data);
1599
1600 ALOGD("%s: Loading mixer file: %s", __func__, mixer_xml_file);
1601 adev->audio_route = audio_route_init(snd_card_num, mixer_xml_file);
1602
1603 if (!adev->audio_route) {
1604 ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
1605 mixer_close(adev->mixer);
1606 adev->mixer = NULL;
1607 hw_info_deinit(my_data->hw_info);
1608 my_data->hw_info = NULL;
1609 goto init_failed;
1610 }
1611 adev->snd_card = snd_card_num;
1612 ALOGD("%s: Opened sound card:%d", __func__, snd_card_num);
1613
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09001614 //set max volume step for voice call
1615 property_get("ro.config.vc_call_vol_steps", value, TOSTRING(MAX_VOL_INDEX));
1616 my_data->max_vol_index = atoi(value);
1617
vivek mehta65ad12d2015-08-13 18:32:48 -07001618 property_get("persist.audio.dualmic.config",value,"");
1619 if (!strcmp("endfire", value)) {
1620 dual_mic_config = true;
1621 }
1622
John Muir9e59a962018-01-10 13:30:00 -08001623 my_data->source_mic_type = 0;
Prashant Malanic92c5962015-08-11 15:10:18 -07001624
Eric Laurentb23d5282013-05-14 15:27:20 -07001625 my_data->fluence_in_spkr_mode = false;
1626 my_data->fluence_in_voice_call = false;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001627 my_data->fluence_in_voice_comm = false;
Eric Laurentb23d5282013-05-14 15:27:20 -07001628 my_data->fluence_in_voice_rec = false;
1629
vivek mehta65ad12d2015-08-13 18:32:48 -07001630 property_get("ro.qc.sdk.audio.fluencetype", value, "none");
Prashant Malanic92c5962015-08-11 15:10:18 -07001631 if (!strcmp("fluencepro", value)) {
1632 my_data->fluence_type = FLUENCE_PRO_ENABLE;
vivek mehta65ad12d2015-08-13 18:32:48 -07001633 } else if (!strcmp("fluence", value) || (dual_mic_config)) {
Prashant Malanic92c5962015-08-11 15:10:18 -07001634 my_data->fluence_type = FLUENCE_ENABLE;
1635 } else if (!strcmp("none", value)) {
1636 my_data->fluence_type = FLUENCE_DISABLE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001637 }
1638
Prashant Malanic92c5962015-08-11 15:10:18 -07001639 if (my_data->fluence_type != FLUENCE_DISABLE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001640 property_get("persist.audio.fluence.voicecall",value,"");
1641 if (!strcmp("true", value)) {
1642 my_data->fluence_in_voice_call = true;
1643 }
1644
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001645 property_get("persist.audio.fluence.voicecomm",value,"");
1646 if (!strcmp("true", value)) {
1647 my_data->fluence_in_voice_comm = true;
1648 }
1649
Eric Laurentb23d5282013-05-14 15:27:20 -07001650 property_get("persist.audio.fluence.voicerec",value,"");
1651 if (!strcmp("true", value)) {
1652 my_data->fluence_in_voice_rec = true;
1653 }
1654
1655 property_get("persist.audio.fluence.speaker",value,"");
1656 if (!strcmp("true", value)) {
1657 my_data->fluence_in_spkr_mode = true;
1658 }
1659 }
1660
Prashant Malanic92c5962015-08-11 15:10:18 -07001661 // support max to mono, example if max count is 3, usecase supports Three, dual and mono mic
1662 switch (my_data->max_mic_count) {
1663 case 4:
1664 my_data->source_mic_type |= SOURCE_QUAD_MIC;
1665 case 3:
1666 my_data->source_mic_type |= SOURCE_THREE_MIC;
1667 case 2:
1668 my_data->source_mic_type |= SOURCE_DUAL_MIC;
1669 case 1:
1670 my_data->source_mic_type |= SOURCE_MONO_MIC;
1671 break;
1672 default:
1673 ALOGE("%s: max_mic_count (%d), is not supported, setting to default",
1674 __func__, my_data->max_mic_count);
1675 my_data->source_mic_type = SOURCE_MONO_MIC|SOURCE_DUAL_MIC;
1676 break;
1677 }
1678
1679 ALOGV("%s: Fluence_Type(%d) max_mic_count(%d) mic_type(0x%x) fluence_in_voice_call(%d)"
1680 " fluence_in_voice_comm(%d) fluence_in_voice_rec(%d) fluence_in_spkr_mode(%d) ",
1681 __func__, my_data->fluence_type, my_data->max_mic_count, my_data->source_mic_type,
1682 my_data->fluence_in_voice_call, my_data->fluence_in_voice_comm,
1683 my_data->fluence_in_voice_rec, my_data->fluence_in_spkr_mode);
1684
Eric Laurentb23d5282013-05-14 15:27:20 -07001685 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
1686 if (my_data->acdb_handle == NULL) {
1687 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
1688 } else {
1689 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
1690 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
1691 "acdb_loader_deallocate_ACDB");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001692 if (!my_data->acdb_deallocate)
1693 ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s",
1694 __func__, LIB_ACDB_LOADER);
1695
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001696 my_data->acdb_send_audio_cal_v3 = (acdb_send_audio_cal_v3_t)dlsym(my_data->acdb_handle,
1697 "acdb_loader_send_audio_cal_v3");
1698 if (!my_data->acdb_send_audio_cal_v3)
1699 ALOGE("%s: Could not find the symbol acdb_send_audio_cal_v3 from %s",
1700 __func__, LIB_ACDB_LOADER);
1701
Eric Laurentb23d5282013-05-14 15:27:20 -07001702 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
1703 "acdb_loader_send_audio_cal");
1704 if (!my_data->acdb_send_audio_cal)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001705 ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s",
Eric Laurentb23d5282013-05-14 15:27:20 -07001706 __func__, LIB_ACDB_LOADER);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001707
Eric Laurentb23d5282013-05-14 15:27:20 -07001708 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
1709 "acdb_loader_send_voice_cal");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001710 if (!my_data->acdb_send_voice_cal)
1711 ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s",
1712 __func__, LIB_ACDB_LOADER);
1713
1714 my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle,
1715 "acdb_loader_reload_vocvoltable");
1716 if (!my_data->acdb_reload_vocvoltable)
1717 ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s",
1718 __func__, LIB_ACDB_LOADER);
vivek mehta1a9b7c02015-06-25 11:49:38 -07001719
1720 my_data->acdb_send_gain_dep_cal = (acdb_send_gain_dep_cal_t)dlsym(my_data->acdb_handle,
1721 "acdb_loader_send_gain_dep_cal");
1722 if (!my_data->acdb_send_gain_dep_cal)
1723 ALOGV("%s: Could not find the symbol acdb_loader_send_gain_dep_cal from %s",
1724 __func__, LIB_ACDB_LOADER);
1725
Xu Han1638fd12018-04-20 12:42:23 -07001726#if defined (FLICKER_SENSOR_INPUT)
1727 configure_flicker_sensor_input(adev->mixer);
1728#endif
1729
Alexey Polyudove920d4b2017-09-15 17:09:07 -07001730#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845)
vivek mehta0fb11312017-05-15 19:35:32 -07001731 acdb_init_v2_cvd_t acdb_init_local;
1732 acdb_init_local = (acdb_init_v2_cvd_t)dlsym(my_data->acdb_handle,
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001733 "acdb_loader_init_v2");
vivek mehta0fb11312017-05-15 19:35:32 -07001734 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001735 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1736 dlerror());
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001737
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001738#elif defined (PLATFORM_MSM8084)
vivek mehta0fb11312017-05-15 19:35:32 -07001739 acdb_init_v2_t acdb_init_local;
1740 acdb_init_local = (acdb_init_v2_t)dlsym(my_data->acdb_handle,
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001741 "acdb_loader_init_v2");
vivek mehta0fb11312017-05-15 19:35:32 -07001742 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001743 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1744 dlerror());
1745
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001746#else
vivek mehta0fb11312017-05-15 19:35:32 -07001747 acdb_init_t acdb_init_local;
1748 acdb_init_local = (acdb_init_t)dlsym(my_data->acdb_handle,
Eric Laurentb23d5282013-05-14 15:27:20 -07001749 "acdb_loader_init_ACDB");
vivek mehta0fb11312017-05-15 19:35:32 -07001750 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001751 ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__,
1752 dlerror());
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001753#endif
vivek mehta0fb11312017-05-15 19:35:32 -07001754 my_data->acdb_init = acdb_init_local;
Eric Laurentb23d5282013-05-14 15:27:20 -07001755
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001756 my_data->acdb_send_custom_top = (acdb_send_custom_top_t)
1757 dlsym(my_data->acdb_handle,
1758 "acdb_loader_send_common_custom_topology");
1759
1760 if (!my_data->acdb_send_custom_top)
1761 ALOGE("%s: Could not find the symbol acdb_get_default_app_type from %s",
1762 __func__, LIB_ACDB_LOADER);
1763
jasmine chac89321b2018-04-10 21:37:01 +08001764 my_data->acdb_set_audio_cal = (acdb_set_audio_cal_t)dlsym(my_data->acdb_handle,
1765 "acdb_loader_set_audio_cal_v2");
1766 if (!my_data->acdb_set_audio_cal)
1767 ALOGE("%s: Could not find the symbol acdb_set_audio_cal_v2 from %s",
1768 __func__, LIB_ACDB_LOADER);
1769
vivek mehta0fb11312017-05-15 19:35:32 -07001770 int result = acdb_init(adev->snd_card);
1771 if (!result) {
1772 my_data->acdb_initialized = true;
1773 ALOGD("ACDB initialized");
1774 } else {
1775 my_data->acdb_initialized = false;
1776 ALOGD("ACDB initialization failed");
1777 }
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001778 }
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001779
David Linee3fe402017-03-13 10:00:42 -07001780 /* init usb */
1781 audio_extn_usb_init(adev);
1782
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001783 /* init a2dp */
1784 audio_extn_a2dp_init(adev);
1785
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001786 audio_extn_spkr_prot_init(adev);
Haynes Mathew George98c95622014-06-20 19:14:25 -07001787
Ravi Kumar Alamanda76315572015-04-23 13:13:56 -07001788 audio_extn_hwdep_cal_send(adev->snd_card, my_data->acdb_handle);
1789
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001790 /* load csd client */
1791 platform_csd_init(my_data);
1792
David Linee3fe402017-03-13 10:00:42 -07001793 platform_backend_config_init(my_data);
1794
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001795 init_be_dai_name_table(adev);
1796
1797 if (platform_supports_app_type_cfg())
1798 platform_backend_app_type_cfg_init(my_data, adev->mixer);
1799
Eric Laurentb23d5282013-05-14 15:27:20 -07001800 return my_data;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001801
1802init_failed:
1803 if (my_data)
1804 free(my_data);
1805 return NULL;
Eric Laurentb23d5282013-05-14 15:27:20 -07001806}
1807
1808void platform_deinit(void *platform)
1809{
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001810 int32_t dev;
keunhui.park2f7306a2015-07-16 16:48:06 +09001811 struct operator_info *info_item;
1812 struct operator_specific_device *device_item;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001813 struct app_type_entry *ap;
keunhui.park2f7306a2015-07-16 16:48:06 +09001814 struct listnode *node;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001815
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001816 struct platform_data *my_data = (struct platform_data *)platform;
1817 close_csd_client(my_data->csd);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001818
vivek mehtade4849c2016-03-03 17:23:38 -08001819 hw_info_deinit(my_data->hw_info);
1820
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001821 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1822 if (backend_tag_table[dev])
1823 free(backend_tag_table[dev]);
1824 if (hw_interface_table[dev])
1825 free(hw_interface_table[dev]);
keunhui.park2f7306a2015-07-16 16:48:06 +09001826 if (operator_specific_device_table[dev]) {
1827 while (!list_empty(operator_specific_device_table[dev])) {
1828 node = list_head(operator_specific_device_table[dev]);
1829 list_remove(node);
1830 device_item = node_to_item(node, struct operator_specific_device, list);
1831 free(device_item->operator);
1832 free(device_item->mixer_path);
1833 free(device_item);
1834 }
1835 free(operator_specific_device_table[dev]);
1836 }
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001837 }
1838
1839 if (my_data->snd_card_name)
1840 free(my_data->snd_card_name);
1841
keunhui.park2f7306a2015-07-16 16:48:06 +09001842 while (!list_empty(&operator_info_list)) {
1843 node = list_head(&operator_info_list);
1844 list_remove(node);
1845 info_item = node_to_item(node, struct operator_info, list);
1846 free(info_item->name);
1847 free(info_item->mccmnc);
1848 free(info_item);
1849 }
1850
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001851 while (!list_empty(&app_type_entry_list)) {
1852 node = list_head(&app_type_entry_list);
1853 list_remove(node);
1854 ap = node_to_item(node, struct app_type_entry, node);
vivek mehtaa68fea62017-06-08 19:04:02 -07001855 if (ap->mode) free(ap->mode);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001856 free(ap);
1857 }
1858
Kevin Rocarde35d4af2017-05-02 16:55:28 -07001859 mixer_close(my_data->adev->mixer);
Eric Laurentb23d5282013-05-14 15:27:20 -07001860 free(platform);
David Linee3fe402017-03-13 10:00:42 -07001861
1862 /* deinit usb */
1863 audio_extn_usb_deinit();
Eric Laurentb23d5282013-05-14 15:27:20 -07001864}
1865
1866const char *platform_get_snd_device_name(snd_device_t snd_device)
1867{
keunhui.park2f7306a2015-07-16 16:48:06 +09001868 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1869 if (operator_specific_device_table[snd_device] != NULL) {
1870 return get_operator_specific_device_mixer_path(snd_device);
1871 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001872 return device_table[snd_device];
keunhui.park2f7306a2015-07-16 16:48:06 +09001873 } else
Ravi Kumar Alamanda64026462014-09-15 00:08:58 -07001874 return "none";
Eric Laurentb23d5282013-05-14 15:27:20 -07001875}
1876
vivek mehtade4849c2016-03-03 17:23:38 -08001877int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
1878 char *device_name)
1879{
1880 struct platform_data *my_data = (struct platform_data *)platform;
1881
David Benjamin1565f992016-09-21 12:10:34 -04001882 if (platform == NULL) {
vivek mehtade4849c2016-03-03 17:23:38 -08001883 ALOGW("%s: something wrong, use legacy get_snd_device name", __func__);
David Benjamin1565f992016-09-21 12:10:34 -04001884 strlcpy(device_name, platform_get_snd_device_name(snd_device),
1885 DEVICE_NAME_MAX_SIZE);
vivek mehtade4849c2016-03-03 17:23:38 -08001886 } else if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1887 if (operator_specific_device_table[snd_device] != NULL) {
1888 strlcpy(device_name, get_operator_specific_device_mixer_path(snd_device),
1889 DEVICE_NAME_MAX_SIZE);
1890 } else {
1891 strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE);
1892 }
1893 hw_info_append_hw_type(my_data->hw_info, snd_device, device_name);
1894 } else {
1895 strlcpy(device_name, "none", DEVICE_NAME_MAX_SIZE);
1896 }
1897
1898 return 0;
1899}
1900
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001901void platform_add_backend_name(void *platform, char *mixer_path,
1902 snd_device_t snd_device)
Eric Laurentb23d5282013-05-14 15:27:20 -07001903{
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001904 struct platform_data *my_data = (struct platform_data *)platform;
1905
Haynes Mathew George98c95622014-06-20 19:14:25 -07001906 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1907 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1908 return;
Ravi Kumar Alamanda1de6e5a2014-06-19 21:55:39 -05001909 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001910
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001911 const char * suffix = backend_tag_table[snd_device];
Haynes Mathew George98c95622014-06-20 19:14:25 -07001912
1913 if (suffix != NULL) {
1914 strcat(mixer_path, " ");
1915 strcat(mixer_path, suffix);
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001916 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001917}
1918
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001919bool platform_check_backends_match(snd_device_t snd_device1, snd_device_t snd_device2)
1920{
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001921 ALOGV("%s: snd_device1 = %s, snd_device2 = %s", __func__,
1922 platform_get_snd_device_name(snd_device1),
1923 platform_get_snd_device_name(snd_device2));
1924
1925 if ((snd_device1 < SND_DEVICE_MIN) || (snd_device1 >= SND_DEVICE_MAX)) {
1926 ALOGE("%s: Invalid snd_device = %s", __func__,
1927 platform_get_snd_device_name(snd_device1));
1928 return false;
1929 }
1930 if ((snd_device2 < SND_DEVICE_MIN) || (snd_device2 >= SND_DEVICE_MAX)) {
1931 ALOGE("%s: Invalid snd_device = %s", __func__,
1932 platform_get_snd_device_name(snd_device2));
1933 return false;
1934 }
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07001935
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001936 const char * be_itf1 = hw_interface_table[snd_device1];
1937 const char * be_itf2 = hw_interface_table[snd_device2];
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07001938 /*
1939 hw_interface_table has overrides for a snd_device.
1940 if there is no entry for a device, assume DEFAULT_RX_BACKEND
1941 */
1942 if (be_itf1 == NULL) {
1943 be_itf1 = DEFAULT_RX_BACKEND;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001944 }
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07001945 if (be_itf2 == NULL) {
1946 be_itf2 = DEFAULT_RX_BACKEND;
1947 }
1948 ALOGV("%s: be_itf1 = %s, be_itf2 = %s", __func__, be_itf1, be_itf2);
1949 /*
1950 this takes care of finding a device within a combo device pair as well
1951 */
1952 return strstr(be_itf1, be_itf2) != NULL || strstr(be_itf2, be_itf1) != NULL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001953}
1954
Eric Laurentb23d5282013-05-14 15:27:20 -07001955int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
1956{
1957 int device_id;
1958 if (device_type == PCM_PLAYBACK)
1959 device_id = pcm_device_table[usecase][0];
1960 else
1961 device_id = pcm_device_table[usecase][1];
1962 return device_id;
1963}
1964
Haynes Mathew George98c95622014-06-20 19:14:25 -07001965static int find_index(const struct name_to_index * table, int32_t len,
1966 const char * name)
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001967{
1968 int ret = 0;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001969 int32_t i;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001970
Haynes Mathew George98c95622014-06-20 19:14:25 -07001971 if (table == NULL) {
1972 ALOGE("%s: table is NULL", __func__);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001973 ret = -ENODEV;
1974 goto done;
1975 }
1976
Haynes Mathew George98c95622014-06-20 19:14:25 -07001977 if (name == NULL) {
1978 ALOGE("null key");
1979 ret = -ENODEV;
1980 goto done;
1981 }
1982
1983 for (i=0; i < len; i++) {
1984 if (!strcmp(table[i].name, name)) {
1985 ret = table[i].index;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001986 goto done;
1987 }
1988 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001989 ALOGE("%s: Could not find index for name = %s",
1990 __func__, name);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001991 ret = -ENODEV;
1992done:
1993 return ret;
1994}
1995
Haynes Mathew George98c95622014-06-20 19:14:25 -07001996int platform_get_snd_device_index(char *device_name)
1997{
1998 return find_index(snd_device_name_index, SND_DEVICE_MAX, device_name);
1999}
2000
2001int platform_get_usecase_index(const char *usecase_name)
2002{
2003 return find_index(usecase_name_index, AUDIO_USECASE_MAX, usecase_name);
2004}
2005
keunhui.park2f7306a2015-07-16 16:48:06 +09002006void platform_add_operator_specific_device(snd_device_t snd_device,
2007 const char *operator,
2008 const char *mixer_path,
2009 unsigned int acdb_id)
2010{
2011 struct operator_specific_device *device;
2012
2013 if (operator_specific_device_table[snd_device] == NULL) {
2014 operator_specific_device_table[snd_device] =
2015 (struct listnode *)calloc(1, sizeof(struct listnode));
2016 list_init(operator_specific_device_table[snd_device]);
2017 }
2018
2019 device = (struct operator_specific_device *)calloc(1, sizeof(struct operator_specific_device));
2020
2021 device->operator = strdup(operator);
2022 device->mixer_path = strdup(mixer_path);
2023 device->acdb_id = acdb_id;
2024
2025 list_add_tail(operator_specific_device_table[snd_device], &device->list);
2026
Eric Laurent2bafff12016-03-17 12:17:23 -07002027 ALOGD("%s: device[%s] -> operator[%s] mixer_path[%s] acdb_id[%d]", __func__,
keunhui.park2f7306a2015-07-16 16:48:06 +09002028 platform_get_snd_device_name(snd_device), operator, mixer_path, acdb_id);
2029
2030}
2031
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002032int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
2033{
2034 int ret = 0;
2035
2036 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
2037 ALOGE("%s: Invalid snd_device = %d",
2038 __func__, snd_device);
2039 ret = -EINVAL;
2040 goto done;
2041 }
2042
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002043 ALOGV("%s: acdb_device_table[%s]: old = %d new = %d", __func__,
2044 platform_get_snd_device_name(snd_device), acdb_device_table[snd_device], acdb_id);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002045 acdb_device_table[snd_device] = acdb_id;
2046done:
2047 return ret;
2048}
2049
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07002050int platform_get_snd_device_acdb_id(snd_device_t snd_device)
2051{
2052 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
2053 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
2054 return -EINVAL;
2055 }
keunhui.park2f7306a2015-07-16 16:48:06 +09002056
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002057 /*
2058 * If speaker protection is enabled, function returns supported
2059 * sound device for speaker. Else same sound device is returned.
2060 */
2061 snd_device = audio_extn_get_spkr_prot_snd_device(snd_device);
2062
keunhui.park2f7306a2015-07-16 16:48:06 +09002063 if (operator_specific_device_table[snd_device] != NULL)
2064 return get_operator_specific_device_acdb_id(snd_device);
2065 else
2066 return acdb_device_table[snd_device];
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07002067}
2068
David Linee3fe402017-03-13 10:00:42 -07002069static int platform_get_backend_index(snd_device_t snd_device)
2070{
2071 int32_t port = DEFAULT_CODEC_BACKEND;
2072
2073 if (snd_device >= SND_DEVICE_OUT_BEGIN && snd_device < SND_DEVICE_OUT_END) {
2074 if (backend_tag_table[snd_device] != NULL) {
2075 if (strncmp(backend_tag_table[snd_device], "headphones",
2076 sizeof("headphones")) == 0)
2077 port = HEADPHONE_BACKEND;
2078 else if (strcmp(backend_tag_table[snd_device], "hdmi") == 0)
2079 port = HDMI_RX_BACKEND;
2080 else if ((strcmp(backend_tag_table[snd_device], "usb-headphones") == 0) ||
2081 (strcmp(backend_tag_table[snd_device], "usb-headset") == 0))
2082 port = USB_AUDIO_RX_BACKEND;
2083 }
2084 } else if (snd_device >= SND_DEVICE_IN_BEGIN && snd_device < SND_DEVICE_IN_END) {
2085 port = DEFAULT_CODEC_TX_BACKEND;
2086 if (backend_tag_table[snd_device] != NULL) {
2087 if (strcmp(backend_tag_table[snd_device], "usb-headset-mic") == 0)
2088 port = USB_AUDIO_TX_BACKEND;
2089 else if (strstr(backend_tag_table[snd_device], "bt-sco") != NULL)
2090 port = BT_SCO_TX_BACKEND;
2091 }
2092 } else {
2093 ALOGW("%s:napb: Invalid device - %d ", __func__, snd_device);
2094 }
2095
2096 ALOGV("%s:napb: backend port - %d device - %d ", __func__, port, snd_device);
2097
2098 return port;
2099}
2100
Eric Laurentb23d5282013-05-14 15:27:20 -07002101int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
2102{
2103 struct platform_data *my_data = (struct platform_data *)platform;
2104 int acdb_dev_id, acdb_dev_type;
2105
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002106 if (platform_supports_app_type_cfg()) // use v2 instead
2107 return -ENOSYS;
2108
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002109 acdb_dev_id = platform_get_snd_device_acdb_id(snd_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07002110 if (acdb_dev_id < 0) {
2111 ALOGE("%s: Could not find acdb id for device(%d)",
2112 __func__, snd_device);
2113 return -EINVAL;
2114 }
2115 if (my_data->acdb_send_audio_cal) {
Joe Onorato188b6222016-03-01 11:02:27 -08002116 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Eric Laurentb23d5282013-05-14 15:27:20 -07002117 __func__, snd_device, acdb_dev_id);
2118 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
2119 snd_device < SND_DEVICE_OUT_END)
2120 acdb_dev_type = ACDB_DEV_TYPE_OUT;
2121 else
2122 acdb_dev_type = ACDB_DEV_TYPE_IN;
2123 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
2124 }
2125 return 0;
2126}
2127
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002128int platform_send_audio_calibration_v2(void *platform, struct audio_usecase *usecase,
2129 int app_type, int sample_rate)
2130{
2131 struct platform_data *my_data = (struct platform_data *)platform;
2132 int acdb_dev_id, acdb_dev_type;
vivek mehta7e573672018-03-13 17:41:41 -07002133 int snd_device = usecase->out_snd_device;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002134 int new_snd_device[SND_DEVICE_OUT_END] = {0};
2135 int i, num_devices = 1;
2136
2137 if (!platform_supports_app_type_cfg()) // use v1 instead
2138 return -ENOSYS;
2139
vivek mehta7e573672018-03-13 17:41:41 -07002140 if ((usecase->type == PCM_HFP_CALL) || (usecase->type == PCM_CAPTURE))
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002141 snd_device = usecase->in_snd_device;
2142
2143 // skipped over get_spkr_prot_device
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002144 acdb_dev_id = platform_get_snd_device_acdb_id(snd_device);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002145 if (acdb_dev_id < 0) {
2146 ALOGE("%s: Could not find acdb id for device(%d)",
2147 __func__, snd_device);
2148 return -EINVAL;
2149 }
2150
2151 if (platform_can_split_snd_device(snd_device,
2152 &num_devices, new_snd_device) < 0) {
2153 new_snd_device[0] = snd_device;
2154 }
2155
2156 for (i = 0; i < num_devices; i++) {
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002157 acdb_dev_id = platform_get_snd_device_acdb_id(new_snd_device[i]);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002158 if (acdb_dev_id < 0) {
2159 ALOGE("%s: Could not find acdb id for device(%d)",
2160 __func__, new_snd_device[i]);
2161 return -EINVAL;
2162 }
2163 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
2164 __func__, new_snd_device[i], acdb_dev_id);
2165 if (new_snd_device[i] >= SND_DEVICE_OUT_BEGIN &&
2166 new_snd_device[i] < SND_DEVICE_OUT_END)
2167 acdb_dev_type = ACDB_DEV_TYPE_OUT;
2168 else
2169 acdb_dev_type = ACDB_DEV_TYPE_IN;
2170
2171 if (my_data->acdb_send_audio_cal_v3) {
2172 my_data->acdb_send_audio_cal_v3(acdb_dev_id, acdb_dev_type,
2173 app_type, sample_rate, i);
2174 } else if (my_data->acdb_send_audio_cal) {
2175 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type); // this version differs from internal
2176 }
2177 }
2178
2179 return 0;
2180}
2181
2182
Eric Laurentb23d5282013-05-14 15:27:20 -07002183int platform_switch_voice_call_device_pre(void *platform)
2184{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002185 struct platform_data *my_data = (struct platform_data *)platform;
2186 int ret = 0;
2187
2188 if (my_data->csd != NULL &&
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002189 voice_is_in_call(my_data->adev)) {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002190 /* This must be called before disabling mixer controls on APQ side */
2191 ret = my_data->csd->disable_device();
2192 if (ret < 0) {
2193 ALOGE("%s: csd_client_disable_device, failed, error %d",
2194 __func__, ret);
2195 }
2196 }
2197 return ret;
2198}
2199
2200int platform_switch_voice_call_enable_device_config(void *platform,
2201 snd_device_t out_snd_device,
2202 snd_device_t in_snd_device)
2203{
2204 struct platform_data *my_data = (struct platform_data *)platform;
2205 int acdb_rx_id, acdb_tx_id;
2206 int ret = 0;
2207
2208 if (my_data->csd == NULL)
2209 return ret;
2210
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002211 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
keunhui.park2f7306a2015-07-16 16:48:06 +09002212 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002213
2214 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
2215 ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
2216 if (ret < 0) {
2217 ALOGE("%s: csd_enable_device_config, failed, error %d",
2218 __func__, ret);
2219 }
2220 } else {
2221 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2222 acdb_rx_id, acdb_tx_id);
2223 }
2224
2225 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002226}
2227
2228int platform_switch_voice_call_device_post(void *platform,
2229 snd_device_t out_snd_device,
2230 snd_device_t in_snd_device)
2231{
2232 struct platform_data *my_data = (struct platform_data *)platform;
2233 int acdb_rx_id, acdb_tx_id;
2234
2235 if (my_data->acdb_send_voice_cal == NULL) {
2236 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
2237 } else {
keunhui.park2f7306a2015-07-16 16:48:06 +09002238 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
2239 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07002240
2241 if (acdb_rx_id > 0 && acdb_tx_id > 0)
2242 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
2243 else
2244 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2245 acdb_rx_id, acdb_tx_id);
2246 }
2247
2248 return 0;
2249}
2250
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002251int platform_switch_voice_call_usecase_route_post(void *platform,
2252 snd_device_t out_snd_device,
2253 snd_device_t in_snd_device)
2254{
2255 struct platform_data *my_data = (struct platform_data *)platform;
2256 int acdb_rx_id, acdb_tx_id;
2257 int ret = 0;
2258
2259 if (my_data->csd == NULL)
2260 return ret;
2261
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002262 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
keunhui.park2f7306a2015-07-16 16:48:06 +09002263 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002264
2265 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
2266 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
2267 my_data->adev->acdb_settings);
2268 if (ret < 0) {
2269 ALOGE("%s: csd_enable_device, failed, error %d", __func__, ret);
2270 }
2271 } else {
2272 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2273 acdb_rx_id, acdb_tx_id);
2274 }
2275
2276 return ret;
2277}
2278
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002279int platform_start_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07002280{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002281 struct platform_data *my_data = (struct platform_data *)platform;
2282 int ret = 0;
2283
2284 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002285 ret = my_data->csd->start_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002286 if (ret < 0) {
2287 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
2288 }
2289 }
2290 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002291}
2292
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002293int platform_stop_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07002294{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002295 struct platform_data *my_data = (struct platform_data *)platform;
2296 int ret = 0;
2297
2298 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002299 ret = my_data->csd->stop_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002300 if (ret < 0) {
2301 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
2302 }
2303 }
2304 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002305}
2306
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002307int platform_get_sample_rate(void *platform, uint32_t *rate)
2308{
2309 struct platform_data *my_data = (struct platform_data *)platform;
2310 int ret = 0;
2311
2312 if (my_data->csd != NULL) {
2313 ret = my_data->csd->get_sample_rate(rate);
2314 if (ret < 0) {
2315 ALOGE("%s: csd_get_sample_rate error %d\n", __func__, ret);
2316 }
2317 }
2318 return ret;
2319}
2320
vivek mehtab6506412015-08-07 16:55:17 -07002321void platform_set_speaker_gain_in_combo(struct audio_device *adev,
2322 snd_device_t snd_device,
2323 bool enable)
2324{
2325 const char* name;
2326 switch (snd_device) {
2327 case SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES:
2328 if (enable)
2329 name = "spkr-gain-in-headphone-combo";
2330 else
2331 name = "speaker-gain-default";
2332 break;
2333 case SND_DEVICE_OUT_SPEAKER_AND_LINE:
2334 if (enable)
2335 name = "spkr-gain-in-line-combo";
2336 else
2337 name = "speaker-gain-default";
2338 break;
2339 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES:
2340 if (enable)
2341 name = "spkr-safe-gain-in-headphone-combo";
2342 else
2343 name = "speaker-safe-gain-default";
2344 break;
2345 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE:
2346 if (enable)
2347 name = "spkr-safe-gain-in-line-combo";
2348 else
2349 name = "speaker-safe-gain-default";
2350 break;
2351 default:
2352 return;
2353 }
2354
2355 audio_route_apply_and_update_path(adev->audio_route, name);
2356}
2357
Eric Laurentb23d5282013-05-14 15:27:20 -07002358int platform_set_voice_volume(void *platform, int volume)
2359{
2360 struct platform_data *my_data = (struct platform_data *)platform;
2361 struct audio_device *adev = my_data->adev;
2362 struct mixer_ctl *ctl;
sangwoo53b2cf02013-07-25 19:18:44 -07002363 const char *mixer_ctl_name = "Voice Rx Gain";
Nadav Barc46d0fa2017-12-24 14:50:37 +02002364 const char *mute_mixer_ctl_name = "Voice Rx Device Mute";
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002365 int vol_index = 0, ret = 0;
2366 uint32_t set_values[ ] = {0,
2367 ALL_SESSION_VSID,
2368 DEFAULT_VOLUME_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07002369
2370 // Voice volume levels are mapped to adsp volume levels as follows.
2371 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
2372 // But this values don't changed in kernel. So, below change is need.
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09002373 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, my_data->max_vol_index);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002374 set_values[0] = vol_index;
Eric Laurentb23d5282013-05-14 15:27:20 -07002375
2376 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2377 if (!ctl) {
2378 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2379 __func__, mixer_ctl_name);
2380 return -EINVAL;
2381 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002382 ALOGV("Setting voice volume index: %d", set_values[0]);
2383 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2384
Nadav Barc46d0fa2017-12-24 14:50:37 +02002385 // Send mute command in case volume index is max since indexes are inverted
2386 // for mixer controls.
2387 if (vol_index == my_data->max_vol_index) {
2388 set_values[0] = 1;
2389 }
2390 else {
2391 set_values[0] = 0;
2392 }
2393
2394 ctl = mixer_get_ctl_by_name(adev->mixer, mute_mixer_ctl_name);
2395 if (!ctl) {
2396 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2397 __func__, mute_mixer_ctl_name);
2398 return -EINVAL;
2399 }
2400 ALOGV("%s: Setting RX Device Mute to: %d", __func__, set_values[0]);
2401 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2402
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002403 if (my_data->csd != NULL) {
2404 ret = my_data->csd->volume(ALL_SESSION_VSID, volume,
2405 DEFAULT_VOLUME_RAMP_DURATION_MS);
2406 if (ret < 0) {
2407 ALOGE("%s: csd_volume error %d", __func__, ret);
2408 }
2409 }
2410 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002411}
2412
2413int platform_set_mic_mute(void *platform, bool state)
2414{
2415 struct platform_data *my_data = (struct platform_data *)platform;
2416 struct audio_device *adev = my_data->adev;
2417 struct mixer_ctl *ctl;
2418 const char *mixer_ctl_name = "Voice Tx Mute";
sangwoo53b2cf02013-07-25 19:18:44 -07002419 int ret = 0;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002420 uint32_t set_values[ ] = {0,
2421 ALL_SESSION_VSID,
2422 DEFAULT_MUTE_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07002423
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09002424 if (adev->mode != AUDIO_MODE_IN_CALL &&
2425 adev->mode != AUDIO_MODE_IN_COMMUNICATION)
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002426 return 0;
2427
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09002428 if (adev->enable_hfp)
2429 mixer_ctl_name = "HFP Tx Mute";
2430
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002431 set_values[0] = state;
2432 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2433 if (!ctl) {
2434 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2435 __func__, mixer_ctl_name);
2436 return -EINVAL;
2437 }
2438 ALOGV("Setting voice mute state: %d", state);
2439 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2440
2441 if (my_data->csd != NULL) {
2442 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state,
2443 DEFAULT_MUTE_RAMP_DURATION_MS);
sangwoo53b2cf02013-07-25 19:18:44 -07002444 if (ret < 0) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002445 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
sangwoo53b2cf02013-07-25 19:18:44 -07002446 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002447 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002448 return ret;
2449}
Eric Laurentb23d5282013-05-14 15:27:20 -07002450
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002451int platform_set_device_mute(void *platform, bool state, char *dir)
2452{
2453 struct platform_data *my_data = (struct platform_data *)platform;
2454 struct audio_device *adev = my_data->adev;
2455 struct mixer_ctl *ctl;
2456 char *mixer_ctl_name = NULL;
2457 int ret = 0;
2458 uint32_t set_values[ ] = {0,
2459 ALL_SESSION_VSID,
2460 0};
2461 if(dir == NULL) {
2462 ALOGE("%s: Invalid direction:%s", __func__, dir);
2463 return -EINVAL;
2464 }
2465
2466 if (!strncmp("rx", dir, sizeof("rx"))) {
2467 mixer_ctl_name = "Voice Rx Device Mute";
2468 } else if (!strncmp("tx", dir, sizeof("tx"))) {
2469 mixer_ctl_name = "Voice Tx Device Mute";
2470 } else {
2471 return -EINVAL;
2472 }
2473
2474 set_values[0] = state;
2475 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2476 if (!ctl) {
2477 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2478 __func__, mixer_ctl_name);
2479 return -EINVAL;
2480 }
2481
2482 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
2483 __func__,state, mixer_ctl_name);
2484 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2485
2486 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002487}
2488
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002489int platform_can_split_snd_device(snd_device_t snd_device,
2490 int *num_devices,
2491 snd_device_t *new_snd_devices)
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002492{
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002493 int ret = -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002494 if (NULL == num_devices || NULL == new_snd_devices) {
2495 ALOGE("%s: NULL pointer ..", __func__);
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002496 return -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002497 }
2498
2499 /*
2500 * If wired headset/headphones/line devices share the same backend
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002501 * with speaker/earpiece this routine returns -EINVAL.
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002502 */
2503 if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES &&
2504 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_HEADPHONES)) {
2505 *num_devices = 2;
2506 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2507 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002508 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002509 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_LINE &&
2510 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_LINE)) {
2511 *num_devices = 2;
2512 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2513 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002514 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002515 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES &&
2516 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_HEADPHONES)) {
2517 *num_devices = 2;
2518 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2519 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002520 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002521 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE &&
2522 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_LINE)) {
2523 *num_devices = 2;
2524 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2525 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002526 ret = 0;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002527 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO &&
2528 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2529 SND_DEVICE_OUT_BT_SCO)) {
2530 *num_devices = 2;
2531 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2532 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO;
2533 ret = 0;
2534 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB &&
2535 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2536 SND_DEVICE_OUT_BT_SCO_WB)) {
2537 *num_devices = 2;
2538 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2539 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO_WB;
2540 ret = 0;
David Linee3fe402017-03-13 10:00:42 -07002541 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET &&
2542 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_USB_HEADSET)) {
2543 *num_devices = 2;
2544 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2545 new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
2546 ret = 0;
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07002547 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET &&
2548 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_USB_HEADSET)) {
2549 *num_devices = 2;
2550 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2551 new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
2552 ret = 0;
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002553 } else if (SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP == snd_device &&
2554 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2555 SND_DEVICE_OUT_BT_A2DP)) {
2556 *num_devices = 2;
2557 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2558 new_snd_devices[1] = SND_DEVICE_OUT_BT_A2DP;
2559 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002560 }
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002561
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002562 return ret;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002563}
2564
Eric Laurentb23d5282013-05-14 15:27:20 -07002565snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
2566{
2567 struct platform_data *my_data = (struct platform_data *)platform;
2568 struct audio_device *adev = my_data->adev;
2569 audio_mode_t mode = adev->mode;
2570 snd_device_t snd_device = SND_DEVICE_NONE;
2571
2572 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
2573 if (devices == AUDIO_DEVICE_NONE ||
2574 devices & AUDIO_DEVICE_BIT_IN) {
2575 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
2576 goto exit;
2577 }
2578
Eric Laurent1b491552015-09-15 17:52:41 -07002579 if (popcount(devices) == 2) {
2580 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2581 AUDIO_DEVICE_OUT_SPEAKER) ||
2582 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2583 AUDIO_DEVICE_OUT_SPEAKER)) {
2584 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
2585 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2586 AUDIO_DEVICE_OUT_SPEAKER)) {
2587 snd_device = SND_DEVICE_OUT_SPEAKER_AND_LINE;
2588 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2589 AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
2590 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2591 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2592 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES;
2593 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2594 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2595 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE;
2596 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
2597 AUDIO_DEVICE_OUT_SPEAKER)) {
2598 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002599 } else if ((devices & AUDIO_DEVICE_OUT_ALL_SCO) &&
2600 ((devices & ~AUDIO_DEVICE_OUT_ALL_SCO) == AUDIO_DEVICE_OUT_SPEAKER)) {
2601 snd_device = adev->bt_wb_speech_enabled ?
2602 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB :
2603 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO;
Eric Laurent99dab492017-06-17 15:19:08 -07002604 } else if ((devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
2605 AUDIO_DEVICE_OUT_SPEAKER)) ||
2606 (devices == (AUDIO_DEVICE_OUT_USB_HEADSET |
2607 AUDIO_DEVICE_OUT_SPEAKER))) {
David Linee3fe402017-03-13 10:00:42 -07002608 snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET;
Eric Laurentd0f7c262017-07-05 09:09:12 -07002609 } else if ((devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
2610 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) ||
2611 (devices == (AUDIO_DEVICE_OUT_USB_HEADSET |
2612 AUDIO_DEVICE_OUT_SPEAKER_SAFE))) {
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07002613 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET;
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002614 } else if ((devices & AUDIO_DEVICE_OUT_SPEAKER) &&
2615 (devices & AUDIO_DEVICE_OUT_ALL_A2DP)) {
2616 snd_device = SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP;
Eric Laurent1b491552015-09-15 17:52:41 -07002617 } else {
2618 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
2619 goto exit;
2620 }
2621 if (snd_device != SND_DEVICE_NONE) {
2622 goto exit;
2623 }
2624 }
2625
2626 if (popcount(devices) != 1) {
2627 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
2628 goto exit;
2629 }
2630
Madhuri Athota3f6051b2016-10-13 23:25:38 +05302631 if (voice_is_in_call(adev) || adev->enable_voicerx || audio_extn_hfp_is_active(adev)) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002632 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002633 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2634 devices & AUDIO_DEVICE_OUT_LINE) {
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002635 if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002636 (adev->voice.tty_mode == TTY_MODE_FULL))
Eric Laurentb23d5282013-05-14 15:27:20 -07002637 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002638 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002639 (adev->voice.tty_mode == TTY_MODE_VCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002640 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002641 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002642 (adev->voice.tty_mode == TTY_MODE_HCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002643 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002644 else {
2645 if (devices & AUDIO_DEVICE_OUT_LINE)
2646 snd_device = SND_DEVICE_OUT_VOICE_LINE;
2647 else
2648 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
2649 }
Eric Laurent99dab492017-06-17 15:19:08 -07002650 } else if (audio_is_usb_out_device(devices)) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002651 if (voice_is_in_call(adev)) {
2652 switch (adev->voice.tty_mode) {
2653 case TTY_MODE_FULL:
2654 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_USB;
2655 break;
2656 case TTY_MODE_VCO:
2657 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_USB;
2658 break;
2659 case TTY_MODE_HCO:
2660 // since Hearing will be on handset\speaker, use existing device
2661 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
2662 break;
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002663 case TTY_MODE_OFF:
2664 break;
vivek mehtaa6b79742017-03-09 15:40:43 -08002665 default:
2666 ALOGE("%s: Invalid TTY mode (%#x)",
2667 __func__, adev->voice.tty_mode);
2668 }
2669 }
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002670 if (snd_device == SND_DEVICE_NONE) {
2671 snd_device = audio_extn_usb_is_capture_supported() ?
2672 SND_DEVICE_OUT_VOICE_USB_HEADSET :
2673 SND_DEVICE_OUT_VOICE_USB_HEADPHONES;
2674 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002675 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002676 if (adev->bt_wb_speech_enabled) {
2677 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2678 } else {
2679 snd_device = SND_DEVICE_OUT_BT_SCO;
2680 }
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002681 } else if (devices & AUDIO_DEVICE_OUT_ALL_A2DP) {
2682 snd_device = SND_DEVICE_OUT_BT_A2DP;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002683 } else if (devices & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002684 if (!adev->enable_hfp) {
2685 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
2686 } else {
2687 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_HFP;
2688 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002689 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002690 if(adev->voice.hac)
2691 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2692 else if (is_operator_tmus())
Eric Laurentb23d5282013-05-14 15:27:20 -07002693 snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS;
2694 else
Eric Laurentb4d368e2014-06-25 10:21:54 -05002695 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002696 } else if (devices & AUDIO_DEVICE_OUT_TELEPHONY_TX)
2697 snd_device = SND_DEVICE_OUT_VOICE_TX;
2698
Eric Laurentb23d5282013-05-14 15:27:20 -07002699 if (snd_device != SND_DEVICE_NONE) {
2700 goto exit;
2701 }
2702 }
2703
Eric Laurentb23d5282013-05-14 15:27:20 -07002704 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2705 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2706 snd_device = SND_DEVICE_OUT_HEADPHONES;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002707 } else if (devices & AUDIO_DEVICE_OUT_LINE) {
2708 snd_device = SND_DEVICE_OUT_LINE;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002709 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) {
2710 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE;
Eric Laurentb23d5282013-05-14 15:27:20 -07002711 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
andysu5b30b062018-04-20 16:34:06 +08002712 /*
2713 * Perform device switch only if acdb tuning is different between SPEAKER & SPEAKER_REVERSE,
2714 * Or there will be a small pause while performing device switch.
2715 */
2716 if (my_data->speaker_lr_swap &&
2717 (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
2718 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]))
Eric Laurentb23d5282013-05-14 15:27:20 -07002719 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
2720 else
2721 snd_device = SND_DEVICE_OUT_SPEAKER;
2722 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002723 if (adev->bt_wb_speech_enabled) {
2724 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2725 } else {
2726 snd_device = SND_DEVICE_OUT_BT_SCO;
2727 }
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002728 } else if (devices & AUDIO_DEVICE_OUT_ALL_A2DP) {
2729 snd_device = SND_DEVICE_OUT_BT_A2DP;
Eric Laurentb23d5282013-05-14 15:27:20 -07002730 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2731 snd_device = SND_DEVICE_OUT_HDMI ;
Eric Laurent99dab492017-06-17 15:19:08 -07002732 } else if (audio_is_usb_out_device(devices)) {
jasmine cha270b7762018-03-30 15:41:33 +08002733 if (audio_extn_ma_supported_usb())
2734 snd_device = SND_DEVICE_OUT_USB_HEADSET_SPEC;
2735 else if (audio_extn_usb_is_capture_supported())
David Linee3fe402017-03-13 10:00:42 -07002736 snd_device = SND_DEVICE_OUT_USB_HEADSET;
2737 else
2738 snd_device = SND_DEVICE_OUT_USB_HEADPHONES;
2739 }else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002740 /*HAC support for voice-ish audio (eg visual voicemail)*/
2741 if(adev->voice.hac)
2742 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2743 else
2744 snd_device = SND_DEVICE_OUT_HANDSET;
Eric Laurentb23d5282013-05-14 15:27:20 -07002745 } else {
2746 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
2747 }
2748exit:
2749 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
2750 return snd_device;
2751}
2752
2753snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
2754{
2755 struct platform_data *my_data = (struct platform_data *)platform;
2756 struct audio_device *adev = my_data->adev;
2757 audio_source_t source = (adev->active_input == NULL) ?
2758 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
2759
2760 audio_mode_t mode = adev->mode;
2761 audio_devices_t in_device = ((adev->active_input == NULL) ?
2762 AUDIO_DEVICE_NONE : adev->active_input->device)
2763 & ~AUDIO_DEVICE_BIT_IN;
2764 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
2765 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
2766 snd_device_t snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002767 int channel_count = popcount(channel_mask);
Eric Laurentb23d5282013-05-14 15:27:20 -07002768
Prashant Malanic92c5962015-08-11 15:10:18 -07002769 ALOGV("%s: enter: out_device(%#x) in_device(%#x) channel_count (%d) channel_mask (0x%x)",
2770 __func__, out_device, in_device, channel_count, channel_mask);
Devin Kimd789e432016-10-26 15:07:27 -07002771 if ((out_device != AUDIO_DEVICE_NONE) && (voice_is_in_call(adev) ||
2772 audio_extn_hfp_is_active(adev))) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002773 if (adev->voice.tty_mode != TTY_MODE_OFF) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002774 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002775 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2776 out_device & AUDIO_DEVICE_OUT_LINE) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002777 switch (adev->voice.tty_mode) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002778 case TTY_MODE_FULL:
2779 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
2780 break;
2781 case TTY_MODE_VCO:
2782 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
2783 break;
2784 case TTY_MODE_HCO:
2785 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
2786 break;
2787 default:
2788 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
2789 }
2790 goto exit;
Eric Laurent99dab492017-06-17 15:19:08 -07002791 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002792 switch (adev->voice.tty_mode) {
2793 case TTY_MODE_FULL:
2794 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC;
2795 break;
2796 case TTY_MODE_VCO:
2797 // since voice will be captured from handset mic, use existing device
2798 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
2799 break;
2800 case TTY_MODE_HCO:
2801 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC;
2802 break;
2803 default:
2804 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
Eric Laurentb23d5282013-05-14 15:27:20 -07002805 }
2806 goto exit;
2807 }
2808 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002809 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002810 if (my_data->fluence_in_voice_call == false) {
2811 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2812 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002813 if (is_operator_tmus())
2814 snd_device = SND_DEVICE_IN_VOICE_DMIC_TMUS;
Eric Laurentb23d5282013-05-14 15:27:20 -07002815 else
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002816 snd_device = SND_DEVICE_IN_VOICE_DMIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002817 }
2818 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2819 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
2820 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002821 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002822 if (adev->bluetooth_nrec)
2823 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2824 else
2825 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002826 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002827 if (adev->bluetooth_nrec)
2828 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2829 else
2830 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002831 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002832 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Prashant Malanic92c5962015-08-11 15:10:18 -07002833 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
2834 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2835 out_device & AUDIO_DEVICE_OUT_LINE) {
2836 if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
2837 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
2838 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
2839 } else {
2840 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2841 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002842 }
vivek mehtafe121d52015-08-10 23:39:23 -07002843
2844 //select default
2845 if (snd_device == SND_DEVICE_NONE) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002846 if (!adev->enable_hfp) {
2847 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2848 } else {
2849 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP;
2850 platform_set_echo_reference(adev, true, out_device);
2851 }
vivek mehtafe121d52015-08-10 23:39:23 -07002852 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002853 } else if (out_device & AUDIO_DEVICE_OUT_TELEPHONY_TX) {
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002854 snd_device = SND_DEVICE_IN_VOICE_RX;
Eric Laurent99dab492017-06-17 15:19:08 -07002855 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
David Lin40b07892017-08-07 15:02:48 -07002856 if (audio_extn_usb_is_capture_supported()) {
2857 snd_device = SND_DEVICE_IN_VOICE_USB_HEADSET_MIC;
2858 } else if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
2859 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
2860 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
2861 } else {
2862 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2863 }
2864 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002865 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002866 } else if (source == AUDIO_SOURCE_CAMCORDER) {
2867 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
2868 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2869 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
2870 }
2871 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
2872 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002873 if (my_data->fluence_in_voice_rec && channel_count == 1) {
2874 if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2875 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002876 if (adev->active_input->enable_aec)
2877 snd_device = SND_DEVICE_IN_HANDSET_QMIC_AEC;
2878 else
2879 snd_device = SND_DEVICE_IN_HANDSET_QMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002880 } else if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2881 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002882 if (adev->active_input->enable_aec)
2883 snd_device = SND_DEVICE_IN_HANDSET_TMIC_AEC;
2884 else
2885 snd_device = SND_DEVICE_IN_HANDSET_TMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002886 } else if (((my_data->fluence_type == FLUENCE_PRO_ENABLE) ||
2887 (my_data->fluence_type == FLUENCE_ENABLE)) &&
2888 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002889 if (adev->active_input->enable_aec)
2890 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
2891 else
2892 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
Prashant Malanic92c5962015-08-11 15:10:18 -07002893 }
2894 platform_set_echo_reference(adev, true, out_device);
2895 } else if ((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) &&
2896 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2897 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002898 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002899 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
2900 snd_device = SND_DEVICE_IN_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002901 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002902 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2903 snd_device = SND_DEVICE_IN_QUAD_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002904 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002905 if (snd_device == SND_DEVICE_NONE) {
vivek mehtaf3440682016-05-11 14:24:37 -07002906 if (adev->active_input->enable_aec) {
2907 if (adev->active_input->enable_ns) {
2908 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS;
2909 } else {
2910 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC;
2911 }
vivek mehta733c1df2016-04-04 15:09:24 -07002912 platform_set_echo_reference(adev, true, out_device);
vivek mehtaf3440682016-05-11 14:24:37 -07002913 } else if (adev->active_input->enable_ns) {
2914 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
2915 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002916 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
vivek mehtaf3440682016-05-11 14:24:37 -07002917 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002918 }
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -07002919 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2920 snd_device = SND_DEVICE_IN_VOICE_REC_HEADSET_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07002921 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002922 snd_device = SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002923 }
rago90fb9612015-12-02 11:37:53 -08002924 } else if (source == AUDIO_SOURCE_UNPROCESSED) {
2925 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
vivek mehta4ed66e62016-04-15 23:33:34 -07002926 if (((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) ||
2927 (channel_mask == AUDIO_CHANNEL_IN_STEREO)) &&
2928 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2929 snd_device = SND_DEVICE_IN_UNPROCESSED_STEREO_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002930 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07002931 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
2932 snd_device = SND_DEVICE_IN_UNPROCESSED_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002933 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07002934 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2935 snd_device = SND_DEVICE_IN_UNPROCESSED_QUAD_MIC;
2936 } else {
2937 snd_device = SND_DEVICE_IN_UNPROCESSED_MIC;
2938 }
rago90fb9612015-12-02 11:37:53 -08002939 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2940 snd_device = SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07002941 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002942 snd_device = SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC;
rago90fb9612015-12-02 11:37:53 -08002943 }
Eric Laurent50a38ed2015-10-14 18:48:06 -07002944 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION ||
rago90fb9612015-12-02 11:37:53 -08002945 mode == AUDIO_MODE_IN_COMMUNICATION) {
David Lin40b07892017-08-07 15:02:48 -07002946 if (out_device & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
2947 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2948 (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE | AUDIO_DEVICE_OUT_USB_HEADSET) &&
2949 !audio_extn_usb_is_capture_supported())) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002950 in_device = AUDIO_DEVICE_IN_BACK_MIC;
David Lin40b07892017-08-07 15:02:48 -07002951 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002952 if (adev->active_input) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002953 if (adev->active_input->enable_aec &&
2954 adev->active_input->enable_ns) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002955 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002956 if (my_data->fluence_in_spkr_mode &&
2957 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002958 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002959 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002960 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002961 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002962 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002963 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002964 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002965 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002966 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002967 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002968 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002969 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002970 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2971 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Eric Laurent99dab492017-06-17 15:19:08 -07002972 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002973 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002974 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002975 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002976 } else if (adev->active_input->enable_aec) {
2977 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2978 if (my_data->fluence_in_spkr_mode &&
2979 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002980 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002981 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002982 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002983 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002984 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002985 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2986 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002987 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002988 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002989 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002990 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002991 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002992 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2993 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Eric Laurent99dab492017-06-17 15:19:08 -07002994 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002995 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
Eric Laurentcefbbac2014-09-04 13:54:10 -05002996 }
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08002997 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002998 } else if (adev->active_input->enable_ns) {
2999 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
3000 if (my_data->fluence_in_spkr_mode &&
3001 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003002 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003003 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003004 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003005 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003006 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003007 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
3008 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003009 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003010 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003011 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003012 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003013 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003014 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05003015 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003016 }
3017 } else if (source == AUDIO_SOURCE_DEFAULT) {
3018 goto exit;
3019 }
3020
3021
3022 if (snd_device != SND_DEVICE_NONE) {
3023 goto exit;
3024 }
3025
3026 if (in_device != AUDIO_DEVICE_NONE &&
3027 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
3028 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
3029 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003030 if ((my_data->source_mic_type & SOURCE_QUAD_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003031 channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003032 snd_device = SND_DEVICE_IN_QUAD_MIC;
3033 } else if ((my_data->source_mic_type & SOURCE_THREE_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003034 channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003035 snd_device = SND_DEVICE_IN_THREE_MIC;
3036 } else if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
3037 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003038 snd_device = SND_DEVICE_IN_HANDSET_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07003039 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
3040 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003041 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003042 } else {
3043 ALOGE("%s: something wrong (1): source type (%d) channel_count (%d) .."
3044 " channel mask (0x%x) no combination found .. setting to mono", __func__,
3045 my_data->source_mic_type, channel_count, channel_mask);
3046 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3047 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003048 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003049 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
3050 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003051 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07003052 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
3053 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003054 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003055 } else {
3056 ALOGE("%s: something wrong (2): source type (%d) channel_count (%d) .."
3057 " no combination found .. setting to mono", __func__,
3058 my_data->source_mic_type, channel_count);
3059 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
3060 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003061 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3062 snd_device = SND_DEVICE_IN_HEADSET_MIC;
3063 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003064 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003065 if (adev->bluetooth_nrec)
3066 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
3067 else
3068 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003069 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003070 if (adev->bluetooth_nrec)
3071 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
3072 else
3073 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003074 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003075 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
3076 snd_device = SND_DEVICE_IN_HDMI_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07003077 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
David Linee3fe402017-03-13 10:00:42 -07003078 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07003079 } else {
3080 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
3081 ALOGW("%s: Using default handset-mic", __func__);
3082 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3083 }
3084 } else {
3085 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
3086 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3087 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
3088 snd_device = SND_DEVICE_IN_HEADSET_MIC;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003089 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07003090 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003091 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05003092 out_device & AUDIO_DEVICE_OUT_LINE) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003093 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
3094 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003095 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07003096 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
3097 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003098 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003099 } else {
3100 ALOGE("%s: something wrong (3): source type (%d) channel_count (%d) .."
3101 " no combination found .. setting to mono", __func__,
3102 my_data->source_mic_type, channel_count);
3103 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
3104 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003105 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003106 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003107 if (adev->bluetooth_nrec)
3108 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
3109 else
3110 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003111 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003112 if (adev->bluetooth_nrec)
3113 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
3114 else
3115 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003116 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003117 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
3118 snd_device = SND_DEVICE_IN_HDMI_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07003119 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
David Linee3fe402017-03-13 10:00:42 -07003120 if (audio_extn_usb_is_capture_supported())
3121 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
3122 else
3123 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07003124 } else {
3125 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
3126 ALOGW("%s: Using default handset-mic", __func__);
3127 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3128 }
3129 }
3130exit:
3131 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
3132 return snd_device;
3133}
3134
3135int platform_set_hdmi_channels(void *platform, int channel_count)
3136{
3137 struct platform_data *my_data = (struct platform_data *)platform;
3138 struct audio_device *adev = my_data->adev;
3139 struct mixer_ctl *ctl;
3140 const char *channel_cnt_str = NULL;
3141 const char *mixer_ctl_name = "HDMI_RX Channels";
3142 switch (channel_count) {
3143 case 8:
3144 channel_cnt_str = "Eight"; break;
3145 case 7:
3146 channel_cnt_str = "Seven"; break;
3147 case 6:
3148 channel_cnt_str = "Six"; break;
3149 case 5:
3150 channel_cnt_str = "Five"; break;
3151 case 4:
3152 channel_cnt_str = "Four"; break;
3153 case 3:
3154 channel_cnt_str = "Three"; break;
3155 default:
3156 channel_cnt_str = "Two"; break;
3157 }
3158 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3159 if (!ctl) {
3160 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3161 __func__, mixer_ctl_name);
3162 return -EINVAL;
3163 }
3164 ALOGV("HDMI channel count: %s", channel_cnt_str);
3165 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
3166 return 0;
3167}
3168
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003169int platform_edid_get_max_channels(void *platform)
Eric Laurentb23d5282013-05-14 15:27:20 -07003170{
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003171 struct platform_data *my_data = (struct platform_data *)platform;
3172 struct audio_device *adev = my_data->adev;
Eric Laurentb23d5282013-05-14 15:27:20 -07003173 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
3174 char *sad = block;
3175 int num_audio_blocks;
3176 int channel_count;
3177 int max_channels = 0;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003178 int i, ret, count;
Eric Laurentb23d5282013-05-14 15:27:20 -07003179
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003180 struct mixer_ctl *ctl;
3181
3182 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
3183 if (!ctl) {
3184 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3185 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
Eric Laurentb23d5282013-05-14 15:27:20 -07003186 return 0;
3187 }
3188
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003189 mixer_ctl_update(ctl);
3190
3191 count = mixer_ctl_get_num_values(ctl);
Eric Laurentb23d5282013-05-14 15:27:20 -07003192
3193 /* Read SAD blocks, clamping the maximum size for safety */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003194 if (count > (int)sizeof(block))
3195 count = (int)sizeof(block);
Eric Laurentb23d5282013-05-14 15:27:20 -07003196
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003197 ret = mixer_ctl_get_array(ctl, block, count);
3198 if (ret != 0) {
3199 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
3200 return 0;
3201 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003202
3203 /* Calculate the number of SAD blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003204 num_audio_blocks = count / SAD_BLOCK_SIZE;
Eric Laurentb23d5282013-05-14 15:27:20 -07003205
3206 for (i = 0; i < num_audio_blocks; i++) {
3207 /* Only consider LPCM blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003208 if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
3209 sad += 3;
Eric Laurentb23d5282013-05-14 15:27:20 -07003210 continue;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003211 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003212
3213 channel_count = (sad[0] & 0x7) + 1;
3214 if (channel_count > max_channels)
3215 max_channels = channel_count;
3216
3217 /* Advance to next block */
3218 sad += 3;
3219 }
3220
3221 return max_channels;
3222}
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003223
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07003224int platform_set_incall_recording_session_id(void *platform,
3225 uint32_t session_id, int rec_mode)
3226{
3227 int ret = 0;
3228 struct platform_data *my_data = (struct platform_data *)platform;
3229 struct audio_device *adev = my_data->adev;
3230 struct mixer_ctl *ctl;
3231 const char *mixer_ctl_name = "Voc VSID";
3232 int num_ctl_values;
3233 int i;
3234
3235 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3236 if (!ctl) {
3237 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3238 __func__, mixer_ctl_name);
3239 ret = -EINVAL;
3240 } else {
3241 num_ctl_values = mixer_ctl_get_num_values(ctl);
3242 for (i = 0; i < num_ctl_values; i++) {
3243 if (mixer_ctl_set_value(ctl, i, session_id)) {
3244 ALOGV("Error: invalid session_id: %x", session_id);
3245 ret = -EINVAL;
3246 break;
3247 }
3248 }
3249 }
3250
3251 if (my_data->csd != NULL) {
3252 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
3253 if (ret < 0) {
3254 ALOGE("%s: csd_client_start_record failed, error %d",
3255 __func__, ret);
3256 }
3257 }
3258
3259 return ret;
3260}
3261
3262int platform_stop_incall_recording_usecase(void *platform)
3263{
3264 int ret = 0;
3265 struct platform_data *my_data = (struct platform_data *)platform;
3266
3267 if (my_data->csd != NULL) {
3268 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
3269 if (ret < 0) {
3270 ALOGE("%s: csd_client_stop_record failed, error %d",
3271 __func__, ret);
3272 }
3273 }
3274
3275 return ret;
3276}
3277
3278int platform_start_incall_music_usecase(void *platform)
3279{
3280 int ret = 0;
3281 struct platform_data *my_data = (struct platform_data *)platform;
3282
3283 if (my_data->csd != NULL) {
3284 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
3285 if (ret < 0) {
3286 ALOGE("%s: csd_client_start_playback failed, error %d",
3287 __func__, ret);
3288 }
3289 }
3290
3291 return ret;
3292}
3293
3294int platform_stop_incall_music_usecase(void *platform)
3295{
3296 int ret = 0;
3297 struct platform_data *my_data = (struct platform_data *)platform;
3298
3299 if (my_data->csd != NULL) {
3300 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
3301 if (ret < 0) {
3302 ALOGE("%s: csd_client_stop_playback failed, error %d",
3303 __func__, ret);
3304 }
3305 }
3306
3307 return ret;
3308}
3309
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003310int platform_set_parameters(void *platform, struct str_parms *parms)
3311{
3312 struct platform_data *my_data = (struct platform_data *)platform;
jasmine chac89321b2018-04-10 21:37:01 +08003313 char *value = NULL;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003314 char *kv_pairs = str_parms_to_str(parms);
jasmine chac89321b2018-04-10 21:37:01 +08003315 int len;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003316 int ret = 0, err;
3317
3318 if (kv_pairs == NULL) {
3319 ret = -EINVAL;
Jasmine Chaa314e192018-05-09 17:46:28 +08003320 ALOGE("%s: key-value pair is NULL", __func__);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003321 goto done;
3322 }
3323
3324 ALOGV("%s: enter: %s", __func__, kv_pairs);
3325
jasmine chac89321b2018-04-10 21:37:01 +08003326 len = strlen(kv_pairs);
Jasmine Chaa314e192018-05-09 17:46:28 +08003327 value = (char*)calloc(len + 1, sizeof(char));
jasmine chac89321b2018-04-10 21:37:01 +08003328 if (value == NULL) {
3329 ret = -ENOMEM;
Jasmine Chaa314e192018-05-09 17:46:28 +08003330 ALOGE("[%s] failed to allocate memory", __func__);
jasmine chac89321b2018-04-10 21:37:01 +08003331 goto done;
3332 }
3333
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003334 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME,
jasmine chac89321b2018-04-10 21:37:01 +08003335 value, len);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003336 if (err >= 0) {
3337 str_parms_del(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME);
3338 my_data->snd_card_name = strdup(value);
3339 ALOGV("%s: sound card name %s", __func__, my_data->snd_card_name);
3340 }
3341
keunhui.park2f7306a2015-07-16 16:48:06 +09003342 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO,
jasmine chac89321b2018-04-10 21:37:01 +08003343 value, len);
keunhui.park2f7306a2015-07-16 16:48:06 +09003344 if (err >= 0) {
3345 struct operator_info *info;
3346 char *str = value;
3347 char *name;
3348
3349 str_parms_del(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO);
3350 info = (struct operator_info *)calloc(1, sizeof(struct operator_info));
3351 name = strtok(str, ";");
3352 info->name = strdup(name);
3353 info->mccmnc = strdup(str + strlen(name) + 1);
3354
3355 list_add_tail(&operator_info_list, &info->list);
Joe Onorato188b6222016-03-01 11:02:27 -08003356 ALOGV("%s: add operator[%s] mccmnc[%s]", __func__, info->name, info->mccmnc);
keunhui.park2f7306a2015-07-16 16:48:06 +09003357 }
Prashant Malanic92c5962015-08-11 15:10:18 -07003358
Jasmine Chaa314e192018-05-09 17:46:28 +08003359 memset(value, 0, len + 1);
Eric Laurentc6333382015-09-14 12:43:44 -07003360 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT,
jasmine chac89321b2018-04-10 21:37:01 +08003361 value, len);
Prashant Malanic92c5962015-08-11 15:10:18 -07003362 if (err >= 0) {
Eric Laurentc6333382015-09-14 12:43:44 -07003363 str_parms_del(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT);
Prashant Malanic92c5962015-08-11 15:10:18 -07003364 my_data->max_mic_count = atoi(value);
3365 ALOGV("%s: max_mic_count %s/%d", __func__, value, my_data->max_mic_count);
Prashant Malanic92c5962015-08-11 15:10:18 -07003366 }
3367
jasmine chac89321b2018-04-10 21:37:01 +08003368 /* handle audio calibration parameters */
3369 set_audiocal(platform, parms, value, len);
3370
vivek mehta90933872017-06-15 18:04:39 -07003371 // to-do: disable setting sidetone gain, will revist this later
3372 // audio_extn_usb_set_sidetone_gain(parms, value, len);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003373done:
3374 ALOGV("%s: exit with code(%d)", __func__, ret);
3375 if (kv_pairs != NULL)
3376 free(kv_pairs);
jasmine chac89321b2018-04-10 21:37:01 +08003377 if (value != NULL)
3378 free(value);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003379
3380 return ret;
3381}
3382
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003383/* Delay in Us */
3384int64_t platform_render_latency(audio_usecase_t usecase)
3385{
3386 switch (usecase) {
3387 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
3388 return DEEP_BUFFER_PLATFORM_DELAY;
3389 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
3390 return LOW_LATENCY_PLATFORM_DELAY;
Haynes Mathew George03c40102016-01-29 17:57:48 -08003391 case USECASE_AUDIO_PLAYBACK_ULL:
3392 return ULL_PLATFORM_DELAY;
Eric Laurent0e46adf2016-12-16 12:49:24 -08003393 case USECASE_AUDIO_PLAYBACK_MMAP:
3394 return MMAP_PLATFORM_DELAY;
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003395 default:
3396 return 0;
3397 }
3398}
Haynes Mathew George98c95622014-06-20 19:14:25 -07003399
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003400int platform_set_snd_device_backend(snd_device_t device, const char *backend_tag,
3401 const char * hw_interface)
Haynes Mathew George98c95622014-06-20 19:14:25 -07003402{
3403 int ret = 0;
3404
3405 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
3406 ALOGE("%s: Invalid snd_device = %d",
3407 __func__, device);
3408 ret = -EINVAL;
3409 goto done;
3410 }
3411
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003412 ALOGV("%s: backend_tag_table[%s]: old = %s new = %s", __func__,
3413 platform_get_snd_device_name(device),
3414 backend_tag_table[device] != NULL ? backend_tag_table[device]: "null", backend_tag);
3415 if (backend_tag_table[device]) {
3416 free(backend_tag_table[device]);
Haynes Mathew George98c95622014-06-20 19:14:25 -07003417 }
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003418 backend_tag_table[device] = strdup(backend_tag);
3419
3420 if (hw_interface != NULL) {
3421 if (hw_interface_table[device])
3422 free(hw_interface_table[device]);
3423 ALOGV("%s: hw_interface_table[%d] = %s", __func__, device, hw_interface);
3424 hw_interface_table[device] = strdup(hw_interface);
3425 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07003426done:
3427 return ret;
3428}
3429
3430int platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t pcm_id)
3431{
3432 int ret = 0;
3433 if ((usecase <= USECASE_INVALID) || (usecase >= AUDIO_USECASE_MAX)) {
3434 ALOGE("%s: invalid usecase case idx %d", __func__, usecase);
3435 ret = -EINVAL;
3436 goto done;
3437 }
3438
3439 if ((type != 0) && (type != 1)) {
3440 ALOGE("%s: invalid usecase type", __func__);
3441 ret = -EINVAL;
3442 }
vivek mehtaa68fea62017-06-08 19:04:02 -07003443 ALOGV("%s: pcm_device_table[%d %s][%d] = %d", __func__, usecase,
3444 use_case_table[usecase],
3445 type, pcm_id);
Haynes Mathew George98c95622014-06-20 19:14:25 -07003446 pcm_device_table[usecase][type] = pcm_id;
3447done:
3448 return ret;
3449}
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003450
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07003451#define DEFAULT_NOMINAL_SPEAKER_GAIN 20
3452int ramp_speaker_gain(struct audio_device *adev, bool ramp_up, int target_ramp_up_gain) {
3453 // backup_gain: gain to try to set in case of an error during ramp
3454 int start_gain, end_gain, step, backup_gain, i;
3455 bool error = false;
3456 const struct mixer_ctl *ctl;
3457 const char *mixer_ctl_name_gain_left = "Left Speaker Gain";
3458 const char *mixer_ctl_name_gain_right = "Right Speaker Gain";
3459 struct mixer_ctl *ctl_left = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_left);
3460 struct mixer_ctl *ctl_right = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_right);
3461 if (!ctl_left || !ctl_right) {
3462 ALOGE("%s: Could not get ctl for mixer cmd - %s or %s, not applying speaker gain ramp",
3463 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
3464 return -EINVAL;
3465 } else if ((mixer_ctl_get_num_values(ctl_left) != 1)
3466 || (mixer_ctl_get_num_values(ctl_right) != 1)) {
3467 ALOGE("%s: Unexpected num values for mixer cmd - %s or %s, not applying speaker gain ramp",
3468 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
3469 return -EINVAL;
3470 }
3471 if (ramp_up) {
3472 start_gain = 0;
3473 end_gain = target_ramp_up_gain > 0 ? target_ramp_up_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
3474 step = +1;
3475 backup_gain = end_gain;
3476 } else {
3477 // using same gain on left and right
3478 const int left_gain = mixer_ctl_get_value(ctl_left, 0);
3479 start_gain = left_gain > 0 ? left_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
3480 end_gain = 0;
3481 step = -1;
3482 backup_gain = start_gain;
3483 }
3484 for (i = start_gain ; i != (end_gain + step) ; i += step) {
3485 //ALOGV("setting speaker gain to %d", i);
3486 if (mixer_ctl_set_value(ctl_left, 0, i)) {
3487 ALOGE("%s: error setting %s to %d during gain ramp",
3488 __func__, mixer_ctl_name_gain_left, i);
3489 error = true;
3490 break;
3491 }
3492 if (mixer_ctl_set_value(ctl_right, 0, i)) {
3493 ALOGE("%s: error setting %s to %d during gain ramp",
3494 __func__, mixer_ctl_name_gain_right, i);
3495 error = true;
3496 break;
3497 }
3498 usleep(1000);
3499 }
3500 if (error) {
3501 // an error occured during the ramp, let's still try to go back to a safe volume
3502 if (mixer_ctl_set_value(ctl_left, 0, backup_gain)) {
3503 ALOGE("%s: error restoring left gain to %d", __func__, backup_gain);
3504 }
3505 if (mixer_ctl_set_value(ctl_right, 0, backup_gain)) {
3506 ALOGE("%s: error restoring right gain to %d", __func__, backup_gain);
3507 }
3508 }
3509 return start_gain;
3510}
3511
vivek mehtae59cfb22017-06-16 15:57:11 -07003512int platform_set_swap_mixer(struct audio_device *adev, bool swap_channels)
3513{
3514 const char *mixer_ctl_name = "Swap channel";
3515 struct mixer_ctl *ctl;
3516 const char *mixer_path;
3517 struct platform_data *my_data = (struct platform_data *)adev->platform;
3518
3519 // forced to set to swap, but device not rotated ... ignore set
3520 if (swap_channels && !my_data->speaker_lr_swap)
3521 return 0;
3522
3523 ALOGV("%s:", __func__);
3524
3525 if (swap_channels) {
3526 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER_REVERSE);
3527 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
3528 } else {
3529 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER);
3530 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
3531 }
3532
3533 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3534 if (!ctl) {
3535 ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name);
3536 return -EINVAL;
3537 }
3538
3539 if (mixer_ctl_set_value(ctl, 0, swap_channels) < 0) {
3540 ALOGE("%s: Could not set reverse cotrol %d",__func__, swap_channels);
3541 return -EINVAL;
3542 }
3543
3544 ALOGV("platfor_force_swap_channel :: Channel orientation ( %s ) ",
3545 swap_channels?"R --> L":"L --> R");
3546
3547 return 0;
3548}
3549
3550int platform_check_and_set_swap_lr_channels(struct audio_device *adev, bool swap_channels)
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003551{
3552 // only update if there is active pcm playback on speaker
3553 struct audio_usecase *usecase;
3554 struct listnode *node;
3555 struct platform_data *my_data = (struct platform_data *)adev->platform;
3556
vivek mehtae59cfb22017-06-16 15:57:11 -07003557 my_data->speaker_lr_swap = swap_channels;
Jean-Michel Trivif7148702016-09-16 18:23:05 -07003558
vivek mehtae59cfb22017-06-16 15:57:11 -07003559 return platform_set_swap_channels(adev, swap_channels);
3560}
Jean-Michel Trivif7148702016-09-16 18:23:05 -07003561
vivek mehtae59cfb22017-06-16 15:57:11 -07003562int platform_set_swap_channels(struct audio_device *adev, bool swap_channels)
3563{
3564 // only update if there is active pcm playback on speaker
3565 struct audio_usecase *usecase;
3566 struct listnode *node;
3567 struct platform_data *my_data = (struct platform_data *)adev->platform;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003568
vivek mehtae59cfb22017-06-16 15:57:11 -07003569 // do not swap channels in audio modes with concurrent capture and playback
3570 // as this may break the echo reference
3571 if ((adev->mode == AUDIO_MODE_IN_COMMUNICATION) || (adev->mode == AUDIO_MODE_IN_CALL)) {
3572 ALOGV("%s: will not swap due to audio mode %d", __func__, adev->mode);
3573 return 0;
3574 }
3575
3576 list_for_each(node, &adev->usecase_list) {
3577 usecase = node_to_item(node, struct audio_usecase, list);
3578 if (usecase->type == PCM_PLAYBACK &&
3579 usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) {
3580 /*
3581 * If acdb tuning is different for SPEAKER_REVERSE, it is must
3582 * to perform device switch to disable the current backend to
3583 * enable it with new acdb data.
3584 */
3585 if (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
3586 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]) {
3587 const int initial_skpr_gain = ramp_speaker_gain(adev, false /*ramp_up*/, -1);
3588 select_devices(adev, usecase->id);
3589 if (initial_skpr_gain != -EINVAL)
3590 ramp_speaker_gain(adev, true /*ramp_up*/, initial_skpr_gain);
3591
3592 } else {
3593 platform_set_swap_mixer(adev, swap_channels);
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003594 }
vivek mehtae59cfb22017-06-16 15:57:11 -07003595 break;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003596 }
3597 }
vivek mehtae59cfb22017-06-16 15:57:11 -07003598
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003599 return 0;
3600}
vivek mehtaa8d7c922016-05-25 14:40:44 -07003601
3602static struct amp_db_and_gain_table tbl_mapping[MAX_VOLUME_CAL_STEPS];
3603static int num_gain_tbl_entry = 0;
3604
3605bool platform_add_gain_level_mapping(struct amp_db_and_gain_table *tbl_entry) {
3606
3607 ALOGV("%s: enter .. add %f %f %d", __func__, tbl_entry->amp, tbl_entry->db, tbl_entry->level);
3608 if (num_gain_tbl_entry == -1) {
3609 ALOGE("%s: num entry beyond valid step levels or corrupted..rejecting custom mapping",
3610 __func__);
3611 return false;
3612 }
3613
3614 if (num_gain_tbl_entry >= MAX_VOLUME_CAL_STEPS) {
3615 ALOGE("%s: max entry reached max[%d] current index[%d] .. rejecting", __func__,
3616 MAX_VOLUME_CAL_STEPS, num_gain_tbl_entry);
3617 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
3618 return false;
3619 }
3620
3621 if (num_gain_tbl_entry > 0 && tbl_mapping[num_gain_tbl_entry - 1].amp >= tbl_entry->amp) {
3622 ALOGE("%s: value not in ascending order .. rejecting custom mapping", __func__);
3623 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
3624 return false;
3625 }
3626
3627 tbl_mapping[num_gain_tbl_entry] = *tbl_entry;
3628 ++num_gain_tbl_entry;
3629
3630 return true;
3631}
3632
3633int platform_get_gain_level_mapping(struct amp_db_and_gain_table *mapping_tbl,
3634 int table_size) {
3635 int itt = 0;
3636 ALOGV("platform_get_gain_level_mapping called ");
3637
3638 if (num_gain_tbl_entry <= 0 || num_gain_tbl_entry > MAX_VOLUME_CAL_STEPS) {
3639 ALOGD("%s: empty or currupted gain_mapping_table", __func__);
3640 return 0;
3641 }
3642
3643 for (; itt < num_gain_tbl_entry && itt <= table_size; itt++) {
3644 mapping_tbl[itt] = tbl_mapping[itt];
3645 ALOGV("%s: added amp[%f] db[%f] level[%d]", __func__,
3646 mapping_tbl[itt].amp, mapping_tbl[itt].db, mapping_tbl[itt].level);
3647 }
3648
3649 return num_gain_tbl_entry;
3650}
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07003651
3652int platform_snd_card_update(void *platform, card_status_t status)
3653{
3654 struct platform_data *my_data = (struct platform_data *)platform;
3655 struct audio_device *adev = my_data->adev;
3656
3657 if (status == CARD_STATUS_ONLINE) {
3658 if (my_data->acdb_send_custom_top)
3659 my_data->acdb_send_custom_top();
3660 }
3661 return 0;
3662}
David Linee3fe402017-03-13 10:00:42 -07003663
3664/*
3665 * configures afe with bit width and Sample Rate
3666 */
Haynes Mathew George65f6b432018-02-27 17:44:55 -08003667int platform_set_backend_cfg(const struct audio_device* adev,
3668 snd_device_t snd_device,
3669 const struct audio_backend_cfg *backend_cfg)
David Linee3fe402017-03-13 10:00:42 -07003670{
3671
3672 int ret = 0;
3673 const int backend_idx = platform_get_backend_index(snd_device);
3674 struct platform_data *my_data = (struct platform_data *)adev->platform;
3675 const unsigned int bit_width = backend_cfg->bit_width;
3676 const unsigned int sample_rate = backend_cfg->sample_rate;
3677 const unsigned int channels = backend_cfg->channels;
3678 const audio_format_t format = backend_cfg->format;
3679 const bool passthrough_enabled = backend_cfg->passthrough_enabled;
3680
3681
3682 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
3683 ", backend_idx %d device (%s)", __func__, bit_width,
3684 sample_rate, channels, backend_idx,
3685 platform_get_snd_device_name(snd_device));
3686
3687 if ((my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl) &&
3688 (bit_width != my_data->current_backend_cfg[backend_idx].bit_width)) {
3689
3690 struct mixer_ctl *ctl = NULL;
3691 ctl = mixer_get_ctl_by_name(adev->mixer,
3692 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
3693 if (!ctl) {
3694 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3695 __func__,
3696 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
3697 return -EINVAL;
3698 }
3699
3700 if (bit_width == 24) {
3701 if (format == AUDIO_FORMAT_PCM_24_BIT_PACKED)
3702 ret = mixer_ctl_set_enum_by_string(ctl, "S24_3LE");
3703 else
3704 ret = mixer_ctl_set_enum_by_string(ctl, "S24_LE");
3705 } else if (bit_width == 32) {
3706 ret = mixer_ctl_set_enum_by_string(ctl, "S32_LE");
3707 } else {
3708 ret = mixer_ctl_set_enum_by_string(ctl, "S16_LE");
3709 }
3710 if ( ret < 0) {
3711 ALOGE("%s:becf: afe: fail for %s mixer set to %d bit for %x format", __func__,
3712 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
3713 } else {
3714 my_data->current_backend_cfg[backend_idx].bit_width = bit_width;
3715 ALOGD("%s:becf: afe: %s mixer set to %d bit for %x format", __func__,
3716 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
3717 }
3718 /* set the ret as 0 and not pass back to upper layer */
3719 ret = 0;
3720 }
3721
3722 if (passthrough_enabled || ((my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl) &&
3723 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate))) {
3724 char *rate_str = NULL;
3725 struct mixer_ctl *ctl = NULL;
3726
3727 switch (sample_rate) {
3728 case 32000:
3729 if (passthrough_enabled) {
3730 rate_str = "KHZ_32";
3731 break;
3732 }
3733 case 8000:
3734 case 11025:
3735 case 16000:
3736 case 22050:
3737 case 48000:
3738 rate_str = "KHZ_48";
3739 break;
3740 case 44100:
3741 rate_str = "KHZ_44P1";
3742 break;
3743 case 64000:
3744 case 96000:
3745 rate_str = "KHZ_96";
3746 break;
3747 case 88200:
3748 rate_str = "KHZ_88P2";
3749 break;
3750 case 176400:
3751 rate_str = "KHZ_176P4";
3752 break;
3753 case 192000:
3754 rate_str = "KHZ_192";
3755 break;
3756 case 352800:
3757 rate_str = "KHZ_352P8";
3758 break;
3759 case 384000:
3760 rate_str = "KHZ_384";
3761 break;
3762 case 144000:
3763 if (passthrough_enabled) {
3764 rate_str = "KHZ_144";
3765 break;
3766 }
3767 default:
3768 rate_str = "KHZ_48";
3769 break;
3770 }
3771
3772 ctl = mixer_get_ctl_by_name(adev->mixer,
3773 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
3774 if(!ctl) {
3775 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3776 __func__,
3777 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
3778 return -EINVAL;
3779 }
3780
3781 ALOGD("%s:becf: afe: %s set to %s", __func__,
3782 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl, rate_str);
3783 mixer_ctl_set_enum_by_string(ctl, rate_str);
3784 my_data->current_backend_cfg[backend_idx].sample_rate = sample_rate;
3785 }
3786 if ((my_data->current_backend_cfg[backend_idx].channels_mixer_ctl) &&
3787 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
3788 struct mixer_ctl *ctl = NULL;
3789 char *channel_cnt_str = NULL;
3790
3791 switch (channels) {
3792 case 8:
3793 channel_cnt_str = "Eight"; break;
3794 case 7:
3795 channel_cnt_str = "Seven"; break;
3796 case 6:
3797 channel_cnt_str = "Six"; break;
3798 case 5:
3799 channel_cnt_str = "Five"; break;
3800 case 4:
3801 channel_cnt_str = "Four"; break;
3802 case 3:
3803 channel_cnt_str = "Three"; break;
3804 case 1:
3805 channel_cnt_str = "One"; break;
3806 case 2:
3807 default:
3808 channel_cnt_str = "Two"; break;
3809 }
3810
3811 ctl = mixer_get_ctl_by_name(adev->mixer,
3812 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
3813 if (!ctl) {
3814 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3815 __func__,
3816 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
3817 return -EINVAL;
3818 }
3819 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
3820 my_data->current_backend_cfg[backend_idx].channels = channels;
3821
3822 // skip EDID configuration for HDMI backend
3823
3824 ALOGD("%s:becf: afe: %s set to %s", __func__,
3825 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl,
3826 channel_cnt_str);
3827 }
3828
3829 // skip set ext_display format mixer control
3830 return ret;
3831}
3832
3833static int platform_get_snd_device_bit_width(snd_device_t snd_device)
3834{
3835 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
3836 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
3837 return CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3838 }
3839
3840 return backend_bit_width_table[snd_device];
3841}
3842
3843/*
3844 * return backend_idx on which voice call is active
3845 */
3846static int platform_get_voice_call_backend(struct audio_device* adev)
3847{
3848 struct audio_usecase *uc = NULL;
3849 struct listnode *node;
3850 snd_device_t out_snd_device = SND_DEVICE_NONE;
3851
3852 int backend_idx = -1;
3853
3854 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
3855 list_for_each(node, &adev->usecase_list) {
3856 uc = node_to_item(node, struct audio_usecase, list);
3857 if (uc && uc->type == VOICE_CALL && uc->stream.out) {
3858 out_snd_device = platform_get_output_snd_device(adev->platform,
3859 uc->stream.out->devices);
3860 backend_idx = platform_get_backend_index(out_snd_device);
3861 break;
3862 }
3863 }
3864 }
3865 return backend_idx;
3866}
3867
3868/*
3869 * goes through all the current usecases and picks the highest
3870 * bitwidth & samplerate
3871 */
3872static bool platform_check_capture_backend_cfg(struct audio_device* adev,
3873 int backend_idx,
3874 struct audio_backend_cfg *backend_cfg)
3875{
3876 bool backend_change = false;
3877 unsigned int bit_width;
3878 unsigned int sample_rate;
3879 unsigned int channels;
3880 struct platform_data *my_data = (struct platform_data *)adev->platform;
3881
3882 bit_width = backend_cfg->bit_width;
3883 sample_rate = backend_cfg->sample_rate;
3884 channels = backend_cfg->channels;
3885
3886 ALOGV("%s:txbecf: afe: Codec selected backend: %d current bit width: %d and "
3887 "sample rate: %d, channels %d",__func__,backend_idx, bit_width,
3888 sample_rate, channels);
3889
3890 // For voice calls use default configuration i.e. 16b/48K, only applicable to
3891 // default backend
3892 // force routing is not required here, caller will do it anyway
3893 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
3894 ALOGW("%s:txbecf: afe: Use default bw and sr for voice/voip calls and "
3895 "for unprocessed/camera source", __func__);
3896 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3897 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3898 }
3899
3900 if (backend_idx == USB_AUDIO_TX_BACKEND) {
3901 audio_extn_usb_is_config_supported(&bit_width, &sample_rate, &channels, false);
3902 ALOGV("%s:txbecf: afe: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
3903 __func__, bit_width, sample_rate, channels);
3904 }
3905
3906 ALOGV("%s:txbecf: afe: Codec selected backend: %d updated bit width: %d and "
3907 "sample rate: %d", __func__, backend_idx, bit_width, sample_rate);
3908
3909 // Force routing if the expected bitwdith or samplerate
3910 // is not same as current backend comfiguration
3911 if ((bit_width != my_data->current_backend_cfg[backend_idx].bit_width) ||
3912 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate) ||
3913 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
3914 backend_cfg->bit_width = bit_width;
3915 backend_cfg->sample_rate= sample_rate;
3916 backend_cfg->channels = channels;
3917 backend_change = true;
3918 ALOGI("%s:txbecf: afe: Codec backend needs to be updated. new bit width: %d "
3919 "new sample rate: %d new channel: %d",
3920 __func__, backend_cfg->bit_width,
3921 backend_cfg->sample_rate, backend_cfg->channels);
3922 }
3923
3924 return backend_change;
3925}
3926
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003927static void pick_playback_cfg_for_uc(struct audio_device *adev,
3928 struct audio_usecase *usecase,
3929 snd_device_t snd_device,
3930 unsigned int *bit_width,
3931 unsigned int *sample_rate,
3932 unsigned int *channels)
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003933{
3934 int i =0;
3935 struct listnode *node;
3936 list_for_each(node, &adev->usecase_list) {
3937 struct audio_usecase *uc;
3938 uc = node_to_item(node, struct audio_usecase, list);
3939 struct stream_out *out = (struct stream_out*) uc->stream.out;
3940 if (uc->type == PCM_PLAYBACK && out && usecase != uc) {
3941 unsigned int out_channels = audio_channel_count_from_out_mask(out->channel_mask);
3942 ALOGV("%s:napb: (%d) - (%s)id (%d) sr %d bw "
3943 "(%d) ch (%d) device %s", __func__, i++, use_case_table[uc->id],
3944 uc->id, out->sample_rate,
3945 pcm_format_to_bits(out->config.format), out_channels,
3946 platform_get_snd_device_name(uc->out_snd_device));
3947
3948 if (platform_check_backends_match(snd_device, uc->out_snd_device)) {
3949 if (*bit_width < pcm_format_to_bits(out->config.format))
3950 *bit_width = pcm_format_to_bits(out->config.format);
3951 if (*sample_rate < out->sample_rate)
3952 *sample_rate = out->sample_rate;
3953 if (out->sample_rate < OUTPUT_SAMPLING_RATE_44100)
3954 *sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3955 if (*channels < out_channels)
3956 *channels = out_channels;
3957 }
3958 }
3959 }
3960 return;
3961}
3962
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003963static void headset_is_config_supported(unsigned int *bit_width,
3964 unsigned int *sample_rate,
3965 unsigned int *channels) {
3966 switch (*bit_width) {
3967 case 16:
3968 case 24:
3969 break;
3970 default:
3971 *bit_width = 16;
3972 break;
3973 }
3974
3975 if (*sample_rate > 192000) {
3976 *sample_rate = 192000;
3977 }
3978
3979 if (*channels > 2) {
3980 *channels = 2;
3981 }
3982}
3983
David Linee3fe402017-03-13 10:00:42 -07003984static bool platform_check_playback_backend_cfg(struct audio_device* adev,
3985 struct audio_usecase* usecase,
3986 snd_device_t snd_device,
3987 struct audio_backend_cfg *backend_cfg)
3988{
3989 bool backend_change = false;
David Linee3fe402017-03-13 10:00:42 -07003990 unsigned int bit_width;
3991 unsigned int sample_rate;
3992 unsigned int channels;
David Linee3fe402017-03-13 10:00:42 -07003993 int backend_idx = DEFAULT_CODEC_BACKEND;
Haynes Mathew George65f6b432018-02-27 17:44:55 -08003994 unsigned long service_interval = 0; // 0 is invalid
David Linee3fe402017-03-13 10:00:42 -07003995 struct platform_data *my_data = (struct platform_data *)adev->platform;
David Linee3fe402017-03-13 10:00:42 -07003996
3997 if (snd_device == SND_DEVICE_OUT_BT_SCO ||
3998 snd_device == SND_DEVICE_OUT_BT_SCO_WB) {
3999 backend_change = false;
4000 return backend_change;
4001 }
4002
4003 backend_idx = platform_get_backend_index(snd_device);
4004 bit_width = backend_cfg->bit_width;
4005 sample_rate = backend_cfg->sample_rate;
4006 channels = backend_cfg->channels;
4007
4008 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
4009 ", backend_idx %d usecase = %d device (%s)", __func__, bit_width,
4010 sample_rate, channels, backend_idx, usecase->id,
4011 platform_get_snd_device_name(snd_device));
4012
4013 if (backend_idx == platform_get_voice_call_backend(adev)) {
4014 ALOGW("%s:becf: afe:Use default bw and sr for voice/voip calls ",
4015 __func__);
4016 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
4017 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4018 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
4019 } else {
4020 /*
4021 * The backend should be configured at highest bit width and/or
4022 * sample rate amongst all playback usecases.
4023 * If the selected sample rate and/or bit width differ with
4024 * current backend sample rate and/or bit width, then, we set the
4025 * backend re-configuration flag.
4026 *
4027 * Exception: 16 bit playbacks is allowed through 16 bit/48/44.1 khz backend only
4028 */
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004029 pick_playback_cfg_for_uc(adev, usecase, snd_device,
4030 &bit_width,
4031 &sample_rate,
4032 &channels);
David Linee3fe402017-03-13 10:00:42 -07004033 }
4034
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004035 switch (backend_idx) {
4036 case USB_AUDIO_RX_BACKEND:
4037 audio_extn_usb_is_config_supported(&bit_width,
4038 &sample_rate, &channels, true);
Haynes Mathew George65f6b432018-02-27 17:44:55 -08004039 if (platform_get_usb_service_interval(adev->platform, true,
4040 &service_interval) == 0) {
4041 /* overwrite with best altset for this service interval */
4042 int ret =
4043 audio_extn_usb_altset_for_service_interval(true /*playback*/,
4044 service_interval,
4045 &bit_width,
4046 &sample_rate,
4047 &channels);
4048 if (ret < 0) {
4049 ALOGE("Failed to find altset for service interval %lu, skip reconfig",
4050 service_interval);
4051 return false;
4052 }
4053 }
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004054 ALOGV("%s: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
4055 __func__, bit_width, sample_rate, channels);
4056 break;
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004057 case HEADPHONE_BACKEND:
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004058 headset_is_config_supported(&bit_width, &sample_rate, &channels);
4059 break;
4060 case DEFAULT_CODEC_BACKEND:
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004061 default:
4062 bit_width = platform_get_snd_device_bit_width(snd_device);
4063 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4064 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
4065 break;
David Linee3fe402017-03-13 10:00:42 -07004066 }
4067
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004068 ALOGV("%s:becf: afe: Codec selected backend: %d updated bit width: %d and"
4069 "sample rate: %d",
David Linee3fe402017-03-13 10:00:42 -07004070 __func__, backend_idx , bit_width, sample_rate);
4071
4072 // Force routing if the expected bitwdith or samplerate
4073 // is not same as current backend comfiguration
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004074 if (bit_width != my_data->current_backend_cfg[backend_idx].bit_width ||
4075 sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate ||
4076 channels != my_data->current_backend_cfg[backend_idx].channels) {
David Linee3fe402017-03-13 10:00:42 -07004077 backend_cfg->bit_width = bit_width;
4078 backend_cfg->sample_rate = sample_rate;
4079 backend_cfg->channels = channels;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004080 backend_cfg->passthrough_enabled = false;
David Linee3fe402017-03-13 10:00:42 -07004081 backend_change = true;
4082 ALOGV("%s:becf: afe: Codec backend needs to be updated. new bit width: %d"
4083 "new sample rate: %d new channels: %d",
4084 __func__, backend_cfg->bit_width, backend_cfg->sample_rate, backend_cfg->channels);
4085 }
4086
4087 return backend_change;
4088}
4089
4090bool platform_check_and_set_playback_backend_cfg(struct audio_device* adev,
4091 struct audio_usecase *usecase, snd_device_t snd_device)
4092{
4093 int backend_idx = DEFAULT_CODEC_BACKEND;
4094 int new_snd_devices[SND_DEVICE_OUT_END];
4095 int i, num_devices = 1;
4096 bool ret = false;
4097 struct platform_data *my_data = (struct platform_data *)adev->platform;
4098 struct audio_backend_cfg backend_cfg;
4099
4100 backend_idx = platform_get_backend_index(snd_device);
4101
4102 backend_cfg.bit_width = pcm_format_to_bits(usecase->stream.out->config.format);
4103 backend_cfg.sample_rate = usecase->stream.out->sample_rate;
4104 backend_cfg.format = usecase->stream.out->format;
4105 backend_cfg.channels = audio_channel_count_from_out_mask(usecase->stream.out->channel_mask);
4106 /*this is populated by check_codec_backend_cfg hence set default value to false*/
4107 backend_cfg.passthrough_enabled = false;
4108
4109 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
4110 ", backend_idx %d usecase = %d device (%s)", __func__, backend_cfg.bit_width,
4111 backend_cfg.sample_rate, backend_cfg.channels, backend_idx, usecase->id,
4112 platform_get_snd_device_name(snd_device));
4113
4114 if (platform_can_split_snd_device(snd_device, &num_devices, new_snd_devices) < 0)
4115 new_snd_devices[0] = snd_device;
4116
4117 for (i = 0; i < num_devices; i++) {
4118 ALOGV("%s: new_snd_devices[%d] is %d", __func__, i, new_snd_devices[i]);
4119 if ((platform_check_playback_backend_cfg(adev, usecase, new_snd_devices[i],
4120 &backend_cfg))) {
4121 platform_set_backend_cfg(adev, new_snd_devices[i],
4122 &backend_cfg);
4123 ret = true;
4124 }
4125 }
4126 return ret;
4127}
4128
4129bool platform_check_and_set_capture_backend_cfg(struct audio_device* adev,
4130 struct audio_usecase *usecase, snd_device_t snd_device)
4131{
4132 int backend_idx = platform_get_backend_index(snd_device);
4133 int ret = 0;
4134 struct audio_backend_cfg backend_cfg;
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004135 memset(&backend_cfg, 0, sizeof(struct audio_backend_cfg));
David Linee3fe402017-03-13 10:00:42 -07004136
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004137 if (usecase->type == PCM_CAPTURE) {
4138 backend_cfg.format = usecase->stream.in->format;
David Linee3fe402017-03-13 10:00:42 -07004139 backend_cfg.channels = audio_channel_count_from_in_mask(usecase->stream.in->channel_mask);
4140 } else {
4141 backend_cfg.bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
4142 backend_cfg.sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4143 backend_cfg.format = AUDIO_FORMAT_PCM_16_BIT;
4144 backend_cfg.channels = 1;
4145 }
4146
4147 ALOGV("%s:txbecf: afe: bitwidth %d, samplerate %d, channel %d"
4148 ", backend_idx %d usecase = %d device (%s)", __func__,
4149 backend_cfg.bit_width,
4150 backend_cfg.sample_rate,
4151 backend_cfg.channels,
4152 backend_idx, usecase->id,
4153 platform_get_snd_device_name(snd_device));
4154
4155 if (platform_check_capture_backend_cfg(adev, backend_idx, &backend_cfg)) {
4156 ret = platform_set_backend_cfg(adev, snd_device,
4157 &backend_cfg);
4158 if(!ret)
4159 return true;
4160 }
4161
4162 return false;
4163}
4164
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004165static int max_be_dai_names = 0;
4166static const struct be_dai_name_struct *be_dai_name_table;
4167
4168/*
4169 * Retrieves the be_dai_name_table from kernel to enable a mapping
4170 * between sound device hw interfaces and backend IDs. This allows HAL to
4171 * specify the backend a specific calibration is needed for.
4172 */
4173static int init_be_dai_name_table(struct audio_device *adev)
4174{
4175 const char *mixer_ctl_name = "Backend DAI Name Table";
4176 struct mixer_ctl *ctl;
4177 int i, j, ret, size;
4178 bool valid_hw_interface;
4179
4180 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
4181 if (!ctl) {
4182 ALOGE("%s: Could not get ctl for mixer name %s\n",
4183 __func__, mixer_ctl_name);
4184 ret = -EINVAL;
4185 goto done;
4186 }
4187
4188 mixer_ctl_update(ctl);
4189
4190 size = mixer_ctl_get_num_values(ctl);
4191 if (size <= 0){
4192 ALOGE("%s: Failed to get %s size %d\n",
4193 __func__, mixer_ctl_name, size);
4194 ret = -EFAULT;
4195 goto done;
4196 }
4197
vivek mehtaa68fea62017-06-08 19:04:02 -07004198 be_dai_name_table =
4199 (const struct be_dai_name_struct *)calloc(1, size);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004200 if (be_dai_name_table == NULL) {
4201 ALOGE("%s: Failed to allocate memory for %s\n",
4202 __func__, mixer_ctl_name);
4203 ret = -ENOMEM;
4204 goto freeMem;
4205 }
4206
4207 ret = mixer_ctl_get_array(ctl, (void *)be_dai_name_table, size);
4208 if (ret) {
4209 ALOGE("%s: Failed to get %s, ret %d\n",
4210 __func__, mixer_ctl_name, ret);
4211 ret = -EFAULT;
4212 goto freeMem;
4213 }
4214
4215 if (be_dai_name_table != NULL) {
4216 max_be_dai_names = size / sizeof(struct be_dai_name_struct);
4217 ALOGV("%s: Successfully got %s, number of be dais is %d\n",
4218 __func__, mixer_ctl_name, max_be_dai_names);
4219 ret = 0;
4220 } else {
4221 ALOGE("%s: Failed to get %s\n", __func__, mixer_ctl_name);
4222 ret = -EFAULT;
4223 goto freeMem;
4224 }
4225
4226 /*
4227 * Validate all sound devices have a valid backend set to catch
4228 * errors for uncommon sound devices
4229 */
4230 for (i = 0; i < SND_DEVICE_MAX; i++) {
4231 valid_hw_interface = false;
4232
4233 if (hw_interface_table[i] == NULL) {
4234 ALOGW("%s: sound device %s has no hw interface set\n",
4235 __func__, platform_get_snd_device_name(i));
4236 continue;
4237 }
4238
4239 for (j = 0; j < max_be_dai_names; j++) {
4240 if (strcmp(hw_interface_table[i], be_dai_name_table[j].be_name)
4241 == 0) {
4242 valid_hw_interface = true;
4243 break;
4244 }
4245 }
4246 if (!valid_hw_interface)
4247 ALOGD("%s: sound device %s does not have a valid hw interface set "
4248 "(disregard for combo devices) %s\n",
4249 __func__, platform_get_snd_device_name(i),
4250 hw_interface_table[i]);
4251 }
4252
4253 goto done;
4254
4255freeMem:
4256 if (be_dai_name_table) {
4257 free((void *)be_dai_name_table);
4258 be_dai_name_table = NULL;
4259 }
4260
4261done:
4262 return ret;
4263}
4264
4265int platform_get_snd_device_backend_index(snd_device_t device)
4266{
4267 int i, be_dai_id;
4268 const char * hw_interface_name = NULL;
4269
4270 ALOGV("%s: enter with device %d\n", __func__, device);
4271
vivek mehtaa68fea62017-06-08 19:04:02 -07004272 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004273 ALOGE("%s: Invalid snd_device = %d",
4274 __func__, device);
4275 be_dai_id = -EINVAL;
4276 goto done;
4277 }
4278
4279 /* Get string value of necessary backend for device */
4280 hw_interface_name = hw_interface_table[device];
4281 if (hw_interface_name == NULL) {
4282 ALOGE("%s: no hw_interface set for device %d\n", __func__, device);
4283 be_dai_id = -EINVAL;
4284 goto done;
4285 }
4286
4287 /* Check if be dai name table was retrieved successfully */
4288 if (be_dai_name_table == NULL) {
4289 ALOGE("%s: BE DAI Name Table is not present\n", __func__);
4290 be_dai_id = -EFAULT;
4291 goto done;
4292 }
4293
4294 /* Get backend ID for device specified */
4295 for (i = 0; i < max_be_dai_names; i++) {
4296 if (strcmp(hw_interface_name, be_dai_name_table[i].be_name) == 0) {
4297 be_dai_id = be_dai_name_table[i].be_id;
4298 goto done;
4299 }
4300 }
4301 ALOGE("%s: no interface matching name %s\n", __func__, hw_interface_name);
4302 be_dai_id = -EINVAL;
4303 goto done;
4304
4305done:
4306 return be_dai_id;
4307}
4308
4309void platform_check_and_update_copp_sample_rate(void* platform, snd_device_t snd_device,
4310 unsigned int stream_sr, int* sample_rate)
4311{
4312 struct platform_data* my_data = (struct platform_data *)platform;
4313 int backend_idx = platform_get_backend_index(snd_device);
4314 int device_sr = my_data->current_backend_cfg[backend_idx].sample_rate;
4315 /*
4316 *Check if device SR is multiple of 8K or 11.025 Khz
4317 *check if the stream SR is multiple of same base, if yes
4318 *then have copp SR equal to stream SR, this ensures that
4319 *post processing happens at stream SR, else have
4320 *copp SR equal to device SR.
4321 */
4322 if (!(((sample_rate_multiple(device_sr, SAMPLE_RATE_8000)) &&
4323 (sample_rate_multiple(stream_sr, SAMPLE_RATE_8000))) ||
4324 ((sample_rate_multiple(device_sr, SAMPLE_RATE_11025)) &&
4325 (sample_rate_multiple(stream_sr, SAMPLE_RATE_11025))))) {
4326 *sample_rate = device_sr;
4327 } else
4328 *sample_rate = stream_sr;
4329
4330 ALOGI("sn_device %d device sr %d stream sr %d copp sr %d", snd_device, device_sr, stream_sr
4331 , *sample_rate);
4332
4333}
4334
4335// called from info parser
vivek mehtaa68fea62017-06-08 19:04:02 -07004336void platform_add_app_type(const char *uc_type,
4337 const char *mode,
4338 int bw,
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004339 int app_type, int max_rate) {
4340 struct app_type_entry *ap =
4341 (struct app_type_entry *)calloc(1, sizeof(struct app_type_entry));
4342
4343 if (!ap) {
4344 ALOGE("%s failed to allocate mem for app type", __func__);
4345 return;
4346 }
4347
4348 ap->uc_type = -1;
4349 for (int i=0; i<USECASE_TYPE_MAX; i++) {
4350 if (!strcmp(uc_type, usecase_type_index[i].name)) {
4351 ap->uc_type = usecase_type_index[i].index;
4352 break;
4353 }
4354 }
4355
4356 if (ap->uc_type == -1) {
4357 free(ap);
4358 return;
4359 }
4360
vivek mehtaa68fea62017-06-08 19:04:02 -07004361 ALOGI("%s uc %s mode %s bw %d app_type %d max_rate %d",
4362 __func__, uc_type, mode, bw, app_type, max_rate);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004363 ap->bit_width = bw;
4364 ap->app_type = app_type;
4365 ap->max_rate = max_rate;
vivek mehtaa68fea62017-06-08 19:04:02 -07004366 ap->mode = strdup(mode);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004367 list_add_tail(&app_type_entry_list, &ap->node);
4368}
4369
4370
4371int platform_get_default_app_type_v2(void *platform __unused,
4372 usecase_type_t type,
4373 int *app_type )
4374{
4375 if (type == PCM_PLAYBACK)
4376 *app_type = DEFAULT_APP_TYPE_RX_PATH;
4377 else
4378 *app_type = DEFAULT_APP_TYPE_TX_PATH;
4379 return 0;
4380}
4381
vivek mehtaa68fea62017-06-08 19:04:02 -07004382int platform_get_app_type_v2(void *platform,
4383 usecase_type_t uc_type,
4384 const char *mode,
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004385 int bw, int sr __unused,
4386 int *app_type)
4387{
4388 struct listnode *node;
4389 struct app_type_entry *entry;
4390 *app_type = -1;
vivek mehtaa68fea62017-06-08 19:04:02 -07004391
4392 ALOGV("%s find match for uc %d mode %s bw %d rate %d",
4393 __func__, uc_type, mode, bw, sr);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004394 list_for_each(node, &app_type_entry_list) {
4395 entry = node_to_item(node, struct app_type_entry, node);
vivek mehtaa68fea62017-06-08 19:04:02 -07004396 ALOGV("%s uc %d mode %s bw %d app_type %d max_rate %d",
4397 __func__, entry->uc_type, entry->mode, entry->bit_width,
4398 entry->app_type, entry->max_rate);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004399 if (entry->bit_width == bw &&
vivek mehtaa68fea62017-06-08 19:04:02 -07004400 entry->uc_type == uc_type &&
4401 sr <= entry->max_rate &&
4402 entry->mode && !strcmp(mode, entry->mode)) {
4403 ALOGV("%s found match %d", __func__, entry->app_type);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004404 *app_type = entry->app_type;
4405 break;
4406 }
4407 }
4408
4409 if (*app_type == -1) {
vivek mehtaa68fea62017-06-08 19:04:02 -07004410 ALOGV("%s no match found, return default", __func__);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004411 return platform_get_default_app_type_v2(platform, uc_type, app_type);
4412 }
4413 return 0;
4414}
vivek mehta90933872017-06-15 18:04:39 -07004415
4416int platform_set_sidetone(struct audio_device *adev,
4417 snd_device_t out_snd_device,
4418 bool enable, char *str)
4419{
4420 int ret;
4421 if (out_snd_device == SND_DEVICE_OUT_USB_HEADSET ||
4422 out_snd_device == SND_DEVICE_OUT_VOICE_USB_HEADSET) {
4423 ret = audio_extn_usb_enable_sidetone(out_snd_device, enable);
4424 if (ret)
4425 ALOGI("%s: usb device %d does not support device sidetone\n",
4426 __func__, out_snd_device);
4427 } else {
4428 ALOGV("%s: sidetone out device(%d) mixer cmd = %s\n",
4429 __func__, out_snd_device, str);
4430 if (enable)
4431 audio_route_apply_and_update_path(adev->audio_route, str);
4432 else
4433 audio_route_reset_and_update_path(adev->audio_route, str);
4434 }
4435 return 0;
4436}
Haynes Mathew George96483a22017-03-28 14:52:47 -07004437
4438int platform_get_mmap_data_fd(void *platform __unused, int fe_dev __unused, int dir __unused,
4439 int *fd __unused, uint32_t *size __unused)
4440{
Alexey Polyudove920d4b2017-09-15 17:09:07 -07004441#if defined (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845)
Haynes Mathew George96483a22017-03-28 14:52:47 -07004442 struct platform_data *my_data = (struct platform_data *)platform;
4443 struct audio_device *adev = my_data->adev;
4444 int hw_fd = -1;
4445 char dev_name[128];
4446 struct snd_pcm_mmap_fd mmap_fd;
4447 memset(&mmap_fd, 0, sizeof(mmap_fd));
4448 mmap_fd.dir = dir;
4449 snprintf(dev_name, sizeof(dev_name), "/dev/snd/hwC%uD%u",
4450 adev->snd_card, HWDEP_FE_BASE+fe_dev);
4451 hw_fd = open(dev_name, O_RDONLY);
4452 if (hw_fd < 0) {
4453 ALOGE("fe hw dep node open %d/%d failed", adev->snd_card, fe_dev);
4454 return -1;
4455 }
4456 if (ioctl(hw_fd, SNDRV_PCM_IOCTL_MMAP_DATA_FD, &mmap_fd) < 0) {
4457 ALOGE("fe hw dep node ioctl failed");
4458 close(hw_fd);
4459 return -1;
4460 }
4461 *fd = mmap_fd.fd;
4462 *size = mmap_fd.size;
4463 close(hw_fd); // mmap_fd should still be valid
4464 return 0;
4465#else
4466 return -1;
4467#endif
4468}
Mikhail Naganov4ee6e3e2018-03-21 16:28:35 +00004469
4470bool platform_sound_trigger_usecase_needs_event(audio_usecase_t uc_id)
4471{
4472 bool needs_event = false;
4473
4474 switch (uc_id) {
4475 /* concurrent capture usecases which needs event */
4476 case USECASE_AUDIO_RECORD:
4477 case USECASE_AUDIO_RECORD_LOW_LATENCY:
4478 case USECASE_AUDIO_RECORD_MMAP:
4479 case USECASE_AUDIO_RECORD_HIFI:
4480 case USECASE_AUDIO_RECORD_VOIP:
4481 case USECASE_VOICEMMODE1_CALL:
4482 case USECASE_VOICEMMODE2_CALL:
4483 /* concurrent playback usecases that needs event */
4484 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
4485 case USECASE_AUDIO_PLAYBACK_OFFLOAD:
4486 needs_event = true;
4487 break;
4488 default:
4489 ALOGV("%s:usecase_id[%d] no need to raise event.", __func__, uc_id);
4490 }
4491 return needs_event;
4492}
4493
4494bool platform_snd_device_has_speaker(snd_device_t dev) {
4495 int num_devs = 2;
4496 snd_device_t split_devs[2] = {SND_DEVICE_NONE, SND_DEVICE_NONE};
4497 if (platform_can_split_snd_device(dev, &num_devs, split_devs) == 0) {
4498 return platform_snd_device_has_speaker(split_devs[0]) ||
4499 platform_snd_device_has_speaker(split_devs[1]);
4500 }
4501
4502 switch (dev) {
4503 case SND_DEVICE_OUT_SPEAKER:
4504 case SND_DEVICE_OUT_SPEAKER_SAFE:
4505 case SND_DEVICE_OUT_SPEAKER_REVERSE:
4506 case SND_DEVICE_OUT_SPEAKER_PROTECTED:
4507 case SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED:
4508 case SND_DEVICE_OUT_VOICE_SPEAKER_HFP:
4509 return true;
4510 default:
4511 break;
4512 }
4513 return false;
4514}
jiabin8962a4d2018-03-19 18:21:24 -07004515
4516bool platform_set_microphone_characteristic(void *platform,
4517 struct audio_microphone_characteristic_t mic) {
4518 struct platform_data *my_data = (struct platform_data *)platform;
4519 if (my_data->declared_mic_count >= AUDIO_MICROPHONE_MAX_COUNT) {
4520 ALOGE("mic number is more than maximum number");
4521 return false;
4522 }
4523 for (size_t ch = 0; ch < AUDIO_CHANNEL_COUNT_MAX; ch++) {
4524 mic.channel_mapping[ch] = AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED;
4525 }
4526 my_data->microphones[my_data->declared_mic_count++] = mic;
4527 return true;
4528}
4529
4530int platform_get_microphones(void *platform,
4531 struct audio_microphone_characteristic_t *mic_array,
4532 size_t *mic_count) {
4533 struct platform_data *my_data = (struct platform_data *)platform;
4534 if (mic_count == NULL) {
4535 return -EINVAL;
4536 }
4537 if (mic_array == NULL) {
4538 return -EINVAL;
4539 }
4540
4541 if (*mic_count == 0) {
4542 *mic_count = my_data->declared_mic_count;
4543 return 0;
4544 }
4545
4546 size_t max_mic_count = *mic_count;
4547 size_t actual_mic_count = 0;
4548 for (size_t i = 0; i < max_mic_count && i < my_data->declared_mic_count; i++) {
4549 mic_array[i] = my_data->microphones[i];
4550 actual_mic_count++;
4551 }
4552 *mic_count = actual_mic_count;
4553 return 0;
4554}
4555
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004556bool platform_set_microphone_map(void *platform, snd_device_t in_snd_device,
4557 const struct mic_info *info) {
4558 struct platform_data *my_data = (struct platform_data *)platform;
4559 if (in_snd_device < SND_DEVICE_IN_BEGIN || in_snd_device >= SND_DEVICE_IN_END) {
4560 ALOGE("%s: Sound device not valid", __func__);
4561 return false;
4562 }
4563 size_t m_count = my_data->mic_map[in_snd_device].mic_count++;
4564 if (m_count >= AUDIO_MICROPHONE_MAX_COUNT) {
4565 ALOGE("%s: Microphone count is greater than max allowed value", __func__);
4566 my_data->mic_map[in_snd_device].mic_count--;
4567 return false;
4568 }
4569 my_data->mic_map[in_snd_device].microphones[m_count] = *info;
4570 return true;
4571}
4572
4573int platform_get_active_microphones(void *platform, unsigned int channels,
4574 audio_usecase_t uc_id,
jiabin8962a4d2018-03-19 18:21:24 -07004575 struct audio_microphone_characteristic_t *mic_array,
4576 size_t *mic_count) {
4577 struct platform_data *my_data = (struct platform_data *)platform;
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004578 struct audio_usecase *usecase = get_usecase_from_list(my_data->adev, uc_id);
4579 if (mic_count == NULL || mic_array == NULL || usecase == NULL) {
jiabin8962a4d2018-03-19 18:21:24 -07004580 return -EINVAL;
4581 }
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004582 size_t max_mic_count = my_data->declared_mic_count;
jiabin8962a4d2018-03-19 18:21:24 -07004583 size_t actual_mic_count = 0;
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004584
4585 snd_device_t active_input_snd_device =
4586 platform_get_input_snd_device(platform, usecase->stream.in->device);
4587 if (active_input_snd_device == SND_DEVICE_NONE) {
4588 ALOGI("%s: No active microphones found", __func__);
4589 goto end;
4590 }
4591
4592 size_t active_mic_count = my_data->mic_map[active_input_snd_device].mic_count;
4593 struct mic_info *m_info = my_data->mic_map[active_input_snd_device].microphones;
4594
4595 for (size_t i = 0; i < active_mic_count; i++) {
4596 unsigned int channels_for_active_mic = channels;
4597 if (channels_for_active_mic > m_info[i].channel_count) {
4598 channels_for_active_mic = m_info[i].channel_count;
4599 }
4600 for (size_t j = 0; j < max_mic_count; j++) {
4601 if (strcmp(my_data->microphones[j].device_id,
4602 m_info[i].device_id) == 0) {
4603 mic_array[actual_mic_count] = my_data->microphones[j];
4604 for (size_t ch = 0; ch < channels_for_active_mic; ch++) {
4605 mic_array[actual_mic_count].channel_mapping[ch] =
4606 m_info[i].channel_mapping[ch];
4607 }
4608 actual_mic_count++;
4609 break;
jiabin8962a4d2018-03-19 18:21:24 -07004610 }
jiabin8962a4d2018-03-19 18:21:24 -07004611 }
4612 }
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004613end:
jiabin8962a4d2018-03-19 18:21:24 -07004614 *mic_count = actual_mic_count;
4615 return 0;
4616}
Haynes Mathew George65f6b432018-02-27 17:44:55 -08004617
4618int platform_set_usb_service_interval(void *platform,
4619 bool playback,
4620 unsigned long service_interval,
4621 bool *reconfig)
4622{
4623#if defined (USB_SERVICE_INTERVAL_ENABLED)
4624 struct platform_data *_platform = (struct platform_data *)platform;
4625 *reconfig = false;
4626 if (!playback) {
4627 ALOGE("%s not valid for capture", __func__);
4628 return -1;
4629 }
4630 const char *ctl_name = "USB_AUDIO_RX service_interval";
4631 struct mixer_ctl *ctl = mixer_get_ctl_by_name(_platform->adev->mixer,
4632 ctl_name);
4633 if (!ctl) {
4634 ALOGV("%s: could not get mixer %s", __func__, ctl_name);
4635 return -1;
4636 }
4637 if (mixer_ctl_get_value(ctl, 0) != (int)service_interval) {
4638 mixer_ctl_set_value(ctl, 0, service_interval);
4639 *reconfig = true;
4640 }
4641 return 0;
4642#else
4643 *reconfig = false;
4644 (void)platform;
4645 (void)playback;
4646 (void)service_interval;
4647 return -1;
4648#endif
4649}
4650
4651int platform_get_usb_service_interval(void *platform,
4652 bool playback,
4653 unsigned long *service_interval)
4654{
4655#if defined (USB_SERVICE_INTERVAL_ENABLED)
4656 struct platform_data *_platform = (struct platform_data *)platform;
4657 if (!playback) {
4658 ALOGE("%s not valid for capture", __func__);
4659 return -1;
4660 }
4661 const char *ctl_name = "USB_AUDIO_RX service_interval";
4662 struct mixer_ctl *ctl = mixer_get_ctl_by_name(_platform->adev->mixer,
4663 ctl_name);
4664 if (!ctl) {
4665 ALOGV("%s: could not get mixer %s", __func__, ctl_name);
4666 return -1;
4667 }
4668 *service_interval = mixer_ctl_get_value(ctl, 0);
4669 return 0;
4670#else
4671 (void)platform;
4672 (void)playback;
4673 (void)service_interval;
4674 return -1;
4675#endif
4676}