blob: d4b81701cf49aa99dbe665da4e7fc75297cfcbe0 [file] [log] [blame]
Eric Laurentb23d5282013-05-14 15:27:20 -07001/*
vivek mehtaa6b79742017-03-09 15:40:43 -08002 * Copyright (C) 2013-2017 The Android Open Source Project
Eric Laurentb23d5282013-05-14 15:27:20 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Eric Laurentb23d5282013-05-14 15:27:20 -070016#define LOG_TAG "msm8974_platform"
17/*#define LOG_NDEBUG 0*/
18#define LOG_NDDEBUG 0
19
20#include <stdlib.h>
21#include <dlfcn.h>
Jiyong Park6431fe62017-06-29 15:15:58 +090022#include <pthread.h>
23#include <unistd.h>
Haynes Mathew Georgee6e2d442018-02-22 18:51:56 -080024#include <log/log.h>
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -070025#include <cutils/str_parms.h>
Eric Laurentb23d5282013-05-14 15:27:20 -070026#include <cutils/properties.h>
27#include <audio_hw.h>
28#include <platform_api.h>
vivek mehta0fb11312017-05-15 19:35:32 -070029#include "acdb.h"
Eric Laurentb23d5282013-05-14 15:27:20 -070030#include "platform.h"
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -070031#include "audio_extn.h"
vivek mehta1a9b7c02015-06-25 11:49:38 -070032#include <linux/msm_audio.h>
Alexey Polyudove920d4b2017-09-15 17:09:07 -070033#if defined (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845)
Haynes Mathew George96483a22017-03-28 14:52:47 -070034#include <sound/devdep_params.h>
35#endif
Eric Laurentb23d5282013-05-14 15:27:20 -070036
jasmine cha270b7762018-03-30 15:41:33 +080037#include "maxxaudio.h"
jasmine chac89321b2018-04-10 21:37:01 +080038#include <resolv.h>
39
Jaekyun Seokf62e17d2017-03-08 17:15:28 +090040#define MIXER_XML_DEFAULT_PATH "mixer_paths.xml"
41#define MIXER_XML_BASE_STRING "mixer_paths"
vivek mehta60ea4152016-02-18 17:10:26 -080042#define TOMTOM_8226_SND_CARD_NAME "msm8226-tomtom-snd-card"
43#define TOMTOM_MIXER_FILE_SUFFIX "wcd9330"
44
Eric Laurentb23d5282013-05-14 15:27:20 -070045#define LIB_ACDB_LOADER "libacdbloader.so"
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -070046#define AUDIO_DATA_BLOCK_MIXER_CTL "HDMI EDID"
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +090047#define CVD_VERSION_MIXER_CTL "CVD Version"
Eric Laurentb23d5282013-05-14 15:27:20 -070048
Eric Laurentf9583c32016-03-28 13:50:50 -070049#define min(a, b) ((a) < (b) ? (a) : (b))
Eric Laurentb23d5282013-05-14 15:27:20 -070050
51/*
Eric Laurentb23d5282013-05-14 15:27:20 -070052 * This file will have a maximum of 38 bytes:
53 *
54 * 4 bytes: number of audio blocks
55 * 4 bytes: total length of Short Audio Descriptor (SAD) blocks
56 * Maximum 10 * 3 bytes: SAD blocks
57 */
58#define MAX_SAD_BLOCKS 10
59#define SAD_BLOCK_SIZE 3
60
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +090061#define MAX_CVD_VERSION_STRING_SIZE 100
62
Eric Laurentb23d5282013-05-14 15:27:20 -070063/* EDID format ID for LPCM audio */
64#define EDID_FORMAT_LPCM 1
65
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -070066#define MAX_SND_CARD_NAME_LEN 31
67
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -080068#define DEFAULT_APP_TYPE_RX_PATH 69936
69#define DEFAULT_APP_TYPE_TX_PATH 69938
Haynes Mathew George39c55dc2017-07-11 19:31:23 -070070#define DEFAULT_RX_BACKEND "SLIMBUS_0_RX"
vivek mehta1a9b7c02015-06-25 11:49:38 -070071
keunhui.parkc5aaa0e2015-07-13 10:57:37 +090072#define TOSTRING_(x) #x
73#define TOSTRING(x) TOSTRING_(x)
74
Eric Laurentb23d5282013-05-14 15:27:20 -070075struct audio_block_header
76{
77 int reserved;
78 int length;
79};
80
vivek mehta1a9b7c02015-06-25 11:49:38 -070081enum {
82 CAL_MODE_SEND = 0x1,
83 CAL_MODE_PERSIST = 0x2,
84 CAL_MODE_RTAC = 0x4
85};
86
keunhui.park2f7306a2015-07-16 16:48:06 +090087#define PLATFORM_CONFIG_KEY_OPERATOR_INFO "operator_info"
88
89struct operator_info {
90 struct listnode list;
91 char *name;
92 char *mccmnc;
93};
94
95struct operator_specific_device {
96 struct listnode list;
97 char *operator;
98 char *mixer_path;
99 int acdb_id;
100};
101
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800102#define BE_DAI_NAME_MAX_LENGTH 24
103struct be_dai_name_struct {
104 unsigned int be_id;
105 char be_name[BE_DAI_NAME_MAX_LENGTH];
106};
107
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -0700108struct snd_device_to_mic_map {
109 struct mic_info microphones[AUDIO_MICROPHONE_MAX_COUNT];
110 size_t mic_count;
111};
112
keunhui.park2f7306a2015-07-16 16:48:06 +0900113static struct listnode operator_info_list;
114static struct listnode *operator_specific_device_table[SND_DEVICE_MAX];
115
jasmine chac89321b2018-04-10 21:37:01 +0800116#define AUDIO_PARAMETER_KEY_AUD_CALDATA "cal_data"
117
118typedef struct acdb_audio_cal_cfg {
119 uint32_t persist;
120 uint32_t snd_dev_id;
121 audio_devices_t dev_id;
122 int32_t acdb_dev_id;
123 uint32_t app_type;
124 uint32_t topo_id;
125 uint32_t sampling_rate;
126 uint32_t cal_type;
127 uint32_t module_id;
128 uint32_t param_id;
129} acdb_audio_cal_cfg_t;
130
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700131/* Audio calibration related functions */
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800132typedef void (*acdb_send_audio_cal_v3_t)(int, int, int, int, int);
Eric Laurentb23d5282013-05-14 15:27:20 -0700133
Eric Laurentb23d5282013-05-14 15:27:20 -0700134struct platform_data {
135 struct audio_device *adev;
136 bool fluence_in_spkr_mode;
137 bool fluence_in_voice_call;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700138 bool fluence_in_voice_comm;
Eric Laurentb23d5282013-05-14 15:27:20 -0700139 bool fluence_in_voice_rec;
Prashant Malanic92c5962015-08-11 15:10:18 -0700140 /* 0 = no fluence, 1 = fluence, 2 = fluence pro */
141 int fluence_type;
142 int source_mic_type;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -0700143 bool speaker_lr_swap;
144
Eric Laurentb23d5282013-05-14 15:27:20 -0700145 void *acdb_handle;
Alexey Polyudove920d4b2017-09-15 17:09:07 -0700146#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -0700147 acdb_init_v2_cvd_t acdb_init;
148#elif defined (PLATFORM_MSM8084)
149 acdb_init_v2_t acdb_init;
150#else
151 acdb_init_t acdb_init;
152#endif
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700153 acdb_deallocate_t acdb_deallocate;
154 acdb_send_audio_cal_t acdb_send_audio_cal;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800155 acdb_send_audio_cal_v3_t acdb_send_audio_cal_v3;
jasmine chac89321b2018-04-10 21:37:01 +0800156 acdb_set_audio_cal_t acdb_set_audio_cal;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700157 acdb_send_voice_cal_t acdb_send_voice_cal;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700158 acdb_reload_vocvoltable_t acdb_reload_vocvoltable;
vivek mehta1a9b7c02015-06-25 11:49:38 -0700159 acdb_send_gain_dep_cal_t acdb_send_gain_dep_cal;
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -0700160 acdb_send_custom_top_t acdb_send_custom_top;
161 bool acdb_initialized;
162
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700163 struct csd_data *csd;
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800164 char ec_ref_mixer_path[64];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700165
David Linee3fe402017-03-13 10:00:42 -0700166 codec_backend_cfg_t current_backend_cfg[MAX_CODEC_BACKENDS];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700167 char *snd_card_name;
keunhui.parkc5aaa0e2015-07-13 10:57:37 +0900168 int max_vol_index;
Prashant Malanic92c5962015-08-11 15:10:18 -0700169 int max_mic_count;
vivek mehtade4849c2016-03-03 17:23:38 -0800170
171 void *hw_info;
jiabin8962a4d2018-03-19 18:21:24 -0700172
173 uint32_t declared_mic_count;
174 struct audio_microphone_characteristic_t microphones[AUDIO_MICROPHONE_MAX_COUNT];
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -0700175 struct snd_device_to_mic_map mic_map[SND_DEVICE_MAX];
Eric Laurentb23d5282013-05-14 15:27:20 -0700176};
177
Haynes Mathew George98c95622014-06-20 19:14:25 -0700178static int pcm_device_table[AUDIO_USECASE_MAX][2] = {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700179 [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = {DEEP_BUFFER_PCM_DEVICE,
180 DEEP_BUFFER_PCM_DEVICE},
181 [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
182 LOWLATENCY_PCM_DEVICE},
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800183 [USECASE_AUDIO_PLAYBACK_HIFI] = {MULTIMEDIA2_PCM_DEVICE,
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700184 MULTIMEDIA2_PCM_DEVICE},
185 [USECASE_AUDIO_PLAYBACK_OFFLOAD] = {PLAYBACK_OFFLOAD_DEVICE,
186 PLAYBACK_OFFLOAD_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700187 [USECASE_AUDIO_PLAYBACK_TTS] = {MULTIMEDIA2_PCM_DEVICE,
188 MULTIMEDIA2_PCM_DEVICE},
189 [USECASE_AUDIO_PLAYBACK_ULL] = {MULTIMEDIA3_PCM_DEVICE,
190 MULTIMEDIA3_PCM_DEVICE},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800191 [USECASE_AUDIO_PLAYBACK_MMAP] = {MMAP_PLAYBACK_PCM_DEVICE,
192 MMAP_PLAYBACK_PCM_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700193
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700194 [USECASE_AUDIO_RECORD] = {AUDIO_RECORD_PCM_DEVICE,
195 AUDIO_RECORD_PCM_DEVICE},
196 [USECASE_AUDIO_RECORD_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
197 LOWLATENCY_PCM_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700198
Eric Laurent0e46adf2016-12-16 12:49:24 -0800199 [USECASE_AUDIO_RECORD_MMAP] = {MMAP_RECORD_PCM_DEVICE,
200 MMAP_RECORD_PCM_DEVICE},
Haynes Mathew George569b7482017-05-08 14:44:27 -0700201 [USECASE_AUDIO_RECORD_HIFI] = {MULTIMEDIA2_PCM_DEVICE,
202 MULTIMEDIA2_PCM_DEVICE},
203
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700204 [USECASE_VOICE_CALL] = {VOICE_CALL_PCM_DEVICE,
205 VOICE_CALL_PCM_DEVICE},
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700206 [USECASE_VOICE2_CALL] = {VOICE2_CALL_PCM_DEVICE, VOICE2_CALL_PCM_DEVICE},
207 [USECASE_VOLTE_CALL] = {VOLTE_CALL_PCM_DEVICE, VOLTE_CALL_PCM_DEVICE},
208 [USECASE_QCHAT_CALL] = {QCHAT_CALL_PCM_DEVICE, QCHAT_CALL_PCM_DEVICE},
209 [USECASE_VOWLAN_CALL] = {VOWLAN_CALL_PCM_DEVICE, VOWLAN_CALL_PCM_DEVICE},
vivek mehtaa51fd402016-02-04 19:49:33 -0800210 [USECASE_VOICEMMODE1_CALL] = {VOICEMMODE1_CALL_PCM_DEVICE,
211 VOICEMMODE1_CALL_PCM_DEVICE},
212 [USECASE_VOICEMMODE2_CALL] = {VOICEMMODE2_CALL_PCM_DEVICE,
213 VOICEMMODE2_CALL_PCM_DEVICE},
214
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700215 [USECASE_INCALL_REC_UPLINK] = {AUDIO_RECORD_PCM_DEVICE,
216 AUDIO_RECORD_PCM_DEVICE},
217 [USECASE_INCALL_REC_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
218 AUDIO_RECORD_PCM_DEVICE},
219 [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
220 AUDIO_RECORD_PCM_DEVICE},
Ravi Kumar Alamanda8e6e98f2013-11-05 15:57:39 -0800221 [USECASE_AUDIO_HFP_SCO] = {HFP_PCM_RX, HFP_SCO_RX},
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700222
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700223 [USECASE_AUDIO_SPKR_CALIB_RX] = {SPKR_PROT_CALIB_RX_PCM_DEVICE, -1},
224 [USECASE_AUDIO_SPKR_CALIB_TX] = {-1, SPKR_PROT_CALIB_TX_PCM_DEVICE},
225
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700226 [USECASE_AUDIO_PLAYBACK_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
227 AFE_PROXY_RECORD_PCM_DEVICE},
228 [USECASE_AUDIO_RECORD_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
229 AFE_PROXY_RECORD_PCM_DEVICE},
zhaoyang yin4211fad2015-06-04 21:13:25 +0800230 [USECASE_AUDIO_DSM_FEEDBACK] = {QUAT_MI2S_PCM_DEVICE, QUAT_MI2S_PCM_DEVICE},
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700231
vivek mehtaa68fea62017-06-08 19:04:02 -0700232 [USECASE_AUDIO_PLAYBACK_VOIP] = {AUDIO_PLAYBACK_VOIP_PCM_DEVICE,
233 AUDIO_PLAYBACK_VOIP_PCM_DEVICE},
234 [USECASE_AUDIO_RECORD_VOIP] = {AUDIO_RECORD_VOIP_PCM_DEVICE,
235 AUDIO_RECORD_VOIP_PCM_DEVICE},
Nadav Bar3d72cfc2018-01-07 12:19:24 +0200236
237 [USECASE_INCALL_MUSIC_UPLINK] = {INCALL_MUSIC_UPLINK_PCM_DEVICE,
238 INCALL_MUSIC_UPLINK_PCM_DEVICE},
Eric Laurentb23d5282013-05-14 15:27:20 -0700239};
240
241/* Array to store sound devices */
242static const char * const device_table[SND_DEVICE_MAX] = {
243 [SND_DEVICE_NONE] = "none",
244 /* Playback sound devices */
245 [SND_DEVICE_OUT_HANDSET] = "handset",
246 [SND_DEVICE_OUT_SPEAKER] = "speaker",
247 [SND_DEVICE_OUT_SPEAKER_REVERSE] = "speaker-reverse",
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700248 [SND_DEVICE_OUT_SPEAKER_SAFE] = "speaker-safe",
Eric Laurentb23d5282013-05-14 15:27:20 -0700249 [SND_DEVICE_OUT_HEADPHONES] = "headphones",
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500250 [SND_DEVICE_OUT_LINE] = "line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700251 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones",
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700252 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = "speaker-safe-and-headphones",
Eric Laurent744996b2014-10-01 11:40:40 -0500253 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = "speaker-and-line",
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700254 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = "speaker-safe-and-line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700255 [SND_DEVICE_OUT_VOICE_HANDSET] = "voice-handset",
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500256 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = "voice-hac-handset",
Eric Laurentb23d5282013-05-14 15:27:20 -0700257 [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker",
258 [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones",
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500259 [SND_DEVICE_OUT_VOICE_LINE] = "voice-line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700260 [SND_DEVICE_OUT_HDMI] = "hdmi",
261 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi",
262 [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700263 [SND_DEVICE_OUT_BT_SCO_WB] = "bt-sco-headset-wb",
Aniket Kumar Lata26483012018-01-31 20:21:42 -0800264 [SND_DEVICE_OUT_BT_A2DP] = "bt-a2dp",
265 [SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] = "speaker-and-bt-a2dp",
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",
David Linee3fe402017-03-13 10:00:42 -0700274 [SND_DEVICE_OUT_USB_HEADSET] = "usb-headset",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700275 [SND_DEVICE_OUT_VOICE_USB_HEADSET] = "usb-headset",
David Linee3fe402017-03-13 10:00:42 -0700276 [SND_DEVICE_OUT_USB_HEADPHONES] = "usb-headphones",
jasmine cha270b7762018-03-30 15:41:33 +0800277 [SND_DEVICE_OUT_USB_HEADSET_SPEC] = "usb-headset",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700278 [SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = "usb-headphones",
David Linee3fe402017-03-13 10:00:42 -0700279 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = "speaker-and-usb-headphones",
Haynes Mathew George9090bfb2017-05-31 11:44:50 -0700280 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] = "speaker-safe-and-usb-headphones",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700281 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = "speaker-protected",
282 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = "voice-speaker-protected",
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -0700283 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = "voice-speaker-hfp",
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -0800284 [SND_DEVICE_OUT_SPEAKER_AND_BT_SCO] = "speaker-and-bt-sco",
285 [SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB] = "speaker-and-bt-sco-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700286
287 /* Capture sound devices */
288 [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700289 [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700290 [SND_DEVICE_IN_HANDSET_MIC_NS] = "handset-mic",
291 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = "handset-mic",
292 [SND_DEVICE_IN_HANDSET_DMIC] = "dmic-endfire",
293 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = "dmic-endfire",
294 [SND_DEVICE_IN_HANDSET_DMIC_NS] = "dmic-endfire",
295 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = "dmic-endfire",
296 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = "dmic-endfire",
297
298 [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
299 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "speaker-mic",
300 [SND_DEVICE_IN_SPEAKER_MIC_NS] = "speaker-mic",
301 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = "speaker-mic",
302 [SND_DEVICE_IN_SPEAKER_DMIC] = "speaker-dmic-endfire",
303 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = "speaker-dmic-endfire",
304 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = "speaker-dmic-endfire",
305 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = "speaker-dmic-endfire",
306 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = "speaker-dmic-endfire",
307
308 [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
Eric Laurentcefbbac2014-09-04 13:54:10 -0500309 [SND_DEVICE_IN_HEADSET_MIC_AEC] = "headset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700310
Eric Laurentb23d5282013-05-14 15:27:20 -0700311 [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic",
312 [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700313 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = "bt-sco-mic",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700314 [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700315 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = "bt-sco-mic-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700316 [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700317
318 [SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef",
319 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = "voice-dmic-ef-tmus",
320 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
321 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = "voice-speaker-dmic-ef",
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -0700322 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = "voice-speaker-mic-hfp",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700323 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700324 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
325 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
326 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
vivek mehtaa6b79742017-03-09 15:40:43 -0800327 [SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = "voice-tty-full-usb-mic",
328 [SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = "voice-tty-hco-usb-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700329
Eric Laurentb23d5282013-05-14 15:27:20 -0700330 [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700331 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = "voice-rec-mic",
vivek mehta733c1df2016-04-04 15:09:24 -0700332 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = "voice-rec-mic",
vivek mehtaf3440682016-05-11 14:24:37 -0700333 [SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700334 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = "voice-rec-dmic-ef",
335 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence",
David Linee3fe402017-03-13 10:00:42 -0700336 [SND_DEVICE_IN_USB_HEADSET_MIC] = "usb-headset-mic",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700337 [SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] ="usb-headset-mic",
338 [SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = "usb-headset-mic",
339 [SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = "usb-headset-mic",
340 [SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = "usb-headset-mic",
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700341 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = "headset-mic",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700342
Ricardo Garcia9034bc42016-04-04 07:11:46 -0700343 [SND_DEVICE_IN_UNPROCESSED_MIC] = "unprocessed-mic",
vivek mehta0125e782016-06-16 18:03:11 -0700344 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = "unprocessed-stereo-mic",
345 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = "unprocessed-three-mic",
346 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = "unprocessed-quad-mic",
347 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = "unprocessed-headset-mic",
rago90fb9612015-12-02 11:37:53 -0800348
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700349 [SND_DEVICE_IN_VOICE_RX] = "voice-rx",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700350
Prashant Malanic92c5962015-08-11 15:10:18 -0700351 [SND_DEVICE_IN_THREE_MIC] = "three-mic",
352 [SND_DEVICE_IN_QUAD_MIC] = "quad-mic",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700353 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = "vi-feedback",
Prashant Malanic92c5962015-08-11 15:10:18 -0700354 [SND_DEVICE_IN_HANDSET_TMIC] = "three-mic",
355 [SND_DEVICE_IN_HANDSET_QMIC] = "quad-mic",
vivek mehta733c1df2016-04-04 15:09:24 -0700356 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = "three-mic",
357 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = "quad-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700358};
359
360/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700361static int acdb_device_table[SND_DEVICE_MAX] = {
Eric Laurentb23d5282013-05-14 15:27:20 -0700362 [SND_DEVICE_NONE] = -1,
363 [SND_DEVICE_OUT_HANDSET] = 7,
364 [SND_DEVICE_OUT_SPEAKER] = 15,
365 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 15,
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700366 [SND_DEVICE_OUT_SPEAKER_SAFE] = 15,
Eric Laurentb23d5282013-05-14 15:27:20 -0700367 [SND_DEVICE_OUT_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500368 [SND_DEVICE_OUT_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700369 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700370 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500371 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = 77,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700372 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = 77,
Ravi Kumar Alamanda235c3482014-08-21 17:32:44 -0700373 [SND_DEVICE_OUT_VOICE_HANDSET] = ACDB_ID_VOICE_HANDSET,
374 [SND_DEVICE_OUT_VOICE_SPEAKER] = ACDB_ID_VOICE_SPEAKER,
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500375 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = 53,
Eric Laurentb23d5282013-05-14 15:27:20 -0700376 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500377 [SND_DEVICE_OUT_VOICE_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700378 [SND_DEVICE_OUT_HDMI] = 18,
379 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 15,
380 [SND_DEVICE_OUT_BT_SCO] = 22,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700381 [SND_DEVICE_OUT_BT_SCO_WB] = 39,
Aniket Kumar Lata26483012018-01-31 20:21:42 -0800382 [SND_DEVICE_OUT_BT_A2DP] = 20,
383 [SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] = 14,
Aniket Kumar Lata9723a962018-05-16 17:41:55 -0700384 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP] = 14,
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700385 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = ACDB_ID_VOICE_HANDSET_TMUS,
Eric Laurentb23d5282013-05-14 15:27:20 -0700386 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
387 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
388 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
vivek mehtaa6b79742017-03-09 15:40:43 -0800389 [SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = 17,
390 [SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = 17,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700391 [SND_DEVICE_OUT_VOICE_TX] = 45,
David Linee3fe402017-03-13 10:00:42 -0700392 [SND_DEVICE_OUT_USB_HEADSET] = 45,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700393 [SND_DEVICE_OUT_VOICE_USB_HEADSET] = 45,
David Linee3fe402017-03-13 10:00:42 -0700394 [SND_DEVICE_OUT_USB_HEADPHONES] = 45,
jasmine cha270b7762018-03-30 15:41:33 +0800395 [SND_DEVICE_OUT_USB_HEADSET_SPEC] = 45,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700396 [SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = 45,
David Linee3fe402017-03-13 10:00:42 -0700397 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = 14,
Haynes Mathew George9090bfb2017-05-31 11:44:50 -0700398 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] = 14,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700399 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = 124,
400 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = 101,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700401 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = ACDB_ID_VOICE_SPEAKER,
Eric Laurentb23d5282013-05-14 15:27:20 -0700402
403 [SND_DEVICE_IN_HANDSET_MIC] = 4,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700404 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 106,
405 [SND_DEVICE_IN_HANDSET_MIC_NS] = 107,
406 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = 108,
407 [SND_DEVICE_IN_HANDSET_DMIC] = 41,
408 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = 109,
409 [SND_DEVICE_IN_HANDSET_DMIC_NS] = 110,
410 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = 111,
411 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = 34,
412
413 [SND_DEVICE_IN_SPEAKER_MIC] = 11,
414 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 112,
415 [SND_DEVICE_IN_SPEAKER_MIC_NS] = 113,
416 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = 114,
417 [SND_DEVICE_IN_SPEAKER_DMIC] = 43,
418 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = 115,
419 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = 116,
420 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = 117,
421 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = 35,
422
rago90fb9612015-12-02 11:37:53 -0800423 [SND_DEVICE_IN_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentcefbbac2014-09-04 13:54:10 -0500424 [SND_DEVICE_IN_HEADSET_MIC_AEC] = ACDB_ID_HEADSET_MIC_AEC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700425
Eric Laurentb23d5282013-05-14 15:27:20 -0700426 [SND_DEVICE_IN_HDMI_MIC] = 4,
427 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700428 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = 21,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700429 [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700430 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = 38,
Eric Laurentb23d5282013-05-14 15:27:20 -0700431 [SND_DEVICE_IN_CAMCORDER_MIC] = 61,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700432
433 [SND_DEVICE_IN_VOICE_DMIC] = 41,
434 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = ACDB_ID_VOICE_DMIC_EF_TMUS,
435 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700436 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = 11,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700437 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 43,
rago90fb9612015-12-02 11:37:53 -0800438 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentb23d5282013-05-14 15:27:20 -0700439 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
440 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
441 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
vivek mehtaa6b79742017-03-09 15:40:43 -0800442 [SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = 16,
443 [SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = 16,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700444
rago90fb9612015-12-02 11:37:53 -0800445 [SND_DEVICE_IN_VOICE_REC_MIC] = ACDB_ID_VOICE_REC_MIC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700446 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = 113,
vivek mehta733c1df2016-04-04 15:09:24 -0700447 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = 112,
vivek mehtaf3440682016-05-11 14:24:37 -0700448 [SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = 114,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700449 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = 35,
450 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 43,
rago90fb9612015-12-02 11:37:53 -0800451 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
452
453 [SND_DEVICE_IN_UNPROCESSED_MIC] = ACDB_ID_VOICE_REC_MIC,
454 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
vivek mehta4ed66e62016-04-15 23:33:34 -0700455 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = 35,
456 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = 125,
457 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = 125,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700458
459 [SND_DEVICE_IN_VOICE_RX] = 44,
David Linee3fe402017-03-13 10:00:42 -0700460 [SND_DEVICE_IN_USB_HEADSET_MIC] = 44,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700461 [SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = 44,
462 [SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = 44,
463 [SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = 44,
464 [SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = 44,
Prashant Malanic92c5962015-08-11 15:10:18 -0700465 [SND_DEVICE_IN_THREE_MIC] = 46,
466 [SND_DEVICE_IN_QUAD_MIC] = 46,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700467 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = 102,
Prashant Malanic92c5962015-08-11 15:10:18 -0700468 [SND_DEVICE_IN_HANDSET_TMIC] = 125,
469 [SND_DEVICE_IN_HANDSET_QMIC] = 125,
vivek mehta733c1df2016-04-04 15:09:24 -0700470 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = 125, /* override this for new target to 140 */
471 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = 125, /* override this for new target to 140 */
Eric Laurentb23d5282013-05-14 15:27:20 -0700472};
473
David Linee3fe402017-03-13 10:00:42 -0700474// Platform specific backend bit width table
475static int backend_bit_width_table[SND_DEVICE_MAX] = {0};
476
Haynes Mathew George98c95622014-06-20 19:14:25 -0700477struct name_to_index {
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700478 char name[100];
479 unsigned int index;
480};
481
482#define TO_NAME_INDEX(X) #X, X
483
Haynes Mathew George98c95622014-06-20 19:14:25 -0700484/* Used to get index from parsed string */
485static const struct name_to_index snd_device_name_index[SND_DEVICE_MAX] = {
486 /* out */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700487 {TO_NAME_INDEX(SND_DEVICE_OUT_HANDSET)},
488 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER)},
489 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_REVERSE)},
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700490 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700491 {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500492 {TO_NAME_INDEX(SND_DEVICE_OUT_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700493 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700494 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES)},
Eric Laurent744996b2014-10-01 11:40:40 -0500495 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_LINE)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700496 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700497 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET)},
498 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700499 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_HFP)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700500 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500501 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700502 {TO_NAME_INDEX(SND_DEVICE_OUT_HDMI)},
503 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HDMI)},
504 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO)},
505 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO_WB)},
Aniket Kumar Lata26483012018-01-31 20:21:42 -0800506 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_A2DP)},
507 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP)},
Aniket Kumar Lata9723a962018-05-16 17:41:55 -0700508 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700509 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET_TMUS)},
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500510 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HAC_HANDSET)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700511 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES)},
512 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES)},
513 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET)},
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -0800514 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_SCO)},
515 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800516 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_USB)},
517 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_USB)},
David Linee3fe402017-03-13 10:00:42 -0700518 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADSET)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700519 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_USB_HEADSET)},
David Linee3fe402017-03-13 10:00:42 -0700520 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADPHONES)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700521 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_USB_HEADPHONES)},
David Linee3fe402017-03-13 10:00:42 -0700522 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET)},
Haynes Mathew George9090bfb2017-05-31 11:44:50 -0700523 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700524 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED)},
525 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED)},
jasmine cha270b7762018-03-30 15:41:33 +0800526 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADSET_SPEC)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800527
528 /* in */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700529 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700530 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700531 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_NS)},
532 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)},
533 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC)},
534 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC)},
535 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_NS)},
536 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)},
537 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_STEREO)},
538
539 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700540 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700541 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_NS)},
542 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)},
543 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC)},
544 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC)},
545 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS)},
546 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)},
547 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_STEREO)},
548
549 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC)},
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700550 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700551
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700552 {TO_NAME_INDEX(SND_DEVICE_IN_HDMI_MIC)},
553 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700554 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700555 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700556 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700557 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700558
559 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC)},
560 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC_TMUS)},
561 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700562 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700563 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC)},
564 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEADSET_MIC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700565 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC)},
566 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC)},
567 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800568 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC)},
569 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC)},
570
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700571
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700572 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700573 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_NS)},
vivek mehta733c1df2016-04-04 15:09:24 -0700574 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC)},
vivek mehtaf3440682016-05-11 14:24:37 -0700575 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700576 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_STEREO)},
577 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE)},
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700578 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_HEADSET_MIC)},
David Linee3fe402017-03-13 10:00:42 -0700579 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700580 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_USB_HEADSET_MIC)},
581 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC)},
582 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC)},
583 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC_AEC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700584
rago90fb9612015-12-02 11:37:53 -0800585 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_MIC)},
586 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC)},
vivek mehta4ed66e62016-04-15 23:33:34 -0700587 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_STEREO_MIC)},
588 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_THREE_MIC)},
589 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_QUAD_MIC)},
rago90fb9612015-12-02 11:37:53 -0800590
Prashant Malanic92c5962015-08-11 15:10:18 -0700591 {TO_NAME_INDEX(SND_DEVICE_IN_THREE_MIC)},
592 {TO_NAME_INDEX(SND_DEVICE_IN_QUAD_MIC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700593 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_VI_FEEDBACK)},
Prashant Malanic92c5962015-08-11 15:10:18 -0700594 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC)},
595 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC)},
vivek mehta733c1df2016-04-04 15:09:24 -0700596 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC_AEC)},
597 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC_AEC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700598};
599
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700600static char * backend_tag_table[SND_DEVICE_MAX] = {0};
601static char * hw_interface_table[SND_DEVICE_MAX] = {0};
Haynes Mathew George98c95622014-06-20 19:14:25 -0700602
603static const struct name_to_index usecase_name_index[AUDIO_USECASE_MAX] = {
604 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_DEEP_BUFFER)},
605 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_LOW_LATENCY)},
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800606 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_HIFI)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700607 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD)},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700608 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_TTS)},
609 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_ULL)},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800610 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_MMAP)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700611 {TO_NAME_INDEX(USECASE_AUDIO_RECORD)},
612 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_LOW_LATENCY)},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800613 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_MMAP)},
Haynes Mathew George569b7482017-05-08 14:44:27 -0700614 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_HIFI)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700615 {TO_NAME_INDEX(USECASE_VOICE_CALL)},
616 {TO_NAME_INDEX(USECASE_VOICE2_CALL)},
617 {TO_NAME_INDEX(USECASE_VOLTE_CALL)},
618 {TO_NAME_INDEX(USECASE_QCHAT_CALL)},
619 {TO_NAME_INDEX(USECASE_VOWLAN_CALL)},
John Muirf1346ce2016-12-06 00:03:41 -0800620 {TO_NAME_INDEX(USECASE_VOICEMMODE1_CALL)},
621 {TO_NAME_INDEX(USECASE_VOICEMMODE2_CALL)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700622 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK)},
623 {TO_NAME_INDEX(USECASE_INCALL_REC_DOWNLINK)},
624 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK_AND_DOWNLINK)},
625 {TO_NAME_INDEX(USECASE_AUDIO_HFP_SCO)},
John Muirf1346ce2016-12-06 00:03:41 -0800626 {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_RX)},
627 {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_TX)},
628 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_AFE_PROXY)},
629 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_AFE_PROXY)},
630 {TO_NAME_INDEX(USECASE_AUDIO_DSM_FEEDBACK)},
vivek mehtaa68fea62017-06-08 19:04:02 -0700631 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_VOIP)},
632 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_VOIP)},
Nadav Bar3d72cfc2018-01-07 12:19:24 +0200633 {TO_NAME_INDEX(USECASE_INCALL_MUSIC_UPLINK)},
Aniket Kumar Lata99546312018-03-19 21:38:38 -0700634 {TO_NAME_INDEX(USECASE_AUDIO_A2DP_ABR_FEEDBACK)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700635};
636
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800637static const struct name_to_index usecase_type_index[USECASE_TYPE_MAX] = {
638 {TO_NAME_INDEX(PCM_PLAYBACK)},
639 {TO_NAME_INDEX(PCM_CAPTURE)},
640 {TO_NAME_INDEX(VOICE_CALL)},
641 {TO_NAME_INDEX(PCM_HFP_CALL)},
642};
643
644struct app_type_entry {
645 int uc_type;
646 int bit_width;
647 int app_type;
648 int max_rate;
vivek mehtaa68fea62017-06-08 19:04:02 -0700649 char *mode;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800650 struct listnode node; // membership in app_type_entry_list;
651};
652
653static struct listnode app_type_entry_list;
654
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700655#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
656#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
Eric Laurent0e46adf2016-12-16 12:49:24 -0800657#define ULL_PLATFORM_DELAY (3*1000LL)
658#define MMAP_PLATFORM_DELAY (3*1000LL)
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700659
Eric Laurentb23d5282013-05-14 15:27:20 -0700660static pthread_once_t check_op_once_ctl = PTHREAD_ONCE_INIT;
661static bool is_tmus = false;
662
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800663static int init_be_dai_name_table(struct audio_device *adev);
664
Eric Laurentb23d5282013-05-14 15:27:20 -0700665static void check_operator()
666{
667 char value[PROPERTY_VALUE_MAX];
668 int mccmnc;
669 property_get("gsm.sim.operator.numeric",value,"0");
670 mccmnc = atoi(value);
Eric Laurent2bafff12016-03-17 12:17:23 -0700671 ALOGD("%s: tmus mccmnc %d", __func__, mccmnc);
Eric Laurentb23d5282013-05-14 15:27:20 -0700672 switch(mccmnc) {
673 /* TMUS MCC(310), MNC(490, 260, 026) */
674 case 310490:
675 case 310260:
676 case 310026:
sangwon.jeonb891db52013-09-14 17:39:15 +0900677 /* Add new TMUS MNC(800, 660, 580, 310, 270, 250, 240, 230, 220, 210, 200, 160) */
678 case 310800:
679 case 310660:
680 case 310580:
681 case 310310:
682 case 310270:
683 case 310250:
684 case 310240:
685 case 310230:
686 case 310220:
687 case 310210:
688 case 310200:
689 case 310160:
Eric Laurentb23d5282013-05-14 15:27:20 -0700690 is_tmus = true;
691 break;
692 }
693}
694
695bool is_operator_tmus()
696{
697 pthread_once(&check_op_once_ctl, check_operator);
698 return is_tmus;
699}
700
keunhui.park2f7306a2015-07-16 16:48:06 +0900701static char *get_current_operator()
702{
703 struct listnode *node;
704 struct operator_info *info_item;
705 char mccmnc[PROPERTY_VALUE_MAX];
706 char *ret = NULL;
707
Tom Cherry7fea2042016-11-10 18:05:59 -0800708 property_get("gsm.sim.operator.numeric",mccmnc,"00000");
keunhui.park2f7306a2015-07-16 16:48:06 +0900709
710 list_for_each(node, &operator_info_list) {
711 info_item = node_to_item(node, struct operator_info, list);
712 if (strstr(info_item->mccmnc, mccmnc) != NULL) {
713 ret = info_item->name;
714 }
715 }
716
717 return ret;
718}
719
720static struct operator_specific_device *get_operator_specific_device(snd_device_t snd_device)
721{
722 struct listnode *node;
723 struct operator_specific_device *ret = NULL;
724 struct operator_specific_device *device_item;
725 char *operator_name;
726
727 operator_name = get_current_operator();
728 if (operator_name == NULL)
729 return ret;
730
731 list_for_each(node, operator_specific_device_table[snd_device]) {
732 device_item = node_to_item(node, struct operator_specific_device, list);
733 if (strcmp(operator_name, device_item->operator) == 0) {
734 ret = device_item;
735 }
736 }
737
738 return ret;
739}
740
741
742static int get_operator_specific_device_acdb_id(snd_device_t snd_device)
743{
744 struct operator_specific_device *device;
745 int ret = acdb_device_table[snd_device];
746
747 device = get_operator_specific_device(snd_device);
748 if (device != NULL)
749 ret = device->acdb_id;
750
751 return ret;
752}
753
754static const char *get_operator_specific_device_mixer_path(snd_device_t snd_device)
755{
756 struct operator_specific_device *device;
757 const char *ret = device_table[snd_device];
758
759 device = get_operator_specific_device(snd_device);
760 if (device != NULL)
761 ret = device->mixer_path;
762
763 return ret;
764}
765
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800766inline bool platform_supports_app_type_cfg()
767{
Alexey Polyudove920d4b2017-09-15 17:09:07 -0700768#if defined (PLATFORM_MSM8998) || (PLATFORM_SDM845)
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800769 return true;
770#else
771 return false;
772#endif
773}
774
jasmine chac89321b2018-04-10 21:37:01 +0800775static int parse_audiocal_cfg(struct str_parms *parms, acdb_audio_cal_cfg_t *cal)
776{
777 int err;
778 char value[64];
779 int ret = 0;
780
781 if (parms == NULL || cal == NULL)
782 return ret;
783
784 err = str_parms_get_str(parms, "cal_persist", value, sizeof(value));
785 if (err >= 0) {
786 str_parms_del(parms, "cal_persist");
787 cal->persist = (uint32_t)strtoul(value, NULL, 0);
788 ret = ret | 0x1;
789 }
790 err = str_parms_get_str(parms, "cal_apptype", value, sizeof(value));
791 if (err >= 0) {
792 str_parms_del(parms, "cal_apptype");
793 cal->app_type = (uint32_t)strtoul(value, NULL, 0);
794 ret = ret | 0x2;
795 }
796 err = str_parms_get_str(parms, "cal_caltype", value, sizeof(value));
797 if (err >= 0) {
798 str_parms_del(parms, "cal_caltype");
799 cal->cal_type = (uint32_t)strtoul(value, NULL, 0);
800 ret = ret | 0x4;
801 }
802 err = str_parms_get_str(parms, "cal_samplerate", value, sizeof(value));
803 if (err >= 0) {
804 str_parms_del(parms, "cal_samplerate");
805 cal->sampling_rate = (uint32_t)strtoul(value, NULL, 0);
806 ret = ret | 0x8;
807 }
808 err = str_parms_get_str(parms, "cal_devid", value, sizeof(value));
809 if (err >= 0) {
810 str_parms_del(parms, "cal_devid");
811 cal->dev_id = (uint32_t)strtoul(value, NULL, 0);
812 ret = ret | 0x10;
813 }
814 err = str_parms_get_str(parms, "cal_snddevid", value, sizeof(value));
815 if (err >= 0) {
816 str_parms_del(parms, "cal_snddevid");
817 cal->snd_dev_id = (uint32_t)strtoul(value, NULL, 0);
818 ret = ret | 0x20;
819 }
820 err = str_parms_get_str(parms, "cal_topoid", value, sizeof(value));
821 if (err >= 0) {
822 str_parms_del(parms, "cal_topoid");
823 cal->topo_id = (uint32_t)strtoul(value, NULL, 0);
824 ret = ret | 0x40;
825 }
826 err = str_parms_get_str(parms, "cal_moduleid", value, sizeof(value));
827 if (err >= 0) {
828 str_parms_del(parms, "cal_moduleid");
829 cal->module_id = (uint32_t)strtoul(value, NULL, 0);
830 ret = ret | 0x80;
831 }
832 err = str_parms_get_str(parms, "cal_paramid", value, sizeof(value));
833 if (err >= 0) {
834 str_parms_del(parms, "cal_paramid");
835 cal->param_id = (uint32_t)strtoul(value, NULL, 0);
836 ret = ret | 0x100;
837 }
838 return ret;
839}
840
841static void set_audiocal(void *platform, struct str_parms *parms, char *value, int len)
842{
843 struct platform_data *my_data = (struct platform_data *)platform;
844 acdb_audio_cal_cfg_t cal;
845 uint8_t *dptr = NULL;
846 int32_t dlen = 0;
847 int err ,ret;
848
849 if (value == NULL || platform == NULL || parms == NULL) {
850 ALOGE("[%s] received null pointer, failed", __func__);
851 goto done_key_audcal;
852 }
853
854 memset(&cal, 0, sizeof(acdb_audio_cal_cfg_t));
855 /* parse audio calibration keys */
856 ret = parse_audiocal_cfg(parms, &cal);
857
858 /* handle audio calibration data now */
859 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_AUD_CALDATA, value, len);
860 if (err >= 0) {
861 str_parms_del(parms, AUDIO_PARAMETER_KEY_AUD_CALDATA);
862 dlen = strlen(value);
863 if (dlen <= 0) {
864 ALOGE("[%s] null data received", __func__);
865 goto done_key_audcal;
866 }
867 /*
868 The base64 encoded string is always larger than the binary data,
869 so b64_pton will always output less data than provided (around 1/3
870 less than the input data). That's why we can allocate input buffer
871 length and then get function work.
872 */
873 dptr = (uint8_t *)calloc(dlen, sizeof(uint8_t));
874 if (dptr == NULL) {
875 ALOGE("[%s] memory allocation failed for %d", __func__, dlen);
876 goto done_key_audcal;
877 }
878 dlen = b64_pton(value, dptr, dlen);
879 if (dlen <= 0) {
880 ALOGE("[%s] data decoding failed %d", __func__, dlen);
881 goto done_key_audcal;
882 }
883
884 if (cal.dev_id) {
885 if (audio_is_input_device(cal.dev_id)) {
886 cal.snd_dev_id = platform_get_input_snd_device(platform, cal.dev_id);
887 } else {
888 cal.snd_dev_id = platform_get_output_snd_device(platform, cal.dev_id);
889 }
890 }
891 cal.acdb_dev_id = platform_get_snd_device_acdb_id(cal.snd_dev_id);
892 ALOGD("Setting audio calibration for snd_device(%d) acdb_id(%d)",
893 cal.snd_dev_id, cal.acdb_dev_id);
894 if (cal.acdb_dev_id == -EINVAL) {
895 ALOGE("[%s] Invalid acdb_device id %d for snd device id %d",
896 __func__, cal.acdb_dev_id, cal.snd_dev_id);
897 goto done_key_audcal;
898 }
899 if (my_data->acdb_set_audio_cal) {
900 ret = my_data->acdb_set_audio_cal((void *)&cal, (void *)dptr, dlen);
901 }
902 }
903done_key_audcal:
904 if (dptr != NULL)
905 free(dptr);
906}
907
vivek mehta1a9b7c02015-06-25 11:49:38 -0700908bool platform_send_gain_dep_cal(void *platform, int level)
909{
910 bool ret_val = false;
911 struct platform_data *my_data = (struct platform_data *)platform;
912 struct audio_device *adev = my_data->adev;
913 int acdb_dev_id, app_type;
914 int acdb_dev_type = MSM_SNDDEV_CAP_RX;
915 int mode = CAL_MODE_RTAC;
916 struct listnode *node;
917 struct audio_usecase *usecase;
Haynes Mathew George67486e22017-06-26 12:58:38 -0700918 bool valid_uc_type;
919 bool valid_dev;
vivek mehta1a9b7c02015-06-25 11:49:38 -0700920
921 if (my_data->acdb_send_gain_dep_cal == NULL) {
922 ALOGE("%s: dlsym error for acdb_send_gain_dep_cal", __func__);
923 return ret_val;
924 }
925
926 if (!voice_is_in_call(adev)) {
927 ALOGV("%s: Not Voice call usecase, apply new cal for level %d",
928 __func__, level);
vivek mehta1a9b7c02015-06-25 11:49:38 -0700929
930 // find the current active sound device
931 list_for_each(node, &adev->usecase_list) {
932 usecase = node_to_item(node, struct audio_usecase, list);
Haynes Mathew George67486e22017-06-26 12:58:38 -0700933 LOG_ALWAYS_FATAL_IF(usecase == NULL,
934 "unxpected NULL usecase in usecase_list");
935 valid_uc_type = usecase->type == PCM_PLAYBACK;
936 valid_dev = false;
937 if (valid_uc_type) {
938 audio_devices_t dev = usecase->stream.out->devices;
939 valid_dev = (dev == AUDIO_DEVICE_OUT_SPEAKER ||
vivek mehta40125092017-08-21 18:48:51 -0700940 dev == AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Haynes Mathew George67486e22017-06-26 12:58:38 -0700941 dev == AUDIO_DEVICE_OUT_WIRED_HEADSET ||
942 dev == AUDIO_DEVICE_OUT_WIRED_HEADPHONE);
943 }
944 if (valid_dev) {
vivek mehta40125092017-08-21 18:48:51 -0700945 ALOGV("%s: out device is %d", __func__, usecase->out_snd_device);
946 if (platform_supports_app_type_cfg())
947 app_type = usecase->stream.out->app_type_cfg.app_type;
948 else
949 app_type = DEFAULT_APP_TYPE_RX_PATH;
vivek mehta4cb82982015-07-13 12:05:49 -0700950
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -0700951 acdb_dev_id = platform_get_snd_device_acdb_id(usecase->out_snd_device);
vivek mehta40125092017-08-21 18:48:51 -0700952
953 if (!my_data->acdb_send_gain_dep_cal(acdb_dev_id, app_type,
vivek mehta1a9b7c02015-06-25 11:49:38 -0700954 acdb_dev_type, mode, level)) {
955 // set ret_val true if at least one calibration is set successfully
956 ret_val = true;
957 } else {
958 ALOGE("%s: my_data->acdb_send_gain_dep_cal failed ", __func__);
959 }
960 } else {
961 ALOGW("%s: Usecase list is empty", __func__);
962 }
963 }
964 } else {
965 ALOGW("%s: Voice call in progress .. ignore setting new cal",
966 __func__);
967 }
968 return ret_val;
969}
970
Eric Laurentcefbbac2014-09-04 13:54:10 -0500971void platform_set_echo_reference(struct audio_device *adev, bool enable, audio_devices_t out_device)
Eric Laurentb23d5282013-05-14 15:27:20 -0700972{
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800973 struct platform_data *my_data = (struct platform_data *)adev->platform;
Eric Laurentcefbbac2014-09-04 13:54:10 -0500974 snd_device_t snd_device = SND_DEVICE_NONE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700975
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800976 if (strcmp(my_data->ec_ref_mixer_path, "")) {
977 ALOGV("%s: diabling %s", __func__, my_data->ec_ref_mixer_path);
978 audio_route_reset_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
Eric Laurentcefbbac2014-09-04 13:54:10 -0500979 }
980
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800981 if (enable) {
982 strcpy(my_data->ec_ref_mixer_path, "echo-reference");
983 if (out_device != AUDIO_DEVICE_NONE) {
984 snd_device = platform_get_output_snd_device(adev->platform, out_device);
985 platform_add_backend_name(adev->platform, my_data->ec_ref_mixer_path, snd_device);
986 }
Eric Laurentcefbbac2014-09-04 13:54:10 -0500987
Joe Onorato188b6222016-03-01 11:02:27 -0800988 ALOGV("%s: enabling %s", __func__, my_data->ec_ref_mixer_path);
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800989 audio_route_apply_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
990 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700991}
992
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700993static struct csd_data *open_csd_client(bool i2s_ext_modem)
994{
995 struct csd_data *csd = calloc(1, sizeof(struct csd_data));
996
997 csd->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
998 if (csd->csd_client == NULL) {
999 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
1000 goto error;
1001 } else {
1002 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
1003
1004 csd->deinit = (deinit_t)dlsym(csd->csd_client,
1005 "csd_client_deinit");
1006 if (csd->deinit == NULL) {
1007 ALOGE("%s: dlsym error %s for csd_client_deinit", __func__,
1008 dlerror());
1009 goto error;
1010 }
1011 csd->disable_device = (disable_device_t)dlsym(csd->csd_client,
1012 "csd_client_disable_device");
1013 if (csd->disable_device == NULL) {
1014 ALOGE("%s: dlsym error %s for csd_client_disable_device",
1015 __func__, dlerror());
1016 goto error;
1017 }
1018 csd->enable_device_config = (enable_device_config_t)dlsym(csd->csd_client,
1019 "csd_client_enable_device_config");
1020 if (csd->enable_device_config == NULL) {
1021 ALOGE("%s: dlsym error %s for csd_client_enable_device_config",
1022 __func__, dlerror());
1023 goto error;
1024 }
1025 csd->enable_device = (enable_device_t)dlsym(csd->csd_client,
1026 "csd_client_enable_device");
1027 if (csd->enable_device == NULL) {
1028 ALOGE("%s: dlsym error %s for csd_client_enable_device",
1029 __func__, dlerror());
1030 goto error;
1031 }
1032 csd->start_voice = (start_voice_t)dlsym(csd->csd_client,
1033 "csd_client_start_voice");
1034 if (csd->start_voice == NULL) {
1035 ALOGE("%s: dlsym error %s for csd_client_start_voice",
1036 __func__, dlerror());
1037 goto error;
1038 }
1039 csd->stop_voice = (stop_voice_t)dlsym(csd->csd_client,
1040 "csd_client_stop_voice");
1041 if (csd->stop_voice == NULL) {
1042 ALOGE("%s: dlsym error %s for csd_client_stop_voice",
1043 __func__, dlerror());
1044 goto error;
1045 }
1046 csd->volume = (volume_t)dlsym(csd->csd_client,
1047 "csd_client_volume");
1048 if (csd->volume == NULL) {
1049 ALOGE("%s: dlsym error %s for csd_client_volume",
1050 __func__, dlerror());
1051 goto error;
1052 }
1053 csd->mic_mute = (mic_mute_t)dlsym(csd->csd_client,
1054 "csd_client_mic_mute");
1055 if (csd->mic_mute == NULL) {
1056 ALOGE("%s: dlsym error %s for csd_client_mic_mute",
1057 __func__, dlerror());
1058 goto error;
1059 }
1060 csd->slow_talk = (slow_talk_t)dlsym(csd->csd_client,
1061 "csd_client_slow_talk");
1062 if (csd->slow_talk == NULL) {
1063 ALOGE("%s: dlsym error %s for csd_client_slow_talk",
1064 __func__, dlerror());
1065 goto error;
1066 }
1067 csd->start_playback = (start_playback_t)dlsym(csd->csd_client,
1068 "csd_client_start_playback");
1069 if (csd->start_playback == NULL) {
1070 ALOGE("%s: dlsym error %s for csd_client_start_playback",
1071 __func__, dlerror());
1072 goto error;
1073 }
1074 csd->stop_playback = (stop_playback_t)dlsym(csd->csd_client,
1075 "csd_client_stop_playback");
1076 if (csd->stop_playback == NULL) {
1077 ALOGE("%s: dlsym error %s for csd_client_stop_playback",
1078 __func__, dlerror());
1079 goto error;
1080 }
1081 csd->start_record = (start_record_t)dlsym(csd->csd_client,
1082 "csd_client_start_record");
1083 if (csd->start_record == NULL) {
1084 ALOGE("%s: dlsym error %s for csd_client_start_record",
1085 __func__, dlerror());
1086 goto error;
1087 }
1088 csd->stop_record = (stop_record_t)dlsym(csd->csd_client,
1089 "csd_client_stop_record");
1090 if (csd->stop_record == NULL) {
1091 ALOGE("%s: dlsym error %s for csd_client_stop_record",
1092 __func__, dlerror());
1093 goto error;
1094 }
1095
1096 csd->get_sample_rate = (get_sample_rate_t)dlsym(csd->csd_client,
1097 "csd_client_get_sample_rate");
1098 if (csd->get_sample_rate == NULL) {
1099 ALOGE("%s: dlsym error %s for csd_client_get_sample_rate",
1100 __func__, dlerror());
1101
1102 goto error;
1103 }
1104
1105 csd->init = (init_t)dlsym(csd->csd_client, "csd_client_init");
1106
1107 if (csd->init == NULL) {
1108 ALOGE("%s: dlsym error %s for csd_client_init",
1109 __func__, dlerror());
1110 goto error;
1111 } else {
1112 csd->init(i2s_ext_modem);
1113 }
1114 }
1115 return csd;
1116
1117error:
1118 free(csd);
1119 csd = NULL;
1120 return csd;
1121}
1122
1123void close_csd_client(struct csd_data *csd)
1124{
1125 if (csd != NULL) {
1126 csd->deinit();
1127 dlclose(csd->csd_client);
1128 free(csd);
1129 csd = NULL;
1130 }
1131}
1132
1133static void platform_csd_init(struct platform_data *my_data)
1134{
1135#ifdef PLATFORM_MSM8084
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001136 int32_t modems, (*count_modems)(void);
1137 const char *name = "libdetectmodem.so";
1138 const char *func = "count_modems";
1139 const char *error;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001140
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001141 my_data->csd = NULL;
1142
1143 void *lib = dlopen(name, RTLD_NOW);
1144 error = dlerror();
1145 if (!lib) {
1146 ALOGE("%s: could not find %s: %s", __func__, name, error);
1147 return;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001148 }
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001149
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001150 count_modems = NULL;
1151 *(void **)(&count_modems) = dlsym(lib, func);
1152 error = dlerror();
1153 if (!count_modems) {
1154 ALOGE("%s: could not find symbol %s in %s: %s",
1155 __func__, func, name, error);
1156 goto done;
1157 }
1158
1159 modems = count_modems();
1160 if (modems < 0) {
1161 ALOGE("%s: count_modems failed\n", __func__);
1162 goto done;
1163 }
1164
Eric Laurent2bafff12016-03-17 12:17:23 -07001165 ALOGD("%s: num_modems %d\n", __func__, modems);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001166 if (modems > 0)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001167 my_data->csd = open_csd_client(false /*is_i2s_ext_modem*/);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001168
1169done:
1170 dlclose(lib);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001171#else
1172 my_data->csd = NULL;
1173#endif
1174}
1175
Eric Laurentc6333382015-09-14 12:43:44 -07001176static void set_platform_defaults(struct platform_data * my_data)
Haynes Mathew George98c95622014-06-20 19:14:25 -07001177{
1178 int32_t dev;
1179 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001180 backend_tag_table[dev] = NULL;
1181 hw_interface_table[dev] = NULL;
keunhui.park2f7306a2015-07-16 16:48:06 +09001182 operator_specific_device_table[dev] = NULL;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001183 }
1184
David Linee3fe402017-03-13 10:00:42 -07001185 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1186 backend_bit_width_table[dev] = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
1187 }
1188
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001189 // To overwrite these go to the audio_platform_info.xml file.
1190 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("bt-sco");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07001191 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("bt-sco");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001192 backend_tag_table[SND_DEVICE_OUT_BT_SCO] = strdup("bt-sco");
1193 backend_tag_table[SND_DEVICE_OUT_HDMI] = strdup("hdmi");
1194 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("speaker-and-hdmi");
1195 backend_tag_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("bt-sco-wb");
1196 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("bt-sco-wb");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07001197 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("bt-sco-wb");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001198 backend_tag_table[SND_DEVICE_OUT_VOICE_TX] = strdup("afe-proxy");
1199 backend_tag_table[SND_DEVICE_IN_VOICE_RX] = strdup("afe-proxy");
Haynes Mathew George98c95622014-06-20 19:14:25 -07001200
David Linee3fe402017-03-13 10:00:42 -07001201 backend_tag_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("usb-headset");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001202 backend_tag_table[SND_DEVICE_OUT_VOICE_USB_HEADSET] = strdup("usb-headset");
David Linee3fe402017-03-13 10:00:42 -07001203 backend_tag_table[SND_DEVICE_OUT_USB_HEADPHONES] = strdup("usb-headphones");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001204 backend_tag_table[SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = strdup("usb-headphones");
David Linee3fe402017-03-13 10:00:42 -07001205 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] =
1206 strdup("speaker-and-usb-headphones");
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07001207 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] =
1208 strdup("speaker-safe-and-usb-headphones");
David Linee3fe402017-03-13 10:00:42 -07001209 backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("usb-headset-mic");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001210 backend_tag_table[SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1211 backend_tag_table[SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1212 backend_tag_table[SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1213 backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = strdup("usb-headset-mic");
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001214 backend_tag_table[SND_DEVICE_OUT_BT_A2DP] = strdup("bt-a2dp");
1215 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] = strdup("speaker-and-bt-a2dp");
Aniket Kumar Lata9723a962018-05-16 17:41:55 -07001216 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP] = strdup("speaker-safe-and-bt-a2dp");
jasmine cha270b7762018-03-30 15:41:33 +08001217 backend_tag_table[SND_DEVICE_OUT_USB_HEADSET_SPEC] = strdup("usb-headset");
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001218
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001219 hw_interface_table[SND_DEVICE_OUT_HANDSET] = strdup("SLIMBUS_0_RX");
1220 hw_interface_table[SND_DEVICE_OUT_SPEAKER] = strdup("SLIMBUS_0_RX");
1221 hw_interface_table[SND_DEVICE_OUT_SPEAKER_REVERSE] = strdup("SLIMBUS_0_RX");
1222 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE] = strdup("SLIMBUS_0_RX");
1223 hw_interface_table[SND_DEVICE_OUT_HEADPHONES] = strdup("SLIMBUS_0_RX");
1224 hw_interface_table[SND_DEVICE_OUT_LINE] = strdup("SLIMBUS_0_RX");
1225 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001226 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001227 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001228 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001229 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET] = strdup("SLIMBUS_0_RX");
1230 hw_interface_table[SND_DEVICE_OUT_VOICE_HAC_HANDSET] = strdup("SLIMBUS_0_RX");
1231 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER] = strdup("SLIMBUS_0_RX");
1232 hw_interface_table[SND_DEVICE_OUT_VOICE_HEADPHONES] = strdup("SLIMBUS_0_RX");
1233 hw_interface_table[SND_DEVICE_OUT_VOICE_LINE] = strdup("SLIMBUS_0_RX");
1234 hw_interface_table[SND_DEVICE_OUT_HDMI] = strdup("HDMI_RX");
1235 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("SLIMBUS_0_RX-and-HDMI_RX");
1236 hw_interface_table[SND_DEVICE_OUT_BT_SCO] = strdup("SEC_AUX_PCM_RX");
1237 hw_interface_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("SEC_AUX_PCM_RX");
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001238 hw_interface_table[SND_DEVICE_OUT_BT_A2DP] = strdup("SLIMBUS_7_RX");
1239 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] =
1240 strdup("SLIMBUS_0_RX-and-SLIMBUS_7_RX");
Aniket Kumar Lata9723a962018-05-16 17:41:55 -07001241 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP] =
1242 strdup("SLIMBUS_0_RX-and-SLIMBUS_7_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001243 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = strdup("SLIMBUS_0_RX");
1244 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = strdup("SLIMBUS_0_RX");
1245 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = strdup("SLIMBUS_0_RX");
1246 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = strdup("SLIMBUS_0_RX");
David Linee3fe402017-03-13 10:00:42 -07001247 hw_interface_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("USB_AUDIO_RX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001248 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = strdup("USB_AUDIO_RX");
1249 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = strdup("USB_AUDIO_RX");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001250 hw_interface_table[SND_DEVICE_OUT_VOICE_USB_HEADSET] = strdup("USB_AUDIO_RX");
David Linee3fe402017-03-13 10:00:42 -07001251 hw_interface_table[SND_DEVICE_OUT_USB_HEADPHONES] = strdup("USB_AUDIO_RX");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001252 hw_interface_table[SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = strdup("USB_AUDIO_RX");
jasmine cha270b7762018-03-30 15:41:33 +08001253 hw_interface_table[SND_DEVICE_OUT_USB_HEADSET_SPEC] = strdup("USB_AUDIO_RX");
David Linee3fe402017-03-13 10:00:42 -07001254 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 -07001255 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 -07001256 hw_interface_table[SND_DEVICE_OUT_VOICE_TX] = strdup("AFE_PCM_RX");
1257 hw_interface_table[SND_DEVICE_OUT_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
1258 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
jasmine cha52284622018-03-23 17:21:35 +08001259 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = strdup("SLIMBUS_0_RX");
1260 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_BT_SCO] = strdup("SLIMBUS_0_RX-and-SEC_AUX_PCM_RX");
1261 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB] = strdup("SLIMBUS_0_RX-and-SEC_AUX_PCM_RX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001262 hw_interface_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1263 hw_interface_table[SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1264 hw_interface_table[SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = strdup("USB_AUDIO_TX");
1265 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1266 hw_interface_table[SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1267 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = strdup("USB_AUDIO_TX");
1268 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = strdup("USB_AUDIO_TX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001269 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001270 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_AEC] = strdup("SLIMBUS_0_TX");
1271 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_NS] = strdup("SLIMBUS_0_TX");
1272 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1273 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC] = strdup("SLIMBUS_0_TX");
1274 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_AEC] = strdup("SLIMBUS_0_TX");
1275 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_NS] = strdup("SLIMBUS_0_TX");
1276 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1277 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001278 hw_interface_table[SND_DEVICE_IN_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001279 hw_interface_table[SND_DEVICE_IN_HEADSET_MIC_AEC] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001280 hw_interface_table[SND_DEVICE_IN_CAMCORDER_MIC] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001281 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC] = strdup("SLIMBUS_0_TX");
1282 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC_NS] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001283 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC_AEC] = strdup("SLIMBUS_0_TX");
1284 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001285 hw_interface_table[SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
1286 hw_interface_table[SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = strdup("SLIMBUS_0_TX");
David Lin93725722017-10-13 14:58:17 -07001287 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_MIC] = strdup("SLIMBUS_0_TX");
1288 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1289 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = strdup("SLIMBUS_0_TX");
1290 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = strdup("SLIMBUS_0_TX");
1291 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001292 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC] = strdup("SLIMBUS_0_TX");
1293 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_AEC] = strdup("SLIMBUS_0_TX");
1294 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_NS] = strdup("SLIMBUS_0_TX");
1295 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1296 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC] = strdup("SLIMBUS_0_TX");
1297 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_AEC] = strdup("SLIMBUS_0_TX");
1298 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_NS] = strdup("SLIMBUS_0_TX");
1299 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001300 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
1301 hw_interface_table[SND_DEVICE_IN_VOICE_DMIC] = strdup("SLIMBUS_0_TX");
1302 hw_interface_table[SND_DEVICE_IN_VOICE_DMIC_TMUS] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001303 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001304 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = strdup("SLIMBUS_0_TX");
1305 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001306 hw_interface_table[SND_DEVICE_IN_VOICE_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001307 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1308 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = strdup("SLIMBUS_0_TX");
1309 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1310 hw_interface_table[SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1311 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("SEC_AUX_PCM_TX");
1312 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("SEC_AUX_PCM_TX");
1313 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("SEC_AUX_PCM_TX");
1314 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("SEC_AUX_PCM_TX");
1315 hw_interface_table[SND_DEVICE_IN_VOICE_RX] = strdup("AFE_PCM_TX");
1316 hw_interface_table[SND_DEVICE_IN_THREE_MIC] = strdup("SLIMBUS_0_TX");
1317 hw_interface_table[SND_DEVICE_IN_QUAD_MIC] = strdup("SLIMBUS_0_TX");
1318 hw_interface_table[SND_DEVICE_IN_HANDSET_TMIC] = strdup("SLIMBUS_0_TX");
1319 hw_interface_table[SND_DEVICE_IN_HANDSET_QMIC] = strdup("SLIMBUS_0_TX");
1320 hw_interface_table[SND_DEVICE_IN_HANDSET_TMIC_AEC] = strdup("SLIMBUS_0_TX");
1321 hw_interface_table[SND_DEVICE_IN_HANDSET_QMIC_AEC] = strdup("SLIMBUS_0_TX");
Eric Laurentc6333382015-09-14 12:43:44 -07001322 my_data->max_mic_count = PLATFORM_DEFAULT_MIC_COUNT;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001323}
1324
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001325void get_cvd_version(char *cvd_version, struct audio_device *adev)
1326{
1327 struct mixer_ctl *ctl;
1328 int count;
1329 int ret = 0;
1330
1331 ctl = mixer_get_ctl_by_name(adev->mixer, CVD_VERSION_MIXER_CTL);
1332 if (!ctl) {
1333 ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__, CVD_VERSION_MIXER_CTL);
1334 goto done;
1335 }
1336 mixer_ctl_update(ctl);
1337
1338 count = mixer_ctl_get_num_values(ctl);
1339 if (count > MAX_CVD_VERSION_STRING_SIZE)
1340 count = MAX_CVD_VERSION_STRING_SIZE - 1;
1341
1342 ret = mixer_ctl_get_array(ctl, cvd_version, count);
1343 if (ret != 0) {
1344 ALOGE("%s: ERROR! mixer_ctl_get_array() failed to get CVD Version", __func__);
1345 goto done;
1346 }
1347
1348done:
1349 return;
1350}
1351
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001352static int platform_acdb_init(void *platform)
1353{
1354 struct platform_data *my_data = (struct platform_data *)platform;
1355 struct audio_device *adev = my_data->adev;
1356
1357 if (!my_data->acdb_init) {
1358 ALOGE("%s: no acdb_init fn provided", __func__);
1359 return -1;
1360 }
1361
1362 if (my_data->acdb_initialized) {
1363 ALOGW("acdb is already initialized");
1364 return 0;
1365 }
1366
Alexey Polyudove920d4b2017-09-15 17:09:07 -07001367#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001368 char *cvd_version = calloc(1, MAX_CVD_VERSION_STRING_SIZE);
1369 if (!cvd_version)
1370 ALOGE("failed to allocate cvd_version");
1371 else {
1372 get_cvd_version(cvd_version, adev);
1373 my_data->acdb_init((char *)my_data->snd_card_name, cvd_version, 0);
1374 free(cvd_version);
1375 }
1376#elif defined (PLATFORM_MSM8084)
1377 my_data->acdb_init((char *)my_data->snd_card_name);
1378#else
1379 my_data->acdb_init();
1380#endif
1381 my_data->acdb_initialized = true;
1382 return 0;
1383}
1384
David Linee3fe402017-03-13 10:00:42 -07001385static void
1386platform_backend_config_init(struct platform_data *pdata)
1387{
1388 int i;
1389
1390 /* initialize backend config */
1391 for (i = 0; i < MAX_CODEC_BACKENDS; i++) {
1392 pdata->current_backend_cfg[i].sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
1393 pdata->current_backend_cfg[i].bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
1394 pdata->current_backend_cfg[i].channels = CODEC_BACKEND_DEFAULT_CHANNELS;
1395
1396 if (i > MAX_RX_CODEC_BACKENDS)
1397 pdata->current_backend_cfg[i].channels = CODEC_BACKEND_DEFAULT_TX_CHANNELS;
1398
1399 pdata->current_backend_cfg[i].bitwidth_mixer_ctl = NULL;
1400 pdata->current_backend_cfg[i].samplerate_mixer_ctl = NULL;
1401 pdata->current_backend_cfg[i].channels_mixer_ctl = NULL;
1402 }
1403
1404 pdata->current_backend_cfg[DEFAULT_CODEC_BACKEND].bitwidth_mixer_ctl =
1405 strdup("SLIM_0_RX Format");
1406 pdata->current_backend_cfg[DEFAULT_CODEC_BACKEND].samplerate_mixer_ctl =
1407 strdup("SLIM_0_RX SampleRate");
1408
1409 pdata->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].bitwidth_mixer_ctl =
1410 strdup("SLIM_0_TX Format");
1411 pdata->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].samplerate_mixer_ctl =
1412 strdup("SLIM_0_TX SampleRate");
1413
1414 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].bitwidth_mixer_ctl =
1415 strdup("USB_AUDIO_TX Format");
1416 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].samplerate_mixer_ctl =
1417 strdup("USB_AUDIO_TX SampleRate");
1418 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].channels_mixer_ctl =
1419 strdup("USB_AUDIO_TX Channels");
1420
1421 pdata->current_backend_cfg[HEADPHONE_BACKEND].bitwidth_mixer_ctl =
1422 strdup("SLIM_6_RX Format");
1423 pdata->current_backend_cfg[HEADPHONE_BACKEND].samplerate_mixer_ctl =
1424 strdup("SLIM_6_RX SampleRate");
1425
1426 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].bitwidth_mixer_ctl =
1427 strdup("USB_AUDIO_RX Format");
1428 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].samplerate_mixer_ctl =
1429 strdup("USB_AUDIO_RX SampleRate");
1430
1431 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].channels = 1;
1432 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].channels_mixer_ctl =
1433 strdup("USB_AUDIO_RX Channels");
1434}
1435
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001436static int
1437platform_backend_app_type_cfg_init(struct platform_data *pdata,
1438 struct mixer *mixer)
1439{
1440 size_t app_type_cfg[128] = {0};
1441 int length, num_app_types = 0;
1442 struct mixer_ctl *ctl = NULL;
1443
1444 const char *mixer_ctl_name = "App Type Config";
1445 ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name);
1446 if (!ctl) {
1447 ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name);
1448 return -1;
1449 }
1450
1451 length = 1; // reserve index 0 for number of app types
1452
1453 struct listnode *node;
1454 struct app_type_entry *entry;
1455 list_for_each(node, &app_type_entry_list) {
1456 entry = node_to_item(node, struct app_type_entry, node);
1457 app_type_cfg[length++] = entry->app_type;
1458 app_type_cfg[length++] = entry->max_rate;
1459 app_type_cfg[length++] = entry->bit_width;
1460 ALOGI("%s add entry %d %d", __func__, entry->app_type, entry->bit_width);
1461 num_app_types += 1;
1462 }
1463
1464 // default for capture
1465 int t;
1466 platform_get_default_app_type_v2(pdata,
1467 PCM_CAPTURE,
1468 &t);
1469 app_type_cfg[length++] = t;
1470 app_type_cfg[length++] = 48000;
1471 app_type_cfg[length++] = 16;
1472 num_app_types += 1;
1473
1474 if (num_app_types) {
1475 app_type_cfg[0] = num_app_types;
1476 if (mixer_ctl_set_array(ctl, app_type_cfg, length) < 0) {
1477 ALOGE("Failed to set app type cfg");
1478 }
1479 }
1480 return 0;
1481}
1482
Xu Han1638fd12018-04-20 12:42:23 -07001483static void configure_flicker_sensor_input(struct mixer *mixer)
1484{
1485 struct mixer_ctl *ctl;
1486 const char* ctl1 = "AIF3_CAP Mixer SLIM TX2";
1487 int setting1 = 1;
1488 const char* ctl2 = "CDC_IF TX2 MUX";
1489 const char* setting2 = "DEC2";
1490 const char* ctl3 = "SLIM_1_TX Channels";
1491 const char* setting3 = "One";
1492 const char* ctl4 = "ADC MUX2";
1493 const char* setting4 = "AMIC";
1494 const char* ctl5 = "AMIC MUX2";
1495 const char* setting5 = "ADC1";
1496 const char* ctl6 = "DEC2 Volume";
1497 int setting6 = 84;
1498 const char* ctl7 = "MultiMedia2 Mixer SLIM_1_TX";
1499 int setting7 = 1;
1500 const char* ctl8 = "SLIM_1_TX SampleRate";
1501 const char* setting8 = "KHZ_8";
1502
1503 ctl = mixer_get_ctl_by_name(mixer, ctl1);
1504 mixer_ctl_set_value(ctl, 0, setting1);
1505 ctl = mixer_get_ctl_by_name(mixer, ctl2);
1506 mixer_ctl_set_enum_by_string(ctl, setting2);
1507 ctl = mixer_get_ctl_by_name(mixer, ctl3);
1508 mixer_ctl_set_enum_by_string(ctl, setting3);
1509 ctl = mixer_get_ctl_by_name(mixer, ctl4);
1510 mixer_ctl_set_enum_by_string(ctl, setting4);
1511 ctl = mixer_get_ctl_by_name(mixer, ctl5);
1512 mixer_ctl_set_enum_by_string(ctl, setting5);
1513 ctl = mixer_get_ctl_by_name(mixer, ctl6);
1514 mixer_ctl_set_value(ctl, 0, setting6);
1515 ctl = mixer_get_ctl_by_name(mixer, ctl7);
1516 mixer_ctl_set_value(ctl, 0, setting7);
1517 ctl = mixer_get_ctl_by_name(mixer, ctl8);
1518 mixer_ctl_set_enum_by_string(ctl, setting8);
1519}
1520
Eric Laurentb23d5282013-05-14 15:27:20 -07001521void *platform_init(struct audio_device *adev)
1522{
1523 char value[PROPERTY_VALUE_MAX];
vivek mehta60ea4152016-02-18 17:10:26 -08001524 struct platform_data *my_data = NULL;
1525 int retry_num = 0, snd_card_num = 0, key = 0, ret = 0;
1526 bool dual_mic_config = false, use_default_mixer_path = true;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001527 const char *snd_card_name;
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001528 char *cvd_version = NULL;
vivek mehta60ea4152016-02-18 17:10:26 -08001529 char *snd_internal_name = NULL;
1530 char *tmp = NULL;
1531 char mixer_xml_file[MIXER_PATH_MAX_LENGTH]= {0};
vivek mehtade4849c2016-03-03 17:23:38 -08001532 char platform_info_file[MIXER_PATH_MAX_LENGTH]= {0};
1533 struct snd_card_split *snd_split_handle = NULL;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001534 my_data = calloc(1, sizeof(struct platform_data));
1535
1536 my_data->adev = adev;
1537
keunhui.park2f7306a2015-07-16 16:48:06 +09001538 list_init(&operator_info_list);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001539 list_init(&app_type_entry_list);
keunhui.park2f7306a2015-07-16 16:48:06 +09001540
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001541 set_platform_defaults(my_data);
1542
vivek mehta0fb11312017-05-15 19:35:32 -07001543 // audio_extn_utils_get_snd_card_num does
1544 // - open mixer and get snd card name
1545 // - parse platform info xml file and check for valid snd card name
1546 // - on failure loop through all the active snd card
sangwoo1b9f4b32013-06-21 18:22:55 -07001547
vivek mehta0fb11312017-05-15 19:35:32 -07001548 snd_card_num = audio_extn_utils_get_snd_card_num();
1549 if (-1 == snd_card_num) {
1550 ALOGE("%s: invalid sound card number (-1), bailing out ", __func__);
1551 goto init_failed;
sangwoo1b9f4b32013-06-21 18:22:55 -07001552 }
1553
vivek mehta0fb11312017-05-15 19:35:32 -07001554 adev->mixer = mixer_open(snd_card_num);
1555 snd_card_name = mixer_get_name(adev->mixer);
1556 my_data->hw_info = hw_info_init(snd_card_name);
1557
1558 audio_extn_set_snd_card_split(snd_card_name);
1559 snd_split_handle = audio_extn_get_snd_card_split();
1560
1561 /* Get the codec internal name from the sound card and/or form factor
1562 * name and form the mixer paths and platfor info file name dynamically.
1563 * This is generic way of picking any codec and forma factor name based
1564 * mixer and platform info files in future with no code change.
1565
1566 * current code extends and looks for any of the exteneded mixer path and
1567 * platform info file present based on codec and form factor.
1568
1569 * order of picking appropriate file is
1570 * <i> mixer_paths_<codec_name>_<form_factor>.xml, if file not present
1571 * <ii> mixer_paths_<codec_name>.xml, if file not present
1572 * <iii> mixer_paths.xml
1573
1574 * same order is followed for audio_platform_info.xml as well
1575 */
1576
1577 // need to carryforward old file name
1578 if (!strncmp(snd_card_name, TOMTOM_8226_SND_CARD_NAME,
1579 min(strlen(TOMTOM_8226_SND_CARD_NAME), strlen(snd_card_name)))) {
1580 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1581 MIXER_XML_BASE_STRING, TOMTOM_MIXER_FILE_SUFFIX );
1582 } else {
1583
1584 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s_%s.xml",
1585 MIXER_XML_BASE_STRING, snd_split_handle->snd_card,
1586 snd_split_handle->form_factor);
1587 if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) {
1588 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1589 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1590 MIXER_XML_BASE_STRING, snd_split_handle->snd_card);
1591
1592 if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) {
1593 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1594 strlcpy(mixer_xml_file, MIXER_XML_DEFAULT_PATH, MIXER_PATH_MAX_LENGTH);
1595 audio_extn_utils_resolve_config_file(mixer_xml_file);
1596 }
1597 }
1598 }
1599
1600 audio_extn_utils_get_platform_info(snd_card_name, platform_info_file);
1601
jiabin8962a4d2018-03-19 18:21:24 -07001602 my_data->declared_mic_count = 0;
vivek mehta0fb11312017-05-15 19:35:32 -07001603 /* Initialize platform specific ids and/or backends*/
1604 platform_info_init(platform_info_file, my_data);
1605
1606 ALOGD("%s: Loading mixer file: %s", __func__, mixer_xml_file);
1607 adev->audio_route = audio_route_init(snd_card_num, mixer_xml_file);
1608
1609 if (!adev->audio_route) {
1610 ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
1611 mixer_close(adev->mixer);
1612 adev->mixer = NULL;
1613 hw_info_deinit(my_data->hw_info);
1614 my_data->hw_info = NULL;
1615 goto init_failed;
1616 }
1617 adev->snd_card = snd_card_num;
1618 ALOGD("%s: Opened sound card:%d", __func__, snd_card_num);
1619
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09001620 //set max volume step for voice call
1621 property_get("ro.config.vc_call_vol_steps", value, TOSTRING(MAX_VOL_INDEX));
1622 my_data->max_vol_index = atoi(value);
1623
vivek mehta65ad12d2015-08-13 18:32:48 -07001624 property_get("persist.audio.dualmic.config",value,"");
1625 if (!strcmp("endfire", value)) {
1626 dual_mic_config = true;
1627 }
1628
John Muir9e59a962018-01-10 13:30:00 -08001629 my_data->source_mic_type = 0;
Prashant Malanic92c5962015-08-11 15:10:18 -07001630
Eric Laurentb23d5282013-05-14 15:27:20 -07001631 my_data->fluence_in_spkr_mode = false;
1632 my_data->fluence_in_voice_call = false;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001633 my_data->fluence_in_voice_comm = false;
Eric Laurentb23d5282013-05-14 15:27:20 -07001634 my_data->fluence_in_voice_rec = false;
1635
vivek mehta65ad12d2015-08-13 18:32:48 -07001636 property_get("ro.qc.sdk.audio.fluencetype", value, "none");
Prashant Malanic92c5962015-08-11 15:10:18 -07001637 if (!strcmp("fluencepro", value)) {
1638 my_data->fluence_type = FLUENCE_PRO_ENABLE;
vivek mehta65ad12d2015-08-13 18:32:48 -07001639 } else if (!strcmp("fluence", value) || (dual_mic_config)) {
Prashant Malanic92c5962015-08-11 15:10:18 -07001640 my_data->fluence_type = FLUENCE_ENABLE;
1641 } else if (!strcmp("none", value)) {
1642 my_data->fluence_type = FLUENCE_DISABLE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001643 }
1644
Prashant Malanic92c5962015-08-11 15:10:18 -07001645 if (my_data->fluence_type != FLUENCE_DISABLE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001646 property_get("persist.audio.fluence.voicecall",value,"");
1647 if (!strcmp("true", value)) {
1648 my_data->fluence_in_voice_call = true;
1649 }
1650
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001651 property_get("persist.audio.fluence.voicecomm",value,"");
1652 if (!strcmp("true", value)) {
1653 my_data->fluence_in_voice_comm = true;
1654 }
1655
Eric Laurentb23d5282013-05-14 15:27:20 -07001656 property_get("persist.audio.fluence.voicerec",value,"");
1657 if (!strcmp("true", value)) {
1658 my_data->fluence_in_voice_rec = true;
1659 }
1660
1661 property_get("persist.audio.fluence.speaker",value,"");
1662 if (!strcmp("true", value)) {
1663 my_data->fluence_in_spkr_mode = true;
1664 }
1665 }
1666
Prashant Malanic92c5962015-08-11 15:10:18 -07001667 // support max to mono, example if max count is 3, usecase supports Three, dual and mono mic
1668 switch (my_data->max_mic_count) {
1669 case 4:
1670 my_data->source_mic_type |= SOURCE_QUAD_MIC;
1671 case 3:
1672 my_data->source_mic_type |= SOURCE_THREE_MIC;
1673 case 2:
1674 my_data->source_mic_type |= SOURCE_DUAL_MIC;
1675 case 1:
1676 my_data->source_mic_type |= SOURCE_MONO_MIC;
1677 break;
1678 default:
1679 ALOGE("%s: max_mic_count (%d), is not supported, setting to default",
1680 __func__, my_data->max_mic_count);
1681 my_data->source_mic_type = SOURCE_MONO_MIC|SOURCE_DUAL_MIC;
1682 break;
1683 }
1684
1685 ALOGV("%s: Fluence_Type(%d) max_mic_count(%d) mic_type(0x%x) fluence_in_voice_call(%d)"
1686 " fluence_in_voice_comm(%d) fluence_in_voice_rec(%d) fluence_in_spkr_mode(%d) ",
1687 __func__, my_data->fluence_type, my_data->max_mic_count, my_data->source_mic_type,
1688 my_data->fluence_in_voice_call, my_data->fluence_in_voice_comm,
1689 my_data->fluence_in_voice_rec, my_data->fluence_in_spkr_mode);
1690
Eric Laurentb23d5282013-05-14 15:27:20 -07001691 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
1692 if (my_data->acdb_handle == NULL) {
1693 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
1694 } else {
1695 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
1696 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
1697 "acdb_loader_deallocate_ACDB");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001698 if (!my_data->acdb_deallocate)
1699 ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s",
1700 __func__, LIB_ACDB_LOADER);
1701
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001702 my_data->acdb_send_audio_cal_v3 = (acdb_send_audio_cal_v3_t)dlsym(my_data->acdb_handle,
1703 "acdb_loader_send_audio_cal_v3");
1704 if (!my_data->acdb_send_audio_cal_v3)
1705 ALOGE("%s: Could not find the symbol acdb_send_audio_cal_v3 from %s",
1706 __func__, LIB_ACDB_LOADER);
1707
Eric Laurentb23d5282013-05-14 15:27:20 -07001708 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
1709 "acdb_loader_send_audio_cal");
1710 if (!my_data->acdb_send_audio_cal)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001711 ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s",
Eric Laurentb23d5282013-05-14 15:27:20 -07001712 __func__, LIB_ACDB_LOADER);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001713
Eric Laurentb23d5282013-05-14 15:27:20 -07001714 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
1715 "acdb_loader_send_voice_cal");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001716 if (!my_data->acdb_send_voice_cal)
1717 ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s",
1718 __func__, LIB_ACDB_LOADER);
1719
1720 my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle,
1721 "acdb_loader_reload_vocvoltable");
1722 if (!my_data->acdb_reload_vocvoltable)
1723 ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s",
1724 __func__, LIB_ACDB_LOADER);
vivek mehta1a9b7c02015-06-25 11:49:38 -07001725
1726 my_data->acdb_send_gain_dep_cal = (acdb_send_gain_dep_cal_t)dlsym(my_data->acdb_handle,
1727 "acdb_loader_send_gain_dep_cal");
1728 if (!my_data->acdb_send_gain_dep_cal)
1729 ALOGV("%s: Could not find the symbol acdb_loader_send_gain_dep_cal from %s",
1730 __func__, LIB_ACDB_LOADER);
1731
Xu Han1638fd12018-04-20 12:42:23 -07001732#if defined (FLICKER_SENSOR_INPUT)
1733 configure_flicker_sensor_input(adev->mixer);
1734#endif
1735
Alexey Polyudove920d4b2017-09-15 17:09:07 -07001736#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845)
vivek mehta0fb11312017-05-15 19:35:32 -07001737 acdb_init_v2_cvd_t acdb_init_local;
1738 acdb_init_local = (acdb_init_v2_cvd_t)dlsym(my_data->acdb_handle,
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001739 "acdb_loader_init_v2");
vivek mehta0fb11312017-05-15 19:35:32 -07001740 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001741 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1742 dlerror());
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001743
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001744#elif defined (PLATFORM_MSM8084)
vivek mehta0fb11312017-05-15 19:35:32 -07001745 acdb_init_v2_t acdb_init_local;
1746 acdb_init_local = (acdb_init_v2_t)dlsym(my_data->acdb_handle,
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001747 "acdb_loader_init_v2");
vivek mehta0fb11312017-05-15 19:35:32 -07001748 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001749 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1750 dlerror());
1751
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001752#else
vivek mehta0fb11312017-05-15 19:35:32 -07001753 acdb_init_t acdb_init_local;
1754 acdb_init_local = (acdb_init_t)dlsym(my_data->acdb_handle,
Eric Laurentb23d5282013-05-14 15:27:20 -07001755 "acdb_loader_init_ACDB");
vivek mehta0fb11312017-05-15 19:35:32 -07001756 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001757 ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__,
1758 dlerror());
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001759#endif
vivek mehta0fb11312017-05-15 19:35:32 -07001760 my_data->acdb_init = acdb_init_local;
Eric Laurentb23d5282013-05-14 15:27:20 -07001761
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001762 my_data->acdb_send_custom_top = (acdb_send_custom_top_t)
1763 dlsym(my_data->acdb_handle,
1764 "acdb_loader_send_common_custom_topology");
1765
1766 if (!my_data->acdb_send_custom_top)
1767 ALOGE("%s: Could not find the symbol acdb_get_default_app_type from %s",
1768 __func__, LIB_ACDB_LOADER);
1769
jasmine chac89321b2018-04-10 21:37:01 +08001770 my_data->acdb_set_audio_cal = (acdb_set_audio_cal_t)dlsym(my_data->acdb_handle,
1771 "acdb_loader_set_audio_cal_v2");
1772 if (!my_data->acdb_set_audio_cal)
1773 ALOGE("%s: Could not find the symbol acdb_set_audio_cal_v2 from %s",
1774 __func__, LIB_ACDB_LOADER);
1775
vivek mehta0fb11312017-05-15 19:35:32 -07001776 int result = acdb_init(adev->snd_card);
1777 if (!result) {
1778 my_data->acdb_initialized = true;
1779 ALOGD("ACDB initialized");
1780 } else {
1781 my_data->acdb_initialized = false;
1782 ALOGD("ACDB initialization failed");
1783 }
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001784 }
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001785
David Linee3fe402017-03-13 10:00:42 -07001786 /* init usb */
1787 audio_extn_usb_init(adev);
1788
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001789 /* init a2dp */
1790 audio_extn_a2dp_init(adev);
1791
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001792 audio_extn_spkr_prot_init(adev);
Haynes Mathew George98c95622014-06-20 19:14:25 -07001793
Ravi Kumar Alamanda76315572015-04-23 13:13:56 -07001794 audio_extn_hwdep_cal_send(adev->snd_card, my_data->acdb_handle);
1795
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001796 /* load csd client */
1797 platform_csd_init(my_data);
1798
David Linee3fe402017-03-13 10:00:42 -07001799 platform_backend_config_init(my_data);
1800
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001801 init_be_dai_name_table(adev);
1802
1803 if (platform_supports_app_type_cfg())
1804 platform_backend_app_type_cfg_init(my_data, adev->mixer);
1805
Eric Laurentb23d5282013-05-14 15:27:20 -07001806 return my_data;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001807
1808init_failed:
1809 if (my_data)
1810 free(my_data);
1811 return NULL;
Eric Laurentb23d5282013-05-14 15:27:20 -07001812}
1813
1814void platform_deinit(void *platform)
1815{
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001816 int32_t dev;
keunhui.park2f7306a2015-07-16 16:48:06 +09001817 struct operator_info *info_item;
1818 struct operator_specific_device *device_item;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001819 struct app_type_entry *ap;
keunhui.park2f7306a2015-07-16 16:48:06 +09001820 struct listnode *node;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001821
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001822 struct platform_data *my_data = (struct platform_data *)platform;
1823 close_csd_client(my_data->csd);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001824
vivek mehtade4849c2016-03-03 17:23:38 -08001825 hw_info_deinit(my_data->hw_info);
1826
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001827 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1828 if (backend_tag_table[dev])
1829 free(backend_tag_table[dev]);
1830 if (hw_interface_table[dev])
1831 free(hw_interface_table[dev]);
keunhui.park2f7306a2015-07-16 16:48:06 +09001832 if (operator_specific_device_table[dev]) {
1833 while (!list_empty(operator_specific_device_table[dev])) {
1834 node = list_head(operator_specific_device_table[dev]);
1835 list_remove(node);
1836 device_item = node_to_item(node, struct operator_specific_device, list);
1837 free(device_item->operator);
1838 free(device_item->mixer_path);
1839 free(device_item);
1840 }
1841 free(operator_specific_device_table[dev]);
1842 }
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001843 }
1844
1845 if (my_data->snd_card_name)
1846 free(my_data->snd_card_name);
1847
keunhui.park2f7306a2015-07-16 16:48:06 +09001848 while (!list_empty(&operator_info_list)) {
1849 node = list_head(&operator_info_list);
1850 list_remove(node);
1851 info_item = node_to_item(node, struct operator_info, list);
1852 free(info_item->name);
1853 free(info_item->mccmnc);
1854 free(info_item);
1855 }
1856
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001857 while (!list_empty(&app_type_entry_list)) {
1858 node = list_head(&app_type_entry_list);
1859 list_remove(node);
1860 ap = node_to_item(node, struct app_type_entry, node);
vivek mehtaa68fea62017-06-08 19:04:02 -07001861 if (ap->mode) free(ap->mode);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001862 free(ap);
1863 }
1864
Kevin Rocarde35d4af2017-05-02 16:55:28 -07001865 mixer_close(my_data->adev->mixer);
Eric Laurentb23d5282013-05-14 15:27:20 -07001866 free(platform);
David Linee3fe402017-03-13 10:00:42 -07001867
1868 /* deinit usb */
1869 audio_extn_usb_deinit();
Eric Laurentb23d5282013-05-14 15:27:20 -07001870}
1871
1872const char *platform_get_snd_device_name(snd_device_t snd_device)
1873{
keunhui.park2f7306a2015-07-16 16:48:06 +09001874 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1875 if (operator_specific_device_table[snd_device] != NULL) {
1876 return get_operator_specific_device_mixer_path(snd_device);
1877 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001878 return device_table[snd_device];
keunhui.park2f7306a2015-07-16 16:48:06 +09001879 } else
Ravi Kumar Alamanda64026462014-09-15 00:08:58 -07001880 return "none";
Eric Laurentb23d5282013-05-14 15:27:20 -07001881}
1882
vivek mehtade4849c2016-03-03 17:23:38 -08001883int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
1884 char *device_name)
1885{
1886 struct platform_data *my_data = (struct platform_data *)platform;
1887
David Benjamin1565f992016-09-21 12:10:34 -04001888 if (platform == NULL) {
vivek mehtade4849c2016-03-03 17:23:38 -08001889 ALOGW("%s: something wrong, use legacy get_snd_device name", __func__);
David Benjamin1565f992016-09-21 12:10:34 -04001890 strlcpy(device_name, platform_get_snd_device_name(snd_device),
1891 DEVICE_NAME_MAX_SIZE);
vivek mehtade4849c2016-03-03 17:23:38 -08001892 } else if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1893 if (operator_specific_device_table[snd_device] != NULL) {
1894 strlcpy(device_name, get_operator_specific_device_mixer_path(snd_device),
1895 DEVICE_NAME_MAX_SIZE);
1896 } else {
1897 strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE);
1898 }
1899 hw_info_append_hw_type(my_data->hw_info, snd_device, device_name);
1900 } else {
1901 strlcpy(device_name, "none", DEVICE_NAME_MAX_SIZE);
1902 }
1903
1904 return 0;
1905}
1906
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001907void platform_add_backend_name(void *platform, char *mixer_path,
1908 snd_device_t snd_device)
Eric Laurentb23d5282013-05-14 15:27:20 -07001909{
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001910 struct platform_data *my_data = (struct platform_data *)platform;
1911
Haynes Mathew George98c95622014-06-20 19:14:25 -07001912 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1913 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1914 return;
Ravi Kumar Alamanda1de6e5a2014-06-19 21:55:39 -05001915 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001916
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001917 const char * suffix = backend_tag_table[snd_device];
Haynes Mathew George98c95622014-06-20 19:14:25 -07001918
1919 if (suffix != NULL) {
1920 strcat(mixer_path, " ");
1921 strcat(mixer_path, suffix);
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001922 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001923}
1924
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001925bool platform_check_backends_match(snd_device_t snd_device1, snd_device_t snd_device2)
1926{
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001927 ALOGV("%s: snd_device1 = %s, snd_device2 = %s", __func__,
1928 platform_get_snd_device_name(snd_device1),
1929 platform_get_snd_device_name(snd_device2));
1930
1931 if ((snd_device1 < SND_DEVICE_MIN) || (snd_device1 >= SND_DEVICE_MAX)) {
1932 ALOGE("%s: Invalid snd_device = %s", __func__,
1933 platform_get_snd_device_name(snd_device1));
1934 return false;
1935 }
1936 if ((snd_device2 < SND_DEVICE_MIN) || (snd_device2 >= SND_DEVICE_MAX)) {
1937 ALOGE("%s: Invalid snd_device = %s", __func__,
1938 platform_get_snd_device_name(snd_device2));
1939 return false;
1940 }
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07001941
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001942 const char * be_itf1 = hw_interface_table[snd_device1];
1943 const char * be_itf2 = hw_interface_table[snd_device2];
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07001944 /*
1945 hw_interface_table has overrides for a snd_device.
1946 if there is no entry for a device, assume DEFAULT_RX_BACKEND
1947 */
1948 if (be_itf1 == NULL) {
1949 be_itf1 = DEFAULT_RX_BACKEND;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001950 }
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07001951 if (be_itf2 == NULL) {
1952 be_itf2 = DEFAULT_RX_BACKEND;
1953 }
1954 ALOGV("%s: be_itf1 = %s, be_itf2 = %s", __func__, be_itf1, be_itf2);
1955 /*
1956 this takes care of finding a device within a combo device pair as well
1957 */
1958 return strstr(be_itf1, be_itf2) != NULL || strstr(be_itf2, be_itf1) != NULL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001959}
1960
Eric Laurentb23d5282013-05-14 15:27:20 -07001961int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
1962{
1963 int device_id;
1964 if (device_type == PCM_PLAYBACK)
1965 device_id = pcm_device_table[usecase][0];
1966 else
1967 device_id = pcm_device_table[usecase][1];
1968 return device_id;
1969}
1970
Haynes Mathew George98c95622014-06-20 19:14:25 -07001971static int find_index(const struct name_to_index * table, int32_t len,
1972 const char * name)
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001973{
1974 int ret = 0;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001975 int32_t i;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001976
Haynes Mathew George98c95622014-06-20 19:14:25 -07001977 if (table == NULL) {
1978 ALOGE("%s: table is NULL", __func__);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001979 ret = -ENODEV;
1980 goto done;
1981 }
1982
Haynes Mathew George98c95622014-06-20 19:14:25 -07001983 if (name == NULL) {
1984 ALOGE("null key");
1985 ret = -ENODEV;
1986 goto done;
1987 }
1988
1989 for (i=0; i < len; i++) {
1990 if (!strcmp(table[i].name, name)) {
1991 ret = table[i].index;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001992 goto done;
1993 }
1994 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001995 ALOGE("%s: Could not find index for name = %s",
1996 __func__, name);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001997 ret = -ENODEV;
1998done:
1999 return ret;
2000}
2001
Haynes Mathew George98c95622014-06-20 19:14:25 -07002002int platform_get_snd_device_index(char *device_name)
2003{
2004 return find_index(snd_device_name_index, SND_DEVICE_MAX, device_name);
2005}
2006
2007int platform_get_usecase_index(const char *usecase_name)
2008{
2009 return find_index(usecase_name_index, AUDIO_USECASE_MAX, usecase_name);
2010}
2011
keunhui.park2f7306a2015-07-16 16:48:06 +09002012void platform_add_operator_specific_device(snd_device_t snd_device,
2013 const char *operator,
2014 const char *mixer_path,
2015 unsigned int acdb_id)
2016{
2017 struct operator_specific_device *device;
2018
2019 if (operator_specific_device_table[snd_device] == NULL) {
2020 operator_specific_device_table[snd_device] =
2021 (struct listnode *)calloc(1, sizeof(struct listnode));
2022 list_init(operator_specific_device_table[snd_device]);
2023 }
2024
2025 device = (struct operator_specific_device *)calloc(1, sizeof(struct operator_specific_device));
2026
2027 device->operator = strdup(operator);
2028 device->mixer_path = strdup(mixer_path);
2029 device->acdb_id = acdb_id;
2030
2031 list_add_tail(operator_specific_device_table[snd_device], &device->list);
2032
Eric Laurent2bafff12016-03-17 12:17:23 -07002033 ALOGD("%s: device[%s] -> operator[%s] mixer_path[%s] acdb_id[%d]", __func__,
keunhui.park2f7306a2015-07-16 16:48:06 +09002034 platform_get_snd_device_name(snd_device), operator, mixer_path, acdb_id);
2035
2036}
2037
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002038int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
2039{
2040 int ret = 0;
2041
2042 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
2043 ALOGE("%s: Invalid snd_device = %d",
2044 __func__, snd_device);
2045 ret = -EINVAL;
2046 goto done;
2047 }
2048
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002049 ALOGV("%s: acdb_device_table[%s]: old = %d new = %d", __func__,
2050 platform_get_snd_device_name(snd_device), acdb_device_table[snd_device], acdb_id);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002051 acdb_device_table[snd_device] = acdb_id;
2052done:
2053 return ret;
2054}
2055
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07002056int platform_get_snd_device_acdb_id(snd_device_t snd_device)
2057{
2058 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
2059 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
2060 return -EINVAL;
2061 }
keunhui.park2f7306a2015-07-16 16:48:06 +09002062
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002063 /*
2064 * If speaker protection is enabled, function returns supported
2065 * sound device for speaker. Else same sound device is returned.
2066 */
2067 snd_device = audio_extn_get_spkr_prot_snd_device(snd_device);
2068
keunhui.park2f7306a2015-07-16 16:48:06 +09002069 if (operator_specific_device_table[snd_device] != NULL)
2070 return get_operator_specific_device_acdb_id(snd_device);
2071 else
2072 return acdb_device_table[snd_device];
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07002073}
2074
David Linee3fe402017-03-13 10:00:42 -07002075static int platform_get_backend_index(snd_device_t snd_device)
2076{
2077 int32_t port = DEFAULT_CODEC_BACKEND;
2078
2079 if (snd_device >= SND_DEVICE_OUT_BEGIN && snd_device < SND_DEVICE_OUT_END) {
2080 if (backend_tag_table[snd_device] != NULL) {
2081 if (strncmp(backend_tag_table[snd_device], "headphones",
2082 sizeof("headphones")) == 0)
2083 port = HEADPHONE_BACKEND;
2084 else if (strcmp(backend_tag_table[snd_device], "hdmi") == 0)
2085 port = HDMI_RX_BACKEND;
2086 else if ((strcmp(backend_tag_table[snd_device], "usb-headphones") == 0) ||
2087 (strcmp(backend_tag_table[snd_device], "usb-headset") == 0))
2088 port = USB_AUDIO_RX_BACKEND;
2089 }
2090 } else if (snd_device >= SND_DEVICE_IN_BEGIN && snd_device < SND_DEVICE_IN_END) {
2091 port = DEFAULT_CODEC_TX_BACKEND;
2092 if (backend_tag_table[snd_device] != NULL) {
2093 if (strcmp(backend_tag_table[snd_device], "usb-headset-mic") == 0)
2094 port = USB_AUDIO_TX_BACKEND;
2095 else if (strstr(backend_tag_table[snd_device], "bt-sco") != NULL)
2096 port = BT_SCO_TX_BACKEND;
2097 }
2098 } else {
2099 ALOGW("%s:napb: Invalid device - %d ", __func__, snd_device);
2100 }
2101
2102 ALOGV("%s:napb: backend port - %d device - %d ", __func__, port, snd_device);
2103
2104 return port;
2105}
2106
Eric Laurentb23d5282013-05-14 15:27:20 -07002107int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
2108{
2109 struct platform_data *my_data = (struct platform_data *)platform;
2110 int acdb_dev_id, acdb_dev_type;
2111
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002112 if (platform_supports_app_type_cfg()) // use v2 instead
2113 return -ENOSYS;
2114
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002115 acdb_dev_id = platform_get_snd_device_acdb_id(snd_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07002116 if (acdb_dev_id < 0) {
2117 ALOGE("%s: Could not find acdb id for device(%d)",
2118 __func__, snd_device);
2119 return -EINVAL;
2120 }
2121 if (my_data->acdb_send_audio_cal) {
Joe Onorato188b6222016-03-01 11:02:27 -08002122 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Eric Laurentb23d5282013-05-14 15:27:20 -07002123 __func__, snd_device, acdb_dev_id);
2124 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
2125 snd_device < SND_DEVICE_OUT_END)
2126 acdb_dev_type = ACDB_DEV_TYPE_OUT;
2127 else
2128 acdb_dev_type = ACDB_DEV_TYPE_IN;
2129 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
2130 }
2131 return 0;
2132}
2133
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002134int platform_send_audio_calibration_v2(void *platform, struct audio_usecase *usecase,
2135 int app_type, int sample_rate)
2136{
2137 struct platform_data *my_data = (struct platform_data *)platform;
2138 int acdb_dev_id, acdb_dev_type;
vivek mehta7e573672018-03-13 17:41:41 -07002139 int snd_device = usecase->out_snd_device;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002140 int new_snd_device[SND_DEVICE_OUT_END] = {0};
2141 int i, num_devices = 1;
2142
2143 if (!platform_supports_app_type_cfg()) // use v1 instead
2144 return -ENOSYS;
2145
vivek mehta7e573672018-03-13 17:41:41 -07002146 if ((usecase->type == PCM_HFP_CALL) || (usecase->type == PCM_CAPTURE))
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002147 snd_device = usecase->in_snd_device;
2148
2149 // skipped over get_spkr_prot_device
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002150 acdb_dev_id = platform_get_snd_device_acdb_id(snd_device);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002151 if (acdb_dev_id < 0) {
2152 ALOGE("%s: Could not find acdb id for device(%d)",
2153 __func__, snd_device);
2154 return -EINVAL;
2155 }
2156
2157 if (platform_can_split_snd_device(snd_device,
2158 &num_devices, new_snd_device) < 0) {
2159 new_snd_device[0] = snd_device;
2160 }
2161
2162 for (i = 0; i < num_devices; i++) {
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002163 acdb_dev_id = platform_get_snd_device_acdb_id(new_snd_device[i]);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002164 if (acdb_dev_id < 0) {
2165 ALOGE("%s: Could not find acdb id for device(%d)",
2166 __func__, new_snd_device[i]);
2167 return -EINVAL;
2168 }
2169 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
2170 __func__, new_snd_device[i], acdb_dev_id);
2171 if (new_snd_device[i] >= SND_DEVICE_OUT_BEGIN &&
2172 new_snd_device[i] < SND_DEVICE_OUT_END)
2173 acdb_dev_type = ACDB_DEV_TYPE_OUT;
2174 else
2175 acdb_dev_type = ACDB_DEV_TYPE_IN;
2176
2177 if (my_data->acdb_send_audio_cal_v3) {
2178 my_data->acdb_send_audio_cal_v3(acdb_dev_id, acdb_dev_type,
2179 app_type, sample_rate, i);
2180 } else if (my_data->acdb_send_audio_cal) {
2181 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type); // this version differs from internal
2182 }
2183 }
2184
2185 return 0;
2186}
2187
2188
Eric Laurentb23d5282013-05-14 15:27:20 -07002189int platform_switch_voice_call_device_pre(void *platform)
2190{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002191 struct platform_data *my_data = (struct platform_data *)platform;
2192 int ret = 0;
2193
2194 if (my_data->csd != NULL &&
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002195 voice_is_in_call(my_data->adev)) {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002196 /* This must be called before disabling mixer controls on APQ side */
2197 ret = my_data->csd->disable_device();
2198 if (ret < 0) {
2199 ALOGE("%s: csd_client_disable_device, failed, error %d",
2200 __func__, ret);
2201 }
2202 }
2203 return ret;
2204}
2205
2206int platform_switch_voice_call_enable_device_config(void *platform,
2207 snd_device_t out_snd_device,
2208 snd_device_t in_snd_device)
2209{
2210 struct platform_data *my_data = (struct platform_data *)platform;
2211 int acdb_rx_id, acdb_tx_id;
2212 int ret = 0;
2213
2214 if (my_data->csd == NULL)
2215 return ret;
2216
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002217 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
keunhui.park2f7306a2015-07-16 16:48:06 +09002218 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002219
2220 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
2221 ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
2222 if (ret < 0) {
2223 ALOGE("%s: csd_enable_device_config, failed, error %d",
2224 __func__, ret);
2225 }
2226 } else {
2227 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2228 acdb_rx_id, acdb_tx_id);
2229 }
2230
2231 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002232}
2233
2234int platform_switch_voice_call_device_post(void *platform,
2235 snd_device_t out_snd_device,
2236 snd_device_t in_snd_device)
2237{
2238 struct platform_data *my_data = (struct platform_data *)platform;
2239 int acdb_rx_id, acdb_tx_id;
2240
2241 if (my_data->acdb_send_voice_cal == NULL) {
2242 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
2243 } else {
keunhui.park2f7306a2015-07-16 16:48:06 +09002244 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
2245 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07002246
2247 if (acdb_rx_id > 0 && acdb_tx_id > 0)
2248 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
2249 else
2250 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2251 acdb_rx_id, acdb_tx_id);
2252 }
2253
2254 return 0;
2255}
2256
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002257int platform_switch_voice_call_usecase_route_post(void *platform,
2258 snd_device_t out_snd_device,
2259 snd_device_t in_snd_device)
2260{
2261 struct platform_data *my_data = (struct platform_data *)platform;
2262 int acdb_rx_id, acdb_tx_id;
2263 int ret = 0;
2264
2265 if (my_data->csd == NULL)
2266 return ret;
2267
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002268 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
keunhui.park2f7306a2015-07-16 16:48:06 +09002269 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002270
2271 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
2272 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
2273 my_data->adev->acdb_settings);
2274 if (ret < 0) {
2275 ALOGE("%s: csd_enable_device, failed, error %d", __func__, ret);
2276 }
2277 } else {
2278 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2279 acdb_rx_id, acdb_tx_id);
2280 }
2281
2282 return ret;
2283}
2284
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002285int platform_start_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07002286{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002287 struct platform_data *my_data = (struct platform_data *)platform;
2288 int ret = 0;
2289
2290 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002291 ret = my_data->csd->start_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002292 if (ret < 0) {
2293 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
2294 }
2295 }
2296 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002297}
2298
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002299int platform_stop_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07002300{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002301 struct platform_data *my_data = (struct platform_data *)platform;
2302 int ret = 0;
2303
2304 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002305 ret = my_data->csd->stop_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002306 if (ret < 0) {
2307 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
2308 }
2309 }
2310 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002311}
2312
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002313int platform_get_sample_rate(void *platform, uint32_t *rate)
2314{
2315 struct platform_data *my_data = (struct platform_data *)platform;
2316 int ret = 0;
2317
2318 if (my_data->csd != NULL) {
2319 ret = my_data->csd->get_sample_rate(rate);
2320 if (ret < 0) {
2321 ALOGE("%s: csd_get_sample_rate error %d\n", __func__, ret);
2322 }
2323 }
2324 return ret;
2325}
2326
vivek mehtab6506412015-08-07 16:55:17 -07002327void platform_set_speaker_gain_in_combo(struct audio_device *adev,
2328 snd_device_t snd_device,
2329 bool enable)
2330{
2331 const char* name;
2332 switch (snd_device) {
2333 case SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES:
2334 if (enable)
2335 name = "spkr-gain-in-headphone-combo";
2336 else
2337 name = "speaker-gain-default";
2338 break;
2339 case SND_DEVICE_OUT_SPEAKER_AND_LINE:
2340 if (enable)
2341 name = "spkr-gain-in-line-combo";
2342 else
2343 name = "speaker-gain-default";
2344 break;
2345 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES:
2346 if (enable)
2347 name = "spkr-safe-gain-in-headphone-combo";
2348 else
2349 name = "speaker-safe-gain-default";
2350 break;
2351 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE:
2352 if (enable)
2353 name = "spkr-safe-gain-in-line-combo";
2354 else
2355 name = "speaker-safe-gain-default";
2356 break;
2357 default:
2358 return;
2359 }
2360
2361 audio_route_apply_and_update_path(adev->audio_route, name);
2362}
2363
Eric Laurentb23d5282013-05-14 15:27:20 -07002364int platform_set_voice_volume(void *platform, int volume)
2365{
2366 struct platform_data *my_data = (struct platform_data *)platform;
2367 struct audio_device *adev = my_data->adev;
2368 struct mixer_ctl *ctl;
sangwoo53b2cf02013-07-25 19:18:44 -07002369 const char *mixer_ctl_name = "Voice Rx Gain";
Nadav Barc46d0fa2017-12-24 14:50:37 +02002370 const char *mute_mixer_ctl_name = "Voice Rx Device Mute";
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002371 int vol_index = 0, ret = 0;
2372 uint32_t set_values[ ] = {0,
2373 ALL_SESSION_VSID,
2374 DEFAULT_VOLUME_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07002375
2376 // Voice volume levels are mapped to adsp volume levels as follows.
2377 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
2378 // But this values don't changed in kernel. So, below change is need.
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09002379 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, my_data->max_vol_index);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002380 set_values[0] = vol_index;
Eric Laurentb23d5282013-05-14 15:27:20 -07002381
2382 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2383 if (!ctl) {
2384 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2385 __func__, mixer_ctl_name);
2386 return -EINVAL;
2387 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002388 ALOGV("Setting voice volume index: %d", set_values[0]);
2389 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2390
Nadav Barc46d0fa2017-12-24 14:50:37 +02002391 // Send mute command in case volume index is max since indexes are inverted
2392 // for mixer controls.
2393 if (vol_index == my_data->max_vol_index) {
2394 set_values[0] = 1;
2395 }
2396 else {
2397 set_values[0] = 0;
2398 }
2399
2400 ctl = mixer_get_ctl_by_name(adev->mixer, mute_mixer_ctl_name);
2401 if (!ctl) {
2402 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2403 __func__, mute_mixer_ctl_name);
2404 return -EINVAL;
2405 }
2406 ALOGV("%s: Setting RX Device Mute to: %d", __func__, set_values[0]);
2407 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2408
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002409 if (my_data->csd != NULL) {
2410 ret = my_data->csd->volume(ALL_SESSION_VSID, volume,
2411 DEFAULT_VOLUME_RAMP_DURATION_MS);
2412 if (ret < 0) {
2413 ALOGE("%s: csd_volume error %d", __func__, ret);
2414 }
2415 }
2416 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002417}
2418
2419int platform_set_mic_mute(void *platform, bool state)
2420{
2421 struct platform_data *my_data = (struct platform_data *)platform;
2422 struct audio_device *adev = my_data->adev;
2423 struct mixer_ctl *ctl;
2424 const char *mixer_ctl_name = "Voice Tx Mute";
sangwoo53b2cf02013-07-25 19:18:44 -07002425 int ret = 0;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002426 uint32_t set_values[ ] = {0,
2427 ALL_SESSION_VSID,
2428 DEFAULT_MUTE_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07002429
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09002430 if (adev->mode != AUDIO_MODE_IN_CALL &&
2431 adev->mode != AUDIO_MODE_IN_COMMUNICATION)
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002432 return 0;
2433
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09002434 if (adev->enable_hfp)
2435 mixer_ctl_name = "HFP Tx Mute";
2436
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002437 set_values[0] = state;
2438 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2439 if (!ctl) {
2440 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2441 __func__, mixer_ctl_name);
2442 return -EINVAL;
2443 }
2444 ALOGV("Setting voice mute state: %d", state);
2445 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2446
2447 if (my_data->csd != NULL) {
2448 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state,
2449 DEFAULT_MUTE_RAMP_DURATION_MS);
sangwoo53b2cf02013-07-25 19:18:44 -07002450 if (ret < 0) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002451 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
sangwoo53b2cf02013-07-25 19:18:44 -07002452 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002453 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002454 return ret;
2455}
Eric Laurentb23d5282013-05-14 15:27:20 -07002456
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002457int platform_set_device_mute(void *platform, bool state, char *dir)
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 char *mixer_ctl_name = NULL;
2463 int ret = 0;
2464 uint32_t set_values[ ] = {0,
2465 ALL_SESSION_VSID,
2466 0};
2467 if(dir == NULL) {
2468 ALOGE("%s: Invalid direction:%s", __func__, dir);
2469 return -EINVAL;
2470 }
2471
2472 if (!strncmp("rx", dir, sizeof("rx"))) {
2473 mixer_ctl_name = "Voice Rx Device Mute";
2474 } else if (!strncmp("tx", dir, sizeof("tx"))) {
2475 mixer_ctl_name = "Voice Tx Device Mute";
2476 } else {
2477 return -EINVAL;
2478 }
2479
2480 set_values[0] = state;
2481 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2482 if (!ctl) {
2483 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2484 __func__, mixer_ctl_name);
2485 return -EINVAL;
2486 }
2487
2488 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
2489 __func__,state, mixer_ctl_name);
2490 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2491
2492 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002493}
2494
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002495int platform_can_split_snd_device(snd_device_t snd_device,
2496 int *num_devices,
2497 snd_device_t *new_snd_devices)
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002498{
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002499 int ret = -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002500 if (NULL == num_devices || NULL == new_snd_devices) {
2501 ALOGE("%s: NULL pointer ..", __func__);
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002502 return -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002503 }
2504
2505 /*
2506 * If wired headset/headphones/line devices share the same backend
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002507 * with speaker/earpiece this routine returns -EINVAL.
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002508 */
2509 if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES &&
2510 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_HEADPHONES)) {
2511 *num_devices = 2;
2512 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2513 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002514 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002515 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_LINE &&
2516 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_LINE)) {
2517 *num_devices = 2;
2518 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2519 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002520 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002521 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES &&
2522 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_HEADPHONES)) {
2523 *num_devices = 2;
2524 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2525 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002526 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002527 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE &&
2528 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_LINE)) {
2529 *num_devices = 2;
2530 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2531 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002532 ret = 0;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002533 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO &&
2534 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2535 SND_DEVICE_OUT_BT_SCO)) {
2536 *num_devices = 2;
2537 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2538 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO;
2539 ret = 0;
2540 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB &&
2541 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2542 SND_DEVICE_OUT_BT_SCO_WB)) {
2543 *num_devices = 2;
2544 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2545 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO_WB;
2546 ret = 0;
David Linee3fe402017-03-13 10:00:42 -07002547 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET &&
2548 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_USB_HEADSET)) {
2549 *num_devices = 2;
2550 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2551 new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
2552 ret = 0;
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07002553 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET &&
2554 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_USB_HEADSET)) {
2555 *num_devices = 2;
2556 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2557 new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
2558 ret = 0;
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002559 } else if (SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP == snd_device &&
2560 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2561 SND_DEVICE_OUT_BT_A2DP)) {
2562 *num_devices = 2;
2563 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2564 new_snd_devices[1] = SND_DEVICE_OUT_BT_A2DP;
2565 ret = 0;
Aniket Kumar Lata9723a962018-05-16 17:41:55 -07002566 } else if (SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP == snd_device &&
2567 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE,
2568 SND_DEVICE_OUT_BT_A2DP)) {
2569 *num_devices = 2;
2570 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2571 new_snd_devices[1] = SND_DEVICE_OUT_BT_A2DP;
2572 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002573 }
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002574
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002575 return ret;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002576}
2577
Eric Laurentb23d5282013-05-14 15:27:20 -07002578snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
2579{
2580 struct platform_data *my_data = (struct platform_data *)platform;
2581 struct audio_device *adev = my_data->adev;
2582 audio_mode_t mode = adev->mode;
2583 snd_device_t snd_device = SND_DEVICE_NONE;
2584
2585 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
2586 if (devices == AUDIO_DEVICE_NONE ||
2587 devices & AUDIO_DEVICE_BIT_IN) {
2588 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
2589 goto exit;
2590 }
2591
Eric Laurent1b491552015-09-15 17:52:41 -07002592 if (popcount(devices) == 2) {
2593 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2594 AUDIO_DEVICE_OUT_SPEAKER) ||
2595 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2596 AUDIO_DEVICE_OUT_SPEAKER)) {
2597 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
2598 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2599 AUDIO_DEVICE_OUT_SPEAKER)) {
2600 snd_device = SND_DEVICE_OUT_SPEAKER_AND_LINE;
2601 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2602 AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
2603 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2604 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2605 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES;
2606 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2607 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2608 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE;
2609 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
2610 AUDIO_DEVICE_OUT_SPEAKER)) {
2611 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002612 } else if ((devices & AUDIO_DEVICE_OUT_ALL_SCO) &&
2613 ((devices & ~AUDIO_DEVICE_OUT_ALL_SCO) == AUDIO_DEVICE_OUT_SPEAKER)) {
2614 snd_device = adev->bt_wb_speech_enabled ?
2615 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB :
2616 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO;
Eric Laurent99dab492017-06-17 15:19:08 -07002617 } else if ((devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
2618 AUDIO_DEVICE_OUT_SPEAKER)) ||
2619 (devices == (AUDIO_DEVICE_OUT_USB_HEADSET |
2620 AUDIO_DEVICE_OUT_SPEAKER))) {
David Linee3fe402017-03-13 10:00:42 -07002621 snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET;
Eric Laurentd0f7c262017-07-05 09:09:12 -07002622 } else if ((devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
2623 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) ||
2624 (devices == (AUDIO_DEVICE_OUT_USB_HEADSET |
2625 AUDIO_DEVICE_OUT_SPEAKER_SAFE))) {
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07002626 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET;
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002627 } else if ((devices & AUDIO_DEVICE_OUT_SPEAKER) &&
2628 (devices & AUDIO_DEVICE_OUT_ALL_A2DP)) {
2629 snd_device = SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP;
Aniket Kumar Lata9723a962018-05-16 17:41:55 -07002630 } else if ((devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) &&
2631 (devices & AUDIO_DEVICE_OUT_ALL_A2DP)) {
2632 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP;
Eric Laurent1b491552015-09-15 17:52:41 -07002633 } else {
2634 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
2635 goto exit;
2636 }
2637 if (snd_device != SND_DEVICE_NONE) {
2638 goto exit;
2639 }
2640 }
2641
2642 if (popcount(devices) != 1) {
2643 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
2644 goto exit;
2645 }
2646
Madhuri Athota3f6051b2016-10-13 23:25:38 +05302647 if (voice_is_in_call(adev) || adev->enable_voicerx || audio_extn_hfp_is_active(adev)) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002648 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002649 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2650 devices & AUDIO_DEVICE_OUT_LINE) {
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002651 if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002652 (adev->voice.tty_mode == TTY_MODE_FULL))
Eric Laurentb23d5282013-05-14 15:27:20 -07002653 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002654 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002655 (adev->voice.tty_mode == TTY_MODE_VCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002656 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002657 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002658 (adev->voice.tty_mode == TTY_MODE_HCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002659 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002660 else {
2661 if (devices & AUDIO_DEVICE_OUT_LINE)
2662 snd_device = SND_DEVICE_OUT_VOICE_LINE;
2663 else
2664 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
2665 }
Eric Laurent99dab492017-06-17 15:19:08 -07002666 } else if (audio_is_usb_out_device(devices)) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002667 if (voice_is_in_call(adev)) {
2668 switch (adev->voice.tty_mode) {
2669 case TTY_MODE_FULL:
2670 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_USB;
2671 break;
2672 case TTY_MODE_VCO:
2673 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_USB;
2674 break;
2675 case TTY_MODE_HCO:
2676 // since Hearing will be on handset\speaker, use existing device
2677 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
2678 break;
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002679 case TTY_MODE_OFF:
2680 break;
vivek mehtaa6b79742017-03-09 15:40:43 -08002681 default:
2682 ALOGE("%s: Invalid TTY mode (%#x)",
2683 __func__, adev->voice.tty_mode);
2684 }
2685 }
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002686 if (snd_device == SND_DEVICE_NONE) {
2687 snd_device = audio_extn_usb_is_capture_supported() ?
2688 SND_DEVICE_OUT_VOICE_USB_HEADSET :
2689 SND_DEVICE_OUT_VOICE_USB_HEADPHONES;
2690 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002691 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002692 if (adev->bt_wb_speech_enabled) {
2693 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2694 } else {
2695 snd_device = SND_DEVICE_OUT_BT_SCO;
2696 }
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002697 } else if (devices & AUDIO_DEVICE_OUT_ALL_A2DP) {
2698 snd_device = SND_DEVICE_OUT_BT_A2DP;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002699 } else if (devices & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002700 if (!adev->enable_hfp) {
2701 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
2702 } else {
2703 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_HFP;
2704 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002705 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002706 if(adev->voice.hac)
2707 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2708 else if (is_operator_tmus())
Eric Laurentb23d5282013-05-14 15:27:20 -07002709 snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS;
2710 else
Eric Laurentb4d368e2014-06-25 10:21:54 -05002711 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002712 } else if (devices & AUDIO_DEVICE_OUT_TELEPHONY_TX)
2713 snd_device = SND_DEVICE_OUT_VOICE_TX;
2714
Eric Laurentb23d5282013-05-14 15:27:20 -07002715 if (snd_device != SND_DEVICE_NONE) {
2716 goto exit;
2717 }
2718 }
2719
Eric Laurentb23d5282013-05-14 15:27:20 -07002720 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2721 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2722 snd_device = SND_DEVICE_OUT_HEADPHONES;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002723 } else if (devices & AUDIO_DEVICE_OUT_LINE) {
2724 snd_device = SND_DEVICE_OUT_LINE;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002725 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) {
2726 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE;
Eric Laurentb23d5282013-05-14 15:27:20 -07002727 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
andysu5b30b062018-04-20 16:34:06 +08002728 /*
2729 * Perform device switch only if acdb tuning is different between SPEAKER & SPEAKER_REVERSE,
2730 * Or there will be a small pause while performing device switch.
2731 */
2732 if (my_data->speaker_lr_swap &&
2733 (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
2734 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]))
Eric Laurentb23d5282013-05-14 15:27:20 -07002735 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
2736 else
2737 snd_device = SND_DEVICE_OUT_SPEAKER;
2738 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002739 if (adev->bt_wb_speech_enabled) {
2740 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2741 } else {
2742 snd_device = SND_DEVICE_OUT_BT_SCO;
2743 }
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002744 } else if (devices & AUDIO_DEVICE_OUT_ALL_A2DP) {
2745 snd_device = SND_DEVICE_OUT_BT_A2DP;
Eric Laurentb23d5282013-05-14 15:27:20 -07002746 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2747 snd_device = SND_DEVICE_OUT_HDMI ;
Eric Laurent99dab492017-06-17 15:19:08 -07002748 } else if (audio_is_usb_out_device(devices)) {
jasmine cha270b7762018-03-30 15:41:33 +08002749 if (audio_extn_ma_supported_usb())
2750 snd_device = SND_DEVICE_OUT_USB_HEADSET_SPEC;
2751 else if (audio_extn_usb_is_capture_supported())
David Linee3fe402017-03-13 10:00:42 -07002752 snd_device = SND_DEVICE_OUT_USB_HEADSET;
2753 else
2754 snd_device = SND_DEVICE_OUT_USB_HEADPHONES;
2755 }else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002756 /*HAC support for voice-ish audio (eg visual voicemail)*/
2757 if(adev->voice.hac)
2758 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2759 else
2760 snd_device = SND_DEVICE_OUT_HANDSET;
Eric Laurentb23d5282013-05-14 15:27:20 -07002761 } else {
2762 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
2763 }
2764exit:
2765 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
2766 return snd_device;
2767}
2768
2769snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
2770{
2771 struct platform_data *my_data = (struct platform_data *)platform;
2772 struct audio_device *adev = my_data->adev;
2773 audio_source_t source = (adev->active_input == NULL) ?
2774 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
2775
2776 audio_mode_t mode = adev->mode;
2777 audio_devices_t in_device = ((adev->active_input == NULL) ?
2778 AUDIO_DEVICE_NONE : adev->active_input->device)
2779 & ~AUDIO_DEVICE_BIT_IN;
2780 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
2781 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
2782 snd_device_t snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002783 int channel_count = popcount(channel_mask);
Eric Laurentb23d5282013-05-14 15:27:20 -07002784
Prashant Malanic92c5962015-08-11 15:10:18 -07002785 ALOGV("%s: enter: out_device(%#x) in_device(%#x) channel_count (%d) channel_mask (0x%x)",
2786 __func__, out_device, in_device, channel_count, channel_mask);
Devin Kimd789e432016-10-26 15:07:27 -07002787 if ((out_device != AUDIO_DEVICE_NONE) && (voice_is_in_call(adev) ||
2788 audio_extn_hfp_is_active(adev))) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002789 if (adev->voice.tty_mode != TTY_MODE_OFF) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002790 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002791 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2792 out_device & AUDIO_DEVICE_OUT_LINE) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002793 switch (adev->voice.tty_mode) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002794 case TTY_MODE_FULL:
2795 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
2796 break;
2797 case TTY_MODE_VCO:
2798 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
2799 break;
2800 case TTY_MODE_HCO:
2801 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
2802 break;
2803 default:
2804 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
2805 }
2806 goto exit;
Eric Laurent99dab492017-06-17 15:19:08 -07002807 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002808 switch (adev->voice.tty_mode) {
2809 case TTY_MODE_FULL:
2810 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC;
2811 break;
2812 case TTY_MODE_VCO:
2813 // since voice will be captured from handset mic, use existing device
2814 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
2815 break;
2816 case TTY_MODE_HCO:
2817 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC;
2818 break;
2819 default:
2820 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
Eric Laurentb23d5282013-05-14 15:27:20 -07002821 }
2822 goto exit;
2823 }
2824 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002825 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002826 if (my_data->fluence_in_voice_call == false) {
2827 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2828 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002829 if (is_operator_tmus())
2830 snd_device = SND_DEVICE_IN_VOICE_DMIC_TMUS;
Eric Laurentb23d5282013-05-14 15:27:20 -07002831 else
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002832 snd_device = SND_DEVICE_IN_VOICE_DMIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002833 }
2834 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2835 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
2836 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002837 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002838 if (adev->bluetooth_nrec)
2839 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2840 else
2841 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002842 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002843 if (adev->bluetooth_nrec)
2844 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2845 else
2846 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002847 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002848 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Prashant Malanic92c5962015-08-11 15:10:18 -07002849 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
2850 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2851 out_device & AUDIO_DEVICE_OUT_LINE) {
2852 if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
2853 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
2854 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
2855 } else {
2856 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2857 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002858 }
vivek mehtafe121d52015-08-10 23:39:23 -07002859
2860 //select default
2861 if (snd_device == SND_DEVICE_NONE) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002862 if (!adev->enable_hfp) {
2863 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2864 } else {
2865 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP;
2866 platform_set_echo_reference(adev, true, out_device);
2867 }
vivek mehtafe121d52015-08-10 23:39:23 -07002868 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002869 } else if (out_device & AUDIO_DEVICE_OUT_TELEPHONY_TX) {
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002870 snd_device = SND_DEVICE_IN_VOICE_RX;
Eric Laurent99dab492017-06-17 15:19:08 -07002871 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
David Lin40b07892017-08-07 15:02:48 -07002872 if (audio_extn_usb_is_capture_supported()) {
2873 snd_device = SND_DEVICE_IN_VOICE_USB_HEADSET_MIC;
2874 } else if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
2875 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
2876 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
2877 } else {
2878 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2879 }
2880 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002881 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002882 } else if (source == AUDIO_SOURCE_CAMCORDER) {
2883 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
2884 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2885 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
2886 }
2887 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
2888 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002889 if (my_data->fluence_in_voice_rec && channel_count == 1) {
2890 if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2891 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002892 if (adev->active_input->enable_aec)
2893 snd_device = SND_DEVICE_IN_HANDSET_QMIC_AEC;
2894 else
2895 snd_device = SND_DEVICE_IN_HANDSET_QMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002896 } else if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2897 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002898 if (adev->active_input->enable_aec)
2899 snd_device = SND_DEVICE_IN_HANDSET_TMIC_AEC;
2900 else
2901 snd_device = SND_DEVICE_IN_HANDSET_TMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002902 } else if (((my_data->fluence_type == FLUENCE_PRO_ENABLE) ||
2903 (my_data->fluence_type == FLUENCE_ENABLE)) &&
2904 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002905 if (adev->active_input->enable_aec)
2906 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
2907 else
2908 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
Prashant Malanic92c5962015-08-11 15:10:18 -07002909 }
2910 platform_set_echo_reference(adev, true, out_device);
2911 } else if ((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) &&
2912 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2913 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002914 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002915 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
2916 snd_device = SND_DEVICE_IN_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002917 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002918 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2919 snd_device = SND_DEVICE_IN_QUAD_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002920 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002921 if (snd_device == SND_DEVICE_NONE) {
vivek mehtaf3440682016-05-11 14:24:37 -07002922 if (adev->active_input->enable_aec) {
2923 if (adev->active_input->enable_ns) {
2924 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS;
2925 } else {
2926 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC;
2927 }
vivek mehta733c1df2016-04-04 15:09:24 -07002928 platform_set_echo_reference(adev, true, out_device);
vivek mehtaf3440682016-05-11 14:24:37 -07002929 } else if (adev->active_input->enable_ns) {
2930 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
2931 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002932 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
vivek mehtaf3440682016-05-11 14:24:37 -07002933 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002934 }
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -07002935 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2936 snd_device = SND_DEVICE_IN_VOICE_REC_HEADSET_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07002937 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002938 snd_device = SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002939 }
rago90fb9612015-12-02 11:37:53 -08002940 } else if (source == AUDIO_SOURCE_UNPROCESSED) {
2941 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
vivek mehta4ed66e62016-04-15 23:33:34 -07002942 if (((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) ||
2943 (channel_mask == AUDIO_CHANNEL_IN_STEREO)) &&
2944 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2945 snd_device = SND_DEVICE_IN_UNPROCESSED_STEREO_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002946 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07002947 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
2948 snd_device = SND_DEVICE_IN_UNPROCESSED_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002949 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07002950 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2951 snd_device = SND_DEVICE_IN_UNPROCESSED_QUAD_MIC;
2952 } else {
2953 snd_device = SND_DEVICE_IN_UNPROCESSED_MIC;
2954 }
rago90fb9612015-12-02 11:37:53 -08002955 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2956 snd_device = SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07002957 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002958 snd_device = SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC;
rago90fb9612015-12-02 11:37:53 -08002959 }
Eric Laurent50a38ed2015-10-14 18:48:06 -07002960 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION ||
rago90fb9612015-12-02 11:37:53 -08002961 mode == AUDIO_MODE_IN_COMMUNICATION) {
David Lin40b07892017-08-07 15:02:48 -07002962 if (out_device & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
2963 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2964 (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE | AUDIO_DEVICE_OUT_USB_HEADSET) &&
2965 !audio_extn_usb_is_capture_supported())) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002966 in_device = AUDIO_DEVICE_IN_BACK_MIC;
David Lin40b07892017-08-07 15:02:48 -07002967 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002968 if (adev->active_input) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002969 if (adev->active_input->enable_aec &&
2970 adev->active_input->enable_ns) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002971 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002972 if (my_data->fluence_in_spkr_mode &&
2973 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002974 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002975 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002976 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002977 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002978 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002979 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002980 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002981 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002982 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002983 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002984 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002985 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002986 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2987 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Eric Laurent99dab492017-06-17 15:19:08 -07002988 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002989 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002990 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002991 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002992 } else if (adev->active_input->enable_aec) {
2993 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2994 if (my_data->fluence_in_spkr_mode &&
2995 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002996 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002997 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002998 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002999 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003000 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003001 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
3002 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003003 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003004 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003005 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003006 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003007 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05003008 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3009 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Eric Laurent99dab492017-06-17 15:19:08 -07003010 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07003011 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
Eric Laurentcefbbac2014-09-04 13:54:10 -05003012 }
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08003013 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003014 } else if (adev->active_input->enable_ns) {
3015 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
3016 if (my_data->fluence_in_spkr_mode &&
3017 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003018 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003019 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003020 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003021 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003022 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003023 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
3024 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003025 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003026 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003027 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003028 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003029 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003030 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05003031 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003032 }
3033 } else if (source == AUDIO_SOURCE_DEFAULT) {
3034 goto exit;
3035 }
3036
3037
3038 if (snd_device != SND_DEVICE_NONE) {
3039 goto exit;
3040 }
3041
3042 if (in_device != AUDIO_DEVICE_NONE &&
3043 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
3044 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
3045 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003046 if ((my_data->source_mic_type & SOURCE_QUAD_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003047 channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003048 snd_device = SND_DEVICE_IN_QUAD_MIC;
3049 } else if ((my_data->source_mic_type & SOURCE_THREE_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003050 channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003051 snd_device = SND_DEVICE_IN_THREE_MIC;
3052 } else if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
3053 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003054 snd_device = SND_DEVICE_IN_HANDSET_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07003055 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
3056 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003057 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003058 } else {
3059 ALOGE("%s: something wrong (1): source type (%d) channel_count (%d) .."
3060 " channel mask (0x%x) no combination found .. setting to mono", __func__,
3061 my_data->source_mic_type, channel_count, channel_mask);
3062 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3063 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003064 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003065 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
3066 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003067 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07003068 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
3069 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003070 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003071 } else {
3072 ALOGE("%s: something wrong (2): source type (%d) channel_count (%d) .."
3073 " no combination found .. setting to mono", __func__,
3074 my_data->source_mic_type, channel_count);
3075 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
3076 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003077 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3078 snd_device = SND_DEVICE_IN_HEADSET_MIC;
3079 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003080 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003081 if (adev->bluetooth_nrec)
3082 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
3083 else
3084 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003085 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003086 if (adev->bluetooth_nrec)
3087 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
3088 else
3089 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003090 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003091 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
3092 snd_device = SND_DEVICE_IN_HDMI_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07003093 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
David Linee3fe402017-03-13 10:00:42 -07003094 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07003095 } else {
3096 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
3097 ALOGW("%s: Using default handset-mic", __func__);
3098 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3099 }
3100 } else {
3101 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
3102 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3103 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
3104 snd_device = SND_DEVICE_IN_HEADSET_MIC;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003105 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07003106 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003107 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05003108 out_device & AUDIO_DEVICE_OUT_LINE) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003109 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_SPEAKER_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_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003115 } else {
3116 ALOGE("%s: something wrong (3): source type (%d) channel_count (%d) .."
3117 " no combination found .. setting to mono", __func__,
3118 my_data->source_mic_type, channel_count);
3119 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
3120 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003121 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003122 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003123 if (adev->bluetooth_nrec)
3124 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
3125 else
3126 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003127 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003128 if (adev->bluetooth_nrec)
3129 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
3130 else
3131 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003132 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003133 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
3134 snd_device = SND_DEVICE_IN_HDMI_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07003135 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
David Linee3fe402017-03-13 10:00:42 -07003136 if (audio_extn_usb_is_capture_supported())
3137 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
3138 else
3139 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07003140 } else {
3141 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
3142 ALOGW("%s: Using default handset-mic", __func__);
3143 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3144 }
3145 }
3146exit:
3147 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
3148 return snd_device;
3149}
3150
3151int platform_set_hdmi_channels(void *platform, int channel_count)
3152{
3153 struct platform_data *my_data = (struct platform_data *)platform;
3154 struct audio_device *adev = my_data->adev;
3155 struct mixer_ctl *ctl;
3156 const char *channel_cnt_str = NULL;
3157 const char *mixer_ctl_name = "HDMI_RX Channels";
3158 switch (channel_count) {
3159 case 8:
3160 channel_cnt_str = "Eight"; break;
3161 case 7:
3162 channel_cnt_str = "Seven"; break;
3163 case 6:
3164 channel_cnt_str = "Six"; break;
3165 case 5:
3166 channel_cnt_str = "Five"; break;
3167 case 4:
3168 channel_cnt_str = "Four"; break;
3169 case 3:
3170 channel_cnt_str = "Three"; break;
3171 default:
3172 channel_cnt_str = "Two"; break;
3173 }
3174 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3175 if (!ctl) {
3176 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3177 __func__, mixer_ctl_name);
3178 return -EINVAL;
3179 }
3180 ALOGV("HDMI channel count: %s", channel_cnt_str);
3181 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
3182 return 0;
3183}
3184
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003185int platform_edid_get_max_channels(void *platform)
Eric Laurentb23d5282013-05-14 15:27:20 -07003186{
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003187 struct platform_data *my_data = (struct platform_data *)platform;
3188 struct audio_device *adev = my_data->adev;
Eric Laurentb23d5282013-05-14 15:27:20 -07003189 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
3190 char *sad = block;
3191 int num_audio_blocks;
3192 int channel_count;
3193 int max_channels = 0;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003194 int i, ret, count;
Eric Laurentb23d5282013-05-14 15:27:20 -07003195
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003196 struct mixer_ctl *ctl;
3197
3198 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
3199 if (!ctl) {
3200 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3201 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
Eric Laurentb23d5282013-05-14 15:27:20 -07003202 return 0;
3203 }
3204
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003205 mixer_ctl_update(ctl);
3206
3207 count = mixer_ctl_get_num_values(ctl);
Eric Laurentb23d5282013-05-14 15:27:20 -07003208
3209 /* Read SAD blocks, clamping the maximum size for safety */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003210 if (count > (int)sizeof(block))
3211 count = (int)sizeof(block);
Eric Laurentb23d5282013-05-14 15:27:20 -07003212
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003213 ret = mixer_ctl_get_array(ctl, block, count);
3214 if (ret != 0) {
3215 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
3216 return 0;
3217 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003218
3219 /* Calculate the number of SAD blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003220 num_audio_blocks = count / SAD_BLOCK_SIZE;
Eric Laurentb23d5282013-05-14 15:27:20 -07003221
3222 for (i = 0; i < num_audio_blocks; i++) {
3223 /* Only consider LPCM blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003224 if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
3225 sad += 3;
Eric Laurentb23d5282013-05-14 15:27:20 -07003226 continue;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003227 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003228
3229 channel_count = (sad[0] & 0x7) + 1;
3230 if (channel_count > max_channels)
3231 max_channels = channel_count;
3232
3233 /* Advance to next block */
3234 sad += 3;
3235 }
3236
3237 return max_channels;
3238}
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003239
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07003240int platform_set_incall_recording_session_id(void *platform,
3241 uint32_t session_id, int rec_mode)
3242{
3243 int ret = 0;
3244 struct platform_data *my_data = (struct platform_data *)platform;
3245 struct audio_device *adev = my_data->adev;
3246 struct mixer_ctl *ctl;
3247 const char *mixer_ctl_name = "Voc VSID";
3248 int num_ctl_values;
3249 int i;
3250
3251 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3252 if (!ctl) {
3253 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3254 __func__, mixer_ctl_name);
3255 ret = -EINVAL;
3256 } else {
3257 num_ctl_values = mixer_ctl_get_num_values(ctl);
3258 for (i = 0; i < num_ctl_values; i++) {
3259 if (mixer_ctl_set_value(ctl, i, session_id)) {
3260 ALOGV("Error: invalid session_id: %x", session_id);
3261 ret = -EINVAL;
3262 break;
3263 }
3264 }
3265 }
3266
3267 if (my_data->csd != NULL) {
3268 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
3269 if (ret < 0) {
3270 ALOGE("%s: csd_client_start_record failed, error %d",
3271 __func__, ret);
3272 }
3273 }
3274
3275 return ret;
3276}
3277
3278int platform_stop_incall_recording_usecase(void *platform)
3279{
3280 int ret = 0;
3281 struct platform_data *my_data = (struct platform_data *)platform;
3282
3283 if (my_data->csd != NULL) {
3284 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
3285 if (ret < 0) {
3286 ALOGE("%s: csd_client_stop_record failed, error %d",
3287 __func__, ret);
3288 }
3289 }
3290
3291 return ret;
3292}
3293
3294int platform_start_incall_music_usecase(void *platform)
3295{
3296 int ret = 0;
3297 struct platform_data *my_data = (struct platform_data *)platform;
3298
3299 if (my_data->csd != NULL) {
3300 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
3301 if (ret < 0) {
3302 ALOGE("%s: csd_client_start_playback failed, error %d",
3303 __func__, ret);
3304 }
3305 }
3306
3307 return ret;
3308}
3309
3310int platform_stop_incall_music_usecase(void *platform)
3311{
3312 int ret = 0;
3313 struct platform_data *my_data = (struct platform_data *)platform;
3314
3315 if (my_data->csd != NULL) {
3316 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
3317 if (ret < 0) {
3318 ALOGE("%s: csd_client_stop_playback failed, error %d",
3319 __func__, ret);
3320 }
3321 }
3322
3323 return ret;
3324}
3325
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003326int platform_set_parameters(void *platform, struct str_parms *parms)
3327{
3328 struct platform_data *my_data = (struct platform_data *)platform;
jasmine chac89321b2018-04-10 21:37:01 +08003329 char *value = NULL;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003330 char *kv_pairs = str_parms_to_str(parms);
jasmine chac89321b2018-04-10 21:37:01 +08003331 int len;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003332 int ret = 0, err;
3333
3334 if (kv_pairs == NULL) {
3335 ret = -EINVAL;
Jasmine Chaa314e192018-05-09 17:46:28 +08003336 ALOGE("%s: key-value pair is NULL", __func__);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003337 goto done;
3338 }
3339
3340 ALOGV("%s: enter: %s", __func__, kv_pairs);
3341
jasmine chac89321b2018-04-10 21:37:01 +08003342 len = strlen(kv_pairs);
Jasmine Chaa314e192018-05-09 17:46:28 +08003343 value = (char*)calloc(len + 1, sizeof(char));
jasmine chac89321b2018-04-10 21:37:01 +08003344 if (value == NULL) {
3345 ret = -ENOMEM;
Jasmine Chaa314e192018-05-09 17:46:28 +08003346 ALOGE("[%s] failed to allocate memory", __func__);
jasmine chac89321b2018-04-10 21:37:01 +08003347 goto done;
3348 }
3349
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003350 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME,
jasmine chac89321b2018-04-10 21:37:01 +08003351 value, len);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003352 if (err >= 0) {
3353 str_parms_del(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME);
3354 my_data->snd_card_name = strdup(value);
3355 ALOGV("%s: sound card name %s", __func__, my_data->snd_card_name);
3356 }
3357
keunhui.park2f7306a2015-07-16 16:48:06 +09003358 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO,
jasmine chac89321b2018-04-10 21:37:01 +08003359 value, len);
keunhui.park2f7306a2015-07-16 16:48:06 +09003360 if (err >= 0) {
3361 struct operator_info *info;
3362 char *str = value;
3363 char *name;
3364
3365 str_parms_del(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO);
3366 info = (struct operator_info *)calloc(1, sizeof(struct operator_info));
3367 name = strtok(str, ";");
3368 info->name = strdup(name);
3369 info->mccmnc = strdup(str + strlen(name) + 1);
3370
3371 list_add_tail(&operator_info_list, &info->list);
Joe Onorato188b6222016-03-01 11:02:27 -08003372 ALOGV("%s: add operator[%s] mccmnc[%s]", __func__, info->name, info->mccmnc);
keunhui.park2f7306a2015-07-16 16:48:06 +09003373 }
Prashant Malanic92c5962015-08-11 15:10:18 -07003374
Jasmine Chaa314e192018-05-09 17:46:28 +08003375 memset(value, 0, len + 1);
Eric Laurentc6333382015-09-14 12:43:44 -07003376 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT,
jasmine chac89321b2018-04-10 21:37:01 +08003377 value, len);
Prashant Malanic92c5962015-08-11 15:10:18 -07003378 if (err >= 0) {
Eric Laurentc6333382015-09-14 12:43:44 -07003379 str_parms_del(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT);
Prashant Malanic92c5962015-08-11 15:10:18 -07003380 my_data->max_mic_count = atoi(value);
3381 ALOGV("%s: max_mic_count %s/%d", __func__, value, my_data->max_mic_count);
Prashant Malanic92c5962015-08-11 15:10:18 -07003382 }
3383
jasmine chac89321b2018-04-10 21:37:01 +08003384 /* handle audio calibration parameters */
3385 set_audiocal(platform, parms, value, len);
3386
vivek mehta90933872017-06-15 18:04:39 -07003387 // to-do: disable setting sidetone gain, will revist this later
3388 // audio_extn_usb_set_sidetone_gain(parms, value, len);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003389done:
3390 ALOGV("%s: exit with code(%d)", __func__, ret);
3391 if (kv_pairs != NULL)
3392 free(kv_pairs);
jasmine chac89321b2018-04-10 21:37:01 +08003393 if (value != NULL)
3394 free(value);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003395
3396 return ret;
3397}
3398
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003399/* Delay in Us */
3400int64_t platform_render_latency(audio_usecase_t usecase)
3401{
3402 switch (usecase) {
3403 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
3404 return DEEP_BUFFER_PLATFORM_DELAY;
3405 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
3406 return LOW_LATENCY_PLATFORM_DELAY;
Haynes Mathew George03c40102016-01-29 17:57:48 -08003407 case USECASE_AUDIO_PLAYBACK_ULL:
3408 return ULL_PLATFORM_DELAY;
Eric Laurent0e46adf2016-12-16 12:49:24 -08003409 case USECASE_AUDIO_PLAYBACK_MMAP:
3410 return MMAP_PLATFORM_DELAY;
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003411 default:
3412 return 0;
3413 }
3414}
Haynes Mathew George98c95622014-06-20 19:14:25 -07003415
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003416int platform_set_snd_device_backend(snd_device_t device, const char *backend_tag,
3417 const char * hw_interface)
Haynes Mathew George98c95622014-06-20 19:14:25 -07003418{
3419 int ret = 0;
3420
3421 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
3422 ALOGE("%s: Invalid snd_device = %d",
3423 __func__, device);
3424 ret = -EINVAL;
3425 goto done;
3426 }
3427
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003428 ALOGV("%s: backend_tag_table[%s]: old = %s new = %s", __func__,
3429 platform_get_snd_device_name(device),
3430 backend_tag_table[device] != NULL ? backend_tag_table[device]: "null", backend_tag);
3431 if (backend_tag_table[device]) {
3432 free(backend_tag_table[device]);
Haynes Mathew George98c95622014-06-20 19:14:25 -07003433 }
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003434 backend_tag_table[device] = strdup(backend_tag);
3435
3436 if (hw_interface != NULL) {
3437 if (hw_interface_table[device])
3438 free(hw_interface_table[device]);
3439 ALOGV("%s: hw_interface_table[%d] = %s", __func__, device, hw_interface);
3440 hw_interface_table[device] = strdup(hw_interface);
3441 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07003442done:
3443 return ret;
3444}
3445
3446int platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t pcm_id)
3447{
3448 int ret = 0;
3449 if ((usecase <= USECASE_INVALID) || (usecase >= AUDIO_USECASE_MAX)) {
3450 ALOGE("%s: invalid usecase case idx %d", __func__, usecase);
3451 ret = -EINVAL;
3452 goto done;
3453 }
3454
3455 if ((type != 0) && (type != 1)) {
3456 ALOGE("%s: invalid usecase type", __func__);
3457 ret = -EINVAL;
3458 }
vivek mehtaa68fea62017-06-08 19:04:02 -07003459 ALOGV("%s: pcm_device_table[%d %s][%d] = %d", __func__, usecase,
3460 use_case_table[usecase],
3461 type, pcm_id);
Haynes Mathew George98c95622014-06-20 19:14:25 -07003462 pcm_device_table[usecase][type] = pcm_id;
3463done:
3464 return ret;
3465}
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003466
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07003467#define DEFAULT_NOMINAL_SPEAKER_GAIN 20
3468int ramp_speaker_gain(struct audio_device *adev, bool ramp_up, int target_ramp_up_gain) {
3469 // backup_gain: gain to try to set in case of an error during ramp
3470 int start_gain, end_gain, step, backup_gain, i;
3471 bool error = false;
3472 const struct mixer_ctl *ctl;
3473 const char *mixer_ctl_name_gain_left = "Left Speaker Gain";
3474 const char *mixer_ctl_name_gain_right = "Right Speaker Gain";
3475 struct mixer_ctl *ctl_left = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_left);
3476 struct mixer_ctl *ctl_right = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_right);
3477 if (!ctl_left || !ctl_right) {
3478 ALOGE("%s: Could not get ctl for mixer cmd - %s or %s, not applying speaker gain ramp",
3479 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
3480 return -EINVAL;
3481 } else if ((mixer_ctl_get_num_values(ctl_left) != 1)
3482 || (mixer_ctl_get_num_values(ctl_right) != 1)) {
3483 ALOGE("%s: Unexpected num values for mixer cmd - %s or %s, not applying speaker gain ramp",
3484 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
3485 return -EINVAL;
3486 }
3487 if (ramp_up) {
3488 start_gain = 0;
3489 end_gain = target_ramp_up_gain > 0 ? target_ramp_up_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
3490 step = +1;
3491 backup_gain = end_gain;
3492 } else {
3493 // using same gain on left and right
3494 const int left_gain = mixer_ctl_get_value(ctl_left, 0);
3495 start_gain = left_gain > 0 ? left_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
3496 end_gain = 0;
3497 step = -1;
3498 backup_gain = start_gain;
3499 }
3500 for (i = start_gain ; i != (end_gain + step) ; i += step) {
3501 //ALOGV("setting speaker gain to %d", i);
3502 if (mixer_ctl_set_value(ctl_left, 0, i)) {
3503 ALOGE("%s: error setting %s to %d during gain ramp",
3504 __func__, mixer_ctl_name_gain_left, i);
3505 error = true;
3506 break;
3507 }
3508 if (mixer_ctl_set_value(ctl_right, 0, i)) {
3509 ALOGE("%s: error setting %s to %d during gain ramp",
3510 __func__, mixer_ctl_name_gain_right, i);
3511 error = true;
3512 break;
3513 }
3514 usleep(1000);
3515 }
3516 if (error) {
3517 // an error occured during the ramp, let's still try to go back to a safe volume
3518 if (mixer_ctl_set_value(ctl_left, 0, backup_gain)) {
3519 ALOGE("%s: error restoring left gain to %d", __func__, backup_gain);
3520 }
3521 if (mixer_ctl_set_value(ctl_right, 0, backup_gain)) {
3522 ALOGE("%s: error restoring right gain to %d", __func__, backup_gain);
3523 }
3524 }
3525 return start_gain;
3526}
3527
vivek mehtae59cfb22017-06-16 15:57:11 -07003528int platform_set_swap_mixer(struct audio_device *adev, bool swap_channels)
3529{
3530 const char *mixer_ctl_name = "Swap channel";
3531 struct mixer_ctl *ctl;
3532 const char *mixer_path;
3533 struct platform_data *my_data = (struct platform_data *)adev->platform;
3534
3535 // forced to set to swap, but device not rotated ... ignore set
3536 if (swap_channels && !my_data->speaker_lr_swap)
3537 return 0;
3538
3539 ALOGV("%s:", __func__);
3540
3541 if (swap_channels) {
3542 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER_REVERSE);
3543 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
3544 } else {
3545 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER);
3546 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
3547 }
3548
3549 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3550 if (!ctl) {
3551 ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name);
3552 return -EINVAL;
3553 }
3554
3555 if (mixer_ctl_set_value(ctl, 0, swap_channels) < 0) {
3556 ALOGE("%s: Could not set reverse cotrol %d",__func__, swap_channels);
3557 return -EINVAL;
3558 }
3559
3560 ALOGV("platfor_force_swap_channel :: Channel orientation ( %s ) ",
3561 swap_channels?"R --> L":"L --> R");
3562
3563 return 0;
3564}
3565
3566int platform_check_and_set_swap_lr_channels(struct audio_device *adev, bool swap_channels)
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003567{
3568 // only update if there is active pcm playback on speaker
3569 struct audio_usecase *usecase;
3570 struct listnode *node;
3571 struct platform_data *my_data = (struct platform_data *)adev->platform;
3572
vivek mehtae59cfb22017-06-16 15:57:11 -07003573 my_data->speaker_lr_swap = swap_channels;
Jean-Michel Trivif7148702016-09-16 18:23:05 -07003574
vivek mehtae59cfb22017-06-16 15:57:11 -07003575 return platform_set_swap_channels(adev, swap_channels);
3576}
Jean-Michel Trivif7148702016-09-16 18:23:05 -07003577
vivek mehtae59cfb22017-06-16 15:57:11 -07003578int platform_set_swap_channels(struct audio_device *adev, bool swap_channels)
3579{
3580 // only update if there is active pcm playback on speaker
3581 struct audio_usecase *usecase;
3582 struct listnode *node;
3583 struct platform_data *my_data = (struct platform_data *)adev->platform;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003584
vivek mehtae59cfb22017-06-16 15:57:11 -07003585 // do not swap channels in audio modes with concurrent capture and playback
3586 // as this may break the echo reference
3587 if ((adev->mode == AUDIO_MODE_IN_COMMUNICATION) || (adev->mode == AUDIO_MODE_IN_CALL)) {
3588 ALOGV("%s: will not swap due to audio mode %d", __func__, adev->mode);
3589 return 0;
3590 }
3591
3592 list_for_each(node, &adev->usecase_list) {
3593 usecase = node_to_item(node, struct audio_usecase, list);
3594 if (usecase->type == PCM_PLAYBACK &&
3595 usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) {
3596 /*
3597 * If acdb tuning is different for SPEAKER_REVERSE, it is must
3598 * to perform device switch to disable the current backend to
3599 * enable it with new acdb data.
3600 */
3601 if (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
3602 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]) {
3603 const int initial_skpr_gain = ramp_speaker_gain(adev, false /*ramp_up*/, -1);
3604 select_devices(adev, usecase->id);
3605 if (initial_skpr_gain != -EINVAL)
3606 ramp_speaker_gain(adev, true /*ramp_up*/, initial_skpr_gain);
3607
3608 } else {
3609 platform_set_swap_mixer(adev, swap_channels);
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003610 }
vivek mehtae59cfb22017-06-16 15:57:11 -07003611 break;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003612 }
3613 }
vivek mehtae59cfb22017-06-16 15:57:11 -07003614
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003615 return 0;
3616}
vivek mehtaa8d7c922016-05-25 14:40:44 -07003617
3618static struct amp_db_and_gain_table tbl_mapping[MAX_VOLUME_CAL_STEPS];
3619static int num_gain_tbl_entry = 0;
3620
3621bool platform_add_gain_level_mapping(struct amp_db_and_gain_table *tbl_entry) {
3622
3623 ALOGV("%s: enter .. add %f %f %d", __func__, tbl_entry->amp, tbl_entry->db, tbl_entry->level);
3624 if (num_gain_tbl_entry == -1) {
3625 ALOGE("%s: num entry beyond valid step levels or corrupted..rejecting custom mapping",
3626 __func__);
3627 return false;
3628 }
3629
3630 if (num_gain_tbl_entry >= MAX_VOLUME_CAL_STEPS) {
3631 ALOGE("%s: max entry reached max[%d] current index[%d] .. rejecting", __func__,
3632 MAX_VOLUME_CAL_STEPS, num_gain_tbl_entry);
3633 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
3634 return false;
3635 }
3636
3637 if (num_gain_tbl_entry > 0 && tbl_mapping[num_gain_tbl_entry - 1].amp >= tbl_entry->amp) {
3638 ALOGE("%s: value not in ascending order .. rejecting custom mapping", __func__);
3639 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
3640 return false;
3641 }
3642
3643 tbl_mapping[num_gain_tbl_entry] = *tbl_entry;
3644 ++num_gain_tbl_entry;
3645
3646 return true;
3647}
3648
3649int platform_get_gain_level_mapping(struct amp_db_and_gain_table *mapping_tbl,
3650 int table_size) {
3651 int itt = 0;
3652 ALOGV("platform_get_gain_level_mapping called ");
3653
3654 if (num_gain_tbl_entry <= 0 || num_gain_tbl_entry > MAX_VOLUME_CAL_STEPS) {
3655 ALOGD("%s: empty or currupted gain_mapping_table", __func__);
3656 return 0;
3657 }
3658
3659 for (; itt < num_gain_tbl_entry && itt <= table_size; itt++) {
3660 mapping_tbl[itt] = tbl_mapping[itt];
3661 ALOGV("%s: added amp[%f] db[%f] level[%d]", __func__,
3662 mapping_tbl[itt].amp, mapping_tbl[itt].db, mapping_tbl[itt].level);
3663 }
3664
3665 return num_gain_tbl_entry;
3666}
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07003667
3668int platform_snd_card_update(void *platform, card_status_t status)
3669{
3670 struct platform_data *my_data = (struct platform_data *)platform;
3671 struct audio_device *adev = my_data->adev;
3672
3673 if (status == CARD_STATUS_ONLINE) {
3674 if (my_data->acdb_send_custom_top)
3675 my_data->acdb_send_custom_top();
3676 }
3677 return 0;
3678}
David Linee3fe402017-03-13 10:00:42 -07003679
3680/*
3681 * configures afe with bit width and Sample Rate
3682 */
Haynes Mathew George65f6b432018-02-27 17:44:55 -08003683int platform_set_backend_cfg(const struct audio_device* adev,
3684 snd_device_t snd_device,
3685 const struct audio_backend_cfg *backend_cfg)
David Linee3fe402017-03-13 10:00:42 -07003686{
3687
3688 int ret = 0;
3689 const int backend_idx = platform_get_backend_index(snd_device);
3690 struct platform_data *my_data = (struct platform_data *)adev->platform;
3691 const unsigned int bit_width = backend_cfg->bit_width;
3692 const unsigned int sample_rate = backend_cfg->sample_rate;
3693 const unsigned int channels = backend_cfg->channels;
3694 const audio_format_t format = backend_cfg->format;
3695 const bool passthrough_enabled = backend_cfg->passthrough_enabled;
3696
3697
3698 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
3699 ", backend_idx %d device (%s)", __func__, bit_width,
3700 sample_rate, channels, backend_idx,
3701 platform_get_snd_device_name(snd_device));
3702
3703 if ((my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl) &&
3704 (bit_width != my_data->current_backend_cfg[backend_idx].bit_width)) {
3705
3706 struct mixer_ctl *ctl = NULL;
3707 ctl = mixer_get_ctl_by_name(adev->mixer,
3708 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
3709 if (!ctl) {
3710 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3711 __func__,
3712 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
3713 return -EINVAL;
3714 }
3715
3716 if (bit_width == 24) {
3717 if (format == AUDIO_FORMAT_PCM_24_BIT_PACKED)
3718 ret = mixer_ctl_set_enum_by_string(ctl, "S24_3LE");
3719 else
3720 ret = mixer_ctl_set_enum_by_string(ctl, "S24_LE");
3721 } else if (bit_width == 32) {
3722 ret = mixer_ctl_set_enum_by_string(ctl, "S32_LE");
3723 } else {
3724 ret = mixer_ctl_set_enum_by_string(ctl, "S16_LE");
3725 }
3726 if ( ret < 0) {
3727 ALOGE("%s:becf: afe: fail for %s mixer set to %d bit for %x format", __func__,
3728 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
3729 } else {
3730 my_data->current_backend_cfg[backend_idx].bit_width = bit_width;
3731 ALOGD("%s:becf: afe: %s mixer set to %d bit for %x format", __func__,
3732 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
3733 }
3734 /* set the ret as 0 and not pass back to upper layer */
3735 ret = 0;
3736 }
3737
3738 if (passthrough_enabled || ((my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl) &&
3739 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate))) {
3740 char *rate_str = NULL;
3741 struct mixer_ctl *ctl = NULL;
3742
3743 switch (sample_rate) {
3744 case 32000:
3745 if (passthrough_enabled) {
3746 rate_str = "KHZ_32";
3747 break;
3748 }
3749 case 8000:
3750 case 11025:
3751 case 16000:
3752 case 22050:
3753 case 48000:
3754 rate_str = "KHZ_48";
3755 break;
3756 case 44100:
3757 rate_str = "KHZ_44P1";
3758 break;
3759 case 64000:
3760 case 96000:
3761 rate_str = "KHZ_96";
3762 break;
3763 case 88200:
3764 rate_str = "KHZ_88P2";
3765 break;
3766 case 176400:
3767 rate_str = "KHZ_176P4";
3768 break;
3769 case 192000:
3770 rate_str = "KHZ_192";
3771 break;
3772 case 352800:
3773 rate_str = "KHZ_352P8";
3774 break;
3775 case 384000:
3776 rate_str = "KHZ_384";
3777 break;
3778 case 144000:
3779 if (passthrough_enabled) {
3780 rate_str = "KHZ_144";
3781 break;
3782 }
3783 default:
3784 rate_str = "KHZ_48";
3785 break;
3786 }
3787
3788 ctl = mixer_get_ctl_by_name(adev->mixer,
3789 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
3790 if(!ctl) {
3791 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3792 __func__,
3793 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
3794 return -EINVAL;
3795 }
3796
3797 ALOGD("%s:becf: afe: %s set to %s", __func__,
3798 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl, rate_str);
3799 mixer_ctl_set_enum_by_string(ctl, rate_str);
3800 my_data->current_backend_cfg[backend_idx].sample_rate = sample_rate;
3801 }
3802 if ((my_data->current_backend_cfg[backend_idx].channels_mixer_ctl) &&
3803 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
3804 struct mixer_ctl *ctl = NULL;
3805 char *channel_cnt_str = NULL;
3806
3807 switch (channels) {
3808 case 8:
3809 channel_cnt_str = "Eight"; break;
3810 case 7:
3811 channel_cnt_str = "Seven"; break;
3812 case 6:
3813 channel_cnt_str = "Six"; break;
3814 case 5:
3815 channel_cnt_str = "Five"; break;
3816 case 4:
3817 channel_cnt_str = "Four"; break;
3818 case 3:
3819 channel_cnt_str = "Three"; break;
3820 case 1:
3821 channel_cnt_str = "One"; break;
3822 case 2:
3823 default:
3824 channel_cnt_str = "Two"; break;
3825 }
3826
3827 ctl = mixer_get_ctl_by_name(adev->mixer,
3828 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
3829 if (!ctl) {
3830 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3831 __func__,
3832 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
3833 return -EINVAL;
3834 }
3835 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
3836 my_data->current_backend_cfg[backend_idx].channels = channels;
3837
3838 // skip EDID configuration for HDMI backend
3839
3840 ALOGD("%s:becf: afe: %s set to %s", __func__,
3841 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl,
3842 channel_cnt_str);
3843 }
3844
3845 // skip set ext_display format mixer control
3846 return ret;
3847}
3848
3849static int platform_get_snd_device_bit_width(snd_device_t snd_device)
3850{
3851 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
3852 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
3853 return CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3854 }
3855
3856 return backend_bit_width_table[snd_device];
3857}
3858
3859/*
3860 * return backend_idx on which voice call is active
3861 */
3862static int platform_get_voice_call_backend(struct audio_device* adev)
3863{
3864 struct audio_usecase *uc = NULL;
3865 struct listnode *node;
3866 snd_device_t out_snd_device = SND_DEVICE_NONE;
3867
3868 int backend_idx = -1;
3869
3870 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
3871 list_for_each(node, &adev->usecase_list) {
3872 uc = node_to_item(node, struct audio_usecase, list);
3873 if (uc && uc->type == VOICE_CALL && uc->stream.out) {
3874 out_snd_device = platform_get_output_snd_device(adev->platform,
3875 uc->stream.out->devices);
3876 backend_idx = platform_get_backend_index(out_snd_device);
3877 break;
3878 }
3879 }
3880 }
3881 return backend_idx;
3882}
3883
3884/*
3885 * goes through all the current usecases and picks the highest
3886 * bitwidth & samplerate
3887 */
3888static bool platform_check_capture_backend_cfg(struct audio_device* adev,
3889 int backend_idx,
3890 struct audio_backend_cfg *backend_cfg)
3891{
3892 bool backend_change = false;
3893 unsigned int bit_width;
3894 unsigned int sample_rate;
3895 unsigned int channels;
3896 struct platform_data *my_data = (struct platform_data *)adev->platform;
3897
3898 bit_width = backend_cfg->bit_width;
3899 sample_rate = backend_cfg->sample_rate;
3900 channels = backend_cfg->channels;
3901
3902 ALOGV("%s:txbecf: afe: Codec selected backend: %d current bit width: %d and "
3903 "sample rate: %d, channels %d",__func__,backend_idx, bit_width,
3904 sample_rate, channels);
3905
3906 // For voice calls use default configuration i.e. 16b/48K, only applicable to
3907 // default backend
3908 // force routing is not required here, caller will do it anyway
3909 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
3910 ALOGW("%s:txbecf: afe: Use default bw and sr for voice/voip calls and "
3911 "for unprocessed/camera source", __func__);
3912 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3913 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3914 }
3915
3916 if (backend_idx == USB_AUDIO_TX_BACKEND) {
3917 audio_extn_usb_is_config_supported(&bit_width, &sample_rate, &channels, false);
3918 ALOGV("%s:txbecf: afe: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
3919 __func__, bit_width, sample_rate, channels);
3920 }
3921
3922 ALOGV("%s:txbecf: afe: Codec selected backend: %d updated bit width: %d and "
3923 "sample rate: %d", __func__, backend_idx, bit_width, sample_rate);
3924
3925 // Force routing if the expected bitwdith or samplerate
3926 // is not same as current backend comfiguration
3927 if ((bit_width != my_data->current_backend_cfg[backend_idx].bit_width) ||
3928 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate) ||
3929 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
3930 backend_cfg->bit_width = bit_width;
3931 backend_cfg->sample_rate= sample_rate;
3932 backend_cfg->channels = channels;
3933 backend_change = true;
3934 ALOGI("%s:txbecf: afe: Codec backend needs to be updated. new bit width: %d "
3935 "new sample rate: %d new channel: %d",
3936 __func__, backend_cfg->bit_width,
3937 backend_cfg->sample_rate, backend_cfg->channels);
3938 }
3939
3940 return backend_change;
3941}
3942
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003943static void pick_playback_cfg_for_uc(struct audio_device *adev,
3944 struct audio_usecase *usecase,
3945 snd_device_t snd_device,
3946 unsigned int *bit_width,
3947 unsigned int *sample_rate,
3948 unsigned int *channels)
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003949{
3950 int i =0;
3951 struct listnode *node;
3952 list_for_each(node, &adev->usecase_list) {
3953 struct audio_usecase *uc;
3954 uc = node_to_item(node, struct audio_usecase, list);
3955 struct stream_out *out = (struct stream_out*) uc->stream.out;
3956 if (uc->type == PCM_PLAYBACK && out && usecase != uc) {
3957 unsigned int out_channels = audio_channel_count_from_out_mask(out->channel_mask);
3958 ALOGV("%s:napb: (%d) - (%s)id (%d) sr %d bw "
3959 "(%d) ch (%d) device %s", __func__, i++, use_case_table[uc->id],
3960 uc->id, out->sample_rate,
3961 pcm_format_to_bits(out->config.format), out_channels,
3962 platform_get_snd_device_name(uc->out_snd_device));
3963
3964 if (platform_check_backends_match(snd_device, uc->out_snd_device)) {
3965 if (*bit_width < pcm_format_to_bits(out->config.format))
3966 *bit_width = pcm_format_to_bits(out->config.format);
3967 if (*sample_rate < out->sample_rate)
3968 *sample_rate = out->sample_rate;
3969 if (out->sample_rate < OUTPUT_SAMPLING_RATE_44100)
3970 *sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3971 if (*channels < out_channels)
3972 *channels = out_channels;
3973 }
3974 }
3975 }
3976 return;
3977}
3978
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003979static void headset_is_config_supported(unsigned int *bit_width,
3980 unsigned int *sample_rate,
3981 unsigned int *channels) {
3982 switch (*bit_width) {
3983 case 16:
3984 case 24:
3985 break;
3986 default:
3987 *bit_width = 16;
3988 break;
3989 }
3990
3991 if (*sample_rate > 192000) {
3992 *sample_rate = 192000;
3993 }
3994
3995 if (*channels > 2) {
3996 *channels = 2;
3997 }
3998}
3999
David Linee3fe402017-03-13 10:00:42 -07004000static bool platform_check_playback_backend_cfg(struct audio_device* adev,
4001 struct audio_usecase* usecase,
4002 snd_device_t snd_device,
4003 struct audio_backend_cfg *backend_cfg)
4004{
4005 bool backend_change = false;
David Linee3fe402017-03-13 10:00:42 -07004006 unsigned int bit_width;
4007 unsigned int sample_rate;
4008 unsigned int channels;
David Linee3fe402017-03-13 10:00:42 -07004009 int backend_idx = DEFAULT_CODEC_BACKEND;
Haynes Mathew George65f6b432018-02-27 17:44:55 -08004010 unsigned long service_interval = 0; // 0 is invalid
David Linee3fe402017-03-13 10:00:42 -07004011 struct platform_data *my_data = (struct platform_data *)adev->platform;
David Linee3fe402017-03-13 10:00:42 -07004012
4013 if (snd_device == SND_DEVICE_OUT_BT_SCO ||
4014 snd_device == SND_DEVICE_OUT_BT_SCO_WB) {
4015 backend_change = false;
4016 return backend_change;
4017 }
4018
4019 backend_idx = platform_get_backend_index(snd_device);
4020 bit_width = backend_cfg->bit_width;
4021 sample_rate = backend_cfg->sample_rate;
4022 channels = backend_cfg->channels;
4023
4024 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
4025 ", backend_idx %d usecase = %d device (%s)", __func__, bit_width,
4026 sample_rate, channels, backend_idx, usecase->id,
4027 platform_get_snd_device_name(snd_device));
4028
4029 if (backend_idx == platform_get_voice_call_backend(adev)) {
4030 ALOGW("%s:becf: afe:Use default bw and sr for voice/voip calls ",
4031 __func__);
4032 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
4033 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4034 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
4035 } else {
4036 /*
4037 * The backend should be configured at highest bit width and/or
4038 * sample rate amongst all playback usecases.
4039 * If the selected sample rate and/or bit width differ with
4040 * current backend sample rate and/or bit width, then, we set the
4041 * backend re-configuration flag.
4042 *
4043 * Exception: 16 bit playbacks is allowed through 16 bit/48/44.1 khz backend only
4044 */
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004045 pick_playback_cfg_for_uc(adev, usecase, snd_device,
4046 &bit_width,
4047 &sample_rate,
4048 &channels);
David Linee3fe402017-03-13 10:00:42 -07004049 }
4050
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004051 switch (backend_idx) {
4052 case USB_AUDIO_RX_BACKEND:
4053 audio_extn_usb_is_config_supported(&bit_width,
4054 &sample_rate, &channels, true);
Haynes Mathew George65f6b432018-02-27 17:44:55 -08004055 if (platform_get_usb_service_interval(adev->platform, true,
4056 &service_interval) == 0) {
4057 /* overwrite with best altset for this service interval */
4058 int ret =
4059 audio_extn_usb_altset_for_service_interval(true /*playback*/,
4060 service_interval,
4061 &bit_width,
4062 &sample_rate,
4063 &channels);
4064 if (ret < 0) {
4065 ALOGE("Failed to find altset for service interval %lu, skip reconfig",
4066 service_interval);
4067 return false;
4068 }
4069 }
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004070 ALOGV("%s: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
4071 __func__, bit_width, sample_rate, channels);
4072 break;
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004073 case HEADPHONE_BACKEND:
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004074 headset_is_config_supported(&bit_width, &sample_rate, &channels);
4075 break;
4076 case DEFAULT_CODEC_BACKEND:
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004077 default:
4078 bit_width = platform_get_snd_device_bit_width(snd_device);
4079 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4080 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
4081 break;
David Linee3fe402017-03-13 10:00:42 -07004082 }
4083
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004084 ALOGV("%s:becf: afe: Codec selected backend: %d updated bit width: %d and"
4085 "sample rate: %d",
David Linee3fe402017-03-13 10:00:42 -07004086 __func__, backend_idx , bit_width, sample_rate);
4087
4088 // Force routing if the expected bitwdith or samplerate
4089 // is not same as current backend comfiguration
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004090 if (bit_width != my_data->current_backend_cfg[backend_idx].bit_width ||
4091 sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate ||
4092 channels != my_data->current_backend_cfg[backend_idx].channels) {
David Linee3fe402017-03-13 10:00:42 -07004093 backend_cfg->bit_width = bit_width;
4094 backend_cfg->sample_rate = sample_rate;
4095 backend_cfg->channels = channels;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004096 backend_cfg->passthrough_enabled = false;
David Linee3fe402017-03-13 10:00:42 -07004097 backend_change = true;
4098 ALOGV("%s:becf: afe: Codec backend needs to be updated. new bit width: %d"
4099 "new sample rate: %d new channels: %d",
4100 __func__, backend_cfg->bit_width, backend_cfg->sample_rate, backend_cfg->channels);
4101 }
4102
4103 return backend_change;
4104}
4105
4106bool platform_check_and_set_playback_backend_cfg(struct audio_device* adev,
4107 struct audio_usecase *usecase, snd_device_t snd_device)
4108{
4109 int backend_idx = DEFAULT_CODEC_BACKEND;
4110 int new_snd_devices[SND_DEVICE_OUT_END];
4111 int i, num_devices = 1;
4112 bool ret = false;
4113 struct platform_data *my_data = (struct platform_data *)adev->platform;
4114 struct audio_backend_cfg backend_cfg;
4115
4116 backend_idx = platform_get_backend_index(snd_device);
4117
4118 backend_cfg.bit_width = pcm_format_to_bits(usecase->stream.out->config.format);
4119 backend_cfg.sample_rate = usecase->stream.out->sample_rate;
4120 backend_cfg.format = usecase->stream.out->format;
4121 backend_cfg.channels = audio_channel_count_from_out_mask(usecase->stream.out->channel_mask);
4122 /*this is populated by check_codec_backend_cfg hence set default value to false*/
4123 backend_cfg.passthrough_enabled = false;
4124
4125 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
4126 ", backend_idx %d usecase = %d device (%s)", __func__, backend_cfg.bit_width,
4127 backend_cfg.sample_rate, backend_cfg.channels, backend_idx, usecase->id,
4128 platform_get_snd_device_name(snd_device));
4129
4130 if (platform_can_split_snd_device(snd_device, &num_devices, new_snd_devices) < 0)
4131 new_snd_devices[0] = snd_device;
4132
4133 for (i = 0; i < num_devices; i++) {
4134 ALOGV("%s: new_snd_devices[%d] is %d", __func__, i, new_snd_devices[i]);
4135 if ((platform_check_playback_backend_cfg(adev, usecase, new_snd_devices[i],
4136 &backend_cfg))) {
4137 platform_set_backend_cfg(adev, new_snd_devices[i],
4138 &backend_cfg);
4139 ret = true;
4140 }
4141 }
4142 return ret;
4143}
4144
4145bool platform_check_and_set_capture_backend_cfg(struct audio_device* adev,
4146 struct audio_usecase *usecase, snd_device_t snd_device)
4147{
4148 int backend_idx = platform_get_backend_index(snd_device);
4149 int ret = 0;
4150 struct audio_backend_cfg backend_cfg;
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004151 memset(&backend_cfg, 0, sizeof(struct audio_backend_cfg));
David Linee3fe402017-03-13 10:00:42 -07004152
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004153 if (usecase->type == PCM_CAPTURE) {
4154 backend_cfg.format = usecase->stream.in->format;
David Linee3fe402017-03-13 10:00:42 -07004155 backend_cfg.channels = audio_channel_count_from_in_mask(usecase->stream.in->channel_mask);
4156 } else {
4157 backend_cfg.bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
4158 backend_cfg.sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4159 backend_cfg.format = AUDIO_FORMAT_PCM_16_BIT;
4160 backend_cfg.channels = 1;
4161 }
4162
4163 ALOGV("%s:txbecf: afe: bitwidth %d, samplerate %d, channel %d"
4164 ", backend_idx %d usecase = %d device (%s)", __func__,
4165 backend_cfg.bit_width,
4166 backend_cfg.sample_rate,
4167 backend_cfg.channels,
4168 backend_idx, usecase->id,
4169 platform_get_snd_device_name(snd_device));
4170
4171 if (platform_check_capture_backend_cfg(adev, backend_idx, &backend_cfg)) {
4172 ret = platform_set_backend_cfg(adev, snd_device,
4173 &backend_cfg);
4174 if(!ret)
4175 return true;
4176 }
4177
4178 return false;
4179}
4180
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004181static int max_be_dai_names = 0;
4182static const struct be_dai_name_struct *be_dai_name_table;
4183
4184/*
4185 * Retrieves the be_dai_name_table from kernel to enable a mapping
4186 * between sound device hw interfaces and backend IDs. This allows HAL to
4187 * specify the backend a specific calibration is needed for.
4188 */
4189static int init_be_dai_name_table(struct audio_device *adev)
4190{
4191 const char *mixer_ctl_name = "Backend DAI Name Table";
4192 struct mixer_ctl *ctl;
4193 int i, j, ret, size;
4194 bool valid_hw_interface;
4195
4196 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
4197 if (!ctl) {
4198 ALOGE("%s: Could not get ctl for mixer name %s\n",
4199 __func__, mixer_ctl_name);
4200 ret = -EINVAL;
4201 goto done;
4202 }
4203
4204 mixer_ctl_update(ctl);
4205
4206 size = mixer_ctl_get_num_values(ctl);
4207 if (size <= 0){
4208 ALOGE("%s: Failed to get %s size %d\n",
4209 __func__, mixer_ctl_name, size);
4210 ret = -EFAULT;
4211 goto done;
4212 }
4213
vivek mehtaa68fea62017-06-08 19:04:02 -07004214 be_dai_name_table =
4215 (const struct be_dai_name_struct *)calloc(1, size);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004216 if (be_dai_name_table == NULL) {
4217 ALOGE("%s: Failed to allocate memory for %s\n",
4218 __func__, mixer_ctl_name);
4219 ret = -ENOMEM;
4220 goto freeMem;
4221 }
4222
4223 ret = mixer_ctl_get_array(ctl, (void *)be_dai_name_table, size);
4224 if (ret) {
4225 ALOGE("%s: Failed to get %s, ret %d\n",
4226 __func__, mixer_ctl_name, ret);
4227 ret = -EFAULT;
4228 goto freeMem;
4229 }
4230
4231 if (be_dai_name_table != NULL) {
4232 max_be_dai_names = size / sizeof(struct be_dai_name_struct);
4233 ALOGV("%s: Successfully got %s, number of be dais is %d\n",
4234 __func__, mixer_ctl_name, max_be_dai_names);
4235 ret = 0;
4236 } else {
4237 ALOGE("%s: Failed to get %s\n", __func__, mixer_ctl_name);
4238 ret = -EFAULT;
4239 goto freeMem;
4240 }
4241
4242 /*
4243 * Validate all sound devices have a valid backend set to catch
4244 * errors for uncommon sound devices
4245 */
4246 for (i = 0; i < SND_DEVICE_MAX; i++) {
4247 valid_hw_interface = false;
4248
4249 if (hw_interface_table[i] == NULL) {
4250 ALOGW("%s: sound device %s has no hw interface set\n",
4251 __func__, platform_get_snd_device_name(i));
4252 continue;
4253 }
4254
4255 for (j = 0; j < max_be_dai_names; j++) {
4256 if (strcmp(hw_interface_table[i], be_dai_name_table[j].be_name)
4257 == 0) {
4258 valid_hw_interface = true;
4259 break;
4260 }
4261 }
4262 if (!valid_hw_interface)
4263 ALOGD("%s: sound device %s does not have a valid hw interface set "
4264 "(disregard for combo devices) %s\n",
4265 __func__, platform_get_snd_device_name(i),
4266 hw_interface_table[i]);
4267 }
4268
4269 goto done;
4270
4271freeMem:
4272 if (be_dai_name_table) {
4273 free((void *)be_dai_name_table);
4274 be_dai_name_table = NULL;
4275 }
4276
4277done:
4278 return ret;
4279}
4280
4281int platform_get_snd_device_backend_index(snd_device_t device)
4282{
4283 int i, be_dai_id;
4284 const char * hw_interface_name = NULL;
4285
4286 ALOGV("%s: enter with device %d\n", __func__, device);
4287
vivek mehtaa68fea62017-06-08 19:04:02 -07004288 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004289 ALOGE("%s: Invalid snd_device = %d",
4290 __func__, device);
4291 be_dai_id = -EINVAL;
4292 goto done;
4293 }
4294
4295 /* Get string value of necessary backend for device */
4296 hw_interface_name = hw_interface_table[device];
4297 if (hw_interface_name == NULL) {
4298 ALOGE("%s: no hw_interface set for device %d\n", __func__, device);
4299 be_dai_id = -EINVAL;
4300 goto done;
4301 }
4302
4303 /* Check if be dai name table was retrieved successfully */
4304 if (be_dai_name_table == NULL) {
4305 ALOGE("%s: BE DAI Name Table is not present\n", __func__);
4306 be_dai_id = -EFAULT;
4307 goto done;
4308 }
4309
4310 /* Get backend ID for device specified */
4311 for (i = 0; i < max_be_dai_names; i++) {
4312 if (strcmp(hw_interface_name, be_dai_name_table[i].be_name) == 0) {
4313 be_dai_id = be_dai_name_table[i].be_id;
4314 goto done;
4315 }
4316 }
4317 ALOGE("%s: no interface matching name %s\n", __func__, hw_interface_name);
4318 be_dai_id = -EINVAL;
4319 goto done;
4320
4321done:
4322 return be_dai_id;
4323}
4324
4325void platform_check_and_update_copp_sample_rate(void* platform, snd_device_t snd_device,
4326 unsigned int stream_sr, int* sample_rate)
4327{
4328 struct platform_data* my_data = (struct platform_data *)platform;
4329 int backend_idx = platform_get_backend_index(snd_device);
4330 int device_sr = my_data->current_backend_cfg[backend_idx].sample_rate;
4331 /*
4332 *Check if device SR is multiple of 8K or 11.025 Khz
4333 *check if the stream SR is multiple of same base, if yes
4334 *then have copp SR equal to stream SR, this ensures that
4335 *post processing happens at stream SR, else have
4336 *copp SR equal to device SR.
4337 */
4338 if (!(((sample_rate_multiple(device_sr, SAMPLE_RATE_8000)) &&
4339 (sample_rate_multiple(stream_sr, SAMPLE_RATE_8000))) ||
4340 ((sample_rate_multiple(device_sr, SAMPLE_RATE_11025)) &&
4341 (sample_rate_multiple(stream_sr, SAMPLE_RATE_11025))))) {
4342 *sample_rate = device_sr;
4343 } else
4344 *sample_rate = stream_sr;
4345
4346 ALOGI("sn_device %d device sr %d stream sr %d copp sr %d", snd_device, device_sr, stream_sr
4347 , *sample_rate);
4348
4349}
4350
4351// called from info parser
vivek mehtaa68fea62017-06-08 19:04:02 -07004352void platform_add_app_type(const char *uc_type,
4353 const char *mode,
4354 int bw,
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004355 int app_type, int max_rate) {
4356 struct app_type_entry *ap =
4357 (struct app_type_entry *)calloc(1, sizeof(struct app_type_entry));
4358
4359 if (!ap) {
4360 ALOGE("%s failed to allocate mem for app type", __func__);
4361 return;
4362 }
4363
4364 ap->uc_type = -1;
4365 for (int i=0; i<USECASE_TYPE_MAX; i++) {
4366 if (!strcmp(uc_type, usecase_type_index[i].name)) {
4367 ap->uc_type = usecase_type_index[i].index;
4368 break;
4369 }
4370 }
4371
4372 if (ap->uc_type == -1) {
4373 free(ap);
4374 return;
4375 }
4376
vivek mehtaa68fea62017-06-08 19:04:02 -07004377 ALOGI("%s uc %s mode %s bw %d app_type %d max_rate %d",
4378 __func__, uc_type, mode, bw, app_type, max_rate);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004379 ap->bit_width = bw;
4380 ap->app_type = app_type;
4381 ap->max_rate = max_rate;
vivek mehtaa68fea62017-06-08 19:04:02 -07004382 ap->mode = strdup(mode);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004383 list_add_tail(&app_type_entry_list, &ap->node);
4384}
4385
4386
4387int platform_get_default_app_type_v2(void *platform __unused,
4388 usecase_type_t type,
4389 int *app_type )
4390{
4391 if (type == PCM_PLAYBACK)
4392 *app_type = DEFAULT_APP_TYPE_RX_PATH;
4393 else
4394 *app_type = DEFAULT_APP_TYPE_TX_PATH;
4395 return 0;
4396}
4397
vivek mehtaa68fea62017-06-08 19:04:02 -07004398int platform_get_app_type_v2(void *platform,
4399 usecase_type_t uc_type,
4400 const char *mode,
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004401 int bw, int sr __unused,
4402 int *app_type)
4403{
4404 struct listnode *node;
4405 struct app_type_entry *entry;
4406 *app_type = -1;
vivek mehtaa68fea62017-06-08 19:04:02 -07004407
4408 ALOGV("%s find match for uc %d mode %s bw %d rate %d",
4409 __func__, uc_type, mode, bw, sr);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004410 list_for_each(node, &app_type_entry_list) {
4411 entry = node_to_item(node, struct app_type_entry, node);
vivek mehtaa68fea62017-06-08 19:04:02 -07004412 ALOGV("%s uc %d mode %s bw %d app_type %d max_rate %d",
4413 __func__, entry->uc_type, entry->mode, entry->bit_width,
4414 entry->app_type, entry->max_rate);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004415 if (entry->bit_width == bw &&
vivek mehtaa68fea62017-06-08 19:04:02 -07004416 entry->uc_type == uc_type &&
4417 sr <= entry->max_rate &&
4418 entry->mode && !strcmp(mode, entry->mode)) {
4419 ALOGV("%s found match %d", __func__, entry->app_type);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004420 *app_type = entry->app_type;
4421 break;
4422 }
4423 }
4424
4425 if (*app_type == -1) {
vivek mehtaa68fea62017-06-08 19:04:02 -07004426 ALOGV("%s no match found, return default", __func__);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004427 return platform_get_default_app_type_v2(platform, uc_type, app_type);
4428 }
4429 return 0;
4430}
vivek mehta90933872017-06-15 18:04:39 -07004431
4432int platform_set_sidetone(struct audio_device *adev,
4433 snd_device_t out_snd_device,
4434 bool enable, char *str)
4435{
4436 int ret;
4437 if (out_snd_device == SND_DEVICE_OUT_USB_HEADSET ||
4438 out_snd_device == SND_DEVICE_OUT_VOICE_USB_HEADSET) {
4439 ret = audio_extn_usb_enable_sidetone(out_snd_device, enable);
4440 if (ret)
4441 ALOGI("%s: usb device %d does not support device sidetone\n",
4442 __func__, out_snd_device);
4443 } else {
4444 ALOGV("%s: sidetone out device(%d) mixer cmd = %s\n",
4445 __func__, out_snd_device, str);
4446 if (enable)
4447 audio_route_apply_and_update_path(adev->audio_route, str);
4448 else
4449 audio_route_reset_and_update_path(adev->audio_route, str);
4450 }
4451 return 0;
4452}
Haynes Mathew George96483a22017-03-28 14:52:47 -07004453
4454int platform_get_mmap_data_fd(void *platform __unused, int fe_dev __unused, int dir __unused,
4455 int *fd __unused, uint32_t *size __unused)
4456{
Alexey Polyudove920d4b2017-09-15 17:09:07 -07004457#if defined (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845)
Haynes Mathew George96483a22017-03-28 14:52:47 -07004458 struct platform_data *my_data = (struct platform_data *)platform;
4459 struct audio_device *adev = my_data->adev;
4460 int hw_fd = -1;
4461 char dev_name[128];
4462 struct snd_pcm_mmap_fd mmap_fd;
4463 memset(&mmap_fd, 0, sizeof(mmap_fd));
4464 mmap_fd.dir = dir;
4465 snprintf(dev_name, sizeof(dev_name), "/dev/snd/hwC%uD%u",
4466 adev->snd_card, HWDEP_FE_BASE+fe_dev);
4467 hw_fd = open(dev_name, O_RDONLY);
4468 if (hw_fd < 0) {
4469 ALOGE("fe hw dep node open %d/%d failed", adev->snd_card, fe_dev);
4470 return -1;
4471 }
4472 if (ioctl(hw_fd, SNDRV_PCM_IOCTL_MMAP_DATA_FD, &mmap_fd) < 0) {
4473 ALOGE("fe hw dep node ioctl failed");
4474 close(hw_fd);
4475 return -1;
4476 }
4477 *fd = mmap_fd.fd;
4478 *size = mmap_fd.size;
4479 close(hw_fd); // mmap_fd should still be valid
4480 return 0;
4481#else
4482 return -1;
4483#endif
4484}
Mikhail Naganov4ee6e3e2018-03-21 16:28:35 +00004485
4486bool platform_sound_trigger_usecase_needs_event(audio_usecase_t uc_id)
4487{
4488 bool needs_event = false;
4489
4490 switch (uc_id) {
4491 /* concurrent capture usecases which needs event */
4492 case USECASE_AUDIO_RECORD:
4493 case USECASE_AUDIO_RECORD_LOW_LATENCY:
4494 case USECASE_AUDIO_RECORD_MMAP:
4495 case USECASE_AUDIO_RECORD_HIFI:
4496 case USECASE_AUDIO_RECORD_VOIP:
4497 case USECASE_VOICEMMODE1_CALL:
4498 case USECASE_VOICEMMODE2_CALL:
4499 /* concurrent playback usecases that needs event */
4500 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
4501 case USECASE_AUDIO_PLAYBACK_OFFLOAD:
4502 needs_event = true;
4503 break;
4504 default:
4505 ALOGV("%s:usecase_id[%d] no need to raise event.", __func__, uc_id);
4506 }
4507 return needs_event;
4508}
4509
4510bool platform_snd_device_has_speaker(snd_device_t dev) {
4511 int num_devs = 2;
4512 snd_device_t split_devs[2] = {SND_DEVICE_NONE, SND_DEVICE_NONE};
4513 if (platform_can_split_snd_device(dev, &num_devs, split_devs) == 0) {
4514 return platform_snd_device_has_speaker(split_devs[0]) ||
4515 platform_snd_device_has_speaker(split_devs[1]);
4516 }
4517
4518 switch (dev) {
4519 case SND_DEVICE_OUT_SPEAKER:
4520 case SND_DEVICE_OUT_SPEAKER_SAFE:
4521 case SND_DEVICE_OUT_SPEAKER_REVERSE:
4522 case SND_DEVICE_OUT_SPEAKER_PROTECTED:
4523 case SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED:
4524 case SND_DEVICE_OUT_VOICE_SPEAKER_HFP:
4525 return true;
4526 default:
4527 break;
4528 }
4529 return false;
4530}
jiabin8962a4d2018-03-19 18:21:24 -07004531
4532bool platform_set_microphone_characteristic(void *platform,
4533 struct audio_microphone_characteristic_t mic) {
4534 struct platform_data *my_data = (struct platform_data *)platform;
4535 if (my_data->declared_mic_count >= AUDIO_MICROPHONE_MAX_COUNT) {
4536 ALOGE("mic number is more than maximum number");
4537 return false;
4538 }
4539 for (size_t ch = 0; ch < AUDIO_CHANNEL_COUNT_MAX; ch++) {
4540 mic.channel_mapping[ch] = AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED;
4541 }
4542 my_data->microphones[my_data->declared_mic_count++] = mic;
4543 return true;
4544}
4545
4546int platform_get_microphones(void *platform,
4547 struct audio_microphone_characteristic_t *mic_array,
4548 size_t *mic_count) {
4549 struct platform_data *my_data = (struct platform_data *)platform;
4550 if (mic_count == NULL) {
4551 return -EINVAL;
4552 }
4553 if (mic_array == NULL) {
4554 return -EINVAL;
4555 }
4556
4557 if (*mic_count == 0) {
4558 *mic_count = my_data->declared_mic_count;
4559 return 0;
4560 }
4561
4562 size_t max_mic_count = *mic_count;
4563 size_t actual_mic_count = 0;
4564 for (size_t i = 0; i < max_mic_count && i < my_data->declared_mic_count; i++) {
4565 mic_array[i] = my_data->microphones[i];
4566 actual_mic_count++;
4567 }
4568 *mic_count = actual_mic_count;
4569 return 0;
4570}
4571
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004572bool platform_set_microphone_map(void *platform, snd_device_t in_snd_device,
4573 const struct mic_info *info) {
4574 struct platform_data *my_data = (struct platform_data *)platform;
4575 if (in_snd_device < SND_DEVICE_IN_BEGIN || in_snd_device >= SND_DEVICE_IN_END) {
4576 ALOGE("%s: Sound device not valid", __func__);
4577 return false;
4578 }
4579 size_t m_count = my_data->mic_map[in_snd_device].mic_count++;
4580 if (m_count >= AUDIO_MICROPHONE_MAX_COUNT) {
4581 ALOGE("%s: Microphone count is greater than max allowed value", __func__);
4582 my_data->mic_map[in_snd_device].mic_count--;
4583 return false;
4584 }
4585 my_data->mic_map[in_snd_device].microphones[m_count] = *info;
4586 return true;
4587}
4588
4589int platform_get_active_microphones(void *platform, unsigned int channels,
4590 audio_usecase_t uc_id,
jiabin8962a4d2018-03-19 18:21:24 -07004591 struct audio_microphone_characteristic_t *mic_array,
4592 size_t *mic_count) {
4593 struct platform_data *my_data = (struct platform_data *)platform;
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004594 struct audio_usecase *usecase = get_usecase_from_list(my_data->adev, uc_id);
4595 if (mic_count == NULL || mic_array == NULL || usecase == NULL) {
jiabin8962a4d2018-03-19 18:21:24 -07004596 return -EINVAL;
4597 }
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004598 size_t max_mic_count = my_data->declared_mic_count;
jiabin8962a4d2018-03-19 18:21:24 -07004599 size_t actual_mic_count = 0;
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004600
4601 snd_device_t active_input_snd_device =
4602 platform_get_input_snd_device(platform, usecase->stream.in->device);
4603 if (active_input_snd_device == SND_DEVICE_NONE) {
4604 ALOGI("%s: No active microphones found", __func__);
4605 goto end;
4606 }
4607
4608 size_t active_mic_count = my_data->mic_map[active_input_snd_device].mic_count;
4609 struct mic_info *m_info = my_data->mic_map[active_input_snd_device].microphones;
4610
4611 for (size_t i = 0; i < active_mic_count; i++) {
4612 unsigned int channels_for_active_mic = channels;
4613 if (channels_for_active_mic > m_info[i].channel_count) {
4614 channels_for_active_mic = m_info[i].channel_count;
4615 }
4616 for (size_t j = 0; j < max_mic_count; j++) {
4617 if (strcmp(my_data->microphones[j].device_id,
4618 m_info[i].device_id) == 0) {
4619 mic_array[actual_mic_count] = my_data->microphones[j];
4620 for (size_t ch = 0; ch < channels_for_active_mic; ch++) {
4621 mic_array[actual_mic_count].channel_mapping[ch] =
4622 m_info[i].channel_mapping[ch];
4623 }
4624 actual_mic_count++;
4625 break;
jiabin8962a4d2018-03-19 18:21:24 -07004626 }
jiabin8962a4d2018-03-19 18:21:24 -07004627 }
4628 }
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004629end:
jiabin8962a4d2018-03-19 18:21:24 -07004630 *mic_count = actual_mic_count;
4631 return 0;
4632}
Haynes Mathew George65f6b432018-02-27 17:44:55 -08004633
4634int platform_set_usb_service_interval(void *platform,
4635 bool playback,
4636 unsigned long service_interval,
4637 bool *reconfig)
4638{
4639#if defined (USB_SERVICE_INTERVAL_ENABLED)
4640 struct platform_data *_platform = (struct platform_data *)platform;
4641 *reconfig = false;
4642 if (!playback) {
4643 ALOGE("%s not valid for capture", __func__);
4644 return -1;
4645 }
4646 const char *ctl_name = "USB_AUDIO_RX service_interval";
4647 struct mixer_ctl *ctl = mixer_get_ctl_by_name(_platform->adev->mixer,
4648 ctl_name);
4649 if (!ctl) {
4650 ALOGV("%s: could not get mixer %s", __func__, ctl_name);
4651 return -1;
4652 }
4653 if (mixer_ctl_get_value(ctl, 0) != (int)service_interval) {
4654 mixer_ctl_set_value(ctl, 0, service_interval);
4655 *reconfig = true;
4656 }
4657 return 0;
4658#else
4659 *reconfig = false;
4660 (void)platform;
4661 (void)playback;
4662 (void)service_interval;
4663 return -1;
4664#endif
4665}
4666
4667int platform_get_usb_service_interval(void *platform,
4668 bool playback,
4669 unsigned long *service_interval)
4670{
4671#if defined (USB_SERVICE_INTERVAL_ENABLED)
4672 struct platform_data *_platform = (struct platform_data *)platform;
4673 if (!playback) {
4674 ALOGE("%s not valid for capture", __func__);
4675 return -1;
4676 }
4677 const char *ctl_name = "USB_AUDIO_RX service_interval";
4678 struct mixer_ctl *ctl = mixer_get_ctl_by_name(_platform->adev->mixer,
4679 ctl_name);
4680 if (!ctl) {
4681 ALOGV("%s: could not get mixer %s", __func__, ctl_name);
4682 return -1;
4683 }
4684 *service_interval = mixer_ctl_get_value(ctl, 0);
4685 return 0;
4686#else
4687 (void)platform;
4688 (void)playback;
4689 (void)service_interval;
4690 return -1;
4691#endif
4692}