blob: 4956d4a596c0f8da2b7b328fbdca4303dcae149c [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",
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500259 [SND_DEVICE_OUT_VOICE_LINE] = "voice-line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700260 [SND_DEVICE_OUT_HDMI] = "hdmi",
261 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi",
262 [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700263 [SND_DEVICE_OUT_BT_SCO_WB] = "bt-sco-headset-wb",
Aniket Kumar Lata26483012018-01-31 20:21:42 -0800264 [SND_DEVICE_OUT_BT_A2DP] = "bt-a2dp",
265 [SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] = "speaker-and-bt-a2dp",
Aniket Kumar Lata9723a962018-05-16 17:41:55 -0700266 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP] = "speaker-safe-and-bt-a2dp",
Eric Laurentb23d5282013-05-14 15:27:20 -0700267 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = "voice-handset-tmus",
268 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones",
269 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones",
270 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset",
vivek mehtaa6b79742017-03-09 15:40:43 -0800271 [SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = "voice-tty-full-usb",
272 [SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = "voice-tty-vco-usb",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700273 [SND_DEVICE_OUT_VOICE_TX] = "voice-tx",
juyuchen66c4ecf2018-08-06 15:39:34 +0800274 [SND_DEVICE_OUT_VOICE_MUSIC_TX] = "voice-music-tx",
David Linee3fe402017-03-13 10:00:42 -0700275 [SND_DEVICE_OUT_USB_HEADSET] = "usb-headset",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700276 [SND_DEVICE_OUT_VOICE_USB_HEADSET] = "usb-headset",
David Linee3fe402017-03-13 10:00:42 -0700277 [SND_DEVICE_OUT_USB_HEADPHONES] = "usb-headphones",
jasmine cha270b7762018-03-30 15:41:33 +0800278 [SND_DEVICE_OUT_USB_HEADSET_SPEC] = "usb-headset",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700279 [SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = "usb-headphones",
David Linee3fe402017-03-13 10:00:42 -0700280 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = "speaker-and-usb-headphones",
Haynes Mathew George9090bfb2017-05-31 11:44:50 -0700281 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] = "speaker-safe-and-usb-headphones",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700282 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = "speaker-protected",
283 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = "voice-speaker-protected",
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -0700284 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = "voice-speaker-hfp",
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -0800285 [SND_DEVICE_OUT_SPEAKER_AND_BT_SCO] = "speaker-and-bt-sco",
juyuchen5351ea62018-05-16 10:54:37 +0800286 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO] = "speaker-safe-and-bt-sco",
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -0800287 [SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB] = "speaker-and-bt-sco-wb",
juyuchen5351ea62018-05-16 10:54:37 +0800288 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB] = "speaker-safe-and-bt-sco-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700289
290 /* Capture sound devices */
291 [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700292 [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700293 [SND_DEVICE_IN_HANDSET_MIC_NS] = "handset-mic",
294 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = "handset-mic",
295 [SND_DEVICE_IN_HANDSET_DMIC] = "dmic-endfire",
296 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = "dmic-endfire",
297 [SND_DEVICE_IN_HANDSET_DMIC_NS] = "dmic-endfire",
298 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = "dmic-endfire",
299 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = "dmic-endfire",
300
301 [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
302 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "speaker-mic",
303 [SND_DEVICE_IN_SPEAKER_MIC_NS] = "speaker-mic",
304 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = "speaker-mic",
305 [SND_DEVICE_IN_SPEAKER_DMIC] = "speaker-dmic-endfire",
306 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = "speaker-dmic-endfire",
307 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = "speaker-dmic-endfire",
308 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = "speaker-dmic-endfire",
309 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = "speaker-dmic-endfire",
310
311 [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
Eric Laurentcefbbac2014-09-04 13:54:10 -0500312 [SND_DEVICE_IN_HEADSET_MIC_AEC] = "headset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700313
Eric Laurentb23d5282013-05-14 15:27:20 -0700314 [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic",
315 [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700316 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = "bt-sco-mic",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700317 [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700318 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = "bt-sco-mic-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700319 [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700320
321 [SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef",
322 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = "voice-dmic-ef-tmus",
323 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
324 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = "voice-speaker-dmic-ef",
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -0700325 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = "voice-speaker-mic-hfp",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700326 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700327 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
328 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
329 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
vivek mehtaa6b79742017-03-09 15:40:43 -0800330 [SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = "voice-tty-full-usb-mic",
331 [SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = "voice-tty-hco-usb-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700332
Eric Laurentb23d5282013-05-14 15:27:20 -0700333 [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700334 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = "voice-rec-mic",
vivek mehta733c1df2016-04-04 15:09:24 -0700335 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = "voice-rec-mic",
vivek mehtaf3440682016-05-11 14:24:37 -0700336 [SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700337 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = "voice-rec-dmic-ef",
338 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence",
David Linee3fe402017-03-13 10:00:42 -0700339 [SND_DEVICE_IN_USB_HEADSET_MIC] = "usb-headset-mic",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700340 [SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] ="usb-headset-mic",
341 [SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = "usb-headset-mic",
342 [SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = "usb-headset-mic",
343 [SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = "usb-headset-mic",
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700344 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = "headset-mic",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700345
Ricardo Garcia9034bc42016-04-04 07:11:46 -0700346 [SND_DEVICE_IN_UNPROCESSED_MIC] = "unprocessed-mic",
vivek mehta0125e782016-06-16 18:03:11 -0700347 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = "unprocessed-stereo-mic",
348 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = "unprocessed-three-mic",
349 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = "unprocessed-quad-mic",
350 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = "unprocessed-headset-mic",
rago90fb9612015-12-02 11:37:53 -0800351
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700352 [SND_DEVICE_IN_VOICE_RX] = "voice-rx",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700353
Prashant Malanic92c5962015-08-11 15:10:18 -0700354 [SND_DEVICE_IN_THREE_MIC] = "three-mic",
355 [SND_DEVICE_IN_QUAD_MIC] = "quad-mic",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700356 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = "vi-feedback",
Prashant Malanic92c5962015-08-11 15:10:18 -0700357 [SND_DEVICE_IN_HANDSET_TMIC] = "three-mic",
358 [SND_DEVICE_IN_HANDSET_QMIC] = "quad-mic",
vivek mehta733c1df2016-04-04 15:09:24 -0700359 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = "three-mic",
360 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = "quad-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700361};
362
363/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700364static int acdb_device_table[SND_DEVICE_MAX] = {
Eric Laurentb23d5282013-05-14 15:27:20 -0700365 [SND_DEVICE_NONE] = -1,
366 [SND_DEVICE_OUT_HANDSET] = 7,
367 [SND_DEVICE_OUT_SPEAKER] = 15,
368 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 15,
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700369 [SND_DEVICE_OUT_SPEAKER_SAFE] = 15,
Eric Laurentb23d5282013-05-14 15:27:20 -0700370 [SND_DEVICE_OUT_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500371 [SND_DEVICE_OUT_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700372 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700373 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500374 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = 77,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700375 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = 77,
Ravi Kumar Alamanda235c3482014-08-21 17:32:44 -0700376 [SND_DEVICE_OUT_VOICE_HANDSET] = ACDB_ID_VOICE_HANDSET,
377 [SND_DEVICE_OUT_VOICE_SPEAKER] = ACDB_ID_VOICE_SPEAKER,
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500378 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = 53,
Eric Laurentb23d5282013-05-14 15:27:20 -0700379 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500380 [SND_DEVICE_OUT_VOICE_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700381 [SND_DEVICE_OUT_HDMI] = 18,
382 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 15,
383 [SND_DEVICE_OUT_BT_SCO] = 22,
juyuchen5351ea62018-05-16 10:54:37 +0800384 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO] = 14,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700385 [SND_DEVICE_OUT_BT_SCO_WB] = 39,
juyuchen5351ea62018-05-16 10:54:37 +0800386 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB] = 14,
Aniket Kumar Lata26483012018-01-31 20:21:42 -0800387 [SND_DEVICE_OUT_BT_A2DP] = 20,
388 [SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] = 14,
Aniket Kumar Lata9723a962018-05-16 17:41:55 -0700389 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP] = 14,
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700390 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = ACDB_ID_VOICE_HANDSET_TMUS,
Eric Laurentb23d5282013-05-14 15:27:20 -0700391 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
392 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
393 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
vivek mehtaa6b79742017-03-09 15:40:43 -0800394 [SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = 17,
395 [SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = 17,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700396 [SND_DEVICE_OUT_VOICE_TX] = 45,
juyuchen66c4ecf2018-08-06 15:39:34 +0800397 [SND_DEVICE_OUT_VOICE_MUSIC_TX] = 3,
David Linee3fe402017-03-13 10:00:42 -0700398 [SND_DEVICE_OUT_USB_HEADSET] = 45,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700399 [SND_DEVICE_OUT_VOICE_USB_HEADSET] = 45,
David Linee3fe402017-03-13 10:00:42 -0700400 [SND_DEVICE_OUT_USB_HEADPHONES] = 45,
jasmine cha270b7762018-03-30 15:41:33 +0800401 [SND_DEVICE_OUT_USB_HEADSET_SPEC] = 45,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700402 [SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = 45,
David Linee3fe402017-03-13 10:00:42 -0700403 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = 14,
Haynes Mathew George9090bfb2017-05-31 11:44:50 -0700404 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] = 14,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700405 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = 124,
406 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = 101,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700407 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = ACDB_ID_VOICE_SPEAKER,
Eric Laurentb23d5282013-05-14 15:27:20 -0700408
409 [SND_DEVICE_IN_HANDSET_MIC] = 4,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700410 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 106,
411 [SND_DEVICE_IN_HANDSET_MIC_NS] = 107,
412 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = 108,
413 [SND_DEVICE_IN_HANDSET_DMIC] = 41,
414 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = 109,
415 [SND_DEVICE_IN_HANDSET_DMIC_NS] = 110,
416 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = 111,
417 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = 34,
418
419 [SND_DEVICE_IN_SPEAKER_MIC] = 11,
420 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 112,
421 [SND_DEVICE_IN_SPEAKER_MIC_NS] = 113,
422 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = 114,
423 [SND_DEVICE_IN_SPEAKER_DMIC] = 43,
424 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = 115,
425 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = 116,
426 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = 117,
427 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = 35,
428
rago90fb9612015-12-02 11:37:53 -0800429 [SND_DEVICE_IN_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentcefbbac2014-09-04 13:54:10 -0500430 [SND_DEVICE_IN_HEADSET_MIC_AEC] = ACDB_ID_HEADSET_MIC_AEC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700431
Eric Laurentb23d5282013-05-14 15:27:20 -0700432 [SND_DEVICE_IN_HDMI_MIC] = 4,
433 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700434 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = 21,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700435 [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700436 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = 38,
Eric Laurentb23d5282013-05-14 15:27:20 -0700437 [SND_DEVICE_IN_CAMCORDER_MIC] = 61,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700438
439 [SND_DEVICE_IN_VOICE_DMIC] = 41,
440 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = ACDB_ID_VOICE_DMIC_EF_TMUS,
441 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700442 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = 11,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700443 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 43,
rago90fb9612015-12-02 11:37:53 -0800444 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentb23d5282013-05-14 15:27:20 -0700445 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
446 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
447 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
vivek mehtaa6b79742017-03-09 15:40:43 -0800448 [SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = 16,
449 [SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = 16,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700450
rago90fb9612015-12-02 11:37:53 -0800451 [SND_DEVICE_IN_VOICE_REC_MIC] = ACDB_ID_VOICE_REC_MIC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700452 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = 113,
vivek mehta733c1df2016-04-04 15:09:24 -0700453 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = 112,
vivek mehtaf3440682016-05-11 14:24:37 -0700454 [SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = 114,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700455 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = 35,
456 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 43,
rago90fb9612015-12-02 11:37:53 -0800457 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
458
459 [SND_DEVICE_IN_UNPROCESSED_MIC] = ACDB_ID_VOICE_REC_MIC,
460 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
vivek mehta4ed66e62016-04-15 23:33:34 -0700461 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = 35,
462 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = 125,
463 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = 125,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700464
465 [SND_DEVICE_IN_VOICE_RX] = 44,
David Linee3fe402017-03-13 10:00:42 -0700466 [SND_DEVICE_IN_USB_HEADSET_MIC] = 44,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700467 [SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = 44,
468 [SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = 44,
469 [SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = 44,
470 [SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = 44,
Prashant Malanic92c5962015-08-11 15:10:18 -0700471 [SND_DEVICE_IN_THREE_MIC] = 46,
472 [SND_DEVICE_IN_QUAD_MIC] = 46,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700473 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = 102,
Prashant Malanic92c5962015-08-11 15:10:18 -0700474 [SND_DEVICE_IN_HANDSET_TMIC] = 125,
475 [SND_DEVICE_IN_HANDSET_QMIC] = 125,
vivek mehta733c1df2016-04-04 15:09:24 -0700476 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = 125, /* override this for new target to 140 */
477 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = 125, /* override this for new target to 140 */
Eric Laurentb23d5282013-05-14 15:27:20 -0700478};
479
David Linee3fe402017-03-13 10:00:42 -0700480// Platform specific backend bit width table
481static int backend_bit_width_table[SND_DEVICE_MAX] = {0};
482
Haynes Mathew George98c95622014-06-20 19:14:25 -0700483struct name_to_index {
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700484 char name[100];
485 unsigned int index;
486};
487
488#define TO_NAME_INDEX(X) #X, X
489
Haynes Mathew George98c95622014-06-20 19:14:25 -0700490/* Used to get index from parsed string */
491static const struct name_to_index snd_device_name_index[SND_DEVICE_MAX] = {
492 /* out */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700493 {TO_NAME_INDEX(SND_DEVICE_OUT_HANDSET)},
494 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER)},
495 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_REVERSE)},
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700496 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700497 {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500498 {TO_NAME_INDEX(SND_DEVICE_OUT_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700499 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700500 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES)},
Eric Laurent744996b2014-10-01 11:40:40 -0500501 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_LINE)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700502 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700503 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET)},
504 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700505 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_HFP)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700506 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500507 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700508 {TO_NAME_INDEX(SND_DEVICE_OUT_HDMI)},
509 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HDMI)},
510 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO)},
juyuchen5351ea62018-05-16 10:54:37 +0800511 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700512 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO_WB)},
juyuchen5351ea62018-05-16 10:54:37 +0800513 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB)},
Aniket Kumar Lata26483012018-01-31 20:21:42 -0800514 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_A2DP)},
515 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP)},
Aniket Kumar Lata9723a962018-05-16 17:41:55 -0700516 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700517 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET_TMUS)},
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500518 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HAC_HANDSET)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700519 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES)},
520 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES)},
521 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET)},
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -0800522 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_SCO)},
523 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800524 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_USB)},
525 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_USB)},
David Linee3fe402017-03-13 10:00:42 -0700526 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADSET)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700527 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_USB_HEADSET)},
David Linee3fe402017-03-13 10:00:42 -0700528 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADPHONES)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700529 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_USB_HEADPHONES)},
David Linee3fe402017-03-13 10:00:42 -0700530 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET)},
Haynes Mathew George9090bfb2017-05-31 11:44:50 -0700531 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700532 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED)},
533 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED)},
jasmine cha270b7762018-03-30 15:41:33 +0800534 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADSET_SPEC)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800535
536 /* in */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700537 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700538 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700539 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_NS)},
540 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)},
541 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC)},
542 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC)},
543 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_NS)},
544 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)},
545 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_STEREO)},
546
547 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700548 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700549 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_NS)},
550 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)},
551 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC)},
552 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC)},
553 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS)},
554 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)},
555 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_STEREO)},
556
557 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC)},
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700558 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700559
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700560 {TO_NAME_INDEX(SND_DEVICE_IN_HDMI_MIC)},
561 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700562 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700563 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700564 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700565 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700566
567 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC)},
568 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC_TMUS)},
569 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700570 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700571 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC)},
572 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEADSET_MIC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700573 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC)},
574 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC)},
575 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800576 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC)},
577 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC)},
578
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700579
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700580 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700581 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_NS)},
vivek mehta733c1df2016-04-04 15:09:24 -0700582 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC)},
vivek mehtaf3440682016-05-11 14:24:37 -0700583 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700584 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_STEREO)},
585 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE)},
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700586 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_HEADSET_MIC)},
David Linee3fe402017-03-13 10:00:42 -0700587 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700588 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_USB_HEADSET_MIC)},
589 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC)},
590 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC)},
591 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC_AEC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700592
rago90fb9612015-12-02 11:37:53 -0800593 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_MIC)},
594 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC)},
vivek mehta4ed66e62016-04-15 23:33:34 -0700595 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_STEREO_MIC)},
596 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_THREE_MIC)},
597 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_QUAD_MIC)},
rago90fb9612015-12-02 11:37:53 -0800598
Prashant Malanic92c5962015-08-11 15:10:18 -0700599 {TO_NAME_INDEX(SND_DEVICE_IN_THREE_MIC)},
600 {TO_NAME_INDEX(SND_DEVICE_IN_QUAD_MIC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700601 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_VI_FEEDBACK)},
Prashant Malanic92c5962015-08-11 15:10:18 -0700602 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC)},
603 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC)},
vivek mehta733c1df2016-04-04 15:09:24 -0700604 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC_AEC)},
605 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC_AEC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700606};
607
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700608static char * backend_tag_table[SND_DEVICE_MAX] = {0};
609static char * hw_interface_table[SND_DEVICE_MAX] = {0};
Haynes Mathew George98c95622014-06-20 19:14:25 -0700610
611static const struct name_to_index usecase_name_index[AUDIO_USECASE_MAX] = {
612 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_DEEP_BUFFER)},
613 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_LOW_LATENCY)},
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800614 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_HIFI)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700615 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD)},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700616 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_TTS)},
617 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_ULL)},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800618 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_MMAP)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700619 {TO_NAME_INDEX(USECASE_AUDIO_RECORD)},
620 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_LOW_LATENCY)},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800621 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_MMAP)},
Haynes Mathew George569b7482017-05-08 14:44:27 -0700622 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_HIFI)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700623 {TO_NAME_INDEX(USECASE_VOICE_CALL)},
624 {TO_NAME_INDEX(USECASE_VOICE2_CALL)},
625 {TO_NAME_INDEX(USECASE_VOLTE_CALL)},
626 {TO_NAME_INDEX(USECASE_QCHAT_CALL)},
627 {TO_NAME_INDEX(USECASE_VOWLAN_CALL)},
John Muirf1346ce2016-12-06 00:03:41 -0800628 {TO_NAME_INDEX(USECASE_VOICEMMODE1_CALL)},
629 {TO_NAME_INDEX(USECASE_VOICEMMODE2_CALL)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700630 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK)},
631 {TO_NAME_INDEX(USECASE_INCALL_REC_DOWNLINK)},
632 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK_AND_DOWNLINK)},
633 {TO_NAME_INDEX(USECASE_AUDIO_HFP_SCO)},
John Muirf1346ce2016-12-06 00:03:41 -0800634 {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_RX)},
635 {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_TX)},
636 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_AFE_PROXY)},
637 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_AFE_PROXY)},
638 {TO_NAME_INDEX(USECASE_AUDIO_DSM_FEEDBACK)},
vivek mehtaa68fea62017-06-08 19:04:02 -0700639 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_VOIP)},
640 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_VOIP)},
Nadav Bar3d72cfc2018-01-07 12:19:24 +0200641 {TO_NAME_INDEX(USECASE_INCALL_MUSIC_UPLINK)},
Aniket Kumar Lata99546312018-03-19 21:38:38 -0700642 {TO_NAME_INDEX(USECASE_AUDIO_A2DP_ABR_FEEDBACK)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700643};
644
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800645static const struct name_to_index usecase_type_index[USECASE_TYPE_MAX] = {
646 {TO_NAME_INDEX(PCM_PLAYBACK)},
647 {TO_NAME_INDEX(PCM_CAPTURE)},
648 {TO_NAME_INDEX(VOICE_CALL)},
649 {TO_NAME_INDEX(PCM_HFP_CALL)},
650};
651
652struct app_type_entry {
653 int uc_type;
654 int bit_width;
655 int app_type;
656 int max_rate;
vivek mehtaa68fea62017-06-08 19:04:02 -0700657 char *mode;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800658 struct listnode node; // membership in app_type_entry_list;
659};
660
661static struct listnode app_type_entry_list;
662
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700663#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
664#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
Eric Laurent0e46adf2016-12-16 12:49:24 -0800665#define ULL_PLATFORM_DELAY (3*1000LL)
666#define MMAP_PLATFORM_DELAY (3*1000LL)
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700667
Eric Laurentb23d5282013-05-14 15:27:20 -0700668static pthread_once_t check_op_once_ctl = PTHREAD_ONCE_INIT;
669static bool is_tmus = false;
670
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800671static int init_be_dai_name_table(struct audio_device *adev);
672
Eric Laurentb23d5282013-05-14 15:27:20 -0700673static void check_operator()
674{
675 char value[PROPERTY_VALUE_MAX];
676 int mccmnc;
677 property_get("gsm.sim.operator.numeric",value,"0");
678 mccmnc = atoi(value);
Eric Laurent2bafff12016-03-17 12:17:23 -0700679 ALOGD("%s: tmus mccmnc %d", __func__, mccmnc);
Eric Laurentb23d5282013-05-14 15:27:20 -0700680 switch(mccmnc) {
681 /* TMUS MCC(310), MNC(490, 260, 026) */
682 case 310490:
683 case 310260:
684 case 310026:
sangwon.jeonb891db52013-09-14 17:39:15 +0900685 /* Add new TMUS MNC(800, 660, 580, 310, 270, 250, 240, 230, 220, 210, 200, 160) */
686 case 310800:
687 case 310660:
688 case 310580:
689 case 310310:
690 case 310270:
691 case 310250:
692 case 310240:
693 case 310230:
694 case 310220:
695 case 310210:
696 case 310200:
697 case 310160:
Eric Laurentb23d5282013-05-14 15:27:20 -0700698 is_tmus = true;
699 break;
700 }
701}
702
703bool is_operator_tmus()
704{
705 pthread_once(&check_op_once_ctl, check_operator);
706 return is_tmus;
707}
708
keunhui.park2f7306a2015-07-16 16:48:06 +0900709static char *get_current_operator()
710{
711 struct listnode *node;
712 struct operator_info *info_item;
713 char mccmnc[PROPERTY_VALUE_MAX];
714 char *ret = NULL;
715
Tom Cherry7fea2042016-11-10 18:05:59 -0800716 property_get("gsm.sim.operator.numeric",mccmnc,"00000");
keunhui.park2f7306a2015-07-16 16:48:06 +0900717
718 list_for_each(node, &operator_info_list) {
719 info_item = node_to_item(node, struct operator_info, list);
720 if (strstr(info_item->mccmnc, mccmnc) != NULL) {
721 ret = info_item->name;
722 }
723 }
724
725 return ret;
726}
727
728static struct operator_specific_device *get_operator_specific_device(snd_device_t snd_device)
729{
730 struct listnode *node;
731 struct operator_specific_device *ret = NULL;
732 struct operator_specific_device *device_item;
733 char *operator_name;
734
735 operator_name = get_current_operator();
736 if (operator_name == NULL)
737 return ret;
738
739 list_for_each(node, operator_specific_device_table[snd_device]) {
740 device_item = node_to_item(node, struct operator_specific_device, list);
741 if (strcmp(operator_name, device_item->operator) == 0) {
742 ret = device_item;
743 }
744 }
745
746 return ret;
747}
748
749
750static int get_operator_specific_device_acdb_id(snd_device_t snd_device)
751{
752 struct operator_specific_device *device;
753 int ret = acdb_device_table[snd_device];
754
755 device = get_operator_specific_device(snd_device);
756 if (device != NULL)
757 ret = device->acdb_id;
758
759 return ret;
760}
761
762static const char *get_operator_specific_device_mixer_path(snd_device_t snd_device)
763{
764 struct operator_specific_device *device;
765 const char *ret = device_table[snd_device];
766
767 device = get_operator_specific_device(snd_device);
768 if (device != NULL)
769 ret = device->mixer_path;
770
771 return ret;
772}
773
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800774inline bool platform_supports_app_type_cfg()
775{
Thierry Strudel07f96d12018-09-20 13:31:34 -0700776#if defined (PLATFORM_MSM8998) || (PLATFORM_SDM845) || (PLATFORM_SDM710) || (PLATFORM_SM8150)
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800777 return true;
778#else
779 return false;
780#endif
781}
782
jasmine chac89321b2018-04-10 21:37:01 +0800783static int parse_audiocal_cfg(struct str_parms *parms, acdb_audio_cal_cfg_t *cal)
784{
785 int err;
786 char value[64];
787 int ret = 0;
788
789 if (parms == NULL || cal == NULL)
790 return ret;
791
792 err = str_parms_get_str(parms, "cal_persist", value, sizeof(value));
793 if (err >= 0) {
794 str_parms_del(parms, "cal_persist");
795 cal->persist = (uint32_t)strtoul(value, NULL, 0);
796 ret = ret | 0x1;
797 }
798 err = str_parms_get_str(parms, "cal_apptype", value, sizeof(value));
799 if (err >= 0) {
800 str_parms_del(parms, "cal_apptype");
801 cal->app_type = (uint32_t)strtoul(value, NULL, 0);
802 ret = ret | 0x2;
803 }
804 err = str_parms_get_str(parms, "cal_caltype", value, sizeof(value));
805 if (err >= 0) {
806 str_parms_del(parms, "cal_caltype");
807 cal->cal_type = (uint32_t)strtoul(value, NULL, 0);
808 ret = ret | 0x4;
809 }
810 err = str_parms_get_str(parms, "cal_samplerate", value, sizeof(value));
811 if (err >= 0) {
812 str_parms_del(parms, "cal_samplerate");
813 cal->sampling_rate = (uint32_t)strtoul(value, NULL, 0);
814 ret = ret | 0x8;
815 }
816 err = str_parms_get_str(parms, "cal_devid", value, sizeof(value));
817 if (err >= 0) {
818 str_parms_del(parms, "cal_devid");
819 cal->dev_id = (uint32_t)strtoul(value, NULL, 0);
820 ret = ret | 0x10;
821 }
822 err = str_parms_get_str(parms, "cal_snddevid", value, sizeof(value));
823 if (err >= 0) {
824 str_parms_del(parms, "cal_snddevid");
825 cal->snd_dev_id = (uint32_t)strtoul(value, NULL, 0);
826 ret = ret | 0x20;
827 }
828 err = str_parms_get_str(parms, "cal_topoid", value, sizeof(value));
829 if (err >= 0) {
830 str_parms_del(parms, "cal_topoid");
831 cal->topo_id = (uint32_t)strtoul(value, NULL, 0);
832 ret = ret | 0x40;
833 }
834 err = str_parms_get_str(parms, "cal_moduleid", value, sizeof(value));
835 if (err >= 0) {
836 str_parms_del(parms, "cal_moduleid");
837 cal->module_id = (uint32_t)strtoul(value, NULL, 0);
838 ret = ret | 0x80;
839 }
840 err = str_parms_get_str(parms, "cal_paramid", value, sizeof(value));
841 if (err >= 0) {
842 str_parms_del(parms, "cal_paramid");
843 cal->param_id = (uint32_t)strtoul(value, NULL, 0);
844 ret = ret | 0x100;
845 }
846 return ret;
847}
848
849static void set_audiocal(void *platform, struct str_parms *parms, char *value, int len)
850{
851 struct platform_data *my_data = (struct platform_data *)platform;
852 acdb_audio_cal_cfg_t cal;
853 uint8_t *dptr = NULL;
854 int32_t dlen = 0;
855 int err ,ret;
856
857 if (value == NULL || platform == NULL || parms == NULL) {
858 ALOGE("[%s] received null pointer, failed", __func__);
859 goto done_key_audcal;
860 }
861
862 memset(&cal, 0, sizeof(acdb_audio_cal_cfg_t));
863 /* parse audio calibration keys */
864 ret = parse_audiocal_cfg(parms, &cal);
865
866 /* handle audio calibration data now */
867 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_AUD_CALDATA, value, len);
868 if (err >= 0) {
869 str_parms_del(parms, AUDIO_PARAMETER_KEY_AUD_CALDATA);
870 dlen = strlen(value);
871 if (dlen <= 0) {
872 ALOGE("[%s] null data received", __func__);
873 goto done_key_audcal;
874 }
875 /*
876 The base64 encoded string is always larger than the binary data,
877 so b64_pton will always output less data than provided (around 1/3
878 less than the input data). That's why we can allocate input buffer
879 length and then get function work.
880 */
881 dptr = (uint8_t *)calloc(dlen, sizeof(uint8_t));
882 if (dptr == NULL) {
883 ALOGE("[%s] memory allocation failed for %d", __func__, dlen);
884 goto done_key_audcal;
885 }
886 dlen = b64_pton(value, dptr, dlen);
887 if (dlen <= 0) {
888 ALOGE("[%s] data decoding failed %d", __func__, dlen);
889 goto done_key_audcal;
890 }
891
892 if (cal.dev_id) {
893 if (audio_is_input_device(cal.dev_id)) {
894 cal.snd_dev_id = platform_get_input_snd_device(platform, cal.dev_id);
895 } else {
896 cal.snd_dev_id = platform_get_output_snd_device(platform, cal.dev_id);
897 }
898 }
899 cal.acdb_dev_id = platform_get_snd_device_acdb_id(cal.snd_dev_id);
900 ALOGD("Setting audio calibration for snd_device(%d) acdb_id(%d)",
901 cal.snd_dev_id, cal.acdb_dev_id);
902 if (cal.acdb_dev_id == -EINVAL) {
903 ALOGE("[%s] Invalid acdb_device id %d for snd device id %d",
904 __func__, cal.acdb_dev_id, cal.snd_dev_id);
905 goto done_key_audcal;
906 }
907 if (my_data->acdb_set_audio_cal) {
908 ret = my_data->acdb_set_audio_cal((void *)&cal, (void *)dptr, dlen);
909 }
910 }
911done_key_audcal:
912 if (dptr != NULL)
913 free(dptr);
914}
915
vivek mehta1a9b7c02015-06-25 11:49:38 -0700916bool platform_send_gain_dep_cal(void *platform, int level)
917{
918 bool ret_val = false;
919 struct platform_data *my_data = (struct platform_data *)platform;
920 struct audio_device *adev = my_data->adev;
921 int acdb_dev_id, app_type;
922 int acdb_dev_type = MSM_SNDDEV_CAP_RX;
923 int mode = CAL_MODE_RTAC;
924 struct listnode *node;
925 struct audio_usecase *usecase;
Haynes Mathew George67486e22017-06-26 12:58:38 -0700926 bool valid_uc_type;
927 bool valid_dev;
vivek mehta1a9b7c02015-06-25 11:49:38 -0700928
929 if (my_data->acdb_send_gain_dep_cal == NULL) {
930 ALOGE("%s: dlsym error for acdb_send_gain_dep_cal", __func__);
931 return ret_val;
932 }
933
934 if (!voice_is_in_call(adev)) {
935 ALOGV("%s: Not Voice call usecase, apply new cal for level %d",
936 __func__, level);
vivek mehta1a9b7c02015-06-25 11:49:38 -0700937
938 // find the current active sound device
939 list_for_each(node, &adev->usecase_list) {
940 usecase = node_to_item(node, struct audio_usecase, list);
Haynes Mathew George67486e22017-06-26 12:58:38 -0700941 LOG_ALWAYS_FATAL_IF(usecase == NULL,
942 "unxpected NULL usecase in usecase_list");
943 valid_uc_type = usecase->type == PCM_PLAYBACK;
944 valid_dev = false;
945 if (valid_uc_type) {
946 audio_devices_t dev = usecase->stream.out->devices;
947 valid_dev = (dev == AUDIO_DEVICE_OUT_SPEAKER ||
vivek mehta40125092017-08-21 18:48:51 -0700948 dev == AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Haynes Mathew George67486e22017-06-26 12:58:38 -0700949 dev == AUDIO_DEVICE_OUT_WIRED_HEADSET ||
950 dev == AUDIO_DEVICE_OUT_WIRED_HEADPHONE);
951 }
952 if (valid_dev) {
vivek mehta40125092017-08-21 18:48:51 -0700953 ALOGV("%s: out device is %d", __func__, usecase->out_snd_device);
954 if (platform_supports_app_type_cfg())
955 app_type = usecase->stream.out->app_type_cfg.app_type;
956 else
957 app_type = DEFAULT_APP_TYPE_RX_PATH;
vivek mehta4cb82982015-07-13 12:05:49 -0700958
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -0700959 acdb_dev_id = platform_get_snd_device_acdb_id(usecase->out_snd_device);
vivek mehta40125092017-08-21 18:48:51 -0700960
961 if (!my_data->acdb_send_gain_dep_cal(acdb_dev_id, app_type,
vivek mehta1a9b7c02015-06-25 11:49:38 -0700962 acdb_dev_type, mode, level)) {
963 // set ret_val true if at least one calibration is set successfully
964 ret_val = true;
965 } else {
966 ALOGE("%s: my_data->acdb_send_gain_dep_cal failed ", __func__);
967 }
968 } else {
969 ALOGW("%s: Usecase list is empty", __func__);
970 }
971 }
972 } else {
973 ALOGW("%s: Voice call in progress .. ignore setting new cal",
974 __func__);
975 }
976 return ret_val;
977}
978
Eric Laurentcefbbac2014-09-04 13:54:10 -0500979void platform_set_echo_reference(struct audio_device *adev, bool enable, audio_devices_t out_device)
Eric Laurentb23d5282013-05-14 15:27:20 -0700980{
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800981 struct platform_data *my_data = (struct platform_data *)adev->platform;
Eric Laurentcefbbac2014-09-04 13:54:10 -0500982 snd_device_t snd_device = SND_DEVICE_NONE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700983
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800984 if (strcmp(my_data->ec_ref_mixer_path, "")) {
985 ALOGV("%s: diabling %s", __func__, my_data->ec_ref_mixer_path);
986 audio_route_reset_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
Eric Laurentcefbbac2014-09-04 13:54:10 -0500987 }
988
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800989 if (enable) {
990 strcpy(my_data->ec_ref_mixer_path, "echo-reference");
991 if (out_device != AUDIO_DEVICE_NONE) {
992 snd_device = platform_get_output_snd_device(adev->platform, out_device);
993 platform_add_backend_name(adev->platform, my_data->ec_ref_mixer_path, snd_device);
994 }
Eric Laurentcefbbac2014-09-04 13:54:10 -0500995
Joe Onorato188b6222016-03-01 11:02:27 -0800996 ALOGV("%s: enabling %s", __func__, my_data->ec_ref_mixer_path);
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800997 audio_route_apply_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
998 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700999}
1000
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001001static struct csd_data *open_csd_client(bool i2s_ext_modem)
1002{
1003 struct csd_data *csd = calloc(1, sizeof(struct csd_data));
1004
1005 csd->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
1006 if (csd->csd_client == NULL) {
1007 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
1008 goto error;
1009 } else {
1010 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
1011
1012 csd->deinit = (deinit_t)dlsym(csd->csd_client,
1013 "csd_client_deinit");
1014 if (csd->deinit == NULL) {
1015 ALOGE("%s: dlsym error %s for csd_client_deinit", __func__,
1016 dlerror());
1017 goto error;
1018 }
1019 csd->disable_device = (disable_device_t)dlsym(csd->csd_client,
1020 "csd_client_disable_device");
1021 if (csd->disable_device == NULL) {
1022 ALOGE("%s: dlsym error %s for csd_client_disable_device",
1023 __func__, dlerror());
1024 goto error;
1025 }
1026 csd->enable_device_config = (enable_device_config_t)dlsym(csd->csd_client,
1027 "csd_client_enable_device_config");
1028 if (csd->enable_device_config == NULL) {
1029 ALOGE("%s: dlsym error %s for csd_client_enable_device_config",
1030 __func__, dlerror());
1031 goto error;
1032 }
1033 csd->enable_device = (enable_device_t)dlsym(csd->csd_client,
1034 "csd_client_enable_device");
1035 if (csd->enable_device == NULL) {
1036 ALOGE("%s: dlsym error %s for csd_client_enable_device",
1037 __func__, dlerror());
1038 goto error;
1039 }
1040 csd->start_voice = (start_voice_t)dlsym(csd->csd_client,
1041 "csd_client_start_voice");
1042 if (csd->start_voice == NULL) {
1043 ALOGE("%s: dlsym error %s for csd_client_start_voice",
1044 __func__, dlerror());
1045 goto error;
1046 }
1047 csd->stop_voice = (stop_voice_t)dlsym(csd->csd_client,
1048 "csd_client_stop_voice");
1049 if (csd->stop_voice == NULL) {
1050 ALOGE("%s: dlsym error %s for csd_client_stop_voice",
1051 __func__, dlerror());
1052 goto error;
1053 }
1054 csd->volume = (volume_t)dlsym(csd->csd_client,
1055 "csd_client_volume");
1056 if (csd->volume == NULL) {
1057 ALOGE("%s: dlsym error %s for csd_client_volume",
1058 __func__, dlerror());
1059 goto error;
1060 }
1061 csd->mic_mute = (mic_mute_t)dlsym(csd->csd_client,
1062 "csd_client_mic_mute");
1063 if (csd->mic_mute == NULL) {
1064 ALOGE("%s: dlsym error %s for csd_client_mic_mute",
1065 __func__, dlerror());
1066 goto error;
1067 }
1068 csd->slow_talk = (slow_talk_t)dlsym(csd->csd_client,
1069 "csd_client_slow_talk");
1070 if (csd->slow_talk == NULL) {
1071 ALOGE("%s: dlsym error %s for csd_client_slow_talk",
1072 __func__, dlerror());
1073 goto error;
1074 }
1075 csd->start_playback = (start_playback_t)dlsym(csd->csd_client,
1076 "csd_client_start_playback");
1077 if (csd->start_playback == NULL) {
1078 ALOGE("%s: dlsym error %s for csd_client_start_playback",
1079 __func__, dlerror());
1080 goto error;
1081 }
1082 csd->stop_playback = (stop_playback_t)dlsym(csd->csd_client,
1083 "csd_client_stop_playback");
1084 if (csd->stop_playback == NULL) {
1085 ALOGE("%s: dlsym error %s for csd_client_stop_playback",
1086 __func__, dlerror());
1087 goto error;
1088 }
1089 csd->start_record = (start_record_t)dlsym(csd->csd_client,
1090 "csd_client_start_record");
1091 if (csd->start_record == NULL) {
1092 ALOGE("%s: dlsym error %s for csd_client_start_record",
1093 __func__, dlerror());
1094 goto error;
1095 }
1096 csd->stop_record = (stop_record_t)dlsym(csd->csd_client,
1097 "csd_client_stop_record");
1098 if (csd->stop_record == NULL) {
1099 ALOGE("%s: dlsym error %s for csd_client_stop_record",
1100 __func__, dlerror());
1101 goto error;
1102 }
1103
1104 csd->get_sample_rate = (get_sample_rate_t)dlsym(csd->csd_client,
1105 "csd_client_get_sample_rate");
1106 if (csd->get_sample_rate == NULL) {
1107 ALOGE("%s: dlsym error %s for csd_client_get_sample_rate",
1108 __func__, dlerror());
1109
1110 goto error;
1111 }
1112
1113 csd->init = (init_t)dlsym(csd->csd_client, "csd_client_init");
1114
1115 if (csd->init == NULL) {
1116 ALOGE("%s: dlsym error %s for csd_client_init",
1117 __func__, dlerror());
1118 goto error;
1119 } else {
1120 csd->init(i2s_ext_modem);
1121 }
1122 }
1123 return csd;
1124
1125error:
1126 free(csd);
1127 csd = NULL;
1128 return csd;
1129}
1130
1131void close_csd_client(struct csd_data *csd)
1132{
1133 if (csd != NULL) {
1134 csd->deinit();
1135 dlclose(csd->csd_client);
1136 free(csd);
1137 csd = NULL;
1138 }
1139}
1140
1141static void platform_csd_init(struct platform_data *my_data)
1142{
1143#ifdef PLATFORM_MSM8084
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001144 int32_t modems, (*count_modems)(void);
1145 const char *name = "libdetectmodem.so";
1146 const char *func = "count_modems";
1147 const char *error;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001148
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001149 my_data->csd = NULL;
1150
1151 void *lib = dlopen(name, RTLD_NOW);
1152 error = dlerror();
1153 if (!lib) {
1154 ALOGE("%s: could not find %s: %s", __func__, name, error);
1155 return;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001156 }
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001157
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001158 count_modems = NULL;
1159 *(void **)(&count_modems) = dlsym(lib, func);
1160 error = dlerror();
1161 if (!count_modems) {
1162 ALOGE("%s: could not find symbol %s in %s: %s",
1163 __func__, func, name, error);
1164 goto done;
1165 }
1166
1167 modems = count_modems();
1168 if (modems < 0) {
1169 ALOGE("%s: count_modems failed\n", __func__);
1170 goto done;
1171 }
1172
Eric Laurent2bafff12016-03-17 12:17:23 -07001173 ALOGD("%s: num_modems %d\n", __func__, modems);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001174 if (modems > 0)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001175 my_data->csd = open_csd_client(false /*is_i2s_ext_modem*/);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001176
1177done:
1178 dlclose(lib);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001179#else
1180 my_data->csd = NULL;
1181#endif
1182}
1183
Eric Laurentc6333382015-09-14 12:43:44 -07001184static void set_platform_defaults(struct platform_data * my_data)
Haynes Mathew George98c95622014-06-20 19:14:25 -07001185{
1186 int32_t dev;
1187 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001188 backend_tag_table[dev] = NULL;
1189 hw_interface_table[dev] = NULL;
keunhui.park2f7306a2015-07-16 16:48:06 +09001190 operator_specific_device_table[dev] = NULL;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001191 }
1192
David Linee3fe402017-03-13 10:00:42 -07001193 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1194 backend_bit_width_table[dev] = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
1195 }
1196
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001197 // To overwrite these go to the audio_platform_info.xml file.
1198 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("bt-sco");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07001199 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("bt-sco");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001200 backend_tag_table[SND_DEVICE_OUT_BT_SCO] = strdup("bt-sco");
1201 backend_tag_table[SND_DEVICE_OUT_HDMI] = strdup("hdmi");
1202 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("speaker-and-hdmi");
1203 backend_tag_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("bt-sco-wb");
1204 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("bt-sco-wb");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07001205 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("bt-sco-wb");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001206 backend_tag_table[SND_DEVICE_OUT_VOICE_TX] = strdup("afe-proxy");
1207 backend_tag_table[SND_DEVICE_IN_VOICE_RX] = strdup("afe-proxy");
Haynes Mathew George98c95622014-06-20 19:14:25 -07001208
David Linee3fe402017-03-13 10:00:42 -07001209 backend_tag_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("usb-headset");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001210 backend_tag_table[SND_DEVICE_OUT_VOICE_USB_HEADSET] = strdup("usb-headset");
David Linee3fe402017-03-13 10:00:42 -07001211 backend_tag_table[SND_DEVICE_OUT_USB_HEADPHONES] = strdup("usb-headphones");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001212 backend_tag_table[SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = strdup("usb-headphones");
David Linee3fe402017-03-13 10:00:42 -07001213 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] =
1214 strdup("speaker-and-usb-headphones");
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07001215 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] =
1216 strdup("speaker-safe-and-usb-headphones");
juyuchen5351ea62018-05-16 10:54:37 +08001217 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO] =
1218 strdup("speaker-safe-and-bt-sco"),
1219 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB] =
1220 strdup("speaker-safe-and-bt-sco-wb"),
David Linee3fe402017-03-13 10:00:42 -07001221 backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("usb-headset-mic");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001222 backend_tag_table[SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1223 backend_tag_table[SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1224 backend_tag_table[SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1225 backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = strdup("usb-headset-mic");
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001226 backend_tag_table[SND_DEVICE_OUT_BT_A2DP] = strdup("bt-a2dp");
1227 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] = strdup("speaker-and-bt-a2dp");
Aniket Kumar Lata9723a962018-05-16 17:41:55 -07001228 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP] = strdup("speaker-safe-and-bt-a2dp");
jasmine cha270b7762018-03-30 15:41:33 +08001229 backend_tag_table[SND_DEVICE_OUT_USB_HEADSET_SPEC] = strdup("usb-headset");
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001230
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001231 hw_interface_table[SND_DEVICE_OUT_HANDSET] = strdup("SLIMBUS_0_RX");
1232 hw_interface_table[SND_DEVICE_OUT_SPEAKER] = strdup("SLIMBUS_0_RX");
1233 hw_interface_table[SND_DEVICE_OUT_SPEAKER_REVERSE] = strdup("SLIMBUS_0_RX");
1234 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE] = strdup("SLIMBUS_0_RX");
1235 hw_interface_table[SND_DEVICE_OUT_HEADPHONES] = strdup("SLIMBUS_0_RX");
1236 hw_interface_table[SND_DEVICE_OUT_LINE] = strdup("SLIMBUS_0_RX");
1237 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001238 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001239 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001240 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001241 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET] = strdup("SLIMBUS_0_RX");
1242 hw_interface_table[SND_DEVICE_OUT_VOICE_HAC_HANDSET] = strdup("SLIMBUS_0_RX");
1243 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER] = strdup("SLIMBUS_0_RX");
1244 hw_interface_table[SND_DEVICE_OUT_VOICE_HEADPHONES] = strdup("SLIMBUS_0_RX");
juyuchen66c4ecf2018-08-06 15:39:34 +08001245 hw_interface_table[SND_DEVICE_OUT_VOICE_MUSIC_TX] = strdup("VOICE_PLAYBACK_TX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001246 hw_interface_table[SND_DEVICE_OUT_VOICE_LINE] = strdup("SLIMBUS_0_RX");
1247 hw_interface_table[SND_DEVICE_OUT_HDMI] = strdup("HDMI_RX");
1248 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("SLIMBUS_0_RX-and-HDMI_RX");
1249 hw_interface_table[SND_DEVICE_OUT_BT_SCO] = strdup("SEC_AUX_PCM_RX");
1250 hw_interface_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("SEC_AUX_PCM_RX");
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001251 hw_interface_table[SND_DEVICE_OUT_BT_A2DP] = strdup("SLIMBUS_7_RX");
1252 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] =
1253 strdup("SLIMBUS_0_RX-and-SLIMBUS_7_RX");
Aniket Kumar Lata9723a962018-05-16 17:41:55 -07001254 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP] =
1255 strdup("SLIMBUS_0_RX-and-SLIMBUS_7_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001256 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = strdup("SLIMBUS_0_RX");
1257 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = strdup("SLIMBUS_0_RX");
1258 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = strdup("SLIMBUS_0_RX");
1259 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = strdup("SLIMBUS_0_RX");
David Linee3fe402017-03-13 10:00:42 -07001260 hw_interface_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("USB_AUDIO_RX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001261 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = strdup("USB_AUDIO_RX");
1262 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = strdup("USB_AUDIO_RX");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001263 hw_interface_table[SND_DEVICE_OUT_VOICE_USB_HEADSET] = strdup("USB_AUDIO_RX");
David Linee3fe402017-03-13 10:00:42 -07001264 hw_interface_table[SND_DEVICE_OUT_USB_HEADPHONES] = strdup("USB_AUDIO_RX");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001265 hw_interface_table[SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = strdup("USB_AUDIO_RX");
jasmine cha270b7762018-03-30 15:41:33 +08001266 hw_interface_table[SND_DEVICE_OUT_USB_HEADSET_SPEC] = strdup("USB_AUDIO_RX");
David Linee3fe402017-03-13 10:00:42 -07001267 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 -07001268 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 -07001269 hw_interface_table[SND_DEVICE_OUT_VOICE_TX] = strdup("AFE_PCM_RX");
1270 hw_interface_table[SND_DEVICE_OUT_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
1271 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
jasmine cha52284622018-03-23 17:21:35 +08001272 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = strdup("SLIMBUS_0_RX");
1273 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_BT_SCO] = strdup("SLIMBUS_0_RX-and-SEC_AUX_PCM_RX");
1274 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 +08001275 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO] = strdup("QUAT_TDM_RX_0-and-SLIMBUS_7_RX"),
1276 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 -07001277 hw_interface_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1278 hw_interface_table[SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1279 hw_interface_table[SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = strdup("USB_AUDIO_TX");
1280 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1281 hw_interface_table[SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1282 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = strdup("USB_AUDIO_TX");
1283 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = strdup("USB_AUDIO_TX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001284 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001285 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_AEC] = strdup("SLIMBUS_0_TX");
1286 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_NS] = strdup("SLIMBUS_0_TX");
1287 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1288 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC] = strdup("SLIMBUS_0_TX");
1289 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_AEC] = strdup("SLIMBUS_0_TX");
1290 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_NS] = strdup("SLIMBUS_0_TX");
1291 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1292 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001293 hw_interface_table[SND_DEVICE_IN_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001294 hw_interface_table[SND_DEVICE_IN_HEADSET_MIC_AEC] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001295 hw_interface_table[SND_DEVICE_IN_CAMCORDER_MIC] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001296 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC] = strdup("SLIMBUS_0_TX");
1297 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC_NS] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001298 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC_AEC] = strdup("SLIMBUS_0_TX");
1299 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001300 hw_interface_table[SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
1301 hw_interface_table[SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = strdup("SLIMBUS_0_TX");
David Lin93725722017-10-13 14:58:17 -07001302 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_MIC] = strdup("SLIMBUS_0_TX");
1303 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1304 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = strdup("SLIMBUS_0_TX");
1305 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = strdup("SLIMBUS_0_TX");
1306 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001307 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC] = strdup("SLIMBUS_0_TX");
1308 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_AEC] = strdup("SLIMBUS_0_TX");
1309 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_NS] = strdup("SLIMBUS_0_TX");
1310 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1311 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC] = strdup("SLIMBUS_0_TX");
1312 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_AEC] = strdup("SLIMBUS_0_TX");
1313 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_NS] = strdup("SLIMBUS_0_TX");
1314 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001315 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
1316 hw_interface_table[SND_DEVICE_IN_VOICE_DMIC] = strdup("SLIMBUS_0_TX");
1317 hw_interface_table[SND_DEVICE_IN_VOICE_DMIC_TMUS] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001318 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001319 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = strdup("SLIMBUS_0_TX");
1320 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001321 hw_interface_table[SND_DEVICE_IN_VOICE_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001322 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1323 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = strdup("SLIMBUS_0_TX");
1324 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1325 hw_interface_table[SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1326 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("SEC_AUX_PCM_TX");
1327 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("SEC_AUX_PCM_TX");
1328 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("SEC_AUX_PCM_TX");
1329 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("SEC_AUX_PCM_TX");
1330 hw_interface_table[SND_DEVICE_IN_VOICE_RX] = strdup("AFE_PCM_TX");
1331 hw_interface_table[SND_DEVICE_IN_THREE_MIC] = strdup("SLIMBUS_0_TX");
1332 hw_interface_table[SND_DEVICE_IN_QUAD_MIC] = strdup("SLIMBUS_0_TX");
1333 hw_interface_table[SND_DEVICE_IN_HANDSET_TMIC] = strdup("SLIMBUS_0_TX");
1334 hw_interface_table[SND_DEVICE_IN_HANDSET_QMIC] = strdup("SLIMBUS_0_TX");
1335 hw_interface_table[SND_DEVICE_IN_HANDSET_TMIC_AEC] = strdup("SLIMBUS_0_TX");
1336 hw_interface_table[SND_DEVICE_IN_HANDSET_QMIC_AEC] = strdup("SLIMBUS_0_TX");
Eric Laurentc6333382015-09-14 12:43:44 -07001337 my_data->max_mic_count = PLATFORM_DEFAULT_MIC_COUNT;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001338}
1339
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001340void get_cvd_version(char *cvd_version, struct audio_device *adev)
1341{
1342 struct mixer_ctl *ctl;
1343 int count;
1344 int ret = 0;
1345
1346 ctl = mixer_get_ctl_by_name(adev->mixer, CVD_VERSION_MIXER_CTL);
1347 if (!ctl) {
1348 ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__, CVD_VERSION_MIXER_CTL);
1349 goto done;
1350 }
1351 mixer_ctl_update(ctl);
1352
1353 count = mixer_ctl_get_num_values(ctl);
1354 if (count > MAX_CVD_VERSION_STRING_SIZE)
1355 count = MAX_CVD_VERSION_STRING_SIZE - 1;
1356
1357 ret = mixer_ctl_get_array(ctl, cvd_version, count);
1358 if (ret != 0) {
1359 ALOGE("%s: ERROR! mixer_ctl_get_array() failed to get CVD Version", __func__);
1360 goto done;
1361 }
1362
1363done:
1364 return;
1365}
1366
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001367static int platform_acdb_init(void *platform)
1368{
1369 struct platform_data *my_data = (struct platform_data *)platform;
1370 struct audio_device *adev = my_data->adev;
1371
1372 if (!my_data->acdb_init) {
1373 ALOGE("%s: no acdb_init fn provided", __func__);
1374 return -1;
1375 }
1376
1377 if (my_data->acdb_initialized) {
1378 ALOGW("acdb is already initialized");
1379 return 0;
1380 }
1381
Thierry Strudel07f96d12018-09-20 13:31:34 -07001382#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845) || (PLATFORM_SDM710) || (PLATFORM_SM8150)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001383 char *cvd_version = calloc(1, MAX_CVD_VERSION_STRING_SIZE);
1384 if (!cvd_version)
1385 ALOGE("failed to allocate cvd_version");
1386 else {
1387 get_cvd_version(cvd_version, adev);
1388 my_data->acdb_init((char *)my_data->snd_card_name, cvd_version, 0);
1389 free(cvd_version);
1390 }
1391#elif defined (PLATFORM_MSM8084)
1392 my_data->acdb_init((char *)my_data->snd_card_name);
1393#else
1394 my_data->acdb_init();
1395#endif
1396 my_data->acdb_initialized = true;
1397 return 0;
1398}
1399
David Linee3fe402017-03-13 10:00:42 -07001400static void
1401platform_backend_config_init(struct platform_data *pdata)
1402{
1403 int i;
1404
1405 /* initialize backend config */
1406 for (i = 0; i < MAX_CODEC_BACKENDS; i++) {
1407 pdata->current_backend_cfg[i].sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
1408 pdata->current_backend_cfg[i].bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
1409 pdata->current_backend_cfg[i].channels = CODEC_BACKEND_DEFAULT_CHANNELS;
1410
1411 if (i > MAX_RX_CODEC_BACKENDS)
1412 pdata->current_backend_cfg[i].channels = CODEC_BACKEND_DEFAULT_TX_CHANNELS;
1413
1414 pdata->current_backend_cfg[i].bitwidth_mixer_ctl = NULL;
1415 pdata->current_backend_cfg[i].samplerate_mixer_ctl = NULL;
1416 pdata->current_backend_cfg[i].channels_mixer_ctl = NULL;
1417 }
1418
1419 pdata->current_backend_cfg[DEFAULT_CODEC_BACKEND].bitwidth_mixer_ctl =
1420 strdup("SLIM_0_RX Format");
1421 pdata->current_backend_cfg[DEFAULT_CODEC_BACKEND].samplerate_mixer_ctl =
1422 strdup("SLIM_0_RX SampleRate");
1423
1424 pdata->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].bitwidth_mixer_ctl =
1425 strdup("SLIM_0_TX Format");
1426 pdata->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].samplerate_mixer_ctl =
1427 strdup("SLIM_0_TX SampleRate");
1428
1429 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].bitwidth_mixer_ctl =
1430 strdup("USB_AUDIO_TX Format");
1431 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].samplerate_mixer_ctl =
1432 strdup("USB_AUDIO_TX SampleRate");
1433 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].channels_mixer_ctl =
1434 strdup("USB_AUDIO_TX Channels");
1435
1436 pdata->current_backend_cfg[HEADPHONE_BACKEND].bitwidth_mixer_ctl =
1437 strdup("SLIM_6_RX Format");
1438 pdata->current_backend_cfg[HEADPHONE_BACKEND].samplerate_mixer_ctl =
1439 strdup("SLIM_6_RX SampleRate");
1440
1441 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].bitwidth_mixer_ctl =
1442 strdup("USB_AUDIO_RX Format");
1443 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].samplerate_mixer_ctl =
1444 strdup("USB_AUDIO_RX SampleRate");
1445
1446 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].channels = 1;
1447 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].channels_mixer_ctl =
1448 strdup("USB_AUDIO_RX Channels");
1449}
1450
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001451static int
1452platform_backend_app_type_cfg_init(struct platform_data *pdata,
1453 struct mixer *mixer)
1454{
1455 size_t app_type_cfg[128] = {0};
1456 int length, num_app_types = 0;
1457 struct mixer_ctl *ctl = NULL;
1458
1459 const char *mixer_ctl_name = "App Type Config";
1460 ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name);
1461 if (!ctl) {
1462 ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name);
1463 return -1;
1464 }
1465
1466 length = 1; // reserve index 0 for number of app types
1467
1468 struct listnode *node;
1469 struct app_type_entry *entry;
1470 list_for_each(node, &app_type_entry_list) {
1471 entry = node_to_item(node, struct app_type_entry, node);
1472 app_type_cfg[length++] = entry->app_type;
1473 app_type_cfg[length++] = entry->max_rate;
1474 app_type_cfg[length++] = entry->bit_width;
1475 ALOGI("%s add entry %d %d", __func__, entry->app_type, entry->bit_width);
1476 num_app_types += 1;
1477 }
1478
1479 // default for capture
1480 int t;
1481 platform_get_default_app_type_v2(pdata,
1482 PCM_CAPTURE,
1483 &t);
1484 app_type_cfg[length++] = t;
1485 app_type_cfg[length++] = 48000;
1486 app_type_cfg[length++] = 16;
1487 num_app_types += 1;
1488
1489 if (num_app_types) {
1490 app_type_cfg[0] = num_app_types;
1491 if (mixer_ctl_set_array(ctl, app_type_cfg, length) < 0) {
1492 ALOGE("Failed to set app type cfg");
1493 }
1494 }
1495 return 0;
1496}
1497
Xu Han1638fd12018-04-20 12:42:23 -07001498static void configure_flicker_sensor_input(struct mixer *mixer)
1499{
1500 struct mixer_ctl *ctl;
1501 const char* ctl1 = "AIF3_CAP Mixer SLIM TX2";
1502 int setting1 = 1;
1503 const char* ctl2 = "CDC_IF TX2 MUX";
1504 const char* setting2 = "DEC2";
1505 const char* ctl3 = "SLIM_1_TX Channels";
1506 const char* setting3 = "One";
1507 const char* ctl4 = "ADC MUX2";
1508 const char* setting4 = "AMIC";
1509 const char* ctl5 = "AMIC MUX2";
1510 const char* setting5 = "ADC1";
1511 const char* ctl6 = "DEC2 Volume";
1512 int setting6 = 84;
Xu Han07e07402018-05-15 14:19:25 -07001513 const char* ctl7 = "MultiMedia9 Mixer SLIM_1_TX";
Xu Han1638fd12018-04-20 12:42:23 -07001514 int setting7 = 1;
1515 const char* ctl8 = "SLIM_1_TX SampleRate";
1516 const char* setting8 = "KHZ_8";
1517
1518 ctl = mixer_get_ctl_by_name(mixer, ctl1);
1519 mixer_ctl_set_value(ctl, 0, setting1);
1520 ctl = mixer_get_ctl_by_name(mixer, ctl2);
1521 mixer_ctl_set_enum_by_string(ctl, setting2);
1522 ctl = mixer_get_ctl_by_name(mixer, ctl3);
1523 mixer_ctl_set_enum_by_string(ctl, setting3);
1524 ctl = mixer_get_ctl_by_name(mixer, ctl4);
1525 mixer_ctl_set_enum_by_string(ctl, setting4);
1526 ctl = mixer_get_ctl_by_name(mixer, ctl5);
1527 mixer_ctl_set_enum_by_string(ctl, setting5);
1528 ctl = mixer_get_ctl_by_name(mixer, ctl6);
1529 mixer_ctl_set_value(ctl, 0, setting6);
1530 ctl = mixer_get_ctl_by_name(mixer, ctl7);
1531 mixer_ctl_set_value(ctl, 0, setting7);
1532 ctl = mixer_get_ctl_by_name(mixer, ctl8);
1533 mixer_ctl_set_enum_by_string(ctl, setting8);
1534}
1535
Eric Laurentb23d5282013-05-14 15:27:20 -07001536void *platform_init(struct audio_device *adev)
1537{
1538 char value[PROPERTY_VALUE_MAX];
vivek mehta60ea4152016-02-18 17:10:26 -08001539 struct platform_data *my_data = NULL;
1540 int retry_num = 0, snd_card_num = 0, key = 0, ret = 0;
1541 bool dual_mic_config = false, use_default_mixer_path = true;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001542 const char *snd_card_name;
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001543 char *cvd_version = NULL;
vivek mehta60ea4152016-02-18 17:10:26 -08001544 char *snd_internal_name = NULL;
1545 char *tmp = NULL;
1546 char mixer_xml_file[MIXER_PATH_MAX_LENGTH]= {0};
vivek mehtade4849c2016-03-03 17:23:38 -08001547 char platform_info_file[MIXER_PATH_MAX_LENGTH]= {0};
1548 struct snd_card_split *snd_split_handle = NULL;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001549 my_data = calloc(1, sizeof(struct platform_data));
1550
1551 my_data->adev = adev;
1552
keunhui.park2f7306a2015-07-16 16:48:06 +09001553 list_init(&operator_info_list);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001554 list_init(&app_type_entry_list);
keunhui.park2f7306a2015-07-16 16:48:06 +09001555
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001556 set_platform_defaults(my_data);
1557
vivek mehta0fb11312017-05-15 19:35:32 -07001558 // audio_extn_utils_get_snd_card_num does
1559 // - open mixer and get snd card name
1560 // - parse platform info xml file and check for valid snd card name
1561 // - on failure loop through all the active snd card
sangwoo1b9f4b32013-06-21 18:22:55 -07001562
vivek mehta0fb11312017-05-15 19:35:32 -07001563 snd_card_num = audio_extn_utils_get_snd_card_num();
1564 if (-1 == snd_card_num) {
1565 ALOGE("%s: invalid sound card number (-1), bailing out ", __func__);
1566 goto init_failed;
sangwoo1b9f4b32013-06-21 18:22:55 -07001567 }
1568
vivek mehta0fb11312017-05-15 19:35:32 -07001569 adev->mixer = mixer_open(snd_card_num);
1570 snd_card_name = mixer_get_name(adev->mixer);
1571 my_data->hw_info = hw_info_init(snd_card_name);
1572
1573 audio_extn_set_snd_card_split(snd_card_name);
1574 snd_split_handle = audio_extn_get_snd_card_split();
1575
1576 /* Get the codec internal name from the sound card and/or form factor
1577 * name and form the mixer paths and platfor info file name dynamically.
1578 * This is generic way of picking any codec and forma factor name based
1579 * mixer and platform info files in future with no code change.
1580
1581 * current code extends and looks for any of the exteneded mixer path and
1582 * platform info file present based on codec and form factor.
1583
1584 * order of picking appropriate file is
1585 * <i> mixer_paths_<codec_name>_<form_factor>.xml, if file not present
1586 * <ii> mixer_paths_<codec_name>.xml, if file not present
1587 * <iii> mixer_paths.xml
1588
1589 * same order is followed for audio_platform_info.xml as well
1590 */
1591
1592 // need to carryforward old file name
1593 if (!strncmp(snd_card_name, TOMTOM_8226_SND_CARD_NAME,
1594 min(strlen(TOMTOM_8226_SND_CARD_NAME), strlen(snd_card_name)))) {
1595 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1596 MIXER_XML_BASE_STRING, TOMTOM_MIXER_FILE_SUFFIX );
1597 } else {
1598
1599 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s_%s.xml",
1600 MIXER_XML_BASE_STRING, snd_split_handle->snd_card,
1601 snd_split_handle->form_factor);
1602 if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) {
1603 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1604 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1605 MIXER_XML_BASE_STRING, snd_split_handle->snd_card);
1606
1607 if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) {
1608 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1609 strlcpy(mixer_xml_file, MIXER_XML_DEFAULT_PATH, MIXER_PATH_MAX_LENGTH);
1610 audio_extn_utils_resolve_config_file(mixer_xml_file);
1611 }
1612 }
1613 }
1614
1615 audio_extn_utils_get_platform_info(snd_card_name, platform_info_file);
1616
jiabin8962a4d2018-03-19 18:21:24 -07001617 my_data->declared_mic_count = 0;
vivek mehta0fb11312017-05-15 19:35:32 -07001618 /* Initialize platform specific ids and/or backends*/
1619 platform_info_init(platform_info_file, my_data);
1620
1621 ALOGD("%s: Loading mixer file: %s", __func__, mixer_xml_file);
1622 adev->audio_route = audio_route_init(snd_card_num, mixer_xml_file);
1623
1624 if (!adev->audio_route) {
1625 ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
1626 mixer_close(adev->mixer);
1627 adev->mixer = NULL;
1628 hw_info_deinit(my_data->hw_info);
1629 my_data->hw_info = NULL;
1630 goto init_failed;
1631 }
1632 adev->snd_card = snd_card_num;
1633 ALOGD("%s: Opened sound card:%d", __func__, snd_card_num);
1634
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09001635 //set max volume step for voice call
1636 property_get("ro.config.vc_call_vol_steps", value, TOSTRING(MAX_VOL_INDEX));
1637 my_data->max_vol_index = atoi(value);
1638
vivek mehta65ad12d2015-08-13 18:32:48 -07001639 property_get("persist.audio.dualmic.config",value,"");
1640 if (!strcmp("endfire", value)) {
1641 dual_mic_config = true;
1642 }
1643
John Muir9e59a962018-01-10 13:30:00 -08001644 my_data->source_mic_type = 0;
Prashant Malanic92c5962015-08-11 15:10:18 -07001645
Eric Laurentb23d5282013-05-14 15:27:20 -07001646 my_data->fluence_in_spkr_mode = false;
1647 my_data->fluence_in_voice_call = false;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001648 my_data->fluence_in_voice_comm = false;
Eric Laurentb23d5282013-05-14 15:27:20 -07001649 my_data->fluence_in_voice_rec = false;
1650
vivek mehta65ad12d2015-08-13 18:32:48 -07001651 property_get("ro.qc.sdk.audio.fluencetype", value, "none");
Prashant Malanic92c5962015-08-11 15:10:18 -07001652 if (!strcmp("fluencepro", value)) {
1653 my_data->fluence_type = FLUENCE_PRO_ENABLE;
vivek mehta65ad12d2015-08-13 18:32:48 -07001654 } else if (!strcmp("fluence", value) || (dual_mic_config)) {
Prashant Malanic92c5962015-08-11 15:10:18 -07001655 my_data->fluence_type = FLUENCE_ENABLE;
1656 } else if (!strcmp("none", value)) {
1657 my_data->fluence_type = FLUENCE_DISABLE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001658 }
1659
Prashant Malanic92c5962015-08-11 15:10:18 -07001660 if (my_data->fluence_type != FLUENCE_DISABLE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001661 property_get("persist.audio.fluence.voicecall",value,"");
1662 if (!strcmp("true", value)) {
1663 my_data->fluence_in_voice_call = true;
1664 }
1665
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001666 property_get("persist.audio.fluence.voicecomm",value,"");
1667 if (!strcmp("true", value)) {
1668 my_data->fluence_in_voice_comm = true;
1669 }
1670
Eric Laurentb23d5282013-05-14 15:27:20 -07001671 property_get("persist.audio.fluence.voicerec",value,"");
1672 if (!strcmp("true", value)) {
1673 my_data->fluence_in_voice_rec = true;
1674 }
1675
1676 property_get("persist.audio.fluence.speaker",value,"");
1677 if (!strcmp("true", value)) {
1678 my_data->fluence_in_spkr_mode = true;
1679 }
1680 }
1681
Prashant Malanic92c5962015-08-11 15:10:18 -07001682 // support max to mono, example if max count is 3, usecase supports Three, dual and mono mic
1683 switch (my_data->max_mic_count) {
1684 case 4:
1685 my_data->source_mic_type |= SOURCE_QUAD_MIC;
1686 case 3:
1687 my_data->source_mic_type |= SOURCE_THREE_MIC;
1688 case 2:
1689 my_data->source_mic_type |= SOURCE_DUAL_MIC;
1690 case 1:
1691 my_data->source_mic_type |= SOURCE_MONO_MIC;
1692 break;
1693 default:
1694 ALOGE("%s: max_mic_count (%d), is not supported, setting to default",
1695 __func__, my_data->max_mic_count);
1696 my_data->source_mic_type = SOURCE_MONO_MIC|SOURCE_DUAL_MIC;
1697 break;
1698 }
1699
1700 ALOGV("%s: Fluence_Type(%d) max_mic_count(%d) mic_type(0x%x) fluence_in_voice_call(%d)"
1701 " fluence_in_voice_comm(%d) fluence_in_voice_rec(%d) fluence_in_spkr_mode(%d) ",
1702 __func__, my_data->fluence_type, my_data->max_mic_count, my_data->source_mic_type,
1703 my_data->fluence_in_voice_call, my_data->fluence_in_voice_comm,
1704 my_data->fluence_in_voice_rec, my_data->fluence_in_spkr_mode);
1705
Eric Laurentb23d5282013-05-14 15:27:20 -07001706 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
1707 if (my_data->acdb_handle == NULL) {
1708 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
1709 } else {
1710 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
1711 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
1712 "acdb_loader_deallocate_ACDB");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001713 if (!my_data->acdb_deallocate)
1714 ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s",
1715 __func__, LIB_ACDB_LOADER);
1716
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001717 my_data->acdb_send_audio_cal_v3 = (acdb_send_audio_cal_v3_t)dlsym(my_data->acdb_handle,
1718 "acdb_loader_send_audio_cal_v3");
1719 if (!my_data->acdb_send_audio_cal_v3)
1720 ALOGE("%s: Could not find the symbol acdb_send_audio_cal_v3 from %s",
1721 __func__, LIB_ACDB_LOADER);
1722
Eric Laurentb23d5282013-05-14 15:27:20 -07001723 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
1724 "acdb_loader_send_audio_cal");
1725 if (!my_data->acdb_send_audio_cal)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001726 ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s",
Eric Laurentb23d5282013-05-14 15:27:20 -07001727 __func__, LIB_ACDB_LOADER);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001728
Eric Laurentb23d5282013-05-14 15:27:20 -07001729 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
1730 "acdb_loader_send_voice_cal");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001731 if (!my_data->acdb_send_voice_cal)
1732 ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s",
1733 __func__, LIB_ACDB_LOADER);
1734
1735 my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle,
1736 "acdb_loader_reload_vocvoltable");
1737 if (!my_data->acdb_reload_vocvoltable)
1738 ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s",
1739 __func__, LIB_ACDB_LOADER);
vivek mehta1a9b7c02015-06-25 11:49:38 -07001740
1741 my_data->acdb_send_gain_dep_cal = (acdb_send_gain_dep_cal_t)dlsym(my_data->acdb_handle,
1742 "acdb_loader_send_gain_dep_cal");
1743 if (!my_data->acdb_send_gain_dep_cal)
1744 ALOGV("%s: Could not find the symbol acdb_loader_send_gain_dep_cal from %s",
1745 __func__, LIB_ACDB_LOADER);
1746
Xu Han1638fd12018-04-20 12:42:23 -07001747#if defined (FLICKER_SENSOR_INPUT)
1748 configure_flicker_sensor_input(adev->mixer);
1749#endif
1750
Thierry Strudel07f96d12018-09-20 13:31:34 -07001751#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845) || (PLATFORM_SDM710) || (PLATFORM_SM8150)
vivek mehta0fb11312017-05-15 19:35:32 -07001752 acdb_init_v2_cvd_t acdb_init_local;
1753 acdb_init_local = (acdb_init_v2_cvd_t)dlsym(my_data->acdb_handle,
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001754 "acdb_loader_init_v2");
vivek mehta0fb11312017-05-15 19:35:32 -07001755 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001756 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1757 dlerror());
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001758
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001759#elif defined (PLATFORM_MSM8084)
vivek mehta0fb11312017-05-15 19:35:32 -07001760 acdb_init_v2_t acdb_init_local;
1761 acdb_init_local = (acdb_init_v2_t)dlsym(my_data->acdb_handle,
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001762 "acdb_loader_init_v2");
vivek mehta0fb11312017-05-15 19:35:32 -07001763 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001764 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1765 dlerror());
1766
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001767#else
vivek mehta0fb11312017-05-15 19:35:32 -07001768 acdb_init_t acdb_init_local;
1769 acdb_init_local = (acdb_init_t)dlsym(my_data->acdb_handle,
Eric Laurentb23d5282013-05-14 15:27:20 -07001770 "acdb_loader_init_ACDB");
vivek mehta0fb11312017-05-15 19:35:32 -07001771 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001772 ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__,
1773 dlerror());
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001774#endif
vivek mehta0fb11312017-05-15 19:35:32 -07001775 my_data->acdb_init = acdb_init_local;
Eric Laurentb23d5282013-05-14 15:27:20 -07001776
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001777 my_data->acdb_send_custom_top = (acdb_send_custom_top_t)
1778 dlsym(my_data->acdb_handle,
1779 "acdb_loader_send_common_custom_topology");
1780
1781 if (!my_data->acdb_send_custom_top)
1782 ALOGE("%s: Could not find the symbol acdb_get_default_app_type from %s",
1783 __func__, LIB_ACDB_LOADER);
1784
jasmine chac89321b2018-04-10 21:37:01 +08001785 my_data->acdb_set_audio_cal = (acdb_set_audio_cal_t)dlsym(my_data->acdb_handle,
1786 "acdb_loader_set_audio_cal_v2");
1787 if (!my_data->acdb_set_audio_cal)
1788 ALOGE("%s: Could not find the symbol acdb_set_audio_cal_v2 from %s",
1789 __func__, LIB_ACDB_LOADER);
1790
vivek mehta0fb11312017-05-15 19:35:32 -07001791 int result = acdb_init(adev->snd_card);
1792 if (!result) {
1793 my_data->acdb_initialized = true;
1794 ALOGD("ACDB initialized");
1795 } else {
1796 my_data->acdb_initialized = false;
1797 ALOGD("ACDB initialization failed");
1798 }
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001799 }
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001800
David Linee3fe402017-03-13 10:00:42 -07001801 /* init usb */
1802 audio_extn_usb_init(adev);
1803
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001804 /* init a2dp */
1805 audio_extn_a2dp_init(adev);
1806
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001807 audio_extn_spkr_prot_init(adev);
Haynes Mathew George98c95622014-06-20 19:14:25 -07001808
Ravi Kumar Alamanda76315572015-04-23 13:13:56 -07001809 audio_extn_hwdep_cal_send(adev->snd_card, my_data->acdb_handle);
1810
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001811 /* load csd client */
1812 platform_csd_init(my_data);
1813
David Linee3fe402017-03-13 10:00:42 -07001814 platform_backend_config_init(my_data);
1815
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001816 init_be_dai_name_table(adev);
1817
1818 if (platform_supports_app_type_cfg())
1819 platform_backend_app_type_cfg_init(my_data, adev->mixer);
1820
Eric Laurentb23d5282013-05-14 15:27:20 -07001821 return my_data;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001822
1823init_failed:
1824 if (my_data)
1825 free(my_data);
1826 return NULL;
Eric Laurentb23d5282013-05-14 15:27:20 -07001827}
1828
1829void platform_deinit(void *platform)
1830{
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001831 int32_t dev;
keunhui.park2f7306a2015-07-16 16:48:06 +09001832 struct operator_info *info_item;
1833 struct operator_specific_device *device_item;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001834 struct app_type_entry *ap;
keunhui.park2f7306a2015-07-16 16:48:06 +09001835 struct listnode *node;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001836
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001837 struct platform_data *my_data = (struct platform_data *)platform;
1838 close_csd_client(my_data->csd);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001839
David Lin41b4fe42018-07-08 16:14:24 -07001840 audio_extn_spkr_prot_deinit(my_data->adev);
1841
vivek mehtade4849c2016-03-03 17:23:38 -08001842 hw_info_deinit(my_data->hw_info);
1843
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001844 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1845 if (backend_tag_table[dev])
1846 free(backend_tag_table[dev]);
1847 if (hw_interface_table[dev])
1848 free(hw_interface_table[dev]);
keunhui.park2f7306a2015-07-16 16:48:06 +09001849 if (operator_specific_device_table[dev]) {
1850 while (!list_empty(operator_specific_device_table[dev])) {
1851 node = list_head(operator_specific_device_table[dev]);
1852 list_remove(node);
1853 device_item = node_to_item(node, struct operator_specific_device, list);
1854 free(device_item->operator);
1855 free(device_item->mixer_path);
1856 free(device_item);
1857 }
1858 free(operator_specific_device_table[dev]);
1859 }
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001860 }
1861
1862 if (my_data->snd_card_name)
1863 free(my_data->snd_card_name);
1864
keunhui.park2f7306a2015-07-16 16:48:06 +09001865 while (!list_empty(&operator_info_list)) {
1866 node = list_head(&operator_info_list);
1867 list_remove(node);
1868 info_item = node_to_item(node, struct operator_info, list);
1869 free(info_item->name);
1870 free(info_item->mccmnc);
1871 free(info_item);
1872 }
1873
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001874 while (!list_empty(&app_type_entry_list)) {
1875 node = list_head(&app_type_entry_list);
1876 list_remove(node);
1877 ap = node_to_item(node, struct app_type_entry, node);
vivek mehtaa68fea62017-06-08 19:04:02 -07001878 if (ap->mode) free(ap->mode);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001879 free(ap);
1880 }
1881
Kevin Rocarde35d4af2017-05-02 16:55:28 -07001882 mixer_close(my_data->adev->mixer);
Eric Laurentb23d5282013-05-14 15:27:20 -07001883 free(platform);
David Linee3fe402017-03-13 10:00:42 -07001884
1885 /* deinit usb */
1886 audio_extn_usb_deinit();
Eric Laurentb23d5282013-05-14 15:27:20 -07001887}
1888
1889const char *platform_get_snd_device_name(snd_device_t snd_device)
1890{
keunhui.park2f7306a2015-07-16 16:48:06 +09001891 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1892 if (operator_specific_device_table[snd_device] != NULL) {
1893 return get_operator_specific_device_mixer_path(snd_device);
1894 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001895 return device_table[snd_device];
keunhui.park2f7306a2015-07-16 16:48:06 +09001896 } else
Ravi Kumar Alamanda64026462014-09-15 00:08:58 -07001897 return "none";
Eric Laurentb23d5282013-05-14 15:27:20 -07001898}
1899
vivek mehtade4849c2016-03-03 17:23:38 -08001900int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
1901 char *device_name)
1902{
1903 struct platform_data *my_data = (struct platform_data *)platform;
1904
David Benjamin1565f992016-09-21 12:10:34 -04001905 if (platform == NULL) {
vivek mehtade4849c2016-03-03 17:23:38 -08001906 ALOGW("%s: something wrong, use legacy get_snd_device name", __func__);
David Benjamin1565f992016-09-21 12:10:34 -04001907 strlcpy(device_name, platform_get_snd_device_name(snd_device),
1908 DEVICE_NAME_MAX_SIZE);
vivek mehtade4849c2016-03-03 17:23:38 -08001909 } else if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1910 if (operator_specific_device_table[snd_device] != NULL) {
1911 strlcpy(device_name, get_operator_specific_device_mixer_path(snd_device),
1912 DEVICE_NAME_MAX_SIZE);
1913 } else {
1914 strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE);
1915 }
1916 hw_info_append_hw_type(my_data->hw_info, snd_device, device_name);
1917 } else {
1918 strlcpy(device_name, "none", DEVICE_NAME_MAX_SIZE);
Aniket Kumar Lataa158e862018-05-11 17:28:40 -07001919 return -EINVAL;
vivek mehtade4849c2016-03-03 17:23:38 -08001920 }
1921
1922 return 0;
1923}
1924
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001925void platform_add_backend_name(void *platform, char *mixer_path,
1926 snd_device_t snd_device)
Eric Laurentb23d5282013-05-14 15:27:20 -07001927{
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001928 struct platform_data *my_data = (struct platform_data *)platform;
1929
Haynes Mathew George98c95622014-06-20 19:14:25 -07001930 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1931 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1932 return;
Ravi Kumar Alamanda1de6e5a2014-06-19 21:55:39 -05001933 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001934
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001935 const char * suffix = backend_tag_table[snd_device];
Haynes Mathew George98c95622014-06-20 19:14:25 -07001936
1937 if (suffix != NULL) {
1938 strcat(mixer_path, " ");
1939 strcat(mixer_path, suffix);
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001940 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001941}
1942
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001943bool platform_check_backends_match(snd_device_t snd_device1, snd_device_t snd_device2)
1944{
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001945 ALOGV("%s: snd_device1 = %s, snd_device2 = %s", __func__,
1946 platform_get_snd_device_name(snd_device1),
1947 platform_get_snd_device_name(snd_device2));
1948
1949 if ((snd_device1 < SND_DEVICE_MIN) || (snd_device1 >= SND_DEVICE_MAX)) {
1950 ALOGE("%s: Invalid snd_device = %s", __func__,
1951 platform_get_snd_device_name(snd_device1));
1952 return false;
1953 }
1954 if ((snd_device2 < SND_DEVICE_MIN) || (snd_device2 >= SND_DEVICE_MAX)) {
1955 ALOGE("%s: Invalid snd_device = %s", __func__,
1956 platform_get_snd_device_name(snd_device2));
1957 return false;
1958 }
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07001959
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001960 const char * be_itf1 = hw_interface_table[snd_device1];
1961 const char * be_itf2 = hw_interface_table[snd_device2];
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07001962 /*
1963 hw_interface_table has overrides for a snd_device.
1964 if there is no entry for a device, assume DEFAULT_RX_BACKEND
1965 */
1966 if (be_itf1 == NULL) {
1967 be_itf1 = DEFAULT_RX_BACKEND;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001968 }
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07001969 if (be_itf2 == NULL) {
1970 be_itf2 = DEFAULT_RX_BACKEND;
1971 }
1972 ALOGV("%s: be_itf1 = %s, be_itf2 = %s", __func__, be_itf1, be_itf2);
1973 /*
1974 this takes care of finding a device within a combo device pair as well
1975 */
1976 return strstr(be_itf1, be_itf2) != NULL || strstr(be_itf2, be_itf1) != NULL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001977}
1978
Eric Laurentb23d5282013-05-14 15:27:20 -07001979int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
1980{
1981 int device_id;
1982 if (device_type == PCM_PLAYBACK)
1983 device_id = pcm_device_table[usecase][0];
1984 else
1985 device_id = pcm_device_table[usecase][1];
1986 return device_id;
1987}
1988
Haynes Mathew George98c95622014-06-20 19:14:25 -07001989static int find_index(const struct name_to_index * table, int32_t len,
1990 const char * name)
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001991{
1992 int ret = 0;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001993 int32_t i;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001994
Haynes Mathew George98c95622014-06-20 19:14:25 -07001995 if (table == NULL) {
1996 ALOGE("%s: table is NULL", __func__);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001997 ret = -ENODEV;
1998 goto done;
1999 }
2000
Haynes Mathew George98c95622014-06-20 19:14:25 -07002001 if (name == NULL) {
2002 ALOGE("null key");
2003 ret = -ENODEV;
2004 goto done;
2005 }
2006
2007 for (i=0; i < len; i++) {
2008 if (!strcmp(table[i].name, name)) {
2009 ret = table[i].index;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002010 goto done;
2011 }
2012 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07002013 ALOGE("%s: Could not find index for name = %s",
2014 __func__, name);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002015 ret = -ENODEV;
2016done:
2017 return ret;
2018}
2019
Haynes Mathew George98c95622014-06-20 19:14:25 -07002020int platform_get_snd_device_index(char *device_name)
2021{
2022 return find_index(snd_device_name_index, SND_DEVICE_MAX, device_name);
2023}
2024
2025int platform_get_usecase_index(const char *usecase_name)
2026{
2027 return find_index(usecase_name_index, AUDIO_USECASE_MAX, usecase_name);
2028}
2029
keunhui.park2f7306a2015-07-16 16:48:06 +09002030void platform_add_operator_specific_device(snd_device_t snd_device,
2031 const char *operator,
2032 const char *mixer_path,
2033 unsigned int acdb_id)
2034{
2035 struct operator_specific_device *device;
2036
2037 if (operator_specific_device_table[snd_device] == NULL) {
2038 operator_specific_device_table[snd_device] =
2039 (struct listnode *)calloc(1, sizeof(struct listnode));
2040 list_init(operator_specific_device_table[snd_device]);
2041 }
2042
2043 device = (struct operator_specific_device *)calloc(1, sizeof(struct operator_specific_device));
2044
2045 device->operator = strdup(operator);
2046 device->mixer_path = strdup(mixer_path);
2047 device->acdb_id = acdb_id;
2048
2049 list_add_tail(operator_specific_device_table[snd_device], &device->list);
2050
Eric Laurent2bafff12016-03-17 12:17:23 -07002051 ALOGD("%s: device[%s] -> operator[%s] mixer_path[%s] acdb_id[%d]", __func__,
keunhui.park2f7306a2015-07-16 16:48:06 +09002052 platform_get_snd_device_name(snd_device), operator, mixer_path, acdb_id);
2053
2054}
2055
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002056int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
2057{
2058 int ret = 0;
2059
2060 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
2061 ALOGE("%s: Invalid snd_device = %d",
2062 __func__, snd_device);
2063 ret = -EINVAL;
2064 goto done;
2065 }
2066
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002067 ALOGV("%s: acdb_device_table[%s]: old = %d new = %d", __func__,
2068 platform_get_snd_device_name(snd_device), acdb_device_table[snd_device], acdb_id);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002069 acdb_device_table[snd_device] = acdb_id;
2070done:
2071 return ret;
2072}
2073
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07002074int platform_get_snd_device_acdb_id(snd_device_t snd_device)
2075{
2076 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
2077 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
2078 return -EINVAL;
2079 }
keunhui.park2f7306a2015-07-16 16:48:06 +09002080
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002081 /*
2082 * If speaker protection is enabled, function returns supported
2083 * sound device for speaker. Else same sound device is returned.
2084 */
2085 snd_device = audio_extn_get_spkr_prot_snd_device(snd_device);
2086
keunhui.park2f7306a2015-07-16 16:48:06 +09002087 if (operator_specific_device_table[snd_device] != NULL)
2088 return get_operator_specific_device_acdb_id(snd_device);
2089 else
2090 return acdb_device_table[snd_device];
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07002091}
2092
David Linee3fe402017-03-13 10:00:42 -07002093static int platform_get_backend_index(snd_device_t snd_device)
2094{
2095 int32_t port = DEFAULT_CODEC_BACKEND;
2096
2097 if (snd_device >= SND_DEVICE_OUT_BEGIN && snd_device < SND_DEVICE_OUT_END) {
2098 if (backend_tag_table[snd_device] != NULL) {
2099 if (strncmp(backend_tag_table[snd_device], "headphones",
2100 sizeof("headphones")) == 0)
2101 port = HEADPHONE_BACKEND;
2102 else if (strcmp(backend_tag_table[snd_device], "hdmi") == 0)
2103 port = HDMI_RX_BACKEND;
2104 else if ((strcmp(backend_tag_table[snd_device], "usb-headphones") == 0) ||
2105 (strcmp(backend_tag_table[snd_device], "usb-headset") == 0))
2106 port = USB_AUDIO_RX_BACKEND;
2107 }
2108 } else if (snd_device >= SND_DEVICE_IN_BEGIN && snd_device < SND_DEVICE_IN_END) {
2109 port = DEFAULT_CODEC_TX_BACKEND;
2110 if (backend_tag_table[snd_device] != NULL) {
2111 if (strcmp(backend_tag_table[snd_device], "usb-headset-mic") == 0)
2112 port = USB_AUDIO_TX_BACKEND;
2113 else if (strstr(backend_tag_table[snd_device], "bt-sco") != NULL)
2114 port = BT_SCO_TX_BACKEND;
2115 }
2116 } else {
2117 ALOGW("%s:napb: Invalid device - %d ", __func__, snd_device);
2118 }
2119
2120 ALOGV("%s:napb: backend port - %d device - %d ", __func__, port, snd_device);
2121
2122 return port;
2123}
2124
Eric Laurentb23d5282013-05-14 15:27:20 -07002125int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
2126{
2127 struct platform_data *my_data = (struct platform_data *)platform;
2128 int acdb_dev_id, acdb_dev_type;
2129
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002130 if (platform_supports_app_type_cfg()) // use v2 instead
2131 return -ENOSYS;
2132
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002133 acdb_dev_id = platform_get_snd_device_acdb_id(snd_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07002134 if (acdb_dev_id < 0) {
2135 ALOGE("%s: Could not find acdb id for device(%d)",
2136 __func__, snd_device);
2137 return -EINVAL;
2138 }
2139 if (my_data->acdb_send_audio_cal) {
Joe Onorato188b6222016-03-01 11:02:27 -08002140 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Eric Laurentb23d5282013-05-14 15:27:20 -07002141 __func__, snd_device, acdb_dev_id);
2142 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
2143 snd_device < SND_DEVICE_OUT_END)
2144 acdb_dev_type = ACDB_DEV_TYPE_OUT;
2145 else
2146 acdb_dev_type = ACDB_DEV_TYPE_IN;
2147 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
2148 }
2149 return 0;
2150}
2151
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002152int platform_send_audio_calibration_v2(void *platform, struct audio_usecase *usecase,
2153 int app_type, int sample_rate)
2154{
2155 struct platform_data *my_data = (struct platform_data *)platform;
2156 int acdb_dev_id, acdb_dev_type;
vivek mehta7e573672018-03-13 17:41:41 -07002157 int snd_device = usecase->out_snd_device;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002158 int new_snd_device[SND_DEVICE_OUT_END] = {0};
2159 int i, num_devices = 1;
2160
2161 if (!platform_supports_app_type_cfg()) // use v1 instead
2162 return -ENOSYS;
2163
vivek mehta7e573672018-03-13 17:41:41 -07002164 if ((usecase->type == PCM_HFP_CALL) || (usecase->type == PCM_CAPTURE))
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002165 snd_device = usecase->in_snd_device;
2166
2167 // skipped over get_spkr_prot_device
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002168 acdb_dev_id = platform_get_snd_device_acdb_id(snd_device);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002169 if (acdb_dev_id < 0) {
2170 ALOGE("%s: Could not find acdb id for device(%d)",
2171 __func__, snd_device);
2172 return -EINVAL;
2173 }
2174
2175 if (platform_can_split_snd_device(snd_device,
2176 &num_devices, new_snd_device) < 0) {
2177 new_snd_device[0] = snd_device;
2178 }
2179
2180 for (i = 0; i < num_devices; i++) {
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002181 acdb_dev_id = platform_get_snd_device_acdb_id(new_snd_device[i]);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002182 if (acdb_dev_id < 0) {
2183 ALOGE("%s: Could not find acdb id for device(%d)",
2184 __func__, new_snd_device[i]);
2185 return -EINVAL;
2186 }
2187 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
2188 __func__, new_snd_device[i], acdb_dev_id);
2189 if (new_snd_device[i] >= SND_DEVICE_OUT_BEGIN &&
2190 new_snd_device[i] < SND_DEVICE_OUT_END)
2191 acdb_dev_type = ACDB_DEV_TYPE_OUT;
2192 else
2193 acdb_dev_type = ACDB_DEV_TYPE_IN;
2194
2195 if (my_data->acdb_send_audio_cal_v3) {
2196 my_data->acdb_send_audio_cal_v3(acdb_dev_id, acdb_dev_type,
2197 app_type, sample_rate, i);
2198 } else if (my_data->acdb_send_audio_cal) {
2199 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type); // this version differs from internal
2200 }
2201 }
2202
2203 return 0;
2204}
2205
2206
Eric Laurentb23d5282013-05-14 15:27:20 -07002207int platform_switch_voice_call_device_pre(void *platform)
2208{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002209 struct platform_data *my_data = (struct platform_data *)platform;
2210 int ret = 0;
2211
2212 if (my_data->csd != NULL &&
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002213 voice_is_in_call(my_data->adev)) {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002214 /* This must be called before disabling mixer controls on APQ side */
2215 ret = my_data->csd->disable_device();
2216 if (ret < 0) {
2217 ALOGE("%s: csd_client_disable_device, failed, error %d",
2218 __func__, ret);
2219 }
2220 }
2221 return ret;
2222}
2223
2224int platform_switch_voice_call_enable_device_config(void *platform,
2225 snd_device_t out_snd_device,
2226 snd_device_t in_snd_device)
2227{
2228 struct platform_data *my_data = (struct platform_data *)platform;
2229 int acdb_rx_id, acdb_tx_id;
2230 int ret = 0;
2231
2232 if (my_data->csd == NULL)
2233 return ret;
2234
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002235 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
keunhui.park2f7306a2015-07-16 16:48:06 +09002236 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002237
2238 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
2239 ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
2240 if (ret < 0) {
2241 ALOGE("%s: csd_enable_device_config, failed, error %d",
2242 __func__, ret);
2243 }
2244 } else {
2245 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2246 acdb_rx_id, acdb_tx_id);
2247 }
2248
2249 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002250}
2251
2252int platform_switch_voice_call_device_post(void *platform,
2253 snd_device_t out_snd_device,
2254 snd_device_t in_snd_device)
2255{
2256 struct platform_data *my_data = (struct platform_data *)platform;
2257 int acdb_rx_id, acdb_tx_id;
2258
2259 if (my_data->acdb_send_voice_cal == NULL) {
2260 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
2261 } else {
keunhui.park2f7306a2015-07-16 16:48:06 +09002262 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
2263 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07002264
2265 if (acdb_rx_id > 0 && acdb_tx_id > 0)
2266 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
2267 else
2268 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2269 acdb_rx_id, acdb_tx_id);
2270 }
2271
2272 return 0;
2273}
2274
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002275int platform_switch_voice_call_usecase_route_post(void *platform,
2276 snd_device_t out_snd_device,
2277 snd_device_t in_snd_device)
2278{
2279 struct platform_data *my_data = (struct platform_data *)platform;
2280 int acdb_rx_id, acdb_tx_id;
2281 int ret = 0;
2282
2283 if (my_data->csd == NULL)
2284 return ret;
2285
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002286 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
keunhui.park2f7306a2015-07-16 16:48:06 +09002287 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002288
2289 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
2290 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
2291 my_data->adev->acdb_settings);
2292 if (ret < 0) {
2293 ALOGE("%s: csd_enable_device, failed, error %d", __func__, ret);
2294 }
2295 } else {
2296 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2297 acdb_rx_id, acdb_tx_id);
2298 }
2299
2300 return ret;
2301}
2302
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002303int platform_start_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07002304{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002305 struct platform_data *my_data = (struct platform_data *)platform;
2306 int ret = 0;
2307
2308 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002309 ret = my_data->csd->start_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002310 if (ret < 0) {
2311 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
2312 }
2313 }
2314 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002315}
2316
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002317int platform_stop_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07002318{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002319 struct platform_data *my_data = (struct platform_data *)platform;
2320 int ret = 0;
2321
2322 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002323 ret = my_data->csd->stop_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002324 if (ret < 0) {
2325 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
2326 }
2327 }
2328 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002329}
2330
Vignesh Kulothunganb6f0a9c2018-03-22 13:50:22 -07002331int platform_set_mic_break_det(void *platform, bool enable)
2332{
2333 int ret = 0;
2334 struct platform_data *my_data = (struct platform_data *)platform;
2335 struct audio_device *adev = my_data->adev;
2336 const char *mixer_ctl_name = "Voice Mic Break Enable";
2337 struct mixer_ctl *ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2338 if (!ctl) {
2339 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2340 __func__, mixer_ctl_name);
2341 return -EINVAL;
2342 }
2343
2344 ret = mixer_ctl_set_value(ctl, 0, enable);
2345 if(ret)
2346 ALOGE("%s: Failed to set mixer ctl: %s", __func__, mixer_ctl_name);
2347
2348 return ret;
2349}
2350
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002351int platform_get_sample_rate(void *platform, uint32_t *rate)
2352{
2353 struct platform_data *my_data = (struct platform_data *)platform;
2354 int ret = 0;
2355
2356 if (my_data->csd != NULL) {
2357 ret = my_data->csd->get_sample_rate(rate);
2358 if (ret < 0) {
2359 ALOGE("%s: csd_get_sample_rate error %d\n", __func__, ret);
2360 }
2361 }
2362 return ret;
2363}
2364
vivek mehtab6506412015-08-07 16:55:17 -07002365void platform_set_speaker_gain_in_combo(struct audio_device *adev,
2366 snd_device_t snd_device,
2367 bool enable)
2368{
2369 const char* name;
2370 switch (snd_device) {
2371 case SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES:
2372 if (enable)
2373 name = "spkr-gain-in-headphone-combo";
2374 else
2375 name = "speaker-gain-default";
2376 break;
2377 case SND_DEVICE_OUT_SPEAKER_AND_LINE:
2378 if (enable)
2379 name = "spkr-gain-in-line-combo";
2380 else
2381 name = "speaker-gain-default";
2382 break;
2383 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES:
2384 if (enable)
2385 name = "spkr-safe-gain-in-headphone-combo";
2386 else
2387 name = "speaker-safe-gain-default";
2388 break;
2389 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE:
2390 if (enable)
2391 name = "spkr-safe-gain-in-line-combo";
2392 else
2393 name = "speaker-safe-gain-default";
2394 break;
2395 default:
2396 return;
2397 }
2398
2399 audio_route_apply_and_update_path(adev->audio_route, name);
2400}
2401
Eric Laurentb23d5282013-05-14 15:27:20 -07002402int platform_set_voice_volume(void *platform, int volume)
2403{
2404 struct platform_data *my_data = (struct platform_data *)platform;
2405 struct audio_device *adev = my_data->adev;
2406 struct mixer_ctl *ctl;
sangwoo53b2cf02013-07-25 19:18:44 -07002407 const char *mixer_ctl_name = "Voice Rx Gain";
Nadav Barc46d0fa2017-12-24 14:50:37 +02002408 const char *mute_mixer_ctl_name = "Voice Rx Device Mute";
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002409 int vol_index = 0, ret = 0;
2410 uint32_t set_values[ ] = {0,
2411 ALL_SESSION_VSID,
2412 DEFAULT_VOLUME_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07002413
2414 // Voice volume levels are mapped to adsp volume levels as follows.
2415 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
2416 // But this values don't changed in kernel. So, below change is need.
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09002417 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, my_data->max_vol_index);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002418 set_values[0] = vol_index;
Eric Laurentb23d5282013-05-14 15:27:20 -07002419
2420 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2421 if (!ctl) {
2422 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2423 __func__, mixer_ctl_name);
2424 return -EINVAL;
2425 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002426 ALOGV("Setting voice volume index: %d", set_values[0]);
2427 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2428
Nadav Barc46d0fa2017-12-24 14:50:37 +02002429 // Send mute command in case volume index is max since indexes are inverted
2430 // for mixer controls.
2431 if (vol_index == my_data->max_vol_index) {
2432 set_values[0] = 1;
2433 }
2434 else {
2435 set_values[0] = 0;
2436 }
2437
2438 ctl = mixer_get_ctl_by_name(adev->mixer, mute_mixer_ctl_name);
2439 if (!ctl) {
2440 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2441 __func__, mute_mixer_ctl_name);
2442 return -EINVAL;
2443 }
2444 ALOGV("%s: Setting RX Device Mute to: %d", __func__, set_values[0]);
2445 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2446
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002447 if (my_data->csd != NULL) {
2448 ret = my_data->csd->volume(ALL_SESSION_VSID, volume,
2449 DEFAULT_VOLUME_RAMP_DURATION_MS);
2450 if (ret < 0) {
2451 ALOGE("%s: csd_volume error %d", __func__, ret);
2452 }
2453 }
2454 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002455}
2456
2457int platform_set_mic_mute(void *platform, bool state)
2458{
2459 struct platform_data *my_data = (struct platform_data *)platform;
2460 struct audio_device *adev = my_data->adev;
2461 struct mixer_ctl *ctl;
2462 const char *mixer_ctl_name = "Voice Tx Mute";
sangwoo53b2cf02013-07-25 19:18:44 -07002463 int ret = 0;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002464 uint32_t set_values[ ] = {0,
2465 ALL_SESSION_VSID,
2466 DEFAULT_MUTE_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07002467
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09002468 if (adev->mode != AUDIO_MODE_IN_CALL &&
2469 adev->mode != AUDIO_MODE_IN_COMMUNICATION)
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002470 return 0;
2471
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09002472 if (adev->enable_hfp)
2473 mixer_ctl_name = "HFP Tx Mute";
2474
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002475 set_values[0] = state;
2476 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2477 if (!ctl) {
2478 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2479 __func__, mixer_ctl_name);
2480 return -EINVAL;
2481 }
2482 ALOGV("Setting voice mute state: %d", state);
2483 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2484
2485 if (my_data->csd != NULL) {
2486 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state,
2487 DEFAULT_MUTE_RAMP_DURATION_MS);
sangwoo53b2cf02013-07-25 19:18:44 -07002488 if (ret < 0) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002489 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
sangwoo53b2cf02013-07-25 19:18:44 -07002490 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002491 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002492 return ret;
2493}
Eric Laurentb23d5282013-05-14 15:27:20 -07002494
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002495int platform_set_device_mute(void *platform, bool state, char *dir)
2496{
2497 struct platform_data *my_data = (struct platform_data *)platform;
2498 struct audio_device *adev = my_data->adev;
2499 struct mixer_ctl *ctl;
2500 char *mixer_ctl_name = NULL;
2501 int ret = 0;
2502 uint32_t set_values[ ] = {0,
2503 ALL_SESSION_VSID,
2504 0};
2505 if(dir == NULL) {
2506 ALOGE("%s: Invalid direction:%s", __func__, dir);
2507 return -EINVAL;
2508 }
2509
2510 if (!strncmp("rx", dir, sizeof("rx"))) {
2511 mixer_ctl_name = "Voice Rx Device Mute";
2512 } else if (!strncmp("tx", dir, sizeof("tx"))) {
2513 mixer_ctl_name = "Voice Tx Device Mute";
2514 } else {
2515 return -EINVAL;
2516 }
2517
2518 set_values[0] = state;
2519 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2520 if (!ctl) {
2521 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2522 __func__, mixer_ctl_name);
2523 return -EINVAL;
2524 }
2525
2526 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
2527 __func__,state, mixer_ctl_name);
2528 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2529
2530 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002531}
2532
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002533int platform_can_split_snd_device(snd_device_t snd_device,
2534 int *num_devices,
2535 snd_device_t *new_snd_devices)
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002536{
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002537 int ret = -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002538 if (NULL == num_devices || NULL == new_snd_devices) {
2539 ALOGE("%s: NULL pointer ..", __func__);
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002540 return -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002541 }
2542
2543 /*
2544 * If wired headset/headphones/line devices share the same backend
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002545 * with speaker/earpiece this routine returns -EINVAL.
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002546 */
2547 if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES &&
2548 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_HEADPHONES)) {
2549 *num_devices = 2;
2550 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2551 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002552 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002553 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_LINE &&
2554 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_LINE)) {
2555 *num_devices = 2;
2556 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2557 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002558 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002559 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES &&
2560 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_HEADPHONES)) {
2561 *num_devices = 2;
2562 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2563 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002564 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002565 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE &&
2566 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_LINE)) {
2567 *num_devices = 2;
2568 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2569 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002570 ret = 0;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002571 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO &&
2572 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2573 SND_DEVICE_OUT_BT_SCO)) {
2574 *num_devices = 2;
2575 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2576 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO;
2577 ret = 0;
juyuchen5351ea62018-05-16 10:54:37 +08002578 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO &&
2579 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE,
2580 SND_DEVICE_OUT_BT_SCO)) {
2581 *num_devices = 2;
2582 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2583 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO;
2584 ret = 0;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002585 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB &&
2586 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2587 SND_DEVICE_OUT_BT_SCO_WB)) {
2588 *num_devices = 2;
2589 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2590 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO_WB;
2591 ret = 0;
juyuchen5351ea62018-05-16 10:54:37 +08002592 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB &&
2593 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE,
2594 SND_DEVICE_OUT_BT_SCO_WB)) {
2595 *num_devices = 2;
2596 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2597 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO_WB;
2598 ret = 0;
David Linee3fe402017-03-13 10:00:42 -07002599 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET &&
2600 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_USB_HEADSET)) {
2601 *num_devices = 2;
2602 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2603 new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
2604 ret = 0;
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07002605 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET &&
2606 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_USB_HEADSET)) {
2607 *num_devices = 2;
2608 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2609 new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
2610 ret = 0;
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002611 } else if (SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP == snd_device &&
2612 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2613 SND_DEVICE_OUT_BT_A2DP)) {
2614 *num_devices = 2;
2615 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2616 new_snd_devices[1] = SND_DEVICE_OUT_BT_A2DP;
2617 ret = 0;
Aniket Kumar Lata9723a962018-05-16 17:41:55 -07002618 } else if (SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP == snd_device &&
2619 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE,
2620 SND_DEVICE_OUT_BT_A2DP)) {
2621 *num_devices = 2;
2622 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2623 new_snd_devices[1] = SND_DEVICE_OUT_BT_A2DP;
2624 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002625 }
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002626
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002627 return ret;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002628}
2629
Eric Laurentb23d5282013-05-14 15:27:20 -07002630snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
2631{
2632 struct platform_data *my_data = (struct platform_data *)platform;
2633 struct audio_device *adev = my_data->adev;
2634 audio_mode_t mode = adev->mode;
2635 snd_device_t snd_device = SND_DEVICE_NONE;
2636
2637 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
2638 if (devices == AUDIO_DEVICE_NONE ||
2639 devices & AUDIO_DEVICE_BIT_IN) {
2640 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
2641 goto exit;
2642 }
2643
Eric Laurent1b491552015-09-15 17:52:41 -07002644 if (popcount(devices) == 2) {
2645 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2646 AUDIO_DEVICE_OUT_SPEAKER) ||
2647 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2648 AUDIO_DEVICE_OUT_SPEAKER)) {
2649 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
2650 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2651 AUDIO_DEVICE_OUT_SPEAKER)) {
2652 snd_device = SND_DEVICE_OUT_SPEAKER_AND_LINE;
2653 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2654 AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
2655 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2656 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2657 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES;
2658 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2659 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2660 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE;
2661 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
2662 AUDIO_DEVICE_OUT_SPEAKER)) {
2663 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002664 } else if ((devices & AUDIO_DEVICE_OUT_ALL_SCO) &&
2665 ((devices & ~AUDIO_DEVICE_OUT_ALL_SCO) == AUDIO_DEVICE_OUT_SPEAKER)) {
2666 snd_device = adev->bt_wb_speech_enabled ?
2667 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB :
2668 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO;
juyuchen5351ea62018-05-16 10:54:37 +08002669 } else if ((devices & AUDIO_DEVICE_OUT_ALL_SCO) &&
2670 ((devices & ~AUDIO_DEVICE_OUT_ALL_SCO) == AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2671 snd_device = adev->bt_wb_speech_enabled ?
2672 SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB :
2673 SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO;
Eric Laurent99dab492017-06-17 15:19:08 -07002674 } else if ((devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
2675 AUDIO_DEVICE_OUT_SPEAKER)) ||
2676 (devices == (AUDIO_DEVICE_OUT_USB_HEADSET |
2677 AUDIO_DEVICE_OUT_SPEAKER))) {
David Linee3fe402017-03-13 10:00:42 -07002678 snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET;
Eric Laurentd0f7c262017-07-05 09:09:12 -07002679 } else if ((devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
2680 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) ||
2681 (devices == (AUDIO_DEVICE_OUT_USB_HEADSET |
2682 AUDIO_DEVICE_OUT_SPEAKER_SAFE))) {
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07002683 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET;
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002684 } else if ((devices & AUDIO_DEVICE_OUT_SPEAKER) &&
2685 (devices & AUDIO_DEVICE_OUT_ALL_A2DP)) {
2686 snd_device = SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP;
Aniket Kumar Lata9723a962018-05-16 17:41:55 -07002687 } else if ((devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) &&
2688 (devices & AUDIO_DEVICE_OUT_ALL_A2DP)) {
2689 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP;
Eric Laurent1b491552015-09-15 17:52:41 -07002690 } else {
2691 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
2692 goto exit;
2693 }
2694 if (snd_device != SND_DEVICE_NONE) {
2695 goto exit;
2696 }
2697 }
2698
2699 if (popcount(devices) != 1) {
2700 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
2701 goto exit;
2702 }
2703
Madhuri Athota3f6051b2016-10-13 23:25:38 +05302704 if (voice_is_in_call(adev) || adev->enable_voicerx || audio_extn_hfp_is_active(adev)) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002705 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002706 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2707 devices & AUDIO_DEVICE_OUT_LINE) {
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002708 if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002709 (adev->voice.tty_mode == TTY_MODE_FULL))
Eric Laurentb23d5282013-05-14 15:27:20 -07002710 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002711 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002712 (adev->voice.tty_mode == TTY_MODE_VCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002713 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002714 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002715 (adev->voice.tty_mode == TTY_MODE_HCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002716 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002717 else {
2718 if (devices & AUDIO_DEVICE_OUT_LINE)
2719 snd_device = SND_DEVICE_OUT_VOICE_LINE;
2720 else
2721 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
2722 }
Eric Laurent99dab492017-06-17 15:19:08 -07002723 } else if (audio_is_usb_out_device(devices)) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002724 if (voice_is_in_call(adev)) {
2725 switch (adev->voice.tty_mode) {
2726 case TTY_MODE_FULL:
2727 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_USB;
2728 break;
2729 case TTY_MODE_VCO:
2730 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_USB;
2731 break;
2732 case TTY_MODE_HCO:
2733 // since Hearing will be on handset\speaker, use existing device
2734 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
2735 break;
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002736 case TTY_MODE_OFF:
2737 break;
vivek mehtaa6b79742017-03-09 15:40:43 -08002738 default:
2739 ALOGE("%s: Invalid TTY mode (%#x)",
2740 __func__, adev->voice.tty_mode);
2741 }
2742 }
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002743 if (snd_device == SND_DEVICE_NONE) {
2744 snd_device = audio_extn_usb_is_capture_supported() ?
2745 SND_DEVICE_OUT_VOICE_USB_HEADSET :
2746 SND_DEVICE_OUT_VOICE_USB_HEADPHONES;
2747 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002748 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002749 if (adev->bt_wb_speech_enabled) {
2750 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2751 } else {
2752 snd_device = SND_DEVICE_OUT_BT_SCO;
2753 }
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002754 } else if (devices & AUDIO_DEVICE_OUT_ALL_A2DP) {
2755 snd_device = SND_DEVICE_OUT_BT_A2DP;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002756 } else if (devices & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002757 if (!adev->enable_hfp) {
2758 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
2759 } else {
2760 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_HFP;
2761 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002762 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002763 if(adev->voice.hac)
2764 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2765 else if (is_operator_tmus())
Eric Laurentb23d5282013-05-14 15:27:20 -07002766 snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS;
2767 else
Eric Laurentb4d368e2014-06-25 10:21:54 -05002768 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002769 } else if (devices & AUDIO_DEVICE_OUT_TELEPHONY_TX)
2770 snd_device = SND_DEVICE_OUT_VOICE_TX;
2771
Eric Laurentb23d5282013-05-14 15:27:20 -07002772 if (snd_device != SND_DEVICE_NONE) {
2773 goto exit;
2774 }
2775 }
2776
Eric Laurentb23d5282013-05-14 15:27:20 -07002777 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2778 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2779 snd_device = SND_DEVICE_OUT_HEADPHONES;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002780 } else if (devices & AUDIO_DEVICE_OUT_LINE) {
2781 snd_device = SND_DEVICE_OUT_LINE;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002782 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) {
2783 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE;
Eric Laurentb23d5282013-05-14 15:27:20 -07002784 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
andysu5b30b062018-04-20 16:34:06 +08002785 /*
2786 * Perform device switch only if acdb tuning is different between SPEAKER & SPEAKER_REVERSE,
2787 * Or there will be a small pause while performing device switch.
2788 */
2789 if (my_data->speaker_lr_swap &&
2790 (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
2791 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]))
Eric Laurentb23d5282013-05-14 15:27:20 -07002792 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
2793 else
2794 snd_device = SND_DEVICE_OUT_SPEAKER;
2795 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002796 if (adev->bt_wb_speech_enabled) {
2797 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2798 } else {
2799 snd_device = SND_DEVICE_OUT_BT_SCO;
2800 }
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002801 } else if (devices & AUDIO_DEVICE_OUT_ALL_A2DP) {
2802 snd_device = SND_DEVICE_OUT_BT_A2DP;
Eric Laurentb23d5282013-05-14 15:27:20 -07002803 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2804 snd_device = SND_DEVICE_OUT_HDMI ;
Eric Laurent99dab492017-06-17 15:19:08 -07002805 } else if (audio_is_usb_out_device(devices)) {
jasmine cha270b7762018-03-30 15:41:33 +08002806 if (audio_extn_ma_supported_usb())
2807 snd_device = SND_DEVICE_OUT_USB_HEADSET_SPEC;
2808 else if (audio_extn_usb_is_capture_supported())
David Linee3fe402017-03-13 10:00:42 -07002809 snd_device = SND_DEVICE_OUT_USB_HEADSET;
2810 else
2811 snd_device = SND_DEVICE_OUT_USB_HEADPHONES;
2812 }else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002813 /*HAC support for voice-ish audio (eg visual voicemail)*/
2814 if(adev->voice.hac)
2815 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2816 else
2817 snd_device = SND_DEVICE_OUT_HANDSET;
Eric Laurentb23d5282013-05-14 15:27:20 -07002818 } else {
2819 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
2820 }
2821exit:
2822 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
2823 return snd_device;
2824}
2825
2826snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
2827{
2828 struct platform_data *my_data = (struct platform_data *)platform;
2829 struct audio_device *adev = my_data->adev;
2830 audio_source_t source = (adev->active_input == NULL) ?
2831 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
2832
2833 audio_mode_t mode = adev->mode;
2834 audio_devices_t in_device = ((adev->active_input == NULL) ?
2835 AUDIO_DEVICE_NONE : adev->active_input->device)
2836 & ~AUDIO_DEVICE_BIT_IN;
2837 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
2838 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
2839 snd_device_t snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002840 int channel_count = popcount(channel_mask);
Eric Laurentb23d5282013-05-14 15:27:20 -07002841
Prashant Malanic92c5962015-08-11 15:10:18 -07002842 ALOGV("%s: enter: out_device(%#x) in_device(%#x) channel_count (%d) channel_mask (0x%x)",
2843 __func__, out_device, in_device, channel_count, channel_mask);
Devin Kimd789e432016-10-26 15:07:27 -07002844 if ((out_device != AUDIO_DEVICE_NONE) && (voice_is_in_call(adev) ||
2845 audio_extn_hfp_is_active(adev))) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002846 if (adev->voice.tty_mode != TTY_MODE_OFF) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002847 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002848 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2849 out_device & AUDIO_DEVICE_OUT_LINE) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002850 switch (adev->voice.tty_mode) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002851 case TTY_MODE_FULL:
2852 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
2853 break;
2854 case TTY_MODE_VCO:
2855 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
2856 break;
2857 case TTY_MODE_HCO:
2858 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
2859 break;
2860 default:
2861 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
2862 }
2863 goto exit;
Eric Laurent99dab492017-06-17 15:19:08 -07002864 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002865 switch (adev->voice.tty_mode) {
2866 case TTY_MODE_FULL:
2867 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC;
2868 break;
2869 case TTY_MODE_VCO:
2870 // since voice will be captured from handset mic, use existing device
2871 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
2872 break;
2873 case TTY_MODE_HCO:
2874 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC;
2875 break;
2876 default:
2877 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
Eric Laurentb23d5282013-05-14 15:27:20 -07002878 }
2879 goto exit;
2880 }
2881 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002882 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002883 if (my_data->fluence_in_voice_call == false) {
2884 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2885 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002886 if (is_operator_tmus())
2887 snd_device = SND_DEVICE_IN_VOICE_DMIC_TMUS;
Eric Laurentb23d5282013-05-14 15:27:20 -07002888 else
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002889 snd_device = SND_DEVICE_IN_VOICE_DMIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002890 }
2891 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2892 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
2893 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002894 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002895 if (adev->bluetooth_nrec)
2896 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2897 else
2898 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002899 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002900 if (adev->bluetooth_nrec)
2901 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2902 else
2903 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002904 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002905 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Prashant Malanic92c5962015-08-11 15:10:18 -07002906 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
2907 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2908 out_device & AUDIO_DEVICE_OUT_LINE) {
2909 if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
2910 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
2911 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
2912 } else {
2913 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2914 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002915 }
vivek mehtafe121d52015-08-10 23:39:23 -07002916
2917 //select default
2918 if (snd_device == SND_DEVICE_NONE) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002919 if (!adev->enable_hfp) {
2920 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2921 } else {
2922 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP;
2923 platform_set_echo_reference(adev, true, out_device);
2924 }
vivek mehtafe121d52015-08-10 23:39:23 -07002925 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002926 } else if (out_device & AUDIO_DEVICE_OUT_TELEPHONY_TX) {
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002927 snd_device = SND_DEVICE_IN_VOICE_RX;
Eric Laurent99dab492017-06-17 15:19:08 -07002928 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
David Lin40b07892017-08-07 15:02:48 -07002929 if (audio_extn_usb_is_capture_supported()) {
2930 snd_device = SND_DEVICE_IN_VOICE_USB_HEADSET_MIC;
2931 } else if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
2932 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
2933 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
2934 } else {
2935 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2936 }
2937 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002938 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002939 } else if (source == AUDIO_SOURCE_CAMCORDER) {
2940 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
2941 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2942 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
2943 }
2944 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
2945 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002946 if (my_data->fluence_in_voice_rec && channel_count == 1) {
2947 if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2948 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002949 if (adev->active_input->enable_aec)
2950 snd_device = SND_DEVICE_IN_HANDSET_QMIC_AEC;
2951 else
2952 snd_device = SND_DEVICE_IN_HANDSET_QMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002953 } else if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2954 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002955 if (adev->active_input->enable_aec)
2956 snd_device = SND_DEVICE_IN_HANDSET_TMIC_AEC;
2957 else
2958 snd_device = SND_DEVICE_IN_HANDSET_TMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002959 } else if (((my_data->fluence_type == FLUENCE_PRO_ENABLE) ||
2960 (my_data->fluence_type == FLUENCE_ENABLE)) &&
2961 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002962 if (adev->active_input->enable_aec)
2963 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
2964 else
2965 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
Prashant Malanic92c5962015-08-11 15:10:18 -07002966 }
2967 platform_set_echo_reference(adev, true, out_device);
2968 } else if ((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) &&
2969 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2970 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002971 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002972 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
2973 snd_device = SND_DEVICE_IN_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002974 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002975 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2976 snd_device = SND_DEVICE_IN_QUAD_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002977 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002978 if (snd_device == SND_DEVICE_NONE) {
vivek mehtaf3440682016-05-11 14:24:37 -07002979 if (adev->active_input->enable_aec) {
2980 if (adev->active_input->enable_ns) {
2981 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS;
2982 } else {
2983 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC;
2984 }
vivek mehta733c1df2016-04-04 15:09:24 -07002985 platform_set_echo_reference(adev, true, out_device);
vivek mehtaf3440682016-05-11 14:24:37 -07002986 } else if (adev->active_input->enable_ns) {
2987 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
2988 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002989 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
vivek mehtaf3440682016-05-11 14:24:37 -07002990 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002991 }
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -07002992 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2993 snd_device = SND_DEVICE_IN_VOICE_REC_HEADSET_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07002994 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002995 snd_device = SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002996 }
rago90fb9612015-12-02 11:37:53 -08002997 } else if (source == AUDIO_SOURCE_UNPROCESSED) {
2998 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
vivek mehta4ed66e62016-04-15 23:33:34 -07002999 if (((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) ||
3000 (channel_mask == AUDIO_CHANNEL_IN_STEREO)) &&
3001 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
3002 snd_device = SND_DEVICE_IN_UNPROCESSED_STEREO_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003003 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07003004 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
3005 snd_device = SND_DEVICE_IN_UNPROCESSED_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003006 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07003007 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
3008 snd_device = SND_DEVICE_IN_UNPROCESSED_QUAD_MIC;
3009 } else {
3010 snd_device = SND_DEVICE_IN_UNPROCESSED_MIC;
3011 }
rago90fb9612015-12-02 11:37:53 -08003012 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3013 snd_device = SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07003014 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07003015 snd_device = SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC;
rago90fb9612015-12-02 11:37:53 -08003016 }
Eric Laurent50a38ed2015-10-14 18:48:06 -07003017 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION ||
rago90fb9612015-12-02 11:37:53 -08003018 mode == AUDIO_MODE_IN_COMMUNICATION) {
David Lin40b07892017-08-07 15:02:48 -07003019 if (out_device & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
3020 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
3021 (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE | AUDIO_DEVICE_OUT_USB_HEADSET) &&
3022 !audio_extn_usb_is_capture_supported())) {
Eric Laurentb23d5282013-05-14 15:27:20 -07003023 in_device = AUDIO_DEVICE_IN_BACK_MIC;
David Lin40b07892017-08-07 15:02:48 -07003024 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003025 if (adev->active_input) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003026 if (adev->active_input->enable_aec &&
3027 adev->active_input->enable_ns) {
Eric Laurentb23d5282013-05-14 15:27:20 -07003028 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003029 if (my_data->fluence_in_spkr_mode &&
3030 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003031 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003032 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003033 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003034 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003035 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003036 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003037 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003038 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003039 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003040 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003041 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003042 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05003043 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3044 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Eric Laurent99dab492017-06-17 15:19:08 -07003045 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07003046 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
Eric Laurentb23d5282013-05-14 15:27:20 -07003047 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05003048 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003049 } else if (adev->active_input->enable_aec) {
3050 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
3051 if (my_data->fluence_in_spkr_mode &&
3052 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003053 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003054 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003055 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003056 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003057 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003058 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
3059 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003060 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003061 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003062 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003063 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003064 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05003065 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3066 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Eric Laurent99dab492017-06-17 15:19:08 -07003067 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07003068 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
Eric Laurentcefbbac2014-09-04 13:54:10 -05003069 }
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08003070 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003071 } else if (adev->active_input->enable_ns) {
3072 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
3073 if (my_data->fluence_in_spkr_mode &&
3074 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003075 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003076 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003077 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003078 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003079 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003080 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
3081 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003082 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003083 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003084 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003085 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003086 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003087 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05003088 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003089 }
3090 } else if (source == AUDIO_SOURCE_DEFAULT) {
3091 goto exit;
3092 }
3093
3094
3095 if (snd_device != SND_DEVICE_NONE) {
3096 goto exit;
3097 }
3098
3099 if (in_device != AUDIO_DEVICE_NONE &&
3100 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
3101 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
3102 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003103 if ((my_data->source_mic_type & SOURCE_QUAD_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003104 channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003105 snd_device = SND_DEVICE_IN_QUAD_MIC;
3106 } else if ((my_data->source_mic_type & SOURCE_THREE_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003107 channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003108 snd_device = SND_DEVICE_IN_THREE_MIC;
3109 } else if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
3110 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003111 snd_device = SND_DEVICE_IN_HANDSET_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07003112 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
3113 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003114 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003115 } else {
3116 ALOGE("%s: something wrong (1): source type (%d) channel_count (%d) .."
3117 " channel mask (0x%x) no combination found .. setting to mono", __func__,
3118 my_data->source_mic_type, channel_count, channel_mask);
3119 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3120 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003121 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003122 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
3123 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003124 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07003125 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
3126 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003127 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003128 } else {
3129 ALOGE("%s: something wrong (2): source type (%d) channel_count (%d) .."
3130 " no combination found .. setting to mono", __func__,
3131 my_data->source_mic_type, channel_count);
3132 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
3133 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003134 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3135 snd_device = SND_DEVICE_IN_HEADSET_MIC;
3136 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003137 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003138 if (adev->bluetooth_nrec)
3139 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
3140 else
3141 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003142 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003143 if (adev->bluetooth_nrec)
3144 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
3145 else
3146 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003147 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003148 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
3149 snd_device = SND_DEVICE_IN_HDMI_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07003150 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
David Linee3fe402017-03-13 10:00:42 -07003151 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07003152 } else {
3153 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
3154 ALOGW("%s: Using default handset-mic", __func__);
3155 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3156 }
3157 } else {
3158 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
3159 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3160 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
3161 snd_device = SND_DEVICE_IN_HEADSET_MIC;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003162 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07003163 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003164 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05003165 out_device & AUDIO_DEVICE_OUT_LINE) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003166 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
3167 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003168 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07003169 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
3170 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003171 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003172 } else {
3173 ALOGE("%s: something wrong (3): source type (%d) channel_count (%d) .."
3174 " no combination found .. setting to mono", __func__,
3175 my_data->source_mic_type, channel_count);
3176 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
3177 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003178 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003179 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003180 if (adev->bluetooth_nrec)
3181 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
3182 else
3183 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003184 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003185 if (adev->bluetooth_nrec)
3186 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
3187 else
3188 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003189 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003190 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
3191 snd_device = SND_DEVICE_IN_HDMI_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07003192 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
David Linee3fe402017-03-13 10:00:42 -07003193 if (audio_extn_usb_is_capture_supported())
3194 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
3195 else
3196 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07003197 } else {
3198 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
3199 ALOGW("%s: Using default handset-mic", __func__);
3200 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3201 }
3202 }
3203exit:
3204 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
3205 return snd_device;
3206}
3207
3208int platform_set_hdmi_channels(void *platform, int channel_count)
3209{
3210 struct platform_data *my_data = (struct platform_data *)platform;
3211 struct audio_device *adev = my_data->adev;
3212 struct mixer_ctl *ctl;
3213 const char *channel_cnt_str = NULL;
3214 const char *mixer_ctl_name = "HDMI_RX Channels";
3215 switch (channel_count) {
3216 case 8:
3217 channel_cnt_str = "Eight"; break;
3218 case 7:
3219 channel_cnt_str = "Seven"; break;
3220 case 6:
3221 channel_cnt_str = "Six"; break;
3222 case 5:
3223 channel_cnt_str = "Five"; break;
3224 case 4:
3225 channel_cnt_str = "Four"; break;
3226 case 3:
3227 channel_cnt_str = "Three"; break;
3228 default:
3229 channel_cnt_str = "Two"; break;
3230 }
3231 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3232 if (!ctl) {
3233 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3234 __func__, mixer_ctl_name);
3235 return -EINVAL;
3236 }
3237 ALOGV("HDMI channel count: %s", channel_cnt_str);
3238 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
3239 return 0;
3240}
3241
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003242int platform_edid_get_max_channels(void *platform)
Eric Laurentb23d5282013-05-14 15:27:20 -07003243{
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003244 struct platform_data *my_data = (struct platform_data *)platform;
3245 struct audio_device *adev = my_data->adev;
Eric Laurentb23d5282013-05-14 15:27:20 -07003246 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
3247 char *sad = block;
3248 int num_audio_blocks;
3249 int channel_count;
3250 int max_channels = 0;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003251 int i, ret, count;
Eric Laurentb23d5282013-05-14 15:27:20 -07003252
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003253 struct mixer_ctl *ctl;
3254
3255 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
3256 if (!ctl) {
3257 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3258 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
Eric Laurentb23d5282013-05-14 15:27:20 -07003259 return 0;
3260 }
3261
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003262 mixer_ctl_update(ctl);
3263
3264 count = mixer_ctl_get_num_values(ctl);
Eric Laurentb23d5282013-05-14 15:27:20 -07003265
3266 /* Read SAD blocks, clamping the maximum size for safety */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003267 if (count > (int)sizeof(block))
3268 count = (int)sizeof(block);
Eric Laurentb23d5282013-05-14 15:27:20 -07003269
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003270 ret = mixer_ctl_get_array(ctl, block, count);
3271 if (ret != 0) {
3272 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
3273 return 0;
3274 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003275
3276 /* Calculate the number of SAD blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003277 num_audio_blocks = count / SAD_BLOCK_SIZE;
Eric Laurentb23d5282013-05-14 15:27:20 -07003278
3279 for (i = 0; i < num_audio_blocks; i++) {
3280 /* Only consider LPCM blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003281 if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
3282 sad += 3;
Eric Laurentb23d5282013-05-14 15:27:20 -07003283 continue;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003284 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003285
3286 channel_count = (sad[0] & 0x7) + 1;
3287 if (channel_count > max_channels)
3288 max_channels = channel_count;
3289
3290 /* Advance to next block */
3291 sad += 3;
3292 }
3293
3294 return max_channels;
3295}
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003296
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07003297int platform_set_incall_recording_session_id(void *platform,
3298 uint32_t session_id, int rec_mode)
3299{
3300 int ret = 0;
3301 struct platform_data *my_data = (struct platform_data *)platform;
3302 struct audio_device *adev = my_data->adev;
3303 struct mixer_ctl *ctl;
3304 const char *mixer_ctl_name = "Voc VSID";
3305 int num_ctl_values;
3306 int i;
3307
3308 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3309 if (!ctl) {
3310 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3311 __func__, mixer_ctl_name);
3312 ret = -EINVAL;
3313 } else {
3314 num_ctl_values = mixer_ctl_get_num_values(ctl);
3315 for (i = 0; i < num_ctl_values; i++) {
3316 if (mixer_ctl_set_value(ctl, i, session_id)) {
3317 ALOGV("Error: invalid session_id: %x", session_id);
3318 ret = -EINVAL;
3319 break;
3320 }
3321 }
3322 }
3323
3324 if (my_data->csd != NULL) {
3325 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
3326 if (ret < 0) {
3327 ALOGE("%s: csd_client_start_record failed, error %d",
3328 __func__, ret);
3329 }
3330 }
3331
3332 return ret;
3333}
3334
Arun Mirpuriba2749a2018-04-17 14:32:24 -07003335int platform_set_incall_recording_session_channels(void *platform,
3336 uint32_t channel_count)
3337{
3338 int ret = 0;
3339 struct platform_data *my_data = (struct platform_data *)platform;
3340 struct audio_device *adev = my_data->adev;
3341 const char *mixer_ctl_name = "Voc Rec Config";
3342 int num_ctl_values;
3343 int i;
3344 struct mixer_ctl *ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3345
3346 if (!ctl) {
3347 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3348 __func__, mixer_ctl_name);
3349 ret = -EINVAL;
3350 } else {
3351 num_ctl_values = mixer_ctl_get_num_values(ctl);
3352 for (i = 0; i < num_ctl_values; i++) {
3353 if (mixer_ctl_set_value(ctl, i, channel_count)) {
3354 ALOGE("Error: invalid channel count: %x", channel_count);
3355 ret = -EINVAL;
3356 break;
3357 }
3358 }
3359 }
3360
3361 return ret;
3362}
3363
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07003364int platform_stop_incall_recording_usecase(void *platform)
3365{
3366 int ret = 0;
3367 struct platform_data *my_data = (struct platform_data *)platform;
3368
3369 if (my_data->csd != NULL) {
3370 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
3371 if (ret < 0) {
3372 ALOGE("%s: csd_client_stop_record failed, error %d",
3373 __func__, ret);
3374 }
3375 }
3376
3377 return ret;
3378}
3379
3380int platform_start_incall_music_usecase(void *platform)
3381{
3382 int ret = 0;
3383 struct platform_data *my_data = (struct platform_data *)platform;
3384
3385 if (my_data->csd != NULL) {
3386 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
3387 if (ret < 0) {
3388 ALOGE("%s: csd_client_start_playback failed, error %d",
3389 __func__, ret);
3390 }
3391 }
3392
3393 return ret;
3394}
3395
3396int platform_stop_incall_music_usecase(void *platform)
3397{
3398 int ret = 0;
3399 struct platform_data *my_data = (struct platform_data *)platform;
3400
3401 if (my_data->csd != NULL) {
3402 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
3403 if (ret < 0) {
3404 ALOGE("%s: csd_client_stop_playback failed, error %d",
3405 __func__, ret);
3406 }
3407 }
3408
3409 return ret;
3410}
3411
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003412int platform_set_parameters(void *platform, struct str_parms *parms)
3413{
3414 struct platform_data *my_data = (struct platform_data *)platform;
jasmine chac89321b2018-04-10 21:37:01 +08003415 char *value = NULL;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003416 char *kv_pairs = str_parms_to_str(parms);
jasmine chac89321b2018-04-10 21:37:01 +08003417 int len;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003418 int ret = 0, err;
3419
3420 if (kv_pairs == NULL) {
3421 ret = -EINVAL;
Jasmine Chaa314e192018-05-09 17:46:28 +08003422 ALOGE("%s: key-value pair is NULL", __func__);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003423 goto done;
3424 }
3425
3426 ALOGV("%s: enter: %s", __func__, kv_pairs);
3427
jasmine chac89321b2018-04-10 21:37:01 +08003428 len = strlen(kv_pairs);
Jasmine Chaa314e192018-05-09 17:46:28 +08003429 value = (char*)calloc(len + 1, sizeof(char));
jasmine chac89321b2018-04-10 21:37:01 +08003430 if (value == NULL) {
3431 ret = -ENOMEM;
Jasmine Chaa314e192018-05-09 17:46:28 +08003432 ALOGE("[%s] failed to allocate memory", __func__);
jasmine chac89321b2018-04-10 21:37:01 +08003433 goto done;
3434 }
3435
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003436 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME,
jasmine chac89321b2018-04-10 21:37:01 +08003437 value, len);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003438 if (err >= 0) {
3439 str_parms_del(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME);
3440 my_data->snd_card_name = strdup(value);
3441 ALOGV("%s: sound card name %s", __func__, my_data->snd_card_name);
3442 }
3443
keunhui.park2f7306a2015-07-16 16:48:06 +09003444 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO,
jasmine chac89321b2018-04-10 21:37:01 +08003445 value, len);
keunhui.park2f7306a2015-07-16 16:48:06 +09003446 if (err >= 0) {
3447 struct operator_info *info;
3448 char *str = value;
3449 char *name;
3450
3451 str_parms_del(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO);
3452 info = (struct operator_info *)calloc(1, sizeof(struct operator_info));
3453 name = strtok(str, ";");
3454 info->name = strdup(name);
3455 info->mccmnc = strdup(str + strlen(name) + 1);
3456
3457 list_add_tail(&operator_info_list, &info->list);
Joe Onorato188b6222016-03-01 11:02:27 -08003458 ALOGV("%s: add operator[%s] mccmnc[%s]", __func__, info->name, info->mccmnc);
keunhui.park2f7306a2015-07-16 16:48:06 +09003459 }
Prashant Malanic92c5962015-08-11 15:10:18 -07003460
Jasmine Chaa314e192018-05-09 17:46:28 +08003461 memset(value, 0, len + 1);
Eric Laurentc6333382015-09-14 12:43:44 -07003462 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT,
jasmine chac89321b2018-04-10 21:37:01 +08003463 value, len);
Prashant Malanic92c5962015-08-11 15:10:18 -07003464 if (err >= 0) {
Eric Laurentc6333382015-09-14 12:43:44 -07003465 str_parms_del(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT);
Prashant Malanic92c5962015-08-11 15:10:18 -07003466 my_data->max_mic_count = atoi(value);
3467 ALOGV("%s: max_mic_count %s/%d", __func__, value, my_data->max_mic_count);
Prashant Malanic92c5962015-08-11 15:10:18 -07003468 }
3469
jasmine chac89321b2018-04-10 21:37:01 +08003470 /* handle audio calibration parameters */
3471 set_audiocal(platform, parms, value, len);
3472
vivek mehta90933872017-06-15 18:04:39 -07003473 // to-do: disable setting sidetone gain, will revist this later
3474 // audio_extn_usb_set_sidetone_gain(parms, value, len);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003475done:
3476 ALOGV("%s: exit with code(%d)", __func__, ret);
3477 if (kv_pairs != NULL)
3478 free(kv_pairs);
jasmine chac89321b2018-04-10 21:37:01 +08003479 if (value != NULL)
3480 free(value);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003481
3482 return ret;
3483}
3484
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003485/* Delay in Us */
3486int64_t platform_render_latency(audio_usecase_t usecase)
3487{
3488 switch (usecase) {
3489 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
3490 return DEEP_BUFFER_PLATFORM_DELAY;
3491 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
3492 return LOW_LATENCY_PLATFORM_DELAY;
Haynes Mathew George03c40102016-01-29 17:57:48 -08003493 case USECASE_AUDIO_PLAYBACK_ULL:
3494 return ULL_PLATFORM_DELAY;
Eric Laurent0e46adf2016-12-16 12:49:24 -08003495 case USECASE_AUDIO_PLAYBACK_MMAP:
3496 return MMAP_PLATFORM_DELAY;
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003497 default:
3498 return 0;
3499 }
3500}
Haynes Mathew George98c95622014-06-20 19:14:25 -07003501
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003502int platform_set_snd_device_backend(snd_device_t device, const char *backend_tag,
3503 const char * hw_interface)
Haynes Mathew George98c95622014-06-20 19:14:25 -07003504{
3505 int ret = 0;
3506
3507 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
3508 ALOGE("%s: Invalid snd_device = %d",
3509 __func__, device);
3510 ret = -EINVAL;
3511 goto done;
3512 }
3513
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003514 ALOGV("%s: backend_tag_table[%s]: old = %s new = %s", __func__,
3515 platform_get_snd_device_name(device),
3516 backend_tag_table[device] != NULL ? backend_tag_table[device]: "null", backend_tag);
3517 if (backend_tag_table[device]) {
3518 free(backend_tag_table[device]);
Haynes Mathew George98c95622014-06-20 19:14:25 -07003519 }
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003520 backend_tag_table[device] = strdup(backend_tag);
3521
3522 if (hw_interface != NULL) {
3523 if (hw_interface_table[device])
3524 free(hw_interface_table[device]);
3525 ALOGV("%s: hw_interface_table[%d] = %s", __func__, device, hw_interface);
3526 hw_interface_table[device] = strdup(hw_interface);
3527 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07003528done:
3529 return ret;
3530}
3531
3532int platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t pcm_id)
3533{
3534 int ret = 0;
3535 if ((usecase <= USECASE_INVALID) || (usecase >= AUDIO_USECASE_MAX)) {
3536 ALOGE("%s: invalid usecase case idx %d", __func__, usecase);
3537 ret = -EINVAL;
3538 goto done;
3539 }
3540
3541 if ((type != 0) && (type != 1)) {
3542 ALOGE("%s: invalid usecase type", __func__);
3543 ret = -EINVAL;
3544 }
vivek mehtaa68fea62017-06-08 19:04:02 -07003545 ALOGV("%s: pcm_device_table[%d %s][%d] = %d", __func__, usecase,
3546 use_case_table[usecase],
3547 type, pcm_id);
Haynes Mathew George98c95622014-06-20 19:14:25 -07003548 pcm_device_table[usecase][type] = pcm_id;
3549done:
3550 return ret;
3551}
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003552
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07003553#define DEFAULT_NOMINAL_SPEAKER_GAIN 20
3554int ramp_speaker_gain(struct audio_device *adev, bool ramp_up, int target_ramp_up_gain) {
3555 // backup_gain: gain to try to set in case of an error during ramp
3556 int start_gain, end_gain, step, backup_gain, i;
3557 bool error = false;
3558 const struct mixer_ctl *ctl;
3559 const char *mixer_ctl_name_gain_left = "Left Speaker Gain";
3560 const char *mixer_ctl_name_gain_right = "Right Speaker Gain";
3561 struct mixer_ctl *ctl_left = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_left);
3562 struct mixer_ctl *ctl_right = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_right);
3563 if (!ctl_left || !ctl_right) {
3564 ALOGE("%s: Could not get ctl for mixer cmd - %s or %s, not applying speaker gain ramp",
3565 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
3566 return -EINVAL;
3567 } else if ((mixer_ctl_get_num_values(ctl_left) != 1)
3568 || (mixer_ctl_get_num_values(ctl_right) != 1)) {
3569 ALOGE("%s: Unexpected num values for mixer cmd - %s or %s, not applying speaker gain ramp",
3570 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
3571 return -EINVAL;
3572 }
3573 if (ramp_up) {
3574 start_gain = 0;
3575 end_gain = target_ramp_up_gain > 0 ? target_ramp_up_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
3576 step = +1;
3577 backup_gain = end_gain;
3578 } else {
3579 // using same gain on left and right
3580 const int left_gain = mixer_ctl_get_value(ctl_left, 0);
3581 start_gain = left_gain > 0 ? left_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
3582 end_gain = 0;
3583 step = -1;
3584 backup_gain = start_gain;
3585 }
3586 for (i = start_gain ; i != (end_gain + step) ; i += step) {
3587 //ALOGV("setting speaker gain to %d", i);
3588 if (mixer_ctl_set_value(ctl_left, 0, i)) {
3589 ALOGE("%s: error setting %s to %d during gain ramp",
3590 __func__, mixer_ctl_name_gain_left, i);
3591 error = true;
3592 break;
3593 }
3594 if (mixer_ctl_set_value(ctl_right, 0, i)) {
3595 ALOGE("%s: error setting %s to %d during gain ramp",
3596 __func__, mixer_ctl_name_gain_right, i);
3597 error = true;
3598 break;
3599 }
3600 usleep(1000);
3601 }
3602 if (error) {
3603 // an error occured during the ramp, let's still try to go back to a safe volume
3604 if (mixer_ctl_set_value(ctl_left, 0, backup_gain)) {
3605 ALOGE("%s: error restoring left gain to %d", __func__, backup_gain);
3606 }
3607 if (mixer_ctl_set_value(ctl_right, 0, backup_gain)) {
3608 ALOGE("%s: error restoring right gain to %d", __func__, backup_gain);
3609 }
3610 }
3611 return start_gain;
3612}
3613
vivek mehtae59cfb22017-06-16 15:57:11 -07003614int platform_set_swap_mixer(struct audio_device *adev, bool swap_channels)
3615{
3616 const char *mixer_ctl_name = "Swap channel";
3617 struct mixer_ctl *ctl;
3618 const char *mixer_path;
3619 struct platform_data *my_data = (struct platform_data *)adev->platform;
3620
3621 // forced to set to swap, but device not rotated ... ignore set
3622 if (swap_channels && !my_data->speaker_lr_swap)
3623 return 0;
3624
3625 ALOGV("%s:", __func__);
3626
3627 if (swap_channels) {
3628 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER_REVERSE);
3629 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
3630 } else {
3631 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER);
3632 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
3633 }
3634
3635 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3636 if (!ctl) {
3637 ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name);
3638 return -EINVAL;
3639 }
3640
3641 if (mixer_ctl_set_value(ctl, 0, swap_channels) < 0) {
3642 ALOGE("%s: Could not set reverse cotrol %d",__func__, swap_channels);
3643 return -EINVAL;
3644 }
3645
3646 ALOGV("platfor_force_swap_channel :: Channel orientation ( %s ) ",
3647 swap_channels?"R --> L":"L --> R");
3648
3649 return 0;
3650}
3651
3652int platform_check_and_set_swap_lr_channels(struct audio_device *adev, bool swap_channels)
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003653{
3654 // only update if there is active pcm playback on speaker
3655 struct audio_usecase *usecase;
3656 struct listnode *node;
3657 struct platform_data *my_data = (struct platform_data *)adev->platform;
3658
vivek mehtae59cfb22017-06-16 15:57:11 -07003659 my_data->speaker_lr_swap = swap_channels;
Jean-Michel Trivif7148702016-09-16 18:23:05 -07003660
vivek mehtae59cfb22017-06-16 15:57:11 -07003661 return platform_set_swap_channels(adev, swap_channels);
3662}
Jean-Michel Trivif7148702016-09-16 18:23:05 -07003663
vivek mehtae59cfb22017-06-16 15:57:11 -07003664int platform_set_swap_channels(struct audio_device *adev, bool swap_channels)
3665{
3666 // only update if there is active pcm playback on speaker
3667 struct audio_usecase *usecase;
3668 struct listnode *node;
3669 struct platform_data *my_data = (struct platform_data *)adev->platform;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003670
vivek mehtae59cfb22017-06-16 15:57:11 -07003671 // do not swap channels in audio modes with concurrent capture and playback
3672 // as this may break the echo reference
3673 if ((adev->mode == AUDIO_MODE_IN_COMMUNICATION) || (adev->mode == AUDIO_MODE_IN_CALL)) {
3674 ALOGV("%s: will not swap due to audio mode %d", __func__, adev->mode);
3675 return 0;
3676 }
3677
3678 list_for_each(node, &adev->usecase_list) {
3679 usecase = node_to_item(node, struct audio_usecase, list);
3680 if (usecase->type == PCM_PLAYBACK &&
3681 usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) {
3682 /*
3683 * If acdb tuning is different for SPEAKER_REVERSE, it is must
3684 * to perform device switch to disable the current backend to
3685 * enable it with new acdb data.
3686 */
3687 if (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
3688 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]) {
3689 const int initial_skpr_gain = ramp_speaker_gain(adev, false /*ramp_up*/, -1);
3690 select_devices(adev, usecase->id);
3691 if (initial_skpr_gain != -EINVAL)
3692 ramp_speaker_gain(adev, true /*ramp_up*/, initial_skpr_gain);
3693
3694 } else {
3695 platform_set_swap_mixer(adev, swap_channels);
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003696 }
vivek mehtae59cfb22017-06-16 15:57:11 -07003697 break;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003698 }
3699 }
vivek mehtae59cfb22017-06-16 15:57:11 -07003700
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003701 return 0;
3702}
vivek mehtaa8d7c922016-05-25 14:40:44 -07003703
3704static struct amp_db_and_gain_table tbl_mapping[MAX_VOLUME_CAL_STEPS];
3705static int num_gain_tbl_entry = 0;
3706
3707bool platform_add_gain_level_mapping(struct amp_db_and_gain_table *tbl_entry) {
3708
3709 ALOGV("%s: enter .. add %f %f %d", __func__, tbl_entry->amp, tbl_entry->db, tbl_entry->level);
3710 if (num_gain_tbl_entry == -1) {
3711 ALOGE("%s: num entry beyond valid step levels or corrupted..rejecting custom mapping",
3712 __func__);
3713 return false;
3714 }
3715
3716 if (num_gain_tbl_entry >= MAX_VOLUME_CAL_STEPS) {
3717 ALOGE("%s: max entry reached max[%d] current index[%d] .. rejecting", __func__,
3718 MAX_VOLUME_CAL_STEPS, num_gain_tbl_entry);
3719 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
3720 return false;
3721 }
3722
3723 if (num_gain_tbl_entry > 0 && tbl_mapping[num_gain_tbl_entry - 1].amp >= tbl_entry->amp) {
3724 ALOGE("%s: value not in ascending order .. rejecting custom mapping", __func__);
3725 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
3726 return false;
3727 }
3728
3729 tbl_mapping[num_gain_tbl_entry] = *tbl_entry;
3730 ++num_gain_tbl_entry;
3731
3732 return true;
3733}
3734
3735int platform_get_gain_level_mapping(struct amp_db_and_gain_table *mapping_tbl,
3736 int table_size) {
3737 int itt = 0;
3738 ALOGV("platform_get_gain_level_mapping called ");
3739
3740 if (num_gain_tbl_entry <= 0 || num_gain_tbl_entry > MAX_VOLUME_CAL_STEPS) {
3741 ALOGD("%s: empty or currupted gain_mapping_table", __func__);
3742 return 0;
3743 }
3744
3745 for (; itt < num_gain_tbl_entry && itt <= table_size; itt++) {
3746 mapping_tbl[itt] = tbl_mapping[itt];
3747 ALOGV("%s: added amp[%f] db[%f] level[%d]", __func__,
3748 mapping_tbl[itt].amp, mapping_tbl[itt].db, mapping_tbl[itt].level);
3749 }
3750
3751 return num_gain_tbl_entry;
3752}
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07003753
3754int platform_snd_card_update(void *platform, card_status_t status)
3755{
3756 struct platform_data *my_data = (struct platform_data *)platform;
3757 struct audio_device *adev = my_data->adev;
3758
3759 if (status == CARD_STATUS_ONLINE) {
3760 if (my_data->acdb_send_custom_top)
3761 my_data->acdb_send_custom_top();
3762 }
3763 return 0;
3764}
David Linee3fe402017-03-13 10:00:42 -07003765
3766/*
3767 * configures afe with bit width and Sample Rate
3768 */
Haynes Mathew George65f6b432018-02-27 17:44:55 -08003769int platform_set_backend_cfg(const struct audio_device* adev,
3770 snd_device_t snd_device,
3771 const struct audio_backend_cfg *backend_cfg)
David Linee3fe402017-03-13 10:00:42 -07003772{
3773
3774 int ret = 0;
3775 const int backend_idx = platform_get_backend_index(snd_device);
3776 struct platform_data *my_data = (struct platform_data *)adev->platform;
3777 const unsigned int bit_width = backend_cfg->bit_width;
3778 const unsigned int sample_rate = backend_cfg->sample_rate;
3779 const unsigned int channels = backend_cfg->channels;
3780 const audio_format_t format = backend_cfg->format;
3781 const bool passthrough_enabled = backend_cfg->passthrough_enabled;
3782
3783
3784 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
3785 ", backend_idx %d device (%s)", __func__, bit_width,
3786 sample_rate, channels, backend_idx,
3787 platform_get_snd_device_name(snd_device));
3788
3789 if ((my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl) &&
3790 (bit_width != my_data->current_backend_cfg[backend_idx].bit_width)) {
3791
3792 struct mixer_ctl *ctl = NULL;
3793 ctl = mixer_get_ctl_by_name(adev->mixer,
3794 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
3795 if (!ctl) {
3796 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3797 __func__,
3798 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
3799 return -EINVAL;
3800 }
3801
3802 if (bit_width == 24) {
3803 if (format == AUDIO_FORMAT_PCM_24_BIT_PACKED)
3804 ret = mixer_ctl_set_enum_by_string(ctl, "S24_3LE");
3805 else
3806 ret = mixer_ctl_set_enum_by_string(ctl, "S24_LE");
3807 } else if (bit_width == 32) {
3808 ret = mixer_ctl_set_enum_by_string(ctl, "S32_LE");
3809 } else {
3810 ret = mixer_ctl_set_enum_by_string(ctl, "S16_LE");
3811 }
3812 if ( ret < 0) {
3813 ALOGE("%s:becf: afe: fail for %s mixer set to %d bit for %x format", __func__,
3814 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
3815 } else {
3816 my_data->current_backend_cfg[backend_idx].bit_width = bit_width;
3817 ALOGD("%s:becf: afe: %s mixer set to %d bit for %x format", __func__,
3818 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
3819 }
3820 /* set the ret as 0 and not pass back to upper layer */
3821 ret = 0;
3822 }
3823
3824 if (passthrough_enabled || ((my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl) &&
3825 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate))) {
3826 char *rate_str = NULL;
3827 struct mixer_ctl *ctl = NULL;
3828
3829 switch (sample_rate) {
3830 case 32000:
3831 if (passthrough_enabled) {
3832 rate_str = "KHZ_32";
3833 break;
3834 }
3835 case 8000:
3836 case 11025:
3837 case 16000:
3838 case 22050:
3839 case 48000:
3840 rate_str = "KHZ_48";
3841 break;
3842 case 44100:
3843 rate_str = "KHZ_44P1";
3844 break;
3845 case 64000:
3846 case 96000:
3847 rate_str = "KHZ_96";
3848 break;
3849 case 88200:
3850 rate_str = "KHZ_88P2";
3851 break;
3852 case 176400:
3853 rate_str = "KHZ_176P4";
3854 break;
3855 case 192000:
3856 rate_str = "KHZ_192";
3857 break;
3858 case 352800:
3859 rate_str = "KHZ_352P8";
3860 break;
3861 case 384000:
3862 rate_str = "KHZ_384";
3863 break;
3864 case 144000:
3865 if (passthrough_enabled) {
3866 rate_str = "KHZ_144";
3867 break;
3868 }
3869 default:
3870 rate_str = "KHZ_48";
3871 break;
3872 }
3873
3874 ctl = mixer_get_ctl_by_name(adev->mixer,
3875 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
3876 if(!ctl) {
3877 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3878 __func__,
3879 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
3880 return -EINVAL;
3881 }
3882
3883 ALOGD("%s:becf: afe: %s set to %s", __func__,
3884 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl, rate_str);
3885 mixer_ctl_set_enum_by_string(ctl, rate_str);
3886 my_data->current_backend_cfg[backend_idx].sample_rate = sample_rate;
3887 }
3888 if ((my_data->current_backend_cfg[backend_idx].channels_mixer_ctl) &&
3889 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
3890 struct mixer_ctl *ctl = NULL;
3891 char *channel_cnt_str = NULL;
3892
3893 switch (channels) {
3894 case 8:
3895 channel_cnt_str = "Eight"; break;
3896 case 7:
3897 channel_cnt_str = "Seven"; break;
3898 case 6:
3899 channel_cnt_str = "Six"; break;
3900 case 5:
3901 channel_cnt_str = "Five"; break;
3902 case 4:
3903 channel_cnt_str = "Four"; break;
3904 case 3:
3905 channel_cnt_str = "Three"; break;
3906 case 1:
3907 channel_cnt_str = "One"; break;
3908 case 2:
3909 default:
3910 channel_cnt_str = "Two"; break;
3911 }
3912
3913 ctl = mixer_get_ctl_by_name(adev->mixer,
3914 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
3915 if (!ctl) {
3916 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3917 __func__,
3918 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
3919 return -EINVAL;
3920 }
3921 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
3922 my_data->current_backend_cfg[backend_idx].channels = channels;
3923
3924 // skip EDID configuration for HDMI backend
3925
3926 ALOGD("%s:becf: afe: %s set to %s", __func__,
3927 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl,
3928 channel_cnt_str);
3929 }
3930
3931 // skip set ext_display format mixer control
3932 return ret;
3933}
3934
3935static int platform_get_snd_device_bit_width(snd_device_t snd_device)
3936{
3937 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
3938 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
3939 return CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3940 }
3941
3942 return backend_bit_width_table[snd_device];
3943}
3944
3945/*
3946 * return backend_idx on which voice call is active
3947 */
3948static int platform_get_voice_call_backend(struct audio_device* adev)
3949{
3950 struct audio_usecase *uc = NULL;
3951 struct listnode *node;
3952 snd_device_t out_snd_device = SND_DEVICE_NONE;
3953
3954 int backend_idx = -1;
3955
3956 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
3957 list_for_each(node, &adev->usecase_list) {
3958 uc = node_to_item(node, struct audio_usecase, list);
3959 if (uc && uc->type == VOICE_CALL && uc->stream.out) {
3960 out_snd_device = platform_get_output_snd_device(adev->platform,
3961 uc->stream.out->devices);
3962 backend_idx = platform_get_backend_index(out_snd_device);
3963 break;
3964 }
3965 }
3966 }
3967 return backend_idx;
3968}
3969
3970/*
3971 * goes through all the current usecases and picks the highest
3972 * bitwidth & samplerate
3973 */
3974static bool platform_check_capture_backend_cfg(struct audio_device* adev,
3975 int backend_idx,
3976 struct audio_backend_cfg *backend_cfg)
3977{
3978 bool backend_change = false;
3979 unsigned int bit_width;
3980 unsigned int sample_rate;
3981 unsigned int channels;
3982 struct platform_data *my_data = (struct platform_data *)adev->platform;
3983
3984 bit_width = backend_cfg->bit_width;
3985 sample_rate = backend_cfg->sample_rate;
3986 channels = backend_cfg->channels;
3987
3988 ALOGV("%s:txbecf: afe: Codec selected backend: %d current bit width: %d and "
3989 "sample rate: %d, channels %d",__func__,backend_idx, bit_width,
3990 sample_rate, channels);
3991
3992 // For voice calls use default configuration i.e. 16b/48K, only applicable to
3993 // default backend
3994 // force routing is not required here, caller will do it anyway
3995 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
3996 ALOGW("%s:txbecf: afe: Use default bw and sr for voice/voip calls and "
3997 "for unprocessed/camera source", __func__);
3998 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3999 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4000 }
4001
4002 if (backend_idx == USB_AUDIO_TX_BACKEND) {
4003 audio_extn_usb_is_config_supported(&bit_width, &sample_rate, &channels, false);
4004 ALOGV("%s:txbecf: afe: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
4005 __func__, bit_width, sample_rate, channels);
4006 }
4007
4008 ALOGV("%s:txbecf: afe: Codec selected backend: %d updated bit width: %d and "
4009 "sample rate: %d", __func__, backend_idx, bit_width, sample_rate);
4010
4011 // Force routing if the expected bitwdith or samplerate
4012 // is not same as current backend comfiguration
4013 if ((bit_width != my_data->current_backend_cfg[backend_idx].bit_width) ||
4014 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate) ||
4015 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
4016 backend_cfg->bit_width = bit_width;
4017 backend_cfg->sample_rate= sample_rate;
4018 backend_cfg->channels = channels;
4019 backend_change = true;
4020 ALOGI("%s:txbecf: afe: Codec backend needs to be updated. new bit width: %d "
4021 "new sample rate: %d new channel: %d",
4022 __func__, backend_cfg->bit_width,
4023 backend_cfg->sample_rate, backend_cfg->channels);
4024 }
4025
4026 return backend_change;
4027}
4028
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004029static void pick_playback_cfg_for_uc(struct audio_device *adev,
4030 struct audio_usecase *usecase,
4031 snd_device_t snd_device,
4032 unsigned int *bit_width,
4033 unsigned int *sample_rate,
4034 unsigned int *channels)
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004035{
4036 int i =0;
4037 struct listnode *node;
4038 list_for_each(node, &adev->usecase_list) {
4039 struct audio_usecase *uc;
4040 uc = node_to_item(node, struct audio_usecase, list);
4041 struct stream_out *out = (struct stream_out*) uc->stream.out;
4042 if (uc->type == PCM_PLAYBACK && out && usecase != uc) {
4043 unsigned int out_channels = audio_channel_count_from_out_mask(out->channel_mask);
4044 ALOGV("%s:napb: (%d) - (%s)id (%d) sr %d bw "
4045 "(%d) ch (%d) device %s", __func__, i++, use_case_table[uc->id],
4046 uc->id, out->sample_rate,
4047 pcm_format_to_bits(out->config.format), out_channels,
4048 platform_get_snd_device_name(uc->out_snd_device));
4049
4050 if (platform_check_backends_match(snd_device, uc->out_snd_device)) {
4051 if (*bit_width < pcm_format_to_bits(out->config.format))
4052 *bit_width = pcm_format_to_bits(out->config.format);
4053 if (*sample_rate < out->sample_rate)
4054 *sample_rate = out->sample_rate;
4055 if (out->sample_rate < OUTPUT_SAMPLING_RATE_44100)
4056 *sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4057 if (*channels < out_channels)
4058 *channels = out_channels;
4059 }
4060 }
4061 }
4062 return;
4063}
4064
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004065static void headset_is_config_supported(unsigned int *bit_width,
4066 unsigned int *sample_rate,
4067 unsigned int *channels) {
4068 switch (*bit_width) {
4069 case 16:
4070 case 24:
4071 break;
4072 default:
4073 *bit_width = 16;
4074 break;
4075 }
4076
4077 if (*sample_rate > 192000) {
4078 *sample_rate = 192000;
4079 }
4080
4081 if (*channels > 2) {
4082 *channels = 2;
4083 }
4084}
4085
David Linee3fe402017-03-13 10:00:42 -07004086static bool platform_check_playback_backend_cfg(struct audio_device* adev,
4087 struct audio_usecase* usecase,
4088 snd_device_t snd_device,
4089 struct audio_backend_cfg *backend_cfg)
4090{
4091 bool backend_change = false;
David Linee3fe402017-03-13 10:00:42 -07004092 unsigned int bit_width;
4093 unsigned int sample_rate;
4094 unsigned int channels;
David Linee3fe402017-03-13 10:00:42 -07004095 int backend_idx = DEFAULT_CODEC_BACKEND;
Haynes Mathew George65f6b432018-02-27 17:44:55 -08004096 unsigned long service_interval = 0; // 0 is invalid
David Linee3fe402017-03-13 10:00:42 -07004097 struct platform_data *my_data = (struct platform_data *)adev->platform;
David Linee3fe402017-03-13 10:00:42 -07004098
4099 if (snd_device == SND_DEVICE_OUT_BT_SCO ||
4100 snd_device == SND_DEVICE_OUT_BT_SCO_WB) {
4101 backend_change = false;
4102 return backend_change;
4103 }
4104
4105 backend_idx = platform_get_backend_index(snd_device);
4106 bit_width = backend_cfg->bit_width;
4107 sample_rate = backend_cfg->sample_rate;
4108 channels = backend_cfg->channels;
4109
4110 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
4111 ", backend_idx %d usecase = %d device (%s)", __func__, bit_width,
4112 sample_rate, channels, backend_idx, usecase->id,
4113 platform_get_snd_device_name(snd_device));
4114
4115 if (backend_idx == platform_get_voice_call_backend(adev)) {
4116 ALOGW("%s:becf: afe:Use default bw and sr for voice/voip calls ",
4117 __func__);
4118 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
4119 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4120 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
4121 } else {
4122 /*
4123 * The backend should be configured at highest bit width and/or
4124 * sample rate amongst all playback usecases.
4125 * If the selected sample rate and/or bit width differ with
4126 * current backend sample rate and/or bit width, then, we set the
4127 * backend re-configuration flag.
4128 *
4129 * Exception: 16 bit playbacks is allowed through 16 bit/48/44.1 khz backend only
4130 */
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004131 pick_playback_cfg_for_uc(adev, usecase, snd_device,
4132 &bit_width,
4133 &sample_rate,
4134 &channels);
David Linee3fe402017-03-13 10:00:42 -07004135 }
4136
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004137 switch (backend_idx) {
4138 case USB_AUDIO_RX_BACKEND:
4139 audio_extn_usb_is_config_supported(&bit_width,
4140 &sample_rate, &channels, true);
Haynes Mathew George65f6b432018-02-27 17:44:55 -08004141 if (platform_get_usb_service_interval(adev->platform, true,
4142 &service_interval) == 0) {
4143 /* overwrite with best altset for this service interval */
4144 int ret =
4145 audio_extn_usb_altset_for_service_interval(true /*playback*/,
4146 service_interval,
4147 &bit_width,
4148 &sample_rate,
4149 &channels);
4150 if (ret < 0) {
4151 ALOGE("Failed to find altset for service interval %lu, skip reconfig",
4152 service_interval);
4153 return false;
4154 }
4155 }
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004156 ALOGV("%s: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
4157 __func__, bit_width, sample_rate, channels);
4158 break;
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004159 case HEADPHONE_BACKEND:
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004160 headset_is_config_supported(&bit_width, &sample_rate, &channels);
4161 break;
4162 case DEFAULT_CODEC_BACKEND:
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004163 default:
4164 bit_width = platform_get_snd_device_bit_width(snd_device);
4165 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4166 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
4167 break;
David Linee3fe402017-03-13 10:00:42 -07004168 }
4169
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004170 ALOGV("%s:becf: afe: Codec selected backend: %d updated bit width: %d and"
4171 "sample rate: %d",
David Linee3fe402017-03-13 10:00:42 -07004172 __func__, backend_idx , bit_width, sample_rate);
4173
4174 // Force routing if the expected bitwdith or samplerate
4175 // is not same as current backend comfiguration
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004176 if (bit_width != my_data->current_backend_cfg[backend_idx].bit_width ||
4177 sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate ||
4178 channels != my_data->current_backend_cfg[backend_idx].channels) {
David Linee3fe402017-03-13 10:00:42 -07004179 backend_cfg->bit_width = bit_width;
4180 backend_cfg->sample_rate = sample_rate;
4181 backend_cfg->channels = channels;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004182 backend_cfg->passthrough_enabled = false;
David Linee3fe402017-03-13 10:00:42 -07004183 backend_change = true;
4184 ALOGV("%s:becf: afe: Codec backend needs to be updated. new bit width: %d"
4185 "new sample rate: %d new channels: %d",
4186 __func__, backend_cfg->bit_width, backend_cfg->sample_rate, backend_cfg->channels);
4187 }
4188
4189 return backend_change;
4190}
4191
4192bool platform_check_and_set_playback_backend_cfg(struct audio_device* adev,
4193 struct audio_usecase *usecase, snd_device_t snd_device)
4194{
4195 int backend_idx = DEFAULT_CODEC_BACKEND;
4196 int new_snd_devices[SND_DEVICE_OUT_END];
4197 int i, num_devices = 1;
4198 bool ret = false;
4199 struct platform_data *my_data = (struct platform_data *)adev->platform;
4200 struct audio_backend_cfg backend_cfg;
4201
4202 backend_idx = platform_get_backend_index(snd_device);
4203
4204 backend_cfg.bit_width = pcm_format_to_bits(usecase->stream.out->config.format);
4205 backend_cfg.sample_rate = usecase->stream.out->sample_rate;
4206 backend_cfg.format = usecase->stream.out->format;
4207 backend_cfg.channels = audio_channel_count_from_out_mask(usecase->stream.out->channel_mask);
4208 /*this is populated by check_codec_backend_cfg hence set default value to false*/
4209 backend_cfg.passthrough_enabled = false;
4210
4211 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
4212 ", backend_idx %d usecase = %d device (%s)", __func__, backend_cfg.bit_width,
4213 backend_cfg.sample_rate, backend_cfg.channels, backend_idx, usecase->id,
4214 platform_get_snd_device_name(snd_device));
4215
4216 if (platform_can_split_snd_device(snd_device, &num_devices, new_snd_devices) < 0)
4217 new_snd_devices[0] = snd_device;
4218
4219 for (i = 0; i < num_devices; i++) {
4220 ALOGV("%s: new_snd_devices[%d] is %d", __func__, i, new_snd_devices[i]);
4221 if ((platform_check_playback_backend_cfg(adev, usecase, new_snd_devices[i],
4222 &backend_cfg))) {
4223 platform_set_backend_cfg(adev, new_snd_devices[i],
4224 &backend_cfg);
4225 ret = true;
4226 }
4227 }
4228 return ret;
4229}
4230
4231bool platform_check_and_set_capture_backend_cfg(struct audio_device* adev,
4232 struct audio_usecase *usecase, snd_device_t snd_device)
4233{
4234 int backend_idx = platform_get_backend_index(snd_device);
4235 int ret = 0;
4236 struct audio_backend_cfg backend_cfg;
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004237 memset(&backend_cfg, 0, sizeof(struct audio_backend_cfg));
David Linee3fe402017-03-13 10:00:42 -07004238
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004239 if (usecase->type == PCM_CAPTURE) {
4240 backend_cfg.format = usecase->stream.in->format;
David Linee3fe402017-03-13 10:00:42 -07004241 backend_cfg.channels = audio_channel_count_from_in_mask(usecase->stream.in->channel_mask);
4242 } else {
4243 backend_cfg.bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
4244 backend_cfg.sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4245 backend_cfg.format = AUDIO_FORMAT_PCM_16_BIT;
4246 backend_cfg.channels = 1;
4247 }
4248
4249 ALOGV("%s:txbecf: afe: bitwidth %d, samplerate %d, channel %d"
4250 ", backend_idx %d usecase = %d device (%s)", __func__,
4251 backend_cfg.bit_width,
4252 backend_cfg.sample_rate,
4253 backend_cfg.channels,
4254 backend_idx, usecase->id,
4255 platform_get_snd_device_name(snd_device));
4256
4257 if (platform_check_capture_backend_cfg(adev, backend_idx, &backend_cfg)) {
4258 ret = platform_set_backend_cfg(adev, snd_device,
4259 &backend_cfg);
4260 if(!ret)
4261 return true;
4262 }
4263
4264 return false;
4265}
4266
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004267static int max_be_dai_names = 0;
4268static const struct be_dai_name_struct *be_dai_name_table;
4269
4270/*
4271 * Retrieves the be_dai_name_table from kernel to enable a mapping
4272 * between sound device hw interfaces and backend IDs. This allows HAL to
4273 * specify the backend a specific calibration is needed for.
4274 */
4275static int init_be_dai_name_table(struct audio_device *adev)
4276{
4277 const char *mixer_ctl_name = "Backend DAI Name Table";
4278 struct mixer_ctl *ctl;
4279 int i, j, ret, size;
4280 bool valid_hw_interface;
4281
4282 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
4283 if (!ctl) {
4284 ALOGE("%s: Could not get ctl for mixer name %s\n",
4285 __func__, mixer_ctl_name);
4286 ret = -EINVAL;
4287 goto done;
4288 }
4289
4290 mixer_ctl_update(ctl);
4291
4292 size = mixer_ctl_get_num_values(ctl);
4293 if (size <= 0){
4294 ALOGE("%s: Failed to get %s size %d\n",
4295 __func__, mixer_ctl_name, size);
4296 ret = -EFAULT;
4297 goto done;
4298 }
4299
vivek mehtaa68fea62017-06-08 19:04:02 -07004300 be_dai_name_table =
4301 (const struct be_dai_name_struct *)calloc(1, size);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004302 if (be_dai_name_table == NULL) {
4303 ALOGE("%s: Failed to allocate memory for %s\n",
4304 __func__, mixer_ctl_name);
4305 ret = -ENOMEM;
4306 goto freeMem;
4307 }
4308
4309 ret = mixer_ctl_get_array(ctl, (void *)be_dai_name_table, size);
4310 if (ret) {
4311 ALOGE("%s: Failed to get %s, ret %d\n",
4312 __func__, mixer_ctl_name, ret);
4313 ret = -EFAULT;
4314 goto freeMem;
4315 }
4316
4317 if (be_dai_name_table != NULL) {
4318 max_be_dai_names = size / sizeof(struct be_dai_name_struct);
4319 ALOGV("%s: Successfully got %s, number of be dais is %d\n",
4320 __func__, mixer_ctl_name, max_be_dai_names);
4321 ret = 0;
4322 } else {
4323 ALOGE("%s: Failed to get %s\n", __func__, mixer_ctl_name);
4324 ret = -EFAULT;
4325 goto freeMem;
4326 }
4327
4328 /*
4329 * Validate all sound devices have a valid backend set to catch
4330 * errors for uncommon sound devices
4331 */
4332 for (i = 0; i < SND_DEVICE_MAX; i++) {
4333 valid_hw_interface = false;
4334
4335 if (hw_interface_table[i] == NULL) {
4336 ALOGW("%s: sound device %s has no hw interface set\n",
4337 __func__, platform_get_snd_device_name(i));
4338 continue;
4339 }
4340
4341 for (j = 0; j < max_be_dai_names; j++) {
4342 if (strcmp(hw_interface_table[i], be_dai_name_table[j].be_name)
4343 == 0) {
4344 valid_hw_interface = true;
4345 break;
4346 }
4347 }
4348 if (!valid_hw_interface)
4349 ALOGD("%s: sound device %s does not have a valid hw interface set "
4350 "(disregard for combo devices) %s\n",
4351 __func__, platform_get_snd_device_name(i),
4352 hw_interface_table[i]);
4353 }
4354
4355 goto done;
4356
4357freeMem:
4358 if (be_dai_name_table) {
4359 free((void *)be_dai_name_table);
4360 be_dai_name_table = NULL;
4361 }
4362
4363done:
4364 return ret;
4365}
4366
4367int platform_get_snd_device_backend_index(snd_device_t device)
4368{
4369 int i, be_dai_id;
4370 const char * hw_interface_name = NULL;
4371
4372 ALOGV("%s: enter with device %d\n", __func__, device);
4373
vivek mehtaa68fea62017-06-08 19:04:02 -07004374 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004375 ALOGE("%s: Invalid snd_device = %d",
4376 __func__, device);
4377 be_dai_id = -EINVAL;
4378 goto done;
4379 }
4380
4381 /* Get string value of necessary backend for device */
4382 hw_interface_name = hw_interface_table[device];
4383 if (hw_interface_name == NULL) {
4384 ALOGE("%s: no hw_interface set for device %d\n", __func__, device);
4385 be_dai_id = -EINVAL;
4386 goto done;
4387 }
4388
4389 /* Check if be dai name table was retrieved successfully */
4390 if (be_dai_name_table == NULL) {
4391 ALOGE("%s: BE DAI Name Table is not present\n", __func__);
4392 be_dai_id = -EFAULT;
4393 goto done;
4394 }
4395
4396 /* Get backend ID for device specified */
4397 for (i = 0; i < max_be_dai_names; i++) {
4398 if (strcmp(hw_interface_name, be_dai_name_table[i].be_name) == 0) {
4399 be_dai_id = be_dai_name_table[i].be_id;
4400 goto done;
4401 }
4402 }
4403 ALOGE("%s: no interface matching name %s\n", __func__, hw_interface_name);
4404 be_dai_id = -EINVAL;
4405 goto done;
4406
4407done:
4408 return be_dai_id;
4409}
4410
4411void platform_check_and_update_copp_sample_rate(void* platform, snd_device_t snd_device,
4412 unsigned int stream_sr, int* sample_rate)
4413{
4414 struct platform_data* my_data = (struct platform_data *)platform;
4415 int backend_idx = platform_get_backend_index(snd_device);
4416 int device_sr = my_data->current_backend_cfg[backend_idx].sample_rate;
4417 /*
4418 *Check if device SR is multiple of 8K or 11.025 Khz
4419 *check if the stream SR is multiple of same base, if yes
4420 *then have copp SR equal to stream SR, this ensures that
4421 *post processing happens at stream SR, else have
4422 *copp SR equal to device SR.
4423 */
4424 if (!(((sample_rate_multiple(device_sr, SAMPLE_RATE_8000)) &&
4425 (sample_rate_multiple(stream_sr, SAMPLE_RATE_8000))) ||
4426 ((sample_rate_multiple(device_sr, SAMPLE_RATE_11025)) &&
4427 (sample_rate_multiple(stream_sr, SAMPLE_RATE_11025))))) {
4428 *sample_rate = device_sr;
4429 } else
4430 *sample_rate = stream_sr;
4431
4432 ALOGI("sn_device %d device sr %d stream sr %d copp sr %d", snd_device, device_sr, stream_sr
4433 , *sample_rate);
4434
4435}
4436
4437// called from info parser
vivek mehtaa68fea62017-06-08 19:04:02 -07004438void platform_add_app_type(const char *uc_type,
4439 const char *mode,
4440 int bw,
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004441 int app_type, int max_rate) {
4442 struct app_type_entry *ap =
4443 (struct app_type_entry *)calloc(1, sizeof(struct app_type_entry));
4444
4445 if (!ap) {
4446 ALOGE("%s failed to allocate mem for app type", __func__);
4447 return;
4448 }
4449
4450 ap->uc_type = -1;
4451 for (int i=0; i<USECASE_TYPE_MAX; i++) {
4452 if (!strcmp(uc_type, usecase_type_index[i].name)) {
4453 ap->uc_type = usecase_type_index[i].index;
4454 break;
4455 }
4456 }
4457
4458 if (ap->uc_type == -1) {
4459 free(ap);
4460 return;
4461 }
4462
vivek mehtaa68fea62017-06-08 19:04:02 -07004463 ALOGI("%s uc %s mode %s bw %d app_type %d max_rate %d",
4464 __func__, uc_type, mode, bw, app_type, max_rate);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004465 ap->bit_width = bw;
4466 ap->app_type = app_type;
4467 ap->max_rate = max_rate;
vivek mehtaa68fea62017-06-08 19:04:02 -07004468 ap->mode = strdup(mode);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004469 list_add_tail(&app_type_entry_list, &ap->node);
4470}
4471
4472
4473int platform_get_default_app_type_v2(void *platform __unused,
4474 usecase_type_t type,
4475 int *app_type )
4476{
4477 if (type == PCM_PLAYBACK)
4478 *app_type = DEFAULT_APP_TYPE_RX_PATH;
4479 else
4480 *app_type = DEFAULT_APP_TYPE_TX_PATH;
4481 return 0;
4482}
4483
vivek mehtaa68fea62017-06-08 19:04:02 -07004484int platform_get_app_type_v2(void *platform,
4485 usecase_type_t uc_type,
4486 const char *mode,
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004487 int bw, int sr __unused,
4488 int *app_type)
4489{
4490 struct listnode *node;
4491 struct app_type_entry *entry;
4492 *app_type = -1;
vivek mehtaa68fea62017-06-08 19:04:02 -07004493
4494 ALOGV("%s find match for uc %d mode %s bw %d rate %d",
4495 __func__, uc_type, mode, bw, sr);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004496 list_for_each(node, &app_type_entry_list) {
4497 entry = node_to_item(node, struct app_type_entry, node);
vivek mehtaa68fea62017-06-08 19:04:02 -07004498 ALOGV("%s uc %d mode %s bw %d app_type %d max_rate %d",
4499 __func__, entry->uc_type, entry->mode, entry->bit_width,
4500 entry->app_type, entry->max_rate);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004501 if (entry->bit_width == bw &&
vivek mehtaa68fea62017-06-08 19:04:02 -07004502 entry->uc_type == uc_type &&
4503 sr <= entry->max_rate &&
4504 entry->mode && !strcmp(mode, entry->mode)) {
4505 ALOGV("%s found match %d", __func__, entry->app_type);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004506 *app_type = entry->app_type;
4507 break;
4508 }
4509 }
4510
4511 if (*app_type == -1) {
vivek mehtaa68fea62017-06-08 19:04:02 -07004512 ALOGV("%s no match found, return default", __func__);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004513 return platform_get_default_app_type_v2(platform, uc_type, app_type);
4514 }
4515 return 0;
4516}
vivek mehta90933872017-06-15 18:04:39 -07004517
4518int platform_set_sidetone(struct audio_device *adev,
4519 snd_device_t out_snd_device,
4520 bool enable, char *str)
4521{
4522 int ret;
4523 if (out_snd_device == SND_DEVICE_OUT_USB_HEADSET ||
4524 out_snd_device == SND_DEVICE_OUT_VOICE_USB_HEADSET) {
4525 ret = audio_extn_usb_enable_sidetone(out_snd_device, enable);
4526 if (ret)
4527 ALOGI("%s: usb device %d does not support device sidetone\n",
4528 __func__, out_snd_device);
4529 } else {
4530 ALOGV("%s: sidetone out device(%d) mixer cmd = %s\n",
4531 __func__, out_snd_device, str);
4532 if (enable)
4533 audio_route_apply_and_update_path(adev->audio_route, str);
4534 else
4535 audio_route_reset_and_update_path(adev->audio_route, str);
4536 }
4537 return 0;
4538}
Haynes Mathew George96483a22017-03-28 14:52:47 -07004539
4540int platform_get_mmap_data_fd(void *platform __unused, int fe_dev __unused, int dir __unused,
4541 int *fd __unused, uint32_t *size __unused)
4542{
Thierry Strudel07f96d12018-09-20 13:31:34 -07004543#if defined (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845) || (PLATFORM_SDM710) || (PLATFORM_SM8150)
Haynes Mathew George96483a22017-03-28 14:52:47 -07004544 struct platform_data *my_data = (struct platform_data *)platform;
4545 struct audio_device *adev = my_data->adev;
4546 int hw_fd = -1;
4547 char dev_name[128];
4548 struct snd_pcm_mmap_fd mmap_fd;
4549 memset(&mmap_fd, 0, sizeof(mmap_fd));
4550 mmap_fd.dir = dir;
4551 snprintf(dev_name, sizeof(dev_name), "/dev/snd/hwC%uD%u",
4552 adev->snd_card, HWDEP_FE_BASE+fe_dev);
4553 hw_fd = open(dev_name, O_RDONLY);
4554 if (hw_fd < 0) {
4555 ALOGE("fe hw dep node open %d/%d failed", adev->snd_card, fe_dev);
4556 return -1;
4557 }
4558 if (ioctl(hw_fd, SNDRV_PCM_IOCTL_MMAP_DATA_FD, &mmap_fd) < 0) {
4559 ALOGE("fe hw dep node ioctl failed");
4560 close(hw_fd);
4561 return -1;
4562 }
4563 *fd = mmap_fd.fd;
4564 *size = mmap_fd.size;
4565 close(hw_fd); // mmap_fd should still be valid
4566 return 0;
4567#else
4568 return -1;
4569#endif
4570}
Mikhail Naganov4ee6e3e2018-03-21 16:28:35 +00004571
4572bool platform_sound_trigger_usecase_needs_event(audio_usecase_t uc_id)
4573{
4574 bool needs_event = false;
4575
4576 switch (uc_id) {
4577 /* concurrent capture usecases which needs event */
4578 case USECASE_AUDIO_RECORD:
4579 case USECASE_AUDIO_RECORD_LOW_LATENCY:
4580 case USECASE_AUDIO_RECORD_MMAP:
4581 case USECASE_AUDIO_RECORD_HIFI:
4582 case USECASE_AUDIO_RECORD_VOIP:
4583 case USECASE_VOICEMMODE1_CALL:
4584 case USECASE_VOICEMMODE2_CALL:
4585 /* concurrent playback usecases that needs event */
4586 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
4587 case USECASE_AUDIO_PLAYBACK_OFFLOAD:
4588 needs_event = true;
4589 break;
4590 default:
4591 ALOGV("%s:usecase_id[%d] no need to raise event.", __func__, uc_id);
4592 }
4593 return needs_event;
4594}
4595
4596bool platform_snd_device_has_speaker(snd_device_t dev) {
4597 int num_devs = 2;
4598 snd_device_t split_devs[2] = {SND_DEVICE_NONE, SND_DEVICE_NONE};
4599 if (platform_can_split_snd_device(dev, &num_devs, split_devs) == 0) {
4600 return platform_snd_device_has_speaker(split_devs[0]) ||
4601 platform_snd_device_has_speaker(split_devs[1]);
4602 }
4603
4604 switch (dev) {
4605 case SND_DEVICE_OUT_SPEAKER:
4606 case SND_DEVICE_OUT_SPEAKER_SAFE:
4607 case SND_DEVICE_OUT_SPEAKER_REVERSE:
4608 case SND_DEVICE_OUT_SPEAKER_PROTECTED:
4609 case SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED:
4610 case SND_DEVICE_OUT_VOICE_SPEAKER_HFP:
4611 return true;
4612 default:
4613 break;
4614 }
4615 return false;
4616}
jiabin8962a4d2018-03-19 18:21:24 -07004617
4618bool platform_set_microphone_characteristic(void *platform,
4619 struct audio_microphone_characteristic_t mic) {
4620 struct platform_data *my_data = (struct platform_data *)platform;
4621 if (my_data->declared_mic_count >= AUDIO_MICROPHONE_MAX_COUNT) {
4622 ALOGE("mic number is more than maximum number");
4623 return false;
4624 }
4625 for (size_t ch = 0; ch < AUDIO_CHANNEL_COUNT_MAX; ch++) {
4626 mic.channel_mapping[ch] = AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED;
4627 }
4628 my_data->microphones[my_data->declared_mic_count++] = mic;
4629 return true;
4630}
4631
4632int platform_get_microphones(void *platform,
4633 struct audio_microphone_characteristic_t *mic_array,
4634 size_t *mic_count) {
4635 struct platform_data *my_data = (struct platform_data *)platform;
4636 if (mic_count == NULL) {
4637 return -EINVAL;
4638 }
4639 if (mic_array == NULL) {
4640 return -EINVAL;
4641 }
4642
4643 if (*mic_count == 0) {
4644 *mic_count = my_data->declared_mic_count;
4645 return 0;
4646 }
4647
4648 size_t max_mic_count = *mic_count;
4649 size_t actual_mic_count = 0;
4650 for (size_t i = 0; i < max_mic_count && i < my_data->declared_mic_count; i++) {
4651 mic_array[i] = my_data->microphones[i];
4652 actual_mic_count++;
4653 }
4654 *mic_count = actual_mic_count;
4655 return 0;
4656}
4657
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004658bool platform_set_microphone_map(void *platform, snd_device_t in_snd_device,
4659 const struct mic_info *info) {
4660 struct platform_data *my_data = (struct platform_data *)platform;
4661 if (in_snd_device < SND_DEVICE_IN_BEGIN || in_snd_device >= SND_DEVICE_IN_END) {
4662 ALOGE("%s: Sound device not valid", __func__);
4663 return false;
4664 }
4665 size_t m_count = my_data->mic_map[in_snd_device].mic_count++;
4666 if (m_count >= AUDIO_MICROPHONE_MAX_COUNT) {
4667 ALOGE("%s: Microphone count is greater than max allowed value", __func__);
4668 my_data->mic_map[in_snd_device].mic_count--;
4669 return false;
4670 }
4671 my_data->mic_map[in_snd_device].microphones[m_count] = *info;
4672 return true;
4673}
4674
4675int platform_get_active_microphones(void *platform, unsigned int channels,
4676 audio_usecase_t uc_id,
jiabin8962a4d2018-03-19 18:21:24 -07004677 struct audio_microphone_characteristic_t *mic_array,
4678 size_t *mic_count) {
4679 struct platform_data *my_data = (struct platform_data *)platform;
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004680 struct audio_usecase *usecase = get_usecase_from_list(my_data->adev, uc_id);
4681 if (mic_count == NULL || mic_array == NULL || usecase == NULL) {
jiabin8962a4d2018-03-19 18:21:24 -07004682 return -EINVAL;
4683 }
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004684 size_t max_mic_count = my_data->declared_mic_count;
jiabin8962a4d2018-03-19 18:21:24 -07004685 size_t actual_mic_count = 0;
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004686
4687 snd_device_t active_input_snd_device =
4688 platform_get_input_snd_device(platform, usecase->stream.in->device);
4689 if (active_input_snd_device == SND_DEVICE_NONE) {
4690 ALOGI("%s: No active microphones found", __func__);
4691 goto end;
4692 }
4693
4694 size_t active_mic_count = my_data->mic_map[active_input_snd_device].mic_count;
4695 struct mic_info *m_info = my_data->mic_map[active_input_snd_device].microphones;
4696
4697 for (size_t i = 0; i < active_mic_count; i++) {
4698 unsigned int channels_for_active_mic = channels;
4699 if (channels_for_active_mic > m_info[i].channel_count) {
4700 channels_for_active_mic = m_info[i].channel_count;
4701 }
4702 for (size_t j = 0; j < max_mic_count; j++) {
4703 if (strcmp(my_data->microphones[j].device_id,
4704 m_info[i].device_id) == 0) {
4705 mic_array[actual_mic_count] = my_data->microphones[j];
4706 for (size_t ch = 0; ch < channels_for_active_mic; ch++) {
4707 mic_array[actual_mic_count].channel_mapping[ch] =
4708 m_info[i].channel_mapping[ch];
4709 }
4710 actual_mic_count++;
4711 break;
jiabin8962a4d2018-03-19 18:21:24 -07004712 }
jiabin8962a4d2018-03-19 18:21:24 -07004713 }
4714 }
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004715end:
jiabin8962a4d2018-03-19 18:21:24 -07004716 *mic_count = actual_mic_count;
4717 return 0;
4718}
Haynes Mathew George65f6b432018-02-27 17:44:55 -08004719
4720int platform_set_usb_service_interval(void *platform,
4721 bool playback,
4722 unsigned long service_interval,
4723 bool *reconfig)
4724{
4725#if defined (USB_SERVICE_INTERVAL_ENABLED)
4726 struct platform_data *_platform = (struct platform_data *)platform;
4727 *reconfig = false;
4728 if (!playback) {
4729 ALOGE("%s not valid for capture", __func__);
4730 return -1;
4731 }
4732 const char *ctl_name = "USB_AUDIO_RX service_interval";
4733 struct mixer_ctl *ctl = mixer_get_ctl_by_name(_platform->adev->mixer,
4734 ctl_name);
4735 if (!ctl) {
4736 ALOGV("%s: could not get mixer %s", __func__, ctl_name);
4737 return -1;
4738 }
4739 if (mixer_ctl_get_value(ctl, 0) != (int)service_interval) {
4740 mixer_ctl_set_value(ctl, 0, service_interval);
4741 *reconfig = true;
4742 }
4743 return 0;
4744#else
4745 *reconfig = false;
4746 (void)platform;
4747 (void)playback;
4748 (void)service_interval;
4749 return -1;
4750#endif
4751}
4752
4753int platform_get_usb_service_interval(void *platform,
4754 bool playback,
4755 unsigned long *service_interval)
4756{
4757#if defined (USB_SERVICE_INTERVAL_ENABLED)
4758 struct platform_data *_platform = (struct platform_data *)platform;
4759 if (!playback) {
4760 ALOGE("%s not valid for capture", __func__);
4761 return -1;
4762 }
4763 const char *ctl_name = "USB_AUDIO_RX service_interval";
4764 struct mixer_ctl *ctl = mixer_get_ctl_by_name(_platform->adev->mixer,
4765 ctl_name);
4766 if (!ctl) {
4767 ALOGV("%s: could not get mixer %s", __func__, ctl_name);
4768 return -1;
4769 }
4770 *service_interval = mixer_ctl_get_value(ctl, 0);
4771 return 0;
4772#else
4773 (void)platform;
4774 (void)playback;
4775 (void)service_interval;
4776 return -1;
4777#endif
4778}
Ashish Jain1c849702018-05-11 20:11:55 +05304779
4780int platform_set_acdb_metainfo_key(void *platform __unused,
4781 char *name __unused,
4782 int key __unused)
4783{
4784 return -ENOSYS;
4785}