blob: 60c0fddf4b6163e63058da492a3be4908f6cd4fe [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;
Xu Han07e07402018-05-15 14:19:25 -07001498 const char* ctl7 = "MultiMedia9 Mixer SLIM_1_TX";
Xu Han1638fd12018-04-20 12:42:23 -07001499 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);
Aniket Kumar Lataa158e862018-05-11 17:28:40 -07001902 return -EINVAL;
vivek mehtade4849c2016-03-03 17:23:38 -08001903 }
1904
1905 return 0;
1906}
1907
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001908void platform_add_backend_name(void *platform, char *mixer_path,
1909 snd_device_t snd_device)
Eric Laurentb23d5282013-05-14 15:27:20 -07001910{
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001911 struct platform_data *my_data = (struct platform_data *)platform;
1912
Haynes Mathew George98c95622014-06-20 19:14:25 -07001913 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1914 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1915 return;
Ravi Kumar Alamanda1de6e5a2014-06-19 21:55:39 -05001916 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001917
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001918 const char * suffix = backend_tag_table[snd_device];
Haynes Mathew George98c95622014-06-20 19:14:25 -07001919
1920 if (suffix != NULL) {
1921 strcat(mixer_path, " ");
1922 strcat(mixer_path, suffix);
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001923 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001924}
1925
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001926bool platform_check_backends_match(snd_device_t snd_device1, snd_device_t snd_device2)
1927{
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001928 ALOGV("%s: snd_device1 = %s, snd_device2 = %s", __func__,
1929 platform_get_snd_device_name(snd_device1),
1930 platform_get_snd_device_name(snd_device2));
1931
1932 if ((snd_device1 < SND_DEVICE_MIN) || (snd_device1 >= SND_DEVICE_MAX)) {
1933 ALOGE("%s: Invalid snd_device = %s", __func__,
1934 platform_get_snd_device_name(snd_device1));
1935 return false;
1936 }
1937 if ((snd_device2 < SND_DEVICE_MIN) || (snd_device2 >= SND_DEVICE_MAX)) {
1938 ALOGE("%s: Invalid snd_device = %s", __func__,
1939 platform_get_snd_device_name(snd_device2));
1940 return false;
1941 }
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07001942
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001943 const char * be_itf1 = hw_interface_table[snd_device1];
1944 const char * be_itf2 = hw_interface_table[snd_device2];
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07001945 /*
1946 hw_interface_table has overrides for a snd_device.
1947 if there is no entry for a device, assume DEFAULT_RX_BACKEND
1948 */
1949 if (be_itf1 == NULL) {
1950 be_itf1 = DEFAULT_RX_BACKEND;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001951 }
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07001952 if (be_itf2 == NULL) {
1953 be_itf2 = DEFAULT_RX_BACKEND;
1954 }
1955 ALOGV("%s: be_itf1 = %s, be_itf2 = %s", __func__, be_itf1, be_itf2);
1956 /*
1957 this takes care of finding a device within a combo device pair as well
1958 */
1959 return strstr(be_itf1, be_itf2) != NULL || strstr(be_itf2, be_itf1) != NULL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001960}
1961
Eric Laurentb23d5282013-05-14 15:27:20 -07001962int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
1963{
1964 int device_id;
1965 if (device_type == PCM_PLAYBACK)
1966 device_id = pcm_device_table[usecase][0];
1967 else
1968 device_id = pcm_device_table[usecase][1];
1969 return device_id;
1970}
1971
Haynes Mathew George98c95622014-06-20 19:14:25 -07001972static int find_index(const struct name_to_index * table, int32_t len,
1973 const char * name)
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001974{
1975 int ret = 0;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001976 int32_t i;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001977
Haynes Mathew George98c95622014-06-20 19:14:25 -07001978 if (table == NULL) {
1979 ALOGE("%s: table is NULL", __func__);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001980 ret = -ENODEV;
1981 goto done;
1982 }
1983
Haynes Mathew George98c95622014-06-20 19:14:25 -07001984 if (name == NULL) {
1985 ALOGE("null key");
1986 ret = -ENODEV;
1987 goto done;
1988 }
1989
1990 for (i=0; i < len; i++) {
1991 if (!strcmp(table[i].name, name)) {
1992 ret = table[i].index;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001993 goto done;
1994 }
1995 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001996 ALOGE("%s: Could not find index for name = %s",
1997 __func__, name);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001998 ret = -ENODEV;
1999done:
2000 return ret;
2001}
2002
Haynes Mathew George98c95622014-06-20 19:14:25 -07002003int platform_get_snd_device_index(char *device_name)
2004{
2005 return find_index(snd_device_name_index, SND_DEVICE_MAX, device_name);
2006}
2007
2008int platform_get_usecase_index(const char *usecase_name)
2009{
2010 return find_index(usecase_name_index, AUDIO_USECASE_MAX, usecase_name);
2011}
2012
keunhui.park2f7306a2015-07-16 16:48:06 +09002013void platform_add_operator_specific_device(snd_device_t snd_device,
2014 const char *operator,
2015 const char *mixer_path,
2016 unsigned int acdb_id)
2017{
2018 struct operator_specific_device *device;
2019
2020 if (operator_specific_device_table[snd_device] == NULL) {
2021 operator_specific_device_table[snd_device] =
2022 (struct listnode *)calloc(1, sizeof(struct listnode));
2023 list_init(operator_specific_device_table[snd_device]);
2024 }
2025
2026 device = (struct operator_specific_device *)calloc(1, sizeof(struct operator_specific_device));
2027
2028 device->operator = strdup(operator);
2029 device->mixer_path = strdup(mixer_path);
2030 device->acdb_id = acdb_id;
2031
2032 list_add_tail(operator_specific_device_table[snd_device], &device->list);
2033
Eric Laurent2bafff12016-03-17 12:17:23 -07002034 ALOGD("%s: device[%s] -> operator[%s] mixer_path[%s] acdb_id[%d]", __func__,
keunhui.park2f7306a2015-07-16 16:48:06 +09002035 platform_get_snd_device_name(snd_device), operator, mixer_path, acdb_id);
2036
2037}
2038
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002039int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
2040{
2041 int ret = 0;
2042
2043 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
2044 ALOGE("%s: Invalid snd_device = %d",
2045 __func__, snd_device);
2046 ret = -EINVAL;
2047 goto done;
2048 }
2049
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002050 ALOGV("%s: acdb_device_table[%s]: old = %d new = %d", __func__,
2051 platform_get_snd_device_name(snd_device), acdb_device_table[snd_device], acdb_id);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002052 acdb_device_table[snd_device] = acdb_id;
2053done:
2054 return ret;
2055}
2056
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07002057int platform_get_snd_device_acdb_id(snd_device_t snd_device)
2058{
2059 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
2060 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
2061 return -EINVAL;
2062 }
keunhui.park2f7306a2015-07-16 16:48:06 +09002063
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002064 /*
2065 * If speaker protection is enabled, function returns supported
2066 * sound device for speaker. Else same sound device is returned.
2067 */
2068 snd_device = audio_extn_get_spkr_prot_snd_device(snd_device);
2069
keunhui.park2f7306a2015-07-16 16:48:06 +09002070 if (operator_specific_device_table[snd_device] != NULL)
2071 return get_operator_specific_device_acdb_id(snd_device);
2072 else
2073 return acdb_device_table[snd_device];
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07002074}
2075
David Linee3fe402017-03-13 10:00:42 -07002076static int platform_get_backend_index(snd_device_t snd_device)
2077{
2078 int32_t port = DEFAULT_CODEC_BACKEND;
2079
2080 if (snd_device >= SND_DEVICE_OUT_BEGIN && snd_device < SND_DEVICE_OUT_END) {
2081 if (backend_tag_table[snd_device] != NULL) {
2082 if (strncmp(backend_tag_table[snd_device], "headphones",
2083 sizeof("headphones")) == 0)
2084 port = HEADPHONE_BACKEND;
2085 else if (strcmp(backend_tag_table[snd_device], "hdmi") == 0)
2086 port = HDMI_RX_BACKEND;
2087 else if ((strcmp(backend_tag_table[snd_device], "usb-headphones") == 0) ||
2088 (strcmp(backend_tag_table[snd_device], "usb-headset") == 0))
2089 port = USB_AUDIO_RX_BACKEND;
2090 }
2091 } else if (snd_device >= SND_DEVICE_IN_BEGIN && snd_device < SND_DEVICE_IN_END) {
2092 port = DEFAULT_CODEC_TX_BACKEND;
2093 if (backend_tag_table[snd_device] != NULL) {
2094 if (strcmp(backend_tag_table[snd_device], "usb-headset-mic") == 0)
2095 port = USB_AUDIO_TX_BACKEND;
2096 else if (strstr(backend_tag_table[snd_device], "bt-sco") != NULL)
2097 port = BT_SCO_TX_BACKEND;
2098 }
2099 } else {
2100 ALOGW("%s:napb: Invalid device - %d ", __func__, snd_device);
2101 }
2102
2103 ALOGV("%s:napb: backend port - %d device - %d ", __func__, port, snd_device);
2104
2105 return port;
2106}
2107
Eric Laurentb23d5282013-05-14 15:27:20 -07002108int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
2109{
2110 struct platform_data *my_data = (struct platform_data *)platform;
2111 int acdb_dev_id, acdb_dev_type;
2112
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002113 if (platform_supports_app_type_cfg()) // use v2 instead
2114 return -ENOSYS;
2115
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002116 acdb_dev_id = platform_get_snd_device_acdb_id(snd_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07002117 if (acdb_dev_id < 0) {
2118 ALOGE("%s: Could not find acdb id for device(%d)",
2119 __func__, snd_device);
2120 return -EINVAL;
2121 }
2122 if (my_data->acdb_send_audio_cal) {
Joe Onorato188b6222016-03-01 11:02:27 -08002123 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Eric Laurentb23d5282013-05-14 15:27:20 -07002124 __func__, snd_device, acdb_dev_id);
2125 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
2126 snd_device < SND_DEVICE_OUT_END)
2127 acdb_dev_type = ACDB_DEV_TYPE_OUT;
2128 else
2129 acdb_dev_type = ACDB_DEV_TYPE_IN;
2130 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
2131 }
2132 return 0;
2133}
2134
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002135int platform_send_audio_calibration_v2(void *platform, struct audio_usecase *usecase,
2136 int app_type, int sample_rate)
2137{
2138 struct platform_data *my_data = (struct platform_data *)platform;
2139 int acdb_dev_id, acdb_dev_type;
vivek mehta7e573672018-03-13 17:41:41 -07002140 int snd_device = usecase->out_snd_device;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002141 int new_snd_device[SND_DEVICE_OUT_END] = {0};
2142 int i, num_devices = 1;
2143
2144 if (!platform_supports_app_type_cfg()) // use v1 instead
2145 return -ENOSYS;
2146
vivek mehta7e573672018-03-13 17:41:41 -07002147 if ((usecase->type == PCM_HFP_CALL) || (usecase->type == PCM_CAPTURE))
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002148 snd_device = usecase->in_snd_device;
2149
2150 // skipped over get_spkr_prot_device
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002151 acdb_dev_id = platform_get_snd_device_acdb_id(snd_device);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002152 if (acdb_dev_id < 0) {
2153 ALOGE("%s: Could not find acdb id for device(%d)",
2154 __func__, snd_device);
2155 return -EINVAL;
2156 }
2157
2158 if (platform_can_split_snd_device(snd_device,
2159 &num_devices, new_snd_device) < 0) {
2160 new_snd_device[0] = snd_device;
2161 }
2162
2163 for (i = 0; i < num_devices; i++) {
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002164 acdb_dev_id = platform_get_snd_device_acdb_id(new_snd_device[i]);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002165 if (acdb_dev_id < 0) {
2166 ALOGE("%s: Could not find acdb id for device(%d)",
2167 __func__, new_snd_device[i]);
2168 return -EINVAL;
2169 }
2170 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
2171 __func__, new_snd_device[i], acdb_dev_id);
2172 if (new_snd_device[i] >= SND_DEVICE_OUT_BEGIN &&
2173 new_snd_device[i] < SND_DEVICE_OUT_END)
2174 acdb_dev_type = ACDB_DEV_TYPE_OUT;
2175 else
2176 acdb_dev_type = ACDB_DEV_TYPE_IN;
2177
2178 if (my_data->acdb_send_audio_cal_v3) {
2179 my_data->acdb_send_audio_cal_v3(acdb_dev_id, acdb_dev_type,
2180 app_type, sample_rate, i);
2181 } else if (my_data->acdb_send_audio_cal) {
2182 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type); // this version differs from internal
2183 }
2184 }
2185
2186 return 0;
2187}
2188
2189
Eric Laurentb23d5282013-05-14 15:27:20 -07002190int platform_switch_voice_call_device_pre(void *platform)
2191{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002192 struct platform_data *my_data = (struct platform_data *)platform;
2193 int ret = 0;
2194
2195 if (my_data->csd != NULL &&
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002196 voice_is_in_call(my_data->adev)) {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002197 /* This must be called before disabling mixer controls on APQ side */
2198 ret = my_data->csd->disable_device();
2199 if (ret < 0) {
2200 ALOGE("%s: csd_client_disable_device, failed, error %d",
2201 __func__, ret);
2202 }
2203 }
2204 return ret;
2205}
2206
2207int platform_switch_voice_call_enable_device_config(void *platform,
2208 snd_device_t out_snd_device,
2209 snd_device_t in_snd_device)
2210{
2211 struct platform_data *my_data = (struct platform_data *)platform;
2212 int acdb_rx_id, acdb_tx_id;
2213 int ret = 0;
2214
2215 if (my_data->csd == NULL)
2216 return ret;
2217
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002218 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
keunhui.park2f7306a2015-07-16 16:48:06 +09002219 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002220
2221 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
2222 ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
2223 if (ret < 0) {
2224 ALOGE("%s: csd_enable_device_config, failed, error %d",
2225 __func__, ret);
2226 }
2227 } else {
2228 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2229 acdb_rx_id, acdb_tx_id);
2230 }
2231
2232 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002233}
2234
2235int platform_switch_voice_call_device_post(void *platform,
2236 snd_device_t out_snd_device,
2237 snd_device_t in_snd_device)
2238{
2239 struct platform_data *my_data = (struct platform_data *)platform;
2240 int acdb_rx_id, acdb_tx_id;
2241
2242 if (my_data->acdb_send_voice_cal == NULL) {
2243 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
2244 } else {
keunhui.park2f7306a2015-07-16 16:48:06 +09002245 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
2246 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07002247
2248 if (acdb_rx_id > 0 && acdb_tx_id > 0)
2249 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
2250 else
2251 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2252 acdb_rx_id, acdb_tx_id);
2253 }
2254
2255 return 0;
2256}
2257
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002258int platform_switch_voice_call_usecase_route_post(void *platform,
2259 snd_device_t out_snd_device,
2260 snd_device_t in_snd_device)
2261{
2262 struct platform_data *my_data = (struct platform_data *)platform;
2263 int acdb_rx_id, acdb_tx_id;
2264 int ret = 0;
2265
2266 if (my_data->csd == NULL)
2267 return ret;
2268
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002269 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
keunhui.park2f7306a2015-07-16 16:48:06 +09002270 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002271
2272 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
2273 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
2274 my_data->adev->acdb_settings);
2275 if (ret < 0) {
2276 ALOGE("%s: csd_enable_device, failed, error %d", __func__, ret);
2277 }
2278 } else {
2279 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2280 acdb_rx_id, acdb_tx_id);
2281 }
2282
2283 return ret;
2284}
2285
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002286int platform_start_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07002287{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002288 struct platform_data *my_data = (struct platform_data *)platform;
2289 int ret = 0;
2290
2291 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002292 ret = my_data->csd->start_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002293 if (ret < 0) {
2294 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
2295 }
2296 }
2297 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002298}
2299
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002300int platform_stop_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07002301{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002302 struct platform_data *my_data = (struct platform_data *)platform;
2303 int ret = 0;
2304
2305 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002306 ret = my_data->csd->stop_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002307 if (ret < 0) {
2308 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
2309 }
2310 }
2311 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002312}
2313
Vignesh Kulothunganb6f0a9c2018-03-22 13:50:22 -07002314int platform_set_mic_break_det(void *platform, bool enable)
2315{
2316 int ret = 0;
2317 struct platform_data *my_data = (struct platform_data *)platform;
2318 struct audio_device *adev = my_data->adev;
2319 const char *mixer_ctl_name = "Voice Mic Break Enable";
2320 struct mixer_ctl *ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2321 if (!ctl) {
2322 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2323 __func__, mixer_ctl_name);
2324 return -EINVAL;
2325 }
2326
2327 ret = mixer_ctl_set_value(ctl, 0, enable);
2328 if(ret)
2329 ALOGE("%s: Failed to set mixer ctl: %s", __func__, mixer_ctl_name);
2330
2331 return ret;
2332}
2333
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002334int platform_get_sample_rate(void *platform, uint32_t *rate)
2335{
2336 struct platform_data *my_data = (struct platform_data *)platform;
2337 int ret = 0;
2338
2339 if (my_data->csd != NULL) {
2340 ret = my_data->csd->get_sample_rate(rate);
2341 if (ret < 0) {
2342 ALOGE("%s: csd_get_sample_rate error %d\n", __func__, ret);
2343 }
2344 }
2345 return ret;
2346}
2347
vivek mehtab6506412015-08-07 16:55:17 -07002348void platform_set_speaker_gain_in_combo(struct audio_device *adev,
2349 snd_device_t snd_device,
2350 bool enable)
2351{
2352 const char* name;
2353 switch (snd_device) {
2354 case SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES:
2355 if (enable)
2356 name = "spkr-gain-in-headphone-combo";
2357 else
2358 name = "speaker-gain-default";
2359 break;
2360 case SND_DEVICE_OUT_SPEAKER_AND_LINE:
2361 if (enable)
2362 name = "spkr-gain-in-line-combo";
2363 else
2364 name = "speaker-gain-default";
2365 break;
2366 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES:
2367 if (enable)
2368 name = "spkr-safe-gain-in-headphone-combo";
2369 else
2370 name = "speaker-safe-gain-default";
2371 break;
2372 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE:
2373 if (enable)
2374 name = "spkr-safe-gain-in-line-combo";
2375 else
2376 name = "speaker-safe-gain-default";
2377 break;
2378 default:
2379 return;
2380 }
2381
2382 audio_route_apply_and_update_path(adev->audio_route, name);
2383}
2384
Eric Laurentb23d5282013-05-14 15:27:20 -07002385int platform_set_voice_volume(void *platform, int volume)
2386{
2387 struct platform_data *my_data = (struct platform_data *)platform;
2388 struct audio_device *adev = my_data->adev;
2389 struct mixer_ctl *ctl;
sangwoo53b2cf02013-07-25 19:18:44 -07002390 const char *mixer_ctl_name = "Voice Rx Gain";
Nadav Barc46d0fa2017-12-24 14:50:37 +02002391 const char *mute_mixer_ctl_name = "Voice Rx Device Mute";
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002392 int vol_index = 0, ret = 0;
2393 uint32_t set_values[ ] = {0,
2394 ALL_SESSION_VSID,
2395 DEFAULT_VOLUME_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07002396
2397 // Voice volume levels are mapped to adsp volume levels as follows.
2398 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
2399 // But this values don't changed in kernel. So, below change is need.
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09002400 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, my_data->max_vol_index);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002401 set_values[0] = vol_index;
Eric Laurentb23d5282013-05-14 15:27:20 -07002402
2403 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2404 if (!ctl) {
2405 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2406 __func__, mixer_ctl_name);
2407 return -EINVAL;
2408 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002409 ALOGV("Setting voice volume index: %d", set_values[0]);
2410 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2411
Nadav Barc46d0fa2017-12-24 14:50:37 +02002412 // Send mute command in case volume index is max since indexes are inverted
2413 // for mixer controls.
2414 if (vol_index == my_data->max_vol_index) {
2415 set_values[0] = 1;
2416 }
2417 else {
2418 set_values[0] = 0;
2419 }
2420
2421 ctl = mixer_get_ctl_by_name(adev->mixer, mute_mixer_ctl_name);
2422 if (!ctl) {
2423 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2424 __func__, mute_mixer_ctl_name);
2425 return -EINVAL;
2426 }
2427 ALOGV("%s: Setting RX Device Mute to: %d", __func__, set_values[0]);
2428 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2429
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002430 if (my_data->csd != NULL) {
2431 ret = my_data->csd->volume(ALL_SESSION_VSID, volume,
2432 DEFAULT_VOLUME_RAMP_DURATION_MS);
2433 if (ret < 0) {
2434 ALOGE("%s: csd_volume error %d", __func__, ret);
2435 }
2436 }
2437 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002438}
2439
2440int platform_set_mic_mute(void *platform, bool state)
2441{
2442 struct platform_data *my_data = (struct platform_data *)platform;
2443 struct audio_device *adev = my_data->adev;
2444 struct mixer_ctl *ctl;
2445 const char *mixer_ctl_name = "Voice Tx Mute";
sangwoo53b2cf02013-07-25 19:18:44 -07002446 int ret = 0;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002447 uint32_t set_values[ ] = {0,
2448 ALL_SESSION_VSID,
2449 DEFAULT_MUTE_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07002450
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09002451 if (adev->mode != AUDIO_MODE_IN_CALL &&
2452 adev->mode != AUDIO_MODE_IN_COMMUNICATION)
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002453 return 0;
2454
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09002455 if (adev->enable_hfp)
2456 mixer_ctl_name = "HFP Tx Mute";
2457
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002458 set_values[0] = state;
2459 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2460 if (!ctl) {
2461 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2462 __func__, mixer_ctl_name);
2463 return -EINVAL;
2464 }
2465 ALOGV("Setting voice mute state: %d", state);
2466 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2467
2468 if (my_data->csd != NULL) {
2469 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state,
2470 DEFAULT_MUTE_RAMP_DURATION_MS);
sangwoo53b2cf02013-07-25 19:18:44 -07002471 if (ret < 0) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002472 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
sangwoo53b2cf02013-07-25 19:18:44 -07002473 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002474 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002475 return ret;
2476}
Eric Laurentb23d5282013-05-14 15:27:20 -07002477
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002478int platform_set_device_mute(void *platform, bool state, char *dir)
2479{
2480 struct platform_data *my_data = (struct platform_data *)platform;
2481 struct audio_device *adev = my_data->adev;
2482 struct mixer_ctl *ctl;
2483 char *mixer_ctl_name = NULL;
2484 int ret = 0;
2485 uint32_t set_values[ ] = {0,
2486 ALL_SESSION_VSID,
2487 0};
2488 if(dir == NULL) {
2489 ALOGE("%s: Invalid direction:%s", __func__, dir);
2490 return -EINVAL;
2491 }
2492
2493 if (!strncmp("rx", dir, sizeof("rx"))) {
2494 mixer_ctl_name = "Voice Rx Device Mute";
2495 } else if (!strncmp("tx", dir, sizeof("tx"))) {
2496 mixer_ctl_name = "Voice Tx Device Mute";
2497 } else {
2498 return -EINVAL;
2499 }
2500
2501 set_values[0] = state;
2502 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2503 if (!ctl) {
2504 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2505 __func__, mixer_ctl_name);
2506 return -EINVAL;
2507 }
2508
2509 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
2510 __func__,state, mixer_ctl_name);
2511 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2512
2513 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002514}
2515
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002516int platform_can_split_snd_device(snd_device_t snd_device,
2517 int *num_devices,
2518 snd_device_t *new_snd_devices)
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002519{
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002520 int ret = -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002521 if (NULL == num_devices || NULL == new_snd_devices) {
2522 ALOGE("%s: NULL pointer ..", __func__);
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002523 return -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002524 }
2525
2526 /*
2527 * If wired headset/headphones/line devices share the same backend
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002528 * with speaker/earpiece this routine returns -EINVAL.
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002529 */
2530 if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES &&
2531 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_HEADPHONES)) {
2532 *num_devices = 2;
2533 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2534 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002535 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002536 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_LINE &&
2537 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_LINE)) {
2538 *num_devices = 2;
2539 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2540 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002541 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002542 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES &&
2543 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_HEADPHONES)) {
2544 *num_devices = 2;
2545 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2546 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002547 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002548 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE &&
2549 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_LINE)) {
2550 *num_devices = 2;
2551 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2552 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002553 ret = 0;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002554 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO &&
2555 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2556 SND_DEVICE_OUT_BT_SCO)) {
2557 *num_devices = 2;
2558 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2559 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO;
2560 ret = 0;
2561 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB &&
2562 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2563 SND_DEVICE_OUT_BT_SCO_WB)) {
2564 *num_devices = 2;
2565 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2566 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO_WB;
2567 ret = 0;
David Linee3fe402017-03-13 10:00:42 -07002568 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET &&
2569 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_USB_HEADSET)) {
2570 *num_devices = 2;
2571 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2572 new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
2573 ret = 0;
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07002574 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET &&
2575 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_USB_HEADSET)) {
2576 *num_devices = 2;
2577 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2578 new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
2579 ret = 0;
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002580 } else if (SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP == snd_device &&
2581 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2582 SND_DEVICE_OUT_BT_A2DP)) {
2583 *num_devices = 2;
2584 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2585 new_snd_devices[1] = SND_DEVICE_OUT_BT_A2DP;
2586 ret = 0;
Aniket Kumar Lata9723a962018-05-16 17:41:55 -07002587 } else if (SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP == snd_device &&
2588 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE,
2589 SND_DEVICE_OUT_BT_A2DP)) {
2590 *num_devices = 2;
2591 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2592 new_snd_devices[1] = SND_DEVICE_OUT_BT_A2DP;
2593 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002594 }
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002595
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002596 return ret;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002597}
2598
Eric Laurentb23d5282013-05-14 15:27:20 -07002599snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
2600{
2601 struct platform_data *my_data = (struct platform_data *)platform;
2602 struct audio_device *adev = my_data->adev;
2603 audio_mode_t mode = adev->mode;
2604 snd_device_t snd_device = SND_DEVICE_NONE;
2605
2606 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
2607 if (devices == AUDIO_DEVICE_NONE ||
2608 devices & AUDIO_DEVICE_BIT_IN) {
2609 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
2610 goto exit;
2611 }
2612
Eric Laurent1b491552015-09-15 17:52:41 -07002613 if (popcount(devices) == 2) {
2614 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2615 AUDIO_DEVICE_OUT_SPEAKER) ||
2616 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2617 AUDIO_DEVICE_OUT_SPEAKER)) {
2618 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
2619 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2620 AUDIO_DEVICE_OUT_SPEAKER)) {
2621 snd_device = SND_DEVICE_OUT_SPEAKER_AND_LINE;
2622 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2623 AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
2624 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2625 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2626 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES;
2627 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2628 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2629 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE;
2630 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
2631 AUDIO_DEVICE_OUT_SPEAKER)) {
2632 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002633 } else if ((devices & AUDIO_DEVICE_OUT_ALL_SCO) &&
2634 ((devices & ~AUDIO_DEVICE_OUT_ALL_SCO) == AUDIO_DEVICE_OUT_SPEAKER)) {
2635 snd_device = adev->bt_wb_speech_enabled ?
2636 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB :
2637 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO;
Eric Laurent99dab492017-06-17 15:19:08 -07002638 } else if ((devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
2639 AUDIO_DEVICE_OUT_SPEAKER)) ||
2640 (devices == (AUDIO_DEVICE_OUT_USB_HEADSET |
2641 AUDIO_DEVICE_OUT_SPEAKER))) {
David Linee3fe402017-03-13 10:00:42 -07002642 snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET;
Eric Laurentd0f7c262017-07-05 09:09:12 -07002643 } else if ((devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
2644 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) ||
2645 (devices == (AUDIO_DEVICE_OUT_USB_HEADSET |
2646 AUDIO_DEVICE_OUT_SPEAKER_SAFE))) {
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07002647 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET;
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002648 } else if ((devices & AUDIO_DEVICE_OUT_SPEAKER) &&
2649 (devices & AUDIO_DEVICE_OUT_ALL_A2DP)) {
2650 snd_device = SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP;
Aniket Kumar Lata9723a962018-05-16 17:41:55 -07002651 } else if ((devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) &&
2652 (devices & AUDIO_DEVICE_OUT_ALL_A2DP)) {
2653 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP;
Eric Laurent1b491552015-09-15 17:52:41 -07002654 } else {
2655 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
2656 goto exit;
2657 }
2658 if (snd_device != SND_DEVICE_NONE) {
2659 goto exit;
2660 }
2661 }
2662
2663 if (popcount(devices) != 1) {
2664 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
2665 goto exit;
2666 }
2667
Madhuri Athota3f6051b2016-10-13 23:25:38 +05302668 if (voice_is_in_call(adev) || adev->enable_voicerx || audio_extn_hfp_is_active(adev)) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002669 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002670 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2671 devices & AUDIO_DEVICE_OUT_LINE) {
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002672 if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002673 (adev->voice.tty_mode == TTY_MODE_FULL))
Eric Laurentb23d5282013-05-14 15:27:20 -07002674 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002675 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002676 (adev->voice.tty_mode == TTY_MODE_VCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002677 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002678 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002679 (adev->voice.tty_mode == TTY_MODE_HCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002680 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002681 else {
2682 if (devices & AUDIO_DEVICE_OUT_LINE)
2683 snd_device = SND_DEVICE_OUT_VOICE_LINE;
2684 else
2685 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
2686 }
Eric Laurent99dab492017-06-17 15:19:08 -07002687 } else if (audio_is_usb_out_device(devices)) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002688 if (voice_is_in_call(adev)) {
2689 switch (adev->voice.tty_mode) {
2690 case TTY_MODE_FULL:
2691 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_USB;
2692 break;
2693 case TTY_MODE_VCO:
2694 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_USB;
2695 break;
2696 case TTY_MODE_HCO:
2697 // since Hearing will be on handset\speaker, use existing device
2698 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
2699 break;
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002700 case TTY_MODE_OFF:
2701 break;
vivek mehtaa6b79742017-03-09 15:40:43 -08002702 default:
2703 ALOGE("%s: Invalid TTY mode (%#x)",
2704 __func__, adev->voice.tty_mode);
2705 }
2706 }
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002707 if (snd_device == SND_DEVICE_NONE) {
2708 snd_device = audio_extn_usb_is_capture_supported() ?
2709 SND_DEVICE_OUT_VOICE_USB_HEADSET :
2710 SND_DEVICE_OUT_VOICE_USB_HEADPHONES;
2711 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002712 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002713 if (adev->bt_wb_speech_enabled) {
2714 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2715 } else {
2716 snd_device = SND_DEVICE_OUT_BT_SCO;
2717 }
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002718 } else if (devices & AUDIO_DEVICE_OUT_ALL_A2DP) {
2719 snd_device = SND_DEVICE_OUT_BT_A2DP;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002720 } else if (devices & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002721 if (!adev->enable_hfp) {
2722 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
2723 } else {
2724 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_HFP;
2725 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002726 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002727 if(adev->voice.hac)
2728 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2729 else if (is_operator_tmus())
Eric Laurentb23d5282013-05-14 15:27:20 -07002730 snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS;
2731 else
Eric Laurentb4d368e2014-06-25 10:21:54 -05002732 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002733 } else if (devices & AUDIO_DEVICE_OUT_TELEPHONY_TX)
2734 snd_device = SND_DEVICE_OUT_VOICE_TX;
2735
Eric Laurentb23d5282013-05-14 15:27:20 -07002736 if (snd_device != SND_DEVICE_NONE) {
2737 goto exit;
2738 }
2739 }
2740
Eric Laurentb23d5282013-05-14 15:27:20 -07002741 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2742 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2743 snd_device = SND_DEVICE_OUT_HEADPHONES;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002744 } else if (devices & AUDIO_DEVICE_OUT_LINE) {
2745 snd_device = SND_DEVICE_OUT_LINE;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002746 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) {
2747 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE;
Eric Laurentb23d5282013-05-14 15:27:20 -07002748 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
andysu5b30b062018-04-20 16:34:06 +08002749 /*
2750 * Perform device switch only if acdb tuning is different between SPEAKER & SPEAKER_REVERSE,
2751 * Or there will be a small pause while performing device switch.
2752 */
2753 if (my_data->speaker_lr_swap &&
2754 (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
2755 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]))
Eric Laurentb23d5282013-05-14 15:27:20 -07002756 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
2757 else
2758 snd_device = SND_DEVICE_OUT_SPEAKER;
2759 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002760 if (adev->bt_wb_speech_enabled) {
2761 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2762 } else {
2763 snd_device = SND_DEVICE_OUT_BT_SCO;
2764 }
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002765 } else if (devices & AUDIO_DEVICE_OUT_ALL_A2DP) {
2766 snd_device = SND_DEVICE_OUT_BT_A2DP;
Eric Laurentb23d5282013-05-14 15:27:20 -07002767 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2768 snd_device = SND_DEVICE_OUT_HDMI ;
Eric Laurent99dab492017-06-17 15:19:08 -07002769 } else if (audio_is_usb_out_device(devices)) {
jasmine cha270b7762018-03-30 15:41:33 +08002770 if (audio_extn_ma_supported_usb())
2771 snd_device = SND_DEVICE_OUT_USB_HEADSET_SPEC;
2772 else if (audio_extn_usb_is_capture_supported())
David Linee3fe402017-03-13 10:00:42 -07002773 snd_device = SND_DEVICE_OUT_USB_HEADSET;
2774 else
2775 snd_device = SND_DEVICE_OUT_USB_HEADPHONES;
2776 }else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002777 /*HAC support for voice-ish audio (eg visual voicemail)*/
2778 if(adev->voice.hac)
2779 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2780 else
2781 snd_device = SND_DEVICE_OUT_HANDSET;
Eric Laurentb23d5282013-05-14 15:27:20 -07002782 } else {
2783 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
2784 }
2785exit:
2786 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
2787 return snd_device;
2788}
2789
2790snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
2791{
2792 struct platform_data *my_data = (struct platform_data *)platform;
2793 struct audio_device *adev = my_data->adev;
2794 audio_source_t source = (adev->active_input == NULL) ?
2795 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
2796
2797 audio_mode_t mode = adev->mode;
2798 audio_devices_t in_device = ((adev->active_input == NULL) ?
2799 AUDIO_DEVICE_NONE : adev->active_input->device)
2800 & ~AUDIO_DEVICE_BIT_IN;
2801 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
2802 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
2803 snd_device_t snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002804 int channel_count = popcount(channel_mask);
Eric Laurentb23d5282013-05-14 15:27:20 -07002805
Prashant Malanic92c5962015-08-11 15:10:18 -07002806 ALOGV("%s: enter: out_device(%#x) in_device(%#x) channel_count (%d) channel_mask (0x%x)",
2807 __func__, out_device, in_device, channel_count, channel_mask);
Devin Kimd789e432016-10-26 15:07:27 -07002808 if ((out_device != AUDIO_DEVICE_NONE) && (voice_is_in_call(adev) ||
2809 audio_extn_hfp_is_active(adev))) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002810 if (adev->voice.tty_mode != TTY_MODE_OFF) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002811 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002812 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2813 out_device & AUDIO_DEVICE_OUT_LINE) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002814 switch (adev->voice.tty_mode) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002815 case TTY_MODE_FULL:
2816 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
2817 break;
2818 case TTY_MODE_VCO:
2819 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
2820 break;
2821 case TTY_MODE_HCO:
2822 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
2823 break;
2824 default:
2825 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
2826 }
2827 goto exit;
Eric Laurent99dab492017-06-17 15:19:08 -07002828 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002829 switch (adev->voice.tty_mode) {
2830 case TTY_MODE_FULL:
2831 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC;
2832 break;
2833 case TTY_MODE_VCO:
2834 // since voice will be captured from handset mic, use existing device
2835 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
2836 break;
2837 case TTY_MODE_HCO:
2838 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC;
2839 break;
2840 default:
2841 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
Eric Laurentb23d5282013-05-14 15:27:20 -07002842 }
2843 goto exit;
2844 }
2845 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002846 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002847 if (my_data->fluence_in_voice_call == false) {
2848 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2849 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002850 if (is_operator_tmus())
2851 snd_device = SND_DEVICE_IN_VOICE_DMIC_TMUS;
Eric Laurentb23d5282013-05-14 15:27:20 -07002852 else
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002853 snd_device = SND_DEVICE_IN_VOICE_DMIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002854 }
2855 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2856 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
2857 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002858 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002859 if (adev->bluetooth_nrec)
2860 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2861 else
2862 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002863 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002864 if (adev->bluetooth_nrec)
2865 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2866 else
2867 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002868 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002869 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Prashant Malanic92c5962015-08-11 15:10:18 -07002870 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
2871 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2872 out_device & AUDIO_DEVICE_OUT_LINE) {
2873 if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
2874 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
2875 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
2876 } else {
2877 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2878 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002879 }
vivek mehtafe121d52015-08-10 23:39:23 -07002880
2881 //select default
2882 if (snd_device == SND_DEVICE_NONE) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002883 if (!adev->enable_hfp) {
2884 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2885 } else {
2886 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP;
2887 platform_set_echo_reference(adev, true, out_device);
2888 }
vivek mehtafe121d52015-08-10 23:39:23 -07002889 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002890 } else if (out_device & AUDIO_DEVICE_OUT_TELEPHONY_TX) {
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002891 snd_device = SND_DEVICE_IN_VOICE_RX;
Eric Laurent99dab492017-06-17 15:19:08 -07002892 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
David Lin40b07892017-08-07 15:02:48 -07002893 if (audio_extn_usb_is_capture_supported()) {
2894 snd_device = SND_DEVICE_IN_VOICE_USB_HEADSET_MIC;
2895 } else if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
2896 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
2897 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
2898 } else {
2899 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2900 }
2901 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002902 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002903 } else if (source == AUDIO_SOURCE_CAMCORDER) {
2904 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
2905 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2906 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
2907 }
2908 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
2909 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002910 if (my_data->fluence_in_voice_rec && channel_count == 1) {
2911 if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2912 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002913 if (adev->active_input->enable_aec)
2914 snd_device = SND_DEVICE_IN_HANDSET_QMIC_AEC;
2915 else
2916 snd_device = SND_DEVICE_IN_HANDSET_QMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002917 } else if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2918 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002919 if (adev->active_input->enable_aec)
2920 snd_device = SND_DEVICE_IN_HANDSET_TMIC_AEC;
2921 else
2922 snd_device = SND_DEVICE_IN_HANDSET_TMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002923 } else if (((my_data->fluence_type == FLUENCE_PRO_ENABLE) ||
2924 (my_data->fluence_type == FLUENCE_ENABLE)) &&
2925 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002926 if (adev->active_input->enable_aec)
2927 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
2928 else
2929 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
Prashant Malanic92c5962015-08-11 15:10:18 -07002930 }
2931 platform_set_echo_reference(adev, true, out_device);
2932 } else if ((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) &&
2933 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2934 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002935 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002936 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
2937 snd_device = SND_DEVICE_IN_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002938 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002939 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2940 snd_device = SND_DEVICE_IN_QUAD_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002941 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002942 if (snd_device == SND_DEVICE_NONE) {
vivek mehtaf3440682016-05-11 14:24:37 -07002943 if (adev->active_input->enable_aec) {
2944 if (adev->active_input->enable_ns) {
2945 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS;
2946 } else {
2947 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC;
2948 }
vivek mehta733c1df2016-04-04 15:09:24 -07002949 platform_set_echo_reference(adev, true, out_device);
vivek mehtaf3440682016-05-11 14:24:37 -07002950 } else if (adev->active_input->enable_ns) {
2951 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
2952 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002953 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
vivek mehtaf3440682016-05-11 14:24:37 -07002954 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002955 }
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -07002956 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2957 snd_device = SND_DEVICE_IN_VOICE_REC_HEADSET_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07002958 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002959 snd_device = SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002960 }
rago90fb9612015-12-02 11:37:53 -08002961 } else if (source == AUDIO_SOURCE_UNPROCESSED) {
2962 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
vivek mehta4ed66e62016-04-15 23:33:34 -07002963 if (((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) ||
2964 (channel_mask == AUDIO_CHANNEL_IN_STEREO)) &&
2965 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2966 snd_device = SND_DEVICE_IN_UNPROCESSED_STEREO_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002967 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07002968 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
2969 snd_device = SND_DEVICE_IN_UNPROCESSED_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002970 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07002971 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2972 snd_device = SND_DEVICE_IN_UNPROCESSED_QUAD_MIC;
2973 } else {
2974 snd_device = SND_DEVICE_IN_UNPROCESSED_MIC;
2975 }
rago90fb9612015-12-02 11:37:53 -08002976 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2977 snd_device = SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07002978 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002979 snd_device = SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC;
rago90fb9612015-12-02 11:37:53 -08002980 }
Eric Laurent50a38ed2015-10-14 18:48:06 -07002981 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION ||
rago90fb9612015-12-02 11:37:53 -08002982 mode == AUDIO_MODE_IN_COMMUNICATION) {
David Lin40b07892017-08-07 15:02:48 -07002983 if (out_device & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
2984 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2985 (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE | AUDIO_DEVICE_OUT_USB_HEADSET) &&
2986 !audio_extn_usb_is_capture_supported())) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002987 in_device = AUDIO_DEVICE_IN_BACK_MIC;
David Lin40b07892017-08-07 15:02:48 -07002988 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002989 if (adev->active_input) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002990 if (adev->active_input->enable_aec &&
2991 adev->active_input->enable_ns) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002992 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002993 if (my_data->fluence_in_spkr_mode &&
2994 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002995 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002996 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002997 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002998 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002999 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003000 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003001 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003002 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003003 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003004 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003005 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003006 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05003007 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3008 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Eric Laurent99dab492017-06-17 15:19:08 -07003009 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07003010 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
Eric Laurentb23d5282013-05-14 15:27:20 -07003011 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05003012 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003013 } else if (adev->active_input->enable_aec) {
3014 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
3015 if (my_data->fluence_in_spkr_mode &&
3016 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003017 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003018 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003019 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003020 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003021 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003022 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
3023 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003024 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003025 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003026 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003027 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003028 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05003029 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3030 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Eric Laurent99dab492017-06-17 15:19:08 -07003031 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07003032 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
Eric Laurentcefbbac2014-09-04 13:54:10 -05003033 }
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08003034 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003035 } else if (adev->active_input->enable_ns) {
3036 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
3037 if (my_data->fluence_in_spkr_mode &&
3038 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003039 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003040 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003041 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003042 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003043 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003044 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
3045 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003046 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003047 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003048 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003049 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003050 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003051 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05003052 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003053 }
3054 } else if (source == AUDIO_SOURCE_DEFAULT) {
3055 goto exit;
3056 }
3057
3058
3059 if (snd_device != SND_DEVICE_NONE) {
3060 goto exit;
3061 }
3062
3063 if (in_device != AUDIO_DEVICE_NONE &&
3064 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
3065 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
3066 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003067 if ((my_data->source_mic_type & SOURCE_QUAD_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003068 channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003069 snd_device = SND_DEVICE_IN_QUAD_MIC;
3070 } else if ((my_data->source_mic_type & SOURCE_THREE_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003071 channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003072 snd_device = SND_DEVICE_IN_THREE_MIC;
3073 } else if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
3074 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003075 snd_device = SND_DEVICE_IN_HANDSET_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07003076 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
3077 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003078 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003079 } else {
3080 ALOGE("%s: something wrong (1): source type (%d) channel_count (%d) .."
3081 " channel mask (0x%x) no combination found .. setting to mono", __func__,
3082 my_data->source_mic_type, channel_count, channel_mask);
3083 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3084 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003085 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003086 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
3087 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003088 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07003089 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
3090 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003091 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003092 } else {
3093 ALOGE("%s: something wrong (2): source type (%d) channel_count (%d) .."
3094 " no combination found .. setting to mono", __func__,
3095 my_data->source_mic_type, channel_count);
3096 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
3097 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003098 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3099 snd_device = SND_DEVICE_IN_HEADSET_MIC;
3100 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003101 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003102 if (adev->bluetooth_nrec)
3103 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
3104 else
3105 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003106 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003107 if (adev->bluetooth_nrec)
3108 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
3109 else
3110 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003111 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003112 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
3113 snd_device = SND_DEVICE_IN_HDMI_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07003114 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
David Linee3fe402017-03-13 10:00:42 -07003115 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07003116 } else {
3117 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
3118 ALOGW("%s: Using default handset-mic", __func__);
3119 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3120 }
3121 } else {
3122 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
3123 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3124 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
3125 snd_device = SND_DEVICE_IN_HEADSET_MIC;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003126 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07003127 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003128 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05003129 out_device & AUDIO_DEVICE_OUT_LINE) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003130 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
3131 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003132 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07003133 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
3134 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003135 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003136 } else {
3137 ALOGE("%s: something wrong (3): source type (%d) channel_count (%d) .."
3138 " no combination found .. setting to mono", __func__,
3139 my_data->source_mic_type, channel_count);
3140 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
3141 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003142 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003143 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003144 if (adev->bluetooth_nrec)
3145 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
3146 else
3147 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003148 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003149 if (adev->bluetooth_nrec)
3150 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
3151 else
3152 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003153 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003154 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
3155 snd_device = SND_DEVICE_IN_HDMI_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07003156 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
David Linee3fe402017-03-13 10:00:42 -07003157 if (audio_extn_usb_is_capture_supported())
3158 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
3159 else
3160 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07003161 } else {
3162 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
3163 ALOGW("%s: Using default handset-mic", __func__);
3164 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3165 }
3166 }
3167exit:
3168 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
3169 return snd_device;
3170}
3171
3172int platform_set_hdmi_channels(void *platform, int channel_count)
3173{
3174 struct platform_data *my_data = (struct platform_data *)platform;
3175 struct audio_device *adev = my_data->adev;
3176 struct mixer_ctl *ctl;
3177 const char *channel_cnt_str = NULL;
3178 const char *mixer_ctl_name = "HDMI_RX Channels";
3179 switch (channel_count) {
3180 case 8:
3181 channel_cnt_str = "Eight"; break;
3182 case 7:
3183 channel_cnt_str = "Seven"; break;
3184 case 6:
3185 channel_cnt_str = "Six"; break;
3186 case 5:
3187 channel_cnt_str = "Five"; break;
3188 case 4:
3189 channel_cnt_str = "Four"; break;
3190 case 3:
3191 channel_cnt_str = "Three"; break;
3192 default:
3193 channel_cnt_str = "Two"; break;
3194 }
3195 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3196 if (!ctl) {
3197 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3198 __func__, mixer_ctl_name);
3199 return -EINVAL;
3200 }
3201 ALOGV("HDMI channel count: %s", channel_cnt_str);
3202 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
3203 return 0;
3204}
3205
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003206int platform_edid_get_max_channels(void *platform)
Eric Laurentb23d5282013-05-14 15:27:20 -07003207{
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003208 struct platform_data *my_data = (struct platform_data *)platform;
3209 struct audio_device *adev = my_data->adev;
Eric Laurentb23d5282013-05-14 15:27:20 -07003210 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
3211 char *sad = block;
3212 int num_audio_blocks;
3213 int channel_count;
3214 int max_channels = 0;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003215 int i, ret, count;
Eric Laurentb23d5282013-05-14 15:27:20 -07003216
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003217 struct mixer_ctl *ctl;
3218
3219 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
3220 if (!ctl) {
3221 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3222 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
Eric Laurentb23d5282013-05-14 15:27:20 -07003223 return 0;
3224 }
3225
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003226 mixer_ctl_update(ctl);
3227
3228 count = mixer_ctl_get_num_values(ctl);
Eric Laurentb23d5282013-05-14 15:27:20 -07003229
3230 /* Read SAD blocks, clamping the maximum size for safety */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003231 if (count > (int)sizeof(block))
3232 count = (int)sizeof(block);
Eric Laurentb23d5282013-05-14 15:27:20 -07003233
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003234 ret = mixer_ctl_get_array(ctl, block, count);
3235 if (ret != 0) {
3236 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
3237 return 0;
3238 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003239
3240 /* Calculate the number of SAD blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003241 num_audio_blocks = count / SAD_BLOCK_SIZE;
Eric Laurentb23d5282013-05-14 15:27:20 -07003242
3243 for (i = 0; i < num_audio_blocks; i++) {
3244 /* Only consider LPCM blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003245 if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
3246 sad += 3;
Eric Laurentb23d5282013-05-14 15:27:20 -07003247 continue;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003248 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003249
3250 channel_count = (sad[0] & 0x7) + 1;
3251 if (channel_count > max_channels)
3252 max_channels = channel_count;
3253
3254 /* Advance to next block */
3255 sad += 3;
3256 }
3257
3258 return max_channels;
3259}
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003260
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07003261int platform_set_incall_recording_session_id(void *platform,
3262 uint32_t session_id, int rec_mode)
3263{
3264 int ret = 0;
3265 struct platform_data *my_data = (struct platform_data *)platform;
3266 struct audio_device *adev = my_data->adev;
3267 struct mixer_ctl *ctl;
3268 const char *mixer_ctl_name = "Voc VSID";
3269 int num_ctl_values;
3270 int i;
3271
3272 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3273 if (!ctl) {
3274 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3275 __func__, mixer_ctl_name);
3276 ret = -EINVAL;
3277 } else {
3278 num_ctl_values = mixer_ctl_get_num_values(ctl);
3279 for (i = 0; i < num_ctl_values; i++) {
3280 if (mixer_ctl_set_value(ctl, i, session_id)) {
3281 ALOGV("Error: invalid session_id: %x", session_id);
3282 ret = -EINVAL;
3283 break;
3284 }
3285 }
3286 }
3287
3288 if (my_data->csd != NULL) {
3289 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
3290 if (ret < 0) {
3291 ALOGE("%s: csd_client_start_record failed, error %d",
3292 __func__, ret);
3293 }
3294 }
3295
3296 return ret;
3297}
3298
Arun Mirpuriba2749a2018-04-17 14:32:24 -07003299int platform_set_incall_recording_session_channels(void *platform,
3300 uint32_t channel_count)
3301{
3302 int ret = 0;
3303 struct platform_data *my_data = (struct platform_data *)platform;
3304 struct audio_device *adev = my_data->adev;
3305 const char *mixer_ctl_name = "Voc Rec Config";
3306 int num_ctl_values;
3307 int i;
3308 struct mixer_ctl *ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3309
3310 if (!ctl) {
3311 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3312 __func__, mixer_ctl_name);
3313 ret = -EINVAL;
3314 } else {
3315 num_ctl_values = mixer_ctl_get_num_values(ctl);
3316 for (i = 0; i < num_ctl_values; i++) {
3317 if (mixer_ctl_set_value(ctl, i, channel_count)) {
3318 ALOGE("Error: invalid channel count: %x", channel_count);
3319 ret = -EINVAL;
3320 break;
3321 }
3322 }
3323 }
3324
3325 return ret;
3326}
3327
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07003328int platform_stop_incall_recording_usecase(void *platform)
3329{
3330 int ret = 0;
3331 struct platform_data *my_data = (struct platform_data *)platform;
3332
3333 if (my_data->csd != NULL) {
3334 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
3335 if (ret < 0) {
3336 ALOGE("%s: csd_client_stop_record failed, error %d",
3337 __func__, ret);
3338 }
3339 }
3340
3341 return ret;
3342}
3343
3344int platform_start_incall_music_usecase(void *platform)
3345{
3346 int ret = 0;
3347 struct platform_data *my_data = (struct platform_data *)platform;
3348
3349 if (my_data->csd != NULL) {
3350 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
3351 if (ret < 0) {
3352 ALOGE("%s: csd_client_start_playback failed, error %d",
3353 __func__, ret);
3354 }
3355 }
3356
3357 return ret;
3358}
3359
3360int platform_stop_incall_music_usecase(void *platform)
3361{
3362 int ret = 0;
3363 struct platform_data *my_data = (struct platform_data *)platform;
3364
3365 if (my_data->csd != NULL) {
3366 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
3367 if (ret < 0) {
3368 ALOGE("%s: csd_client_stop_playback failed, error %d",
3369 __func__, ret);
3370 }
3371 }
3372
3373 return ret;
3374}
3375
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003376int platform_set_parameters(void *platform, struct str_parms *parms)
3377{
3378 struct platform_data *my_data = (struct platform_data *)platform;
jasmine chac89321b2018-04-10 21:37:01 +08003379 char *value = NULL;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003380 char *kv_pairs = str_parms_to_str(parms);
jasmine chac89321b2018-04-10 21:37:01 +08003381 int len;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003382 int ret = 0, err;
3383
3384 if (kv_pairs == NULL) {
3385 ret = -EINVAL;
Jasmine Chaa314e192018-05-09 17:46:28 +08003386 ALOGE("%s: key-value pair is NULL", __func__);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003387 goto done;
3388 }
3389
3390 ALOGV("%s: enter: %s", __func__, kv_pairs);
3391
jasmine chac89321b2018-04-10 21:37:01 +08003392 len = strlen(kv_pairs);
Jasmine Chaa314e192018-05-09 17:46:28 +08003393 value = (char*)calloc(len + 1, sizeof(char));
jasmine chac89321b2018-04-10 21:37:01 +08003394 if (value == NULL) {
3395 ret = -ENOMEM;
Jasmine Chaa314e192018-05-09 17:46:28 +08003396 ALOGE("[%s] failed to allocate memory", __func__);
jasmine chac89321b2018-04-10 21:37:01 +08003397 goto done;
3398 }
3399
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003400 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME,
jasmine chac89321b2018-04-10 21:37:01 +08003401 value, len);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003402 if (err >= 0) {
3403 str_parms_del(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME);
3404 my_data->snd_card_name = strdup(value);
3405 ALOGV("%s: sound card name %s", __func__, my_data->snd_card_name);
3406 }
3407
keunhui.park2f7306a2015-07-16 16:48:06 +09003408 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO,
jasmine chac89321b2018-04-10 21:37:01 +08003409 value, len);
keunhui.park2f7306a2015-07-16 16:48:06 +09003410 if (err >= 0) {
3411 struct operator_info *info;
3412 char *str = value;
3413 char *name;
3414
3415 str_parms_del(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO);
3416 info = (struct operator_info *)calloc(1, sizeof(struct operator_info));
3417 name = strtok(str, ";");
3418 info->name = strdup(name);
3419 info->mccmnc = strdup(str + strlen(name) + 1);
3420
3421 list_add_tail(&operator_info_list, &info->list);
Joe Onorato188b6222016-03-01 11:02:27 -08003422 ALOGV("%s: add operator[%s] mccmnc[%s]", __func__, info->name, info->mccmnc);
keunhui.park2f7306a2015-07-16 16:48:06 +09003423 }
Prashant Malanic92c5962015-08-11 15:10:18 -07003424
Jasmine Chaa314e192018-05-09 17:46:28 +08003425 memset(value, 0, len + 1);
Eric Laurentc6333382015-09-14 12:43:44 -07003426 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT,
jasmine chac89321b2018-04-10 21:37:01 +08003427 value, len);
Prashant Malanic92c5962015-08-11 15:10:18 -07003428 if (err >= 0) {
Eric Laurentc6333382015-09-14 12:43:44 -07003429 str_parms_del(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT);
Prashant Malanic92c5962015-08-11 15:10:18 -07003430 my_data->max_mic_count = atoi(value);
3431 ALOGV("%s: max_mic_count %s/%d", __func__, value, my_data->max_mic_count);
Prashant Malanic92c5962015-08-11 15:10:18 -07003432 }
3433
jasmine chac89321b2018-04-10 21:37:01 +08003434 /* handle audio calibration parameters */
3435 set_audiocal(platform, parms, value, len);
3436
vivek mehta90933872017-06-15 18:04:39 -07003437 // to-do: disable setting sidetone gain, will revist this later
3438 // audio_extn_usb_set_sidetone_gain(parms, value, len);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003439done:
3440 ALOGV("%s: exit with code(%d)", __func__, ret);
3441 if (kv_pairs != NULL)
3442 free(kv_pairs);
jasmine chac89321b2018-04-10 21:37:01 +08003443 if (value != NULL)
3444 free(value);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003445
3446 return ret;
3447}
3448
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003449/* Delay in Us */
3450int64_t platform_render_latency(audio_usecase_t usecase)
3451{
3452 switch (usecase) {
3453 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
3454 return DEEP_BUFFER_PLATFORM_DELAY;
3455 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
3456 return LOW_LATENCY_PLATFORM_DELAY;
Haynes Mathew George03c40102016-01-29 17:57:48 -08003457 case USECASE_AUDIO_PLAYBACK_ULL:
3458 return ULL_PLATFORM_DELAY;
Eric Laurent0e46adf2016-12-16 12:49:24 -08003459 case USECASE_AUDIO_PLAYBACK_MMAP:
3460 return MMAP_PLATFORM_DELAY;
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003461 default:
3462 return 0;
3463 }
3464}
Haynes Mathew George98c95622014-06-20 19:14:25 -07003465
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003466int platform_set_snd_device_backend(snd_device_t device, const char *backend_tag,
3467 const char * hw_interface)
Haynes Mathew George98c95622014-06-20 19:14:25 -07003468{
3469 int ret = 0;
3470
3471 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
3472 ALOGE("%s: Invalid snd_device = %d",
3473 __func__, device);
3474 ret = -EINVAL;
3475 goto done;
3476 }
3477
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003478 ALOGV("%s: backend_tag_table[%s]: old = %s new = %s", __func__,
3479 platform_get_snd_device_name(device),
3480 backend_tag_table[device] != NULL ? backend_tag_table[device]: "null", backend_tag);
3481 if (backend_tag_table[device]) {
3482 free(backend_tag_table[device]);
Haynes Mathew George98c95622014-06-20 19:14:25 -07003483 }
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003484 backend_tag_table[device] = strdup(backend_tag);
3485
3486 if (hw_interface != NULL) {
3487 if (hw_interface_table[device])
3488 free(hw_interface_table[device]);
3489 ALOGV("%s: hw_interface_table[%d] = %s", __func__, device, hw_interface);
3490 hw_interface_table[device] = strdup(hw_interface);
3491 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07003492done:
3493 return ret;
3494}
3495
3496int platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t pcm_id)
3497{
3498 int ret = 0;
3499 if ((usecase <= USECASE_INVALID) || (usecase >= AUDIO_USECASE_MAX)) {
3500 ALOGE("%s: invalid usecase case idx %d", __func__, usecase);
3501 ret = -EINVAL;
3502 goto done;
3503 }
3504
3505 if ((type != 0) && (type != 1)) {
3506 ALOGE("%s: invalid usecase type", __func__);
3507 ret = -EINVAL;
3508 }
vivek mehtaa68fea62017-06-08 19:04:02 -07003509 ALOGV("%s: pcm_device_table[%d %s][%d] = %d", __func__, usecase,
3510 use_case_table[usecase],
3511 type, pcm_id);
Haynes Mathew George98c95622014-06-20 19:14:25 -07003512 pcm_device_table[usecase][type] = pcm_id;
3513done:
3514 return ret;
3515}
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003516
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07003517#define DEFAULT_NOMINAL_SPEAKER_GAIN 20
3518int ramp_speaker_gain(struct audio_device *adev, bool ramp_up, int target_ramp_up_gain) {
3519 // backup_gain: gain to try to set in case of an error during ramp
3520 int start_gain, end_gain, step, backup_gain, i;
3521 bool error = false;
3522 const struct mixer_ctl *ctl;
3523 const char *mixer_ctl_name_gain_left = "Left Speaker Gain";
3524 const char *mixer_ctl_name_gain_right = "Right Speaker Gain";
3525 struct mixer_ctl *ctl_left = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_left);
3526 struct mixer_ctl *ctl_right = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_right);
3527 if (!ctl_left || !ctl_right) {
3528 ALOGE("%s: Could not get ctl for mixer cmd - %s or %s, not applying speaker gain ramp",
3529 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
3530 return -EINVAL;
3531 } else if ((mixer_ctl_get_num_values(ctl_left) != 1)
3532 || (mixer_ctl_get_num_values(ctl_right) != 1)) {
3533 ALOGE("%s: Unexpected num values for mixer cmd - %s or %s, not applying speaker gain ramp",
3534 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
3535 return -EINVAL;
3536 }
3537 if (ramp_up) {
3538 start_gain = 0;
3539 end_gain = target_ramp_up_gain > 0 ? target_ramp_up_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
3540 step = +1;
3541 backup_gain = end_gain;
3542 } else {
3543 // using same gain on left and right
3544 const int left_gain = mixer_ctl_get_value(ctl_left, 0);
3545 start_gain = left_gain > 0 ? left_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
3546 end_gain = 0;
3547 step = -1;
3548 backup_gain = start_gain;
3549 }
3550 for (i = start_gain ; i != (end_gain + step) ; i += step) {
3551 //ALOGV("setting speaker gain to %d", i);
3552 if (mixer_ctl_set_value(ctl_left, 0, i)) {
3553 ALOGE("%s: error setting %s to %d during gain ramp",
3554 __func__, mixer_ctl_name_gain_left, i);
3555 error = true;
3556 break;
3557 }
3558 if (mixer_ctl_set_value(ctl_right, 0, i)) {
3559 ALOGE("%s: error setting %s to %d during gain ramp",
3560 __func__, mixer_ctl_name_gain_right, i);
3561 error = true;
3562 break;
3563 }
3564 usleep(1000);
3565 }
3566 if (error) {
3567 // an error occured during the ramp, let's still try to go back to a safe volume
3568 if (mixer_ctl_set_value(ctl_left, 0, backup_gain)) {
3569 ALOGE("%s: error restoring left gain to %d", __func__, backup_gain);
3570 }
3571 if (mixer_ctl_set_value(ctl_right, 0, backup_gain)) {
3572 ALOGE("%s: error restoring right gain to %d", __func__, backup_gain);
3573 }
3574 }
3575 return start_gain;
3576}
3577
vivek mehtae59cfb22017-06-16 15:57:11 -07003578int platform_set_swap_mixer(struct audio_device *adev, bool swap_channels)
3579{
3580 const char *mixer_ctl_name = "Swap channel";
3581 struct mixer_ctl *ctl;
3582 const char *mixer_path;
3583 struct platform_data *my_data = (struct platform_data *)adev->platform;
3584
3585 // forced to set to swap, but device not rotated ... ignore set
3586 if (swap_channels && !my_data->speaker_lr_swap)
3587 return 0;
3588
3589 ALOGV("%s:", __func__);
3590
3591 if (swap_channels) {
3592 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER_REVERSE);
3593 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
3594 } else {
3595 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER);
3596 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
3597 }
3598
3599 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3600 if (!ctl) {
3601 ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name);
3602 return -EINVAL;
3603 }
3604
3605 if (mixer_ctl_set_value(ctl, 0, swap_channels) < 0) {
3606 ALOGE("%s: Could not set reverse cotrol %d",__func__, swap_channels);
3607 return -EINVAL;
3608 }
3609
3610 ALOGV("platfor_force_swap_channel :: Channel orientation ( %s ) ",
3611 swap_channels?"R --> L":"L --> R");
3612
3613 return 0;
3614}
3615
3616int platform_check_and_set_swap_lr_channels(struct audio_device *adev, bool swap_channels)
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003617{
3618 // only update if there is active pcm playback on speaker
3619 struct audio_usecase *usecase;
3620 struct listnode *node;
3621 struct platform_data *my_data = (struct platform_data *)adev->platform;
3622
vivek mehtae59cfb22017-06-16 15:57:11 -07003623 my_data->speaker_lr_swap = swap_channels;
Jean-Michel Trivif7148702016-09-16 18:23:05 -07003624
vivek mehtae59cfb22017-06-16 15:57:11 -07003625 return platform_set_swap_channels(adev, swap_channels);
3626}
Jean-Michel Trivif7148702016-09-16 18:23:05 -07003627
vivek mehtae59cfb22017-06-16 15:57:11 -07003628int platform_set_swap_channels(struct audio_device *adev, bool swap_channels)
3629{
3630 // only update if there is active pcm playback on speaker
3631 struct audio_usecase *usecase;
3632 struct listnode *node;
3633 struct platform_data *my_data = (struct platform_data *)adev->platform;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003634
vivek mehtae59cfb22017-06-16 15:57:11 -07003635 // do not swap channels in audio modes with concurrent capture and playback
3636 // as this may break the echo reference
3637 if ((adev->mode == AUDIO_MODE_IN_COMMUNICATION) || (adev->mode == AUDIO_MODE_IN_CALL)) {
3638 ALOGV("%s: will not swap due to audio mode %d", __func__, adev->mode);
3639 return 0;
3640 }
3641
3642 list_for_each(node, &adev->usecase_list) {
3643 usecase = node_to_item(node, struct audio_usecase, list);
3644 if (usecase->type == PCM_PLAYBACK &&
3645 usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) {
3646 /*
3647 * If acdb tuning is different for SPEAKER_REVERSE, it is must
3648 * to perform device switch to disable the current backend to
3649 * enable it with new acdb data.
3650 */
3651 if (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
3652 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]) {
3653 const int initial_skpr_gain = ramp_speaker_gain(adev, false /*ramp_up*/, -1);
3654 select_devices(adev, usecase->id);
3655 if (initial_skpr_gain != -EINVAL)
3656 ramp_speaker_gain(adev, true /*ramp_up*/, initial_skpr_gain);
3657
3658 } else {
3659 platform_set_swap_mixer(adev, swap_channels);
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003660 }
vivek mehtae59cfb22017-06-16 15:57:11 -07003661 break;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003662 }
3663 }
vivek mehtae59cfb22017-06-16 15:57:11 -07003664
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003665 return 0;
3666}
vivek mehtaa8d7c922016-05-25 14:40:44 -07003667
3668static struct amp_db_and_gain_table tbl_mapping[MAX_VOLUME_CAL_STEPS];
3669static int num_gain_tbl_entry = 0;
3670
3671bool platform_add_gain_level_mapping(struct amp_db_and_gain_table *tbl_entry) {
3672
3673 ALOGV("%s: enter .. add %f %f %d", __func__, tbl_entry->amp, tbl_entry->db, tbl_entry->level);
3674 if (num_gain_tbl_entry == -1) {
3675 ALOGE("%s: num entry beyond valid step levels or corrupted..rejecting custom mapping",
3676 __func__);
3677 return false;
3678 }
3679
3680 if (num_gain_tbl_entry >= MAX_VOLUME_CAL_STEPS) {
3681 ALOGE("%s: max entry reached max[%d] current index[%d] .. rejecting", __func__,
3682 MAX_VOLUME_CAL_STEPS, num_gain_tbl_entry);
3683 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
3684 return false;
3685 }
3686
3687 if (num_gain_tbl_entry > 0 && tbl_mapping[num_gain_tbl_entry - 1].amp >= tbl_entry->amp) {
3688 ALOGE("%s: value not in ascending order .. rejecting custom mapping", __func__);
3689 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
3690 return false;
3691 }
3692
3693 tbl_mapping[num_gain_tbl_entry] = *tbl_entry;
3694 ++num_gain_tbl_entry;
3695
3696 return true;
3697}
3698
3699int platform_get_gain_level_mapping(struct amp_db_and_gain_table *mapping_tbl,
3700 int table_size) {
3701 int itt = 0;
3702 ALOGV("platform_get_gain_level_mapping called ");
3703
3704 if (num_gain_tbl_entry <= 0 || num_gain_tbl_entry > MAX_VOLUME_CAL_STEPS) {
3705 ALOGD("%s: empty or currupted gain_mapping_table", __func__);
3706 return 0;
3707 }
3708
3709 for (; itt < num_gain_tbl_entry && itt <= table_size; itt++) {
3710 mapping_tbl[itt] = tbl_mapping[itt];
3711 ALOGV("%s: added amp[%f] db[%f] level[%d]", __func__,
3712 mapping_tbl[itt].amp, mapping_tbl[itt].db, mapping_tbl[itt].level);
3713 }
3714
3715 return num_gain_tbl_entry;
3716}
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07003717
3718int platform_snd_card_update(void *platform, card_status_t status)
3719{
3720 struct platform_data *my_data = (struct platform_data *)platform;
3721 struct audio_device *adev = my_data->adev;
3722
3723 if (status == CARD_STATUS_ONLINE) {
3724 if (my_data->acdb_send_custom_top)
3725 my_data->acdb_send_custom_top();
3726 }
3727 return 0;
3728}
David Linee3fe402017-03-13 10:00:42 -07003729
3730/*
3731 * configures afe with bit width and Sample Rate
3732 */
Haynes Mathew George65f6b432018-02-27 17:44:55 -08003733int platform_set_backend_cfg(const struct audio_device* adev,
3734 snd_device_t snd_device,
3735 const struct audio_backend_cfg *backend_cfg)
David Linee3fe402017-03-13 10:00:42 -07003736{
3737
3738 int ret = 0;
3739 const int backend_idx = platform_get_backend_index(snd_device);
3740 struct platform_data *my_data = (struct platform_data *)adev->platform;
3741 const unsigned int bit_width = backend_cfg->bit_width;
3742 const unsigned int sample_rate = backend_cfg->sample_rate;
3743 const unsigned int channels = backend_cfg->channels;
3744 const audio_format_t format = backend_cfg->format;
3745 const bool passthrough_enabled = backend_cfg->passthrough_enabled;
3746
3747
3748 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
3749 ", backend_idx %d device (%s)", __func__, bit_width,
3750 sample_rate, channels, backend_idx,
3751 platform_get_snd_device_name(snd_device));
3752
3753 if ((my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl) &&
3754 (bit_width != my_data->current_backend_cfg[backend_idx].bit_width)) {
3755
3756 struct mixer_ctl *ctl = NULL;
3757 ctl = mixer_get_ctl_by_name(adev->mixer,
3758 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
3759 if (!ctl) {
3760 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3761 __func__,
3762 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
3763 return -EINVAL;
3764 }
3765
3766 if (bit_width == 24) {
3767 if (format == AUDIO_FORMAT_PCM_24_BIT_PACKED)
3768 ret = mixer_ctl_set_enum_by_string(ctl, "S24_3LE");
3769 else
3770 ret = mixer_ctl_set_enum_by_string(ctl, "S24_LE");
3771 } else if (bit_width == 32) {
3772 ret = mixer_ctl_set_enum_by_string(ctl, "S32_LE");
3773 } else {
3774 ret = mixer_ctl_set_enum_by_string(ctl, "S16_LE");
3775 }
3776 if ( ret < 0) {
3777 ALOGE("%s:becf: afe: fail for %s mixer set to %d bit for %x format", __func__,
3778 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
3779 } else {
3780 my_data->current_backend_cfg[backend_idx].bit_width = bit_width;
3781 ALOGD("%s:becf: afe: %s mixer set to %d bit for %x format", __func__,
3782 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
3783 }
3784 /* set the ret as 0 and not pass back to upper layer */
3785 ret = 0;
3786 }
3787
3788 if (passthrough_enabled || ((my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl) &&
3789 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate))) {
3790 char *rate_str = NULL;
3791 struct mixer_ctl *ctl = NULL;
3792
3793 switch (sample_rate) {
3794 case 32000:
3795 if (passthrough_enabled) {
3796 rate_str = "KHZ_32";
3797 break;
3798 }
3799 case 8000:
3800 case 11025:
3801 case 16000:
3802 case 22050:
3803 case 48000:
3804 rate_str = "KHZ_48";
3805 break;
3806 case 44100:
3807 rate_str = "KHZ_44P1";
3808 break;
3809 case 64000:
3810 case 96000:
3811 rate_str = "KHZ_96";
3812 break;
3813 case 88200:
3814 rate_str = "KHZ_88P2";
3815 break;
3816 case 176400:
3817 rate_str = "KHZ_176P4";
3818 break;
3819 case 192000:
3820 rate_str = "KHZ_192";
3821 break;
3822 case 352800:
3823 rate_str = "KHZ_352P8";
3824 break;
3825 case 384000:
3826 rate_str = "KHZ_384";
3827 break;
3828 case 144000:
3829 if (passthrough_enabled) {
3830 rate_str = "KHZ_144";
3831 break;
3832 }
3833 default:
3834 rate_str = "KHZ_48";
3835 break;
3836 }
3837
3838 ctl = mixer_get_ctl_by_name(adev->mixer,
3839 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
3840 if(!ctl) {
3841 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3842 __func__,
3843 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
3844 return -EINVAL;
3845 }
3846
3847 ALOGD("%s:becf: afe: %s set to %s", __func__,
3848 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl, rate_str);
3849 mixer_ctl_set_enum_by_string(ctl, rate_str);
3850 my_data->current_backend_cfg[backend_idx].sample_rate = sample_rate;
3851 }
3852 if ((my_data->current_backend_cfg[backend_idx].channels_mixer_ctl) &&
3853 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
3854 struct mixer_ctl *ctl = NULL;
3855 char *channel_cnt_str = NULL;
3856
3857 switch (channels) {
3858 case 8:
3859 channel_cnt_str = "Eight"; break;
3860 case 7:
3861 channel_cnt_str = "Seven"; break;
3862 case 6:
3863 channel_cnt_str = "Six"; break;
3864 case 5:
3865 channel_cnt_str = "Five"; break;
3866 case 4:
3867 channel_cnt_str = "Four"; break;
3868 case 3:
3869 channel_cnt_str = "Three"; break;
3870 case 1:
3871 channel_cnt_str = "One"; break;
3872 case 2:
3873 default:
3874 channel_cnt_str = "Two"; break;
3875 }
3876
3877 ctl = mixer_get_ctl_by_name(adev->mixer,
3878 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
3879 if (!ctl) {
3880 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3881 __func__,
3882 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
3883 return -EINVAL;
3884 }
3885 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
3886 my_data->current_backend_cfg[backend_idx].channels = channels;
3887
3888 // skip EDID configuration for HDMI backend
3889
3890 ALOGD("%s:becf: afe: %s set to %s", __func__,
3891 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl,
3892 channel_cnt_str);
3893 }
3894
3895 // skip set ext_display format mixer control
3896 return ret;
3897}
3898
3899static int platform_get_snd_device_bit_width(snd_device_t snd_device)
3900{
3901 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
3902 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
3903 return CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3904 }
3905
3906 return backend_bit_width_table[snd_device];
3907}
3908
3909/*
3910 * return backend_idx on which voice call is active
3911 */
3912static int platform_get_voice_call_backend(struct audio_device* adev)
3913{
3914 struct audio_usecase *uc = NULL;
3915 struct listnode *node;
3916 snd_device_t out_snd_device = SND_DEVICE_NONE;
3917
3918 int backend_idx = -1;
3919
3920 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
3921 list_for_each(node, &adev->usecase_list) {
3922 uc = node_to_item(node, struct audio_usecase, list);
3923 if (uc && uc->type == VOICE_CALL && uc->stream.out) {
3924 out_snd_device = platform_get_output_snd_device(adev->platform,
3925 uc->stream.out->devices);
3926 backend_idx = platform_get_backend_index(out_snd_device);
3927 break;
3928 }
3929 }
3930 }
3931 return backend_idx;
3932}
3933
3934/*
3935 * goes through all the current usecases and picks the highest
3936 * bitwidth & samplerate
3937 */
3938static bool platform_check_capture_backend_cfg(struct audio_device* adev,
3939 int backend_idx,
3940 struct audio_backend_cfg *backend_cfg)
3941{
3942 bool backend_change = false;
3943 unsigned int bit_width;
3944 unsigned int sample_rate;
3945 unsigned int channels;
3946 struct platform_data *my_data = (struct platform_data *)adev->platform;
3947
3948 bit_width = backend_cfg->bit_width;
3949 sample_rate = backend_cfg->sample_rate;
3950 channels = backend_cfg->channels;
3951
3952 ALOGV("%s:txbecf: afe: Codec selected backend: %d current bit width: %d and "
3953 "sample rate: %d, channels %d",__func__,backend_idx, bit_width,
3954 sample_rate, channels);
3955
3956 // For voice calls use default configuration i.e. 16b/48K, only applicable to
3957 // default backend
3958 // force routing is not required here, caller will do it anyway
3959 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
3960 ALOGW("%s:txbecf: afe: Use default bw and sr for voice/voip calls and "
3961 "for unprocessed/camera source", __func__);
3962 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3963 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3964 }
3965
3966 if (backend_idx == USB_AUDIO_TX_BACKEND) {
3967 audio_extn_usb_is_config_supported(&bit_width, &sample_rate, &channels, false);
3968 ALOGV("%s:txbecf: afe: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
3969 __func__, bit_width, sample_rate, channels);
3970 }
3971
3972 ALOGV("%s:txbecf: afe: Codec selected backend: %d updated bit width: %d and "
3973 "sample rate: %d", __func__, backend_idx, bit_width, sample_rate);
3974
3975 // Force routing if the expected bitwdith or samplerate
3976 // is not same as current backend comfiguration
3977 if ((bit_width != my_data->current_backend_cfg[backend_idx].bit_width) ||
3978 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate) ||
3979 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
3980 backend_cfg->bit_width = bit_width;
3981 backend_cfg->sample_rate= sample_rate;
3982 backend_cfg->channels = channels;
3983 backend_change = true;
3984 ALOGI("%s:txbecf: afe: Codec backend needs to be updated. new bit width: %d "
3985 "new sample rate: %d new channel: %d",
3986 __func__, backend_cfg->bit_width,
3987 backend_cfg->sample_rate, backend_cfg->channels);
3988 }
3989
3990 return backend_change;
3991}
3992
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003993static void pick_playback_cfg_for_uc(struct audio_device *adev,
3994 struct audio_usecase *usecase,
3995 snd_device_t snd_device,
3996 unsigned int *bit_width,
3997 unsigned int *sample_rate,
3998 unsigned int *channels)
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003999{
4000 int i =0;
4001 struct listnode *node;
4002 list_for_each(node, &adev->usecase_list) {
4003 struct audio_usecase *uc;
4004 uc = node_to_item(node, struct audio_usecase, list);
4005 struct stream_out *out = (struct stream_out*) uc->stream.out;
4006 if (uc->type == PCM_PLAYBACK && out && usecase != uc) {
4007 unsigned int out_channels = audio_channel_count_from_out_mask(out->channel_mask);
4008 ALOGV("%s:napb: (%d) - (%s)id (%d) sr %d bw "
4009 "(%d) ch (%d) device %s", __func__, i++, use_case_table[uc->id],
4010 uc->id, out->sample_rate,
4011 pcm_format_to_bits(out->config.format), out_channels,
4012 platform_get_snd_device_name(uc->out_snd_device));
4013
4014 if (platform_check_backends_match(snd_device, uc->out_snd_device)) {
4015 if (*bit_width < pcm_format_to_bits(out->config.format))
4016 *bit_width = pcm_format_to_bits(out->config.format);
4017 if (*sample_rate < out->sample_rate)
4018 *sample_rate = out->sample_rate;
4019 if (out->sample_rate < OUTPUT_SAMPLING_RATE_44100)
4020 *sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4021 if (*channels < out_channels)
4022 *channels = out_channels;
4023 }
4024 }
4025 }
4026 return;
4027}
4028
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004029static void headset_is_config_supported(unsigned int *bit_width,
4030 unsigned int *sample_rate,
4031 unsigned int *channels) {
4032 switch (*bit_width) {
4033 case 16:
4034 case 24:
4035 break;
4036 default:
4037 *bit_width = 16;
4038 break;
4039 }
4040
4041 if (*sample_rate > 192000) {
4042 *sample_rate = 192000;
4043 }
4044
4045 if (*channels > 2) {
4046 *channels = 2;
4047 }
4048}
4049
David Linee3fe402017-03-13 10:00:42 -07004050static bool platform_check_playback_backend_cfg(struct audio_device* adev,
4051 struct audio_usecase* usecase,
4052 snd_device_t snd_device,
4053 struct audio_backend_cfg *backend_cfg)
4054{
4055 bool backend_change = false;
David Linee3fe402017-03-13 10:00:42 -07004056 unsigned int bit_width;
4057 unsigned int sample_rate;
4058 unsigned int channels;
David Linee3fe402017-03-13 10:00:42 -07004059 int backend_idx = DEFAULT_CODEC_BACKEND;
Haynes Mathew George65f6b432018-02-27 17:44:55 -08004060 unsigned long service_interval = 0; // 0 is invalid
David Linee3fe402017-03-13 10:00:42 -07004061 struct platform_data *my_data = (struct platform_data *)adev->platform;
David Linee3fe402017-03-13 10:00:42 -07004062
4063 if (snd_device == SND_DEVICE_OUT_BT_SCO ||
4064 snd_device == SND_DEVICE_OUT_BT_SCO_WB) {
4065 backend_change = false;
4066 return backend_change;
4067 }
4068
4069 backend_idx = platform_get_backend_index(snd_device);
4070 bit_width = backend_cfg->bit_width;
4071 sample_rate = backend_cfg->sample_rate;
4072 channels = backend_cfg->channels;
4073
4074 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
4075 ", backend_idx %d usecase = %d device (%s)", __func__, bit_width,
4076 sample_rate, channels, backend_idx, usecase->id,
4077 platform_get_snd_device_name(snd_device));
4078
4079 if (backend_idx == platform_get_voice_call_backend(adev)) {
4080 ALOGW("%s:becf: afe:Use default bw and sr for voice/voip calls ",
4081 __func__);
4082 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
4083 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4084 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
4085 } else {
4086 /*
4087 * The backend should be configured at highest bit width and/or
4088 * sample rate amongst all playback usecases.
4089 * If the selected sample rate and/or bit width differ with
4090 * current backend sample rate and/or bit width, then, we set the
4091 * backend re-configuration flag.
4092 *
4093 * Exception: 16 bit playbacks is allowed through 16 bit/48/44.1 khz backend only
4094 */
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004095 pick_playback_cfg_for_uc(adev, usecase, snd_device,
4096 &bit_width,
4097 &sample_rate,
4098 &channels);
David Linee3fe402017-03-13 10:00:42 -07004099 }
4100
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004101 switch (backend_idx) {
4102 case USB_AUDIO_RX_BACKEND:
4103 audio_extn_usb_is_config_supported(&bit_width,
4104 &sample_rate, &channels, true);
Haynes Mathew George65f6b432018-02-27 17:44:55 -08004105 if (platform_get_usb_service_interval(adev->platform, true,
4106 &service_interval) == 0) {
4107 /* overwrite with best altset for this service interval */
4108 int ret =
4109 audio_extn_usb_altset_for_service_interval(true /*playback*/,
4110 service_interval,
4111 &bit_width,
4112 &sample_rate,
4113 &channels);
4114 if (ret < 0) {
4115 ALOGE("Failed to find altset for service interval %lu, skip reconfig",
4116 service_interval);
4117 return false;
4118 }
4119 }
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004120 ALOGV("%s: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
4121 __func__, bit_width, sample_rate, channels);
4122 break;
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004123 case HEADPHONE_BACKEND:
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004124 headset_is_config_supported(&bit_width, &sample_rate, &channels);
4125 break;
4126 case DEFAULT_CODEC_BACKEND:
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004127 default:
4128 bit_width = platform_get_snd_device_bit_width(snd_device);
4129 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4130 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
4131 break;
David Linee3fe402017-03-13 10:00:42 -07004132 }
4133
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004134 ALOGV("%s:becf: afe: Codec selected backend: %d updated bit width: %d and"
4135 "sample rate: %d",
David Linee3fe402017-03-13 10:00:42 -07004136 __func__, backend_idx , bit_width, sample_rate);
4137
4138 // Force routing if the expected bitwdith or samplerate
4139 // is not same as current backend comfiguration
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004140 if (bit_width != my_data->current_backend_cfg[backend_idx].bit_width ||
4141 sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate ||
4142 channels != my_data->current_backend_cfg[backend_idx].channels) {
David Linee3fe402017-03-13 10:00:42 -07004143 backend_cfg->bit_width = bit_width;
4144 backend_cfg->sample_rate = sample_rate;
4145 backend_cfg->channels = channels;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004146 backend_cfg->passthrough_enabled = false;
David Linee3fe402017-03-13 10:00:42 -07004147 backend_change = true;
4148 ALOGV("%s:becf: afe: Codec backend needs to be updated. new bit width: %d"
4149 "new sample rate: %d new channels: %d",
4150 __func__, backend_cfg->bit_width, backend_cfg->sample_rate, backend_cfg->channels);
4151 }
4152
4153 return backend_change;
4154}
4155
4156bool platform_check_and_set_playback_backend_cfg(struct audio_device* adev,
4157 struct audio_usecase *usecase, snd_device_t snd_device)
4158{
4159 int backend_idx = DEFAULT_CODEC_BACKEND;
4160 int new_snd_devices[SND_DEVICE_OUT_END];
4161 int i, num_devices = 1;
4162 bool ret = false;
4163 struct platform_data *my_data = (struct platform_data *)adev->platform;
4164 struct audio_backend_cfg backend_cfg;
4165
4166 backend_idx = platform_get_backend_index(snd_device);
4167
4168 backend_cfg.bit_width = pcm_format_to_bits(usecase->stream.out->config.format);
4169 backend_cfg.sample_rate = usecase->stream.out->sample_rate;
4170 backend_cfg.format = usecase->stream.out->format;
4171 backend_cfg.channels = audio_channel_count_from_out_mask(usecase->stream.out->channel_mask);
4172 /*this is populated by check_codec_backend_cfg hence set default value to false*/
4173 backend_cfg.passthrough_enabled = false;
4174
4175 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
4176 ", backend_idx %d usecase = %d device (%s)", __func__, backend_cfg.bit_width,
4177 backend_cfg.sample_rate, backend_cfg.channels, backend_idx, usecase->id,
4178 platform_get_snd_device_name(snd_device));
4179
4180 if (platform_can_split_snd_device(snd_device, &num_devices, new_snd_devices) < 0)
4181 new_snd_devices[0] = snd_device;
4182
4183 for (i = 0; i < num_devices; i++) {
4184 ALOGV("%s: new_snd_devices[%d] is %d", __func__, i, new_snd_devices[i]);
4185 if ((platform_check_playback_backend_cfg(adev, usecase, new_snd_devices[i],
4186 &backend_cfg))) {
4187 platform_set_backend_cfg(adev, new_snd_devices[i],
4188 &backend_cfg);
4189 ret = true;
4190 }
4191 }
4192 return ret;
4193}
4194
4195bool platform_check_and_set_capture_backend_cfg(struct audio_device* adev,
4196 struct audio_usecase *usecase, snd_device_t snd_device)
4197{
4198 int backend_idx = platform_get_backend_index(snd_device);
4199 int ret = 0;
4200 struct audio_backend_cfg backend_cfg;
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004201 memset(&backend_cfg, 0, sizeof(struct audio_backend_cfg));
David Linee3fe402017-03-13 10:00:42 -07004202
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004203 if (usecase->type == PCM_CAPTURE) {
4204 backend_cfg.format = usecase->stream.in->format;
David Linee3fe402017-03-13 10:00:42 -07004205 backend_cfg.channels = audio_channel_count_from_in_mask(usecase->stream.in->channel_mask);
4206 } else {
4207 backend_cfg.bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
4208 backend_cfg.sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4209 backend_cfg.format = AUDIO_FORMAT_PCM_16_BIT;
4210 backend_cfg.channels = 1;
4211 }
4212
4213 ALOGV("%s:txbecf: afe: bitwidth %d, samplerate %d, channel %d"
4214 ", backend_idx %d usecase = %d device (%s)", __func__,
4215 backend_cfg.bit_width,
4216 backend_cfg.sample_rate,
4217 backend_cfg.channels,
4218 backend_idx, usecase->id,
4219 platform_get_snd_device_name(snd_device));
4220
4221 if (platform_check_capture_backend_cfg(adev, backend_idx, &backend_cfg)) {
4222 ret = platform_set_backend_cfg(adev, snd_device,
4223 &backend_cfg);
4224 if(!ret)
4225 return true;
4226 }
4227
4228 return false;
4229}
4230
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004231static int max_be_dai_names = 0;
4232static const struct be_dai_name_struct *be_dai_name_table;
4233
4234/*
4235 * Retrieves the be_dai_name_table from kernel to enable a mapping
4236 * between sound device hw interfaces and backend IDs. This allows HAL to
4237 * specify the backend a specific calibration is needed for.
4238 */
4239static int init_be_dai_name_table(struct audio_device *adev)
4240{
4241 const char *mixer_ctl_name = "Backend DAI Name Table";
4242 struct mixer_ctl *ctl;
4243 int i, j, ret, size;
4244 bool valid_hw_interface;
4245
4246 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
4247 if (!ctl) {
4248 ALOGE("%s: Could not get ctl for mixer name %s\n",
4249 __func__, mixer_ctl_name);
4250 ret = -EINVAL;
4251 goto done;
4252 }
4253
4254 mixer_ctl_update(ctl);
4255
4256 size = mixer_ctl_get_num_values(ctl);
4257 if (size <= 0){
4258 ALOGE("%s: Failed to get %s size %d\n",
4259 __func__, mixer_ctl_name, size);
4260 ret = -EFAULT;
4261 goto done;
4262 }
4263
vivek mehtaa68fea62017-06-08 19:04:02 -07004264 be_dai_name_table =
4265 (const struct be_dai_name_struct *)calloc(1, size);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004266 if (be_dai_name_table == NULL) {
4267 ALOGE("%s: Failed to allocate memory for %s\n",
4268 __func__, mixer_ctl_name);
4269 ret = -ENOMEM;
4270 goto freeMem;
4271 }
4272
4273 ret = mixer_ctl_get_array(ctl, (void *)be_dai_name_table, size);
4274 if (ret) {
4275 ALOGE("%s: Failed to get %s, ret %d\n",
4276 __func__, mixer_ctl_name, ret);
4277 ret = -EFAULT;
4278 goto freeMem;
4279 }
4280
4281 if (be_dai_name_table != NULL) {
4282 max_be_dai_names = size / sizeof(struct be_dai_name_struct);
4283 ALOGV("%s: Successfully got %s, number of be dais is %d\n",
4284 __func__, mixer_ctl_name, max_be_dai_names);
4285 ret = 0;
4286 } else {
4287 ALOGE("%s: Failed to get %s\n", __func__, mixer_ctl_name);
4288 ret = -EFAULT;
4289 goto freeMem;
4290 }
4291
4292 /*
4293 * Validate all sound devices have a valid backend set to catch
4294 * errors for uncommon sound devices
4295 */
4296 for (i = 0; i < SND_DEVICE_MAX; i++) {
4297 valid_hw_interface = false;
4298
4299 if (hw_interface_table[i] == NULL) {
4300 ALOGW("%s: sound device %s has no hw interface set\n",
4301 __func__, platform_get_snd_device_name(i));
4302 continue;
4303 }
4304
4305 for (j = 0; j < max_be_dai_names; j++) {
4306 if (strcmp(hw_interface_table[i], be_dai_name_table[j].be_name)
4307 == 0) {
4308 valid_hw_interface = true;
4309 break;
4310 }
4311 }
4312 if (!valid_hw_interface)
4313 ALOGD("%s: sound device %s does not have a valid hw interface set "
4314 "(disregard for combo devices) %s\n",
4315 __func__, platform_get_snd_device_name(i),
4316 hw_interface_table[i]);
4317 }
4318
4319 goto done;
4320
4321freeMem:
4322 if (be_dai_name_table) {
4323 free((void *)be_dai_name_table);
4324 be_dai_name_table = NULL;
4325 }
4326
4327done:
4328 return ret;
4329}
4330
4331int platform_get_snd_device_backend_index(snd_device_t device)
4332{
4333 int i, be_dai_id;
4334 const char * hw_interface_name = NULL;
4335
4336 ALOGV("%s: enter with device %d\n", __func__, device);
4337
vivek mehtaa68fea62017-06-08 19:04:02 -07004338 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004339 ALOGE("%s: Invalid snd_device = %d",
4340 __func__, device);
4341 be_dai_id = -EINVAL;
4342 goto done;
4343 }
4344
4345 /* Get string value of necessary backend for device */
4346 hw_interface_name = hw_interface_table[device];
4347 if (hw_interface_name == NULL) {
4348 ALOGE("%s: no hw_interface set for device %d\n", __func__, device);
4349 be_dai_id = -EINVAL;
4350 goto done;
4351 }
4352
4353 /* Check if be dai name table was retrieved successfully */
4354 if (be_dai_name_table == NULL) {
4355 ALOGE("%s: BE DAI Name Table is not present\n", __func__);
4356 be_dai_id = -EFAULT;
4357 goto done;
4358 }
4359
4360 /* Get backend ID for device specified */
4361 for (i = 0; i < max_be_dai_names; i++) {
4362 if (strcmp(hw_interface_name, be_dai_name_table[i].be_name) == 0) {
4363 be_dai_id = be_dai_name_table[i].be_id;
4364 goto done;
4365 }
4366 }
4367 ALOGE("%s: no interface matching name %s\n", __func__, hw_interface_name);
4368 be_dai_id = -EINVAL;
4369 goto done;
4370
4371done:
4372 return be_dai_id;
4373}
4374
4375void platform_check_and_update_copp_sample_rate(void* platform, snd_device_t snd_device,
4376 unsigned int stream_sr, int* sample_rate)
4377{
4378 struct platform_data* my_data = (struct platform_data *)platform;
4379 int backend_idx = platform_get_backend_index(snd_device);
4380 int device_sr = my_data->current_backend_cfg[backend_idx].sample_rate;
4381 /*
4382 *Check if device SR is multiple of 8K or 11.025 Khz
4383 *check if the stream SR is multiple of same base, if yes
4384 *then have copp SR equal to stream SR, this ensures that
4385 *post processing happens at stream SR, else have
4386 *copp SR equal to device SR.
4387 */
4388 if (!(((sample_rate_multiple(device_sr, SAMPLE_RATE_8000)) &&
4389 (sample_rate_multiple(stream_sr, SAMPLE_RATE_8000))) ||
4390 ((sample_rate_multiple(device_sr, SAMPLE_RATE_11025)) &&
4391 (sample_rate_multiple(stream_sr, SAMPLE_RATE_11025))))) {
4392 *sample_rate = device_sr;
4393 } else
4394 *sample_rate = stream_sr;
4395
4396 ALOGI("sn_device %d device sr %d stream sr %d copp sr %d", snd_device, device_sr, stream_sr
4397 , *sample_rate);
4398
4399}
4400
4401// called from info parser
vivek mehtaa68fea62017-06-08 19:04:02 -07004402void platform_add_app_type(const char *uc_type,
4403 const char *mode,
4404 int bw,
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004405 int app_type, int max_rate) {
4406 struct app_type_entry *ap =
4407 (struct app_type_entry *)calloc(1, sizeof(struct app_type_entry));
4408
4409 if (!ap) {
4410 ALOGE("%s failed to allocate mem for app type", __func__);
4411 return;
4412 }
4413
4414 ap->uc_type = -1;
4415 for (int i=0; i<USECASE_TYPE_MAX; i++) {
4416 if (!strcmp(uc_type, usecase_type_index[i].name)) {
4417 ap->uc_type = usecase_type_index[i].index;
4418 break;
4419 }
4420 }
4421
4422 if (ap->uc_type == -1) {
4423 free(ap);
4424 return;
4425 }
4426
vivek mehtaa68fea62017-06-08 19:04:02 -07004427 ALOGI("%s uc %s mode %s bw %d app_type %d max_rate %d",
4428 __func__, uc_type, mode, bw, app_type, max_rate);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004429 ap->bit_width = bw;
4430 ap->app_type = app_type;
4431 ap->max_rate = max_rate;
vivek mehtaa68fea62017-06-08 19:04:02 -07004432 ap->mode = strdup(mode);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004433 list_add_tail(&app_type_entry_list, &ap->node);
4434}
4435
4436
4437int platform_get_default_app_type_v2(void *platform __unused,
4438 usecase_type_t type,
4439 int *app_type )
4440{
4441 if (type == PCM_PLAYBACK)
4442 *app_type = DEFAULT_APP_TYPE_RX_PATH;
4443 else
4444 *app_type = DEFAULT_APP_TYPE_TX_PATH;
4445 return 0;
4446}
4447
vivek mehtaa68fea62017-06-08 19:04:02 -07004448int platform_get_app_type_v2(void *platform,
4449 usecase_type_t uc_type,
4450 const char *mode,
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004451 int bw, int sr __unused,
4452 int *app_type)
4453{
4454 struct listnode *node;
4455 struct app_type_entry *entry;
4456 *app_type = -1;
vivek mehtaa68fea62017-06-08 19:04:02 -07004457
4458 ALOGV("%s find match for uc %d mode %s bw %d rate %d",
4459 __func__, uc_type, mode, bw, sr);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004460 list_for_each(node, &app_type_entry_list) {
4461 entry = node_to_item(node, struct app_type_entry, node);
vivek mehtaa68fea62017-06-08 19:04:02 -07004462 ALOGV("%s uc %d mode %s bw %d app_type %d max_rate %d",
4463 __func__, entry->uc_type, entry->mode, entry->bit_width,
4464 entry->app_type, entry->max_rate);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004465 if (entry->bit_width == bw &&
vivek mehtaa68fea62017-06-08 19:04:02 -07004466 entry->uc_type == uc_type &&
4467 sr <= entry->max_rate &&
4468 entry->mode && !strcmp(mode, entry->mode)) {
4469 ALOGV("%s found match %d", __func__, entry->app_type);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004470 *app_type = entry->app_type;
4471 break;
4472 }
4473 }
4474
4475 if (*app_type == -1) {
vivek mehtaa68fea62017-06-08 19:04:02 -07004476 ALOGV("%s no match found, return default", __func__);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004477 return platform_get_default_app_type_v2(platform, uc_type, app_type);
4478 }
4479 return 0;
4480}
vivek mehta90933872017-06-15 18:04:39 -07004481
4482int platform_set_sidetone(struct audio_device *adev,
4483 snd_device_t out_snd_device,
4484 bool enable, char *str)
4485{
4486 int ret;
4487 if (out_snd_device == SND_DEVICE_OUT_USB_HEADSET ||
4488 out_snd_device == SND_DEVICE_OUT_VOICE_USB_HEADSET) {
4489 ret = audio_extn_usb_enable_sidetone(out_snd_device, enable);
4490 if (ret)
4491 ALOGI("%s: usb device %d does not support device sidetone\n",
4492 __func__, out_snd_device);
4493 } else {
4494 ALOGV("%s: sidetone out device(%d) mixer cmd = %s\n",
4495 __func__, out_snd_device, str);
4496 if (enable)
4497 audio_route_apply_and_update_path(adev->audio_route, str);
4498 else
4499 audio_route_reset_and_update_path(adev->audio_route, str);
4500 }
4501 return 0;
4502}
Haynes Mathew George96483a22017-03-28 14:52:47 -07004503
4504int platform_get_mmap_data_fd(void *platform __unused, int fe_dev __unused, int dir __unused,
4505 int *fd __unused, uint32_t *size __unused)
4506{
Alexey Polyudove920d4b2017-09-15 17:09:07 -07004507#if defined (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845)
Haynes Mathew George96483a22017-03-28 14:52:47 -07004508 struct platform_data *my_data = (struct platform_data *)platform;
4509 struct audio_device *adev = my_data->adev;
4510 int hw_fd = -1;
4511 char dev_name[128];
4512 struct snd_pcm_mmap_fd mmap_fd;
4513 memset(&mmap_fd, 0, sizeof(mmap_fd));
4514 mmap_fd.dir = dir;
4515 snprintf(dev_name, sizeof(dev_name), "/dev/snd/hwC%uD%u",
4516 adev->snd_card, HWDEP_FE_BASE+fe_dev);
4517 hw_fd = open(dev_name, O_RDONLY);
4518 if (hw_fd < 0) {
4519 ALOGE("fe hw dep node open %d/%d failed", adev->snd_card, fe_dev);
4520 return -1;
4521 }
4522 if (ioctl(hw_fd, SNDRV_PCM_IOCTL_MMAP_DATA_FD, &mmap_fd) < 0) {
4523 ALOGE("fe hw dep node ioctl failed");
4524 close(hw_fd);
4525 return -1;
4526 }
4527 *fd = mmap_fd.fd;
4528 *size = mmap_fd.size;
4529 close(hw_fd); // mmap_fd should still be valid
4530 return 0;
4531#else
4532 return -1;
4533#endif
4534}
Mikhail Naganov4ee6e3e2018-03-21 16:28:35 +00004535
4536bool platform_sound_trigger_usecase_needs_event(audio_usecase_t uc_id)
4537{
4538 bool needs_event = false;
4539
4540 switch (uc_id) {
4541 /* concurrent capture usecases which needs event */
4542 case USECASE_AUDIO_RECORD:
4543 case USECASE_AUDIO_RECORD_LOW_LATENCY:
4544 case USECASE_AUDIO_RECORD_MMAP:
4545 case USECASE_AUDIO_RECORD_HIFI:
4546 case USECASE_AUDIO_RECORD_VOIP:
4547 case USECASE_VOICEMMODE1_CALL:
4548 case USECASE_VOICEMMODE2_CALL:
4549 /* concurrent playback usecases that needs event */
4550 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
4551 case USECASE_AUDIO_PLAYBACK_OFFLOAD:
4552 needs_event = true;
4553 break;
4554 default:
4555 ALOGV("%s:usecase_id[%d] no need to raise event.", __func__, uc_id);
4556 }
4557 return needs_event;
4558}
4559
4560bool platform_snd_device_has_speaker(snd_device_t dev) {
4561 int num_devs = 2;
4562 snd_device_t split_devs[2] = {SND_DEVICE_NONE, SND_DEVICE_NONE};
4563 if (platform_can_split_snd_device(dev, &num_devs, split_devs) == 0) {
4564 return platform_snd_device_has_speaker(split_devs[0]) ||
4565 platform_snd_device_has_speaker(split_devs[1]);
4566 }
4567
4568 switch (dev) {
4569 case SND_DEVICE_OUT_SPEAKER:
4570 case SND_DEVICE_OUT_SPEAKER_SAFE:
4571 case SND_DEVICE_OUT_SPEAKER_REVERSE:
4572 case SND_DEVICE_OUT_SPEAKER_PROTECTED:
4573 case SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED:
4574 case SND_DEVICE_OUT_VOICE_SPEAKER_HFP:
4575 return true;
4576 default:
4577 break;
4578 }
4579 return false;
4580}
jiabin8962a4d2018-03-19 18:21:24 -07004581
4582bool platform_set_microphone_characteristic(void *platform,
4583 struct audio_microphone_characteristic_t mic) {
4584 struct platform_data *my_data = (struct platform_data *)platform;
4585 if (my_data->declared_mic_count >= AUDIO_MICROPHONE_MAX_COUNT) {
4586 ALOGE("mic number is more than maximum number");
4587 return false;
4588 }
4589 for (size_t ch = 0; ch < AUDIO_CHANNEL_COUNT_MAX; ch++) {
4590 mic.channel_mapping[ch] = AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED;
4591 }
4592 my_data->microphones[my_data->declared_mic_count++] = mic;
4593 return true;
4594}
4595
4596int platform_get_microphones(void *platform,
4597 struct audio_microphone_characteristic_t *mic_array,
4598 size_t *mic_count) {
4599 struct platform_data *my_data = (struct platform_data *)platform;
4600 if (mic_count == NULL) {
4601 return -EINVAL;
4602 }
4603 if (mic_array == NULL) {
4604 return -EINVAL;
4605 }
4606
4607 if (*mic_count == 0) {
4608 *mic_count = my_data->declared_mic_count;
4609 return 0;
4610 }
4611
4612 size_t max_mic_count = *mic_count;
4613 size_t actual_mic_count = 0;
4614 for (size_t i = 0; i < max_mic_count && i < my_data->declared_mic_count; i++) {
4615 mic_array[i] = my_data->microphones[i];
4616 actual_mic_count++;
4617 }
4618 *mic_count = actual_mic_count;
4619 return 0;
4620}
4621
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004622bool platform_set_microphone_map(void *platform, snd_device_t in_snd_device,
4623 const struct mic_info *info) {
4624 struct platform_data *my_data = (struct platform_data *)platform;
4625 if (in_snd_device < SND_DEVICE_IN_BEGIN || in_snd_device >= SND_DEVICE_IN_END) {
4626 ALOGE("%s: Sound device not valid", __func__);
4627 return false;
4628 }
4629 size_t m_count = my_data->mic_map[in_snd_device].mic_count++;
4630 if (m_count >= AUDIO_MICROPHONE_MAX_COUNT) {
4631 ALOGE("%s: Microphone count is greater than max allowed value", __func__);
4632 my_data->mic_map[in_snd_device].mic_count--;
4633 return false;
4634 }
4635 my_data->mic_map[in_snd_device].microphones[m_count] = *info;
4636 return true;
4637}
4638
4639int platform_get_active_microphones(void *platform, unsigned int channels,
4640 audio_usecase_t uc_id,
jiabin8962a4d2018-03-19 18:21:24 -07004641 struct audio_microphone_characteristic_t *mic_array,
4642 size_t *mic_count) {
4643 struct platform_data *my_data = (struct platform_data *)platform;
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004644 struct audio_usecase *usecase = get_usecase_from_list(my_data->adev, uc_id);
4645 if (mic_count == NULL || mic_array == NULL || usecase == NULL) {
jiabin8962a4d2018-03-19 18:21:24 -07004646 return -EINVAL;
4647 }
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004648 size_t max_mic_count = my_data->declared_mic_count;
jiabin8962a4d2018-03-19 18:21:24 -07004649 size_t actual_mic_count = 0;
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004650
4651 snd_device_t active_input_snd_device =
4652 platform_get_input_snd_device(platform, usecase->stream.in->device);
4653 if (active_input_snd_device == SND_DEVICE_NONE) {
4654 ALOGI("%s: No active microphones found", __func__);
4655 goto end;
4656 }
4657
4658 size_t active_mic_count = my_data->mic_map[active_input_snd_device].mic_count;
4659 struct mic_info *m_info = my_data->mic_map[active_input_snd_device].microphones;
4660
4661 for (size_t i = 0; i < active_mic_count; i++) {
4662 unsigned int channels_for_active_mic = channels;
4663 if (channels_for_active_mic > m_info[i].channel_count) {
4664 channels_for_active_mic = m_info[i].channel_count;
4665 }
4666 for (size_t j = 0; j < max_mic_count; j++) {
4667 if (strcmp(my_data->microphones[j].device_id,
4668 m_info[i].device_id) == 0) {
4669 mic_array[actual_mic_count] = my_data->microphones[j];
4670 for (size_t ch = 0; ch < channels_for_active_mic; ch++) {
4671 mic_array[actual_mic_count].channel_mapping[ch] =
4672 m_info[i].channel_mapping[ch];
4673 }
4674 actual_mic_count++;
4675 break;
jiabin8962a4d2018-03-19 18:21:24 -07004676 }
jiabin8962a4d2018-03-19 18:21:24 -07004677 }
4678 }
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004679end:
jiabin8962a4d2018-03-19 18:21:24 -07004680 *mic_count = actual_mic_count;
4681 return 0;
4682}
Haynes Mathew George65f6b432018-02-27 17:44:55 -08004683
4684int platform_set_usb_service_interval(void *platform,
4685 bool playback,
4686 unsigned long service_interval,
4687 bool *reconfig)
4688{
4689#if defined (USB_SERVICE_INTERVAL_ENABLED)
4690 struct platform_data *_platform = (struct platform_data *)platform;
4691 *reconfig = false;
4692 if (!playback) {
4693 ALOGE("%s not valid for capture", __func__);
4694 return -1;
4695 }
4696 const char *ctl_name = "USB_AUDIO_RX service_interval";
4697 struct mixer_ctl *ctl = mixer_get_ctl_by_name(_platform->adev->mixer,
4698 ctl_name);
4699 if (!ctl) {
4700 ALOGV("%s: could not get mixer %s", __func__, ctl_name);
4701 return -1;
4702 }
4703 if (mixer_ctl_get_value(ctl, 0) != (int)service_interval) {
4704 mixer_ctl_set_value(ctl, 0, service_interval);
4705 *reconfig = true;
4706 }
4707 return 0;
4708#else
4709 *reconfig = false;
4710 (void)platform;
4711 (void)playback;
4712 (void)service_interval;
4713 return -1;
4714#endif
4715}
4716
4717int platform_get_usb_service_interval(void *platform,
4718 bool playback,
4719 unsigned long *service_interval)
4720{
4721#if defined (USB_SERVICE_INTERVAL_ENABLED)
4722 struct platform_data *_platform = (struct platform_data *)platform;
4723 if (!playback) {
4724 ALOGE("%s not valid for capture", __func__);
4725 return -1;
4726 }
4727 const char *ctl_name = "USB_AUDIO_RX service_interval";
4728 struct mixer_ctl *ctl = mixer_get_ctl_by_name(_platform->adev->mixer,
4729 ctl_name);
4730 if (!ctl) {
4731 ALOGV("%s: could not get mixer %s", __func__, ctl_name);
4732 return -1;
4733 }
4734 *service_interval = mixer_ctl_get_value(ctl, 0);
4735 return 0;
4736#else
4737 (void)platform;
4738 (void)playback;
4739 (void)service_interval;
4740 return -1;
4741#endif
4742}
Ashish Jain1c849702018-05-11 20:11:55 +05304743
4744int platform_set_acdb_metainfo_key(void *platform __unused,
4745 char *name __unused,
4746 int key __unused)
4747{
4748 return -ENOSYS;
4749}