blob: 87aba23d286f285e912e264943911b19806b40e1 [file] [log] [blame]
Eric Laurentb23d5282013-05-14 15:27:20 -07001/*
vivek mehtaa6b79742017-03-09 15:40:43 -08002 * Copyright (C) 2013-2017 The Android Open Source Project
Eric Laurentb23d5282013-05-14 15:27:20 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Eric Laurentb23d5282013-05-14 15:27:20 -070016#define LOG_TAG "msm8974_platform"
17/*#define LOG_NDEBUG 0*/
18#define LOG_NDDEBUG 0
19
20#include <stdlib.h>
21#include <dlfcn.h>
Jiyong Park6431fe62017-06-29 15:15:58 +090022#include <pthread.h>
23#include <unistd.h>
Haynes Mathew Georgee6e2d442018-02-22 18:51:56 -080024#include <log/log.h>
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -070025#include <cutils/str_parms.h>
Eric Laurentb23d5282013-05-14 15:27:20 -070026#include <cutils/properties.h>
27#include <audio_hw.h>
28#include <platform_api.h>
vivek mehta0fb11312017-05-15 19:35:32 -070029#include "acdb.h"
Eric Laurentb23d5282013-05-14 15:27:20 -070030#include "platform.h"
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -070031#include "audio_extn.h"
vivek mehta1a9b7c02015-06-25 11:49:38 -070032#include <linux/msm_audio.h>
Thierry Strudel07f96d12018-09-20 13:31:34 -070033#if defined (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845) || (PLATFORM_SDM710) || (PLATFORM_SM8150)
Haynes Mathew George96483a22017-03-28 14:52:47 -070034#include <sound/devdep_params.h>
35#endif
Eric Laurentb23d5282013-05-14 15:27:20 -070036
jasmine cha270b7762018-03-30 15:41:33 +080037#include "maxxaudio.h"
jasmine chac89321b2018-04-10 21:37:01 +080038#include <resolv.h>
39
Jaekyun Seokf62e17d2017-03-08 17:15:28 +090040#define MIXER_XML_DEFAULT_PATH "mixer_paths.xml"
41#define MIXER_XML_BASE_STRING "mixer_paths"
vivek mehta60ea4152016-02-18 17:10:26 -080042#define TOMTOM_8226_SND_CARD_NAME "msm8226-tomtom-snd-card"
43#define TOMTOM_MIXER_FILE_SUFFIX "wcd9330"
44
Eric Laurentb23d5282013-05-14 15:27:20 -070045#define LIB_ACDB_LOADER "libacdbloader.so"
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -070046#define AUDIO_DATA_BLOCK_MIXER_CTL "HDMI EDID"
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +090047#define CVD_VERSION_MIXER_CTL "CVD Version"
Eric Laurentb23d5282013-05-14 15:27:20 -070048
Eric Laurentf9583c32016-03-28 13:50:50 -070049#define min(a, b) ((a) < (b) ? (a) : (b))
Eric Laurentb23d5282013-05-14 15:27:20 -070050
51/*
Eric Laurentb23d5282013-05-14 15:27:20 -070052 * This file will have a maximum of 38 bytes:
53 *
54 * 4 bytes: number of audio blocks
55 * 4 bytes: total length of Short Audio Descriptor (SAD) blocks
56 * Maximum 10 * 3 bytes: SAD blocks
57 */
58#define MAX_SAD_BLOCKS 10
59#define SAD_BLOCK_SIZE 3
60
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +090061#define MAX_CVD_VERSION_STRING_SIZE 100
62
Eric Laurentb23d5282013-05-14 15:27:20 -070063/* EDID format ID for LPCM audio */
64#define EDID_FORMAT_LPCM 1
65
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -070066#define MAX_SND_CARD_NAME_LEN 31
67
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -080068#define DEFAULT_APP_TYPE_RX_PATH 69936
69#define DEFAULT_APP_TYPE_TX_PATH 69938
Haynes Mathew George39c55dc2017-07-11 19:31:23 -070070#define DEFAULT_RX_BACKEND "SLIMBUS_0_RX"
vivek mehta1a9b7c02015-06-25 11:49:38 -070071
keunhui.parkc5aaa0e2015-07-13 10:57:37 +090072#define TOSTRING_(x) #x
73#define TOSTRING(x) TOSTRING_(x)
74
Eric Laurentb23d5282013-05-14 15:27:20 -070075struct audio_block_header
76{
77 int reserved;
78 int length;
79};
80
vivek mehta1a9b7c02015-06-25 11:49:38 -070081enum {
82 CAL_MODE_SEND = 0x1,
83 CAL_MODE_PERSIST = 0x2,
84 CAL_MODE_RTAC = 0x4
85};
86
keunhui.park2f7306a2015-07-16 16:48:06 +090087#define PLATFORM_CONFIG_KEY_OPERATOR_INFO "operator_info"
88
89struct operator_info {
90 struct listnode list;
91 char *name;
92 char *mccmnc;
93};
94
95struct operator_specific_device {
96 struct listnode list;
97 char *operator;
98 char *mixer_path;
99 int acdb_id;
100};
101
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800102#define BE_DAI_NAME_MAX_LENGTH 24
103struct be_dai_name_struct {
104 unsigned int be_id;
105 char be_name[BE_DAI_NAME_MAX_LENGTH];
106};
107
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -0700108struct snd_device_to_mic_map {
109 struct mic_info microphones[AUDIO_MICROPHONE_MAX_COUNT];
110 size_t mic_count;
111};
112
keunhui.park2f7306a2015-07-16 16:48:06 +0900113static struct listnode operator_info_list;
114static struct listnode *operator_specific_device_table[SND_DEVICE_MAX];
115
jasmine chac89321b2018-04-10 21:37:01 +0800116#define AUDIO_PARAMETER_KEY_AUD_CALDATA "cal_data"
117
118typedef struct acdb_audio_cal_cfg {
119 uint32_t persist;
120 uint32_t snd_dev_id;
121 audio_devices_t dev_id;
122 int32_t acdb_dev_id;
123 uint32_t app_type;
124 uint32_t topo_id;
125 uint32_t sampling_rate;
126 uint32_t cal_type;
127 uint32_t module_id;
128 uint32_t param_id;
129} acdb_audio_cal_cfg_t;
130
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700131/* Audio calibration related functions */
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800132typedef void (*acdb_send_audio_cal_v3_t)(int, int, int, int, int);
Eric Laurentb23d5282013-05-14 15:27:20 -0700133
Eric Laurentb23d5282013-05-14 15:27:20 -0700134struct platform_data {
135 struct audio_device *adev;
136 bool fluence_in_spkr_mode;
137 bool fluence_in_voice_call;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700138 bool fluence_in_voice_comm;
Eric Laurentb23d5282013-05-14 15:27:20 -0700139 bool fluence_in_voice_rec;
Prashant Malanic92c5962015-08-11 15:10:18 -0700140 /* 0 = no fluence, 1 = fluence, 2 = fluence pro */
141 int fluence_type;
142 int source_mic_type;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -0700143 bool speaker_lr_swap;
144
Eric Laurentb23d5282013-05-14 15:27:20 -0700145 void *acdb_handle;
Thierry Strudel07f96d12018-09-20 13:31:34 -0700146#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845) || (PLATFORM_SDM710) || (PLATFORM_SM8150)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -0700147 acdb_init_v2_cvd_t acdb_init;
148#elif defined (PLATFORM_MSM8084)
149 acdb_init_v2_t acdb_init;
150#else
151 acdb_init_t acdb_init;
152#endif
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700153 acdb_deallocate_t acdb_deallocate;
154 acdb_send_audio_cal_t acdb_send_audio_cal;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800155 acdb_send_audio_cal_v3_t acdb_send_audio_cal_v3;
jasmine chac89321b2018-04-10 21:37:01 +0800156 acdb_set_audio_cal_t acdb_set_audio_cal;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700157 acdb_send_voice_cal_t acdb_send_voice_cal;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700158 acdb_reload_vocvoltable_t acdb_reload_vocvoltable;
vivek mehta1a9b7c02015-06-25 11:49:38 -0700159 acdb_send_gain_dep_cal_t acdb_send_gain_dep_cal;
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -0700160 acdb_send_custom_top_t acdb_send_custom_top;
161 bool acdb_initialized;
162
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700163 struct csd_data *csd;
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800164 char ec_ref_mixer_path[64];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700165
David Linee3fe402017-03-13 10:00:42 -0700166 codec_backend_cfg_t current_backend_cfg[MAX_CODEC_BACKENDS];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700167 char *snd_card_name;
keunhui.parkc5aaa0e2015-07-13 10:57:37 +0900168 int max_vol_index;
Prashant Malanic92c5962015-08-11 15:10:18 -0700169 int max_mic_count;
vivek mehtade4849c2016-03-03 17:23:38 -0800170
171 void *hw_info;
jiabin8962a4d2018-03-19 18:21:24 -0700172
173 uint32_t declared_mic_count;
174 struct audio_microphone_characteristic_t microphones[AUDIO_MICROPHONE_MAX_COUNT];
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -0700175 struct snd_device_to_mic_map mic_map[SND_DEVICE_MAX];
Eric Laurentb23d5282013-05-14 15:27:20 -0700176};
177
Haynes Mathew George98c95622014-06-20 19:14:25 -0700178static int pcm_device_table[AUDIO_USECASE_MAX][2] = {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700179 [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = {DEEP_BUFFER_PCM_DEVICE,
180 DEEP_BUFFER_PCM_DEVICE},
181 [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
182 LOWLATENCY_PCM_DEVICE},
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800183 [USECASE_AUDIO_PLAYBACK_HIFI] = {MULTIMEDIA2_PCM_DEVICE,
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700184 MULTIMEDIA2_PCM_DEVICE},
185 [USECASE_AUDIO_PLAYBACK_OFFLOAD] = {PLAYBACK_OFFLOAD_DEVICE,
186 PLAYBACK_OFFLOAD_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700187 [USECASE_AUDIO_PLAYBACK_TTS] = {MULTIMEDIA2_PCM_DEVICE,
188 MULTIMEDIA2_PCM_DEVICE},
189 [USECASE_AUDIO_PLAYBACK_ULL] = {MULTIMEDIA3_PCM_DEVICE,
190 MULTIMEDIA3_PCM_DEVICE},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800191 [USECASE_AUDIO_PLAYBACK_MMAP] = {MMAP_PLAYBACK_PCM_DEVICE,
192 MMAP_PLAYBACK_PCM_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700193
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700194 [USECASE_AUDIO_RECORD] = {AUDIO_RECORD_PCM_DEVICE,
195 AUDIO_RECORD_PCM_DEVICE},
196 [USECASE_AUDIO_RECORD_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
197 LOWLATENCY_PCM_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700198
Eric Laurent0e46adf2016-12-16 12:49:24 -0800199 [USECASE_AUDIO_RECORD_MMAP] = {MMAP_RECORD_PCM_DEVICE,
200 MMAP_RECORD_PCM_DEVICE},
Haynes Mathew George569b7482017-05-08 14:44:27 -0700201 [USECASE_AUDIO_RECORD_HIFI] = {MULTIMEDIA2_PCM_DEVICE,
202 MULTIMEDIA2_PCM_DEVICE},
203
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700204 [USECASE_VOICE_CALL] = {VOICE_CALL_PCM_DEVICE,
205 VOICE_CALL_PCM_DEVICE},
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700206 [USECASE_VOICE2_CALL] = {VOICE2_CALL_PCM_DEVICE, VOICE2_CALL_PCM_DEVICE},
207 [USECASE_VOLTE_CALL] = {VOLTE_CALL_PCM_DEVICE, VOLTE_CALL_PCM_DEVICE},
208 [USECASE_QCHAT_CALL] = {QCHAT_CALL_PCM_DEVICE, QCHAT_CALL_PCM_DEVICE},
209 [USECASE_VOWLAN_CALL] = {VOWLAN_CALL_PCM_DEVICE, VOWLAN_CALL_PCM_DEVICE},
vivek mehtaa51fd402016-02-04 19:49:33 -0800210 [USECASE_VOICEMMODE1_CALL] = {VOICEMMODE1_CALL_PCM_DEVICE,
211 VOICEMMODE1_CALL_PCM_DEVICE},
212 [USECASE_VOICEMMODE2_CALL] = {VOICEMMODE2_CALL_PCM_DEVICE,
213 VOICEMMODE2_CALL_PCM_DEVICE},
214
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700215 [USECASE_INCALL_REC_UPLINK] = {AUDIO_RECORD_PCM_DEVICE,
216 AUDIO_RECORD_PCM_DEVICE},
217 [USECASE_INCALL_REC_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
218 AUDIO_RECORD_PCM_DEVICE},
219 [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
220 AUDIO_RECORD_PCM_DEVICE},
Ravi Kumar Alamanda8e6e98f2013-11-05 15:57:39 -0800221 [USECASE_AUDIO_HFP_SCO] = {HFP_PCM_RX, HFP_SCO_RX},
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700222
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700223 [USECASE_AUDIO_SPKR_CALIB_RX] = {SPKR_PROT_CALIB_RX_PCM_DEVICE, -1},
224 [USECASE_AUDIO_SPKR_CALIB_TX] = {-1, SPKR_PROT_CALIB_TX_PCM_DEVICE},
225
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700226 [USECASE_AUDIO_PLAYBACK_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
227 AFE_PROXY_RECORD_PCM_DEVICE},
228 [USECASE_AUDIO_RECORD_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
229 AFE_PROXY_RECORD_PCM_DEVICE},
zhaoyang yin4211fad2015-06-04 21:13:25 +0800230 [USECASE_AUDIO_DSM_FEEDBACK] = {QUAT_MI2S_PCM_DEVICE, QUAT_MI2S_PCM_DEVICE},
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700231
vivek mehtaa68fea62017-06-08 19:04:02 -0700232 [USECASE_AUDIO_PLAYBACK_VOIP] = {AUDIO_PLAYBACK_VOIP_PCM_DEVICE,
233 AUDIO_PLAYBACK_VOIP_PCM_DEVICE},
234 [USECASE_AUDIO_RECORD_VOIP] = {AUDIO_RECORD_VOIP_PCM_DEVICE,
235 AUDIO_RECORD_VOIP_PCM_DEVICE},
Nadav Bar3d72cfc2018-01-07 12:19:24 +0200236
237 [USECASE_INCALL_MUSIC_UPLINK] = {INCALL_MUSIC_UPLINK_PCM_DEVICE,
238 INCALL_MUSIC_UPLINK_PCM_DEVICE},
Eric Laurentb23d5282013-05-14 15:27:20 -0700239};
240
241/* Array to store sound devices */
242static const char * const device_table[SND_DEVICE_MAX] = {
243 [SND_DEVICE_NONE] = "none",
244 /* Playback sound devices */
245 [SND_DEVICE_OUT_HANDSET] = "handset",
246 [SND_DEVICE_OUT_SPEAKER] = "speaker",
247 [SND_DEVICE_OUT_SPEAKER_REVERSE] = "speaker-reverse",
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700248 [SND_DEVICE_OUT_SPEAKER_SAFE] = "speaker-safe",
Eric Laurentb23d5282013-05-14 15:27:20 -0700249 [SND_DEVICE_OUT_HEADPHONES] = "headphones",
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500250 [SND_DEVICE_OUT_LINE] = "line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700251 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones",
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700252 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = "speaker-safe-and-headphones",
Eric Laurent744996b2014-10-01 11:40:40 -0500253 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = "speaker-and-line",
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700254 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = "speaker-safe-and-line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700255 [SND_DEVICE_OUT_VOICE_HANDSET] = "voice-handset",
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500256 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = "voice-hac-handset",
Eric Laurentb23d5282013-05-14 15:27:20 -0700257 [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker",
258 [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones",
yixuanjiang9536e672018-09-06 18:43:36 +0800259 [SND_DEVICE_OUT_VOICE_HEADSET] = "voice-headphones",
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500260 [SND_DEVICE_OUT_VOICE_LINE] = "voice-line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700261 [SND_DEVICE_OUT_HDMI] = "hdmi",
262 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi",
263 [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700264 [SND_DEVICE_OUT_BT_SCO_WB] = "bt-sco-headset-wb",
Aniket Kumar Lata26483012018-01-31 20:21:42 -0800265 [SND_DEVICE_OUT_BT_A2DP] = "bt-a2dp",
266 [SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] = "speaker-and-bt-a2dp",
Aniket Kumar Lata9723a962018-05-16 17:41:55 -0700267 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP] = "speaker-safe-and-bt-a2dp",
Eric Laurentb23d5282013-05-14 15:27:20 -0700268 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = "voice-handset-tmus",
269 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones",
270 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones",
271 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset",
vivek mehtaa6b79742017-03-09 15:40:43 -0800272 [SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = "voice-tty-full-usb",
273 [SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = "voice-tty-vco-usb",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700274 [SND_DEVICE_OUT_VOICE_TX] = "voice-tx",
juyuchen66c4ecf2018-08-06 15:39:34 +0800275 [SND_DEVICE_OUT_VOICE_MUSIC_TX] = "voice-music-tx",
David Linee3fe402017-03-13 10:00:42 -0700276 [SND_DEVICE_OUT_USB_HEADSET] = "usb-headset",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700277 [SND_DEVICE_OUT_VOICE_USB_HEADSET] = "usb-headset",
David Linee3fe402017-03-13 10:00:42 -0700278 [SND_DEVICE_OUT_USB_HEADPHONES] = "usb-headphones",
jasmine cha270b7762018-03-30 15:41:33 +0800279 [SND_DEVICE_OUT_USB_HEADSET_SPEC] = "usb-headset",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700280 [SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = "usb-headphones",
David Linee3fe402017-03-13 10:00:42 -0700281 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = "speaker-and-usb-headphones",
Haynes Mathew George9090bfb2017-05-31 11:44:50 -0700282 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] = "speaker-safe-and-usb-headphones",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700283 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = "speaker-protected",
284 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = "voice-speaker-protected",
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -0700285 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = "voice-speaker-hfp",
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -0800286 [SND_DEVICE_OUT_SPEAKER_AND_BT_SCO] = "speaker-and-bt-sco",
juyuchen5351ea62018-05-16 10:54:37 +0800287 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO] = "speaker-safe-and-bt-sco",
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -0800288 [SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB] = "speaker-and-bt-sco-wb",
juyuchen5351ea62018-05-16 10:54:37 +0800289 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB] = "speaker-safe-and-bt-sco-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700290
291 /* Capture sound devices */
292 [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700293 [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700294 [SND_DEVICE_IN_HANDSET_MIC_NS] = "handset-mic",
295 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = "handset-mic",
296 [SND_DEVICE_IN_HANDSET_DMIC] = "dmic-endfire",
297 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = "dmic-endfire",
298 [SND_DEVICE_IN_HANDSET_DMIC_NS] = "dmic-endfire",
299 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = "dmic-endfire",
300 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = "dmic-endfire",
301
302 [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
303 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "speaker-mic",
304 [SND_DEVICE_IN_SPEAKER_MIC_NS] = "speaker-mic",
305 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = "speaker-mic",
306 [SND_DEVICE_IN_SPEAKER_DMIC] = "speaker-dmic-endfire",
307 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = "speaker-dmic-endfire",
308 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = "speaker-dmic-endfire",
309 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = "speaker-dmic-endfire",
310 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = "speaker-dmic-endfire",
311
312 [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
Eric Laurentcefbbac2014-09-04 13:54:10 -0500313 [SND_DEVICE_IN_HEADSET_MIC_AEC] = "headset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700314
Eric Laurentb23d5282013-05-14 15:27:20 -0700315 [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic",
316 [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700317 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = "bt-sco-mic",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700318 [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700319 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = "bt-sco-mic-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700320 [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700321
322 [SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef",
323 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = "voice-dmic-ef-tmus",
324 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
325 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = "voice-speaker-dmic-ef",
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -0700326 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = "voice-speaker-mic-hfp",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700327 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700328 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
329 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
330 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
vivek mehtaa6b79742017-03-09 15:40:43 -0800331 [SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = "voice-tty-full-usb-mic",
332 [SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = "voice-tty-hco-usb-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700333
Eric Laurentb23d5282013-05-14 15:27:20 -0700334 [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700335 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = "voice-rec-mic",
vivek mehta733c1df2016-04-04 15:09:24 -0700336 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = "voice-rec-mic",
vivek mehtaf3440682016-05-11 14:24:37 -0700337 [SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700338 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = "voice-rec-dmic-ef",
339 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence",
David Linee3fe402017-03-13 10:00:42 -0700340 [SND_DEVICE_IN_USB_HEADSET_MIC] = "usb-headset-mic",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700341 [SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] ="usb-headset-mic",
342 [SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = "usb-headset-mic",
343 [SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = "usb-headset-mic",
344 [SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = "usb-headset-mic",
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700345 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = "headset-mic",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700346
Ricardo Garcia9034bc42016-04-04 07:11:46 -0700347 [SND_DEVICE_IN_UNPROCESSED_MIC] = "unprocessed-mic",
vivek mehta0125e782016-06-16 18:03:11 -0700348 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = "unprocessed-stereo-mic",
349 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = "unprocessed-three-mic",
350 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = "unprocessed-quad-mic",
351 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = "unprocessed-headset-mic",
rago90fb9612015-12-02 11:37:53 -0800352
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700353 [SND_DEVICE_IN_VOICE_RX] = "voice-rx",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700354
Prashant Malanic92c5962015-08-11 15:10:18 -0700355 [SND_DEVICE_IN_THREE_MIC] = "three-mic",
356 [SND_DEVICE_IN_QUAD_MIC] = "quad-mic",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700357 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = "vi-feedback",
Prashant Malanic92c5962015-08-11 15:10:18 -0700358 [SND_DEVICE_IN_HANDSET_TMIC] = "three-mic",
359 [SND_DEVICE_IN_HANDSET_QMIC] = "quad-mic",
vivek mehta733c1df2016-04-04 15:09:24 -0700360 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = "three-mic",
361 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = "quad-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700362};
363
364/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700365static int acdb_device_table[SND_DEVICE_MAX] = {
Eric Laurentb23d5282013-05-14 15:27:20 -0700366 [SND_DEVICE_NONE] = -1,
367 [SND_DEVICE_OUT_HANDSET] = 7,
368 [SND_DEVICE_OUT_SPEAKER] = 15,
369 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 15,
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700370 [SND_DEVICE_OUT_SPEAKER_SAFE] = 15,
Eric Laurentb23d5282013-05-14 15:27:20 -0700371 [SND_DEVICE_OUT_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500372 [SND_DEVICE_OUT_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700373 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700374 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500375 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = 77,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700376 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = 77,
Ravi Kumar Alamanda235c3482014-08-21 17:32:44 -0700377 [SND_DEVICE_OUT_VOICE_HANDSET] = ACDB_ID_VOICE_HANDSET,
378 [SND_DEVICE_OUT_VOICE_SPEAKER] = ACDB_ID_VOICE_SPEAKER,
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500379 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = 53,
Eric Laurentb23d5282013-05-14 15:27:20 -0700380 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
yixuanjiang9536e672018-09-06 18:43:36 +0800381 [SND_DEVICE_OUT_VOICE_HEADSET] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500382 [SND_DEVICE_OUT_VOICE_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700383 [SND_DEVICE_OUT_HDMI] = 18,
384 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 15,
385 [SND_DEVICE_OUT_BT_SCO] = 22,
juyuchen5351ea62018-05-16 10:54:37 +0800386 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO] = 14,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700387 [SND_DEVICE_OUT_BT_SCO_WB] = 39,
juyuchen5351ea62018-05-16 10:54:37 +0800388 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB] = 14,
Aniket Kumar Lata26483012018-01-31 20:21:42 -0800389 [SND_DEVICE_OUT_BT_A2DP] = 20,
390 [SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] = 14,
Aniket Kumar Lata9723a962018-05-16 17:41:55 -0700391 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP] = 14,
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700392 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = ACDB_ID_VOICE_HANDSET_TMUS,
Eric Laurentb23d5282013-05-14 15:27:20 -0700393 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
394 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
395 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
vivek mehtaa6b79742017-03-09 15:40:43 -0800396 [SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = 17,
397 [SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = 17,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700398 [SND_DEVICE_OUT_VOICE_TX] = 45,
juyuchen66c4ecf2018-08-06 15:39:34 +0800399 [SND_DEVICE_OUT_VOICE_MUSIC_TX] = 3,
David Linee3fe402017-03-13 10:00:42 -0700400 [SND_DEVICE_OUT_USB_HEADSET] = 45,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700401 [SND_DEVICE_OUT_VOICE_USB_HEADSET] = 45,
David Linee3fe402017-03-13 10:00:42 -0700402 [SND_DEVICE_OUT_USB_HEADPHONES] = 45,
jasmine cha270b7762018-03-30 15:41:33 +0800403 [SND_DEVICE_OUT_USB_HEADSET_SPEC] = 45,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700404 [SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = 45,
David Linee3fe402017-03-13 10:00:42 -0700405 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = 14,
Haynes Mathew George9090bfb2017-05-31 11:44:50 -0700406 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] = 14,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700407 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = 124,
408 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = 101,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700409 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = ACDB_ID_VOICE_SPEAKER,
Eric Laurentb23d5282013-05-14 15:27:20 -0700410
411 [SND_DEVICE_IN_HANDSET_MIC] = 4,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700412 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 106,
413 [SND_DEVICE_IN_HANDSET_MIC_NS] = 107,
414 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = 108,
415 [SND_DEVICE_IN_HANDSET_DMIC] = 41,
416 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = 109,
417 [SND_DEVICE_IN_HANDSET_DMIC_NS] = 110,
418 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = 111,
419 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = 34,
420
421 [SND_DEVICE_IN_SPEAKER_MIC] = 11,
422 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 112,
423 [SND_DEVICE_IN_SPEAKER_MIC_NS] = 113,
424 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = 114,
425 [SND_DEVICE_IN_SPEAKER_DMIC] = 43,
426 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = 115,
427 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = 116,
428 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = 117,
429 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = 35,
430
rago90fb9612015-12-02 11:37:53 -0800431 [SND_DEVICE_IN_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentcefbbac2014-09-04 13:54:10 -0500432 [SND_DEVICE_IN_HEADSET_MIC_AEC] = ACDB_ID_HEADSET_MIC_AEC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700433
Eric Laurentb23d5282013-05-14 15:27:20 -0700434 [SND_DEVICE_IN_HDMI_MIC] = 4,
435 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700436 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = 21,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700437 [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700438 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = 38,
Eric Laurentb23d5282013-05-14 15:27:20 -0700439 [SND_DEVICE_IN_CAMCORDER_MIC] = 61,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700440
441 [SND_DEVICE_IN_VOICE_DMIC] = 41,
442 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = ACDB_ID_VOICE_DMIC_EF_TMUS,
443 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700444 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = 11,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700445 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 43,
rago90fb9612015-12-02 11:37:53 -0800446 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentb23d5282013-05-14 15:27:20 -0700447 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
448 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
449 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
vivek mehtaa6b79742017-03-09 15:40:43 -0800450 [SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = 16,
451 [SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = 16,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700452
rago90fb9612015-12-02 11:37:53 -0800453 [SND_DEVICE_IN_VOICE_REC_MIC] = ACDB_ID_VOICE_REC_MIC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700454 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = 113,
vivek mehta733c1df2016-04-04 15:09:24 -0700455 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = 112,
vivek mehtaf3440682016-05-11 14:24:37 -0700456 [SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = 114,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700457 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = 35,
458 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 43,
rago90fb9612015-12-02 11:37:53 -0800459 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
460
461 [SND_DEVICE_IN_UNPROCESSED_MIC] = ACDB_ID_VOICE_REC_MIC,
462 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
vivek mehta4ed66e62016-04-15 23:33:34 -0700463 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = 35,
464 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = 125,
465 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = 125,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700466
467 [SND_DEVICE_IN_VOICE_RX] = 44,
David Linee3fe402017-03-13 10:00:42 -0700468 [SND_DEVICE_IN_USB_HEADSET_MIC] = 44,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700469 [SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = 44,
470 [SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = 44,
471 [SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = 44,
472 [SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = 44,
Prashant Malanic92c5962015-08-11 15:10:18 -0700473 [SND_DEVICE_IN_THREE_MIC] = 46,
474 [SND_DEVICE_IN_QUAD_MIC] = 46,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700475 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = 102,
Prashant Malanic92c5962015-08-11 15:10:18 -0700476 [SND_DEVICE_IN_HANDSET_TMIC] = 125,
477 [SND_DEVICE_IN_HANDSET_QMIC] = 125,
vivek mehta733c1df2016-04-04 15:09:24 -0700478 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = 125, /* override this for new target to 140 */
479 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = 125, /* override this for new target to 140 */
Eric Laurentb23d5282013-05-14 15:27:20 -0700480};
481
David Linee3fe402017-03-13 10:00:42 -0700482// Platform specific backend bit width table
483static int backend_bit_width_table[SND_DEVICE_MAX] = {0};
484
Haynes Mathew George98c95622014-06-20 19:14:25 -0700485struct name_to_index {
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700486 char name[100];
487 unsigned int index;
488};
489
490#define TO_NAME_INDEX(X) #X, X
491
Haynes Mathew George98c95622014-06-20 19:14:25 -0700492/* Used to get index from parsed string */
493static const struct name_to_index snd_device_name_index[SND_DEVICE_MAX] = {
494 /* out */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700495 {TO_NAME_INDEX(SND_DEVICE_OUT_HANDSET)},
496 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER)},
497 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_REVERSE)},
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700498 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700499 {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500500 {TO_NAME_INDEX(SND_DEVICE_OUT_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700501 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700502 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES)},
Eric Laurent744996b2014-10-01 11:40:40 -0500503 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_LINE)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700504 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700505 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET)},
506 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700507 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_HFP)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700508 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADPHONES)},
yixuanjiang9536e672018-09-06 18:43:36 +0800509 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADSET)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500510 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700511 {TO_NAME_INDEX(SND_DEVICE_OUT_HDMI)},
512 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HDMI)},
513 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO)},
juyuchen5351ea62018-05-16 10:54:37 +0800514 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700515 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO_WB)},
juyuchen5351ea62018-05-16 10:54:37 +0800516 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB)},
Aniket Kumar Lata26483012018-01-31 20:21:42 -0800517 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_A2DP)},
518 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP)},
Aniket Kumar Lata9723a962018-05-16 17:41:55 -0700519 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700520 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET_TMUS)},
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500521 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HAC_HANDSET)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700522 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES)},
523 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES)},
524 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET)},
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -0800525 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_SCO)},
526 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800527 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_USB)},
528 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_USB)},
David Linee3fe402017-03-13 10:00:42 -0700529 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADSET)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700530 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_USB_HEADSET)},
David Linee3fe402017-03-13 10:00:42 -0700531 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADPHONES)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700532 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_USB_HEADPHONES)},
David Linee3fe402017-03-13 10:00:42 -0700533 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET)},
Haynes Mathew George9090bfb2017-05-31 11:44:50 -0700534 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700535 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED)},
536 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED)},
jasmine cha270b7762018-03-30 15:41:33 +0800537 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADSET_SPEC)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800538
539 /* in */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700540 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700541 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700542 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_NS)},
543 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)},
544 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC)},
545 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC)},
546 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_NS)},
547 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)},
548 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_STEREO)},
549
550 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700551 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700552 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_NS)},
553 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)},
554 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC)},
555 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC)},
556 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS)},
557 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)},
558 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_STEREO)},
559
560 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC)},
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700561 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700562
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700563 {TO_NAME_INDEX(SND_DEVICE_IN_HDMI_MIC)},
564 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700565 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700566 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700567 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700568 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700569
570 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC)},
571 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC_TMUS)},
572 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700573 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700574 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC)},
575 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEADSET_MIC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700576 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC)},
577 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC)},
578 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800579 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC)},
580 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC)},
581
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700582
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700583 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700584 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_NS)},
vivek mehta733c1df2016-04-04 15:09:24 -0700585 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC)},
vivek mehtaf3440682016-05-11 14:24:37 -0700586 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700587 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_STEREO)},
588 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE)},
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700589 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_HEADSET_MIC)},
David Linee3fe402017-03-13 10:00:42 -0700590 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700591 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_USB_HEADSET_MIC)},
592 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC)},
593 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC)},
594 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC_AEC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700595
rago90fb9612015-12-02 11:37:53 -0800596 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_MIC)},
597 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC)},
vivek mehta4ed66e62016-04-15 23:33:34 -0700598 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_STEREO_MIC)},
599 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_THREE_MIC)},
600 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_QUAD_MIC)},
rago90fb9612015-12-02 11:37:53 -0800601
Prashant Malanic92c5962015-08-11 15:10:18 -0700602 {TO_NAME_INDEX(SND_DEVICE_IN_THREE_MIC)},
603 {TO_NAME_INDEX(SND_DEVICE_IN_QUAD_MIC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700604 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_VI_FEEDBACK)},
Prashant Malanic92c5962015-08-11 15:10:18 -0700605 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC)},
606 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC)},
vivek mehta733c1df2016-04-04 15:09:24 -0700607 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC_AEC)},
608 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC_AEC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700609};
610
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700611static char * backend_tag_table[SND_DEVICE_MAX] = {0};
612static char * hw_interface_table[SND_DEVICE_MAX] = {0};
Haynes Mathew George98c95622014-06-20 19:14:25 -0700613
614static const struct name_to_index usecase_name_index[AUDIO_USECASE_MAX] = {
615 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_DEEP_BUFFER)},
616 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_LOW_LATENCY)},
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800617 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_HIFI)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700618 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD)},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700619 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_TTS)},
620 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_ULL)},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800621 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_MMAP)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700622 {TO_NAME_INDEX(USECASE_AUDIO_RECORD)},
623 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_LOW_LATENCY)},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800624 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_MMAP)},
Haynes Mathew George569b7482017-05-08 14:44:27 -0700625 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_HIFI)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700626 {TO_NAME_INDEX(USECASE_VOICE_CALL)},
627 {TO_NAME_INDEX(USECASE_VOICE2_CALL)},
628 {TO_NAME_INDEX(USECASE_VOLTE_CALL)},
629 {TO_NAME_INDEX(USECASE_QCHAT_CALL)},
630 {TO_NAME_INDEX(USECASE_VOWLAN_CALL)},
John Muirf1346ce2016-12-06 00:03:41 -0800631 {TO_NAME_INDEX(USECASE_VOICEMMODE1_CALL)},
632 {TO_NAME_INDEX(USECASE_VOICEMMODE2_CALL)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700633 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK)},
634 {TO_NAME_INDEX(USECASE_INCALL_REC_DOWNLINK)},
635 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK_AND_DOWNLINK)},
636 {TO_NAME_INDEX(USECASE_AUDIO_HFP_SCO)},
John Muirf1346ce2016-12-06 00:03:41 -0800637 {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_RX)},
638 {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_TX)},
639 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_AFE_PROXY)},
640 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_AFE_PROXY)},
641 {TO_NAME_INDEX(USECASE_AUDIO_DSM_FEEDBACK)},
vivek mehtaa68fea62017-06-08 19:04:02 -0700642 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_VOIP)},
643 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_VOIP)},
Nadav Bar3d72cfc2018-01-07 12:19:24 +0200644 {TO_NAME_INDEX(USECASE_INCALL_MUSIC_UPLINK)},
Aniket Kumar Lata99546312018-03-19 21:38:38 -0700645 {TO_NAME_INDEX(USECASE_AUDIO_A2DP_ABR_FEEDBACK)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700646};
647
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800648static const struct name_to_index usecase_type_index[USECASE_TYPE_MAX] = {
649 {TO_NAME_INDEX(PCM_PLAYBACK)},
650 {TO_NAME_INDEX(PCM_CAPTURE)},
651 {TO_NAME_INDEX(VOICE_CALL)},
652 {TO_NAME_INDEX(PCM_HFP_CALL)},
653};
654
655struct app_type_entry {
656 int uc_type;
657 int bit_width;
658 int app_type;
659 int max_rate;
vivek mehtaa68fea62017-06-08 19:04:02 -0700660 char *mode;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800661 struct listnode node; // membership in app_type_entry_list;
662};
663
664static struct listnode app_type_entry_list;
665
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700666#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
667#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
Eric Laurent0e46adf2016-12-16 12:49:24 -0800668#define ULL_PLATFORM_DELAY (3*1000LL)
669#define MMAP_PLATFORM_DELAY (3*1000LL)
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700670
Eric Laurentb23d5282013-05-14 15:27:20 -0700671static pthread_once_t check_op_once_ctl = PTHREAD_ONCE_INIT;
672static bool is_tmus = false;
673
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800674static int init_be_dai_name_table(struct audio_device *adev);
675
Eric Laurentb23d5282013-05-14 15:27:20 -0700676static void check_operator()
677{
678 char value[PROPERTY_VALUE_MAX];
679 int mccmnc;
680 property_get("gsm.sim.operator.numeric",value,"0");
681 mccmnc = atoi(value);
Eric Laurent2bafff12016-03-17 12:17:23 -0700682 ALOGD("%s: tmus mccmnc %d", __func__, mccmnc);
Eric Laurentb23d5282013-05-14 15:27:20 -0700683 switch(mccmnc) {
684 /* TMUS MCC(310), MNC(490, 260, 026) */
685 case 310490:
686 case 310260:
687 case 310026:
sangwon.jeonb891db52013-09-14 17:39:15 +0900688 /* Add new TMUS MNC(800, 660, 580, 310, 270, 250, 240, 230, 220, 210, 200, 160) */
689 case 310800:
690 case 310660:
691 case 310580:
692 case 310310:
693 case 310270:
694 case 310250:
695 case 310240:
696 case 310230:
697 case 310220:
698 case 310210:
699 case 310200:
700 case 310160:
Eric Laurentb23d5282013-05-14 15:27:20 -0700701 is_tmus = true;
702 break;
703 }
704}
705
706bool is_operator_tmus()
707{
708 pthread_once(&check_op_once_ctl, check_operator);
709 return is_tmus;
710}
711
keunhui.park2f7306a2015-07-16 16:48:06 +0900712static char *get_current_operator()
713{
714 struct listnode *node;
715 struct operator_info *info_item;
716 char mccmnc[PROPERTY_VALUE_MAX];
717 char *ret = NULL;
718
Tom Cherry7fea2042016-11-10 18:05:59 -0800719 property_get("gsm.sim.operator.numeric",mccmnc,"00000");
keunhui.park2f7306a2015-07-16 16:48:06 +0900720
721 list_for_each(node, &operator_info_list) {
722 info_item = node_to_item(node, struct operator_info, list);
723 if (strstr(info_item->mccmnc, mccmnc) != NULL) {
724 ret = info_item->name;
725 }
726 }
727
728 return ret;
729}
730
731static struct operator_specific_device *get_operator_specific_device(snd_device_t snd_device)
732{
733 struct listnode *node;
734 struct operator_specific_device *ret = NULL;
735 struct operator_specific_device *device_item;
736 char *operator_name;
737
738 operator_name = get_current_operator();
739 if (operator_name == NULL)
740 return ret;
741
742 list_for_each(node, operator_specific_device_table[snd_device]) {
743 device_item = node_to_item(node, struct operator_specific_device, list);
744 if (strcmp(operator_name, device_item->operator) == 0) {
745 ret = device_item;
746 }
747 }
748
749 return ret;
750}
751
752
753static int get_operator_specific_device_acdb_id(snd_device_t snd_device)
754{
755 struct operator_specific_device *device;
756 int ret = acdb_device_table[snd_device];
757
758 device = get_operator_specific_device(snd_device);
759 if (device != NULL)
760 ret = device->acdb_id;
761
762 return ret;
763}
764
765static const char *get_operator_specific_device_mixer_path(snd_device_t snd_device)
766{
767 struct operator_specific_device *device;
768 const char *ret = device_table[snd_device];
769
770 device = get_operator_specific_device(snd_device);
771 if (device != NULL)
772 ret = device->mixer_path;
773
774 return ret;
775}
776
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800777inline bool platform_supports_app_type_cfg()
778{
Thierry Strudel07f96d12018-09-20 13:31:34 -0700779#if defined (PLATFORM_MSM8998) || (PLATFORM_SDM845) || (PLATFORM_SDM710) || (PLATFORM_SM8150)
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800780 return true;
781#else
782 return false;
783#endif
784}
785
jasmine chac89321b2018-04-10 21:37:01 +0800786static int parse_audiocal_cfg(struct str_parms *parms, acdb_audio_cal_cfg_t *cal)
787{
788 int err;
789 char value[64];
790 int ret = 0;
791
792 if (parms == NULL || cal == NULL)
793 return ret;
794
795 err = str_parms_get_str(parms, "cal_persist", value, sizeof(value));
796 if (err >= 0) {
797 str_parms_del(parms, "cal_persist");
798 cal->persist = (uint32_t)strtoul(value, NULL, 0);
799 ret = ret | 0x1;
800 }
801 err = str_parms_get_str(parms, "cal_apptype", value, sizeof(value));
802 if (err >= 0) {
803 str_parms_del(parms, "cal_apptype");
804 cal->app_type = (uint32_t)strtoul(value, NULL, 0);
805 ret = ret | 0x2;
806 }
807 err = str_parms_get_str(parms, "cal_caltype", value, sizeof(value));
808 if (err >= 0) {
809 str_parms_del(parms, "cal_caltype");
810 cal->cal_type = (uint32_t)strtoul(value, NULL, 0);
811 ret = ret | 0x4;
812 }
813 err = str_parms_get_str(parms, "cal_samplerate", value, sizeof(value));
814 if (err >= 0) {
815 str_parms_del(parms, "cal_samplerate");
816 cal->sampling_rate = (uint32_t)strtoul(value, NULL, 0);
817 ret = ret | 0x8;
818 }
819 err = str_parms_get_str(parms, "cal_devid", value, sizeof(value));
820 if (err >= 0) {
821 str_parms_del(parms, "cal_devid");
822 cal->dev_id = (uint32_t)strtoul(value, NULL, 0);
823 ret = ret | 0x10;
824 }
825 err = str_parms_get_str(parms, "cal_snddevid", value, sizeof(value));
826 if (err >= 0) {
827 str_parms_del(parms, "cal_snddevid");
828 cal->snd_dev_id = (uint32_t)strtoul(value, NULL, 0);
829 ret = ret | 0x20;
830 }
831 err = str_parms_get_str(parms, "cal_topoid", value, sizeof(value));
832 if (err >= 0) {
833 str_parms_del(parms, "cal_topoid");
834 cal->topo_id = (uint32_t)strtoul(value, NULL, 0);
835 ret = ret | 0x40;
836 }
837 err = str_parms_get_str(parms, "cal_moduleid", value, sizeof(value));
838 if (err >= 0) {
839 str_parms_del(parms, "cal_moduleid");
840 cal->module_id = (uint32_t)strtoul(value, NULL, 0);
841 ret = ret | 0x80;
842 }
843 err = str_parms_get_str(parms, "cal_paramid", value, sizeof(value));
844 if (err >= 0) {
845 str_parms_del(parms, "cal_paramid");
846 cal->param_id = (uint32_t)strtoul(value, NULL, 0);
847 ret = ret | 0x100;
848 }
849 return ret;
850}
851
852static void set_audiocal(void *platform, struct str_parms *parms, char *value, int len)
853{
854 struct platform_data *my_data = (struct platform_data *)platform;
855 acdb_audio_cal_cfg_t cal;
856 uint8_t *dptr = NULL;
857 int32_t dlen = 0;
858 int err ,ret;
859
860 if (value == NULL || platform == NULL || parms == NULL) {
861 ALOGE("[%s] received null pointer, failed", __func__);
862 goto done_key_audcal;
863 }
864
865 memset(&cal, 0, sizeof(acdb_audio_cal_cfg_t));
866 /* parse audio calibration keys */
867 ret = parse_audiocal_cfg(parms, &cal);
868
869 /* handle audio calibration data now */
870 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_AUD_CALDATA, value, len);
871 if (err >= 0) {
872 str_parms_del(parms, AUDIO_PARAMETER_KEY_AUD_CALDATA);
873 dlen = strlen(value);
874 if (dlen <= 0) {
875 ALOGE("[%s] null data received", __func__);
876 goto done_key_audcal;
877 }
878 /*
879 The base64 encoded string is always larger than the binary data,
880 so b64_pton will always output less data than provided (around 1/3
881 less than the input data). That's why we can allocate input buffer
882 length and then get function work.
883 */
884 dptr = (uint8_t *)calloc(dlen, sizeof(uint8_t));
885 if (dptr == NULL) {
886 ALOGE("[%s] memory allocation failed for %d", __func__, dlen);
887 goto done_key_audcal;
888 }
889 dlen = b64_pton(value, dptr, dlen);
890 if (dlen <= 0) {
891 ALOGE("[%s] data decoding failed %d", __func__, dlen);
892 goto done_key_audcal;
893 }
894
895 if (cal.dev_id) {
896 if (audio_is_input_device(cal.dev_id)) {
897 cal.snd_dev_id = platform_get_input_snd_device(platform, cal.dev_id);
898 } else {
899 cal.snd_dev_id = platform_get_output_snd_device(platform, cal.dev_id);
900 }
901 }
902 cal.acdb_dev_id = platform_get_snd_device_acdb_id(cal.snd_dev_id);
903 ALOGD("Setting audio calibration for snd_device(%d) acdb_id(%d)",
904 cal.snd_dev_id, cal.acdb_dev_id);
905 if (cal.acdb_dev_id == -EINVAL) {
906 ALOGE("[%s] Invalid acdb_device id %d for snd device id %d",
907 __func__, cal.acdb_dev_id, cal.snd_dev_id);
908 goto done_key_audcal;
909 }
910 if (my_data->acdb_set_audio_cal) {
911 ret = my_data->acdb_set_audio_cal((void *)&cal, (void *)dptr, dlen);
912 }
913 }
914done_key_audcal:
915 if (dptr != NULL)
916 free(dptr);
917}
918
vivek mehta1a9b7c02015-06-25 11:49:38 -0700919bool platform_send_gain_dep_cal(void *platform, int level)
920{
921 bool ret_val = false;
922 struct platform_data *my_data = (struct platform_data *)platform;
923 struct audio_device *adev = my_data->adev;
924 int acdb_dev_id, app_type;
925 int acdb_dev_type = MSM_SNDDEV_CAP_RX;
926 int mode = CAL_MODE_RTAC;
927 struct listnode *node;
928 struct audio_usecase *usecase;
Haynes Mathew George67486e22017-06-26 12:58:38 -0700929 bool valid_uc_type;
930 bool valid_dev;
vivek mehta1a9b7c02015-06-25 11:49:38 -0700931
932 if (my_data->acdb_send_gain_dep_cal == NULL) {
933 ALOGE("%s: dlsym error for acdb_send_gain_dep_cal", __func__);
934 return ret_val;
935 }
936
937 if (!voice_is_in_call(adev)) {
938 ALOGV("%s: Not Voice call usecase, apply new cal for level %d",
939 __func__, level);
vivek mehta1a9b7c02015-06-25 11:49:38 -0700940
941 // find the current active sound device
942 list_for_each(node, &adev->usecase_list) {
943 usecase = node_to_item(node, struct audio_usecase, list);
Haynes Mathew George67486e22017-06-26 12:58:38 -0700944 LOG_ALWAYS_FATAL_IF(usecase == NULL,
945 "unxpected NULL usecase in usecase_list");
946 valid_uc_type = usecase->type == PCM_PLAYBACK;
947 valid_dev = false;
948 if (valid_uc_type) {
949 audio_devices_t dev = usecase->stream.out->devices;
950 valid_dev = (dev == AUDIO_DEVICE_OUT_SPEAKER ||
vivek mehta40125092017-08-21 18:48:51 -0700951 dev == AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Haynes Mathew George67486e22017-06-26 12:58:38 -0700952 dev == AUDIO_DEVICE_OUT_WIRED_HEADSET ||
953 dev == AUDIO_DEVICE_OUT_WIRED_HEADPHONE);
954 }
955 if (valid_dev) {
vivek mehta40125092017-08-21 18:48:51 -0700956 ALOGV("%s: out device is %d", __func__, usecase->out_snd_device);
957 if (platform_supports_app_type_cfg())
958 app_type = usecase->stream.out->app_type_cfg.app_type;
959 else
960 app_type = DEFAULT_APP_TYPE_RX_PATH;
vivek mehta4cb82982015-07-13 12:05:49 -0700961
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -0700962 acdb_dev_id = platform_get_snd_device_acdb_id(usecase->out_snd_device);
vivek mehta40125092017-08-21 18:48:51 -0700963
964 if (!my_data->acdb_send_gain_dep_cal(acdb_dev_id, app_type,
vivek mehta1a9b7c02015-06-25 11:49:38 -0700965 acdb_dev_type, mode, level)) {
966 // set ret_val true if at least one calibration is set successfully
967 ret_val = true;
968 } else {
969 ALOGE("%s: my_data->acdb_send_gain_dep_cal failed ", __func__);
970 }
971 } else {
972 ALOGW("%s: Usecase list is empty", __func__);
973 }
974 }
975 } else {
976 ALOGW("%s: Voice call in progress .. ignore setting new cal",
977 __func__);
978 }
979 return ret_val;
980}
981
Eric Laurentcefbbac2014-09-04 13:54:10 -0500982void platform_set_echo_reference(struct audio_device *adev, bool enable, audio_devices_t out_device)
Eric Laurentb23d5282013-05-14 15:27:20 -0700983{
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800984 struct platform_data *my_data = (struct platform_data *)adev->platform;
Eric Laurentcefbbac2014-09-04 13:54:10 -0500985 snd_device_t snd_device = SND_DEVICE_NONE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700986
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800987 if (strcmp(my_data->ec_ref_mixer_path, "")) {
988 ALOGV("%s: diabling %s", __func__, my_data->ec_ref_mixer_path);
989 audio_route_reset_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
Eric Laurentcefbbac2014-09-04 13:54:10 -0500990 }
991
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800992 if (enable) {
993 strcpy(my_data->ec_ref_mixer_path, "echo-reference");
994 if (out_device != AUDIO_DEVICE_NONE) {
995 snd_device = platform_get_output_snd_device(adev->platform, out_device);
996 platform_add_backend_name(adev->platform, my_data->ec_ref_mixer_path, snd_device);
997 }
Eric Laurentcefbbac2014-09-04 13:54:10 -0500998
Joe Onorato188b6222016-03-01 11:02:27 -0800999 ALOGV("%s: enabling %s", __func__, my_data->ec_ref_mixer_path);
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08001000 audio_route_apply_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
1001 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001002}
1003
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001004static struct csd_data *open_csd_client(bool i2s_ext_modem)
1005{
1006 struct csd_data *csd = calloc(1, sizeof(struct csd_data));
1007
1008 csd->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
1009 if (csd->csd_client == NULL) {
1010 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
1011 goto error;
1012 } else {
1013 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
1014
1015 csd->deinit = (deinit_t)dlsym(csd->csd_client,
1016 "csd_client_deinit");
1017 if (csd->deinit == NULL) {
1018 ALOGE("%s: dlsym error %s for csd_client_deinit", __func__,
1019 dlerror());
1020 goto error;
1021 }
1022 csd->disable_device = (disable_device_t)dlsym(csd->csd_client,
1023 "csd_client_disable_device");
1024 if (csd->disable_device == NULL) {
1025 ALOGE("%s: dlsym error %s for csd_client_disable_device",
1026 __func__, dlerror());
1027 goto error;
1028 }
1029 csd->enable_device_config = (enable_device_config_t)dlsym(csd->csd_client,
1030 "csd_client_enable_device_config");
1031 if (csd->enable_device_config == NULL) {
1032 ALOGE("%s: dlsym error %s for csd_client_enable_device_config",
1033 __func__, dlerror());
1034 goto error;
1035 }
1036 csd->enable_device = (enable_device_t)dlsym(csd->csd_client,
1037 "csd_client_enable_device");
1038 if (csd->enable_device == NULL) {
1039 ALOGE("%s: dlsym error %s for csd_client_enable_device",
1040 __func__, dlerror());
1041 goto error;
1042 }
1043 csd->start_voice = (start_voice_t)dlsym(csd->csd_client,
1044 "csd_client_start_voice");
1045 if (csd->start_voice == NULL) {
1046 ALOGE("%s: dlsym error %s for csd_client_start_voice",
1047 __func__, dlerror());
1048 goto error;
1049 }
1050 csd->stop_voice = (stop_voice_t)dlsym(csd->csd_client,
1051 "csd_client_stop_voice");
1052 if (csd->stop_voice == NULL) {
1053 ALOGE("%s: dlsym error %s for csd_client_stop_voice",
1054 __func__, dlerror());
1055 goto error;
1056 }
1057 csd->volume = (volume_t)dlsym(csd->csd_client,
1058 "csd_client_volume");
1059 if (csd->volume == NULL) {
1060 ALOGE("%s: dlsym error %s for csd_client_volume",
1061 __func__, dlerror());
1062 goto error;
1063 }
1064 csd->mic_mute = (mic_mute_t)dlsym(csd->csd_client,
1065 "csd_client_mic_mute");
1066 if (csd->mic_mute == NULL) {
1067 ALOGE("%s: dlsym error %s for csd_client_mic_mute",
1068 __func__, dlerror());
1069 goto error;
1070 }
1071 csd->slow_talk = (slow_talk_t)dlsym(csd->csd_client,
1072 "csd_client_slow_talk");
1073 if (csd->slow_talk == NULL) {
1074 ALOGE("%s: dlsym error %s for csd_client_slow_talk",
1075 __func__, dlerror());
1076 goto error;
1077 }
1078 csd->start_playback = (start_playback_t)dlsym(csd->csd_client,
1079 "csd_client_start_playback");
1080 if (csd->start_playback == NULL) {
1081 ALOGE("%s: dlsym error %s for csd_client_start_playback",
1082 __func__, dlerror());
1083 goto error;
1084 }
1085 csd->stop_playback = (stop_playback_t)dlsym(csd->csd_client,
1086 "csd_client_stop_playback");
1087 if (csd->stop_playback == NULL) {
1088 ALOGE("%s: dlsym error %s for csd_client_stop_playback",
1089 __func__, dlerror());
1090 goto error;
1091 }
1092 csd->start_record = (start_record_t)dlsym(csd->csd_client,
1093 "csd_client_start_record");
1094 if (csd->start_record == NULL) {
1095 ALOGE("%s: dlsym error %s for csd_client_start_record",
1096 __func__, dlerror());
1097 goto error;
1098 }
1099 csd->stop_record = (stop_record_t)dlsym(csd->csd_client,
1100 "csd_client_stop_record");
1101 if (csd->stop_record == NULL) {
1102 ALOGE("%s: dlsym error %s for csd_client_stop_record",
1103 __func__, dlerror());
1104 goto error;
1105 }
1106
1107 csd->get_sample_rate = (get_sample_rate_t)dlsym(csd->csd_client,
1108 "csd_client_get_sample_rate");
1109 if (csd->get_sample_rate == NULL) {
1110 ALOGE("%s: dlsym error %s for csd_client_get_sample_rate",
1111 __func__, dlerror());
1112
1113 goto error;
1114 }
1115
1116 csd->init = (init_t)dlsym(csd->csd_client, "csd_client_init");
1117
1118 if (csd->init == NULL) {
1119 ALOGE("%s: dlsym error %s for csd_client_init",
1120 __func__, dlerror());
1121 goto error;
1122 } else {
1123 csd->init(i2s_ext_modem);
1124 }
1125 }
1126 return csd;
1127
1128error:
1129 free(csd);
1130 csd = NULL;
1131 return csd;
1132}
1133
1134void close_csd_client(struct csd_data *csd)
1135{
1136 if (csd != NULL) {
1137 csd->deinit();
1138 dlclose(csd->csd_client);
1139 free(csd);
1140 csd = NULL;
1141 }
1142}
1143
1144static void platform_csd_init(struct platform_data *my_data)
1145{
1146#ifdef PLATFORM_MSM8084
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001147 int32_t modems, (*count_modems)(void);
1148 const char *name = "libdetectmodem.so";
1149 const char *func = "count_modems";
1150 const char *error;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001151
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001152 my_data->csd = NULL;
1153
1154 void *lib = dlopen(name, RTLD_NOW);
1155 error = dlerror();
1156 if (!lib) {
1157 ALOGE("%s: could not find %s: %s", __func__, name, error);
1158 return;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001159 }
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001160
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001161 count_modems = NULL;
1162 *(void **)(&count_modems) = dlsym(lib, func);
1163 error = dlerror();
1164 if (!count_modems) {
1165 ALOGE("%s: could not find symbol %s in %s: %s",
1166 __func__, func, name, error);
1167 goto done;
1168 }
1169
1170 modems = count_modems();
1171 if (modems < 0) {
1172 ALOGE("%s: count_modems failed\n", __func__);
1173 goto done;
1174 }
1175
Eric Laurent2bafff12016-03-17 12:17:23 -07001176 ALOGD("%s: num_modems %d\n", __func__, modems);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001177 if (modems > 0)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001178 my_data->csd = open_csd_client(false /*is_i2s_ext_modem*/);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001179
1180done:
1181 dlclose(lib);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001182#else
1183 my_data->csd = NULL;
1184#endif
1185}
1186
Eric Laurentc6333382015-09-14 12:43:44 -07001187static void set_platform_defaults(struct platform_data * my_data)
Haynes Mathew George98c95622014-06-20 19:14:25 -07001188{
1189 int32_t dev;
1190 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001191 backend_tag_table[dev] = NULL;
1192 hw_interface_table[dev] = NULL;
keunhui.park2f7306a2015-07-16 16:48:06 +09001193 operator_specific_device_table[dev] = NULL;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001194 }
1195
David Linee3fe402017-03-13 10:00:42 -07001196 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1197 backend_bit_width_table[dev] = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
1198 }
1199
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001200 // To overwrite these go to the audio_platform_info.xml file.
1201 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("bt-sco");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07001202 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("bt-sco");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001203 backend_tag_table[SND_DEVICE_OUT_BT_SCO] = strdup("bt-sco");
1204 backend_tag_table[SND_DEVICE_OUT_HDMI] = strdup("hdmi");
1205 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("speaker-and-hdmi");
1206 backend_tag_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("bt-sco-wb");
1207 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("bt-sco-wb");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07001208 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("bt-sco-wb");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001209 backend_tag_table[SND_DEVICE_OUT_VOICE_TX] = strdup("afe-proxy");
1210 backend_tag_table[SND_DEVICE_IN_VOICE_RX] = strdup("afe-proxy");
Haynes Mathew George98c95622014-06-20 19:14:25 -07001211
David Linee3fe402017-03-13 10:00:42 -07001212 backend_tag_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("usb-headset");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001213 backend_tag_table[SND_DEVICE_OUT_VOICE_USB_HEADSET] = strdup("usb-headset");
David Linee3fe402017-03-13 10:00:42 -07001214 backend_tag_table[SND_DEVICE_OUT_USB_HEADPHONES] = strdup("usb-headphones");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001215 backend_tag_table[SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = strdup("usb-headphones");
David Linee3fe402017-03-13 10:00:42 -07001216 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] =
1217 strdup("speaker-and-usb-headphones");
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07001218 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] =
1219 strdup("speaker-safe-and-usb-headphones");
juyuchen5351ea62018-05-16 10:54:37 +08001220 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO] =
1221 strdup("speaker-safe-and-bt-sco"),
1222 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB] =
1223 strdup("speaker-safe-and-bt-sco-wb"),
David Linee3fe402017-03-13 10:00:42 -07001224 backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("usb-headset-mic");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001225 backend_tag_table[SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1226 backend_tag_table[SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1227 backend_tag_table[SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1228 backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = strdup("usb-headset-mic");
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001229 backend_tag_table[SND_DEVICE_OUT_BT_A2DP] = strdup("bt-a2dp");
1230 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] = strdup("speaker-and-bt-a2dp");
Aniket Kumar Lata9723a962018-05-16 17:41:55 -07001231 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP] = strdup("speaker-safe-and-bt-a2dp");
jasmine cha270b7762018-03-30 15:41:33 +08001232 backend_tag_table[SND_DEVICE_OUT_USB_HEADSET_SPEC] = strdup("usb-headset");
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001233
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001234 hw_interface_table[SND_DEVICE_OUT_HANDSET] = strdup("SLIMBUS_0_RX");
1235 hw_interface_table[SND_DEVICE_OUT_SPEAKER] = strdup("SLIMBUS_0_RX");
1236 hw_interface_table[SND_DEVICE_OUT_SPEAKER_REVERSE] = strdup("SLIMBUS_0_RX");
1237 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE] = strdup("SLIMBUS_0_RX");
1238 hw_interface_table[SND_DEVICE_OUT_HEADPHONES] = strdup("SLIMBUS_0_RX");
1239 hw_interface_table[SND_DEVICE_OUT_LINE] = strdup("SLIMBUS_0_RX");
1240 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001241 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001242 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001243 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001244 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET] = strdup("SLIMBUS_0_RX");
1245 hw_interface_table[SND_DEVICE_OUT_VOICE_HAC_HANDSET] = strdup("SLIMBUS_0_RX");
1246 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER] = strdup("SLIMBUS_0_RX");
1247 hw_interface_table[SND_DEVICE_OUT_VOICE_HEADPHONES] = strdup("SLIMBUS_0_RX");
yixuanjiang9536e672018-09-06 18:43:36 +08001248 hw_interface_table[SND_DEVICE_OUT_VOICE_HEADSET] = strdup("SLIMBUS_0_RX");
juyuchen66c4ecf2018-08-06 15:39:34 +08001249 hw_interface_table[SND_DEVICE_OUT_VOICE_MUSIC_TX] = strdup("VOICE_PLAYBACK_TX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001250 hw_interface_table[SND_DEVICE_OUT_VOICE_LINE] = strdup("SLIMBUS_0_RX");
1251 hw_interface_table[SND_DEVICE_OUT_HDMI] = strdup("HDMI_RX");
1252 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("SLIMBUS_0_RX-and-HDMI_RX");
1253 hw_interface_table[SND_DEVICE_OUT_BT_SCO] = strdup("SEC_AUX_PCM_RX");
1254 hw_interface_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("SEC_AUX_PCM_RX");
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001255 hw_interface_table[SND_DEVICE_OUT_BT_A2DP] = strdup("SLIMBUS_7_RX");
1256 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] =
1257 strdup("SLIMBUS_0_RX-and-SLIMBUS_7_RX");
Aniket Kumar Lata9723a962018-05-16 17:41:55 -07001258 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP] =
1259 strdup("SLIMBUS_0_RX-and-SLIMBUS_7_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001260 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = strdup("SLIMBUS_0_RX");
1261 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = strdup("SLIMBUS_0_RX");
1262 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = strdup("SLIMBUS_0_RX");
1263 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = strdup("SLIMBUS_0_RX");
David Linee3fe402017-03-13 10:00:42 -07001264 hw_interface_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("USB_AUDIO_RX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001265 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = strdup("USB_AUDIO_RX");
1266 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = strdup("USB_AUDIO_RX");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001267 hw_interface_table[SND_DEVICE_OUT_VOICE_USB_HEADSET] = strdup("USB_AUDIO_RX");
David Linee3fe402017-03-13 10:00:42 -07001268 hw_interface_table[SND_DEVICE_OUT_USB_HEADPHONES] = strdup("USB_AUDIO_RX");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001269 hw_interface_table[SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = strdup("USB_AUDIO_RX");
jasmine cha270b7762018-03-30 15:41:33 +08001270 hw_interface_table[SND_DEVICE_OUT_USB_HEADSET_SPEC] = strdup("USB_AUDIO_RX");
David Linee3fe402017-03-13 10:00:42 -07001271 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = strdup("SLIMBUS_0_RX-and-USB_AUDIO_RX");
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07001272 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] = strdup("SLIMBUS_0_RX-and-USB_AUDIO_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001273 hw_interface_table[SND_DEVICE_OUT_VOICE_TX] = strdup("AFE_PCM_RX");
1274 hw_interface_table[SND_DEVICE_OUT_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
1275 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
jasmine cha52284622018-03-23 17:21:35 +08001276 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = strdup("SLIMBUS_0_RX");
1277 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_BT_SCO] = strdup("SLIMBUS_0_RX-and-SEC_AUX_PCM_RX");
1278 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB] = strdup("SLIMBUS_0_RX-and-SEC_AUX_PCM_RX");
juyuchen5351ea62018-05-16 10:54:37 +08001279 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO] = strdup("QUAT_TDM_RX_0-and-SLIMBUS_7_RX"),
1280 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB] = strdup("QUAT_TDM_RX_0-and-SLIMBUS_7_RX"),
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001281 hw_interface_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1282 hw_interface_table[SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1283 hw_interface_table[SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = strdup("USB_AUDIO_TX");
1284 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1285 hw_interface_table[SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1286 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = strdup("USB_AUDIO_TX");
1287 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = strdup("USB_AUDIO_TX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001288 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001289 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_AEC] = strdup("SLIMBUS_0_TX");
1290 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_NS] = strdup("SLIMBUS_0_TX");
1291 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1292 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC] = strdup("SLIMBUS_0_TX");
1293 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_AEC] = strdup("SLIMBUS_0_TX");
1294 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_NS] = strdup("SLIMBUS_0_TX");
1295 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1296 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001297 hw_interface_table[SND_DEVICE_IN_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001298 hw_interface_table[SND_DEVICE_IN_HEADSET_MIC_AEC] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001299 hw_interface_table[SND_DEVICE_IN_CAMCORDER_MIC] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001300 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC] = strdup("SLIMBUS_0_TX");
1301 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC_NS] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001302 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC_AEC] = strdup("SLIMBUS_0_TX");
1303 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001304 hw_interface_table[SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
1305 hw_interface_table[SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = strdup("SLIMBUS_0_TX");
David Lin93725722017-10-13 14:58:17 -07001306 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_MIC] = strdup("SLIMBUS_0_TX");
1307 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1308 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = strdup("SLIMBUS_0_TX");
1309 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = strdup("SLIMBUS_0_TX");
1310 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001311 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC] = strdup("SLIMBUS_0_TX");
1312 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_AEC] = strdup("SLIMBUS_0_TX");
1313 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_NS] = strdup("SLIMBUS_0_TX");
1314 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1315 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC] = strdup("SLIMBUS_0_TX");
1316 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_AEC] = strdup("SLIMBUS_0_TX");
1317 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_NS] = strdup("SLIMBUS_0_TX");
1318 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001319 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
1320 hw_interface_table[SND_DEVICE_IN_VOICE_DMIC] = strdup("SLIMBUS_0_TX");
1321 hw_interface_table[SND_DEVICE_IN_VOICE_DMIC_TMUS] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001322 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001323 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = strdup("SLIMBUS_0_TX");
1324 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001325 hw_interface_table[SND_DEVICE_IN_VOICE_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001326 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1327 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = strdup("SLIMBUS_0_TX");
1328 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1329 hw_interface_table[SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1330 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("SEC_AUX_PCM_TX");
1331 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("SEC_AUX_PCM_TX");
1332 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("SEC_AUX_PCM_TX");
1333 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("SEC_AUX_PCM_TX");
1334 hw_interface_table[SND_DEVICE_IN_VOICE_RX] = strdup("AFE_PCM_TX");
1335 hw_interface_table[SND_DEVICE_IN_THREE_MIC] = strdup("SLIMBUS_0_TX");
1336 hw_interface_table[SND_DEVICE_IN_QUAD_MIC] = strdup("SLIMBUS_0_TX");
1337 hw_interface_table[SND_DEVICE_IN_HANDSET_TMIC] = strdup("SLIMBUS_0_TX");
1338 hw_interface_table[SND_DEVICE_IN_HANDSET_QMIC] = strdup("SLIMBUS_0_TX");
1339 hw_interface_table[SND_DEVICE_IN_HANDSET_TMIC_AEC] = strdup("SLIMBUS_0_TX");
1340 hw_interface_table[SND_DEVICE_IN_HANDSET_QMIC_AEC] = strdup("SLIMBUS_0_TX");
Eric Laurentc6333382015-09-14 12:43:44 -07001341 my_data->max_mic_count = PLATFORM_DEFAULT_MIC_COUNT;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001342}
1343
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001344void get_cvd_version(char *cvd_version, struct audio_device *adev)
1345{
1346 struct mixer_ctl *ctl;
1347 int count;
1348 int ret = 0;
1349
1350 ctl = mixer_get_ctl_by_name(adev->mixer, CVD_VERSION_MIXER_CTL);
1351 if (!ctl) {
1352 ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__, CVD_VERSION_MIXER_CTL);
1353 goto done;
1354 }
1355 mixer_ctl_update(ctl);
1356
1357 count = mixer_ctl_get_num_values(ctl);
1358 if (count > MAX_CVD_VERSION_STRING_SIZE)
1359 count = MAX_CVD_VERSION_STRING_SIZE - 1;
1360
1361 ret = mixer_ctl_get_array(ctl, cvd_version, count);
1362 if (ret != 0) {
1363 ALOGE("%s: ERROR! mixer_ctl_get_array() failed to get CVD Version", __func__);
1364 goto done;
1365 }
1366
1367done:
1368 return;
1369}
1370
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001371static int platform_acdb_init(void *platform)
1372{
1373 struct platform_data *my_data = (struct platform_data *)platform;
1374 struct audio_device *adev = my_data->adev;
1375
1376 if (!my_data->acdb_init) {
1377 ALOGE("%s: no acdb_init fn provided", __func__);
1378 return -1;
1379 }
1380
1381 if (my_data->acdb_initialized) {
1382 ALOGW("acdb is already initialized");
1383 return 0;
1384 }
1385
Thierry Strudel07f96d12018-09-20 13:31:34 -07001386#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845) || (PLATFORM_SDM710) || (PLATFORM_SM8150)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001387 char *cvd_version = calloc(1, MAX_CVD_VERSION_STRING_SIZE);
1388 if (!cvd_version)
1389 ALOGE("failed to allocate cvd_version");
1390 else {
1391 get_cvd_version(cvd_version, adev);
1392 my_data->acdb_init((char *)my_data->snd_card_name, cvd_version, 0);
1393 free(cvd_version);
1394 }
1395#elif defined (PLATFORM_MSM8084)
1396 my_data->acdb_init((char *)my_data->snd_card_name);
1397#else
1398 my_data->acdb_init();
1399#endif
1400 my_data->acdb_initialized = true;
1401 return 0;
1402}
1403
David Linee3fe402017-03-13 10:00:42 -07001404static void
1405platform_backend_config_init(struct platform_data *pdata)
1406{
1407 int i;
1408
1409 /* initialize backend config */
1410 for (i = 0; i < MAX_CODEC_BACKENDS; i++) {
1411 pdata->current_backend_cfg[i].sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
1412 pdata->current_backend_cfg[i].bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
1413 pdata->current_backend_cfg[i].channels = CODEC_BACKEND_DEFAULT_CHANNELS;
1414
1415 if (i > MAX_RX_CODEC_BACKENDS)
1416 pdata->current_backend_cfg[i].channels = CODEC_BACKEND_DEFAULT_TX_CHANNELS;
1417
1418 pdata->current_backend_cfg[i].bitwidth_mixer_ctl = NULL;
1419 pdata->current_backend_cfg[i].samplerate_mixer_ctl = NULL;
1420 pdata->current_backend_cfg[i].channels_mixer_ctl = NULL;
1421 }
1422
1423 pdata->current_backend_cfg[DEFAULT_CODEC_BACKEND].bitwidth_mixer_ctl =
1424 strdup("SLIM_0_RX Format");
1425 pdata->current_backend_cfg[DEFAULT_CODEC_BACKEND].samplerate_mixer_ctl =
1426 strdup("SLIM_0_RX SampleRate");
1427
1428 pdata->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].bitwidth_mixer_ctl =
1429 strdup("SLIM_0_TX Format");
1430 pdata->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].samplerate_mixer_ctl =
1431 strdup("SLIM_0_TX SampleRate");
1432
1433 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].bitwidth_mixer_ctl =
1434 strdup("USB_AUDIO_TX Format");
1435 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].samplerate_mixer_ctl =
1436 strdup("USB_AUDIO_TX SampleRate");
1437 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].channels_mixer_ctl =
1438 strdup("USB_AUDIO_TX Channels");
1439
1440 pdata->current_backend_cfg[HEADPHONE_BACKEND].bitwidth_mixer_ctl =
1441 strdup("SLIM_6_RX Format");
1442 pdata->current_backend_cfg[HEADPHONE_BACKEND].samplerate_mixer_ctl =
1443 strdup("SLIM_6_RX SampleRate");
1444
1445 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].bitwidth_mixer_ctl =
1446 strdup("USB_AUDIO_RX Format");
1447 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].samplerate_mixer_ctl =
1448 strdup("USB_AUDIO_RX SampleRate");
1449
1450 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].channels = 1;
1451 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].channels_mixer_ctl =
1452 strdup("USB_AUDIO_RX Channels");
1453}
1454
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001455static int
1456platform_backend_app_type_cfg_init(struct platform_data *pdata,
1457 struct mixer *mixer)
1458{
1459 size_t app_type_cfg[128] = {0};
1460 int length, num_app_types = 0;
1461 struct mixer_ctl *ctl = NULL;
1462
1463 const char *mixer_ctl_name = "App Type Config";
1464 ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name);
1465 if (!ctl) {
1466 ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name);
1467 return -1;
1468 }
1469
1470 length = 1; // reserve index 0 for number of app types
1471
1472 struct listnode *node;
1473 struct app_type_entry *entry;
1474 list_for_each(node, &app_type_entry_list) {
1475 entry = node_to_item(node, struct app_type_entry, node);
1476 app_type_cfg[length++] = entry->app_type;
1477 app_type_cfg[length++] = entry->max_rate;
1478 app_type_cfg[length++] = entry->bit_width;
1479 ALOGI("%s add entry %d %d", __func__, entry->app_type, entry->bit_width);
1480 num_app_types += 1;
1481 }
1482
1483 // default for capture
1484 int t;
1485 platform_get_default_app_type_v2(pdata,
1486 PCM_CAPTURE,
1487 &t);
1488 app_type_cfg[length++] = t;
1489 app_type_cfg[length++] = 48000;
1490 app_type_cfg[length++] = 16;
1491 num_app_types += 1;
1492
1493 if (num_app_types) {
1494 app_type_cfg[0] = num_app_types;
1495 if (mixer_ctl_set_array(ctl, app_type_cfg, length) < 0) {
1496 ALOGE("Failed to set app type cfg");
1497 }
1498 }
1499 return 0;
1500}
1501
Xu Han1638fd12018-04-20 12:42:23 -07001502static void configure_flicker_sensor_input(struct mixer *mixer)
1503{
1504 struct mixer_ctl *ctl;
1505 const char* ctl1 = "AIF3_CAP Mixer SLIM TX2";
1506 int setting1 = 1;
1507 const char* ctl2 = "CDC_IF TX2 MUX";
1508 const char* setting2 = "DEC2";
1509 const char* ctl3 = "SLIM_1_TX Channels";
1510 const char* setting3 = "One";
1511 const char* ctl4 = "ADC MUX2";
1512 const char* setting4 = "AMIC";
1513 const char* ctl5 = "AMIC MUX2";
1514 const char* setting5 = "ADC1";
1515 const char* ctl6 = "DEC2 Volume";
1516 int setting6 = 84;
Xu Han07e07402018-05-15 14:19:25 -07001517 const char* ctl7 = "MultiMedia9 Mixer SLIM_1_TX";
Xu Han1638fd12018-04-20 12:42:23 -07001518 int setting7 = 1;
1519 const char* ctl8 = "SLIM_1_TX SampleRate";
1520 const char* setting8 = "KHZ_8";
1521
1522 ctl = mixer_get_ctl_by_name(mixer, ctl1);
1523 mixer_ctl_set_value(ctl, 0, setting1);
1524 ctl = mixer_get_ctl_by_name(mixer, ctl2);
1525 mixer_ctl_set_enum_by_string(ctl, setting2);
1526 ctl = mixer_get_ctl_by_name(mixer, ctl3);
1527 mixer_ctl_set_enum_by_string(ctl, setting3);
1528 ctl = mixer_get_ctl_by_name(mixer, ctl4);
1529 mixer_ctl_set_enum_by_string(ctl, setting4);
1530 ctl = mixer_get_ctl_by_name(mixer, ctl5);
1531 mixer_ctl_set_enum_by_string(ctl, setting5);
1532 ctl = mixer_get_ctl_by_name(mixer, ctl6);
1533 mixer_ctl_set_value(ctl, 0, setting6);
1534 ctl = mixer_get_ctl_by_name(mixer, ctl7);
1535 mixer_ctl_set_value(ctl, 0, setting7);
1536 ctl = mixer_get_ctl_by_name(mixer, ctl8);
1537 mixer_ctl_set_enum_by_string(ctl, setting8);
1538}
1539
Eric Laurentb23d5282013-05-14 15:27:20 -07001540void *platform_init(struct audio_device *adev)
1541{
1542 char value[PROPERTY_VALUE_MAX];
vivek mehta60ea4152016-02-18 17:10:26 -08001543 struct platform_data *my_data = NULL;
1544 int retry_num = 0, snd_card_num = 0, key = 0, ret = 0;
1545 bool dual_mic_config = false, use_default_mixer_path = true;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001546 const char *snd_card_name;
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001547 char *cvd_version = NULL;
vivek mehta60ea4152016-02-18 17:10:26 -08001548 char *snd_internal_name = NULL;
1549 char *tmp = NULL;
1550 char mixer_xml_file[MIXER_PATH_MAX_LENGTH]= {0};
vivek mehtade4849c2016-03-03 17:23:38 -08001551 char platform_info_file[MIXER_PATH_MAX_LENGTH]= {0};
1552 struct snd_card_split *snd_split_handle = NULL;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001553 my_data = calloc(1, sizeof(struct platform_data));
1554
1555 my_data->adev = adev;
1556
keunhui.park2f7306a2015-07-16 16:48:06 +09001557 list_init(&operator_info_list);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001558 list_init(&app_type_entry_list);
keunhui.park2f7306a2015-07-16 16:48:06 +09001559
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001560 set_platform_defaults(my_data);
1561
vivek mehta0fb11312017-05-15 19:35:32 -07001562 // audio_extn_utils_get_snd_card_num does
1563 // - open mixer and get snd card name
1564 // - parse platform info xml file and check for valid snd card name
1565 // - on failure loop through all the active snd card
sangwoo1b9f4b32013-06-21 18:22:55 -07001566
vivek mehta0fb11312017-05-15 19:35:32 -07001567 snd_card_num = audio_extn_utils_get_snd_card_num();
1568 if (-1 == snd_card_num) {
1569 ALOGE("%s: invalid sound card number (-1), bailing out ", __func__);
1570 goto init_failed;
sangwoo1b9f4b32013-06-21 18:22:55 -07001571 }
1572
vivek mehta0fb11312017-05-15 19:35:32 -07001573 adev->mixer = mixer_open(snd_card_num);
1574 snd_card_name = mixer_get_name(adev->mixer);
1575 my_data->hw_info = hw_info_init(snd_card_name);
1576
1577 audio_extn_set_snd_card_split(snd_card_name);
1578 snd_split_handle = audio_extn_get_snd_card_split();
1579
1580 /* Get the codec internal name from the sound card and/or form factor
1581 * name and form the mixer paths and platfor info file name dynamically.
1582 * This is generic way of picking any codec and forma factor name based
1583 * mixer and platform info files in future with no code change.
1584
1585 * current code extends and looks for any of the exteneded mixer path and
1586 * platform info file present based on codec and form factor.
1587
1588 * order of picking appropriate file is
1589 * <i> mixer_paths_<codec_name>_<form_factor>.xml, if file not present
1590 * <ii> mixer_paths_<codec_name>.xml, if file not present
1591 * <iii> mixer_paths.xml
1592
1593 * same order is followed for audio_platform_info.xml as well
1594 */
1595
1596 // need to carryforward old file name
1597 if (!strncmp(snd_card_name, TOMTOM_8226_SND_CARD_NAME,
1598 min(strlen(TOMTOM_8226_SND_CARD_NAME), strlen(snd_card_name)))) {
1599 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1600 MIXER_XML_BASE_STRING, TOMTOM_MIXER_FILE_SUFFIX );
1601 } else {
1602
1603 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s_%s.xml",
1604 MIXER_XML_BASE_STRING, snd_split_handle->snd_card,
1605 snd_split_handle->form_factor);
1606 if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) {
1607 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1608 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1609 MIXER_XML_BASE_STRING, snd_split_handle->snd_card);
1610
1611 if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) {
1612 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1613 strlcpy(mixer_xml_file, MIXER_XML_DEFAULT_PATH, MIXER_PATH_MAX_LENGTH);
1614 audio_extn_utils_resolve_config_file(mixer_xml_file);
1615 }
1616 }
1617 }
1618
1619 audio_extn_utils_get_platform_info(snd_card_name, platform_info_file);
1620
jiabin8962a4d2018-03-19 18:21:24 -07001621 my_data->declared_mic_count = 0;
vivek mehta0fb11312017-05-15 19:35:32 -07001622 /* Initialize platform specific ids and/or backends*/
1623 platform_info_init(platform_info_file, my_data);
1624
1625 ALOGD("%s: Loading mixer file: %s", __func__, mixer_xml_file);
1626 adev->audio_route = audio_route_init(snd_card_num, mixer_xml_file);
1627
1628 if (!adev->audio_route) {
1629 ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
1630 mixer_close(adev->mixer);
1631 adev->mixer = NULL;
1632 hw_info_deinit(my_data->hw_info);
1633 my_data->hw_info = NULL;
1634 goto init_failed;
1635 }
1636 adev->snd_card = snd_card_num;
1637 ALOGD("%s: Opened sound card:%d", __func__, snd_card_num);
1638
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09001639 //set max volume step for voice call
1640 property_get("ro.config.vc_call_vol_steps", value, TOSTRING(MAX_VOL_INDEX));
1641 my_data->max_vol_index = atoi(value);
1642
vivek mehta65ad12d2015-08-13 18:32:48 -07001643 property_get("persist.audio.dualmic.config",value,"");
1644 if (!strcmp("endfire", value)) {
1645 dual_mic_config = true;
1646 }
1647
John Muir9e59a962018-01-10 13:30:00 -08001648 my_data->source_mic_type = 0;
Prashant Malanic92c5962015-08-11 15:10:18 -07001649
Eric Laurentb23d5282013-05-14 15:27:20 -07001650 my_data->fluence_in_spkr_mode = false;
1651 my_data->fluence_in_voice_call = false;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001652 my_data->fluence_in_voice_comm = false;
Eric Laurentb23d5282013-05-14 15:27:20 -07001653 my_data->fluence_in_voice_rec = false;
1654
vivek mehta65ad12d2015-08-13 18:32:48 -07001655 property_get("ro.qc.sdk.audio.fluencetype", value, "none");
Prashant Malanic92c5962015-08-11 15:10:18 -07001656 if (!strcmp("fluencepro", value)) {
1657 my_data->fluence_type = FLUENCE_PRO_ENABLE;
vivek mehta65ad12d2015-08-13 18:32:48 -07001658 } else if (!strcmp("fluence", value) || (dual_mic_config)) {
Prashant Malanic92c5962015-08-11 15:10:18 -07001659 my_data->fluence_type = FLUENCE_ENABLE;
1660 } else if (!strcmp("none", value)) {
1661 my_data->fluence_type = FLUENCE_DISABLE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001662 }
1663
Prashant Malanic92c5962015-08-11 15:10:18 -07001664 if (my_data->fluence_type != FLUENCE_DISABLE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001665 property_get("persist.audio.fluence.voicecall",value,"");
1666 if (!strcmp("true", value)) {
1667 my_data->fluence_in_voice_call = true;
1668 }
1669
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001670 property_get("persist.audio.fluence.voicecomm",value,"");
1671 if (!strcmp("true", value)) {
1672 my_data->fluence_in_voice_comm = true;
1673 }
1674
Eric Laurentb23d5282013-05-14 15:27:20 -07001675 property_get("persist.audio.fluence.voicerec",value,"");
1676 if (!strcmp("true", value)) {
1677 my_data->fluence_in_voice_rec = true;
1678 }
1679
1680 property_get("persist.audio.fluence.speaker",value,"");
1681 if (!strcmp("true", value)) {
1682 my_data->fluence_in_spkr_mode = true;
1683 }
1684 }
1685
Prashant Malanic92c5962015-08-11 15:10:18 -07001686 // support max to mono, example if max count is 3, usecase supports Three, dual and mono mic
1687 switch (my_data->max_mic_count) {
1688 case 4:
1689 my_data->source_mic_type |= SOURCE_QUAD_MIC;
1690 case 3:
1691 my_data->source_mic_type |= SOURCE_THREE_MIC;
1692 case 2:
1693 my_data->source_mic_type |= SOURCE_DUAL_MIC;
1694 case 1:
1695 my_data->source_mic_type |= SOURCE_MONO_MIC;
1696 break;
1697 default:
1698 ALOGE("%s: max_mic_count (%d), is not supported, setting to default",
1699 __func__, my_data->max_mic_count);
1700 my_data->source_mic_type = SOURCE_MONO_MIC|SOURCE_DUAL_MIC;
1701 break;
1702 }
1703
1704 ALOGV("%s: Fluence_Type(%d) max_mic_count(%d) mic_type(0x%x) fluence_in_voice_call(%d)"
1705 " fluence_in_voice_comm(%d) fluence_in_voice_rec(%d) fluence_in_spkr_mode(%d) ",
1706 __func__, my_data->fluence_type, my_data->max_mic_count, my_data->source_mic_type,
1707 my_data->fluence_in_voice_call, my_data->fluence_in_voice_comm,
1708 my_data->fluence_in_voice_rec, my_data->fluence_in_spkr_mode);
1709
Eric Laurentb23d5282013-05-14 15:27:20 -07001710 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
1711 if (my_data->acdb_handle == NULL) {
1712 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
1713 } else {
1714 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
1715 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
1716 "acdb_loader_deallocate_ACDB");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001717 if (!my_data->acdb_deallocate)
1718 ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s",
1719 __func__, LIB_ACDB_LOADER);
1720
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001721 my_data->acdb_send_audio_cal_v3 = (acdb_send_audio_cal_v3_t)dlsym(my_data->acdb_handle,
1722 "acdb_loader_send_audio_cal_v3");
1723 if (!my_data->acdb_send_audio_cal_v3)
1724 ALOGE("%s: Could not find the symbol acdb_send_audio_cal_v3 from %s",
1725 __func__, LIB_ACDB_LOADER);
1726
Eric Laurentb23d5282013-05-14 15:27:20 -07001727 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
1728 "acdb_loader_send_audio_cal");
1729 if (!my_data->acdb_send_audio_cal)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001730 ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s",
Eric Laurentb23d5282013-05-14 15:27:20 -07001731 __func__, LIB_ACDB_LOADER);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001732
Eric Laurentb23d5282013-05-14 15:27:20 -07001733 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
1734 "acdb_loader_send_voice_cal");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001735 if (!my_data->acdb_send_voice_cal)
1736 ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s",
1737 __func__, LIB_ACDB_LOADER);
1738
1739 my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle,
1740 "acdb_loader_reload_vocvoltable");
1741 if (!my_data->acdb_reload_vocvoltable)
1742 ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s",
1743 __func__, LIB_ACDB_LOADER);
vivek mehta1a9b7c02015-06-25 11:49:38 -07001744
1745 my_data->acdb_send_gain_dep_cal = (acdb_send_gain_dep_cal_t)dlsym(my_data->acdb_handle,
1746 "acdb_loader_send_gain_dep_cal");
1747 if (!my_data->acdb_send_gain_dep_cal)
1748 ALOGV("%s: Could not find the symbol acdb_loader_send_gain_dep_cal from %s",
1749 __func__, LIB_ACDB_LOADER);
1750
Xu Han1638fd12018-04-20 12:42:23 -07001751#if defined (FLICKER_SENSOR_INPUT)
1752 configure_flicker_sensor_input(adev->mixer);
1753#endif
1754
Thierry Strudel07f96d12018-09-20 13:31:34 -07001755#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845) || (PLATFORM_SDM710) || (PLATFORM_SM8150)
vivek mehta0fb11312017-05-15 19:35:32 -07001756 acdb_init_v2_cvd_t acdb_init_local;
1757 acdb_init_local = (acdb_init_v2_cvd_t)dlsym(my_data->acdb_handle,
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001758 "acdb_loader_init_v2");
vivek mehta0fb11312017-05-15 19:35:32 -07001759 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001760 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1761 dlerror());
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001762
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001763#elif defined (PLATFORM_MSM8084)
vivek mehta0fb11312017-05-15 19:35:32 -07001764 acdb_init_v2_t acdb_init_local;
1765 acdb_init_local = (acdb_init_v2_t)dlsym(my_data->acdb_handle,
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001766 "acdb_loader_init_v2");
vivek mehta0fb11312017-05-15 19:35:32 -07001767 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001768 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1769 dlerror());
1770
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001771#else
vivek mehta0fb11312017-05-15 19:35:32 -07001772 acdb_init_t acdb_init_local;
1773 acdb_init_local = (acdb_init_t)dlsym(my_data->acdb_handle,
Eric Laurentb23d5282013-05-14 15:27:20 -07001774 "acdb_loader_init_ACDB");
vivek mehta0fb11312017-05-15 19:35:32 -07001775 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001776 ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__,
1777 dlerror());
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001778#endif
vivek mehta0fb11312017-05-15 19:35:32 -07001779 my_data->acdb_init = acdb_init_local;
Eric Laurentb23d5282013-05-14 15:27:20 -07001780
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001781 my_data->acdb_send_custom_top = (acdb_send_custom_top_t)
1782 dlsym(my_data->acdb_handle,
1783 "acdb_loader_send_common_custom_topology");
1784
1785 if (!my_data->acdb_send_custom_top)
1786 ALOGE("%s: Could not find the symbol acdb_get_default_app_type from %s",
1787 __func__, LIB_ACDB_LOADER);
1788
jasmine chac89321b2018-04-10 21:37:01 +08001789 my_data->acdb_set_audio_cal = (acdb_set_audio_cal_t)dlsym(my_data->acdb_handle,
1790 "acdb_loader_set_audio_cal_v2");
1791 if (!my_data->acdb_set_audio_cal)
1792 ALOGE("%s: Could not find the symbol acdb_set_audio_cal_v2 from %s",
1793 __func__, LIB_ACDB_LOADER);
1794
vivek mehta0fb11312017-05-15 19:35:32 -07001795 int result = acdb_init(adev->snd_card);
1796 if (!result) {
1797 my_data->acdb_initialized = true;
1798 ALOGD("ACDB initialized");
1799 } else {
1800 my_data->acdb_initialized = false;
1801 ALOGD("ACDB initialization failed");
1802 }
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001803 }
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001804
David Linee3fe402017-03-13 10:00:42 -07001805 /* init usb */
1806 audio_extn_usb_init(adev);
1807
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001808 /* init a2dp */
1809 audio_extn_a2dp_init(adev);
1810
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001811 audio_extn_spkr_prot_init(adev);
Haynes Mathew George98c95622014-06-20 19:14:25 -07001812
Ravi Kumar Alamanda76315572015-04-23 13:13:56 -07001813 audio_extn_hwdep_cal_send(adev->snd_card, my_data->acdb_handle);
1814
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001815 /* load csd client */
1816 platform_csd_init(my_data);
1817
David Linee3fe402017-03-13 10:00:42 -07001818 platform_backend_config_init(my_data);
1819
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001820 init_be_dai_name_table(adev);
1821
1822 if (platform_supports_app_type_cfg())
1823 platform_backend_app_type_cfg_init(my_data, adev->mixer);
1824
Eric Laurentb23d5282013-05-14 15:27:20 -07001825 return my_data;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001826
1827init_failed:
1828 if (my_data)
1829 free(my_data);
1830 return NULL;
Eric Laurentb23d5282013-05-14 15:27:20 -07001831}
1832
1833void platform_deinit(void *platform)
1834{
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001835 int32_t dev;
keunhui.park2f7306a2015-07-16 16:48:06 +09001836 struct operator_info *info_item;
1837 struct operator_specific_device *device_item;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001838 struct app_type_entry *ap;
keunhui.park2f7306a2015-07-16 16:48:06 +09001839 struct listnode *node;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001840
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001841 struct platform_data *my_data = (struct platform_data *)platform;
1842 close_csd_client(my_data->csd);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001843
David Lin41b4fe42018-07-08 16:14:24 -07001844 audio_extn_spkr_prot_deinit(my_data->adev);
1845
vivek mehtade4849c2016-03-03 17:23:38 -08001846 hw_info_deinit(my_data->hw_info);
1847
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001848 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1849 if (backend_tag_table[dev])
1850 free(backend_tag_table[dev]);
1851 if (hw_interface_table[dev])
1852 free(hw_interface_table[dev]);
keunhui.park2f7306a2015-07-16 16:48:06 +09001853 if (operator_specific_device_table[dev]) {
1854 while (!list_empty(operator_specific_device_table[dev])) {
1855 node = list_head(operator_specific_device_table[dev]);
1856 list_remove(node);
1857 device_item = node_to_item(node, struct operator_specific_device, list);
1858 free(device_item->operator);
1859 free(device_item->mixer_path);
1860 free(device_item);
1861 }
1862 free(operator_specific_device_table[dev]);
1863 }
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001864 }
1865
1866 if (my_data->snd_card_name)
1867 free(my_data->snd_card_name);
1868
keunhui.park2f7306a2015-07-16 16:48:06 +09001869 while (!list_empty(&operator_info_list)) {
1870 node = list_head(&operator_info_list);
1871 list_remove(node);
1872 info_item = node_to_item(node, struct operator_info, list);
1873 free(info_item->name);
1874 free(info_item->mccmnc);
1875 free(info_item);
1876 }
1877
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001878 while (!list_empty(&app_type_entry_list)) {
1879 node = list_head(&app_type_entry_list);
1880 list_remove(node);
1881 ap = node_to_item(node, struct app_type_entry, node);
vivek mehtaa68fea62017-06-08 19:04:02 -07001882 if (ap->mode) free(ap->mode);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001883 free(ap);
1884 }
1885
Kevin Rocarde35d4af2017-05-02 16:55:28 -07001886 mixer_close(my_data->adev->mixer);
Eric Laurentb23d5282013-05-14 15:27:20 -07001887 free(platform);
David Linee3fe402017-03-13 10:00:42 -07001888
1889 /* deinit usb */
1890 audio_extn_usb_deinit();
Eric Laurentb23d5282013-05-14 15:27:20 -07001891}
1892
1893const char *platform_get_snd_device_name(snd_device_t snd_device)
1894{
keunhui.park2f7306a2015-07-16 16:48:06 +09001895 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1896 if (operator_specific_device_table[snd_device] != NULL) {
1897 return get_operator_specific_device_mixer_path(snd_device);
1898 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001899 return device_table[snd_device];
keunhui.park2f7306a2015-07-16 16:48:06 +09001900 } else
Ravi Kumar Alamanda64026462014-09-15 00:08:58 -07001901 return "none";
Eric Laurentb23d5282013-05-14 15:27:20 -07001902}
1903
vivek mehtade4849c2016-03-03 17:23:38 -08001904int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
1905 char *device_name)
1906{
1907 struct platform_data *my_data = (struct platform_data *)platform;
1908
David Benjamin1565f992016-09-21 12:10:34 -04001909 if (platform == NULL) {
vivek mehtade4849c2016-03-03 17:23:38 -08001910 ALOGW("%s: something wrong, use legacy get_snd_device name", __func__);
David Benjamin1565f992016-09-21 12:10:34 -04001911 strlcpy(device_name, platform_get_snd_device_name(snd_device),
1912 DEVICE_NAME_MAX_SIZE);
vivek mehtade4849c2016-03-03 17:23:38 -08001913 } else if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1914 if (operator_specific_device_table[snd_device] != NULL) {
1915 strlcpy(device_name, get_operator_specific_device_mixer_path(snd_device),
1916 DEVICE_NAME_MAX_SIZE);
1917 } else {
1918 strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE);
1919 }
1920 hw_info_append_hw_type(my_data->hw_info, snd_device, device_name);
1921 } else {
1922 strlcpy(device_name, "none", DEVICE_NAME_MAX_SIZE);
Aniket Kumar Lataa158e862018-05-11 17:28:40 -07001923 return -EINVAL;
vivek mehtade4849c2016-03-03 17:23:38 -08001924 }
1925
1926 return 0;
1927}
1928
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001929void platform_add_backend_name(void *platform, char *mixer_path,
1930 snd_device_t snd_device)
Eric Laurentb23d5282013-05-14 15:27:20 -07001931{
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001932 struct platform_data *my_data = (struct platform_data *)platform;
1933
Haynes Mathew George98c95622014-06-20 19:14:25 -07001934 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1935 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1936 return;
Ravi Kumar Alamanda1de6e5a2014-06-19 21:55:39 -05001937 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001938
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001939 const char * suffix = backend_tag_table[snd_device];
Haynes Mathew George98c95622014-06-20 19:14:25 -07001940
1941 if (suffix != NULL) {
1942 strcat(mixer_path, " ");
1943 strcat(mixer_path, suffix);
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001944 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001945}
1946
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001947bool platform_check_backends_match(snd_device_t snd_device1, snd_device_t snd_device2)
1948{
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001949 ALOGV("%s: snd_device1 = %s, snd_device2 = %s", __func__,
1950 platform_get_snd_device_name(snd_device1),
1951 platform_get_snd_device_name(snd_device2));
1952
1953 if ((snd_device1 < SND_DEVICE_MIN) || (snd_device1 >= SND_DEVICE_MAX)) {
1954 ALOGE("%s: Invalid snd_device = %s", __func__,
1955 platform_get_snd_device_name(snd_device1));
1956 return false;
1957 }
1958 if ((snd_device2 < SND_DEVICE_MIN) || (snd_device2 >= SND_DEVICE_MAX)) {
1959 ALOGE("%s: Invalid snd_device = %s", __func__,
1960 platform_get_snd_device_name(snd_device2));
1961 return false;
1962 }
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07001963
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001964 const char * be_itf1 = hw_interface_table[snd_device1];
1965 const char * be_itf2 = hw_interface_table[snd_device2];
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07001966 /*
1967 hw_interface_table has overrides for a snd_device.
1968 if there is no entry for a device, assume DEFAULT_RX_BACKEND
1969 */
1970 if (be_itf1 == NULL) {
1971 be_itf1 = DEFAULT_RX_BACKEND;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001972 }
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07001973 if (be_itf2 == NULL) {
1974 be_itf2 = DEFAULT_RX_BACKEND;
1975 }
1976 ALOGV("%s: be_itf1 = %s, be_itf2 = %s", __func__, be_itf1, be_itf2);
1977 /*
1978 this takes care of finding a device within a combo device pair as well
1979 */
1980 return strstr(be_itf1, be_itf2) != NULL || strstr(be_itf2, be_itf1) != NULL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001981}
1982
Eric Laurentb23d5282013-05-14 15:27:20 -07001983int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
1984{
1985 int device_id;
1986 if (device_type == PCM_PLAYBACK)
1987 device_id = pcm_device_table[usecase][0];
1988 else
1989 device_id = pcm_device_table[usecase][1];
1990 return device_id;
1991}
1992
Haynes Mathew George98c95622014-06-20 19:14:25 -07001993static int find_index(const struct name_to_index * table, int32_t len,
1994 const char * name)
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001995{
1996 int ret = 0;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001997 int32_t i;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001998
Haynes Mathew George98c95622014-06-20 19:14:25 -07001999 if (table == NULL) {
2000 ALOGE("%s: table is NULL", __func__);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002001 ret = -ENODEV;
2002 goto done;
2003 }
2004
Haynes Mathew George98c95622014-06-20 19:14:25 -07002005 if (name == NULL) {
2006 ALOGE("null key");
2007 ret = -ENODEV;
2008 goto done;
2009 }
2010
2011 for (i=0; i < len; i++) {
2012 if (!strcmp(table[i].name, name)) {
2013 ret = table[i].index;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002014 goto done;
2015 }
2016 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07002017 ALOGE("%s: Could not find index for name = %s",
2018 __func__, name);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002019 ret = -ENODEV;
2020done:
2021 return ret;
2022}
2023
Haynes Mathew George98c95622014-06-20 19:14:25 -07002024int platform_get_snd_device_index(char *device_name)
2025{
2026 return find_index(snd_device_name_index, SND_DEVICE_MAX, device_name);
2027}
2028
2029int platform_get_usecase_index(const char *usecase_name)
2030{
2031 return find_index(usecase_name_index, AUDIO_USECASE_MAX, usecase_name);
2032}
2033
keunhui.park2f7306a2015-07-16 16:48:06 +09002034void platform_add_operator_specific_device(snd_device_t snd_device,
2035 const char *operator,
2036 const char *mixer_path,
2037 unsigned int acdb_id)
2038{
2039 struct operator_specific_device *device;
2040
2041 if (operator_specific_device_table[snd_device] == NULL) {
2042 operator_specific_device_table[snd_device] =
2043 (struct listnode *)calloc(1, sizeof(struct listnode));
2044 list_init(operator_specific_device_table[snd_device]);
2045 }
2046
2047 device = (struct operator_specific_device *)calloc(1, sizeof(struct operator_specific_device));
2048
2049 device->operator = strdup(operator);
2050 device->mixer_path = strdup(mixer_path);
2051 device->acdb_id = acdb_id;
2052
2053 list_add_tail(operator_specific_device_table[snd_device], &device->list);
2054
Eric Laurent2bafff12016-03-17 12:17:23 -07002055 ALOGD("%s: device[%s] -> operator[%s] mixer_path[%s] acdb_id[%d]", __func__,
keunhui.park2f7306a2015-07-16 16:48:06 +09002056 platform_get_snd_device_name(snd_device), operator, mixer_path, acdb_id);
2057
2058}
2059
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002060int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
2061{
2062 int ret = 0;
2063
2064 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
2065 ALOGE("%s: Invalid snd_device = %d",
2066 __func__, snd_device);
2067 ret = -EINVAL;
2068 goto done;
2069 }
2070
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002071 ALOGV("%s: acdb_device_table[%s]: old = %d new = %d", __func__,
2072 platform_get_snd_device_name(snd_device), acdb_device_table[snd_device], acdb_id);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002073 acdb_device_table[snd_device] = acdb_id;
2074done:
2075 return ret;
2076}
2077
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07002078int platform_get_snd_device_acdb_id(snd_device_t snd_device)
2079{
2080 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
2081 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
2082 return -EINVAL;
2083 }
keunhui.park2f7306a2015-07-16 16:48:06 +09002084
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002085 /*
2086 * If speaker protection is enabled, function returns supported
2087 * sound device for speaker. Else same sound device is returned.
2088 */
2089 snd_device = audio_extn_get_spkr_prot_snd_device(snd_device);
2090
keunhui.park2f7306a2015-07-16 16:48:06 +09002091 if (operator_specific_device_table[snd_device] != NULL)
2092 return get_operator_specific_device_acdb_id(snd_device);
2093 else
2094 return acdb_device_table[snd_device];
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07002095}
2096
David Linee3fe402017-03-13 10:00:42 -07002097static int platform_get_backend_index(snd_device_t snd_device)
2098{
2099 int32_t port = DEFAULT_CODEC_BACKEND;
2100
2101 if (snd_device >= SND_DEVICE_OUT_BEGIN && snd_device < SND_DEVICE_OUT_END) {
2102 if (backend_tag_table[snd_device] != NULL) {
2103 if (strncmp(backend_tag_table[snd_device], "headphones",
2104 sizeof("headphones")) == 0)
2105 port = HEADPHONE_BACKEND;
2106 else if (strcmp(backend_tag_table[snd_device], "hdmi") == 0)
2107 port = HDMI_RX_BACKEND;
2108 else if ((strcmp(backend_tag_table[snd_device], "usb-headphones") == 0) ||
2109 (strcmp(backend_tag_table[snd_device], "usb-headset") == 0))
2110 port = USB_AUDIO_RX_BACKEND;
2111 }
2112 } else if (snd_device >= SND_DEVICE_IN_BEGIN && snd_device < SND_DEVICE_IN_END) {
2113 port = DEFAULT_CODEC_TX_BACKEND;
2114 if (backend_tag_table[snd_device] != NULL) {
2115 if (strcmp(backend_tag_table[snd_device], "usb-headset-mic") == 0)
2116 port = USB_AUDIO_TX_BACKEND;
2117 else if (strstr(backend_tag_table[snd_device], "bt-sco") != NULL)
2118 port = BT_SCO_TX_BACKEND;
2119 }
2120 } else {
2121 ALOGW("%s:napb: Invalid device - %d ", __func__, snd_device);
2122 }
2123
2124 ALOGV("%s:napb: backend port - %d device - %d ", __func__, port, snd_device);
2125
2126 return port;
2127}
2128
Eric Laurentb23d5282013-05-14 15:27:20 -07002129int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
2130{
2131 struct platform_data *my_data = (struct platform_data *)platform;
2132 int acdb_dev_id, acdb_dev_type;
2133
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002134 if (platform_supports_app_type_cfg()) // use v2 instead
2135 return -ENOSYS;
2136
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002137 acdb_dev_id = platform_get_snd_device_acdb_id(snd_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07002138 if (acdb_dev_id < 0) {
2139 ALOGE("%s: Could not find acdb id for device(%d)",
2140 __func__, snd_device);
2141 return -EINVAL;
2142 }
2143 if (my_data->acdb_send_audio_cal) {
Joe Onorato188b6222016-03-01 11:02:27 -08002144 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Eric Laurentb23d5282013-05-14 15:27:20 -07002145 __func__, snd_device, acdb_dev_id);
2146 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
2147 snd_device < SND_DEVICE_OUT_END)
2148 acdb_dev_type = ACDB_DEV_TYPE_OUT;
2149 else
2150 acdb_dev_type = ACDB_DEV_TYPE_IN;
2151 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
2152 }
2153 return 0;
2154}
2155
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002156int platform_send_audio_calibration_v2(void *platform, struct audio_usecase *usecase,
2157 int app_type, int sample_rate)
2158{
2159 struct platform_data *my_data = (struct platform_data *)platform;
2160 int acdb_dev_id, acdb_dev_type;
vivek mehta7e573672018-03-13 17:41:41 -07002161 int snd_device = usecase->out_snd_device;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002162 int new_snd_device[SND_DEVICE_OUT_END] = {0};
2163 int i, num_devices = 1;
2164
2165 if (!platform_supports_app_type_cfg()) // use v1 instead
2166 return -ENOSYS;
2167
vivek mehta7e573672018-03-13 17:41:41 -07002168 if ((usecase->type == PCM_HFP_CALL) || (usecase->type == PCM_CAPTURE))
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002169 snd_device = usecase->in_snd_device;
2170
2171 // skipped over get_spkr_prot_device
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002172 acdb_dev_id = platform_get_snd_device_acdb_id(snd_device);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002173 if (acdb_dev_id < 0) {
2174 ALOGE("%s: Could not find acdb id for device(%d)",
2175 __func__, snd_device);
2176 return -EINVAL;
2177 }
2178
2179 if (platform_can_split_snd_device(snd_device,
2180 &num_devices, new_snd_device) < 0) {
2181 new_snd_device[0] = snd_device;
2182 }
2183
2184 for (i = 0; i < num_devices; i++) {
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002185 acdb_dev_id = platform_get_snd_device_acdb_id(new_snd_device[i]);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002186 if (acdb_dev_id < 0) {
2187 ALOGE("%s: Could not find acdb id for device(%d)",
2188 __func__, new_snd_device[i]);
2189 return -EINVAL;
2190 }
2191 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
2192 __func__, new_snd_device[i], acdb_dev_id);
2193 if (new_snd_device[i] >= SND_DEVICE_OUT_BEGIN &&
2194 new_snd_device[i] < SND_DEVICE_OUT_END)
2195 acdb_dev_type = ACDB_DEV_TYPE_OUT;
2196 else
2197 acdb_dev_type = ACDB_DEV_TYPE_IN;
2198
2199 if (my_data->acdb_send_audio_cal_v3) {
2200 my_data->acdb_send_audio_cal_v3(acdb_dev_id, acdb_dev_type,
2201 app_type, sample_rate, i);
2202 } else if (my_data->acdb_send_audio_cal) {
2203 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type); // this version differs from internal
2204 }
2205 }
2206
2207 return 0;
2208}
2209
2210
Eric Laurentb23d5282013-05-14 15:27:20 -07002211int platform_switch_voice_call_device_pre(void *platform)
2212{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002213 struct platform_data *my_data = (struct platform_data *)platform;
2214 int ret = 0;
2215
2216 if (my_data->csd != NULL &&
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002217 voice_is_in_call(my_data->adev)) {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002218 /* This must be called before disabling mixer controls on APQ side */
2219 ret = my_data->csd->disable_device();
2220 if (ret < 0) {
2221 ALOGE("%s: csd_client_disable_device, failed, error %d",
2222 __func__, ret);
2223 }
2224 }
2225 return ret;
2226}
2227
2228int platform_switch_voice_call_enable_device_config(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 int ret = 0;
2235
2236 if (my_data->csd == NULL)
2237 return ret;
2238
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002239 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
keunhui.park2f7306a2015-07-16 16:48:06 +09002240 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002241
2242 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
2243 ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
2244 if (ret < 0) {
2245 ALOGE("%s: csd_enable_device_config, failed, error %d",
2246 __func__, ret);
2247 }
2248 } else {
2249 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2250 acdb_rx_id, acdb_tx_id);
2251 }
2252
2253 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002254}
2255
2256int platform_switch_voice_call_device_post(void *platform,
2257 snd_device_t out_snd_device,
2258 snd_device_t in_snd_device)
2259{
2260 struct platform_data *my_data = (struct platform_data *)platform;
2261 int acdb_rx_id, acdb_tx_id;
2262
2263 if (my_data->acdb_send_voice_cal == NULL) {
2264 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
2265 } else {
keunhui.park2f7306a2015-07-16 16:48:06 +09002266 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
2267 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07002268
2269 if (acdb_rx_id > 0 && acdb_tx_id > 0)
2270 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
2271 else
2272 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2273 acdb_rx_id, acdb_tx_id);
2274 }
2275
2276 return 0;
2277}
2278
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002279int platform_switch_voice_call_usecase_route_post(void *platform,
2280 snd_device_t out_snd_device,
2281 snd_device_t in_snd_device)
2282{
2283 struct platform_data *my_data = (struct platform_data *)platform;
2284 int acdb_rx_id, acdb_tx_id;
2285 int ret = 0;
2286
2287 if (my_data->csd == NULL)
2288 return ret;
2289
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002290 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
keunhui.park2f7306a2015-07-16 16:48:06 +09002291 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002292
2293 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
2294 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
2295 my_data->adev->acdb_settings);
2296 if (ret < 0) {
2297 ALOGE("%s: csd_enable_device, failed, error %d", __func__, ret);
2298 }
2299 } else {
2300 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2301 acdb_rx_id, acdb_tx_id);
2302 }
2303
2304 return ret;
2305}
2306
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002307int platform_start_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07002308{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002309 struct platform_data *my_data = (struct platform_data *)platform;
2310 int ret = 0;
2311
2312 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002313 ret = my_data->csd->start_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002314 if (ret < 0) {
2315 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
2316 }
2317 }
2318 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002319}
2320
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002321int platform_stop_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07002322{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002323 struct platform_data *my_data = (struct platform_data *)platform;
2324 int ret = 0;
2325
2326 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002327 ret = my_data->csd->stop_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002328 if (ret < 0) {
2329 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
2330 }
2331 }
2332 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002333}
2334
Vignesh Kulothunganb6f0a9c2018-03-22 13:50:22 -07002335int platform_set_mic_break_det(void *platform, bool enable)
2336{
2337 int ret = 0;
2338 struct platform_data *my_data = (struct platform_data *)platform;
2339 struct audio_device *adev = my_data->adev;
2340 const char *mixer_ctl_name = "Voice Mic Break Enable";
2341 struct mixer_ctl *ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2342 if (!ctl) {
2343 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2344 __func__, mixer_ctl_name);
2345 return -EINVAL;
2346 }
2347
2348 ret = mixer_ctl_set_value(ctl, 0, enable);
2349 if(ret)
2350 ALOGE("%s: Failed to set mixer ctl: %s", __func__, mixer_ctl_name);
2351
2352 return ret;
2353}
2354
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002355int platform_get_sample_rate(void *platform, uint32_t *rate)
2356{
2357 struct platform_data *my_data = (struct platform_data *)platform;
2358 int ret = 0;
2359
2360 if (my_data->csd != NULL) {
2361 ret = my_data->csd->get_sample_rate(rate);
2362 if (ret < 0) {
2363 ALOGE("%s: csd_get_sample_rate error %d\n", __func__, ret);
2364 }
2365 }
2366 return ret;
2367}
2368
vivek mehtab6506412015-08-07 16:55:17 -07002369void platform_set_speaker_gain_in_combo(struct audio_device *adev,
2370 snd_device_t snd_device,
2371 bool enable)
2372{
2373 const char* name;
2374 switch (snd_device) {
2375 case SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES:
2376 if (enable)
2377 name = "spkr-gain-in-headphone-combo";
2378 else
2379 name = "speaker-gain-default";
2380 break;
2381 case SND_DEVICE_OUT_SPEAKER_AND_LINE:
2382 if (enable)
2383 name = "spkr-gain-in-line-combo";
2384 else
2385 name = "speaker-gain-default";
2386 break;
2387 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES:
2388 if (enable)
2389 name = "spkr-safe-gain-in-headphone-combo";
2390 else
2391 name = "speaker-safe-gain-default";
2392 break;
2393 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE:
2394 if (enable)
2395 name = "spkr-safe-gain-in-line-combo";
2396 else
2397 name = "speaker-safe-gain-default";
2398 break;
2399 default:
2400 return;
2401 }
2402
2403 audio_route_apply_and_update_path(adev->audio_route, name);
2404}
2405
Eric Laurentb23d5282013-05-14 15:27:20 -07002406int platform_set_voice_volume(void *platform, int volume)
2407{
2408 struct platform_data *my_data = (struct platform_data *)platform;
2409 struct audio_device *adev = my_data->adev;
2410 struct mixer_ctl *ctl;
sangwoo53b2cf02013-07-25 19:18:44 -07002411 const char *mixer_ctl_name = "Voice Rx Gain";
Nadav Barc46d0fa2017-12-24 14:50:37 +02002412 const char *mute_mixer_ctl_name = "Voice Rx Device Mute";
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002413 int vol_index = 0, ret = 0;
2414 uint32_t set_values[ ] = {0,
2415 ALL_SESSION_VSID,
2416 DEFAULT_VOLUME_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07002417
2418 // Voice volume levels are mapped to adsp volume levels as follows.
2419 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
2420 // But this values don't changed in kernel. So, below change is need.
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09002421 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, my_data->max_vol_index);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002422 set_values[0] = vol_index;
Eric Laurentb23d5282013-05-14 15:27:20 -07002423
2424 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2425 if (!ctl) {
2426 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2427 __func__, mixer_ctl_name);
2428 return -EINVAL;
2429 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002430 ALOGV("Setting voice volume index: %d", set_values[0]);
2431 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2432
Nadav Barc46d0fa2017-12-24 14:50:37 +02002433 // Send mute command in case volume index is max since indexes are inverted
2434 // for mixer controls.
2435 if (vol_index == my_data->max_vol_index) {
2436 set_values[0] = 1;
2437 }
2438 else {
2439 set_values[0] = 0;
2440 }
2441
2442 ctl = mixer_get_ctl_by_name(adev->mixer, mute_mixer_ctl_name);
2443 if (!ctl) {
2444 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2445 __func__, mute_mixer_ctl_name);
2446 return -EINVAL;
2447 }
2448 ALOGV("%s: Setting RX Device Mute to: %d", __func__, set_values[0]);
2449 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2450
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002451 if (my_data->csd != NULL) {
2452 ret = my_data->csd->volume(ALL_SESSION_VSID, volume,
2453 DEFAULT_VOLUME_RAMP_DURATION_MS);
2454 if (ret < 0) {
2455 ALOGE("%s: csd_volume error %d", __func__, ret);
2456 }
2457 }
2458 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002459}
2460
2461int platform_set_mic_mute(void *platform, bool state)
2462{
2463 struct platform_data *my_data = (struct platform_data *)platform;
2464 struct audio_device *adev = my_data->adev;
2465 struct mixer_ctl *ctl;
2466 const char *mixer_ctl_name = "Voice Tx Mute";
sangwoo53b2cf02013-07-25 19:18:44 -07002467 int ret = 0;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002468 uint32_t set_values[ ] = {0,
2469 ALL_SESSION_VSID,
2470 DEFAULT_MUTE_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07002471
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09002472 if (adev->mode != AUDIO_MODE_IN_CALL &&
2473 adev->mode != AUDIO_MODE_IN_COMMUNICATION)
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002474 return 0;
2475
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09002476 if (adev->enable_hfp)
2477 mixer_ctl_name = "HFP Tx Mute";
2478
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002479 set_values[0] = state;
2480 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2481 if (!ctl) {
2482 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2483 __func__, mixer_ctl_name);
2484 return -EINVAL;
2485 }
2486 ALOGV("Setting voice mute state: %d", state);
2487 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2488
2489 if (my_data->csd != NULL) {
2490 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state,
2491 DEFAULT_MUTE_RAMP_DURATION_MS);
sangwoo53b2cf02013-07-25 19:18:44 -07002492 if (ret < 0) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002493 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
sangwoo53b2cf02013-07-25 19:18:44 -07002494 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002495 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002496 return ret;
2497}
Eric Laurentb23d5282013-05-14 15:27:20 -07002498
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002499int platform_set_device_mute(void *platform, bool state, char *dir)
2500{
2501 struct platform_data *my_data = (struct platform_data *)platform;
2502 struct audio_device *adev = my_data->adev;
2503 struct mixer_ctl *ctl;
2504 char *mixer_ctl_name = NULL;
2505 int ret = 0;
2506 uint32_t set_values[ ] = {0,
2507 ALL_SESSION_VSID,
2508 0};
2509 if(dir == NULL) {
2510 ALOGE("%s: Invalid direction:%s", __func__, dir);
2511 return -EINVAL;
2512 }
2513
2514 if (!strncmp("rx", dir, sizeof("rx"))) {
2515 mixer_ctl_name = "Voice Rx Device Mute";
2516 } else if (!strncmp("tx", dir, sizeof("tx"))) {
2517 mixer_ctl_name = "Voice Tx Device Mute";
2518 } else {
2519 return -EINVAL;
2520 }
2521
2522 set_values[0] = state;
2523 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2524 if (!ctl) {
2525 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2526 __func__, mixer_ctl_name);
2527 return -EINVAL;
2528 }
2529
2530 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
2531 __func__,state, mixer_ctl_name);
2532 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2533
2534 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002535}
2536
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002537int platform_can_split_snd_device(snd_device_t snd_device,
2538 int *num_devices,
2539 snd_device_t *new_snd_devices)
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002540{
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002541 int ret = -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002542 if (NULL == num_devices || NULL == new_snd_devices) {
2543 ALOGE("%s: NULL pointer ..", __func__);
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002544 return -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002545 }
2546
2547 /*
2548 * If wired headset/headphones/line devices share the same backend
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002549 * with speaker/earpiece this routine returns -EINVAL.
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002550 */
2551 if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES &&
2552 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_HEADPHONES)) {
2553 *num_devices = 2;
2554 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2555 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002556 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002557 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_LINE &&
2558 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_LINE)) {
2559 *num_devices = 2;
2560 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2561 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002562 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002563 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES &&
2564 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_HEADPHONES)) {
2565 *num_devices = 2;
2566 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2567 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002568 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002569 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE &&
2570 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_LINE)) {
2571 *num_devices = 2;
2572 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2573 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002574 ret = 0;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002575 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO &&
2576 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2577 SND_DEVICE_OUT_BT_SCO)) {
2578 *num_devices = 2;
2579 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2580 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO;
2581 ret = 0;
juyuchen5351ea62018-05-16 10:54:37 +08002582 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO &&
2583 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE,
2584 SND_DEVICE_OUT_BT_SCO)) {
2585 *num_devices = 2;
2586 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2587 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO;
2588 ret = 0;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002589 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB &&
2590 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2591 SND_DEVICE_OUT_BT_SCO_WB)) {
2592 *num_devices = 2;
2593 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2594 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO_WB;
2595 ret = 0;
juyuchen5351ea62018-05-16 10:54:37 +08002596 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB &&
2597 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE,
2598 SND_DEVICE_OUT_BT_SCO_WB)) {
2599 *num_devices = 2;
2600 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2601 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO_WB;
2602 ret = 0;
David Linee3fe402017-03-13 10:00:42 -07002603 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET &&
2604 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_USB_HEADSET)) {
2605 *num_devices = 2;
2606 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2607 new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
2608 ret = 0;
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07002609 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET &&
2610 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_USB_HEADSET)) {
2611 *num_devices = 2;
2612 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2613 new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
2614 ret = 0;
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002615 } else if (SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP == snd_device &&
2616 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2617 SND_DEVICE_OUT_BT_A2DP)) {
2618 *num_devices = 2;
2619 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2620 new_snd_devices[1] = SND_DEVICE_OUT_BT_A2DP;
2621 ret = 0;
Aniket Kumar Lata9723a962018-05-16 17:41:55 -07002622 } else if (SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP == snd_device &&
2623 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE,
2624 SND_DEVICE_OUT_BT_A2DP)) {
2625 *num_devices = 2;
2626 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2627 new_snd_devices[1] = SND_DEVICE_OUT_BT_A2DP;
2628 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002629 }
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002630
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002631 return ret;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002632}
2633
Eric Laurentb23d5282013-05-14 15:27:20 -07002634snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
2635{
2636 struct platform_data *my_data = (struct platform_data *)platform;
2637 struct audio_device *adev = my_data->adev;
2638 audio_mode_t mode = adev->mode;
2639 snd_device_t snd_device = SND_DEVICE_NONE;
2640
2641 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
2642 if (devices == AUDIO_DEVICE_NONE ||
2643 devices & AUDIO_DEVICE_BIT_IN) {
2644 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
2645 goto exit;
2646 }
2647
Eric Laurent1b491552015-09-15 17:52:41 -07002648 if (popcount(devices) == 2) {
2649 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2650 AUDIO_DEVICE_OUT_SPEAKER) ||
2651 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2652 AUDIO_DEVICE_OUT_SPEAKER)) {
2653 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
2654 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2655 AUDIO_DEVICE_OUT_SPEAKER)) {
2656 snd_device = SND_DEVICE_OUT_SPEAKER_AND_LINE;
2657 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2658 AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
2659 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2660 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2661 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES;
2662 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2663 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2664 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE;
2665 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
2666 AUDIO_DEVICE_OUT_SPEAKER)) {
2667 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002668 } else if ((devices & AUDIO_DEVICE_OUT_ALL_SCO) &&
2669 ((devices & ~AUDIO_DEVICE_OUT_ALL_SCO) == AUDIO_DEVICE_OUT_SPEAKER)) {
2670 snd_device = adev->bt_wb_speech_enabled ?
2671 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB :
2672 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO;
juyuchen5351ea62018-05-16 10:54:37 +08002673 } else if ((devices & AUDIO_DEVICE_OUT_ALL_SCO) &&
2674 ((devices & ~AUDIO_DEVICE_OUT_ALL_SCO) == AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2675 snd_device = adev->bt_wb_speech_enabled ?
2676 SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB :
2677 SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO;
Eric Laurent99dab492017-06-17 15:19:08 -07002678 } else if ((devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
2679 AUDIO_DEVICE_OUT_SPEAKER)) ||
2680 (devices == (AUDIO_DEVICE_OUT_USB_HEADSET |
2681 AUDIO_DEVICE_OUT_SPEAKER))) {
David Linee3fe402017-03-13 10:00:42 -07002682 snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET;
Eric Laurentd0f7c262017-07-05 09:09:12 -07002683 } else if ((devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
2684 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) ||
2685 (devices == (AUDIO_DEVICE_OUT_USB_HEADSET |
2686 AUDIO_DEVICE_OUT_SPEAKER_SAFE))) {
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07002687 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET;
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002688 } else if ((devices & AUDIO_DEVICE_OUT_SPEAKER) &&
2689 (devices & AUDIO_DEVICE_OUT_ALL_A2DP)) {
2690 snd_device = SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP;
Aniket Kumar Lata9723a962018-05-16 17:41:55 -07002691 } else if ((devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) &&
2692 (devices & AUDIO_DEVICE_OUT_ALL_A2DP)) {
2693 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP;
Eric Laurent1b491552015-09-15 17:52:41 -07002694 } else {
2695 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
2696 goto exit;
2697 }
2698 if (snd_device != SND_DEVICE_NONE) {
2699 goto exit;
2700 }
2701 }
2702
2703 if (popcount(devices) != 1) {
2704 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
2705 goto exit;
2706 }
2707
Madhuri Athota3f6051b2016-10-13 23:25:38 +05302708 if (voice_is_in_call(adev) || adev->enable_voicerx || audio_extn_hfp_is_active(adev)) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002709 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002710 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2711 devices & AUDIO_DEVICE_OUT_LINE) {
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002712 if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002713 (adev->voice.tty_mode == TTY_MODE_FULL))
Eric Laurentb23d5282013-05-14 15:27:20 -07002714 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002715 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002716 (adev->voice.tty_mode == TTY_MODE_VCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002717 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002718 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002719 (adev->voice.tty_mode == TTY_MODE_HCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002720 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002721 else {
2722 if (devices & AUDIO_DEVICE_OUT_LINE)
2723 snd_device = SND_DEVICE_OUT_VOICE_LINE;
yixuanjiang9536e672018-09-06 18:43:36 +08002724 else if (devices & AUDIO_DEVICE_OUT_WIRED_HEADSET)
2725 snd_device = SND_DEVICE_OUT_VOICE_HEADSET;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002726 else
2727 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
2728 }
Eric Laurent99dab492017-06-17 15:19:08 -07002729 } else if (audio_is_usb_out_device(devices)) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002730 if (voice_is_in_call(adev)) {
2731 switch (adev->voice.tty_mode) {
2732 case TTY_MODE_FULL:
2733 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_USB;
2734 break;
2735 case TTY_MODE_VCO:
2736 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_USB;
2737 break;
2738 case TTY_MODE_HCO:
2739 // since Hearing will be on handset\speaker, use existing device
2740 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
2741 break;
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002742 case TTY_MODE_OFF:
2743 break;
vivek mehtaa6b79742017-03-09 15:40:43 -08002744 default:
2745 ALOGE("%s: Invalid TTY mode (%#x)",
2746 __func__, adev->voice.tty_mode);
2747 }
2748 }
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002749 if (snd_device == SND_DEVICE_NONE) {
2750 snd_device = audio_extn_usb_is_capture_supported() ?
2751 SND_DEVICE_OUT_VOICE_USB_HEADSET :
2752 SND_DEVICE_OUT_VOICE_USB_HEADPHONES;
2753 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002754 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002755 if (adev->bt_wb_speech_enabled) {
2756 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2757 } else {
2758 snd_device = SND_DEVICE_OUT_BT_SCO;
2759 }
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002760 } else if (devices & AUDIO_DEVICE_OUT_ALL_A2DP) {
2761 snd_device = SND_DEVICE_OUT_BT_A2DP;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002762 } else if (devices & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002763 if (!adev->enable_hfp) {
2764 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
2765 } else {
2766 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_HFP;
2767 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002768 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002769 if(adev->voice.hac)
2770 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2771 else if (is_operator_tmus())
Eric Laurentb23d5282013-05-14 15:27:20 -07002772 snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS;
2773 else
Eric Laurentb4d368e2014-06-25 10:21:54 -05002774 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002775 } else if (devices & AUDIO_DEVICE_OUT_TELEPHONY_TX)
2776 snd_device = SND_DEVICE_OUT_VOICE_TX;
2777
Eric Laurentb23d5282013-05-14 15:27:20 -07002778 if (snd_device != SND_DEVICE_NONE) {
2779 goto exit;
2780 }
2781 }
2782
Eric Laurentb23d5282013-05-14 15:27:20 -07002783 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2784 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2785 snd_device = SND_DEVICE_OUT_HEADPHONES;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002786 } else if (devices & AUDIO_DEVICE_OUT_LINE) {
2787 snd_device = SND_DEVICE_OUT_LINE;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002788 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) {
2789 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE;
Eric Laurentb23d5282013-05-14 15:27:20 -07002790 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
andysu5b30b062018-04-20 16:34:06 +08002791 /*
2792 * Perform device switch only if acdb tuning is different between SPEAKER & SPEAKER_REVERSE,
2793 * Or there will be a small pause while performing device switch.
2794 */
2795 if (my_data->speaker_lr_swap &&
2796 (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
2797 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]))
Eric Laurentb23d5282013-05-14 15:27:20 -07002798 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
2799 else
2800 snd_device = SND_DEVICE_OUT_SPEAKER;
2801 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002802 if (adev->bt_wb_speech_enabled) {
2803 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2804 } else {
2805 snd_device = SND_DEVICE_OUT_BT_SCO;
2806 }
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002807 } else if (devices & AUDIO_DEVICE_OUT_ALL_A2DP) {
2808 snd_device = SND_DEVICE_OUT_BT_A2DP;
Eric Laurentb23d5282013-05-14 15:27:20 -07002809 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2810 snd_device = SND_DEVICE_OUT_HDMI ;
Eric Laurent99dab492017-06-17 15:19:08 -07002811 } else if (audio_is_usb_out_device(devices)) {
jasmine cha270b7762018-03-30 15:41:33 +08002812 if (audio_extn_ma_supported_usb())
2813 snd_device = SND_DEVICE_OUT_USB_HEADSET_SPEC;
2814 else if (audio_extn_usb_is_capture_supported())
David Linee3fe402017-03-13 10:00:42 -07002815 snd_device = SND_DEVICE_OUT_USB_HEADSET;
2816 else
2817 snd_device = SND_DEVICE_OUT_USB_HEADPHONES;
2818 }else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002819 /*HAC support for voice-ish audio (eg visual voicemail)*/
2820 if(adev->voice.hac)
2821 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2822 else
2823 snd_device = SND_DEVICE_OUT_HANDSET;
Eric Laurentb23d5282013-05-14 15:27:20 -07002824 } else {
2825 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
2826 }
2827exit:
2828 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
2829 return snd_device;
2830}
2831
2832snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
2833{
2834 struct platform_data *my_data = (struct platform_data *)platform;
2835 struct audio_device *adev = my_data->adev;
2836 audio_source_t source = (adev->active_input == NULL) ?
2837 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
2838
2839 audio_mode_t mode = adev->mode;
2840 audio_devices_t in_device = ((adev->active_input == NULL) ?
2841 AUDIO_DEVICE_NONE : adev->active_input->device)
2842 & ~AUDIO_DEVICE_BIT_IN;
2843 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
2844 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
2845 snd_device_t snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002846 int channel_count = popcount(channel_mask);
Eric Laurentb23d5282013-05-14 15:27:20 -07002847
Prashant Malanic92c5962015-08-11 15:10:18 -07002848 ALOGV("%s: enter: out_device(%#x) in_device(%#x) channel_count (%d) channel_mask (0x%x)",
2849 __func__, out_device, in_device, channel_count, channel_mask);
Devin Kimd789e432016-10-26 15:07:27 -07002850 if ((out_device != AUDIO_DEVICE_NONE) && (voice_is_in_call(adev) ||
2851 audio_extn_hfp_is_active(adev))) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002852 if (adev->voice.tty_mode != TTY_MODE_OFF) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002853 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002854 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2855 out_device & AUDIO_DEVICE_OUT_LINE) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002856 switch (adev->voice.tty_mode) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002857 case TTY_MODE_FULL:
2858 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
2859 break;
2860 case TTY_MODE_VCO:
2861 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
2862 break;
2863 case TTY_MODE_HCO:
2864 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
2865 break;
2866 default:
2867 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
2868 }
2869 goto exit;
Eric Laurent99dab492017-06-17 15:19:08 -07002870 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002871 switch (adev->voice.tty_mode) {
2872 case TTY_MODE_FULL:
2873 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC;
2874 break;
2875 case TTY_MODE_VCO:
2876 // since voice will be captured from handset mic, use existing device
2877 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
2878 break;
2879 case TTY_MODE_HCO:
2880 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC;
2881 break;
2882 default:
2883 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
Eric Laurentb23d5282013-05-14 15:27:20 -07002884 }
2885 goto exit;
2886 }
2887 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002888 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002889 if (my_data->fluence_in_voice_call == false) {
2890 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2891 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002892 if (is_operator_tmus())
2893 snd_device = SND_DEVICE_IN_VOICE_DMIC_TMUS;
Eric Laurentb23d5282013-05-14 15:27:20 -07002894 else
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002895 snd_device = SND_DEVICE_IN_VOICE_DMIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002896 }
2897 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2898 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
2899 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002900 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002901 if (adev->bluetooth_nrec)
2902 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2903 else
2904 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002905 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002906 if (adev->bluetooth_nrec)
2907 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2908 else
2909 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002910 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002911 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Prashant Malanic92c5962015-08-11 15:10:18 -07002912 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
2913 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2914 out_device & AUDIO_DEVICE_OUT_LINE) {
2915 if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
2916 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
2917 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
2918 } else {
2919 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2920 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002921 }
vivek mehtafe121d52015-08-10 23:39:23 -07002922
2923 //select default
2924 if (snd_device == SND_DEVICE_NONE) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002925 if (!adev->enable_hfp) {
2926 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2927 } else {
2928 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP;
2929 platform_set_echo_reference(adev, true, out_device);
2930 }
vivek mehtafe121d52015-08-10 23:39:23 -07002931 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002932 } else if (out_device & AUDIO_DEVICE_OUT_TELEPHONY_TX) {
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002933 snd_device = SND_DEVICE_IN_VOICE_RX;
Eric Laurent99dab492017-06-17 15:19:08 -07002934 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
David Lin40b07892017-08-07 15:02:48 -07002935 if (audio_extn_usb_is_capture_supported()) {
2936 snd_device = SND_DEVICE_IN_VOICE_USB_HEADSET_MIC;
2937 } else if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
2938 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
2939 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
2940 } else {
2941 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2942 }
2943 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002944 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002945 } else if (source == AUDIO_SOURCE_CAMCORDER) {
2946 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
2947 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2948 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
2949 }
2950 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
2951 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002952 if (my_data->fluence_in_voice_rec && channel_count == 1) {
2953 if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2954 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002955 if (adev->active_input->enable_aec)
2956 snd_device = SND_DEVICE_IN_HANDSET_QMIC_AEC;
2957 else
2958 snd_device = SND_DEVICE_IN_HANDSET_QMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002959 } else if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2960 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002961 if (adev->active_input->enable_aec)
2962 snd_device = SND_DEVICE_IN_HANDSET_TMIC_AEC;
2963 else
2964 snd_device = SND_DEVICE_IN_HANDSET_TMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002965 } else if (((my_data->fluence_type == FLUENCE_PRO_ENABLE) ||
2966 (my_data->fluence_type == FLUENCE_ENABLE)) &&
2967 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002968 if (adev->active_input->enable_aec)
2969 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
2970 else
2971 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
Prashant Malanic92c5962015-08-11 15:10:18 -07002972 }
2973 platform_set_echo_reference(adev, true, out_device);
2974 } else if ((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) &&
2975 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2976 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002977 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002978 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
2979 snd_device = SND_DEVICE_IN_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002980 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002981 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2982 snd_device = SND_DEVICE_IN_QUAD_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002983 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002984 if (snd_device == SND_DEVICE_NONE) {
vivek mehtaf3440682016-05-11 14:24:37 -07002985 if (adev->active_input->enable_aec) {
2986 if (adev->active_input->enable_ns) {
2987 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS;
2988 } else {
2989 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC;
2990 }
vivek mehta733c1df2016-04-04 15:09:24 -07002991 platform_set_echo_reference(adev, true, out_device);
vivek mehtaf3440682016-05-11 14:24:37 -07002992 } else if (adev->active_input->enable_ns) {
2993 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
2994 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002995 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
vivek mehtaf3440682016-05-11 14:24:37 -07002996 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002997 }
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -07002998 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2999 snd_device = SND_DEVICE_IN_VOICE_REC_HEADSET_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07003000 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07003001 snd_device = SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07003002 }
rago90fb9612015-12-02 11:37:53 -08003003 } else if (source == AUDIO_SOURCE_UNPROCESSED) {
3004 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
vivek mehta4ed66e62016-04-15 23:33:34 -07003005 if (((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) ||
3006 (channel_mask == AUDIO_CHANNEL_IN_STEREO)) &&
3007 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
3008 snd_device = SND_DEVICE_IN_UNPROCESSED_STEREO_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003009 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07003010 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
3011 snd_device = SND_DEVICE_IN_UNPROCESSED_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003012 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07003013 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
3014 snd_device = SND_DEVICE_IN_UNPROCESSED_QUAD_MIC;
3015 } else {
3016 snd_device = SND_DEVICE_IN_UNPROCESSED_MIC;
3017 }
rago90fb9612015-12-02 11:37:53 -08003018 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3019 snd_device = SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07003020 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07003021 snd_device = SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC;
rago90fb9612015-12-02 11:37:53 -08003022 }
Eric Laurent50a38ed2015-10-14 18:48:06 -07003023 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION ||
rago90fb9612015-12-02 11:37:53 -08003024 mode == AUDIO_MODE_IN_COMMUNICATION) {
David Lin40b07892017-08-07 15:02:48 -07003025 if (out_device & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
3026 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
3027 (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE | AUDIO_DEVICE_OUT_USB_HEADSET) &&
3028 !audio_extn_usb_is_capture_supported())) {
Eric Laurentb23d5282013-05-14 15:27:20 -07003029 in_device = AUDIO_DEVICE_IN_BACK_MIC;
David Lin40b07892017-08-07 15:02:48 -07003030 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003031 if (adev->active_input) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003032 if (adev->active_input->enable_aec &&
3033 adev->active_input->enable_ns) {
Eric Laurentb23d5282013-05-14 15:27:20 -07003034 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003035 if (my_data->fluence_in_spkr_mode &&
3036 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003037 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003038 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003039 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003040 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003041 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003042 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003043 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003044 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003045 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003046 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003047 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003048 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05003049 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3050 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Eric Laurent99dab492017-06-17 15:19:08 -07003051 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07003052 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
Eric Laurentb23d5282013-05-14 15:27:20 -07003053 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05003054 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003055 } else if (adev->active_input->enable_aec) {
3056 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
3057 if (my_data->fluence_in_spkr_mode &&
3058 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003059 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003060 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003061 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003062 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003063 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003064 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
3065 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003066 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003067 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003068 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003069 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003070 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05003071 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3072 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Eric Laurent99dab492017-06-17 15:19:08 -07003073 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07003074 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
Eric Laurentcefbbac2014-09-04 13:54:10 -05003075 }
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08003076 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003077 } else if (adev->active_input->enable_ns) {
3078 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
3079 if (my_data->fluence_in_spkr_mode &&
3080 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003081 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003082 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003083 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003084 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003085 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003086 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
3087 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003088 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003089 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003090 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003091 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003092 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003093 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05003094 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003095 }
3096 } else if (source == AUDIO_SOURCE_DEFAULT) {
3097 goto exit;
3098 }
3099
3100
3101 if (snd_device != SND_DEVICE_NONE) {
3102 goto exit;
3103 }
3104
3105 if (in_device != AUDIO_DEVICE_NONE &&
3106 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
3107 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
3108 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003109 if ((my_data->source_mic_type & SOURCE_QUAD_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003110 channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003111 snd_device = SND_DEVICE_IN_QUAD_MIC;
3112 } else if ((my_data->source_mic_type & SOURCE_THREE_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003113 channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003114 snd_device = SND_DEVICE_IN_THREE_MIC;
3115 } else if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
3116 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003117 snd_device = SND_DEVICE_IN_HANDSET_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07003118 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
3119 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003120 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003121 } else {
3122 ALOGE("%s: something wrong (1): source type (%d) channel_count (%d) .."
3123 " channel mask (0x%x) no combination found .. setting to mono", __func__,
3124 my_data->source_mic_type, channel_count, channel_mask);
3125 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3126 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003127 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003128 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
3129 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003130 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07003131 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
3132 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003133 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003134 } else {
3135 ALOGE("%s: something wrong (2): source type (%d) channel_count (%d) .."
3136 " no combination found .. setting to mono", __func__,
3137 my_data->source_mic_type, channel_count);
3138 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
3139 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003140 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3141 snd_device = SND_DEVICE_IN_HEADSET_MIC;
3142 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003143 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003144 if (adev->bluetooth_nrec)
3145 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
3146 else
3147 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003148 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003149 if (adev->bluetooth_nrec)
3150 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
3151 else
3152 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003153 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003154 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
3155 snd_device = SND_DEVICE_IN_HDMI_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07003156 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
David Linee3fe402017-03-13 10:00:42 -07003157 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07003158 } else {
3159 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
3160 ALOGW("%s: Using default handset-mic", __func__);
3161 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3162 }
3163 } else {
3164 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
3165 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3166 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
3167 snd_device = SND_DEVICE_IN_HEADSET_MIC;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003168 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07003169 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003170 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05003171 out_device & AUDIO_DEVICE_OUT_LINE) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003172 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
3173 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003174 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07003175 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
3176 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003177 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003178 } else {
3179 ALOGE("%s: something wrong (3): source type (%d) channel_count (%d) .."
3180 " no combination found .. setting to mono", __func__,
3181 my_data->source_mic_type, channel_count);
3182 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
3183 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003184 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003185 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003186 if (adev->bluetooth_nrec)
3187 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
3188 else
3189 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003190 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003191 if (adev->bluetooth_nrec)
3192 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
3193 else
3194 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003195 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003196 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
3197 snd_device = SND_DEVICE_IN_HDMI_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07003198 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
David Linee3fe402017-03-13 10:00:42 -07003199 if (audio_extn_usb_is_capture_supported())
3200 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
3201 else
3202 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07003203 } else {
3204 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
3205 ALOGW("%s: Using default handset-mic", __func__);
3206 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3207 }
3208 }
3209exit:
3210 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
3211 return snd_device;
3212}
3213
3214int platform_set_hdmi_channels(void *platform, int channel_count)
3215{
3216 struct platform_data *my_data = (struct platform_data *)platform;
3217 struct audio_device *adev = my_data->adev;
3218 struct mixer_ctl *ctl;
3219 const char *channel_cnt_str = NULL;
3220 const char *mixer_ctl_name = "HDMI_RX Channels";
3221 switch (channel_count) {
3222 case 8:
3223 channel_cnt_str = "Eight"; break;
3224 case 7:
3225 channel_cnt_str = "Seven"; break;
3226 case 6:
3227 channel_cnt_str = "Six"; break;
3228 case 5:
3229 channel_cnt_str = "Five"; break;
3230 case 4:
3231 channel_cnt_str = "Four"; break;
3232 case 3:
3233 channel_cnt_str = "Three"; break;
3234 default:
3235 channel_cnt_str = "Two"; break;
3236 }
3237 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3238 if (!ctl) {
3239 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3240 __func__, mixer_ctl_name);
3241 return -EINVAL;
3242 }
3243 ALOGV("HDMI channel count: %s", channel_cnt_str);
3244 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
3245 return 0;
3246}
3247
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003248int platform_edid_get_max_channels(void *platform)
Eric Laurentb23d5282013-05-14 15:27:20 -07003249{
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003250 struct platform_data *my_data = (struct platform_data *)platform;
3251 struct audio_device *adev = my_data->adev;
Eric Laurentb23d5282013-05-14 15:27:20 -07003252 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
3253 char *sad = block;
3254 int num_audio_blocks;
3255 int channel_count;
3256 int max_channels = 0;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003257 int i, ret, count;
Eric Laurentb23d5282013-05-14 15:27:20 -07003258
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003259 struct mixer_ctl *ctl;
3260
3261 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
3262 if (!ctl) {
3263 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3264 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
Eric Laurentb23d5282013-05-14 15:27:20 -07003265 return 0;
3266 }
3267
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003268 mixer_ctl_update(ctl);
3269
3270 count = mixer_ctl_get_num_values(ctl);
Eric Laurentb23d5282013-05-14 15:27:20 -07003271
3272 /* Read SAD blocks, clamping the maximum size for safety */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003273 if (count > (int)sizeof(block))
3274 count = (int)sizeof(block);
Eric Laurentb23d5282013-05-14 15:27:20 -07003275
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003276 ret = mixer_ctl_get_array(ctl, block, count);
3277 if (ret != 0) {
3278 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
3279 return 0;
3280 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003281
3282 /* Calculate the number of SAD blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003283 num_audio_blocks = count / SAD_BLOCK_SIZE;
Eric Laurentb23d5282013-05-14 15:27:20 -07003284
3285 for (i = 0; i < num_audio_blocks; i++) {
3286 /* Only consider LPCM blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003287 if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
3288 sad += 3;
Eric Laurentb23d5282013-05-14 15:27:20 -07003289 continue;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003290 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003291
3292 channel_count = (sad[0] & 0x7) + 1;
3293 if (channel_count > max_channels)
3294 max_channels = channel_count;
3295
3296 /* Advance to next block */
3297 sad += 3;
3298 }
3299
3300 return max_channels;
3301}
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003302
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07003303int platform_set_incall_recording_session_id(void *platform,
3304 uint32_t session_id, int rec_mode)
3305{
3306 int ret = 0;
3307 struct platform_data *my_data = (struct platform_data *)platform;
3308 struct audio_device *adev = my_data->adev;
3309 struct mixer_ctl *ctl;
3310 const char *mixer_ctl_name = "Voc VSID";
3311 int num_ctl_values;
3312 int i;
3313
3314 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3315 if (!ctl) {
3316 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3317 __func__, mixer_ctl_name);
3318 ret = -EINVAL;
3319 } else {
3320 num_ctl_values = mixer_ctl_get_num_values(ctl);
3321 for (i = 0; i < num_ctl_values; i++) {
3322 if (mixer_ctl_set_value(ctl, i, session_id)) {
3323 ALOGV("Error: invalid session_id: %x", session_id);
3324 ret = -EINVAL;
3325 break;
3326 }
3327 }
3328 }
3329
3330 if (my_data->csd != NULL) {
3331 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
3332 if (ret < 0) {
3333 ALOGE("%s: csd_client_start_record failed, error %d",
3334 __func__, ret);
3335 }
3336 }
3337
3338 return ret;
3339}
3340
Arun Mirpuriba2749a2018-04-17 14:32:24 -07003341int platform_set_incall_recording_session_channels(void *platform,
3342 uint32_t channel_count)
3343{
3344 int ret = 0;
3345 struct platform_data *my_data = (struct platform_data *)platform;
3346 struct audio_device *adev = my_data->adev;
3347 const char *mixer_ctl_name = "Voc Rec Config";
3348 int num_ctl_values;
3349 int i;
3350 struct mixer_ctl *ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3351
3352 if (!ctl) {
3353 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3354 __func__, mixer_ctl_name);
3355 ret = -EINVAL;
3356 } else {
3357 num_ctl_values = mixer_ctl_get_num_values(ctl);
3358 for (i = 0; i < num_ctl_values; i++) {
3359 if (mixer_ctl_set_value(ctl, i, channel_count)) {
3360 ALOGE("Error: invalid channel count: %x", channel_count);
3361 ret = -EINVAL;
3362 break;
3363 }
3364 }
3365 }
3366
3367 return ret;
3368}
3369
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07003370int platform_stop_incall_recording_usecase(void *platform)
3371{
3372 int ret = 0;
3373 struct platform_data *my_data = (struct platform_data *)platform;
3374
3375 if (my_data->csd != NULL) {
3376 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
3377 if (ret < 0) {
3378 ALOGE("%s: csd_client_stop_record failed, error %d",
3379 __func__, ret);
3380 }
3381 }
3382
3383 return ret;
3384}
3385
3386int platform_start_incall_music_usecase(void *platform)
3387{
3388 int ret = 0;
3389 struct platform_data *my_data = (struct platform_data *)platform;
3390
3391 if (my_data->csd != NULL) {
3392 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
3393 if (ret < 0) {
3394 ALOGE("%s: csd_client_start_playback failed, error %d",
3395 __func__, ret);
3396 }
3397 }
3398
3399 return ret;
3400}
3401
3402int platform_stop_incall_music_usecase(void *platform)
3403{
3404 int ret = 0;
3405 struct platform_data *my_data = (struct platform_data *)platform;
3406
3407 if (my_data->csd != NULL) {
3408 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
3409 if (ret < 0) {
3410 ALOGE("%s: csd_client_stop_playback failed, error %d",
3411 __func__, ret);
3412 }
3413 }
3414
3415 return ret;
3416}
3417
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003418int platform_set_parameters(void *platform, struct str_parms *parms)
3419{
3420 struct platform_data *my_data = (struct platform_data *)platform;
jasmine chac89321b2018-04-10 21:37:01 +08003421 char *value = NULL;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003422 char *kv_pairs = str_parms_to_str(parms);
jasmine chac89321b2018-04-10 21:37:01 +08003423 int len;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003424 int ret = 0, err;
3425
3426 if (kv_pairs == NULL) {
3427 ret = -EINVAL;
Jasmine Chaa314e192018-05-09 17:46:28 +08003428 ALOGE("%s: key-value pair is NULL", __func__);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003429 goto done;
3430 }
3431
3432 ALOGV("%s: enter: %s", __func__, kv_pairs);
3433
jasmine chac89321b2018-04-10 21:37:01 +08003434 len = strlen(kv_pairs);
Jasmine Chaa314e192018-05-09 17:46:28 +08003435 value = (char*)calloc(len + 1, sizeof(char));
jasmine chac89321b2018-04-10 21:37:01 +08003436 if (value == NULL) {
3437 ret = -ENOMEM;
Jasmine Chaa314e192018-05-09 17:46:28 +08003438 ALOGE("[%s] failed to allocate memory", __func__);
jasmine chac89321b2018-04-10 21:37:01 +08003439 goto done;
3440 }
3441
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003442 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME,
jasmine chac89321b2018-04-10 21:37:01 +08003443 value, len);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003444 if (err >= 0) {
3445 str_parms_del(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME);
3446 my_data->snd_card_name = strdup(value);
3447 ALOGV("%s: sound card name %s", __func__, my_data->snd_card_name);
3448 }
3449
keunhui.park2f7306a2015-07-16 16:48:06 +09003450 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO,
jasmine chac89321b2018-04-10 21:37:01 +08003451 value, len);
keunhui.park2f7306a2015-07-16 16:48:06 +09003452 if (err >= 0) {
3453 struct operator_info *info;
3454 char *str = value;
3455 char *name;
3456
3457 str_parms_del(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO);
3458 info = (struct operator_info *)calloc(1, sizeof(struct operator_info));
3459 name = strtok(str, ";");
3460 info->name = strdup(name);
3461 info->mccmnc = strdup(str + strlen(name) + 1);
3462
3463 list_add_tail(&operator_info_list, &info->list);
Joe Onorato188b6222016-03-01 11:02:27 -08003464 ALOGV("%s: add operator[%s] mccmnc[%s]", __func__, info->name, info->mccmnc);
keunhui.park2f7306a2015-07-16 16:48:06 +09003465 }
Prashant Malanic92c5962015-08-11 15:10:18 -07003466
Jasmine Chaa314e192018-05-09 17:46:28 +08003467 memset(value, 0, len + 1);
Eric Laurentc6333382015-09-14 12:43:44 -07003468 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT,
jasmine chac89321b2018-04-10 21:37:01 +08003469 value, len);
Prashant Malanic92c5962015-08-11 15:10:18 -07003470 if (err >= 0) {
Eric Laurentc6333382015-09-14 12:43:44 -07003471 str_parms_del(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT);
Prashant Malanic92c5962015-08-11 15:10:18 -07003472 my_data->max_mic_count = atoi(value);
3473 ALOGV("%s: max_mic_count %s/%d", __func__, value, my_data->max_mic_count);
Prashant Malanic92c5962015-08-11 15:10:18 -07003474 }
3475
jasmine chac89321b2018-04-10 21:37:01 +08003476 /* handle audio calibration parameters */
3477 set_audiocal(platform, parms, value, len);
3478
vivek mehta90933872017-06-15 18:04:39 -07003479 // to-do: disable setting sidetone gain, will revist this later
3480 // audio_extn_usb_set_sidetone_gain(parms, value, len);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003481done:
3482 ALOGV("%s: exit with code(%d)", __func__, ret);
3483 if (kv_pairs != NULL)
3484 free(kv_pairs);
jasmine chac89321b2018-04-10 21:37:01 +08003485 if (value != NULL)
3486 free(value);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003487
3488 return ret;
3489}
3490
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003491/* Delay in Us */
3492int64_t platform_render_latency(audio_usecase_t usecase)
3493{
3494 switch (usecase) {
3495 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
3496 return DEEP_BUFFER_PLATFORM_DELAY;
3497 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
3498 return LOW_LATENCY_PLATFORM_DELAY;
Haynes Mathew George03c40102016-01-29 17:57:48 -08003499 case USECASE_AUDIO_PLAYBACK_ULL:
3500 return ULL_PLATFORM_DELAY;
Eric Laurent0e46adf2016-12-16 12:49:24 -08003501 case USECASE_AUDIO_PLAYBACK_MMAP:
3502 return MMAP_PLATFORM_DELAY;
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003503 default:
3504 return 0;
3505 }
3506}
Haynes Mathew George98c95622014-06-20 19:14:25 -07003507
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003508int platform_set_snd_device_backend(snd_device_t device, const char *backend_tag,
3509 const char * hw_interface)
Haynes Mathew George98c95622014-06-20 19:14:25 -07003510{
3511 int ret = 0;
3512
3513 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
3514 ALOGE("%s: Invalid snd_device = %d",
3515 __func__, device);
3516 ret = -EINVAL;
3517 goto done;
3518 }
3519
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003520 ALOGV("%s: backend_tag_table[%s]: old = %s new = %s", __func__,
3521 platform_get_snd_device_name(device),
3522 backend_tag_table[device] != NULL ? backend_tag_table[device]: "null", backend_tag);
3523 if (backend_tag_table[device]) {
3524 free(backend_tag_table[device]);
Haynes Mathew George98c95622014-06-20 19:14:25 -07003525 }
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003526 backend_tag_table[device] = strdup(backend_tag);
3527
3528 if (hw_interface != NULL) {
3529 if (hw_interface_table[device])
3530 free(hw_interface_table[device]);
3531 ALOGV("%s: hw_interface_table[%d] = %s", __func__, device, hw_interface);
3532 hw_interface_table[device] = strdup(hw_interface);
3533 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07003534done:
3535 return ret;
3536}
3537
3538int platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t pcm_id)
3539{
3540 int ret = 0;
3541 if ((usecase <= USECASE_INVALID) || (usecase >= AUDIO_USECASE_MAX)) {
3542 ALOGE("%s: invalid usecase case idx %d", __func__, usecase);
3543 ret = -EINVAL;
3544 goto done;
3545 }
3546
3547 if ((type != 0) && (type != 1)) {
3548 ALOGE("%s: invalid usecase type", __func__);
3549 ret = -EINVAL;
3550 }
vivek mehtaa68fea62017-06-08 19:04:02 -07003551 ALOGV("%s: pcm_device_table[%d %s][%d] = %d", __func__, usecase,
3552 use_case_table[usecase],
3553 type, pcm_id);
Haynes Mathew George98c95622014-06-20 19:14:25 -07003554 pcm_device_table[usecase][type] = pcm_id;
3555done:
3556 return ret;
3557}
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003558
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07003559#define DEFAULT_NOMINAL_SPEAKER_GAIN 20
3560int ramp_speaker_gain(struct audio_device *adev, bool ramp_up, int target_ramp_up_gain) {
3561 // backup_gain: gain to try to set in case of an error during ramp
3562 int start_gain, end_gain, step, backup_gain, i;
3563 bool error = false;
3564 const struct mixer_ctl *ctl;
3565 const char *mixer_ctl_name_gain_left = "Left Speaker Gain";
3566 const char *mixer_ctl_name_gain_right = "Right Speaker Gain";
3567 struct mixer_ctl *ctl_left = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_left);
3568 struct mixer_ctl *ctl_right = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_right);
3569 if (!ctl_left || !ctl_right) {
3570 ALOGE("%s: Could not get ctl for mixer cmd - %s or %s, not applying speaker gain ramp",
3571 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
3572 return -EINVAL;
3573 } else if ((mixer_ctl_get_num_values(ctl_left) != 1)
3574 || (mixer_ctl_get_num_values(ctl_right) != 1)) {
3575 ALOGE("%s: Unexpected num values for mixer cmd - %s or %s, not applying speaker gain ramp",
3576 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
3577 return -EINVAL;
3578 }
3579 if (ramp_up) {
3580 start_gain = 0;
3581 end_gain = target_ramp_up_gain > 0 ? target_ramp_up_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
3582 step = +1;
3583 backup_gain = end_gain;
3584 } else {
3585 // using same gain on left and right
3586 const int left_gain = mixer_ctl_get_value(ctl_left, 0);
3587 start_gain = left_gain > 0 ? left_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
3588 end_gain = 0;
3589 step = -1;
3590 backup_gain = start_gain;
3591 }
3592 for (i = start_gain ; i != (end_gain + step) ; i += step) {
3593 //ALOGV("setting speaker gain to %d", i);
3594 if (mixer_ctl_set_value(ctl_left, 0, i)) {
3595 ALOGE("%s: error setting %s to %d during gain ramp",
3596 __func__, mixer_ctl_name_gain_left, i);
3597 error = true;
3598 break;
3599 }
3600 if (mixer_ctl_set_value(ctl_right, 0, i)) {
3601 ALOGE("%s: error setting %s to %d during gain ramp",
3602 __func__, mixer_ctl_name_gain_right, i);
3603 error = true;
3604 break;
3605 }
3606 usleep(1000);
3607 }
3608 if (error) {
3609 // an error occured during the ramp, let's still try to go back to a safe volume
3610 if (mixer_ctl_set_value(ctl_left, 0, backup_gain)) {
3611 ALOGE("%s: error restoring left gain to %d", __func__, backup_gain);
3612 }
3613 if (mixer_ctl_set_value(ctl_right, 0, backup_gain)) {
3614 ALOGE("%s: error restoring right gain to %d", __func__, backup_gain);
3615 }
3616 }
3617 return start_gain;
3618}
3619
vivek mehtae59cfb22017-06-16 15:57:11 -07003620int platform_set_swap_mixer(struct audio_device *adev, bool swap_channels)
3621{
3622 const char *mixer_ctl_name = "Swap channel";
3623 struct mixer_ctl *ctl;
3624 const char *mixer_path;
3625 struct platform_data *my_data = (struct platform_data *)adev->platform;
3626
3627 // forced to set to swap, but device not rotated ... ignore set
3628 if (swap_channels && !my_data->speaker_lr_swap)
3629 return 0;
3630
3631 ALOGV("%s:", __func__);
3632
3633 if (swap_channels) {
3634 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER_REVERSE);
3635 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
3636 } else {
3637 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER);
3638 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
3639 }
3640
3641 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3642 if (!ctl) {
3643 ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name);
3644 return -EINVAL;
3645 }
3646
3647 if (mixer_ctl_set_value(ctl, 0, swap_channels) < 0) {
3648 ALOGE("%s: Could not set reverse cotrol %d",__func__, swap_channels);
3649 return -EINVAL;
3650 }
3651
3652 ALOGV("platfor_force_swap_channel :: Channel orientation ( %s ) ",
3653 swap_channels?"R --> L":"L --> R");
3654
3655 return 0;
3656}
3657
3658int platform_check_and_set_swap_lr_channels(struct audio_device *adev, bool swap_channels)
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003659{
3660 // only update if there is active pcm playback on speaker
3661 struct audio_usecase *usecase;
3662 struct listnode *node;
3663 struct platform_data *my_data = (struct platform_data *)adev->platform;
3664
vivek mehtae59cfb22017-06-16 15:57:11 -07003665 my_data->speaker_lr_swap = swap_channels;
Jean-Michel Trivif7148702016-09-16 18:23:05 -07003666
vivek mehtae59cfb22017-06-16 15:57:11 -07003667 return platform_set_swap_channels(adev, swap_channels);
3668}
Jean-Michel Trivif7148702016-09-16 18:23:05 -07003669
vivek mehtae59cfb22017-06-16 15:57:11 -07003670int platform_set_swap_channels(struct audio_device *adev, bool swap_channels)
3671{
3672 // only update if there is active pcm playback on speaker
3673 struct audio_usecase *usecase;
3674 struct listnode *node;
3675 struct platform_data *my_data = (struct platform_data *)adev->platform;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003676
vivek mehtae59cfb22017-06-16 15:57:11 -07003677 // do not swap channels in audio modes with concurrent capture and playback
3678 // as this may break the echo reference
3679 if ((adev->mode == AUDIO_MODE_IN_COMMUNICATION) || (adev->mode == AUDIO_MODE_IN_CALL)) {
3680 ALOGV("%s: will not swap due to audio mode %d", __func__, adev->mode);
3681 return 0;
3682 }
3683
3684 list_for_each(node, &adev->usecase_list) {
3685 usecase = node_to_item(node, struct audio_usecase, list);
3686 if (usecase->type == PCM_PLAYBACK &&
3687 usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) {
3688 /*
3689 * If acdb tuning is different for SPEAKER_REVERSE, it is must
3690 * to perform device switch to disable the current backend to
3691 * enable it with new acdb data.
3692 */
3693 if (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
3694 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]) {
3695 const int initial_skpr_gain = ramp_speaker_gain(adev, false /*ramp_up*/, -1);
3696 select_devices(adev, usecase->id);
3697 if (initial_skpr_gain != -EINVAL)
3698 ramp_speaker_gain(adev, true /*ramp_up*/, initial_skpr_gain);
3699
3700 } else {
3701 platform_set_swap_mixer(adev, swap_channels);
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003702 }
vivek mehtae59cfb22017-06-16 15:57:11 -07003703 break;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003704 }
3705 }
vivek mehtae59cfb22017-06-16 15:57:11 -07003706
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003707 return 0;
3708}
vivek mehtaa8d7c922016-05-25 14:40:44 -07003709
3710static struct amp_db_and_gain_table tbl_mapping[MAX_VOLUME_CAL_STEPS];
3711static int num_gain_tbl_entry = 0;
3712
3713bool platform_add_gain_level_mapping(struct amp_db_and_gain_table *tbl_entry) {
3714
3715 ALOGV("%s: enter .. add %f %f %d", __func__, tbl_entry->amp, tbl_entry->db, tbl_entry->level);
3716 if (num_gain_tbl_entry == -1) {
3717 ALOGE("%s: num entry beyond valid step levels or corrupted..rejecting custom mapping",
3718 __func__);
3719 return false;
3720 }
3721
3722 if (num_gain_tbl_entry >= MAX_VOLUME_CAL_STEPS) {
3723 ALOGE("%s: max entry reached max[%d] current index[%d] .. rejecting", __func__,
3724 MAX_VOLUME_CAL_STEPS, num_gain_tbl_entry);
3725 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
3726 return false;
3727 }
3728
3729 if (num_gain_tbl_entry > 0 && tbl_mapping[num_gain_tbl_entry - 1].amp >= tbl_entry->amp) {
3730 ALOGE("%s: value not in ascending order .. rejecting custom mapping", __func__);
3731 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
3732 return false;
3733 }
3734
3735 tbl_mapping[num_gain_tbl_entry] = *tbl_entry;
3736 ++num_gain_tbl_entry;
3737
3738 return true;
3739}
3740
3741int platform_get_gain_level_mapping(struct amp_db_and_gain_table *mapping_tbl,
3742 int table_size) {
3743 int itt = 0;
3744 ALOGV("platform_get_gain_level_mapping called ");
3745
3746 if (num_gain_tbl_entry <= 0 || num_gain_tbl_entry > MAX_VOLUME_CAL_STEPS) {
3747 ALOGD("%s: empty or currupted gain_mapping_table", __func__);
3748 return 0;
3749 }
3750
3751 for (; itt < num_gain_tbl_entry && itt <= table_size; itt++) {
3752 mapping_tbl[itt] = tbl_mapping[itt];
3753 ALOGV("%s: added amp[%f] db[%f] level[%d]", __func__,
3754 mapping_tbl[itt].amp, mapping_tbl[itt].db, mapping_tbl[itt].level);
3755 }
3756
3757 return num_gain_tbl_entry;
3758}
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07003759
3760int platform_snd_card_update(void *platform, card_status_t status)
3761{
3762 struct platform_data *my_data = (struct platform_data *)platform;
3763 struct audio_device *adev = my_data->adev;
3764
3765 if (status == CARD_STATUS_ONLINE) {
3766 if (my_data->acdb_send_custom_top)
3767 my_data->acdb_send_custom_top();
3768 }
3769 return 0;
3770}
David Linee3fe402017-03-13 10:00:42 -07003771
3772/*
3773 * configures afe with bit width and Sample Rate
3774 */
Haynes Mathew George65f6b432018-02-27 17:44:55 -08003775int platform_set_backend_cfg(const struct audio_device* adev,
3776 snd_device_t snd_device,
3777 const struct audio_backend_cfg *backend_cfg)
David Linee3fe402017-03-13 10:00:42 -07003778{
3779
3780 int ret = 0;
3781 const int backend_idx = platform_get_backend_index(snd_device);
3782 struct platform_data *my_data = (struct platform_data *)adev->platform;
3783 const unsigned int bit_width = backend_cfg->bit_width;
3784 const unsigned int sample_rate = backend_cfg->sample_rate;
3785 const unsigned int channels = backend_cfg->channels;
3786 const audio_format_t format = backend_cfg->format;
3787 const bool passthrough_enabled = backend_cfg->passthrough_enabled;
3788
3789
3790 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
3791 ", backend_idx %d device (%s)", __func__, bit_width,
3792 sample_rate, channels, backend_idx,
3793 platform_get_snd_device_name(snd_device));
3794
3795 if ((my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl) &&
3796 (bit_width != my_data->current_backend_cfg[backend_idx].bit_width)) {
3797
3798 struct mixer_ctl *ctl = NULL;
3799 ctl = mixer_get_ctl_by_name(adev->mixer,
3800 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
3801 if (!ctl) {
3802 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3803 __func__,
3804 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
3805 return -EINVAL;
3806 }
3807
3808 if (bit_width == 24) {
3809 if (format == AUDIO_FORMAT_PCM_24_BIT_PACKED)
3810 ret = mixer_ctl_set_enum_by_string(ctl, "S24_3LE");
3811 else
3812 ret = mixer_ctl_set_enum_by_string(ctl, "S24_LE");
3813 } else if (bit_width == 32) {
3814 ret = mixer_ctl_set_enum_by_string(ctl, "S32_LE");
3815 } else {
3816 ret = mixer_ctl_set_enum_by_string(ctl, "S16_LE");
3817 }
3818 if ( ret < 0) {
3819 ALOGE("%s:becf: afe: fail for %s mixer set to %d bit for %x format", __func__,
3820 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
3821 } else {
3822 my_data->current_backend_cfg[backend_idx].bit_width = bit_width;
3823 ALOGD("%s:becf: afe: %s mixer set to %d bit for %x format", __func__,
3824 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
3825 }
3826 /* set the ret as 0 and not pass back to upper layer */
3827 ret = 0;
3828 }
3829
3830 if (passthrough_enabled || ((my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl) &&
3831 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate))) {
3832 char *rate_str = NULL;
3833 struct mixer_ctl *ctl = NULL;
3834
3835 switch (sample_rate) {
3836 case 32000:
3837 if (passthrough_enabled) {
3838 rate_str = "KHZ_32";
3839 break;
3840 }
3841 case 8000:
3842 case 11025:
3843 case 16000:
3844 case 22050:
3845 case 48000:
3846 rate_str = "KHZ_48";
3847 break;
3848 case 44100:
3849 rate_str = "KHZ_44P1";
3850 break;
3851 case 64000:
3852 case 96000:
3853 rate_str = "KHZ_96";
3854 break;
3855 case 88200:
3856 rate_str = "KHZ_88P2";
3857 break;
3858 case 176400:
3859 rate_str = "KHZ_176P4";
3860 break;
3861 case 192000:
3862 rate_str = "KHZ_192";
3863 break;
3864 case 352800:
3865 rate_str = "KHZ_352P8";
3866 break;
3867 case 384000:
3868 rate_str = "KHZ_384";
3869 break;
3870 case 144000:
3871 if (passthrough_enabled) {
3872 rate_str = "KHZ_144";
3873 break;
3874 }
3875 default:
3876 rate_str = "KHZ_48";
3877 break;
3878 }
3879
3880 ctl = mixer_get_ctl_by_name(adev->mixer,
3881 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
3882 if(!ctl) {
3883 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3884 __func__,
3885 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
3886 return -EINVAL;
3887 }
3888
3889 ALOGD("%s:becf: afe: %s set to %s", __func__,
3890 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl, rate_str);
3891 mixer_ctl_set_enum_by_string(ctl, rate_str);
3892 my_data->current_backend_cfg[backend_idx].sample_rate = sample_rate;
3893 }
3894 if ((my_data->current_backend_cfg[backend_idx].channels_mixer_ctl) &&
3895 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
3896 struct mixer_ctl *ctl = NULL;
3897 char *channel_cnt_str = NULL;
3898
3899 switch (channels) {
3900 case 8:
3901 channel_cnt_str = "Eight"; break;
3902 case 7:
3903 channel_cnt_str = "Seven"; break;
3904 case 6:
3905 channel_cnt_str = "Six"; break;
3906 case 5:
3907 channel_cnt_str = "Five"; break;
3908 case 4:
3909 channel_cnt_str = "Four"; break;
3910 case 3:
3911 channel_cnt_str = "Three"; break;
3912 case 1:
3913 channel_cnt_str = "One"; break;
3914 case 2:
3915 default:
3916 channel_cnt_str = "Two"; break;
3917 }
3918
3919 ctl = mixer_get_ctl_by_name(adev->mixer,
3920 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
3921 if (!ctl) {
3922 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3923 __func__,
3924 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
3925 return -EINVAL;
3926 }
3927 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
3928 my_data->current_backend_cfg[backend_idx].channels = channels;
3929
3930 // skip EDID configuration for HDMI backend
3931
3932 ALOGD("%s:becf: afe: %s set to %s", __func__,
3933 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl,
3934 channel_cnt_str);
3935 }
3936
3937 // skip set ext_display format mixer control
3938 return ret;
3939}
3940
3941static int platform_get_snd_device_bit_width(snd_device_t snd_device)
3942{
3943 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
3944 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
3945 return CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3946 }
3947
3948 return backend_bit_width_table[snd_device];
3949}
3950
3951/*
3952 * return backend_idx on which voice call is active
3953 */
3954static int platform_get_voice_call_backend(struct audio_device* adev)
3955{
3956 struct audio_usecase *uc = NULL;
3957 struct listnode *node;
3958 snd_device_t out_snd_device = SND_DEVICE_NONE;
3959
3960 int backend_idx = -1;
3961
3962 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
3963 list_for_each(node, &adev->usecase_list) {
3964 uc = node_to_item(node, struct audio_usecase, list);
3965 if (uc && uc->type == VOICE_CALL && uc->stream.out) {
3966 out_snd_device = platform_get_output_snd_device(adev->platform,
3967 uc->stream.out->devices);
3968 backend_idx = platform_get_backend_index(out_snd_device);
3969 break;
3970 }
3971 }
3972 }
3973 return backend_idx;
3974}
3975
3976/*
3977 * goes through all the current usecases and picks the highest
3978 * bitwidth & samplerate
3979 */
3980static bool platform_check_capture_backend_cfg(struct audio_device* adev,
3981 int backend_idx,
3982 struct audio_backend_cfg *backend_cfg)
3983{
3984 bool backend_change = false;
3985 unsigned int bit_width;
3986 unsigned int sample_rate;
3987 unsigned int channels;
3988 struct platform_data *my_data = (struct platform_data *)adev->platform;
3989
3990 bit_width = backend_cfg->bit_width;
3991 sample_rate = backend_cfg->sample_rate;
3992 channels = backend_cfg->channels;
3993
3994 ALOGV("%s:txbecf: afe: Codec selected backend: %d current bit width: %d and "
3995 "sample rate: %d, channels %d",__func__,backend_idx, bit_width,
3996 sample_rate, channels);
3997
3998 // For voice calls use default configuration i.e. 16b/48K, only applicable to
3999 // default backend
4000 // force routing is not required here, caller will do it anyway
4001 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
4002 ALOGW("%s:txbecf: afe: Use default bw and sr for voice/voip calls and "
4003 "for unprocessed/camera source", __func__);
4004 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
4005 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4006 }
4007
4008 if (backend_idx == USB_AUDIO_TX_BACKEND) {
4009 audio_extn_usb_is_config_supported(&bit_width, &sample_rate, &channels, false);
4010 ALOGV("%s:txbecf: afe: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
4011 __func__, bit_width, sample_rate, channels);
4012 }
4013
4014 ALOGV("%s:txbecf: afe: Codec selected backend: %d updated bit width: %d and "
4015 "sample rate: %d", __func__, backend_idx, bit_width, sample_rate);
4016
4017 // Force routing if the expected bitwdith or samplerate
4018 // is not same as current backend comfiguration
4019 if ((bit_width != my_data->current_backend_cfg[backend_idx].bit_width) ||
4020 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate) ||
4021 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
4022 backend_cfg->bit_width = bit_width;
4023 backend_cfg->sample_rate= sample_rate;
4024 backend_cfg->channels = channels;
4025 backend_change = true;
4026 ALOGI("%s:txbecf: afe: Codec backend needs to be updated. new bit width: %d "
4027 "new sample rate: %d new channel: %d",
4028 __func__, backend_cfg->bit_width,
4029 backend_cfg->sample_rate, backend_cfg->channels);
4030 }
4031
4032 return backend_change;
4033}
4034
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004035static void pick_playback_cfg_for_uc(struct audio_device *adev,
4036 struct audio_usecase *usecase,
4037 snd_device_t snd_device,
4038 unsigned int *bit_width,
4039 unsigned int *sample_rate,
4040 unsigned int *channels)
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004041{
4042 int i =0;
4043 struct listnode *node;
4044 list_for_each(node, &adev->usecase_list) {
4045 struct audio_usecase *uc;
4046 uc = node_to_item(node, struct audio_usecase, list);
4047 struct stream_out *out = (struct stream_out*) uc->stream.out;
4048 if (uc->type == PCM_PLAYBACK && out && usecase != uc) {
4049 unsigned int out_channels = audio_channel_count_from_out_mask(out->channel_mask);
4050 ALOGV("%s:napb: (%d) - (%s)id (%d) sr %d bw "
4051 "(%d) ch (%d) device %s", __func__, i++, use_case_table[uc->id],
4052 uc->id, out->sample_rate,
4053 pcm_format_to_bits(out->config.format), out_channels,
4054 platform_get_snd_device_name(uc->out_snd_device));
4055
4056 if (platform_check_backends_match(snd_device, uc->out_snd_device)) {
4057 if (*bit_width < pcm_format_to_bits(out->config.format))
4058 *bit_width = pcm_format_to_bits(out->config.format);
4059 if (*sample_rate < out->sample_rate)
4060 *sample_rate = out->sample_rate;
4061 if (out->sample_rate < OUTPUT_SAMPLING_RATE_44100)
4062 *sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4063 if (*channels < out_channels)
4064 *channels = out_channels;
4065 }
4066 }
4067 }
4068 return;
4069}
4070
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004071static void headset_is_config_supported(unsigned int *bit_width,
4072 unsigned int *sample_rate,
4073 unsigned int *channels) {
4074 switch (*bit_width) {
4075 case 16:
4076 case 24:
4077 break;
4078 default:
4079 *bit_width = 16;
4080 break;
4081 }
4082
4083 if (*sample_rate > 192000) {
4084 *sample_rate = 192000;
4085 }
4086
4087 if (*channels > 2) {
4088 *channels = 2;
4089 }
4090}
4091
David Linee3fe402017-03-13 10:00:42 -07004092static bool platform_check_playback_backend_cfg(struct audio_device* adev,
4093 struct audio_usecase* usecase,
4094 snd_device_t snd_device,
4095 struct audio_backend_cfg *backend_cfg)
4096{
4097 bool backend_change = false;
David Linee3fe402017-03-13 10:00:42 -07004098 unsigned int bit_width;
4099 unsigned int sample_rate;
4100 unsigned int channels;
David Linee3fe402017-03-13 10:00:42 -07004101 int backend_idx = DEFAULT_CODEC_BACKEND;
Haynes Mathew George65f6b432018-02-27 17:44:55 -08004102 unsigned long service_interval = 0; // 0 is invalid
David Linee3fe402017-03-13 10:00:42 -07004103 struct platform_data *my_data = (struct platform_data *)adev->platform;
David Linee3fe402017-03-13 10:00:42 -07004104
4105 if (snd_device == SND_DEVICE_OUT_BT_SCO ||
4106 snd_device == SND_DEVICE_OUT_BT_SCO_WB) {
4107 backend_change = false;
4108 return backend_change;
4109 }
4110
4111 backend_idx = platform_get_backend_index(snd_device);
4112 bit_width = backend_cfg->bit_width;
4113 sample_rate = backend_cfg->sample_rate;
4114 channels = backend_cfg->channels;
4115
4116 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
4117 ", backend_idx %d usecase = %d device (%s)", __func__, bit_width,
4118 sample_rate, channels, backend_idx, usecase->id,
4119 platform_get_snd_device_name(snd_device));
4120
4121 if (backend_idx == platform_get_voice_call_backend(adev)) {
4122 ALOGW("%s:becf: afe:Use default bw and sr for voice/voip calls ",
4123 __func__);
4124 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
4125 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4126 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
4127 } else {
4128 /*
4129 * The backend should be configured at highest bit width and/or
4130 * sample rate amongst all playback usecases.
4131 * If the selected sample rate and/or bit width differ with
4132 * current backend sample rate and/or bit width, then, we set the
4133 * backend re-configuration flag.
4134 *
4135 * Exception: 16 bit playbacks is allowed through 16 bit/48/44.1 khz backend only
4136 */
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004137 pick_playback_cfg_for_uc(adev, usecase, snd_device,
4138 &bit_width,
4139 &sample_rate,
4140 &channels);
David Linee3fe402017-03-13 10:00:42 -07004141 }
4142
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004143 switch (backend_idx) {
4144 case USB_AUDIO_RX_BACKEND:
4145 audio_extn_usb_is_config_supported(&bit_width,
4146 &sample_rate, &channels, true);
Haynes Mathew George65f6b432018-02-27 17:44:55 -08004147 if (platform_get_usb_service_interval(adev->platform, true,
4148 &service_interval) == 0) {
4149 /* overwrite with best altset for this service interval */
4150 int ret =
4151 audio_extn_usb_altset_for_service_interval(true /*playback*/,
4152 service_interval,
4153 &bit_width,
4154 &sample_rate,
4155 &channels);
4156 if (ret < 0) {
4157 ALOGE("Failed to find altset for service interval %lu, skip reconfig",
4158 service_interval);
4159 return false;
4160 }
4161 }
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004162 ALOGV("%s: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
4163 __func__, bit_width, sample_rate, channels);
4164 break;
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004165 case HEADPHONE_BACKEND:
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004166 headset_is_config_supported(&bit_width, &sample_rate, &channels);
4167 break;
4168 case DEFAULT_CODEC_BACKEND:
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004169 default:
4170 bit_width = platform_get_snd_device_bit_width(snd_device);
4171 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4172 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
4173 break;
David Linee3fe402017-03-13 10:00:42 -07004174 }
4175
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004176 ALOGV("%s:becf: afe: Codec selected backend: %d updated bit width: %d and"
4177 "sample rate: %d",
David Linee3fe402017-03-13 10:00:42 -07004178 __func__, backend_idx , bit_width, sample_rate);
4179
4180 // Force routing if the expected bitwdith or samplerate
4181 // is not same as current backend comfiguration
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004182 if (bit_width != my_data->current_backend_cfg[backend_idx].bit_width ||
4183 sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate ||
4184 channels != my_data->current_backend_cfg[backend_idx].channels) {
David Linee3fe402017-03-13 10:00:42 -07004185 backend_cfg->bit_width = bit_width;
4186 backend_cfg->sample_rate = sample_rate;
4187 backend_cfg->channels = channels;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004188 backend_cfg->passthrough_enabled = false;
David Linee3fe402017-03-13 10:00:42 -07004189 backend_change = true;
4190 ALOGV("%s:becf: afe: Codec backend needs to be updated. new bit width: %d"
4191 "new sample rate: %d new channels: %d",
4192 __func__, backend_cfg->bit_width, backend_cfg->sample_rate, backend_cfg->channels);
4193 }
4194
4195 return backend_change;
4196}
4197
4198bool platform_check_and_set_playback_backend_cfg(struct audio_device* adev,
4199 struct audio_usecase *usecase, snd_device_t snd_device)
4200{
4201 int backend_idx = DEFAULT_CODEC_BACKEND;
4202 int new_snd_devices[SND_DEVICE_OUT_END];
4203 int i, num_devices = 1;
4204 bool ret = false;
4205 struct platform_data *my_data = (struct platform_data *)adev->platform;
4206 struct audio_backend_cfg backend_cfg;
4207
4208 backend_idx = platform_get_backend_index(snd_device);
4209
4210 backend_cfg.bit_width = pcm_format_to_bits(usecase->stream.out->config.format);
4211 backend_cfg.sample_rate = usecase->stream.out->sample_rate;
4212 backend_cfg.format = usecase->stream.out->format;
4213 backend_cfg.channels = audio_channel_count_from_out_mask(usecase->stream.out->channel_mask);
4214 /*this is populated by check_codec_backend_cfg hence set default value to false*/
4215 backend_cfg.passthrough_enabled = false;
4216
4217 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
4218 ", backend_idx %d usecase = %d device (%s)", __func__, backend_cfg.bit_width,
4219 backend_cfg.sample_rate, backend_cfg.channels, backend_idx, usecase->id,
4220 platform_get_snd_device_name(snd_device));
4221
4222 if (platform_can_split_snd_device(snd_device, &num_devices, new_snd_devices) < 0)
4223 new_snd_devices[0] = snd_device;
4224
4225 for (i = 0; i < num_devices; i++) {
4226 ALOGV("%s: new_snd_devices[%d] is %d", __func__, i, new_snd_devices[i]);
4227 if ((platform_check_playback_backend_cfg(adev, usecase, new_snd_devices[i],
4228 &backend_cfg))) {
4229 platform_set_backend_cfg(adev, new_snd_devices[i],
4230 &backend_cfg);
4231 ret = true;
4232 }
4233 }
4234 return ret;
4235}
4236
4237bool platform_check_and_set_capture_backend_cfg(struct audio_device* adev,
4238 struct audio_usecase *usecase, snd_device_t snd_device)
4239{
4240 int backend_idx = platform_get_backend_index(snd_device);
4241 int ret = 0;
4242 struct audio_backend_cfg backend_cfg;
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004243 memset(&backend_cfg, 0, sizeof(struct audio_backend_cfg));
David Linee3fe402017-03-13 10:00:42 -07004244
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004245 if (usecase->type == PCM_CAPTURE) {
4246 backend_cfg.format = usecase->stream.in->format;
David Linee3fe402017-03-13 10:00:42 -07004247 backend_cfg.channels = audio_channel_count_from_in_mask(usecase->stream.in->channel_mask);
4248 } else {
4249 backend_cfg.bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
4250 backend_cfg.sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4251 backend_cfg.format = AUDIO_FORMAT_PCM_16_BIT;
4252 backend_cfg.channels = 1;
4253 }
4254
4255 ALOGV("%s:txbecf: afe: bitwidth %d, samplerate %d, channel %d"
4256 ", backend_idx %d usecase = %d device (%s)", __func__,
4257 backend_cfg.bit_width,
4258 backend_cfg.sample_rate,
4259 backend_cfg.channels,
4260 backend_idx, usecase->id,
4261 platform_get_snd_device_name(snd_device));
4262
4263 if (platform_check_capture_backend_cfg(adev, backend_idx, &backend_cfg)) {
4264 ret = platform_set_backend_cfg(adev, snd_device,
4265 &backend_cfg);
4266 if(!ret)
4267 return true;
4268 }
4269
4270 return false;
4271}
4272
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004273static int max_be_dai_names = 0;
4274static const struct be_dai_name_struct *be_dai_name_table;
4275
4276/*
4277 * Retrieves the be_dai_name_table from kernel to enable a mapping
4278 * between sound device hw interfaces and backend IDs. This allows HAL to
4279 * specify the backend a specific calibration is needed for.
4280 */
4281static int init_be_dai_name_table(struct audio_device *adev)
4282{
4283 const char *mixer_ctl_name = "Backend DAI Name Table";
4284 struct mixer_ctl *ctl;
4285 int i, j, ret, size;
4286 bool valid_hw_interface;
4287
4288 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
4289 if (!ctl) {
4290 ALOGE("%s: Could not get ctl for mixer name %s\n",
4291 __func__, mixer_ctl_name);
4292 ret = -EINVAL;
4293 goto done;
4294 }
4295
4296 mixer_ctl_update(ctl);
4297
4298 size = mixer_ctl_get_num_values(ctl);
4299 if (size <= 0){
4300 ALOGE("%s: Failed to get %s size %d\n",
4301 __func__, mixer_ctl_name, size);
4302 ret = -EFAULT;
4303 goto done;
4304 }
4305
vivek mehtaa68fea62017-06-08 19:04:02 -07004306 be_dai_name_table =
4307 (const struct be_dai_name_struct *)calloc(1, size);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004308 if (be_dai_name_table == NULL) {
4309 ALOGE("%s: Failed to allocate memory for %s\n",
4310 __func__, mixer_ctl_name);
4311 ret = -ENOMEM;
4312 goto freeMem;
4313 }
4314
4315 ret = mixer_ctl_get_array(ctl, (void *)be_dai_name_table, size);
4316 if (ret) {
4317 ALOGE("%s: Failed to get %s, ret %d\n",
4318 __func__, mixer_ctl_name, ret);
4319 ret = -EFAULT;
4320 goto freeMem;
4321 }
4322
4323 if (be_dai_name_table != NULL) {
4324 max_be_dai_names = size / sizeof(struct be_dai_name_struct);
4325 ALOGV("%s: Successfully got %s, number of be dais is %d\n",
4326 __func__, mixer_ctl_name, max_be_dai_names);
4327 ret = 0;
4328 } else {
4329 ALOGE("%s: Failed to get %s\n", __func__, mixer_ctl_name);
4330 ret = -EFAULT;
4331 goto freeMem;
4332 }
4333
4334 /*
4335 * Validate all sound devices have a valid backend set to catch
4336 * errors for uncommon sound devices
4337 */
4338 for (i = 0; i < SND_DEVICE_MAX; i++) {
4339 valid_hw_interface = false;
4340
4341 if (hw_interface_table[i] == NULL) {
4342 ALOGW("%s: sound device %s has no hw interface set\n",
4343 __func__, platform_get_snd_device_name(i));
4344 continue;
4345 }
4346
4347 for (j = 0; j < max_be_dai_names; j++) {
4348 if (strcmp(hw_interface_table[i], be_dai_name_table[j].be_name)
4349 == 0) {
4350 valid_hw_interface = true;
4351 break;
4352 }
4353 }
4354 if (!valid_hw_interface)
4355 ALOGD("%s: sound device %s does not have a valid hw interface set "
4356 "(disregard for combo devices) %s\n",
4357 __func__, platform_get_snd_device_name(i),
4358 hw_interface_table[i]);
4359 }
4360
4361 goto done;
4362
4363freeMem:
4364 if (be_dai_name_table) {
4365 free((void *)be_dai_name_table);
4366 be_dai_name_table = NULL;
4367 }
4368
4369done:
4370 return ret;
4371}
4372
4373int platform_get_snd_device_backend_index(snd_device_t device)
4374{
4375 int i, be_dai_id;
4376 const char * hw_interface_name = NULL;
4377
4378 ALOGV("%s: enter with device %d\n", __func__, device);
4379
vivek mehtaa68fea62017-06-08 19:04:02 -07004380 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004381 ALOGE("%s: Invalid snd_device = %d",
4382 __func__, device);
4383 be_dai_id = -EINVAL;
4384 goto done;
4385 }
4386
4387 /* Get string value of necessary backend for device */
4388 hw_interface_name = hw_interface_table[device];
4389 if (hw_interface_name == NULL) {
4390 ALOGE("%s: no hw_interface set for device %d\n", __func__, device);
4391 be_dai_id = -EINVAL;
4392 goto done;
4393 }
4394
4395 /* Check if be dai name table was retrieved successfully */
4396 if (be_dai_name_table == NULL) {
4397 ALOGE("%s: BE DAI Name Table is not present\n", __func__);
4398 be_dai_id = -EFAULT;
4399 goto done;
4400 }
4401
4402 /* Get backend ID for device specified */
4403 for (i = 0; i < max_be_dai_names; i++) {
4404 if (strcmp(hw_interface_name, be_dai_name_table[i].be_name) == 0) {
4405 be_dai_id = be_dai_name_table[i].be_id;
4406 goto done;
4407 }
4408 }
4409 ALOGE("%s: no interface matching name %s\n", __func__, hw_interface_name);
4410 be_dai_id = -EINVAL;
4411 goto done;
4412
4413done:
4414 return be_dai_id;
4415}
4416
4417void platform_check_and_update_copp_sample_rate(void* platform, snd_device_t snd_device,
4418 unsigned int stream_sr, int* sample_rate)
4419{
4420 struct platform_data* my_data = (struct platform_data *)platform;
4421 int backend_idx = platform_get_backend_index(snd_device);
4422 int device_sr = my_data->current_backend_cfg[backend_idx].sample_rate;
4423 /*
4424 *Check if device SR is multiple of 8K or 11.025 Khz
4425 *check if the stream SR is multiple of same base, if yes
4426 *then have copp SR equal to stream SR, this ensures that
4427 *post processing happens at stream SR, else have
4428 *copp SR equal to device SR.
4429 */
4430 if (!(((sample_rate_multiple(device_sr, SAMPLE_RATE_8000)) &&
4431 (sample_rate_multiple(stream_sr, SAMPLE_RATE_8000))) ||
4432 ((sample_rate_multiple(device_sr, SAMPLE_RATE_11025)) &&
4433 (sample_rate_multiple(stream_sr, SAMPLE_RATE_11025))))) {
4434 *sample_rate = device_sr;
4435 } else
4436 *sample_rate = stream_sr;
4437
4438 ALOGI("sn_device %d device sr %d stream sr %d copp sr %d", snd_device, device_sr, stream_sr
4439 , *sample_rate);
4440
4441}
4442
4443// called from info parser
vivek mehtaa68fea62017-06-08 19:04:02 -07004444void platform_add_app_type(const char *uc_type,
4445 const char *mode,
4446 int bw,
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004447 int app_type, int max_rate) {
4448 struct app_type_entry *ap =
4449 (struct app_type_entry *)calloc(1, sizeof(struct app_type_entry));
4450
4451 if (!ap) {
4452 ALOGE("%s failed to allocate mem for app type", __func__);
4453 return;
4454 }
4455
4456 ap->uc_type = -1;
4457 for (int i=0; i<USECASE_TYPE_MAX; i++) {
4458 if (!strcmp(uc_type, usecase_type_index[i].name)) {
4459 ap->uc_type = usecase_type_index[i].index;
4460 break;
4461 }
4462 }
4463
4464 if (ap->uc_type == -1) {
4465 free(ap);
4466 return;
4467 }
4468
vivek mehtaa68fea62017-06-08 19:04:02 -07004469 ALOGI("%s uc %s mode %s bw %d app_type %d max_rate %d",
4470 __func__, uc_type, mode, bw, app_type, max_rate);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004471 ap->bit_width = bw;
4472 ap->app_type = app_type;
4473 ap->max_rate = max_rate;
vivek mehtaa68fea62017-06-08 19:04:02 -07004474 ap->mode = strdup(mode);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004475 list_add_tail(&app_type_entry_list, &ap->node);
4476}
4477
4478
4479int platform_get_default_app_type_v2(void *platform __unused,
4480 usecase_type_t type,
4481 int *app_type )
4482{
4483 if (type == PCM_PLAYBACK)
4484 *app_type = DEFAULT_APP_TYPE_RX_PATH;
4485 else
4486 *app_type = DEFAULT_APP_TYPE_TX_PATH;
4487 return 0;
4488}
4489
vivek mehtaa68fea62017-06-08 19:04:02 -07004490int platform_get_app_type_v2(void *platform,
4491 usecase_type_t uc_type,
4492 const char *mode,
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004493 int bw, int sr __unused,
4494 int *app_type)
4495{
4496 struct listnode *node;
4497 struct app_type_entry *entry;
4498 *app_type = -1;
vivek mehtaa68fea62017-06-08 19:04:02 -07004499
4500 ALOGV("%s find match for uc %d mode %s bw %d rate %d",
4501 __func__, uc_type, mode, bw, sr);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004502 list_for_each(node, &app_type_entry_list) {
4503 entry = node_to_item(node, struct app_type_entry, node);
vivek mehtaa68fea62017-06-08 19:04:02 -07004504 ALOGV("%s uc %d mode %s bw %d app_type %d max_rate %d",
4505 __func__, entry->uc_type, entry->mode, entry->bit_width,
4506 entry->app_type, entry->max_rate);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004507 if (entry->bit_width == bw &&
vivek mehtaa68fea62017-06-08 19:04:02 -07004508 entry->uc_type == uc_type &&
4509 sr <= entry->max_rate &&
4510 entry->mode && !strcmp(mode, entry->mode)) {
4511 ALOGV("%s found match %d", __func__, entry->app_type);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004512 *app_type = entry->app_type;
4513 break;
4514 }
4515 }
4516
4517 if (*app_type == -1) {
vivek mehtaa68fea62017-06-08 19:04:02 -07004518 ALOGV("%s no match found, return default", __func__);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004519 return platform_get_default_app_type_v2(platform, uc_type, app_type);
4520 }
4521 return 0;
4522}
vivek mehta90933872017-06-15 18:04:39 -07004523
4524int platform_set_sidetone(struct audio_device *adev,
4525 snd_device_t out_snd_device,
4526 bool enable, char *str)
4527{
4528 int ret;
4529 if (out_snd_device == SND_DEVICE_OUT_USB_HEADSET ||
4530 out_snd_device == SND_DEVICE_OUT_VOICE_USB_HEADSET) {
4531 ret = audio_extn_usb_enable_sidetone(out_snd_device, enable);
4532 if (ret)
4533 ALOGI("%s: usb device %d does not support device sidetone\n",
4534 __func__, out_snd_device);
4535 } else {
4536 ALOGV("%s: sidetone out device(%d) mixer cmd = %s\n",
4537 __func__, out_snd_device, str);
4538 if (enable)
4539 audio_route_apply_and_update_path(adev->audio_route, str);
4540 else
4541 audio_route_reset_and_update_path(adev->audio_route, str);
4542 }
4543 return 0;
4544}
Haynes Mathew George96483a22017-03-28 14:52:47 -07004545
4546int platform_get_mmap_data_fd(void *platform __unused, int fe_dev __unused, int dir __unused,
4547 int *fd __unused, uint32_t *size __unused)
4548{
Thierry Strudel07f96d12018-09-20 13:31:34 -07004549#if defined (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845) || (PLATFORM_SDM710) || (PLATFORM_SM8150)
Haynes Mathew George96483a22017-03-28 14:52:47 -07004550 struct platform_data *my_data = (struct platform_data *)platform;
4551 struct audio_device *adev = my_data->adev;
4552 int hw_fd = -1;
4553 char dev_name[128];
4554 struct snd_pcm_mmap_fd mmap_fd;
4555 memset(&mmap_fd, 0, sizeof(mmap_fd));
4556 mmap_fd.dir = dir;
4557 snprintf(dev_name, sizeof(dev_name), "/dev/snd/hwC%uD%u",
4558 adev->snd_card, HWDEP_FE_BASE+fe_dev);
4559 hw_fd = open(dev_name, O_RDONLY);
4560 if (hw_fd < 0) {
4561 ALOGE("fe hw dep node open %d/%d failed", adev->snd_card, fe_dev);
4562 return -1;
4563 }
4564 if (ioctl(hw_fd, SNDRV_PCM_IOCTL_MMAP_DATA_FD, &mmap_fd) < 0) {
4565 ALOGE("fe hw dep node ioctl failed");
4566 close(hw_fd);
4567 return -1;
4568 }
4569 *fd = mmap_fd.fd;
4570 *size = mmap_fd.size;
4571 close(hw_fd); // mmap_fd should still be valid
4572 return 0;
4573#else
4574 return -1;
4575#endif
4576}
Mikhail Naganov4ee6e3e2018-03-21 16:28:35 +00004577
4578bool platform_sound_trigger_usecase_needs_event(audio_usecase_t uc_id)
4579{
4580 bool needs_event = false;
4581
4582 switch (uc_id) {
4583 /* concurrent capture usecases which needs event */
4584 case USECASE_AUDIO_RECORD:
4585 case USECASE_AUDIO_RECORD_LOW_LATENCY:
4586 case USECASE_AUDIO_RECORD_MMAP:
4587 case USECASE_AUDIO_RECORD_HIFI:
4588 case USECASE_AUDIO_RECORD_VOIP:
4589 case USECASE_VOICEMMODE1_CALL:
4590 case USECASE_VOICEMMODE2_CALL:
4591 /* concurrent playback usecases that needs event */
4592 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
4593 case USECASE_AUDIO_PLAYBACK_OFFLOAD:
4594 needs_event = true;
4595 break;
4596 default:
4597 ALOGV("%s:usecase_id[%d] no need to raise event.", __func__, uc_id);
4598 }
4599 return needs_event;
4600}
4601
4602bool platform_snd_device_has_speaker(snd_device_t dev) {
4603 int num_devs = 2;
4604 snd_device_t split_devs[2] = {SND_DEVICE_NONE, SND_DEVICE_NONE};
4605 if (platform_can_split_snd_device(dev, &num_devs, split_devs) == 0) {
4606 return platform_snd_device_has_speaker(split_devs[0]) ||
4607 platform_snd_device_has_speaker(split_devs[1]);
4608 }
4609
4610 switch (dev) {
4611 case SND_DEVICE_OUT_SPEAKER:
4612 case SND_DEVICE_OUT_SPEAKER_SAFE:
4613 case SND_DEVICE_OUT_SPEAKER_REVERSE:
4614 case SND_DEVICE_OUT_SPEAKER_PROTECTED:
4615 case SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED:
4616 case SND_DEVICE_OUT_VOICE_SPEAKER_HFP:
4617 return true;
4618 default:
4619 break;
4620 }
4621 return false;
4622}
jiabin8962a4d2018-03-19 18:21:24 -07004623
4624bool platform_set_microphone_characteristic(void *platform,
4625 struct audio_microphone_characteristic_t mic) {
4626 struct platform_data *my_data = (struct platform_data *)platform;
4627 if (my_data->declared_mic_count >= AUDIO_MICROPHONE_MAX_COUNT) {
4628 ALOGE("mic number is more than maximum number");
4629 return false;
4630 }
4631 for (size_t ch = 0; ch < AUDIO_CHANNEL_COUNT_MAX; ch++) {
4632 mic.channel_mapping[ch] = AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED;
4633 }
4634 my_data->microphones[my_data->declared_mic_count++] = mic;
4635 return true;
4636}
4637
4638int platform_get_microphones(void *platform,
4639 struct audio_microphone_characteristic_t *mic_array,
4640 size_t *mic_count) {
4641 struct platform_data *my_data = (struct platform_data *)platform;
4642 if (mic_count == NULL) {
4643 return -EINVAL;
4644 }
4645 if (mic_array == NULL) {
4646 return -EINVAL;
4647 }
4648
4649 if (*mic_count == 0) {
4650 *mic_count = my_data->declared_mic_count;
4651 return 0;
4652 }
4653
4654 size_t max_mic_count = *mic_count;
4655 size_t actual_mic_count = 0;
4656 for (size_t i = 0; i < max_mic_count && i < my_data->declared_mic_count; i++) {
4657 mic_array[i] = my_data->microphones[i];
4658 actual_mic_count++;
4659 }
4660 *mic_count = actual_mic_count;
4661 return 0;
4662}
4663
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004664bool platform_set_microphone_map(void *platform, snd_device_t in_snd_device,
4665 const struct mic_info *info) {
4666 struct platform_data *my_data = (struct platform_data *)platform;
4667 if (in_snd_device < SND_DEVICE_IN_BEGIN || in_snd_device >= SND_DEVICE_IN_END) {
4668 ALOGE("%s: Sound device not valid", __func__);
4669 return false;
4670 }
4671 size_t m_count = my_data->mic_map[in_snd_device].mic_count++;
4672 if (m_count >= AUDIO_MICROPHONE_MAX_COUNT) {
4673 ALOGE("%s: Microphone count is greater than max allowed value", __func__);
4674 my_data->mic_map[in_snd_device].mic_count--;
4675 return false;
4676 }
4677 my_data->mic_map[in_snd_device].microphones[m_count] = *info;
4678 return true;
4679}
4680
4681int platform_get_active_microphones(void *platform, unsigned int channels,
4682 audio_usecase_t uc_id,
jiabin8962a4d2018-03-19 18:21:24 -07004683 struct audio_microphone_characteristic_t *mic_array,
4684 size_t *mic_count) {
4685 struct platform_data *my_data = (struct platform_data *)platform;
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004686 struct audio_usecase *usecase = get_usecase_from_list(my_data->adev, uc_id);
4687 if (mic_count == NULL || mic_array == NULL || usecase == NULL) {
jiabin8962a4d2018-03-19 18:21:24 -07004688 return -EINVAL;
4689 }
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004690 size_t max_mic_count = my_data->declared_mic_count;
jiabin8962a4d2018-03-19 18:21:24 -07004691 size_t actual_mic_count = 0;
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004692
4693 snd_device_t active_input_snd_device =
4694 platform_get_input_snd_device(platform, usecase->stream.in->device);
4695 if (active_input_snd_device == SND_DEVICE_NONE) {
4696 ALOGI("%s: No active microphones found", __func__);
4697 goto end;
4698 }
4699
4700 size_t active_mic_count = my_data->mic_map[active_input_snd_device].mic_count;
4701 struct mic_info *m_info = my_data->mic_map[active_input_snd_device].microphones;
4702
4703 for (size_t i = 0; i < active_mic_count; i++) {
4704 unsigned int channels_for_active_mic = channels;
4705 if (channels_for_active_mic > m_info[i].channel_count) {
4706 channels_for_active_mic = m_info[i].channel_count;
4707 }
4708 for (size_t j = 0; j < max_mic_count; j++) {
4709 if (strcmp(my_data->microphones[j].device_id,
4710 m_info[i].device_id) == 0) {
4711 mic_array[actual_mic_count] = my_data->microphones[j];
4712 for (size_t ch = 0; ch < channels_for_active_mic; ch++) {
4713 mic_array[actual_mic_count].channel_mapping[ch] =
4714 m_info[i].channel_mapping[ch];
4715 }
4716 actual_mic_count++;
4717 break;
jiabin8962a4d2018-03-19 18:21:24 -07004718 }
jiabin8962a4d2018-03-19 18:21:24 -07004719 }
4720 }
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004721end:
jiabin8962a4d2018-03-19 18:21:24 -07004722 *mic_count = actual_mic_count;
4723 return 0;
4724}
Haynes Mathew George65f6b432018-02-27 17:44:55 -08004725
4726int platform_set_usb_service_interval(void *platform,
4727 bool playback,
4728 unsigned long service_interval,
4729 bool *reconfig)
4730{
4731#if defined (USB_SERVICE_INTERVAL_ENABLED)
4732 struct platform_data *_platform = (struct platform_data *)platform;
4733 *reconfig = false;
4734 if (!playback) {
4735 ALOGE("%s not valid for capture", __func__);
4736 return -1;
4737 }
4738 const char *ctl_name = "USB_AUDIO_RX service_interval";
4739 struct mixer_ctl *ctl = mixer_get_ctl_by_name(_platform->adev->mixer,
4740 ctl_name);
4741 if (!ctl) {
4742 ALOGV("%s: could not get mixer %s", __func__, ctl_name);
4743 return -1;
4744 }
4745 if (mixer_ctl_get_value(ctl, 0) != (int)service_interval) {
4746 mixer_ctl_set_value(ctl, 0, service_interval);
4747 *reconfig = true;
4748 }
4749 return 0;
4750#else
4751 *reconfig = false;
4752 (void)platform;
4753 (void)playback;
4754 (void)service_interval;
4755 return -1;
4756#endif
4757}
4758
4759int platform_get_usb_service_interval(void *platform,
4760 bool playback,
4761 unsigned long *service_interval)
4762{
4763#if defined (USB_SERVICE_INTERVAL_ENABLED)
4764 struct platform_data *_platform = (struct platform_data *)platform;
4765 if (!playback) {
4766 ALOGE("%s not valid for capture", __func__);
4767 return -1;
4768 }
4769 const char *ctl_name = "USB_AUDIO_RX service_interval";
4770 struct mixer_ctl *ctl = mixer_get_ctl_by_name(_platform->adev->mixer,
4771 ctl_name);
4772 if (!ctl) {
4773 ALOGV("%s: could not get mixer %s", __func__, ctl_name);
4774 return -1;
4775 }
4776 *service_interval = mixer_ctl_get_value(ctl, 0);
4777 return 0;
4778#else
4779 (void)platform;
4780 (void)playback;
4781 (void)service_interval;
4782 return -1;
4783#endif
4784}
Ashish Jain1c849702018-05-11 20:11:55 +05304785
4786int platform_set_acdb_metainfo_key(void *platform __unused,
4787 char *name __unused,
4788 int key __unused)
4789{
4790 return -ENOSYS;
4791}